aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-02 02:38:25 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-02 02:38:25 +0200
commit856d3242f34f7a787f02b086c0cb4b5b97eb34ca (patch)
treecca84191a5ba58090f88a4d3de6b83dcc991e589 /src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt
parentab30c1128b42eed24d0decf9ecf9e6a2c98a79e2 (diff)
downloadpotato-crimes-856d3242f34f7a787f02b086c0cb4b5b97eb34ca.tar.gz
potato-crimes-856d3242f34f7a787f02b086c0cb4b5b97eb34ca.tar.bz2
potato-crimes-856d3242f34f7a787f02b086c0cb4b5b97eb34ca.zip
Improve texture
Diffstat (limited to 'src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt')
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/PotatoCrime.kt56
1 files changed, 47 insertions, 9 deletions
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