Add EntityInsideBlockEvent (#5596)

This commit is contained in:
Jake Potrebic 2021-05-24 00:39:49 -07:00 committed by GitHub
parent 47d48790d1
commit d9766433ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 314 additions and 0 deletions

View file

@ -0,0 +1,92 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 8 May 2021 18:02:06 -0700
Subject: [PATCH] Add EntityInsideBlockEvent
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityInsideBlockEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityInsideBlockEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..94e8b6f6501c92711bd0bc9ee0f67e28f85a605f
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityInsideBlockEvent.java
@@ -0,0 +1,80 @@
+package io.papermc.paper.event.entity;
+
+import org.bukkit.block.Block;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when an entity enters the hitbox of a block.
+ * Only called for blocks that react when an entity is inside.
+ * If cancelled, any action that would have resulted from that entity
+ * being in the block will not happen (such as extinguishing an entity in a cauldron).
+ * <p>
+ * Blocks this is currently called for:
+ * <ul>
+ * <li>Bubble column</li>
+ * <li>Buttons</li>
+ * <li>Cactus</li>
+ * <li>Campfire</li>
+ * <li>Cauldron</li>
+ * <li>Crops</li>
+ * <li>Ender Portal</li>
+ * <li>Fires</li>
+ * <li>Honey</li>
+ * <li>Hopper</li>
+ * <li>Detector rails</li>
+ * <li>Nether portals</li>
+ * <li>Pressure plates</li>
+ * <li>Sweet berry bush</li>
+ * <li>Tripwire</li>
+ * <li>Waterlily</li>
+ * <li>Web</li>
+ * <li>Wither rose</li>
+ * </ul>
+ */
+public class EntityInsideBlockEvent extends EntityEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Block block;
+ private boolean cancelled;
+
+ public EntityInsideBlockEvent(@NotNull Entity entity, @NotNull Block block) {
+ super(entity);
+ this.block = block;
+ }
+
+ /**
+ * Gets the block.
+ *
+ * @return the block
+ */
+ @NotNull
+ public Block getBlock() {
+ return block;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}

View file

@ -0,0 +1,222 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 8 May 2021 18:02:36 -0700
Subject: [PATCH] Add EntityInsideBlockEvent
diff --git a/src/main/java/net/minecraft/world/level/block/BlockBubbleColumn.java b/src/main/java/net/minecraft/world/level/block/BlockBubbleColumn.java
index efeae8cd002a3f801b8d5054389f9a0c74187fc4..e117853e8255cc4702e33ea7491a4e8d0d9b554a 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockBubbleColumn.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockBubbleColumn.java
@@ -33,6 +33,7 @@ public class BlockBubbleColumn extends Block implements IFluidSource {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
IBlockData iblockdata1 = world.getType(blockposition.up());
if (iblockdata1.isAir()) {
diff --git a/src/main/java/net/minecraft/world/level/block/BlockButtonAbstract.java b/src/main/java/net/minecraft/world/level/block/BlockButtonAbstract.java
index e62112f00d5c9c444aef4a142290ad28caa05264..be8e175e4f4fb2606a0393739d1a470bdacdb440 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockButtonAbstract.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockButtonAbstract.java
@@ -180,6 +180,7 @@ public abstract class BlockButtonAbstract extends BlockAttachable {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!world.isClientSide && this.v && !(Boolean) iblockdata.get(BlockButtonAbstract.POWERED)) {
this.e(iblockdata, world, blockposition);
}
diff --git a/src/main/java/net/minecraft/world/level/block/BlockCactus.java b/src/main/java/net/minecraft/world/level/block/BlockCactus.java
index 9f1e9fc5361cd051b909e2e1b2095722064185da..dc0e87b2f7d2923822e45efb129c7c6da2790298 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCactus.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCactus.java
@@ -116,6 +116,7 @@ public class BlockCactus extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
CraftEventFactory.blockDamage = world.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()); // CraftBukkit
entity.damageEntity(DamageSource.CACTUS, 1.0F);
CraftEventFactory.blockDamage = null; // CraftBukkit
diff --git a/src/main/java/net/minecraft/world/level/block/BlockCampfire.java b/src/main/java/net/minecraft/world/level/block/BlockCampfire.java
index 21baa8fb99b0587da503e14e2b04abf3134d03bc..023128e5c737ad26e40e4019e70df856395addcb 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCampfire.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCampfire.java
@@ -88,6 +88,7 @@ public class BlockCampfire extends BlockTileEntity implements IBlockWaterlogged
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!entity.isFireProof() && (Boolean) iblockdata.get(BlockCampfire.LIT) && entity instanceof EntityLiving && !EnchantmentManager.i((EntityLiving) entity)) {
entity.damageEntity(DamageSource.FIRE, (float) this.h);
}
diff --git a/src/main/java/net/minecraft/world/level/block/BlockCauldron.java b/src/main/java/net/minecraft/world/level/block/BlockCauldron.java
index 66d0a08f250fc947ec2d978a527ad77e32114b84..7fc66d4bf6b6f84ce7c7bda282788abc855b3ea8 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCauldron.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCauldron.java
@@ -59,6 +59,7 @@ public class BlockCauldron extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
int i = (Integer) iblockdata.get(BlockCauldron.LEVEL);
float f = (float) blockposition.getY() + (6.0F + (float) (3 * i)) / 16.0F;
diff --git a/src/main/java/net/minecraft/world/level/block/BlockCrops.java b/src/main/java/net/minecraft/world/level/block/BlockCrops.java
index 09f15d9087f1c40e5d50cb56f8c764ddaa992e41..32d71b6fc3fd0300386fb80e6d12d5f7c2361efe 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCrops.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCrops.java
@@ -160,6 +160,7 @@ public class BlockCrops extends BlockPlant implements IBlockFragilePlantElement
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (entity instanceof EntityRavager && !CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.getBlockData(), !world.getGameRules().getBoolean(GameRules.MOB_GRIEFING)).isCancelled()) { // CraftBukkit
world.a(blockposition, true, entity);
}
diff --git a/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java b/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java
index fc89b3bf5075497596885548d80e4ed0b800ea89..ed916f69747b44b75eb06db4cf27adaf5e47fd1e 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java
@@ -43,6 +43,7 @@ public class BlockEnderPortal extends BlockTileEntity {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (world instanceof WorldServer && !entity.isPassenger() && !entity.isVehicle() && entity.canPortal() && VoxelShapes.c(VoxelShapes.a(entity.getBoundingBox().d((double) (-blockposition.getX()), (double) (-blockposition.getY()), (double) (-blockposition.getZ()))), iblockdata.getShape(world, blockposition), OperatorBoolean.AND)) {
ResourceKey<World> resourcekey = world.getTypeKey() == DimensionManager.THE_END ? World.OVERWORLD : World.THE_END; // CraftBukkit - SPIGOT-6152: send back to main overworld in custom ends
WorldServer worldserver = ((WorldServer) world).getMinecraftServer().getWorldServer(resourcekey);
diff --git a/src/main/java/net/minecraft/world/level/block/BlockFireAbstract.java b/src/main/java/net/minecraft/world/level/block/BlockFireAbstract.java
index 02047bf07c2008c7de8daf3d76b660e25b77bce8..a256ab003d3798407d2e9432006bfea161bec1d2 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockFireAbstract.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockFireAbstract.java
@@ -48,6 +48,7 @@ public abstract class BlockFireAbstract extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!entity.isFireProof()) {
entity.setFireTicks(entity.getFireTicks() + 1);
if (entity.getFireTicks() == 0) {
diff --git a/src/main/java/net/minecraft/world/level/block/BlockHoney.java b/src/main/java/net/minecraft/world/level/block/BlockHoney.java
index d62cd3717f05c014f0ba26fc459318e10519def4..47b0ef3796413025cd5e10628f6ab92fead92ea9 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockHoney.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockHoney.java
@@ -49,6 +49,7 @@ public class BlockHoney extends BlockHalfTransparent {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (this.a(blockposition, entity)) {
this.a(entity, blockposition);
this.d(entity);
diff --git a/src/main/java/net/minecraft/world/level/block/BlockHopper.java b/src/main/java/net/minecraft/world/level/block/BlockHopper.java
index f9f5d11dee04f4056395fb8edb61a4616051350a..3555c2bdba01bcfadbd72459d69a850da35d3bdc 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockHopper.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockHopper.java
@@ -197,6 +197,7 @@ public class BlockHopper extends BlockTileEntity {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
TileEntity tileentity = world.getTileEntity(blockposition);
if (tileentity instanceof TileEntityHopper) {
diff --git a/src/main/java/net/minecraft/world/level/block/BlockMinecartDetector.java b/src/main/java/net/minecraft/world/level/block/BlockMinecartDetector.java
index 27573a0334b06f4b6ada672057695d8f8a2bcfc4..5bff21c47c608eeddf564270ba433f83ccaea1ea 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockMinecartDetector.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockMinecartDetector.java
@@ -45,6 +45,7 @@ public class BlockMinecartDetector extends BlockMinecartTrackAbstract {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!world.isClientSide) {
if (!(Boolean) iblockdata.get(BlockMinecartDetector.POWERED)) {
this.a(world, blockposition, iblockdata);
diff --git a/src/main/java/net/minecraft/world/level/block/BlockPortal.java b/src/main/java/net/minecraft/world/level/block/BlockPortal.java
index 5f797260eff317409a5039b88b01ad79ee2fdd91..f030aa3ddd001e018539ae93c238f2afb26e0fc2 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockPortal.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockPortal.java
@@ -82,6 +82,7 @@ public class BlockPortal extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!entity.isPassenger() && !entity.isVehicle() && entity.canPortal()) {
// CraftBukkit start - Entity in portal
EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()));
diff --git a/src/main/java/net/minecraft/world/level/block/BlockPressurePlateAbstract.java b/src/main/java/net/minecraft/world/level/block/BlockPressurePlateAbstract.java
index 5b03e2ddf31db372607e6a997840ebe7f179801f..4fc3cf7c255a183f3da19fd91c13cd5e3c0550b6 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockPressurePlateAbstract.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockPressurePlateAbstract.java
@@ -66,6 +66,7 @@ public abstract class BlockPressurePlateAbstract extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!world.isClientSide) {
int i = this.getPower(iblockdata);
diff --git a/src/main/java/net/minecraft/world/level/block/BlockSweetBerryBush.java b/src/main/java/net/minecraft/world/level/block/BlockSweetBerryBush.java
index 46459c3840ea23d11d2f44befc687018be2cf7e5..24c9863bd063390aa2911a86dc9c9d6c77f7ecd7 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockSweetBerryBush.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockSweetBerryBush.java
@@ -67,6 +67,7 @@ public class BlockSweetBerryBush extends BlockPlant implements IBlockFragilePlan
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (entity instanceof EntityLiving && entity.getEntityType() != EntityTypes.FOX && entity.getEntityType() != EntityTypes.BEE) {
entity.a(iblockdata, new Vec3D(0.800000011920929D, 0.75D, 0.800000011920929D));
if (!world.isClientSide && (Integer) iblockdata.get(BlockSweetBerryBush.a) > 0 && (entity.D != entity.locX() || entity.F != entity.locZ())) {
diff --git a/src/main/java/net/minecraft/world/level/block/BlockTripwire.java b/src/main/java/net/minecraft/world/level/block/BlockTripwire.java
index 74037572010c40b363af62fd251d3f514a0940e9..46a4dd932d84bf72c1837e36add56f219d6b5e77 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockTripwire.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockTripwire.java
@@ -119,6 +119,7 @@ public class BlockTripwire extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!world.isClientSide) {
if (!(Boolean) iblockdata.get(BlockTripwire.POWERED)) {
this.a(world, blockposition);
diff --git a/src/main/java/net/minecraft/world/level/block/BlockWaterLily.java b/src/main/java/net/minecraft/world/level/block/BlockWaterLily.java
index f32993d037bad535ef9867ae7634da5d53681dba..97bb8c7677ca56692666e54bf67ec43d403d3eec 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockWaterLily.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockWaterLily.java
@@ -25,6 +25,7 @@ public class BlockWaterLily extends BlockPlant {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
super.a(iblockdata, world, blockposition, entity);
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (world instanceof WorldServer && entity instanceof EntityBoat && !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, Blocks.AIR.getBlockData()).isCancelled()) { // CraftBukkit
world.a(new BlockPosition(blockposition), true, entity);
}
diff --git a/src/main/java/net/minecraft/world/level/block/BlockWeb.java b/src/main/java/net/minecraft/world/level/block/BlockWeb.java
index a574878b1e69538430d9967b708e8d6a5060233d..d88663610c4833004c2fd33b8570a67fc884d380 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockWeb.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockWeb.java
@@ -15,6 +15,7 @@ public class BlockWeb extends Block {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
entity.a(iblockdata, new Vec3D(0.25D, 0.05000000074505806D, 0.25D));
}
}
diff --git a/src/main/java/net/minecraft/world/level/block/BlockWitherRose.java b/src/main/java/net/minecraft/world/level/block/BlockWitherRose.java
index 3c43e498fb3aa61fb7ee6592623581764b27f160..2692c205d099880205ccd73a739679f3946839ab 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockWitherRose.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockWitherRose.java
@@ -26,6 +26,7 @@ public class BlockWitherRose extends BlockFlowers {
@Override
public void a(IBlockData iblockdata, World world, BlockPosition blockposition, Entity entity) {
+ if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, blockposition)).callEvent()) { return; } // Paper
if (!world.isClientSide && world.getDifficulty() != EnumDifficulty.PEACEFUL) {
if (entity instanceof EntityLiving) {
EntityLiving entityliving = (EntityLiving) entity;