Minecolonies & Reworking Sapling and Ore Handling
The last two days I was quite busy reworking the way we were recognizing ores and Saplings.
Previously our sapling code worked the following:
On placement of the Lumberjack we calculated all existing saplings. using the Forge OreDict which allowed us to find all existing.
These saplings we then stored in the Building of the Lumberjack in a Map with a boolean which describes if the lumberjack should cut it or not.
Now, this part was working well, but, when we were trying to recognize trees, we used the metadata from the log of the tree and the metadata from the sapling to check if we should cut it.
Now, this is quite bad since the saplings are often different blocks with completely different metadata. Therefore, modded trees just didn't respond to the restrictions and would even, if deactivated block our existing trees.
Therefore, I did the following to fix this:
I created a CompatabilityManager (which will also be used for Ores) to generate all saplings and ores once on gamestart.
It fills a list of saplings the buildings will query on load and on creation.
We do the same thing with the ores.
Additionally, I created a BiMap which stores leaves and saplings (Leaves as IBlockStates and Saplings as ItemStorage (Our own implementation of items).
This way, when the lumberjack finds a tree it will register the leave of the tree with the sapling it drops (We can't do this on startup since we don't have access to all leaveblocks in a certain position in the world yet).
So as visible in the picture we check if we registered anything to the sapling or leave yet and we try to get a blockState without any additional data (like rotation etc) to store it as clean as possible.
Then, everytime we encounter a tree we just query the list of saplings in the lumberjack, take a leave from the tree and check it with the leaveToSapling map to see if we should cut this tree or not.
Then after we cut it, we can decide on the basis of the leave which sapling to use.
This way we easily find all saplings for all trees and place the correct one.
Our previous ore code only considered ores which extend the default minecraft ore class, but, unfortunately, we noticed that most mods don't do that, therefore we load all ores which are "somewhat an ore" in the OreDictionary and register it, as the saplings, on game load.
The miner then only queries if the ores are in the list and can decide on basis of that if it is an ore or not.
Besides that I fixed a bunch of other bugs:
- Double registering of buildings
- Correct spawning and requesting of entities with the Request system
- Correct ignoring of air spaces in whichever tileEntities.
I hope you liked our progress.
I'll keep you in touch.
Posted on Utopian.io - Rewarding Open Source Contributors