Fixes + improve standingon

-Blocks standing on is now a list
-Fixed a stuck issue when clipping into walls
This commit is contained in:
ThisTestUser
2022-09-30 17:51:02 -04:00
parent de17a89235
commit a736e59262
5 changed files with 122 additions and 17 deletions

View File

@@ -12,6 +12,7 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.List;
import java.util.UUID;
public interface Terminator {
@@ -52,7 +53,7 @@ public interface Terminator {
boolean isBotOnGround();
Block getStandingOn();
List<Block> getStandingOn();
void setBotPitch(float pitch);

View File

@@ -11,6 +11,7 @@ import net.nuggetmc.tplus.api.event.BotDamageByPlayerEvent;
import net.nuggetmc.tplus.api.event.BotDeathEvent;
import net.nuggetmc.tplus.api.event.BotFallDamageEvent;
import net.nuggetmc.tplus.api.event.TerminatorLocateTargetEvent;
import net.nuggetmc.tplus.api.utils.BotUtils;
import net.nuggetmc.tplus.api.utils.MathUtils;
import net.nuggetmc.tplus.api.utils.PlayerUtils;
import org.bukkit.*;
@@ -444,6 +445,71 @@ public class LegacyAgent extends Agent {
BlockFace dir = player.getFacing();
LegacyLevel level = null;
Block get = null;
BoundingBox box = player.getBoundingBox();
double[] xVals = new double[]{
box.getMinX(),
box.getMaxX() - 0.01
};
double[] zVals = new double[]{
box.getMinZ(),
box.getMaxZ() - 0.01
};
List<Location> locStanding = new ArrayList<>();
for (double x : xVals) {
for (double z : zVals) {
Location loc = new Location(player.getWorld(), Math.floor(x), npc.getLocation().getBlockY(), Math.floor(z));
if (!locStanding.contains(loc))
locStanding.add(loc);
}
}
Collections.sort(locStanding, (a, b) ->
Double.compare(BotUtils.getHorizSqDist(a, player.getLocation()), BotUtils.getHorizSqDist(b, player.getLocation())));
//Break potential obstructing walls
for (Location loc : locStanding) {
boolean up = false;
get = loc.getBlock();
if (!LegacyMats.FENCE.contains(get.getType())) {
up = true;
get = loc.add(0, 1, 0).getBlock();
if (!LegacyMats.FENCE.contains(get.getType())) {
get = null;
}
}
if (get != null) {
int distanceX = get.getLocation().getBlockX() - player.getLocation().getBlockX();
int distanceZ = get.getLocation().getBlockZ() - player.getLocation().getBlockZ();
if (distanceX == 1 && distanceZ == 0) {
if (dir == BlockFace.NORTH || dir == BlockFace.SOUTH) {
npc.faceLocation(get.getLocation());
level = up ? LegacyLevel.EAST : LegacyLevel.EAST_D;
}
} else if (distanceX == -1 && distanceZ == 0) {
if (dir == BlockFace.NORTH || dir == BlockFace.SOUTH) {
npc.faceLocation(get.getLocation());
level = up ? LegacyLevel.WEST : LegacyLevel.WEST_D;
}
} else if (distanceX == 0 && distanceZ == 1) {
if (dir == BlockFace.EAST || dir == BlockFace.WEST) {
npc.faceLocation(get.getLocation());
level = up ? LegacyLevel.SOUTH : LegacyLevel.SOUTH_D;
}
} else if (distanceX == 0 && distanceZ == -1) {
if (dir == BlockFace.EAST || dir == BlockFace.WEST) {
npc.faceLocation(get.getLocation());
level = up ? LegacyLevel.NORTH : LegacyLevel.NORTH_D;
}
}
if (level != null) {
preBreak(npc, player, get, level);
return level;
}
}
}
switch (dir) {
case NORTH:
@@ -457,7 +523,7 @@ public class LegacyAgent extends Agent {
get = get.getLocation().add(0, -2, 0).getBlock();
level = LegacyLevel.NORTH_D_2;
} else {
Block standing = npc.getStandingOn();
Block standing = npc.getStandingOn().isEmpty() ? null : npc.getStandingOn().get(0);
if(standing == null)
break;
boolean obstructed = standing.getLocation().getBlockY() == player.getLocation().getBlockY()
@@ -500,7 +566,7 @@ public class LegacyAgent extends Agent {
get = get.getLocation().add(0, -2, 0).getBlock();
level = LegacyLevel.SOUTH_D_2;
} else {
Block standing = npc.getStandingOn();
Block standing = npc.getStandingOn().isEmpty() ? null : npc.getStandingOn().get(0);
if(standing == null)
break;
boolean obstructed = standing.getLocation().getBlockY() == player.getLocation().getBlockY()
@@ -543,7 +609,7 @@ public class LegacyAgent extends Agent {
get = get.getLocation().add(0, -2, 0).getBlock();
level = LegacyLevel.EAST_D_2;
} else {
Block standing = npc.getStandingOn();
Block standing = npc.getStandingOn().isEmpty() ? null : npc.getStandingOn().get(0);
if(standing == null)
break;
boolean obstructed = standing.getLocation().getBlockY() == player.getLocation().getBlockY()
@@ -586,7 +652,7 @@ public class LegacyAgent extends Agent {
get = get.getLocation().add(0, -2, 0).getBlock();
level = LegacyLevel.WEST_D_2;
} else {
Block standing = npc.getStandingOn();
Block standing = npc.getStandingOn().isEmpty() ? null : npc.getStandingOn().get(0);
if(standing == null)
break;
boolean obstructed = standing.getLocation().getBlockY() == player.getLocation().getBlockY()
@@ -782,7 +848,7 @@ public class LegacyAgent extends Agent {
return false;
if (c && npc.getLocation().getBlockY() > loc.getBlockY() + 1) {
Block block = npc.getStandingOn();
Block block = npc.getStandingOn().isEmpty() ? null : npc.getStandingOn().get(0);
if (block == null)
return false;
npc.look(BlockFace.DOWN);
@@ -798,7 +864,7 @@ public class LegacyAgent extends Agent {
b.setY(0);
if (npc.getLocation().getBlockY() > loc.getBlockY() + 10 && a.distance(b) < 10) {
Block block = npc.getStandingOn();
Block block = npc.getStandingOn().isEmpty() ? null : npc.getStandingOn().get(0);
if (block == null)
return false;
npc.look(BlockFace.DOWN);
@@ -938,7 +1004,7 @@ public class LegacyAgent extends Agent {
cur = player.getLocation().add(0, 2, 0).getBlock();
break;
case BELOW:
cur = bot.getStandingOn();
cur = bot.getStandingOn().isEmpty() ? null : bot.getStandingOn().get(0);
break;
case NORTH_U:
cur = player.getLocation().add(0, 2, -1).getBlock();

View File

@@ -1,20 +1,30 @@
package net.nuggetmc.tplus.api.event;
import java.util.List;
import org.bukkit.block.Block;
import net.nuggetmc.tplus.api.Terminator;
public class BotFallDamageEvent {
private final Terminator bot;
private final List<Block> standingOn;
private boolean cancelled;
public BotFallDamageEvent(Terminator bot) {
public BotFallDamageEvent(Terminator bot, List<Block> standingOn) {
this.bot = bot;
this.standingOn = standingOn;
}
public Terminator getBot() {
return bot;
}
public List<Block> getStandingOn() {
return standingOn;
}
public boolean isCancelled() {
return cancelled;

View File

@@ -1,7 +1,10 @@
package net.nuggetmc.tplus.api.utils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.NumberConversions;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -13,7 +16,9 @@ public class BotUtils {
Material.WATER,
Material.LAVA,
Material.TWISTING_VINES,
Material.VINE
Material.VINE,
Material.LADDER,
Material.COBWEB
));
public static UUID randomSteveUUID() {
@@ -29,4 +34,8 @@ public class BotUtils {
public static boolean solidAt(BoundingBox playerBox, BoundingBox blockBox) {
return playerBox.overlaps(blockBox);
}
public static double getHorizSqDist(Location blockLoc, Location pLoc) {
return NumberConversions.square(blockLoc.getX() + 0.5 - pLoc.getX()) + NumberConversions.square(blockLoc.getZ() + 0.5 - pLoc.getZ());
}
}