Skip to content

Commit

Permalink
cleanup + more math
Browse files Browse the repository at this point in the history
  • Loading branch information
CammiePone committed Oct 18, 2021
1 parent e1bf35c commit 54f7f97
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
6 changes: 2 additions & 4 deletions src/main/java/dev/cammiescorner/icarus/Icarus.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<IcarusConfig> configHolder;

@Override
public void onInitialize()
{
public void onInitialize() {
AutoConfig.register(IcarusConfig.class, JanksonConfigSerializer::new);
configHolder = AutoConfig.getConfigHolder(IcarusConfig.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* MIT License
*
* <p>
* Copyright (c) 2020 Mirsario
*
* <p>
* 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:
*
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* <p>
* 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
Expand Down Expand Up @@ -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<TrinketComponent> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,19 @@

public final class CameraSystem implements CameraUpdateCallback {
private static double prevRollOffset;
private static double lerpSpeed = 1.0D;

public CameraSystem() {
CameraUpdateCallback.EVENT.Register(this);
}

@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;
}
Expand All @@ -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);

Expand Down

0 comments on commit 54f7f97

Please sign in to comment.