Add EntityInsideBlockEvent (#5596)

This commit is contained in:
Jake Potrebic 2021-05-24 00:39:49 -07:00
parent 0edaf770ea
commit 6eefa715e3
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..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityInsideBlockEvent.java
@@ -0,0 +0,0 @@
+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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockBubbleColumn.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockBubbleColumn.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockButtonAbstract.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockButtonAbstract.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCactus.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCactus.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCampfire.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCampfire.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCauldron.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCauldron.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockCrops.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockCrops.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockEnderPortal.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockFireAbstract.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockFireAbstract.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockHoney.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockHoney.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockHopper.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockHopper.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockMinecartDetector.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockMinecartDetector.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockPortal.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockPortal.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockPressurePlateAbstract.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockPressurePlateAbstract.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockSweetBerryBush.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockSweetBerryBush.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockTripwire.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockTripwire.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockWaterLily.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockWaterLily.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockWeb.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockWeb.java
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/level/block/BlockWitherRose.java
+++ b/src/main/java/net/minecraft/world/level/block/BlockWitherRose.java
@@ -0,0 +0,0 @@ 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;