add ItemStack to/from NBT helpers (#202)
to simplify the "stackSize" NBT tag workaround
This commit is contained in:
+2
-5
@@ -61,6 +61,7 @@ import java.util.List;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
|
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
|
||||||
|
|
||||||
public class GuiInterfaceConfigurationTerminal extends AEBaseGui implements IJEIGhostIngredients {
|
public class GuiInterfaceConfigurationTerminal extends AEBaseGui implements IJEIGhostIngredients {
|
||||||
@@ -299,11 +300,7 @@ public class GuiInterfaceConfigurationTerminal extends AEBaseGui implements IJEI
|
|||||||
for (int x = 0; x < current.getInventory().getSlots(); x++) {
|
for (int x = 0; x < current.getInventory().getSlots(); x++) {
|
||||||
final String which = Integer.toString(x);
|
final String which = Integer.toString(x);
|
||||||
if (invData.hasKey(which)) {
|
if (invData.hasKey(which)) {
|
||||||
NBTTagCompound tag = invData.getCompoundTag(which);
|
current.getInventory().setStackInSlot(x, stackFromNBT(invData.getCompoundTag(which)));
|
||||||
current.getInventory().setStackInSlot(x, new ItemStack(tag));
|
|
||||||
if (tag.hasKey("stackSize")) {
|
|
||||||
current.getInventory().getStackInSlot(x).setCount(tag.getInteger("stackSize"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final NumberFormatException ignored) {
|
} catch (final NumberFormatException ignored) {
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ import java.io.IOException;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
|
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
|
||||||
|
|
||||||
public class GuiInterfaceTerminal extends AEBaseGui {
|
public class GuiInterfaceTerminal extends AEBaseGui {
|
||||||
@@ -321,7 +322,7 @@ public class GuiInterfaceTerminal extends AEBaseGui {
|
|||||||
for (int x = 0; x < current.getInventory().getSlots(); x++) {
|
for (int x = 0; x < current.getInventory().getSlots(); x++) {
|
||||||
final String which = Integer.toString(x);
|
final String which = Integer.toString(x);
|
||||||
if (invData.hasKey(which)) {
|
if (invData.hasKey(which)) {
|
||||||
current.getInventory().setStackInSlot(x, new ItemStack(invData.getCompoundTag(which)));
|
current.getInventory().setStackInSlot(x, stackFromNBT(invData.getCompoundTag(which)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final NumberFormatException ignored) {
|
} catch (final NumberFormatException ignored) {
|
||||||
|
|||||||
+3
-4
@@ -50,6 +50,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
|
||||||
|
|
||||||
|
|
||||||
public final class ContainerInterfaceConfigurationTerminal extends AEBaseContainer {
|
public final class ContainerInterfaceConfigurationTerminal extends AEBaseContainer {
|
||||||
|
|
||||||
@@ -310,10 +312,7 @@ public final class ContainerInterfaceConfigurationTerminal extends AEBaseContain
|
|||||||
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
|
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
|
||||||
|
|
||||||
if (!is.isEmpty()) {
|
if (!is.isEmpty()) {
|
||||||
is.writeToNBT(itemNBT);
|
stackWriteToNBT(is, itemNBT);
|
||||||
if (is.getCount() > Byte.MAX_VALUE) {
|
|
||||||
itemNBT.setInteger("stackSize", is.getCount());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setTag(Integer.toString(x + offset), itemNBT);
|
tag.setTag(Integer.toString(x + offset), itemNBT);
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
|
||||||
|
|
||||||
|
|
||||||
public final class ContainerInterfaceTerminal extends AEBaseContainer {
|
public final class ContainerInterfaceTerminal extends AEBaseContainer {
|
||||||
|
|
||||||
@@ -345,7 +347,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer {
|
|||||||
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
|
ItemHandlerUtil.setStackInSlot(inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy());
|
||||||
|
|
||||||
if (!is.isEmpty()) {
|
if (!is.isEmpty()) {
|
||||||
is.writeToNBT(itemNBT);
|
stackWriteToNBT(is, itemNBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
tag.setTag(Integer.toString(x + offset), itemNBT);
|
tag.setTag(Integer.toString(x + offset), itemNBT);
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
|
||||||
|
|
||||||
public abstract class ContainerPatternEncoder extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
|
public abstract class ContainerPatternEncoder extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket {
|
||||||
|
|
||||||
private final AbstractPartEncoder patternTerminal;
|
private final AbstractPartEncoder patternTerminal;
|
||||||
@@ -526,10 +528,7 @@ public abstract class ContainerPatternEncoder extends ContainerMEMonitorable imp
|
|||||||
final NBTTagCompound c = new NBTTagCompound();
|
final NBTTagCompound c = new NBTTagCompound();
|
||||||
|
|
||||||
if (!i.isEmpty()) {
|
if (!i.isEmpty()) {
|
||||||
i.writeToNBT(c);
|
stackWriteToNBT(i, c);
|
||||||
if (i.getCount() > Byte.MAX_VALUE) {
|
|
||||||
c.setInteger("stackSize", i.getCount());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
|
||||||
|
|
||||||
public class PacketJEIRecipe extends AppEngPacket {
|
public class PacketJEIRecipe extends AppEngPacket {
|
||||||
|
|
||||||
@@ -85,7 +87,7 @@ public class PacketJEIRecipe extends AppEngPacket {
|
|||||||
if (list.tagCount() > 0) {
|
if (list.tagCount() > 0) {
|
||||||
this.recipe.add(new ItemStack[list.tagCount()]);
|
this.recipe.add(new ItemStack[list.tagCount()]);
|
||||||
for (int y = 0; y < list.tagCount(); y++) {
|
for (int y = 0; y < list.tagCount(); y++) {
|
||||||
this.recipe.get(x)[y] = new ItemStack(list.getCompoundTagAt(y));
|
this.recipe.get(x)[y] = stackFromNBT(list.getCompoundTagAt(y));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.recipe.add(emptyArray);
|
this.recipe.add(emptyArray);
|
||||||
@@ -97,7 +99,7 @@ public class PacketJEIRecipe extends AppEngPacket {
|
|||||||
final NBTTagList outputList = comp.getTagList("outputs", 10);
|
final NBTTagList outputList = comp.getTagList("outputs", 10);
|
||||||
this.output = new ArrayList<>();
|
this.output = new ArrayList<>();
|
||||||
for (int z = 0; z < outputList.tagCount(); z++) {
|
for (int z = 0; z < outputList.tagCount(); z++) {
|
||||||
this.output.add(new ItemStack(outputList.getCompoundTagAt(z)));
|
this.output.add(stackFromNBT(outputList.getCompoundTagAt(z)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,8 @@ import net.minecraftforge.items.wrapper.RangedWrapper;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.*;
|
||||||
|
|
||||||
|
|
||||||
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost {
|
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost {
|
||||||
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
|
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
|
||||||
@@ -208,12 +210,8 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
final NBTTagList waitingToSend = new NBTTagList();
|
final NBTTagList waitingToSend = new NBTTagList();
|
||||||
if (this.waitingToSend != null) {
|
if (this.waitingToSend != null) {
|
||||||
for (final ItemStack is : this.waitingToSend) {
|
for (final ItemStack is : this.waitingToSend) {
|
||||||
final NBTTagCompound item = new NBTTagCompound();
|
final NBTTagCompound itemNBT = stackToNBT(is);
|
||||||
is.writeToNBT(item);
|
waitingToSend.appendTag(itemNBT);
|
||||||
if (is.getCount() > Byte.MAX_VALUE) {
|
|
||||||
item.setInteger("stackSize", is.getCount());
|
|
||||||
}
|
|
||||||
waitingToSend.appendTag(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.setTag("waitingToSend", waitingToSend);
|
data.setTag("waitingToSend", waitingToSend);
|
||||||
@@ -225,12 +223,8 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
NBTTagList waitingListSided = new NBTTagList();
|
NBTTagList waitingListSided = new NBTTagList();
|
||||||
if (this.waitingToSendFacing.containsKey(s)) {
|
if (this.waitingToSendFacing.containsKey(s)) {
|
||||||
for (final ItemStack is : this.waitingToSendFacing.get(s)) {
|
for (final ItemStack is : this.waitingToSendFacing.get(s)) {
|
||||||
final NBTTagCompound item = new NBTTagCompound();
|
final NBTTagCompound itemNBT = stackToNBT(is);
|
||||||
is.writeToNBT(item);
|
waitingListSided.appendTag(itemNBT);
|
||||||
if (is.getCount() > Byte.MAX_VALUE) {
|
|
||||||
item.setInteger("stackSize", is.getCount());
|
|
||||||
}
|
|
||||||
waitingListSided.appendTag(item);
|
|
||||||
}
|
}
|
||||||
sidedWaitList.setTag(s.name(), waitingListSided);
|
sidedWaitList.setTag(s.name(), waitingListSided);
|
||||||
}
|
}
|
||||||
@@ -246,10 +240,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
for (int x = 0; x < waitingList.tagCount(); x++) {
|
for (int x = 0; x < waitingList.tagCount(); x++) {
|
||||||
final NBTTagCompound c = waitingList.getCompoundTagAt(x);
|
final NBTTagCompound c = waitingList.getCompoundTagAt(x);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
final ItemStack is = new ItemStack(c);
|
final ItemStack is = stackFromNBT(c);
|
||||||
if (c.hasKey("stackSize")) {
|
|
||||||
is.setCount(c.getInteger("stackSize"));
|
|
||||||
}
|
|
||||||
this.addToSendList(is);
|
this.addToSendList(is);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,10 +255,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
for (int x = 0; x < w.tagCount(); x++) {
|
for (int x = 0; x < w.tagCount(); x++) {
|
||||||
final NBTTagCompound c = w.getCompoundTagAt(x);
|
final NBTTagCompound c = w.getCompoundTagAt(x);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
final ItemStack is = new ItemStack(c);
|
final ItemStack is = stackFromNBT(c);
|
||||||
if (c.hasKey("stackSize")) {
|
|
||||||
is.setCount(c.getInteger("stackSize"));
|
|
||||||
}
|
|
||||||
this.addToSendListFacing(is, EnumFacing.getFront(s.getIndex()));
|
this.addToSendListFacing(is, EnumFacing.getFront(s.getIndex()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ import net.minecraft.util.text.TextFormatting;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
|
||||||
|
|
||||||
public class InvalidPatternHelper {
|
public class InvalidPatternHelper {
|
||||||
|
|
||||||
@@ -89,11 +91,14 @@ public class InvalidPatternHelper {
|
|||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
|
|
||||||
public PatternIngredient(NBTTagCompound tag) {
|
public PatternIngredient(NBTTagCompound tag) {
|
||||||
this.stack = new ItemStack(tag);
|
this.stack = stackFromNBT(tag);
|
||||||
|
|
||||||
if (this.stack.isEmpty()) {
|
if (this.stack.isEmpty()) {
|
||||||
this.id = tag.getString("id");
|
this.id = tag.getString("id");
|
||||||
this.count = tag.getByte("Count");
|
this.count = tag.getByte("Count");
|
||||||
|
if (tag.hasKey("stackSize")) {
|
||||||
|
this.count = tag.getInteger("stackSize");
|
||||||
|
}
|
||||||
this.damage = Math.max(0, tag.getShort("Damage"));
|
this.damage = Math.max(0, tag.getShort("Damage"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package appeng.helpers;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methods to help with the added "stackSize" NBT tag to get around "Count" being written and read as a byte.
|
||||||
|
*/
|
||||||
|
public class ItemStackHelper {
|
||||||
|
public static ItemStack stackFromNBT(NBTTagCompound itemNBT) {
|
||||||
|
ItemStack is = new ItemStack(itemNBT);
|
||||||
|
if (itemNBT.hasKey("stackSize")) {
|
||||||
|
is.setCount(itemNBT.getInteger("stackSize"));
|
||||||
|
}
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stackWriteToNBT(ItemStack is, NBTTagCompound itemNBT) {
|
||||||
|
is.writeToNBT(itemNBT);
|
||||||
|
if (is.getCount() > Byte.MAX_VALUE) {
|
||||||
|
itemNBT.setInteger("stackSize", is.getCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static NBTTagCompound stackToNBT(ItemStack is) {
|
||||||
|
NBTTagCompound itemNBT = new NBTTagCompound();
|
||||||
|
stackWriteToNBT(is, itemNBT);
|
||||||
|
return itemNBT;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -40,6 +40,8 @@ import net.minecraftforge.common.crafting.IShapedRecipe;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
|
||||||
|
|
||||||
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper> {
|
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper> {
|
||||||
|
|
||||||
@@ -91,11 +93,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||||||
|
|
||||||
for (int x = 0; x < inTag.tagCount(); x++) {
|
for (int x = 0; x < inTag.tagCount(); x++) {
|
||||||
NBTTagCompound ingredient = inTag.getCompoundTagAt(x);
|
NBTTagCompound ingredient = inTag.getCompoundTagAt(x);
|
||||||
final ItemStack gs = new ItemStack(ingredient);
|
final ItemStack gs = stackFromNBT(ingredient);
|
||||||
|
|
||||||
if (ingredient.hasKey("stackSize")) {
|
|
||||||
gs.setCount(ingredient.getInteger("stackSize"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ingredient.hasNoTags() && gs.isEmpty()) {
|
if (!ingredient.hasNoTags() && gs.isEmpty()) {
|
||||||
throw new IllegalArgumentException("No pattern here!");
|
throw new IllegalArgumentException("No pattern here!");
|
||||||
@@ -126,11 +124,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
|||||||
|
|
||||||
for (int x = 0; x < outTag.tagCount(); x++) {
|
for (int x = 0; x < outTag.tagCount(); x++) {
|
||||||
NBTTagCompound resultItemTag = outTag.getCompoundTagAt(x);
|
NBTTagCompound resultItemTag = outTag.getCompoundTagAt(x);
|
||||||
final ItemStack gs = new ItemStack(resultItemTag);
|
final ItemStack gs = stackFromNBT(resultItemTag);
|
||||||
|
|
||||||
if (resultItemTag.hasKey("stackSize")) {
|
|
||||||
gs.setCount(resultItemTag.getInteger("stackSize"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!resultItemTag.hasNoTags() && gs.isEmpty()) {
|
if (!resultItemTag.hasNoTags() && gs.isEmpty()) {
|
||||||
throw new IllegalArgumentException("No pattern here!");
|
throw new IllegalArgumentException("No pattern here!");
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackToNBT;
|
||||||
|
|
||||||
|
|
||||||
class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandler<T> {
|
class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandler<T> {
|
||||||
|
|
||||||
@@ -108,8 +110,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
if (!ingredient.isInput()) {
|
if (!ingredient.isInput()) {
|
||||||
ItemStack output = ingredient.getDisplayedIngredient();
|
ItemStack output = ingredient.getDisplayedIngredient();
|
||||||
if (output != null) {
|
if (output != null) {
|
||||||
final NBTTagCompound tag = new NBTTagCompound();
|
final NBTTagCompound tag = stackToNBT(output);
|
||||||
output.writeToNBT(tag);
|
|
||||||
outputs.appendTag(tag);
|
outputs.appendTag(tag);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@@ -140,8 +141,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (final ItemStack is : list) {
|
for (final ItemStack is : list) {
|
||||||
final NBTTagCompound tag = new NBTTagCompound();
|
final NBTTagCompound tag = stackToNBT(is);
|
||||||
is.writeToNBT(tag);
|
|
||||||
tags.appendTag(tag);
|
tags.appendTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ import javax.annotation.Nonnull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
|
||||||
|
|
||||||
|
|
||||||
public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInventory {
|
public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInventory {
|
||||||
|
|
||||||
@@ -50,7 +53,7 @@ public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInven
|
|||||||
final NBTTagCompound opt = data.getCompoundTag("inv");
|
final NBTTagCompound opt = data.getCompoundTag("inv");
|
||||||
for (int x = 0; x < inv.getSlots(); x++) {
|
for (int x = 0; x < inv.getSlots(); x++) {
|
||||||
final NBTTagCompound item = opt.getCompoundTag("item" + x);
|
final NBTTagCompound item = opt.getCompoundTag("item" + x);
|
||||||
ItemHandlerUtil.setStackInSlot(inv, x, new ItemStack(item));
|
ItemHandlerUtil.setStackInSlot(inv, x, stackFromNBT(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -65,12 +68,12 @@ public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInven
|
|||||||
if (inv != EmptyHandler.INSTANCE) {
|
if (inv != EmptyHandler.INSTANCE) {
|
||||||
final NBTTagCompound opt = new NBTTagCompound();
|
final NBTTagCompound opt = new NBTTagCompound();
|
||||||
for (int x = 0; x < inv.getSlots(); x++) {
|
for (int x = 0; x < inv.getSlots(); x++) {
|
||||||
final NBTTagCompound item = new NBTTagCompound();
|
final NBTTagCompound itemNBT = new NBTTagCompound();
|
||||||
final ItemStack is = inv.getStackInSlot(x);
|
final ItemStack is = inv.getStackInSlot(x);
|
||||||
if (!is.isEmpty()) {
|
if (!is.isEmpty()) {
|
||||||
is.writeToNBT(item);
|
stackWriteToNBT(is, itemNBT);
|
||||||
}
|
}
|
||||||
opt.setTag("item" + x, item);
|
opt.setTag("item" + x, itemNBT);
|
||||||
}
|
}
|
||||||
data.setTag("inv", opt);
|
data.setTag("inv", opt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ import java.util.EnumMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackWriteToNBT;
|
||||||
|
|
||||||
|
|
||||||
public class TileMolecularAssembler extends AENetworkInvTile implements IUpgradeableHost, IConfigManagerHost, IGridTickable, ICraftingMachine, IPowerChannelState {
|
public class TileMolecularAssembler extends AENetworkInvTile implements IUpgradeableHost, IConfigManagerHost, IGridTickable, ICraftingMachine, IPowerChannelState {
|
||||||
private final InventoryCrafting craftingInv;
|
private final InventoryCrafting craftingInv;
|
||||||
@@ -288,7 +291,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
|||||||
final ItemStack pattern = this.myPlan.getPattern();
|
final ItemStack pattern = this.myPlan.getPattern();
|
||||||
if (!pattern.isEmpty()) {
|
if (!pattern.isEmpty()) {
|
||||||
final NBTTagCompound compound = new NBTTagCompound();
|
final NBTTagCompound compound = new NBTTagCompound();
|
||||||
pattern.writeToNBT(compound);
|
stackWriteToNBT(pattern, compound);
|
||||||
data.setTag("myPlan", compound);
|
data.setTag("myPlan", compound);
|
||||||
data.setInteger("pushDirection", this.pushDirection.ordinal());
|
data.setInteger("pushDirection", this.pushDirection.ordinal());
|
||||||
}
|
}
|
||||||
@@ -303,7 +306,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
|||||||
public void readFromNBT(final NBTTagCompound data) {
|
public void readFromNBT(final NBTTagCompound data) {
|
||||||
super.readFromNBT(data);
|
super.readFromNBT(data);
|
||||||
if (data.hasKey("myPlan")) {
|
if (data.hasKey("myPlan")) {
|
||||||
final ItemStack myPat = new ItemStack(data.getCompoundTag("myPlan"));
|
final ItemStack myPat = stackFromNBT(data.getCompoundTag("myPlan"));
|
||||||
|
|
||||||
if (!myPat.isEmpty() && myPat.getItem() instanceof ItemEncodedPattern) {
|
if (!myPat.isEmpty() && myPat.getItem() instanceof ItemEncodedPattern) {
|
||||||
final World w = this.getWorld();
|
final World w = this.getWorld();
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackToNBT;
|
||||||
|
|
||||||
|
|
||||||
public class AppEngInternalInventory extends ItemStackHandler implements Iterable<ItemStack> {
|
public class AppEngInternalInventory extends ItemStackHandler implements Iterable<ItemStack> {
|
||||||
protected boolean enableClientEvents = false;
|
protected boolean enableClientEvents = false;
|
||||||
@@ -162,12 +165,8 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
|||||||
for (int i = 0; i < stacks.size(); i++) {
|
for (int i = 0; i < stacks.size(); i++) {
|
||||||
ItemStack is = stacks.get(i);
|
ItemStack is = stacks.get(i);
|
||||||
if (!is.isEmpty()) {
|
if (!is.isEmpty()) {
|
||||||
NBTTagCompound itemTag = new NBTTagCompound();
|
NBTTagCompound itemTag = stackToNBT(is);
|
||||||
itemTag.setInteger("Slot", i);
|
itemTag.setInteger("Slot", i);
|
||||||
if (is.getCount() > Byte.MAX_VALUE) {
|
|
||||||
itemTag.setInteger("stackSize", stacks.get(i).getCount());
|
|
||||||
}
|
|
||||||
stacks.get(i).writeToNBT(itemTag);
|
|
||||||
nbtTagList.appendTag(itemTag);
|
nbtTagList.appendTag(itemTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -196,11 +195,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
|||||||
NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
|
NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
|
||||||
int slot = itemTags.getInteger("Slot");
|
int slot = itemTags.getInteger("Slot");
|
||||||
if (slot >= 0 && slot < stacks.size()) {
|
if (slot >= 0 && slot < stacks.size()) {
|
||||||
stacks.set(slot, new ItemStack(itemTags));
|
stacks.set(slot, stackFromNBT(itemTags));
|
||||||
if (itemTags.hasKey("stackSize")) {
|
|
||||||
int stackSize = itemTags.getInteger("stackSize");
|
|
||||||
stacks.get(slot).setCount(stackSize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onLoad();
|
onLoad();
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ import java.util.EnumSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static appeng.helpers.ItemStackHelper.stackFromNBT;
|
||||||
|
|
||||||
|
|
||||||
public class TileSecurityStation extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider, IColorableTile {
|
public class TileSecurityStation extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider, IColorableTile {
|
||||||
|
|
||||||
@@ -175,7 +177,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost,
|
|||||||
for (final Object key : storedItems.getKeySet()) {
|
for (final Object key : storedItems.getKeySet()) {
|
||||||
final NBTBase obj = storedItems.getTag((String) key);
|
final NBTBase obj = storedItems.getTag((String) key);
|
||||||
if (obj instanceof NBTTagCompound) {
|
if (obj instanceof NBTTagCompound) {
|
||||||
this.inventory.getStoredItems().add(AEItemStack.fromItemStack(new ItemStack((NBTTagCompound) obj)));
|
this.inventory.getStoredItems().add(AEItemStack.fromItemStack(stackFromNBT((NBTTagCompound) obj)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user