Different Icons for specific enchantments
Bernasss12 opened this issue · 4 comments
Wouldn't it be better to have Chime and CIT Resewn support instead of reinventing the wheel? Like, to have a resourcepack with custom textured books bundled with the mod that the user could optionally enable via resourcepacks menu
Well CIT Resewn wasn't a thing when this was requested, but yes now that does seem like a better alternative
Big question, should it be:
- Made to work with existing resourcepacks that have it? Constraining the amount of flexibility the format can have.
- Make a new system with customizability and configurability in mind? This would cripple the support from availible resource packs.
I would have a special json file in resource packs, that maps enchantment ids to model locations:
{
"minecraft:sharpness": "prettyenchants:item/sharpness_enchanted_book",
"minecraft:power": "prettyenchants:item/power_enchanted_book"
}
This map could be overlayed like sounds.json
. Then you could do something like this :
@Mixin(ModelLoader.class)
public abstract class ModelLoaderMixin {
@Unique
private static final Identifier ENCHANTED_BOOK_ID = new Identifier("item/enchanted_book");
@Shadow @Final protected ResourceManager manager;
@ModifyVariable(method = "loadModelFromJson", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/render/model/json/JsonUnbakedModel;deserialize(Ljava/io/Reader;)Lnet/minecraft/client/render/model/json/JsonUnbakedModel;"))
private JsonUnbakedModel addEnchantedBookOverride(JsonUnbakedModel model, Identifier id) {
if (ENCHANTED_BOOK_ID.equals(id)) {
Map<Identifier, Identifier> enchantmentTextures;
for (var resource : manager.findResources("better_enchanted_books_models.json") {
// process
}
for (var entry : enchantmentTextures.entrySet()) {
// some enchantments may come from a mod
if (Registry.ENCHANTMENTS.containsId(entry.getKey()) {
Map<Identifier, Float> minPropertyValues = new HashMap<>();
minPropertyValues.put(entry.getKey(), 1F);
model.getOverrides().add(new ModelItemOverride(entry.getValue(), minPropertyValues));
}
}
}
return model;
}
}
then add a property override to Items.ENCHANTED_BOOK
for every registered enchantment (RegistryAddedCallback
).