aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-04-01 21:57:16 +0200
committerLinnea Gräf <nea@nea.moe>2024-04-01 21:57:16 +0200
commitab30c1128b42eed24d0decf9ecf9e6a2c98a79e2 (patch)
treee0b23161678b97c09e89fda00dfa5f3d7569238f /src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
parent0fe5e487922a6ff50b9c415b9384157fbd64b2b5 (diff)
downloadpotato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.gz
potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.tar.bz2
potato-crimes-ab30c1128b42eed24d0decf9ecf9e6a2c98a79e2.zip
Add potato guard
Diffstat (limited to 'src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt')
-rw-r--r--src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
index b7282ea..33ea7d1 100644
--- a/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
+++ b/src/main/kotlin/moe/nea/potatocrime/entity/PotatoGuard.kt
@@ -1,3 +1,51 @@
package moe.nea.potatocrime.entity
-import net.minecraft.entity.LivingEntity
+import moe.nea.potatocrime.registry.PotatoRegistry
+import net.minecraft.entity.EntityType
+import net.minecraft.entity.ai.goal.*
+import net.minecraft.entity.attribute.DefaultAttributeContainer
+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.world.World
+
+class PotatoGuardEntity(entityType: EntityType<out PotatoGuardEntity>, world: World?) :
+ PathAwareEntity(entityType, world) {
+ companion object {
+ fun createMobAttributes(): DefaultAttributeContainer.Builder {
+ return HostileEntity.createHostileAttributes()
+ .add(EntityAttributes.GENERIC_FOLLOW_RANGE, 35.0)
+ .add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.4)
+ .add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 10.0)
+ .add(EntityAttributes.GENERIC_ARMOR, 4.0)
+ .add(EntityAttributes.GENERIC_MAX_HEALTH, 40.0)
+ }
+ }
+
+
+ override fun initGoals() {
+ goalSelector.add(3, MeleeAttackGoal(this, 1.0, false))
+ goalSelector.add(8, LookAroundGoal(this))
+ goalSelector.add(7, WanderAroundFarGoal(this, 1.0))
+ goalSelector.add(6, object : Goal() {
+ override fun canStart(): Boolean {
+ return this@PotatoGuardEntity.target == null && this@PotatoGuardEntity.getRandom().nextFloat() < 0.01
+ }
+ })
+ targetSelector.add(
+ 1,
+ ActiveTargetGoal(
+ this,
+ PlayerEntity::class.java,
+ true
+ ) { player ->
+ (player as PlayerEntity)
+ .inventory
+ .getMatchingStacks { it.isIn(PotatoRegistry.carrotIshItems) }
+ .isNotEmpty()
+ }
+ )
+ }
+
+}