Search in sources :

Example 1 with IEClientPlayNetworkHandler

use of com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler in project ImmersivePortalsMod by qouteall.

the class ClientWorldLoader method createFakedClientWorld.

// fool minecraft using the faked world
private ClientWorld createFakedClientWorld(DimensionType dimension) {
    assert mc.world.dimension.getType() == mc.player.dimension;
    assert (mc.player.dimension != dimension);
    isLoadingFakedWorld = true;
    // TODO get load distance
    int chunkLoadDistance = 3;
    WorldRenderer worldRenderer = new WorldRenderer(mc);
    ClientWorld newWorld;
    try {
        ClientPlayNetworkHandler newNetworkHandler = new ClientPlayNetworkHandler(mc, new ChatScreen("You should not be seeing me. I'm just a faked screen."), new ClientConnection(NetworkSide.CLIENTBOUND), new GameProfile(null, "faked_profiler_id"));
        // multiple net handlers share the same playerListEntries object
        ((IEClientPlayNetworkHandler) newNetworkHandler).setPlayerListEntries(((IEClientPlayNetworkHandler) mc.player.networkHandler).getPlayerListEntries());
        newWorld = new ClientWorld(newNetworkHandler, new LevelInfo(0L, GameMode.CREATIVE, true, isHardCore, LevelGeneratorType.FLAT), dimension, chunkLoadDistance, mc.getProfiler(), worldRenderer);
    } catch (Exception e) {
        throw new IllegalStateException("Creating Faked World " + dimension + " " + clientWorldMap.keySet(), e);
    }
    worldRenderer.setWorld(newWorld);
    worldRenderer.apply(mc.getResourceManager());
    ((IEClientPlayNetworkHandler) ((IEClientWorld) newWorld).getNetHandler()).setWorld(newWorld);
    clientWorldMap.put(dimension, newWorld);
    worldRendererMap.put(dimension, worldRenderer);
    Helper.log("Faked World Created " + dimension);
    isLoadingFakedWorld = false;
    return newWorld;
}
Also used : ChatScreen(net.minecraft.client.gui.screen.ChatScreen) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) GameProfile(com.mojang.authlib.GameProfile) LevelInfo(net.minecraft.world.level.LevelInfo) ClientConnection(net.minecraft.network.ClientConnection) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) WorldRenderer(net.minecraft.client.render.WorldRenderer) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Example 2 with IEClientPlayNetworkHandler

use of com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler in project ImmersivePortalsMod by qouteall.

the class MyNetworkClient method processRedirectedPacket.

private static void processRedirectedPacket(DimensionType dimension, Packet packet) {
    MinecraftClient mc = MinecraftClient.getInstance();
    mc.execute(() -> {
        ClientWorld packetWorld = CGlobal.clientWorldLoader.getOrCreateFakedWorld(dimension);
        assert packetWorld != null;
        assert packetWorld.getChunkManager() instanceof MyClientChunkManager;
        ClientPlayNetworkHandler netHandler = ((IEClientWorld) packetWorld).getNetHandler();
        if ((netHandler).getWorld() != packetWorld) {
            ((IEClientPlayNetworkHandler) netHandler).setWorld(packetWorld);
            Helper.err("The world field of client net handler is wrong");
        }
        ClientWorld originalWorld = mc.world;
        // some packet handling may use mc.world so switch it
        mc.world = packetWorld;
        try {
            packet.apply(netHandler);
        } catch (Throwable e) {
            throw new IllegalStateException("handling packet in " + dimension, e);
        } finally {
            mc.world = originalWorld;
        }
    });
}
Also used : IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) MinecraftClient(net.minecraft.client.MinecraftClient) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) MyClientChunkManager(com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)

Example 3 with IEClientPlayNetworkHandler

use of com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler in project ImmersivePortalsMod by qouteall.

the class ClientTeleportationManager method changePlayerDimension.

/**
 * {@link ClientPlayNetworkHandler#onPlayerRespawn(PlayerRespawnS2CPacket)}
 */
private void changePlayerDimension(ClientPlayerEntity player, ClientWorld fromWorld, ClientWorld toWorld, Vec3d destination) {
    DimensionType toDimension = toWorld.dimension.getType();
    DimensionType fromDimension = fromWorld.dimension.getType();
    ClientPlayNetworkHandler workingNetHandler = ((IEClientWorld) fromWorld).getNetHandler();
    ClientPlayNetworkHandler fakedNetHandler = ((IEClientWorld) toWorld).getNetHandler();
    ((IEClientPlayNetworkHandler) workingNetHandler).setWorld(toWorld);
    ((IEClientPlayNetworkHandler) fakedNetHandler).setWorld(fromWorld);
    ((IEClientWorld) fromWorld).setNetHandler(fakedNetHandler);
    ((IEClientWorld) toWorld).setNetHandler(workingNetHandler);
    fromWorld.removeEntity(player.getEntityId());
    player.removed = false;
    player.world = toWorld;
    player.dimension = toDimension;
    player.x = destination.x;
    player.y = destination.y;
    player.z = destination.z;
    toWorld.addPlayer(player.getEntityId(), player);
    mc.world = toWorld;
    mc.worldRenderer = CGlobal.clientWorldLoader.getWorldRenderer(toDimension);
    toWorld.setScoreboard(fromWorld.getScoreboard());
    if (mc.particleManager != null)
        mc.particleManager.setWorld(toWorld);
    BlockEntityRenderDispatcher.INSTANCE.setWorld(toWorld);
    CGlobal.clientWorldLoader.getDimensionRenderHelper(toDimension).switchToMe();
    Helper.log(String.format("Client Changed Dimension from %s to %s time: %s", fromDimension, toDimension, tickTimeForTeleportation));
    Helper.log("Portal Number Near Player Now" + McHelper.getEntitiesNearby(mc.player, Portal.class, 10).count());
    // because the teleportation may happen before rendering
    // but after pre render info being updated
    MyRenderHelper.updatePreRenderInfo(MyRenderHelper.partialTicks);
    OFInterface.onPlayerTraveled.accept(fromDimension, toDimension);
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) Portal(com.qouteall.immersive_portals.portal.Portal) IEClientPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler) ClientPlayNetworkHandler(net.minecraft.client.network.ClientPlayNetworkHandler)

Aggregations

IEClientPlayNetworkHandler (com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)3 IEClientWorld (com.qouteall.immersive_portals.ducks.IEClientWorld)3 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)3 ClientWorld (net.minecraft.client.world.ClientWorld)2 GameProfile (com.mojang.authlib.GameProfile)1 MyClientChunkManager (com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager)1 Portal (com.qouteall.immersive_portals.portal.Portal)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 ChatScreen (net.minecraft.client.gui.screen.ChatScreen)1 WorldRenderer (net.minecraft.client.render.WorldRenderer)1 ClientConnection (net.minecraft.network.ClientConnection)1 DimensionType (net.minecraft.world.dimension.DimensionType)1 LevelInfo (net.minecraft.world.level.LevelInfo)1