fix more bugs

This commit is contained in:
Badbird-5907
2022-06-17 22:02:52 -04:00
parent 855d6ede79
commit e3533b9e92
8 changed files with 69 additions and 24 deletions

View File

@@ -31,9 +31,9 @@ public interface Terminator {
boolean isBotAlive(); //Has to be named like this because paper re-obfuscates it
float getHealth();
float getBotHealth();
float getMaxHealth();
float getBotMaxHealth();
void ignite();
@@ -45,11 +45,15 @@ public interface Terminator {
void block(int length, int cooldown);
boolean isInWater();
boolean isBotInWater();
boolean isOnGround();
boolean isBotOnGround();
void setXRot(float pitch);
void setBotPitch(float pitch);
default void setBotXRot(float pitch) {
setBotPitch(pitch);
}
void jump(Vector velocity);
@@ -77,6 +81,8 @@ public interface Terminator {
void removeVisually();
void removeBot();
int getKills();
void incrementKills();

View File

@@ -102,7 +102,7 @@ public class BotAgent extends Agent {
Vector vel = target.toVector().subtract(loc.toVector()).normalize();
if (bot.tickDelay(5)) bot.faceLocation(player.getLocation());
if (!bot.isOnGround()) return; // calling this a second time later on
if (!bot.isBotOnGround()) return; // calling this a second time later on
bot.stand(); // eventually create a memory system so packets do not have to be sent every tick
bot.setItem(null); // method to check item in main hand, bot.getItemInHand()

View File

@@ -144,7 +144,7 @@ public class LegacyAgent extends Agent {
if (btCheck.containsKey(botPlayer)) sameXZ = btCheck.get(botPlayer);
if (waterGround || bot.isOnGround() || onBoat(botPlayer)) {
if (waterGround || bot.isBotOnGround() || onBoat(botPlayer)) {
byte sideResult = 1;
if (towerList.containsKey(botPlayer)) {
@@ -192,7 +192,7 @@ public class LegacyAgent extends Agent {
Vector vel = target.toVector().subtract(position).normalize();
if (bot.tickDelay(5)) bot.faceLocation(livingTarget.getLocation());
if (!bot.isOnGround()) return; // calling this a second time later on
if (!bot.isBotOnGround()) return; // calling this a second time later on
bot.stand(); // eventually create a memory system so packets do not have to be sent every tick
bot.setItem(null); // method to check item in main hand, bot.getItemInHand()
@@ -572,7 +572,7 @@ public class LegacyAgent extends Agent {
}
}, 5);
if (npc.isOnGround()) {
if (npc.isBotOnGround()) {
if (target.getLocation().distance(playerNPC.getLocation()) < 16) {
if (noJump.contains(playerNPC)) {
@@ -593,7 +593,7 @@ public class LegacyAgent extends Agent {
return true;
}
} else {
if (npc.isOnGround()) {
if (npc.isBotOnGround()) {
Location locBlock = playerNPC.getLocation();
locBlock.setX(locBlock.getBlockX() + 0.5);
locBlock.setZ(locBlock.getBlockZ() + 0.5);
@@ -616,7 +616,7 @@ public class LegacyAgent extends Agent {
npc.look(BlockFace.UP);
preBreak(npc, playerNPC, block, LegacyLevel.ABOVE);
if (npc.isOnGround()) {
if (npc.isBotOnGround()) {
Location locBlock = playerNPC.getLocation();
locBlock.setX(locBlock.getBlockX() + 0.5);
locBlock.setZ(locBlock.getBlockZ() + 0.5);
@@ -682,7 +682,7 @@ public class LegacyAgent extends Agent {
npc.setVelocity(vector);
}
if (npc.isInWater()) {
if (npc.isBotInWater()) {
Location locBlock = player.getLocation();
locBlock.setX(locBlock.getBlockX() + 0.5);
locBlock.setZ(locBlock.getBlockZ() + 0.5);
@@ -737,7 +737,7 @@ public class LegacyAgent extends Agent {
bot.setItem(new ItemStack(item));
if (level == LegacyLevel.EAST_D || level == LegacyLevel.NORTH_D || level == LegacyLevel.SOUTH_D || level == LegacyLevel.WEST_D) {
bot.setXRot(69);
bot.setBotPitch(69);
scheduler.runTaskLater(plugin, () -> {
btCheck.put(player, true);

View File

@@ -20,7 +20,7 @@ public class BotData {
Location a = bot.getLocation();
Location b = target.getLocation();
float health = bot.getHealth();
float health = bot.getBotHealth();
values.put(BotDataType.CRITICAL_HEALTH, health >= 5 ? 0 : 5D - health);
values.put(BotDataType.DISTANCE_XZ, Math.sqrt(MathUtils.square(a.getX() - b.getX()) + MathUtils.square(a.getZ() - b.getZ())));

View File

@@ -326,7 +326,7 @@ public class IntelligenceAgent {
if (!bots.isEmpty()) {
print("Removing all cached bots...");
bots.values().forEach(Terminator::removeVisually);
bots.values().forEach(Terminator::removeBot);
bots.clear();
}

View File

@@ -255,6 +255,16 @@ public class Bot extends ServerPlayer implements Terminator {
return isAlive();
}
@Override
public float getBotHealth() {
return getHealth();
}
@Override
public float getBotMaxHealth() {
return getMaxHealth();
}
@Override
public void tick() {
loadChunks();
@@ -412,7 +422,6 @@ public class Bot extends ServerPlayer implements Terminator {
public void setShield(boolean enabled) {
this.shield = enabled;
System.out.println("set shield");
setItemOffhand(new org.bukkit.inventory.ItemStack(enabled ? Material.SHIELD : Material.AIR));
}
@@ -421,7 +430,7 @@ public class Bot extends ServerPlayer implements Terminator {
MathUtils.clean(velocity); // TODO lag????
if (isInWater()) {
if (isBotInWater()) {
y = Math.min(velocity.getY() + 0.1, 0.1);
addFriction(0.8);
velocity.setY(y);
@@ -440,7 +449,7 @@ public class Bot extends ServerPlayer implements Terminator {
}
@Override
public boolean isInWater() {
public boolean isBotInWater() {
Location loc = getLocation();
for (int i = 0; i <= 2; i++) {
@@ -531,7 +540,7 @@ public class Bot extends ServerPlayer implements Terminator {
}
@Override
public boolean isOnGround() {
public boolean isBotOnGround() {
return groundTicks != 0;
}
@@ -552,6 +561,16 @@ public class Bot extends ServerPlayer implements Terminator {
this.setDead();
}
@Override
public void removeBot() {
if (Bukkit.isPrimaryThread()) {
this.remove(RemovalReason.DISCARDED);
} else {
scheduler.runTask(plugin, () -> this.remove(RemovalReason.DISCARDED));
}
this.removeVisually();
}
private void removeTab() {
sendPacket(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, this));
}
@@ -667,7 +686,7 @@ public class Bot extends ServerPlayer implements Terminator {
private void kb(Location loc1, Location loc2) {
Vector vel = loc1.toVector().subtract(loc2.toVector()).setY(0).normalize().multiply(0.3);
if (isOnGround()) vel.multiply(0.8).setY(0.4);
if (isBotOnGround()) vel.multiply(0.8).setY(0.4);
velocity = vel;
}
@@ -687,6 +706,11 @@ public class Bot extends ServerPlayer implements Terminator {
return getBukkitEntity().getLocation();
}
@Override
public void setBotPitch(float pitch) {
super.setXRot(pitch);
}
@Override
public void faceLocation(Location loc) {
look(loc.toVector().subtract(getLocation().toVector()), false);
@@ -742,7 +766,6 @@ public class Bot extends ServerPlayer implements Terminator {
@Override
public void setItemOffhand(org.bukkit.inventory.ItemStack item) {
setItem(item, EquipmentSlot.OFFHAND);
System.out.println("set offhand");
}
@Override
@@ -754,15 +777,15 @@ public class Bot extends ServerPlayer implements Terminator {
public void setItem(org.bukkit.inventory.ItemStack item, EquipmentSlot slot) {
if (item == null) item = defaultItem;
System.out.println("set");
//System.out.println("set");
if (slot == EquipmentSlot.MAINHAND) {
getBukkitEntity().getInventory().setItemInMainHand(item);
} else if (slot == EquipmentSlot.OFFHAND) {
getBukkitEntity().getInventory().setItemInOffHand(item);
}
System.out.println("slot = " + slot);
System.out.println("item = " + item);
//System.out.println("slot = " + slot);
//System.out.println("item = " + item);
sendPacket(new ClientboundSetEquipmentPacket(getId(), new ArrayList<>(Collections.singletonList(
new Pair<>(slot, CraftItemStack.asNMSCopy(item))
))));

View File

@@ -63,6 +63,10 @@ public class AICommand extends CommandInstance implements AIManager {
desc = "Begin an AI training session."
)
public void reinforcement(Player sender, @Arg("population-size") int populationSize, @Arg("name") String name, @OptArg("skin") String skin) {
//FIXME: Sometimes, bots will become invisible, or just stop working if they're the last one alive, this has been partially fixed (invis part) see Terminator#removeBot, which removes the bot.
//This seems to fix it for the most part, but its still buggy, as the bot will sometimes still freeze
//see https://cdn.carbonhost.cloud/6201479d7b237373ab269385/screenshots/javaw_DluMN4m0FR.png
//Blocks are also not placeable where bots have died
if (agent != null) {
sender.sendMessage("A session is already active.");
return;

View File

@@ -1,5 +1,6 @@
package net.nuggetmc.tplus.utils;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.nuggetmc.tplus.TerminatorPlus;
import net.nuggetmc.tplus.api.Terminator;
import net.nuggetmc.tplus.api.agent.Agent;
@@ -178,6 +179,17 @@ public class Debugger {
}
}
public void renderBots() {
int rendered = 0;
for (Terminator fetch : TerminatorPlus.getInstance().getManager().fetch()) {
rendered++;
Bot bot = (Bot) fetch;
ServerGamePacketListenerImpl connection = bot.getBukkitEntity().getHandle().connection;
fetch.renderBot(connection, true);
}
print("Rendered " + rendered + " bots.");
}
public void lol(String name, String skinName) {
String[] skin = MojangAPI.getSkin(skinName);