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;
}
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);
});
}
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;
}
});
}
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);
}
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);
}
}
Aggregations