From 54f7f973031b11a90a5240157aaf1972fddfcd0c Mon Sep 17 00:00:00 2001 From: CammiePone Date: Mon, 18 Oct 2021 12:15:37 -0400 Subject: [PATCH] cleanup + more math --- .../java/dev/cammiescorner/icarus/Icarus.java | 6 ++--- .../core/mixins/client/GameRendererMixin.java | 26 +++++++------------ .../icarus/core/util/CameraSystem.java | 6 +++-- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/main/java/dev/cammiescorner/icarus/Icarus.java b/src/main/java/dev/cammiescorner/icarus/Icarus.java index 82d1b3a..bce01a2 100644 --- a/src/main/java/dev/cammiescorner/icarus/Icarus.java +++ b/src/main/java/dev/cammiescorner/icarus/Icarus.java @@ -13,15 +13,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; -public class Icarus implements ModInitializer -{ +public class Icarus implements ModInitializer { public static final String MOD_ID = "icarus"; public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(new Identifier(MOD_ID, "general"), () -> new ItemStack(ModItems.WHITE_FEATHERED_WINGS)); private static ConfigHolder configHolder; @Override - public void onInitialize() - { + public void onInitialize() { AutoConfig.register(IcarusConfig.class, JanksonConfigSerializer::new); configHolder = AutoConfig.getConfigHolder(IcarusConfig.class); diff --git a/src/main/java/dev/cammiescorner/icarus/core/mixins/client/GameRendererMixin.java b/src/main/java/dev/cammiescorner/icarus/core/mixins/client/GameRendererMixin.java index 6e45dd3..059802b 100644 --- a/src/main/java/dev/cammiescorner/icarus/core/mixins/client/GameRendererMixin.java +++ b/src/main/java/dev/cammiescorner/icarus/core/mixins/client/GameRendererMixin.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2020 Mirsario - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -46,24 +46,16 @@ import java.util.Optional; @Mixin(GameRenderer.class) -public abstract class GameRendererMixin implements SynchronousResourceReloader, AutoCloseable -{ - @Shadow - @Final - private MinecraftClient client; - - @Shadow - @Final - private Camera camera; +public abstract class GameRendererMixin implements SynchronousResourceReloader, AutoCloseable { + @Shadow @Final private MinecraftClient client; + @Shadow @Final private Camera camera; @Inject(method = "renderWorld", at = @At(value = "INVOKE", shift = At.Shift.BEFORE, target = "Lnet/minecraft/client/render/WorldRenderer;render(Lnet/minecraft/client/util/math/MatrixStack;FJZLnet/minecraft/client/render/Camera;Lnet/minecraft/client/render/GameRenderer;Lnet/minecraft/client/render/LightmapTextureManager;Lnet/minecraft/util/math/Matrix4f;)V")) - private void PostCameraUpdate(float tickDelta, long limitTime, MatrixStack matrix, CallbackInfo info) - { + private void PostCameraUpdate(float tickDelta, long limitTime, MatrixStack matrix, CallbackInfo info) { Optional component = TrinketsApi.getTrinketComponent(client.player); boolean isWingItem = component.isPresent() && component.get().isEquipped(itemStack -> itemStack.getItem() instanceof WingItem); - if(client.player.isFallFlying() && isWingItem) - { + if(client.player != null && client.player.isFallFlying() && isWingItem) { Transform cameraTransform = new Transform(camera.getPos(), new Vec3d(camera.getPitch(), camera.getYaw(), 0D)); cameraTransform = CameraUpdateCallback.EVENT.Invoker().onCameraUpdate(camera, cameraTransform, tickDelta); diff --git a/src/main/java/dev/cammiescorner/icarus/core/util/CameraSystem.java b/src/main/java/dev/cammiescorner/icarus/core/util/CameraSystem.java index e4cb43d..701f5b3 100644 --- a/src/main/java/dev/cammiescorner/icarus/core/util/CameraSystem.java +++ b/src/main/java/dev/cammiescorner/icarus/core/util/CameraSystem.java @@ -32,7 +32,6 @@ public final class CameraSystem implements CameraUpdateCallback { private static double prevRollOffset; - private static double lerpSpeed = 1.0D; public CameraSystem() { CameraUpdateCallback.EVENT.Register(this); @@ -40,10 +39,12 @@ public CameraSystem() { @Override public Transform onCameraUpdate(Camera camera, Transform cameraTransform, float deltaTime) { + float pitch = camera.getPitch(); + float rollAmount = (pitch < -90 || pitch > 90) ? Icarus.getConfig().rollAmount : -Icarus.getConfig().rollAmount; Vec3d velocity = camera.getFocusedEntity().getVelocity(); Vec2f relativeXZVelocity = rotate(new Vec2f((float) velocity.x, (float) velocity.z), 360.0F - (float) cameraTransform.eulerRot.y); - rollOffset(cameraTransform, relativeXZVelocity, deltaTime, -Icarus.getConfig().rollAmount); + rollOffset(cameraTransform, relativeXZVelocity, deltaTime, rollAmount); return cameraTransform; } @@ -58,6 +59,7 @@ public static Vec2f rotate(Vec2f vec, float degrees) { private void rollOffset(Transform transform, Vec2f relativeXZVelocity, double deltaTime, float intensity) { double strafingRollOffset = -relativeXZVelocity.x * 15.0D; + double lerpSpeed = 1.0D; prevRollOffset = strafingRollOffset = lerp(prevRollOffset, strafingRollOffset, deltaTime * lerpSpeed);