mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-05 02:22:12 +01:00
#1242: Add more Sculk API (bloom, shriek, bloom event)
By: Collin <collinjbarber@gmail.com>
This commit is contained in:
parent
832e3ca9bf
commit
4e2ef19474
4 changed files with 116 additions and 1 deletions
|
@ -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<SculkSpreader.a> cursors = new ArrayList();
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
+ World level; // CraftBukkit
|
||||
|
||||
public SculkSpreader(boolean flag, TagKey<Block> 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<List<SculkSpreader.a>> 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<NBTBase> 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) {
|
|
@ -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);
|
||||
|
|
|
@ -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<SculkCatalystBlockEntity> implements SculkCatalyst {
|
||||
|
@ -9,4 +12,15 @@ public class CraftSculkCatalyst extends CraftBlockEntityState<SculkCatalystBlock
|
|||
public CraftSculkCatalyst(World world, SculkCatalystBlockEntity tileEntity) {
|
||||
super(world, tileEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bloom(Block block, int charge) {
|
||||
Preconditions.checkArgument(block != null, "block cannot be null");
|
||||
Preconditions.checkArgument(charge > 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<SculkShriekerBlockEntity> implements SculkShrieker {
|
||||
|
||||
|
@ -19,4 +22,12 @@ public class CraftSculkShrieker extends CraftBlockEntityState<SculkShriekerBlock
|
|||
public void setWarningLevel(int level) {
|
||||
getSnapshot().warningLevel = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tryShriek(Player player) {
|
||||
requirePlaced();
|
||||
|
||||
EntityPlayer entityPlayer = (player == null) ? null : ((CraftPlayer) player).getHandle();
|
||||
getTileEntity().tryShriek(world.getHandle(), entityPlayer);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue