Search in sources :

Example 6 with FarmDirection

use of forestry.api.farming.FarmDirection in project Binnie by ForestryMC.

the class GardenLogic method maintainSoil.

private boolean maintainSoil(World world, BlockPos pos, FarmDirection direction, int extent, IFarmHousing housing) {
    IGardeningManager gardening = BotanyCore.getGardening();
    for (int i = 0; i < extent; ++i) {
        BlockPos position = pos.offset(direction.getFacing(), i);
        if (fertilised && gardening.isSoil(getBlock(world, position))) {
            IBlockSoil soil = (IBlockSoil) getBlock(world, position);
            if (soil.fertilise(world, position, EnumSoilType.FLOWERBED)) {
                continue;
            }
        }
        if (getBlock(world, position.up()) == ModuleGardening.plant) {
            world.setBlockToAir(position.up());
        } else {
            if (acidity != null && gardening.isSoil(getBlock(world, position))) {
                IBlockSoil soil = (IBlockSoil) getBlock(world, position);
                EnumAcidity pH = soil.getPH(world, position);
                if (pH.ordinal() < acidity.ordinal()) {
                    ItemStack stack = getAvailableFertiliser(housing, EnumFertiliserType.ALKALINE);
                    if (!stack.isEmpty() && soil.setPH(world, position, EnumAcidity.values()[pH.ordinal() + 1])) {
                        NonNullList<ItemStack> resources = NonNullList.create();
                        resources.add(stack);
                        housing.getFarmInventory().removeResources(resources);
                        continue;
                    }
                }
                if (pH.ordinal() > acidity.ordinal()) {
                    ItemStack stack = getAvailableFertiliser(housing, EnumFertiliserType.ACID);
                    if (!stack.isEmpty() && soil.setPH(world, position, EnumAcidity.values()[pH.ordinal() - 1])) {
                        NonNullList<ItemStack> resources = NonNullList.create();
                        resources.add(stack);
                        housing.getFarmInventory().removeResources(resources);
                        continue;
                    }
                }
            }
            if (!isAirBlock(world, position) && !BlockUtil.isReplaceableBlock(getBlockState(world, position), world, position)) {
                ItemStack block = getAsItemStack(world, position);
                ItemStack loam = getAvailableLoam(housing);
                if (isWaste(block) && !loam.isEmpty()) {
                    IBlockState blockState = Block.getBlockFromItem(block.getItem()).getStateFromMeta(block.getItemDamage());
                    Blocks.DIRT.getDrops(produce, world, position, blockState, 0);
                    setBlock(world, position, Blocks.AIR, 0);
                    return trySetSoil(world, position, loam, housing);
                }
            } else if (!isManual()) {
                if (!isWaterBlock(world, position)) {
                    if (i % 2 == 0) {
                        return trySetSoil(world, position, housing);
                    }
                    FarmDirection cclock = FarmDirection.EAST;
                    if (direction == FarmDirection.EAST) {
                        cclock = FarmDirection.SOUTH;
                    } else if (direction == FarmDirection.SOUTH) {
                        cclock = FarmDirection.EAST;
                    } else if (direction == FarmDirection.WEST) {
                        cclock = FarmDirection.SOUTH;
                    }
                    BlockPos previous = position.offset(cclock.getFacing());
                    ItemStack soil2 = getAsItemStack(world, previous);
                    if (!gardening.isSoil(soil2.getItem())) {
                        trySetSoil(world, position, housing);
                    }
                }
            }
        }
    }
    return false;
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) IBlockState(net.minecraft.block.state.IBlockState) EnumAcidity(binnie.botany.api.gardening.EnumAcidity) BlockPos(net.minecraft.util.math.BlockPos) FarmDirection(forestry.api.farming.FarmDirection) ItemStack(net.minecraft.item.ItemStack) IGardeningManager(binnie.botany.api.gardening.IGardeningManager)

Aggregations

FarmDirection (forestry.api.farming.FarmDirection)6 IErrorLogic (forestry.api.core.IErrorLogic)2 ICrop (forestry.api.farming.ICrop)2 IFarmLogic (forestry.api.farming.IFarmLogic)2 FarmWorkStatus (forestry.farming.FarmHelper.FarmWorkStatus)2 FarmTarget (forestry.farming.FarmTarget)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 EnumAcidity (binnie.botany.api.gardening.EnumAcidity)1 IBlockSoil (binnie.botany.api.gardening.IBlockSoil)1 IGardeningManager (binnie.botany.api.gardening.IGardeningManager)1 ICircuitLayout (forestry.api.circuits.ICircuitLayout)1 ICircuitSocketType (forestry.api.circuits.ICircuitSocketType)1 ArrayList (java.util.ArrayList)1 IBlockState (net.minecraft.block.state.IBlockState)1