diff options
Diffstat (limited to 'src/main')
8 files changed, 96 insertions, 34 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 7a5c3e9..a032f14 100644 --- a/src/main/generated/assets/potato-crime/lang/en_us.json +++ b/src/main/generated/assets/potato-crime/lang/en_us.json @@ -1,6 +1,7 @@ { "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.fill-level": "Hidden carrots: %s/1000.", "potato-crime.text.item-group": "Potato Crimes", "potato-crime.text.no-carrots": "No carrots to deposit." diff --git a/src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json b/src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json index c13496b..40a2c20 100644 --- a/src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json +++ b/src/main/generated/data/potato-crime/advancements/recipes/tools/contraband.json @@ -11,16 +11,6 @@ }, "trigger": "minecraft:inventory_changed" }, - "has_paper": { - "conditions": { - "items": [ - { - "items": "minecraft:paper" - } - ] - }, - "trigger": "minecraft:inventory_changed" - }, "has_the_recipe": { "conditions": { "recipe": "potato-crime:contraband" @@ -31,7 +21,6 @@ "requirements": [ [ "has_the_recipe", - "has_paper", "has_carrot" ] ], diff --git a/src/main/java/moe/nea/potatocrime/mixin/OnEnterPotatoWorldPatch.java b/src/main/java/moe/nea/potatocrime/mixin/OnEnterPotatoWorldPatch.java new file mode 100644 index 0000000..7d41687 --- /dev/null +++ b/src/main/java/moe/nea/potatocrime/mixin/OnEnterPotatoWorldPatch.java @@ -0,0 +1,20 @@ +package moe.nea.potatocrime.mixin; + +import moe.nea.potatocrime.events.OnEnterPotatoWorld; +import net.minecraft.entity.Entity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Entity.class) +public class OnEnterPotatoWorldPatch { + @Inject(method = "tickPortal", at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;moveToWorld(Lnet/minecraft/server/world/ServerWorld;Z)Lnet/minecraft/entity/Entity;", + shift = At.Shift.AFTER + )) + private void onMoveToWorld(CallbackInfo ci) { + OnEnterPotatoWorld.Companion.getEVENT().invoker().onEnterPotatoWorld((Entity) (Object) this); + } +} diff --git a/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt b/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt index 5d0cddc..b6ac78d 100644 --- a/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt +++ b/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt @@ -1,22 +1,60 @@ package moe.nea.potatocrime import moe.nea.potatocrime.entity.PotatoGuardEntity +import moe.nea.potatocrime.events.OnEnterPotatoWorld import moe.nea.potatocrime.registry.PotatoRegistry +import moe.nea.potatocrime.registry.PotatoTranslations import net.fabricmc.api.ModInitializer import net.fabricmc.fabric.api.`object`.builder.v1.entity.FabricDefaultAttributeRegistry +import net.minecraft.entity.SpawnReason +import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.world.ServerWorld +import net.minecraft.util.math.Direction +import net.minecraft.world.dimension.DimensionTypes import org.slf4j.LoggerFactory object PotatoCrime : ModInitializer { - val modId = "potato-crime" + val modId = "potato-crime" private val logger = LoggerFactory.getLogger("potato-crime") - override fun onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - logger.info("Hello Fabric world!") - PotatoRegistry.registerAll() - FabricDefaultAttributeRegistry.register(PotatoRegistry.potatoGuard, PotatoGuardEntity.createMobAttributes()) - } + override fun onInitialize() { + // This code runs as soon as Minecraft is in a mod-load-ready state. + // However, some things (like resources) may still be uninitialized. + // Proceed with mild caution. + logger.info("Hello Fabric world!") + PotatoRegistry.registerAll() + FabricDefaultAttributeRegistry.register(PotatoRegistry.potatoGuard, PotatoGuardEntity.createMobAttributes()) + OnEnterPotatoWorld.EVENT.register(OnEnterPotatoWorld { player -> + if (player is ServerPlayerEntity + && player.world.dimensionEntry.matchesKey(DimensionTypes.POTATO) + && hasContraband(player) + ) { + player.sendMessage(PotatoTranslations.youBrokeTheLaw.format()) + repeat(player.random.nextBetween(2, 4)) { + val randomOffsetPosition = + player.blockPos + .offset(Direction.Axis.X, player.random.nextBetween(-10, 10)) + .offset(Direction.Axis.Z, player.random.nextBetween(-10, 10)) + player.world.spawnEntity( + PotatoRegistry.potatoGuard.create( + player.world as ServerWorld, + null, + randomOffsetPosition, + SpawnReason.EVENT, + false, + false + ) + ) + } + } + }) + } + + fun hasContraband(entity: ServerPlayerEntity): Boolean { + return entity.inventory + .getMatchingStacks { it.isIn(PotatoRegistry.carrotIshItems) } + .isNotEmpty() + + } }
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt index 33ea7d1..40e0519 100644 --- a/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt +++ b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt @@ -1,6 +1,6 @@ package moe.nea.potatocrime.entity -import moe.nea.potatocrime.registry.PotatoRegistry +import moe.nea.potatocrime.PotatoCrime import net.minecraft.entity.EntityType import net.minecraft.entity.ai.goal.* import net.minecraft.entity.attribute.DefaultAttributeContainer @@ -8,6 +8,7 @@ import net.minecraft.entity.attribute.EntityAttributes import net.minecraft.entity.mob.HostileEntity import net.minecraft.entity.mob.PathAwareEntity import net.minecraft.entity.player.PlayerEntity +import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.world.World class PotatoGuardEntity(entityType: EntityType<out PotatoGuardEntity>, world: World?) : @@ -40,10 +41,7 @@ class PotatoGuardEntity(entityType: EntityType<out PotatoGuardEntity>, world: Wo PlayerEntity::class.java, true ) { player -> - (player as PlayerEntity) - .inventory - .getMatchingStacks { it.isIn(PotatoRegistry.carrotIshItems) } - .isNotEmpty() + PotatoCrime.hasContraband(player as ServerPlayerEntity) } ) } diff --git a/src/main/kotlin/moe/nea/potatocrime/events/OnWorldSwap.kt b/src/main/kotlin/moe/nea/potatocrime/events/OnWorldSwap.kt new file mode 100644 index 0000000..135ea51 --- /dev/null +++ b/src/main/kotlin/moe/nea/potatocrime/events/OnWorldSwap.kt @@ -0,0 +1,14 @@ +package moe.nea.potatocrime.events + +import net.fabricmc.fabric.api.event.EventFactory +import net.minecraft.entity.Entity + +fun interface OnEnterPotatoWorld { + fun onEnterPotatoWorld(entity: Entity) + + companion object { + val EVENT = EventFactory.createArrayBacked(OnEnterPotatoWorld::class.java) { events -> + OnEnterPotatoWorld { entity -> events.forEach { it.onEnterPotatoWorld(entity) } } + } + } +}
\ No newline at end of file diff --git a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt index 8d7fd19..a2cabf8 100644 --- a/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt +++ b/src/main/kotlin/moe/nea/potatocrime/registry/PotatoTranslations.kt @@ -21,5 +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!") }
\ 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 ba5b256..323c639 100644 --- a/src/main/resources/potato-crime.mixins.json +++ b/src/main/resources/potato-crime.mixins.json @@ -1,11 +1,12 @@ { - "required": true, - "package": "moe.nea.potatocrime.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "ExampleMixin" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "package": "moe.nea.potatocrime.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "ExampleMixin", + "OnEnterPotatoWorldPatch" + ], + "injectors": { + "defaultRequire": 1 + } }
\ No newline at end of file |