use of net.minecraft.block.IGrowable in project NetherEx by LogicTechCorp.
the class ItemWitherDust method applyBoneMeal.
private static boolean applyBoneMeal(ItemStack stack, World world, BlockPos pos, EntityPlayer player) {
IBlockState state = world.getBlockState(pos);
int hook = ForgeEventFactory.onApplyBonemeal(player, world, pos, state, stack);
if (hook != 0) {
return hook > 0;
}
if (state.getBlock() instanceof IGrowable) {
IGrowable growable = (IGrowable) state.getBlock();
if (growable.canGrow(world, pos, state, world.isRemote)) {
if (!world.isRemote) {
if (growable.canUseBonemeal(world, world.rand, pos, state)) {
growable.grow(world, world.rand, pos, state);
}
stack.shrink(1);
}
return true;
}
}
return false;
}
use of net.minecraft.block.IGrowable in project ArsMagica2 by Mithion.
the class HarvestPlants method applyEffectBlock.
@Override
public boolean applyEffectBlock(ItemStack stack, World world, int blockx, int blocky, int blockz, int blockFace, double impactX, double impactY, double impactZ, EntityLivingBase caster) {
Block block = world.getBlock(blockx, blocky, blockz);
if (!(block instanceof IGrowable))
return false;
if (!world.isRemote) {
block.breakBlock(world, blockx, blocky, blockz, block, 0);
block.dropBlockAsItem(world, blockx, blocky, blockz, world.getBlockMetadata(blockx, blocky, blockz), Block.getIdFromBlock(block));
world.setBlock(blockx, blocky, blockz, Blocks.air);
}
return true;
}
use of net.minecraft.block.IGrowable in project minecolonies by Minecolonies.
the class EntityAIWorkFarmer method initialize.
/**
* This (re)initializes a field.
* Checks the block above to see if it is a plant, if so, breaks it. Then tills.
*/
private AIState initialize() {
@Nullable final BuildingFarmer buildingFarmer = getOwnBuilding();
if (buildingFarmer == null || checkForHoe() || buildingFarmer.getCurrentField() == null) {
return AIState.PREPARING;
}
@Nullable final Field field = buildingFarmer.getCurrentField();
if (workingOffset != null) {
final BlockPos position = field.getLocation().down().south(workingOffset.getZ()).east(workingOffset.getX());
// Still moving to the block
if (walkToBlock(position.up())) {
return AIState.FARMER_INITIALIZE;
}
// Check to see if the block is a plant, and if it is, break it.
final IBlockState blockState = world.getBlockState(position.up());
if (blockState.getBlock() instanceof IGrowable && (!(blockState.getBlock() instanceof BlockCrops) || ((BlockCrops) blockState.getBlock()).getItem(world, position.up(), blockState) != field.getSeed())) {
mineBlock(position.up());
setDelay(getLevelDelay());
return AIState.FARMER_INITIALIZE;
}
// hoe the block if able to.
if (hoeIfAble(position, field)) {
setDelay(getLevelDelay());
return AIState.FARMER_INITIALIZE;
}
if (shouldPlant(position, field) && !plantCrop(field.getSeed(), position)) {
resetVariables();
return AIState.PREPARING;
}
}
if (!handleOffset(field)) {
resetVariables();
shouldDumpInventory = true;
field.setInitialized(true);
field.setNeedsWork(false);
return AIState.IDLE;
}
setDelay(getLevelDelay());
return AIState.FARMER_INITIALIZE;
}
use of net.minecraft.block.IGrowable 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