9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2026-01-03 22:26:12 +00:00

Optimize fakeplayer and fix a memory leak

This commit is contained in:
violetc
2023-12-01 13:08:34 +08:00
parent 717898a4b1
commit e8203ab40d

View File

@@ -1221,10 +1221,10 @@ index 0000000000000000000000000000000000000000..daaece30b2a3983f1cc9ee9a851e8f37
+}
diff --git a/src/main/java/top/leavesmc/leaves/bot/ServerBot.java b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..e362d4e67258901a8e9b1dacdbb4f95835141fc0
index 0000000000000000000000000000000000000000..02ef39695d921f804c2a89ae5cf7959c0c0e2903
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,714 @@
@@ -0,0 +1,722 @@
+package top.leavesmc.leaves.bot;
+
+import com.google.common.collect.Lists;
@@ -1366,10 +1366,18 @@ index 0000000000000000000000000000000000000000..e362d4e67258901a8e9b1dacdbb4f958
+
+ ServerBot bot = new ServerBot(server, world, profile);
+
+ bot.connection = new ServerGamePacketListenerImpl(server, new Connection(PacketFlow.SERVERBOUND) {
+ bot.connection = new ServerGamePacketListenerImpl(server, new Connection(PacketFlow.SERVERBOUND) { // ?
+ @Override
+ public void send(@NotNull Packet<?> packet) {
+ }
+
+ @Override
+ public void send(@NotNull Packet<?> packet, @Nullable PacketSendListener packetsendlistener) {
+ }
+
+ @Override
+ public void send(@NotNull Packet<?> packet, @Nullable PacketSendListener callbacks, boolean flush) {
+ }
+ }, bot, CommonListenerCookie.createInitial(profile));
+ bot.isRealPlayer = true;
+ bot.createState = state;
@@ -1534,21 +1542,21 @@ index 0000000000000000000000000000000000000000..e362d4e67258901a8e9b1dacdbb4f958
+ this.updateLocation();
+ this.updatePlayerPose();
+
+ /* Disable now
+ float health = getHealth();
+ float maxHealth = getMaxHealth();
+ float regenAmount = LeavesConfig.fakeplayerRegenAmount;
+ float amount;
+ if (server.getTickCount() % 20 == 0) {
+ float health = getHealth();
+ float maxHealth = getMaxHealth();
+ float regenAmount = LeavesConfig.fakeplayerRegenAmount * 20;
+ float amount;
+
+ if (health < maxHealth - regenAmount) {
+ amount = health + regenAmount;
+ } else {
+ amount = maxHealth;
+ if (health < maxHealth - regenAmount) {
+ amount = health + regenAmount;
+ } else {
+ amount = maxHealth;
+ }
+
+ this.setHealth(amount);
+ }
+
+ this.setHealth(amount);
+ */
+
+ BlockPos blockposition = this.getOnPosLegacy();
+ BlockState iblockdata = this.level().getBlockState(blockposition);
+ Vec3 vec3d1 = this.collide(velocity);