Mekanism-tilera-Edition/src/main/java/mekanism/common/Upgrade.java

176 lines
3.9 KiB
Java
Raw Normal View History

package mekanism.common;
import java.util.ArrayList;
2014-07-22 03:21:53 +02:00
import java.util.HashMap;
import java.util.List;
2014-07-22 03:21:53 +02:00
import java.util.Map;
import mekanism.api.EnumColor;
import mekanism.api.MekanismConfig.general;
import mekanism.common.base.IUpgradeTile;
2015-05-11 01:04:42 +02:00
import mekanism.common.util.LangUtils;
import net.minecraft.item.ItemStack;
2014-07-22 03:21:53 +02:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
2014-07-22 03:21:53 +02:00
import net.minecraftforge.common.util.Constants.NBT;
public enum Upgrade
{
2014-07-22 03:21:53 +02:00
SPEED("speed", 8, EnumColor.RED),
ENERGY("energy", 8, EnumColor.BRIGHT_GREEN),
2015-03-21 19:16:42 +01:00
FILTER("filter", 1, EnumColor.DARK_AQUA),
GAS("gas", 8, EnumColor.YELLOW),
MUFFLING("muffling", 4, EnumColor.DARK_GREY);
private String name;
2014-07-22 02:46:35 +02:00
private int maxStack;
2014-07-22 03:21:53 +02:00
private EnumColor color;
2014-07-22 03:21:53 +02:00
private Upgrade(String s, int max, EnumColor c)
{
name = s;
2014-07-22 02:46:35 +02:00
maxStack = max;
2014-07-22 03:21:53 +02:00
color = c;
}
public String getName()
{
2015-05-11 01:04:42 +02:00
return LangUtils.localize("upgrade." + name);
}
public String getDescription()
{
2015-05-11 01:04:42 +02:00
return LangUtils.localize("upgrade." + name + ".desc");
}
2014-07-22 02:46:35 +02:00
public int getMax()
{
return maxStack;
}
2014-07-22 03:21:53 +02:00
public EnumColor getColor()
{
return color;
}
2014-07-22 03:21:53 +02:00
public boolean canMultiply()
{
return getMax() > 1;
}
public ItemStack getStack()
{
switch(this)
{
case SPEED:
return new ItemStack(MekanismItems.SpeedUpgrade);
case ENERGY:
return new ItemStack(MekanismItems.EnergyUpgrade);
case FILTER:
return new ItemStack(MekanismItems.FilterUpgrade);
case MUFFLING:
return new ItemStack(MekanismItems.MufflingUpgrade);
2015-03-21 19:16:42 +01:00
case GAS:
return new ItemStack(MekanismItems.GasUpgrade);
}
return null;
}
public List<String> getInfo(TileEntity tile)
{
List<String> ret = new ArrayList<String>();
if(tile instanceof IUpgradeTile)
{
if(tile instanceof IUpgradeInfoHandler)
{
return ((IUpgradeInfoHandler)tile).getInfo(this);
}
else {
ret = getMultScaledInfo((IUpgradeTile)tile);
}
}
return ret;
}
public List<String> getMultScaledInfo(IUpgradeTile tile)
{
List<String> ret = new ArrayList<String>();
if(canMultiply())
{
double effect = Math.pow(general.maxUpgradeMultiplier, (float)tile.getComponent().getUpgrades(this)/(float)getMax());
2015-05-11 01:04:42 +02:00
ret.add(LangUtils.localize("gui.upgrades.effect") + ": " + (Math.round(effect*100)/100F) + "x");
}
return ret;
}
public List<String> getExpScaledInfo(IUpgradeTile tile)
{
List<String> ret = new ArrayList<String>();
if(canMultiply())
{
double effect = Math.pow(2, (float)tile.getComponent().getUpgrades(this));
2015-05-11 01:04:42 +02:00
ret.add(LangUtils.localize("gui.upgrades.effect") + ": " + effect + "x");
}
return ret;
}
2014-07-22 03:21:53 +02:00
public static Map<Upgrade, Integer> buildMap(NBTTagCompound nbtTags)
{
Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
if(nbtTags != null)
2014-07-22 03:21:53 +02:00
{
if(nbtTags.hasKey("upgrades"))
2014-07-22 03:33:43 +02:00
{
NBTTagList list = nbtTags.getTagList("upgrades", NBT.TAG_COMPOUND);
2014-07-22 03:33:43 +02:00
for(int tagCount = 0; tagCount < list.tagCount(); tagCount++)
{
NBTTagCompound compound = list.getCompoundTagAt(tagCount);
Upgrade upgrade = Upgrade.values()[compound.getInteger("type")];
upgrades.put(upgrade, compound.getInteger("amount"));
}
}
2014-07-22 03:21:53 +02:00
}
return upgrades;
}
public static void saveMap(Map<Upgrade, Integer> upgrades, NBTTagCompound nbtTags)
{
NBTTagList list = new NBTTagList();
for(Map.Entry<Upgrade, Integer> entry : upgrades.entrySet())
{
list.appendTag(getTagFor(entry.getKey(), entry.getValue()));
}
nbtTags.setTag("upgrades", list);
}
public static NBTTagCompound getTagFor(Upgrade upgrade, int amount)
{
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("type", upgrade.ordinal());
compound.setInteger("amount", amount);
return compound;
}
public static interface IUpgradeInfoHandler
{
public List<String> getInfo(Upgrade upgrade);
}
}