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