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();
}
}
}
}
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());
}
}
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()));
}
}
Aggregations