Search in sources :

Example 1 with CommonProxy

use of com.lying.variousoddities.proxy.CommonProxy in project VariousOddities by Lyinginbedmon.

the class PacketSpeciesOpenScreen method handle.

public static void handle(PacketSpeciesOpenScreen msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    if (context.getDirection().getReceptionSide().isServer())
        context.setPacketHandled(true);
    else {
        CommonProxy proxy = (CommonProxy) VariousOddities.proxy;
        proxy.openSpeciesSelectScreen(proxy.getPlayerEntity(context));
        context.setPacketHandled(true);
    }
}
Also used : NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) CommonProxy(com.lying.variousoddities.proxy.CommonProxy)

Example 2 with CommonProxy

use of com.lying.variousoddities.proxy.CommonProxy in project VariousOddities by Lyinginbedmon.

the class PacketSyncAbilities method handle.

public static void handle(PacketSyncAbilities msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    if (context.getDirection().getReceptionSide().isClient()) {
        PlayerEntity player = ((CommonProxy) VariousOddities.proxy).getPlayerEntity(context);
        if (player != null) {
            World world = player.getEntityWorld();
            if (world != null) {
                LivingEntity entity = null;
                for (LivingEntity living : world.getEntitiesWithinAABB(LivingEntity.class, Minecraft.getInstance().player.getBoundingBox().grow(64D))) if (living.getUniqueID().equals(msg.uuid)) {
                    entity = living;
                    break;
                }
                if (entity != null) {
                    LivingData data = LivingData.forEntity(entity);
                    data.getAbilities().deserializeNBT(msg.abilitiesData);
                }
            }
        }
    } else {
        ServerPlayerEntity sender = context.getSender();
        if (sender != null) {
            Abilities abilities = LivingData.forEntity(sender).getAbilities();
            abilities.forceRecache();
            CompoundNBT data = abilities.serializeNBT();
            PacketHandler.sendToNearby(sender.getEntityWorld(), sender, new PacketSyncAbilities(sender.getUniqueID(), data));
        }
    }
    context.setPacketHandled(true);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Abilities(com.lying.variousoddities.capabilities.Abilities) CompoundNBT(net.minecraft.nbt.CompoundNBT) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) CommonProxy(com.lying.variousoddities.proxy.CommonProxy) LivingData(com.lying.variousoddities.capabilities.LivingData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 3 with CommonProxy

use of com.lying.variousoddities.proxy.CommonProxy in project VariousOddities by Lyinginbedmon.

the class PacketSyncBludgeoning method handle.

public static void handle(PacketSyncBludgeoning msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    context.setPacketHandled(true);
    if (context.getDirection().getReceptionSide().isServer())
        return;
    PlayerEntity sender = ((CommonProxy) VariousOddities.proxy).getPlayerEntity(context);
    if (sender != null) {
        LivingData data = LivingData.forEntity(sender);
        if (data != null)
            data.setBludgeoning(msg.bludgeoning);
    }
}
Also used : NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) CommonProxy(com.lying.variousoddities.proxy.CommonProxy) LivingData(com.lying.variousoddities.capabilities.LivingData) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 4 with CommonProxy

use of com.lying.variousoddities.proxy.CommonProxy in project VariousOddities by Lyinginbedmon.

the class PacketSyncLivingData method handle.

public static void handle(PacketSyncLivingData msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    if (context.getDirection().getReceptionSide().isServer()) {
        ServerPlayerEntity player = context.getSender();
        LivingEntity target = null;
        if (player.getUniqueID().equals(msg.entityID))
            target = player;
        else {
            World world = player.getEntityWorld();
            for (LivingEntity ent : world.getEntitiesWithinAABB(LivingEntity.class, player.getBoundingBox().grow(64D))) if (ent.getUniqueID().equals(msg.entityID)) {
                target = ent;
                break;
            }
        }
        if (target != null)
            PacketHandler.sendTo(player, new PacketSyncLivingData(msg.entityID, LivingData.forEntity(target)));
    } else {
        PlayerEntity player = ((CommonProxy) VariousOddities.proxy).getPlayerEntity(context);
        LivingEntity target = null;
        if (player.getUniqueID().equals(msg.entityID))
            target = player;
        else {
            World world = player.getEntityWorld();
            for (LivingEntity ent : world.getEntitiesWithinAABB(LivingEntity.class, player.getBoundingBox().grow(64D))) if (ent.getUniqueID().equals(msg.entityID)) {
                target = ent;
                break;
            }
        }
        if (target != null) {
            LivingData data = LivingData.forEntity(target);
            if (data != null)
                data.deserializeNBT(msg.dataNBT);
        }
    }
    context.setPacketHandled(true);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) CommonProxy(com.lying.variousoddities.proxy.CommonProxy) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) LivingData(com.lying.variousoddities.capabilities.LivingData) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 5 with CommonProxy

use of com.lying.variousoddities.proxy.CommonProxy in project VariousOddities by Lyinginbedmon.

the class PacketSyncScents method handle.

public static void handle(PacketSyncScents msg, Supplier<NetworkEvent.Context> cxt) {
    NetworkEvent.Context context = cxt.get();
    if (!context.getDirection().getReceptionSide().isServer()) {
        PlayerEntity player = ((CommonProxy) VariousOddities.proxy).getPlayerEntity(context);
        ScentsManager manager = VariousOddities.proxy.getScentsManager(player.getEntityWorld());
        manager.read(msg.scentData);
    }
    context.setPacketHandled(true);
}
Also used : ScentsManager(com.lying.variousoddities.world.savedata.ScentsManager) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) CommonProxy(com.lying.variousoddities.proxy.CommonProxy) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

CommonProxy (com.lying.variousoddities.proxy.CommonProxy)20 NetworkEvent (net.minecraftforge.fml.network.NetworkEvent)20 PlayerEntity (net.minecraft.entity.player.PlayerEntity)19 LivingData (com.lying.variousoddities.capabilities.LivingData)9 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)7 LivingEntity (net.minecraft.entity.LivingEntity)6 World (net.minecraft.world.World)5 Abilities (com.lying.variousoddities.capabilities.Abilities)4 Ability (com.lying.variousoddities.species.abilities.Ability)2 ScentsManager (com.lying.variousoddities.world.savedata.ScentsManager)2 AbilityRemoveEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityRemoveEvent)1 PlayerData (com.lying.variousoddities.capabilities.PlayerData)1 IMountInventory (com.lying.variousoddities.entity.IMountInventory)1 ActivatedAbility (com.lying.variousoddities.species.abilities.ActivatedAbility)1 ScentMarker (com.lying.variousoddities.world.savedata.ScentsManager.ScentMarker)1 Entity (net.minecraft.entity.Entity)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1