Use new waterlogged methods

This commit is contained in:
fullwall 2021-06-25 17:01:18 +08:00
parent f5a56ba8f8
commit 9c8d26e73b
3 changed files with 13 additions and 9 deletions

View File

@ -5,6 +5,7 @@ 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;
@ -68,9 +69,10 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
@Override
public float getCost(BlockSource source, PathPoint point) {
Vector pos = point.getVector();
Material in = source.getMaterialAt(pos);
Material above = source.getMaterialAt(pos.setY(pos.getY() + 1));
return params.avoidWater() && MinecraftBlockExaminer.isLiquid(in, above) ? 1F : 0F;
return params.avoidWater() && (MinecraftBlockExaminer.isLiquid(above)
|| MinecraftBlockExaminer.isLiquidOrInLiquid(pos.toLocation(source.getWorld()).getBlock())) ? 1F
: 0F;
}
@Override
@ -135,7 +137,7 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
Location currLoc = npc.getEntity().getLocation(NPC_LOCATION);
Vector destVector = new Vector(vector.getX() + 0.5, vector.getY(), vector.getZ() + 0.5);
/* Proper door movement - gets stuck on corners at times
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData();
@ -168,8 +170,9 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
params.speed());
} else {
Vector dir = destVector.subtract(npc.getEntity().getLocation().toVector()).normalize().multiply(0.2);
Material in = npc.getEntity().getLocation().getBlock().getType();
if (distance > 0 && dY >= 1 && xzDistance <= 2.75 || (dY >= 0.2 && MinecraftBlockExaminer.isLiquid(in))) {
Block in = npc.getEntity().getLocation().getBlock();
if (distance > 0 && dY >= 1 && xzDistance <= 2.75
|| (dY >= 0.2 && MinecraftBlockExaminer.isLiquidOrInLiquid(in))) {
dir.add(new Vector(0, 0.75, 0));
}
Util.faceLocation(npc.getEntity(), destVector.toLocation(npc.getEntity().getWorld()));

View File

@ -1,7 +1,6 @@
package net.citizensnpcs.npc.ai;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
@ -113,8 +112,9 @@ public class StraightLineNavigationStrategy extends AbstractPathStrategy {
params.speed());
} else {
Vector dir = destVector.subtract(npc.getEntity().getLocation().toVector()).normalize().multiply(0.2);
Material in = npc.getEntity().getLocation().getBlock().getType();
if (distance > 0 && dY >= 1 && xzDistance <= 2.75 || (dY >= 0.2 && MinecraftBlockExaminer.isLiquid(in))) {
Block in = npc.getEntity().getLocation().getBlock();
if (distance > 0 && dY >= 1 && xzDistance <= 2.75
|| (dY >= 0.2 && MinecraftBlockExaminer.isLiquidOrInLiquid(in))) {
dir.add(new Vector(0, 0.75, 0));
}
Util.faceLocation(npc.getEntity(), destVector.toLocation(npc.getEntity().getWorld()));

View File

@ -105,7 +105,8 @@ public class Util {
int mode = 2;
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
if (npc.requiresNameHologram() || npc.data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("false")) {
if (npc.requiresNameHologram()
|| npc.data().<Object> get(NPC.NAMEPLATE_VISIBLE_METADATA, true).toString().equals("false")) {
NMS.setTeamNameTagVisible(team, false);
}
mode = 0;