// 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.modules.powers.data.AllomancerCapability;
import com.legobmw99.allomancy.network.Network;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
package com.legobmw99.allomancy.modules.powers.network;



public class UpdateEnhancedPacket {

    private final int enhance_time;
    private final int entityID;


    public UpdateEnhancedPacket(boolean enhanced, int entityID) {
        this.enhance_time = enhanced ? 100 : 0;
        this.entityID = entityID;
    }

    public UpdateEnhancedPacket(int enhance_time, int entityID) {
        this.enhance_time = enhance_time;
        this.entityID = entityID;
    }

    public static UpdateEnhancedPacket decode(FriendlyByteBuf buf) {
        return new UpdateEnhancedPacket(buf.readInt(), buf.readInt());
    }

    public void encode(FriendlyByteBuf buf) {
        buf.writeInt(this.enhance_time);
        buf.writeInt(this.entityID);
    }

    public void handle(Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {
            if (ctx.get().getDirection() == NetworkDirection.PLAY_TO_SERVER) { // Update player of own status
                Player player = (Player) ctx.get().getSender().level.getEntity(this.entityID);
                if (player != null) {
                    player.getCapability(AllomancerCapability.PLAYER_CAP).ifPresent(data -> {
                        data.setEnhanced(this.enhance_time);
// 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/UpdateEnhancedPacket.java
import com.legobmw99.allomancy.modules.powers.data.AllomancerCapability;
import com.legobmw99.allomancy.network.Network;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;

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



public class UpdateEnhancedPacket {

    private final int enhance_time;
    private final int entityID;


    public UpdateEnhancedPacket(boolean enhanced, int entityID) {
        this.enhance_time = enhanced ? 100 : 0;
        this.entityID = entityID;
    }

    public UpdateEnhancedPacket(int enhance_time, int entityID) {
        this.enhance_time = enhance_time;
        this.entityID = entityID;
    }

    public static UpdateEnhancedPacket decode(FriendlyByteBuf buf) {
        return new UpdateEnhancedPacket(buf.readInt(), buf.readInt());
    }

    public void encode(FriendlyByteBuf buf) {
        buf.writeInt(this.enhance_time);
        buf.writeInt(this.entityID);
    }

    public void handle(Supplier<NetworkEvent.Context> ctx) {
        ctx.get().enqueueWork(() -> {
            if (ctx.get().getDirection() == NetworkDirection.PLAY_TO_SERVER) { // Update player of own status
                Player player = (Player) ctx.get().getSender().level.getEntity(this.entityID);
                if (player != null) {
                    player.getCapability(AllomancerCapability.PLAYER_CAP).ifPresent(data -> {
                        data.setEnhanced(this.enhance_time);
                        Network.sync(new UpdateEnhancedPacket(this.enhance_time, this.entityID), player);