Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Immersive Portals Fixes #246

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
import net.minecraft.world.phys.Vec3;
import org.vivecraft.client.VRPlayersClient;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.render.RenderPass;
import org.vivecraft.mod_compat_vr.immersiveportals.ImmersivePortalsHelper;

import java.util.UUID;

Expand All @@ -36,7 +38,10 @@ public VRPlayerRenderer(EntityRendererProvider.Context context, boolean slim, bo

@Override
public void render(AbstractClientPlayer entityIn, float pEntityYaw, float pPartialTicks, PoseStack matrixStackIn, MultiBufferSource pBuffer, int pPackedLight) {

if (Xplat.isModLoaded("immersive_portals") && entityIn == Minecraft.getInstance().player
&& ImmersivePortalsHelper.isStandingInPortal()) {
return;
}
VRPlayersClient.RotInfo playermodelcontroller$rotinfo = VRPlayersClient.getInstance().getRotationsForPlayer(entityIn.getUUID());

if (playermodelcontroller$rotinfo != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
Expand Down Expand Up @@ -70,15 +71,17 @@ public static boolean isInsideOpaqueBlock(Vec3 in) {
}

public static Triple<Float, BlockState, BlockPos> getNearOpaqueBlock(Vec3 in, double dist) {
if (mc.level == null) {
// Prefer mc.player.level() to prevent getting the head stuck in block with ImmersivePortals.
Level level = mc.player != null && mc.player.level() != null ? mc.player.level() : mc.level;
if (level == null) {
return null;
} else {
AABB aabb = new AABB(in.subtract(dist, dist, dist), in.add(dist, dist, dist));
Stream<BlockPos> stream = BlockPos.betweenClosedStream(aabb).filter((bp) ->
mc.level.getBlockState(bp).isSolidRender(mc.level, bp));
level.getBlockState(bp).isSolidRender(level, bp));
Optional<BlockPos> optional = stream.findFirst();
return optional.isPresent()
? Triple.of(1.0F, mc.level.getBlockState(optional.get()), optional.get())
? Triple.of(1.0F, level.getBlockState(optional.get()), optional.get())
: null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package org.vivecraft.mod_compat_vr.immersiveportals;

import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.AABB;
import qouteall.imm_ptl.core.IPGlobal;
import qouteall.imm_ptl.core.portal.Mirror;
import qouteall.imm_ptl.core.portal.Portal;
import qouteall.imm_ptl.core.render.context_management.PortalRendering;

public class ImmersivePortalsHelper {
Expand All @@ -11,4 +16,10 @@ public static boolean isRenderingPortal() {
public static boolean shouldRenderSelf() {
return IPGlobal.renderYourselfInPortal && isRenderingPortal();
}

public static boolean isStandingInPortal() {
Player player = Minecraft.getInstance().player;
return !player.level().getEntities(player, AABB.ofSize(player.position(), 0.1, 0.1, 0.1),
(entity -> entity instanceof Portal && !(entity instanceof Mirror))).isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.vivecraft.mod_compat_vr.immersiveportals.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import qouteall.imm_ptl.core.portal.Portal;
import qouteall.imm_ptl.core.teleportation.ClientTeleportationManager;
import qouteall.imm_ptl.core.teleportation.TeleportationUtil;

@Mixin(ClientTeleportationManager.class)
public class ClientTeleportationManagerMixin {
@Shadow
private static long lastTeleportGameTime;

@Shadow
public static long tickTimeForTeleportation;

@Inject(method = "teleportPlayer", at = @At("HEAD"), remap = false, cancellable = true)
private static void onlyOneTpPerFrame(TeleportationUtil.Teleportation teleportation, float partialTicks, CallbackInfo ci) {
if (lastTeleportGameTime == tickTimeForTeleportation) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.vivecraft.mod_compat_vr.immersiveportals.mixin;

import net.minecraft.client.Camera;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.VRState;
import org.vivecraft.client_vr.gameplay.VRPlayer;
import qouteall.imm_ptl.core.render.CrossPortalViewRendering;
import qouteall.imm_ptl.core.teleportation.ClientTeleportationManager;

@Mixin(CrossPortalViewRendering.class)
public class CrossPortalViewRenderingMixin {

@Redirect(method = "renderCrossPortalView", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Camera;getPosition()Lnet/minecraft/world/phys/Vec3;"), remap = false)
private static Vec3 getPlayerCameraPos(Camera camera) {
if (VRState.vrRunning && ClientDataHolderVR.getInstance() != null && VRPlayer.get() != null) {
return VRPlayer.get().vrdata_world_render.getEye(ClientDataHolderVR.getInstance().currentPass).getPosition();
}
return camera.getPosition();
}

@Redirect(method = "renderCrossPortalView", at = @At(value = "INVOKE", target = "Lqouteall/imm_ptl/core/render/TransformationManager;getIsometricAdjustedCameraPos(Lnet/minecraft/client/Camera;)Lnet/minecraft/world/phys/Vec3;"), remap = false)
private static Vec3 getPlayerCameraPos2(Camera camera) {
if (VRState.vrRunning && ClientDataHolderVR.getInstance() != null && VRPlayer.get() != null) {
return VRPlayer.get().vrdata_world_render.getEye(ClientDataHolderVR.getInstance().currentPass).getPosition();
}
return camera.getPosition();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.vivecraft.mod_compat_vr.immersiveportals.mixin;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.vivecraft.client_vr.gameplay.VRPlayer;
import qouteall.imm_ptl.core.McHelper;

@Mixin(McHelper.class)
public class McHelperMixin {

@Inject(at = @At("HEAD"), method = "updateBoundingBox")
private static void updateBoundingBox(Entity player, CallbackInfo ci) {
if (VRPlayer.get() != null) {
Vec3 newPos = player.position();
Vec3 offset = newPos.subtract(VRPlayer.get().roomOrigin);
VRPlayer.get().vrdata_world_render.origin = VRPlayer.get().vrdata_world_render.origin.add(offset);
VRPlayer.get().vrdata_world_pre.origin = VRPlayer.get().vrdata_world_pre.origin.add(offset);
VRPlayer.get().vrdata_world_post.origin = VRPlayer.get().vrdata_world_post.origin.add(offset);
VRPlayer.get().setRoomOrigin(newPos.x, newPos.y, newPos.z, true);
}
}

}
12 changes: 12 additions & 0 deletions common/src/main/resources/vivecraft.immersiveportals.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": false,
"package": "org.vivecraft.mod_compat_vr.immersiveportals.mixin",
"plugin": "org.vivecraft.MixinConfig",
"compatibilityLevel": "JAVA_17",
"client": [
"ClientTeleportationManagerMixin",
"CrossPortalViewRenderingMixin",
"McHelperMixin"
],
"minVersion": "0.8.4"
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"vivecraft.dynamicfps.mixins.json",
"vivecraft.sodium.mixins.json",
"vivecraft.fabric.sodium.mixins.json",
"vivecraft.immersiveportals.mixins.json",
"vivecraft.iris.mixins.json",
"vivecraft.modmenu.mixins.json",
"vivecraft.physicsmod.mixins.json",
Expand Down
1 change: 1 addition & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ loom {
mixinConfig "vivecraft.sodium.mixins.json"
mixinConfig "vivecraft.forge.sodium.mixins.json"
mixinConfig "vivecraft.iris.mixins.json"
mixinConfig "vivecraft.immersiveportals.mixins.json"
mixinConfig "vivecraft.physicsmod.mixins.json"
mixinConfig "vivecraft.rei.mixins.json"
mixinConfig "vivecraft.resolutioncontrol.mixins.json"
Expand Down