Skip to content

Commit

Permalink
account for player scale attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
fayer3 committed Sep 24, 2024
1 parent 7fdcb55 commit 0f8f684
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.phys.Vec3;
import org.vivecraft.client.VRPlayersClient;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.utils.ScaleHelper;
import org.vivecraft.mod_compat_vr.optifine.OptifineHelper;
import org.vivecraft.mod_compat_vr.pehkui.PehkuiHelper;
import org.vivecraft.mod_compat_vr.sodium.SodiumHelper;

public class VRPlayerModel_WithArms<T extends LivingEntity> extends VRPlayerModel<T> {
Expand Down Expand Up @@ -157,13 +156,11 @@ public void setupAnim(T pEntity, float pLimbSwing, float pLimbSwingAmount, float
this.leftShoulder.y += 3.2F;
}

Vec3 vec3 = rotinfo.leftArmPos;
Vec3 vec32 = rotinfo.rightArmPos;
if (Xplat.isModLoaded("pehkui")) {
// remove pehkui scale from that, since the whole entity is scaled
vec3 = vec3.scale(1.0F / PehkuiHelper.getPlayerScale(pEntity, Minecraft.getInstance().getFrameTime()));
vec32 = vec32.scale(1.0F / PehkuiHelper.getPlayerScale(pEntity, Minecraft.getInstance().getFrameTime()));
}
// remove entity scale from that
float scale = 1.0F / ScaleHelper.getEntityScale(pEntity, Minecraft.getInstance().getFrameTime());
Vec3 vec3 = rotinfo.leftArmPos.scale(scale);
Vec3 vec32 = rotinfo.rightArmPos.scale(scale);

vec3 = vec3.add(0.0D, d0, 0.0D);
vec3 = vec3.yRot((float) (-Math.PI + d1));
vec3 = vec3.scale(16.0F / rotinfo.heightScale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.vivecraft.client.VivecraftVRMod;
import org.vivecraft.client.Xplat;
import org.vivecraft.client.network.ClientNetworking;
import org.vivecraft.client_vr.utils.ScaleHelper;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.ItemTags;
import org.vivecraft.client_vr.MethodHolder;
Expand All @@ -39,7 +39,6 @@
import org.vivecraft.client_vr.render.RenderPass;
import org.vivecraft.client_vr.settings.VRSettings;
import org.vivecraft.common.VRServerPerms;
import org.vivecraft.mod_compat_vr.pehkui.PehkuiHelper;

import java.util.ArrayList;
import java.util.Random;
Expand Down Expand Up @@ -147,16 +146,14 @@ public void preTick() {

this.worldScale = rawWorldScale;

if (Xplat.isModLoaded("pehkui")) {
// scale world with player size
this.worldScale *= PehkuiHelper.getPlayerScale(mc.player, mc.getFrameTime());
// limit scale
if (this.worldScale > 100F) {
this.worldScale = 100F;
} else if (this.worldScale < 0.025F) //minClip + player position indicator offset
{
this.worldScale = 0.025F;
}
// scale world with player size
this.worldScale *= ScaleHelper.getEntityScale(mc.player, mc.getFrameTime());
// limit scale
if (this.worldScale > 100F) {
this.worldScale = 100F;
} else if (this.worldScale < 0.025F) //minClip + player position indicator offset
{
this.worldScale = 0.025F;
}

// check that nobody tries to bypass the server set worldscale limit it with a runtime worldscale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import net.minecraft.world.item.UseAnim;
import net.minecraft.world.phys.Vec3;
import org.vivecraft.client.VivecraftVRMod;
import org.vivecraft.client.Xplat;
import org.vivecraft.client.network.ClientNetworking;
import org.vivecraft.client_vr.utils.ScaleHelper;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.client_vr.VRData;
import org.vivecraft.client_vr.extensions.PlayerExtension;
Expand All @@ -22,7 +22,6 @@
import org.vivecraft.client_vr.settings.VRSettings;
import org.vivecraft.common.network.CommonNetworkHelper;
import org.vivecraft.common.utils.math.Vector3;
import org.vivecraft.mod_compat_vr.pehkui.PehkuiHelper;

import java.nio.ByteBuffer;

Expand Down Expand Up @@ -126,12 +125,9 @@ public void doProcess(LocalPlayer player) {
this.lastpressed = this.pressed;
this.lastDraw = this.currentDraw;
this.lastcanDraw = this.canDraw;
this.maxDraw = (double) this.mc.player.getBbHeight() * 0.22D;

if (Xplat.isModLoaded("pehkui")) {
// this is meant to be relative to the base Bb height, not the scaled one
this.maxDraw /= PehkuiHelper.getPlayerBbScale(player, mc.getFrameTime());
}
// this is meant to be relative to the base Bb height, not the scaled one
this.maxDraw = (double) this.mc.player.getBbHeight() * 0.22D / ScaleHelper.getEntityBbScale(player, mc.getFrameTime());

Vec3 vec3 = vrdata.getController(0).getPosition();
Vec3 vec31 = vrdata.getController(1).getPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
import net.minecraft.world.entity.Pose;
import org.vivecraft.client.Xplat;
import org.vivecraft.client.network.ClientNetworking;
import org.vivecraft.client_vr.utils.ScaleHelper;
import org.vivecraft.client_vr.ClientDataHolderVR;
import org.vivecraft.common.network.CommonNetworkHelper;
import org.vivecraft.mod_compat_vr.pehkui.PehkuiHelper;

public class CrawlTracker extends Tracker {
private boolean wasCrawling;
Expand Down Expand Up @@ -44,10 +43,7 @@ public void reset(LocalPlayer player) {
}

public void doProcess(LocalPlayer player) {
double scaleMultiplier = 1.0;
if (Xplat.isModLoaded("pehkui")) {
scaleMultiplier /= PehkuiHelper.getPlayerScale(player, mc.getFrameTime());
}
float scaleMultiplier = 1.0F / ScaleHelper.getEntityScale(player, mc.getFrameTime());
this.crawling = this.dh.vr.hmdPivotHistory.averagePosition(0.2F).y * (double) this.dh.vrPlayer.worldScale * scaleMultiplier + (double) 0.1F < (double) this.dh.vrSettings.crawlThreshold;
this.updateState(player);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.vivecraft.client_vr.utils;

import net.minecraft.world.entity.LivingEntity;
import org.vivecraft.client.Xplat;
import org.vivecraft.mod_compat_vr.pehkui.PehkuiHelper;

public class ScaleHelper {

public static float getEntityScale(LivingEntity livingEntity, float tickDelta) {
float scale = livingEntity.getScale();
if (Xplat.isModLoaded("pehkui")) {
scale *= PehkuiHelper.getEntityScale(livingEntity, tickDelta);
}
return scale;
}

public static float getEntityBbScale(LivingEntity livingEntity, float tickDelta) {
float scale = livingEntity.getScale();
if (Xplat.isModLoaded("pehkui")) {
scale *= PehkuiHelper.getEntityBbScale(livingEntity, tickDelta);
}
return scale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.vivecraft.client.Xplat;
import org.vivecraft.client_vr.VRState;
import org.vivecraft.client_vr.render.helpers.RenderHelper;
import org.vivecraft.mod_compat_vr.pehkui.PehkuiHelper;

@Mixin(ItemPickupParticle.class)
public class ItemPickupParticleVRMixin {
Expand Down Expand Up @@ -45,14 +43,7 @@ public class ItemPickupParticleVRMixin {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Mth;lerp(DDD)D", ordinal = 1), method = "render")
public double vivecraft$updateY(double d, double e, double f) {
if (VRState.vrRunning && target == vivecraft$mc.player) {
float offset = 0.5F;
if (Xplat.isModLoaded("pehkui")) {
// pehkui changes the offset, need to account for that
offset *= PehkuiHelper.getPlayerScale(target, (float) d);
}
// offset, so the particle is centered around the arm
offset += itemEntity.getBbHeight();
e = f = vivecraft$playerPos.y - offset;
e = f = vivecraft$playerPos.y - itemEntity.getBbHeight();
}

return Mth.lerp(d, e, f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import virtuoel.pehkui.util.ScaleUtils;

public class PehkuiHelper {
public static float getPlayerScale(Entity player, float tickDelta) {
return ScaleUtils.getEyeHeightScale(player, tickDelta);
public static float getEntityScale(Entity entity, float tickDelta) {
return ScaleUtils.getEyeHeightScale(entity, tickDelta);
}

public static float getPlayerBbScale(Entity player, float tickDelta) {
return ScaleUtils.getBoundingBoxHeightScale(player, tickDelta);
public static float getEntityBbScale(Entity entity, float tickDelta) {
return ScaleUtils.getBoundingBoxHeightScale(entity, tickDelta);
}
}

0 comments on commit 0f8f684

Please sign in to comment.