Search in sources :

Example 1 with Material

use of net.minecraft.block.material.Material in project MinecraftForge by MinecraftForge.

the class FluidUtil method tryPlaceFluid.

/**
     * Tries to place a fluid in the world in block form and drains the container.
     * Makes a fluid emptying sound when successful.
     * Honors the amount of fluid contained by the used container.
     * Checks if water-like fluids should vaporize like in the nether.
     *
     * Modeled after {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
     *
     * @param player    Player who places the fluid. May be null for blocks like dispensers.
     * @param world     World to place the fluid in
     * @param pos       The position in the world to place the fluid block
     * @param container The fluid container holding the fluidStack to place
     * @param resource  The fluidStack to place
     * @return the container's ItemStack with the remaining amount of fluid if the placement was successful, null otherwise
     */
@Nonnull
public static FluidActionResult tryPlaceFluid(@Nullable EntityPlayer player, World world, BlockPos pos, @Nonnull ItemStack container, FluidStack resource) {
    if (world == null || resource == null || pos == null) {
        return FluidActionResult.FAILURE;
    }
    Fluid fluid = resource.getFluid();
    if (fluid == null || !fluid.canBePlacedInWorld()) {
        return FluidActionResult.FAILURE;
    }
    // check that we can place the fluid at the destination
    IBlockState destBlockState = world.getBlockState(pos);
    Material destMaterial = destBlockState.getMaterial();
    boolean isDestNonSolid = !destMaterial.isSolid();
    boolean isDestReplaceable = destBlockState.getBlock().isReplaceable(world, pos);
    if (!world.isAirBlock(pos) && !isDestNonSolid && !isDestReplaceable) {
        // Non-air, solid, unreplacable block. We can't put fluid here.
        return FluidActionResult.FAILURE;
    }
    if (world.provider.doesWaterVaporize() && fluid.doesVaporize(resource)) {
        fluid.vaporize(player, world, pos, resource);
        return tryEmptyContainer(container, new VoidFluidHandler(), Integer.MAX_VALUE, player, true);
    } else {
        if (!world.isRemote && (isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid()) {
            world.destroyBlock(pos, true);
        }
        // Defer the placement to the fluid block
        // Instead of actually "filling", the fluid handler method replaces the block
        Block block = fluid.getBlock();
        IFluidHandler handler;
        if (block instanceof IFluidBlock) {
            handler = new FluidBlockWrapper((IFluidBlock) block, world, pos);
        } else if (block instanceof BlockLiquid) {
            handler = new BlockLiquidWrapper((BlockLiquid) block, world, pos);
        } else {
            handler = new BlockWrapper(block, world, pos);
        }
        FluidActionResult result = tryEmptyContainer(container, handler, Integer.MAX_VALUE, player, true);
        if (result.isSuccess()) {
            SoundEvent soundevent = fluid.getEmptySound(resource);
            world.playSound(player, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
        }
        return result;
    }
}
Also used : VoidFluidHandler(net.minecraftforge.fluids.capability.templates.VoidFluidHandler) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BlockWrapper(net.minecraftforge.fluids.capability.wrappers.BlockWrapper) IBlockState(net.minecraft.block.state.IBlockState) Material(net.minecraft.block.material.Material) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) SoundEvent(net.minecraft.util.SoundEvent) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLiquidWrapper(net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper) Block(net.minecraft.block.Block) Nonnull(javax.annotation.Nonnull)

Example 2 with Material

use of net.minecraft.block.material.Material in project MinecraftForge by MinecraftForge.

the class BlockFluidBase method displaceIfPossible.

/**
     * Attempt to displace the block at (pos), return true if it was displaced.
     */
public boolean displaceIfPossible(World world, BlockPos pos) {
    if (world.isAirBlock(pos)) {
        return true;
    }
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (block == this) {
        return false;
    }
    if (displacements.containsKey(block)) {
        if (displacements.get(block)) {
            if (//Forge: Vanilla has a 'bug' where snowballs don't drop like every other block. So special case because ewww...
            state.getBlock() != Blocks.SNOW_LAYER)
                block.dropBlockAsItem(world, pos, state, 0);
            return true;
        }
        return false;
    }
    Material material = state.getMaterial();
    if (material.blocksMovement() || material == Material.PORTAL) {
        return false;
    }
    int density = getDensity(world, pos);
    if (density == Integer.MAX_VALUE) {
        block.dropBlockAsItem(world, pos, state, 0);
        return true;
    }
    if (this.density > density) {
        return true;
    } else {
        return false;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) Material(net.minecraft.block.material.Material)

Example 3 with Material

use of net.minecraft.block.material.Material in project MinecraftForge by MinecraftForge.

the class BlockFluidClassic method canFlowInto.

protected boolean canFlowInto(IBlockAccess world, BlockPos pos) {
    if (world.isAirBlock(pos))
        return true;
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() == this) {
        return true;
    }
    if (displacements.containsKey(state.getBlock())) {
        return displacements.get(state.getBlock());
    }
    Material material = state.getMaterial();
    if (material.blocksMovement() || material == Material.WATER || material == Material.LAVA || material == Material.PORTAL) {
        return false;
    }
    int density = getDensity(world, pos);
    if (density == Integer.MAX_VALUE) {
        return true;
    }
    if (this.density > density) {
        return true;
    } else {
        return false;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Material(net.minecraft.block.material.Material)

Example 4 with Material

use of net.minecraft.block.material.Material in project MinecraftForge by MinecraftForge.

the class BlockLiquidWrapper method fill.

@Override
public int fill(FluidStack resource, boolean doFill) {
    // NOTE: "Filling" means placement in this context!
    if (resource.amount < Fluid.BUCKET_VOLUME) {
        return 0;
    }
    if (doFill) {
        Material material = blockLiquid.getDefaultState().getMaterial();
        BlockLiquid block = BlockLiquid.getStaticBlock(material);
        world.setBlockState(blockPos, block.getDefaultState().withProperty(BlockLiquid.LEVEL, 0), 11);
    }
    return Fluid.BUCKET_VOLUME;
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) Material(net.minecraft.block.material.Material)

Example 5 with Material

use of net.minecraft.block.material.Material in project MineFactoryReloaded by powercrystals.

the class WorldGenLakesMeta method generate.

@Override
public boolean generate(World world, Random random, int x, int y, int z) {
    x -= 8;
    for (z -= 8; y > 5 && world.isAirBlock(x, y, z); --y) {
        ;
    }
    if (y <= 4) {
        return false;
    } else {
        y -= 4;
        boolean[] aboolean = new boolean[2048];
        int l = random.nextInt(4) + 4;
        int i1;
        for (i1 = 0; i1 < l; ++i1) {
            double d0 = random.nextDouble() * 6.0D + 3.0D;
            double d1 = random.nextDouble() * 4.0D + 2.0D;
            double d2 = random.nextDouble() * 6.0D + 3.0D;
            double d3 = random.nextDouble() * (16.0D - d0 - 2.0D) + 1.0D + d0 / 2.0D;
            double d4 = random.nextDouble() * (8.0D - d1 - 4.0D) + 2.0D + d1 / 2.0D;
            double d5 = random.nextDouble() * (16.0D - d2 - 2.0D) + 1.0D + d2 / 2.0D;
            for (int j1 = 1; j1 < 15; ++j1) {
                for (int k1 = 1; k1 < 15; ++k1) {
                    for (int l1 = 1; l1 < 7; ++l1) {
                        double d6 = (j1 - d3) / (d0 / 2.0D);
                        double d7 = (l1 - d4) / (d1 / 2.0D);
                        double d8 = (k1 - d5) / (d2 / 2.0D);
                        double d9 = d6 * d6 + d7 * d7 + d8 * d8;
                        if (d9 < 1.0D) {
                            aboolean[(j1 * 16 + k1) * 8 + l1] = true;
                        }
                    }
                }
            }
        }
        int i2;
        int j2;
        boolean flag;
        for (i1 = 0; i1 < 16; ++i1) {
            for (j2 = 0; j2 < 16; ++j2) {
                for (i2 = 0; i2 < 8; ++i2) {
                    flag = !aboolean[(i1 * 16 + j2) * 8 + i2] && (i1 < 15 && aboolean[((i1 + 1) * 16 + j2) * 8 + i2] || i1 > 0 && aboolean[((i1 - 1) * 16 + j2) * 8 + i2] || j2 < 15 && aboolean[(i1 * 16 + j2 + 1) * 8 + i2] || j2 > 0 && aboolean[(i1 * 16 + (j2 - 1)) * 8 + i2] || i2 < 7 && aboolean[(i1 * 16 + j2) * 8 + i2 + 1] || i2 > 0 && aboolean[(i1 * 16 + j2) * 8 + (i2 - 1)]);
                    if (flag) {
                        Material material = world.getBlockMaterial(x + i1, y + i2, z + j2);
                        if (i2 >= 4 && material.isLiquid()) {
                            return false;
                        }
                        if (i2 < 4 && !material.isSolid() && world.getBlockId(x + i1, y + i2, z + j2) != _blockId) {
                            return false;
                        }
                    }
                }
            }
        }
        for (i1 = 0; i1 < 16; ++i1) {
            for (j2 = 0; j2 < 16; ++j2) {
                for (i2 = 0; i2 < 8; ++i2) {
                    if (aboolean[(i1 * 16 + j2) * 8 + i2]) {
                        world.setBlock(x + i1, y + i2, z + j2, i2 >= 4 ? 0 : _blockId, _blockMeta, 2);
                    }
                }
            }
        }
        for (i1 = 0; i1 < 16; ++i1) {
            for (j2 = 0; j2 < 16; ++j2) {
                for (i2 = 4; i2 < 8; ++i2) {
                    if (aboolean[(i1 * 16 + j2) * 8 + i2] && world.getBlockId(x + i1, y + i2 - 1, z + j2) == Block.dirt.blockID && world.getSavedLightValue(EnumSkyBlock.Sky, x + i1, y + i2, z + j2) > 0) {
                        BiomeGenBase biomegenbase = world.getBiomeGenForCoords(x + i1, z + j2);
                        if (biomegenbase.topBlock == Block.mycelium.blockID) {
                            world.setBlock(x + i1, y + i2 - 1, z + j2, Block.mycelium.blockID, 0, 2);
                        } else {
                            world.setBlock(x + i1, y + i2 - 1, z + j2, Block.grass.blockID, 0, 2);
                        }
                    }
                }
            }
        }
        return true;
    }
}
Also used : Material(net.minecraft.block.material.Material) BiomeGenBase(net.minecraft.world.biome.BiomeGenBase)

Aggregations

Material (net.minecraft.block.material.Material)31 IBlockState (net.minecraft.block.state.IBlockState)11 Block (net.minecraft.block.Block)9 BlockPos (net.minecraft.util.math.BlockPos)9 BlockLiquid (net.minecraft.block.BlockLiquid)6 ItemStack (net.minecraft.item.ItemStack)6 World (net.minecraft.world.World)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 DirectionalBlockPos (blusunrize.immersiveengineering.api.DirectionalBlockPos)1 IPos3D (com.builtbroken.jlib.data.vector.IPos3D)1 Location (com.builtbroken.mc.imp.transform.vector.Location)1 Pos (com.builtbroken.mc.imp.transform.vector.Pos)1 PlacementData (com.builtbroken.mc.lib.world.edit.PlacementData)1 FMLControlledNamespacedRegistry (cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry)1 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)1 ThreadLargeExplosion (icbm.classic.content.explosive.thread.ThreadLargeExplosion)1 IThreadCallBack (icbm.classic.content.explosive.thread.ThreadLargeExplosion.IThreadCallBack)1 MaterialNegativeSpace (ivorius.reccomplex.block.materials.MaterialNegativeSpace)1