Search in sources :

Example 31 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project GregTech by GregTechCE.

the class SurfaceRockPopulator method findUndergroundMaterials.

private Set<Material> findUndergroundMaterials(Collection<IBlockState> generatedBlocks) {
    HashSet<Material> result = new HashSet<>();
    for (IBlockState blockState : generatedBlocks) {
        Material resultMaterial;
        if (blockState.getBlock() instanceof IFluidBlock || blockState.getBlock() instanceof BlockLiquid) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(blockState.getBlock());
            resultMaterial = fluid == null ? null : MetaFluids.getMaterialFromFluid(fluid);
        } else {
            ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().damageDropped(blockState));
            UnificationEntry entry = OreDictUnifier.getUnificationEntry(itemStack);
            resultMaterial = entry == null ? null : entry.material;
        }
        if (resultMaterial != null) {
            result.add(resultMaterial);
        }
    }
    return result;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Fluid(net.minecraftforge.fluids.Fluid) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.type.Material) ItemStack(net.minecraft.item.ItemStack)

Example 32 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project GregTech by GregTechCE.

the class WorldGenRubberTree method generate.

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
    if (world.getWorldType() == WorldType.FLAT || !world.provider.isSurfaceWorld()) {
        // do not generate in flat worlds, or in non-surface worlds
        return;
    }
    BlockPos randomPos = new BlockPos(chunkX * 16 + 8, 0, chunkZ * 16 + 8);
    Biome biome = world.getBiome(randomPos);
    if (BiomeDictionary.hasType(biome, Type.COLD) || BiomeDictionary.hasType(biome, Type.HOT) || BiomeDictionary.hasType(biome, Type.DRY) || BiomeDictionary.hasType(biome, Type.DEAD) || BiomeDictionary.hasType(biome, Type.SPOOKY))
        // do not generate in inappropriate biomes
        return;
    int rubberTreeChance = 6;
    if (BiomeDictionary.hasType(biome, Type.SWAMP) || BiomeDictionary.hasType(biome, Type.WET))
        // double chance of spawning in swamp or wet biomes
        rubberTreeChance /= 2;
    if (random.nextInt(rubberTreeChance) == 0) {
        randomPos = world.getTopSolidOrLiquidBlock(randomPos).down();
        IBlockState solidBlockState = world.getBlockState(randomPos);
        BlockGregSapling sapling = MetaBlocks.SAPLING;
        if (solidBlockState.getBlock().canSustainPlant(solidBlockState, world, randomPos, EnumFacing.UP, sapling)) {
            BlockPos abovePos = randomPos.up();
            IBlockState aboveState = world.getBlockState(abovePos);
            if (aboveState.getBlock() instanceof BlockLiquid) {
                return;
            }
            IBlockState saplingState = sapling.getDefaultState().withProperty(BlockGregSapling.VARIANT, LogVariant.RUBBER_WOOD);
            world.setBlockState(abovePos, saplingState);
            sapling.generateTree(world, abovePos, saplingState, random);
        }
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockPos(net.minecraft.util.math.BlockPos) BlockGregSapling(gregtech.common.blocks.wood.BlockGregSapling)

Example 33 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MinecraftForge by MinecraftForge.

the class FluidUtil method tryPickUpFluid.

/**
     * Attempts to pick up a fluid in the world and put it in an empty container item.
     *
     * @param emptyContainer The empty container to fill.
     *                       Will not be modified directly, if modifications are necessary a modified copy is returned in the result.
     * @param playerIn       The player filling the container. Optional.
     * @param worldIn        The world the fluid is in.
     * @param pos            The position of the fluid in the world.
     * @param side           The side of the fluid that is being drained.
     * @return a {@link FluidActionResult} holding the result and the resulting container.
     */
@Nonnull
public static FluidActionResult tryPickUpFluid(@Nonnull ItemStack emptyContainer, @Nullable EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side) {
    if (emptyContainer.isEmpty() || worldIn == null || pos == null) {
        return FluidActionResult.FAILURE;
    }
    IBlockState state = worldIn.getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof IFluidBlock || block instanceof BlockLiquid) {
        IFluidHandler targetFluidHandler = FluidUtil.getFluidHandler(worldIn, pos, side);
        if (targetFluidHandler != null) {
            FluidActionResult fluidActionResult = FluidUtil.tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true);
            if (fluidActionResult.isSuccess()) {
                return fluidActionResult;
            }
        }
    }
    return FluidActionResult.FAILURE;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) Block(net.minecraft.block.Block) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Nonnull(javax.annotation.Nonnull)

Example 34 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class CallRunner method onExplosionA.

public static void onExplosionA(Explosion e) {
    Vector center = new Vector(e.explosionX, e.explosionY, e.explosionZ);
    World worldIn = e.worldObj;
    float radius = e.explosionSize;
    AxisAlignedBB toCheck = new AxisAlignedBB(center.X - radius, center.Y - radius, center.Z - radius, center.X + radius, center.Y + radius, center.Z + radius);
    List<PhysicsWrapperEntity> shipsNear = ValkyrienWarfareMod.physicsManager.getManagerForWorld(e.worldObj).getNearbyPhysObjects(toCheck);
    e.doExplosionA();
    // TODO: Make this compatible and shit!
    for (PhysicsWrapperEntity ship : shipsNear) {
        Vector inLocal = new Vector(center);
        RotationMatrices.applyTransform(ship.wrapping.coordTransform.wToLTransform, inLocal);
        // inLocal.roundToWhole();
        Explosion expl = new Explosion(ship.worldObj, null, inLocal.X, inLocal.Y, inLocal.Z, radius, false, false);
        double waterRange = .6D;
        boolean cancelDueToWater = false;
        for (int x = (int) Math.floor(expl.explosionX - waterRange); x <= Math.ceil(expl.explosionX + waterRange); x++) {
            for (int y = (int) Math.floor(expl.explosionY - waterRange); y <= Math.ceil(expl.explosionY + waterRange); y++) {
                for (int z = (int) Math.floor(expl.explosionZ - waterRange); z <= Math.ceil(expl.explosionZ + waterRange); z++) {
                    if (!cancelDueToWater) {
                        IBlockState state = e.worldObj.getBlockState(new BlockPos(x, y, z));
                        if (state.getBlock() instanceof BlockLiquid) {
                            cancelDueToWater = true;
                        }
                    }
                }
            }
        }
        expl.doExplosionA();
        double affectedPositions = 0D;
        for (Object o : expl.affectedBlockPositions) {
            BlockPos pos = (BlockPos) o;
            IBlockState state = ship.worldObj.getBlockState(pos);
            Block block = state.getBlock();
            if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
                affectedPositions++;
            }
        }
        if (!cancelDueToWater) {
            for (Object o : expl.affectedBlockPositions) {
                BlockPos pos = (BlockPos) o;
                IBlockState state = ship.worldObj.getBlockState(pos);
                Block block = state.getBlock();
                if (!block.isAir(state, worldIn, (BlockPos) o) || ship.wrapping.explodedPositionsThisTick.contains((BlockPos) o)) {
                    if (block.canDropFromExplosion(expl)) {
                        block.dropBlockAsItemWithChance(ship.worldObj, pos, state, 1.0F / expl.explosionSize, 0);
                    }
                    block.onBlockExploded(ship.worldObj, pos, expl);
                    if (!worldIn.isRemote) {
                        Vector posVector = new Vector(pos.getX() + .5, pos.getY() + .5, pos.getZ() + .5);
                        ship.wrapping.coordTransform.fromLocalToGlobal(posVector);
                        double mass = BlockMass.basicMass.getMassFromState(state, pos, ship.worldObj);
                        double explosionForce = Math.sqrt(e.explosionSize) * 1000D * mass;
                        Vector forceVector = new Vector(pos.getX() + .5 - expl.explosionX, pos.getY() + .5 - expl.explosionY, pos.getZ() + .5 - expl.explosionZ);
                        double vectorDist = forceVector.length();
                        forceVector.normalize();
                        forceVector.multiply(explosionForce / vectorDist);
                        RotationMatrices.doRotationOnly(ship.wrapping.coordTransform.lToWRotation, forceVector);
                        PhysicsQueuedForce queuedForce = new PhysicsQueuedForce(forceVector, posVector, false, 1);
                        if (!ship.wrapping.explodedPositionsThisTick.contains(pos)) {
                            ship.wrapping.explodedPositionsThisTick.add(pos);
                        }
                        ship.wrapping.queueForce(queuedForce);
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Explosion(net.minecraft.world.Explosion) IBlockState(net.minecraft.block.state.IBlockState) World(net.minecraft.world.World) BlockLiquid(net.minecraft.block.BlockLiquid) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) PhysicsQueuedForce(ValkyrienWarfareBase.Physics.PhysicsQueuedForce) Vector(ValkyrienWarfareBase.API.Vector)

Example 35 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project RFToolsDimensions by McJty.

the class DimensionInformation method getDisplayName.

public static String getDisplayName(IBlockState state) {
    if (state == null) {
        return "null";
    }
    Block block = state.getBlock();
    String suffix = "";
    if ("chisel".equals(block.getRegistryName().getResourceDomain()) && RFToolsDim.chisel) {
        // Special case for chisel as it has the same name as the base block for all its variants
        String readableName = ChiselCompat.getReadableName(state);
        if (readableName != null) {
            suffix = ", " + readableName;
        }
    }
    if (block instanceof BlockLiquid) {
        Fluid fluid = FluidRegistry.lookupFluidForBlock(block);
        if (fluid != null) {
            FluidStack stack = new FluidStack(fluid, 1);
            return stack.getLocalizedName() + suffix;
        }
    }
    ItemStack itemStack = new ItemStack(block, 1, block.getMetaFromState(state));
    if (itemStack.isEmpty()) {
        return block.getLocalizedName() + suffix;
    }
    return itemStack.getDisplayName() + suffix;
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BlockLiquid (net.minecraft.block.BlockLiquid)57 IBlockState (net.minecraft.block.state.IBlockState)44 Block (net.minecraft.block.Block)27 BlockPos (net.minecraft.util.math.BlockPos)22 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)20 Material (net.minecraft.block.material.Material)11 ItemStack (net.minecraft.item.ItemStack)8 EnumFacing (net.minecraft.util.EnumFacing)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 BlockPos (net.minecraft.util.BlockPos)4 BlockFluidBase (net.minecraftforge.fluids.BlockFluidBase)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)4 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 Entity (net.minecraft.entity.Entity)3 World (net.minecraft.world.World)3 IPlantable (net.minecraftforge.common.IPlantable)3 Location (com.builtbroken.mc.imp.transform.vector.Location)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2