mirror of
https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git
synced 2024-11-25 13:56:14 +00:00
67 lines
3.9 KiB
Diff
67 lines
3.9 KiB
Diff
--- a/net/minecraft/world/level/block/BlockTurtleEgg.java
|
|
+++ b/net/minecraft/world/level/block/BlockTurtleEgg.java
|
|
@@ -32,6 +32,12 @@
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.event.entity.EntityInteractEvent;
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+// CraftBukkit end
|
|
+
|
|
public class BlockTurtleEgg extends Block {
|
|
|
|
public static final MapCodec<BlockTurtleEgg> CODEC = simpleCodec(BlockTurtleEgg::new);
|
|
@@ -74,6 +80,19 @@
|
|
private void destroyEgg(World world, IBlockData iblockdata, BlockPosition blockposition, Entity entity, int i) {
|
|
if (iblockdata.is(Blocks.TURTLE_EGG) && world instanceof WorldServer worldserver) {
|
|
if (this.canDestroyEgg(worldserver, entity) && world.random.nextInt(i) == 0) {
|
|
+ // CraftBukkit start - Step on eggs
|
|
+ org.bukkit.event.Cancellable cancellable;
|
|
+ if (entity instanceof EntityHuman) {
|
|
+ cancellable = CraftEventFactory.callPlayerInteractEvent((EntityHuman) entity, org.bukkit.event.block.Action.PHYSICAL, blockposition, null, null, null);
|
|
+ } else {
|
|
+ cancellable = new EntityInteractEvent(entity.getBukkitEntity(), CraftBlock.at(worldserver, blockposition));
|
|
+ worldserver.getCraftServer().getPluginManager().callEvent((EntityInteractEvent) cancellable);
|
|
+ }
|
|
+
|
|
+ if (cancellable.isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
this.decreaseEggs(worldserver, blockposition, iblockdata);
|
|
}
|
|
}
|
|
@@ -100,10 +119,20 @@
|
|
int i = (Integer) iblockdata.getValue(BlockTurtleEgg.HATCH);
|
|
|
|
if (i < 2) {
|
|
+ // CraftBukkit start - Call BlockGrowEvent
|
|
+ if (!CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2)) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
worldserver.playSound((EntityHuman) null, blockposition, SoundEffects.TURTLE_EGG_CRACK, SoundCategory.BLOCKS, 0.7F, 0.9F + randomsource.nextFloat() * 0.2F);
|
|
- worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2);
|
|
+ // worldserver.setBlock(blockposition, (IBlockData) iblockdata.setValue(BlockTurtleEgg.HATCH, i + 1), 2); // CraftBukkit - handled above
|
|
worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata));
|
|
} else {
|
|
+ // CraftBukkit start - Call BlockFadeEvent
|
|
+ if (CraftEventFactory.callBlockFadeEvent(worldserver, blockposition, Blocks.AIR.defaultBlockState()).isCancelled()) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
worldserver.playSound((EntityHuman) null, blockposition, SoundEffects.TURTLE_EGG_HATCH, SoundCategory.BLOCKS, 0.7F, 0.9F + randomsource.nextFloat() * 0.2F);
|
|
worldserver.removeBlock(blockposition, false);
|
|
worldserver.gameEvent((Holder) GameEvent.BLOCK_DESTROY, blockposition, GameEvent.a.of(iblockdata));
|
|
@@ -116,7 +145,7 @@
|
|
entityturtle.setAge(-24000);
|
|
entityturtle.setHomePos(blockposition);
|
|
entityturtle.moveTo((double) blockposition.getX() + 0.3D + (double) j * 0.2D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.3D, 0.0F, 0.0F);
|
|
- worldserver.addFreshEntity(entityturtle);
|
|
+ worldserver.addFreshEntity(entityturtle, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.EGG); // CraftBukkit
|
|
}
|
|
}
|
|
}
|