Jump to content

Spawning Structure


ZTheDragonz

Recommended Posts

I've coded my own structure generator, but it isn't really ready to share.  There are some others out there you may want to look at.  But here is the the general approach.

 

First of all, you need to decide whether your structures are made of "regular" pieces (like straight walls, perfect boxes, etc.) or irregular.  If they are regular, you can make methods for each regular part like generateWall() or generateHollowCube().  These would simply consist of nested for loops that cycle through all the locations and place the desired block.

 

I personally tend to have irregular structures.  So in that case I use a "schematic" method.  This means I have a file that basically maps out the placement of every block.  Then my generation method simply reads the file and places blocks as indicated.

 

There are several tricks though. First of all, a structure has a LOT of blocks in it.  A 20 x 20 x 20 room could have 8000 blocks!  So at the time of generation there can be significant lag.  I have worked on a way where the structure is built over several game ticks so that there is no lag, but frankly it is an intermediate programming level to get this right.  Also, because there are so many blocks, you need to use an external text file for the schematic -- otherwise you'll reach the limit of the size of a Java class.

 

Secondly, the order that you place some blocks matter, like if you try to place a torch before there is a wall to attach it it will cause trouble.  So I actually do three "passes" in the generation.  First I place all the regular blocks with no metadata that are also not special (I'll explain that in a sec).  Then I place blocks with metadata.  Then I place some special blocks like tripwire.  If you place tripwire before there is ground to place it on, it will just become an EntityItem rather than proper block.

 

Thirdly, rotation of a structure is EXTREMELY difficult because unfortunately the metadata is not consistent.  Rotating a bed to the East is different than rotating a door to the East, so you have to do a huge number of if statements to get it right.  I personally find it easier to make separate schematics that are already rotated than to have one schematic and try to rotate it via code.

 

But generally the idea is simple -- create a schematic in a text file (make this an asset resource), read the file back and place the blocks according to the schematic.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.