|
| 1 | +package cc.cassian.raspberry.mixin.minecraft; |
| 2 | + |
| 3 | +import cc.cassian.raspberry.config.ModConfig; |
| 4 | +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; |
| 5 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 6 | +import net.minecraft.network.chat.CommonComponents; |
| 7 | +import net.minecraft.network.chat.Component; |
| 8 | +import net.minecraft.network.chat.contents.TranslatableContents; |
| 9 | +import net.minecraft.world.item.Item; |
| 10 | +import net.minecraft.world.item.ItemStack; |
| 11 | +import net.minecraft.world.item.SmithingTemplateItem; |
| 12 | +import net.minecraft.world.item.TooltipFlag; |
| 13 | +import net.minecraft.world.level.Level; |
| 14 | +import org.spongepowered.asm.mixin.Final; |
| 15 | +import org.spongepowered.asm.mixin.Mixin; |
| 16 | +import org.spongepowered.asm.mixin.Shadow; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | + |
| 20 | +@Mixin(SmithingTemplateItem.class) |
| 21 | +public abstract class SmithingTemplateMixin extends Item { |
| 22 | + @Shadow |
| 23 | + @Final |
| 24 | + private Component upgradeDescription; |
| 25 | + |
| 26 | + @Shadow |
| 27 | + @Final |
| 28 | + private static Component APPLIES_TO_TITLE; |
| 29 | + |
| 30 | + @Shadow |
| 31 | + @Final |
| 32 | + private static Component INGREDIENTS_TITLE; |
| 33 | + |
| 34 | + @Shadow |
| 35 | + @Final |
| 36 | + private Component appliesTo; |
| 37 | + |
| 38 | + @Shadow |
| 39 | + @Final |
| 40 | + private Component ingredients; |
| 41 | + |
| 42 | + public SmithingTemplateMixin(Properties properties) { |
| 43 | + super(properties); |
| 44 | + } |
| 45 | + |
| 46 | + @WrapMethod(method = "getDescriptionId") |
| 47 | + private String betterName(Operation<String> original) { |
| 48 | + if (ModConfig.get().noTemplates) { |
| 49 | + return ((TranslatableContents) this.upgradeDescription.getContents()).getKey(); |
| 50 | + }else { |
| 51 | + return original.call(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @WrapMethod(method = "appendHoverText") |
| 56 | + private <E> void removeWarning(ItemStack stack, Level level, List<Component> tooltipComponents, TooltipFlag isAdvanced, Operation<Void> original) { |
| 57 | + if (ModConfig.get().noTemplates) { |
| 58 | + super.appendHoverText(stack, level, tooltipComponents, isAdvanced); |
| 59 | + tooltipComponents.add(APPLIES_TO_TITLE); |
| 60 | + tooltipComponents.add(CommonComponents.space().append(this.appliesTo)); |
| 61 | + tooltipComponents.add(INGREDIENTS_TITLE); |
| 62 | + tooltipComponents.add(CommonComponents.space().append(this.ingredients)); |
| 63 | + } |
| 64 | + |
| 65 | + } |
| 66 | +} |
0 commit comments