use of net.minecraftforge.common.IPlantable 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.minecraftforge.common.IPlantable 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.minecraftforge.common.IPlantable in project ConvenientAdditions by Necr0.
the class BlockCompostSoil 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(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(DEGRADATION, deg + 1));
else
world.setBlockState(pos, Blocks.DIRT.getDefaultState());
}
}
}
use of net.minecraftforge.common.IPlantable in project ConvenientAdditions by Necr0.
the class ItemCompost method tryCompostApply.
public boolean tryCompostApply(ItemStack compost, World world, BlockPos pos) {
IBlockState state = world.getBlockState(pos);
Block b = state.getBlock();
//change to support applying compost on the plant instead of the soil
if (b != null && (b instanceof IPlantable)) {
pos = pos.down();
state = world.getBlockState(pos);
b = state.getBlock();
}
if (!(b == Blocks.DIRT || b == Blocks.FARMLAND || b == Blocks.GRASS || ((b == ModBlocks.compostSoilBlock || b == ModBlocks.compostSoilTilledBlock) && b.getMetaFromState(state) != 0)))
return false;
if (!world.isRemote) {
if (b == Blocks.DIRT)
world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState());
else if (b == Blocks.FARMLAND)
world.setBlockState(pos, ModBlocks.compostSoilTilledBlock.getDefaultState());
else if (b == Blocks.GRASS) {
if (compost.getItemDamage() == 1 && world.rand.nextFloat() < ModConfigMisc.composter_sporesMyceliumChance)
world.setBlockState(pos, Blocks.MYCELIUM.getDefaultState());
else
world.setBlockState(pos, ModBlocks.compostSoilBlock.getDefaultState(), 3);
} else if (b == ModBlocks.compostSoilBlock || b == ModBlocks.compostSoilTilledBlock) {
world.setBlockState(pos, b.getDefaultState(), 3 + 4);
}
compost.shrink(1);
}
world.playSound(null, pos, Blocks.GRASS.getSoundType().getHitSound(), SoundCategory.BLOCKS, Blocks.GRASS.getSoundType().getVolume(), Blocks.GRASS.getSoundType().getPitch());
return true;
}
use of net.minecraftforge.common.IPlantable in project Railcraft by Railcraft.
the class EntityCartTrackLayer method isValidReplacementBlock.
private boolean isValidReplacementBlock(BlockPos pos) {
IBlockState state = WorldPlugin.getBlockState(worldObj, pos);
Block block = state.getBlock();
return (WorldPlugin.isBlockAir(worldObj, pos, state) || block instanceof IPlantable || block instanceof IShearable || EntityTunnelBore.replaceableBlocks.contains(block)) || block.isReplaceable(worldObj, pos);
}
Aggregations