From d0bce54059a4ed7821c502e63810b47ec5f444f5 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Sat, 26 Aug 2023 22:12:46 +0200 Subject: [PATCH] Add sniffer egg api (#9288) --- .../server/Add-EntityFertilizeEggEvent.patch | 4 +- .../server/Add-missing-BlockFadeEvents.patch | 31 +++++++++++++++ ...us-missing-EntityDropItemEvent-calls.patch | 15 +++++++ ...ll-BlockGrowEvent-for-missing-blocks.patch | 39 +++++++++++++++++++ ...-BlockGrowEvent-for-the-pitcher-crop.patch | 19 --------- .../Configure-sniffer-egg-hatch-time.patch | 28 +++++++++++++ ...and-additions-to-the-SpawnReason-API.patch | 13 +++++++ patches/server/Paper-config-files.patch | 7 ++++ 8 files changed, 135 insertions(+), 21 deletions(-) create mode 100644 patches/server/Call-BlockGrowEvent-for-missing-blocks.patch delete mode 100644 patches/server/Call-BlockGrowEvent-for-the-pitcher-crop.patch create mode 100644 patches/server/Configure-sniffer-egg-hatch-time.patch diff --git a/patches/server/Add-EntityFertilizeEggEvent.patch b/patches/server/Add-EntityFertilizeEggEvent.patch index d3a14192ba..a37fa048cf 100644 --- a/patches/server/Add-EntityFertilizeEggEvent.patch +++ b/patches/server/Add-EntityFertilizeEggEvent.patch @@ -65,9 +65,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 entityitem.setDefaultPickUpDelay(); - this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null); + this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null, result.getExperience()); // Paper - Add EntityFertilizeEggEvent event + if (this.spawnAtLocation(entityitem) != null) { // Paper - call EntityDropItemEvent this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F); - world.addFreshEntity(entityitem); - } + } // Paper 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 diff --git a/patches/server/Add-missing-BlockFadeEvents.patch b/patches/server/Add-missing-BlockFadeEvents.patch index 992632f683..4bbc246c55 100644 --- a/patches/server/Add-missing-BlockFadeEvents.patch +++ b/patches/server/Add-missing-BlockFadeEvents.patch @@ -20,3 +20,34 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 this.destroyBlock(world, pos); world.playSound((Player)null, pos, SoundEvents.FROGSPAWN_HATCH, SoundSource.BLOCKS, 1.0F, 1.0F); this.spawnTadpoles(world, pos, random); +diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +@@ -0,0 +0,0 @@ public class SnifferEggBlock extends Block { + return this.getHatchLevel(state) == 2; + } + ++ // Paper start ++ private void rescheduleTick(ServerLevel world, BlockPos pos) { ++ int baseDelay = hatchBoost(world, pos) ? BOOSTED_HATCH_TIME_TICKS : REGULAR_HATCH_TIME_TICKS; ++ world.scheduleTick(pos, this, (baseDelay / 3) + world.random.nextInt(RANDOM_HATCH_OFFSET_TICKS)); ++ // reschedule to avoid being stuck here and behave like the other calls (see #onPlace) ++ } ++ // Paper end ++ + @Override + public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { + if (!this.isReadyToHatch(state)) { + world.playSound((Player)null, pos, SoundEvents.SNIFFER_EGG_CRACK, SoundSource.BLOCKS, 0.7F, 0.9F + random.nextFloat() * 0.2F); + world.setBlock(pos, state.setValue(HATCH, Integer.valueOf(this.getHatchLevel(state) + 1)), 2); + } else { ++ // Paper start - Call BlockFadeEvent ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(world, pos, state.getFluidState().createLegacyBlock()).isCancelled()) { ++ rescheduleTick(world, pos); ++ return; ++ } ++ // Paper end + world.playSound((Player)null, pos, SoundEvents.SNIFFER_EGG_HATCH, SoundSource.BLOCKS, 0.7F, 0.9F + random.nextFloat() * 0.2F); + world.destroyBlock(pos, false); + Sniffer sniffer = EntityType.SNIFFER.create(world); diff --git a/patches/server/Add-various-missing-EntityDropItemEvent-calls.patch b/patches/server/Add-various-missing-EntityDropItemEvent-calls.patch index 9810525728..f7cf0ad3a0 100644 --- a/patches/server/Add-various-missing-EntityDropItemEvent-calls.patch +++ b/patches/server/Add-various-missing-EntityDropItemEvent-calls.patch @@ -71,3 +71,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } } +diff --git a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java ++++ b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java +@@ -0,0 +0,0 @@ public class Sniffer extends Animal { + + entityitem.setDefaultPickUpDelay(); + this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null); ++ if (this.spawnAtLocation(entityitem) != null) { // Paper - call EntityDropItemEvent + this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F); +- world.addFreshEntity(entityitem); ++ } // Paper + } + + @Override diff --git a/patches/server/Call-BlockGrowEvent-for-missing-blocks.patch b/patches/server/Call-BlockGrowEvent-for-missing-blocks.patch new file mode 100644 index 0000000000..12c758f41d --- /dev/null +++ b/patches/server/Call-BlockGrowEvent-for-missing-blocks.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> +Date: Fri, 9 Jun 2023 13:04:42 +0200 +Subject: [PATCH] Call BlockGrowEvent for missing blocks + +Call the event for pitcher crops and sniffer egg + +diff --git a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java +@@ -0,0 +0,0 @@ public class PitcherCropBlock extends DoublePlantBlock implements BonemealableBl + private void grow(ServerLevel world, BlockState state, BlockPos pos, int amount) { + int i = Math.min(state.getValue(AGE) + amount, 4); + if (this.canGrow(world, pos, state, i)) { +- world.setBlock(pos, state.setValue(AGE, Integer.valueOf(i)), 2); ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, pos, state.setValue(AGE, Integer.valueOf(i)), 2)) return; // Paper + if (i >= 3) { + BlockPos blockPos = pos.above(); + world.setBlock(blockPos, copyWaterloggedFrom(world, pos, this.defaultBlockState().setValue(AGE, Integer.valueOf(i)).setValue(HALF, DoubleBlockHalf.UPPER)), 3); +diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +@@ -0,0 +0,0 @@ public class SnifferEggBlock extends Block { + @Override + public void tick(BlockState state, ServerLevel world, BlockPos pos, RandomSource random) { + if (!this.isReadyToHatch(state)) { ++ // Paper start ++ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, pos, state.setValue(HATCH, Integer.valueOf(this.getHatchLevel(state) + 1)), 2)) { ++ rescheduleTick(world, pos); ++ return; ++ } ++ // Paper end + world.playSound((Player)null, pos, SoundEvents.SNIFFER_EGG_CRACK, SoundSource.BLOCKS, 0.7F, 0.9F + random.nextFloat() * 0.2F); +- world.setBlock(pos, state.setValue(HATCH, Integer.valueOf(this.getHatchLevel(state) + 1)), 2); + } else { + // Paper start - Call BlockFadeEvent + if (org.bukkit.craftbukkit.event.CraftEventFactory.callBlockFadeEvent(world, pos, state.getFluidState().createLegacyBlock()).isCancelled()) { diff --git a/patches/server/Call-BlockGrowEvent-for-the-pitcher-crop.patch b/patches/server/Call-BlockGrowEvent-for-the-pitcher-crop.patch deleted file mode 100644 index 2c92410664..0000000000 --- a/patches/server/Call-BlockGrowEvent-for-the-pitcher-crop.patch +++ /dev/null @@ -1,19 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> -Date: Fri, 9 Jun 2023 13:04:42 +0200 -Subject: [PATCH] Call BlockGrowEvent for the pitcher crop - - -diff --git a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java -+++ b/src/main/java/net/minecraft/world/level/block/PitcherCropBlock.java -@@ -0,0 +0,0 @@ public class PitcherCropBlock extends DoublePlantBlock implements BonemealableBl - private void grow(ServerLevel world, BlockState state, BlockPos pos, int amount) { - int i = Math.min(state.getValue(AGE) + amount, 4); - if (this.canGrow(world, pos, state, i)) { -- world.setBlock(pos, state.setValue(AGE, Integer.valueOf(i)), 2); -+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.handleBlockGrowEvent(world, pos, state.setValue(AGE, Integer.valueOf(i)), 2)) return; // Paper - if (i >= 3) { - BlockPos blockPos = pos.above(); - world.setBlock(blockPos, copyWaterloggedFrom(world, pos, this.defaultBlockState().setValue(AGE, Integer.valueOf(i)).setValue(HALF, DoubleBlockHalf.UPPER)), 3); diff --git a/patches/server/Configure-sniffer-egg-hatch-time.patch b/patches/server/Configure-sniffer-egg-hatch-time.patch new file mode 100644 index 0000000000..1a4cc7aa8e --- /dev/null +++ b/patches/server/Configure-sniffer-egg-hatch-time.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> +Date: Tue, 27 Jun 2023 13:26:06 +0200 +Subject: [PATCH] Configure sniffer egg hatch time + + +diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +@@ -0,0 +0,0 @@ public class SnifferEggBlock extends Block { + + // Paper start + private void rescheduleTick(ServerLevel world, BlockPos pos) { +- int baseDelay = hatchBoost(world, pos) ? BOOSTED_HATCH_TIME_TICKS : REGULAR_HATCH_TIME_TICKS; ++ int baseDelay = hatchBoost(world, pos) ? world.paperConfig().entities.sniffer.boostedHatchTime.or(BOOSTED_HATCH_TIME_TICKS) : world.paperConfig().entities.sniffer.hatchTime.or(REGULAR_HATCH_TIME_TICKS); + world.scheduleTick(pos, this, (baseDelay / 3) + world.random.nextInt(RANDOM_HATCH_OFFSET_TICKS)); + // reschedule to avoid being stuck here and behave like the other calls (see #onPlace) + } +@@ -0,0 +0,0 @@ public class SnifferEggBlock extends Block { + world.levelEvent(3009, pos, 0); + } + +- int i = bl ? 12000 : 24000; ++ int i = bl ? world.paperConfig().entities.sniffer.boostedHatchTime.or(BOOSTED_HATCH_TIME_TICKS) : world.paperConfig().entities.sniffer.hatchTime.or(REGULAR_HATCH_TIME_TICKS); // Paper + int j = i / 3; + world.gameEvent(GameEvent.BLOCK_PLACE, pos, GameEvent.Context.of(state)); + world.scheduleTick(pos, this, j + world.random.nextInt(300)); diff --git a/patches/server/Fixes-and-additions-to-the-SpawnReason-API.patch b/patches/server/Fixes-and-additions-to-the-SpawnReason-API.patch index 397ac1ffd7..563f963f29 100644 --- a/patches/server/Fixes-and-additions-to-the-SpawnReason-API.patch +++ b/patches/server/Fixes-and-additions-to-the-SpawnReason-API.patch @@ -69,3 +69,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } } +diff --git a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java ++++ b/src/main/java/net/minecraft/world/level/block/SnifferEggBlock.java +@@ -0,0 +0,0 @@ public class SnifferEggBlock extends Block { + Vec3 vec3 = pos.getCenter(); + sniffer.setBaby(true); + sniffer.moveTo(vec3.x(), vec3.y(), vec3.z(), Mth.wrapDegrees(world.random.nextFloat() * 360.0F), 0.0F); +- world.addFreshEntity(sniffer); ++ world.addFreshEntity(sniffer, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // Paper + } + + } diff --git a/patches/server/Paper-config-files.patch b/patches/server/Paper-config-files.patch index 0a5ebf81b6..fc61cd0d03 100644 --- a/patches/server/Paper-config-files.patch +++ b/patches/server/Paper-config-files.patch @@ -1616,6 +1616,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public boolean tick = true; + } + ++ public Sniffer sniffer; ++ ++ public class Sniffer extends ConfigurationPart { ++ public IntOr.Default hatchTime = IntOr.Default.USE_DEFAULT; ++ public IntOr.Default boostedHatchTime = IntOr.Default.USE_DEFAULT; ++ } ++ + public Spawning spawning; + + public class Spawning extends ConfigurationPart {