Search in sources :

Example 1 with IFluidState

use of net.minecraft.fluid.IFluidState in project Arclight by IzzelAliz.

the class SpongeBlockMixin method absorb.

/**
 * @author IzzelAliz
 * @reason
 */
@SuppressWarnings("unchecked")
@Overwrite
private boolean absorb(World worldIn, BlockPos pos) {
    Queue<Tuple<BlockPos, Integer>> queue = Lists.newLinkedList();
    queue.add(new Tuple<>(pos, 0));
    int i = 0;
    BlockStateListPopulator blockList = new BlockStateListPopulator(worldIn);
    while (!queue.isEmpty()) {
        Tuple<BlockPos, Integer> tuple = queue.poll();
        BlockPos blockpos = tuple.getA();
        int j = tuple.getB();
        for (Direction direction : Direction.values()) {
            BlockPos blockpos1 = blockpos.offset(direction);
            BlockState blockstate = blockList.getBlockState(blockpos1);
            IFluidState ifluidstate = blockList.getFluidState(blockpos1);
            Material material = blockstate.getMaterial();
            if (ifluidstate.isTagged(FluidTags.WATER)) {
                if (blockstate.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) blockstate.getBlock()).pickupFluid(worldIn, blockpos1, blockstate) != Fluids.EMPTY) {
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (blockstate.getBlock() instanceof FlowingFluidBlock) {
                    worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    // TileEntity tileentity = blockstate.getBlock().hasTileEntity() ? worldIn.getTileEntity(blockpos1) : null;
                    // Block.spawnDrops(blockstate, worldIn, blockpos1, tileentity);
                    blockList.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 3);
                    ++i;
                    if (j < 6) {
                        queue.add(new Tuple<>(blockpos1, j + 1));
                    }
                }
            }
        }
        if (i > 64) {
            break;
        }
    }
    // Is a clone
    List<CraftBlockState> blocks = blockList.getList();
    if (!blocks.isEmpty()) {
        final org.bukkit.block.Block bblock = CraftBlock.at(worldIn, pos);
        SpongeAbsorbEvent event = new SpongeAbsorbEvent(bblock, (List<org.bukkit.block.BlockState>) (List) blocks);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            return false;
        }
        for (CraftBlockState block : blocks) {
            BlockPos blockposition2 = block.getPosition();
            BlockState iblockdata = worldIn.getBlockState(blockposition2);
            IFluidState fluid = worldIn.getFluidState(blockposition2);
            Material material = iblockdata.getMaterial();
            if (fluid.isTagged(FluidTags.WATER)) {
                if (iblockdata.getBlock() instanceof IBucketPickupHandler && ((IBucketPickupHandler) iblockdata.getBlock()).pickupFluid(blockList, blockposition2, iblockdata) != Fluids.EMPTY) {
                // NOP
                } else if (iblockdata.getBlock() instanceof FlowingFluidBlock) {
                // NOP
                } else if (material == Material.OCEAN_PLANT || material == Material.SEA_GRASS) {
                    TileEntity tileentity = iblockdata.getBlock().hasTileEntity(iblockdata) ? worldIn.getTileEntity(blockposition2) : null;
                    Block.spawnDrops(iblockdata, worldIn, blockposition2, tileentity);
                }
            }
            worldIn.setBlockState(blockposition2, block.getHandle(), block.getFlag());
        }
    }
    return i > 0;
}
Also used : IBucketPickupHandler(net.minecraft.block.IBucketPickupHandler) FlowingFluidBlock(net.minecraft.block.FlowingFluidBlock) SpongeAbsorbEvent(org.bukkit.event.block.SpongeAbsorbEvent) BlockStateListPopulator(org.bukkit.craftbukkit.v.util.BlockStateListPopulator) Material(net.minecraft.block.material.Material) Direction(net.minecraft.util.Direction) TileEntity(net.minecraft.tileentity.TileEntity) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) CraftBlockState(org.bukkit.craftbukkit.v.block.CraftBlockState) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) Tuple(net.minecraft.util.Tuple) IFluidState(net.minecraft.fluid.IFluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with IFluidState

use of net.minecraft.fluid.IFluidState in project Arclight by IzzelAliz.

the class ExplosionMixin method doExplosionA.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void doExplosionA() {
    Set<BlockPos> set = Sets.newHashSet();
    int i = 16;
    for (int j = 0; j < 16; ++j) {
        for (int k = 0; k < 16; ++k) {
            for (int l = 0; l < 16; ++l) {
                if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) {
                    double d0 = ((float) j / 15.0F * 2.0F - 1.0F);
                    double d1 = ((float) k / 15.0F * 2.0F - 1.0F);
                    double d2 = ((float) l / 15.0F * 2.0F - 1.0F);
                    double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
                    d0 = d0 / d3;
                    d1 = d1 / d3;
                    d2 = d2 / d3;
                    float f = this.size * (0.7F + this.world.rand.nextFloat() * 0.6F);
                    double d4 = this.x;
                    double d6 = this.y;
                    double d8 = this.z;
                    for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
                        BlockPos blockpos = new BlockPos(d4, d6, d8);
                        BlockState blockstate = this.world.getBlockState(blockpos);
                        IFluidState ifluidstate = this.world.getFluidState(blockpos);
                        if (!blockstate.isAir(this.world, blockpos) || !ifluidstate.isEmpty()) {
                            float f2 = Math.max(blockstate.getExplosionResistance(this.world, blockpos, exploder, (Explosion) (Object) this), ifluidstate.getExplosionResistance(this.world, blockpos, exploder, (Explosion) (Object) this));
                            if (this.exploder != null) {
                                f2 = this.exploder.getExplosionResistance((Explosion) (Object) this, this.world, blockpos, blockstate, ifluidstate, f2);
                            }
                            f -= (f2 + 0.3F) * 0.3F;
                        }
                        if (f > 0.0F && (this.exploder == null || this.exploder.canExplosionDestroyBlock((Explosion) (Object) this, this.world, blockpos, blockstate, f))) {
                            set.add(blockpos);
                        }
                        d4 += d0 * (double) 0.3F;
                        d6 += d1 * (double) 0.3F;
                        d8 += d2 * (double) 0.3F;
                    }
                }
            }
        }
    }
    this.affectedBlockPositions.addAll(set);
    float f3 = this.size * 2.0F;
    int k1 = MathHelper.floor(this.x - (double) f3 - 1.0D);
    int l1 = MathHelper.floor(this.x + (double) f3 + 1.0D);
    int i2 = MathHelper.floor(this.y - (double) f3 - 1.0D);
    int i1 = MathHelper.floor(this.y + (double) f3 + 1.0D);
    int j2 = MathHelper.floor(this.z - (double) f3 - 1.0D);
    int j1 = MathHelper.floor(this.z + (double) f3 + 1.0D);
    List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(this.exploder, new AxisAlignedBB(k1, i2, j2, l1, i1, j1));
    net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.world, (Explosion) (Object) this, list, f3);
    Vec3d vec3d = new Vec3d(this.x, this.y, this.z);
    for (Entity entity : list) {
        if (!entity.isImmuneToExplosions()) {
            double d12 = MathHelper.sqrt(entity.getDistanceSq(vec3d)) / f3;
            if (d12 <= 1.0D) {
                double d5 = entity.posX - this.x;
                double d7 = ((EntityBridge) entity).bridge$getEyeHeight() - this.y;
                double d9 = entity.posZ - this.z;
                double d13 = MathHelper.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
                if (d13 != 0.0D) {
                    d5 = d5 / d13;
                    d7 = d7 / d13;
                    d9 = d9 / d13;
                    double d14 = Explosion.getBlockDensity(vec3d, entity);
                    double d10 = (1.0D - d12) * d14;
                    CraftEventFactory.entityDamage = this.exploder;
                    ((EntityBridge) entity).bridge$setForceExplosionKnockback(false);
                    boolean wasDamaged = entity.attackEntityFrom(this.getDamageSource(), (float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
                    CraftEventFactory.entityDamage = null;
                    if (!wasDamaged && !(entity instanceof TNTEntity || entity instanceof FallingBlockEntity) && !((EntityBridge) entity).bridge$isForceExplosionKnockback()) {
                        continue;
                    }
                    double d11 = d10;
                    if (entity instanceof LivingEntity) {
                        d11 = ProtectionEnchantment.getBlastDamageReduction((LivingEntity) entity, d10);
                    }
                    entity.setMotion(entity.getMotion().add(d5 * d11, d7 * d11, d9 * d11));
                    if (entity instanceof PlayerEntity) {
                        PlayerEntity playerentity = (PlayerEntity) entity;
                        if (!playerentity.isSpectator() && (!playerentity.isCreative() || !playerentity.abilities.isFlying)) {
                            this.playerKnockbackMap.put(playerentity, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
                        }
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) FallingBlockEntity(net.minecraft.entity.item.FallingBlockEntity) TNTEntity(net.minecraft.entity.item.TNTEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) LivingEntity(net.minecraft.entity.LivingEntity) Explosion(net.minecraft.world.Explosion) TNTEntity(net.minecraft.entity.item.TNTEntity) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) IFluidState(net.minecraft.fluid.IFluidState) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with IFluidState

use of net.minecraft.fluid.IFluidState in project Arclight by IzzelAliz.

the class IBlockReaderMixin method rayTraceBlock.

// @formatter:on
default BlockRayTraceResult rayTraceBlock(RayTraceContext context, BlockPos pos) {
    BlockState blockstate = this.getBlockState(pos);
    IFluidState ifluidstate = this.getFluidState(pos);
    Vec3d vec3d = context.getStartVec();
    Vec3d vec3d1 = context.getStartVec();
    VoxelShape voxelshape = context.getBlockShape(blockstate, (IBlockReader) this, pos);
    BlockRayTraceResult blockraytraceresult = this.rayTraceBlocks(vec3d, vec3d1, pos, voxelshape, blockstate);
    VoxelShape voxelshape1 = context.getFluidShape(ifluidstate, (IBlockReader) this, pos);
    BlockRayTraceResult blockraytraceresult1 = voxelshape1.rayTrace(vec3d, vec3d1, pos);
    double d0 = blockraytraceresult == null ? Double.MAX_VALUE : context.getStartVec().squareDistanceTo(blockraytraceresult.getHitVec());
    double d1 = blockraytraceresult1 == null ? Double.MAX_VALUE : context.getStartVec().squareDistanceTo(blockraytraceresult1.getHitVec());
    return d0 <= d1 ? blockraytraceresult : blockraytraceresult1;
}
Also used : BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) IFluidState(net.minecraft.fluid.IFluidState) Vec3d(net.minecraft.util.math.Vec3d)

Example 4 with IFluidState

use of net.minecraft.fluid.IFluidState in project Enigmatic-Legacy by Aizistral-Studios.

the class Megasponge method getCollidedWater.

@SuppressWarnings("deprecation")
public BlockPos getCollidedWater(Tag<Fluid> p_210500_1_, PlayerEntity player) {
    AxisAlignedBB axisalignedbb = player.getBoundingBox().shrink(0.001D);
    int i = MathHelper.floor(axisalignedbb.minX);
    int j = MathHelper.ceil(axisalignedbb.maxX);
    int k = MathHelper.floor(axisalignedbb.minY);
    int l = MathHelper.ceil(axisalignedbb.maxY);
    int i1 = MathHelper.floor(axisalignedbb.minZ);
    int j1 = MathHelper.ceil(axisalignedbb.maxZ);
    BlockPos pos = null;
    if (!player.world.isAreaLoaded(i, k, i1, j, l, j1)) {
        return null;
    } else {
        try (BlockPos.PooledMutableBlockPos blockpos$pooledmutableblockpos = BlockPos.PooledMutableBlockPos.retain()) {
            for (int l1 = i; l1 < j; ++l1) {
                for (int i2 = k; i2 < l; ++i2) {
                    for (int j2 = i1; j2 < j1; ++j2) {
                        blockpos$pooledmutableblockpos.setPos(l1, i2, j2);
                        IFluidState ifluidstate = player.world.getFluidState(blockpos$pooledmutableblockpos);
                        if (ifluidstate.isTagged(p_210500_1_)) {
                            ifluidstate.func_215679_a(player.world, blockpos$pooledmutableblockpos);
                            pos = new BlockPos(l1, i2, j2);
                        }
                    }
                }
            }
        }
        return pos;
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockPos(net.minecraft.util.math.BlockPos) IFluidState(net.minecraft.fluid.IFluidState)

Example 5 with IFluidState

use of net.minecraft.fluid.IFluidState in project xercamods by ercanserteli.

the class BlockRicePlant method isValidGround.

@Override
protected boolean isValidGround(BlockState state, IBlockReader worldIn, BlockPos pos) {
    if (state.getBlock() == Blocks.FARMLAND && state.get(FarmlandBlock.MOISTURE) > 6) {
        int water_count = 0;
        for (Direction direction : Direction.Plane.HORIZONTAL) {
            BlockState blockstate = worldIn.getBlockState(pos.offset(direction));
            IFluidState ifluidstate = worldIn.getFluidState(pos.offset(direction));
            if (ifluidstate.isTagged(FluidTags.WATER) || blockstate.getBlock() == net.minecraft.block.Blocks.FROSTED_ICE) {
                water_count++;
                if (water_count >= 2) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Direction(net.minecraft.util.Direction) IFluidState(net.minecraft.fluid.IFluidState)

Aggregations

IFluidState (net.minecraft.fluid.IFluidState)5 BlockState (net.minecraft.block.BlockState)3 BlockPos (net.minecraft.util.math.BlockPos)3 Direction (net.minecraft.util.Direction)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 Vec3d (net.minecraft.util.math.Vec3d)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 EntityBridge (io.izzel.arclight.common.bridge.entity.EntityBridge)1 List (java.util.List)1 FlowingFluidBlock (net.minecraft.block.FlowingFluidBlock)1 IBucketPickupHandler (net.minecraft.block.IBucketPickupHandler)1 Material (net.minecraft.block.material.Material)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 FallingBlockEntity (net.minecraft.entity.item.FallingBlockEntity)1 TNTEntity (net.minecraft.entity.item.TNTEntity)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Tuple (net.minecraft.util.Tuple)1