Skip to content

Commit

Permalink
Fix more
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jun 23, 2024
1 parent 68213e9 commit a442f0d
Show file tree
Hide file tree
Showing 13 changed files with 339 additions and 307 deletions.
20 changes: 17 additions & 3 deletions patches/server/0007-Leaves-Protocol-Core.patch
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ index 7655987d061bdb2839b30f926efb034046feaea3..7ae6b2bb868cc3d391bae87fa5e141cf
}
};
}
diff --git a/src/main/java/net/minecraft/resources/ResourceLocation.java b/src/main/java/net/minecraft/resources/ResourceLocation.java
index 1967c43ee3a12e63365cc40ee6565307e2fd73cf..6e376d0db5321d8e9b6e0b54617ffd171bf4ee73 100644
--- a/src/main/java/net/minecraft/resources/ResourceLocation.java
+++ b/src/main/java/net/minecraft/resources/ResourceLocation.java
@@ -36,7 +36,7 @@ public final class ResourceLocation implements Comparable<ResourceLocation> {
private final String namespace;
private final String path;

- private ResourceLocation(String namespace, String path) {
+ public ResourceLocation(String namespace, String path) { // Leaves - private -> public
assert isValidNamespace(namespace);

assert isValidPath(path);
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 1b8f7ff3b0ccef6ce3ac99eecf98622fb13f9269..307c5a0b4b7c68fe2c7d1cf77ff23c766335882d 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
Expand Down Expand Up @@ -163,13 +176,14 @@ index 0000000000000000000000000000000000000000..986d2a6641ff8017dddf3e5f2655adfc
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java b/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..3a33982b92bfb12ce1284fb9429672a698a7ce4b
index 0000000000000000000000000000000000000000..87fe53e19b66ece66dc0654fb79923418210aa4a
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/core/LeavesProtocolManager.java
@@ -0,0 +1,365 @@
@@ -0,0 +1,366 @@
+package org.leavesmc.leaves.protocol.core;
+
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.chat.Component;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import org.apache.commons.lang.ArrayUtils;
Expand Down Expand Up @@ -333,7 +347,7 @@ index 0000000000000000000000000000000000000000..3a33982b92bfb12ce1284fb9429672a6
+
+ public static void handlePayload(ServerPlayer player, LeavesCustomPayload<?> payload) {
+ if (payload instanceof ErrorPayload errorPayload) {
+ player.connection.disconnect("Payload " + Arrays.toString(errorPayload.packetID) + " from " + Arrays.toString(errorPayload.protocolID) + " error", PlayerKickEvent.Cause.INVALID_PAYLOAD);
+ player.connection.disconnect(Component.literal("Payload " + Arrays.toString(errorPayload.packetID) + " from " + Arrays.toString(errorPayload.protocolID) + " error"), PlayerKickEvent.Cause.INVALID_PAYLOAD);
+ return;
+ }
+
Expand Down
25 changes: 17 additions & 8 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1318,10 +1318,10 @@ index 0000000000000000000000000000000000000000..0db337866c71283464d026a4f230016b
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/ServerBot.java b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..bba57a2d72ab3051aacd4f4defa3e7377511c36b
index 0000000000000000000000000000000000000000..549fd54c35c8283200562d678fa4bba593878c62
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,716 @@
@@ -0,0 +1,725 @@
+package org.leavesmc.leaves.bot;
+
+import com.google.common.collect.Lists;
Expand All @@ -1337,14 +1337,14 @@ index 0000000000000000000000000000000000000000..bba57a2d72ab3051aacd4f4defa3e737
+import net.minecraft.network.PacketSendListener;
+import net.minecraft.network.protocol.Packet;
+import net.minecraft.network.protocol.PacketFlow;
+import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
+import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
+import net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket;
+import net.minecraft.network.protocol.game.ClientboundRotateHeadPacket;
+import net.minecraft.network.syncher.EntityDataAccessor;
+import net.minecraft.network.syncher.EntityDataSerializers;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ChunkMap;
+import net.minecraft.server.level.ClientInformation;
+import net.minecraft.server.level.ServerLevel;
+import net.minecraft.server.level.ServerPlayer;
Expand All @@ -1365,6 +1365,7 @@ index 0000000000000000000000000000000000000000..bba57a2d72ab3051aacd4f4defa3e737
+import net.minecraft.world.inventory.ChestMenu;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.gameevent.GameEvent;
+import net.minecraft.world.level.portal.DimensionTransition;
+import net.minecraft.world.level.storage.LevelResource;
+import net.minecraft.world.phys.AABB;
+import net.minecraft.world.phys.Vec3;
Expand All @@ -1377,7 +1378,9 @@ index 0000000000000000000000000000000000000000..bba57a2d72ab3051aacd4f4defa3e737
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.leavesmc.leaves.LeavesConfig;
+import org.leavesmc.leaves.LeavesLogger;
+import org.leavesmc.leaves.bot.agent.BotAction;
+import org.leavesmc.leaves.bot.agent.actions.StopAction;
+import org.leavesmc.leaves.entity.Bot;
Expand All @@ -1387,7 +1390,6 @@ index 0000000000000000000000000000000000000000..bba57a2d72ab3051aacd4f4defa3e737
+import org.leavesmc.leaves.event.bot.BotJoinEvent;
+import org.leavesmc.leaves.util.MathUtils;
+
+import javax.annotation.Nullable;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
Expand Down Expand Up @@ -1548,13 +1550,20 @@ index 0000000000000000000000000000000000000000..bba57a2d72ab3051aacd4f4defa3e737
+ }
+
+ public void sendFakeData(ServerPlayerConnection playerConnection, boolean login) {
+ playerConnection.send(new ClientboundAddEntityPacket(this));
+ ChunkMap.TrackedEntity entityTracker = ((ServerLevel) this.level()).getChunkSource().chunkMap.entityMap.get(this.getId());
+
+ if (entityTracker == null) {
+ LeavesLogger.LOGGER.warning("Fakeplayer cant get entity tracker for " + this.getId());
+ return;
+ }
+
+ playerConnection.send(this.getAddEntityPacket(entityTracker.serverEntity));
+ if (login) {
+ Bukkit.getScheduler().runTaskLater(CraftScheduler.MINECRAFT, () -> {
+ connection.send(new ClientboundRotateHeadPacket(this, (byte) ((getYRot() * 256f) / 360f)));
+ playerConnection.send(new ClientboundRotateHeadPacket(this, (byte) ((getYRot() * 256f) / 360f)));
+ }, 10);
+ } else {
+ connection.send(new ClientboundRotateHeadPacket(this, (byte) ((getYRot() * 256f) / 360f)));
+ playerConnection.send(new ClientboundRotateHeadPacket(this, (byte) ((getYRot() * 256f) / 360f)));
+ }
+ }
+
Expand Down Expand Up @@ -1597,7 +1606,7 @@ index 0000000000000000000000000000000000000000..bba57a2d72ab3051aacd4f4defa3e737
+
+ @Nullable
+ @Override
+ public Entity changeDimension(@NotNull ServerLevel destination) {
+ public Entity changeDimension(@NotNull DimensionTransition teleportTarget) {
+ return null; // disable dimension change
+ }
+
Expand Down
8 changes: 4 additions & 4 deletions patches/server/0039-Jade-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ index 055f4b87c01ee7ecf7d2a111b72cc5aa85d9fbe8..5d9030f4787a43c56ae9455180badd56
public Optional<SpawnData> nextSpawnData;
diff --git a/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..cd5dfd55b6554e47a336c7aa4cb24db3cb4919dd
index 0000000000000000000000000000000000000000..33741d707715619929e5412a786470c5372f5978
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/jade/JadeProtocol.java
@@ -0,0 +1,343 @@
Expand Down Expand Up @@ -160,7 +160,7 @@ index 0000000000000000000000000000000000000000..cd5dfd55b6554e47a336c7aa4cb24db3
+
+ @Contract("_ -> new")
+ public static @NotNull ResourceLocation mc_id(String path) {
+ return new ResourceLocation(path);
+ return ResourceLocation.withDefaultNamespace(path);
+ }
+
+ private static boolean isPrimaryKey(ResourceLocation key) {
Expand Down Expand Up @@ -824,7 +824,7 @@ index 0000000000000000000000000000000000000000..fd4112ed1911171b3c6b5840b7184b5f
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/jade/provider/block/CampfireProvider.java b/src/main/java/org/leavesmc/leaves/protocol/jade/provider/block/CampfireProvider.java
new file mode 100644
index 0000000000000000000000000000000000000000..d22013480b53017db71697af37c0b3daa19c7ac5
index 0000000000000000000000000000000000000000..a1a479987f2c0b6ff4cfd511cbcac1ea7b1c247b
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/jade/provider/block/CampfireProvider.java
@@ -0,0 +1,52 @@
Expand Down Expand Up @@ -864,7 +864,7 @@ index 0000000000000000000000000000000000000000..d22013480b53017db71697af37c0b3da
+ stack = stack.copy();
+
+ CustomData customData = stack.getOrDefault(DataComponents.CUSTOM_DATA, CustomData.EMPTY)
+ .update(COOKING_TIME_CODEC, campfire.cookingTime[i] - campfire.cookingProgress[i])
+ .update(NbtOps.INSTANCE, COOKING_TIME_CODEC, campfire.cookingTime[i] - campfire.cookingProgress[i])
+ .getOrThrow();
+ stack.set(DataComponents.CUSTOM_DATA, customData);
+
Expand Down
Loading

0 comments on commit a442f0d

Please sign in to comment.