Darkhax-Minecraft / Distracting-Trims

Armor with gold plated trims will distract piglins from attacking you.
1 stars 1 forks source link

[Compat Request] Compatibility with Armor Trims Backport #1

Open Hipposgrumm opened 1 year ago

Hipposgrumm commented 1 year ago

So I was recently browsing the "Armor Trims" search on Modrinth and found this mod. I realized that it would probably be very easy to backport this mod using Armor Trims Backport. I decided to look at the source code and realized how easy it would be. To make it easier, I already wrote the code for porting your mod using mine.

package net.darkhax.distractingtrims.mixin;

import gg.hipposgrumm.armor_trims.trimming.TrimmableItem;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.monster.piglin.PiglinAi;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
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;

@Mixin(PiglinAi.class)
public class MixinPiglinAi {

    @Unique
    private static final TagKey<ResourceLocation> DISTRACTING_TRIM = TagKey.create(Registries.ITEM_TAG, new ResourceLocation("distractingtrims", "distracts_piglins"));

    @Inject(method = "isWearingGold(Lnet/minecraft/world/entity/LivingEntity;)Z", at = @At("HEAD"), cancellable = true)
    private static void isWearingGold(LivingEntity wearer, CallbackInfoReturnable<Boolean> cbi) {
        for (ItemStack stack : wearer.getArmorSlots()) {
            if (stack.hasTag()) {
                final ResourceLocation material = TrimmableItem.getMaterial(stack);
                if (material != null && Registry.ITEM.get(material).getDefaultInstance().is(DISTRACTING_TRIM)) {
                    cbi.setReturnValue(true);
                }
            }
        }
    }
}

Note: This is based off of your existing code. Note 2: This was written on the fly and is untested. You may want to double check that it actually works.

Darkhax commented 1 year ago

Thanks for letting me know about your mod. I am going to abstract the code a bit but this should be a good start.

Hipposgrumm commented 1 year ago

You might want to hold off on releasing Distracting Trims with Armor Trims Backport until after I release v1.4 which will include a Fabric version and hopefully fix the JEI issues.

Darkhax commented 8 months ago

Hey @Hipposgrumm, is the 1.4 version still being worked on?

Hipposgrumm commented 8 months ago

Yeah, just taking a really long time (procrastination and demotivation and that kind of stuff).

Thing is I thought it would be a good idea to overhaul the mod and port it to Fabric at the same time.