From 69825c8fc85cf392ffa143752117901205082d8b Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Sun, 6 Apr 2014 14:39:21 +0200 Subject: [PATCH] fixed item translations in inventories, fix #1565 --- .../buildcraft/api/blueprints/Schematic.java | 38 +++++++++++++++++++ .../api/blueprints/SchematicEntity.java | 4 ++ .../api/blueprints/SchematicTile.java | 10 +++++ common/buildcraft/builders/TileArchitect.java | 1 - .../builders/schematics/SchematicHanging.java | 11 ++++-- 5 files changed, 59 insertions(+), 5 deletions(-) diff --git a/common/buildcraft/api/blueprints/Schematic.java b/common/buildcraft/api/blueprints/Schematic.java index e5a792c4..2b014074 100755 --- a/common/buildcraft/api/blueprints/Schematic.java +++ b/common/buildcraft/api/blueprints/Schematic.java @@ -13,6 +13,8 @@ import java.util.LinkedList; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import buildcraft.core.utils.Utils; /** * This class allow to specify specific behavior for blocks stored in @@ -182,5 +184,41 @@ public class Schematic { } + public void inventorySlotsToBlueprint (MappingRegistry registry, NBTTagCompound nbt) { + inventorySlotsToBlueprint(registry, nbt, "Items"); + } + public void inventorySlotsToBlueprint (MappingRegistry registry, NBTTagCompound nbt, String nbtName) { + if (!nbt.hasKey(nbtName)) { + return; + } + + NBTTagList list = nbt.getTagList(nbtName, + Utils.NBTTag_Types.NBTTagCompound.ordinal()); + + for (int i = 0; i < list.tagCount(); ++i) { + NBTTagCompound invSlot = list.getCompoundTagAt(i); + Item item = Item.getItemById(invSlot.getInteger ("id")); + invSlot.setInteger("id", registry.getIdForItem(item)); + } + } + + public void inventorySlotsToWorld (MappingRegistry registry, NBTTagCompound nbt) { + inventorySlotsToWorld (registry, nbt, "Items"); + } + + public void inventorySlotsToWorld (MappingRegistry registry, NBTTagCompound nbt, String nbtName) { + if (!nbt.hasKey(nbtName)) { + return; + } + + NBTTagList list = nbt.getTagList(nbtName, + Utils.NBTTag_Types.NBTTagCompound.ordinal()); + + for (int i = 0; i < list.tagCount(); ++i) { + NBTTagCompound invSlot = list.getCompoundTagAt(i); + Item item = registry.getItemForId(invSlot.getInteger ("id")); + invSlot.setInteger("id", Item.getIdFromItem(item)); + } + } } diff --git a/common/buildcraft/api/blueprints/SchematicEntity.java b/common/buildcraft/api/blueprints/SchematicEntity.java index 7e0f4a1b..bed5cfb7 100755 --- a/common/buildcraft/api/blueprints/SchematicEntity.java +++ b/common/buildcraft/api/blueprints/SchematicEntity.java @@ -53,6 +53,8 @@ public class SchematicEntity extends Schematic { cpt.setTag("Pos", this.newDoubleNBTList(new double[] { pos.x, pos.y, pos.z })); + + inventorySlotsToBlueprint(registry, cpt); } @Override @@ -64,6 +66,8 @@ public class SchematicEntity extends Schematic { cpt.setTag("Pos", this.newDoubleNBTList(new double[] { pos.x, pos.y, pos.z })); + + inventorySlotsToWorld(registry, cpt); } @Override diff --git a/common/buildcraft/api/blueprints/SchematicTile.java b/common/buildcraft/api/blueprints/SchematicTile.java index 59eeced7..3a991376 100755 --- a/common/buildcraft/api/blueprints/SchematicTile.java +++ b/common/buildcraft/api/blueprints/SchematicTile.java @@ -27,6 +27,16 @@ public class SchematicTile extends SchematicBlock { */ public NBTTagCompound cpt = new NBTTagCompound(); + @Override + public void transformToBlueprint(MappingRegistry registry, Translation transform) { + inventorySlotsToBlueprint(registry, cpt); + } + + @Override + public void transformToWorld(MappingRegistry registry, Translation transform) { + inventorySlotsToWorld(registry, cpt); + } + /** * Places the block in the world, at the location specified in the slot. */ diff --git a/common/buildcraft/builders/TileArchitect.java b/common/buildcraft/builders/TileArchitect.java index 4288d7f4..b41653b5 100644 --- a/common/buildcraft/builders/TileArchitect.java +++ b/common/buildcraft/builders/TileArchitect.java @@ -75,7 +75,6 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro / (float) blockScanner.totalBlocks()) * 100); if (blockScanner.blocksLeft() == 0) { - System.out.println ("Z_A " + writingContext.box.sizeZ()); writingBlueprint.readEntitiesFromWorld (writingContext, this); Translation transform = new Translation(); diff --git a/common/buildcraft/builders/schematics/SchematicHanging.java b/common/buildcraft/builders/schematics/SchematicHanging.java index 1227e1ef..a2033c45 100755 --- a/common/buildcraft/builders/schematics/SchematicHanging.java +++ b/common/buildcraft/builders/schematics/SchematicHanging.java @@ -68,10 +68,13 @@ public class SchematicHanging extends SchematicEntity { @Override public void writeToWorld(IBuilderContext context) { if (baseItem == Items.item_frame) { - NBTTagCompound tag = cpt.getCompoundTag("Item"); - tag.setInteger("id", Item.itemRegistry.getIDForObject(context - .getMappingRegistry().getItemForId(tag.getInteger("id")))); - cpt.setTag("Item", tag); + if (cpt.hasKey("Item")) { + NBTTagCompound tag = cpt.getCompoundTag("Item"); + tag.setInteger("id", Item.itemRegistry.getIDForObject(context + .getMappingRegistry() + .getItemForId(tag.getInteger("id")))); + cpt.setTag("Item", tag); + } } super.writeToWorld(context);