Jump to content

Recommended Posts

Posted (edited)

I used MCEdit and exported a building as .NBT and I was able to get BlockPos's as well the block using Block#getBlockFromName() but I have no idea how to get the BlockState properties. I know where they are stored but I don't know how to convert them to Block State. See the picture. For example at the first index in the Properties Compount Tag it has a property snowy: false. What I would use is 

Blocks.GRASS.getDefaultState().withProperty(BlockGrass.SNOWY, false)

Searching the minecraft's source code I found some classes like IBlockStatePalette that I suspect they can transform this but I do not know how to use it

Untitled.png

Edited by GeorgeTsak
Posted

Unsure if this class exists in 1.9.4, but NBTUtil#func_190008_d takes an NBTTagCompound (which has an IBlockState serialized within it) and returns the proper IBlockState.
You can see how vanilla MC makes use of this in Template#read.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted (edited)
7 hours ago, Matryoshika said:

Unsure if this class exists in 1.9.4, but NBTUtil#func_190008_d takes an NBTTagCompound (which has an IBlockState serialized within it) and returns the proper IBlockState.
You can see how vanilla MC makes use of this in Template#read.

 

OK since func_190008_d does not exist,I used the Template#read method like this:

public class NBTBuilding {

    NBTTagCompound nbtTagCompound;

    public NBTBuilding(String filename){
       try {

           InputStream is = Schematic.class.getResourceAsStream("/assets/modname/schematics/" + filename + ".nbt");
           this.nbtTagCompound = CompressedStreamTools.readCompressed(is);
           is.close();
       }
       catch (Exception e){
           FMLLog.warning("Error occurred while reading " + filename + ".nbt");
           FMLLog.warning(String.valueOf(e));
       }
    }

    public void createBuilding(World world, int x, int y, int z){
        //System.out.println("Requested to create a building at " + x + ", " + y + ", " + z);

        Template template = ((WorldServer)(world)).getStructureTemplateManager().getTemplate(world.getMinecraftServer(), new ResourceLocation(ModName.MODID, "name"));
        template.read(nbtTagCompound);
        template.addBlocksToWorldChunk(world, new BlockPos(x, y, z), new PlacementSettings());

    }

}

Well the structure generates in the correct shape however the blocks are messed up... Not a single block is correct. Eg instead of Stone it uses Lava. Checking here http://minecraft.gamepedia.com/Structure_block_file_format I see that my NBT file has the correct format. Any clue?

Edited by GeorgeTsak
Provide more info
Posted

Ok finally I got it. Aparrently the read method of Template does not work with the new Structure NBT of the 1.10+ So what I did was create a custom class copying the read code from 1.10. Now it works perfectly even if code is messed up a bit.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.