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;
}
Aggregations