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
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;
}
...
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.
Can confirm