Search in sources :

Example 1 with IEClientWorld

use of com.qouteall.immersive_portals.ducks.IEClientWorld 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 IEClientWorld

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

the class MyNetworkClient method processGlobalPortalUpdate.

private static void processGlobalPortalUpdate(PacketContext context, PacketByteBuf buf) {
    DimensionType dimensionType = DimensionType.byRawId(buf.readInt());
    CompoundTag compoundTag = buf.readCompoundTag();
    MinecraftClient.getInstance().execute(() -> {
        ClientWorld world = CGlobal.clientWorldLoader.getOrCreateFakedWorld(dimensionType);
        List<GlobalTrackedPortal> portals = GlobalPortalStorage.getPortalsFromTag(compoundTag, world);
        ((IEClientWorld) world).setGlobalPortals(portals);
    });
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) CompoundTag(net.minecraft.nbt.CompoundTag) GlobalTrackedPortal(com.qouteall.immersive_portals.portal.global_portals.GlobalTrackedPortal)

Example 3 with IEClientWorld

use of com.qouteall.immersive_portals.ducks.IEClientWorld 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 4 with IEClientWorld

use of com.qouteall.immersive_portals.ducks.IEClientWorld 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)

Example 5 with IEClientWorld

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

the class CHelper method getClientNearbyPortals.

public static Stream<Portal> getClientNearbyPortals(double range) {
    ClientPlayerEntity player = MinecraftClient.getInstance().player;
    List<GlobalTrackedPortal> globalPortals = ((IEClientWorld) player.world).getGlobalPortals();
    Stream<Portal> nearbyPortals = McHelper.getEntitiesNearby(player, Portal.class, range);
    if (globalPortals == null) {
        return nearbyPortals;
    } else {
        return Streams.concat(globalPortals.stream().filter(p -> p.getDistanceToNearestPointInPortal(player.getPos()) < range * 2), nearbyPortals);
    }
}
Also used : MyRenderHelper(com.qouteall.immersive_portals.render.MyRenderHelper) World(net.minecraft.world.World) Environment(net.fabricmc.api.Environment) Streams(com.google.common.collect.Streams) PlayerListEntry(net.minecraft.client.network.PlayerListEntry) GlobalTrackedPortal(com.qouteall.immersive_portals.portal.global_portals.GlobalTrackedPortal) List(java.util.List) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) Stream(java.util.stream.Stream) DimensionType(net.minecraft.world.dimension.DimensionType) Portal(com.qouteall.immersive_portals.portal.Portal) EnvType(net.fabricmc.api.EnvType) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) GlobalTrackedPortal(com.qouteall.immersive_portals.portal.global_portals.GlobalTrackedPortal) Portal(com.qouteall.immersive_portals.portal.Portal) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) GlobalTrackedPortal(com.qouteall.immersive_portals.portal.global_portals.GlobalTrackedPortal)

Aggregations

IEClientWorld (com.qouteall.immersive_portals.ducks.IEClientWorld)5 IEClientPlayNetworkHandler (com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)3 ClientPlayNetworkHandler (net.minecraft.client.network.ClientPlayNetworkHandler)3 ClientWorld (net.minecraft.client.world.ClientWorld)3 DimensionType (net.minecraft.world.dimension.DimensionType)3 Portal (com.qouteall.immersive_portals.portal.Portal)2 GlobalTrackedPortal (com.qouteall.immersive_portals.portal.global_portals.GlobalTrackedPortal)2 MinecraftClient (net.minecraft.client.MinecraftClient)2 Streams (com.google.common.collect.Streams)1 GameProfile (com.mojang.authlib.GameProfile)1 MyClientChunkManager (com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager)1 MyRenderHelper (com.qouteall.immersive_portals.render.MyRenderHelper)1 List (java.util.List)1 Stream (java.util.stream.Stream)1 EnvType (net.fabricmc.api.EnvType)1 Environment (net.fabricmc.api.Environment)1 ChatScreen (net.minecraft.client.gui.screen.ChatScreen)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 PlayerListEntry (net.minecraft.client.network.PlayerListEntry)1 WorldRenderer (net.minecraft.client.render.WorldRenderer)1