package micdoodle8.mods.galacticraft.planets.asteroids.items;
import micdoodle8.mods.galacticraft.core.items.ISortableItem;
import micdoodle8.mods.galacticraft.core.items.ItemCanisterGeneric;
import micdoodle8.mods.galacticraft.core.util.EnumSortCategoryItem;
import micdoodle8.mods.galacticraft.core.util.GCCoreUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemCanisterLiquidNitrogen extends ItemCanisterGeneric implements ISortableItem
{
// protected IIcon[] icons = new IIcon[7];
public ItemCanisterLiquidNitrogen(String assetName)
{
super(assetName);
this.setAllowedFluid("liquidnitrogen");
//this.setTextureName(GalacticraftPlanets.TEXTURE_PREFIX + assetName);
}
/*@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister)
{
for (int i = 0; i < this.icons.length; i++)
{
this.icons[i] = iconRegister.registerIcon(this.getIconString() + "_" + i);
}
}*/
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
if (itemStack.getMaxDamage() - itemStack.getItemDamage() == 0)
{
return "item.empty_gas_canister";
}
if (itemStack.getItemDamage() == 1)
{
return "item.canister.liquid_nitrogen.full";
}
return "item.canister.liquid_nitrogen.partial";
}
/*@Override
public IIcon getIconFromDamage(int par1)
{
final int damage = 6 * par1 / this.getMaxDamage();
if (this.icons.length > damage)
{
return this.icons[this.icons.length - damage - 1];
}
return super.getIconFromDamage(damage);
}*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List<String> tooltip, boolean par4)
{
if (par1ItemStack.getMaxDamage() - par1ItemStack.getItemDamage() > 0)
{
tooltip.add(GCCoreUtil.translate("item.canister.liquid_nitrogen.name") + ": " + (par1ItemStack.getMaxDamage() - par1ItemStack.getItemDamage()));
}
}
private Block canFreeze(Block b)
{
if (b == Blocks.water)
{
return Blocks.ice;
}
if (b == Blocks.lava)
{
return Blocks.obsidian;
}
return null;
}
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World par2World, EntityPlayer par3EntityPlayer)
{
int damage = itemStack.getItemDamage() + 125;
if (damage > itemStack.getMaxDamage())
{
return itemStack;
}
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);
if (movingobjectposition == null)
{
return itemStack;
}
else
{
if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
{
BlockPos pos = movingobjectposition.getBlockPos();
if (!par2World.canMineBlockBody(par3EntityPlayer, pos))
{
return itemStack;
}
if (!par3EntityPlayer.canPlayerEdit(pos, movingobjectposition.sideHit, itemStack))
{
return itemStack;
}
//Material material = par2World.getBlock(i, j, k).getMaterial();
IBlockState state = par2World.getBlockState(pos);
Block b = state.getBlock();
int meta = b.getMetaFromState(state);
Block result = this.canFreeze(b);
if (result != null)
{
this.setNewDamage(itemStack, damage);
par2World.playSoundEffect(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, "fire.ignite", 1.0F, Item.itemRand.nextFloat() * 0.4F + 0.8F);
par2World.setBlockState(pos, result.getDefaultState(), 3);
return itemStack;
}
}
return itemStack;
}
}
@Override
public EnumSortCategoryItem getCategory(int meta)
{
return EnumSortCategoryItem.CANISTER;
}
}