infernalstudios / Nekos-Enchanted-Books

3 stars 8 forks source link

1.18.2 Unable to add book and texture through datapack #14

Closed Raidobw2 closed 2 years ago

Raidobw2 commented 2 years ago

If you attempt to add textures to other enchanted books following the small procedure on the front page for new books, it doesn't work. If you replace the png in assets\nebs\textures\items for protection as an example it works. Adding a new key to the properties.json file through datapack doesn't work. I'm using KubeJS's virtual datapack to load it on top, although one could also just be using a normal datapack or OpenLoader and I think the result would be the same.

I think this is because the books' textures use Resource Location https://github.com/infernalexp/Nekos-Enchanted-Books/blob/c2a3e0b202f77126bcdb5dd7a5bd033eb795e837/src/main/java/org/infernalstudios/nebs/ModItemModelProvider.java#L25 whereas the registration looks like it does not, it's reading disk https://github.com/infernalexp/Nekos-Enchanted-Books/blob/c2a3e0b202f77126bcdb5dd7a5bd033eb795e837/src/main/java/org/infernalstudios/nebs/ModItemModelProvider.java#L37

The textures for the books look good and add to the quality of the gameplay experience. Thank you for your work!

SwanX1 commented 2 years ago

Hi there! This isn't intended behaviour. If it had been intended, we would have properly documented it. The file you're referencing, ModItemModelProvider, isn't a part of the mod that gets loaded when you play the game. It's only used for generating model files from the properties.json before compilation. The reason we don't use resource location, is because Minecraft's resource reader isn't available to use in the stage we're loading the mod. When the mod is loaded, the item property (custom model for the enchanted book) is added. Not all mods are loaded at this stage. The properties.json file tells the code where to look for the item models. There currently isn't a way to add new models for books via a datapack. You could use KubeJS's reflection to your advantage and modify the enchantmentMap when it is available to you (most likely on client post-setup):

onEvent('postinit', event => {
  var enchantmentMap = java('org.infernalstudios.nebs.NekosEnchantedBooks.enchantmentMap');
  enchantmentMap.put('modid:enchant', 69.69); // the number must be unique.
});

Then you need to modify the entire enchanted book model file: assets/minecraft/models/item/enchanted_book.json ...which then links to the new book model which uses your texture.

NOTE: I will not help with KubeJS related problems, or you trying to debug your own model files while doing this.

SwanX1 commented 2 years ago

If you'd like to have support for a mod's enchantment, feel free to make an issue regarding that.

Raidobw2 commented 2 years ago

Ah I see! Thank you very much for the answer and KubeJS snippet. What I'll do tomorrow is make a list of enchantments to support and make another issue as feature request. I've played with reflection before so I'll give it a test for my own knowledge, although I'm assuming you'll end up supporting the other enchants, so the reflection code will be short lived. Thanks again for the detailed answer and have a good day!