Open WeasleyWalls opened 1 year ago
I also encountered this type of crash one time with the Direwolf20 1.19.2 modpack. I'm not familiar with Minecraft modding but I don't think its fortunate to just cast objects without checking them prior, like in this case.
The code in this repo:
public static boolean canBeLit(BlockState state, BlockPos pos, Level world) {
return !state.getValue(BlockStateProperties.WATERLOGGED) && (((CandleTile)world.getBlockEntity(pos)).candleLit1 == 0 || (((CandleTile)world.getBlockEntity(pos)).candleLit2 == 0 && ((CandleTile)world.getBlockEntity(pos)).candleType2 != 0) || (((CandleTile)world.getBlockEntity(pos)).candleLit3 == 0 && ((CandleTile)world.getBlockEntity(pos)).candleType3 != 0) || (((CandleTile)world.getBlockEntity(pos)).candleLit4 == 0 && ((CandleTile)world.getBlockEntity(pos)).candleType4 != 0));
}
The type check that would've saved me from the crash:
public static boolean canBeLit(BlockState state, BlockPos pos, Level world) {
if (world instanceof CandleTile) {
return !state.getValue(BlockStateProperties.WATERLOGGED) && (((CandleTile)world.getBlockEntity(pos)).candleLit1 == 0 || (((CandleTile)world.getBlockEntity(pos)).candleLit2 == 0 && ((CandleTile)world.getBlockEntity(pos)).candleType2 != 0) || (((CandleTile)world.getBlockEntity(pos)).candleLit3 == 0 && ((CandleTile)world.getBlockEntity(pos)).candleType3 != 0) || (((CandleTile)world.getBlockEntity(pos)).candleLit4 == 0 && ((CandleTile)world.getBlockEntity(pos)).candleType4 != 0));
} else {
return false;
}
}
@JoeFoxe tagging you to grab your attention. :) Again, I've never touched Minecraft mods before, so I don't know what's the best practice in this situation, it's just generally safer to check the type. And if you fancy a more readable code you can even do something like this:
public static boolean canBeLit(BlockState state, BlockPos pos, Level world) {
if (world instanceof CandleTile) {
CandleTile ct = (CandleTile)world;
return !state.getValue(BlockStateProperties.WATERLOGGED) && ((ct.getBlockEntity(pos)).candleLit1 == 0 || ((ct.getBlockEntity(pos)).candleLit2 == 0 && (ct.getBlockEntity(pos)).candleType2 != 0) || ((ctgetBlockEntity(pos)).candleLit3 == 0 && (ct.getBlockEntity(pos)).candleType3 != 0) || ((ct.getBlockEntity(pos)).candleLit4 == 0 && (ct.getBlockEntity(pos)).candleType4 != 0));
} else {
return false;
}
}
Will be fixed for the next update :) sorry it took so long I have been working on other projects (Vault Hunters) also the update should be within a few days, just doing final testing on my patreon server before launching
Using flint and steel in a dispenser on a campfire crashes server.
crash-2023-01-11_13.41.07-server.txt