use of net.minecraft.block.BlockBush in project AgriCraft by AgriCraft.
the class DebugModeClearGrass method debugActionBlockClicked.
@Override
public void debugActionBlockClicked(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
pos = pos.toImmutable();
for (int x = -radius; x < radius; x++) {
for (int z = -radius; z < radius; z++) {
BlockPos loc = pos.add(x, 0, z);
Block block = world.getBlockState(loc).getBlock();
if (block instanceof BlockBush) {
world.destroyBlock(loc, false);
}
}
}
}
use of net.minecraft.block.BlockBush in project Gaia-Dimension by Andromander.
the class GDMineralRiver method decorate.
@Override
public void decorate(World world, Random rand, BlockPos pos) {
for (int l3 = 0; l3 < 4; ++l3) {
if (rand.nextInt(4) == 0) {
int i4 = rand.nextInt(16) + 8;
int k8 = rand.nextInt(16) + 8;
int j12 = world.getHeight(pos.add(i4, 0, k8)).getY() * 2;
if (j12 > 0) {
int k15 = rand.nextInt(j12);
new WorldGenBush((BlockBush) GDBlocks.crystalBloom).generate(world, rand, pos.add(i4, k15, k8));
}
}
}
}
use of net.minecraft.block.BlockBush in project Galacticraft by micdoodle8.
the class TileEntityTerraformer method update.
@Override
public void update() {
super.update();
if (!this.worldObj.isRemote) {
final FluidStack liquid = FluidUtil.getFluidContained(this.containingItems[0]);
if (FluidUtil.isFluidStrict(liquid, FluidRegistry.WATER.getName())) {
FluidUtil.loadFromContainer(waterTank, FluidRegistry.WATER, containingItems, 0, liquid.amount);
}
this.active = this.bubbleSize == this.MAX_SIZE && this.hasEnoughEnergyToRun && this.getFirstBonemealStack() != null && this.waterTank.getFluid() != null && this.waterTank.getFluid().amount > 0;
}
if (!this.worldObj.isRemote && (this.active != this.lastActive || this.ticks % 60 == 0)) {
this.terraformableBlocksList.clear();
this.grassBlockList.clear();
if (this.active) {
int bubbleSize = (int) Math.ceil(this.bubbleSize);
double bubbleSizeSq = this.bubbleSize;
bubbleSizeSq *= bubbleSizeSq;
boolean doGrass = !this.grassDisabled && this.getFirstSeedStack() != null;
boolean doTrees = !this.treesDisabled && this.getFirstSaplingStack() != null;
for (int x = this.getPos().getX() - bubbleSize; x < this.getPos().getX() + bubbleSize; x++) {
for (int y = this.getPos().getY() - bubbleSize; y < this.getPos().getY() + bubbleSize; y++) {
for (int z = this.getPos().getZ() - bubbleSize; z < this.getPos().getZ() + bubbleSize; z++) {
BlockPos pos = new BlockPos(x, y, z);
Block blockID = this.worldObj.getBlockState(pos).getBlock();
if (blockID == null) {
continue;
}
if (!(blockID.isAir(this.worldObj, pos)) && this.getDistanceFromServer(x, y, z) < bubbleSizeSq) {
if (doGrass && blockID instanceof ITerraformableBlock && ((ITerraformableBlock) blockID).isTerraformable(this.worldObj, pos)) {
this.terraformableBlocksList.add(new BlockPos(x, y, z));
} else if (doTrees) {
Block blockIDAbove = this.worldObj.getBlockState(pos.up()).getBlock();
if (blockID == Blocks.grass && blockIDAbove.isAir(this.worldObj, pos.up())) {
this.grassBlockList.add(new BlockPos(x, y, z));
}
}
}
}
}
}
}
}
if (!this.worldObj.isRemote && this.terraformableBlocksList.size() > 0 && this.ticks % 15 == 0) {
ArrayList<BlockPos> terraformableBlocks2 = new ArrayList<BlockPos>(this.terraformableBlocksList);
int randomIndex = this.worldObj.rand.nextInt(this.terraformableBlocksList.size());
BlockPos vec = terraformableBlocks2.get(randomIndex);
if (this.worldObj.getBlockState(vec).getBlock() instanceof ITerraformableBlock) {
Block id;
switch(this.worldObj.rand.nextInt(40)) {
case 0:
if (this.worldObj.isBlockFullCube(new BlockPos(vec.getX() - 1, vec.getY(), vec.getZ())) && this.worldObj.isBlockFullCube(new BlockPos(vec.getX() + 1, vec.getY(), vec.getZ())) && this.worldObj.isBlockFullCube(new BlockPos(vec.getX(), vec.getY(), vec.getZ() - 1)) && this.worldObj.isBlockFullCube(new BlockPos(vec.getX(), vec.getY(), vec.getZ() + 1))) {
id = Blocks.flowing_water;
} else {
id = Blocks.grass;
}
break;
default:
id = Blocks.grass;
break;
}
this.worldObj.setBlockState(vec, id.getDefaultState());
if (id == Blocks.grass) {
this.useCount[0]++;
this.waterTank.drain(1, true);
this.checkUsage(1);
} else if (id == Blocks.flowing_water) {
this.checkUsage(2);
}
}
this.terraformableBlocksList.remove(randomIndex);
}
if (!this.worldObj.isRemote && !this.treesDisabled && this.grassBlockList.size() > 0 && this.ticks % 50 == 0) {
int randomIndex = this.worldObj.rand.nextInt(this.grassBlockList.size());
BlockPos vecGrass = grassBlockList.get(randomIndex);
if (this.worldObj.getBlockState(vecGrass).getBlock() == Blocks.grass) {
BlockPos vecSapling = vecGrass.add(0, 1, 0);
ItemStack sapling = this.getFirstSaplingStack();
boolean flag = false;
// Attempt to prevent placement too close to other trees
for (BlockPos testVec : this.grownTreesList) {
if (testVec.distanceSq(vecSapling) < 9) {
flag = true;
break;
}
}
if (!flag && sapling != null) {
Block b = Block.getBlockFromItem(sapling.getItem());
this.worldObj.setBlockState(vecSapling, b.getStateFromMeta(sapling.getItemDamage()), 3);
if (b instanceof BlockSapling) {
if (this.worldObj.getLightFromNeighbors(vecSapling) >= 9) {
((BlockSapling) b).grow(this.worldObj, vecSapling, this.worldObj.getBlockState(vecSapling), this.worldObj.rand);
this.grownTreesList.add(new BlockPos(vecSapling.getX(), vecSapling.getY(), vecSapling.getZ()));
}
} else if (b instanceof BlockBush) {
if (this.worldObj.getLightFromNeighbors(vecSapling) >= 5) // Hammer the update tick a few times to try to get it to grow - it won't always
{
for (int j = 0; j < 12; j++) {
if (this.worldObj.getBlockState(vecSapling).getBlock() == b) {
((BlockBush) b).updateTick(this.worldObj, vecSapling, this.worldObj.getBlockState(vecSapling), this.worldObj.rand);
} else {
this.grownTreesList.add(new BlockPos(vecSapling.getX(), vecSapling.getY(), vecSapling.getZ()));
break;
}
}
}
}
this.useCount[1]++;
this.waterTank.drain(50, true);
this.checkUsage(0);
}
}
this.grassBlockList.remove(randomIndex);
}
if (!this.worldObj.isRemote) {
this.terraformableBlocksListSize = this.terraformableBlocksList.size();
this.grassBlocksListSize = this.grassBlockList.size();
}
if (this.hasEnoughEnergyToRun && (!this.grassDisabled || !this.treesDisabled)) {
this.bubbleSize = (float) Math.min(Math.max(0, this.bubbleSize + 0.1F), this.MAX_SIZE);
} else {
this.bubbleSize = (float) Math.min(Math.max(0, this.bubbleSize - 0.1F), this.MAX_SIZE);
}
this.lastActive = this.active;
}
use of net.minecraft.block.BlockBush in project Galacticraft by micdoodle8.
the class ContainerTerraformer method initSaplingList.
private static void initSaplingList() {
ContainerTerraformer.saplingList = new LinkedList<>();
Iterator iterator = Block.blockRegistry.iterator();
while (iterator.hasNext()) {
Block b = (Block) iterator.next();
if (b instanceof BlockBush) {
try {
Item item = Item.getItemFromBlock(b);
if (item != null) {
// item.getSubItems(item, null, subItemsList); - can't use because clientside only
ContainerTerraformer.saplingList.add(new ItemStack(item, 1, 0));
String basicName = item.getUnlocalizedName(new ItemStack(item, 1, 0));
for (int i = 1; i < 16; i++) {
ItemStack testStack = new ItemStack(item, 1, i);
String testName = item.getUnlocalizedName(testStack);
if (testName == null || testName.equals("") || testName.equals(basicName)) {
break;
}
ContainerTerraformer.saplingList.add(testStack);
}
}
} catch (Exception e) {
}
}
}
}
use of net.minecraft.block.BlockBush in project BiomesOPlenty by Glitchfiend.
the class GeneratorDoubleFlora method generate.
@Override
public boolean generate(World world, Random random, BlockPos pos) {
Block bottomBlock = this.with.getBlock();
for (int i = 0; i < this.generationAttempts; ++i) {
BlockPos genPos = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
if (this.placeOn.matches(world, genPos.down()) && this.replace.matches(world, genPos) && this.replace.matches(world, genPos.up()) && genPos.getY() < 254) {
boolean canStay;
if (bottomBlock instanceof BlockBOPDecoration) {
canStay = ((BlockBOPDecoration) bottomBlock).canBlockStay(world, genPos, this.with);
} else if (bottomBlock instanceof BlockBush) {
canStay = bottomBlock.canPlaceBlockAt(world, genPos);
} else {
canStay = bottomBlock.canPlaceBlockAt(world, genPos);
}
if (canStay) {
world.setBlockState(genPos, this.with, 2);
world.setBlockState(genPos.up(), this.withTop, 2);
}
}
}
return true;
}
Aggregations