Also use the original camera position when Immersive Portals is loaded.

This commit is contained in:
Acuadragon100
2026-05-16 13:24:38 +02:00
parent 938631a379
commit 7d918fe8dc
4 changed files with 33 additions and 1 deletions
@@ -4,9 +4,11 @@ package com.seibel.distanthorizons.common.commonMixins;
import com.seibel.distanthorizons.common.wrappers.modAccessor.ImmersivePortalsAccessorCommon;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.phys.Vec3;
public class MixinImmersivePortalsRenderStatesCommon
{
@@ -19,8 +21,10 @@ public class MixinImmersivePortalsRenderStatesCommon
if (mc.player == null) {
ImmersivePortalsAccessorCommon.originalBlockPos = null;
ImmersivePortalsAccessorCommon.originalChunkPos = null;
ImmersivePortalsAccessorCommon.originalCameraPos = null;
return;
}
BlockPos pos = mc.player.blockPosition();
ImmersivePortalsAccessorCommon.originalBlockPos = new DhBlockPos(pos.getX(), pos.getY(), pos.getZ());
#if MC_VER < MC_1_17_1
@@ -34,6 +38,14 @@ public class MixinImmersivePortalsRenderStatesCommon
#else
ImmersivePortalsAccessorCommon.originalChunkPos = new DhChunkPos(cPos.x(), cPos.z());
#endif
#if MC_VER <= MC_1_21_10
Vec3 cameraPos = mc.gameRenderer.getMainCamera().getPosition();
#else
Vec3 cameraPos = mc.gameRenderer.getMainCamera().position();
#endif
ImmersivePortalsAccessorCommon.originalCameraPos = new Vec3d(cameraPos.x(), cameraPos.y(), cameraPos.z());
}
}
@@ -64,6 +64,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import com.seibel.distanthorizons.core.util.math.Vec3f;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IImmersivePortalsAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.IOptifineAccessor;
#if MC_VER <= MC_1_12_2
@@ -127,6 +128,11 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
private static final Minecraft MC = Minecraft.getInstance();
#endif
// Need to classload this field later because otherwise it will be null even when Immersive Portals is present.
public static class Late {
private static final IImmersivePortalsAccessor IMMERSIVE_PORTALS = ModAccessorInjector.INSTANCE.get(IImmersivePortalsAccessor.class);
}
/**
* In the case of immersive portals multiple levels may be active at once, causing conflicting lightmaps. <br>
* Requiring the use of multiple {@link LightMapWrapper}.
@@ -205,6 +211,11 @@ public class MinecraftRenderWrapper implements IMinecraftRenderWrapper
@Override
public Vec3d getCameraExactPosition()
{
if (Late.IMMERSIVE_PORTALS != null)
{
Vec3d cameraPos = Late.IMMERSIVE_PORTALS.getOriginalCameraPos();
if (cameraPos != null) return cameraPos;
}
#if MC_VER <= MC_1_12_2
RenderManager rm = MC.getRenderManager();
return new Vec3d(rm.viewerPosX, rm.viewerPosY, rm.viewerPosZ);
@@ -25,6 +25,7 @@ import com.seibel.distanthorizons.common.wrappers.world.ClientLevelWrapper;
import com.seibel.distanthorizons.core.api.internal.ClientApi;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
import com.seibel.distanthorizons.core.util.math.Vec3d;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.ImmersivePortalsAbstractAccessor;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import net.minecraft.client.Minecraft;
@@ -56,6 +57,8 @@ public abstract class ImmersivePortalsAccessorCommon extends ImmersivePortalsAbs
public static volatile DhBlockPos originalBlockPos;
@Nullable
public static volatile DhChunkPos originalChunkPos;
@Nullable
public static volatile Vec3d originalCameraPos;
@Override
protected Object getClientLevel() { return Minecraft.getInstance().level; }
@@ -130,6 +133,12 @@ public abstract class ImmersivePortalsAccessorCommon extends ImmersivePortalsAbs
return ClientLevelWrapper.getWrapper(originalLevel, false);
}
@Override
@Nullable
public Vec3d getOriginalCameraPos() {
return originalCameraPos;
}
}
#endif