Skip to content

Outdated food detection - getFood() uses Material switch instead of consumable/food components #114

Description

@MLG-SERBUR

Expected

Only recognized foods should trigger the energy-bar eating logic. OldFood.java:76 getFood(ItemStack) should return heal amount >0 for actual consumables (steak, bread, potion, milk bucket, etc.) and 0 for non-foods (blocks, tools). Heal amount should match food balance (currently 6.0 default, 1.0 potion, 2.0 milk).

With Paper 26.1.2+ (MC 1.20.5+), consumability is defined by data components DataComponentTypes.FOOD / DataComponentTypes.CONSUMABLE, not just Material. New foods (e.g., honey bottle, enchanted golden apple variants, custom components) should be detected correctly.

What happens

OldFood.java:76 uses a hard-coded switch(item.getType()):

This means:

  • Any item with a Material falls to default and returns 6D, so right-clicking with a dirt block or sword at food 20 / health < max incorrectly triggers OldFood.java:41 getFood()>0 check and sets foodLevel=19 for non-food.
  • Modern Paper 26.2 foods that rely on FOOD/CONSUMABLE components rather than distinct Material are not distinguished; the switch is stale and will mis-classify new consumables (or miss them if future materials are added). It also hard-codes heal values instead of deriving from component nutrition/saturation.
  • Combined with PlayerItemConsumeEvent copy-based semantics (1.20.5+), the event's getItem() is a copy; without checking components, logic may fire for items that vanilla wouldn't consider consumable, or fail for items vanilla does consider consumable.

File: OldFood.java | pom.xml:137 paper-api [26.1.2.build,)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions