mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Fix buckets. (and any other raytraced items)
This commit is contained in:
parent
d58d854354
commit
589d218e91
4 changed files with 135 additions and 1 deletions
94
src/main/java/com/minelittlepony/client/HorseCam.java
Normal file
94
src/main/java/com/minelittlepony/client/HorseCam.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
package com.minelittlepony.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import com.minelittlepony.pony.IPony;
|
||||
import com.minelittlepony.settings.PonySettings;
|
||||
|
||||
public class HorseCam {
|
||||
/**
|
||||
* Transforms the client pony's pitch to the corresponding angle for a human character.
|
||||
*/
|
||||
public static float transformCameraAngle(float pitch) {
|
||||
|
||||
if (!PonySettings.FILLYCAM.get()) {
|
||||
return pitch;
|
||||
}
|
||||
|
||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||
IPony pony = MineLittlePony.getInstance().getManager().getPony(player);
|
||||
|
||||
if (!pony.getRace(false).isHuman()) {
|
||||
float factor = pony.getMetadata().getSize().getEyeHeightFactor();
|
||||
return rescaleCameraPitch(player.getStandingEyeHeight() / factor, pitch);
|
||||
}
|
||||
|
||||
return pitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a corresponding camera pitch for the current player at
|
||||
* the specified character height.
|
||||
*
|
||||
* @param toHeight Target height.
|
||||
* @param originalPitch Original, unchanged pitch.
|
||||
*
|
||||
* @return The new pitch value, otherwise the original value passed in.
|
||||
*/
|
||||
public static float rescaleCameraPitch(double toHeight, float originalPitch) {
|
||||
/* -90
|
||||
* |
|
||||
* ---------------0
|
||||
* |
|
||||
* 90
|
||||
*/
|
||||
/* A A - toHeight
|
||||
* |\ B - fromHeight
|
||||
* |?\ y - headPitch
|
||||
* | \ ? - result
|
||||
* | \ C - raytrace
|
||||
* B- \
|
||||
* |y - \
|
||||
* | - \ Tan(?) = horDist / toHeight
|
||||
* |-------C ? = arcTan(horDist / toHeight);
|
||||
* horDist
|
||||
*/
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
PlayerEntity player = client.player;
|
||||
HitResult hit = client.hitResult;
|
||||
|
||||
// noop
|
||||
if (hit == null || player == null) {
|
||||
return originalPitch;
|
||||
}
|
||||
|
||||
// Small angles aren't worth changing.
|
||||
// Helps with bows, arrows, and projectiles.
|
||||
if (Math.abs(originalPitch) < 10) {
|
||||
return originalPitch;
|
||||
}
|
||||
|
||||
Vec3d hitPos = hit.getPos();
|
||||
Vec3d pos = player.getPos();
|
||||
|
||||
double diffX = Math.abs(hitPos.x - pos.x);
|
||||
double diffZ = Math.abs(hitPos.z - pos.z);
|
||||
double horDist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||
|
||||
float theta = (float)Math.atan(horDist / toHeight);
|
||||
|
||||
// convert to degress
|
||||
theta /= Math.PI / 180;
|
||||
|
||||
// convert to vertical pitch (-90 to 90).
|
||||
// Preserve up/down direction.
|
||||
float newPitch = (90 - theta) * Math.signum(originalPitch);
|
||||
|
||||
System.out.println("From " + originalPitch + " to " + newPitch);
|
||||
|
||||
return newPitch;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.minelittlepony.client.mixin;
|
||||
|
||||
import net.minecraft.server.network.packet.PlayerMoveC2SPacket;
|
||||
|
||||
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 com.minelittlepony.client.HorseCam;
|
||||
|
||||
@Mixin(PlayerMoveC2SPacket.Both.class)
|
||||
public abstract class MixinPlayerMoveC2SPacket_Both extends PlayerMoveC2SPacket {
|
||||
@Inject(method = "<init>(DDDFFZ)V",
|
||||
at = @At("RETURN"))
|
||||
private void onInit(CallbackInfo info) {
|
||||
this.pitch = HorseCam.transformCameraAngle(this.pitch);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.minelittlepony.client.mixin;
|
||||
|
||||
import net.minecraft.server.network.packet.PlayerMoveC2SPacket;
|
||||
|
||||
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 com.minelittlepony.client.HorseCam;
|
||||
|
||||
@Mixin(PlayerMoveC2SPacket.LookOnly.class)
|
||||
public abstract class MixinPlayerMoveC2SPacket_LookOnly extends PlayerMoveC2SPacket {
|
||||
@Inject(method = "<init>(FFZ)V",
|
||||
at = @At("RETURN"))
|
||||
private void onInit(CallbackInfo info) {
|
||||
this.pitch = HorseCam.transformCameraAngle(this.pitch);
|
||||
}
|
||||
}
|
|
@ -12,6 +12,8 @@
|
|||
"MixinFirstPersonRenderer",
|
||||
"MixinGlStateManager",
|
||||
"MixinItemRenderer",
|
||||
"MixinClientPlayerEntity"
|
||||
"MixinClientPlayerEntity",
|
||||
"MixinPlayerMoveC2SPacket_Both",
|
||||
"MixinPlayerMoveC2SPacket_LookOnly"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue