Skip to content

Commit

Permalink
Update petrified oak slab fix - finished port
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 4, 2024
1 parent 72ab236 commit b6b4289
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,29 @@
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;

import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
import net.minecraft.client.render.item.ItemRenderer;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.entity.LivingEntity;
import net.minecraft.client.item.ItemModelManager;
import net.minecraft.component.ComponentType;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(ItemRenderer.class)
@Mixin(ItemModelManager.class)
public abstract class MixinItemRenderer {

@Shadow
@Final
private BakedModelManager bakedModelManager;
@Unique
private static final Identifier viaFabricPlus$missingIdentifier = Identifier.of(String.valueOf(System.currentTimeMillis()));

@Inject(method = "getModel(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)Lnet/minecraft/client/render/model/BakedModel;", at = @At("HEAD"), cancellable = true)
private void removeModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) {
if (VisualSettings.global().replacePetrifiedOakSlab.isEnabled() && world != null /* world is null in gui rendering */ && stack.isOf(Items.PETRIFIED_OAK_SLAB)) {
cir.setReturnValue(this.bakedModelManager.getMissingModel());
@Redirect(method = "update(Lnet/minecraft/client/render/item/ItemRenderState;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ModelTransformationMode;Lnet/minecraft/world/World;Lnet/minecraft/entity/LivingEntity;I)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;get(Lnet/minecraft/component/ComponentType;)Ljava/lang/Object;"))
public Object removeModel(ItemStack instance, ComponentType componentType) {
if (VisualSettings.global().replacePetrifiedOakSlab.isEnabled() && instance.isOf(Items.PETRIFIED_OAK_SLAB)) {
return viaFabricPlus$missingIdentifier;
} else {
return instance.get(componentType);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/viafabricplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"fixes.minecraft.item.MixinBrushItem",
"fixes.minecraft.item.MixinBucketItem",
"fixes.minecraft.item.MixinDrawContext",
"fixes.minecraft.item.MixinEnderEyeItem",
"fixes.minecraft.item.MixinEnderPearlItem",
"fixes.minecraft.item.MixinEquippableComponent",
"fixes.minecraft.item.MixinFireChargeItem",
Expand Down Expand Up @@ -216,8 +217,7 @@
"fixes.viaversion.MixinWorldPacketRewriter1_19",
"viabedrock.MixinJoinPackets",
"vialegacy.MixinExtensionProtocolMetadataStorage",
"vialegacy.MixinViaLegacyConfig",
"fixes.minecraft.item.MixinEnderEyeItem"
"vialegacy.MixinViaLegacyConfig"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b6b4289

Please sign in to comment.