Skip to content

Commit

Permalink
Fix fakeplayer use action (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Sep 25, 2024
1 parent bff6bbd commit dd487df
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3958,10 +3958,10 @@ index 0000000000000000000000000000000000000000..b5ccedee17857bc955301512ee965d81
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..1bdde4f8dc5e379d45fac19ba11aa07c4a1b735c
index 0000000000000000000000000000000000000000..c511ed17e9d5df6d2b961c24ca6f8c157a2baf07
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemAction.java
@@ -0,0 +1,22 @@
@@ -0,0 +1,26 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.world.InteractionHand;
Expand All @@ -3979,17 +3979,21 @@ index 0000000000000000000000000000000000000000..1bdde4f8dc5e379d45fac19ba11aa07c
+ if (bot.isUsingItem()) {
+ return false;
+ }
+ bot.swing(InteractionHand.MAIN_HAND);
+ bot.updateItemInHand(InteractionHand.MAIN_HAND);
+ return bot.gameMode.useItem(bot, bot.level(), bot.getItemInHand(InteractionHand.MAIN_HAND), InteractionHand.MAIN_HAND).consumesAction();
+
+ boolean flag = bot.gameMode.useItem(bot, bot.level(), bot.getItemInHand(InteractionHand.MAIN_HAND), InteractionHand.MAIN_HAND).consumesAction();
+ if (flag) {
+ bot.swing(InteractionHand.MAIN_HAND);
+ bot.updateItemInHand(InteractionHand.MAIN_HAND);
+ }
+ return flag;
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOffHandAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOffHandAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..f6de022b7177da0eb7c089f11ce039ab22c34903
index 0000000000000000000000000000000000000000..26d7286fe9ca9885a02f4f13a8d648d59c7550cd
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOffHandAction.java
@@ -0,0 +1,22 @@
@@ -0,0 +1,26 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.world.InteractionHand;
Expand All @@ -4007,17 +4011,21 @@ index 0000000000000000000000000000000000000000..f6de022b7177da0eb7c089f11ce039ab
+ if (bot.isUsingItem()) {
+ return false;
+ }
+ bot.swing(InteractionHand.OFF_HAND);
+ bot.updateItemInHand(InteractionHand.OFF_HAND);
+ return bot.gameMode.useItem(bot, bot.level(), bot.getItemInHand(InteractionHand.OFF_HAND), InteractionHand.OFF_HAND).consumesAction();
+
+ boolean flag = bot.gameMode.useItem(bot, bot.level(), bot.getItemInHand(InteractionHand.OFF_HAND), InteractionHand.OFF_HAND).consumesAction();
+ if (flag) {
+ bot.swing(InteractionHand.OFF_HAND);
+ bot.updateItemInHand(InteractionHand.OFF_HAND);
+ }
+ return flag;
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..f73cd841009117e4032f953a3e754305d97a68be
index 0000000000000000000000000000000000000000..232d0abecb871d3e48c6833f839c921f405b7be7
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnAction.java
@@ -0,0 +1,42 @@
@@ -0,0 +1,45 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.world.InteractionHand;
Expand All @@ -4044,6 +4052,9 @@ index 0000000000000000000000000000000000000000..f73cd841009117e4032f953a3e754305
+ HitResult result = bot.getRayTrace(5, ClipContext.Fluid.NONE);
+ if (result instanceof BlockHitResult blockHitResult) {
+ BlockState state = bot.serverLevel().getBlockState(blockHitResult.getBlockPos());
+ if (state.isAir()) {
+ return false;
+ }
+ bot.swing(InteractionHand.MAIN_HAND);
+ if (state.getBlock() == Blocks.TRAPPED_CHEST) {
+ BlockEntity entity = bot.serverLevel().getBlockEntity(blockHitResult.getBlockPos());
Expand All @@ -4062,10 +4073,10 @@ index 0000000000000000000000000000000000000000..f73cd841009117e4032f953a3e754305
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnOffhandAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnOffhandAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..c0cd258151f690ccbf3df1ffd640b83d8f36aa7d
index 0000000000000000000000000000000000000000..3616802c37908372cb7e30c61d6d343bcd3c1cc8
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemOnOffhandAction.java
@@ -0,0 +1,42 @@
@@ -0,0 +1,45 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.world.InteractionHand;
Expand All @@ -4092,6 +4103,9 @@ index 0000000000000000000000000000000000000000..c0cd258151f690ccbf3df1ffd640b83d
+ HitResult result = bot.getRayTrace(5, ClipContext.Fluid.NONE);
+ if (result instanceof BlockHitResult blockHitResult) {
+ BlockState state = bot.serverLevel().getBlockState(blockHitResult.getBlockPos());
+ if (state.isAir()) {
+ return false;
+ }
+ bot.swing(InteractionHand.OFF_HAND);
+ if (state.getBlock() == Blocks.TRAPPED_CHEST) {
+ BlockEntity entity = bot.serverLevel().getBlockEntity(blockHitResult.getBlockPos());
Expand All @@ -4110,10 +4124,10 @@ index 0000000000000000000000000000000000000000..c0cd258151f690ccbf3df1ffd640b83d
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemToAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemToAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..2048024b754cce85d2bf4f2cbcb800a1f4727495
index 0000000000000000000000000000000000000000..05be3dd5ca71a7cd81cd150b9588c60e86b54b73
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemToAction.java
@@ -0,0 +1,24 @@
@@ -0,0 +1,27 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.world.InteractionHand;
Expand All @@ -4131,19 +4145,22 @@ index 0000000000000000000000000000000000000000..2048024b754cce85d2bf4f2cbcb800a1
+ public boolean doTick(@NotNull ServerBot bot) {
+ Entity entity = bot.getTargetEntity(3, null);
+ if (entity != null) {
+ bot.swing(InteractionHand.MAIN_HAND);
+ bot.updateItemInHand(InteractionHand.MAIN_HAND);
+ return bot.interactOn(entity, InteractionHand.MAIN_HAND).consumesAction();
+ boolean flag = bot.interactOn(entity, InteractionHand.MAIN_HAND).consumesAction();
+ if (flag) {
+ bot.swing(InteractionHand.MAIN_HAND);
+ bot.updateItemInHand(InteractionHand.MAIN_HAND);
+ }
+ return flag;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemToOffhandAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemToOffhandAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..e42288a4f99f7de6655d49ee1a05d37b79652c22
index 0000000000000000000000000000000000000000..f8334858a7a0572d1c3dcf5f04696fbbec552a84
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/UseItemToOffhandAction.java
@@ -0,0 +1,24 @@
@@ -0,0 +1,27 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.world.InteractionHand;
Expand All @@ -4161,9 +4178,12 @@ index 0000000000000000000000000000000000000000..e42288a4f99f7de6655d49ee1a05d37b
+ public boolean doTick(@NotNull ServerBot bot) {
+ Entity entity = bot.getTargetEntity(3, null);
+ if (entity != null) {
+ bot.swing(InteractionHand.OFF_HAND);
+ bot.updateItemInHand(InteractionHand.OFF_HAND);
+ return bot.interactOn(entity, InteractionHand.OFF_HAND).consumesAction();
+ boolean flag = bot.interactOn(entity, InteractionHand.OFF_HAND).consumesAction();
+ if (flag) {
+ bot.swing(InteractionHand.OFF_HAND);
+ bot.updateItemInHand(InteractionHand.OFF_HAND);
+ }
+ return flag;
+ }
+ return false;
+ }
Expand Down

0 comments on commit dd487df

Please sign in to comment.