2013-04-16 08:19:59 +00:00
|
|
|
package biomesoplenty.blocks;
|
2013-03-28 19:03:53 +00:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Random;
|
|
|
|
|
2013-04-16 08:19:59 +00:00
|
|
|
import biomesoplenty.mod_BiomesOPlenty;
|
|
|
|
import biomesoplenty.configuration.BOPBlocks;
|
|
|
|
import biomesoplenty.worldgen.WorldGenPromisedTree;
|
2013-04-16 06:43:45 +00:00
|
|
|
|
2013-03-28 19:03:53 +00:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockSapling;
|
2013-03-30 17:14:03 +00:00
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
2013-03-28 19:03:53 +00:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-04-10 01:14:41 +00:00
|
|
|
import net.minecraft.util.Icon;
|
2013-03-28 19:03:53 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraft.world.gen.feature.WorldGenerator;
|
|
|
|
|
2013-04-16 12:57:04 +00:00
|
|
|
@Deprecated
|
2013-03-28 19:03:53 +00:00
|
|
|
public class BlockHolySapling extends BlockSapling
|
|
|
|
{
|
|
|
|
public static final String[] WOOD_TYPES = new String[] {"holy"};
|
2013-03-31 07:44:08 +00:00
|
|
|
private Icon[] blockIcon = new Icon[1];
|
2013-03-28 19:03:53 +00:00
|
|
|
|
2013-03-30 17:14:03 +00:00
|
|
|
public BlockHolySapling(int par1)
|
2013-03-28 19:03:53 +00:00
|
|
|
{
|
2013-03-30 17:14:03 +00:00
|
|
|
super(par1);
|
2013-03-28 19:03:53 +00:00
|
|
|
float var3 = 0.4F;
|
|
|
|
this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, var3 * 2.0F, 0.5F + var3);
|
|
|
|
this.setCreativeTab(mod_BiomesOPlenty.tabBiomesOPlenty);
|
|
|
|
}
|
|
|
|
|
2013-03-30 17:14:03 +00:00
|
|
|
@Override
|
|
|
|
public void registerIcons(IconRegister par1IconRegister)
|
|
|
|
{
|
2013-03-31 07:44:08 +00:00
|
|
|
this.blockIcon[0] = par1IconRegister.registerIcon("BiomesOPlenty:holysapling");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Icon getBlockTextureFromSideAndMetadata(int par1, int par2)
|
|
|
|
{
|
|
|
|
return this.blockIcon[0];
|
2013-03-30 17:14:03 +00:00
|
|
|
}
|
2013-04-01 07:41:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean canBlockStay(World par1World, int par2, int par3, int par4)
|
|
|
|
{
|
|
|
|
Block soil = blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
|
|
|
|
return (par1World.getFullBlockLightValue(par2, par3, par4) >= 8 || par1World.canBlockSeeTheSky(par2, par3, par4)) &&
|
2013-04-05 03:41:51 +00:00
|
|
|
(soil != null && soil.blockID == BOPBlocks.holyGrass.blockID);
|
2013-04-01 07:41:26 +00:00
|
|
|
}
|
2013-03-30 17:14:03 +00:00
|
|
|
|
2013-03-28 19:03:53 +00:00
|
|
|
/**
|
|
|
|
* Ticks the block if it's been scheduled
|
|
|
|
*/
|
|
|
|
public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
|
|
|
|
{
|
|
|
|
if (!par1World.isRemote)
|
|
|
|
{
|
|
|
|
super.updateTick(par1World, par2, par3, par4, par5Random);
|
|
|
|
|
|
|
|
if (par1World.getBlockLightValue(par2, par3 + 1, par4) >= 9 && par5Random.nextInt(7) == 0)
|
|
|
|
{
|
|
|
|
int var6 = par1World.getBlockMetadata(par2, par3, par4);
|
|
|
|
|
|
|
|
if ((var6 & 8) == 0)
|
|
|
|
{
|
2013-03-30 17:14:03 +00:00
|
|
|
par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 | 8, 2);
|
2013-03-28 19:03:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.growTree(par1World, par2, par3, par4, par5Random);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
|
|
|
|
*/
|
2013-03-30 17:14:03 +00:00
|
|
|
/*public int getBlockTextureFromSideAndMetadata(int par1, int par2)
|
2013-03-28 19:03:53 +00:00
|
|
|
{
|
|
|
|
par2 &= 3;
|
|
|
|
return par2 == 1 ? 63 : (par2 == 2 ? 79 : (par2 == 3 ? 30 : super.getBlockTextureFromSideAndMetadata(par1, par2)));
|
2013-03-30 17:14:03 +00:00
|
|
|
}*/
|
2013-03-28 19:03:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets passed in the blockID of the block below and supposed to return true if its allowed to grow on the type of
|
|
|
|
* blockID passed in. Args: blockID
|
|
|
|
*/
|
|
|
|
protected boolean canThisPlantGrowOnThisBlockID(int par1)
|
|
|
|
{
|
2013-04-05 03:41:51 +00:00
|
|
|
return par1 == BOPBlocks.holyGrass.blockID;
|
2013-03-28 19:03:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempts to grow a sapling into a tree
|
|
|
|
*/
|
|
|
|
public void growTree(World par1World, int par2, int par3, int par4, Random par5Random)
|
|
|
|
{
|
|
|
|
int var6 = par1World.getBlockMetadata(par2, par3, par4) & 3;
|
|
|
|
Object var7 = null;
|
|
|
|
int var8 = 0;
|
|
|
|
int var9 = 0;
|
|
|
|
boolean var10 = false;
|
|
|
|
|
|
|
|
for (var8 = 0; var8 >= -1; --var8)
|
|
|
|
{
|
|
|
|
for (var9 = 0; var9 >= -1; --var9)
|
|
|
|
{
|
|
|
|
if (this.isSameSapling(par1World, par2 + var8, par3, par4 + var9, 0) && this.isSameSapling(par1World, par2 + var8 + 1, par3, par4 + var9, 0) && this.isSameSapling(par1World, par2 + var8, par3, par4 + var9 + 1, 0) && this.isSameSapling(par1World, par2 + var8 + 1, par3, par4 + var9 + 1, 0))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var7 != null)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var7 == null)
|
|
|
|
{
|
|
|
|
var9 = 0;
|
|
|
|
var8 = 0;
|
|
|
|
var7 = new WorldGenPromisedTree(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var10)
|
|
|
|
{
|
|
|
|
par1World.setBlock(par2 + var8, par3, par4 + var9, 0);
|
|
|
|
par1World.setBlock(par2 + var8 + 1, par3, par4 + var9, 0);
|
|
|
|
par1World.setBlock(par2 + var8, par3, par4 + var9 + 1, 0);
|
|
|
|
par1World.setBlock(par2 + var8 + 1, par3, par4 + var9 + 1, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
par1World.setBlock(par2, par3, par4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!((WorldGenerator)var7).generate(par1World, par5Random, par2 + var8, par3, par4 + var9))
|
|
|
|
{
|
|
|
|
if (var10)
|
|
|
|
{
|
2013-03-30 17:14:03 +00:00
|
|
|
par1World.setBlock(par2 + var8, par3, par4 + var9, this.blockID, var6, 2);
|
|
|
|
par1World.setBlock(par2 + var8 + 1, par3, par4 + var9, this.blockID, var6, 2);
|
|
|
|
par1World.setBlock(par2 + var8, par3, par4 + var9 + 1, this.blockID, var6, 2);
|
|
|
|
par1World.setBlock(par2 + var8 + 1, par3, par4 + var9 + 1, this.blockID, var6, 2);
|
2013-03-28 19:03:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-30 17:14:03 +00:00
|
|
|
par1World.setBlock(par2, par3, par4, this.blockID, var6, 2);
|
2013-03-28 19:03:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the same sapling is present at the given location.
|
|
|
|
*/
|
|
|
|
public boolean isSameSapling(World par1World, int par2, int par3, int par4, int par5)
|
|
|
|
{
|
|
|
|
return par1World.getBlockId(par2, par3, par4) == this.blockID && (par1World.getBlockMetadata(par2, par3, par4) & 3) == par5;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the damage on the item the block drops. Used in cloth and wood.
|
|
|
|
*/
|
|
|
|
public int damageDropped(int par1)
|
|
|
|
{
|
|
|
|
return par1 & 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
|
|
|
*/
|
|
|
|
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
|
|
|
|
{
|
|
|
|
par3List.add(new ItemStack(par1, 1, 0));
|
|
|
|
}
|
|
|
|
}
|