Search in sources :

Example 1 with NetworkManager

use of net.minecraft.network.NetworkManager in project MinecraftForge by MinecraftForge.

the class ChannelRegistrationHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception {
    Side side = msg.getTarget();
    NetworkManager manager = msg.getOrigin();
    if (msg.channel().equals("REGISTER") || msg.channel().equals("UNREGISTER")) {
        byte[] data = new byte[msg.payload().readableBytes()];
        msg.payload().readBytes(data);
        String channels = new String(data, Charsets.UTF_8);
        String[] split = channels.split("\0");
        Set<String> channelSet = ImmutableSet.copyOf(split);
        FMLCommonHandler.instance().fireNetRegistrationEvent(manager, channelSet, msg.channel(), side);
    } else {
        ctx.fireChannelRead(msg);
    }
}
Also used : Side(net.minecraftforge.fml.relauncher.Side) NetworkManager(net.minecraft.network.NetworkManager)

Example 2 with NetworkManager

use of net.minecraft.network.NetworkManager in project HorsePower by GoryMoon.

the class HPEventHandler method onServerLeave.

@SubscribeEvent
public static void onServerLeave(WorldEvent.Unload event) {
    if (FMLCommonHandler.instance().getSide().isClient()) {
        NetworkManager manager = FMLClientHandler.instance().getClientToServerNetworkManager();
        if (manager != null && !manager.isLocalChannel() && HPRecipes.serverSyncedRecipes) {
            HPRecipes.serverSyncedRecipes = false;
            HPRecipes.instance().reloadRecipes();
        }
    }
}
Also used : NetworkManager(net.minecraft.network.NetworkManager) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with NetworkManager

use of net.minecraft.network.NetworkManager in project PneumaticCraft by MineMaarten.

the class EntityDrone method initializeFakePlayer.

private void initializeFakePlayer() {
    fakePlayer = new DroneFakePlayer((WorldServer) worldObj, new GameProfile(playerUUID != null ? UUID.fromString(playerUUID) : null, playerName), new FakePlayerItemInWorldManager(worldObj, fakePlayer, this), this);
    fakePlayer.playerNetServerHandler = new NetHandlerPlayServer(MinecraftServer.getServer(), new NetworkManager(false), fakePlayer);
    fakePlayer.inventory = new InventoryFakePlayer(fakePlayer);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) WorldServer(net.minecraft.world.WorldServer) NetworkManager(net.minecraft.network.NetworkManager) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) FakePlayerItemInWorldManager(pneumaticCraft.common.ai.FakePlayerItemInWorldManager)

Example 4 with NetworkManager

use of net.minecraft.network.NetworkManager in project PneumaticCraft by MineMaarten.

the class TileEntityProgrammableController method initializeFakePlayer.

private void initializeFakePlayer() {
    String playerUUID = null;
    String playerName = "Drone";
    fakePlayer = new DroneFakePlayer((WorldServer) worldObj, new GameProfile(playerUUID != null ? UUID.fromString(playerUUID) : null, playerName), new FakePlayerItemInWorldManager(worldObj, fakePlayer, this), this);
    fakePlayer.playerNetServerHandler = new NetHandlerPlayServer(MinecraftServer.getServer(), new NetworkManager(false), fakePlayer);
    fakePlayer.inventory = new InventoryPlayer(fakePlayer) {

        private ItemStack oldStack;

        @Override
        public int getSizeInventory() {
            return getDroneSlots();
        }

        @Override
        public void setInventorySlotContents(int slot, ItemStack stack) {
            super.setInventorySlotContents(slot, stack);
            if (slot == 0) {
                if (oldStack != null) {
                    getFakePlayer().getAttributeMap().removeAttributeModifiers(oldStack.getAttributeModifiers());
                }
                if (stack != null) {
                    getFakePlayer().getAttributeMap().applyAttributeModifiers(stack.getAttributeModifiers());
                }
                oldStack = stack;
            }
        }
    };
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) GameProfile(com.mojang.authlib.GameProfile) WorldServer(net.minecraft.world.WorldServer) DroneFakePlayer(pneumaticCraft.common.entity.living.EntityDrone.DroneFakePlayer) NetworkManager(net.minecraft.network.NetworkManager) ItemStack(net.minecraft.item.ItemStack) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) FakePlayerItemInWorldManager(pneumaticCraft.common.ai.FakePlayerItemInWorldManager)

Example 5 with NetworkManager

use of net.minecraft.network.NetworkManager in project pnc-repressurized by TeamPneumatic.

the class TileEntityProgrammableController method initializeFakePlayer.

private void initializeFakePlayer() {
    fakePlayer = new DroneFakePlayer((WorldServer) getWorld(), new GameProfile(getOwnerUUID(), ownerName), this);
    fakePlayer.connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer);
    fakePlayer.inventory = new InventoryPlayer(fakePlayer) {

        private ItemStack oldStack = ItemStack.EMPTY;

        @Override
        public int getSizeInventory() {
            return getDroneSlots();
        }

        @Override
        public void setInventorySlotContents(int slot, ItemStack stack) {
            super.setInventorySlotContents(slot, stack);
            if (slot == 0) {
                for (EntityEquipmentSlot ee : EntityEquipmentSlot.values()) {
                    if (!oldStack.isEmpty()) {
                        getFakePlayer().getAttributeMap().removeAttributeModifiers(oldStack.getAttributeModifiers(ee));
                    }
                    if (!stack.isEmpty()) {
                        getFakePlayer().getAttributeMap().applyAttributeModifiers(stack.getAttributeModifiers(ee));
                    }
                }
                oldStack = stack;
            }
        }
    };
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) GameProfile(com.mojang.authlib.GameProfile) WorldServer(net.minecraft.world.WorldServer) DroneFakePlayer(me.desht.pneumaticcraft.common.entity.living.EntityDrone.DroneFakePlayer) NetworkManager(net.minecraft.network.NetworkManager) ItemStack(net.minecraft.item.ItemStack) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer)

Aggregations

NetworkManager (net.minecraft.network.NetworkManager)8 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)5 GameProfile (com.mojang.authlib.GameProfile)4 WorldServer (net.minecraft.world.WorldServer)4 ItemStack (net.minecraft.item.ItemStack)3 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)2 FakePlayerItemInWorldManager (pneumaticCraft.common.ai.FakePlayerItemInWorldManager)2 HashMap (java.util.HashMap)1 DroneFakePlayer (me.desht.pneumaticcraft.common.entity.living.EntityDrone.DroneFakePlayer)1 Enchantment (net.minecraft.enchantment.Enchantment)1 EntityEquipmentSlot (net.minecraft.inventory.EntityEquipmentSlot)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 Packet (net.minecraft.network.Packet)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 Side (net.minecraftforge.fml.relauncher.Side)1 DroneFakePlayer (pneumaticCraft.common.entity.living.EntityDrone.DroneFakePlayer)1