Patch me this, patch me that

This commit is contained in:
Bjarne Koll 2024-10-24 12:11:32 +02:00
parent 951043246e
commit 199ab95b0d
60 changed files with 336 additions and 360 deletions

View File

@ -35,7 +35,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
return org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getPotion());
}
// Paper end - WitchReadyPotionEvent

View File

@ -32,7 +32,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
io.papermc.paper.event.block.BlockFailedDispenseEvent event = new io.papermc.paper.event.block.BlockFailedDispenseEvent(block);
return event.callEvent();
}

View File

@ -72,7 +72,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
return event.callEvent();
}
// Paper end

View File

@ -13,20 +13,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return;
}
- this.player.getInventory().pickSlot(packet.getSlot()); // Paper - Diff above if changed
// Paper end - validate pick item position
+ // Paper start - Add PlayerPickItemEvent
+ // this.player.getInventory().pickSlot(packet.getSlot()); // Paper - Diff above if changed - moved down
+ Player bukkitPlayer = this.player.getBukkitEntity();
+ int targetSlot = this.player.getInventory().getSuitableHotbarSlot();
+ int sourceSlot = packet.getSlot();
+
+ io.papermc.paper.event.player.PlayerPickItemEvent event = new io.papermc.paper.event.player.PlayerPickItemEvent(bukkitPlayer, targetSlot, sourceSlot);
+ if (!event.callEvent()) return;
+
+ this.player.getInventory().pickSlot(event.getSourceSlot(), event.getTargetSlot());
+ // Paper end - Add PlayerPickItemEvent
this.player.connection.send(new ClientboundContainerSetSlotPacket(-2, 0, this.player.getInventory().selected, this.player.getInventory().getItem(this.player.getInventory().selected)));
this.player.connection.send(new ClientboundContainerSetSlotPacket(-2, 0, packet.getSlot(), this.player.getInventory().getItem(packet.getSlot())));
this.player.connection.send(new ClientboundSetCarriedItemPacket(this.player.getInventory().selected));
+
+ this.player.getInventory().pickSlot(event.getSourceSlot(), event.getTargetSlot()); // Paper - Add PlayerPickItemEvent
// Paper end - validate pick item position
int i = this.player.getInventory().selected;
diff --git a/src/main/java/net/minecraft/world/entity/player/Inventory.java b/src/main/java/net/minecraft/world/entity/player/Inventory.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/player/Inventory.java

View File

@ -97,7 +97,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
}
public static PrepareAnvilEvent callPrepareAnvilEvent(AnvilView view, ItemStack item) {
@ -110,7 +110,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
event.getInventory().setItem(2, event.getResult());
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
}
public static PrepareGrindstoneEvent callPrepareGrindstoneEvent(InventoryView view, ItemStack item) {
@ -123,7 +123,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
PrepareGrindstoneEvent event = new PrepareGrindstoneEvent(view, CraftItemStack.asCraftMirror(item).clone());
event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
event.getInventory().setItem(2, event.getResult());
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
}
public static PrepareSmithingEvent callPrepareSmithingEvent(InventoryView view, ItemStack item) {

View File

@ -64,7 +64,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
return CraftEventFactory.callEntityDamageEvent(source.getDirectBlock(), source.getDirectBlockState(), entity, DamageCause.BLOCK_EXPLOSION, bukkitDamageSource, modifiers, modifierFunctions, cancelled);
}
DamageCause damageCause = (damager.getBukkitEntity() instanceof org.bukkit.entity.TNTPrimed) ? DamageCause.BLOCK_EXPLOSION : DamageCause.ENTITY_EXPLOSION;
@ -73,7 +73,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} else if (damager != null || source.getDirectEntity() != null) {
DamageCause cause = (source.isSweep()) ? DamageCause.ENTITY_SWEEP_ATTACK : DamageCause.ENTITY_ATTACK;
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
cause = DamageCause.MAGIC;
}
@ -82,7 +82,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} else if (source.is(DamageTypes.FELL_OUT_OF_WORLD)) {
return CraftEventFactory.callEntityDamageEvent(source.getDirectBlock(), source.getDirectBlockState(), entity, DamageCause.VOID, bukkitDamageSource, modifiers, modifierFunctions, cancelled);
} else if (source.is(DamageTypes.LAVA)) {
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
cause = DamageCause.CUSTOM;
}

View File

@ -14,14 +14,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// CraftBukkit start
- if (CraftEventFactory.callBlockShearEntityEvent(entityliving, bukkitBlock, craftItem).isCancelled()) {
+ // Paper start - Add drops to shear events
+ org.bukkit.event.block.BlockShearEntityEvent event = CraftEventFactory.callBlockShearEntityEvent(entityliving, bukkitBlock, craftItem, ishearable.generateDefaultDrops());
+ org.bukkit.event.block.BlockShearEntityEvent event = CraftEventFactory.callBlockShearEntityEvent(entityliving, bukkitBlock, craftItem, ishearable.generateDefaultDrops(worldserver, itemstack));
+ if (event.isCancelled()) {
+ // Paper end - Add drops to shear events
continue;
}
// CraftBukkit end
- ishearable.shear(SoundSource.BLOCKS);
+ ishearable.shear(SoundSource.BLOCKS, CraftItemStack.asNMSCopy(event.getDrops())); // Paper - Add drops to shear events
- ishearable.shear(worldserver, SoundSource.BLOCKS, itemstack);
+ ishearable.shear(worldserver, SoundSource.BLOCKS, itemstack, CraftItemStack.asNMSCopy(event.getDrops())); // Paper - Add drops to shear events
worldserver.gameEvent((Entity) null, (Holder) GameEvent.SHEAR, blockposition);
return true;
}
@ -29,16 +29,16 @@ diff --git a/src/main/java/net/minecraft/world/entity/Shearable.java b/src/main/
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/Shearable.java
+++ b/src/main/java/net/minecraft/world/entity/Shearable.java
@@ -0,0 +0,0 @@ package net.minecraft.world.entity;
import net.minecraft.sounds.SoundSource;
@@ -0,0 +0,0 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.world.item.ItemStack;
public interface Shearable {
+ default void shear(SoundSource soundCategory, java.util.List<net.minecraft.world.item.ItemStack> drops) { this.shear(soundCategory); } // Paper - Add drops to shear events
void shear(SoundSource shearedSoundCategory);
+ default void shear(ServerLevel world, SoundSource soundCategory, ItemStack shears, java.util.List<net.minecraft.world.item.ItemStack> drops) { this.shear(world, soundCategory, shears); } // Paper - Add drops to shear events
void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears);
boolean readyForShearing();
+ // Paper start - custom shear drops; ensure all implementing entities override this
+ default java.util.List<net.minecraft.world.item.ItemStack> generateDefaultDrops() {
+ default java.util.List<net.minecraft.world.item.ItemStack> generateDefaultDrops(final ServerLevel serverLevel, final ItemStack shears) {
+ return java.util.Collections.emptyList();
+ }
+ // Paper end - custom shear drops
@ -47,275 +47,262 @@ diff --git a/src/main/java/net/minecraft/world/entity/animal/MushroomCow.java b/
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/animal/MushroomCow.java
+++ b/src/main/java/net/minecraft/world/entity/animal/MushroomCow.java
@@ -0,0 +0,0 @@ import net.minecraft.world.level.storage.loot.BuiltInLootTables;
// CraftBukkit start
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.event.entity.EntityDropItemEvent;
import org.bukkit.event.entity.EntityTransformEvent;
// CraftBukkit end
@@ -0,0 +0,0 @@ public class MushroomCow extends Cow implements Shearable, VariantHolder<Mushroo
return InteractionResult.sidedSuccess(this.level().isClientSide);
} else if (itemstack.is(Items.SHEARS) && this.readyForShearing()) {
ServerLevel worldserver = (ServerLevel) world;
// CraftBukkit start
- if (!CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand)) {
- return InteractionResult.PASS;
+ // Paper start - custom shear drops
+ java.util.List<ItemStack> drops = this.generateDefaultDrops();
+ java.util.List<ItemStack> drops = this.generateDefaultDrops(worldserver, itemstack);
+ org.bukkit.event.player.PlayerShearEntityEvent event = CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand, drops);
+ if (event != null) {
+ if (event.isCancelled()) {
+ return InteractionResult.PASS;
+ }
+ drops = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getDrops());
}
+ // Paper end - custom shear drops
}
// CraftBukkit end
- this.shear(SoundSource.PLAYERS);
+ this.shear(SoundSource.PLAYERS, drops); // Paper - custom shear drops
- this.shear(worldserver, SoundSource.PLAYERS, itemstack);
+ this.shear(worldserver, SoundSource.PLAYERS, itemstack, drops); // Paper - custom shear drops
this.gameEvent(GameEvent.SHEAR, player);
if (!this.level().isClientSide) {
itemstack.hurtAndBreak(1, player, getSlotForHand(hand));
}
@@ -0,0 +0,0 @@ public class MushroomCow extends Cow implements Shearable, VariantHolder<Mushroo
@Override
public void shear(SoundSource shearedSoundCategory) {
public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears) {
+ // Paper start - custom shear drops
+ this.shear(shearedSoundCategory, this.generateDefaultDrops());
+ this.shear(world, shearedSoundCategory, shears, this.generateDefaultDrops(world, shears));
+ }
+
+ @Override
+ public java.util.List<ItemStack> generateDefaultDrops() {
+ java.util.List<ItemStack> dropEntities = new java.util.ArrayList<>(5);
+ for (int i = 0; i < 5; ++i) {
+ dropEntities.add(new ItemStack(this.getVariant().getBlockState().getBlock()));
+ }
+ return dropEntities;
+ public java.util.List<ItemStack> generateDefaultDrops(final ServerLevel serverLevel, final ItemStack shears) {
+ final java.util.List<ItemStack> drops = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
+ this.dropFromShearingLootTable(serverLevel, BuiltInLootTables.SHEAR_MOOSHROOM, shears, (ignored, stack) -> {
+ for (int i = 0; i < stack.getCount(); ++i) drops.add(stack.copyWithCount(1));
+ });
+ return drops;
+ }
+
+ @Override
+ public void shear(SoundSource shearedSoundCategory, java.util.List<ItemStack> drops) { // If drops is null, need to generate drops
+ public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears, java.util.List<ItemStack> drops) {
+ // Paper end - custom shear drops
this.level().playSound((Player) null, (Entity) this, SoundEvents.MOOSHROOM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
if (!this.level().isClientSide()) {
Cow entitycow = (Cow) EntityType.COW.create(this.level());
@@ -0,0 +0,0 @@ public class MushroomCow extends Cow implements Shearable, VariantHolder<Mushroo
this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - from above and add Bukkit remove cause
// CraftBukkit end
- for (int i = 0; i < 5; ++i) {
world.playSound((Player) null, (Entity) this, SoundEvents.MOOSHROOM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
this.convertTo(EntityType.COW, ConversionParams.single(this, false, false), (entitycow) -> {
world.sendParticles(ParticleTypes.EXPLOSION, this.getX(), this.getY(0.5D), this.getZ(), 1, 0.0D, 0.0D, 0.0D, 0.0D);
- this.dropFromShearingLootTable(world, BuiltInLootTables.SHEAR_MOOSHROOM, shears, (worldserver1, itemstack1) -> {
- for (int i = 0; i < itemstack1.getCount(); ++i) {
- // CraftBukkit start
- ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), this.getY(1.0D), this.getZ(), new ItemStack(this.getVariant().blockState.getBlock()));
- ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), this.getY(1.0D), this.getZ(), itemstack1.copyWithCount(1));
- EntityDropItemEvent event = new EntityDropItemEvent(this.getBukkitEntity(), (org.bukkit.entity.Item) entityitem.getBukkitEntity());
- Bukkit.getPluginManager().callEvent(event);
- if (event.isCancelled()) {
- continue;
- }
- this.level().addFreshEntity(entityitem);
- worldserver1.addFreshEntity(entityitem);
- // CraftBukkit end
+ // Paper start - custom shear drops; moved drop generation to separate method
+ drops.forEach(itemstack1 -> {
+ for (final ItemStack drop : drops) {
+ ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), this.getY(1.0D), this.getZ(), drop);
+ this.spawnAtLocation(entityitem);
}
+ // Paper end - custom shear drops
-
+ // Paper end - custom shear drops; moved drop generation to separate method
});
}, EntityTransformEvent.TransformReason.SHEARED, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SHEARED); // CraftBukkit
}
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/Sheep.java b/src/main/java/net/minecraft/world/entity/animal/Sheep.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Sheep.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Sheep.java
@@ -0,0 +0,0 @@ public class Sheep extends Animal implements Shearable {
if (itemstack.is(Items.SHEARS)) {
if (!this.level().isClientSide && this.readyForShearing()) {
if (this.readyForShearing()) {
// CraftBukkit start
- if (!CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand)) {
- return InteractionResult.PASS;
+ // Paper start - custom shear drops
+ java.util.List<ItemStack> drops = this.generateDefaultDrops();
+ java.util.List<ItemStack> drops = this.generateDefaultDrops(worldserver, itemstack);
+ org.bukkit.event.player.PlayerShearEntityEvent event = CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand, drops);
+ if (event != null) {
+ if (event.isCancelled()) {
+ return InteractionResult.PASS;
+ }
+ drops = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getDrops());
}
+ // Paper end - custom shear drops
}
// CraftBukkit end
- this.shear(SoundSource.PLAYERS);
+ this.shear(SoundSource.PLAYERS, drops); // Paper
- this.shear(worldserver, SoundSource.PLAYERS, itemstack);
+ this.shear(worldserver, SoundSource.PLAYERS, itemstack, drops); // Paper - custom shear drops
this.gameEvent(GameEvent.SHEAR, player);
itemstack.hurtAndBreak(1, player, getSlotForHand(hand));
return InteractionResult.SUCCESS;
return InteractionResult.SUCCESS_SERVER;
@@ -0,0 +0,0 @@ public class Sheep extends Animal implements Shearable {
@Override
public void shear(SoundSource shearedSoundCategory) {
public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears) {
+ // Paper start - custom shear drops
+ this.shear(shearedSoundCategory, this.generateDefaultDrops());
+ this.shear(world, shearedSoundCategory, shears, this.generateDefaultDrops(world, shears));
+ }
+
+ @Override
+ public java.util.List<ItemStack> generateDefaultDrops() {
+ int count = 1 + this.random.nextInt(3);
+ java.util.List<ItemStack> dropEntities = new java.util.ArrayList<>(count);
+ for (int j = 0; j < count; ++j) {
+ dropEntities.add(new ItemStack(Sheep.ITEM_BY_DYE.get(this.getColor())));
+ }
+ return dropEntities;
+ public java.util.List<ItemStack> generateDefaultDrops(final ServerLevel serverLevel, final ItemStack shears) {
+ final java.util.List<ItemStack> drops = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
+ this.dropFromShearingLootTable(serverLevel, BuiltInLootTables.SHEAR_SHEEP, shears, (ignored, stack) -> {
+ for (int i = 0; i < stack.getCount(); ++i) drops.add(stack.copyWithCount(1));
+ });
+ return drops;
+ }
+
+ @Override
+ public void shear(SoundSource shearedSoundCategory, java.util.List<ItemStack> drops) {
+ public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears, java.util.List<ItemStack> drops) {
+ final ServerLevel worldserver1 = world; // Named for lambda consumption
+ // Paper end - custom shear drops
this.level().playSound((Player) null, (Entity) this, SoundEvents.SHEEP_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
this.setSheared(true);
int i = 1 + this.random.nextInt(3);
- for (int j = 0; j < i; ++j) {
+ for (final ItemStack drop : drops) { // Paper - custom shear drops (moved drop generation to separate method)
world.playSound((Player) null, (Entity) this, SoundEvents.SHEEP_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
- this.dropFromShearingLootTable(world, BuiltInLootTables.SHEAR_SHEEP, shears, (worldserver1, itemstack1) -> {
- for (int i = 0; i < itemstack1.getCount(); ++i) {
+ drops.forEach(itemstack1 -> { // Paper - custom drops - loop in generated default drops
+ if (true) { // Paper - custom drops - loop in generated default drops
this.forceDrops = true; // CraftBukkit
- ItemEntity entityitem = this.spawnAtLocation((ItemLike) Sheep.ITEM_BY_DYE.get(this.getColor()), 1);
+ ItemEntity entityitem = this.spawnAtLocation(drop, 1); // Paper - custom shear drops
ItemEntity entityitem = this.spawnAtLocation(worldserver1, itemstack1.copyWithCount(1), 1.0F);
this.forceDrops = false; // CraftBukkit
if (entityitem != null) {
diff --git a/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java b/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java
+++ b/src/main/java/net/minecraft/world/entity/animal/SnowGolem.java
@@ -0,0 +0,0 @@ public class SnowGolem extends AbstractGolem implements Shearable, RangedAttackM
ServerLevel worldserver = (ServerLevel) world;
if (itemstack.is(Items.SHEARS) && this.readyForShearing()) {
// CraftBukkit start
- if (!CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand)) {
- return InteractionResult.PASS;
+ // Paper start - custom shear drops
+ java.util.List<ItemStack> drops = this.generateDefaultDrops();
+ java.util.List<ItemStack> drops = this.generateDefaultDrops(worldserver, itemstack);
+ org.bukkit.event.player.PlayerShearEntityEvent event = CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand, drops);
+ if (event != null) {
+ if (event.isCancelled()) {
+ return InteractionResult.PASS;
+ }
+ drops = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getDrops());
}
+ // Paper end - custom shear drops
}
// CraftBukkit end
- this.shear(SoundSource.PLAYERS);
+ this.shear(SoundSource.PLAYERS, drops); // Paper
- this.shear(worldserver, SoundSource.PLAYERS, itemstack);
+ this.shear(worldserver, SoundSource.PLAYERS, itemstack, drops); // Paper - custom shear drops
this.gameEvent(GameEvent.SHEAR, player);
if (!this.level().isClientSide) {
itemstack.hurtAndBreak(1, player, getSlotForHand(hand));
}
@@ -0,0 +0,0 @@ public class SnowGolem extends AbstractGolem implements Shearable, RangedAttackM
@Override
public void shear(SoundSource shearedSoundCategory) {
public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears) {
+ // Paper start - custom shear drops
+ this.shear(shearedSoundCategory, this.generateDefaultDrops());
+ this.shear(world, shearedSoundCategory, shears, this.generateDefaultDrops(world, shears));
+ }
+
+ @Override
+ public java.util.List<ItemStack> generateDefaultDrops() {
+ return java.util.Collections.singletonList(new ItemStack(Items.CARVED_PUMPKIN));
+ public java.util.List<ItemStack> generateDefaultDrops(final ServerLevel serverLevel, final ItemStack shears) {
+ final java.util.List<ItemStack> drops = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
+ this.dropFromShearingLootTable(serverLevel, BuiltInLootTables.SHEAR_SNOW_GOLEM, shears, (ignored, stack) -> {
+ drops.add(stack);
+ });
+ return drops;
+ }
+
+ @Override
+ public void shear(SoundSource shearedSoundCategory, java.util.List<ItemStack> drops) {
+ public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears, java.util.List<ItemStack> drops) {
+ final ServerLevel worldserver1 = world; // Named for lambda consumption
+ // Paper end - custom shear drops
this.level().playSound((Player) null, (Entity) this, SoundEvents.SNOW_GOLEM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
if (!this.level().isClientSide()) {
world.playSound((Player) null, (Entity) this, SoundEvents.SNOW_GOLEM_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
this.setPumpkin(false);
- this.forceDrops = true; // CraftBukkit
- this.spawnAtLocation(new ItemStack(Items.CARVED_PUMPKIN), this.getEyeHeight());
- this.forceDrops = false; // CraftBukkit
+ // Paper start - custom shear drops (moved drop generation to separate method)
+ for (final ItemStack drop : drops) {
+ this.forceDrops = true;
+ this.spawnAtLocation(drop, this.getEyeHeight());
+ this.forceDrops = false;
+ }
+ // Paper end - custom shear drops
}
}
- this.dropFromShearingLootTable(world, BuiltInLootTables.SHEAR_SNOW_GOLEM, shears, (worldserver1, itemstack1) -> {
+ drops.forEach(itemstack1 -> { // Paper - custom shear drops
this.forceDrops = true; // CraftBukkit
this.spawnAtLocation(worldserver1, itemstack1, this.getEyeHeight());
this.forceDrops = false; // CraftBukkit
diff --git a/src/main/java/net/minecraft/world/entity/monster/Bogged.java b/src/main/java/net/minecraft/world/entity/monster/Bogged.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Bogged.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Bogged.java
@@ -0,0 +0,0 @@ public class Bogged extends AbstractSkeleton implements Shearable {
@@ -0,0 +0,0 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.storage.loot.BuiltInLootTables;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
public class Bogged extends AbstractSkeleton implements Shearable {
@@ -0,0 +0,0 @@ public class Bogged extends AbstractSkeleton implements Shearable {
ServerLevel worldserver = (ServerLevel) world;
if (itemstack.is(Items.SHEARS) && this.readyForShearing()) {
// CraftBukkit start
- if (!org.bukkit.craftbukkit.event.CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand)) {
- this.getEntityData().markDirty(Bogged.DATA_SHEARED); // CraftBukkit - mark dirty to restore sheared state to clients
- return InteractionResult.PASS;
+ // Paper start - expose drops in event
+ java.util.List<net.minecraft.world.item.ItemStack> drops = generateDefaultDrops();
+ final org.bukkit.event.player.PlayerShearEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand, drops);
+ // Paper start - custom shear drops
+ java.util.List<ItemStack> drops = this.generateDefaultDrops(worldserver, itemstack);
+ org.bukkit.event.player.PlayerShearEntityEvent event = CraftEventFactory.handlePlayerShearEntityEvent(player, this, itemstack, hand, drops);
+ if (event != null) {
+ if (event.isCancelled()) {
+ if (player instanceof final net.minecraft.server.level.ServerPlayer serverPlayer) this.resendPossiblyDesyncedDataValues(java.util.List.of(Bogged.DATA_SHEARED), serverPlayer);
+ this.getEntityData().markDirty(Bogged.DATA_SHEARED); // CraftBukkit - mark dirty to restore sheared state to clients
+ return InteractionResult.PASS;
+ }
+ drops = org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getDrops());
+ // Paper end - expose drops in event
+ // Paper end - custom shear drops
}
// CraftBukkit end
- this.shear(SoundSource.PLAYERS);
+ this.shear(SoundSource.PLAYERS, drops); // Paper - expose drops in event
- this.shear(worldserver, SoundSource.PLAYERS, itemstack);
+ this.shear(worldserver, SoundSource.PLAYERS, itemstack, drops); // Paper - custom shear drops
this.gameEvent(GameEvent.SHEAR, player);
if (!this.level().isClientSide) {
itemstack.hurtAndBreak(1, player, getSlotForHand(hand));
}
@@ -0,0 +0,0 @@ public class Bogged extends AbstractSkeleton implements Shearable {
@Override
public void shear(SoundSource shearedSoundCategory) {
+ // Paper start - shear drop API
+ this.shear(shearedSoundCategory, generateDefaultDrops());
public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears) {
+ // Paper start - custom shear drops
+ this.shear(world, shearedSoundCategory, shears, this.generateDefaultDrops(world, shears));
+ }
+
+ @Override
+ public void shear(SoundSource shearedSoundCategory, java.util.List<net.minecraft.world.item.ItemStack> drops) {
+ // Paper end - shear drop API
this.level().playSound((Player) null, (Entity) this, SoundEvents.BOGGED_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
- this.spawnShearedMushrooms();
+ this.spawnDrops(drops); // Paper - shear drop API
+ public java.util.List<ItemStack> generateDefaultDrops(final ServerLevel serverLevel, final ItemStack shears) {
+ final java.util.List<ItemStack> drops = new it.unimi.dsi.fastutil.objects.ObjectArrayList<>();
+ this.dropFromShearingLootTable(serverLevel, BuiltInLootTables.BOGGED_SHEAR, shears, (ignored, stack) -> {
+ drops.add(stack);
+ });
+ return drops;
+ }
+
+ @Override
+ public void shear(ServerLevel world, SoundSource shearedSoundCategory, ItemStack shears, java.util.List<ItemStack> drops) {
+ // Paper end - custom shear drops
world.playSound((Player) null, (Entity) this, SoundEvents.BOGGED_SHEAR, shearedSoundCategory, 1.0F, 1.0F);
- this.spawnShearedMushrooms(world, shears);
+ this.spawnShearedMushrooms(world, shears, drops); // Paper - custom shear drops
this.setSheared(true);
}
private void spawnShearedMushrooms() {
+ // Paper start - shear drops API
+ this.spawnDrops(generateDefaultDrops()); // Only here for people calling spawnSheardMushrooms. Not used otherwise.
+ }
+ private void spawnDrops(java.util.List<net.minecraft.world.item.ItemStack> drops) {
+ drops.forEach(stack -> {
+ this.forceDrops = true;
+ this.spawnAtLocation(stack, this.getBbHeight());
+ this.forceDrops = false;
+ });
+ }
+ private void generateShearedMushrooms(java.util.function.Consumer<ItemStack> stackConsumer) {
+ // Paper end - shear drops API
Level world = this.level();
if (world instanceof ServerLevel worldserver) {
@@ -0,0 +0,0 @@ public class Bogged extends AbstractSkeleton implements Shearable {
while (objectlistiterator.hasNext()) {
ItemStack itemstack = (ItemStack) objectlistiterator.next();
- this.spawnAtLocation(itemstack, this.getBbHeight());
+ stackConsumer.accept(itemstack); // Paper
- private void spawnShearedMushrooms(ServerLevel world, ItemStack shears) {
- this.dropFromShearingLootTable(world, BuiltInLootTables.BOGGED_SHEAR, shears, (worldserver1, itemstack1) -> {
+ // Paper start - custom shear drops
+ private void spawnShearedMushrooms(ServerLevel world, ItemStack shears, java.util.List<ItemStack> drops) {
+ final ServerLevel worldserver1 = world; // Named for lambda consumption
+ drops.forEach(itemstack1 -> {
+ // Paper end - custom shear drops
this.spawnAtLocation(worldserver1, itemstack1, this.getBbHeight());
});
}
}
}
+ // Paper start - shear drops API
+ @Override
+ public java.util.List<ItemStack> generateDefaultDrops() {
+ final java.util.List<ItemStack> drops = new java.util.ArrayList<>();
+ this.generateShearedMushrooms(drops::add);
+ return drops;
+ }
+ // Paper end - shear drops API
+
@Override
public boolean readyForShearing() {
return !this.isSheared() && this.isAlive();
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java

View File

@ -180,28 +180,40 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/ItemCombinerMenu.java
@@ -0,0 +0,0 @@ public abstract class ItemCombinerMenu extends AbstractContainerMenu {
protected final ContainerLevelAccess access;
protected final Player player;
protected final Container inputSlots;
private final List<Integer> inputSlotIndexes;
- protected final ResultContainer resultSlots = new ResultContainer();
- protected final ResultContainer resultSlots = new ResultContainer() {
- @Override
- public void setChanged() {
- ItemCombinerMenu.this.slotsChanged(this);
- }
- };
+ protected final ResultContainer resultSlots; // Paper - Add missing InventoryHolders; delay field init
private final int resultSlotIndex;
protected abstract boolean mayPickup(Player player, boolean present);
protected boolean mayPickup(Player player, boolean present) {
@@ -0,0 +0,0 @@ public abstract class ItemCombinerMenu extends AbstractContainerMenu {
public ItemCombinerMenu(@Nullable MenuType<?> type, int syncId, Inventory playerInventory, ContainerLevelAccess context) {
public ItemCombinerMenu(@Nullable MenuType<?> type, int syncId, Inventory playerInventory, ContainerLevelAccess context, ItemCombinerMenuSlotDefinition forgingSlotsManager) {
super(type, syncId);
this.access = context;
+ this.resultSlots = new ResultContainer(this.createBlockHolder(this.access)); // Paper - Add missing InventoryHolders; delay field init
+ // Paper start - Add missing InventoryHolders; delay field init
+ this.resultSlots = new ResultContainer(this.createBlockHolder(this.access)) {
+ @Override
+ public void setChanged() {
+ ItemCombinerMenu.this.slotsChanged(this);
+ }
+ };
+ // Paper end - Add missing InventoryHolders; delay field init
this.player = playerInventory.player;
ItemCombinerMenuSlotDefinition itemcombinermenuslotdefinition = this.createInputSlotDefinitions();
this.inputSlots = this.createContainer(forgingSlotsManager.getNumOfInputSlots());
this.resultSlotIndex = forgingSlotsManager.getResultSlotIndex();
@@ -0,0 +0,0 @@ public abstract class ItemCombinerMenu extends AbstractContainerMenu {
protected abstract ItemCombinerMenuSlotDefinition createInputSlotDefinitions();
public abstract void createResult();
private SimpleContainer createContainer(int size) {
- return new SimpleContainer(size) {
+ return new SimpleContainer(this.createBlockHolder(this.access), size) { // Paper - Add missing InventoryHolders
+ return new SimpleContainer(this.createBlockHolder(this.access), size) {
@Override
public void setChanged() {
super.setChanged();

View File

@ -53,7 +53,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
}
// Paper end

View File

@ -9,42 +9,35 @@ This can happen as a result of users moving regionfiles around,
which would cause a crash on Folia but would appear to function
fine on Paper.
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/ChunkSerializer.java
@@ -0,0 +0,0 @@ public class ChunkSerializer {
for (int k1 = 0; k1 < nbttaglist3.size(); ++k1) {
CompoundTag nbttagcompound4 = nbttaglist3.getCompound(k1);
--- a/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
@@ -0,0 +0,0 @@ public record SerializableChunkData(Registry<Biome> biomeRegistry, ChunkPos chun
while (iterator2.hasNext()) {
nbttagcompound = (CompoundTag) iterator2.next();
+ // Paper start - do not read tile entities positioned outside the chunk
+ BlockPos blockposition = BlockEntity.getPosFromTag(nbttagcompound4);
+ final BlockPos blockposition = BlockEntity.getPosFromTag(nbttagcompound);
+ if ((blockposition.getX() >> 4) != chunkPos.x || (blockposition.getZ() >> 4) != chunkPos.z) {
+ LOGGER.warn("Tile entity serialized in chunk " + chunkPos + " in world '" + world.getWorld().getName() + "' positioned at " + blockposition + " is located outside of the chunk");
+ LOGGER.warn("Tile entity serialized in chunk {} in world '{}' positioned at {} is located outside of the chunk", chunkPos, world.getWorld().getName(), blockposition);
+ continue;
+ }
+ // Paper end - do not read tile entities positioned outside the chunk
((ChunkAccess) object1).setBlockEntityNbt(nbttagcompound4);
protochunk1.setBlockEntityNbt(nbttagcompound);
}
@@ -0,0 +0,0 @@ public class ChunkSerializer {
CompoundTag nbttagcompound1 = nbttaglist1.getCompound(i);
boolean flag = nbttagcompound1.getBoolean("keepPacked");
@@ -0,0 +0,0 @@ public record SerializableChunkData(Registry<Biome> biomeRegistry, ChunkPos chun
chunk.setBlockEntityNbt(nbttagcompound);
} else {
BlockPos blockposition = BlockEntity.getPosFromTag(nbttagcompound);
+ // Paper start - do not read tile entities positioned outside the chunk
+ BlockPos blockposition = BlockEntity.getPosFromTag(nbttagcompound1); // moved up
+ ChunkPos chunkPos = chunk.getPos();
+ if ((blockposition.getX() >> 4) != chunkPos.x || (blockposition.getZ() >> 4) != chunkPos.z) {
+ LOGGER.warn("Tile entity serialized in chunk " + chunkPos + " in world '" + world.getWorld().getName() + "' positioned at " + blockposition + " is located outside of the chunk");
+ continue;
+ }
+ // Paper end - do not read tile entities positioned outside the chunk
+
if (flag) {
chunk.setBlockEntityNbt(nbttagcompound1);
} else {
- BlockPos blockposition = BlockEntity.getPosFromTag(nbttagcompound1);
+ // Paper - do not read tile entities positioned outside the chunk; move up
BlockEntity tileentity = BlockEntity.loadStatic(blockposition, chunk.getBlockState(blockposition), nbttagcompound1, world.registryAccess());
BlockEntity tileentity = BlockEntity.loadStatic(blockposition, chunk.getBlockState(blockposition), nbttagcompound, world.registryAccess());
if (tileentity != null) {

View File

@ -22,7 +22,7 @@ diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/mai
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
// CraftBukkit start
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
@ -54,14 +54,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
}
public static Optional<Entity> create(CompoundTag nbt, Level world) {
public static Optional<Entity> create(CompoundTag nbt, Level world, EntitySpawnReason reason) {
+ // Paper start - Don't fire sync event during generation
+ return create(nbt, world, false);
+ }
+ public static Optional<Entity> create(CompoundTag nbt, Level world, boolean generation) {
+ public static Optional<Entity> create(CompoundTag nbt, Level world, EntitySpawnReason reason, boolean generation) {
+ // Paper end - Don't fire sync event during generation
return Util.ifElse(EntityType.by(nbt).map((entitytypes) -> {
return entitytypes.create(world);
return entitytypes.create(world, reason);
}), (entity) -> {
+ if (generation) entity.generation = true; // Paper - Don't fire sync event during generation
entity.load(nbt);
@ -127,8 +127,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
private static Optional<Entity> createEntityIgnoreException(ServerLevelAccessor world, CompoundTag nbt) {
// CraftBukkit start
// try {
- return EntityType.create(nbt, world.getLevel());
+ return EntityType.create(nbt, world.getLevel(), true); // Paper - Don't fire sync event during generation
- return EntityType.create(nbt, world.getLevel(), EntitySpawnReason.STRUCTURE);
+ return EntityType.create(nbt, world.getLevel(), EntitySpawnReason.STRUCTURE, true); // Paper - Don't fire sync event during generation
// } catch (Exception exception) {
// return Optional.empty();
// }
@ -140,26 +140,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return this.handle.getLevel();
}
- @Override
- public void addFreshEntityWithPassengers(Entity arg0, CreatureSpawnEvent.SpawnReason arg1) {
- this.handle.addFreshEntityWithPassengers(arg0, arg1);
- }
-
- @Override
- public void addFreshEntityWithPassengers(Entity entity) {
- this.handle.addFreshEntityWithPassengers(entity);
- }
-
- @Override
- public void addFreshEntityWithPassengers(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
- this.handle.addFreshEntityWithPassengers(entity, reason);
- }
+ // Paper start - Don't fire sync event during generation; don't override these methods so all entities are run through addFreshEntity
+ // @Override
+ // public void addFreshEntityWithPassengers(Entity arg0, CreatureSpawnEvent.SpawnReason arg1) {
+ // this.handle.addFreshEntityWithPassengers(arg0, arg1);
+ // }
+ //
+ // @Override
+ // public void addFreshEntityWithPassengers(Entity entity) {
+ // this.handle.addFreshEntityWithPassengers(entity);
+ // }
+ // Paper end - Don't fire sync event during generation; don't override these methods
+ //
+ // @Override
+ // public void addFreshEntityWithPassengers(Entity entity, CreatureSpawnEvent.SpawnReason reason) {
+ // this.handle.addFreshEntityWithPassengers(entity, reason);
+ // }
+ // Paper end - Don't fire sync event during generation; don't override these methods so all entities are run through addFreshEntity
@Override
public ServerLevel getMinecraftWorld() {

View File

@ -137,7 +137,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- ((ServerPlayer) user).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
+ // ((ServerPlayer) user).connection.send(new ClientboundBlockUpdatePacket(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager) // Paper - Don't resend blocks
((ServerPlayer) user).getBukkitEntity().updateInventory(); // SPIGOT-4541
return InteractionResultHolder.fail(itemstack);
return InteractionResult.FAIL;
}
@@ -0,0 +0,0 @@ public class BucketItem extends Item implements DispensibleContainerItem {
if (flag2 && entityhuman != null) {

View File

@ -142,7 +142,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
Bukkit.getPluginManager().callEvent(new PlayerRecipeBookSettingsChangeEvent(player.getBukkitEntity(), bukkitType, open, filter));
}

View File

@ -8,7 +8,7 @@ diff --git a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.ja
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
+++ b/src/main/java/net/minecraft/world/entity/projectile/ThrownPotion.java
@@ -0,0 +0,0 @@ public class ThrownPotion extends ThrowableItemProjectile implements ItemSupplie
@@ -0,0 +0,0 @@ public class ThrownPotion extends ThrowableItemProjectile {
boolean noEffects = potioncontents.hasEffects(); // Paper - Fix potions splash events
// CraftBukkit start
org.bukkit.event.entity.LingeringPotionSplashEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callLingeringPotionSplashEvent(this, position, entityareaeffectcloud);

View File

@ -52,7 +52,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
return event;
}

View File

@ -14,7 +14,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
--- a/src/main/java/net/minecraft/server/commands/TeleportCommand.java
+++ b/src/main/java/net/minecraft/server/commands/TeleportCommand.java
@@ -0,0 +0,0 @@ public class TeleportCommand {
Location to = new Location(world.getWorld(), x, y, z, f2, f3);
Location to = new Location(world.getWorld(), d3, d4, d5, f4, f5);
EntityTeleportEvent event = new EntityTeleportEvent(target.getBukkitEntity(), target.getBukkitEntity().getLocation(), to);
world.getCraftServer().getPluginManager().callEvent(event);
- if (event.isCancelled()) {
@ -23,8 +23,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
+ to = event.getTo(); // Paper - actually track new location
x = to.getX();
y = to.getY();
d3 = to.getX();
d4 = to.getY();
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java

View File

@ -11,7 +11,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues {
ResourceLocation minecraftkey = CraftNamespacedKey.toMinecraft(key);
JsonElement jsonelement = ServerAdvancementManager.GSON.fromJson(advancement, JsonElement.class);
JsonElement jsonelement = JsonParser.parseString(advancement);
- net.minecraft.advancements.Advancement nms = net.minecraft.advancements.Advancement.CODEC.parse(JsonOps.INSTANCE, jsonelement).getOrThrow(JsonParseException::new);
+ final net.minecraft.resources.RegistryOps<JsonElement> ops = CraftRegistry.getMinecraftRegistry().createSerializationContext(JsonOps.INSTANCE); // Paper - use RegistryOps
+ final net.minecraft.advancements.Advancement nms = net.minecraft.advancements.Advancement.CODEC.parse(ops, jsonelement).getOrThrow(JsonParseException::new); // Paper - use RegistryOps

View File

@ -10,7 +10,7 @@ diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/mai
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -0,0 +0,0 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@Nullable
@Override
public MapItemSavedData getMapData(MapId id) {

View File

@ -199,7 +199,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -0,0 +0,0 @@ populateFields(victim, event); // Paper - make cancellable
@@ -0,0 +0,0 @@ public class CraftEventFactory {
return event;
}

View File

@ -22,9 +22,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
this.usePlayerItem(player, hand, itemstack);
- this.setInLove(player);
+ this.setInLove(player, breedCopy); // Paper - Fix EntityBreedEvent copying
return InteractionResult.SUCCESS;
this.playEatingSound();
return InteractionResult.SUCCESS_SERVER;
}
@@ -0,0 +0,0 @@ public abstract class Animal extends AgeableMob {
return this.inLove <= 0;
}
@ -66,28 +66,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- this.setInLove(player);
+ this.setInLove(player, breedCopy); // Paper - Fix EntityBreedEvent copying
} else {
if (this.level().isClientSide || this.isSitting() || this.isInWater()) {
return InteractionResult.PASS;
diff --git a/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java b/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java
+++ b/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java
@@ -0,0 +0,0 @@ public class Armadillo extends Animal {
}
@Override
- public void setInLove(@Nullable Player player) {
- super.setInLove(player);
+ public void setInLove(@Nullable Player player, @Nullable ItemStack breedItemCopy) { // Paper
+ super.setInLove(player, breedItemCopy); // Paper
this.makeSound(SoundEvents.ARMADILLO_EAT);
}
Level world = this.level();
diff --git a/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java b/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
+++ b/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
@@ -0,0 +0,0 @@ public class Camel extends AbstractHorse implements PlayerRideableJumping, Saddl
@@ -0,0 +0,0 @@ public class Camel extends AbstractHorse {
boolean flag1 = this.isTamed() && this.getAge() == 0 && this.canFallInLove();
if (flag1) {

View File

@ -39,18 +39,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
private void spawnFire(int spreadAttempts) {
- if (!this.visualOnly && !this.level().isClientSide && this.level().getGameRules().getBoolean(GameRules.RULE_DOFIRETICK)) {
+ if (!this.visualOnly && !this.isEffect && !this.level().isClientSide && this.level().getGameRules().getBoolean(GameRules.RULE_DOFIRETICK)) { // Paper - Properly handle lightning effects api
BlockPos blockposition = this.blockPosition();
BlockState iblockdata = BaseFireBlock.getState(this.level(), blockposition);
- if (!this.visualOnly) {
+ if (!this.visualOnly && !this.isEffect) { // Paper - Properly handle lightning effects api
Level world = this.level();
if (world instanceof ServerLevel) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -0,0 +0,0 @@ public class CraftWorld extends CraftRegionAccessor implements World {
LightningBolt lightning = EntityType.LIGHTNING_BOLT.create(this.world);
LightningBolt lightning = EntityType.LIGHTNING_BOLT.create(this.world, EntitySpawnReason.COMMAND);
lightning.moveTo(loc.getX(), loc.getY(), loc.getZ());
- lightning.setVisualOnly(isVisual);
+ lightning.isEffect = isVisual; // Paper - Properly handle lightning effects api

View File

@ -463,7 +463,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage);
event.setKeepInventory(keepInventory);
event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel
+populateFields(victim, event); // Paper - make cancellable
+ populateFields(victim, event); // Paper - make cancellable
Bukkit.getServer().getPluginManager().callEvent(event);
+ // Paper start - make cancellable
+ if (event.isCancelled()) {

View File

@ -18,7 +18,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
- java.util.List<org.bukkit.inventory.ItemStack> loot = new java.util.ArrayList<>(this.getInventory().getContainerSize());
+ List<DefaultDrop> loot = new java.util.ArrayList<>(this.getInventory().getContainerSize()); // Paper - Restore vanilla drops behavior
boolean keepInventory = this.level().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
boolean keepInventory = this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || this.isSpectator();
if (!keepInventory) {
for (ItemStack item : this.getInventory().getContents()) {
@ -30,7 +30,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
}
if (this.shouldDropLoot() && this.level().getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { // Paper - fix player loottables running when mob loot gamerule is false
// SPIGOT-5071: manually add player loot tables (SPIGOT-5195 - ignores keepInventory rule)
this.dropFromLootTable(damageSource, this.lastHurtByPlayerTime > 0);
this.dropFromLootTable(this.serverLevel(), damageSource, this.lastHurtByPlayerTime > 0);
- this.dropCustomDeathLoot(this.serverLevel(), damageSource, flag);
+ // Paper - Restore vanilla drops behaviour; custom death loot is a noop on server player, remove.
@ -43,9 +43,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@Nullable
public ItemEntity spawnAtLocation(ItemStack stack, float yOffset) {
public ItemEntity spawnAtLocation(ServerLevel world, ItemStack stack, float yOffset) {
+ // Paper start - Restore vanilla drops behavior
+ return this.spawnAtLocation(stack, yOffset, null);
+ return this.spawnAtLocation(world, stack, yOffset, null);
+ }
+ public record DefaultDrop(Item item, org.bukkit.inventory.ItemStack stack, @Nullable java.util.function.Consumer<ItemStack> dropConsumer) {
+ public DefaultDrop(final ItemStack stack, final java.util.function.Consumer<ItemStack> dropConsumer) {
@ -61,12 +61,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ }
+ @Nullable
+ public ItemEntity spawnAtLocation(ItemStack stack, float yOffset, @Nullable java.util.function.Consumer<? super ItemEntity> delayedAddConsumer) {
+ public ItemEntity spawnAtLocation(ServerLevel world, ItemStack stack, float yOffset, @Nullable java.util.function.Consumer<? super ItemEntity> delayedAddConsumer) {
+ // Paper end - Restore vanilla drops behavior
if (stack.isEmpty()) {
return null;
} else if (this.level().isClientSide) {
@@ -0,0 +0,0 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
} else {
// CraftBukkit start - Capture drops for death event
if (this instanceof net.minecraft.world.entity.LivingEntity && !((net.minecraft.world.entity.LivingEntity) this).forceDrops) {
@ -82,7 +80,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
return null;
}
// CraftBukkit end
ItemEntity entityitem = new ItemEntity(this.level(), this.getX(), this.getY() + (double) yOffset, this.getZ(), stack.copy()); // Paper - copy so we can destroy original
ItemEntity entityitem = new ItemEntity(world, this.getX(), this.getY() + (double) yOffset, this.getZ(), stack);
stack.setCount(0); // Paper - destroy this item - if this ever leaks due to game bugs, ensure it doesn't dupe
- entityitem.setDefaultPickUpDelay();
@ -107,13 +105,13 @@ diff --git a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.jav
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
+++ b/src/main/java/net/minecraft/world/entity/boss/wither/WitherBoss.java
@@ -0,0 +0,0 @@ public class WitherBoss extends Monster implements PowerableMob, RangedAttackMob
@@ -0,0 +0,0 @@ public class WitherBoss extends Monster implements RangedAttackMob {
@Override
protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {
super.dropCustomDeathLoot(world, source, causedByPlayer);
- ItemEntity entityitem = this.spawnAtLocation((ItemLike) Items.NETHER_STAR);
-
+ ItemEntity entityitem = this.spawnAtLocation(new net.minecraft.world.item.ItemStack(Items.NETHER_STAR), 0, ItemEntity::setExtendedLifetime); // Paper - Restore vanilla drops behavior; spawnAtLocation returns null so modify the item entity with a consumer
- ItemEntity entityitem = this.spawnAtLocation(world, (ItemLike) Items.NETHER_STAR);
+ ItemEntity entityitem = this.spawnAtLocation(world, new net.minecraft.world.item.ItemStack(Items.NETHER_STAR), 0, ItemEntity::setExtendedLifetime); // Paper - Restore vanilla drops behavior; spawnAtLocation returns null so modify the item entity with a consumer
if (entityitem != null) {
- entityitem.setExtendedLifetime();
+ entityitem.setExtendedLifetime(); // Paper - diff on change
@ -175,15 +173,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return new Entity.DefaultDrop(CraftItemType.bukkitToMinecraft(stack.getType()), stack, null);
+ };
+
+ public static EntityDeathEvent callEntityDeathEvent(net.minecraft.world.entity.LivingEntity victim, DamageSource damageSource, List<Entity.DefaultDrop> drops, Runnable lootCheck) { // Paper
+ public static EntityDeathEvent callEntityDeathEvent(net.minecraft.world.entity.LivingEntity victim, DamageSource damageSource, List<Entity.DefaultDrop> drops, Runnable lootCheck) { // Paper - Restore vanilla drops behavior
// Paper end
CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
- EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity()));
+ EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, new io.papermc.paper.util.TransformingRandomAccessList<>(drops, Entity.DefaultDrop::stack, FROM_FUNCTION), victim.getExpReward(damageSource.getEntity())); // Paper - Restore vanilla drops behavior
populateFields(victim, event); // Paper - make cancellable
CraftWorld world = (CraftWorld) entity.getWorld();
- EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(world.getHandle(), damageSource.getEntity()));
+ EntityDeathEvent event = new EntityDeathEvent(entity, bukkitDamageSource, new io.papermc.paper.util.TransformingRandomAccessList<>(drops, Entity.DefaultDrop::stack, FROM_FUNCTION), victim.getExpReward(world.getHandle(), damageSource.getEntity())); // Paper - Restore vanilla drops behavior, victim.getExpReward(world.getHandle(), damageSource.getEntity()));
populateFields(victim, event); // Paper - make cancellable
Bukkit.getServer().getPluginManager().callEvent(event);
@@ -0,0 +0,0 @@ public class CraftEventFactory {
victim.expToDrop = event.getDroppedExp();
lootCheck.run(); // Paper - advancement triggers before destroying items
@ -208,8 +207,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public static PlayerDeathEvent callPlayerDeathEvent(ServerPlayer victim, DamageSource damageSource, List<Entity.DefaultDrop> drops, net.kyori.adventure.text.Component deathMessage, boolean keepInventory) { // Paper - Adventure & Restore vanilla drops behavior
CraftPlayer entity = victim.getBukkitEntity();
CraftDamageSource bukkitDamageSource = new CraftDamageSource(damageSource);
- PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(damageSource.getEntity()), 0, deathMessage);
+ PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, new io.papermc.paper.util.TransformingRandomAccessList<>(drops, Entity.DefaultDrop::stack, FROM_FUNCTION), victim.getExpReward(damageSource.getEntity()), 0, deathMessage); // Paper - Restore vanilla drops behavior
- PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, drops, victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage);
+ PlayerDeathEvent event = new PlayerDeathEvent(entity, bukkitDamageSource, new io.papermc.paper.util.TransformingRandomAccessList<>(drops, Entity.DefaultDrop::stack, FROM_FUNCTION), victim.getExpReward(victim.serverLevel(), damageSource.getEntity()), 0, deathMessage); // Paper - Restore vanilla drops behavior
event.setKeepInventory(keepInventory);
event.setKeepLevel(victim.keepLevel); // SPIGOT-2222: pre-set keepLevel
populateFields(victim, event); // Paper - make cancellable
@ -229,7 +228,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- victim.drop(CraftItemStack.asNMSCopy(stack), true, false, false); // SPIGOT-7800, SPIGOT-7801: Vanilla Behaviour for Player Inventory dropped items
- } else {
- victim.forceDrops = true;
- victim.spawnAtLocation(CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items
- victim.spawnAtLocation(victim.serverLevel(), CraftItemStack.asNMSCopy(stack)); // SPIGOT-7806: Vanilla Behaviour for items not related to Player Inventory dropped items
- victim.forceDrops = false;
- }
+ drop.runConsumer(s -> victim.drop(CraftItemStack.unwrap(s), true, false, false)); // Paper - Restore vanilla drops behavior