Fixed #401 various crashes with explosion resistance checks

This commit is contained in:
Unknown 2019-09-09 23:08:24 +02:00 committed by unknown
parent 56aefcf8f8
commit 08cca9ba2e
3 changed files with 12 additions and 5 deletions

View file

@ -42,6 +42,7 @@ import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional;
@ -358,7 +359,8 @@ public class TileEntityLaser extends TileEntityAbstractLaser implements IBeamFre
final IBlockState blockState = world.getBlockState(scanResult_position);
scanResult_blockUnlocalizedName = blockState.getBlock().getTranslationKey();
scanResult_blockMetadata = blockState.getBlock().getMetaFromState(blockState);
scanResult_blockResistance = blockState.getBlock().getExplosionResistance(world, scanResult_position, null, null);
final Explosion explosion = new Explosion(world, null, pos.getX(), pos.getY(), pos.getZ(), 1, true, true);
scanResult_blockResistance = blockState.getBlock().getExplosionResistance(world, scanResult_position, null, explosion);
PacketHandler.sendBeamPacket(world, vSource, new Vector3(mopResult.hitVec), r, g, b, 50, energy, 200);
} else {
scanResult_type = ScanResultType.NONE;

View file

@ -31,6 +31,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.world.Explosion;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
@ -63,6 +64,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
// computed properties
private float explosionResistanceMax = 10000.0F;
private Explosion explosion;
private float viscosityMax = 0.0F;
private int radiusX_actual = 0;
private int radiusZ_actual = 0;
@ -96,7 +98,8 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
@Override
protected void onFirstUpdateTick() {
super.onFirstUpdateTick();
explosionResistanceMax = Blocks.OBSIDIAN.getExplosionResistance(world, pos, null, null);
explosion = new Explosion(world, null, pos.getX(), pos.getY(), pos.getZ(), 1, true, true);
explosionResistanceMax = Blocks.OBSIDIAN.getExplosionResistance(world, pos, null, explosion);
updateParameters();
}
@ -346,7 +349,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractMiner {
return true;
}
// check default (explosion resistance is used to test for force fields and reinforced blocks, basically preventing mining a base or ship)
final float explosionResistance = blockState.getBlock().getExplosionResistance(world, blockPos, null, null);
final float explosionResistance = blockState.getBlock().getExplosionResistance(world, blockPos, null, explosion);
if (explosionResistance <= explosionResistanceMax) {
return true;
}

View file

@ -27,6 +27,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockPos.MutableBlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
@ -440,7 +441,8 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController {
this, radius, chanceOfRemoval ));
if (radius > 1) {
final MutableBlockPos mutableBlockPos = new MutableBlockPos(pos);
final float explosionResistanceThreshold = Blocks.OBSIDIAN.getExplosionResistance(world, mutableBlockPos, null, null);
final Explosion explosion = new Explosion(world, null, vCenter.x, vCenter.y, vCenter.z, radius, true, true);
final float explosionResistanceThreshold = Blocks.OBSIDIAN.getExplosionResistance(world, mutableBlockPos, null, explosion);
for (int x = pos.getX() - radius; x <= pos.getX() + radius; x++) {
for (int y = pos.getY() - radius; y <= pos.getY() + radius; y++) {
for (int z = pos.getZ() - radius; z <= pos.getZ() + radius; z++) {
@ -448,7 +450,7 @@ public class TileEntityEnanReactorCore extends TileEntityEnanReactorController {
if (world.rand.nextDouble() < chanceOfRemoval) {
mutableBlockPos.setPos(x, y, z);
final IBlockState blockState = world.getBlockState(mutableBlockPos);
final float explosionResistanceActual = blockState.getBlock().getExplosionResistance(world, mutableBlockPos, null, null);
final float explosionResistanceActual = blockState.getBlock().getExplosionResistance(world, mutableBlockPos, null, explosion);
if (explosionResistanceActual >= explosionResistanceThreshold) {
WarpDrive.logger.debug(String.format("%s De-materializing %s %s",
this, blockState, Commons.format(world, mutableBlockPos) ));