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;
}
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));
}
}
}
}
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());
}
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));
}
}
}
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);
}
Aggregations