Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static NBTTagCompound saveWorldRegionToNBT(World world, BlockPOS pos1,
- BlockPOS pos2) {
- NBTTagCompound compound = new NBTTagCompound();
- if(pos1.x>pos2.x){
- int temp1=pos1.x;
- int temp2=pos2.x;
- pos2.x=temp1;
- pos1.x=temp2;
- }
- if(pos1.y>pos2.y){
- int temp1=pos1.y;
- int temp2=pos2.y;
- pos2.y=temp1;
- pos1.y=temp2;
- }
- if(pos1.z>pos2.z){
- int temp1=pos1.z;
- int temp2=pos2.z;
- pos2.z=temp1;
- pos1.z=temp2;
- }
- int height = pos1.y - pos2.y;
- int width = pos1.x - pos2.x;
- int depth = pos1.z - pos2.z;
- for (int y = pos1.y; y < height + 1; y++) {
- for (int x = 0; x < width + 1; x++) {
- for (int z = 0; z < depth + 1; z++) {
- int relativeX=pos1.x-x;
- int relativeZ=pos1.z-z;
- int relativeY=pos1.y-y;
- Block currentBlock = world.getBlock(x, y, z);
- NBTTagCompound currentBlockCompound = new NBTTagCompound();
- NBTTagCompound tileEntityCompound=new NBTTagCompound();
- String currentBlockName = (String) Block.blockRegistry
- .getNameForObject(currentBlock);
- Integer metadata = world.getBlockMetadata(x, y, z);
- System.out.println("processing block at:" +new BlockPOS(x, y, z)+"relative condinates:"+new BlockPOS(relativeX, relativeY, relativeZ)+"Block type:"+currentBlockName+"matedata:"+metadata);
- currentBlockCompound.setBoolean("hasTileEntity", currentBlock.hasTileEntity(metadata));
- currentBlockCompound.setString("blockid", currentBlockName);
- currentBlockCompound.setInteger("metadata", metadata);
- String name = String.format("Block|%x|%y|%z", relativeX, relativeY, relativeZ);
- if(currentBlock.hasTileEntity(metadata)){
- world.getTileEntity(z, y, z).writeToNBT(tileEntityCompound);
- }
- currentBlockCompound.setTag("tileEntityTag", tileEntityCompound);
- compound.setTag(name, currentBlockCompound);
- }
- }
- }
- return compound;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement