Jump to content

[1.8] How to code a multi-block structure similar to Big Reactors [Question]


Recommended Posts

I'm pretty new to Java, as I took a course on it a couple weeks ago. I'm currently taking a course on programming Minecraft mods, and next week I'll be able to program my own ideas as I'll be finished the standard part of the course. I'm not sure how to program a greenhouse multi-block structure similar to a Big Reactor that will allow plants to be planted inside it, speed up the growth speed, and make the crops yield more food, as well as protect them from diseases. I was wondering how I would program in something similar to Big Reactors where it requires a frame of Greenhouse Blocks and Greenhouse Glass windows, with a Controller as well to check how much the increase is. The increase is multiplied by 0.5% per glass block for increasing the gain, and can only have dirt and greenhouse blocks as the floor. I have no clue how to code a lot of this, so could any experienced coders help me out here?

Link to comment
Share on other sites



I'd advise to start out simple :)


First step is to add the different types of blocks you want and get them to render properly.  In fact, best to start just by add one of the blocks and getting it working first...


Then you need to add some logic somewhere to recognise when the player has constructed a complete greenhouse, typically this is called whenever one of your greenhouse blocks is placed, deleted, or otherwise changed.


Once you've gotten that far, come back and ask again, assuming you haven't become the expert yet :)



Link to comment
Share on other sites

I've made all of my blocks render properly and added them into the game, and I've been reading a little about tile entities and I took a quick look at some code for different Multi-block structures. I'm not sure how to create logic that allows me to make the greenhouse with walls of GH Glass or Blocks that have to have the frame as GH Blocks. I would also like to leave out the part with only having certain blocks in the interior so anyone can decorate their GH however they want. Can someone give me a starting point or tutorial on where I could learn how to make this?

Link to comment
Share on other sites

I'm going to assume you wish to have this structure variable sized? If so here's a few steps of the process.


Note that this is for explaination purposes, there are more efficient ways of doing parts of this, but as it's a task for a lesson you can try to figure some of that out :D


Do something similar to these when your blocks are placed:

1: Identify the corners of your structure:

    1a: Since this seems to be class project related, I won't give exact instructions

    1b: determine if the block was placed on a wall of floor/ceiling (using blocks next to it)

    1c: Depending, iterate through the blocks negative and positive to find the corner blocks.

    1d: For easy later, it's easiest to make the corners the absolute negative corner and the absolute positive corner.

2: Now that you have the corners, check the border blocks:

    2a: Start at the negative corner:

    2b: For each axis iterate and check the blocks the ensure they're the proper type

    2c: Do the same with the positive corner.

3: Check the walls of the cuboid for your type:

    3a:you can get a wall by taking 2 of the axis from one point and iterating towards the values of the other point, but always keeping the remaining axis equal to the value of the starting point.

    3b: You can also (although less efficient as it cycles through each block) cycle through each block, a block is located on the wall (or floor/ceiling) if any of the coordinates are equal on any axis to the values of either corner, all blocks in the middle will have 0 matching locations (the x will not be equal to either of the point's x location, same for y and z)

4: If these conditions are met, create the tile entity, store the two corners inside the tile entity.

5: On the tile entity update you can perform your operations within the two corners (be careful with how intensive your operation is or how often you set the tile to be ticked, you can cause a lot of lag).


6: You may have issues if your greenhouse crosses multiple chunks, if the chunk the tile entity is in isn't loaded, but the rest ofthe greenhouse is, the greenhouse will not function. If you need it to function regardless you can setup a master-slave system with the tile entities. Create a tile entity on each of the 4 corners on the bottom (or top if you wish) of your greenhouse. Set one as the master, another one as the secondary, another as the third, and the last as the fourth. When these tick they will first check if the tile entity one higher on the master-slave ladder is loaded, if so it will tick that instead, this would continue until it reaches the highest ranked loaded tile entity. On the highest ranked tile entity check if it has already ticked within the last while (however long you have between ticks) to prevent the entity ticking too often. At least one of the corners will be loaded any time any of the greenhouse is loaded (unless the greenhouse is like 32 or something chunks wide, which in that case that's a major problem).


7: You can also choose to, if you wish to make it easier at the cost of some slight memory, you can create a tile entity per chunk in that greenhouse that doesn't tick. Upon reaking a block of your type, you may iterate through the list of tile entites in that chunk, find that one and you may store on that tile entity the locationns of the 4 master-slave tile entities. Based on these locations you can determine with higher efficiency whether your block you broke was part of the greenouse (without having to do the stages in 1 again). If it was, destroy the tile entities, your greenhouse has been deconstructed.

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.

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.


  • Create New...

Important Information

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