// Path: src/main/java/com/legobmw99/allomancy/api/enums/Metal.java
// public enum Metal {
//     IRON(true),
//     STEEL,
//     TIN,
//     PEWTER,
//     ZINC,
//     BRASS,
//     COPPER(true),
//     BRONZE,
//     ALUMINUM,
//     DURALUMIN,
//     CHROMIUM,
//     NICROSIL,
//     GOLD(true),
//     ELECTRUM,
//     CADMIUM,
//     BENDALLOY;
// 
// 
//     private final boolean vanilla;
// 
//     Metal() {
//         this(false);
//     }
// 
//     Metal(boolean isVanilla) {
//         this.vanilla = isVanilla;
//     }
// 
//     public static Metal getMetal(int index) {
//         for (Metal metal : values()) {
//             if (metal.getIndex() == index) {
//                 return metal;
//             }
//         }
//         throw new IllegalArgumentException("Allomancy: Bad Metal Index");
//     }
// 
//     public boolean isVanilla() {
//         return this.vanilla;
//     }
// 
//     public String getName() {
//         return name().toLowerCase(Locale.ROOT);
//     }
// 
//     public int getIndex() {
//         return ordinal();
//     }
// 
// 
// }
// 
// Path: src/main/java/com/legobmw99/allomancy/modules/powers/data/AllomancerCapability.java
// public class AllomancerCapability {
// 
//     public static final Capability<IAllomancerData> PLAYER_CAP = CapabilityManager.get(new CapabilityToken<>() {
//     });
// 
//     public static final ResourceLocation IDENTIFIER = new ResourceLocation(Allomancy.MODID, "allomancy_data");
// 
//     public static void registerCapability(final RegisterCapabilitiesEvent event) {
//         event.register(IAllomancerData.class);
//     }
// 
// }
// 
// Path: src/main/java/com/legobmw99/allomancy/network/Network.java
// public class Network {
// 
//     private static final String VERSION = "1.1";
//     public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(Allomancy.MODID, "networking"), () -> VERSION, VERSION::equals,
//                                                                                   VERSION::equals);
// 
//     private static int index = 0;
// 
//     private static int nextIndex() {
//         return index++;
//     }
// 
//     public static void registerPackets() {
//         INSTANCE.registerMessage(nextIndex(), AllomancerDataPacket.class, AllomancerDataPacket::encode, AllomancerDataPacket::decode, AllomancerDataPacket::handle);
//         INSTANCE.registerMessage(nextIndex(), UpdateBurnPacket.class, UpdateBurnPacket::encode, UpdateBurnPacket::decode, UpdateBurnPacket::handle);
//         INSTANCE.registerMessage(nextIndex(), ChangeEmotionPacket.class, ChangeEmotionPacket::encode, ChangeEmotionPacket::decode, ChangeEmotionPacket::handle);
//         INSTANCE.registerMessage(nextIndex(), TryPushPullEntity.class, TryPushPullEntity::encode, TryPushPullEntity::decode, TryPushPullEntity::handle);
//         INSTANCE.registerMessage(nextIndex(), TryPushPullBlock.class, TryPushPullBlock::encode, TryPushPullBlock::decode, TryPushPullBlock::handle);
//         INSTANCE.registerMessage(nextIndex(), UpdateEnhancedPacket.class, UpdateEnhancedPacket::encode, UpdateEnhancedPacket::decode, UpdateEnhancedPacket::handle);
//     }
// 
//     public static void sendToServer(Object msg) {
//         INSTANCE.sendToServer(msg);
//     }
// 
//     public static void sendTo(Object msg, ServerPlayer player) {
//         if (!(player instanceof FakePlayer)) {
//             INSTANCE.sendTo(msg, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT);
//         }
//     }
// 
//     public static void sendTo(Object msg, PacketDistributor.PacketTarget target) {
//         INSTANCE.send(target, msg);
//     }
// 
//     public static void sync(Player player) {
//         player.getCapability(AllomancerCapability.PLAYER_CAP).ifPresent(data -> sync(data, player));
//     }
// 
//     public static void sync(IAllomancerData cap, Player player) {
//         sync(new AllomancerDataPacket(cap, player), player);
//     }
// 
//     public static void sync(Object msg, Player player) {
//         sendTo(msg, PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> player));
//     }
// 
// }


import com.legobmw99.allomancy.api.enums.Metal;
import com.legobmw99.allomancy.modules.powers.data.AllomancerCapability;
import com.legobmw99.allomancy.network.Network;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkEvent;
import java.util.Arrays;
import java.util.function.Supplier;
package com.legobmw99.allomancy.modules.powers.network;




public class UpdateBurnPacket {

    private final Metal mt;
    private final boolean value;

    /**
     * Send request to the server to change the burning state of a metal
     *
     * @param mt    the metal
     * @param value whether it is burning
     */
    public UpdateBurnPacket(Metal mt, boolean value) {
        this.mt = mt;
        this.value = value; // Convert bool to int
    }

    public static UpdateBurnPacket decode(FriendlyByteBuf buf) {
        return new UpdateBurnPacket(buf.readEnum(Metal.class), buf.readBoolean());
    }

    public void encode(FriendlyByteBuf buf) {
        buf.writeEnum(this.mt);
        buf.writeBoolean(this.value);
    }

    public void handle(Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {

            ServerPlayer player = ctx.get().getSender();

            player.getCapability(AllomancerCapability.PLAYER_CAP).ifPresent(data -> {
                if (data.hasPower(this.mt) && data.getAmount(this.mt) > 0) {
                    data.setBurning(this.mt, this.value);
                    if (!this.value && this.mt == Metal.DURALUMIN) {
// Path: src/main/java/com/legobmw99/allomancy/api/enums/Metal.java
// public enum Metal {
//     IRON(true),
//     STEEL,
//     TIN,
//     PEWTER,
//     ZINC,
//     BRASS,
//     COPPER(true),
//     BRONZE,
//     ALUMINUM,
//     DURALUMIN,
//     CHROMIUM,
//     NICROSIL,
//     GOLD(true),
//     ELECTRUM,
//     CADMIUM,
//     BENDALLOY;
// 
// 
//     private final boolean vanilla;
// 
//     Metal() {
//         this(false);
//     }
// 
//     Metal(boolean isVanilla) {
//         this.vanilla = isVanilla;
//     }
// 
//     public static Metal getMetal(int index) {
//         for (Metal metal : values()) {
//             if (metal.getIndex() == index) {
//                 return metal;
//             }
//         }
//         throw new IllegalArgumentException("Allomancy: Bad Metal Index");
//     }
// 
//     public boolean isVanilla() {
//         return this.vanilla;
//     }
// 
//     public String getName() {
//         return name().toLowerCase(Locale.ROOT);
//     }
// 
//     public int getIndex() {
//         return ordinal();
//     }
// 
// 
// }
// 
// Path: src/main/java/com/legobmw99/allomancy/modules/powers/data/AllomancerCapability.java
// public class AllomancerCapability {
// 
//     public static final Capability<IAllomancerData> PLAYER_CAP = CapabilityManager.get(new CapabilityToken<>() {
//     });
// 
//     public static final ResourceLocation IDENTIFIER = new ResourceLocation(Allomancy.MODID, "allomancy_data");
// 
//     public static void registerCapability(final RegisterCapabilitiesEvent event) {
//         event.register(IAllomancerData.class);
//     }
// 
// }
// 
// Path: src/main/java/com/legobmw99/allomancy/network/Network.java
// public class Network {
// 
//     private static final String VERSION = "1.1";
//     public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(new ResourceLocation(Allomancy.MODID, "networking"), () -> VERSION, VERSION::equals,
//                                                                                   VERSION::equals);
// 
//     private static int index = 0;
// 
//     private static int nextIndex() {
//         return index++;
//     }
// 
//     public static void registerPackets() {
//         INSTANCE.registerMessage(nextIndex(), AllomancerDataPacket.class, AllomancerDataPacket::encode, AllomancerDataPacket::decode, AllomancerDataPacket::handle);
//         INSTANCE.registerMessage(nextIndex(), UpdateBurnPacket.class, UpdateBurnPacket::encode, UpdateBurnPacket::decode, UpdateBurnPacket::handle);
//         INSTANCE.registerMessage(nextIndex(), ChangeEmotionPacket.class, ChangeEmotionPacket::encode, ChangeEmotionPacket::decode, ChangeEmotionPacket::handle);
//         INSTANCE.registerMessage(nextIndex(), TryPushPullEntity.class, TryPushPullEntity::encode, TryPushPullEntity::decode, TryPushPullEntity::handle);
//         INSTANCE.registerMessage(nextIndex(), TryPushPullBlock.class, TryPushPullBlock::encode, TryPushPullBlock::decode, TryPushPullBlock::handle);
//         INSTANCE.registerMessage(nextIndex(), UpdateEnhancedPacket.class, UpdateEnhancedPacket::encode, UpdateEnhancedPacket::decode, UpdateEnhancedPacket::handle);
//     }
// 
//     public static void sendToServer(Object msg) {
//         INSTANCE.sendToServer(msg);
//     }
// 
//     public static void sendTo(Object msg, ServerPlayer player) {
//         if (!(player instanceof FakePlayer)) {
//             INSTANCE.sendTo(msg, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT);
//         }
//     }
// 
//     public static void sendTo(Object msg, PacketDistributor.PacketTarget target) {
//         INSTANCE.send(target, msg);
//     }
// 
//     public static void sync(Player player) {
//         player.getCapability(AllomancerCapability.PLAYER_CAP).ifPresent(data -> sync(data, player));
//     }
// 
//     public static void sync(IAllomancerData cap, Player player) {
//         sync(new AllomancerDataPacket(cap, player), player);
//     }
// 
//     public static void sync(Object msg, Player player) {
//         sendTo(msg, PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> player));
//     }
// 
// }


// Path: src/main/java/com/legobmw99/allomancy/modules/powers/network/UpdateBurnPacket.java
import com.legobmw99.allomancy.api.enums.Metal;
import com.legobmw99.allomancy.modules.powers.data.AllomancerCapability;
import com.legobmw99.allomancy.network.Network;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkEvent;
import java.util.Arrays;
import java.util.function.Supplier;

package com.legobmw99.allomancy.modules.powers.network;




public class UpdateBurnPacket {

    private final Metal mt;
    private final boolean value;

    /**
     * Send request to the server to change the burning state of a metal
     *
     * @param mt    the metal
     * @param value whether it is burning
     */
    public UpdateBurnPacket(Metal mt, boolean value) {
        this.mt = mt;
        this.value = value; // Convert bool to int
    }

    public static UpdateBurnPacket decode(FriendlyByteBuf buf) {
        return new UpdateBurnPacket(buf.readEnum(Metal.class), buf.readBoolean());
    }

    public void encode(FriendlyByteBuf buf) {
        buf.writeEnum(this.mt);
        buf.writeBoolean(this.value);
    }

    public void handle(Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {

            ServerPlayer player = ctx.get().getSender();

            player.getCapability(AllomancerCapability.PLAYER_CAP).ifPresent(data -> {
                if (data.hasPower(this.mt) && data.getAmount(this.mt) > 0) {
                    data.setBurning(this.mt, this.value);
                    if (!this.value && this.mt == Metal.DURALUMIN) {
                        data.drainMetals(Arrays.stream(Metal.values()).filter(data::isBurning).toArray(Metal[]::new));