You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
248 lines
9.4 KiB
Java
248 lines
9.4 KiB
Java
package net.minecraft.block;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.item.Item;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.IIcon;
|
|
import net.minecraft.util.MathHelper;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.gen.feature.WorldGenBigTree;
|
|
import net.minecraft.world.gen.feature.WorldGenCanopyTree;
|
|
import net.minecraft.world.gen.feature.WorldGenForest;
|
|
import net.minecraft.world.gen.feature.WorldGenMegaJungle;
|
|
import net.minecraft.world.gen.feature.WorldGenMegaPineTree;
|
|
import net.minecraft.world.gen.feature.WorldGenSavannaTree;
|
|
import net.minecraft.world.gen.feature.WorldGenTaiga2;
|
|
import net.minecraft.world.gen.feature.WorldGenTrees;
|
|
import net.minecraft.world.gen.feature.WorldGenerator;
|
|
|
|
public class BlockSapling extends BlockBush implements IGrowable
|
|
{
|
|
public static final String[] field_149882_a = new String[] {"oak", "spruce", "birch", "jungle", "acacia", "roofed_oak"};
|
|
private static final IIcon[] field_149881_b = new IIcon[field_149882_a.length];
|
|
private static final String __OBFID = "CL_00000305";
|
|
|
|
protected BlockSapling()
|
|
{
|
|
float f = 0.4F;
|
|
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
|
|
this.setCreativeTab(CreativeTabs.tabDecorations);
|
|
}
|
|
|
|
/**
|
|
* Ticks the block if it's been scheduled
|
|
*/
|
|
public void updateTick(World worldIn, int x, int y, int z, Random random)
|
|
{
|
|
if (!worldIn.isRemote)
|
|
{
|
|
super.updateTick(worldIn, x, y, z, random);
|
|
|
|
if (worldIn.getBlockLightValue(x, y + 1, z) >= 9 && random.nextInt(7) == 0)
|
|
{
|
|
this.func_149879_c(worldIn, x, y, z, random);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Gets the block's texture. Args: side, meta
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public IIcon getIcon(int side, int meta)
|
|
{
|
|
meta &= 7;
|
|
return field_149881_b[MathHelper.clamp_int(meta, 0, 5)];
|
|
}
|
|
|
|
public void func_149879_c(World p_149879_1_, int p_149879_2_, int p_149879_3_, int p_149879_4_, Random p_149879_5_)
|
|
{
|
|
int l = p_149879_1_.getBlockMetadata(p_149879_2_, p_149879_3_, p_149879_4_);
|
|
|
|
if ((l & 8) == 0)
|
|
{
|
|
p_149879_1_.setBlockMetadataWithNotify(p_149879_2_, p_149879_3_, p_149879_4_, l | 8, 4);
|
|
}
|
|
else
|
|
{
|
|
this.func_149878_d(p_149879_1_, p_149879_2_, p_149879_3_, p_149879_4_, p_149879_5_);
|
|
}
|
|
}
|
|
|
|
public void func_149878_d(World p_149878_1_, int p_149878_2_, int p_149878_3_, int p_149878_4_, Random p_149878_5_)
|
|
{
|
|
if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(p_149878_1_, p_149878_5_, p_149878_2_, p_149878_3_, p_149878_4_)) return;
|
|
int l = p_149878_1_.getBlockMetadata(p_149878_2_, p_149878_3_, p_149878_4_) & 7;
|
|
Object object = p_149878_5_.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true);
|
|
int i1 = 0;
|
|
int j1 = 0;
|
|
boolean flag = false;
|
|
|
|
switch (l)
|
|
{
|
|
case 0:
|
|
default:
|
|
break;
|
|
case 1:
|
|
label78:
|
|
|
|
for (i1 = 0; i1 >= -1; --i1)
|
|
{
|
|
for (j1 = 0; j1 >= -1; --j1)
|
|
{
|
|
if (this.func_149880_a(p_149878_1_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1, 1) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1, 1) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1 + 1, 1) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1 + 1, 1))
|
|
{
|
|
object = new WorldGenMegaPineTree(false, p_149878_5_.nextBoolean());
|
|
flag = true;
|
|
break label78;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!flag)
|
|
{
|
|
j1 = 0;
|
|
i1 = 0;
|
|
object = new WorldGenTaiga2(true);
|
|
}
|
|
|
|
break;
|
|
case 2:
|
|
object = new WorldGenForest(true, false);
|
|
break;
|
|
case 3:
|
|
label93:
|
|
|
|
for (i1 = 0; i1 >= -1; --i1)
|
|
{
|
|
for (j1 = 0; j1 >= -1; --j1)
|
|
{
|
|
if (this.func_149880_a(p_149878_1_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1, 3) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1, 3) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1 + 1, 3) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1 + 1, 3))
|
|
{
|
|
object = new WorldGenMegaJungle(true, 10, 20, 3, 3);
|
|
flag = true;
|
|
break label93;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!flag)
|
|
{
|
|
j1 = 0;
|
|
i1 = 0;
|
|
object = new WorldGenTrees(true, 4 + p_149878_5_.nextInt(7), 3, 3, false);
|
|
}
|
|
|
|
break;
|
|
case 4:
|
|
object = new WorldGenSavannaTree(true);
|
|
break;
|
|
case 5:
|
|
label108:
|
|
|
|
for (i1 = 0; i1 >= -1; --i1)
|
|
{
|
|
for (j1 = 0; j1 >= -1; --j1)
|
|
{
|
|
if (this.func_149880_a(p_149878_1_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1, 5) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1, 5) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1 + 1, 5) && this.func_149880_a(p_149878_1_, p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1 + 1, 5))
|
|
{
|
|
object = new WorldGenCanopyTree(true);
|
|
flag = true;
|
|
break label108;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!flag)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
Block block = Blocks.air;
|
|
|
|
if (flag)
|
|
{
|
|
p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1, block, 0, 4);
|
|
p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1, block, 0, 4);
|
|
p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1 + 1, block, 0, 4);
|
|
p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1 + 1, block, 0, 4);
|
|
}
|
|
else
|
|
{
|
|
p_149878_1_.setBlock(p_149878_2_, p_149878_3_, p_149878_4_, block, 0, 4);
|
|
}
|
|
|
|
if (!((WorldGenerator)object).generate(p_149878_1_, p_149878_5_, p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1))
|
|
{
|
|
if (flag)
|
|
{
|
|
p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1, this, l, 4);
|
|
p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1, this, l, 4);
|
|
p_149878_1_.setBlock(p_149878_2_ + i1, p_149878_3_, p_149878_4_ + j1 + 1, this, l, 4);
|
|
p_149878_1_.setBlock(p_149878_2_ + i1 + 1, p_149878_3_, p_149878_4_ + j1 + 1, this, l, 4);
|
|
}
|
|
else
|
|
{
|
|
p_149878_1_.setBlock(p_149878_2_, p_149878_3_, p_149878_4_, this, l, 4);
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean func_149880_a(World p_149880_1_, int p_149880_2_, int p_149880_3_, int p_149880_4_, int p_149880_5_)
|
|
{
|
|
return p_149880_1_.getBlock(p_149880_2_, p_149880_3_, p_149880_4_) == this && (p_149880_1_.getBlockMetadata(p_149880_2_, p_149880_3_, p_149880_4_) & 7) == p_149880_5_;
|
|
}
|
|
|
|
/**
|
|
* Determines the damage on the item the block drops. Used in cloth and wood.
|
|
*/
|
|
public int damageDropped(int meta)
|
|
{
|
|
return MathHelper.clamp_int(meta & 7, 0, 5);
|
|
}
|
|
|
|
/**
|
|
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public void getSubBlocks(Item itemIn, CreativeTabs tab, List list)
|
|
{
|
|
list.add(new ItemStack(itemIn, 1, 0));
|
|
list.add(new ItemStack(itemIn, 1, 1));
|
|
list.add(new ItemStack(itemIn, 1, 2));
|
|
list.add(new ItemStack(itemIn, 1, 3));
|
|
list.add(new ItemStack(itemIn, 1, 4));
|
|
list.add(new ItemStack(itemIn, 1, 5));
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerBlockIcons(IIconRegister reg)
|
|
{
|
|
for (int i = 0; i < field_149881_b.length; ++i)
|
|
{
|
|
field_149881_b[i] = reg.registerIcon(this.getTextureName() + "_" + field_149882_a[i]);
|
|
}
|
|
}
|
|
|
|
public boolean func_149851_a(World worldIn, int x, int y, int z, boolean isClient)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public boolean func_149852_a(World worldIn, Random random, int x, int y, int z)
|
|
{
|
|
return (double)worldIn.rand.nextFloat() < 0.45D;
|
|
}
|
|
|
|
public void func_149853_b(World worldIn, Random random, int x, int y, int z)
|
|
{
|
|
this.func_149879_c(worldIn, x, y, z, random);
|
|
}
|
|
} |