project rebrand
This commit is contained in:
@@ -2,11 +2,14 @@ package net.nuggetmc.ai.bot;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.server.v1_16_R3.Chunk;
|
||||
import net.minecraft.server.v1_16_R3.*;
|
||||
import net.nuggetmc.ai.PlayerAI;
|
||||
import net.nuggetmc.ai.TerminatorPlus;
|
||||
import net.nuggetmc.ai.bot.event.BotFallDamageEvent;
|
||||
import net.nuggetmc.ai.utils.BotUtils;
|
||||
import net.nuggetmc.ai.utils.MathUtils;
|
||||
import net.nuggetmc.ai.utils.MojangAPI;
|
||||
import net.nuggetmc.ai.utils.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.World;
|
||||
@@ -29,6 +32,8 @@ import java.util.UUID;
|
||||
|
||||
public class Bot extends EntityPlayer {
|
||||
|
||||
public boolean item; // eventually make this not garbage lol
|
||||
|
||||
public Vector velocity;
|
||||
private Vector oldVelocity;
|
||||
|
||||
@@ -55,13 +60,17 @@ public class Bot extends EntityPlayer {
|
||||
datawatcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 0xFF);
|
||||
}
|
||||
|
||||
public static Bot createBot(Location loc, String name) {
|
||||
return createBot(loc, name, MojangAPI.getSkin(name), true);
|
||||
}
|
||||
|
||||
public static Bot createBot(Location loc, String name, String[] skin, boolean removeOnDeath) {
|
||||
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
WorldServer nmsWorld = ((CraftWorld) Objects.requireNonNull(loc.getWorld())).getHandle();
|
||||
|
||||
UUID uuid = BotUtils.randomSteveUUID();
|
||||
|
||||
CustomGameProfile profile = new CustomGameProfile(uuid, name, skin);
|
||||
CustomGameProfile profile = new CustomGameProfile(uuid, StringUtils.trim16(name), skin);
|
||||
PlayerInteractManager interactManager = new PlayerInteractManager(nmsWorld);
|
||||
|
||||
Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager);
|
||||
@@ -74,7 +83,7 @@ public class Bot extends EntityPlayer {
|
||||
|
||||
bot.renderAll();
|
||||
|
||||
PlayerAI.getInstance().getManager().add(bot);
|
||||
TerminatorPlus.getInstance().getManager().add(bot);
|
||||
|
||||
return bot;
|
||||
}
|
||||
@@ -90,7 +99,7 @@ public class Bot extends EntityPlayer {
|
||||
connection.sendPacket(packets[2]);
|
||||
|
||||
if (login) {
|
||||
Bukkit.getScheduler().runTaskLater(PlayerAI.getInstance(), () -> connection.sendPacket(packets[3]), 10);
|
||||
Bukkit.getScheduler().runTaskLater(TerminatorPlus.getInstance(), () -> connection.sendPacket(packets[3]), 10);
|
||||
} else {
|
||||
connection.sendPacket(packets[3]);
|
||||
}
|
||||
@@ -140,6 +149,8 @@ public class Bot extends EntityPlayer {
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
loadChunks();
|
||||
|
||||
super.tick();
|
||||
|
||||
if (!isAlive()) return;
|
||||
@@ -162,7 +173,7 @@ public class Bot extends EntityPlayer {
|
||||
|
||||
float health = getHealth();
|
||||
float maxHealth = getMaxHealth();
|
||||
float regenAmount = 0.05f;
|
||||
float regenAmount = 0.025f;
|
||||
float amount;
|
||||
|
||||
if (health < maxHealth - regenAmount) {
|
||||
@@ -179,6 +190,20 @@ public class Bot extends EntityPlayer {
|
||||
oldVelocity = velocity.clone();
|
||||
}
|
||||
|
||||
private void loadChunks() {
|
||||
net.minecraft.server.v1_16_R3.World world = getWorld();
|
||||
|
||||
for (int i = chunkX - 1; i <= chunkX + 1; i++) {
|
||||
for (int j = chunkZ - 1; j <= chunkZ + 1; j++) {
|
||||
Chunk chunk = world.getChunkAt(i, j);
|
||||
|
||||
if (!chunk.loaded) {
|
||||
chunk.setLoaded(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fireDamageCheck() {
|
||||
if (!isAlive()) {
|
||||
return; // maybe also have packet reset thing
|
||||
@@ -231,7 +256,7 @@ public class Bot extends EntityPlayer {
|
||||
if (groundTicks != 0 && noFallTicks == 0 && !(oldVelocity.getY() >= -0.8) && !BotUtils.NO_FALL.contains(getLocation().getBlock().getType())) {
|
||||
BotFallDamageEvent event = new BotFallDamageEvent(this);
|
||||
|
||||
PlayerAI.getInstance().getManager().getAgent().onFallDamage(event);
|
||||
TerminatorPlus.getInstance().getManager().getAgent().onFallDamage(event);
|
||||
|
||||
if (!event.isCancelled()) {
|
||||
damageEntity(DamageSource.FALL, (float) Math.pow(3.6, -oldVelocity.getY()));
|
||||
@@ -301,7 +326,7 @@ public class Bot extends EntityPlayer {
|
||||
punch();
|
||||
|
||||
if (entity instanceof Damageable) {
|
||||
((Damageable) entity).damage(2, getBukkitEntity()); // fist damage is 0.25
|
||||
((Damageable) entity).damage(item ? 6 : 0.25, getBukkitEntity()); // fist damage is 0.25
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,7 +406,7 @@ public class Bot extends EntityPlayer {
|
||||
|
||||
private void dieCheck() {
|
||||
if (removeOnDeath) {
|
||||
PlayerAI plugin = PlayerAI.getInstance();
|
||||
TerminatorPlus plugin = TerminatorPlus.getInstance();
|
||||
plugin.getManager().remove(this);
|
||||
this.removeTab();
|
||||
Bukkit.getScheduler().runTaskLater(plugin, this::setDead, 30);
|
||||
@@ -512,7 +537,7 @@ public class Bot extends EntityPlayer {
|
||||
}
|
||||
|
||||
public void setItem(org.bukkit.inventory.ItemStack item) {
|
||||
if (item == null) item = new org.bukkit.inventory.ItemStack(Material.AIR);
|
||||
if (item == null) item = new org.bukkit.inventory.ItemStack(this.item ? Material.IRON_SWORD : Material.AIR);
|
||||
|
||||
getBukkitEntity().getInventory().setItemInMainHand(item);
|
||||
|
||||
|
||||
@@ -4,10 +4,7 @@ import net.minecraft.server.v1_16_R3.PlayerConnection;
|
||||
import net.nuggetmc.ai.bot.agent.Agent;
|
||||
import net.nuggetmc.ai.bot.agent.legacyagent.LegacyAgent;
|
||||
import net.nuggetmc.ai.utils.MojangAPI;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -26,6 +23,7 @@ public class BotManager implements Listener {
|
||||
private final Set<Bot> bots;
|
||||
private final NumberFormat numberFormat;
|
||||
|
||||
public boolean joinMessages = false;
|
||||
public boolean removeOnDeath = true;
|
||||
|
||||
public BotManager() {
|
||||
@@ -39,6 +37,10 @@ public class BotManager implements Listener {
|
||||
}
|
||||
|
||||
public void add(Bot bot) {
|
||||
if (joinMessages) {
|
||||
Bukkit.broadcastMessage(ChatColor.YELLOW + bot.getName() + " joined the game");
|
||||
}
|
||||
|
||||
bots.add(bot);
|
||||
}
|
||||
|
||||
@@ -64,9 +66,6 @@ public class BotManager implements Listener {
|
||||
World world = sender.getWorld();
|
||||
Location loc = sender.getLocation();
|
||||
|
||||
if (name.length() > 16) name = name.substring(0, 16);
|
||||
if (skinName != null && skinName.length() > 16) skinName = skinName.substring(0, 16);
|
||||
|
||||
sender.sendMessage("Creating " + (n == 1 ? "new bot" : ChatColor.RED + numberFormat.format(n) + ChatColor.RESET + " new bots")
|
||||
+ " with name " + ChatColor.GREEN + name
|
||||
+ (skinName == null ? "" : ChatColor.RESET + " and skin " + ChatColor.GREEN + skinName)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.nuggetmc.ai.bot.agent;
|
||||
|
||||
import net.nuggetmc.ai.PlayerAI;
|
||||
import net.nuggetmc.ai.bot.Bot;
|
||||
import net.nuggetmc.ai.TerminatorPlus;
|
||||
import net.nuggetmc.ai.bot.BotManager;
|
||||
import net.nuggetmc.ai.bot.event.BotFallDamageEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -14,7 +13,7 @@ import java.util.Set;
|
||||
|
||||
public abstract class Agent {
|
||||
|
||||
protected final PlayerAI plugin;
|
||||
protected final TerminatorPlus plugin;
|
||||
protected final BotManager manager;
|
||||
protected final BukkitScheduler scheduler;
|
||||
protected final Set<BukkitRunnable> taskList;
|
||||
@@ -24,7 +23,7 @@ public abstract class Agent {
|
||||
protected int taskID;
|
||||
|
||||
public Agent(BotManager manager) {
|
||||
this.plugin = PlayerAI.getInstance();
|
||||
this.plugin = TerminatorPlus.getInstance();
|
||||
this.manager = manager;
|
||||
this.scheduler = Bukkit.getScheduler();
|
||||
this.taskList = new HashSet<>();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.nuggetmc.ai.bot.agent.legacyagent;
|
||||
|
||||
public enum EnumTargetGoal {
|
||||
CLOSEST_REAL_VULNERABLE_PLAYER,
|
||||
CLOSEST_REAL_PLAYER,
|
||||
CLOSEST_BOT_DIFFER,
|
||||
CLOSEST_BOT,
|
||||
NEAREST_REAL_VULNERABLE_PLAYER,
|
||||
NEAREST_REAL_PLAYER,
|
||||
NEAREST_BOT_DIFFER,
|
||||
NEAREST_BOT,
|
||||
NONE;
|
||||
|
||||
public static EnumTargetGoal of(int n) {
|
||||
@@ -13,16 +13,16 @@ public enum EnumTargetGoal {
|
||||
return NONE;
|
||||
|
||||
case 1:
|
||||
return CLOSEST_REAL_VULNERABLE_PLAYER;
|
||||
return NEAREST_REAL_VULNERABLE_PLAYER;
|
||||
|
||||
case 2:
|
||||
return CLOSEST_REAL_PLAYER;
|
||||
return NEAREST_REAL_PLAYER;
|
||||
|
||||
case 3:
|
||||
return CLOSEST_BOT_DIFFER;
|
||||
return NEAREST_BOT_DIFFER;
|
||||
|
||||
case 4:
|
||||
return CLOSEST_BOT;
|
||||
return NEAREST_BOT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,10 +26,12 @@ public class LegacyAgent extends Agent {
|
||||
|
||||
private final LegacyBlockCheck blockCheck;
|
||||
|
||||
private boolean useAIManipulators;
|
||||
|
||||
public LegacyAgent(BotManager manager) {
|
||||
super(manager);
|
||||
|
||||
this.goal = EnumTargetGoal.CLOSEST_REAL_VULNERABLE_PLAYER;
|
||||
this.goal = EnumTargetGoal.NEAREST_REAL_VULNERABLE_PLAYER;
|
||||
this.blockCheck = new LegacyBlockCheck(this);
|
||||
}
|
||||
|
||||
@@ -1038,16 +1040,16 @@ public class LegacyAgent extends Agent {
|
||||
|
||||
private Player nearestPlayer(Bot bot, Location loc) {
|
||||
switch (goal) {
|
||||
case CLOSEST_REAL_VULNERABLE_PLAYER:
|
||||
case NEAREST_REAL_VULNERABLE_PLAYER:
|
||||
return nearestRealVulnerablePlayer(loc);
|
||||
|
||||
case CLOSEST_REAL_PLAYER:
|
||||
case NEAREST_REAL_PLAYER:
|
||||
return nearestRealPlayer(loc);
|
||||
|
||||
case CLOSEST_BOT_DIFFER:
|
||||
case NEAREST_BOT_DIFFER:
|
||||
return nearestBotDiffer(bot, loc);
|
||||
|
||||
case CLOSEST_BOT:
|
||||
case NEAREST_BOT:
|
||||
return nearestBot(bot, loc);
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.nuggetmc.ai.bot.agent.legacyagent;
|
||||
|
||||
import net.nuggetmc.ai.PlayerAI;
|
||||
import net.nuggetmc.ai.TerminatorPlus;
|
||||
import net.nuggetmc.ai.bot.Bot;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -14,11 +14,11 @@ import java.util.Set;
|
||||
|
||||
public class LegacyBlockCheck {
|
||||
|
||||
private final PlayerAI plugin;
|
||||
private final TerminatorPlus plugin;
|
||||
private final LegacyAgent agent;
|
||||
|
||||
public LegacyBlockCheck(LegacyAgent agent) {
|
||||
this.plugin = PlayerAI.getInstance();
|
||||
this.plugin = TerminatorPlus.getInstance();
|
||||
this.agent = agent;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.nuggetmc.ai.bot.agent.legacyagent.ai;
|
||||
|
||||
import net.nuggetmc.ai.bot.Bot;
|
||||
import net.nuggetmc.ai.utils.MathUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
// If this is laggy, try only instantiating this once and update it instead of creating a new instance every tick
|
||||
public class BotData {
|
||||
|
||||
private final float health;
|
||||
|
||||
private final double distXZ;
|
||||
private final double distY;
|
||||
|
||||
private final boolean enemyBlocking;
|
||||
|
||||
private BotData(Bot bot, Player target) {
|
||||
Location a = bot.getLocation();
|
||||
Location b = target.getLocation();
|
||||
|
||||
this.health = bot.getHealth();
|
||||
this.distXZ = Math.sqrt(MathUtils.square(a.getX() - b.getX()) + MathUtils.square(a.getZ() - b.getZ()));
|
||||
this.distY = b.getY() - a.getY();
|
||||
this.enemyBlocking = target.isBlocking();
|
||||
}
|
||||
|
||||
public static BotData generate(Bot bot, Player target) {
|
||||
return new BotData(bot, target);
|
||||
}
|
||||
|
||||
public float getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public double getDistXZ() {
|
||||
return distXZ;
|
||||
}
|
||||
|
||||
public double getDistY() {
|
||||
return distY;
|
||||
}
|
||||
|
||||
public boolean getEnemyBlocking() {
|
||||
return enemyBlocking;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.nuggetmc.ai.bot.agent.legacyagent.ai;
|
||||
|
||||
public class NeuralNetwork {
|
||||
|
||||
private final NodeConnections nodeL; // left strafe
|
||||
private final NodeConnections nodeR; // right strafe (if L and R are opposite, move forward)
|
||||
private final NodeConnections nodeB; // block
|
||||
private final NodeConnections nodeJ; // jump
|
||||
|
||||
public NeuralNetwork() {
|
||||
this.nodeL = new NodeConnections();
|
||||
this.nodeR = new NodeConnections();
|
||||
this.nodeB = new NodeConnections();
|
||||
this.nodeJ = new NodeConnections();
|
||||
}
|
||||
|
||||
public void feed(BotData data) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package net.nuggetmc.ai.bot.agent.legacyagent.ai;
|
||||
|
||||
public class NodeConnections {
|
||||
|
||||
private final double connectionX; // horizontal distance
|
||||
private final double connectionY; // vertical distance
|
||||
private final double connectionB; // enemy blocking
|
||||
private final double connectionH; // health
|
||||
|
||||
public NodeConnections() {
|
||||
this.connectionX = generate();
|
||||
this.connectionY = generate();
|
||||
this.connectionB = generate();
|
||||
this.connectionH = generate();
|
||||
}
|
||||
|
||||
public NodeConnections(double y, double b, double t, double h) {
|
||||
this.connectionX = t;
|
||||
this.connectionY = y;
|
||||
this.connectionB = b;
|
||||
this.connectionH = h;
|
||||
}
|
||||
|
||||
private double generate() {
|
||||
return Math.random() * 20 - 10;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return connectionX;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return connectionY;
|
||||
}
|
||||
|
||||
public double getB() {
|
||||
return connectionB;
|
||||
}
|
||||
|
||||
public double getH() {
|
||||
return connectionH;
|
||||
}
|
||||
|
||||
public boolean test(double y, double b, double t, double h) {
|
||||
return Math.tanh(y * connectionX + b * connectionY + t * connectionB + h * connectionH) >= 0.5;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user