Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

TileEntity and Region.WriteChunk(x,z,c) #1

Open
ducttapecrown opened this issue Jun 17, 2013 · 8 comments
Open

TileEntity and Region.WriteChunk(x,z,c) #1

ducttapecrown opened this issue Jun 17, 2013 · 8 comments
Assignees

Comments

@ducttapecrown
Copy link

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.

@ghost ghost assigned LB-- Jun 17, 2013
@LB--
Copy link
Owner

LB-- commented Jun 17, 2013

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:

```java
code;
code;
code;
```

Glad you like the library :) I still need to update it for the latest version of Minecraft - the latest commit is only some halfwork.

@ducttapecrown
Copy link
Author

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

}

@LB--
Copy link
Owner

LB-- commented Jun 18, 2013

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.

@ducttapecrown
Copy link
Author

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
WriteChunk results in no TileEntities.

On Tue, Jun 18, 2013 at 5:14 PM, LB-- [email protected] wrote:

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.


Reply to this email directly or view it on GitHubhttps://github.com/LB--/MCModify/issues/1#issuecomment-19622340
.

@LB--
Copy link
Owner

LB-- commented Jun 18, 2013

Strange, it works for me. I'll try and figure out why that might happen.

@ducttapecrown
Copy link
Author

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

1
0

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?

@PanierAvide
Copy link

Hello,
A part of the problem may come from Chunk.java, line 959

tileticklist = new Tag.List("TileEntities", Tag.Type.COMPOUND);

It might not be "TileTicks" instead ?

LB-- added a commit that referenced this issue Feb 12, 2014
@LB--
Copy link
Owner

LB-- commented Feb 12, 2014

@PanierAvide thanks! That was a copy-paste error.

@ninjabattyshogun can you see if 9837959 fixes the issue for you?

@LB-- LB-- added bug labels Aug 29, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants