diff options
Diffstat (limited to 'src/main')
6 files changed, 61 insertions, 7 deletions
diff --git a/src/main/generated/assets/potato-crime/lang/en_us.json b/src/main/generated/assets/potato-crime/lang/en_us.json index a032f14..7f8fa71 100644 --- a/src/main/generated/assets/potato-crime/lang/en_us.json +++ b/src/main/generated/assets/potato-crime/lang/en_us.json @@ -1,8 +1,9 @@ { "entity.potato-crime.potato_guard": "Potato Guard", "item.potato-crime.contraband": "Contraband", - "potato-crime.text.arrest": "You broke the law by bringing carrots into those holy land!", + "potato-crime.text.arrest": "You broke the law by bringing carrots into this potato dimension!", "potato-crime.text.fill-level": "Hidden carrots: %s/1000.", "potato-crime.text.item-group": "Potato Crimes", - "potato-crime.text.no-carrots": "No carrots to deposit." + "potato-crime.text.no-carrots": "No carrots to deposit.", + "potato-crime.text.trade": "You got that good stuff. Here, have an emerald." }
\ No newline at end of file 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())); + } + } + } +} diff --git a/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt b/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt index b6ac78d..9aec040 100644 --- a/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt +++ b/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt @@ -49,6 +49,7 @@ object PotatoCrime : ModInitializer { } } }) + } fun hasContraband(entity: ServerPlayerEntity): Boolean { diff --git a/src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt b/src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt index 728d84a..06fe573 100644 --- a/src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt +++ b/src/main/kotlin/moe/nea/potatocrime/item/ContrabandItem.kt @@ -41,8 +41,8 @@ class ContrabandItem : Item( context: TooltipContext ) { val count = stack.getContrabandCount() - tooltip.add( - PotatoTranslations.contrabandFillText.format(count.toString()).styled { it.withColor(Formatting.DARK_GRAY) }) + tooltip.add(PotatoTranslations.contrabandFillText.format(count.toString()) + .styled { it.withColor(Formatting.DARK_GRAY) }) } override fun use(world: World, user: PlayerEntity, hand: Hand): TypedActionResult<ItemStack> { diff --git a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt index a2cabf8..0f1f041 100644 --- a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt +++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt @@ -21,6 +21,6 @@ object PotatoTranslations { val noCarrotsToDeposit = PT("no-carrots", "No carrots to deposit.") val itemGroup = PT("item-group", "Potato Crimes") val contrabandFillText = PT("fill-level", "Hidden carrots: %s/1000.") - val youBrokeTheLaw = PT("arrest", "You broke the law by bringing carrots into those holy land!") - + val youBrokeTheLaw = PT("arrest", "You broke the law by bringing carrots into this potato dimension!") + val villagerTrade = PT("trade","Oh, you got that good stuff! Here, have some emeralds.") }
\ No newline at end of file diff --git a/src/main/resources/potato-crime.mixins.json b/src/main/resources/potato-crime.mixins.json index 323c639..669712a 100644 --- a/src/main/resources/potato-crime.mixins.json +++ b/src/main/resources/potato-crime.mixins.json @@ -4,7 +4,8 @@ "compatibilityLevel": "JAVA_17", "mixins": [ "ExampleMixin", - "OnEnterPotatoWorldPatch" + "OnEnterPotatoWorldPatch", + "ShillCarrotsToVillagerPatch" ], "injectors": { "defaultRequire": 1 |