Skip to content

Commit

Permalink
And make #297 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Aug 7, 2024
1 parent 26e31ff commit af01380
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 12 deletions.
27 changes: 21 additions & 6 deletions patches/server/0006-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,10 @@ index 0000000000000000000000000000000000000000..2f0e6671dd8bfe4f320eab92c5f5bbc1
+}
diff --git a/src/main/java/org/leavesmc/leaves/command/CommandArgumentResult.java b/src/main/java/org/leavesmc/leaves/command/CommandArgumentResult.java
new file mode 100644
index 0000000000000000000000000000000000000000..6549037cf0bb8460fef8bef41d2335be079b9e9b
index 0000000000000000000000000000000000000000..3f0707940f22736f703c24f4da25c18fa6e5b309
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/command/CommandArgumentResult.java
@@ -0,0 +1,61 @@
@@ -0,0 +1,65 @@
+package org.leavesmc.leaves.command;
+
+import net.minecraft.core.BlockPos;
Expand All @@ -1105,14 +1105,18 @@ index 0000000000000000000000000000000000000000..6549037cf0bb8460fef8bef41d2335be
+ this.result = result;
+ }
+
+ public Integer readInt(int def) {
+ public int readInt(int def) {
+ return Objects.requireNonNullElse(read(Integer.class), def);
+ }
+
+ public Double readDouble(double def) {
+ public double readDouble(double def) {
+ return Objects.requireNonNullElse(read(Double.class), def);
+ }
+
+ public float readFloat(float def) {
+ return Objects.requireNonNullElse(read(Float.class), def);
+ }
+
+ public String readString(String def) {
+ return Objects.requireNonNullElse(read(String.class), def);
+ }
Expand Down Expand Up @@ -1152,10 +1156,10 @@ index 0000000000000000000000000000000000000000..6549037cf0bb8460fef8bef41d2335be
+}
diff --git a/src/main/java/org/leavesmc/leaves/command/CommandArgumentType.java b/src/main/java/org/leavesmc/leaves/command/CommandArgumentType.java
new file mode 100644
index 0000000000000000000000000000000000000000..dccd32714b86d1fa3e0a9b10a23f765fc54a2c66
index 0000000000000000000000000000000000000000..0d6d33e66461dda39c8f0e8395bf3f047ef88cbd
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/command/CommandArgumentType.java
@@ -0,0 +1,37 @@
@@ -0,0 +1,48 @@
+package org.leavesmc.leaves.command;
+
+import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -1184,6 +1188,17 @@ index 0000000000000000000000000000000000000000..dccd32714b86d1fa3e0a9b10a23f765f
+ }
+ };
+
+ public static final CommandArgumentType<Float> FLOAT = new CommandArgumentType<>() {
+ @Override
+ public Float pasre(@NotNull String arg) {
+ try {
+ return Float.parseFloat(arg);
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+ };
+
+ public static final CommandArgumentType<String> STRING = new CommandArgumentType<>() {
+ @Override
+ public String pasre(@NotNull String arg) {
Expand Down
66 changes: 60 additions & 6 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1555,10 +1555,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..2ab3ca511b62ef89a655b59481089ba2a9bac762
index 0000000000000000000000000000000000000000..f05e769328ee4b32c0cb21da65f8502d7167353b
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,754 @@
@@ -0,0 +1,757 @@
+package org.leavesmc.leaves.bot;
+
+import com.google.common.collect.Lists;
Expand Down Expand Up @@ -1736,7 +1736,6 @@ index 0000000000000000000000000000000000000000..2ab3ca511b62ef89a655b59481089ba2
+
+ bot.teleportTo(location.getX(), location.getY(), location.getZ());
+ bot.setRot(location.getYaw(), location.getPitch());
+ bot.getBukkitEntity().setRotation(location.getYaw(), location.getPitch());
+ world.addFreshEntity(bot, CreatureSpawnEvent.SpawnReason.COMMAND);
+
+ bot.renderAll();
Expand Down Expand Up @@ -2084,7 +2083,11 @@ index 0000000000000000000000000000000000000000..2ab3ca511b62ef89a655b59481089ba2
+ sendPacket(new ClientboundRotateHeadPacket(this, (byte) (yaw * 256 / 360f)));
+ }
+
+ setRot(yaw, pitch);
+ this.setRot(yaw, pitch);
+ }
+
+ @Override
+ public void setRot(float yaw, float pitch) {
+ this.getBukkitEntity().setRotation(yaw, pitch);
+ }
+
Expand Down Expand Up @@ -2460,10 +2463,10 @@ index 0000000000000000000000000000000000000000..d626ac47af400d01993c358fa5a93671
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/Actions.java b/src/main/java/org/leavesmc/leaves/bot/agent/Actions.java
new file mode 100644
index 0000000000000000000000000000000000000000..5555d5fc7bc169cd08f6760b296a83d9d9853118
index 0000000000000000000000000000000000000000..15cbf363f587a27d55f4bc7ec897787158a7d534
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/Actions.java
@@ -0,0 +1,65 @@
@@ -0,0 +1,66 @@
+package org.leavesmc.leaves.bot.agent;
+
+import org.jetbrains.annotations.Contract;
Expand Down Expand Up @@ -2496,6 +2499,7 @@ index 0000000000000000000000000000000000000000..5555d5fc7bc169cd08f6760b296a83d9
+ register(new UseItemOffHandAction());
+ register(new UseItemOnOffhandAction());
+ register(new UseItemToOffhandAction());
+ register(new RotationAction());
+ }
+
+ public static boolean register(@NotNull BotAction action) {
Expand Down Expand Up @@ -3078,6 +3082,56 @@ index 0000000000000000000000000000000000000000..fe872cad0cbf9ede825e0561cdb4ecb2
+ return true;
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/RotationAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/RotationAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..6983bf8555058cb715328f761df80d0b89c0b8f0
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/RotationAction.java
@@ -0,0 +1,44 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.server.level.ServerPlayer;
+import org.jetbrains.annotations.NotNull;
+import org.leavesmc.leaves.bot.ServerBot;
+import org.leavesmc.leaves.bot.agent.BotAction;
+import org.leavesmc.leaves.command.CommandArgument;
+import org.leavesmc.leaves.command.CommandArgumentResult;
+import org.leavesmc.leaves.command.CommandArgumentType;
+
+import java.util.List;
+
+public class RotationAction extends BotAction {
+
+ public RotationAction() {
+ super("rotation", new CommandArgument(CommandArgumentType.FLOAT, CommandArgumentType.FLOAT));
+ setTabComplete(0, List.of("<yaw>"));
+ setTabComplete(1, List.of("<pitch>"));
+ }
+
+ @Override
+ public BotAction getNew(@NotNull ServerPlayer player, @NotNull CommandArgumentResult result) {
+ return new RotationAction().setYaw(result.readFloat(player.getYRot())).setPitch(result.readFloat(player.getXRot())).setTickDelay(0).setNumber(1);
+ }
+
+ private float yaw;
+ private float pitch;
+
+ public RotationAction setYaw(float yaw) {
+ this.yaw = yaw;
+ return this;
+ }
+
+ public RotationAction setPitch(float pitch) {
+ this.pitch = pitch;
+ return this;
+ }
+
+ @Override
+ public boolean doTick(@NotNull ServerBot bot) {
+ bot.setRot(yaw, pitch);
+ return true;
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/SneakAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/SneakAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..9b4406bc0b418abc6a253e047c504b4ad15f059a
Expand Down

0 comments on commit af01380

Please sign in to comment.