Skip to content

Commit ffc2486

Browse files
Mark as nullable and add more null checks
1 parent 3ecb5eb commit ffc2486

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/java/gregtech/api/pipenet/block/BlockPipe.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,9 @@ public BlockFaceShape getBlockFaceShape(@NotNull IBlockAccess worldIn, @NotNull
564564
}
565565

566566
@Override
567-
public boolean recolorBlock(World world, @NotNull BlockPos pos, @NotNull EnumFacing side,
567+
public boolean recolorBlock(@NotNull World world, @NotNull BlockPos pos, @NotNull EnumFacing side,
568568
@NotNull EnumDyeColor color) {
569-
IPipeTile<PipeType, NodeDataType> tileEntityPipe = (IPipeTile<PipeType, NodeDataType>) world.getTileEntity(pos);
569+
IPipeTile<PipeType, NodeDataType> tileEntityPipe = getPipeTileEntity(world, pos);
570570
if (tileEntityPipe != null && tileEntityPipe.getPipeType() != null &&
571571
tileEntityPipe.getPipeType().isPaintable() &&
572572
tileEntityPipe.getPaintingColor() != color.colorValue) {
@@ -588,6 +588,7 @@ public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(IBlockAccess world, B
588588
return getPipeTileEntity(tileEntityAtPos);
589589
}
590590

591+
@Nullable
591592
public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(TileEntity tileEntityAtPos) {
592593
if (tileEntityAtPos instanceof IPipeTile &&
593594
isThisPipeBlock(((IPipeTile<PipeType, NodeDataType>) tileEntityAtPos).getPipeBlock())) {

src/main/java/gregtech/common/pipelike/cable/BlockCable.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public int getLightValue(@NotNull IBlockState state, IBlockAccess world, @NotNul
131131
@Override
132132
public void breakBlock(@NotNull World worldIn, @NotNull BlockPos pos, @NotNull IBlockState state) {
133133
if (worldIn.isRemote) {
134-
TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos);
134+
IPipeTile<Insulation, WireProperties> pipeTile = getPipeTileEntity(worldIn, pos);
135+
if (pipeTile == null) return;
136+
TileEntityCable cable = (TileEntityCable) pipeTile;
135137
cable.killParticle();
136138
}
137139
super.breakBlock(worldIn, pos, state);
@@ -168,8 +170,8 @@ public void onEntityCollision(World worldIn, @NotNull BlockPos pos, @NotNull IBl
168170
if (pipeTile == null) return;
169171
Insulation insulation = pipeTile.getPipeType();
170172
if (insulation.insulationLevel == -1 && entityIn instanceof EntityLivingBase entityLiving) {
171-
TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos);
172-
if (cable != null && cable.getFrameMaterial() == null && cable.getNodeData().getLossPerBlock() > 0) {
173+
TileEntityCable cable = (TileEntityCable) pipeTile;
174+
if (cable.getFrameMaterial() == null && cable.getNodeData().getLossPerBlock() > 0) {
173175
long voltage = cable.getCurrentMaxVoltage();
174176
double amperage = cable.getAverageAmperage();
175177
if (voltage > 0L && amperage > 0L) {

0 commit comments

Comments
 (0)