Adjust the camera distance to match that of the entity the player is disguised as

This commit is contained in:
Sollace 2020-10-04 12:59:07 +02:00
parent 5e331016ff
commit e532b20137
6 changed files with 62 additions and 30 deletions

View file

@ -204,6 +204,10 @@ public class Disguise implements NbtSerialisable {
return -1;
}
public Optional<Double> getDistance(Pony player) {
return EntityBehaviour.forEntity(entity).getCameraDistance(entity, player);
}
public Optional<EntityDimensions> getDimensions() {
return dimensions = EntityBehaviour.forEntity(entity).getDimensions(entity, dimensions);
}

View file

@ -57,6 +57,17 @@ public class EntityBehaviour<T extends Entity> {
entity.remove();
}
public Optional<Double> getCameraDistance(Entity entity, Pony player) {
if (entity == null) {
return Optional.empty();
}
double normalHeight = PlayerEntity.STANDING_DIMENSIONS.height;
double entityHeight = entity.getDimensions(entity.getPose()).height;
return Optional.of(entityHeight / normalHeight);
}
public Optional<EntityDimensions> getDimensions(T entity, Optional<EntityDimensions> current) {
if (entity == null) {
return Optional.empty();

View file

@ -1,27 +1,27 @@
package com.minelittlepony.unicopia.entity.player;
import com.minelittlepony.common.util.animation.MotionCompositor;
import java.util.Optional;
import com.minelittlepony.common.util.animation.MotionCompositor;
import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
import net.minecraft.util.math.Vec3d;
public class PlayerCamera extends MotionCompositor {
private final Pony player;
private double baseRoll = 0;
public PlayerCamera(Pony player) {
this.player = player;
}
public float calculateRoll() {
double roll = baseRoll;
double roll = 0;
if (player.getMotion().isFlying()) {
Vec3d vel = player.getOwner().getVelocity();
roll -= super.calculateRoll(player.getOwner(), vel.x, vel.y, vel.z);
roll -= calculateRoll(player.getOwner(), vel.x, vel.y, vel.z);
}
if (player.getPhysics().isGravityNegative()) {
@ -44,6 +44,13 @@ public class PlayerCamera extends MotionCompositor {
return yaw + getEnergyAddition();
}
public Optional<Double> calculateDistance(double distance) {
return player.getSpellOrEmpty(DisguiseSpell.class, false)
.map(DisguiseSpell::getDisguise)
.flatMap(d -> d.getDistance(player))
.map(d -> distance * d);
}
public double calculateFieldOfView(double fov) {
fov += player.getMagicalReserves().getExertion().get() / 5F;
fov += getEnergyAddition();
@ -66,12 +73,4 @@ public class PlayerCamera extends MotionCompositor {
return energyAddition;
}
public double getBaseRoll() {
return baseRoll;
}
public void setBaseRoll(double roll) {
baseRoll = roll;
}
}

View file

@ -2,13 +2,12 @@ package com.minelittlepony.unicopia.mixin.client;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.client.MinecraftClient;
import com.minelittlepony.unicopia.client.UnicopiaClient;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.player.PlayerEntity;
@Mixin(Camera.class)
abstract class MixinCamera {
@ -17,13 +16,7 @@ abstract class MixinCamera {
ordinal = 0,
argsOnly = true)
private float modifyYaw(float yaw) {
PlayerEntity player = MinecraftClient.getInstance().player;
if (player != null && MinecraftClient.getInstance().cameraEntity == player) {
return Pony.of(player).getCamera().calculateYaw(yaw);
}
return yaw;
return UnicopiaClient.getCamera().map(c -> c.calculateYaw(yaw)).orElse(yaw);
}
@ModifyVariable(method = "setRotation(FF)V",
@ -31,12 +24,13 @@ abstract class MixinCamera {
ordinal = 1,
argsOnly = true)
private float modifyPitch(float pitch) {
PlayerEntity player = MinecraftClient.getInstance().player;
return UnicopiaClient.getCamera().map(c -> c.calculatePitch(pitch)).orElse(pitch);
}
if (player != null && MinecraftClient.getInstance().cameraEntity == player) {
return Pony.of(player).getCamera().calculatePitch(pitch);
}
return pitch;
@Inject(method = "clipToSpace(D)D",
at = @At("RETURN"),
cancellable = true)
private void redirectCameraDistance(double initial, CallbackInfoReturnable<Double> info) {
UnicopiaClient.getCamera().flatMap(c -> c.calculateDistance(info.getReturnValueD())).ifPresent(info::setReturnValue);
}
}

View file

@ -0,0 +1,23 @@
package com.minelittlepony.unicopia.mixin.client;
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.CallbackInfoReturnable;
import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerInteractionManager;
@Mixin(ClientPlayerInteractionManager.class)
abstract class MixinClientPlayerInteractionManager {
@Inject(method = "getReachDistance()F", at = @At("RETURN"), cancellable = true)
private void onGetReachDistance(CallbackInfoReturnable<Float> info) {
Pony player = Pony.of(MinecraftClient.getInstance().player);
if (player != null) {
info.setReturnValue(player.getExtendedReach() + info.getReturnValueF());
}
}
}

View file

@ -20,6 +20,7 @@
],
"client": [
"client.MixinCamera",
"client.MixinClientPlayerInteractionManager",
"client.MixinEntityRenderDispatcher",
"client.MixinGameRenderer",
"client.MixinInGameHud",