blob: c59b76c078aac3983f96c15c4faa60c3bf5b8713 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
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"
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())
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
.contains { it.isIn(PotatoRegistry.carrotIshItems) }
}
}
|