Skip to content

Commit

Permalink
Update to 1.16-pre2, do The Flattening
Browse files Browse the repository at this point in the history
OkZoomerMod is now split between the keybind management (OkZoomerClientMod) and ZoomUtils. Also, main has been split into client and nothing, you'll see why.
  • Loading branch information
Past Ennui committed Jun 7, 2020
1 parent 57a6b9d commit 90952e3
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 93 deletions.
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
org.gradle.jvmargs = -Xmx1G

# Fabric Properties, check these on http://modmuss50.me/fabric.html
minecraft_version = 20w21a
yarn_mappings = 20w21a+build.17
loader_version = 0.8.4+build.198
minecraft_version = 1.16-pre2
yarn_mappings = 1.16-pre2+build.2
loader_version = 0.8.7+build.201

# Mod Properties
mod_version = 4.0.0-alpha.1.20w21a
mod_version = 4.0.0-alpha.2.1.16.pre2
maven_group = io.github.joaoh1
archives_base_name = okzoomer

# Dependencies
fabric_version = 0.10.10+build.347-1.16
mod_menu_version = 1.11.6+build.11
cloth_config_version = 4.4.0-unstable
fabric_version = 0.11.7+build.356-1.16
mod_menu_version = 1.11.8+build.13
cloth_config_version = 4.5.0-unstable
fiber_version = 0.22.1-1
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
package io.github.joaoh1.okzoomer;
package io.github.joaoh1.okzoomer.client;

import java.util.Random;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;

import io.github.joaoh1.okzoomer.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.utils.ZoomUtils;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.fabric.api.event.client.ClientTickCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier;

//TODO - Split the zoom management from the keybind management.
//This class is responsible for the management of the zoom divisor and of the keybinds.
public class OkZoomerMod implements ClientModInitializer {
public class OkZoomerClientMod implements ClientModInitializer {
//The logger, used here to owo, because why not?
protected static final Logger modLogger = LogManager.getFormatterLogger("Ok Zoomer Next");

public static final int getDefaultKey() {
//If OptiFabric (and therefore, OptiFine) is detected, use Z as the default value instead.
if (FabricLoader.getInstance().isModLoaded("optifabric")) {
modLogger.info("[Ok Zoomer Next] OptiFabric was detected! Using Z as the default key.");
return GLFW.GLFW_KEY_Z;
} else {
return GLFW.GLFW_KEY_C;
}
}

//The zoom keybinding, which will be registered.
public static final FabricKeyBinding zoomKeyBinding = FabricKeyBinding.Builder
.create(new Identifier("okzoomer", "zoom"), InputUtil.Type.KEYSYM, getDefaultKey(), "key.okzoomer.category")
.create(new Identifier("okzoomer", "zoom"), InputUtil.Type.KEYSYM, ZoomUtils.getDefaultZoomKey(), "key.okzoomer.category")
.build();

//The "Decrease Zoom" keybinding.
Expand All @@ -43,39 +35,15 @@ public static final int getDefaultKey() {
.create(new Identifier("okzoomer", "increase_zoom"), InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), "key.okzoomer.category")
.build();

//The zoom signal, which is managed in an event and used by other mixins.
public static boolean isZoomKeyPressed = false;

//Used internally in order to make zoom toggling possible.
private static boolean previousZoomPress = false;

//Used for post-zoom actions like updating the terrain.
public static boolean zoomHasHappened = false;

//The zoom divisor, managed by the zoom press and zoom scrolling. Used by other mixins.
public static double zoomDivisor = OkZoomerConfig.zoomDivisor.getValue();

public static void changeZoomDivisor(boolean increase) {
if (increase) {
if (zoomDivisor < OkZoomerConfig.maximumZoomDivisor.getValue()) {
zoomDivisor += 0.5D;
} else {
zoomDivisor = OkZoomerConfig.maximumZoomDivisor.getValue();
}
} else {
if (zoomDivisor > OkZoomerConfig.minimumZoomDivisor.getValue()) {
zoomDivisor -= 0.5D;
zoomHasHappened = true;
} else {
zoomDivisor = OkZoomerConfig.minimumZoomDivisor.getValue();
}
}
}

@Override
public void onInitializeClient() {
//TODO - Actually do zoom stuff, remove when everything's done.
modLogger.info("[Ok Zoomer Next] owo what's this");
Random random = new Random();
String[] owo = new String[]{"owo", "OwO", "uwu", "nwn", "^w^", ">w<", "Owo", "owO", ";w;", "0w0"};
modLogger.info("[Ok Zoomer Next] " + owo[random.nextInt(10)] + " what's this");

//Register the zoom category.
KeyBindingRegistry.INSTANCE.addCategory("key.okzoomer.category");
Expand All @@ -95,21 +63,21 @@ public void onInitializeClient() {

if (!OkZoomerConfig.zoomToggle.getValue()) {
//If zoom toggling is disabled, then the zoom signal is determined by if the key is pressed or not.
isZoomKeyPressed = zoomKeyBinding.isPressed();
zoomDivisor = OkZoomerConfig.zoomDivisor.getValue();
ZoomUtils.isZoomKeyPressed = zoomKeyBinding.isPressed();
ZoomUtils.zoomDivisor = OkZoomerConfig.zoomDivisor.getValue();
} else {
//If zoom toggling is enabled, toggle the zoom signal instead.
if (zoomKeyBinding.isPressed()) {
isZoomKeyPressed = !isZoomKeyPressed;
zoomDivisor = OkZoomerConfig.zoomDivisor.getValue();
ZoomUtils.isZoomKeyPressed = !ZoomUtils.isZoomKeyPressed;
ZoomUtils.zoomDivisor = OkZoomerConfig.zoomDivisor.getValue();
}
}

//Manage the post-zoom signal.
if (!isZoomKeyPressed && previousZoomPress) {
zoomHasHappened = true;
if (!ZoomUtils.isZoomKeyPressed && previousZoomPress) {
ZoomUtils.zoomHasHappened = true;
} else {
zoomHasHappened = false;
ZoomUtils.zoomHasHappened = false;
}

//Set the previous zoom signal for the next tick.
Expand All @@ -118,11 +86,11 @@ public void onInitializeClient() {

ClientTickCallback.EVENT.register(e -> {
if (decreaseZoomKeyBinding.isPressed()) {
changeZoomDivisor(false);
ZoomUtils.changeZoomDivisor(false);
}

if (increaseZoomKeyBinding.isPressed()) {
changeZoomDivisor(true);
ZoomUtils.changeZoomDivisor(true);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.joaoh1.okzoomer.config;
package io.github.joaoh1.okzoomer.client.config;

import java.io.IOException;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.joaoh1.okzoomer.config;
package io.github.joaoh1.okzoomer.client.config;

import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.joaoh1.okzoomer.config.modmenu;
package io.github.joaoh1.okzoomer.client.config.modmenu;

import io.github.joaoh1.okzoomer.config.OkZoomerConfigScreen;
import io.github.joaoh1.okzoomer.client.config.OkZoomerConfigScreen;
import io.github.prospector.modmenu.api.ConfigScreenFactory;
import io.github.prospector.modmenu.api.ModMenuApi;
import net.fabricmc.api.Environment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.joaoh1.okzoomer.mixin;
package io.github.joaoh1.okzoomer.client.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -7,8 +7,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import io.github.joaoh1.okzoomer.OkZoomerMod;
import io.github.joaoh1.okzoomer.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.utils.ZoomUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.Camera;
import net.minecraft.client.render.GameRenderer;
Expand All @@ -27,8 +27,8 @@ public class GameRendererMixin {
private void updateZoomFovMultiplier() {
float zoomMultiplier = 1.0F;

if (OkZoomerMod.isZoomKeyPressed) {
zoomMultiplier /= OkZoomerMod.zoomDivisor;
if (ZoomUtils.isZoomKeyPressed) {
zoomMultiplier /= ZoomUtils.zoomDivisor;
}

this.lastZoomFovMultiplier = this.zoomFovMultiplier;
Expand Down Expand Up @@ -56,14 +56,14 @@ private double getZoomedFov(Camera camera, float tickDelta, boolean changingFov,
}
} else {
//Handle the zoom without smooth transitions.
if (OkZoomerMod.isZoomKeyPressed) {
double zoomedFov = fov / OkZoomerMod.zoomDivisor;
if (ZoomUtils.isZoomKeyPressed) {
double zoomedFov = fov / ZoomUtils.zoomDivisor;
info.setReturnValue(zoomedFov);
}
}

//Regardless of the mode, if the zoom is over, update the terrain in order to stop terrain glitches.
if (OkZoomerMod.zoomHasHappened) {
if (ZoomUtils.zoomHasHappened) {
if (changingFov) {
this.client.worldRenderer.scheduleTerrainUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package io.github.joaoh1.okzoomer.mixin;
package io.github.joaoh1.okzoomer.client.mixin;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import io.github.joaoh1.okzoomer.OkZoomerMod;
import io.github.joaoh1.okzoomer.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.OkZoomerClientMod;
import io.github.joaoh1.okzoomer.client.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.utils.ZoomUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.RunArgs;
import net.minecraft.client.options.GameOptions;
Expand All @@ -32,6 +33,7 @@ public class MinecraftClientMixin {
@Shadow
public final File runDirectory;

//The logger, used here to let the user know that the "Save Toolbar Activator" keybind has been changed.
private static final Logger modLogger = LogManager.getFormatterLogger("Ok Zoomer Next");

public MinecraftClientMixin(RunArgs args) {
Expand All @@ -43,10 +45,12 @@ public MinecraftClientMixin(RunArgs args) {
public void hijackCKeybind(RunArgs args, CallbackInfo info) {
//If the configuration didn't exist before, unbind the "Save Toolbar Activator" keybind if there's a conflict.
if (!Files.exists(OkZoomerConfig.okZoomerConfigPath)) {
if (OkZoomerMod.zoomKeyBinding.isDefault()) {
if (this.options.keySaveToolbarActivator.isDefault()) {
modLogger.info("[Ok Zoomer Next] The \"Save Toolbar Activator\" keybind was occupying C! Unbinding... This process won't be repeated.");
this.options.keySaveToolbarActivator.setBoundKey(InputUtil.fromKeyCode(InputUtil.UNKNOWN_KEY.getCode(), InputUtil.UNKNOWN_KEY.getCode()));
if (OkZoomerClientMod.zoomKeyBinding.isDefault()) {
if (ZoomUtils.getDefaultZoomKey() == GLFW.GLFW_KEY_C) {
if (this.options.keySaveToolbarActivator.isDefault()) {
modLogger.info("[Ok Zoomer Next] The \"Save Toolbar Activator\" keybind was occupying C! Unbinding... This process won't be repeated.");
this.options.keySaveToolbarActivator.setBoundKey(InputUtil.fromKeyCode(InputUtil.UNKNOWN_KEY.getCode(), InputUtil.UNKNOWN_KEY.getCode()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.joaoh1.okzoomer.mixin;
package io.github.joaoh1.okzoomer.client.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand All @@ -8,8 +8,8 @@
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

import io.github.joaoh1.okzoomer.OkZoomerMod;
import io.github.joaoh1.okzoomer.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.config.OkZoomerConfig;
import io.github.joaoh1.okzoomer.client.utils.ZoomUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.Mouse;
import net.minecraft.client.util.SmoothUtil;
Expand Down Expand Up @@ -51,8 +51,8 @@ public MouseMixin(MinecraftClient client) {
private double applyReduceSensitivity(double g) {
double modifiedMouseSensitivity = this.client.options.mouseSensitivity;
if (OkZoomerConfig.reduceSensitivity.getValue()) {
if (OkZoomerMod.isZoomKeyPressed) {
modifiedMouseSensitivity /= OkZoomerMod.zoomDivisor;
if (ZoomUtils.isZoomKeyPressed) {
modifiedMouseSensitivity /= ZoomUtils.zoomDivisor;
}
}
double appliedMouseSensitivity = modifiedMouseSensitivity * 0.6000000238418579D + 0.20000000298023224D;
Expand All @@ -68,7 +68,7 @@ private void obtainCinematicCameraValues(CallbackInfo info, double d, double e)

@ModifyVariable(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;cursorDeltaX:D", ordinal = 3, shift = At.Shift.BEFORE), method = "updateMouse()V", ordinal = 1)
private double applyCinematicModeX(double l) {
if (!OkZoomerConfig.cinematicCamera.getValue().equals("off") && OkZoomerMod.isZoomKeyPressed) {
if (!OkZoomerConfig.cinematicCamera.getValue().equals("off") && ZoomUtils.isZoomKeyPressed) {
if (OkZoomerConfig.cinematicCamera.getValue().equals("vanilla")) {
if (this.client.options.smoothCameraEnabled) {
l = this.cursorXSmoother.smooth(this.cursorDeltaX * this.adjustedG, (this.extractedE * this.adjustedG));
Expand All @@ -92,7 +92,7 @@ private double applyCinematicModeX(double l) {

@ModifyVariable(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;cursorDeltaY:D", ordinal = 3, shift = At.Shift.BEFORE), method = "updateMouse()V", ordinal = 2)
private double applyCinematicModeY(double m) {
if (!OkZoomerConfig.cinematicCamera.getValue().equals("off") && OkZoomerMod.isZoomKeyPressed) {
if (!OkZoomerConfig.cinematicCamera.getValue().equals("off") && ZoomUtils.isZoomKeyPressed) {
if (OkZoomerConfig.cinematicCamera.getValue().equals("vanilla")) {
if (this.client.options.smoothCameraEnabled) {
m = this.cursorYSmoother.smooth(this.cursorDeltaY * this.adjustedG, (this.extractedE * this.adjustedG));
Expand All @@ -117,12 +117,12 @@ private double applyCinematicModeY(double m) {
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/client/Mouse;eventDeltaWheel:D", ordinal = 7), method = "onMouseScroll(JDD)V", cancellable = true)
private void zoomerOnMouseScroll(CallbackInfo info) {
if (OkZoomerConfig.zoomScrolling.getValue()) {
if (OkZoomerMod.isZoomKeyPressed) {
if (ZoomUtils.isZoomKeyPressed) {
if (this.eventDeltaWheel != 0.0) {
if (this.eventDeltaWheel > 0.0) {
OkZoomerMod.changeZoomDivisor(true);
ZoomUtils.changeZoomDivisor(true);
} else if (this.eventDeltaWheel < 0.0) {
OkZoomerMod.changeZoomDivisor(false);
ZoomUtils.changeZoomDivisor(false);
}

info.cancel();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package io.github.joaoh1.okzoomer.client.utils;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.glfw.GLFW;

import io.github.joaoh1.okzoomer.client.config.OkZoomerConfig;
import net.fabricmc.loader.api.FabricLoader;

public class ZoomUtils {
//The logger, used here for letting the user know that the zoom key isn't C if Z is chosen.
protected static final Logger modLogger = LogManager.getFormatterLogger("Ok Zoomer Next");

public static final int getDefaultZoomKey() {
//If OptiFabric (and therefore, OptiFine) is detected, use Z as the default value instead.
if (FabricLoader.getInstance().isModLoaded("optifabric")) {
modLogger.info("[Ok Zoomer Next] OptiFabric was detected! Using Z as the default key.");
return GLFW.GLFW_KEY_Z;
} else {
return GLFW.GLFW_KEY_C;
}
}

//The zoom signal, which is managed in an event and used by other mixins.
public static boolean isZoomKeyPressed = false;

//Used for post-zoom actions like updating the terrain.
public static boolean zoomHasHappened = false;

//The zoom divisor, managed by the zoom press and zoom scrolling. Used by other mixins.
public static double zoomDivisor = OkZoomerConfig.zoomDivisor.getValue();

//
public static void changeZoomDivisor(boolean increase) {
if (increase) {
if (zoomDivisor < OkZoomerConfig.maximumZoomDivisor.getValue()) {
zoomDivisor += 0.5D;
} else {
zoomDivisor = OkZoomerConfig.maximumZoomDivisor.getValue();
}
} else {
if (zoomDivisor > OkZoomerConfig.minimumZoomDivisor.getValue()) {
zoomDivisor -= 0.5D;
zoomHasHappened = true;
} else {
zoomDivisor = OkZoomerConfig.minimumZoomDivisor.getValue();
}
}
}
}
Loading

0 comments on commit 90952e3

Please sign in to comment.