Search in sources :

Example 1 with Explosion

use of net.minecraft.world.explosion.Explosion in project roadrunner by MaxNeedsSnacks.

the class ExplosionMixin method traverseBlock.

/**
 * Called for every step made by a ray being cast by an explosion.
 *
 * @param strength The strength of the ray during this step
 * @param blockX   The x-coordinate of the block the ray is inside of
 * @param blockY   The y-coordinate of the block the ray is inside of
 * @param blockZ   The z-coordinate of the block the ray is inside of
 * @return The resistance of the current block space to the ray
 */
private float traverseBlock(float strength, int blockX, int blockY, int blockZ, LongOpenHashSet touched) {
    BlockPos pos = this.cachedPos.set(blockX, blockY, blockZ);
    // Early-exit if the y-coordinate is out of bounds.
    if (World.isOutOfBuildLimitVertically(blockY)) {
        Optional<Float> blastResistance = this.behavior.getBlastResistance((Explosion) (Object) this, this.world, pos, Blocks.AIR.getDefaultState(), Fluids.EMPTY.getDefaultState());
        // noinspection OptionalIsPresent
        if (blastResistance.isPresent()) {
            return (blastResistance.get() + 0.3F) * 0.3F;
        }
        return 0.0F;
    }
    int chunkX = blockX >> 4;
    int chunkZ = blockZ >> 4;
    // Avoid calling into the chunk manager as much as possible through managing chunks locally
    if (this.prevChunkX != chunkX || this.prevChunkZ != chunkZ) {
        this.prevChunk = this.world.getChunk(chunkX, chunkZ);
        this.prevChunkX = chunkX;
        this.prevChunkZ = chunkZ;
    }
    final Chunk chunk = this.prevChunk;
    BlockState blockState = Blocks.AIR.getDefaultState();
    float totalResistance = 0.0F;
    Optional<Float> blastResistance;
    labelGetBlastResistance: {
        // If the chunk is missing or out of bounds, assume that it is air
        if (chunk != null) {
            // We operate directly on chunk sections to avoid interacting with BlockPos and to squeeze out as much
            // performance as possible here
            ChunkSection section = chunk.getSectionArray()[blockY >> 4];
            // If the section doesn't exist or it's empty, assume that the block is air
            if (section != null && !section.isEmpty()) {
                // Retrieve the block state from the chunk section directly to avoid associated overhead
                blockState = section.getBlockState(blockX & 15, blockY & 15, blockZ & 15);
                // If the block state is air, it cannot have fluid or any kind of resistance, so just leave
                if (blockState.getBlock() != Blocks.AIR) {
                    // Rather than query the fluid state from the container as we just did with the block state, we can
                    // simply ask the block state we retrieved what fluid it has. This is exactly what the call would
                    // do anyways, except that it would have to retrieve the block state a second time, adding overhead.
                    FluidState fluidState = blockState.getFluidState();
                    // Get the explosion resistance like vanilla
                    blastResistance = this.behavior.getBlastResistance((Explosion) (Object) this, this.world, pos, blockState, fluidState);
                    break labelGetBlastResistance;
                }
            }
        }
        blastResistance = this.behavior.getBlastResistance((Explosion) (Object) this, this.world, pos, Blocks.AIR.getDefaultState(), Fluids.EMPTY.getDefaultState());
    }
    // Calculate how much this block will resist an explosion's ray
    if (blastResistance.isPresent()) {
        totalResistance = (blastResistance.get() + 0.3F) * 0.3F;
    }
    // Check if this ray is still strong enough to break blocks, and if so, add this position to the set
    // of positions to destroy
    float reducedStrength = strength - totalResistance;
    if (reducedStrength > 0.0F && (this.explodeAirBlocks || !blockState.isAir())) {
        if (this.behavior.canDestroyBlock((Explosion) (Object) this, this.world, pos, blockState, reducedStrength)) {
            touched.add(pos.asLong());
        }
    }
    return totalResistance;
}
Also used : BlockState(net.minecraft.block.BlockState) Explosion(net.minecraft.world.explosion.Explosion) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk) ChunkSection(net.minecraft.world.chunk.ChunkSection) FluidState(net.minecraft.fluid.FluidState)

Example 2 with Explosion

use of net.minecraft.world.explosion.Explosion in project lithium-fabric by CaffeineMC.

the class ExplosionMixin method traverseBlock.

/**
 * Called for every step made by a ray being cast by an explosion.
 *
 * @param strength The strength of the ray during this step
 * @param blockX   The x-coordinate of the block the ray is inside of
 * @param blockY   The y-coordinate of the block the ray is inside of
 * @param blockZ   The z-coordinate of the block the ray is inside of
 * @return The resistance of the current block space to the ray
 */
private float traverseBlock(float strength, int blockX, int blockY, int blockZ, LongOpenHashSet touched) {
    BlockPos pos = this.cachedPos.set(blockX, blockY, blockZ);
    // Early-exit if the y-coordinate is out of bounds.
    if (this.world.isOutOfHeightLimit(blockY)) {
        Optional<Float> blastResistance = this.behavior.getBlastResistance((Explosion) (Object) this, this.world, pos, Blocks.AIR.getDefaultState(), Fluids.EMPTY.getDefaultState());
        // noinspection OptionalIsPresent
        if (blastResistance.isPresent()) {
            return (blastResistance.get() + 0.3F) * 0.3F;
        }
        return 0.0F;
    }
    int chunkX = Pos.ChunkCoord.fromBlockCoord(blockX);
    int chunkZ = Pos.ChunkCoord.fromBlockCoord(blockZ);
    // Avoid calling into the chunk manager as much as possible through managing chunks locally
    if (this.prevChunkX != chunkX || this.prevChunkZ != chunkZ) {
        this.prevChunk = this.world.getChunk(chunkX, chunkZ);
        this.prevChunkX = chunkX;
        this.prevChunkZ = chunkZ;
    }
    final Chunk chunk = this.prevChunk;
    BlockState blockState = Blocks.AIR.getDefaultState();
    float totalResistance = 0.0F;
    Optional<Float> blastResistance;
    labelGetBlastResistance: {
        // If the chunk is missing or out of bounds, assume that it is air
        if (chunk != null) {
            // We operate directly on chunk sections to avoid interacting with BlockPos and to squeeze out as much
            // performance as possible here
            ChunkSection section = chunk.getSectionArray()[Pos.SectionYIndex.fromBlockCoord(chunk, blockY)];
            // If the section doesn't exist or it's empty, assume that the block is air
            if (section != null && !section.isEmpty()) {
                // Retrieve the block state from the chunk section directly to avoid associated overhead
                blockState = section.getBlockState(blockX & 15, blockY & 15, blockZ & 15);
                // If the block state is air, it cannot have fluid or any kind of resistance, so just leave
                if (blockState.getBlock() != Blocks.AIR) {
                    // Rather than query the fluid state from the container as we just did with the block state, we can
                    // simply ask the block state we retrieved what fluid it has. This is exactly what the call would
                    // do anyways, except that it would have to retrieve the block state a second time, adding overhead.
                    FluidState fluidState = blockState.getFluidState();
                    // Get the explosion resistance like vanilla
                    blastResistance = this.behavior.getBlastResistance((Explosion) (Object) this, this.world, pos, blockState, fluidState);
                    break labelGetBlastResistance;
                }
            }
        }
        blastResistance = this.behavior.getBlastResistance((Explosion) (Object) this, this.world, pos, Blocks.AIR.getDefaultState(), Fluids.EMPTY.getDefaultState());
    }
    // Calculate how much this block will resist an explosion's ray
    if (blastResistance.isPresent()) {
        totalResistance = (blastResistance.get() + 0.3F) * 0.3F;
    }
    // Check if this ray is still strong enough to break blocks, and if so, add this position to the set
    // of positions to destroy
    float reducedStrength = strength - totalResistance;
    if (reducedStrength > 0.0F && (this.explodeAirBlocks || !blockState.isAir())) {
        if (this.behavior.canDestroyBlock((Explosion) (Object) this, this.world, pos, blockState, reducedStrength)) {
            touched.add(pos.asLong());
        }
    }
    return totalResistance;
}
Also used : BlockState(net.minecraft.block.BlockState) Explosion(net.minecraft.world.explosion.Explosion) BlockPos(net.minecraft.util.math.BlockPos) Chunk(net.minecraft.world.chunk.Chunk) ChunkSection(net.minecraft.world.chunk.ChunkSection) FluidState(net.minecraft.fluid.FluidState)

Example 3 with Explosion

use of net.minecraft.world.explosion.Explosion in project Wurst7 by Wurst-Imperium.

the class KaboomHack method onUpdate.

@Override
public void onUpdate() {
    // check fly-kick
    if (!MC.player.getAbilities().creativeMode && !MC.player.isOnGround())
        return;
    // do explosion particles
    new Explosion(MC.world, MC.player, MC.player.getX(), MC.player.getY(), MC.player.getZ(), 6F, false, Explosion.DestructionType.NONE).affectWorld(true);
    // get valid blocks
    ArrayList<BlockPos> blocks = getBlocksByDistanceReversed(6);
    // break all blocks
    for (int i = 0; i < power.getValueI(); i++) BlockBreaker.breakBlocksWithPacketSpam(blocks);
    // disable
    setEnabled(false);
}
Also used : Explosion(net.minecraft.world.explosion.Explosion) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with Explosion

use of net.minecraft.world.explosion.Explosion in project JexClient by DustinRepo.

the class MixinClientPlayNetworkHandler method onExplosion.

@Inject(method = "onExplosion", at = @At("HEAD"), cancellable = true)
public void onExplosion(ExplosionS2CPacket packet, CallbackInfo ci) {
    if (isBotHandler())
        return;
    NetworkThreadUtils.forceMainThread(packet, (ClientPlayNetworkHandler) (Object) this, Wrapper.INSTANCE.getMinecraft());
    Explosion explosion = new Explosion(Wrapper.INSTANCE.getMinecraft().world, (Entity) null, packet.getX(), packet.getY(), packet.getZ(), packet.getRadius(), packet.getAffectedBlocks());
    explosion.affectWorld(true);
    EventExplosionVelocity eventExplosionVelocity = new EventExplosionVelocity().run();
    if (!eventExplosionVelocity.isCancelled())
        Wrapper.INSTANCE.getLocalPlayer().setVelocity(Wrapper.INSTANCE.getLocalPlayer().getVelocity().add((double) packet.getPlayerVelocityX() * eventExplosionVelocity.getMultX(), (double) packet.getPlayerVelocityY() * eventExplosionVelocity.getMultY(), (double) packet.getPlayerVelocityZ() * eventExplosionVelocity.getMultZ()));
    ci.cancel();
}
Also used : EventExplosionVelocity(me.dustin.jex.event.player.EventExplosionVelocity) Explosion(net.minecraft.world.explosion.Explosion) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with Explosion

use of net.minecraft.world.explosion.Explosion in project BigRat by ZimnyCat.

the class CrystalUtils method calculateDamage.

public static float calculateDamage(final World p_World, double posX, double posY, double posZ, Entity entity, int p_InterlopedAmount) {
    float doubleExplosionSize = 12.0F;
    double l_Distance = entity.squaredDistanceTo(posX, posY, posZ);
    if (l_Distance > doubleExplosionSize)
        return 0f;
    if (p_InterlopedAmount > 0) {
        Vec3d l_Interloped = EntityUtil.getInterpolatedAmount(entity, p_InterlopedAmount);
        l_Distance = EntityUtils.GetDistance(l_Interloped.x, l_Interloped.y, l_Interloped.z, posX, posY, posZ);
    }
    double distancedsize = l_Distance / (double) doubleExplosionSize;
    Vec3d vec3d = new Vec3d(posX, posY, posZ);
    double blockDensity = 0.5;
    double v = (1.0D - distancedsize) * blockDensity;
    float damage = (int) ((v * v + v) / 2.0D * 7.0D * doubleExplosionSize + 1.0D);
    double finald = 1.0D;
    /*
         * if (entity instanceof EntityLivingBase) finald =
         * getBlastReduction((EntityLivingBase) entity,getDamageMultiplied(damage));
         */
    if (entity instanceof LivingEntity) {
        finald = damage - getBlastReduction((PlayerEntity) entity, getDamageMultiplied(p_World, damage), new Explosion(p_World, null, posX, posY, posZ, 6F, false, Explosion.DestructionType.DESTROY));
    }
    return (float) finald;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Explosion(net.minecraft.world.explosion.Explosion) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Explosion (net.minecraft.world.explosion.Explosion)5 BlockPos (net.minecraft.util.math.BlockPos)3 BlockState (net.minecraft.block.BlockState)2 FluidState (net.minecraft.fluid.FluidState)2 Chunk (net.minecraft.world.chunk.Chunk)2 ChunkSection (net.minecraft.world.chunk.ChunkSection)2 EventExplosionVelocity (me.dustin.jex.event.player.EventExplosionVelocity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 Vec3d (net.minecraft.util.math.Vec3d)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1