mirror of
https://github.com/LeavesMC/Leaves.git
synced 2026-01-06 15:51:33 +00:00
Add New Actions And Fix Actions Bug
This commit is contained in:
@@ -474,16 +474,18 @@ index 3b8d44fb61d504e521e73d3a34f6bd8ad9f13aee..ec1c53e2f98717b648c80ddf7573edad
|
||||
}
|
||||
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..c2a5e344745a0966d57cebce893d80c26dce0f83
|
||||
index 0000000000000000000000000000000000000000..ccedc7b77bef852b66dfa8c4ee3d69b3c71717a0
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/bot/agent/Actions.java
|
||||
@@ -0,0 +1,43 @@
|
||||
@@ -0,0 +1,47 @@
|
||||
+package top.leavesmc.leaves.bot.agent;
|
||||
+
|
||||
+import top.leavesmc.leaves.bot.agent.action.AttackAction;
|
||||
+import top.leavesmc.leaves.bot.agent.action.DropAction;
|
||||
+import top.leavesmc.leaves.bot.agent.action.RotateAction;
|
||||
+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 java.util.HashSet;
|
||||
+import java.util.Set;
|
||||
@@ -497,6 +499,8 @@ index 0000000000000000000000000000000000000000..c2a5e344745a0966d57cebce893d80c2
|
||||
+ register(new DropAction());
|
||||
+ register(new RotateAction());
|
||||
+ register(new UseItemAction());
|
||||
+ register(new UseItemOnAction());
|
||||
+ register(new StopAction());
|
||||
+ }
|
||||
+
|
||||
+ public static void register(BotAction action) {
|
||||
@@ -571,20 +575,16 @@ index 0000000000000000000000000000000000000000..78f04e28afa856c900f84af42f22666b
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/action/AttackAction.java b/src/main/java/top/leavesmc/leaves/bot/agent/action/AttackAction.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..78cf21fc321d3d3d13b2db315897acdf386c696f
|
||||
index 0000000000000000000000000000000000000000..975b45b7ba3107b143577f53c6b54194e3a699b6
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/bot/agent/action/AttackAction.java
|
||||
@@ -0,0 +1,34 @@
|
||||
@@ -0,0 +1,26 @@
|
||||
+package top.leavesmc.leaves.bot.agent.action;
|
||||
+
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import org.bukkit.Location;
|
||||
+import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
+import org.bukkit.util.RayTraceResult;
|
||||
+import org.bukkit.util.Vector;
|
||||
+import net.minecraft.world.phys.EntityHitResult;
|
||||
+import top.leavesmc.leaves.bot.Bot;
|
||||
+import top.leavesmc.leaves.bot.agent.BotAction;
|
||||
+import top.leavesmc.leaves.util.MathUtils;
|
||||
+
|
||||
+public class AttackAction extends BotAction {
|
||||
+
|
||||
@@ -599,14 +599,10 @@ index 0000000000000000000000000000000000000000..78cf21fc321d3d3d13b2db315897acdf
|
||||
+
|
||||
+ @Override
|
||||
+ public void tick(Bot bot) {
|
||||
+ Vector vector = MathUtils.getDirection(bot.getYRot(), bot.getXRot()).normalize();
|
||||
+ Location loc = bot.getBukkitPlayer().getEyeLocation().add(vector);
|
||||
+
|
||||
+ RayTraceResult result = loc.getWorld().rayTraceEntities(loc, vector, 5);
|
||||
+
|
||||
+ if (result != null && result.getHitEntity() != null) {
|
||||
+ bot.attack(((CraftEntity) result.getHitEntity()).getHandle());
|
||||
+ }
|
||||
+ EntityHitResult result = bot.getTargetEntity(3);
|
||||
+ if (result != null) {
|
||||
+ bot.attack(result.getEntity());
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/action/DropAction.java b/src/main/java/top/leavesmc/leaves/bot/agent/action/DropAction.java
|
||||
@@ -672,6 +668,33 @@ index 0000000000000000000000000000000000000000..8f7263a97f56144e98794eae3e137a3a
|
||||
+ this.setCancel(true);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/action/StopAction.java b/src/main/java/top/leavesmc/leaves/bot/agent/action/StopAction.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..09049b934d34aece15a201473f1cf4ed500a05a7
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/bot/agent/action/StopAction.java
|
||||
@@ -0,0 +1,21 @@
|
||||
+package top.leavesmc.leaves.bot.agent.action;
|
||||
+
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import top.leavesmc.leaves.bot.Bot;
|
||||
+import top.leavesmc.leaves.bot.agent.BotAction;
|
||||
+
|
||||
+public class StopAction extends BotAction {
|
||||
+ public StopAction() {
|
||||
+ super("stop");
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public BotAction getNew(int tickDelay, ServerPlayer player) {
|
||||
+ return new StopAction();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void tick(Bot bot) {
|
||||
+ this.setCancel(true);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemAction.java b/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemAction.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..8f39161ff8f84392ef57a1ecda3b098a791841e5
|
||||
@@ -702,6 +725,41 @@ index 0000000000000000000000000000000000000000..8f39161ff8f84392ef57a1ecda3b098a
|
||||
+ bot.updateItemInMainHand();
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemOnAction.java b/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemOnAction.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..a58c57e572b5cd952b0b276a8157250170ce6285
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/top/leavesmc/leaves/bot/agent/action/UseItemOnAction.java
|
||||
@@ -0,0 +1,29 @@
|
||||
+package top.leavesmc.leaves.bot.agent.action;
|
||||
+
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import net.minecraft.world.InteractionHand;
|
||||
+import net.minecraft.world.phys.BlockHitResult;
|
||||
+import net.minecraft.world.phys.HitResult;
|
||||
+import top.leavesmc.leaves.bot.Bot;
|
||||
+import top.leavesmc.leaves.bot.agent.BotAction;
|
||||
+
|
||||
+public class UseItemOnAction extends BotAction {
|
||||
+ public UseItemOnAction() {
|
||||
+ super("use_on");
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public BotAction getNew(int tickDelay, ServerPlayer player) {
|
||||
+ return new UseItemOnAction().setTickDelay(tickDelay);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void tick(Bot bot) {
|
||||
+ HitResult result = bot.getRayTrace(4);
|
||||
+ if (result != null && result.getType() == HitResult.Type.BLOCK) {
|
||||
+ bot.gameMode.useItemOn(bot, bot.getLevel(), bot.getItemInHand(InteractionHand.MAIN_HAND), InteractionHand.MAIN_HAND, (BlockHitResult) result);
|
||||
+ bot.punch();
|
||||
+ bot.updateItemInMainHand();
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/top/leavesmc/leaves/util/MathUtils.java b/src/main/java/top/leavesmc/leaves/util/MathUtils.java
|
||||
index acdef051d6d4eb4e0d957bfbd7f205827c2f23a9..d6a809569455872d08aeab81b174024d2bc3b53a 100644
|
||||
--- a/src/main/java/top/leavesmc/leaves/util/MathUtils.java
|
||||
|
||||
Reference in New Issue
Block a user