importing TE

This commit is contained in:
StevenRS11 2013-06-12 00:42:24 -04:00
parent eee6f11154
commit 2c09434e4c
2 changed files with 72 additions and 14 deletions

View file

@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityDispenser;
import net.minecraft.util.WeightedRandomChestContent;
@ -40,9 +41,11 @@ public class SchematicLoader
public byte[] addId = new byte[0];
public NBTTagCompound[] tileEntityList;
public NBTTagList entities;
public NBTTagList tileentities;
public NBTTagList tileEntities;
private Random rand = new Random();
@ -103,6 +106,15 @@ public class SchematicLoader
addId = nbtdata.getByteArray("AddBlocks");
tileEntities = nbtdata.getTagList("TileEntities");
tileEntityList = new NBTTagCompound[width*height*length];
for(int count = 0; count<tileEntities.tagCount(); count++)
{
NBTTagCompound tag = (NBTTagCompound)tileEntities.tagAt(count);
tileEntityList[tag.getInteger("y")*width*length+tag.getInteger("z")*width+tag.getInteger("x")]=tag;
}
// entities = nbtdata.getTagList("Entities");
//tileentities = nbtdata.getTagList("TileEntities");
@ -263,6 +275,8 @@ public class SchematicLoader
else if(Block.blocksList[blockID] instanceof BlockRedstoneRepeater ||Block.blocksList[blockID] instanceof BlockDoor ||blockID== Block.tripWireSource.blockID||Block.blocksList[blockID] instanceof BlockComparator)
{
switch (metadata)
{
case 0:
@ -756,8 +770,7 @@ public class SchematicLoader
int blockToReplace=loader.blocks[index];
int blockMetaData=loader.blockData[index];
NBTTagList tileEntity = loader.tileentities;
HashMap tileEntityMap= new HashMap();
NBTTagList tileEntity = loader.tileEntities;
//int size = tileEntity.tagCount();
@ -797,6 +810,16 @@ public class SchematicLoader
if(Block.blocksList[blockToReplace] instanceof BlockContainer)
{
TileEntity tile = world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe);
NBTTagCompound tag = this.tileEntityList[index];
if(tag!=null)
{
tile.readFromNBT(tag);
}
/**
// System.out.println("found container");
Random rand= new Random();
if(world.getBlockTileEntity(i+xCooe, j+yCooe, k+zCooe) instanceof TileEntityChest)
@ -835,6 +858,7 @@ public class SchematicLoader
dispenser.addItem(new ItemStack(Item.arrow, 64));
}
**/
}
}

View file

@ -4,17 +4,26 @@ import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.DungeonGenerator;
import StevenDimDoors.mod_pocketDim.LinkData;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ByteArrayTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.CompoundTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.IntTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.NBTOutputStream;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.ShortTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.StringTag;
import StevenDimDoors.mod_pocketDim.helpers.jnbt.Tag;
/**
@ -205,10 +214,11 @@ public class DungeonHelper
this.metadataFlipList.add(Block.signWall.blockID);
this.metadataFlipList.add(Block.skull.blockID);
this.metadataFlipList.add(Block.ladder.blockID);
this.metadataFlipList.add(Block.redstoneComparatorIdle);
this.metadataFlipList.add(Block.redstoneComparatorIdle);
this.metadataFlipList.add(Block.redstoneComparatorIdle);
this.metadataFlipList.add(Block.redstoneComparatorIdle);
this.metadataFlipList.add(Block.vine.blockID);
this.metadataFlipList.add(Block.anvil.blockID);
this.metadataFlipList.add(Block.chest.blockID);
this.metadataFlipList.add(Block.chestTrapped.blockID);
this.metadataFlipList.add(Block.hopperBlock.blockID);
this.metadataFlipList.add(Block.stairsNetherBrick.blockID);
this.metadataFlipList.add(Block.stairsCobblestone.blockID);
@ -363,16 +373,20 @@ public class DungeonHelper
short height= (short) (yMax-yMin);
short length= (short) (zMax-zMin);
//ArrayList<NBTTagCompound> tileEntities = new ArrayList<NBTTagCompound>();
NBTTagList tileEntites = new NBTTagList();
byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null;
byte[] blockData = new byte[width * height * length];
for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y) {
for (int z = 0; z < length; ++z) {
for (int y = 0; y < height; ++y)
{
for (int z = 0; z < length; ++z)
{
int index = y * width * length + z * width + x;
int blockID = world.getBlockId(x+xMin, y+yMin, z+zMin);
int meta= world.getBlockMetadata(x+xMin, y+yMin, z+zMin);
@ -388,8 +402,10 @@ public class DungeonHelper
}
// Save 4096 IDs in an AddBlocks section
if (blockID > 255) {
if (addBlocks == null) { // Lazily create section
if (blockID > 255)
{
if (addBlocks == null)
{ // Lazily create section
addBlocks = new byte[(blocks.length >> 1) + 1];
}
@ -400,6 +416,23 @@ public class DungeonHelper
blocks[index] = (byte) blockID;
blockData[index] = (byte) meta;
if (Block.blocksList[blockID] instanceof BlockContainer)
{
TileEntity tileEntityBlock = world.getBlockTileEntity(x+xMin, y+yMin, z+zMin);
NBTTagCompound tag = new NBTTagCompound();
tileEntityBlock.writeToNBT(tag);
// Get the list of key/values from the block
if (tag != null)
{
tileEntites.appendTag(tag);
}
}
}
}
}
@ -420,6 +453,7 @@ public class DungeonHelper
schematic.put("Width", new ShortTag("Width", (short) width));
schematic.put("Length", new ShortTag("Length", (short) length));
schematic.put("Height", new ShortTag("Height", (short) height));
schematic.put("TileEntites", tileEntites);
if (addBlocks != null) {
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));
}