blob: e3fd4db9a5f5d6dbe1271ed32226b3a723f24180 [file] [log] [blame] [raw]
package mekanism.common.item;
import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.client.MekKeyHandler;
import mekanism.client.MekanismKeyHandler;
import mekanism.common.Mekanism;
import mekanism.common.security.IOwnerItem;
import mekanism.common.util.LangUtils;
import mekanism.common.util.SecurityUtils;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
public class ItemPortableTeleporter extends ItemEnergized implements IOwnerItem
{
public ItemPortableTeleporter()
{
super(1000000);
}
@Override
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
list.add(SecurityUtils.getOwnerDisplay(entityplayer.getName(), getOwner(itemstack)));
if(getFrequency(itemstack) != null)
{
list.add(EnumColor.INDIGO + LangUtils.localize("gui.frequency") + ": " + EnumColor.GREY + getFrequency(itemstack));
list.add(EnumColor.INDIGO + LangUtils.localize("gui.mode") + ": " + EnumColor.GREY + LangUtils.localize("gui." + (isPrivateMode(itemstack) ? "private" : "public")));
}
if(!MekKeyHandler.getIsKeyPressed(MekanismKeyHandler.sneakKey))
{
list.add(LangUtils.localize("tooltip.hold") + " " + EnumColor.AQUA + GameSettings.getKeyDisplayString(MekanismKeyHandler.sneakKey.getKeyCode()) + EnumColor.GREY + " " + LangUtils.localize("tooltip.forDetails") + ".");
}
else {
super.addInformation(itemstack, entityplayer, list, flag);
}
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
if(!world.isRemote)
{
if(getOwner(itemstack) == null)
{
setOwner(itemstack, entityplayer.getName());
entityplayer.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("gui.nowOwn")));
}
else {
if(SecurityUtils.canAccess(entityplayer, itemstack))
{
entityplayer.openGui(Mekanism.instance, 14, world, 0, 0, 0);
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
}
}
return itemstack;
}
public static double calculateEnergyCost(Entity entity, Coord4D coords)
{
if(coords == null)
{
return 0;
}
int neededEnergy = 1000;
if(entity.worldObj.provider.getDimensionId() != coords.dimensionId)
{
neededEnergy+=10000;
}
int distance = (int)entity.getDistance(coords.getX(), coords.getY(), coords.getZ());
neededEnergy+=(distance*10);
return neededEnergy;
}
@Override
public boolean canSend(ItemStack itemStack)
{
return false;
}
@Override
public String getOwner(ItemStack stack)
{
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("owner"))
{
return stack.getTagCompound().getString("owner");
}
return null;
}
@Override
public void setOwner(ItemStack stack, String owner)
{
setFrequency(stack, null);
setPrivateMode(stack, false);
if(owner == null || owner.isEmpty())
{
stack.getTagCompound().removeTag("owner");
return;
}
stack.getTagCompound().setString("owner", owner);
}
@Override
public boolean hasOwner(ItemStack stack)
{
return true;
}
public boolean isPrivateMode(ItemStack stack)
{
if(stack.hasTagCompound())
{
return stack.getTagCompound().getBoolean("private");
}
return false;
}
public void setPrivateMode(ItemStack stack, boolean isPrivate)
{
if(!stack.hasTagCompound())
{
stack.setTagCompound(new NBTTagCompound());
}
stack.getTagCompound().setBoolean("private", isPrivate);
}
public String getFrequency(ItemStack stack)
{
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("frequency"))
{
return stack.getTagCompound().getString("frequency");
}
return null;
}
public void setFrequency(ItemStack stack, String frequency)
{
if(!stack.hasTagCompound())
{
stack.setTagCompound(new NBTTagCompound());
}
if(frequency == null || frequency.isEmpty())
{
stack.getTagCompound().removeTag("frequency");
return;
}
stack.getTagCompound().setString("frequency", frequency);
}
}