Jump to content

[1.7.10] Hollow Multiblock Structure


LordMastodonFTW

Recommended Posts

when you place a block (from your mod ideally) override onBlockAdded and perform some checks for the near blocks. You must consider where that block might go. Example: railcraft has tanks. When you place any of the blocks it performs a check counting how many blocks there are in x, y and z. If one of them is 1 (1 layer) the other 2 are the height and width of the tank. After that, check if the structure is valid and, if it is, find the center block and set its tile entity (all of the blocks probably have a tile entity I would guess) to store all the data (size, pos, fluid, amount...). You might want to set the metadata of the blocks "part of a multiblock" to some value (maybe different values based on position) for rendering purposes. The trick to make it look cool is, of course, connected textures. Hope this helps!

Check out my blog!

http://www.whov.altervista.org

Link to comment
Share on other sites

It depends on what you want to get. There is no cookbook ready to use because you can have various multiblock structures. Do you have a shape for your multiblock or does it need to change a lot (like irregular shapes, far from cuboids)? Moreover, do you have a particular block that is like a "masterpiece" (like ars magica has that key block for the portals and the altar) or, like railcraft, it's just blocks from your mod that are used specifically for that purpose? Do you want to allow multiple multiblocks of the same type side by side? Besides, is the multiblock formed on some event (right click of a valve like good old XYcraft tanks)?. The key to make it is considering exactly what you want and find common schemes present in each one. Give me a general idea and I'll come up with something. Bye!

PS: please, don't tell me you want a totally irregular one, I made one (the first and only multiblock I ever made), but they are crazy. Basically it would keep looking for adiacent blocks until it found valid ones and then save all the coords. Fun times when it comes to break such a thing..

Check out my blog!

http://www.whov.altervista.org

Link to comment
Share on other sites

Nah, I just want a normal hollow 5 x 5 x 5. I do want the activation to be based on a right-click, and I do want different blocks in the multiblock to have different metadata. Again, don't provide me with copy/paste, just basic instruction.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Link to comment
Share on other sites

Ok. You will need a function that checks if multiblock structure is valid and that eventually makes it setting the metadata values and activating some tile entities maybe. That would be called from onBlockActivated. You will also need a breakMultiblock method that is called when you do something like breaking a block that is part of the structure.

 

For some code to check if multiblock structure is valid you must be either creative or copy from some tutorials on the net. I suggest something like 3 nested for loops from -4 to 0 and check every block: if it's valid (metadata==0 so not already part of multiblock and block==yourBlock) the consider it the bottom left left corner and perform a check (like 3 more nested for loops 0-4 and, if one of the variables is 0 or 4, then you are in a face/edge/corner => must be yourblock and metadata==0, else must be air block). If returns false then just keep on looping. Else found multiblock at coords of the bottom left left corner x,y,z and call a method to set metadata (like 1 for corner, 2 for edge and 3 for face, just base on the variables of the for loops and see if the are the min or the max) and, I suggest, set all the tile entities of the blocks to refer to a master block (like the center bottom one) doing something like coords of bottom left left corner + 2 on x and z and that is the master. Every other tile entity will send every request to that tile.

 

Now make sure that onBlockActivated does that only if metadata==0, else open some kind of gui or whatever sending the request like this: ((MultiBlockTile)world.getTileEntity(x, y, z)).getMasterBlock().doWhateverYouWant(). getMasterBlock gets the tile entity from the same world of the one you clicked but with the saved (also in NBT!!) coordinates.

 

Last but not least in your onBlockDestroyed (might be another name) if your block has metadata>0 than get the tile entity, get the master and from those coords (might be useful to shift x and z back 2 so that you can use the same algorithm of the create method) break the multiblock setting metadata=0 and tileEntity master=null or something. Don't necessarely wipe out all the data from the master, just delete all references to it for the time being. That will allow players to change every other block in the structure (swap blocks for others like tank valve for gauge) and not lose all the honey..I mean data ;). Of course, if you attach a custom tileEntitySpecialRenderer to your tiles and, based on metadata or something, do some magic rendering that would be the best  8)

Post again if you have more questions :D

Check out my blog!

http://www.whov.altervista.org

Link to comment
Share on other sites

But my problem with that is what if it's the top middle or something like that. Then, my for loops would return something completely wrong and the player would have to place the block in the bottom left to get it to work. How would I get it to do the for loops with an x/y/z relative to the bottom left corner rather than an x/y/z relative to the block itself?

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Link to comment
Share on other sites

for x1, y1, z1 [-4;0] getBlock. if block==... then isMultiBlock(x+x1, y+y1, z+z1);

//if the corner were further then this block wouldn't be in the structure anyway

 

isMultiBlock(x, y, z) {

for x1, y1, z1 [0;4] {block = getBlock(x+x1, y+y1, z+z1);

if (inside&&block!=air||corner&&block!=yours) return false;

}

formMultiBlock(x, y, z);//do the things

return true;

}

Check out my blog!

http://www.whov.altervista.org

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.