Update to 1.18.1

This commit is contained in:
MCMDEV
2022-02-20 12:17:26 +01:00
parent fadcc88946
commit 093464aa4b
10 changed files with 214 additions and 171 deletions

38
pom.xml
View File

@@ -17,7 +17,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>8</source> <source>8</source>
<target>8</target> <target>8</target>
@@ -50,6 +50,39 @@
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version> <version>2.3.1</version>
</plugin> </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> </plugins>
<resources> <resources>
<resource> <resource>
@@ -77,7 +110,8 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version> <version>1.18.1-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -4,8 +4,27 @@ import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener; import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.server.v1_16_R3.Chunk; import net.minecraft.network.Connection;
import net.minecraft.server.v1_16_R3.*; 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;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.level.Level;
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.TerminatorPlus;
import net.nuggetmc.tplus.bot.agent.Agent; import net.nuggetmc.tplus.bot.agent.Agent;
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork; import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
@@ -19,14 +38,15 @@ import org.bukkit.World;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer; import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.entity.Damageable; import org.bukkit.entity.Damageable;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -35,7 +55,7 @@ import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class Bot extends EntityPlayer { public class Bot extends ServerPlayer {
private final TerminatorPlus plugin; private final TerminatorPlus plugin;
private final BukkitScheduler scheduler; private final BukkitScheduler scheduler;
@@ -76,8 +96,8 @@ public class Bot extends EntityPlayer {
private final Vector offset; private final Vector offset;
private Bot(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile profile, PlayerInteractManager manager) { private Bot(MinecraftServer minecraftServer, ServerLevel worldServer, GameProfile profile) {
super(minecraftServer, worldServer, profile, manager); super(minecraftServer, worldServer, profile);
this.plugin = TerminatorPlus.getInstance(); this.plugin = TerminatorPlus.getInstance();
this.scheduler = Bukkit.getScheduler(); this.scheduler = Bukkit.getScheduler();
@@ -90,7 +110,7 @@ public class Bot extends EntityPlayer {
this.removeOnDeath = true; this.removeOnDeath = true;
this.offset = MathUtils.circleOffset(3); this.offset = MathUtils.circleOffset(3);
datawatcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 0xFF); //this.entityData.set(new EntityDataAccessor<>(16, EntityDataSerializers.BYTE), (byte) 0xFF);
} }
public static Bot createBot(Location loc, String name) { public static Bot createBot(Location loc, String name) {
@@ -99,28 +119,28 @@ public class Bot extends EntityPlayer {
public static Bot createBot(Location loc, String name, String[] skin) { public static Bot createBot(Location loc, String name, String[] skin) {
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld) Objects.requireNonNull(loc.getWorld())).getHandle(); ServerLevel nmsWorld = ((CraftWorld) Objects.requireNonNull(loc.getWorld())).getHandle();
UUID uuid = BotUtils.randomSteveUUID(); UUID uuid = BotUtils.randomSteveUUID();
CustomGameProfile profile = new CustomGameProfile(uuid, ChatUtils.trim16(name), skin); CustomGameProfile profile = new CustomGameProfile(uuid, ChatUtils.trim16(name), skin);
PlayerInteractManager interactManager = new PlayerInteractManager(nmsWorld);
Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager); Bot bot = new Bot(nmsServer, nmsWorld, profile);
bot.playerConnection = new PlayerConnection(nmsServer, new NetworkManager(EnumProtocolDirection.CLIENTBOUND) { bot.connection = new ServerGamePacketListenerImpl(nmsServer, new Connection(PacketFlow.CLIENTBOUND) {
@Override @Override
public void sendPacket(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) { } public void send(Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
}
}, bot); }, bot);
bot.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); bot.setPos(loc.getX(), loc.getY(), loc.getZ());
bot.setRot(loc.getYaw(), loc.getPitch());
bot.getBukkitEntity().setNoDamageTicks(0); bot.getBukkitEntity().setNoDamageTicks(0);
Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().playerConnection.sendPacket( Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, bot))); new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, bot)));
nmsWorld.addFreshEntity(bot);
nmsWorld.addEntity(bot);
bot.renderAll(); bot.renderAll();
TerminatorPlus.getInstance().getManager().add(bot); TerminatorPlus.getInstance().getManager().add(bot);
@@ -130,50 +150,50 @@ public class Bot extends EntityPlayer {
private void renderAll() { private void renderAll() {
Packet<?>[] packets = getRenderPacketsNoInfo(); Packet<?>[] packets = getRenderPacketsNoInfo();
Bukkit.getOnlinePlayers().forEach(p -> renderNoInfo(((CraftPlayer) p).getHandle().playerConnection, packets, false)); Bukkit.getOnlinePlayers().forEach(p -> renderNoInfo(((CraftPlayer) p).getHandle().connection, packets, false));
} }
private void render(PlayerConnection connection, Packet<?>[] packets, boolean login) { private void render(ServerGamePacketListenerImpl connection, Packet<?>[] packets, boolean login) {
connection.sendPacket(packets[0]); connection.send(packets[0]);
connection.sendPacket(packets[1]); connection.send(packets[1]);
connection.sendPacket(packets[2]); connection.send(packets[2]);
if (login) { if (login) {
scheduler.runTaskLater(plugin, () -> connection.sendPacket(packets[3]), 10); scheduler.runTaskLater(plugin, () -> connection.send(packets[3]), 10);
} else { } else {
connection.sendPacket(packets[3]); connection.send(packets[3]);
} }
} }
private void renderNoInfo(PlayerConnection connection, Packet<?>[] packets, boolean login) { private void renderNoInfo(ServerGamePacketListenerImpl connection, Packet<?>[] packets, boolean login) {
connection.sendPacket(packets[0]); connection.send(packets[0]);
connection.sendPacket(packets[1]); connection.send(packets[1]);
if (login) { if (login) {
scheduler.runTaskLater(plugin, () -> connection.sendPacket(packets[2]), 10); scheduler.runTaskLater(plugin, () -> connection.send(packets[2]), 10);
} else { } else {
connection.sendPacket(packets[2]); connection.send(packets[2]);
} }
} }
public void render(PlayerConnection connection, boolean login) { public void render(ServerGamePacketListenerImpl connection, boolean login) {
render(connection, getRenderPackets(), login); render(connection, getRenderPackets(), login);
} }
private Packet<?>[] getRenderPackets() { private Packet<?>[] getRenderPackets() {
return new Packet[] { return new Packet[] {
new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, this), new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, this),
new PacketPlayOutNamedEntitySpawn(this), new ClientboundAddPlayerPacket(this),
new PacketPlayOutEntityMetadata(this.getId(), this.getDataWatcher(), true), new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true),
new PacketPlayOutEntityHeadRotation(this, (byte) ((this.yaw * 256f) / 360f)) new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f))
}; };
} }
private Packet<?>[] getRenderPacketsNoInfo() { private Packet<?>[] getRenderPacketsNoInfo() {
return new Packet[] { return new Packet[] {
new PacketPlayOutNamedEntitySpawn(this), new ClientboundAddPlayerPacket(this),
new PacketPlayOutEntityMetadata(this.getId(), this.getDataWatcher(), true), new ClientboundSetEntityDataPacket(this.getId(), this.entityData, true),
new PacketPlayOutEntityHeadRotation(this, (byte) ((this.yaw * 256f) / 360f)) new ClientboundRotateHeadPacket(this, (byte) ((this.yHeadRot * 256f) / 360f))
}; };
} }
@@ -211,7 +231,7 @@ public class Bot extends EntityPlayer {
} }
private void sendPacket(Packet<?> packet) { private void sendPacket(Packet<?> packet) {
Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet)); Bukkit.getOnlinePlayers().forEach(p -> ((CraftPlayer) p).getHandle().connection.send(packet));
} }
@Override @Override
@@ -225,7 +245,7 @@ public class Bot extends EntityPlayer {
aliveTicks++; aliveTicks++;
if (fireTicks > 0) --fireTicks; if (fireTicks > 0) --fireTicks;
if (noDamageTicks > 0) --noDamageTicks; if (invulnerableTime > 0) --invulnerableTime;
if (jumpTicks > 0) --jumpTicks; if (jumpTicks > 0) --jumpTicks;
if (noFallTicks > 0) --noFallTicks; if (noFallTicks > 0) --noFallTicks;
@@ -253,19 +273,19 @@ public class Bot extends EntityPlayer {
fireDamageCheck(); fireDamageCheck();
fallDamageCheck(); fallDamageCheck();
if(locY() < -64) { if(position().y < -64) {
an(); die(DamageSource.OUT_OF_WORLD);
} }
oldVelocity = velocity.clone(); oldVelocity = velocity.clone();
} }
private void loadChunks() { private void loadChunks() {
net.minecraft.server.v1_16_R3.World world = getWorld(); Level world = getLevel();
for (int i = chunkX - 1; i <= chunkX + 1; i++) { for (int i = chunkPosition().x - 1; i <= chunkPosition().x + 1; i++) {
for (int j = chunkZ - 1; j <= chunkZ + 1; j++) { for (int j = chunkPosition().z - 1; j <= chunkPosition().z + 1; j++) {
Chunk chunk = world.getChunkAt(i, j); LevelChunk chunk = world.getChunk(i, j);
if (!chunk.loaded) { if (!chunk.loaded) {
chunk.loaded = true; chunk.loaded = true;
@@ -293,13 +313,13 @@ public class Bot extends EntityPlayer {
ignite(); ignite();
} }
if (noDamageTicks == 0) { if (invulnerableTime == 0) {
if (lava) { if (lava) {
damageEntity(DamageSource.LAVA, 4); hurt(DamageSource.LAVA, 4);
noDamageTicks = 20;//this used to be 12 ticks but that would cause the bot to take damage too quickly invulnerableTime = 20;//this used to be 12 ticks but that would cause the bot to take damage too quickly
} else if (fireTicks > 1) { } else if (fireTicks > 1) {
damageEntity(DamageSource.FIRE, 1); hurt(DamageSource.IN_FIRE, 1);
noDamageTicks = 20; invulnerableTime = 20;
} }
} }
@@ -314,8 +334,8 @@ public class Bot extends EntityPlayer {
} }
public void setOnFirePackets(boolean onFire) { public void setOnFirePackets(boolean onFire) {
datawatcher.set(new DataWatcherObject<>(0, DataWatcherRegistry.a), onFire ? (byte) 1 : (byte) 0); //entityData.set(new EntityDataAccessor<>(0, EntityDataSerializers.BYTE), onFire ? (byte) 1 : (byte) 0);
sendPacket(new PacketPlayOutEntityMetadata(getId(), datawatcher, false)); //sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, false));
} }
public boolean isOnFire() { public boolean isOnFire() {
@@ -329,7 +349,7 @@ public class Bot extends EntityPlayer {
plugin.getManager().getAgent().onFallDamage(event); plugin.getManager().getAgent().onFallDamage(event);
if (!event.isCancelled()) { if (!event.isCancelled()) {
damageEntity(DamageSource.FALL, (float) Math.pow(3.6, -oldVelocity.getY())); hurt(DamageSource.FALL, (float) Math.pow(3.6, -oldVelocity.getY()));
} }
} }
} }
@@ -347,15 +367,15 @@ public class Bot extends EntityPlayer {
private void startBlocking() { private void startBlocking() {
this.blocking = true; this.blocking = true;
this.blockUse = true; this.blockUse = true;
c(EnumHand.OFF_HAND); startUsingItem(InteractionHand.OFF_HAND);
sendPacket(new PacketPlayOutEntityMetadata(getId(), datawatcher, true)); sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, true));
} }
private void stopBlocking(int cooldown) { private void stopBlocking(int cooldown) {
this.blocking = false; this.blocking = false;
clearActiveItem(); stopUsingItem();
scheduler.runTaskLater(plugin, () -> this.blockUse = false, cooldown); scheduler.runTaskLater(plugin, () -> this.blockUse = false, cooldown);
sendPacket(new PacketPlayOutEntityMetadata(getId(), datawatcher, true)); sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, true));
} }
public boolean isBlocking() { public boolean isBlocking() {
@@ -365,6 +385,7 @@ public class Bot extends EntityPlayer {
public void setShield(boolean enabled) { public void setShield(boolean enabled) {
this.shield = enabled; this.shield = enabled;
System.out.println("set shield");
setItemOffhand(new org.bukkit.inventory.ItemStack(enabled ? Material.SHIELD : Material.AIR)); setItemOffhand(new org.bukkit.inventory.ItemStack(enabled ? Material.SHIELD : Material.AIR));
} }
@@ -390,7 +411,7 @@ public class Bot extends EntityPlayer {
} }
} }
this.move(EnumMoveType.SELF, new Vec3D(velocity.getX(), y, velocity.getZ())); this.move(MoverType.SELF, new Vec3(velocity.getX(), y, velocity.getZ()));
} }
@Override @Override
@@ -442,7 +463,7 @@ public class Bot extends EntityPlayer {
} }
public void punch() { public void punch() {
swingHand(EnumHand.MAIN_HAND); swing(InteractionHand.MAIN_HAND);
} }
public boolean checkGround() { public boolean checkGround() {
@@ -453,7 +474,7 @@ public class Bot extends EntityPlayer {
} }
World world = getBukkitEntity().getWorld(); World world = getBukkitEntity().getWorld();
AxisAlignedBB box = getBoundingBox(); AABB box = getBoundingBox();
double[] xVals = new double[] { double[] xVals = new double[] {
box.minX, box.minX,
@@ -467,7 +488,7 @@ public class Bot extends EntityPlayer {
for (double x : xVals) { for (double x : xVals) {
for (double z : zVals) { for (double z : zVals) {
Location loc = new Location(world, x, locY() - 0.01, z); Location loc = new Location(world, x, position().y - 0.01, z);
Block block = world.getBlockAt(loc); Block block = world.getBlockAt(loc);
if (block.getType().isSolid() && BotUtils.solidAt(loc)) { if (block.getType().isSolid() && BotUtils.solidAt(loc)) {
@@ -500,7 +521,7 @@ public class Bot extends EntityPlayer {
} }
private void removeTab() { private void removeTab() {
sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, this)); sendPacket(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, this));
} }
public void setRemoveOnDeath(boolean enabled) { public void setRemoveOnDeath(boolean enabled) {
@@ -508,12 +529,12 @@ public class Bot extends EntityPlayer {
} }
private void setDead() { private void setDead() {
sendPacket(new PacketPlayOutEntityDestroy(getId())); sendPacket(new ClientboundRemoveEntitiesPacket(getId()));
this.dead = true; this.dead = true;
this.defaultContainer.b(this); this.inventoryMenu.removed(this);
if (this.activeContainer != null) { if (this.containerMenu != null) {
this.activeContainer.b(this); this.containerMenu.removed(this);
} }
} }
@@ -530,12 +551,6 @@ public class Bot extends EntityPlayer {
} }
} }
@Override
public void die() {
super.die();
this.dieCheck();
}
@Override @Override
public void die(DamageSource damageSource) { public void die(DamageSource damageSource) {
super.die(damageSource); super.die(damageSource);
@@ -543,13 +558,13 @@ public class Bot extends EntityPlayer {
} }
@Override @Override
public void collide(Entity entity) { public void push(Entity entity) {
if (!this.isSameVehicle(entity) && !entity.noclip && !this.noclip) { if (!this.isPassengerOfSameVehicle(entity) && !entity.noPhysics && !this.noPhysics) {
double d0 = entity.locX() - this.locX(); double d0 = entity.getX() - this.getZ();
double d1 = entity.locZ() - this.locZ(); double d1 = entity.getX() - this.getZ();
double d2 = MathHelper.a(d0, d1); double d2 = Mth.absMax(d0, d1);
if (d2 >= 0.009999999776482582D) { if (d2 >= 0.009999999776482582D) {
d2 = MathHelper.sqrt(d2); d2 = Math.sqrt(d2);
d0 /= d2; d0 /= d2;
d1 /= d2; d1 /= d2;
double d3 = 1.0D / d2; double d3 = 1.0D / d2;
@@ -561,32 +576,30 @@ public class Bot extends EntityPlayer {
d1 *= d3; d1 *= d3;
d0 *= 0.05000000074505806D; d0 *= 0.05000000074505806D;
d1 *= 0.05000000074505806D; d1 *= 0.05000000074505806D;
d0 *= 1.0F - this.I;
d1 *= 1.0F - this.I;
if (!this.isVehicle()) { if (!this.isVehicle()) {
velocity.add(new Vector(-d0 * 3, 0.0D, -d1 * 3)); velocity.add(new Vector(-d0, 0.0D, -d1));
} }
if (!entity.isVehicle()) { if (!entity.isVehicle()) {
entity.i(d0, 0.0D, d1); entity.push(d0, 0.0D, d1);
} }
} }
} }
} }
@Override @Override
public boolean damageEntity(DamageSource damagesource, float f) { public boolean hurt(DamageSource damagesource, float f) {
net.minecraft.server.v1_16_R3.Entity attacker = damagesource.getEntity(); Entity attacker = damagesource.getEntity();
float damage; float damage;
boolean playerInstance = attacker instanceof EntityPlayer; boolean playerInstance = attacker instanceof ServerPlayer;
Player killer; Player killer;
if (playerInstance) { if (playerInstance) {
killer = ((EntityPlayer) attacker).getBukkitEntity(); killer = ((ServerPlayer) attacker).getBukkitEntity();
BotDamageByPlayerEvent event = new BotDamageByPlayerEvent(this, killer, f); BotDamageByPlayerEvent event = new BotDamageByPlayerEvent(this, killer, f);
@@ -602,7 +615,7 @@ public class Bot extends EntityPlayer {
damage = f; damage = f;
} }
boolean damaged = super.damageEntity(damagesource, damage); boolean damaged = super.hurt(damagesource, damage);
if (!damaged && blocking) { if (!damaged && blocking) {
getBukkitEntity().getWorld().playSound(getLocation(), Sound.ITEM_SHIELD_BLOCK, 1, 1); getBukkitEntity().getWorld().playSound(getLocation(), Sound.ITEM_SHIELD_BLOCK, 1, 1);
@@ -651,17 +664,17 @@ public class Bot extends EntityPlayer {
float yaw, pitch; float yaw, pitch;
if (keepYaw) { if (keepYaw) {
yaw = this.yaw; yaw = this.getYRot();
pitch = MathUtils.fetchPitch(dir); pitch = MathUtils.fetchPitch(dir);
} else { } else {
float[] vals = MathUtils.fetchYawPitch(dir); float[] vals = MathUtils.fetchYawPitch(dir);
yaw = vals[0]; yaw = vals[0];
pitch = vals[1]; pitch = vals[1];
sendPacket(new PacketPlayOutEntityHeadRotation(getBukkitEntity().getHandle(), (byte) (yaw * 256 / 360f))); sendPacket(new ClientboundRotateHeadPacket(getBukkitEntity().getHandle(), (byte) (yaw * 256 / 360f)));
} }
setYawPitch(yaw, pitch); setRot(yaw, pitch);
} }
public void attemptBlockPlace(Location loc, Material type, boolean down) { public void attemptBlockPlace(Location loc, Material type, boolean down) {
@@ -684,35 +697,39 @@ public class Bot extends EntityPlayer {
} }
public void setItem(org.bukkit.inventory.ItemStack item) { public void setItem(org.bukkit.inventory.ItemStack item) {
setItem(item, EnumItemSlot.MAINHAND); setItem(item, EquipmentSlot.MAINHAND);
} }
public void setItemOffhand(org.bukkit.inventory.ItemStack item) { public void setItemOffhand(org.bukkit.inventory.ItemStack item) {
setItem(item, EnumItemSlot.OFFHAND); setItem(item, EquipmentSlot.OFFHAND);
System.out.println("set offhand");
} }
public void setItem(org.bukkit.inventory.ItemStack item, EnumItemSlot slot) { public void setItem(org.bukkit.inventory.ItemStack item, EquipmentSlot slot) {
if (item == null) item = defaultItem; if (item == null) item = defaultItem;
if (slot == EnumItemSlot.MAINHAND) { System.out.println("set");
if (slot == EquipmentSlot.MAINHAND) {
getBukkitEntity().getInventory().setItemInMainHand(item); getBukkitEntity().getInventory().setItemInMainHand(item);
} else if (slot == EnumItemSlot.OFFHAND) { } else if (slot == EquipmentSlot.OFFHAND) {
getBukkitEntity().getInventory().setItemInOffHand(item); getBukkitEntity().getInventory().setItemInOffHand(item);
} }
sendPacket(new PacketPlayOutEntityEquipment(getId(), new ArrayList<>(Collections.singletonList( 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))
)))); ))));
} }
public void swim() { public void swim() {
getBukkitEntity().setSwimming(true); getBukkitEntity().setSwimming(true);
registerPose(EntityPose.SWIMMING); registerPose(Pose.SWIMMING);
} }
public void sneak() { public void sneak() {
getBukkitEntity().setSneaking(true); getBukkitEntity().setSneaking(true);
registerPose(EntityPose.CROUCHING); registerPose(Pose.CROUCHING);
} }
public void stand() { public void stand() {
@@ -720,26 +737,27 @@ public class Bot extends EntityPlayer {
player.setSneaking(false); player.setSneaking(false);
player.setSwimming(false); player.setSwimming(false);
registerPose(EntityPose.STANDING); registerPose(Pose.STANDING);
} }
private void registerPose(EntityPose pose) { private void registerPose(Pose pose) {
datawatcher.set(DataWatcherRegistry.s.a(6), pose); //entityData.set(new EntityDataAccessor<>(6, EntityDataSerializers.POSE), pose);
sendPacket(new PacketPlayOutEntityMetadata(getId(), datawatcher, false)); //sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, false));
} }
@Override @Override
public void playerTick() { public void doTick() {
if (this.hurtTicks > 0) { if (this.hurtTime > 0) {
this.hurtTicks -= 1; this.hurtTime -= 1;
} }
entityBaseTick(); baseTick();
tickPotionEffects(); tickEffects();
this.aU = (int) this.aT; this.animStepO = (int) this.animStep;
this.aL = this.aK; this.yBodyRotO = this.yBodyRot;
this.lastYaw = this.yaw; this.yHeadRotO = this.yHeadRot;
this.lastPitch = this.pitch; this.yRotO = this.getYRot();
this.xRotO = this.getXRot();
} }
} }

View File

@@ -1,13 +1,13 @@
package net.nuggetmc.tplus.bot; package net.nuggetmc.tplus.bot;
import net.minecraft.server.v1_16_R3.PlayerConnection; import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.nuggetmc.tplus.bot.agent.Agent; import net.nuggetmc.tplus.bot.agent.Agent;
import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent; import net.nuggetmc.tplus.bot.agent.legacyagent.LegacyAgent;
import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork; import net.nuggetmc.tplus.bot.agent.legacyagent.ai.NeuralNetwork;
import net.nuggetmc.tplus.bot.event.BotDeathEvent; import net.nuggetmc.tplus.bot.event.BotDeathEvent;
import net.nuggetmc.tplus.utils.MojangAPI; import net.nuggetmc.tplus.utils.MojangAPI;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -41,7 +41,7 @@ public class BotManager implements Listener {
public void add(Bot bot) { public void add(Bot bot) {
if (joinMessages) { if (joinMessages) {
Bukkit.broadcastMessage(ChatColor.YELLOW + bot.getName() + " joined the game"); Bukkit.broadcastMessage(ChatColor.YELLOW + (bot.getName() + " joined the game"));
} }
bots.add(bot); bots.add(bot);
@@ -58,7 +58,7 @@ public class BotManager implements Listener {
} }
public List<String> fetchNames() { public List<String> fetchNames() {
return bots.stream().map(Bot::getName).collect(Collectors.toList()); return bots.stream().map(Bot::getName).map(component -> component.getString()).collect(Collectors.toList());
} }
public Agent getAgent() { public Agent getAgent() {
@@ -166,7 +166,7 @@ public class BotManager implements Listener {
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event) {
PlayerConnection connection = ((CraftPlayer) event.getPlayer()).getHandle().playerConnection; ServerGamePacketListenerImpl connection = ((CraftPlayer) event.getPlayer()).getHandle().connection;
bots.forEach(bot -> bot.render(connection, true)); bots.forEach(bot -> bot.render(connection, true));
} }

View File

@@ -1,7 +1,7 @@
package net.nuggetmc.tplus.bot.agent.legacyagent; package net.nuggetmc.tplus.bot.agent.legacyagent;
import net.minecraft.server.v1_16_R3.BlockPosition; import net.minecraft.core.BlockPos;
import net.minecraft.server.v1_16_R3.PacketPlayOutBlockBreakAnimation; import net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket;
import net.nuggetmc.tplus.bot.Bot; import net.nuggetmc.tplus.bot.Bot;
import net.nuggetmc.tplus.bot.BotManager; import net.nuggetmc.tplus.bot.BotManager;
import net.nuggetmc.tplus.bot.agent.Agent; import net.nuggetmc.tplus.bot.agent.Agent;
@@ -16,8 +16,7 @@ import net.nuggetmc.tplus.utils.PlayerUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Mob; import org.bukkit.entity.Mob;
@@ -753,7 +752,7 @@ public class LegacyAgent extends Agent {
bot.setItem(new ItemStack(item)); bot.setItem(new ItemStack(item));
if (level == LegacyLevel.EAST_D || level == LegacyLevel.NORTH_D || level == LegacyLevel.SOUTH_D || level == LegacyLevel.WEST_D) { if (level == LegacyLevel.EAST_D || level == LegacyLevel.NORTH_D || level == LegacyLevel.SOUTH_D || level == LegacyLevel.WEST_D) {
bot.pitch = 69; bot.setXRot(69);
scheduler.runTaskLater(plugin, () -> { scheduler.runTaskLater(plugin, () -> {
btCheck.put(player, true); btCheck.put(player, true);
@@ -836,9 +835,9 @@ public class LegacyAgent extends Agent {
if (player.isDead()) { if (player.isDead()) {
this.cancel(); this.cancel();
PacketPlayOutBlockBreakAnimation crack = new PacketPlayOutBlockBreakAnimation(crackList.get(block), new BlockPosition(block.getX(), block.getY(), block.getZ()), -1); ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1);
for (Player all : Bukkit.getOnlinePlayers()) { for (Player all : Bukkit.getOnlinePlayers()) {
((CraftPlayer) all).getHandle().playerConnection.sendPacket(crack); ((CraftPlayer) all).getHandle().connection.send(crack);
} }
crackList.remove(block); crackList.remove(block);
@@ -849,9 +848,9 @@ public class LegacyAgent extends Agent {
if (!block.equals(cur) || block.getType() != cur.getType()) { if (!block.equals(cur) || block.getType() != cur.getType()) {
this.cancel(); this.cancel();
PacketPlayOutBlockBreakAnimation crack = new PacketPlayOutBlockBreakAnimation(crackList.get(block), new BlockPosition(block.getX(), block.getY(), block.getZ()), -1); ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1);
for (Player all : Bukkit.getOnlinePlayers()) { for (Player all : Bukkit.getOnlinePlayers()) {
((CraftPlayer) all).getHandle().playerConnection.sendPacket(crack); ((CraftPlayer) all).getHandle().connection.send(crack);
} }
crackList.remove(block); crackList.remove(block);
@@ -864,9 +863,9 @@ public class LegacyAgent extends Agent {
if (i == 9) { if (i == 9) {
this.cancel(); this.cancel();
PacketPlayOutBlockBreakAnimation crack = new PacketPlayOutBlockBreakAnimation(crackList.get(block), new BlockPosition(block.getX(), block.getY(), block.getZ()), -1); ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), -1);
for (Player all : Bukkit.getOnlinePlayers()) { for (Player all : Bukkit.getOnlinePlayers()) {
((CraftPlayer) all).getHandle().playerConnection.sendPacket(crack); ((CraftPlayer) all).getHandle().connection.send(crack);
} }
if (sound != null) { if (sound != null) {
@@ -894,9 +893,9 @@ public class LegacyAgent extends Agent {
if (block.getType() == Material.BARRIER || block.getType() == Material.BEDROCK || block.getType() == Material.END_PORTAL_FRAME) return; if (block.getType() == Material.BARRIER || block.getType() == Material.BEDROCK || block.getType() == Material.END_PORTAL_FRAME) return;
PacketPlayOutBlockBreakAnimation crack = new PacketPlayOutBlockBreakAnimation(crackList.get(block), new BlockPosition(block.getX(), block.getY(), block.getZ()), i); ClientboundBlockDestructionPacket crack = new ClientboundBlockDestructionPacket(crackList.get(block), new BlockPos(block.getX(), block.getY(), block.getZ()), i);
for (Player all : Bukkit.getOnlinePlayers()) { for (Player all : Bukkit.getOnlinePlayers()) {
((CraftPlayer) all).getHandle().playerConnection.sendPacket(crack); ((CraftPlayer) all).getHandle().connection.send(crack);
} }
mining.put(this, (byte) (i + 1)); mining.put(this, (byte) (i + 1));
@@ -1191,7 +1190,7 @@ public class LegacyAgent extends Agent {
} }
case NEAREST_BOT_DIFFER: { case NEAREST_BOT_DIFFER: {
String name = bot.getName(); String name = bot.getName().getString();
for (Bot otherBot : manager.fetch()) { for (Bot otherBot : manager.fetch()) {
if (bot != otherBot) { if (bot != otherBot) {
@@ -1207,13 +1206,13 @@ public class LegacyAgent extends Agent {
} }
case NEAREST_BOT_DIFFER_ALPHA: { case NEAREST_BOT_DIFFER_ALPHA: {
String name = bot.getName().replaceAll("[^A-Za-z]+", ""); String name = bot.getName().getString().replaceAll("[^A-Za-z]+", "");
for (Bot otherBot : manager.fetch()) { for (Bot otherBot : manager.fetch()) {
if (bot != otherBot) { if (bot != otherBot) {
Player player = otherBot.getBukkitEntity(); Player player = otherBot.getBukkitEntity();
if (!name.equals(otherBot.getName().replaceAll("[^A-Za-z]+", "")) && validateCloserEntity(player, loc, result)) { if (!name.equals(otherBot.getName().getString().replaceAll("[^A-Za-z]+", "")) && validateCloserEntity(player, loc, result)) {
result = player; result = player;
} }
} }

View File

@@ -71,7 +71,7 @@ public class LegacyMats {
Material.LAVA, Material.LAVA,
Material.TALL_GRASS, Material.TALL_GRASS,
Material.SNOW, Material.SNOW,
Material.GRASS_PATH, Material.DIRT_PATH,
Material.CAVE_AIR, Material.CAVE_AIR,
Material.VINE, Material.VINE,
Material.FERN, Material.FERN,

View File

@@ -1,10 +1,13 @@
package net.nuggetmc.tplus.bot.agent.legacyagent; package net.nuggetmc.tplus.bot.agent.legacyagent;
import net.minecraft.server.v1_16_R3.*; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@@ -35,23 +38,12 @@ public class LegacyUtils {
} }
public static Sound breakBlockSound(Block block) { public static Sound breakBlockSound(Block block) {
try { Level nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
World nmsWorld = ((CraftWorld) block.getWorld()).getHandle(); BlockState blockState = nmsWorld.getBlockState(new BlockPos(block.getX(), block.getY(), block.getZ()));
net.minecraft.server.v1_16_R3.Block nmsBlock = nmsWorld.getType(new BlockPosition(block.getX(), block.getY(), block.getZ())).getBlock(); net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
SoundEffectType soundEffectType = nmsBlock.getStepSound(nmsBlock.getBlockData()); SoundType soundEffectType = nmsBlock.getSoundType(blockState);
Field breakSound = SoundEffectType.class.getDeclaredField("stepSound"); return Sound.valueOf( soundEffectType.getBreakSound().getLocation().getPath().replace(".", "_").toUpperCase());
breakSound.setAccessible(true);
SoundEffect nmsSound = (SoundEffect) breakSound.get(soundEffectType);
Field keyField = SoundEffect.class.getDeclaredField("b");
keyField.setAccessible(true);
MinecraftKey nmsString = (MinecraftKey) keyField.get(nmsSound);
return Sound.valueOf(nmsString.getKey().replace(".", "_").toUpperCase());
} catch (IllegalAccessException | NoSuchFieldException ex) {
return null;
}
} }
} }

View File

@@ -1,6 +1,6 @@
package net.nuggetmc.tplus.bot.agent.legacyagent.ai; package net.nuggetmc.tplus.bot.agent.legacyagent.ai;
import net.minecraft.server.v1_16_R3.EntityLiving; import net.minecraft.world.entity.LivingEntity;
import net.nuggetmc.tplus.TerminatorPlus; import net.nuggetmc.tplus.TerminatorPlus;
import net.nuggetmc.tplus.bot.Bot; import net.nuggetmc.tplus.bot.Bot;
import net.nuggetmc.tplus.bot.BotManager; import net.nuggetmc.tplus.bot.BotManager;
@@ -141,7 +141,7 @@ public class IntelligenceAgent {
} }
bots.forEach(bot -> { bots.forEach(bot -> {
String name = bot.getName(); String name = bot.getName().getString();
while (this.bots.containsKey(name)) { while (this.bots.containsKey(name)) {
name += "_"; name += "_";
@@ -245,7 +245,7 @@ public class IntelligenceAgent {
} }
private int aliveCount() { private int aliveCount() {
return (int) bots.values().stream().filter(EntityLiving::isAlive).count(); return (int) bots.values().stream().filter(LivingEntity::isAlive).count();
} }
private void close() { private void close() {

View File

@@ -12,7 +12,7 @@ import net.nuggetmc.tplus.utils.Debugger;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap; import org.bukkit.command.SimpleCommandMap;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer; import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
@@ -55,7 +55,7 @@ public class CommandHandler {
commandMap.put(command.getName(), command); commandMap.put(command.getName(), command);
bukkitCommandMap.register(fallback, command); bukkitCommandMap.register(fallback, command);
Method[] methods = command.getClass().getDeclaredMethods(); Method[] methods = command.getClass().getMethods();
for (Method method : methods) { for (Method method : methods) {
if (method.isAnnotationPresent(Command.class)) { if (method.isAnnotationPresent(Command.class)) {

View File

@@ -1,6 +1,6 @@
package net.nuggetmc.tplus.command.commands; package net.nuggetmc.tplus.command.commands;
import net.minecraft.server.v1_16_R3.EnumItemSlot; import net.minecraft.world.entity.EquipmentSlot;
import net.nuggetmc.tplus.TerminatorPlus; import net.nuggetmc.tplus.TerminatorPlus;
import net.nuggetmc.tplus.bot.Bot; import net.nuggetmc.tplus.bot.Bot;
import net.nuggetmc.tplus.bot.BotManager; import net.nuggetmc.tplus.bot.BotManager;
@@ -160,10 +160,10 @@ public class BotCommand extends CommandInstance {
bot.getBukkitEntity().updateInventory(); bot.getBukkitEntity().updateInventory();
// packet sending to ensure // packet sending to ensure
bot.setItem(armor[0], EnumItemSlot.FEET); bot.setItem(armor[0], EquipmentSlot.FEET);
bot.setItem(armor[1], EnumItemSlot.LEGS); bot.setItem(armor[1], EquipmentSlot.LEGS);
bot.setItem(armor[2], EnumItemSlot.CHEST); bot.setItem(armor[2], EquipmentSlot.CHEST);
bot.setItem(armor[3], EnumItemSlot.HEAD); bot.setItem(armor[3], EquipmentSlot.HEAD);
}); });
sender.sendMessage("Successfully set the armor tier to " + ChatColor.YELLOW + tier + ChatColor.RESET + " for all current bots."); sender.sendMessage("Successfully set the armor tier to " + ChatColor.YELLOW + tier + ChatColor.RESET + " for all current bots.");
@@ -207,7 +207,7 @@ public class BotCommand extends CommandInstance {
* neural network values (network name if loaded, otherwise RANDOM) * neural network values (network name if loaded, otherwise RANDOM)
*/ */
String botName = bot.getName(); String botName = bot.getName().getString();
String world = ChatColor.YELLOW + bot.getBukkitEntity().getWorld().getName(); String world = ChatColor.YELLOW + bot.getBukkitEntity().getWorld().getName();
Location loc = bot.getLocation(); Location loc = bot.getLocation();
String strLoc = ChatColor.YELLOW + formatter.format(loc.getBlockX()) + ", " + formatter.format(loc.getBlockY()) + ", " + formatter.format(loc.getBlockZ()); String strLoc = ChatColor.YELLOW + formatter.format(loc.getBlockX()) + ", " + formatter.format(loc.getBlockY()) + ", " + formatter.format(loc.getBlockZ());

View File

@@ -1,6 +1,6 @@
package net.nuggetmc.tplus.utils; package net.nuggetmc.tplus.utils;
import net.minecraft.server.v1_16_R3.EntityLiving; import net.minecraft.world.entity.LivingEntity;
import net.nuggetmc.tplus.TerminatorPlus; import net.nuggetmc.tplus.TerminatorPlus;
import net.nuggetmc.tplus.bot.Bot; import net.nuggetmc.tplus.bot.Bot;
import net.nuggetmc.tplus.bot.agent.Agent; import net.nuggetmc.tplus.bot.agent.Agent;
@@ -222,7 +222,7 @@ public class Debugger {
public void tpall() { public void tpall() {
Player player = (Player) sender; Player player = (Player) sender;
TerminatorPlus.getInstance().getManager().fetch().stream().filter(EntityLiving::isAlive).forEach(bot -> bot.getBukkitEntity().teleport(player)); TerminatorPlus.getInstance().getManager().fetch().stream().filter(LivingEntity::isAlive).forEach(bot -> bot.getBukkitEntity().teleport(player));
} }
public void viewsession() { public void viewsession() {
@@ -352,14 +352,14 @@ public class Debugger {
} }
public void tp() { public void tp() {
Bot bot = MathUtils.getRandomSetElement(TerminatorPlus.getInstance().getManager().fetch().stream().filter(EntityLiving::isAlive).collect(Collectors.toSet())); Bot bot = MathUtils.getRandomSetElement(TerminatorPlus.getInstance().getManager().fetch().stream().filter(LivingEntity::isAlive).collect(Collectors.toSet()));
if (bot == null) { if (bot == null) {
print("Failed to locate a bot."); print("Failed to locate a bot.");
return; return;
} }
print("Located bot", ChatColor.GREEN + bot.getName() + ChatColor.RESET + "."); print("Located bot", (ChatColor.GREEN.toString() + bot.getName() + ChatColor.RESET.toString() + "."));
if (sender instanceof Player) { if (sender instanceof Player) {
print("Teleporting..."); print("Teleporting...");