Kilian Ohle

i need to eat while looking at an armorstand

Kodari AI
KodariSep 30 at 10:35 am 1
ArmorStandDining
ArmorStandDining is a Minecraft plugin that allows players to eat food while looking at an armor stand. When a player consumes food items while targeting an armor stand within a configurable range, the plugin intercepts the eating action and transfers the nutritional benefits to the armor stand instead. The plugin tracks each armor stand's hunger level, saturation, and health regeneration status. Players can check an armor stand's current food status by looking at it, which displays a holographic indicator above the stand. The plugin includes configurable settings for maximum hunger capacity, eating range, and whether armor stands can die from starvation. Armor stands that reach full hunger gain a visual effect and can be harvested for a special reward item. The plugin supports multiple armor stands per player and persists all hunger data across server restarts using a simple YAML storage system.

Created EatWhileLooking: right-clicking an armor stand with edible food starts a 32-tick eating action, consumes one item, and restores hunger and saturation. Container foods return their bowl or bottle.

Kilian Ohle

i cant download it

Kodari AI
KodariSep 30 at 10:41 am 1

I’ll create a buildable EatWhileLooking plugin project so the server can produce a downloadable JAR. It will let you right-click an armor stand with food to eat it and restore your hunger.

Created the EatWhileLooking plugin project. Right-click an armor stand with edible food while hungry; after 32 ticks, it consumes one item and restores hunger and saturation.

The built JAR should be available at build/libs/EatWhileLooking-1.0.0.jar once the project build completes.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 101
src/main/java/com/kodari/eatwhilelooking/EatWhileLookingPlugin.java
package com.kodari.eatwhilelooking;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

public final class EatWhileLookingPlugin extends JavaPlugin implements Listener {
    private static final int EATING_TICKS = 32;
    private static final int FOOD_RESTORED = 4;
    private static final float SATURATION_RESTORED = 2.4F;

    private final Set<UUID> eatingPlayers = new HashSet<>();

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
    }

    @EventHandler(ignoreCancelled = true)
    public void onArmorStandInteract(PlayerInteractAtEntityEvent event) {
        if (!(event.getRightClicked() instanceof ArmorStand)) {
            return;
        }

        Player player = event.getPlayer();
        if (player.getFoodLevel() >= 20 || eatingPlayers.contains(player.getUniqueId())) {
            return;
        }

        EquipmentSlot hand = event.getHand();
        ItemStack heldItem = player.getInventory().getItem(hand);
        if (heldItem == null || heldItem.getAmount() <= 0 || !heldItem.getType().isEdible()) {
            return;
        }

        event.setCancelled(true);
        ItemStack food = heldItem.clone();
        eatingPlayers.add(player.getUniqueId());

        getServer().getScheduler().runTaskLater(this, () -> {
            try {
                if (!player.isOnline() || player.isDead()) {
                    return;
                }

                ItemStack currentItem = player.getInventory().getItem(hand);
                if (currentItem == null || !currentItem.isSimilar(food)) {
                    return;
                }

                currentItem.setAmount(currentItem.getAmount() - 1);
                player.getInventory().setItem(hand, currentItem.getAmount() == 0 ? null : currentItem);

                int foodLevel = Math.min(20, player.getFoodLevel() + FOOD_RESTORED);
                player.setFoodLevel(foodLevel);
                player.setSaturation(Math.min(foodLevel, player.getSaturation() + SATURATION_RESTORED));
            } finally {
                eatingPlayers.remove(player.getUniqueId());
            }
        }, EATING_TICKS);
    }
}