Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Check some pipe TE fetches #2722

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/gregtech/api/pipenet/block/BlockPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PipeType, NodeDataType> tileEntityPipe = (IPipeTile<PipeType, NodeDataType>) world.getTileEntity(pos);
IPipeTile<PipeType, NodeDataType> tileEntityPipe = getPipeTileEntity(world, pos);
if (tileEntityPipe != null && tileEntityPipe.getPipeType() != null &&
tileEntityPipe.getPipeType().isPaintable() &&
tileEntityPipe.getPaintingColor() != color.colorValue) {
Expand All @@ -588,6 +588,7 @@ public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(IBlockAccess world, B
return getPipeTileEntity(tileEntityAtPos);
}

@Nullable
public IPipeTile<PipeType, NodeDataType> getPipeTileEntity(TileEntity tileEntityAtPos) {
if (tileEntityAtPos instanceof IPipeTile &&
isThisPipeBlock(((IPipeTile<PipeType, NodeDataType>) tileEntityAtPos).getPipeBlock())) {
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/gregtech/common/pipelike/cable/BlockCable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -132,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<Insulation, WireProperties> pipeTile = getPipeTileEntity(worldIn, pos);
if (pipeTile == null) return;
TileEntityCable cable = (TileEntityCable) pipeTile;
cable.killParticle();
}
super.breakBlock(worldIn, pos, state);
Expand Down Expand Up @@ -165,11 +166,12 @@ 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;
TileEntityCable cable = (TileEntityCable) getPipeTileEntity(worldIn, pos);
if (cable != null && cable.getFrameMaterial() == null && cable.getNodeData().getLossPerBlock() > 0) {
IPipeTile<Insulation, WireProperties> pipeTile = getPipeTileEntity(worldIn, pos);
if (pipeTile == null) return;
Insulation insulation = pipeTile.getPipeType();
if (insulation.insulationLevel == -1 && entityIn instanceof EntityLivingBase entityLiving) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FluidPipeType, FluidPipeProperties> 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) {
Expand Down