Hey everyone, do you remember our crazy good looking shingles I introduced here they looked so awesome that, 1 day after I finished themm our modeler told me that we can't use them yet since they look bad when roofs have uneven sizes.
And as you can see, the line of oak planks doesn't look very good.
So I had to code a slab block which adapts to the block next to it.
Now, @d3miurge made amazing block models:
To be exact, 6 amazing block models.
One for 4 blocks connecting at each side.
One when one block on each side is connected to it:
One when only 1 block is connected to one of the sides:
Another one when two blocks are connected but in a curve.
The 5th one when 4 blocks are connected.
And the last one for 3 blocks.
Now my main task was a) to implement that this block integrates into the minecraft world (As in registering a recipe, the block, item and connect the models with the blockstates).
And b) the bigger part: To make sure that the block adapts its appearance depending on the neighboring blocks.
For this reason I defined 4*6 blockStates.
Now, the difficult part of this is, that minecraft has a limited amount of spaces for blockStates since there is a limit on amount of states the world can store per block (which will change in 1.13).
Therefore I used the limited space to store the orientation of the block.
Facing North, East, West or South.
And a blockState called the variant.
I defined the 6 variants following what I described above:
After that I was finally ready to go to the tough part.
First of all I had the idea to store an array of boolean variables of the state of all 4 directly neighboring blocks (not considering up and down).
This way we only have to ask the server once about the state of the certain positions.
Then, I calculated how many blocks are connected at all.
Which was super easy with the array.
Following this I had to think about all possible edgecases with sub types:
Which are basically:
- No Connected Blocks
- 1 Connected Block
- Connected North/South/West/East;
- Is there a shingle block connecting under it;
- 2 Connected Blocks
- Connected North or South, or in a curve (all 4 curve cases);
- 3 Connected Blocks
- Connected North/South/West/East;
- 4 Connected Blocks
Then I translated this into conditional statements.
Which basically now allows me to build a huge curve with the slabs and they will follow the right form!
And the roof from earlier?
Looking way better now as well.
I hope you liked this post, I was kinda afraid of this talk since I thought it's going to be a lot of headache, but after I sat down and planned my steps ahead, things started to get really easy after all.
Posted on Utopian.io - Rewarding Open Source Contributors