diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-02 03:26:21 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-02 03:26:21 +0200 |
commit | 4866f1360529d4d77dbd85c5e23d77a032043667 (patch) | |
tree | e4bd36d54ae0e00c3bb955bb0329e0f216e9c2de /src/main/java/moe/nea/potatocrime/mixin/ShillCarrotsToVillagerPatch.java | |
parent | 856d3242f34f7a787f02b086c0cb4b5b97eb34ca (diff) | |
download | potato-crimes-4866f1360529d4d77dbd85c5e23d77a032043667.tar.gz potato-crimes-4866f1360529d4d77dbd85c5e23d77a032043667.tar.bz2 potato-crimes-4866f1360529d4d77dbd85c5e23d77a032043667.zip |
Make carrots tradeable
Diffstat (limited to 'src/main/java/moe/nea/potatocrime/mixin/ShillCarrotsToVillagerPatch.java')
-rw-r--r-- | src/main/java/moe/nea/potatocrime/mixin/ShillCarrotsToVillagerPatch.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/potatocrime/mixin/ShillCarrotsToVillagerPatch.java b/src/main/java/moe/nea/potatocrime/mixin/ShillCarrotsToVillagerPatch.java new file mode 100644 index 0000000..e091069 --- /dev/null +++ b/src/main/java/moe/nea/potatocrime/mixin/ShillCarrotsToVillagerPatch.java @@ -0,0 +1,51 @@ +package moe.nea.potatocrime.mixin; + +import moe.nea.potatocrime.registry.PotatoTranslations; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.passive.MerchantEntity; +import net.minecraft.entity.passive.VillagerEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(VillagerEntity.class) +public abstract class ShillCarrotsToVillagerPatch extends MerchantEntity { + @Shadow + public abstract boolean isClient(); + + public ShillCarrotsToVillagerPatch(EntityType<? extends MerchantEntity> entityType, World world) { + super(entityType, world); + throw new UnsupportedOperationException(); + } + + @Inject(method = "interactMob", at = @At("HEAD"), cancellable = true) + private void onInteractMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) { + var itemInHand = player.getStackInHand(hand); + if (this.isAlive() && !this.hasCustomer() && !this.isSleeping()) { + if (itemInHand.isOf(Items.CARROT)) { + if (!isClient()) { + itemInHand.setCount(itemInHand.getCount() - 1); + player.giveItemStack(new ItemStack(Items.EMERALD)); + player.sendMessage(PotatoTranslations.INSTANCE.getVillagerTrade().format()); + } + cir.setReturnValue(ActionResult.success(isClient())); + } + if (itemInHand.isOf(Items.GOLDEN_CARROT)) { + if (!isClient()) { + itemInHand.setCount(itemInHand.getCount() - 1); + player.giveItemStack(new ItemStack(Items.EMERALD_BLOCK)); + player.sendMessage(PotatoTranslations.INSTANCE.getVillagerTrade().format()); + } + cir.setReturnValue(ActionResult.success(isClient())); + } + } + } +} |