Skip to content

Commit

Permalink
the merge of all time
Browse files Browse the repository at this point in the history
how fun
  • Loading branch information
rhysdh540 committed Apr 26, 2024
2 parents 4402ca7 + ce04b32 commit a850401
Show file tree
Hide file tree
Showing 88 changed files with 956 additions and 597 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
- name: :build
run: ./gradlew build
run: ./gradlew build --stacktrace
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
- added support for NeoForge 20.5+
- made missing dependencies error on Fabric more user-friendly
- improved mod compatibility by using events on LexForge for mc17-mc18.2
- added explicit incompatibility with outdated versions of Embeddium++ which were causing obscure crashes
- fixed crash on NeoForge 20.5+
- many internal refactors
- further improvements to overall system stability and other minor adjustments have been made to enhance the user experience
5 changes: 3 additions & 2 deletions common/build.gradle.kts → api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ operator fun String.invoke(): String {
}

buildConfig {
className("Constants")
packageName("dev.nolij.zume.common")
className("ZumeConstants")
packageName("dev.nolij.zume.impl")

useJavaOutput()

// the below errors shown by IntelliJ can be safely ignored; Jabel works around this
buildConfigField("MOD_ID", "mod_id"())
buildConfigField("MOD_VERSION", Zume.version)
buildConfigField("MOD_NAME", "mod_name"())
buildConfigField("ARCHAIC_VERSION_RANGE", "archaic_minecraft_range"())
Expand Down
20 changes: 20 additions & 0 deletions api/src/main/java/dev/nolij/zume/api/config/v0/ZumeConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.nolij.zume.api.config.v0;

public class ZumeConfig {

public boolean isCinematicZoomEnabled;
public double mouseSensitivityFloor;
public short zoomSpeed;
public boolean isZoomScrollingEnabled;
public short zoomSmoothnessMilliseconds;
public double animationEasingExponent;
public double zoomEasingExponent;
public double defaultZoom;
public boolean isFirstPersonToggleModeEnabled;
public boolean isThirdPersonToggleModeEnabled;
public double minimumFOV;
public double maximumThirdPersonZoomBlocks;
public double minimumThirdPersonZoomBlocks;
public boolean isDisabled;

}
106 changes: 106 additions & 0 deletions api/src/main/java/dev/nolij/zume/api/config/v0/ZumeConfigAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package dev.nolij.zume.api.config.v0;

import dev.nolij.zume.impl.Zume;
import dev.nolij.zume.impl.config.ZumeConfigImpl;

public final class ZumeConfigAPI {

public static boolean isCinematicZoomEnabled() {
return Zume.config.enableCinematicZoom;
}

public static double getMouseSensitivityFloor() {
return Zume.config.mouseSensitivityFloor;
}

public static short getZoomSpeed() {
return Zume.config.zoomSpeed;
}

public static boolean isZoomScrollingEnabled() {
return Zume.config.enableZoomScrolling;
}

public static short getZoomSmoothnessMilliseconds() {
return Zume.config.zoomSmoothnessMs;
}

public static double getAnimationEasingExponent() {
return Zume.config.animationEasingExponent;
}

public static double getZoomEasingExponent() {
return Zume.config.zoomEasingExponent;
}

public static double getDefaultZoom() {
return Zume.config.defaultZoom;
}

public static boolean isFirstPersonToggleModeEnabled() {
return Zume.config.toggleMode;
}

public static boolean isThirdPersonToggleModeEnabled() {
return Zume.config.thirdPersonToggleMode;
}

public static double getMinimumFOV() {
return Zume.config.minFOV;
}

public static double getMaximumThirdPersonZoomBlocks() {
return Zume.config.maxThirdPersonZoomDistance;
}

public static double getMinimumThirdPersonZoomBlocks() {
return Zume.config.minThirdPersonZoomDistance;
}

public static boolean isDisabled() {
return Zume.config.disable;
}

public static ZumeConfig getSnapshot() {
final ZumeConfig snapshot = new ZumeConfig();

snapshot.isCinematicZoomEnabled = isCinematicZoomEnabled();
snapshot.mouseSensitivityFloor = getMouseSensitivityFloor();
snapshot.zoomSpeed = getZoomSpeed();
snapshot.isZoomScrollingEnabled = isZoomScrollingEnabled();
snapshot.zoomSmoothnessMilliseconds = getZoomSmoothnessMilliseconds();
snapshot.animationEasingExponent = getAnimationEasingExponent();
snapshot.zoomEasingExponent = getZoomEasingExponent();
snapshot.defaultZoom = getDefaultZoom();
snapshot.isFirstPersonToggleModeEnabled = isFirstPersonToggleModeEnabled();
snapshot.isThirdPersonToggleModeEnabled = isThirdPersonToggleModeEnabled();
snapshot.minimumFOV = getMinimumFOV();
snapshot.maximumThirdPersonZoomBlocks = getMaximumThirdPersonZoomBlocks();
snapshot.minimumThirdPersonZoomBlocks = getMinimumThirdPersonZoomBlocks();
snapshot.isDisabled = isDisabled();

return snapshot;
}

public static void replaceConfig(ZumeConfig replacement) throws InterruptedException {
final ZumeConfigImpl config = new ZumeConfigImpl();

config.enableCinematicZoom = replacement.isCinematicZoomEnabled;
config.mouseSensitivityFloor = replacement.mouseSensitivityFloor;
config.zoomSpeed = replacement.zoomSpeed;
config.enableZoomScrolling = replacement.isZoomScrollingEnabled;
config.zoomSmoothnessMs = replacement.zoomSmoothnessMilliseconds;
config.animationEasingExponent = replacement.animationEasingExponent;
config.zoomEasingExponent = replacement.zoomEasingExponent;
config.defaultZoom = replacement.defaultZoom;
config.toggleMode = replacement.isFirstPersonToggleModeEnabled;
config.thirdPersonToggleMode = replacement.isThirdPersonToggleModeEnabled;
config.minFOV = replacement.minimumFOV;
config.maxThirdPersonZoomDistance = replacement.maximumThirdPersonZoomBlocks;
config.minThirdPersonZoomDistance = replacement.minimumThirdPersonZoomBlocks;
config.disable = replacement.isDisabled;

ZumeConfigImpl.replace(config);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.nolij.zume.api.platform.v0;

public enum CameraPerspective {

FIRST_PERSON,
THIRD_PERSON,
THIRD_PERSON_FLIPPED,

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.nolij.zume.common;
package dev.nolij.zume.api.platform.v0;

public interface IZumeImplementation {

Expand Down
143 changes: 143 additions & 0 deletions api/src/main/java/dev/nolij/zume/api/platform/v0/ZumeAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package dev.nolij.zume.api.platform.v0;

import dev.nolij.zume.impl.CameraPerspective;
import dev.nolij.zume.impl.Zume;
import org.apache.logging.log4j.Logger;

import java.nio.file.Path;

public final class ZumeAPI {

public static Logger getLogger() {
return Zume.LOGGER;
}

/**
* Attempts to open Zume's config file in the system's text editor.
*/
public static void openConfigFile() {
Zume.openConfigFile();
}

/**
* Invoke this in the initializer of your Zume implementation.
*
* @param implementation The {@linkplain IZumeImplementation} Zume should use.
* @param instanceConfigPath The {@linkplain Path} Zume should use for storing the instance-specific config.
*/
public static void registerImplementation(IZumeImplementation implementation, Path instanceConfigPath) {
Zume.init(new dev.nolij.zume.impl.IZumeImplementation() {
@Override
public boolean isZoomPressed() {
return implementation.isZoomPressed();
}

@Override
public boolean isZoomInPressed() {
return implementation.isZoomInPressed();
}

@Override
public boolean isZoomOutPressed() {
return implementation.isZoomOutPressed();
}

@Override
public CameraPerspective getCameraPerspective() {
return CameraPerspective.values()[implementation.getCameraPerspective().ordinal()];
}

@Override
public void onZoomActivate() {
implementation.onZoomActivate();
}
}, instanceConfigPath);
}

//region Query Methods
/**
* Returns `true` if Zoom is activated.
*/
public static boolean isActive() {
return Zume.isEnabled();
}

/**
* Returns `true` if FOV should be hooked.
*/
public static boolean isFOVHookActive() {
return Zume.shouldHookFOV();
}

/**
* Returns `true` if mouse scrolling should be hooked.
*/
public static boolean isMouseScrollHookActive() {
return Zume.shouldCancelScroll();
}
//endregion

//region Hooks
/**
* This should be invoked once at the beginning of every frame.
* It will handle Keybindings and Zoom Scrolling if the other hooks in this API are used correctly.
*/
public static void renderHook() {
Zume.render();
}

/**
* ONLY INVOKE THIS METHOD WHEN {@linkplain ZumeAPI#isFOVHookActive()} RETURNS `true`.
* That check was explicitly excluded from this method for efficiency and for mixin compatibility.
* The {@linkplain IZumeImplementation} is responsible for this check.
*
* @param fov The unmodified FOV value
* {@return The new FOV transformed by Zume}
*/
public static double fovHook(double fov) {
return Zume.transformFOV(fov);
}

/**
* This method assumes Zume is active and the camera perspective is third-person.
* If it is not, using this value will cause bugs.
*
* @param distance The vanilla third-person camera distance
* @return The new third-person camera distance
*/
public static double thirdPersonCameraHook(double distance) {
return Zume.transformThirdPersonDistance(distance);
}

/**
* The return value of this method can be safely used without checking whether Zume is active.
*
* @param mouseSensitivity The unmodified mouse sensitivity
* {@return The new mouse sensitivity, transformed by Zume}
*/
public static double mouseSensitivityHook(double mouseSensitivity) {
return Zume.transformMouseSensitivity(mouseSensitivity);
}

/**
* The return value of this method can be safely used without checking whether Zume is active.
*
* @param cinematicCameraEnabled The unmodified cinematic camera state
* {@return The new cinematic camera state, transformed by Zume}
*/
public static boolean cinematicCameraEnabledHook(boolean cinematicCameraEnabled) {
return Zume.transformCinematicCamera(cinematicCameraEnabled);
}

/**
* The return value of this method can be safely used without checking whether Zume is active.
*
* @param scrollDelta The scroll delta (magnitude will be ignored, only the sign is used)
* {@return `true` if the invoker should prevent further handling of this scroll event}
*/
public static boolean mouseScrollHook(int scrollDelta) {
return Zume.interceptScroll(scrollDelta);
}
//endregion

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.nolij.zume.common.easing;
package dev.nolij.zume.api.util.v0;

public final class EasingHelper {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.nolij.zume.common.util;
package dev.nolij.zume.api.util.v0;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
Expand All @@ -25,6 +25,14 @@ public static Class<?> getClassOrNull(String className) {
}
}

public static Class<?> getClassOrNull(ClassLoader classLoader, String className) {
try {
return Class.forName(className, true, classLoader);
} catch (ClassNotFoundException ignored) {
return null;
}
}

public static Class<?> getClassOrNull(String... classNames) {
for (final String className : classNames) {
try {
Expand All @@ -35,6 +43,16 @@ public static Class<?> getClassOrNull(String... classNames) {
return null;
}

public static Class<?> getClassOrNull(ClassLoader classLoader, String... classNames) {
for (final String className : classNames) {
try {
return Class.forName(className, true, classLoader);
} catch (ClassNotFoundException ignored) { }
}

return null;
}

public static MethodHandle getMethodOrNull(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
if (clazz == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.nolij.zume.common;
package dev.nolij.zume.impl;

public enum CameraPerspective {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package dev.nolij.zume.common.easing;
package dev.nolij.zume.impl;

import dev.nolij.zume.api.util.v0.EasingHelper;

public class EasedDouble {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.nolij.zume.common;
package dev.nolij.zume.impl;

public enum HostPlatform {

Expand Down
13 changes: 13 additions & 0 deletions api/src/main/java/dev/nolij/zume/impl/IZumeImplementation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.nolij.zume.impl;

public interface IZumeImplementation {

boolean isZoomPressed();
boolean isZoomInPressed();
boolean isZoomOutPressed();

CameraPerspective getCameraPerspective();

void onZoomActivate();

}
Loading

0 comments on commit a850401

Please sign in to comment.