Skip to content

Commit 43f5492

Browse files
Null Check some pipe TE fetches (#2722)
1 parent abb98d7 commit 43f5492

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
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: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ protected boolean isPipeTool(@NotNull ItemStack stack) {
114114
@Override
115115
public int getLightValue(@NotNull IBlockState state, IBlockAccess world, @NotNull BlockPos pos) {
116116
TileEntity tile = world.getTileEntity(pos);
117-
if (tile instanceof TileEntityCable) {
118-
TileEntityCable cable = (TileEntityCable) tile;
117+
if (tile instanceof TileEntityCable cable) {
119118
int temp = cable.getTemperature();
120119
// max light at 5000 K
121120
// min light at 500 K
@@ -132,7 +131,9 @@ public int getLightValue(@NotNull IBlockState state, IBlockAccess world, @NotNul
132131
@Override
133132
public void breakBlock(@NotNull World worldIn, @NotNull BlockPos pos, @NotNull IBlockState state) {
134133
if (worldIn.isRemote) {
135-
TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos);
134+
IPipeTile<Insulation, WireProperties> pipeTile = getPipeTileEntity(worldIn, pos);
135+
if (pipeTile == null) return;
136+
TileEntityCable cable = (TileEntityCable) pipeTile;
136137
cable.killParticle();
137138
}
138139
super.breakBlock(worldIn, pos, state);
@@ -165,11 +166,12 @@ public void onEntityCollision(World worldIn, @NotNull BlockPos pos, @NotNull IBl
165166
@NotNull Entity entityIn) {
166167
super.onEntityCollision(worldIn, pos, state, entityIn);
167168
if (worldIn.isRemote) return;
168-
Insulation insulation = getPipeTileEntity(worldIn, pos).getPipeType();
169-
if (insulation.insulationLevel == -1 && entityIn instanceof EntityLivingBase) {
170-
EntityLivingBase entityLiving = (EntityLivingBase) entityIn;
171-
TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos);
172-
if (cable != null && cable.getFrameMaterial() == null && cable.getNodeData().getLossPerBlock() > 0) {
169+
IPipeTile<Insulation, WireProperties> pipeTile = getPipeTileEntity(worldIn, pos);
170+
if (pipeTile == null) return;
171+
Insulation insulation = pipeTile.getPipeType();
172+
if (insulation.insulationLevel == -1 && entityIn instanceof EntityLivingBase entityLiving) {
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) {

src/main/java/gregtech/common/pipelike/fluidpipe/BlockFluidPipe.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ public void onEntityCollision(@NotNull World worldIn, @NotNull BlockPos pos, @No
131131
@NotNull Entity entityIn) {
132132
super.onEntityCollision(worldIn, pos, state, entityIn);
133133
if (worldIn.isRemote) return;
134-
TileEntityFluidPipe pipe = (TileEntityFluidPipe) getPipeTileEntity(worldIn, pos);
134+
IPipeTile<FluidPipeType, FluidPipeProperties> pipeTile = getPipeTileEntity(worldIn, pos);
135+
if (pipeTile == null) return;
136+
TileEntityFluidPipe pipe = (TileEntityFluidPipe) pipeTile;
135137
if (pipe instanceof TileEntityFluidPipeTickable && pipe.getFrameMaterial() == null &&
136138
((TileEntityFluidPipeTickable) pipe).getOffsetTimer() % 10 == 0) {
137139
if (entityIn instanceof EntityLivingBase) {

0 commit comments

Comments
 (0)