Open Bernasss12 opened 4 years ago
Big question, should it be:
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
).
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
For reference this is the where the idea came from:
How to go about it?