From 3ecb5eb82b7a48f1b969fdcac3bbf8f05182cbde Mon Sep 17 00:00:00 2001 From: alongstringofnumbers Date: Wed, 12 Feb 2025 12:18:48 -0700 Subject: [PATCH 1/2] Null Check some pipe TE fetches --- .../gregtech/common/pipelike/cable/BlockCable.java | 10 +++++----- .../common/pipelike/fluidpipe/BlockFluidPipe.java | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/gregtech/common/pipelike/cable/BlockCable.java b/src/main/java/gregtech/common/pipelike/cable/BlockCable.java index 204010ed522..0c9d70bcd6c 100644 --- a/src/main/java/gregtech/common/pipelike/cable/BlockCable.java +++ b/src/main/java/gregtech/common/pipelike/cable/BlockCable.java @@ -114,8 +114,7 @@ protected boolean isPipeTool(@NotNull ItemStack stack) { @Override public int getLightValue(@NotNull IBlockState state, IBlockAccess world, @NotNull BlockPos pos) { TileEntity tile = world.getTileEntity(pos); - if (tile instanceof TileEntityCable) { - TileEntityCable cable = (TileEntityCable) tile; + if (tile instanceof TileEntityCable cable) { int temp = cable.getTemperature(); // max light at 5000 K // min light at 500 K @@ -165,9 +164,10 @@ public void onEntityCollision(World worldIn, @NotNull BlockPos pos, @NotNull IBl @NotNull Entity entityIn) { super.onEntityCollision(worldIn, pos, state, entityIn); if (worldIn.isRemote) return; - Insulation insulation = getPipeTileEntity(worldIn, pos).getPipeType(); - if (insulation.insulationLevel == -1 && entityIn instanceof EntityLivingBase) { - EntityLivingBase entityLiving = (EntityLivingBase) entityIn; + IPipeTile pipeTile = getPipeTileEntity(worldIn, pos); + if (pipeTile == null) return; + Insulation insulation = pipeTile.getPipeType(); + if (insulation.insulationLevel == -1 && entityIn instanceof EntityLivingBase entityLiving) { TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos); if (cable != null && cable.getFrameMaterial() == null && cable.getNodeData().getLossPerBlock() > 0) { long voltage = cable.getCurrentMaxVoltage(); diff --git a/src/main/java/gregtech/common/pipelike/fluidpipe/BlockFluidPipe.java b/src/main/java/gregtech/common/pipelike/fluidpipe/BlockFluidPipe.java index 20ac0640a0f..d94dc304bdf 100644 --- a/src/main/java/gregtech/common/pipelike/fluidpipe/BlockFluidPipe.java +++ b/src/main/java/gregtech/common/pipelike/fluidpipe/BlockFluidPipe.java @@ -131,7 +131,9 @@ public void onEntityCollision(@NotNull World worldIn, @NotNull BlockPos pos, @No @NotNull Entity entityIn) { super.onEntityCollision(worldIn, pos, state, entityIn); if (worldIn.isRemote) return; - TileEntityFluidPipe pipe = (TileEntityFluidPipe) getPipeTileEntity(worldIn, pos); + IPipeTile pipeTile = getPipeTileEntity(worldIn, pos); + if (pipeTile == null) return; + TileEntityFluidPipe pipe = (TileEntityFluidPipe) pipeTile; if (pipe instanceof TileEntityFluidPipeTickable && pipe.getFrameMaterial() == null && ((TileEntityFluidPipeTickable) pipe).getOffsetTimer() % 10 == 0) { if (entityIn instanceof EntityLivingBase) { From ffc248622288659a1f3ee7378005703841238c3d Mon Sep 17 00:00:00 2001 From: alongstringofnumbers Date: Wed, 12 Feb 2025 12:44:51 -0700 Subject: [PATCH 2/2] Mark as nullable and add more null checks --- src/main/java/gregtech/api/pipenet/block/BlockPipe.java | 5 +++-- .../java/gregtech/common/pipelike/cable/BlockCable.java | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/pipenet/block/BlockPipe.java b/src/main/java/gregtech/api/pipenet/block/BlockPipe.java index 667b67fcf52..119075cd5ee 100644 --- a/src/main/java/gregtech/api/pipenet/block/BlockPipe.java +++ b/src/main/java/gregtech/api/pipenet/block/BlockPipe.java @@ -564,9 +564,9 @@ public BlockFaceShape getBlockFaceShape(@NotNull IBlockAccess worldIn, @NotNull } @Override - public boolean recolorBlock(World world, @NotNull BlockPos pos, @NotNull EnumFacing side, + public boolean recolorBlock(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing side, @NotNull EnumDyeColor color) { - IPipeTile tileEntityPipe = (IPipeTile) world.getTileEntity(pos); + IPipeTile tileEntityPipe = getPipeTileEntity(world, pos); if (tileEntityPipe != null && tileEntityPipe.getPipeType() != null && tileEntityPipe.getPipeType().isPaintable() && tileEntityPipe.getPaintingColor() != color.colorValue) { @@ -588,6 +588,7 @@ public IPipeTile getPipeTileEntity(IBlockAccess world, B return getPipeTileEntity(tileEntityAtPos); } + @Nullable public IPipeTile getPipeTileEntity(TileEntity tileEntityAtPos) { if (tileEntityAtPos instanceof IPipeTile && isThisPipeBlock(((IPipeTile) tileEntityAtPos).getPipeBlock())) { diff --git a/src/main/java/gregtech/common/pipelike/cable/BlockCable.java b/src/main/java/gregtech/common/pipelike/cable/BlockCable.java index 0c9d70bcd6c..98be62d35b1 100644 --- a/src/main/java/gregtech/common/pipelike/cable/BlockCable.java +++ b/src/main/java/gregtech/common/pipelike/cable/BlockCable.java @@ -131,7 +131,9 @@ public int getLightValue(@NotNull IBlockState state, IBlockAccess world, @NotNul @Override public void breakBlock(@NotNull World worldIn, @NotNull BlockPos pos, @NotNull IBlockState state) { if (worldIn.isRemote) { - TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos); + IPipeTile pipeTile = getPipeTileEntity(worldIn, pos); + if (pipeTile == null) return; + TileEntityCable cable = (TileEntityCable) pipeTile; cable.killParticle(); } super.breakBlock(worldIn, pos, state); @@ -168,8 +170,8 @@ public void onEntityCollision(World worldIn, @NotNull BlockPos pos, @NotNull IBl if (pipeTile == null) return; Insulation insulation = pipeTile.getPipeType(); if (insulation.insulationLevel == -1 && entityIn instanceof EntityLivingBase entityLiving) { - TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos); - if (cable != null && cable.getFrameMaterial() == null && cable.getNodeData().getLossPerBlock() > 0) { + TileEntityCable cable = (TileEntityCable) pipeTile; + if (cable.getFrameMaterial() == null && cable.getNodeData().getLossPerBlock() > 0) { long voltage = cable.getCurrentMaxVoltage(); double amperage = cable.getAverageAmperage(); if (voltage > 0L && amperage > 0L) {