Skip to content

Instantly share code, notes, and snippets.

Created May 26, 2017 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3a3277feaba459d1ec526530ee8b24e2 to your computer and use it in GitHub Desktop.
Save anonymous/3a3277feaba459d1ec526530ee8b24e2 to your computer and use it in GitHub Desktop.
package com.chocolatemod.blocks;
import java.util.Iterator;
import java.util.Random;
import com.chocolatemod.init.ChocolateBlocks;
import com.chocolatemod.worldgen.WorldGenBigChocoShroom;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBush;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.IGrowable;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenBigMushroom;
public class BlockChocoShroom extends BlockBush implements IGrowable
{
private static final String __OBFID = "CL_00000272";
public BlockChocoShroom()
{
float f = 0.2F;
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
this.setTickRandomly(true);
}
public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
if (rand.nextInt(25) == 0)
{
int i = 5;
boolean flag = true;
Iterator iterator = BlockPos.getAllInBoxMutable(pos.add(-4, -1, -4), pos.add(4, 1, 4)).iterator();
while (iterator.hasNext())
{
BlockPos blockpos1 = (BlockPos)iterator.next();
if (worldIn.getBlockState(blockpos1).getBlock() == this)
{
--i;
if (i <= 0)
{
return;
}
}
}
BlockPos blockpos2 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
for (int j = 0; j < 4; ++j)
{
if (worldIn.isAirBlock(blockpos2) && this.canBlockStay(worldIn, blockpos2, this.getDefaultState()))
{
pos = blockpos2;
}
blockpos2 = pos.add(rand.nextInt(3) - 1, rand.nextInt(2) - rand.nextInt(2), rand.nextInt(3) - 1);
}
if (worldIn.isAirBlock(blockpos2) && this.canBlockStay(worldIn, blockpos2, this.getDefaultState()))
{
worldIn.setBlockState(blockpos2, this.getDefaultState(), 2);
}
}
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
return super.canPlaceBlockAt(worldIn, pos) && this.canBlockStay(worldIn, pos, this.getDefaultState());
}
/**
* is the block grass, dirt or farmland
*/
protected boolean canPlaceBlockOn(Block ground)
{
return ground.isFullBlock();
}
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state)
{
if (pos.getY() >= 0 && pos.getY() < 256)
{
IBlockState iblockstate1 = worldIn.getBlockState(pos.down());
return iblockstate1.getBlock() == ChocolateBlocks.chocoGrass ? true : iblockstate1.getBlock() == ChocolateBlocks.chocoDirt ? true : iblockstate1.getBlock() == Blocks.mycelium ? true : (iblockstate1.getBlock() == Blocks.dirt && iblockstate1.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.PODZOL ? true : worldIn.getLight(pos) < 13 && iblockstate1.getBlock().canSustainPlant(worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this));
}
else
{
return false;
}
}
public boolean generateBigMushroom(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
worldIn.setBlockToAir(pos);
WorldGenBigChocoShroom worldgenbigmushroom = null;
if (this == ChocolateBlocks.chocoShroomWhite)
{
worldgenbigmushroom = new WorldGenBigChocoShroom(0);
}
else if (this == ChocolateBlocks.chocoShroomBrown)
{
worldgenbigmushroom = new WorldGenBigChocoShroom(1);
}
if (worldgenbigmushroom != null && worldgenbigmushroom.generate(worldIn, rand, pos))
{
return true;
}
else
{
worldIn.setBlockState(pos, state, 3);
return false;
}
}
/**
* Whether this IGrowable can grow
*/
public boolean canGrow(World worldIn, BlockPos pos, IBlockState state, boolean isClient)
{
return true;
}
public boolean canUseBonemeal(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
return (double)rand.nextFloat() < 0.4D;
}
public void grow(World worldIn, Random rand, BlockPos pos, IBlockState state)
{
this.generateBigMushroom(worldIn, pos, state, rand);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment