Skip to content

Commit

Permalink
CustomModelData fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Theoness1 committed May 21, 2024
1 parent c62ee7b commit 64d9fb7
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
Expand All @@ -24,21 +23,20 @@ public abstract class DrawContextMixin {
@SuppressWarnings(value = "all")
@ModifyVariable(method = "drawItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;IIII)V", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/render/item/ItemRenderer;getModel(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)Lnet/minecraft/client/render/model/BakedModel;"))
private BakedModel getModel(BakedModel bakedModel, @Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed, int z) {
if(stack.contains(DataComponentTypes.FOOD)){
return this.getHeldFoodItemModel(stack, null, entity, seed);
if(stack.contains(DataComponentTypes.FOOD) && stack.get(DataComponentTypes.CUSTOM_MODEL_DATA) == null) {
return this.getHeldFoodItemModel(stack, entity, seed);
}
return this.client.getItemRenderer().getModel(stack, world, entity, seed);
return client.getItemRenderer().getModel(stack, world, entity, seed);
}

@Unique
public BakedModel getHeldFoodItemModel(ItemStack stack, @Nullable World world, @Nullable LivingEntity entity, int seed) {
public BakedModel getHeldFoodItemModel(ItemStack stack, @Nullable LivingEntity entity, int seed) {

BakedModel currentItemBakedModel = client.getItemRenderer().getModels().getModel(stack);

ClientWorld clientWorld = world instanceof ClientWorld ? (ClientWorld)world : null;
BakedModel itemBakedModel = stack.contains(DataComponentTypes.FOOD)
? client.getItemRenderer().getModels().getModel(stack)
: currentItemBakedModel.getOverrides().apply(currentItemBakedModel, stack, clientWorld, entity, seed);
: currentItemBakedModel.getOverrides().apply(currentItemBakedModel, stack, client.world, entity, seed);

return itemBakedModel == null ? client.getItemRenderer().getModels().getModelManager().getMissingModel() : itemBakedModel;
}
Expand Down

0 comments on commit 64d9fb7

Please sign in to comment.