Cache item values in RC converters.

This commit is contained in:
Florian Nücke 2015-10-02 23:25:26 +02:00
parent 17c416007a
commit ad4787beec
4 changed files with 30 additions and 21 deletions

View File

@ -41,7 +41,7 @@ object Mods {
val ElectricalAge = new SimpleMod(IDs.ElectricalAge, providesPower = true) val ElectricalAge = new SimpleMod(IDs.ElectricalAge, providesPower = true)
val EnderIO = new SimpleMod(IDs.EnderIO, version = "@[2.2,2.3)") val EnderIO = new SimpleMod(IDs.EnderIO, version = "@[2.2,2.3)")
val EnderStorage = new SimpleMod(IDs.EnderStorage) val EnderStorage = new SimpleMod(IDs.EnderStorage)
val ExtraCells = new SimpleMod(IDs.ExtraCells, version = "@[2.2.73,)") val ExtraCells = new SimpleMod(IDs.ExtraCells, version = "@[2.2.73,)")
val Factorization = new SimpleMod(IDs.Factorization, providesPower = true) val Factorization = new SimpleMod(IDs.Factorization, providesPower = true)
val Forestry = new SimpleMod(IDs.Forestry) val Forestry = new SimpleMod(IDs.Forestry)
val ForgeMultipart = new SimpleMod(IDs.ForgeMultipart) val ForgeMultipart = new SimpleMod(IDs.ForgeMultipart)

View File

@ -1,6 +1,5 @@
package li.cil.oc.integration.rotarycraft; package li.cil.oc.integration.rotarycraft;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import li.cil.oc.api.driver.Converter; import li.cil.oc.api.driver.Converter;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -11,20 +10,23 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class ConverterJetpackItem implements Converter { public class ConverterJetpackItem implements Converter {
final Item BedrockJetPack = GameRegistry.findItem("RotaryCraft", "rotarycraft_item_bedpack");
final Item SteelJetPack = GameRegistry.findItem("RotaryCraft", "rotarycraft_item_steelpack");
final Item JetPack = GameRegistry.findItem("RotaryCraft", "rotarycraft_item_jetpack");
@Override @Override
public void convert(final Object value, final Map<Object, Object> output) { public void convert(final Object value, final Map<Object, Object> output) {
if (value instanceof ItemStack) { if (value instanceof ItemStack) {
final ItemStack stack = (ItemStack) value; final ItemStack stack = (ItemStack) value;
final Item item = stack.getItem(); final Item item = stack.getItem();
if (item.equals(GameRegistry.findItem("RotaryCraft", "rotarycraft_item_bedpack")) || if (item != null && item == BedrockJetPack || item == SteelJetPack || item == JetPack) {
item.equals(GameRegistry.findItem("RotaryCraft", "rotarycraft_item_steelpack")) ||
item.equals(GameRegistry.findItem("RotaryCraft", "rotarycraft_item_jetpack"))) {
final NBTTagCompound tag = stack.getTagCompound(); final NBTTagCompound tag = stack.getTagCompound();
if (tag != null && tag.hasKey("fuel")) if (tag != null && tag.hasKey("fuel")) {
output.put("fuel", stack.stackTagCompound.getInteger("fuel")); output.put("fuel", stack.stackTagCompound.getInteger("fuel"));
else } else {
output.put("fuel", 0); output.put("fuel", 0);
}
if (tag != null && tag.hasKey("liquid")) { if (tag != null && tag.hasKey("liquid")) {
output.put("fuelType", tag.getString("liquid")); output.put("fuelType", tag.getString("liquid"));
@ -32,17 +34,18 @@ public class ConverterJetpackItem implements Converter {
output.put("fuelType", "empty"); output.put("fuelType", "empty");
} }
if (item.equals(GameRegistry.findItem("RotaryCraft", "rotarycraft_item_bedpack"))) if (item == BedrockJetPack) {
output.put("chestplateMaterial", "bedrock"); output.put("chestplateMaterial", "bedrock");
else if (item.equals(GameRegistry.findItem("RotaryCraft", "rotarycraft_item_steelpack"))) } else if (item == SteelJetPack) {
output.put("chestplateMaterial", "steel"); output.put("chestplateMaterial", "steel");
else } else {
output.put("chestplateMaterial", "none"); output.put("chestplateMaterial", "none");
}
final HashMap<String, Boolean> upgrades = new HashMap<String, Boolean>(); final HashMap<String, Boolean> upgrades = new HashMap<String, Boolean>();
upgrades.put("cooling", tag != null ? tag.getBoolean("cooling") : false); upgrades.put("cooling", tag != null && tag.getBoolean("cooling"));
upgrades.put("thrustBoost", tag != null ? tag.getBoolean("jet") : false); upgrades.put("thrustBoost", tag != null && tag.getBoolean("jet"));
upgrades.put("winged", tag != null ? tag.getBoolean("wing") : false); upgrades.put("winged", tag != null && tag.getBoolean("wing"));
output.put("upgrades", upgrades); output.put("upgrades", upgrades);
} }
} }

View File

@ -9,22 +9,27 @@ import net.minecraft.nbt.NBTTagCompound;
import java.util.Map; import java.util.Map;
public class ConverterPumpItem implements Converter { public class ConverterPumpItem implements Converter {
final Item Pump = GameRegistry.findItem("RotaryCraft", "rotarycraft_item_pump");
@Override @Override
public void convert(final Object value, final Map<Object, Object> output) { public void convert(final Object value, final Map<Object, Object> output) {
if (value instanceof ItemStack) { if (value instanceof ItemStack) {
final ItemStack stack = (ItemStack) value; final ItemStack stack = (ItemStack) value;
final Item item = stack.getItem(); final Item item = stack.getItem();
if (stack.getItem().equals(GameRegistry.findItem("RotaryCraft", "rotarycraft_item_pump"))) { if (item != null && item == Pump) {
final NBTTagCompound tag = stack.getTagCompound(); final NBTTagCompound tag = stack.getTagCompound();
if (tag != null && tag.hasKey("liquid"))
output.put("liquid", stack.stackTagCompound.getString("liquid"));
else
output.put("liquid", "empty");
if (tag != null && tag.hasKey("lvl")) if (tag != null && tag.hasKey("liquid")) {
output.put("liquid", stack.stackTagCompound.getString("liquid"));
} else {
output.put("liquid", "empty");
}
if (tag != null && tag.hasKey("lvl")) {
output.put("fluidAmount", stack.stackTagCompound.getInteger("lvl")); output.put("fluidAmount", stack.stackTagCompound.getInteger("lvl"));
else } else {
output.put("fluidAmount", 0); output.put("fluidAmount", 0);
}
} }
} }
} }

View File

@ -1,7 +1,8 @@
package li.cil.oc.integration.rotarycraft package li.cil.oc.integration.rotarycraft
import li.cil.oc.api.Driver import li.cil.oc.api.Driver
import li.cil.oc.integration.{ModProxy, Mods} import li.cil.oc.integration.ModProxy
import li.cil.oc.integration.Mods
object ModRotaryCraft extends ModProxy { object ModRotaryCraft extends ModProxy {
override def getMod = Mods.RotaryCraft override def getMod = Mods.RotaryCraft