-
Notifications
You must be signed in to change notification settings - Fork 10
TileEntity and Region.WriteChunk(x,z,c) #1
Comments
Could you give a sample of the code you're using to do that? You can format code with syntax highlighting on GitHub like this:
Glad you like the library :) I still need to update it for the latest version of Minecraft - the latest commit is only some halfwork. |
import java.io.FileInputStream;
import java.io.FileOutputStream;
import NBT.Tag;
import NBT.Serialization.NBTable;
import NBT.Minecraft.Map;
import NBT.Minecraft.IDs;
import NBT.Minecraft.Mob;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import NBT.FormatException;
import NBT.Minecraft.Level;
import NBT.Minecraft.Inventory;
import static NBT.Minecraft.IDs.*;
import NBT.Minecraft.Region;
import NBT.Minecraft.Chunk;
import NBT.Minecraft.TileEntity;
public class toMinecraft
{
public static void main( String args[] ) throws Throwable
{
toMinecraft run = new toMinecraft();
try
{
Region region = new Region( new File( "TestWorld/region/r.0.0.mca" ) );
Chunk chunk = region.ReadChunk( 0, 0 );
/*int y = 0;
for( int x=0; x<16; x++ )
for( int z=0; z<16; z++ )
chunk.BlockID( x, y, z, IDs.DiamondOre );
chunk.BlockID( 0, 2, 0, IDs.Chest );
chunk.BlockID( 0, 3, 0, IDs.Chest );*/
/*System.out.println( "\n"+ chunk.Empty() +"\n"+ chunk.TileEntities().size() );
*/
//chunk.TileEntities().add( run.newChest() );
//chunk.Entities().add( new Mob.Zombie( 1, 10, 1 )) ;
chunk.BlockID( 0, 4, 0, IDs.Chest );
for( TileEntity te : chunk.TileEntities() )
{
System.out.println( te.ToNBT(null) );
}
chunk = new Chunk( chunk.ToNBT(null) );
region.WriteChunk( 0, 0, chunk );
chunk = region.ReadChunk( 0, 0 );
System.out.println( chunk.TileEntities().size()+" "+chunk.BlockID(0,4,0) );
for( TileEntity te : chunk.TileEntities() )
System.out.println( te.ToNBT(null) );
//System.out.println( region.ReadChunk(0,0).TileEntities().size() );
}
catch( IOException e )
{
e.printStackTrace();
}
}
public TileEntity.Chest newChest() throws FormatException
{
Inventory.Item item = new Inventory.Item( 267, 0, 1 );
Tag.List Items = new Tag.List( "Items", Tag.List.Type.COMPOUND, item.ToNBT(null, (byte)0 ) );
Tag.Compound chest = new Tag.Compound( "Chest", Items, new Tag.String("id", "Chest"), new Tag.Int("x", 0), new Tag.Int("y", 4), new Tag.Int("z", 0) );
return new TileEntity.Chest( chest );
}
} |
Setting the block ID to that of a chest does not automatically create the tile entity for you, you still have to create the correct tile entity yourself and add it to the chunk. chunk.BlockID( 0, 4, 0, IDs.Chest );
chunk.TileEntities().add(new TileEntity.Chest(new Tag.Compound(null, new Tag.List("Items", Tag.Type.COMPOUND)))); In the future I will be adding default constructors so everything doesn't have to be constructed from NBT. |
Oh, right, sorry. I thought it was still in there. I was doing chunk.TileEntities().add( newChest() ); and then region.WriteChunk(). Doing an add() to TileEntities and then using On Tue, Jun 18, 2013 at 5:14 PM, LB-- [email protected] wrote:
|
Strange, it works for me. I'll try and figure out why that might happen. |
public class toMinecraft
{
public static void main( String args[] ) throws Throwable
{
toMinecraft run = new toMinecraft();
try
{
Region region = new Region( new File( "TestWorld/region/r.0.0.mca" ) );
Chunk chunk = region.ReadChunk( 0, 0 );
chunk.TileEntities().add( run.newChest() );
System.out.println( chunk.TileEntities().size() ); //output here
chunk = new Chunk( chunk.ToNBT(null) );
region.WriteChunk( 0, 0, chunk );
chunk = region.ReadChunk( 0, 0 );
System.out.println( chunk.TileEntities().size() ); //output here
}
catch( IOException e )
{
e.printStackTrace();
}
}
public TileEntity.Chest newChest() throws FormatException
{
Inventory.Item item = new Inventory.Item( 267, 0, 1 );
Tag.List Items = new Tag.List( "Items", Tag.List.Type.COMPOUND, item.ToNBT(null, (byte)0 ) );
Tag.Compound chest = new Tag.Compound( "Chest", Items, new Tag.String("id", "Chest"), new Tag.Int("x", 0), new Tag.Int("y", 4), new Tag.Int("z", 0) );
return new TileEntity.Chest( chest );
}
} Alright, this code should be clearer to read. I just lazily copy pasted stuff in earlier. I get the output
I'm running OSX 10.8.4 and Java 1.7.0_21-b12. That probably doesn't change anything, though, as minecraft files are pretty standard across machines, right? |
Hello, tileticklist = new Tag.List("TileEntities", Tag.Type.COMPOUND); It might not be "TileTicks" instead ? |
@PanierAvide thanks! That was a copy-paste error. @ninjabattyshogun can you see if 9837959 fixes the issue for you? |
I couldn't get WriteChunk to work with TileEntities. I would add a TileEntity, WriteChunk, ReadChunk, and TileEntities would be empty. I'm also not really sure how TileEntities and BlockIDs work. I might have missed something?
On a side note, the library is really nice and simple to use. I'm making a level generator, NetHack style.
The text was updated successfully, but these errors were encountered: