ensure that ids on blueprints are not correlated to worlds ids
This commit is contained in:
parent
4f8a4535b9
commit
39c9cd3391
3 changed files with 16 additions and 21 deletions
|
@ -25,14 +25,14 @@ public class MappingRegistry {
|
|||
private HashMap <Item, Integer> itemToId = new HashMap<Item, Integer>();
|
||||
private HashMap <Integer, Item> idToItem = new HashMap<Integer, Item>();
|
||||
|
||||
public void setIdForItem (Item item, int id) {
|
||||
private void setIdForItem (Item item, int id) {
|
||||
if (!itemToId.containsKey(item)) {
|
||||
itemToId.put(item, id);
|
||||
idToItem.put(id, item);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIdForBlock (Block block, int id) {
|
||||
private void setIdForBlock (Block block, int id) {
|
||||
if (!blockToId.containsKey(block)) {
|
||||
blockToId.put(block, id);
|
||||
idToBlock.put(id, block);
|
||||
|
@ -40,35 +40,35 @@ public class MappingRegistry {
|
|||
}
|
||||
|
||||
public Item getItemForId(int id) {
|
||||
if (idToItem.containsKey(id)) {
|
||||
return idToItem.get(id);
|
||||
if (!idToItem.containsKey(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
return idToItem.get(id);
|
||||
}
|
||||
|
||||
public int getIdForItem(Item item) {
|
||||
if (itemToId.containsKey(item)) {
|
||||
return itemToId.get(item);
|
||||
if (!itemToId.containsKey(item)) {
|
||||
setIdForItem(item, itemToId.size());
|
||||
}
|
||||
|
||||
return 0;
|
||||
return itemToId.get(item);
|
||||
}
|
||||
|
||||
public Block getBlockForId(int id) {
|
||||
if (idToBlock.containsKey(id)) {
|
||||
return idToBlock.get(id);
|
||||
if (!idToBlock.containsKey(id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
return idToBlock.get(id);
|
||||
}
|
||||
|
||||
public int getIdForBlock(Block block) {
|
||||
if (blockToId.containsKey(block)) {
|
||||
return blockToId.get(block);
|
||||
if (!blockToId.containsKey(block)) {
|
||||
setIdForBlock(block, blockToId.size());
|
||||
}
|
||||
|
||||
return 0;
|
||||
return blockToId.get(block);
|
||||
}
|
||||
|
||||
public void write (NBTTagCompound nbt) {
|
||||
|
|
|
@ -11,7 +11,6 @@ package buildcraft.core.blueprints;
|
|||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -94,8 +93,6 @@ public class BptSlot extends BptSlotInfo {
|
|||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) {
|
||||
registry.setIdForBlock(block, Block.blockRegistry.getIDForObject(block));
|
||||
|
||||
nbt.setInteger("blockId", registry.getIdForBlock(block));
|
||||
nbt.setInteger("blockMeta", meta);
|
||||
nbt.setTag("blockCpt", cpt);
|
||||
|
@ -103,11 +100,10 @@ public class BptSlot extends BptSlotInfo {
|
|||
NBTTagList rq = new NBTTagList();
|
||||
|
||||
for (ItemStack stack : storedRequirements) {
|
||||
registry.setIdForItem(stack.getItem(),
|
||||
Item.itemRegistry.getIDForObject(stack.getItem()));
|
||||
|
||||
NBTTagCompound sub = new NBTTagCompound();
|
||||
stack.writeToNBT(stack.writeToNBT(sub));
|
||||
sub.setInteger("id", Item.itemRegistry.getIDForObject(registry
|
||||
.getItemForId(sub.getInteger("id"))));
|
||||
rq.appendTag(sub);
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,6 @@ public class BptBlockPipe extends BptBlock {
|
|||
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
|
||||
|
||||
if (BlockGenericPipe.isValid(pipe)) {
|
||||
context.getMappingRegistry().setIdForItem(pipe.item, Item.getIdFromItem(pipe.item));
|
||||
slot.cpt.setInteger("pipeId", context.getMappingRegistry()
|
||||
.getIdForItem(pipe.item));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue