net.minecraft.network.NetHandlerPlayServer Java Examples
The following examples show how to use
net.minecraft.network.NetHandlerPlayServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ITransformablePacket.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
/** * Puts the player into local coordinates and makes a record of where they used to be. */ default void doPreProcessing(INetHandlerPlayServer server, boolean callingFromSponge) { if (isPacketOnMainThread(server, callingFromSponge)) { // System.out.println("Pre packet process"); NetHandlerPlayServer serverHandler = (NetHandlerPlayServer) server; EntityPlayerMP player = serverHandler.player; PhysicsWrapperEntity wrapper = getPacketParent(serverHandler); if (wrapper != null && wrapper.getPhysicsObject().getShipTransformationManager() != null) { ISubspaceProvider worldProvider = (ISubspaceProvider) player.getServerWorld(); ISubspace worldSubspace = worldProvider.getSubspace(); worldSubspace.snapshotSubspacedEntity((ISubspacedEntity) player); wrapper.getPhysicsObject().getShipTransformationManager() .getCurrentTickTransform().transform(player, TransformType.GLOBAL_TO_SUBSPACE); } } }
Example #2
Source File: ITransformablePacket.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
/** * Restores the player from local coordinates to where they used to be. */ default void doPostProcessing(INetHandlerPlayServer server, boolean callingFromSponge) { if (isPacketOnMainThread(server, callingFromSponge)) { NetHandlerPlayServer serverHandler = (NetHandlerPlayServer) server; EntityPlayerMP player = serverHandler.player; PhysicsWrapperEntity wrapper = getPacketParent(serverHandler); // I don't care what happened to that ship in the time between, we must restore // the player to their proper coordinates. ISubspaceProvider worldProvider = (ISubspaceProvider) player.getServerWorld(); ISubspace worldSubspace = worldProvider.getSubspace(); ISubspacedEntity subspacedEntity = (ISubspacedEntity) player; ISubspacedEntityRecord record = worldSubspace .getRecordForSubspacedEntity(subspacedEntity); // System.out.println(player.getPosition()); if (subspacedEntity.currentSubspaceType() == CoordinateSpaceType.SUBSPACE_COORDINATES) { subspacedEntity.restoreSubspacedEntityStateToRecord(record); player.setPosition(player.posX, player.posY, player.posZ); } // System.out.println(player.getPosition()); // We need this because Sponge Mixins prevent this from properly working. This // won't be necessary on client however. } }
Example #3
Source File: PacketPipeline.java From NBTEdit with GNU General Public License v3.0 | 6 votes |
@Override protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception { ByteBuf payload = msg.payload(); byte discriminator = payload.readByte(); Class<? extends AbstractPacket> clazz = this.packets.get(discriminator); AbstractPacket pkt = clazz.newInstance(); pkt.decodeInto(ctx, payload.slice()); switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: pkt.handleClientSide(this.getClientPlayer()); break; case SERVER: INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); pkt.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity); break; default: break; } out.add(pkt); }
Example #4
Source File: MixinCPacketPlayer.java From Valkyrien-Skies with Apache License 2.0 | 6 votes |
@Override public void doPostProcessing(INetHandlerPlayServer server, boolean callingFromSponge) { if (isPacketOnMainThread(server, callingFromSponge)) { // ===== Dangerous code here ===== if (cachedPlayerGameType != null) { getPacketPlayer(server).interactionManager.gameType = cachedPlayerGameType; } PhysicsWrapperEntity parent = getPacketParent((NetHandlerPlayServer) server); if (parent != null) { parent.getPhysicsObject().getSubspace() .forceSubspaceRecord((ISubspacedEntity) getPacketPlayer(server), null); } IDraggable draggable = (IDraggable) getPacketPlayer(server); draggable.setForcedRelativeSubspace(null); } }
Example #5
Source File: MCPacketHandler.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer()); break; case SERVER: packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity); break; default: break; } }
Example #6
Source File: MCPacketHandler.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: FMLClientHandler.instance().getClient().addScheduledTask(() -> packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer())); break; case SERVER: FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity)); break; default: break; } }
Example #7
Source File: MCPacketHandler.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception { INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); switch (FMLCommonHandler.instance().getEffectiveSide()) { case CLIENT: FMLClientHandler.instance().getClient().addScheduledTask(() -> packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer())); break; case SERVER: FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> packet.handleServerSide(((NetHandlerPlayServer) netHandler).player)); break; default: break; } }
Example #8
Source File: NetworkHandler.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@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)); } } }
Example #9
Source File: OpenClientProxy.java From OpenModsLib with MIT License | 5 votes |
@Override public EntityPlayer getPlayerFromHandler(INetHandler handler) { if (handler instanceof NetHandlerPlayServer) return ((NetHandlerPlayServer)handler).player; if (handler instanceof NetHandlerPlayClient) return getThePlayer(); return null; }
Example #10
Source File: TileEntityProgrammableController.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
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; } } }; }
Example #11
Source File: PacketCustom.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof NetworkHandshakeEstablished) { INetHandler netHandler = ((NetworkDispatcher) ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).get()).getNetHandler(); if (netHandler instanceof NetHandlerPlayServer) handler.handshakeRecieved((NetHandlerPlayServer) netHandler); } else ctx.fireUserEventTriggered(evt); }
Example #12
Source File: PacketCustom.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void handle(final INetHandler netHandler, final String channel, final PacketCustom packet) { if (netHandler instanceof NetHandlerPlayServer) { MinecraftServer mc = MinecraftServer.getServer(); if (!mc.isCallingFromMinecraftThread()) mc.addScheduledTask(new Runnable() { public void run() { handle(netHandler, channel, packet); } }); else handler.handlePacket(packet, ((NetHandlerPlayServer) netHandler).playerEntity, (INetHandlerPlayServer) netHandler); } else System.err.println("Invalid INetHandler for PacketCustom on channel: " + channel); }
Example #13
Source File: PacketHandler.java From qcraft-mod with Apache License 2.0 | 5 votes |
@SubscribeEvent public void onServerPacket( FMLNetworkEvent.ServerCustomPacketEvent event ) { try { QCraftPacket packet = new QCraftPacket(); packet.fromBytes( event.packet.payload() ); QCraft.handleServerPacket( packet, ((NetHandlerPlayServer)event.handler).playerEntity ); } catch( Exception e ) { // Something failed, ignore it e.printStackTrace(); } }
Example #14
Source File: MixinPacketUtil.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Inject(method = "onProcessPacket", at = @At(value = "RETURN")) private static void postOnProcessPacket(Packet packetIn, INetHandler netHandler, CallbackInfo info) { if (packetIn instanceof ITransformablePacket) { ITransformablePacket transformPacket = (ITransformablePacket) packetIn; transformPacket.doPostProcessing((NetHandlerPlayServer) netHandler, true); } }
Example #15
Source File: MixinPacketUtil.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Inject(method = "onProcessPacket", at = @At(value = "HEAD")) private static void preOnProcessPacket(Packet packetIn, INetHandler netHandler, CallbackInfo info) { if (packetIn instanceof ITransformablePacket) { ITransformablePacket transformPacket = (ITransformablePacket) packetIn; transformPacket.doPreProcessing((NetHandlerPlayServer) netHandler, true); } }
Example #16
Source File: MixinCPacketPlayerTryUseItemOnBlock.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Override public PhysicsWrapperEntity getPacketParent(NetHandlerPlayServer server) { World world = server.player.getEntityWorld(); Optional<PhysicsObject> physicsObject = ValkyrienUtils .getPhysicsObject(world, thisPacketTryUse.getPos()); if (physicsObject.isPresent()) { return physicsObject.get() .getWrapperEntity(); } else { return null; } }
Example #17
Source File: MixinCPacketUpdateSign.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Override public PhysicsWrapperEntity getPacketParent(NetHandlerPlayServer server) { World world = server.player.getEntityWorld(); Optional<PhysicsObject> physicsObject = ValkyrienUtils .getPhysicsObject(world, thisAsPacketSign.getPosition()); return physicsObject.map(PhysicsObject::getWrapperEntity).orElse(null); }
Example #18
Source File: MixinCPacketPlayerDigging.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Override public PhysicsWrapperEntity getPacketParent(NetHandlerPlayServer server) { World world = server.player.getEntityWorld(); Optional<PhysicsObject> physicsObject = ValkyrienUtils .getPhysicsObject(world, thisPacketTryUse.getPosition()); if (physicsObject.isPresent()) { return physicsObject.get() .getWrapperEntity(); } else { return null; } }
Example #19
Source File: MixinCPacketPlayer.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
@Override public void doPreProcessing(INetHandlerPlayServer server, boolean callingFromSponge) { if (isPacketOnMainThread(server, callingFromSponge)) { PhysicsWrapperEntity parent = getPacketParent((NetHandlerPlayServer) server); if (parent != null) { ISubspace parentSubspace = parent.getPhysicsObject().getSubspace(); ISubspacedEntityRecord entityRecord = parentSubspace .getRecordForSubspacedEntity((ISubspacedEntity) getPacketPlayer(server)); VectorImmutable positionGlobal = entityRecord.getPositionInGlobalCoordinates(); VectorImmutable lookVectorGlobal = entityRecord .getLookDirectionInGlobalCoordinates(); float pitch = (float) VSMath.getPitchFromVectorImmutable(lookVectorGlobal); float yaw = (float) VSMath.getYawFromVectorImmutable(lookVectorGlobal, pitch); // ===== Set the proper position values for the player packet ==== thisPacket.moving = true; thisPacket.onGround = true; thisPacket.x = positionGlobal.getX(); thisPacket.y = positionGlobal.getY(); thisPacket.z = positionGlobal.getZ(); // ===== Set the proper rotation values for the player packet ===== thisPacket.rotating = true; thisPacket.yaw = yaw; thisPacket.pitch = pitch; // ===== Dangerous code here ===== cachedPlayerGameType = getPacketPlayer(server).interactionManager.gameType; getPacketPlayer(server).interactionManager.gameType = GameType.CREATIVE; } } }
Example #20
Source File: ITransformablePacket.java From Valkyrien-Skies with Apache License 2.0 | 5 votes |
default boolean isPacketOnMainThread(INetHandlerPlayServer server, boolean callingFromSponge) { if (!MixinLoadManager.isSpongeEnabled() || callingFromSponge) { NetHandlerPlayServer serverHandler = (NetHandlerPlayServer) server; EntityPlayerMP player = serverHandler.player; return player.getServerWorld().isCallingFromMinecraftThread(); } else { return false; } }
Example #21
Source File: CraftPlayer.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public void setScoreboard(Scoreboard scoreboard) { Validate.notNull(scoreboard, "Scoreboard cannot be null"); NetHandlerPlayServer connection = getHandle().connection; if (connection == null) { return; } if (connection.isDisconnected()) { } this.server.getScoreboardManager().setPlayerBoard(this, scoreboard); }
Example #22
Source File: LookingGlassPacketManager.java From LookingGlass with GNU General Public License v3.0 | 4 votes |
@SubscribeEvent public void onPacketData(ServerCustomPacketEvent event) { FMLProxyPacket pkt = event.packet; onPacketData(event.manager, pkt, ((NetHandlerPlayServer) event.handler).playerEntity); }
Example #23
Source File: MixinCPacketPlayer.java From Valkyrien-Skies with Apache License 2.0 | 4 votes |
private EntityPlayerMP getPacketPlayer(INetHandlerPlayServer server) { return ((NetHandlerPlayServer) server).player; }
Example #24
Source File: MixinCPacketPlayer.java From Valkyrien-Skies with Apache License 2.0 | 4 votes |
@Override public PhysicsWrapperEntity getPacketParent(NetHandlerPlayServer server) { EntityPlayerMP player = server.player; IDraggable draggable = (IDraggable) player; return draggable.getForcedSubspaceBelowFeet(); }
Example #25
Source File: ASMessagePipeline.java From archimedes-ships with MIT License | 4 votes |
@Override protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception { ByteBuf payload = msg.payload(); byte discriminator = payload.readByte(); Class<? extends ASMessage> clazz = packets.get(discriminator); if (clazz == null) { throw new NullPointerException("No packet registered for discriminator: " + discriminator); } EntityPlayer player = null; Side side = FMLCommonHandler.instance().getEffectiveSide(); switch (side) { case CLIENT: player = getClientPlayer(); break; case SERVER: INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); player = ((NetHandlerPlayServer) netHandler).playerEntity; break; default: } ASMessage pkt = clazz.newInstance(); try { pkt.decodeInto(ctx, payload.slice(), player); } catch (IOException e) { e.printStackTrace(); throw e; } switch (side) { case CLIENT: pkt.handleClientSide(player); break; case SERVER: pkt.handleServerSide(player); break; default: } out.add(pkt); }
Example #26
Source File: EntityDrone.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
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); }
Example #27
Source File: NetworkHandler.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public static <T extends Packet> void registerServerExecutor(Class<T> packet, PacketExecutor<T, NetHandlerPlayServer> executor) { serverExecutors.put(packet, executor); }
Example #28
Source File: OpenServerProxy.java From OpenModsLib with MIT License | 4 votes |
@Override public EntityPlayer getPlayerFromHandler(INetHandler handler) { if (handler instanceof NetHandlerPlayServer) return ((NetHandlerPlayServer)handler).player; return null; }
Example #29
Source File: ITransformablePacket.java From Valkyrien-Skies with Apache License 2.0 | votes |
PhysicsWrapperEntity getPacketParent(NetHandlerPlayServer server);
Example #30
Source File: PacketCustom.java From CodeChickenLib with GNU Lesser General Public License v2.1 | votes |
public void handshakeRecieved(NetHandlerPlayServer netHandler);