diff --git a/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java b/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java index 5c089c6351..cb27ebb6c8 100644 --- a/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java +++ b/src/main/java/vazkii/quark/content/experimental/module/VariantSelectorModule.java @@ -15,6 +15,7 @@ import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -81,6 +82,7 @@ public class VariantSelectorModule extends QuarkModule { @Config public static boolean showSimpleHud = false; @Config public static boolean showHud = true; @Config public static boolean enableGreenTint = true; + @Config public static boolean overrideHeldItemRender = true; @Config public static BlockSuffixConfig variants = new BlockSuffixConfig( @@ -268,6 +270,24 @@ public static BlockState modifyBlockPlacementState(BlockState state, BlockPlaceC return state; } + + @OnlyIn(Dist.CLIENT) + public static ItemStack modifyHeldItemStack(AbstractClientPlayer player, ItemStack stack) { + if(!staticEnabled || !overrideHeldItemRender) + return stack; + + Minecraft mc = Minecraft.getInstance(); + if(player == mc.player && stack.getItem() instanceof BlockItem bi) { + Block block = bi.getBlock(); + if(clientVariant != null && !clientVariant.isEmpty()) { + Block variant = variants.getBlockForVariant(block, clientVariant); + if(variant != null && variant != block) + return new ItemStack(variant); + } + } + + return stack; + } @SubscribeEvent @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/vazkii/quark/mixin/client/ItemInHandRendererMixin.java b/src/main/java/vazkii/quark/mixin/client/ItemInHandRendererMixin.java new file mode 100644 index 0000000000..84a88ffeb2 --- /dev/null +++ b/src/main/java/vazkii/quark/mixin/client/ItemInHandRendererMixin.java @@ -0,0 +1,21 @@ +package vazkii.quark.mixin.client; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.renderer.ItemInHandRenderer; +import net.minecraft.world.item.ItemStack; +import vazkii.quark.content.experimental.module.VariantSelectorModule; + +@Mixin(ItemInHandRenderer.class) +public class ItemInHandRendererMixin { + + @ModifyVariable(method = "renderArmWithItem", at = @At("HEAD"), argsOnly = true) + private ItemStack renderArmWithItem(ItemStack stack, AbstractClientPlayer player) { + return VariantSelectorModule.modifyHeldItemStack(player, stack); + } + + +} diff --git a/src/main/resources/quark.mixins.json b/src/main/resources/quark.mixins.json index 03b107af6b..513c6ce913 100644 --- a/src/main/resources/quark.mixins.json +++ b/src/main/resources/quark.mixins.json @@ -100,6 +100,7 @@ "client.RenderBuffersMixin", "client.ScreenMixin", "client.ThrownTridentRendererMixin", + "client.ItemInHandRendererMixin", "client.accessor.AccessorBlockColors", "client.accessor.AccessorItemColors", "client.accessor.AccessorLocalPlayer",