Moved to gradle & started work on separating API and plugin
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package net.nuggetmc.tplus.api;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public interface Terminator {
|
||||
|
||||
String getBotName();
|
||||
|
||||
GameProfile getGameProfile();
|
||||
|
||||
NeuralNetwork getNeuralNetwork();
|
||||
|
||||
void setNeuralNetwork(NeuralNetwork neuralNetwork);
|
||||
|
||||
boolean hasNeuralNetwork();
|
||||
|
||||
Location getLocation();
|
||||
|
||||
float getHealth();
|
||||
|
||||
float getMaxHealth();
|
||||
|
||||
void ignite();
|
||||
|
||||
boolean isOnFire();
|
||||
|
||||
boolean isFalling();
|
||||
|
||||
boolean isBlocking();
|
||||
|
||||
void block(int length, int cooldown);
|
||||
|
||||
boolean isInWater();
|
||||
|
||||
void jump(Vector velocity);
|
||||
|
||||
void jump();
|
||||
|
||||
void walk(Vector velocity);
|
||||
|
||||
void look(BlockFace face);
|
||||
|
||||
void attack(Entity target);
|
||||
|
||||
void attemptBlockPlace(Location loc, Material type, boolean down);
|
||||
|
||||
void punch();
|
||||
|
||||
void swim();
|
||||
|
||||
void sneak();
|
||||
|
||||
void stand();
|
||||
|
||||
void addFriction(double factor);
|
||||
|
||||
void removeVisually();
|
||||
|
||||
int getKills();
|
||||
|
||||
void incrementKills();
|
||||
|
||||
void setItem(ItemStack item);
|
||||
|
||||
void setItem(ItemStack item, EquipmentSlot slot);
|
||||
|
||||
void setItemOffhand(ItemStack item);
|
||||
|
||||
void setDefaultItem(ItemStack item);
|
||||
|
||||
Vector getOffset();
|
||||
|
||||
Vector getVelocity();
|
||||
|
||||
void setVelocity(Vector velocity);
|
||||
|
||||
void addVelocity(Vector velocity);
|
||||
|
||||
int getAliveTicks();
|
||||
|
||||
boolean tickDelay(int ticks);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
||||
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||
|
||||
public enum ActivationType {
|
||||
TANH,
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
||||
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||
|
||||
import net.nuggetmc.tplus.bot.Bot;
|
||||
import net.nuggetmc.tplus.api.Terminator;
|
||||
import net.nuggetmc.tplus.utils.MathUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Location;
|
||||
@@ -14,7 +14,7 @@ public class BotData {
|
||||
|
||||
private final Map<BotDataType, Double> values;
|
||||
|
||||
private BotData(Bot bot, LivingEntity target) {
|
||||
private BotData(Terminator bot, LivingEntity target) {
|
||||
this.values = new HashMap<>();
|
||||
|
||||
Location a = bot.getLocation();
|
||||
@@ -25,10 +25,10 @@ public class BotData {
|
||||
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())));
|
||||
values.put(BotDataType.DISTANCE_Y, b.getY() - a.getY());
|
||||
values.put(BotDataType.ENEMY_BLOCKING, target instanceof Player && ((Player)target).isBlocking() ? 1D : 0);
|
||||
values.put(BotDataType.ENEMY_BLOCKING, target instanceof Player && ((Player) target).isBlocking() ? 1D : 0);
|
||||
}
|
||||
|
||||
public static BotData generate(Bot bot, LivingEntity target) {
|
||||
public static BotData generate(Terminator bot, LivingEntity target) {
|
||||
return new BotData(bot, target);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
||||
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||
|
||||
public enum BotDataType {
|
||||
CRITICAL_HEALTH("h"),
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
||||
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||
|
||||
public enum BotNode {
|
||||
BLOCK, // block (can't attack while blocking)
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
||||
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.nuggetmc.tplus.utils.MathUtils;
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
||||
package net.nuggetmc.tplus.api.agent.legacyagent.ai;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.nuggetmc.tplus.utils;
|
||||
|
||||
import net.nuggetmc.tplus.bot.Bot;
|
||||
import net.nuggetmc.tplus.api.Terminator;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@@ -22,9 +22,7 @@ public class MathUtils {
|
||||
|
||||
if (x == 0.0D && z == 0.0D) {
|
||||
out[1] = (float) (dir.getY() > 0.0D ? -90 : 90);
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
double theta = Math.atan2(-x, z);
|
||||
out[0] = (float) Math.toDegrees((theta + 6.283185307179586D) % 6.283185307179586D);
|
||||
|
||||
@@ -45,9 +43,7 @@ public class MathUtils {
|
||||
|
||||
if (x == 0.0D && z == 0.0D) {
|
||||
result = (float) (dir.getY() > 0.0D ? -90 : 90);
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
double x2 = NumberConversions.square(x);
|
||||
double z2 = NumberConversions.square(z);
|
||||
double xz = Math.sqrt(x2 + z2);
|
||||
@@ -92,8 +88,8 @@ public class MathUtils {
|
||||
return FORMATTER_2.format(n);
|
||||
}
|
||||
|
||||
public static List<Map.Entry<Bot, Integer>> sortByValue(HashMap<Bot, Integer> hm) {
|
||||
List<Map.Entry<Bot, Integer>> list = new LinkedList<>(hm.entrySet());
|
||||
public static List<Map.Entry<Terminator, Integer>> sortByValue(HashMap<Terminator, Integer> hm) {
|
||||
List<Map.Entry<Terminator, Integer>> list = new LinkedList<>(hm.entrySet());
|
||||
list.sort(Map.Entry.comparingByValue());
|
||||
Collections.reverse(list);
|
||||
return list;
|
||||
@@ -161,9 +157,9 @@ public class MathUtils {
|
||||
double dist = distribution(list, mid);
|
||||
double p = mutationSize * dist / Math.sqrt(list.size());
|
||||
|
||||
return new double[] {
|
||||
mid - p,
|
||||
mid + p
|
||||
return new double[]{
|
||||
mid - p,
|
||||
mid + p
|
||||
};
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -26,18 +24,17 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.nuggetmc.tplus.TerminatorPlus;
|
||||
import net.nuggetmc.tplus.api.Terminator;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent;
|
||||
import net.nuggetmc.tplus.bot.event.BotFallDamageEvent;
|
||||
import net.nuggetmc.tplus.bot.event.BotKilledByPlayerEvent;
|
||||
import net.nuggetmc.tplus.utils.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
@@ -46,7 +43,6 @@ import org.bukkit.entity.Damageable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@@ -55,47 +51,26 @@ import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Bot extends ServerPlayer {
|
||||
public class Bot extends ServerPlayer implements Terminator {
|
||||
|
||||
private final TerminatorPlus plugin;
|
||||
private final BukkitScheduler scheduler;
|
||||
private final Agent agent;
|
||||
|
||||
private NeuralNetwork network;
|
||||
|
||||
public NeuralNetwork getNeuralNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public void setNeuralNetwork(NeuralNetwork network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
public boolean hasNeuralNetwork() {
|
||||
return network != null;
|
||||
}
|
||||
|
||||
private final Vector offset;
|
||||
public ItemStack defaultItem;
|
||||
|
||||
private NeuralNetwork network;
|
||||
private boolean shield;
|
||||
private boolean blocking;
|
||||
private boolean blockUse;
|
||||
|
||||
private Vector velocity;
|
||||
private Vector oldVelocity;
|
||||
|
||||
private boolean removeOnDeath;
|
||||
|
||||
private int aliveTicks;
|
||||
private int kills;
|
||||
|
||||
private byte fireTicks;
|
||||
private byte groundTicks;
|
||||
private byte jumpTicks;
|
||||
private byte noFallTicks;
|
||||
|
||||
private final Vector offset;
|
||||
|
||||
private Bot(MinecraftServer minecraftServer, ServerLevel worldServer, GameProfile profile) {
|
||||
super(minecraftServer, worldServer, profile);
|
||||
|
||||
@@ -139,15 +114,35 @@ public class Bot extends ServerPlayer {
|
||||
bot.setRot(loc.getYaw(), loc.getPitch());
|
||||
bot.getBukkitEntity().setNoDamageTicks(0);
|
||||
Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(
|
||||
new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, bot)));
|
||||
new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, bot)));
|
||||
nmsWorld.addFreshEntity(bot);
|
||||
bot.renderAll();
|
||||
|
||||
|
||||
TerminatorPlus.getInstance().getManager().add(bot);
|
||||
|
||||
return bot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBotName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NeuralNetwork getNeuralNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNeuralNetwork(NeuralNetwork network) {
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNeuralNetwork() {
|
||||
return network != null;
|
||||
}
|
||||
|
||||
private void renderAll() {
|
||||
Packet<?>[] packets = getRenderPacketsNoInfo();
|
||||
Bukkit.getOnlinePlayers().forEach(p -> renderNoInfo(((CraftPlayer) p).getHandle().connection, packets, false));
|
||||
@@ -164,7 +159,7 @@ public class Bot extends ServerPlayer {
|
||||
connection.send(packets[3]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void renderNoInfo(ServerGamePacketListenerImpl connection, Packet<?>[] packets, boolean login) {
|
||||
connection.send(packets[0]);
|
||||
connection.send(packets[1]);
|
||||
@@ -181,38 +176,43 @@ public class Bot extends ServerPlayer {
|
||||
}
|
||||
|
||||
private Packet<?>[] getRenderPackets() {
|
||||
return new Packet[] {
|
||||
new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, this),
|
||||
new ClientboundAddPlayerPacket(this),
|
||||
new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true),
|
||||
new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f))
|
||||
};
|
||||
}
|
||||
|
||||
private Packet<?>[] getRenderPacketsNoInfo() {
|
||||
return new Packet[] {
|
||||
new ClientboundAddPlayerPacket(this),
|
||||
new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true),
|
||||
new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f))
|
||||
return new Packet[]{
|
||||
new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, this),
|
||||
new ClientboundAddPlayerPacket(this),
|
||||
new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true),
|
||||
new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f))
|
||||
};
|
||||
}
|
||||
|
||||
private Packet<?>[] getRenderPacketsNoInfo() {
|
||||
return new Packet[]{
|
||||
new ClientboundAddPlayerPacket(this),
|
||||
new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true),
|
||||
new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f))
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDefaultItem(ItemStack item) {
|
||||
this.defaultItem = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector getVelocity() {
|
||||
return velocity.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVelocity(Vector vector) {
|
||||
this.velocity = vector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVelocity(Vector vector) { // This can cause lag? (maybe i fixed it with the new static method)
|
||||
if (MathUtils.isNotFinite(vector)) {
|
||||
velocity = vector;
|
||||
@@ -222,10 +222,12 @@ public class Bot extends ServerPlayer {
|
||||
velocity.add(vector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAliveTicks() {
|
||||
return aliveTicks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tickDelay(int i) {
|
||||
return aliveTicks % i == 0;
|
||||
}
|
||||
@@ -272,8 +274,8 @@ public class Bot extends ServerPlayer {
|
||||
|
||||
fireDamageCheck();
|
||||
fallDamageCheck();
|
||||
|
||||
if(position().y < -64) {
|
||||
|
||||
if (position().y < -64) {
|
||||
die(DamageSource.OUT_OF_WORLD);
|
||||
}
|
||||
|
||||
@@ -328,6 +330,7 @@ public class Bot extends ServerPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignite() {
|
||||
if (fireTicks <= 1) setOnFirePackets(true);
|
||||
fireTicks = 100;
|
||||
@@ -338,6 +341,7 @@ public class Bot extends ServerPlayer {
|
||||
//sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnFire() {
|
||||
return fireTicks != 0;
|
||||
}
|
||||
@@ -354,10 +358,12 @@ public class Bot extends ServerPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFalling() {
|
||||
return velocity.getY() < -0.8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void block(int blockLength, int cooldown) {
|
||||
if (!shield || blockUse) return;
|
||||
startBlocking();
|
||||
@@ -378,6 +384,7 @@ public class Bot extends ServerPlayer {
|
||||
sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlocking() {
|
||||
return blocking;
|
||||
}
|
||||
@@ -398,9 +405,7 @@ public class Bot extends ServerPlayer {
|
||||
y = Math.min(velocity.getY() + 0.1, 0.1);
|
||||
addFriction(0.8);
|
||||
velocity.setY(y);
|
||||
}
|
||||
|
||||
else {
|
||||
} else {
|
||||
if (groundTicks != 0) {
|
||||
velocity.setY(0);
|
||||
addFriction(0.5);
|
||||
@@ -431,6 +436,7 @@ public class Bot extends ServerPlayer {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jump(Vector vel) {
|
||||
if (jumpTicks == 0 && groundTicks > 1) {
|
||||
jumpTicks = 4;
|
||||
@@ -438,10 +444,12 @@ public class Bot extends ServerPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jump() {
|
||||
jump(new Vector(0, 0.5, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void walk(Vector vel) {
|
||||
double max = 0.4;
|
||||
|
||||
@@ -451,6 +459,7 @@ public class Bot extends ServerPlayer {
|
||||
velocity = sum;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(org.bukkit.entity.Entity entity) {
|
||||
faceLocation(entity.getLocation());
|
||||
punch();
|
||||
@@ -462,6 +471,7 @@ public class Bot extends ServerPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void punch() {
|
||||
swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
@@ -476,14 +486,14 @@ public class Bot extends ServerPlayer {
|
||||
World world = getBukkitEntity().getWorld();
|
||||
AABB box = getBoundingBox();
|
||||
|
||||
double[] xVals = new double[] {
|
||||
box.minX,
|
||||
box.maxX
|
||||
double[] xVals = new double[]{
|
||||
box.minX,
|
||||
box.maxX
|
||||
};
|
||||
|
||||
double[] zVals = new double[] {
|
||||
box.minZ,
|
||||
box.maxZ
|
||||
double[] zVals = new double[]{
|
||||
box.minZ,
|
||||
box.maxZ
|
||||
};
|
||||
|
||||
for (double x : xVals) {
|
||||
@@ -505,6 +515,7 @@ public class Bot extends ServerPlayer {
|
||||
return groundTicks != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFriction(double factor) {
|
||||
double frictionMin = 0.01;
|
||||
|
||||
@@ -515,6 +526,7 @@ public class Bot extends ServerPlayer {
|
||||
velocity.setZ(Math.abs(z) < frictionMin ? 0 : z * factor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeVisually() {
|
||||
this.removeTab();
|
||||
this.setDead();
|
||||
@@ -640,14 +652,17 @@ public class Bot extends ServerPlayer {
|
||||
velocity = vel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getKills() {
|
||||
return kills;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementKills() {
|
||||
kills++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return getBukkitEntity().getLocation();
|
||||
}
|
||||
@@ -656,6 +671,7 @@ public class Bot extends ServerPlayer {
|
||||
look(loc.toVector().subtract(getLocation().toVector()), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void look(BlockFace face) {
|
||||
look(face.getDirection(), face == BlockFace.DOWN || face == BlockFace.UP);
|
||||
}
|
||||
@@ -677,6 +693,7 @@ public class Bot extends ServerPlayer {
|
||||
setRot(yaw, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attemptBlockPlace(Location loc, Material type, boolean down) {
|
||||
if (down) {
|
||||
look(BlockFace.DOWN);
|
||||
@@ -696,15 +713,23 @@ public class Bot extends ServerPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(org.bukkit.inventory.ItemStack item) {
|
||||
setItem(item, EquipmentSlot.MAINHAND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemOffhand(org.bukkit.inventory.ItemStack item) {
|
||||
setItem(item, EquipmentSlot.OFFHAND);
|
||||
System.out.println("set offhand");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(ItemStack item, org.bukkit.inventory.EquipmentSlot slot) {
|
||||
EquipmentSlot nmsSlot = CraftEquipmentSlot.getNMS(slot);
|
||||
setItem(item, nmsSlot);
|
||||
}
|
||||
|
||||
public void setItem(org.bukkit.inventory.ItemStack item, EquipmentSlot slot) {
|
||||
if (item == null) item = defaultItem;
|
||||
|
||||
@@ -718,20 +743,23 @@ public class Bot extends ServerPlayer {
|
||||
System.out.println("slot = " + slot);
|
||||
System.out.println("item = " + item);
|
||||
sendPacket(new ClientboundSetEquipmentPacket(getId(), new ArrayList<>(Collections.singletonList(
|
||||
new Pair<>(slot, CraftItemStack.asNMSCopy(item))
|
||||
new Pair<>(slot, CraftItemStack.asNMSCopy(item))
|
||||
))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swim() {
|
||||
getBukkitEntity().setSwimming(true);
|
||||
registerPose(Pose.SWIMMING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sneak() {
|
||||
getBukkitEntity().setSneaking(true);
|
||||
registerPose(Pose.CROUCHING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stand() {
|
||||
Player player = getBukkitEntity();
|
||||
player.setSneaking(false);
|
||||
@@ -3,15 +3,17 @@ package net.nuggetmc.tplus.bot;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.bot.event.BotDeathEvent;
|
||||
import net.nuggetmc.tplus.utils.MojangAPI;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -149,19 +151,31 @@ public class BotManager implements Listener {
|
||||
agent.stopAllTasks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a bot from a Player object
|
||||
* @param player
|
||||
* @deprecated Use {@link #getBot(UUID)} instead as this may no longer work
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public Bot getBot(Player player) { // potentially memory intensive
|
||||
Bot bot = null;
|
||||
|
||||
int id = player.getEntityId();
|
||||
return getBot(id);
|
||||
}
|
||||
|
||||
for (Bot b : bots) {
|
||||
if (id == b.getId()) {
|
||||
bot = b;
|
||||
break;
|
||||
public Bot getBot(UUID uuid) {
|
||||
Entity entity = Bukkit.getEntity(uuid);
|
||||
if (entity == null) return null;
|
||||
return getBot(entity.getEntityId());
|
||||
}
|
||||
|
||||
public Bot getBot(int entityId) {
|
||||
for (Bot bot : bots) {
|
||||
if (bot.getId() == entityId) {
|
||||
return bot;
|
||||
}
|
||||
}
|
||||
|
||||
return bot;
|
||||
return null;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -171,10 +185,9 @@ public class BotManager implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
Bot bot = getBot(player);
|
||||
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
LivingEntity bukkitEntity = event.getEntity();
|
||||
Bot bot = getBot(bukkitEntity.getEntityId());
|
||||
if (bot != null) {
|
||||
agent.onBotDeath(new BotDeathEvent(event, bot));
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
|
||||
import net.nuggetmc.tplus.bot.Bot;
|
||||
import net.nuggetmc.tplus.bot.BotManager;
|
||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.BotData;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.BotNode;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotData;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotNode;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.bot.event.BotDamageByPlayerEvent;
|
||||
import net.nuggetmc.tplus.bot.event.BotDeathEvent;
|
||||
import net.nuggetmc.tplus.bot.event.BotFallDamageEvent;
|
||||
@@ -1154,7 +1154,7 @@ public class LegacyAgent extends Agent {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case NEAREST_HOSTILE: {
|
||||
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
|
||||
if (entity instanceof Monster && validateCloserEntity(entity, loc, result)) {
|
||||
@@ -1164,7 +1164,7 @@ public class LegacyAgent extends Agent {
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case NEAREST_MOB: {
|
||||
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
|
||||
if (entity instanceof Mob && validateCloserEntity(entity, loc, result)) {
|
||||
@@ -10,8 +10,6 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class LegacyUtils {
|
||||
|
||||
public static boolean checkFreeSpace(Location a, Location b) {
|
||||
@@ -2,6 +2,10 @@ package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
|
||||
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.nuggetmc.tplus.TerminatorPlus;
|
||||
import net.nuggetmc.tplus.api.Terminator;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotDataType;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.BotNode;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.bot.Bot;
|
||||
import net.nuggetmc.tplus.bot.BotManager;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.EnumTargetGoal;
|
||||
@@ -166,22 +170,22 @@ public class IntelligenceAgent {
|
||||
|
||||
print("Generation " + ChatColor.RED + generation + ChatColor.RESET + " has ended.");
|
||||
|
||||
HashMap<Bot, Integer> values = new HashMap<>();
|
||||
HashMap<Terminator, Integer> values = new HashMap<>();
|
||||
|
||||
for (Bot bot : bots.values()) {
|
||||
for (Terminator bot : bots.values()) {
|
||||
values.put(bot, bot.getAliveTicks());
|
||||
}
|
||||
|
||||
List<Map.Entry<Bot, Integer>> sorted = MathUtils.sortByValue(values);
|
||||
Set<Bot> winners = new HashSet<>();
|
||||
List<Map.Entry<Terminator, Integer>> sorted = MathUtils.sortByValue(values);
|
||||
Set<Terminator> winners = new HashSet<>();
|
||||
|
||||
int i = 1;
|
||||
|
||||
for (Map.Entry<Bot, Integer> entry : sorted) {
|
||||
Bot bot = entry.getKey();
|
||||
for (Map.Entry<Terminator, Integer> entry : sorted) {
|
||||
Terminator bot = entry.getKey();
|
||||
boolean check = i <= cutoff;
|
||||
if (check) {
|
||||
print(ChatColor.GRAY + "[" + ChatColor.YELLOW + "#" + i + ChatColor.GRAY + "] " + ChatColor.GREEN + bot.getName()
|
||||
print(ChatColor.GRAY + "[" + ChatColor.YELLOW + "#" + i + ChatColor.GRAY + "] " + ChatColor.GREEN + bot.getBotName()
|
||||
+ ChatUtils.BULLET_FORMATTED + ChatColor.RED + bot.getKills() + " kills");
|
||||
winners.add(bot);
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package net.nuggetmc.tplus.bot.event;
|
||||
|
||||
import net.nuggetmc.tplus.bot.Bot;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
public class BotDeathEvent extends PlayerDeathEvent {
|
||||
public class BotDeathEvent extends EntityDeathEvent {
|
||||
|
||||
private final Bot bot;
|
||||
|
||||
public BotDeathEvent(PlayerDeathEvent event, Bot bot) {
|
||||
super(event.getEntity(), event.getDrops(), event.getDroppedExp(), event.getDeathMessage());
|
||||
public BotDeathEvent(EntityDeathEvent event, Bot bot) {
|
||||
super(event.getEntity(), event.getDrops(), event.getDroppedExp());
|
||||
this.bot = bot;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import net.nuggetmc.tplus.TerminatorPlus;
|
||||
import net.nuggetmc.tplus.bot.Bot;
|
||||
import net.nuggetmc.tplus.bot.BotManager;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.IntelligenceAgent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.command.CommandHandler;
|
||||
import net.nuggetmc.tplus.command.CommandInstance;
|
||||
import net.nuggetmc.tplus.command.annotation.Arg;
|
||||
@@ -6,7 +6,7 @@ import net.nuggetmc.tplus.bot.Bot;
|
||||
import net.nuggetmc.tplus.bot.agent.Agent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.IntelligenceAgent;
|
||||
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.api.agent.legacyagent.ai.NeuralNetwork;
|
||||
import net.nuggetmc.tplus.command.commands.AICommand;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
18
build.gradle.kts
Normal file
18
build.gradle.kts
Normal file
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
id("java")
|
||||
}
|
||||
|
||||
group = "net.tplus"
|
||||
version = "3.1-BETA"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
}
|
||||
|
||||
tasks.getByName<Test>("test") {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
118
pom.xml
118
pom.xml
@@ -1,118 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.nuggetmc</groupId>
|
||||
<artifactId>TerminatorPlus</artifactId>
|
||||
<version>3.1-BETA</version>
|
||||
<name>TerminatorPlus</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||
<shadedClassifierName>shaded</shadedClassifierName>
|
||||
<!--
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||
</transformers>
|
||||
-->
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>specialsource-maven-plugin</artifactId>
|
||||
<version>1.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>remap</goal>
|
||||
</goals>
|
||||
<id>remap-obf</id>
|
||||
<configuration>
|
||||
<srgIn>org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
|
||||
<reverse>true</reverse>
|
||||
<remappedDependencies>org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
|
||||
<remappedArtifactAttached>true</remappedArtifactAttached>
|
||||
<remappedClassifierName>remapped-obf</remappedClassifierName>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>remap</goal>
|
||||
</goals>
|
||||
<id>remap-spigot</id>
|
||||
<configuration>
|
||||
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
|
||||
<srgIn>org.spigotmc:minecraft-server:1.18.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
|
||||
<remappedDependencies>org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<!-- Spigot Repo -->
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<!-- Advanced Spigot Repo -->
|
||||
<repository>
|
||||
<id>dre-repo</id>
|
||||
<url>https://erethon.de/repo/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!--Spigot + Bukkit -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.18.1-R0.1-SNAPSHOT</version>
|
||||
<classifier>remapped-mojang</classifier>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
10
settings.gradle.kts
Normal file
10
settings.gradle.kts
Normal file
@@ -0,0 +1,10 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "TerminatorPlus"
|
||||
include("TerminatorPlus-Plugin")
|
||||
include("TerminatorPlus-API")
|
||||
Reference in New Issue
Block a user