SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot
2024-07-28 08:54:10 +10:00
parent 1a0dce328a
commit 8317d4c799
4 changed files with 80 additions and 17 deletions

View File

@@ -1,18 +1,17 @@
--- a/net/minecraft/world/level/portal/BlockPortalShape.java
+++ b/net/minecraft/world/level/portal/BlockPortalShape.java
@@ -21,6 +21,11 @@
@@ -21,6 +21,10 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftPortalEvent;
+import org.bukkit.event.world.PortalCreateEvent;
+// CraftBukkit end
+
public class BlockPortalShape {
private static final int MIN_WIDTH = 2;
@@ -40,6 +45,7 @@
@@ -40,6 +44,7 @@
private BlockPosition bottomLeft;
private int height;
private final int width;
@@ -20,7 +19,7 @@
public static Optional<BlockPortalShape> findEmptyPortalShape(GeneratorAccess generatoraccess, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) {
return findPortalShape(generatoraccess, blockposition, (blockportalshape) -> {
@@ -60,6 +66,7 @@
@@ -60,6 +65,7 @@
}
public BlockPortalShape(GeneratorAccess generatoraccess, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) {
@@ -28,7 +27,7 @@
this.level = generatoraccess;
this.axis = enumdirection_enumaxis;
this.rightDir = enumdirection_enumaxis == EnumDirection.EnumAxis.X ? EnumDirection.WEST : EnumDirection.SOUTH;
@@ -104,6 +111,7 @@
@@ -104,6 +110,7 @@
if (!isEmpty(iblockdata)) {
if (BlockPortalShape.FRAME.test(iblockdata, this.level, blockposition_mutableblockposition)) {
@@ -36,7 +35,7 @@
return i;
}
break;
@@ -114,6 +122,7 @@
@@ -114,6 +121,7 @@
if (!BlockPortalShape.FRAME.test(iblockdata1, this.level, blockposition_mutableblockposition)) {
break;
}
@@ -44,7 +43,7 @@
}
return 0;
@@ -133,6 +142,7 @@
@@ -133,6 +141,7 @@
if (!BlockPortalShape.FRAME.test(this.level.getBlockState(blockposition_mutableblockposition1), this.level, blockposition_mutableblockposition1)) {
return false;
}
@@ -52,7 +51,7 @@
}
return true;
@@ -162,6 +172,10 @@
@@ -162,6 +171,10 @@
++this.numPortalBlocks;
}
}
@@ -63,13 +62,13 @@
}
return 21;
@@ -175,12 +189,28 @@
@@ -175,12 +188,28 @@
return this.bottomLeft != null && this.width >= 2 && this.width <= 21 && this.height >= 3 && this.height <= 21;
}
- public void createPortalBlocks() {
+ // CraftBukkit start - return boolean
+ public boolean createPortalBlocks() {
+ // CraftBukkit start - return boolean, add entity
+ public boolean createPortalBlocks(Entity entity) {
+ org.bukkit.World bworld = this.level.getMinecraftWorld().getWorld();
+
+ // Copy below for loop
@@ -79,7 +78,7 @@
+ blocks.setBlock(blockposition, iblockdata, 18);
+ });
+
+ PortalCreateEvent event = new PortalCreateEvent((java.util.List<org.bukkit.block.BlockState>) (java.util.List) blocks.getList(), bworld, null, PortalCreateEvent.CreateReason.FIRE);
+ PortalCreateEvent event = new PortalCreateEvent((java.util.List<org.bukkit.block.BlockState>) (java.util.List) blocks.getList(), bworld, (entity == null) ? null : entity.getBukkitEntity(), PortalCreateEvent.CreateReason.FIRE);
+ this.level.getMinecraftWorld().getServer().server.getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {