Skip to content

Commit

Permalink
Fix class cast exception found by Cellman_XM8
Browse files Browse the repository at this point in the history
  • Loading branch information
cam72cam committed Mar 18, 2018
1 parent 710d856 commit bc00b23
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public static boolean tryBreakRail(IBlockAccess world, BlockPos pos) {

@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor){
TileRailBase tileEntity = SyncdTileEntity.get(world, pos, EnumCreateEntityType.CHECK); // Prevent recursive loading
SyncdTileEntity syncd = SyncdTileEntity.get(world, pos, EnumCreateEntityType.CHECK);
TileRailBase tileEntity = syncd instanceof TileRailBase ? (TileRailBase)syncd : null; // Prevent recursive loading
if (tileEntity == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
public class SyncdTileEntity extends TileEntity {
public boolean hasTileData;

@SuppressWarnings("unchecked")
public static <T extends SyncdTileEntity> T get(IBlockAccess world, BlockPos pos, EnumCreateEntityType type) {
public static SyncdTileEntity get(IBlockAccess world, BlockPos pos, EnumCreateEntityType type) {
TileEntity te;
if (world instanceof World) {
te = ((World)world).getChunkFromBlockCoords(pos).getTileEntity(pos, type);
Expand All @@ -22,11 +21,7 @@ public static <T extends SyncdTileEntity> T get(IBlockAccess world, BlockPos pos
}

if (te instanceof SyncdTileEntity) {
try {
return (T) te;
} catch (ClassCastException e) {
return null;
}
return (SyncdTileEntity) te;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@

public class TileRailBase extends SyncdTileEntity implements ITrack, ITickable {
public static TileRailBase get(IBlockAccess world, BlockPos pos) {
return SyncdTileEntity.get(world, pos, EnumCreateEntityType.IMMEDIATE);
SyncdTileEntity te = SyncdTileEntity.get(world, pos, EnumCreateEntityType.IMMEDIATE);
return te instanceof TileRailBase ? (TileRailBase)te : null;
}

private BlockPos parent;
Expand Down

0 comments on commit bc00b23

Please sign in to comment.