Commit a1f88a25 by Jonathan Thomas

Adding custom entity speed adjustments for a variety of Enties, that follow too…

Adding custom entity speed adjustments for a variety of Enties, that follow too slow or too fast. Most work fine with a speed of 1.0 though.
parent 7e75e9e2
Pipeline #11969 passed with stage
in 19 seconds
...@@ -16,6 +16,7 @@ import net.minecraft.server.MinecraftServer; ...@@ -16,6 +16,7 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Rarity; import net.minecraft.util.Rarity;
import net.minecraft.util.WorldSavePath; import net.minecraft.util.WorldSavePath;
import net.minecraft.util.math.MathHelper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -220,22 +221,28 @@ public class ChatDataManager { ...@@ -220,22 +221,28 @@ public class ChatDataManager {
LOGGER.info("Behavior: " + behavior.getName() + (behavior.getArgument() != null ? LOGGER.info("Behavior: " + behavior.getName() + (behavior.getArgument() != null ?
", Argument: " + behavior.getArgument() : "")); ", Argument: " + behavior.getArgument() : ""));
// Determine entity's default speed
// Some Entities (i.e. Axolotl) set this incorrectly... so adjusting in the SpeedControls class
float entitySpeed = SpeedControls.getMaxSpeed(entity);
float entitySpeedFast = MathHelper.clamp(entitySpeed * 1.3F, 0.5f, 1.3f);
// Apply behaviors to entity // Apply behaviors to entity
if (behavior.getName().equals("FOLLOW")) { if (behavior.getName().equals("FOLLOW")) {
FollowPlayerGoal followGoal = new FollowPlayerGoal(player, entity, 1F); FollowPlayerGoal followGoal = new FollowPlayerGoal(player, entity, entitySpeed);
EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class);
EntityBehaviorManager.addGoal(entity, followGoal, GoalPriority.FOLLOW_PLAYER); EntityBehaviorManager.addGoal(entity, followGoal, GoalPriority.FOLLOW_PLAYER);
} else if (behavior.getName().equals("UNFOLLOW")) { } else if (behavior.getName().equals("UNFOLLOW")) {
EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class);
} else if (behavior.getName().equals("FLEE")) { } else if (behavior.getName().equals("FLEE")) {
FleePlayerGoal fleeGoal = new FleePlayerGoal(player, entity, 1.5F, 20F); float fleeDistance = 400F; // 20 blocks squared
FleePlayerGoal fleeGoal = new FleePlayerGoal(player, entity, entitySpeedFast, fleeDistance);
EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, AttackPlayerGoal.class);
EntityBehaviorManager.addGoal(entity, fleeGoal, GoalPriority.FLEE_PLAYER); EntityBehaviorManager.addGoal(entity, fleeGoal, GoalPriority.FLEE_PLAYER);
} else if (behavior.getName().equals("ATTACK")) { } else if (behavior.getName().equals("ATTACK")) {
AttackPlayerGoal attackGoal = new AttackPlayerGoal(player, entity, 1.1F); AttackPlayerGoal attackGoal = new AttackPlayerGoal(player, entity, entitySpeedFast);
EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, TalkPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FollowPlayerGoal.class);
EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class); EntityBehaviorManager.removeGoal(entity, FleePlayerGoal.class);
......
...@@ -106,7 +106,7 @@ public class AttackPlayerGoal extends Goal { ...@@ -106,7 +106,7 @@ public class AttackPlayerGoal extends Goal {
break; break;
case CHARGING: case CHARGING:
this.entity.getNavigation().startMovingTo(this.targetPlayer, this.speed / 2D); this.entity.getNavigation().startMovingTo(this.targetPlayer, this.speed / 2.5D);
if (cooldownTimer <= 0) { if (cooldownTimer <= 0) {
currentState = EntityState.LEAPING; currentState = EntityState.LEAPING;
} }
...@@ -123,7 +123,7 @@ public class AttackPlayerGoal extends Goal { ...@@ -123,7 +123,7 @@ public class AttackPlayerGoal extends Goal {
case ATTACKING: case ATTACKING:
// Attack player // Attack player
this.entity.getNavigation().startMovingTo(this.targetPlayer, this.speed / 2D); this.entity.getNavigation().startMovingTo(this.targetPlayer, this.speed / 2.5D);
if (squaredDistanceToPlayer < ATTACK_DISTANCE && cooldownTimer <= 0) { if (squaredDistanceToPlayer < ATTACK_DISTANCE && cooldownTimer <= 0) {
this.performAttack(); this.performAttack();
currentState = EntityState.IDLE; currentState = EntityState.IDLE;
......
...@@ -12,9 +12,6 @@ import net.minecraft.util.math.MathHelper; ...@@ -12,9 +12,6 @@ import net.minecraft.util.math.MathHelper;
public class LookControls { public class LookControls {
public static void LookAtEntity(ServerPlayerEntity player, MobEntity entity) { public static void LookAtEntity(ServerPlayerEntity player, MobEntity entity) {
// Make the entity look at the player without moving towards them
entity.getLookControl().lookAt(player, 10.0F, (float)entity.getMaxLookPitchChange());
// Fix Slimes (who handle looking differently) // Fix Slimes (who handle looking differently)
if (entity instanceof SlimeEntity) { if (entity instanceof SlimeEntity) {
// Calculate direction which entity needs to face // Calculate direction which entity needs to face
...@@ -27,6 +24,10 @@ public class LookControls { ...@@ -27,6 +24,10 @@ public class LookControls {
float yawChange = MathHelper.clamp(yawDifference, -10.0F, 10.0F); // Limits the change to 10 degrees float yawChange = MathHelper.clamp(yawDifference, -10.0F, 10.0F); // Limits the change to 10 degrees
((SlimeEntity.SlimeMoveControl) entity.getMoveControl()).look(currentYaw + yawChange, false); ((SlimeEntity.SlimeMoveControl) entity.getMoveControl()).look(currentYaw + yawChange, false);
} else {
// Make the entity look at the player
entity.getLookControl().lookAt(player, 10.0F, (float)entity.getMaxLookPitchChange());
} }
} }
......
package com.owlmaddie.goals;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.mob.VindicatorEntity;
import net.minecraft.entity.mob.WitchEntity;
import net.minecraft.entity.passive.*;
/**
* The {@code SpeedControls} class has methods to return adjusted MaxSpeed values for different MobEntity instances.
* Unfortunately, some entities need to be hard-coded here, for a comfortable max speed.
*/
public class SpeedControls {
public static float getMaxSpeed(MobEntity entity) {
float speed = 1.0F;
// Adjust speeds for certain Entities
if (entity instanceof AxolotlEntity) {
speed = 0.5F;
} else if (entity instanceof VillagerEntity) {
speed = 0.5F;
} else if (entity instanceof AllayEntity) {
speed = 1.5F;
} else if (entity instanceof CamelEntity) {
speed = 3F;
} else if (entity instanceof AbstractDonkeyEntity) {
speed = 1.5F;
} else if (entity instanceof FrogEntity) {
speed = 2F;
} else if (entity instanceof PandaEntity) {
speed = 2F;
} else if (entity instanceof VindicatorEntity) {
speed = 0.75F;
} else if (entity instanceof WitchEntity) {
speed = 0.75F;
} else if (entity instanceof RabbitEntity) {
speed = 1.5F;
}
return speed;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment