Search in sources :

Example 21 with IBlockState

use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.

the class DynBucketTest method onBucketFill.

@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
    RayTraceResult target = event.getTarget();
    if (target != null) {
        IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
        if (state.getBlock() instanceof IFluidBlock) {
            Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
            FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
            ItemStack bucket = event.getEmptyBucket();
            IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(bucket);
            if (fluidHandler != null) {
                int fillAmount = fluidHandler.fill(fs, true);
                if (fillAmount > 0) {
                    ItemStack filledBucket = fluidHandler.getContainer();
                    event.setFilledBucket(filledBucket);
                    event.setResult(Result.ALLOW);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Fluid(net.minecraftforge.fluids.Fluid) TestFluid(net.minecraftforge.debug.ModelFluidDebug.TestFluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 22 with IBlockState

use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.

the class WorldGenSeaweed method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    IBlockState b;
    if (canGenerateAt(world, pos)) {
        BlockPos p;
        int direction;
        if (seaweedBlock.getBlock().canPlaceBlockAt(world, pos)) {
            world.setBlockState(pos, seaweedBlock, 2);
        }
        for (int i = 0; i < height; i++) {
            direction = rand.nextInt(4);
            switch(direction) {
                case 0:
                    x -= 1;
                    break;
                case 1:
                    x += 1;
                    break;
                case 2:
                    z -= 1;
                    break;
                case 3:
                    z += 1;
                    break;
                default:
                    // Straight up.
                    ;
                    break;
            }
            p = new BlockPos(x, y + i, z);
            b = world.getBlockState(p);
            if (b == Blocks.WATER.getDefaultState()) {
                if (seaweedBlock.getBlock().canPlaceBlockAt(world, p)) {
                    world.setBlockState(p, seaweedBlock, 2);
                }
            }
        }
    }
    return true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 23 with IBlockState

use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.

the class WorldGenShrubRTG method buildLeaves.

public void buildLeaves(World world, int x, int y, int z, int size) {
    IBlockState b = world.getBlockState(new BlockPos(x, y - 2, z));
    IBlockState b1 = world.getBlockState(new BlockPos(x, y - 1, z));
    if ((b == Blocks.SAND.getDefaultState() || b1 == Blocks.SAND.getDefaultState()) && !rtgConfig.ALLOW_TREES_TO_GENERATE_ON_SAND.get()) {
        return;
    }
    if (b.getMaterial() == Material.GRASS || b.getMaterial() == Material.GROUND || (varSand && b.getMaterial() == Material.SAND)) {
        if (b1 != Blocks.WATER.getDefaultState()) {
            if (!rtgConfig.ALLOW_SHRUBS_TO_GENERATE_BELOW_SURFACE.get()) {
                if (b1.getMaterial() != Material.AIR && b1.getMaterial() != Material.VINE && b1.getMaterial() != Material.PLANTS && b1 != Blocks.SNOW_LAYER.getDefaultState()) {
                    return;
                }
            }
            for (int i = -size; i <= size; i++) {
                for (int j = -1; j <= 1; j++) {
                    for (int k = -size; k <= size; k++) {
                        if (Math.abs(i) + Math.abs(j) + Math.abs(k) <= size) {
                            buildBlock(world, x + i, y + j, z + k, leaveBlock);
                        }
                    }
                }
            }
            world.setBlockState(new BlockPos(x, y - 1, z), logBlock, 0);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 24 with IBlockState

use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.

the class WorldGenSponge method generate.

@Override
public boolean generate(World world, Random rand, BlockPos pos) {
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();
    while (true) {
        if (y > 3) {
            label63: {
                if (!world.isAirBlock(new BlockPos(x, y - 1, z))) {
                    IBlockState block = world.getBlockState(new BlockPos(x, y - 1, z));
                    if (validGroundBlocks.contains(block.getBlock())) {
                        break label63;
                    }
                }
                --y;
                continue;
            }
        }
        if (y <= 3) {
            return false;
        }
        int k2 = this.spongeSize;
        for (int l = 0; k2 >= 0 && l < 3; ++l) {
            int i1 = k2 + rand.nextInt(2);
            int j1 = k2 + rand.nextInt(2);
            int k1 = k2 + rand.nextInt(2);
            float f = (float) (i1 + j1 + k1) * 0.333F + 0.5F;
            for (int l1 = x - i1; l1 <= x + i1; ++l1) {
                for (int i2 = z - k1; i2 <= z + k1; ++i2) {
                    for (int j2 = y - j1; j2 <= y + j1; ++j2) {
                        float f1 = (float) (l1 - x);
                        float f2 = (float) (i2 - z);
                        float f3 = (float) (j2 - y);
                        if (f1 * f1 + f2 * f2 + f3 * f3 <= f * f) {
                            if (isAdjacent(world, l1, j2, i2)) {
                                world.setBlockState(new BlockPos(l1, j2, i2), spongeBlock, 2);
                            //Logger.debug("Sponge generated at %d %d %d", l1, j2, i2);
                            }
                        }
                    }
                }
            }
            x += -(k2 + 1) + rand.nextInt(2 + k2 * 2);
            z += -(k2 + 1) + rand.nextInt(2 + k2 * 2);
            y += 0 - rand.nextInt(2);
        }
        return true;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 25 with IBlockState

use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.

the class WorldGenVinesRTG method addVine.

protected void addVine(World worldIn, Random rand, BlockPos pos, EnumFacing enumfacing) {
    IBlockState iblockstate = this.vineBlock.getDefaultState().withProperty(this.propNorth, enumfacing == EnumFacing.SOUTH).withProperty(this.propEast, enumfacing == EnumFacing.WEST).withProperty(this.propSouth, enumfacing == EnumFacing.NORTH).withProperty(this.propWest, enumfacing == EnumFacing.EAST);
    this.setBlockAndNotifyAdequately(worldIn, pos, iblockstate);
    int i = rand.nextInt(4) + 1;
    for (pos = pos.down(); worldIn.isAirBlock(pos) && i > 0; --i) {
        this.setBlockAndNotifyAdequately(worldIn, pos, iblockstate);
        pos = pos.down();
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)798 BlockPos (net.minecraft.util.math.BlockPos)325 Block (net.minecraft.block.Block)246 ItemStack (net.minecraft.item.ItemStack)118 TileEntity (net.minecraft.tileentity.TileEntity)84 EnumFacing (net.minecraft.util.EnumFacing)81 World (net.minecraft.world.World)66 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)42 EntityPlayer (net.minecraft.entity.player.EntityPlayer)34 Entity (net.minecraft.entity.Entity)30 Random (java.util.Random)28 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)28 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)28 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)23 ArrayList (java.util.ArrayList)22 Vec3d (net.minecraft.util.math.Vec3d)22 SoundType (net.minecraft.block.SoundType)21 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)21 ResourceLocation (net.minecraft.util.ResourceLocation)21 RayTraceResult (net.minecraft.util.math.RayTraceResult)21