2014-07-21 20:57:31 +02:00
|
|
|
package mekanism.common;
|
|
|
|
|
2014-07-23 17:06:58 +02:00
|
|
|
import java.util.ArrayList;
|
2014-07-22 03:21:53 +02:00
|
|
|
import java.util.HashMap;
|
2014-07-23 17:06:58 +02:00
|
|
|
import java.util.List;
|
2014-07-22 03:21:53 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import mekanism.api.EnumColor;
|
2014-08-01 01:58:12 +02:00
|
|
|
import mekanism.api.MekanismConfig.general;
|
2014-08-10 04:20:49 +02:00
|
|
|
import mekanism.common.base.IUpgradeTile;
|
2015-05-11 01:04:42 +02:00
|
|
|
import mekanism.common.util.LangUtils;
|
2014-07-23 02:37:53 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-07-22 03:21:53 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2014-07-23 17:06:58 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-07-22 03:21:53 +02:00
|
|
|
import net.minecraftforge.common.util.Constants.NBT;
|
2014-07-21 20:57:31 +02:00
|
|
|
|
|
|
|
public enum Upgrade
|
|
|
|
{
|
2014-07-22 03:21:53 +02:00
|
|
|
SPEED("speed", 8, EnumColor.RED),
|
2015-02-18 03:27:35 +01:00
|
|
|
ENERGY("energy", 8, EnumColor.BRIGHT_GREEN),
|
2015-03-21 19:16:42 +01:00
|
|
|
FILTER("filter", 1, EnumColor.DARK_AQUA),
|
2016-02-03 04:55:26 +01:00
|
|
|
GAS("gas", 8, EnumColor.YELLOW),
|
|
|
|
MUFFLING("muffling", 4, EnumColor.DARK_GREY);
|
2014-07-21 20:57:31 +02:00
|
|
|
|
|
|
|
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-21 20:57:31 +02:00
|
|
|
|
2014-07-22 03:21:53 +02:00
|
|
|
private Upgrade(String s, int max, EnumColor c)
|
2014-07-21 20:57:31 +02:00
|
|
|
{
|
|
|
|
name = s;
|
2014-07-22 02:46:35 +02:00
|
|
|
maxStack = max;
|
2014-07-22 03:21:53 +02:00
|
|
|
color = c;
|
2014-07-21 20:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getName()
|
|
|
|
{
|
2015-05-11 01:04:42 +02:00
|
|
|
return LangUtils.localize("upgrade." + name);
|
2014-07-21 20:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getDescription()
|
|
|
|
{
|
2015-05-11 01:04:42 +02:00
|
|
|
return LangUtils.localize("upgrade." + name + ".desc");
|
2014-07-21 20:57:31 +02:00
|
|
|
}
|
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-23 16:17:03 +02:00
|
|
|
}
|
2014-07-22 03:21:53 +02:00
|
|
|
|
|
|
|
public boolean canMultiply()
|
|
|
|
{
|
|
|
|
return getMax() > 1;
|
|
|
|
}
|
|
|
|
|
2014-07-23 02:37:53 +02:00
|
|
|
public ItemStack getStack()
|
|
|
|
{
|
|
|
|
switch(this)
|
|
|
|
{
|
|
|
|
case SPEED:
|
2014-08-01 01:58:12 +02:00
|
|
|
return new ItemStack(MekanismItems.SpeedUpgrade);
|
2014-07-23 02:37:53 +02:00
|
|
|
case ENERGY:
|
2014-08-01 01:58:12 +02:00
|
|
|
return new ItemStack(MekanismItems.EnergyUpgrade);
|
2015-02-18 03:27:35 +01:00
|
|
|
case FILTER:
|
|
|
|
return new ItemStack(MekanismItems.FilterUpgrade);
|
2016-02-03 04:55:26 +01:00
|
|
|
case MUFFLING:
|
|
|
|
return new ItemStack(MekanismItems.MufflingUpgrade);
|
2015-03-21 19:16:42 +01:00
|
|
|
case GAS:
|
|
|
|
return new ItemStack(MekanismItems.GasUpgrade);
|
2014-07-23 02:37:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-07-23 17:06:58 +02:00
|
|
|
public List<String> getInfo(TileEntity tile)
|
|
|
|
{
|
|
|
|
List<String> ret = new ArrayList<String>();
|
|
|
|
|
|
|
|
if(tile instanceof IUpgradeTile)
|
|
|
|
{
|
2015-02-26 22:47:36 +01:00
|
|
|
if(tile instanceof IUpgradeInfoHandler)
|
2014-07-23 17:06:58 +02:00
|
|
|
{
|
2015-02-26 22:47:36 +01:00
|
|
|
return ((IUpgradeInfoHandler)tile).getInfo(this);
|
2014-07-23 17:06:58 +02:00
|
|
|
}
|
2015-02-26 22:47:36 +01:00
|
|
|
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");
|
2015-02-26 22:47:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
2014-07-23 17:06:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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>();
|
|
|
|
|
2015-03-19 23:57:09 +01:00
|
|
|
if(nbtTags != null)
|
2014-07-22 03:21:53 +02:00
|
|
|
{
|
2015-03-19 23:57:09 +01:00
|
|
|
if(nbtTags.hasKey("upgrades"))
|
2014-07-22 03:33:43 +02:00
|
|
|
{
|
2015-03-19 23:57:09 +01:00
|
|
|
NBTTagList list = nbtTags.getTagList("upgrades", NBT.TAG_COMPOUND);
|
2014-07-22 03:33:43 +02:00
|
|
|
|
2015-03-19 23:57:09 +01: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;
|
|
|
|
}
|
2015-02-26 22:47:36 +01:00
|
|
|
|
|
|
|
public static interface IUpgradeInfoHandler
|
|
|
|
{
|
|
|
|
public List<String> getInfo(Upgrade upgrade);
|
|
|
|
}
|
2014-07-21 20:57:31 +02:00
|
|
|
}
|