Navigation

Libraries

MCSchematicTool

Current supported minecraft version: 1.9 - Many thanks to Inostupid Streams for updating it

09/01/2016: Update to 1.9 by Inostupid Streams, thanks
04/18/2013: Update to 1.5.1. Added 30 blocks and 23 Items! Additionally, all texture images are now in a single file (as they are in current MC) and all items support names.
08/26/2012: Update to 1.3.2. Added additional tree types, sandstone types, 10 Blocks and 3 items. Also changed all block IDs to short (they are byte in the schematic, but unsigned while java's byte type is signed. Short was used for ease of use)
03/11/2012: Update to 1.2.3. Added 2 Items and 2 Blocks. Also added a workaround for the "ShortTag cannot be cast to IntTag"-Error (that is actually a problem with the exporting program, not with S2B)
01/22/2012: Update to final 1.1.0. 20 items and 13 blocks added. Added print and marker functionality to ImageGrid and fixed the memory problem by not using one component/block to draw the ImageGrid.
11/7/2011: Update to 1.8.1 and various bugfixes. 10 items and 22 blocks added.
7/8/2011: Added some info-messages to the ParseException
6/28/2011: Added an image export directly to Slice (was only aviable from ImageGrid) and added a text export to SliceStack that is compatible with the Builders-Mod

Contents

Description
Support for texture packs
Note concerning Redstone Circuits
Note concerning empty Dispensers and blank Signs
Sample Code
Licence
Download and Javadoc

Post comment (Allready 28)

Description

This is a tool (a java library) to handle schematic files, an export format of many MineCraft tools.

After reading a schematic file, it provides you with a SliceStack object. This object represents a cuboid inside MineCraft, a three-dimensional collection of blocks.
The SliceStack contains various Slices representing a single horizontal plane of the SliceStack, ordered so that the index 0,0 corresponds to the north-west corner of the slice (first index is width, second is height).
Each slice consists of various Blocks, each one representing a single block inside the world of MineCraft. All blocks that have a data value, such as the direction they're facing, have a subclass handling its special needs, for example, Redstone Torches have a direction (RedstoneTorch.getDirection()) and can be on or off (RedstoneTorch.isOn()). To ensure that everything can be written back to a schematic file, all changes to a block (such as RedstoneTorch.setOn(false)) will update its data values.

All those classes also have the ability to give you a graphic representation of them as a swing component, making it easy to build GUI programs. To enable this, you have to call ImageProvider.initialize(). For memory and speed reasons, images are not loaded if you don't so the tool can be used in the background just as well.
All Blocks have the function getImage() returning a BufferedImage-instance of the block and the function getComponent, returning a special swing component that displays the image and updates with changes to this block. It also has tooltips giving more informations about the block. Some blocks, like Chests, have a special tooltip that displays an image.
Slices have the function getImages() which gives you an ImageGrid, a swing component holding the representation of the slice (a graphical grid grid containing all its blocks). SliceStacks return an array of such slice components wrapped inside a ImageGridStack object (which handles zooming etc).

Back to contents

Support for texture packs

Because MCSchematicTool uses the default MineCraft terrain.png and items.png for most of its block images, one can easely just replace them with those from a (16x16) texture pack to change the looks. For example, the screenshot from above with the Painterly texture pack looks like this:

Back to contents

Note concerning Redstone Circuits

This is only of interest if you plan to use the graphic features

Redstone wires are the only blocks in MineCraft that require knowledge of their surrounding to determine their direction. This is rather costly compared with other blocks, therefore MCSchematicTool gives you the ability to not calculate that trough a parameter for the getImages()-method of slice and slicestack, which will result in all redstone wires looking like the default cross piece. If you plan to let MCSchematicTools calculate the redstone wire directions, it is better to always use the SliceStacks getImages() method and not the one of Slice.
Because Slice represents a single, well, slice, even when calculating the redstone directions, it can only calculate them according to the current slice, so redstone lines going up a hill will not be recognized, but they will be in SliceStack.

Also, because of the way MCSchematicTool updates the graphical representations, you will have to get the complete ImageGridStack again if you change any block that will change the display of the wires.

Note that this is for displaying only and does not concern MCRedstoneTool in any other way at all.

Back to contents

Note concerning empty Dispensers and blank Signs

This is not actually a bug of MCSchematicTool, but a bug in WorldEdit that does not export the content of signs and dispensers.

Back to contents

Sample Code

To read a schematic file and graphically display a single slice from it (used for above screenshots):

try {
	ImageProvider.initialize();
			
	JFrame frm = new JFrame();
	frm.setTitle("Test");
	frm.setSize(250, 250);

	File f = new File("/path/to/your/shematic");
	SliceStack stack = SchematicReader.readSchematicsFile(f);
	// get lowest slice
	Slice slice = stack.getSlice(0);
	
	// 2 = zoom value - display the blocks at double slice (1 would be 16px x 16px)
	// true = calculate redstone wires (only for the current slice in this case)
	JScrollPane scrPn = new JScrollPane(slice.getImages(2, true));
	
	frm.add(scrPn);
	frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frm.setVisible(true);
} catch (IOException e) {
	// file not found
	e.printStackTrace();
} catch (ClassicNotSupportedException e) {
	// schematic is in Minecraft classic format
	e.printStackTrace();
} catch (ParseException e) {
	// schematic is invalid
	e.printStackTrace();
}

To just output the contents of the schematics in the console:

try {
	File f = new File("/path/to/your/shematic");
	SliceStack s = SchematicReader.readSchematicsFile(f);
	System.out.println(s);
} catch (IOException e) {
	// file not found
	e.printStackTrace();
} catch (ClassicNotSupportedException e) {
	// schematic is in Minecraft classic format
	e.printStackTrace();
} catch (ParseException e) {
	// schematic is invalid
	e.printStackTrace();
}


Example output:
[Diamond Block][Chest, contents: [3x Bone, 2x Cobblestone, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -, -]]
[Gold Block][Glass]
-------------
[Cobblestone][Dirt]
[Iron Block][Stone]
-------------

To trim and rotate the content of the schematic and save it to a new file:

try {
	File source = new File("/path/to/your/source.shematic");
	File target = new File("/path/to/your/target.shematic");
	SliceStack stack = SchematicReader.readSchematicsFile(source);
	stack.trim();
	stack.turnCW();
	SchematicWriter.writeSchematicsFile(stack, target);
} catch (IOException e) {
	// file not found
	e.printStackTrace();
} catch (ClassicNotSupportedException e) {
	// schematic is in Minecraft classic format
	e.printStackTrace();
} catch (ParseException e) {
	// schematic is invalid
	e.printStackTrace();
}

Back to contents

Licence

Would be nice if you would drop a link back to me if you use it. As for the rest, you're only bound to the licence of JNBT. See the Licence directory in the jar file for the full licence text.

Back to contents

Download and Javadoc

MCSchematicTool.jar (also containing source)

Back to contents

Comments

#27 Bierfreund wrote at 04/25/2013 02:39 PM (EST):
Danke, das ist genau das Tool, dass mir gefehlt hat. Gute Arbeit



Blender, binvox, constructor, mcedit und dein schematic2blueprint, ein perfektes lineup.

PS: Gabs wirklich keinen kürzeren Namen dafür? ;)

#25 Zeke wrote at 08/20/2012 10:58 AM (EST):
What do I do once I have the .jar file downloaded? How do I use/run the program?

#26 Klaue wrote at 08/31/2012 03:20 PM (EST):
This is not a program, this is a library. Hence why it's listed under "Library". What you want is the Program Schematic2Blueprint.

#21 Tom Baer wrote at 10/19/2011 10:09 PM (EST):
I am loving your kindness in the amount of comments.

#17 Tom Baer wrote at 10/19/2011 03:05 PM (EST):
It doesn't let me extract it. WinRar and 7Zip give a broken archive error. Is that some kind of protection? How could I look at the source? I am making an applet that can convert schematics to components for 1.8.1.

#18 Klaue wrote at 10/19/2011 04:14 PM (EST):
I just tested it and it extracts fine here. Maybe redownload it and try again?
As for your project: the lib is jurrently still on 1.6 (it works with newer schematics, or it should at least, but it would not recognise the new blocks and therefore just treat them as a general "unknown" block) as I had no time to update it...

#19 Tom Baer wrote at 10/19/2011 09:44 PM (EST):
That is fine, after my third time downloading it worked. I will write in the new blocks, and likely the fix the rotation stuff. The tile entities I will need to look into, because things like saving chests full of items or mob spawners is a big deal for some things.

#20 Tom Baer wrote at 10/19/2011 09:45 PM (EST):
If you want after it's written in, I can send it to you.

#22 Klaue wrote at 10/19/2011 11:16 PM (EST):
The chests with all the items should allready work. Some schematic exporters do not save them, though, and my tool cannot read what's not in the file, that's why some chests appear to be empty even if they weren't inside minecraft. Signs have the same problem.

If you want, I could give you the "beta" with my current status, it allready contains most of the new blocks and items.
It would contain Shears, Melon Slice, Pumpkin Seeds, Melon Seeds, Raw Chicken, Cooked Chicken, Raw Beef, Steak, Rotten Flesh, Ender Pearl, Stone Brick (Normal, Mossy, Cracked), Stone Brick Slabs, Brick Slabs, Stone Brick Stairs, Brick Stairs, Glass Pane, Iron Bars, Melon, Melon Stem / Pumpkin Stem, Vines, Fence Gate

It still lacks the red and brown mushroom caps and the mushroom stem (95% done, only direction stuff still incomplete) and the pistons.
By the way, there was some confusion because notch had to state that the sun rises in the north instead of east which fucked up all the directions, but I decided to still act like sun rising = east because a) it makes more sense to users and b) changing that would mean mayor work,

Note that I diddn't test any of the new blocks yet, so each one in the "done" list could fail. Still, probably way less work to take the beta.
Just tell me if you want it, but you'd have to wait until evening (central european time) because I'm off to work now.
Best would be to type in your email adress in the comment form here (if you diddn't allready do it). Nowbody but me can see that so spam is no issue ;)

#23 Tom Baer wrote at 10/20/2011 06:32 AM (EST):
Cool, that'd be great, I just set up my eclipse workspace yesterday and looked at some of the code, but I plan to getting to work later today.

#24 Klaue wrote at 10/24/2011 02:15 PM (EST):
Hey, did you receive the code? haven't heard anything since I sent it to you last thursday

#14 DV8FromTheWorld wrote at 09/10/2011 12:01 PM (EST):
Did I miss something? because after I downloaded it and tried to run it, it says "A Java Exception has occured" in the Java Virtual Machine Launcher

#16 Klaue wrote at 09/10/2011 08:31 PM (EST):
This is a programming library to build other programs with, not a program itself.
Maybe you're looking for Schematic2Blueprint, which uses this lib?
http://klaue.net16.net/programme/ownprogs/java/schematic2blueprint.en.php

#13 Serge wrote at 08/26/2011 09:08 AM (EST):
Does he copy modded blocks to the schematic file?

#15 Klaue wrote at 09/10/2011 08:30 PM (EST):
If you mean if it can handle modded blocks, then the short answer is "most of the time".
The long answer is:
Depends. it does care for unknown blocks, but if the modded block uses additional data in Tile Entities (only very few original ones, like the chest and the sign, use them), that will be lost. Also, it will be handled as if it had no direction (like most normal blocks), so if you rotated the schematic, the block will be moved to the right place, but without changing it's data value (that is where, for example, torches save their direction)

#7 Robert wrote at 06/28/2011 01:23 PM (EST):
Apparently refreshing the page resubmitted my last post. apologies for the double. Also I don't know if this would have been more appropriate as a suggestion for 'schematic2blueprint'

#8 Klaue wrote at 06/28/2011 01:44 PM (EST):
Hi Robert
Yeah, this comment thingy uses normal forms for the comments, which get resent with a reload. It's just this way because I don't like to use javascript ;)

About your suggestion: It looks like that would be simple enough to implement. What do the numbers in hat txt stand for or is there any docu about that format? My first guess would be block ids, but there isn't any block with the ID -1.

As for Schematic2Blueprint or this, I think this would be better. S2B is more or less just a GUI for this, only the code to save as images is new. MCST can do more than what's in S2B, for example, it can cut off unused layers (if the shematic contains 10 layers of air above it for example), it can turn it, change it, save the result as a new schematic - so even if I put that into S2B, I would probably build it in MCST anyway ;)

If you want to try it yourself, it's probably like this (out of the top of my head, note that I used block IDs for the numbers):
File f = new File("/path/to/your/shematic");
PrintWriter writer = new PrintWriter("/path/to/your/output.txt");
writer.println("##" + f.getName());

SliceStack stack = SchematicReader.readSchematicsFile(f);
for (int i = 0; i < stack.getHeight(); ++i) {
writer.println("##Layer " + i);
Slice s = stack.getSlice(i);
for (int height = 0; height < slice.getHeight(); ++height) {
for (int width = 0; width < slice.getWidth(); ++width) {
if (width != 0) { // add space
writer.print(" ");
}
writer.print(slice.getBlockAt(width, height).getId());
}
writer.println(); // newline
}
writer.println("##End Layer");
}
writer.flush();
writer.close();

#9 Klaue wrote at 06/28/2011 03:12 PM (EST):
Well, Done :)
Found a description of the files, they're normal block IDs, -1 and -2 are just special cases. (they just lack the data values, so black wool and red wool will just be white wool)

#10 Robert wrote at 06/28/2011 07:47 PM (EST):
Awesome, thank you for the help. I'll try to tinker with it until you ever implement it yourself - I'm afraid of trying to build a bigger project than I'm used to :P

As for the negative values, you found the description. The mod has 10 different types of builders, each with their own default block, so they can each build the same shape structure, using their default block if it is set to -1. The rest are just block ID's. This lets a brick builder build a house out of brick, and a cobblebuilder to build its house out of cobble, yet both of them use glass (blockid 20) for windows. Pretty simple.

I think it'd be neat, using your program/modified version to be able to convert schematics to make the builders randomly choose to build something much more interesting!

#11 Robert wrote at 06/28/2011 07:49 PM (EST):
Oh geez just realized you already updated it. You are a speed demon. Amazing! <3

#12 Klaue wrote at 06/28/2011 11:02 PM (EST):
Usually I take my sweet time to build something new, but I was just in the mood and it was easy enough ;)

I decided against using builder-specific bricks as that could look really awful for a lot of schematics, but you can always search+replace in the generated txt ;)

#6 Robert wrote at 06/28/2011 01:20 PM (EST):
I have a kind of request/comment for you. The work you have done here is great, I really appreciate the function the schematic tool provides in conjunction with making blueprints. Since the program already uses arrays and stacks to dissasemble schematic files, I figure this wouldn't be too hard to implement.

The popular mod 'builders' uses blueprint files, which are text files to allow building by the NPC's it provides. A sample portion of a blueprint is as follows:

//Name of Blueprint
##House 1
//Blueprint Layout
##Layer 1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 0 0 0 0 0 0 -1
-1 -2 0 0 0 0 0 -1
-1 -1 64 -1 -1 -1 -1 -1
##End Layer
##Layer 2
-1 -1 -1 -1 -1 -1 -1 -1
-1 0 -1 -1 -1 -1 -1 -1
-1 0 0 0 0 0 0 -1
-1 50 0 0 0 0 0 -1
-1 -1 0 -1 -1 20 -1 -1
##End Layer

Now looking through the javadocs and the source, it looks like a new class to export a text file similar to this instead of an image would be almost trivial. The program here already has to check the block type and associate it with a texture, so why not be able to associate it with just a number and save into an array?

I have taken java for some time, but it has been years since I have had to program anything, and I have a hard time wrapping my head around your whole program like you can, no doubt. Is there any chance you could update with a new class to export in a txt blueprint format, or tell me where I should start to do it myself? You would no doubt get a lot of attention from the modding community for that.

Of note, builders claims to support schematics, and perhaps its a bug in a recent version or user error, but very very simple schematics seem to work, but more complicated ones often break the mod and the builders stop building. It may be fixed in a future version, but the .txt blueprints are bulletproof, and work every time within the game.

Thanks for reading this wall of text!

#5 Robert wrote at 06/28/2011 01:17 PM (EST):
I have a kind of request/comment for you. The work you have done here is great, I really appreciate the function the schematic tool provides in conjunction with making blueprints. Since the program already uses arrays and stacks to dissasemble schematic files, I figure this wouldn't be too hard to implement.

The popular mod 'builders' uses blueprint files, which are text files to allow building by the NPC's it provides. A sample portion of a blueprint is as follows:

//Name of Blueprint
##House 1
//Blueprint Layout
##Layer 1
-1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1
-1 0 0 0 0 0 0 -1
-1 -2 0 0 0 0 0 -1
-1 -1 64 -1 -1 -1 -1 -1
##End Layer
##Layer 2
-1 -1 -1 -1 -1 -1 -1 -1
-1 0 -1 -1 -1 -1 -1 -1
-1 0 0 0 0 0 0 -1
-1 50 0 0 0 0 0 -1
-1 -1 0 -1 -1 20 -1 -1
##End Layer

Now looking through the javadocs and the source, it looks like a new class to export a text file similar to this instead of an image would be almost trivial. The program here already has to check the block type and associate it with a texture, so why not be able to associate it with just a number and save into an array?

I have taken java for some time, but it has been years since I have had to program anything, and I have a hard time wrapping my head around your whole program like you can, no doubt. Is there any chance you could update with a new class to export in a txt blueprint format, or tell me where I should start to do it myself? You would no doubt get a lot of attention from the modding community for that.

Of note, builders claims to support schematics, and perhaps its a bug in a recent version or user error, but very very simple schematics seem to work, but more complicated ones often break the mod and the builders stop building. It may be fixed in a future version, but the .txt blueprints are bulletproof, and work every time within the game.

Thanks for reading this wall of text!

#3 J. Stoever wrote at 06/18/2011 07:12 PM (EST):
Just wanted to say thank you for this awesome tool (although I think it would be more useful if you added some convenience methods for 2/3 dimensional arrays). Today, this solved an issue I had with MCEdit in like 10 minutes.

#4 Klaue wrote at 06/19/2011 02:16 AM (EST):
Nice it helped you :)
as for the arrays - slices are basically 2d arrays and the slicestack is basically a vector of those slices, so a conversion is just a simple loop - easy enough, I think :)


Add comment

*Name:

Email:
(Optional, hidden. Only if you want to be notified of replies)

Homepage:

* Spam check: 2 * 3 =
*Comment:

Back to contents