mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-21 12:32:13 +00:00
More work!
This commit is contained in:
1 parent
2523d2fd6b
commit
076c5f7377
8 files changed
+116
-62
No files matched your search
@@ -1,19 +1,29 @@
|
||||
package mekanism.common;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants.NBT;
|
||||
|
||||
public enum Upgrade
|
||||
{
|
||||
SPEED("speed", 16),
|
||||
ENERGY("energy", 16);
|
||||
SPEED("speed", 8, EnumColor.RED),
|
||||
ENERGY("energy", 8, EnumColor.BRIGHT_GREEN);
|
||||
|
||||
private String name;
|
||||
private int maxStack;
|
||||
private EnumColor color;
|
||||
private boolean canMultiply;
|
||||
|
||||
private Upgrade(String s, int max)
|
||||
private Upgrade(String s, int max, EnumColor c)
|
||||
{
|
||||
name = s;
|
||||
maxStack = max;
|
||||
color = c;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
@@ -30,4 +40,52 @@ public enum Upgrade
|
||||
{
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
public EnumColor getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean canMultiply()
|
||||
{
|
||||
return getMax() > 1;
|
||||
}
|
||||
|
||||
public static Map<Upgrade, Integer> buildMap(NBTTagCompound nbtTags)
|
||||
{
|
||||
Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();
|
||||
NBTTagList list = nbtTags.getTagList("upgrades", NBT.TAG_COMPOUND);
|
||||
|
||||
for(int tagCount = 0; tagCount < list.tagCount(); tagCount++)
|
||||
{
|
||||
NBTTagCompound compound = (NBTTagCompound)list.getCompoundTagAt(tagCount);
|
||||
|
||||
Upgrade upgrade = Upgrade.values()[compound.getInteger("type")];
|
||||
upgrades.put(upgrade, compound.getInteger("amount"));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user