net.minecraft.network.play.INetHandlerPlayServer Java Examples

The following examples show how to use net.minecraft.network.play.INetHandlerPlayServer. 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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: MixinCPacketPlayer.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@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 #5
Source File: ITransformablePacket.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: TranslocatorSPH.java    From Translocators with MIT License 5 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer handler) {
    switch (packet.getType()) {
        case 1:
            Translocator.blockCraftingGrid.placeBlock(sender.worldObj, sender, packet.readInt(), packet.readInt(), packet.readInt(), packet.readUByte());
            break;
        case 2:
            TileEntity tile = sender.worldObj.getTileEntity(packet.readInt(), packet.readInt(), packet.readInt());
            if (tile instanceof TileCraftingGrid)
                ((TileCraftingGrid) tile).craft(sender);
            break;
    }
}
 
Example #7
Source File: ChunkLoaderSPH.java    From ChickenChunks with MIT License 5 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer handler) {
    switch(packet.getType())
    {
        case 1:
            PlayerChunkViewerManager.instance().closeViewer(sender.getCommandSenderName());
            break;
        case 2:
            handleChunkLoaderChangePacket(sender.worldObj, packet);
            break;
        
    }
}
 
Example #8
Source File: EnderStorageSPH.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer handler) {
    switch (packet.getType()) {
        case 1:
            TankSynchroniser.handleVisiblityPacket(sender, packet);
            break;
    }
}
 
Example #9
Source File: MixinCPacketPlayer.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: MixinCPacketPlayerDigging.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "HEAD"))
public void preDiggingProcessPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPreProcessing(server, false);
}
 
Example #11
Source File: MixinCPacketPlayerDigging.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "RETURN"))
public void postDiggingProcessPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPostProcessing(server, false);
}
 
Example #12
Source File: MixinCPacketUpdateSign.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "HEAD"))
public void preHandleUseItemPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPreProcessing(server, false);
}
 
Example #13
Source File: MixinCPacketUpdateSign.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "RETURN"))
public void postHandleUseItemPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPostProcessing(server, false);
}
 
Example #14
Source File: MixinCPacketPlayerTryUseItemOnBlock.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "HEAD"))
public void preHandleUseItemPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPreProcessing(server, false);
}
 
Example #15
Source File: MixinCPacketPlayerTryUseItemOnBlock.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "RETURN"))
public void postHandleUseItemPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPostProcessing(server, false);
}
 
Example #16
Source File: NEIServerPacketHandler.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer netHandler) {
    if (!NEIServerConfig.authenticatePacket(sender, packet)) {
        return;
    }

    switch (packet.getType()) {
        case 1:
            handleGiveItem(sender, packet);
            break;
        case 4:
            NEIServerUtils.deleteAllItems(sender);
            break;
        case 5:
            setInventorySlot(sender, packet);
            break;
        case 6:
            NEIServerUtils.toggleMagnetMode(sender);
            break;
        case 7:
            NEIServerUtils.setHourForward(sender.world, packet.readUByte(), true);
            break;
        case 8:
            NEIServerUtils.healPlayer(sender);
            break;
        case 9:
            NEIServerUtils.toggleRaining(sender.world, true);
            break;
        case 10:
            sendLoginState(sender);
            break;
        case 11:
            sender.sendAllContents(sender.openContainer, sender.openContainer.getInventory());
            break;
        case 12:
            handleActionDisableStateChange(sender, packet);
            break;
        case 13:
            NEIServerUtils.setGamemode(sender, packet.readUByte());
            break;
        case 14:
            NEIServerUtils.cycleCreativeInv(sender, packet.readInt());
            break;
        case 15:
            handleMobSpawnerID(sender.world, packet.readPos(), packet.readString());
            break;
        case 20:
            handleContainerPacket(sender, packet);
            break;
        case 21:
            openEnchantmentGui(sender);
            break;
        case 22:
            modifyEnchantment(sender, packet.readUByte(), packet.readUByte(), packet.readBoolean());
            break;
        case 23:
            processCreativeInv(sender, packet.readBoolean());
            break;
        case 24:
            openPotionGui(sender, packet);
            break;
        case 25:
            handleDummySlotSet(sender, packet);
            break;
    }
}
 
Example #17
Source File: MixinCPacketPlayer.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
private EntityPlayerMP getPacketPlayer(INetHandlerPlayServer server) {
    return ((NetHandlerPlayServer) server).player;
}
 
Example #18
Source File: NEISPH.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer netHandler) {
    if (!NEIServerConfig.authenticatePacket(sender, packet))
        return;

    switch (packet.getType()) {
        case 1:
            handleGiveItem(sender, packet);
            break;
        case 4:
            NEIServerUtils.deleteAllItems(sender);
            break;
        case 5:
            setInventorySlot(sender, packet);
            break;
        case 6:
            NEIServerUtils.toggleMagnetMode(sender);
            break;
        case 7:
            NEIServerUtils.setHourForward(sender.worldObj, packet.readUByte(), true);
            break;
        case 8:
            NEIServerUtils.healPlayer(sender);
            break;
        case 9:
            NEIServerUtils.toggleRaining(sender.worldObj, true);
            break;
        case 10:
            sendLoginState(sender);
            break;
        case 11:
            sender.updateCraftingInventory(sender.openContainer, sender.openContainer.getInventory());
            break;
        case 12:
            handlePropertyChange(sender, packet);
            break;
        case 13:
            NEIServerUtils.setGamemode(sender, packet.readUByte());
            break;
        case 14:
            NEIServerUtils.cycleCreativeInv(sender, packet.readInt());
            break;
        case 15:
            handleMobSpawnerID(sender.worldObj, packet.readCoord(), packet.readString());
            break;
        case 20:
            handleContainerPacket(sender, packet);
            break;
        case 21:
            openEnchantmentGui(sender);
            break;
        case 22:
            modifyEnchantment(sender, packet.readUByte(), packet.readUByte(), packet.readBoolean());
            break;
        case 23:
            processCreativeInv(sender, packet.readBoolean());
            break;
        case 24:
            openPotionGui(sender, packet);
            break;
        case 25:
            handleDummySlotSet(sender, packet);
            break;
    }
}
 
Example #19
Source File: MixinCPacketPlayer.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "RETURN"))
public void postDiggingProcessPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPostProcessing(server, false);
}
 
Example #20
Source File: WRAddonSPH.java    From WirelessRedstone with MIT License 4 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer handler) {
    handlePacket((WorldServer) sender.worldObj, sender, packet);
}
 
Example #21
Source File: WRCoreSPH.java    From WirelessRedstone with MIT License 4 votes vote down vote up
@Override
public void handlePacket(PacketCustom packet, EntityPlayerMP sender, INetHandlerPlayServer handler) {
    handlePacket((WorldServer) sender.worldObj, sender, packet);
    for(IServerPacketHandler delegate : delegates)
        delegate.handlePacket(packet, sender, handler);
}
 
Example #22
Source File: MixinCPacketPlayer.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
@Inject(method = "processPacket", at = @At(value = "HEAD"))
public void preDiggingProcessPacket(INetHandlerPlayServer server, CallbackInfo info) {
    this.doPreProcessing(server, false);
}
 
Example #23
Source File: PacketCustom.java    From CodeChickenLib with GNU Lesser General Public License v2.1 votes vote down vote up
public void handlePacket(PacketCustom packetCustom, EntityPlayerMP sender, INetHandlerPlayServer handler);