Jump to content

Schematic Structure Generation


Resinresin

Recommended Posts

I stopped modding a year ago due to exams and the 1.7 update meaning that the way i generate schematics no longer works due to the fact that schematics store block ID's which as i understand are not relevant to forge post 1.6

 

After a few hours of searching i have been unable to find a solution and as my mod uses hundreds of schematic files i am not sure what to do. I am an amateur and a year away from modding has not helped so any help or light you may be able to shed on the issue would be greatly appreciated.

 

This is the code used to generate the schematic files:

 

 

public class Loader {

 

public byte[] blocks;

public byte[] datablocks;

public short width;

public short length;

public short height;

public short[] sizes;

 

public Loader(String path) {

blocks = null;

datablocks = null;

width = 0;

length = 0;

height = 0;

load(path);

}

 

public void load(String path) {

try {

InputStream inputstream = Loader.class.getResourceAsStream("/assets/warsmod/structures/" + path);

NBTTagCompound nbt = CompressedStreamTools.readCompressed(inputstream);

 

blocks = nbt.getByteArray("Blocks");

datablocks = nbt.getByteArray("Data");

width = nbt.getShort("Width");

length = nbt.getShort("Length");

height = nbt.getShort("Height");

sizes = new short[] { width, length, height };

} catch (Exception e) {

e.printStackTrace();

}

}

 

public void generate(World world, int posX, int posY, int posZ, boolean spawnairblocks) {

try {

int xnum = 0;

int ynum = 0;

int znum = 0;

 

for (int i = 0; i < blocks.length; i++) {

int blockId = UnsignedBytes.toInt(blocks);

if (((blocks != 0) && (!spawnairblocks)) || (spawnairblocks == true)) {

 

world.setBlock(posX + xnum, posY + ynum, posZ + znum, blockId, datablocks, 2);

}

 

if (xnum < width - 1) {

xnum++;

} else if ((xnum >= width - 1) && (znum < length - 1)) {

xnum = 0;

znum++;

} else if ((xnum >= width - 1) && (znum >= length - 1) && (ynum < height - 1)) {

xnum = 0;

znum = 0;

ynum++;

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

Link to comment
Share on other sites

I stopped modding a year ago due to exams and the 1.7 update meaning that the way i generate schematics no longer works due to the fact that schematics store block ID's which as i understand are not relevant to forge post 1.6

 

After a few hours of searching i have been unable to find a solution and as my mod uses hundreds of schematic files i am not sure what to do. I am an amateur and a year away from modding has not helped so any help or light you may be able to shed on the issue would be greatly appreciated.

 

This is the code used to generate the schematic files:

 

 

public class Loader {

 

public byte[] blocks;

public byte[] datablocks;

public short width;

public short length;

public short height;

public short[] sizes;

 

public Loader(String path) {

blocks = null;

datablocks = null;

width = 0;

length = 0;

height = 0;

load(path);

}

 

public void load(String path) {

try {

InputStream inputstream = Loader.class.getResourceAsStream("/assets/warsmod/structures/" + path);

NBTTagCompound nbt = CompressedStreamTools.readCompressed(inputstream);

 

blocks = nbt.getByteArray("Blocks");

datablocks = nbt.getByteArray("Data");

width = nbt.getShort("Width");

length = nbt.getShort("Length");

height = nbt.getShort("Height");

sizes = new short[] { width, length, height };

} catch (Exception e) {

e.printStackTrace();

}

}

 

public void generate(World world, int posX, int posY, int posZ, boolean spawnairblocks) {

try {

int xnum = 0;

int ynum = 0;

int znum = 0;

 

for (int i = 0; i < blocks.length; i++) {

int blockId = UnsignedBytes.toInt(blocks);

if (((blocks != 0) && (!spawnairblocks)) || (spawnairblocks == true)) {

 

world.setBlock(posX + xnum, posY + ynum, posZ + znum, blockId, datablocks, 2);

}

 

if (xnum < width - 1) {

xnum++;

} else if ((xnum >= width - 1) && (znum < length - 1)) {

xnum = 0;

znum++;

} else if ((xnum >= width - 1) && (znum >= length - 1) && (ynum < height - 1)) {

xnum = 0;

znum = 0;

ynum++;

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

}

For reading old schematics, Block#getBlockById(int i) should work for reading them as blocks. In 1.7.10, I believe blocks still have metadata, so you should be good there, unless you are jumping straight from 1.6 to 1.8, in which case Block#getStateFromMeta will also be helpful.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

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.