Move patches to unapplied

This commit is contained in:
Nassim Jahnke
2024-12-12 12:22:12 +01:00
parent ff75689b08
commit 45ddf764d9
821 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
--- a/net/minecraft/world/item/enchantment/ItemEnchantments.java
+++ b/net/minecraft/world/item/enchantment/ItemEnchantments.java
@@ -26,12 +26,25 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.component.TooltipProvider;
+// Paper start
+import it.unimi.dsi.fastutil.objects.Object2IntAVLTreeMap;
+// Paper end
public class ItemEnchantments implements TooltipProvider {
- public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntOpenHashMap<>(), true);
+ // Paper start
+ private static final java.util.Comparator<Holder<Enchantment>> ENCHANTMENT_ORDER = java.util.Comparator.comparing(Holder::getRegisteredName);
+ public static final ItemEnchantments EMPTY = new ItemEnchantments(new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), true);
+ // Paper end
private static final Codec<Integer> LEVEL_CODEC = Codec.intRange(1, 255);
- private static final Codec<Object2IntOpenHashMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(Enchantment.CODEC, LEVEL_CODEC)
- .xmap(Object2IntOpenHashMap::new, Function.identity());
+ private static final Codec<Object2IntAVLTreeMap<Holder<Enchantment>>> LEVELS_CODEC = Codec.unboundedMap(
+ Enchantment.CODEC, LEVEL_CODEC
+ )// Paper start - sort enchantments
+ .xmap(m -> {
+ final Object2IntAVLTreeMap<Holder<Enchantment>> map = new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER);
+ map.putAll(m);
+ return map;
+ }, Function.identity());
+ // Paper end - sort enchantments
private static final Codec<ItemEnchantments> FULL_CODEC = RecordCodecBuilder.create(
instance -> instance.group(
LEVELS_CODEC.fieldOf("levels").forGetter(component -> component.enchantments),
@@ -41,16 +54,16 @@
);
public static final Codec<ItemEnchantments> CODEC = Codec.withAlternative(FULL_CODEC, LEVELS_CODEC, map -> new ItemEnchantments(map, true));
public static final StreamCodec<RegistryFriendlyByteBuf, ItemEnchantments> STREAM_CODEC = StreamCodec.composite(
- ByteBufCodecs.map(Object2IntOpenHashMap::new, Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT),
+ ByteBufCodecs.map((v) -> new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER), Enchantment.STREAM_CODEC, ByteBufCodecs.VAR_INT),
component -> component.enchantments,
ByteBufCodecs.BOOL,
component -> component.showInTooltip,
ItemEnchantments::new
);
- final Object2IntOpenHashMap<Holder<Enchantment>> enchantments;
+ final Object2IntAVLTreeMap<Holder<Enchantment>> enchantments; // Paper
public final boolean showInTooltip;
- ItemEnchantments(Object2IntOpenHashMap<Holder<Enchantment>> enchantments, boolean showInTooltip) {
+ ItemEnchantments(Object2IntAVLTreeMap<Holder<Enchantment>> enchantments, boolean showInTooltip) { // Paper
this.enchantments = enchantments;
this.showInTooltip = showInTooltip;
@@ -139,7 +152,7 @@
}
public static class Mutable {
- private final Object2IntOpenHashMap<Holder<Enchantment>> enchantments = new Object2IntOpenHashMap<>();
+ private final Object2IntAVLTreeMap<Holder<Enchantment>> enchantments = new Object2IntAVLTreeMap<>(ENCHANTMENT_ORDER); // Paper
public boolean showInTooltip;
public Mutable(ItemEnchantments enchantmentsComponent) {

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/enchantment/effects/ApplyMobEffect.java
+++ b/net/minecraft/world/item/enchantment/effects/ApplyMobEffect.java
@@ -34,7 +34,7 @@
int j = Math.round(Mth.randomBetween(randomsource, this.minDuration.calculate(level), this.maxDuration.calculate(level)) * 20.0F);
int k = Math.max(0, Math.round(Mth.randomBetween(randomsource, this.minAmplifier.calculate(level), this.maxAmplifier.calculate(level))));
- entityliving.addEffect(new MobEffectInstance((Holder) optional.get(), j, k));
+ entityliving.addEffect(new MobEffectInstance((Holder) optional.get(), j, k), org.bukkit.event.entity.EntityPotionEffectEvent.Cause.ATTACK); // CraftBukkit
}
}

View File

@@ -0,0 +1,14 @@
--- a/net/minecraft/world/item/enchantment/effects/ChangeItemDamage.java
+++ b/net/minecraft/world/item/enchantment/effects/ChangeItemDamage.java
@@ -21,9 +21,9 @@
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity user, Vec3 pos) {
ItemStack itemStack = context.itemStack();
if (itemStack.has(DataComponents.MAX_DAMAGE) && itemStack.has(DataComponents.DAMAGE)) {
- ServerPlayer serverPlayer2 = context.owner() instanceof ServerPlayer serverPlayer ? serverPlayer : null;
+ // ServerPlayer serverPlayer2 = context.owner() instanceof ServerPlayer serverPlayer ? serverPlayer : null; // Paper - EntityDamageItemEvent - always pass in entity
int i = (int)this.amount.calculate(level);
- itemStack.hurtAndBreak(i, world, serverPlayer2, context.onBreak());
+ itemStack.hurtAndBreak(i, world, context.owner(), context.onBreak()); // Paper - EntityDamageItemEvent - always pass in entity
}
}

View File

@@ -0,0 +1,36 @@
--- a/net/minecraft/world/item/enchantment/effects/Ignite.java
+++ b/net/minecraft/world/item/enchantment/effects/Ignite.java
@@ -7,6 +7,10 @@
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
import net.minecraft.world.item.enchantment.LevelBasedValue;
import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.entity.EntityCombustEvent;
+// CraftBukkit end
public record Ignite(LevelBasedValue duration) implements EnchantmentEntityEffect {
@@ -18,7 +22,21 @@
@Override
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity user, Vec3 pos) {
- user.igniteForSeconds(this.duration.calculate(level));
+ // CraftBukkit start - Call a combust event when somebody hits with a fire enchanted item
+ EntityCombustEvent entityCombustEvent;
+ if (context.owner() != null) {
+ entityCombustEvent = new EntityCombustByEntityEvent(context.owner().getBukkitEntity(), user.getBukkitEntity(), this.duration.calculate(level));
+ } else {
+ entityCombustEvent = new EntityCombustEvent(user.getBukkitEntity(), this.duration.calculate(level));
+ }
+
+ org.bukkit.Bukkit.getPluginManager().callEvent(entityCombustEvent);
+ if (entityCombustEvent.isCancelled()) {
+ return;
+ }
+
+ user.igniteForSeconds(entityCombustEvent.getDuration(), false);
+ // CraftBukkit end
}
@Override

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/enchantment/effects/ReplaceBlock.java
+++ b/net/minecraft/world/item/enchantment/effects/ReplaceBlock.java
@@ -26,7 +26,7 @@
if ((Boolean) this.predicate.map((blockpredicate) -> {
return blockpredicate.test(world, blockposition);
- }).orElse(true) && world.setBlockAndUpdate(blockposition, this.blockState.getState(user.getRandom(), blockposition))) {
+ }).orElse(true) && org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(world, blockposition, this.blockState.getState(user.getRandom(), blockposition), user)) { // CraftBukkit - Call EntityBlockFormEvent
this.triggerGameEvent.ifPresent((holder) -> {
world.gameEvent(user, holder, blockposition);
});

View File

@@ -0,0 +1,11 @@
--- a/net/minecraft/world/item/enchantment/effects/ReplaceDisk.java
+++ b/net/minecraft/world/item/enchantment/effects/ReplaceDisk.java
@@ -37,7 +37,7 @@
if (blockposition1.distToCenterSqr(pos.x(), (double) blockposition1.getY() + 0.5D, pos.z()) < (double) Mth.square(j) && (Boolean) this.predicate.map((blockpredicate) -> {
return blockpredicate.test(world, blockposition1);
- }).orElse(true) && world.setBlockAndUpdate(blockposition1, this.blockState.getState(randomsource, blockposition1))) {
+ }).orElse(true) && org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockFormEvent(world, blockposition1, this.blockState.getState(randomsource, blockposition1), user)) { // CraftBukkit - Call EntityBlockFormEvent for Frost Walker
this.triggerGameEvent.ifPresent((holder) -> {
world.gameEvent(user, holder, blockposition1);
});

View File

@@ -0,0 +1,35 @@
--- a/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.java
+++ b/net/minecraft/world/item/enchantment/effects/SummonEntityEffect.java
@@ -19,6 +19,11 @@
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import net.minecraft.world.item.Items;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.weather.LightningStrikeEvent;
+// CraftBukkit end
public record SummonEntityEffect(HolderSet<EntityType<?>> entityTypes, boolean joinTeam) implements EnchantmentEntityEffect {
@@ -34,7 +39,7 @@
Optional<Holder<EntityType<?>>> optional = this.entityTypes().getRandomElement(world.getRandom());
if (!optional.isEmpty()) {
- Entity entity1 = ((EntityType) ((Holder) optional.get()).value()).spawn(world, blockposition, EntitySpawnReason.TRIGGERED);
+ Entity entity1 = ((EntityType) ((Holder) optional.get()).value()).create(world, null, blockposition, EntitySpawnReason.TRIGGERED, false, false); // CraftBukkit
if (entity1 != null) {
if (entity1 instanceof LightningBolt) {
@@ -46,6 +51,11 @@
entitylightning.setCause(entityplayer);
}
+ // CraftBukkit start
+ world.strikeLightning(entity1, (context.itemStack().getItem() == Items.TRIDENT) ? LightningStrikeEvent.Cause.TRIDENT : LightningStrikeEvent.Cause.ENCHANTMENT);
+ } else {
+ world.addFreshEntityWithPassengers(entity1, CreatureSpawnEvent.SpawnReason.ENCHANTMENT);
+ // CraftBukkit end
}
if (this.joinTeam && user.getTeam() != null) {