Search in sources :

Example 16 with IPlantable

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;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockFarmland(net.minecraft.block.BlockFarmland) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IPlantable (net.minecraftforge.common.IPlantable)16 Block (net.minecraft.block.Block)12 IBlockState (net.minecraft.block.state.IBlockState)8 ItemStack (net.minecraft.item.ItemStack)6 BlockPos (net.minecraft.util.math.BlockPos)5 IGrowable (net.minecraft.block.IGrowable)4 Item (net.minecraft.item.Item)3 CABlock (convenientadditions.base.block.CABlock)2 BlockFarmland (net.minecraft.block.BlockFarmland)2 BlockLeaves (net.minecraft.block.BlockLeaves)2 IInventory (net.minecraft.inventory.IInventory)2 ItemBlock (net.minecraft.item.ItemBlock)2 World (net.minecraft.world.World)2 IShearable (net.minecraftforge.common.IShearable)2 Affinity (am2.api.spell.enums.Affinity)1 AMParticle (am2.particles.AMParticle)1 ParticleFloatUpward (am2.particles.ParticleFloatUpward)1 InventoryItem (com.bluepowermod.container.inventory.InventoryItem)1 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 HashMap (java.util.HashMap)1