mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
feat: swap action (#657)
This commit is contained in:
@@ -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<SwapAction> {
|
||||
static SwapAction create() {
|
||||
return Bukkit.getBotManager().newAction(SwapAction.class);
|
||||
}
|
||||
}
|
||||
@@ -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<? extends BotAction<?>> type) {
|
||||
|
||||
@@ -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<ServerSwapAction> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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<SwapAction, ServerSwapAction> implements SwapAction {
|
||||
|
||||
public CraftSwapAction(ServerSwapAction serverAction) {
|
||||
super(serverAction, CraftSwapAction::new);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user