diff --git a/api/buildcraft/api/blueprints/MappingRegistry.java b/api/buildcraft/api/blueprints/MappingRegistry.java index cd340c50..605c22f7 100755 --- a/api/buildcraft/api/blueprints/MappingRegistry.java +++ b/api/buildcraft/api/blueprints/MappingRegistry.java @@ -14,8 +14,10 @@ import java.util.HashMap; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagByte; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagShort; import net.minecraftforge.common.util.Constants; @@ -128,8 +130,8 @@ public class MappingRegistry { * referential. */ public void stackToRegistry(NBTTagCompound nbt) { - Item item = Item.getItemById(nbt.getInteger("id")); - nbt.setInteger("id", getIdForItem(item)); + Item item = Item.getItemById(nbt.getShort("id")); + nbt.setShort("id", (short) getIdForItem(item)); } /** @@ -137,27 +139,72 @@ public class MappingRegistry { * referential. */ public void stackToWorld(NBTTagCompound nbt) { - Item item = getItemForId(nbt.getInteger("id")); - nbt.setInteger("id", Item.getIdFromItem(item)); + Item item = getItemForId(nbt.getShort("id")); + nbt.setShort("id", (short) Item.getIdFromItem(item)); } - /** - * Relocates an inventory nbt from the world referential to the registry - * referential. - */ - public void inventoryToRegistry(NBTTagList nbt) { - for (int i = 0; i < nbt.tagCount(); ++i) { - stackToRegistry(nbt.getCompoundTagAt(i)); + private boolean isStackLayout(NBTTagCompound nbt) { + return nbt.hasKey("id") && + nbt.hasKey("Count") && + nbt.hasKey("Damage") && + nbt.getTag("id") instanceof NBTTagShort && + nbt.getTag("Count") instanceof NBTTagByte && + nbt.getTag("Damage") instanceof NBTTagShort; + } + + public void scanAndTranslateStacksToRegistry(NBTTagCompound nbt) { + // First, check if this nbt is itself a stack + + if (isStackLayout(nbt)) { + stackToRegistry(nbt); + } + + // Then, look at the nbt compound contained in this nbt (even if it's a + // stack) and checks for stacks in it. + for (Object keyO : nbt.func_150296_c()) { + String key = (String) keyO; + + if (nbt.getTag(key) instanceof NBTTagCompound) { + scanAndTranslateStacksToRegistry(nbt.getCompoundTag(key)); + } + + if (nbt.getTag(key) instanceof NBTTagList) { + NBTTagList list = (NBTTagList) nbt.getTag(key); + + if (list.func_150303_d() == Constants.NBT.TAG_COMPOUND) { + for (int i = 0; i < list.tagCount(); ++i) { + scanAndTranslateStacksToRegistry(list.getCompoundTagAt(i)); + } + } + } } } - /** - * Relocates an inventory nbt from the registry referential to the world - * referential. - */ - public void inventoryToWorld(NBTTagList nbt) { - for (int i = 0; i < nbt.tagCount(); ++i) { - stackToWorld(nbt.getCompoundTagAt(i)); + public void scanAndTranslateStacksToWorld(NBTTagCompound nbt) { + // First, check if this nbt is itself a stack + + if (isStackLayout(nbt)) { + stackToWorld(nbt); + } + + // Then, look at the nbt compound contained in this nbt (even if it's a + // stack) and checks for stacks in it. + for (Object keyO : nbt.func_150296_c()) { + String key = (String) keyO; + + if (nbt.getTag(key) instanceof NBTTagCompound) { + scanAndTranslateStacksToWorld(nbt.getCompoundTag(key)); + } + + if (nbt.getTag(key) instanceof NBTTagList) { + NBTTagList list = (NBTTagList) nbt.getTag(key); + + if (list.func_150303_d() == Constants.NBT.TAG_COMPOUND) { + for (int i = 0; i < list.tagCount(); ++i) { + scanAndTranslateStacksToWorld(list.getCompoundTagAt(i)); + } + } + } } } diff --git a/api/buildcraft/api/blueprints/Schematic.java b/api/buildcraft/api/blueprints/Schematic.java index bd770716..56724fe5 100755 --- a/api/buildcraft/api/blueprints/Schematic.java +++ b/api/buildcraft/api/blueprints/Schematic.java @@ -14,8 +14,6 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.Constants; - import buildcraft.api.core.IInvSlot; /** @@ -220,24 +218,6 @@ public abstract class Schematic { } - public void inventorySlotsToSchematic (MappingRegistry registry, NBTTagCompound nbt, String nbtName) { - if (!nbt.hasKey(nbtName)) { - return; - } else { - registry.inventoryToRegistry(nbt.getTagList(nbtName, - Constants.NBT.TAG_COMPOUND)); - } - } - - public void inventorySlotsToWorld (MappingRegistry registry, NBTTagCompound nbt, String nbtName) { - if (!nbt.hasKey(nbtName)) { - return; - } else { - registry.inventoryToWorld(nbt.getTagList(nbtName, - Constants.NBT.TAG_COMPOUND)); - } - } - public LinkedList getStacksToDisplay( LinkedList stackConsumed) { diff --git a/api/buildcraft/api/blueprints/SchematicEntity.java b/api/buildcraft/api/blueprints/SchematicEntity.java index 4f4a3da6..61949ac4 100755 --- a/api/buildcraft/api/blueprints/SchematicEntity.java +++ b/api/buildcraft/api/blueprints/SchematicEntity.java @@ -77,12 +77,12 @@ public class SchematicEntity extends Schematic { @Override public void idsToSchematic(MappingRegistry registry) { - inventorySlotsToSchematic(registry, cpt, "Items"); + registry.scanAndTranslateStacksToRegistry(cpt); } @Override public void idsToWorld(MappingRegistry registry) { - inventorySlotsToWorld(registry, cpt, "Items"); + registry.scanAndTranslateStacksToWorld(cpt); } @Override diff --git a/api/buildcraft/api/blueprints/SchematicTile.java b/api/buildcraft/api/blueprints/SchematicTile.java index 93aab883..0d83cb24 100755 --- a/api/buildcraft/api/blueprints/SchematicTile.java +++ b/api/buildcraft/api/blueprints/SchematicTile.java @@ -30,12 +30,12 @@ public class SchematicTile extends SchematicBlock { @Override public void idsToSchematic(MappingRegistry registry) { - inventorySlotsToSchematic(registry, cpt, "Items"); + registry.scanAndTranslateStacksToRegistry(cpt); } @Override public void idsToWorld(MappingRegistry registry) { - inventorySlotsToWorld(registry, cpt, "Items"); + registry.scanAndTranslateStacksToWorld(cpt); } /** diff --git a/common/buildcraft/BuildCraftTransport.java b/common/buildcraft/BuildCraftTransport.java index 24679a62..163fc8cc 100644 --- a/common/buildcraft/BuildCraftTransport.java +++ b/common/buildcraft/BuildCraftTransport.java @@ -106,7 +106,6 @@ import buildcraft.transport.pipes.PipeStructureCobblestone; import buildcraft.transport.schematics.BptItemPipeFilters; import buildcraft.transport.schematics.BptPipeIron; import buildcraft.transport.schematics.BptPipeWooden; -import buildcraft.transport.schematics.SchematicFilteredBuffer; import buildcraft.transport.schematics.SchematicPipe; import buildcraft.transport.triggers.ActionEnergyPulsar; import buildcraft.transport.triggers.ActionExtractionPreset; @@ -437,7 +436,6 @@ public class BuildCraftTransport extends BuildCraftMod { TransportProxy.proxy.registerTileEntities(); SchematicRegistry.registerSchematicBlock(genericPipeBlock, SchematicPipe.class); - SchematicRegistry.registerSchematicBlock(filteredBufferBlock, SchematicFilteredBuffer.class); new BptPipeIron(pipeItemsIron); new BptPipeIron(pipeFluidsIron); diff --git a/common/buildcraft/silicon/schematics/SchematicLaserTableBase.java b/common/buildcraft/silicon/schematics/SchematicLaserTableBase.java index 6ad7f2bb..95d9bd6b 100755 --- a/common/buildcraft/silicon/schematics/SchematicLaserTableBase.java +++ b/common/buildcraft/silicon/schematics/SchematicLaserTableBase.java @@ -9,7 +9,6 @@ package buildcraft.silicon.schematics; import buildcraft.api.blueprints.IBuilderContext; -import buildcraft.api.blueprints.MappingRegistry; import buildcraft.api.blueprints.SchematicTile; public class SchematicLaserTableBase extends SchematicTile { @@ -20,21 +19,4 @@ public class SchematicLaserTableBase extends SchematicTile { cpt.removeTag("energy"); } - - @Override - public void idsToSchematic(MappingRegistry registry) { - super.idsToSchematic(registry); - - inventorySlotsToSchematic(registry, cpt, "inv"); - inventorySlotsToSchematic(registry, cpt, "craftingSlots"); - } - - @Override - public void idsToWorld(MappingRegistry registry) { - super.idsToWorld(registry); - - inventorySlotsToWorld(registry, cpt, "inv"); - inventorySlotsToWorld(registry, cpt, "craftingSlots"); - } - } diff --git a/common/buildcraft/transport/schematics/SchematicFilteredBuffer.java b/common/buildcraft/transport/schematics/SchematicFilteredBuffer.java deleted file mode 100755 index f9521d3d..00000000 --- a/common/buildcraft/transport/schematics/SchematicFilteredBuffer.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com - * - * BuildCraft is distributed under the terms of the Minecraft Mod Public - * License 1.0, or MMPL. Please check the contents of the license located in - * http://www.mod-buildcraft.com/MMPL-1.0.txt - */ -package buildcraft.transport.schematics; - -import buildcraft.api.blueprints.MappingRegistry; -import buildcraft.api.blueprints.SchematicTile; - -public class SchematicFilteredBuffer extends SchematicTile { - - @Override - public void idsToSchematic(MappingRegistry registry) { - super.idsToSchematic(registry); - - inventorySlotsToSchematic(registry, cpt, "inventoryFilters"); - } - - @Override - public void idsToWorld(MappingRegistry registry) { - super.idsToWorld(registry); - - inventorySlotsToWorld(registry, cpt, "inventoryFilters"); - } - -} diff --git a/common/buildcraft/transport/schematics/SchematicPipe.java b/common/buildcraft/transport/schematics/SchematicPipe.java index 04efa033..e99a6868 100644 --- a/common/buildcraft/transport/schematics/SchematicPipe.java +++ b/common/buildcraft/transport/schematics/SchematicPipe.java @@ -52,7 +52,7 @@ public class SchematicPipe extends SchematicTile { props.rotateLeft(); props.writeToNBT(cpt); - Item pipeItem = context.getMappingRegistry().getItemForId(cpt.getInteger("pipeId")); + Item pipeItem = Item.getItemById(cpt.getInteger("pipeId")); if (BptPipeExtension.contains(pipeItem)) { BptPipeExtension.get(pipeItem).rotateLeft(this, context); @@ -129,7 +129,7 @@ public class SchematicPipe extends SchematicTile { @Override public void postProcessing(IBuilderContext context, int x, int y, int z) { - Item pipeItem = context.getMappingRegistry().getItemForId(cpt.getInteger("pipeId")); + Item pipeItem = Item.getItemById(cpt.getInteger("pipeId")); if (BptPipeExtension.contains(pipeItem)) { BptPipeExtension.get(pipeItem).postProcessing(this, context); @@ -149,20 +149,6 @@ public class SchematicPipe extends SchematicTile { Item item = Item.getItemById(cpt.getInteger("pipeId")); cpt.setInteger("pipeId", registry.getIdForItem(item)); - - if (cpt.hasKey("Gate")) { - NBTTagCompound gateNBT = cpt.getCompoundTag("Gate"); - - for (int i = 0; i < 8; ++i) { - if (gateNBT.hasKey("triggerParameters[" + i + "]")) { - NBTTagCompound parameterNBT = gateNBT.getCompoundTag("triggerParameters[" + i + "]"); - - if (parameterNBT.hasKey("stack")) { - registry.stackToRegistry(parameterNBT.getCompoundTag("stack")); - } - } - } - } } } @@ -174,21 +160,6 @@ public class SchematicPipe extends SchematicTile { Item item = registry.getItemForId(cpt.getInteger("pipeId")); cpt.setInteger("pipeId", Item.getIdFromItem(item)); - - if (cpt.hasKey("Gate")) { - NBTTagCompound gateNBT = cpt.getCompoundTag("Gate"); - - for (int i = 0; i < 8; ++i) { - if (gateNBT.hasKey("triggerParameters[" + i + "]")) { - NBTTagCompound parameterNBT = gateNBT.getCompoundTag("triggerParameters[" + i + "]"); - - if (parameterNBT.hasKey("stack")) { - registry.stackToWorld(parameterNBT.getCompoundTag("stack")); - } - } - } - } - } }