Skip to content

Commit

Permalink
Add eating check
Browse files Browse the repository at this point in the history
  • Loading branch information
Lumine1909 committed Aug 22, 2024
1 parent cb5e0e3 commit 94a776e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions patches/server/0010-Fakeplayer-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1555,10 +1555,10 @@ index 0000000000000000000000000000000000000000..0db337866c71283464d026a4f230016b
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/ServerBot.java b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
new file mode 100644
index 0000000000000000000000000000000000000000..99803680553d04ee2ae6664bb6d5e937ef3aac6f
index 0000000000000000000000000000000000000000..64d8fbe3b1a7c5337436ffa3ea754cec0207f996
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/ServerBot.java
@@ -0,0 +1,777 @@
@@ -0,0 +1,781 @@
+package org.leavesmc.leaves.bot;
+
+import com.google.common.collect.Lists;
Expand Down Expand Up @@ -2023,6 +2023,10 @@ index 0000000000000000000000000000000000000000..99803680553d04ee2ae6664bb6d5e937
+ detectEquipmentUpdatesPublic();
+ }
+
+ public long getEatStartTime() {
+ return eatStartTime;
+ }
+
+ @Override
+ public void checkFallDamage(double heightDifference, boolean onGround, @NotNull BlockState state, @NotNull BlockPos landedPosition) {
+ if (onGround) {
Expand Down Expand Up @@ -2809,10 +2813,10 @@ index 0000000000000000000000000000000000000000..adcce8f8c39b0a1e445f5552ce744360
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/ConsumeAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/ConsumeAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..b3d2885e1d4df1e74c8d100ac42883767d3de013
index 0000000000000000000000000000000000000000..7abc21ef62b84bf6e51ab4381555f29ef54c45b4
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/ConsumeAction.java
@@ -0,0 +1,51 @@
@@ -0,0 +1,53 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.core.component.DataComponents;
Expand Down Expand Up @@ -2846,11 +2850,13 @@ index 0000000000000000000000000000000000000000..b3d2885e1d4df1e74c8d100ac4288376
+
+ @Override
+ public boolean doTick(@NotNull ServerBot bot) {
+
+ ItemStack itemStack = bot.getItemInHand(InteractionHand.MAIN_HAND);
+ if (itemStack.get(DataComponents.FOOD) == null && itemStack.get(DataComponents.POTION_CONTENTS) == null) {
+ return false;
+ }
+ if (bot.getEatStartTime() > 0) {
+ return false;
+ }
+ int consumeTick = itemStack.getUseDuration(bot);
+ bot.startUsingItem(InteractionHand.MAIN_HAND);
+ AtomicInteger count = new AtomicInteger(0);
Expand All @@ -2866,10 +2872,10 @@ index 0000000000000000000000000000000000000000..b3d2885e1d4df1e74c8d100ac4288376
+}
diff --git a/src/main/java/org/leavesmc/leaves/bot/agent/actions/ConsumeOffhandAction.java b/src/main/java/org/leavesmc/leaves/bot/agent/actions/ConsumeOffhandAction.java
new file mode 100644
index 0000000000000000000000000000000000000000..a27276715c7064d94f7147285f1c5bf61b7fac70
index 0000000000000000000000000000000000000000..18f8032056a59b9e4d144e5ff5c3aa1fdf2fec05
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/bot/agent/actions/ConsumeOffhandAction.java
@@ -0,0 +1,50 @@
@@ -0,0 +1,53 @@
+package org.leavesmc.leaves.bot.agent.actions;
+
+import net.minecraft.core.component.DataComponents;
Expand Down Expand Up @@ -2907,6 +2913,9 @@ index 0000000000000000000000000000000000000000..a27276715c7064d94f7147285f1c5bf6
+ if (itemStack.get(DataComponents.FOOD) == null && itemStack.get(DataComponents.POTION_CONTENTS) == null) {
+ return false;
+ }
+ if (bot.getEatStartTime() > 0) {
+ return false;
+ }
+ int consumeTick = itemStack.getUseDuration(bot);
+ bot.startUsingItem(InteractionHand.OFF_HAND);
+ AtomicInteger count = new AtomicInteger(0);
Expand Down

0 comments on commit 94a776e

Please sign in to comment.