use of net.minecraft.block.IGrowable in project NetherEx by LogicTechCorp.
the class EventHandler method onBoneMealUse.
@SubscribeEvent
public static void onBoneMealUse(BonemealEvent event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = event.getBlock();
EntityPlayer player = event.getEntityPlayer();
if (player.getHeldItem(EnumHand.MAIN_HAND).getItem() == NetherExItems.ITEM_DUST_WITHER) {
if (state.getBlock() == Blocks.NETHER_WART) {
int age = state.getValue(BlockNetherWart.AGE);
if (age < 3) {
state = state.withProperty(BlockNetherWart.AGE, age + 1);
world.setBlockState(pos, state);
event.setResult(Event.Result.ALLOW);
}
} else if (state.getBlock() instanceof IGrowable) {
IGrowable growable = (IGrowable) state.getBlock();
if (growable.canGrow(world, pos, state, world.isRemote)) {
growable.grow(world, world.rand, pos, state);
}
} else {
event.setCanceled(true);
}
}
}
use of net.minecraft.block.IGrowable in project ArsMagica2 by Mithion.
the class FlickerOperatorNaturesBounty method DoOperation.
@Override
public boolean DoOperation(World worldObj, IFlickerController habitat, boolean powered, Affinity[] flickers) {
int radius = 6;
int diameter = radius * 2 + 1;
boolean updatedOnce = false;
if (!worldObj.isRemote) {
for (int i = 0; i < (powered ? 5 : 1); ++i) {
int effectX = ((TileEntity) habitat).xCoord - radius + (worldObj.rand.nextInt(diameter));
int effectZ = ((TileEntity) habitat).zCoord - radius + (worldObj.rand.nextInt(diameter));
int effectY = ((TileEntity) habitat).yCoord;
while (worldObj.isAirBlock(effectX, effectY, effectZ) && effectY > 0) {
effectY--;
}
while (!worldObj.isAirBlock(effectX, effectY, effectZ) && effectY > 0) {
effectY++;
}
effectY--;
Block block = worldObj.getBlock(effectX, effectY, effectZ);
if (block instanceof IPlantable || block instanceof IGrowable) {
block.updateTick(worldObj, effectX, effectY, effectZ, worldObj.rand);
updatedOnce = true;
}
}
} else {
int posY = ((TileEntity) habitat).yCoord;
while (!worldObj.isAirBlock(((TileEntity) habitat).xCoord, posY, ((TileEntity) habitat).zCoord)) {
posY++;
}
posY--;
for (int i = 0; i < AMCore.config.getGFXLevel() * 2; ++i) {
AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "plant", ((TileEntity) habitat).xCoord + 0.5, posY + 0.5f, ((TileEntity) habitat).zCoord + 0.5);
if (particle != null) {
particle.addRandomOffset(diameter, 0, diameter);
particle.AddParticleController(new ParticleFloatUpward(particle, 0.01f, 0.04f, 1, false));
particle.setMaxAge(16);
particle.setParticleScale(0.08f);
}
}
}
if (powered) {
for (Affinity aff : flickers) {
if (aff == Affinity.WATER)
FlickerOperatorRegistry.instance.getOperatorForMask(Affinity.WATER.getAffinityMask()).DoOperation(worldObj, habitat, powered);
}
}
return updatedOnce;
}
use of net.minecraft.block.IGrowable in project ConvenientAdditions by Necr0.
the class BlockCompostSoilTilled method updateTick.
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random r) {
if (!world.isRemote) {
BlockPos posU = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
IBlockState s = world.getBlockState(posU);
Block b = s.getBlock();
int deg = state.getValue(BlockCompostSoil.DEGRADATION);
boolean flag = false;
if (b != null && (b instanceof IPlantable || b instanceof IGrowable)) {
if (b instanceof IGrowable)
flag = ((IGrowable) b).canGrow(world, posU, s, false);
//trigger growth tick
b.updateTick(world, posU, world.getBlockState(posU), r);
//degradation: 0-10
int i = deg;
if (//if random number(0-23) is bigger than degradation
r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
i++;
if (r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
i++;
if (r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
i++;
if (r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
}
if (r.nextInt(5 + (flag ? 3 : 0)) == 0) {
if (deg < 10)
world.setBlockState(pos, state.withProperty(BlockCompostSoil.DEGRADATION, deg + 1));
else
world.setBlockState(pos, Blocks.FARMLAND.getDefaultState().withProperty(BlockFarmland.MOISTURE, 7));
}
if (s.getMaterial().isSolid())
world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState().withProperty(BlockCompostSoil.DEGRADATION, deg), 2);
}
}
use of net.minecraft.block.IGrowable in project AgriCraft by AgriCraft.
the class TileEntitySprinkler method irrigate.
/**
* Depending on the block type either irrigates farmland or forces plant
* GROWTH (based on chance)
*/
private void irrigate(BlockPos pos, boolean farmlandOnly) {
IBlockState state = this.getWorld().getBlockState(pos);
Block block = state.getBlock();
if (block instanceof BlockFarmland && block.getMetaFromState(state) < 7) {
// irrigate farmland
int flag = counter == 0 ? 2 : 6;
worldObj.setBlockState(pos, block.getStateFromMeta(7), flag);
} else if (!farmlandOnly && ((block instanceof IPlantable) || (block instanceof IGrowable))) {
// X1 chance to force GROWTH tick on plant every Y1 ticks
if (counter == 0 && worldObj.rand.nextDouble() <= AgriCraftConfig.sprinklerGrowthChancePercent) {
block.updateTick(this.getWorld(), pos, state, worldObj.rand);
}
}
}
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;
}
Aggregations