Exemplo n.º 1
0
  public static NBTTagCompound getTagFor(Upgrade upgrade, int amount) {
    NBTTagCompound compound = new NBTTagCompound();

    compound.setInteger("type", upgrade.ordinal());
    compound.setInteger("amount", amount);

    return compound;
  }
Exemplo n.º 2
0
  public static Map<Upgrade, Integer> buildMap(NBTTagCompound nbtTags) {
    Map<Upgrade, Integer> upgrades = new HashMap<Upgrade, Integer>();

    if (nbtTags != null) {
      if (nbtTags.hasKey("upgrades")) {
        NBTTagList list = nbtTags.getTagList("upgrades", NBT.TAG_COMPOUND);

        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"));
        }
      } else if (nbtTags.hasKey("energyMultiplier")
          && nbtTags.hasKey("speedMultiplier")) // TODO remove soon
      {
        upgrades.put(Upgrade.ENERGY, nbtTags.getInteger("energyMultiplier"));
        upgrades.put(Upgrade.SPEED, nbtTags.getInteger("speedMultiplier"));
      }
    }

    return upgrades;
  }