legobmw99/Allomancy

Allow metal whitelist to use tags

sciguyryan opened this issue · 6 comments

Hi.

It would be really handy if I could specify a tag (or list of tags) in the whitelist. I have scripts that assign a whole bunch of tags to various items and blocks, which I could repurpose for use with this config option.

An example would be: #forge:nuggets/zinc

I agree, but this is actually a more difficult problem than one would expect. It seems (in all my exploration, anyway) that the tag system is really good at answering the question "What tags does this item have?" and really bad at answering the question "What items are in this tag?"

The next update (which will come whenever I can find a spare weekend - it mostly just needs texture work at this point) will include a smarter default whitelist, which looks through all the registered items/blocks for names like 'zinc', 'iron', etc. It won't be perfect, but it will handle most of what a tag based system would, assuming you're sticking to metal items and not trying to add 'non-canon' things

I do not know enough about it to give a good commentary on that either I am afraid. I have only done minor modding work in the past.

AFAIK you can use ItemTags.getCollection() to get the complete TagCollection object, from which you can look up a Tag by its ID. You can then do Tag.contains(thing) to see if it contains that item.

That may or may not be the case, I have not looked at this in a while.

Your idea might actually work reasonably well anyway. I could quickly compile a list of the most common modded metals, if that would be of any assistance?

Yep, that's the "does this item have the tag" direction. In order for the whitelist to be feasible, it has to be 100% pre known, so I can reduce the logic of checking if a block or item is valid to a HashSet membership test. When you're doing hundreds of these checks a tick, it's crucial they be fast.

The method you described would need to try each tag that exists in the whitelist whenever an item is being looked up. If there's a way to get all the names out of a Tag ahead of time, I don't know it. I guess I could do it the really manual way of trying every item in the game at launch against the tags, then cacheing that result

The method you described would need to try each tag that exists in the whitelist whenever an item is being looked up. If there's a way to get all the names out of a Tag ahead of time, I don't know it. I guess I could do it the really manual way of trying every item in the game at launch against the tags, then cacheing that result

Would Tag.getAllElements() satisfy this requirement? If what I am reading is correct (I just pulled up my old modded Forge instance) this should return all elements that match that specific tab type.

Yeah, I understand the performance concerns here. The modded instance I have built has thousands (if not tens of thousands) of items as it has over 200 mods in it. I can see how not doing this optimally would be... bad.

It seems like Tag.getAllElements should work, but the TagCollection isn't populated at the loading stage when the config is read. I'm sure there is a way around this, but it also seems like it may be unnecessary.

I've decided to go the smarter auto-whitelist route