Search in sources :

Example 6 with IBlockSoil

use of binnie.botany.api.gardening.IBlockSoil 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)

Example 7 with IBlockSoil

use of binnie.botany.api.gardening.IBlockSoil in project Binnie by ForestryMC.

the class BlockPlant method updateTick.

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
    PlantType type = state.getValue(PLANT_TYPE);
    if (rand.nextInt(4) == 0) {
        if (type == PlantType.WEEDS) {
            world.setBlockState(pos, state.withProperty(PLANT_TYPE, PlantType.WEEDS_LONG), 2);
        } else if (type == PlantType.WEEDS_LONG) {
            world.setBlockState(pos, state.withProperty(PLANT_TYPE, PlantType.WEEDS_VERY_LONG), 2);
        } else if (type == PlantType.DEAD_FLOWER) {
            world.setBlockState(pos, state.withProperty(PLANT_TYPE, PlantType.DECAYING_FLOWER), 2);
        } else if (type == PlantType.DECAYING_FLOWER) {
            world.setBlockToAir(pos);
            return;
        }
    }
    if (rand.nextInt(6) == 0) {
        if (type == PlantType.WEEDS) {
            world.setBlockToAir(pos);
        } else if (type == PlantType.WEEDS_LONG) {
            world.setBlockState(pos, state.withProperty(PLANT_TYPE, PlantType.WEEDS), 2);
        } else if (type == PlantType.WEEDS_VERY_LONG) {
            world.setBlockState(pos, state.withProperty(PLANT_TYPE, PlantType.WEEDS_LONG), 2);
        }
    }
    Block below = world.getBlockState(pos.down()).getBlock();
    if (!BotanyCore.getGardening().isSoil(below)) {
        return;
    }
    IBlockSoil soil = (IBlockSoil) below;
    if (rand.nextInt(3) != 0) {
        return;
    }
    if (type.isWeed()) {
        if (!soil.degrade(world, pos.down(), EnumSoilType.LOAM)) {
            soil.degrade(world, pos.down(), EnumSoilType.SOIL);
        }
    } else if (type == PlantType.DECAYING_FLOWER && !soil.fertilise(world, pos.down(), EnumSoilType.LOAM)) {
        soil.fertilise(world, pos.down(), EnumSoilType.FLOWERBED);
    }
}
Also used : IBlockSoil(binnie.botany.api.gardening.IBlockSoil) Block(net.minecraft.block.Block)

Aggregations

IBlockSoil (binnie.botany.api.gardening.IBlockSoil)7 Block (net.minecraft.block.Block)5 IGardeningManager (binnie.botany.api.gardening.IGardeningManager)4 BlockPos (net.minecraft.util.math.BlockPos)4 ItemStack (net.minecraft.item.ItemStack)3 IBlockState (net.minecraft.block.state.IBlockState)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 EnumAcidity (binnie.botany.api.gardening.EnumAcidity)1 EnumSoilType (binnie.botany.api.gardening.EnumSoilType)1 IFlower (binnie.botany.api.genetics.IFlower)1 IFlowerRoot (binnie.botany.api.genetics.IFlowerRoot)1 FarmDirection (forestry.api.farming.FarmDirection)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 TextComponentString (net.minecraft.util.text.TextComponentString)1