Smooth out the transition when flipping gravity

This commit is contained in:
Sollace 2020-09-25 23:39:57 +02:00
parent 882627cd3f
commit 9a7671f4f7
4 changed files with 24 additions and 8 deletions

View file

@ -29,6 +29,10 @@ public class UnicopiaClient implements ClientModInitializer {
return Unicopia.getConfig().getPrefferedRace();
}
public static float getWorldBrightness(float initial) {
return Math.min(1, initial + 0.6F);
}
@Override
public void onInitializeClient() {
InteractionManager.INSTANCE = new ClientInteractionManager();

View file

@ -14,24 +14,34 @@ public class WorldRenderDelegate {
public static final WorldRenderDelegate INSTANCE = new WorldRenderDelegate();
public void beforeEntityRender(Pony pony, MatrixStack matrices, double x, double y, double z) {
if (pony.getPhysics().isGravityNegative()) {
matrices.push();
Entity entity = pony.getOwner();
matrices.push();
Entity entity = pony.getOwner();
boolean negative = pony.getPhysics().isGravityNegative();
float roll = negative ? 180 : 0;
roll = pony.getInterpolator().interpolate("g_roll", roll, 15);
if (negative) {
matrices.translate(x, y, z);
matrices.translate(0, entity.getHeight(), 0);
matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(180));
matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(roll));
matrices.translate(-x, -y, -z);
flipAngles(entity);
} else {
matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(roll));
}
}
public void afterEntityRender(Pony pony, MatrixStack matrices) {
if (pony.getPhysics().isGravityNegative()) {
matrices.pop();
matrices.pop();
if (pony.getPhysics().isGravityNegative()) {
flipAngles(pony.getOwner());
}
}

View file

@ -248,6 +248,7 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01 || entity.isSneaking() || !canHangAt()) {
attr.removeModifier(PlayerAttributes.BAT_HANGING);
entity.calculateDimensions();
}
}

View file

@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.client.UnicopiaClient;
import com.minelittlepony.unicopia.client.render.WorldRenderDelegate;
import com.minelittlepony.unicopia.entity.player.Pony;
@ -40,7 +41,7 @@ abstract class MixinGameRenderer implements AutoCloseable, SynchronousResourceRe
cancellable = true)
private static void onGetNightVisionStrengthHead(LivingEntity entity, float tickDelta, CallbackInfoReturnable<Float> info) {
if (!entity.hasStatusEffect(StatusEffects.NIGHT_VISION)) {
info.setReturnValue(0.6F);
info.setReturnValue(UnicopiaClient.getWorldBrightness(0));
}
}
@Inject(method = "getNightVisionStrength(FJLnet/minecraft/entity/LivingEntity;F)F",
@ -48,7 +49,7 @@ abstract class MixinGameRenderer implements AutoCloseable, SynchronousResourceRe
cancellable = true)
private static void onGetNightVisionStrengthReturn(LivingEntity entity, float tickDelta, CallbackInfoReturnable<Float> info) {
if (entity.hasStatusEffect(StatusEffects.NIGHT_VISION) && EquinePredicates.PLAYER_BAT.test(entity)) {
info.setReturnValue(Math.min(1, info.getReturnValueF() + 0.6F));
info.setReturnValue(UnicopiaClient.getWorldBrightness(info.getReturnValueF()));
}
}
}