From 4e2ef1947439366f1ef6c39f54c2f179c21fd7a9 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 6 Sep 2023 20:44:19 +1000 Subject: [PATCH] #1242: Add more Sculk API (bloom, shriek, bloom event) By: Collin --- .../world/level/block/SculkSpreader.patch | 69 +++++++++++++++++++ .../entity/SculkCatalystBlockEntity.patch | 23 ++++++- .../craftbukkit/block/CraftSculkCatalyst.java | 14 ++++ .../craftbukkit/block/CraftSculkShrieker.java | 11 +++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch b/paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch new file mode 100644 index 0000000000..80c47c7971 --- /dev/null +++ b/paper-server/nms-patches/net/minecraft/world/level/block/SculkSpreader.patch @@ -0,0 +1,69 @@ +--- a/net/minecraft/world/level/block/SculkSpreader.java ++++ b/net/minecraft/world/level/block/SculkSpreader.java +@@ -41,6 +41,14 @@ + import net.minecraft.world.level.block.state.IBlockData; + import org.slf4j.Logger; + ++// CraftBukkit start ++import net.minecraft.nbt.NBTBase; ++import net.minecraft.world.level.World; ++import org.bukkit.Bukkit; ++import org.bukkit.craftbukkit.block.CraftBlock; ++import org.bukkit.event.block.SculkBloomEvent; ++// CraftBukkit end ++ + public class SculkSpreader { + + public static final int MAX_GROWTH_RATE_RADIUS = 24; +@@ -56,6 +64,7 @@ + private final int additionalDecayRate; + private List cursors = new ArrayList(); + private static final Logger LOGGER = LogUtils.getLogger(); ++ World level; // CraftBukkit + + public SculkSpreader(boolean flag, TagKey tagkey, int i, int j, int k, int l) { + this.isWorldGeneration = flag; +@@ -110,7 +119,7 @@ + public void load(NBTTagCompound nbttagcompound) { + if (nbttagcompound.contains("cursors", 9)) { + this.cursors.clear(); +- DataResult dataresult = SculkSpreader.a.CODEC.listOf().parse(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.getList("cursors", 10))); ++ DataResult> dataresult = SculkSpreader.a.CODEC.listOf().parse(new Dynamic<>(DynamicOpsNBT.INSTANCE, nbttagcompound.getList("cursors", 10))); // CraftBukkit - decompile error + Logger logger = SculkSpreader.LOGGER; + + Objects.requireNonNull(logger); +@@ -125,7 +134,7 @@ + } + + public void save(NBTTagCompound nbttagcompound) { +- DataResult dataresult = SculkSpreader.a.CODEC.listOf().encodeStart(DynamicOpsNBT.INSTANCE, this.cursors); ++ DataResult dataresult = SculkSpreader.a.CODEC.listOf().encodeStart(DynamicOpsNBT.INSTANCE, this.cursors); // CraftBukkit - decompile error + Logger logger = SculkSpreader.LOGGER; + + Objects.requireNonNull(logger); +@@ -146,6 +155,16 @@ + + private void addCursor(SculkSpreader.a sculkspreader_a) { + if (this.cursors.size() < 32) { ++ // CraftBukkit start ++ CraftBlock bukkitBlock = CraftBlock.at(level, sculkspreader_a.pos); ++ SculkBloomEvent event = new SculkBloomEvent(bukkitBlock, sculkspreader_a.getCharge()); ++ Bukkit.getPluginManager().callEvent(event); ++ if (event.isCancelled()) ++ return; ++ ++ sculkspreader_a.charge = event.getCharge(); ++ // CraftBukkit end ++ + this.cursors.add(sculkspreader_a); + } + } +@@ -241,7 +260,7 @@ + this.charge = i; + this.decayDelay = j; + this.updateDelay = k; +- this.facings = (Set) optional.orElse((Object) null); ++ this.facings = (Set) optional.orElse(null); // CraftBukkit - decompile error + } + + public a(BlockPosition blockposition, int i) { diff --git a/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch b/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch index 24b71f33ad..398b38b68e 100644 --- a/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch +++ b/paper-server/nms-patches/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.patch @@ -1,6 +1,10 @@ --- a/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java +++ b/net/minecraft/world/level/block/entity/SculkCatalystBlockEntity.java -@@ -35,11 +35,14 @@ +@@ -32,14 +32,18 @@ + public SculkCatalystBlockEntity(BlockPosition blockposition, IBlockData iblockdata) { + super(TileEntityTypes.SCULK_CATALYST, blockposition, iblockdata); + this.catalystListener = new SculkCatalystBlockEntity.a(iblockdata, new BlockPositionSource(blockposition)); ++ catalystListener.level = level; // CraftBukkit } public static void serverTick(World world, BlockPosition blockposition, IBlockData iblockdata, SculkCatalystBlockEntity sculkcatalystblockentity) { @@ -15,3 +19,20 @@ this.catalystListener.sculkSpreader.load(nbttagcompound); } +@@ -60,6 +64,7 @@ + final SculkSpreader sculkSpreader; + private final IBlockData blockState; + private final PositionSource positionSource; ++ private World level; // CraftBukkit + + public a(IBlockData iblockdata, PositionSource positionsource) { + this.blockState = iblockdata; +@@ -116,7 +121,7 @@ + return this.sculkSpreader; + } + +- private void bloom(WorldServer worldserver, BlockPosition blockposition, IBlockData iblockdata, RandomSource randomsource) { ++ public void bloom(WorldServer worldserver, BlockPosition blockposition, IBlockData iblockdata, RandomSource randomsource) { + worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(SculkCatalystBlock.PULSE, true), 3); + worldserver.scheduleTick(blockposition, iblockdata.getBlock(), 8); + worldserver.sendParticles(Particles.SCULK_SOUL, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 1.15D, (double) blockposition.getZ() + 0.5D, 2, 0.2D, 0.0D, 0.2D, 0.0D); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkCatalyst.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkCatalyst.java index dc7d6c443a..e81cd23e38 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkCatalyst.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkCatalyst.java @@ -1,7 +1,10 @@ package org.bukkit.craftbukkit.block; +import com.google.common.base.Preconditions; +import net.minecraft.core.BlockPosition; import net.minecraft.world.level.block.entity.SculkCatalystBlockEntity; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.block.SculkCatalyst; public class CraftSculkCatalyst extends CraftBlockEntityState implements SculkCatalyst { @@ -9,4 +12,15 @@ public class CraftSculkCatalyst extends CraftBlockEntityState 0, "charge must be positive"); + requirePlaced(); + + // bloom() is for visual blooming effect, cursors are what changes the blocks. + getTileEntity().getListener().bloom(world.getHandle(), getPosition(), getHandle(), world.getHandle().getRandom()); + getTileEntity().getListener().getSculkSpreader().addCursors(new BlockPosition(block.getX(), block.getY(), block.getZ()), charge); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkShrieker.java b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkShrieker.java index 2e7e117f6e..d9e43669ce 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkShrieker.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/block/CraftSculkShrieker.java @@ -1,8 +1,11 @@ package org.bukkit.craftbukkit.block; +import net.minecraft.server.level.EntityPlayer; import net.minecraft.world.level.block.entity.SculkShriekerBlockEntity; import org.bukkit.World; import org.bukkit.block.SculkShrieker; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.Player; public class CraftSculkShrieker extends CraftBlockEntityState implements SculkShrieker { @@ -19,4 +22,12 @@ public class CraftSculkShrieker extends CraftBlockEntityState