BiomesOPlenty/common/biomesoplenty/itemblocks/ItemBlockCoral.java

148 lines
3.5 KiB
Java
Raw Normal View History

2013-07-03 07:51:39 +00:00
package biomesoplenty.itemblocks;
2013-05-23 03:30:41 +00:00
import net.minecraft.block.Block;
2013-09-08 14:43:08 +00:00
import net.minecraft.client.renderer.texture.IconRegister;
2013-05-23 03:30:41 +00:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2013-05-23 03:30:41 +00:00
2013-07-03 07:51:39 +00:00
public class ItemBlockCoral extends ItemBlock
2013-05-23 03:30:41 +00:00
{
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
@SideOnly(Side.CLIENT)
private Icon[] textures;
2013-07-03 07:51:39 +00:00
public ItemBlockCoral(int par1)
2013-05-31 10:34:02 +00:00
{
super(par1);
setMaxDamage(0);
setHasSubtypes(true);
}
@Override
public int getMetadata(int meta)
{
return meta & 15;
}
2013-09-08 14:43:08 +00:00
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
textures = new Icon[1];
textures[0] = iconRegister.registerIcon("biomesoplenty:item_kelp");
}
2013-05-31 10:34:02 +00:00
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
int meta = itemStack.getItemDamage();
if (meta < 0 || meta >= coral.length) {
meta = 0;
}
2013-06-09 06:47:13 +00:00
return super.getUnlocalizedName() + "." + coral[meta];
2013-05-31 10:34:02 +00:00
}
@Override
public Icon getIconFromDamage(int meta)
{
2013-09-08 14:43:08 +00:00
if (meta == 3)
return textures[0];
else
return Block.blocksList[itemID].getIcon(0, meta);
2013-05-31 10:34:02 +00:00
}
@Override
public EnumAction getItemUseAction(ItemStack par1ItemStack)
{
2013-05-23 03:30:41 +00:00
return null;
2013-05-31 10:34:02 +00:00
}
@Override
public int getMaxItemUseDuration(ItemStack par1ItemStack)
{
return 20;
}
@Override
public boolean onItemUse(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
int id = world.getBlockId(x, y, z);
if (id == Block.snow.blockID && (world.getBlockMetadata(x, y, z) & 7) < 1)
{
side = 1;
}
else if (id != Block.vine.blockID && id != Block.tallGrass.blockID && id != Block.deadBush.blockID && (Block.blocksList[id] == null || !Block.blocksList[id].isBlockReplaceable(world, x, y, z)))
{
if (side == 0)
{
--y;
}
if (side == 1)
{
++y;
}
if (side == 2)
{
--z;
}
if (side == 3)
{
++z;
}
if (side == 4)
{
--x;
}
if (side == 5)
{
++x;
}
}
if (itemstack.stackSize == 0)
return false;
else if (!player.canPlayerEdit(x, y, z, side, itemstack))
return false;
else if (y == 255 && Block.blocksList[itemID].blockMaterial.isSolid())
return false;
else if (world.canPlaceEntityOnSide(itemID, x, y, z, false, side, player, itemstack))
{
2013-09-08 18:23:45 +00:00
if (world.getBlockId(x, y + 1, z) == Block.waterStill.blockID || world.getBlockId(x, y + 1, z) == Block.waterMoving.blockID)
2013-05-31 10:34:02 +00:00
{
onItemUsePlaceBlock(itemstack, player, world, x, y, z, side, hitX, hitY, hitZ);
return true;
}
}
return false;
}
public void onItemUsePlaceBlock(ItemStack itemstack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
{
Block block = Block.blocksList[itemID];
int j1 = this.getMetadata(itemstack.getItemDamage());
2013-05-31 10:34:02 +00:00
int k1 = Block.blocksList[itemID].onBlockPlaced(world, x, y, z, side, hitX, hitY, hitZ, j1);
2013-05-23 03:30:41 +00:00
if (placeBlockAt(itemstack, player, world, x, y, z, side, hitX, hitY, hitZ, k1))
2013-05-31 10:34:02 +00:00
{
world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, block.stepSound.getPlaceSound(), (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F);
--itemstack.stackSize;
}
2013-05-31 10:34:02 +00:00
}
2013-05-23 03:30:41 +00:00
}