Implemented heuristic for wider default id translation. Close #1778.

This commit is contained in:
SpaceToad 2014-05-11 11:51:17 +02:00
parent 9b02f71b54
commit bc1a7486cd
8 changed files with 71 additions and 123 deletions

View file

@ -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));
}
}
}
}
}

View file

@ -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<ItemStack> getStacksToDisplay(
LinkedList<ItemStack> stackConsumed) {

View file

@ -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

View file

@ -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);
}
/**

View file

@ -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);

View file

@ -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");
}
}

View file

@ -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");
}
}

View file

@ -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"));
}
}
}
}
}
}