use of net.minecraftforge.common.IPlantable in project AgriCraft by AgriCraft.
the class TileEntitySprinkler method irrigateColumn.
/**
* This method will search through a vertical column of positions, starting from the top. It
* will stop searching any lower once it hits anything other than air or plants. Any plant found
* has an independant chance for a growth tick. That percentage is controlled by
* AgriCraftConfig. Farmland also ends the search, but it first has its moisture set to max (7)
* if it isn't already. The lowest position is special: a plant this far away is not helped.
* Only farmland is currently.
*/
private void irrigateColumn(final int targetX, final int targetZ, final int highestY, final int lowestY) {
for (int targetY = highestY; targetY >= lowestY; targetY -= 1) {
BlockPos target = new BlockPos(targetX, targetY, targetZ);
IBlockState state = this.getWorld().getBlockState(target);
Block block = state.getBlock();
// TODO: Is there a way to use isSideSolid to ignore minor obstructions? (Farmland isn't solid.)
if (block.isAir(state, this.getWorld(), target)) {
continue;
}
// Option B: Give plants a chance to grow, and then continue onward to irrigate the farmland too.
if ((block instanceof IPlantable || block instanceof IGrowable) && targetY != lowestY) {
if (this.getRandom().nextInt(100) < AgriCraftConfig.sprinklerGrowthChance) {
block.updateTick(this.getWorld(), target, state, this.getRandom());
}
continue;
}
// Option C: Dry farmland gets set as moist.
if (block instanceof BlockFarmland) {
if (state.getValue(BlockFarmland.MOISTURE) < 7) {
this.getWorld().setBlockState(target, state.withProperty(BlockFarmland.MOISTURE, 7), 2);
}
// Explicitly expresses the intent to stop.
break;
}
// Option D: If it's none of the above, it blocks the sprinkler's irrigation. Stop.
break;
}
}
Aggregations