Search in sources :

Example 1 with BlockCropsMP

use of stevekung.mods.moreplanets.util.blocks.BlockCropsMP in project MorePlanets by SteveKunG.

the class EntityAINibiruVillagerHarvestFarmland method shouldMoveTo.

@Override
protected boolean shouldMoveTo(World world, BlockPos pos) {
    Block block = world.getBlockState(pos).getBlock();
    if (block == NibiruBlocks.INFECTED_FARMLAND) {
        pos = pos.up();
        IBlockState iblockstate = world.getBlockState(pos);
        block = iblockstate.getBlock();
        if (block instanceof BlockCropsMP && iblockstate.getValue(BlockCropsMP.AGE).intValue() == 7 && this.field_179503_e && (this.field_179501_f == 0 || this.field_179501_f < 0)) {
            this.field_179501_f = 0;
            return true;
        }
        if (block == Blocks.AIR && this.hasFarmItem && (this.field_179501_f == 1 || this.field_179501_f < 0)) {
            this.field_179501_f = 1;
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockCropsMP(stevekung.mods.moreplanets.util.blocks.BlockCropsMP) EntityAIMoveToBlock(net.minecraft.entity.ai.EntityAIMoveToBlock) Block(net.minecraft.block.Block)

Example 2 with BlockCropsMP

use of stevekung.mods.moreplanets.util.blocks.BlockCropsMP in project MorePlanets by SteveKunG.

the class EntityAINibiruVillagerHarvestFarmland method updateTask.

@Override
public void updateTask() {
    super.updateTask();
    this.theVillager.getLookHelper().setLookPosition(this.destinationBlock.getX() + 0.5D, this.destinationBlock.getY() + 1, this.destinationBlock.getZ() + 0.5D, 10.0F, this.theVillager.getVerticalFaceSpeed());
    if (this.getIsAboveDestination()) {
        World world = this.theVillager.world;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();
        if (this.field_179501_f == 0 && block instanceof BlockCropsMP && iblockstate.getValue(BlockCropsMP.AGE).intValue() == 7) {
            world.destroyBlock(blockpos, true);
        } else if (this.field_179501_f == 1 && block == Blocks.AIR) {
            InventoryBasic inventorybasic = this.theVillager.getVillagerInventory();
            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i) {
                ItemStack itemStack = inventorybasic.getStackInSlot(i);
                boolean flag = false;
                if (!itemStack.isEmpty()) {
                    if (itemStack.getItem() == NibiruItems.INFECTED_WHEAT_SEEDS) {
                        world.setBlockState(blockpos, NibiruBlocks.INFECTED_WHEAT_BLOCK.getDefaultState(), 3);
                        flag = true;
                    } else if (itemStack.getItem() == NibiruItems.NIBIRU_FRUITS && itemStack.getItemDamage() == 6) {
                        world.setBlockState(blockpos, NibiruBlocks.TERRABERRY_BLOCK.getDefaultState(), 3);
                        flag = true;
                    }
                }
                if (flag) {
                    itemStack.shrink(1);
                    if (itemStack.getCount() <= 0) {
                        inventorybasic.setInventorySlotContents(i, ItemStack.EMPTY);
                    }
                    break;
                }
            }
        }
        this.field_179501_f = -1;
        this.runDelay = 10;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockCropsMP(stevekung.mods.moreplanets.util.blocks.BlockCropsMP) EntityAIMoveToBlock(net.minecraft.entity.ai.EntityAIMoveToBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) InventoryBasic(net.minecraft.inventory.InventoryBasic)

Aggregations

Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityAIMoveToBlock (net.minecraft.entity.ai.EntityAIMoveToBlock)2 BlockCropsMP (stevekung.mods.moreplanets.util.blocks.BlockCropsMP)2 InventoryBasic (net.minecraft.inventory.InventoryBasic)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1