Skip to content

Commit

Permalink
SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether port…
Browse files Browse the repository at this point in the history
…als ignited by flint and steel
  • Loading branch information
md-5 committed Jul 27, 2024
1 parent d53d0d0 commit 8c51673
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
2 changes: 1 addition & 1 deletion nms-patches/net/minecraft/world/item/ItemStack.patch
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
+ IBlockData block = world.getBlockState(newblockposition);
+
+ if (!(block.getBlock() instanceof BlockTileEntity)) { // Containers get placed automatically
+ block.onPlace(world, newblockposition, oldBlock, true);
+ block.onPlace(world, newblockposition, oldBlock, true, itemactioncontext);
+ }
+
+ world.notifyAndUpdatePhysics(newblockposition, null, oldBlock, block, world.getBlockState(newblockposition), updateFlag, 512); // send null chunk as chunk.k() returns false by this point
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
--- a/net/minecraft/world/level/block/BlockFireAbstract.java
+++ b/net/minecraft/world/level/block/BlockFireAbstract.java
@@ -127,7 +127,14 @@
@@ -19,6 +19,10 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;

+// CraftBukkit start
+import net.minecraft.world.item.context.ItemActionContext;
+// CraftBukkit end
+
public abstract class BlockFireAbstract extends Block {

private static final int SECONDS_ON_FIRE = 8;
@@ -127,7 +131,14 @@
if (!entity.fireImmune()) {
entity.setRemainingFireTicks(entity.getRemainingFireTicks() + 1);
if (entity.getRemainingFireTicks() == 0) {
Expand All @@ -16,7 +27,21 @@
}
}

@@ -148,14 +155,14 @@
@@ -136,26 +147,26 @@
}

@Override
- protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
+ protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag, ItemActionContext context) { // CraftBukkit - context
if (!iblockdata1.is(iblockdata.getBlock())) {
if (inPortalDimension(world)) {
Optional<BlockPortalShape> optional = BlockPortalShape.findEmptyPortalShape(world, blockposition, EnumDirection.EnumAxis.X);

if (optional.isPresent()) {
- ((BlockPortalShape) optional.get()).createPortalBlocks();
+ ((BlockPortalShape) optional.get()).createPortalBlocks((context == null) ? null : context.getPlayer()); // CraftBukkit - player
return;
}
}

if (!iblockdata.canSurvive(world, blockposition)) {
Expand All @@ -33,7 +58,7 @@
}

@Override
@@ -203,4 +210,12 @@
@@ -203,4 +214,12 @@
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
--- a/net/minecraft/world/level/block/state/BlockBase.java
+++ b/net/minecraft/world/level/block/state/BlockBase.java
@@ -173,8 +173,10 @@
@@ -81,6 +81,10 @@
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
import net.minecraft.world.phys.shapes.VoxelShapes;

+// CraftBukkit start
+import net.minecraft.world.item.context.ItemActionContext;
+// CraftBukkit end
+
public abstract class BlockBase implements FeatureElement {

protected static final EnumDirection[] UPDATE_SHAPE_ORDER = new EnumDirection[]{EnumDirection.WEST, EnumDirection.EAST, EnumDirection.NORTH, EnumDirection.SOUTH, EnumDirection.DOWN, EnumDirection.UP};
@@ -156,6 +160,12 @@

protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {}

+ // CraftBukkit start
+ protected void onPlace(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag, @Nullable ItemActionContext context) {
+ this.onPlace(iblockdata, world, blockposition, iblockdata1, flag);
+ }
+ // CraftBukkit end
+
protected void onRemove(IBlockData iblockdata, World world, BlockPosition blockposition, IBlockData iblockdata1, boolean flag) {
if (iblockdata.hasBlockEntity() && !iblockdata.is(iblockdata1.getBlock())) {
world.removeBlockEntity(blockposition);
@@ -173,8 +183,10 @@
TileEntity tileentity = iblockdata.hasBlockEntity() ? world.getBlockEntity(blockposition) : null;
LootParams.a lootparams_a = (new LootParams.a(worldserver)).withParameter(LootContextParameters.ORIGIN, Vec3D.atCenterOf(blockposition)).withParameter(LootContextParameters.TOOL, ItemStack.EMPTY).withOptionalParameter(LootContextParameters.BLOCK_ENTITY, tileentity).withOptionalParameter(LootContextParameters.THIS_ENTITY, explosion.getDirectSourceEntity());

Expand All @@ -13,3 +37,18 @@
}

iblockdata.spawnAfterBreak(worldserver, blockposition, ItemStack.EMPTY, flag);
@@ -1066,7 +1078,13 @@
}

public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
- this.getBlock().onPlace(this.asState(), world, blockposition, iblockdata, flag);
+ // CraftBukkit start
+ this.onPlace(world, blockposition, iblockdata, flag, null);
+ }
+
+ public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata, boolean flag, @Nullable ItemActionContext context) {
+ this.getBlock().onPlace(this.asState(), world, blockposition, iblockdata, flag, context);
+ // CraftBukkit end
}

public void onRemove(World world, BlockPosition blockposition, IBlockData iblockdata, boolean flag) {
23 changes: 11 additions & 12 deletions nms-patches/net/minecraft/world/level/portal/BlockPortalShape.patch
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
--- 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;
+ org.bukkit.craftbukkit.util.BlockStateListPopulator blocks; // CraftBukkit - add field

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) {
+ blocks = new org.bukkit.craftbukkit.util.BlockStateListPopulator(generatoraccess.getMinecraftWorld()); // CraftBukkit
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)) {
+ blocks.setBlock(blockposition_mutableblockposition, iblockdata, 18); // CraftBukkit - lower left / right
return i;
}
break;
@@ -114,6 +122,7 @@
@@ -114,6 +121,7 @@
if (!BlockPortalShape.FRAME.test(iblockdata1, this.level, blockposition_mutableblockposition)) {
break;
}
+ blocks.setBlock(blockposition_mutableblockposition, iblockdata1, 18); // CraftBukkit - bottom row
}

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;
}
+ blocks.setBlock(blockposition_mutableblockposition1, this.level.getBlockState(blockposition_mutableblockposition1), 18); // CraftBukkit - upper row
}

return true;
@@ -162,6 +172,10 @@
@@ -162,6 +171,10 @@
++this.numPortalBlocks;
}
}
Expand All @@ -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
Expand All @@ -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()) {
Expand Down

0 comments on commit 8c51673

Please sign in to comment.