net.minecraft.block.BlockCrops Java Examples

The following examples show how to use net.minecraft.block.BlockCrops. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityAIHarvestTofuFarmland.java    From TofuCraftReload with MIT License 6 votes vote down vote up
/**
 * Return true to set given position as destination
 */
protected boolean shouldMoveTo(World worldIn, BlockPos pos)
{
    Block block = worldIn.getBlockState(pos).getBlock();

    if (block == Blocks.FARMLAND || block == BlockLoader.TOFUFARMLAND)
    {
        pos = pos.up();
        IBlockState iblockstate = worldIn.getBlockState(pos);
        block = iblockstate.getBlock();

        if (block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate) && this.wantsToReapStuff && (this.currentTask == 0 || this.currentTask < 0))
        {
            this.currentTask = 0;
            return true;
        }

        if (iblockstate.getMaterial() == Material.AIR && this.hasFarmItem && (this.currentTask == 1 || this.currentTask < 0))
        {
            this.currentTask = 1;
            return true;
        }
    }

    return false;
}
 
Example #2
Source File: ToolSense.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean canMineBlock(IBlockState block, ItemStack stack) {
    return block.getMaterial() == Material.PLANTS ||
        block.getMaterial() == Material.LEAVES ||
        block.getMaterial() == Material.VINE ||
        block.getBlock() instanceof BlockCrops;
}
 
Example #3
Source File: ToolSense.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onBlockPreBreak(ItemStack stack, BlockPos blockPos, EntityPlayer player) {
    if (player.world.isRemote || player.capabilities.isCreativeMode) {
        return false;
    }
    ToolMetaItem<?> toolMetaItem = (ToolMetaItem<?>) stack.getItem();
    int damagePerBlockBreak = getToolDamagePerBlockBreak(stack);
    for(int x = -5; x <= 5; x++) {
        for(int z = -5; z <= 5; z++) {
            for(int y = -5; y <= 5; y++) {BlockPos offsetPos = blockPos.add(x, y, z);
                IBlockState blockState = player.world.getBlockState(offsetPos);
                if(player.world.isBlockModifiable(player, offsetPos) && toolMetaItem.isUsable(stack, damagePerBlockBreak)) {
                    if(blockState.getBlock() instanceof BlockCrops) {

                        player.world.playEvent(2001, offsetPos, Block.getStateId(blockState));
                        ToolUtility.applyHarvestBehavior(offsetPos, player);
                        toolMetaItem.damageItem(stack, damagePerBlockBreak, false);

                    } else if(blockState.getMaterial() == Material.PLANTS ||
                        blockState.getMaterial() == Material.LEAVES ||
                        blockState.getMaterial() == Material.VINE) {

                        player.world.playEvent(2001, offsetPos, Block.getStateId(blockState));
                        player.world.setBlockToAir(offsetPos);
                        toolMetaItem.damageItem(stack, damagePerBlockBreak, false);
                    }
                }

            }
        }
    }
    return true;
}
 
Example #4
Source File: ToolUtility.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean applyHarvestBehavior(BlockPos pos, EntityPlayer player) {
    IBlockState blockState = player.world.getBlockState(pos);
    Block block = blockState.getBlock();
    if(block instanceof BlockCrops) {
        BlockCrops blockCrops = (BlockCrops) block;
        if(blockCrops.isMaxAge(blockState)) {
            @SuppressWarnings("deprecation")
            List<ItemStack> drops = blockCrops.getDrops(player.world, pos, blockState, 0);
            dropListOfItems(player.world, pos, drops);
            player.world.setBlockState(pos, blockCrops.withAge(0));
            return true;
        }
    }
    return false;
}
 
Example #5
Source File: EntityAIHarvestTofuFarmland.java    From TofuCraftReload with MIT License 4 votes vote down vote up
/**
 * Keep ticking a continuous task that has already been started
 */
public void updateTask()
{
    super.updateTask();
    this.villager.getLookHelper().setLookPosition((double)this.destinationBlock.getX() + 0.5D, (double)(this.destinationBlock.getY() + 1), (double)this.destinationBlock.getZ() + 0.5D, 10.0F, (float)this.villager.getVerticalFaceSpeed());

    if (this.getIsAboveDestination())
    {
        World world = this.villager.world;
        BlockPos blockpos = this.destinationBlock.up();
        IBlockState iblockstate = world.getBlockState(blockpos);
        Block block = iblockstate.getBlock();

        if (this.currentTask == 0 && block instanceof BlockCrops && ((BlockCrops)block).isMaxAge(iblockstate))
        {
            world.destroyBlock(blockpos, true);
        }
        else if (this.currentTask == 1 && iblockstate.getMaterial() == Material.AIR)
        {
            InventoryBasic inventorybasic = this.villager.getVillagerInventory();

            for (int i = 0; i < inventorybasic.getSizeInventory(); ++i)
            {
                ItemStack itemstack = inventorybasic.getStackInSlot(i);
                boolean flag = false;

                if (!itemstack.isEmpty())
                {
                    if (itemstack.getItem() == Items.WHEAT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.WHEAT.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.POTATO)
                    {
                        world.setBlockState(blockpos, Blocks.POTATOES.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.CARROT)
                    {
                        world.setBlockState(blockpos, Blocks.CARROTS.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() == Items.BEETROOT_SEEDS)
                    {
                        world.setBlockState(blockpos, Blocks.BEETROOTS.getDefaultState(), 3);
                        flag = true;
                    }
                    else if (itemstack.getItem() instanceof net.minecraftforge.common.IPlantable) {
                        if(((net.minecraftforge.common.IPlantable)itemstack.getItem()).getPlantType(world,blockpos) == net.minecraftforge.common.EnumPlantType.Crop) {
                            world.setBlockState(blockpos, ((net.minecraftforge.common.IPlantable)itemstack.getItem()).getPlant(world,blockpos),3);
                            flag = true;
                        }
                    }
                }

                if (flag)
                {
                    itemstack.shrink(1);

                    if (itemstack.isEmpty())
                    {
                        inventorybasic.setInventorySlotContents(i, ItemStack.EMPTY);
                    }

                    break;
                }
            }
        }

        this.currentTask = -1;
        this.runDelay = 10;
    }
}
 
Example #6
Source File: PlantHelper.java    From EmergingTechnology with MIT License 4 votes vote down vote up
public static int getPlantGrowthAtPosition(World world, BlockPos position) {
    IBlockState state = world.getBlockState(position);

    if (state == null)
        return 0;

    Block block = state.getBlock();

    if (block instanceof BlockReed || block instanceof BlockCactus) {
        int growth = 0;

        Block[] aboveBlocks = new Block[] { world.getBlockState(position.add(0, 1, 0)).getBlock(),
                world.getBlockState(position.add(0, 2, 0)).getBlock(),
                world.getBlockState(position.add(0, 3, 0)).getBlock() };

        for (Block aboveBlock : aboveBlocks) {
            if (aboveBlock instanceof BlockReed || block instanceof BlockCactus) {
                growth++;
            } else {
                return growth;
            }
            ;
        }

        return growth;
    }
    ;

    if (block instanceof BlockCrops) {

        // int maxAge = 0;
        int age = 0;

        // tnx draco
        Iterator<IProperty<?>> properties = state.getPropertyKeys().iterator();
        while (properties.hasNext()) {

            IProperty<?> p = properties.next();

            if (p instanceof PropertyInteger && p.getName().toLowerCase().equals("age")) {

                PropertyInteger ageProperty = (PropertyInteger) p;

                // maxAge = Iterables.getLast(ageProperty.getAllowedValues());
                age = state.getValue(ageProperty);
            }
        }

        return age;
    }

    return 0;
}
 
Example #7
Source File: PlantHelper.java    From EmergingTechnology with MIT License 4 votes vote down vote up
public static boolean isCropAtPositionReadyForHarvest(World world, BlockPos position) {
    IBlockState state = world.getBlockState(position);

    if (state == null)
        return false;

    Block block = state.getBlock();

    if (isStackableCropReady(world, block, position)) {
        return true;
    }

    if (block instanceof BlockCrops) {

        int maxAge = 0;
        int age = 0;

        // tnx draco
        Iterator<IProperty<?>> properties = state.getPropertyKeys().iterator();
        while (properties.hasNext()) {

            IProperty<?> p = properties.next();

            if (p instanceof PropertyInteger && p.getName().toLowerCase().equals("age")) {

                PropertyInteger ageProperty = (PropertyInteger) p;

                maxAge = Iterables.getLast(ageProperty.getAllowedValues());
                age = state.getValue(ageProperty);
            }
        }

        if (maxAge == 0) {
            return false;
        }

        if (age == maxAge) {
            return true;
        }
    }

    return false;
}
 
Example #8
Source File: HydroponicTileEntity.java    From EmergingTechnology with MIT License 4 votes vote down vote up
public boolean doGrowthMultiplierProcess() {

        // Get blockstate of whatever is on top of block
        IBlockState aboveBlockState = this.world.getBlockState(this.pos.add(0, 1, 0));

        // If there is no blockstate above, abandon ship
        if (aboveBlockState == null) {
            return false;
        }

        // Get the blockstate's gooey block center
        Block aboveBlock = aboveBlockState.getBlock();

        // Get internal growth medium
        ItemStack growthMedium = this.getItemStack();

        // Get threshold from medium
        int growthProbabilityThreshold = HydroponicHelper.getGrowthProbabilityForMedium(growthMedium);

        // If it ain't a plant, we ain't interested
        if (!PlantHelper.isPlantBlock(aboveBlock)) {
            return false;
        }

        // Check if fluids provide boost
        int totalFluidBoost = 0;

        // If this medium works especially well in this fluid, we can give it a little
        // boost
        int growthProbabilityBoostModifierFromFluid = HydroponicHelper
                .getSpecificPlantGrowthBoostForFluidStack(this.fluidHandler.getFluid(), aboveBlockState);
        int growthMultiplierFromFluid = HydroponicHelper.getGrowthProbabilityForFluid(this.fluidHandler.getFluid());

        // If no boost, just add regular growth modifier.
        if (growthProbabilityBoostModifierFromFluid == 0) {
            totalFluidBoost += growthMultiplierFromFluid;
        } else {
            totalFluidBoost += growthProbabilityBoostModifierFromFluid;
        }

        growthProbabilityThreshold += totalFluidBoost;

        // If this medium works especially well on this plant, we can give it a little
        // boost
        int growthProbabilityBoostModifier = HydroponicHelper.getSpecificPlantGrowthBoostForId(mediumId,
                aboveBlockState);

        growthProbabilityThreshold += growthProbabilityBoostModifier;

        // If impossible, skidaddle
        if (growthProbabilityThreshold == 0) {
            return false;
        }

        // If the above is one of those BlockCrops fellas or fancy IPlantable, roll the
        // dice
        if (aboveBlock instanceof BlockCrops || aboveBlock instanceof IPlantable) {
            return rollForGrow(aboveBlock, aboveBlockState, growthProbabilityThreshold);
        }

        return false;
    }
 
Example #9
Source File: CivilizationHandlers.java    From ToroQuest with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isCrop(Block block) {
	return block instanceof BlockCrops || block instanceof BlockStem;
}