From c1242c6509d2a25f450aa1b7564b58ec32feb47d Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Thu, 8 Dec 2022 19:40:43 +0800 Subject: [PATCH] Update fakeplayer use_to action --- .../server/0010-Add-fakeplayer-support.patch | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/patches/server/0010-Add-fakeplayer-support.patch b/patches/server/0010-Add-fakeplayer-support.patch index 5406f78c..2a3b82b2 100644 --- a/patches/server/0010-Add-fakeplayer-support.patch +++ b/patches/server/0010-Add-fakeplayer-support.patch @@ -1306,10 +1306,10 @@ index 0000000000000000000000000000000000000000..821d456d11b6f49ea8eba59e79d09980 +} diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/Actions.java b/src/main/java/top/leavesmc/leaves/bot/agent/Actions.java new file mode 100644 -index 0000000000000000000000000000000000000000..899079c1bd323bc8d18b2cee1589bf094937996a +index 0000000000000000000000000000000000000000..0296cf157ef2472ade3c6bf39c5765708ae52eaa --- /dev/null +++ b/src/main/java/top/leavesmc/leaves/bot/agent/Actions.java -@@ -0,0 +1,51 @@ +@@ -0,0 +1,53 @@ +package top.leavesmc.leaves.bot.agent; + +import top.leavesmc.leaves.bot.agent.action.AttackAction; @@ -1320,6 +1320,7 @@ index 0000000000000000000000000000000000000000..899079c1bd323bc8d18b2cee1589bf09 +import top.leavesmc.leaves.bot.agent.action.StopAction; +import top.leavesmc.leaves.bot.agent.action.UseItemAction; +import top.leavesmc.leaves.bot.agent.action.UseItemOnAction; ++import top.leavesmc.leaves.bot.agent.action.UseItemToAction; + +import java.util.HashSet; +import java.util.Set; @@ -1337,6 +1338,7 @@ index 0000000000000000000000000000000000000000..899079c1bd323bc8d18b2cee1589bf09 + register(new StopAction()); + register(new BreakBlockAction()); + register(new SneakAction()); ++ register(new UseItemToAction()); + } + + public static void register(BotAction action) { @@ -1731,6 +1733,45 @@ index 0000000000000000000000000000000000000000..58d6bcd4c6b6b02c42b7175e192b7600 + return false; + } +} +diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemToAction.java b/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemToAction.java +new file mode 100644 +index 0000000000000000000000000000000000000000..c3b373b2ab61a467194ae3653a5e56997bec5317 +--- /dev/null ++++ b/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemToAction.java +@@ -0,0 +1,33 @@ ++package top.leavesmc.leaves.bot.agent.action; ++ ++import net.minecraft.server.level.ServerPlayer; ++import net.minecraft.world.InteractionHand; ++import net.minecraft.world.entity.Entity; ++import net.minecraft.world.phys.EntityHitResult; ++import net.minecraft.world.phys.HitResult; ++import org.jetbrains.annotations.NotNull; ++import top.leavesmc.leaves.bot.ServerBot; ++import top.leavesmc.leaves.bot.agent.BotAction; ++ ++public class UseItemToAction extends BotAction { ++ ++ public UseItemToAction() { ++ super("use_to", true, true); ++ } ++ ++ @Override ++ public BotAction getNew(int tickDelay, int number, @NotNull ServerPlayer player) { ++ return new UseItemToAction().setNumber(number).setTickDelay(tickDelay); ++ } ++ ++ @Override ++ public boolean doTick(@NotNull ServerBot bot) { ++ HitResult result = bot.getRayTrace(4); ++ if (result.getType() == HitResult.Type.ENTITY) { ++ bot.punch(); ++ bot.updateItemInMainHand(); ++ return ((EntityHitResult) result).getEntity().interact(bot, InteractionHand.MAIN_HAND).consumesAction(); ++ } ++ return false; ++ } ++} diff --git a/src/main/java/top/leavesmc/leaves/entity/CraftBot.java b/src/main/java/top/leavesmc/leaves/entity/CraftBot.java new file mode 100644 index 0000000000000000000000000000000000000000..2d5044c4a09044364e818b7674908bf98932bf58