diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalLeapAtTarget.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalLeapAtTarget.java new file mode 100644 index 00000000..04d05718 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalLeapAtTarget.java @@ -0,0 +1,14 @@ +package com.willfp.eco.core.entities.ai.goals.entity; + +import com.willfp.eco.core.entities.ai.goals.EntityGoal; + +/** + * Leap at target. + * + * @param velocity The leap velocity. + */ +public record EntityGoalLeapAtTarget( + double velocity +) implements EntityGoal { + +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalLookAtPlayer.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalLookAtPlayer.java new file mode 100644 index 00000000..4c5edc7e --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalLookAtPlayer.java @@ -0,0 +1,16 @@ +package com.willfp.eco.core.entities.ai.goals.entity; + +import com.willfp.eco.core.entities.ai.goals.EntityGoal; + +/** + * Look at the player. + * + * @param range The range at which to look at the player. + * @param chance The chance to look at the player, as a percentage. + */ +public record EntityGoalLookAtPlayer( + double range, + double chance +) implements EntityGoal { + +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMeleeAttack.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMeleeAttack.java new file mode 100644 index 00000000..eaf21b45 --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMeleeAttack.java @@ -0,0 +1,16 @@ +package com.willfp.eco.core.entities.ai.goals.entity; + +import com.willfp.eco.core.entities.ai.goals.EntityGoal; + +/** + * Melee attack target. + * + * @param speed The speed at which to attack the target. + * @param pauseWhenMobIdle If the entity should pause attacking when the target is idle. + */ +public record EntityGoalMeleeAttack( + double speed, + boolean pauseWhenMobIdle +) implements EntityGoal { + +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveBackToVillage.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveBackToVillage.java new file mode 100644 index 00000000..214a02ee --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveBackToVillage.java @@ -0,0 +1,16 @@ +package com.willfp.eco.core.entities.ai.goals.entity; + +import com.willfp.eco.core.entities.ai.goals.EntityGoal; + +/** + * Move back to village. + * + * @param speed The speed at which to move back to the village. + * @param canDespawn If the entity can despawn. + */ +public record EntityGoalMoveBackToVillage( + double speed, + boolean canDespawn +) implements EntityGoal { + +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveThroughVillage.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveThroughVillage.java new file mode 100644 index 00000000..b257588a --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveThroughVillage.java @@ -0,0 +1,22 @@ +package com.willfp.eco.core.entities.ai.goals.entity; + +import com.willfp.eco.core.entities.ai.goals.EntityGoal; + +import java.util.function.BooleanSupplier; + +/** + * Move through village. + * + * @param speed The speed at which to move through the village. + * @param onlyAtNight If the entity can only move through village at night. + * @param distance The distance to move through the village. + * @param canPassThroughDoorsGetter A getter for if the entity can pass through doors. + */ +public record EntityGoalMoveThroughVillage( + double speed, + boolean onlyAtNight, + int distance, + BooleanSupplier canPassThroughDoorsGetter +) implements EntityGoal { + +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveTowardsRestriction.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveTowardsRestriction.java new file mode 100644 index 00000000..d0b2d26c --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveTowardsRestriction.java @@ -0,0 +1,14 @@ +package com.willfp.eco.core.entities.ai.goals.entity; + +import com.willfp.eco.core.entities.ai.goals.EntityGoal; + +/** + * Move towards restriction. + * + * @param speed The speed at which to move towards the restriction. + */ +public record EntityGoalMoveTowardsRestriction( + double speed +) implements EntityGoal { + +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveTowardsTarget.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveTowardsTarget.java new file mode 100644 index 00000000..59ff87ad --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/goals/entity/EntityGoalMoveTowardsTarget.java @@ -0,0 +1,16 @@ +package com.willfp.eco.core.entities.ai.goals.entity; + +import com.willfp.eco.core.entities.ai.goals.EntityGoal; + +/** + * Move towards target. + * + * @param speed The speed at which to move towards the target. + * @param maxDistance The maximum distance the target can be where the entity will still move towards it. + */ +public record EntityGoalMoveTowardsTarget( + double speed, + double maxDistance +) implements EntityGoal { + +} diff --git a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/ai/EntityGoals.kt b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/ai/EntityGoals.kt index 2e73ab55..5b42f6b2 100644 --- a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/ai/EntityGoals.kt +++ b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/ai/EntityGoals.kt @@ -10,6 +10,13 @@ import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalFloat import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalFollowBoats import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalFollowMobs import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalInteract +import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalLeapAtTarget +import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalLookAtPlayer +import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalMeleeAttack +import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalMoveBackToVillage +import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalMoveThroughVillage +import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalMoveTowardsRestriction +import com.willfp.eco.core.entities.ai.goals.entity.EntityGoalMoveTowardsTarget import net.minecraft.world.entity.PathfinderMob import net.minecraft.world.entity.ai.goal.AvoidEntityGoal import net.minecraft.world.entity.ai.goal.BreakDoorGoal @@ -21,6 +28,14 @@ import net.minecraft.world.entity.ai.goal.FollowBoatGoal import net.minecraft.world.entity.ai.goal.FollowMobGoal import net.minecraft.world.entity.ai.goal.Goal import net.minecraft.world.entity.ai.goal.InteractGoal +import net.minecraft.world.entity.ai.goal.LeapAtTargetGoal +import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal +import net.minecraft.world.entity.ai.goal.MeleeAttackGoal +import net.minecraft.world.entity.ai.goal.MoveBackToVillageGoal +import net.minecraft.world.entity.ai.goal.MoveThroughVillageGoal +import net.minecraft.world.entity.ai.goal.MoveTowardsRestrictionGoal +import net.minecraft.world.entity.ai.goal.MoveTowardsTargetGoal +import net.minecraft.world.entity.player.Player fun T.getImplementation(): EcoEntityGoal { @Suppress("UNCHECKED_CAST") @@ -34,6 +49,13 @@ fun T.getImplementation(): EcoEntityGoal { is EntityGoalFollowBoats -> FollowBoatsImpl is EntityGoalFollowMobs -> FollowMobsImpl is EntityGoalInteract -> InteractImpl + is EntityGoalLeapAtTarget -> LeapAtTargetImpl + is EntityGoalLookAtPlayer -> LookAtPlayerImpl + is EntityGoalMeleeAttack -> MeleeAttackImpl + is EntityGoalMoveBackToVillage -> MoveBackToVillageImpl + is EntityGoalMoveThroughVillage -> MoveThroughVillageImpl + is EntityGoalMoveTowardsRestriction -> MoveTowardsRestrictionImpl + is EntityGoalMoveTowardsTarget -> MoveTowardsTargetImpl else -> throw IllegalArgumentException("Unknown API goal!") } as EcoEntityGoal } @@ -125,3 +147,74 @@ object InteractImpl : EcoEntityGoal { ) } } + +object LeapAtTargetImpl : EcoEntityGoal { + override fun generateNMSGoal(apiGoal: EntityGoalLeapAtTarget, entity: PathfinderMob): Goal { + return LeapAtTargetGoal( + entity, + apiGoal.velocity.toFloat() + ) + } +} + +object LookAtPlayerImpl : EcoEntityGoal { + override fun generateNMSGoal(apiGoal: EntityGoalLookAtPlayer, entity: PathfinderMob): Goal { + return LookAtPlayerGoal( + entity, + Player::class.java, + apiGoal.range.toFloat(), + apiGoal.chance.toFloat() / 100f, + ) + } +} + +object MeleeAttackImpl : EcoEntityGoal { + override fun generateNMSGoal(apiGoal: EntityGoalMeleeAttack, entity: PathfinderMob): Goal { + return MeleeAttackGoal( + entity, + apiGoal.speed, + apiGoal.pauseWhenMobIdle + ) + } +} + +object MoveBackToVillageImpl : EcoEntityGoal { + override fun generateNMSGoal(apiGoal: EntityGoalMoveBackToVillage, entity: PathfinderMob): Goal { + return MoveBackToVillageGoal( + entity, + apiGoal.speed, + apiGoal.canDespawn + ) + } +} + +object MoveThroughVillageImpl : EcoEntityGoal { + override fun generateNMSGoal(apiGoal: EntityGoalMoveThroughVillage, entity: PathfinderMob): Goal { + return MoveThroughVillageGoal( + entity, + apiGoal.speed, + apiGoal.onlyAtNight, + apiGoal.distance, + apiGoal.canPassThroughDoorsGetter + ) + } +} + +object MoveTowardsRestrictionImpl : EcoEntityGoal { + override fun generateNMSGoal(apiGoal: EntityGoalMoveTowardsRestriction, entity: PathfinderMob): Goal { + return MoveTowardsRestrictionGoal( + entity, + apiGoal.speed + ) + } +} + +object MoveTowardsTargetImpl : EcoEntityGoal { + override fun generateNMSGoal(apiGoal: EntityGoalMoveTowardsTarget, entity: PathfinderMob): Goal { + return MoveTowardsTargetGoal( + entity, + apiGoal.speed, + apiGoal.maxDistance.toFloat() + ) + } +}