Skip to content

Commit

Permalink
Override held item render
Browse files Browse the repository at this point in the history
  • Loading branch information
Vazkii committed Oct 13, 2023
1 parent 239af0f commit 66b21c7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}


}
1 change: 1 addition & 0 deletions src/main/resources/quark.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"client.RenderBuffersMixin",
"client.ScreenMixin",
"client.ThrownTridentRendererMixin",
"client.ItemInHandRendererMixin",
"client.accessor.AccessorBlockColors",
"client.accessor.AccessorItemColors",
"client.accessor.AccessorLocalPlayer",
Expand Down

0 comments on commit 66b21c7

Please sign in to comment.