From 5cb5770a2021cce8390765f38b22113245cc623d Mon Sep 17 00:00:00 2001 From: "Luis C.M" <42545778+c0508383@users.noreply.github.com> Date: Sun, 6 Nov 2022 01:23:54 -0600 Subject: [PATCH] Fixed NullPointerException crash from breaking blocks that have no tile entities. --- src/main/java/noppes/npcs/scripted/NpcAPI.java | 8 +++++--- src/main/java/noppes/npcs/scripted/ScriptBlock.java | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index ebb8a15ba..7e4fbe98c 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -171,15 +171,17 @@ public class NpcAPI extends AbstractNpcAPI { } public ITileEntity getITileEntity(IWorld world, IPos pos) { - return new ScriptTileEntity<>(world.getMCWorld().getTileEntity(pos.getX(), pos.getY(),pos.getZ())); + TileEntity tileEntity = world.getMCWorld().getTileEntity(pos.getX(), pos.getY(),pos.getZ()); + return this.getITileEntity(tileEntity); } public ITileEntity getITileEntity(IWorld world, int x, int y, int z) { - return new ScriptTileEntity<>(world.getMCWorld().getTileEntity(x,y,z)); + TileEntity tileEntity = world.getMCWorld().getTileEntity(x,y,z); + return this.getITileEntity(tileEntity); } public ITileEntity getITileEntity(TileEntity tileEntity) { - return new ScriptTileEntity<>(tileEntity); + return tileEntity == null ? null : new ScriptTileEntity<>(tileEntity); } public IPos getIPos(BlockPos pos) { diff --git a/src/main/java/noppes/npcs/scripted/ScriptBlock.java b/src/main/java/noppes/npcs/scripted/ScriptBlock.java index 15f775868..b45d3b120 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptBlock.java +++ b/src/main/java/noppes/npcs/scripted/ScriptBlock.java @@ -31,7 +31,7 @@ public class ScriptBlock implements IBlock { this.block = block; this.pos = pos; this.bPos = NpcAPI.Instance().getIPos(pos); - this.tile = new ScriptTileEntity<>(world.getTileEntity(pos.getX(),pos.getY(), pos.getZ())); + this.tile = NpcAPI.Instance().getITileEntity(world.getTileEntity(pos.getX(),pos.getY(), pos.getZ())); } public IPos getPos() {