Search in sources :

Example 1 with INetHandlerPlayServer

use of net.minecraft.network.play.INetHandlerPlayServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ITransformablePacket method isPacketOnMainThread.

default boolean isPacketOnMainThread(INetHandlerPlayServer server, boolean callingFromSponge) {
    if (!ValkyrienSkiesMod.isSpongePresent() || callingFromSponge) {
        NetHandlerPlayServer serverHandler = (NetHandlerPlayServer) server;
        EntityPlayerMP player = serverHandler.player;
        return player.getServerWorld().isCallingFromMinecraftThread();
    } else {
        return false;
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) INetHandlerPlayServer(net.minecraft.network.play.INetHandlerPlayServer)

Example 2 with INetHandlerPlayServer

use of net.minecraft.network.play.INetHandlerPlayServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ITransformablePacket method doPostProcessing.

/**
 * 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;
        // If we made a backup in doPreProcessing(), then restore from that backup.
        ICapabilityEntityBackup entityBackup = player.getCapability(VSCapabilityRegistry.VS_ENTITY_BACKUP, null);
        if (entityBackup.hasBackupPosition()) {
            entityBackup.restoreEntityToBackup(player);
        }
    }
}
Also used : ICapabilityEntityBackup(org.valkyrienskies.mod.common.capability.entity_backup.ICapabilityEntityBackup) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) INetHandlerPlayServer(net.minecraft.network.play.INetHandlerPlayServer)

Example 3 with INetHandlerPlayServer

use of net.minecraft.network.play.INetHandlerPlayServer in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class ITransformablePacket method doPreProcessing.

/**
 * 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;
        ShipData physicsObject = getPacketParent(serverHandler);
        if (physicsObject != null) {
            // First make a backup of the player position
            ICapabilityEntityBackup entityBackup = player.getCapability(VSCapabilityRegistry.VS_ENTITY_BACKUP, null);
            entityBackup.backupEntityPosition(player);
            // Then put the player into ship coordinates.
            physicsObject.getShipTransform().transform(player, TransformType.GLOBAL_TO_SUBSPACE, true);
        }
    }
}
Also used : ShipData(org.valkyrienskies.mod.common.ships.ShipData) ICapabilityEntityBackup(org.valkyrienskies.mod.common.capability.entity_backup.ICapabilityEntityBackup) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) INetHandlerPlayServer(net.minecraft.network.play.INetHandlerPlayServer)

Aggregations

EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)3 INetHandlerPlayServer (net.minecraft.network.play.INetHandlerPlayServer)3 ICapabilityEntityBackup (org.valkyrienskies.mod.common.capability.entity_backup.ICapabilityEntityBackup)2 ShipData (org.valkyrienskies.mod.common.ships.ShipData)1