Skip to content

Commit

Permalink
Change HandheldModels To InventoryModels
Browse files Browse the repository at this point in the history
  • Loading branch information
FirstMegaGame4 committed Apr 25, 2024
1 parent 0b2f6f3 commit 89d3aec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import java.util.Set;

@FunctionalInterface
public interface HandheldModels {
public interface InventoryModels {

Set<Identifier> MODDED_HANDHELD_MODELS = new HashSet<>();

Event<HandheldModels> EVENT = Event.create(HandheldModels.class, callbacks -> stack -> {
for (HandheldModels callback : callbacks) {
Event<InventoryModels> EVENT = Event.create(InventoryModels.class, callbacks -> stack -> {
for (InventoryModels callback : callbacks) {
Identifier identifier = callback.getModelForStack(stack);
if (identifier != null) {
return identifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.llamalad7.mixinextras.sugar.Share;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import com.mmodding.mmodding_lib.ducks.BakedModelManagerDuckInterface;
import com.mmodding.mmodding_lib.library.client.render.model.HandheldModels;
import com.mmodding.mmodding_lib.library.client.render.model.InventoryModels;
import com.mmodding.mmodding_lib.library.glint.client.GlintPack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.render.RenderLayer;
Expand Down Expand Up @@ -37,24 +37,12 @@ public abstract class ItemRendererMixin {
@Final
private ItemModels models;

@WrapOperation(method = "getHeldItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/BakedModel;getOverrides()Lnet/minecraft/client/render/model/json/ModelOverrideList;"))
private ModelOverrideList wrapHeldModels(BakedModel instance, Operation<ModelOverrideList> original, @Local(argsOnly = true) ItemStack stack) {
Identifier identifier = HandheldModels.EVENT.invoker().getModelForStack(stack);
@Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/BakedModel;getTransformation()Lnet/minecraft/client/render/model/json/ModelTransformation;"))
private void wrapHeldModels(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci, @Local(argsOnly = true) LocalRef<BakedModel> mutableModel) {
Identifier identifier = InventoryModels.EVENT.invoker().getModelForStack(stack);
if (identifier != null) {
BakedModel bakedModel = ((BakedModelManagerDuckInterface) this.models.getModelManager()).mmodding_lib$getModel(identifier);
return original.call(bakedModel);
mutableModel.set(((BakedModelManagerDuckInterface) this.models.getModelManager()).mmodding_lib$getModel(identifier));
}
return original.call(instance);
}

@WrapOperation(method = "getHeldItemModel", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/json/ModelOverrideList;apply(Lnet/minecraft/client/render/model/BakedModel;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/entity/LivingEntity;I)Lnet/minecraft/client/render/model/BakedModel;"))
private BakedModel applyHeldModels(ModelOverrideList instance, BakedModel model, ItemStack stack, ClientWorld world, LivingEntity entity, int seed, Operation<BakedModel> original) {
Identifier identifier = HandheldModels.EVENT.invoker().getModelForStack(stack);
if (identifier != null) {
BakedModel bakedModel = ((BakedModelManagerDuckInterface) this.models.getModelManager()).mmodding_lib$getModel(identifier);
return original.call(instance, bakedModel, stack, world, entity, seed);
}
return original.call(instance, model, stack, world, entity, seed);
}

@Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("HEAD"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mmodding.mmodding_lib.mixin.injectors.client;

import com.mmodding.mmodding_lib.library.client.render.model.HandheldModels;
import com.mmodding.mmodding_lib.library.client.render.model.InventoryModels;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.UnbakedModel;
Expand Down Expand Up @@ -33,7 +33,7 @@ public abstract class ModelLoaderMixin {

@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ModelLoader;addModel(Lnet/minecraft/client/util/ModelIdentifier;)V", shift = At.Shift.AFTER, ordinal = 1))
private void appendModdedModels(ResourceManager resourceManager, BlockColors blockColors, Profiler profiler, int i, CallbackInfo ci) {
HandheldModels.MODDED_HANDHELD_MODELS.forEach(this::mmodding_lib$addModdedModel);
InventoryModels.MODDED_HANDHELD_MODELS.forEach(this::mmodding_lib$addModdedModel);
}

@Unique
Expand Down

0 comments on commit 89d3aec

Please sign in to comment.