mojira.dev
MC-213937

The "drinking finished" event only works for potions

The bug

The drinking finished event on triggers when a potion is finished. It does not trigger when milk is finished. In addition, honey and stews are counted as foods, so finishing them outputs the wrong strength from a sculk sensor attached to a comparator.

Code analysis

Code analysis by @unknown can be found in this comment.

Comments 7

Can confirm this behavior in 1.17.1 and 1.18 Pre-release 2.

Can confirm in 1.18.1.

Here's a code analysis along with a potential fix regarding this issue. The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn. 🙂

Code Analysis:

net.minecraft.world.item.MilkBucketItem.java

public class MilkBucketItem extends Item {
   ...
   public ItemStack finishUsingItem(ItemStack $is, Level $l, LivingEntity $le) {
      if ($le instanceof ServerPlayer) {
         ServerPlayer serverplayer = (ServerPlayer)$le;
         CriteriaTriggers.CONSUME_ITEM.trigger(serverplayer, $is);
         serverplayer.awardStat(Stats.ITEM_USED.get(this));
      }

      if ($le instanceof Player && !((Player)$le).getAbilities().instabuild) {
         $is.shrink(1);
      }

      if (!$l.isClientSide) {
         $le.removeAllEffects();
      }

      return $is.isEmpty() ? new ItemStack(Items.BUCKET) : $is;
   }
   ...

If we look at the above class, we can that the gameEvent() method is never called when drinking a milk bucket, resulting in sculk sensors not detecting this action as a vibration.

Potential Fix:

Simply adding a line of code that registers drinking milk buckets as a game event should resolve this problem. The following line of code could be used in order to fix this:

$l.gameEvent($le, GameEvent.DRINKING_FINISH, $le.eyeBlockPosition());

The correct piece of code within its class should look something like the following:

net.minecraft.world.item.MilkBucketItem.java

public class MilkBucketItem extends Item {
   ...
   public ItemStack finishUsingItem(ItemStack $is, Level $l, LivingEntity $le) {
      if ($le instanceof ServerPlayer) {
         ServerPlayer serverplayer = (ServerPlayer)$le;
         CriteriaTriggers.CONSUME_ITEM.trigger(serverplayer, $is);
         serverplayer.awardStat(Stats.ITEM_USED.get(this));
      }

      if ($le instanceof Player && !((Player)$le).getAbilities().instabuild) {
         $is.shrink(1);
      }

      if (!$l.isClientSide) {
         $le.removeAllEffects();
      }

      $l.gameEvent($le, GameEvent.DRINKING_FINISH, $le.eyeBlockPosition());
      return $is.isEmpty() ? new ItemStack(Items.BUCKET) : $is;
   }
   ...

can confirm in 1.18.2 and 22w15a

This looks fixed to me in 23w05a (possibly earlier). Can someone please double check?

Still an issue in 1.19.4 Pre-release 3, for honey bottles at least; they output a signal of 8 instead of 7. Cannot test for milk buckets due to MC-260444.

PancakeIdentity

(Unassigned)

Confirmed

Platform

Normal

Game Events

sculk_sensor

21w05a, 21w05b, 21w06a, 21w10a, 1.17.1, 1.18.1, 1.18.2, 22w14a, 22w15a, 1.19.4 Pre-release 1

Retrieved