mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-24 04:50:30 -04:00
Merge pull request #106 from GTNewHorizons/fixFluidPatterns
Fix modifying fluid patterns with OC
This commit is contained in:
commit
91c32e503f
@ -1,10 +1,14 @@
|
||||
package li.cil.oc.integration.appeng;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.util.Platform;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import li.cil.oc.api.driver.Converter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
public final class ConverterPattern implements Converter {
|
||||
@Override
|
||||
@ -12,27 +16,46 @@ public final class ConverterPattern implements Converter {
|
||||
if (value instanceof ItemStack) {
|
||||
ItemStack is = (ItemStack) value;
|
||||
try {
|
||||
PatternHelper p = new PatternHelper(is, null);
|
||||
Map[] inputs = new Map[p.getInputs().length];
|
||||
for (int i = 0; i < p.getInputs().length; ++i) {
|
||||
inputs[i] = new HashMap<>();
|
||||
if (p.getInputs()[i] == null) continue;
|
||||
ItemStack input = p.getInputs()[i].getItemStack();
|
||||
inputs[i].put("name", input.getItem().getItemStackDisplayName(input));
|
||||
inputs[i].put("count", input.stackSize);
|
||||
final NBTTagCompound encodedValue = is.getTagCompound();
|
||||
if (encodedValue != null) {
|
||||
final NBTTagList inTag = encodedValue.getTagList("in", 10);
|
||||
final NBTTagList outTag = encodedValue.getTagList("out", 10);
|
||||
|
||||
Map[] inputs = new Map[inTag.tagCount()];
|
||||
for (int i = 0; i < inTag.tagCount(); i++) {
|
||||
inputs[i] = new HashMap<>();
|
||||
final NBTTagCompound tag = inTag.getCompoundTagAt(i);
|
||||
final ItemStack inputItem = Platform.loadItemStackFromNBT(tag);
|
||||
if (inputItem != null) {
|
||||
inputs[i].put("name", inputItem.getItem().getItemStackDisplayName(inputItem));
|
||||
if (tag.getLong("Cnt") > 0) {
|
||||
inputs[i].put("count", tag.getLong("Cnt"));
|
||||
} else {
|
||||
inputs[i].put("count", inputItem.stackSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map[] results = new Map[outTag.tagCount()];
|
||||
for (int i = 0; i < outTag.tagCount(); i++) {
|
||||
results[i] = new HashMap<>();
|
||||
final NBTTagCompound tag = outTag.getCompoundTagAt(i);
|
||||
final ItemStack outputItem = Platform.loadItemStackFromNBT(tag);
|
||||
if (outputItem != null) {
|
||||
results[i].put("name", outputItem.getItem().getItemStackDisplayName(outputItem));
|
||||
if (tag.getLong("Cnt") > 0) {
|
||||
results[i].put("count", tag.getLong("Cnt"));
|
||||
} else {
|
||||
results[i].put("count", outputItem.stackSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
output.put("inputs", inputs);
|
||||
output.put("outputs", results);
|
||||
output.put("isCraftable", encodedValue.getBoolean("crafting"));
|
||||
}
|
||||
output.put("inputs", inputs);
|
||||
Map[] results = new Map[p.getOutputs().length];
|
||||
for (int i = 0; i < p.getOutputs().length; ++i) {
|
||||
results[i] = new HashMap<>();
|
||||
if (p.getOutputs()[i] == null) continue;
|
||||
ItemStack result = p.getOutputs()[i].getItemStack();
|
||||
results[i].put("name", result.getItem().getItemStackDisplayName(result));
|
||||
results[i].put("count", result.stackSize);
|
||||
}
|
||||
output.put("outputs", results);
|
||||
output.put("isCraftable", p.isCraftable());
|
||||
} catch (final Throwable ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,6 +162,7 @@ object DriverBlockInterface extends DriverSidedTileEntity {
|
||||
val nbt = new NBTTagCompound()
|
||||
stack.writeToNBT(nbt)
|
||||
nbt.setInteger("Count", stack.stackSize)
|
||||
nbt.setLong("Cnt", stack.stackSize)
|
||||
inTag.func_150304_a(index, nbt)
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user