Search in sources :

Example 1 with BlockBOPGrass

use of biomesoplenty.common.block.BlockBOPGrass in project BiomesOPlenty by Glitchfiend.

the class EntityAIEatBOPGrass method updateTask.

@Override
public void updateTask() {
    this.bopEatingGrassTimer = Math.max(0, this.bopEatingGrassTimer - 1);
    if (this.bopEatingGrassTimer == 4) {
        BlockPos pos = new BlockPos(this.sheep.posX, this.sheep.posY, this.sheep.posZ);
        IBlockState state = this.world.getBlockState(pos);
        if (IS_TALL_GRASS.apply(state) || IS_SHORT_GRASS.apply(state) || IS_MEDIUM_GRASS.apply(state) || IS_WHEAT_GRASS.apply(state) || IS_DAMP_GRASS.apply(state)) {
            if (this.world.getGameRules().getBoolean("mobGriefing")) {
                this.world.destroyBlock(pos, false);
            }
            this.sheep.eatGrassBonus();
        } else {
            BlockPos posDown = pos.down();
            IBlockState stateDown = world.getBlockState(posDown);
            if (stateDown.getBlock() instanceof BlockBOPGrass) {
                BlockBOPGrass grass = (BlockBOPGrass) stateDown.getBlock();
                Block dirtBlock = BlockBOPGrass.getDirtBlockState(stateDown).getBlock();
                if (dirtBlock instanceof BlockBOPDirt) {
                    if (this.world.getGameRules().getBoolean("mobGriefing")) {
                        this.world.playEvent(2001, posDown, Block.getIdFromBlock(Blocks.GRASS));
                        this.world.setBlockState(posDown, BlockBOPGrass.getDirtBlockState(stateDown), 2);
                    }
                } else if (stateDown.getValue(BlockBOPGrass.VARIANT) == BlockBOPGrass.BOPGrassType.DAISY) {
                    if (this.world.getGameRules().getBoolean("mobGriefing")) {
                        this.world.playEvent(2001, posDown, Block.getIdFromBlock(Blocks.GRASS));
                        this.world.setBlockState(posDown, Blocks.DIRT.getDefaultState(), 2);
                    }
                }
                this.sheep.eatGrassBonus();
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockBOPDirt(biomesoplenty.common.block.BlockBOPDirt) BlockBOPGrass(biomesoplenty.common.block.BlockBOPGrass)

Example 2 with BlockBOPGrass

use of biomesoplenty.common.block.BlockBOPGrass 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 3 with BlockBOPGrass

use of biomesoplenty.common.block.BlockBOPGrass in project BiomesOPlenty by Glitchfiend.

the class GrassPathEventHandler method onBlockRightClick.

@SubscribeEvent
public void onBlockRightClick(PlayerInteractEvent.RightClickBlock event) {
    if (event.getResult() != Event.Result.DEFAULT || event.isCanceled()) {
        return;
    }
    ItemStack stack = event.getItemStack();
    EntityPlayer player = event.getEntityPlayer();
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    EnumFacing facing = event.getFace();
    IBlockState state = world.getBlockState(pos);
    boolean result = false;
    if (state.getBlock() instanceof BlockBOPGrass && stack != null && (stack.getItem() instanceof ItemSpade || stack.getItem().getToolClasses(stack) == Collections.singleton("shovel"))) {
        Block dirtBlock = BlockBOPGrass.getDirtBlockState(state).getBlock();
        if (dirtBlock instanceof BlockBOPDirt) {
            if (facing != EnumFacing.DOWN && world.getBlockState(pos.up()).getMaterial() == Material.AIR) {
                result = true;
                BlockBOPDirt.BOPDirtType dirtType = (BlockBOPDirt.BOPDirtType) BlockBOPGrass.getDirtBlockState(state).getValue(BlockBOPDirt.VARIANT);
                world.setBlockState(pos, BlockBOPGrassPath.paging.getVariantState(dirtType), 11);
            }
        }
    }
    if (result) {
        if (!event.getEntityPlayer().capabilities.isCreativeMode) {
            stack.damageItem(1, player);
        }
        world.playSound(player, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS, 1.0F, 1.0F);
        player.swingArm(PlayerUtil.getHandForItemAndMeta(player, stack.getItem(), stack.getMetadata()));
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) World(net.minecraft.world.World) ItemSpade(net.minecraft.item.ItemSpade) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockBOPDirt(biomesoplenty.common.block.BlockBOPDirt) ItemStack(net.minecraft.item.ItemStack) BlockBOPGrass(biomesoplenty.common.block.BlockBOPGrass) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

BlockBOPDirt (biomesoplenty.common.block.BlockBOPDirt)3 BlockBOPGrass (biomesoplenty.common.block.BlockBOPGrass)3 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 BlockPos (net.minecraft.util.math.BlockPos)3 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 BlockDirt (net.minecraft.block.BlockDirt)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemSpade (net.minecraft.item.ItemSpade)1 ItemStack (net.minecraft.item.ItemStack)1 EnumFacing (net.minecraft.util.EnumFacing)1