From 94a776e4d18c6e311af553864d3510a2f88936f1 Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Thu, 22 Aug 2024 02:44:01 -0400 Subject: [PATCH] Add eating check --- patches/server/0010-Fakeplayer-support.patch | 23 ++++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/patches/server/0010-Fakeplayer-support.patch b/patches/server/0010-Fakeplayer-support.patch index 98d284c..eda26db 100644 --- a/patches/server/0010-Fakeplayer-support.patch +++ b/patches/server/0010-Fakeplayer-support.patch @@ -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; @@ -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) { @@ -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; @@ -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); @@ -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; @@ -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);