import { Direction, MolangVariableMap, system, world } from "@minecraft/server";
import { McEntities } from "../reg/mcEntities";
import { shrinkIfInSurvival } from "../util/miscUtils";
import { SuppItems } from "../reg/suppItems";
import { offsetVec } from "../util/dirUtils";
import { SuppParticles } from "../reg/suppParticles";
import { vecScale, vecSum } from "../util/mthUtils";
world.beforeEvents.playerInteractWithEntity.subscribe((event) => {
    //after since we can always interact with a dog
    const entity = event.target;
    const player = event.player;
    if (entity.typeId == McEntities.Wolf) {
        const item = event.itemStack;
        if (item && item.typeId == SuppItems.Chocolate) {
            system.run(() => {
                entity.dimension.spawnParticle(SuppParticles.BreakingChocolateItem, vecSum(entity.getHeadLocation(), vecScale(entity.getViewDirection(), 0.33)));
                entity.dimension.playSound("mob.fox.eat", entity.location, { pitch: 0.8, volume: 1 });
                entity.addEffect("minecraft:fatal_poison" /* McEffects.FatalPoison */, 80, { amplifier: 1 });
                shrinkIfInSurvival(player, item);
                const molang = new MolangVariableMap();
                entity.dimension.spawnParticle("minecraft:breaking_item_icon", // This shows the "broken block" particles
                offsetVec(entity.location, Direction.Up, 0.3), molang);
            });
        }
    }
});
