Skip to content

Commit

Permalink
fix staff renderer (fixes #41)
Browse files Browse the repository at this point in the history
  • Loading branch information
UpcraftLP committed Jan 7, 2025
1 parent 180b469 commit 44c449e
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry;
import net.fabricmc.fabric.api.resource.ResourceReloadListenerKeys;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
Expand All @@ -13,6 +14,9 @@
import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack;

import java.util.Collection;
import java.util.Set;

public class StaffItemRenderer implements BuiltinItemRendererRegistry.DynamicItemRenderer, SimpleSynchronousResourceReloadListener {
private final ResourceLocation id;
private final ResourceLocation itemId;
Expand All @@ -30,12 +34,17 @@ public ResourceLocation getFabricId() {
return this.id;
}

@Override
public Collection<ResourceLocation> getFabricDependencies() {
return Set.of(ResourceReloadListenerKeys.MODELS);
}

@Override
public void onResourceManagerReload(ResourceManager resourceManager) {
final Minecraft client = Minecraft.getInstance();
itemRenderer = client.getItemRenderer();
inventoryItemModel = client.getModelManager().getModel(new ModelResourceLocation(itemId.withPath(itemId.getPath() + "_gui"), "inventory"));
worldItemModel = client.getModelManager().getModel(new ModelResourceLocation(itemId.withPath(itemId.getPath() + "_handheld"), "inventory"));
inventoryItemModel = client.getModelManager().getModel(new ModelResourceLocation(itemId.withSuffix("_gui"), "inventory"));
worldItemModel = client.getModelManager().getModel(new ModelResourceLocation(itemId.withSuffix("_handheld"), "inventory"));
}

@Override
Expand All @@ -46,6 +55,8 @@ public void render(ItemStack stack, ItemDisplayContext mode, PoseStack matrices,
switch (mode) {
case FIRST_PERSON_LEFT_HAND, THIRD_PERSON_LEFT_HAND ->
itemRenderer.render(stack, mode, true, matrices, vertexConsumers, light, overlay, worldItemModel);
case FIRST_PERSON_RIGHT_HAND, THIRD_PERSON_RIGHT_HAND ->
itemRenderer.render(stack, mode, false, matrices, vertexConsumers, light, overlay, worldItemModel);
default ->
itemRenderer.render(stack, mode, false, matrices, vertexConsumers, light, overlay, inventoryItemModel);
}
Expand Down

0 comments on commit 44c449e

Please sign in to comment.