diff --git a/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/SwapAction.java b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/SwapAction.java new file mode 100644 index 00000000..f2248b7e --- /dev/null +++ b/leaves-api/src/main/java/org/leavesmc/leaves/entity/bot/action/SwapAction.java @@ -0,0 +1,11 @@ +package org.leavesmc.leaves.entity.bot.action; + +import org.bukkit.Bukkit; +/** + * Represents an action for a bot to swap items between the main hand and off-hand. + */ +public interface SwapAction extends BotAction { + static SwapAction create() { + return Bukkit.getBotManager().newAction(SwapAction.class); + } +} diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Actions.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Actions.java index 366951b0..6b9cabc7 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Actions.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/Actions.java @@ -35,6 +35,7 @@ public class Actions { register(new ServerRotationAction(), RotationAction.class); register(new ServerMoveAction(), MoveAction.class); register(new ServerMountAction(), MountAction.class); + register(new ServerSwapAction(), SwapAction.class); } public static boolean register(@NotNull ServerBotAction action, Class> type) { diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerSwapAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerSwapAction.java new file mode 100644 index 00000000..8363b11d --- /dev/null +++ b/leaves-server/src/main/java/org/leavesmc/leaves/bot/agent/actions/ServerSwapAction.java @@ -0,0 +1,29 @@ +package org.leavesmc.leaves.bot.agent.actions; + +import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.leavesmc.leaves.bot.ServerBot; +import org.leavesmc.leaves.command.CommandArgument; +import org.leavesmc.leaves.entity.bot.actions.CraftSwapAction; + +public class ServerSwapAction extends ServerBotAction { + + public ServerSwapAction() { + super("swap", CommandArgument.EMPTY, ServerSwapAction::new); + } + + @Override + public boolean doTick(@NotNull ServerBot bot) { + ItemStack mainHandItem = bot.getMainHandItem(); + ItemStack offHandItem = bot.getOffhandItem(); + bot.setItemInHand(InteractionHand.MAIN_HAND, offHandItem); + bot.setItemInHand(InteractionHand.OFF_HAND, mainHandItem); + return true; + } + + @Override + public Object asCraft() { + return new CraftSwapAction(this); + } +} diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/entity/bot/actions/CraftSwapAction.java b/leaves-server/src/main/java/org/leavesmc/leaves/entity/bot/actions/CraftSwapAction.java new file mode 100644 index 00000000..3b74963b --- /dev/null +++ b/leaves-server/src/main/java/org/leavesmc/leaves/entity/bot/actions/CraftSwapAction.java @@ -0,0 +1,11 @@ +package org.leavesmc.leaves.entity.bot.actions; + +import org.leavesmc.leaves.bot.agent.actions.*; +import org.leavesmc.leaves.entity.bot.action.*; + +public class CraftSwapAction extends CraftBotAction implements SwapAction { + + public CraftSwapAction(ServerSwapAction serverAction) { + super(serverAction, CraftSwapAction::new); + } +}