Search in sources :

Example 16 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project artisan-worktables by codetaylor.

the class SPacketWorktableTab method onMessage.

@Override
public IMessage onMessage(SPacketWorktableTab message, MessageContext ctx, TileEntity tileEntity) {
    // Reference:
    // https://github.com/SlimeKnights/TinkersConstruct/blob/master/src/main/java/slimeknights/tconstruct/tools/common/network/TinkerStationTabPacket.java
    NetHandlerPlayServer serverHandler = ctx.getServerHandler();
    EntityPlayerMP player = serverHandler.player;
    ItemStack heldStack = player.inventory.getItemStack();
    if (!heldStack.isEmpty()) {
        player.inventory.setItemStack(ItemStack.EMPTY);
    }
    if (tileEntity instanceof TileEntityBase) {
        player.openGui(ModuleWorktables.MOD_INSTANCE, 1, player.getEntityWorld(), message.blockPos.getX(), message.blockPos.getY(), message.blockPos.getZ());
    }
    if (!heldStack.isEmpty()) {
        player.inventory.setItemStack(heldStack);
        serverHandler.sendPacket(new SPacketSetSlot(-1, -1, heldStack));
    }
    return null;
}
Also used : TileEntityBase(com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase) SPacketTileEntityBase(com.codetaylor.mc.athenaeum.spi.packet.SPacketTileEntityBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(net.minecraft.item.ItemStack) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer)

Example 17 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project SpongeForge by SpongePowered.

the class SpongeModNetworkManager method onCustomPacketRegistration.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onCustomPacketRegistration(CustomPacketRegistrationEvent<?> event) {
    Set<String> channels = ((IMixinNetPlayHandler) event.getHandler()).getRegisteredChannels();
    ;
    final boolean isMainThread = Sponge.isServerAvailable() && Sponge.getServer().isMainThread();
    try (final CauseStackManager.StackFrame frame = isMainThread ? Sponge.getCauseStackManager().pushCauseFrame() : null) {
        if (isMainThread) {
            if (event.getHandler() instanceof NetHandlerPlayServer) {
                Sponge.getCauseStackManager().pushCause(((NetHandlerPlayServer) event.getHandler()).player);
            }
            Sponge.getCauseStackManager().addContext(NET_HANDLER, event.getHandler());
        }
        if (event.getOperation().equals("REGISTER")) {
            channels.addAll(event.getRegistrations());
            for (String channel : event.getRegistrations()) {
                final Cause currentCause = isMainThread ? Sponge.getCauseStackManager().getCurrentCause() : Cause.of(EventContext.empty(), Sponge.getGame());
                SpongeImpl.postEvent(SpongeEventFactory.createChannelRegistrationEventRegister(currentCause, channel));
            }
        } else if (event.getOperation().equals("UNREGISTER")) {
            channels.removeAll(event.getRegistrations());
            for (String channel : event.getRegistrations()) {
                final Cause currentCause = isMainThread ? Sponge.getCauseStackManager().getCurrentCause() : Cause.of(EventContext.empty(), Sponge.getGame());
                SpongeImpl.postEvent(SpongeEventFactory.createChannelRegistrationEventUnregister(currentCause, channel));
            }
        }
    }
}
Also used : CauseStackManager(org.spongepowered.api.event.CauseStackManager) Cause(org.spongepowered.api.event.cause.Cause) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) IMixinNetPlayHandler(org.spongepowered.mod.interfaces.IMixinNetPlayHandler) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 18 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project ForestryMC by ForestryMC.

the class PacketHandler method onPacket.

@SubscribeEvent
public void onPacket(ServerCustomPacketEvent event) {
    PacketBufferForestry data = new PacketBufferForestry(event.getPacket().payload());
    EntityPlayerMP player = ((NetHandlerPlayServer) event.getHandler()).player;
    byte packetIdOrdinal = data.readByte();
    PacketIdServer packetId = PacketIdServer.VALUES[packetIdOrdinal];
    IForestryPacketHandlerServer packetHandler = packetId.getPacketHandler();
    checkThreadAndEnqueue(packetHandler, data, player, player.getServerWorld());
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 19 with NetHandlerPlayServer

use of net.minecraft.network.NetHandlerPlayServer in project GregTech by GregTechCE.

the class NetworkHandler method onServerPacket.

@SubscribeEvent
@SuppressWarnings("unchecked")
public void onServerPacket(FMLNetworkEvent.ServerCustomPacketEvent event) {
    Packet packet = proxy2packet(event.getPacket());
    if (serverExecutors.containsKey(packet.getClass())) {
        PacketExecutor<Packet, NetHandlerPlayServer> executor = (PacketExecutor<Packet, NetHandlerPlayServer>) serverExecutors.get(packet.getClass());
        NetHandlerPlayServer handler = (NetHandlerPlayServer) event.getHandler();
        IThreadListener threadListener = FMLCommonHandler.instance().getWorldThread(handler);
        if (threadListener.isCallingFromMinecraftThread()) {
            executor.execute(packet, handler);
        } else {
            threadListener.addScheduledTask(() -> executor.execute(packet, handler));
        }
    }
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) IThreadListener(net.minecraft.util.IThreadListener) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 20 with NetHandlerPlayServer

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

the class EntityDrone method initializeFakePlayer.

private void initializeFakePlayer() {
    fakePlayer = new DroneFakePlayer((WorldServer) world, new GameProfile(UUID.fromString(getOwnerUUID()), playerName), this);
    fakePlayer.connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), 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)

Aggregations

NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)26 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)16 ItemStack (net.minecraft.item.ItemStack)6 GameProfile (com.mojang.authlib.GameProfile)5 NetworkManager (net.minecraft.network.NetworkManager)5 WorldServer (net.minecraft.world.WorldServer)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)3 SaveDirectoryData (ivorius.reccomplex.utils.SaveDirectoryData)3 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 INetHandlerPlayServer (net.minecraft.network.play.INetHandlerPlayServer)3 Entity (net.minecraft.entity.Entity)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 SPacketCustomPayload (net.minecraft.network.play.server.SPacketCustomPayload)2 SPacketSetSlot (net.minecraft.network.play.server.SPacketSetSlot)2 Player (org.spongepowered.api.entity.living.player.Player)2 CauseStackManager (org.spongepowered.api.event.CauseStackManager)2 ICapabilityEntityBackup (org.valkyrienskies.mod.common.capability.entity_backup.ICapabilityEntityBackup)2 FakePlayerItemInWorldManager (pneumaticCraft.common.ai.FakePlayerItemInWorldManager)2