mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-15 01:04:21 +01:00
Fixed eye position and model offsets when in a boat
This commit is contained in:
parent
5728ce46bc
commit
b9f3259a2c
8 changed files with 53 additions and 19 deletions
|
@ -163,7 +163,7 @@ public class ModelAttributes {
|
|||
|
||||
public void updateLivingState(LivingEntity entity, Pony pony, Mode mode) {
|
||||
metadata = pony.metadata();
|
||||
size = entity.isBaby() ? SizePreset.FOAL : PonyConfig.getEffectiveSize(metadata.size());
|
||||
size = entity.isBaby() ? SizePreset.FOAL : pony.size();
|
||||
isPlayer = entity instanceof PlayerEntity;
|
||||
visualHeight = entity.getHeight() + 0.125F;
|
||||
isSitting = PonyPosture.isSitting(entity);
|
||||
|
|
|
@ -23,8 +23,7 @@ abstract class MixinPlayerEntity implements RegistrationHandler {
|
|||
|
||||
@ModifyReturnValue(method = "getBaseDimensions(Lnet/minecraft/entity/EntityPose;)Lnet/minecraft/entity/EntityDimensions;", at = @At("RETURN"))
|
||||
private EntityDimensions modifyEyeHeight(EntityDimensions dimensions, EntityPose pose) {
|
||||
float factor = syncedPony.getCachedPonyData().size().eyeHeightFactor();
|
||||
return factor == 1 ? dimensions : dimensions.withEyeHeight(dimensions.eyeHeight() * factor);
|
||||
return getSyncedPony().modifyEyeHeight((PlayerEntity)(Object)this, dimensions, pose);
|
||||
}
|
||||
|
||||
@Inject(method = "tick()V", at = @At("TAIL"))
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.client.util.math.MatrixStack;
|
|||
import net.minecraft.util.math.Box;
|
||||
|
||||
import com.minelittlepony.api.model.RenderPass;
|
||||
import com.minelittlepony.client.render.entity.state.PlayerPonyRenderState;
|
||||
import com.minelittlepony.client.render.entity.state.PonyRenderState;
|
||||
|
||||
public final class DebugBoundingBoxRenderer {
|
||||
|
@ -21,7 +22,11 @@ public final class DebugBoundingBoxRenderer {
|
|||
}
|
||||
|
||||
stack.push();
|
||||
VertexRendering.drawBox(stack, matrices.getBuffer(RenderLayer.getLines()), getBoundingBox(state).offset(-state.x, -state.y, -state.z), 1, 1, 0, 1);
|
||||
VertexRendering.drawBox(stack, matrices.getBuffer(RenderLayer.getLines()), getBoundingBox(state).offset(
|
||||
-state.x,
|
||||
-state.y + (state instanceof PlayerPonyRenderState s ? s.baseScale * s.yOffset : 0),
|
||||
-state.z
|
||||
), 1, 1, 0, 1);
|
||||
stack.pop();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,11 @@ import net.minecraft.client.MinecraftClient;
|
|||
import net.minecraft.client.render.entity.model.EntityModel;
|
||||
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -121,13 +122,12 @@ public class EquineRenderManager<
|
|||
}
|
||||
|
||||
public static class SyncedPony {
|
||||
@Nullable
|
||||
private Pony lastRenderedPony;
|
||||
private Optional<Pony> lastRenderedPony = Optional.empty();
|
||||
private Supplier<Optional<PonyData>> lastPonyData = PonyDataLoader.NULL;
|
||||
@Nullable
|
||||
private Pony lastTransmittedPony;
|
||||
private Optional<Pony> lastTransmittedPony = Optional.empty();
|
||||
private boolean seated;
|
||||
|
||||
public Pony getCachedPony() {
|
||||
public Optional<Pony> getCachedPony() {
|
||||
return lastRenderedPony;
|
||||
}
|
||||
|
||||
|
@ -135,24 +135,44 @@ public class EquineRenderManager<
|
|||
return lastPonyData.get().orElse(PonyData.NULL);
|
||||
}
|
||||
|
||||
public EntityDimensions modifyEyeHeight(PlayerEntity player, EntityDimensions dimensions, EntityPose pose) {
|
||||
Pony pony = lastRenderedPony.orElse(null);
|
||||
float factor = pony == null || pony.race().isHuman() ? 1 : pony.size().eyeHeightFactor();
|
||||
if (factor == 1) {
|
||||
return dimensions;
|
||||
}
|
||||
float eyeHeight = dimensions.eyeHeight() * factor;
|
||||
if (player.hasVehicle()) {
|
||||
Vec3d attachment = dimensions.attachments().getPointNullable(EntityAttachmentType.VEHICLE, 0, 0);
|
||||
if (attachment != null) {
|
||||
double yAttachment = attachment.getY();
|
||||
eyeHeight += yAttachment * factor;
|
||||
}
|
||||
}
|
||||
|
||||
return dimensions.withEyeHeight(eyeHeight);
|
||||
}
|
||||
|
||||
public void synchronize(PlayerEntity player) {
|
||||
Pony pony = Pony.getManager().getPony(player);
|
||||
boolean changed = pony.compareTo(lastRenderedPony) != 0;
|
||||
boolean changed = pony.compareTo(lastRenderedPony.orElse(null)) != 0;
|
||||
boolean seated = player.hasVehicle();
|
||||
|
||||
if (changed) {
|
||||
lastRenderedPony = pony;
|
||||
if (changed || seated != this.seated) {
|
||||
lastRenderedPony = Optional.of(pony);
|
||||
lastPonyData = pony.metadataGetter();
|
||||
player.calculateDimensions();
|
||||
}
|
||||
this.seated = seated;
|
||||
|
||||
if (!(player instanceof PreviewModel)) {
|
||||
@Nullable
|
||||
PlayerEntity clientPlayer = MinecraftClient.getInstance().player;
|
||||
|
||||
if (ClientChannel.isRegistered() && pony.compareTo(lastTransmittedPony) != 0) {
|
||||
if (ClientChannel.isRegistered() && pony.compareTo(lastTransmittedPony.orElse(null)) != 0) {
|
||||
if (clientPlayer != null && (Objects.equals(player, clientPlayer) || Objects.equals(player.getGameProfile(), clientPlayer.getGameProfile()))) {
|
||||
if (ClientChannel.broadcastPonyData(pony.metadata())) {
|
||||
lastTransmittedPony = pony;
|
||||
lastTransmittedPony = Optional.of(pony);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class AquaticPlayerPonyRenderer extends FormChangingPlayerPonyRenderer {
|
|||
public void updateState(LivingEntity entity, PonyModel<?> model, Pony pony, ModelAttributes.Mode mode) {
|
||||
super.updateState(entity, model, pony, mode);
|
||||
Identifier skinOverride = getSkinOverride((AbstractClientPlayerEntity)entity);
|
||||
yOffset = skinOverride != null ? (0.6 + (isInSneakingPose ? 0.125 : 0)) : 0;
|
||||
yOffset += skinOverride != null ? (0.6 + (isInSneakingPose ? 0.125 : 0)) : 0;
|
||||
pose = EntityPose.STANDING;
|
||||
isInSneakingPose = false;
|
||||
attributes.isCrouching = false;
|
||||
|
|
|
@ -73,7 +73,9 @@ public class PlayerPonyRenderer
|
|||
|
||||
public Vec3d getPositionOffset(PlayerEntityRenderState state) {
|
||||
Vec3d offset = super.getPositionOffset(state);
|
||||
return offset.add(state.baseScale * ((PlayerPonyRenderState)state).yOffset).multiply(((PonyRenderState)state).attributes.size.scaleFactor());
|
||||
return offset
|
||||
.multiply(((PonyRenderState)state).attributes.size.scaleFactor())
|
||||
.add(0, state.baseScale * ((PlayerPonyRenderState)state).yOffset, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,9 +2,11 @@ package com.minelittlepony.client.render.entity.state;
|
|||
|
||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.util.SkinTextures;
|
||||
import net.minecraft.entity.EntityAttachmentType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import com.minelittlepony.api.model.*;
|
||||
import com.minelittlepony.api.pony.Pony;
|
||||
|
@ -23,6 +25,13 @@ public class PlayerPonyRenderState extends PonyRenderState {
|
|||
public void updateState(LivingEntity entity, PonyModel<?> model, Pony pony, ModelAttributes.Mode mode) {
|
||||
smallArms = ((AbstractClientPlayerEntity)entity).getSkinTextures().model() == SkinTextures.Model.SLIM;
|
||||
super.updateState(entity, model, pony, mode);
|
||||
yOffset = 0;
|
||||
if (entity.hasVehicle()) {
|
||||
Vec3d attachment = entity.getDimensions(entity.getPose()).attachments().getPointNullable(EntityAttachmentType.VEHICLE, 0, 0);
|
||||
if (attachment != null) {
|
||||
yOffset += attachment.getY() * (1 - attributes.size.eyeHeightFactor());
|
||||
}
|
||||
}
|
||||
isPreviewModel = entity instanceof PreviewModel;
|
||||
wearabledTextures.clear();
|
||||
for (Wearable wearable : Wearable.REGISTRY.values()) {
|
||||
|
|
|
@ -9,7 +9,6 @@ import net.minecraft.entity.mob.ZombifiedPiglinEntity;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
import com.minelittlepony.api.config.PonyConfig;
|
||||
import com.minelittlepony.api.events.PonyModelPrepareCallback;
|
||||
import com.minelittlepony.api.model.ModelAttributes;
|
||||
import com.minelittlepony.api.model.PonyModel;
|
||||
|
@ -39,7 +38,7 @@ public class PonyRenderState extends PlayerEntityRenderState implements PonyMode
|
|||
attributes.updateLivingState(entity, pony, mode);
|
||||
attributes.checkRainboom(entity, model, age);
|
||||
baby = attributes.size == SizePreset.FOAL;
|
||||
race = PonyConfig.getEffectiveRace(attributes.metadata.race());
|
||||
race = pony.race();
|
||||
vehicleOffset = hasVehicle ? entity.getVehicle().getEyeHeight(pose) : 0;
|
||||
riderOffset = getRiderYOffset();
|
||||
nameplateYOffset = getNamePlateYOffset(entity);
|
||||
|
|
Loading…
Reference in a new issue