Fixed some magic values in boat emulation.

This commit is contained in:
FlorianMichael 2023-10-02 01:49:36 +02:00
parent 8c7ece3004
commit eff452e1da
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
5 changed files with 38 additions and 48 deletions

View File

@ -33,37 +33,6 @@ import org.joml.Vector3f;
public class EntityHeightOffsetsPre1_20_2 {
public static void clamPassengerYaw(final Entity entity, final Entity passenger) {
if (entity instanceof CamelEntity camelEntity) {
passenger.setBodyYaw(camelEntity.getYaw());
final float passengerYaw = passenger.getYaw();
final float deltaDegrees = MathHelper.wrapDegrees(passengerYaw - camelEntity.getYaw());
final float clampedDelta = MathHelper.clamp(deltaDegrees, -160.0f, 160.0f);
passenger.prevYaw += clampedDelta - deltaDegrees;
final float newYaw = passengerYaw + clampedDelta - deltaDegrees;
passenger.setYaw(newYaw);
passenger.setHeadYaw(newYaw);
} else if (entity instanceof BoatEntity boatEntity) {
passenger.setYaw(passenger.getYaw() + boatEntity.yawVelocity);
passenger.setHeadYaw(passenger.getHeadYaw() + boatEntity.yawVelocity);
passenger.setBodyYaw(entity.getYaw());
final float f = MathHelper.wrapDegrees(passenger.getYaw() - entity.getYaw());
final float g = MathHelper.clamp(f, -105.0f, 105.0f);
passenger.prevYaw += g - f;
passenger.setYaw(passenger.getYaw() + g - f);
passenger.setHeadYaw(passenger.getYaw());
if (passenger instanceof AnimalEntity && boatEntity.getPassengerList().size() == boatEntity.getMaxPassengers()) {
int j = passenger.getId() % 2 == 0 ? 90 : 270;
passenger.setBodyYaw(((AnimalEntity) passenger).bodyYaw + (float) j);
passenger.setHeadYaw(passenger.getHeadYaw() + (float) j);
}
}
}
public static Vector3f getMountedHeightOffset(final Entity entity, final Entity passenger) {
double yOffset = entity.getHeight() * 0.75;

View File

@ -8,5 +8,10 @@ import java.nio.ByteBuffer;
This library is part of the AuthLib, we are overwriting this class to add a new field.
*/
public record KeyPairResponseBypass(KeyPairResponse.KeyPair keyPair, ByteBuffer publicKeySignatureV2, ByteBuffer publicKeySignature /* own field */, String expiresAt, String refreshedAfter) {
public record KeyPairResponse1_19_0(
KeyPairResponse.KeyPair keyPair,
ByteBuffer publicKeySignatureV2,
ByteBuffer publicKeySignature /* removed in 1.20-rc1 */,
String expiresAt,
String refreshedAfter) {
}

View File

@ -34,7 +34,7 @@ public class BoatRenderer_1_8 extends EntityRenderer<BoatEntity> {
public BoatRenderer_1_8(EntityRendererFactory.Context ctx) {
super(ctx);
shadowRadius = 0.8f;
shadowRadius = 0.5F;
model = new BoatModel_1_8(ctx.getPart(BoatModel_1_8.MODEL_LAYER));
}
@ -46,14 +46,15 @@ public class BoatRenderer_1_8 extends EntityRenderer<BoatEntity> {
@Override
public void render(BoatEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
matrices.push();
matrices.translate(0, 0.375, 0);
matrices.translate(0, 0.25, 0);
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(180 - yaw));
float damageWobbleTicks = entity.getDamageWobbleTicks() - tickDelta;
float damageWobbleStrength = entity.getDamageWobbleStrength() - tickDelta;
if (damageWobbleStrength < 0) {
damageWobbleStrength = 0;
}
if (damageWobbleTicks > 0) {
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(MathHelper.sin(damageWobbleTicks) * damageWobbleTicks * damageWobbleStrength / 10 * entity.getDamageWobbleSide()));
}

View File

@ -20,7 +20,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.authlib;
import com.mojang.authlib.minecraft.client.MinecraftClient;
import com.mojang.authlib.yggdrasil.YggdrasilUserApiService;
import com.mojang.authlib.yggdrasil.response.KeyPairResponse;
import de.florianmichael.viafabricplus.definition.authlib.KeyPairResponseBypass;
import de.florianmichael.viafabricplus.definition.authlib.KeyPairResponse1_19_0;
import de.florianmichael.viafabricplus.injection.access.IKeyPairResponse;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
@ -31,10 +31,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.net.URL;
/*
Workaround for https://github.com/ViaVersion/ViaFabricPlus/issues/258
*/
@Mixin(value = YggdrasilUserApiService.class, remap = false)
public class MixinYggdrasilUserApiService {
@ -43,13 +39,16 @@ public class MixinYggdrasilUserApiService {
@Shadow @Final private URL routeKeyPair;
@Inject(method = "getKeyPair", at = @At("HEAD"), cancellable = true)
public void trackLegacyKeyPair(CallbackInfoReturnable<KeyPairResponse> cir) {
final var response = minecraftClient.post(routeKeyPair, KeyPairResponseBypass.class);
if (response == null) return;
public void storeLegacyPublicKeySignature(CallbackInfoReturnable<KeyPairResponse> cir) {
final var response = minecraftClient.post(routeKeyPair, KeyPairResponse1_19_0.class);
if (response == null) { // the response can't be null for us since we are constructing a new object with it.
cir.setReturnValue(null);
return;
}
final var returnValue = new KeyPairResponse(response.keyPair(), response.publicKeySignatureV2(), response.expiresAt(), response.refreshedAfter());
((IKeyPairResponse) (Object) returnValue).viafabricplus_setLegacyPublicKeySignature(response.publicKeySignature());
final var keyPairResponse = new KeyPairResponse(response.keyPair(), response.publicKeySignatureV2(), response.expiresAt(), response.refreshedAfter());
((IKeyPairResponse) (Object) keyPairResponse).viafabricplus_setLegacyPublicKeySignature(response.publicKeySignature());
cir.setReturnValue(returnValue);
cir.setReturnValue(keyPairResponse);
}
}

View File

@ -6,9 +6,11 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.AbstractHorseEntity;
import net.minecraft.entity.passive.CamelEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@ -27,10 +29,24 @@ public abstract class MixinCamelEntity extends AbstractHorseEntity {
return instance.isBaby();
}
@Unique
public void viafabricplus_clamPassengerYaw(final Entity passenger) {
passenger.setBodyYaw(this.getYaw());
final float passengerYaw = passenger.getYaw();
final float deltaDegrees = MathHelper.wrapDegrees(passengerYaw - this.getYaw());
final float clampedDelta = MathHelper.clamp(deltaDegrees, -160.0f, 160.0f);
passenger.prevYaw += clampedDelta - deltaDegrees;
final float newYaw = passengerYaw + clampedDelta - deltaDegrees;
passenger.setYaw(newYaw);
passenger.setHeadYaw(newYaw);
}
@Override
public void onPassengerLookAround(Entity passenger) {
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1) && this.getControllingPassenger() != passenger) {
EntityHeightOffsetsPre1_20_2.clamPassengerYaw(this, passenger);
viafabricplus_clamPassengerYaw(passenger);
}
}
@ -39,7 +55,7 @@ public abstract class MixinCamelEntity extends AbstractHorseEntity {
super.updatePassengerPosition(passenger, positionUpdater);
if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_20tor1_20_1)) {
EntityHeightOffsetsPre1_20_2.clamPassengerYaw(this, passenger);
viafabricplus_clamPassengerYaw(passenger);
}
}
}