Make NPCs more likely to swim, add speed setting in water

This commit is contained in:
fullwall 2023-02-08 22:07:15 +08:00
parent bbfbc767dc
commit 7244834e34
15 changed files with 22 additions and 22 deletions

View File

@ -154,6 +154,7 @@ public class Settings {
NPC_SKIN_ROTATION_UPDATE_DEGREES("npc.skins.rotation-update-degrees", 90f),
NPC_SKIN_USE_LATEST("npc.skins.use-latest-by-default", false),
NPC_SKIN_VIEW_DISTANCE("npc.skins.view-distance", 100D),
NPC_WATER_SPEED_MODIFIER("npc.movement.water-speed-modifier", 1.25F),
PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
PLACEHOLDER_SKIN_UPDATE_FREQUENCY("npc.skins.placeholder-update-frequency-ticks", 5 * 60 * 20),
PLAYER_TELEPORT_DELAY("npc.teleport-delay", "npc.delay-player-teleport-ticks", -1),

View File

@ -468,6 +468,8 @@ public class CitizensNPC extends AbstractNPC {
if (navigator.isNavigating()) {
if (data().get(NPC.Metadata.SWIMMING, true)) {
getEntity().setVelocity(getEntity().getVelocity().multiply(data()
.get(NPC.Metadata.WATER_SPEED_MODIFIER, Setting.NPC_WATER_SPEED_MODIFIER.asFloat())));
Location currentDest = navigator.getPathStrategy().getCurrentDestination();
if (currentDest == null || currentDest.getY() > getStoredLocation().getY()) {
NMS.trySwim(getEntity());

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector;
@ -131,9 +130,8 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
NMS.setDestination(npc.getEntity(), dest.getX(), dest.getY(), dest.getZ(), params.speed());
} else {
Vector dir = dest.toVector().subtract(npc.getEntity().getLocation().toVector()).normalize().multiply(0.2);
Block in = npc.getEntity().getLocation().getBlock();
if ((dY >= 1 && Math.sqrt(xzDistance) <= 0.4)
|| (dY >= 0.2 && MinecraftBlockExaminer.isLiquidOrInLiquid(in))) {
boolean liquidOrInLiquid = MinecraftBlockExaminer.isLiquidOrInLiquid(NPC_LOCATION.getBlock());
if ((dY >= 1 && Math.sqrt(xzDistance) <= 0.4) || (dY >= 0.2 && liquidOrInLiquid)) {
dir.add(new Vector(0, 0.75, 0));
}
npc.getEntity().setVelocity(dir);

View File

@ -1370,7 +1370,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && (handle.ak() || handle.ao())) {
if (RANDOM.nextFloat() <= 0.85F && (handle.ak() || handle.ao())) {
handle.motY += power;
}
}

View File

@ -1437,7 +1437,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && (handle.ak() || handle.ao())) {
if (RANDOM.nextFloat() <= 0.85F && (handle.ak() || handle.ao())) {
handle.motY += power;
}
}

View File

@ -1444,7 +1444,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && (handle.aq() || handle.au())) {
if (RANDOM.nextFloat() <= 0.85F && (handle.aq() || handle.au())) {
handle.motY += power;
}
}

View File

@ -1487,7 +1487,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && (handle.at() || handle.ax())) {
if (RANDOM.nextFloat() <= 0.85F && (handle.at() || handle.ax())) {
handle.motY += power;
}
}

View File

@ -1479,7 +1479,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && (handle.isInWater() || handle.ay())) {
if (RANDOM.nextFloat() <= 0.85F && (handle.isInWater() || handle.ay())) {
handle.setMot(handle.getMot().getX(), handle.getMot().getY() + power, handle.getMot().getZ());
}
}

View File

@ -1528,7 +1528,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && (handle.isInWater() || handle.aC())) {
if (RANDOM.nextFloat() <= 0.85F && (handle.isInWater() || handle.aC())) {
handle.setMot(handle.getMot().getX(), handle.getMot().getY() + power, handle.getMot().getZ());
}
}

View File

@ -1548,7 +1548,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && handle.isInWater()) {
if (RANDOM.nextFloat() <= 0.85F && handle.isInWater()) {
handle.setMot(handle.getMot().getX(), handle.getMot().getY() + power, handle.getMot().getZ());
}
}

View File

@ -1539,7 +1539,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && handle.isInWater()) {
if (RANDOM.nextFloat() <= 0.85F && handle.isInWater()) {
handle.setDeltaMovement(handle.getDeltaMovement().x, handle.getDeltaMovement().y + power,
handle.getDeltaMovement().z);
}

View File

@ -1547,7 +1547,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && handle.isInWater()) {
if (RANDOM.nextFloat() <= 0.85F && handle.isInWater()) {
handle.setDeltaMovement(handle.getDeltaMovement().x, handle.getDeltaMovement().y + power,
handle.getDeltaMovement().z);
}

View File

@ -42,20 +42,19 @@ public class HorseController extends MobEntityController {
super(EntityHorseNPC.class);
}
@Override
public org.bukkit.entity.Horse getBukkitEntity() {
return (org.bukkit.entity.Horse) super.getBukkitEntity();
}
@Override
public void create(Location at, NPC npc) {
npc.getOrAddTrait(HorseModifiers.class);
super.create(at, npc);
}
@Override
public org.bukkit.entity.Horse getBukkitEntity() {
return (org.bukkit.entity.Horse) super.getBukkitEntity();
}
public static class EntityHorseNPC extends Horse implements NPCHolder {
private double baseMovementSpeed;
private boolean calledNMSHeight = false;
private final CitizensNPC npc;
private boolean riding;

View File

@ -1358,7 +1358,7 @@ public class NMSImpl implements NMSBridge {
NMSImpl.sendPacket(recipient, packet);
/* if (VIA_ENABLED == true) {
/* if (VIA_ENABLED == true) {
int version = Via.getAPI().getPlayerVersion(recipient);
return version < 761;
}*/
@ -1677,7 +1677,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && handle.isInWater()) {
if (RANDOM.nextFloat() <= 0.85F && handle.isInWater()) {
handle.setDeltaMovement(handle.getDeltaMovement().x, handle.getDeltaMovement().y + power,
handle.getDeltaMovement().z);
}

View File

@ -1301,7 +1301,7 @@ public class NMSImpl implements NMSBridge {
Entity handle = NMSImpl.getHandle(entity);
if (handle == null)
return;
if (RANDOM.nextFloat() < 0.8F && (handle.W() || handle.ab())) {
if (RANDOM.nextFloat() <= 0.85F && (handle.W() || handle.ab())) {
handle.motY += power;
}
}