BiomesOPlenty/src/minecraft/biomesoplenty/blocks/BlockBOPCoral.java

208 lines
5 KiB
Java
Raw Normal View History

2013-05-23 03:30:41 +00:00
package biomesoplenty.blocks;
import java.util.List;
import java.util.Random;
2013-05-23 03:30:41 +00:00
import net.minecraft.block.Block;
import net.minecraft.block.BlockFlower;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
2013-09-08 14:43:08 +00:00
import net.minecraft.world.IBlockAccess;
2013-05-23 03:30:41 +00:00
import net.minecraft.world.World;
import biomesoplenty.BiomesOPlenty;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockBOPCoral extends BlockFlower
{
2013-09-08 14:43:08 +00:00
private static final String[] coral = new String[] {"kelpbottom", "kelpmiddle", "kelptop", "kelpsingle", "pinkcoral", "orangecoral", "bluecoral", "glowcoral"};
2013-05-31 10:34:02 +00:00
private Icon[] textures;
protected BlockBOPCoral(int blockID, Material material)
{
super(blockID, material);
this.setTickRandomly(true);
float f = 0.4F;
setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, 0.8F, 0.5F + f);
this.setCreativeTab(BiomesOPlenty.tabBiomesOPlenty);
}
public BlockBOPCoral(int blockID)
{
this(blockID, Material.water);
}
@Override
public void registerIcons(IconRegister iconRegister)
{
textures = new Icon[coral.length];
for (int i = 0; i < coral.length; ++i) {
textures[i] = iconRegister.registerIcon("biomesoplenty:" + coral[i]);
2013-05-31 10:34:02 +00:00
}
}
@Override
public Icon getIcon(int side, int meta)
{
if (meta < 0 || meta >= textures.length) {
meta = 0;
}
return textures[meta];
}
@Override
public int getRenderType ()
{
return 1;
}
@Override
@SideOnly(Side.CLIENT)
@SuppressWarnings({ "rawtypes", "unchecked" })
public void getSubBlocks(int blockID, CreativeTabs creativeTabs, List list) {
for (int i = 0; i < coral.length; ++i)
2013-05-23 03:30:41 +00:00
{
2013-09-08 14:43:08 +00:00
if (i > 2)
2013-05-23 03:30:41 +00:00
{
list.add(new ItemStack(blockID, 1, i));
}
}
2013-05-31 10:34:02 +00:00
}
@Override
protected boolean canThisPlantGrowOnThisBlockID(int id)
{
return id == Block.dirt.blockID || id == Block.sand.blockID || id == blockID;
2013-05-31 10:34:02 +00:00
}
protected boolean canThisPlantGrowOnThisBlockID(int id, int metadata)
{
if (metadata == 1)
return id == blockID;
if (metadata == 2)
return id == blockID || id == Block.dirt.blockID || id == Block.sand.blockID;
else
return id == Block.dirt.blockID || id == Block.sand.blockID;
2013-05-31 10:34:02 +00:00
}
@Override
public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side, ItemStack itemStack)
{
int id = world.getBlockId(x, y - 1, z);
int meta = itemStack.getItemDamage();
//boolean sky = world.getFullBlockLightValue(x, y, z) >= 8 || world.canBlockSeeTheSky(x, y, z);
if (itemStack.itemID == blockID) {
switch (meta)
{
case 1: // Kelp Middle
return id == blockID;
case 2: // Kelp Bottom
return id == blockID;
default:
return id == Block.dirt.blockID || id == Block.sand.blockID;
}
} else
2013-05-31 10:34:02 +00:00
return this.canPlaceBlockOnSide(world, x, y, z, side);
}
2013-09-08 18:41:07 +00:00
2013-05-31 10:34:02 +00:00
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID)
{
2013-09-08 18:41:07 +00:00
super.onNeighborBlockChange(world, x, y, z, neighborID);
2013-05-31 10:34:02 +00:00
this.checkFlowerChange(world, x, y, z);
2013-09-08 18:41:07 +00:00
if (world.getBlockMetadata(x, y, z) == 0 && world.getBlockId(x, y + 1, z) != blockID)
{
world.setBlock(x, y, z, blockID, 3, 2);
}
if (world.getBlockMetadata(x, y, z) == 1 && world.getBlockId(x, y + 1, z) != blockID)
{
if (world.getBlockMetadata(x, y, z) == 1 && world.getBlockId(x, y - 1, z) == blockID)
{
world.setBlock(x, y, z, blockID, 2, 2);
}
else
{
world.setBlock(x, y, z, Block.waterMoving.blockID, 0, 2);
}
}
if (world.getBlockMetadata(x, y, z) == 1 && world.getBlockId(x, y - 1, z) != blockID)
{
world.setBlock(x, y, z, Block.waterMoving.blockID, 0, 2);
}
if (world.getBlockMetadata(x, y, z) == 2 && world.getBlockId(x, y - 1, z) == blockID)
{
world.setBlock(x, y, z, Block.waterMoving.blockID, 0, 2);
}
2013-05-31 10:34:02 +00:00
}
@Override
public int damageDropped(int meta)
{
2013-09-08 17:10:08 +00:00
if (meta < 3)
{
return 3;
}
return meta;
2013-05-31 10:34:02 +00:00
}
@Override
public int quantityDropped(int meta, int fortune, Random random)
{
2013-05-23 03:30:41 +00:00
return 1;
2013-05-31 10:34:02 +00:00
}
2013-09-08 14:43:08 +00:00
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta == 7)
return 10;
else
return 0;
}
@Override
public int getDamageValue(World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta < 3) {
meta = 3;
}
return meta;
}
2013-05-31 10:34:02 +00:00
@Override
public boolean canBlockStay(World world, int x, int y, int z)
{
if (world.getBlockId(x, y, z) != blockID)
return this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z));
2013-05-31 10:34:02 +00:00
else
return this.canThisPlantGrowOnThisBlockID(world.getBlockId(x, y - 1, z), world.getBlockMetadata(x, y, z));
2013-05-31 10:34:02 +00:00
}
@Override
public boolean isBlockReplaceable(World world, int x, int y, int z)
{
//ItemStack itemstack = new ItemStack(Blocks.flowers.get(), 1, 10);
if (world.getBlockMetadata(x, y, z) == 10)
//if (!world.isRemote)
//world.spawnEntityInWorld(new EntityItem(world, x, y, z, itemstack));
return true;
return false;
}
2013-05-23 03:30:41 +00:00
}