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.
233 lines
6.8 KiB
Java
233 lines
6.8 KiB
Java
package net.minecraft.block;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
import java.util.ArrayList;
|
|
import java.util.Random;
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.init.Items;
|
|
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.minecraftforge.common.util.ForgeDirection;
|
|
|
|
public class BlockCrops extends BlockBush implements IGrowable
|
|
{
|
|
@SideOnly(Side.CLIENT)
|
|
private IIcon[] field_149867_a;
|
|
private static final String __OBFID = "CL_00000222";
|
|
|
|
protected BlockCrops()
|
|
{
|
|
this.setTickRandomly(true);
|
|
float f = 0.5F;
|
|
this.setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.25F, 0.5F + f);
|
|
this.setCreativeTab((CreativeTabs)null);
|
|
this.setHardness(0.0F);
|
|
this.setStepSound(soundTypeGrass);
|
|
this.disableStats();
|
|
}
|
|
|
|
/**
|
|
* is the block grass, dirt or farmland
|
|
*/
|
|
protected boolean canPlaceBlockOn(Block ground)
|
|
{
|
|
return ground == Blocks.farmland;
|
|
}
|
|
|
|
/**
|
|
* Ticks the block if it's been scheduled
|
|
*/
|
|
public void updateTick(World worldIn, int x, int y, int z, Random random)
|
|
{
|
|
super.updateTick(worldIn, x, y, z, random);
|
|
|
|
if (worldIn.getBlockLightValue(x, y + 1, z) >= 9)
|
|
{
|
|
int l = worldIn.getBlockMetadata(x, y, z);
|
|
|
|
if (l < 7)
|
|
{
|
|
float f = this.func_149864_n(worldIn, x, y, z);
|
|
|
|
if (random.nextInt((int)(25.0F / f) + 1) == 0)
|
|
{
|
|
++l;
|
|
worldIn.setBlockMetadataWithNotify(x, y, z, l, 2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void func_149863_m(World p_149863_1_, int p_149863_2_, int p_149863_3_, int p_149863_4_)
|
|
{
|
|
int l = p_149863_1_.getBlockMetadata(p_149863_2_, p_149863_3_, p_149863_4_) + MathHelper.getRandomIntegerInRange(p_149863_1_.rand, 2, 5);
|
|
|
|
if (l > 7)
|
|
{
|
|
l = 7;
|
|
}
|
|
|
|
p_149863_1_.setBlockMetadataWithNotify(p_149863_2_, p_149863_3_, p_149863_4_, l, 2);
|
|
}
|
|
|
|
private float func_149864_n(World p_149864_1_, int p_149864_2_, int p_149864_3_, int p_149864_4_)
|
|
{
|
|
float f = 1.0F;
|
|
Block block = p_149864_1_.getBlock(p_149864_2_, p_149864_3_, p_149864_4_ - 1);
|
|
Block block1 = p_149864_1_.getBlock(p_149864_2_, p_149864_3_, p_149864_4_ + 1);
|
|
Block block2 = p_149864_1_.getBlock(p_149864_2_ - 1, p_149864_3_, p_149864_4_);
|
|
Block block3 = p_149864_1_.getBlock(p_149864_2_ + 1, p_149864_3_, p_149864_4_);
|
|
Block block4 = p_149864_1_.getBlock(p_149864_2_ - 1, p_149864_3_, p_149864_4_ - 1);
|
|
Block block5 = p_149864_1_.getBlock(p_149864_2_ + 1, p_149864_3_, p_149864_4_ - 1);
|
|
Block block6 = p_149864_1_.getBlock(p_149864_2_ + 1, p_149864_3_, p_149864_4_ + 1);
|
|
Block block7 = p_149864_1_.getBlock(p_149864_2_ - 1, p_149864_3_, p_149864_4_ + 1);
|
|
boolean flag = block2 == this || block3 == this;
|
|
boolean flag1 = block == this || block1 == this;
|
|
boolean flag2 = block4 == this || block5 == this || block6 == this || block7 == this;
|
|
|
|
for (int l = p_149864_2_ - 1; l <= p_149864_2_ + 1; ++l)
|
|
{
|
|
for (int i1 = p_149864_4_ - 1; i1 <= p_149864_4_ + 1; ++i1)
|
|
{
|
|
float f1 = 0.0F;
|
|
|
|
if (p_149864_1_.getBlock(l, p_149864_3_ - 1, i1).canSustainPlant(p_149864_1_, l, p_149864_3_ - 1, i1, ForgeDirection.UP, this))
|
|
{
|
|
f1 = 1.0F;
|
|
|
|
if (p_149864_1_.getBlock(l, p_149864_3_ - 1, i1).isFertile(p_149864_1_, l, p_149864_3_ - 1, i1))
|
|
{
|
|
f1 = 3.0F;
|
|
}
|
|
}
|
|
|
|
if (l != p_149864_2_ || i1 != p_149864_4_)
|
|
{
|
|
f1 /= 4.0F;
|
|
}
|
|
|
|
f += f1;
|
|
}
|
|
}
|
|
|
|
if (flag2 || flag && flag1)
|
|
{
|
|
f /= 2.0F;
|
|
}
|
|
|
|
return f;
|
|
}
|
|
|
|
/**
|
|
* Gets the block's texture. Args: side, meta
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public IIcon getIcon(int side, int meta)
|
|
{
|
|
if (meta < 0 || meta > 7)
|
|
{
|
|
meta = 7;
|
|
}
|
|
|
|
return this.field_149867_a[meta];
|
|
}
|
|
|
|
/**
|
|
* The type of render function that is called for this block
|
|
*/
|
|
public int getRenderType()
|
|
{
|
|
return 6;
|
|
}
|
|
|
|
protected Item func_149866_i()
|
|
{
|
|
return Items.wheat_seeds;
|
|
}
|
|
|
|
protected Item func_149865_P()
|
|
{
|
|
return Items.wheat;
|
|
}
|
|
|
|
/**
|
|
* Drops the block items with a specified chance of dropping the specified items
|
|
*/
|
|
public void dropBlockAsItemWithChance(World worldIn, int x, int y, int z, int meta, float chance, int fortune)
|
|
{
|
|
super.dropBlockAsItemWithChance(worldIn, x, y, z, meta, chance, 0);
|
|
}
|
|
|
|
public Item getItemDropped(int meta, Random random, int fortune)
|
|
{
|
|
return meta == 7 ? this.func_149865_P() : this.func_149866_i();
|
|
}
|
|
|
|
/**
|
|
* Returns the quantity of items to drop on block destruction.
|
|
*/
|
|
public int quantityDropped(Random random)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
public boolean func_149851_a(World worldIn, int x, int y, int z, boolean isClient)
|
|
{
|
|
return worldIn.getBlockMetadata(x, y, z) != 7;
|
|
}
|
|
|
|
public boolean func_149852_a(World worldIn, Random random, int x, int y, int z)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Gets an item for the block being called on. Args: world, x, y, z
|
|
*/
|
|
@SideOnly(Side.CLIENT)
|
|
public Item getItem(World worldIn, int x, int y, int z)
|
|
{
|
|
return this.func_149866_i();
|
|
}
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
public void registerBlockIcons(IIconRegister reg)
|
|
{
|
|
this.field_149867_a = new IIcon[8];
|
|
|
|
for (int i = 0; i < this.field_149867_a.length; ++i)
|
|
{
|
|
this.field_149867_a[i] = reg.registerIcon(this.getTextureName() + "_stage_" + i);
|
|
}
|
|
}
|
|
|
|
public void func_149853_b(World worldIn, Random random, int x, int y, int z)
|
|
{
|
|
this.func_149863_m(worldIn, x, y, z);
|
|
}
|
|
|
|
@Override
|
|
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune)
|
|
{
|
|
ArrayList<ItemStack> ret = super.getDrops(world, x, y, z, metadata, fortune);
|
|
|
|
if (metadata >= 7)
|
|
{
|
|
for (int i = 0; i < 3 + fortune; ++i)
|
|
{
|
|
if (world.rand.nextInt(15) <= metadata)
|
|
{
|
|
ret.add(new ItemStack(this.func_149866_i(), 1, 0));
|
|
}
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
} |