Search in sources :

Example 1 with BlockCrops

use of net.minecraft.block.BlockCrops in project VoodooCraft by Mod-DevCafeTeam.

the class HexGreenFingers method activeUse.

@Override
public ItemStack activeUse(ItemStack stackIn, World world, EntityPlayer player, EnumHand hand, int strength, @Nullable EntityLivingBase target) {
    if (world.isRemote)
        return super.activeUse(stackIn, world, player, hand, strength, target);
    RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
    BlockPos pos = result.getBlockPos();
    Block block = world.getBlockState(pos).getBlock();
    if (block instanceof BlockCrops) {
        if (block instanceof BlockBeetroot) {
            world.setBlockState(pos, block.getDefaultState().cycleProperty(BlockBeetroot.BEETROOT_AGE));
        } else {
            world.setBlockState(pos, block.getDefaultState().cycleProperty(BlockCrops.AGE));
        }
    }
    return super.activeUse(stackIn, world, player, hand, strength, target);
}
Also used : BlockCrops(net.minecraft.block.BlockCrops) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) BlockBeetroot(net.minecraft.block.BlockBeetroot) BlockPos(net.minecraft.util.math.BlockPos)

Example 2 with BlockCrops

use of net.minecraft.block.BlockCrops in project BetterWithAddons by DaedalusGame.

the class BlockCropRice method updateTick.

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    checkAndDropBlock(world, pos, state);
    int meta = state.getValue(AGE);
    double growthChance = 15D;
    if (world.getBlockState(pos.down()).getBlock().isFertile(world, pos.down()))
        growthChance /= 1.33D;
    else if (world.getBlockState(pos.down()).getBlock().canSustainPlant(world.getBlockState(pos.down()), world, pos.down(), EnumFacing.UP, this))
        growthChance /= 1.2D;
    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        IBlockState check = world.getBlockState(pos.offset(facing));
        if (check.getBlock() instanceof BlockCrops)
            growthChance /= 1.1D;
    }
    if (!isMaxAge(state)) {
        if (rand.nextInt(MathHelper.floor(growthChance)) == 0)
            world.setBlockState(pos, state.withProperty(AGE, meta + 1));
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockCrops(net.minecraft.block.BlockCrops) EnumFacing(net.minecraft.util.EnumFacing)

Example 3 with BlockCrops

use of net.minecraft.block.BlockCrops in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method containsPlants.

/**
     * Checks to see if field contains plants.
     *
     * @param field the field to check.
     * @return Boolean if there were plants found.
     */
private boolean containsPlants(final Field field) {
    BlockPos position;
    IBlockState blockState;
    while (handleOffset(field)) {
        // Check to see if the block is a plant, and if it is, break it.
        position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
        blockState = world.getBlockState(position.up());
        if (blockState.getBlock() instanceof BlockCrops) {
            return true;
        }
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockCrops(net.minecraft.block.BlockCrops) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockCrops

use of net.minecraft.block.BlockCrops in project minecolonies by Minecolonies.

the class EntityAIWorkFarmer method initialize.

/**
     * This (re)initializes a field.
     * Checks the block above to see if it is a plant, if so, breaks it. Then tills.
     */
private AIState initialize() {
    @Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
    if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
        return AIState.PREPARING;
    }
    @Nullable final Field field = buildingFarmer.getCurrentField();
    if (workingOffset != null) {
        final BlockPos position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
        // Still moving to the block
        if (walkToBlock(position.up())) {
            return AIState.FARMER_INITIALIZE;
        }
        // Check to see if the block is a plant, and if it is, break it.
        final IBlockState blockState = world.getBlockState(position.up());
        if (blockState.getBlock() instanceof IGrowable && (!(blockState.getBlock() instanceof BlockCrops) || ((BlockCrops) blockState.getBlock()).getItem(world, position.up(), blockState) != field.getSeed())) {
            mineBlock(position.up());
            setDelay(getLevelDelay());
            return AIState.FARMER_INITIALIZE;
        }
        // hoe the block if able to.
        if (hoeIfAble(position, field)) {
            setDelay(getLevelDelay());
            return AIState.FARMER_INITIALIZE;
        }
        if (shouldPlant(position, field) && !plantCrop(field.getSeed(), position)) {
            resetVariables();
            return AIState.PREPARING;
        }
    }
    if (!handleOffset(field)) {
        resetVariables();
        shouldDumpInventory = true;
        field.setInitialized(true);
        field.setNeedsWork(false);
        return AIState.IDLE;
    }
    setDelay(getLevelDelay());
    return AIState.FARMER_INITIALIZE;
}
Also used : BlockHutField(com.minecolonies.coremod.blocks.BlockHutField) IBlockState(net.minecraft.block.state.IBlockState) BlockCrops(net.minecraft.block.BlockCrops) IGrowable(net.minecraft.block.IGrowable) BlockPos(net.minecraft.util.math.BlockPos) BuildingFarmer(com.minecolonies.coremod.colony.buildings.BuildingFarmer) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with BlockCrops

use of net.minecraft.block.BlockCrops in project BetterWithAddons by DaedalusGame.

the class BlockCropRush method updateTick.

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    checkAndDropBlock(world, pos, state);
    BlockPos up = pos.up();
    int meta = state.getValue(AGE);
    double growthChance = 15D;
    if (world.getBlockState(pos.down()).getBlock().isFertile(world, pos.down()))
        growthChance /= 1.33D;
    else if (world.getBlockState(pos.down()).getBlock().canSustainPlant(world.getBlockState(pos.down()), world, pos.down(), EnumFacing.UP, this))
        growthChance /= 1.2D;
    for (EnumFacing facing : EnumFacing.HORIZONTALS) {
        IBlockState check = world.getBlockState(pos.offset(facing));
        if (check.getBlock() instanceof BlockCrops)
            growthChance /= 1.1D;
    }
    if (!isMaxAge(state)) {
        if (world.getLightFromNeighbors(up) > 12) {
            if (rand.nextInt(MathHelper.floor(growthChance)) == 0)
                world.setBlockState(pos, state.withProperty(AGE, meta + 1));
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockCrops(net.minecraft.block.BlockCrops) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockCrops (net.minecraft.block.BlockCrops)5 IBlockState (net.minecraft.block.state.IBlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 EnumFacing (net.minecraft.util.EnumFacing)2 BlockHutField (com.minecolonies.coremod.blocks.BlockHutField)1 BuildingFarmer (com.minecolonies.coremod.colony.buildings.BuildingFarmer)1 Block (net.minecraft.block.Block)1 BlockBeetroot (net.minecraft.block.BlockBeetroot)1 IGrowable (net.minecraft.block.IGrowable)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Nullable (org.jetbrains.annotations.Nullable)1