[Performance Suggestion] OreDictionary lookups
TheBlueCrystal opened this issue ยท 4 comments
Hello,
I have discovered with great pleasure, that you have implemented Ore-Dictionary lookups for planks and logs for freight-cars.
If I may make a suggestion for reducing the cpu-load of the server - Instead of creating a complete block-list of logs and planks and iterating over them for each inserted item, you could just get the Ore-Dictionary-ID (which is of type Integer) of logWood and plankWood with:
int logWood = OreDictionary.getOreID("logWood");
int plankWood = OreDictionary.getOreID("plankWood");
and afterwards you could simply do for example:
if(entity instanceof EntityFlatCarLogs_DB || entity instanceof EntityFreightWood || entity instanceof EntityFreightWood2) {
return OreDictionary.getOreID(itemstack) == logWood;
}
This would reduce the CPU-load considerable (especially with item-loaders), since you do not have to iterate over (like in my case) hundreds of log- and plank-blocks for each item inserted, but instead reduce it to a mere single hashmap-lookup followed by a single integer-comparison.
Just an idea. :)
Not saying I won't do this later, because it's a really good idea, but if you're really looking to make some modifications, the code is open source, so feel free to make a pull request with changes.
It would be an honour to me to contribute to the traincraft project.
I love this mod since the first release, and I have also made already some additions / modifications locally (for example I have added a "sky-view" check every 5 seconds for the windmill for the 3x3 blocks it's standing on, so you can't just plug it into a complete rock occlusion and it produces power nontheless (I know that's not a perfect solution, but it works :)) and I have also modified the Power-Track to draw real RF (from the block it's sitting on) instead of just needing a redstone signal which can be provided with a switched on lever on the bottom of the block for infinite power).
I will make separate pull-requests for each modfication, if that's okay.
Yeah that works fine. thanks for the contributions, every bit helps.
Also feel free to join the discord if you'd like to chat live. I'm always hanging out over there, unless I'm asleep. It's the more active side of the community.
Come to think of it, i should have a link for it in the readme.....