import { world, system, EntityItemComponent, MinecraftDimensionTypes } from "@minecraft/server";

export default class AntiBurner {
    constructor(ItemPrefixes) {
        this.AllowedPrefixes = ItemPrefixes;

        const Dimensions = [ MinecraftDimensionTypes.overworld, MinecraftDimensionTypes.nether, MinecraftDimensionTypes.theEnd ];
        system.runInterval(() => {
            Dimensions.map(dimension => this.evitBurning(dimension, this.AllowedPrefixes));
        }, 0);
    }

    evitBurning(dimensionId, ItemPrefixes) {
        const dimension = world.getDimension(dimensionId);
            
        for (const entity of dimension.getEntities({ type: "minecraft:item" })) {
            const ItemStack = entity.getComponent(EntityItemComponent.componentId);

            if (!this.AllowedPrefixes.some(prefix => ItemStack.itemStack.typeId.includes(prefix))) continue;
            entity.triggerEvent("pure_netherite_fire"); 
        }
    }
}