Search in sources :

Example 1 with BlockDirt

use of net.minecraft.block.BlockDirt in project BiomesOPlenty by Glitchfiend.

the class UseHoeEventHandler method useHoe.

@SubscribeEvent
public void useHoe(UseHoeEvent event) {
    if (event.getResult() != Event.Result.DEFAULT || event.isCanceled()) {
        return;
    }
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    boolean result = false;
    if (block instanceof BlockBOPDirt && world.isAirBlock(pos.up())) {
        result = true;
        if (state.getValue(BlockBOPDirt.COARSE)) {
            world.setBlockState(pos, state.withProperty(BlockBOPDirt.COARSE, false));
        } else {
            world.setBlockState(pos, BlockBOPFarmland.paging.getVariantState((BlockBOPDirt.BOPDirtType) state.getValue(BlockBOPDirt.VARIANT)));
        }
    } else if (block instanceof BlockBOPGrass && world.isAirBlock(pos.up())) {
        result = true;
        IBlockState dirtState = BlockBOPGrass.getDirtBlockState(state);
        if (dirtState.getBlock() instanceof BlockBOPDirt) {
            BlockBOPDirt.BOPDirtType dirtType = (BlockBOPDirt.BOPDirtType) dirtState.getValue(BlockBOPDirt.VARIANT);
            world.setBlockState(pos, BlockBOPFarmland.paging.getVariantState(dirtType));
        } else if (dirtState.getBlock() instanceof BlockDirt) {
            world.setBlockState(pos, Blocks.FARMLAND.getDefaultState());
        } else {
            // There is no associated farmland, so just turn it to its associated dirt
            // Mostly useful for overgrown grass turning to stone
            world.setBlockState(pos, dirtState);
        }
    }
    if (result) {
        event.setResult(Event.Result.ALLOW);
        world.playSound(event.getEntityPlayer(), pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
        event.getEntityPlayer().swingArm(PlayerUtil.getHandForItemAndMeta(event.getEntityPlayer(), event.getCurrent().getItem(), event.getCurrent().getMetadata()));
        event.getCurrent().damageItem(1, event.getEntityPlayer());
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockBOPDirt(biomesoplenty.common.block.BlockBOPDirt) World(net.minecraft.world.World) BlockBOPGrass(biomesoplenty.common.block.BlockBOPGrass) BlockDirt(net.minecraft.block.BlockDirt) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with BlockDirt

use of net.minecraft.block.BlockDirt in project harvestcraft by MatrexsVigil.

the class TileEntityGroundTrap method countFlowers.

public int countFlowers() {
    byte radius = 2;
    int count = 0;
    // final World world = world;
    final int varX = pos.getX();
    final int varY = pos.getY();
    final int varZ = pos.getZ();
    for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
        for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
            if (offsetX * offsetX + offsetZ * offsetZ <= radius * radius && (offsetX != -(radius - 1) || offsetZ != -(radius - 1)) && (offsetX != radius - 1 || offsetZ != radius - 1) && (offsetX != radius - 1 || offsetZ != -(radius - 1)) && (offsetX != -(radius - 1) || offsetZ != radius - 1)) {
                final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
                if (!world.isBlockLoaded(pos))
                    continue;
                final Block blockAtCoords = world.getBlockState(pos).getBlock();
                if (blockAtCoords instanceof BlockDirt || blockAtCoords instanceof BlockGrass) {
                    count++;
                }
            }
        }
    }
    return count;
}
Also used : BlockGrass(net.minecraft.block.BlockGrass) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockDirt(net.minecraft.block.BlockDirt)

Example 3 with BlockDirt

use of net.minecraft.block.BlockDirt in project harvestcraft by MatrexsVigil.

the class TileEntityGroundTrap method getRunTime.

private int getRunTime() {
    final int radius = 2;
    // final World world = world;
    final int varX = pos.getX();
    final int varY = pos.getY();
    final int varZ = pos.getZ();
    int speed = 3500;
    for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
        for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
            if (offsetX * offsetX + offsetZ * offsetZ > radius * radius || offsetX == -radius - 1 && offsetZ == -radius - 1 || offsetX == radius - 1 && offsetZ == radius - 1 || offsetX == radius - 1 && offsetZ == -radius - 1 || offsetX == -radius - 1 && offsetZ == radius - 1)
                continue;
            final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
            if (!world.isBlockLoaded(pos))
                continue;
            final Block blockAtCoords = world.getBlockState(pos).getBlock();
            if (blockAtCoords instanceof BlockDirt || blockAtCoords instanceof BlockGrass) {
                speed = (int) (speed * 0.95);
            }
            if (blockAtCoords != BlockRegistry.groundtrap)
                continue;
            speed = (int) (speed / 0.85);
        }
    }
    return speed;
}
Also used : BlockGrass(net.minecraft.block.BlockGrass) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockDirt(net.minecraft.block.BlockDirt)

Aggregations

Block (net.minecraft.block.Block)3 BlockDirt (net.minecraft.block.BlockDirt)3 BlockPos (net.minecraft.util.math.BlockPos)3 BlockGrass (net.minecraft.block.BlockGrass)2 BlockBOPDirt (biomesoplenty.common.block.BlockBOPDirt)1 BlockBOPGrass (biomesoplenty.common.block.BlockBOPGrass)1 IBlockState (net.minecraft.block.state.IBlockState)1 World (net.minecraft.world.World)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1