com.parzivail.pswg.mixin.ItemRendererMixin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pswg Show documentation
Show all versions of pswg Show documentation
Explore the galaxy with Galaxies: Parzi's Star Wars Mod!
package com.parzivail.pswg.mixin;
import com.parzivail.util.client.render.ICustomItemRenderer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_1087;
import net.minecraft.class_1309;
import net.minecraft.class_1799;
import net.minecraft.class_1937;
import net.minecraft.class_4587;
import net.minecraft.class_4597;
import net.minecraft.class_811;
import net.minecraft.class_918;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(class_918.class)
@Environment(EnvType.CLIENT)
public abstract class ItemRendererMixin
{
@Shadow
public abstract class_1087 getModel(class_1799 stack, @Nullable class_1937 world, @Nullable class_1309 entity, int seed);
// Handle the more specific case where the item is being rendered as being held by an entity
@Inject(method = "renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/world/World;III)V", at = @At("HEAD"), cancellable = true)
public void renderItem(class_1309 entity, class_1799 stack, class_811 renderMode, boolean leftHanded, class_4587 matrices, class_4597 vertexConsumers, class_1937 world, int light, int overlay, int seed, CallbackInfo ci)
{
if (!stack.method_7960())
{
var bakedModel = this.getModel(stack, world, entity, seed);
@Nullable
final ICustomItemRenderer itemRenderer = ICustomItemRenderer.REGISTRY.get(stack.method_7909().getClass());
if (itemRenderer != null)
{
itemRenderer.render(entity, stack, renderMode, leftHanded, matrices, vertexConsumers, light, overlay, bakedModel);
ci.cancel();
}
}
}
// TODO: check if this can be replaced by net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry
@Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("HEAD"), cancellable = true)
public void renderItem(class_1799 stack, class_811 renderMode, boolean leftHanded, class_4587 matrices, class_4597 vertexConsumers, int light, int overlay, class_1087 model, CallbackInfo ci)
{
if (!stack.method_7960())
{
@Nullable
final ICustomItemRenderer itemRenderer = ICustomItemRenderer.REGISTRY.get(stack.method_7909().getClass());
if (itemRenderer != null)
{
itemRenderer.render(null, stack, renderMode, leftHanded, matrices, vertexConsumers, light, overlay, model);
ci.cancel();
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy