From 31681666d4aa92de2c2e2667f04dc3946299345e Mon Sep 17 00:00:00 2001 From: hf02 Date: Mon, 24 Jul 2023 15:19:03 -0400 Subject: [PATCH] delete files --- .../ScrollForWorldEdit.java | 24 -- .../hf02/scrollForWorldEdit/client/Key.java | 46 --- .../scrollForWorldEdit/client/KeyHandler.java | 5 - .../scrollForWorldEdit/client/KeyManager.java | 257 ----------------- .../client/MouseScrollCallback.java | 32 --- .../client/MouseScrollHandler.java | 83 ------ .../client/ScrollForWorldEditClient.java | 267 ------------------ .../client/StatusTextType.java | 7 - .../scrollForWorldEdit/client/TakeScroll.java | 12 - .../client/TextDirectionType.java | 9 - .../client/TextRenderer.java | 73 ----- .../config/ModMenuIntegration.java | 16 -- .../config/ScrollForWorldEditConfig.java | 52 ---- .../mixin/MouseWheelMixin.java | 29 -- .../mixin/TextHudMixin.java | 22 -- .../hf02/scrollForWorldedit/client/Key.java | 46 --- .../scrollForWorldedit/client/KeyHandler.java | 5 - .../scrollForWorldedit/client/KeyManager.java | 257 ----------------- .../client/MouseScrollCallback.java | 32 --- .../client/MouseScrollHandler.java | 83 ------ .../client/ScrollForWorldEditClient.java | 267 ------------------ .../client/StatusTextType.java | 7 - .../scrollForWorldedit/client/TakeScroll.java | 12 - .../client/TextDirectionType.java | 9 - .../client/TextRenderer.java | 73 ----- .../config/ModMenuIntegration.java | 16 -- .../config/ScrollForWorldEditConfig.java | 52 ---- .../mixin/MouseWheelMixin.java | 29 -- .../mixin/TextHudMixin.java | 22 -- 29 files changed, 1844 deletions(-) delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/ScrollForWorldEdit.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/Key.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyHandler.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyManager.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollCallback.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollHandler.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/ScrollForWorldEditClient.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/StatusTextType.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/TakeScroll.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/TextDirectionType.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/client/TextRenderer.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/config/ModMenuIntegration.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/config/ScrollForWorldEditConfig.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/mixin/MouseWheelMixin.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldEdit/mixin/TextHudMixin.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/Key.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/KeyHandler.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/KeyManager.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollCallback.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollHandler.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/ScrollForWorldEditClient.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/StatusTextType.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/TakeScroll.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/TextDirectionType.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/client/TextRenderer.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/config/ModMenuIntegration.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/config/ScrollForWorldEditConfig.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/mixin/MouseWheelMixin.java delete mode 100644 src/main/java/com/github/hf02/scrollForWorldedit/mixin/TextHudMixin.java diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/ScrollForWorldEdit.java b/src/main/java/com/github/hf02/scrollForWorldEdit/ScrollForWorldEdit.java deleted file mode 100644 index 451c8db..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/ScrollForWorldEdit.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.hf02.scrollForWorldEdit; - -import net.fabricmc.api.ModInitializer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ScrollForWorldEdit implements ModInitializer { - - // This logger is used to write text to the console and the log file. - // It is considered best practice to use your mod id as the logger's name. - // That way, it's clear which mod wrote info, warnings, and errors. - public static final Logger LOGGER = LoggerFactory.getLogger( - "scroll-for-worldedit" - ); - - @Override - public void onInitialize() { - // This code runs as soon as Minecraft is in a mod-load-ready state. - // However, some things (like resources) may still be uninitialized. - // Proceed with mild caution. - - LOGGER.info("Scroll for WorldEdit :)"); - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/Key.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/Key.java deleted file mode 100644 index 4fa1f97..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/Key.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.option.KeyBinding; - -public class Key { - - public final String code; - public final String name; - public final String command; - public final KeyBinding keybinding; - public final KeyManager keyManager; - private final ScrollForWorldEditClient scrollClient; - public final KeyHandler handler; - - public Key( - KeyManager keyManager, - String code, - String command, - String name, - String keybindingName, - net.minecraft.client.util.InputUtil.Type type, - int defaultCode, - String category, - KeyHandler handler - ) { - this.keyManager = keyManager; - this.code = code; - this.command = command; - this.name = name; - this.scrollClient = keyManager.scrollClient; - this.handler = handler; - this.keybinding = - KeyBindingHelper.registerKeyBinding( - new KeyBinding(keybindingName, type, defaultCode, category) - ); - } - - public void run(TakeScroll scroll) { - boolean isActive = keyManager.isKeyActive(this.code); - if (isActive) { - scrollClient.mouseHandler.capturingScroll = true; - this.handler.callback(this, scroll); - } - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyHandler.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyHandler.java deleted file mode 100644 index 990d652..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyHandler.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public interface KeyHandler { - void callback(Key key, TakeScroll scroll); -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyManager.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyManager.java deleted file mode 100644 index e4403ff..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/KeyManager.java +++ /dev/null @@ -1,257 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import com.github.hf02.scrollForWorldEdit.ScrollForWorldEdit; -import java.util.Optional; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import org.lwjgl.glfw.GLFW; - -public class KeyManager { - - private Key[] keys; - - public final int count; - - public final KeyBinding modeKey = KeyBindingHelper.registerKeyBinding( - new KeyBinding( - "key.scroll-for-worldedit.mode", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_LEFT_CONTROL, - "key.scroll-for-worldedit.main" - ) - ); - private boolean modeKeyToggle = false; - - public final KeyBinding useKey = KeyBindingHelper.registerKeyBinding( - new KeyBinding( - "key.scroll-for-worldedit.use", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_LEFT_ALT, - "key.scroll-for-worldedit.main" - ) - ); - private boolean useKeyToggle = false; - - public final KeyBinding modifierKey = KeyBindingHelper.registerKeyBinding( - new KeyBinding( - "key.scroll-for-worldedit.modifier", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_Z, - "key.scroll-for-worldedit.main" - ) - ); - - private Optional getKey(String code) { - for (Key key : keys) { - if (key.code == code) { - return Optional.of(key); - } - } - return Optional.empty(); - } - - public boolean isUseKeyActive() { - return ScrollForWorldEditClient.config.useKeyToggles - ? useKeyToggle - : useKey.isPressed(); - } - - public boolean isModeKeyActive() { - boolean modeKeyAllowed = ScrollForWorldEditClient.config.mustHoldUseKeyForModeKey - ? isUseKeyActive() - : true; - boolean modeKeyPressed = ScrollForWorldEditClient.config.modeKeyToggles - ? modeKeyToggle - : modeKey.isPressed(); - return modeKeyAllowed && modeKeyPressed; - } - - private int activeKeyIndex = 0; - private Key activeKey; - - public void setActiveKey(int index) { - activeKeyIndex = index % count; - if (activeKeyIndex < 0) { - activeKeyIndex = count + activeKeyIndex; - } - activeKey = keys[activeKeyIndex]; - } - - public Key getActiveKey() { - return activeKey; - } - - public int getActiveKeyIndex() { - return activeKeyIndex; - } - - public final ScrollForWorldEditClient scrollClient; - - public KeyManager(ScrollForWorldEditClient scrollForWorldEditClient) { - this.scrollClient = scrollForWorldEditClient; - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - while (useKey.wasPressed()) { - useKeyToggle = - ScrollForWorldEditClient.config.useKeyToggles - ? !useKeyToggle - : false; - } - while (modeKey.wasPressed()) { - modeKeyToggle = - ScrollForWorldEditClient.config.modeKeyToggles - ? !modeKeyToggle - : false; - } - }); - - keys = - new Key[] { - new Key( - this, - "move", - "/move %s %s -s", - "scroll-for-worldedit.mode.move", - "key.scroll-for-worldedit.move", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runNonNegativeMove - ), - new Key( - this, - "expand", - "/expand %s %s", - "scroll-for-worldedit.mode.expand", - "key.scroll-for-worldedit.expand", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runMove - ), - new Key( - this, - "contract", - "/contract %s %s", - "scroll-for-worldedit.mode.contract", - "key.scroll-for-worldedit.contract", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runMove - ), - new Key( - this, - "shift", - "/shift %s %s", - "scroll-for-worldedit.mode.shift", - "key.scroll-for-worldedit.shift", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runMove - ), - new Key( - this, - "stack", - "/stack %s %s -s", - "scroll-for-worldedit.mode.stack", - "key.scroll-for-worldedit.stack", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runNonNegativeMove - ), - }; - count = keys.length; - setActiveKey(0); - } - - public boolean isKeyActive(String keyName) { - Optional key = getKey(keyName); - if (!key.isPresent()) { - ScrollForWorldEdit.LOGGER.warn( - String.format("isKeyActive(): Unknown key %s", keyName) - ); - return false; - } - if (isUseKeyActive() && activeKey == key.get()) { - return true; - } - return key.get().keybinding.isPressed(); - } - - public void processKeys(TakeScroll scroll) { - for (Key key : keys) { - key.run(scroll); - } - } - - private void sendCommand(String command) { - scrollClient.client.player.networkHandler.sendChatCommand(command); - } - - // methods to handle Keys - - private void runNonNegativeMove(Key key, TakeScroll scroll) { - if (scroll.scrollY > 0) { - sendCommand( - String.format( - key.command, - scroll.scrollY, - scrollClient.primaryTextDirection() - ) - ); - } else if (scroll.scrollY < 0) { - sendCommand( - String.format( - key.command, - -scroll.scrollY, - scrollClient.primaryTextDirection(true) - ) - ); - } - - if (scroll.scrollX > 0) { - sendCommand( - String.format( - key.command, - scroll.scrollX, - scrollClient.secondaryTextDirection() - ) - ); - } else if (scroll.scrollX < 0) { - sendCommand( - String.format( - key.command, - -scroll.scrollX, - scrollClient.secondaryTextDirection(true) - ) - ); - } - } - - private void runMove(Key key, TakeScroll scroll) { - if (scroll.scrollY != 0) { - sendCommand( - String.format( - key.command, - scroll.scrollY, - scrollClient.primaryTextDirection() - ) - ); - } - - if (scroll.scrollX != 0) { - sendCommand( - String.format( - key.command, - scroll.scrollX, - scrollClient.secondaryTextDirection() - ) - ); - } - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollCallback.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollCallback.java deleted file mode 100644 index 5b791dc..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollCallback.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.util.ActionResult; - -/** - * callback for the mouse scrolling. - * returning SUCCESS will cancel minecraft's handling of the mouse - * wheel. - */ -public interface MouseScrollCallback { - Event EVENT = EventFactory.createArrayBacked( - MouseScrollCallback.class, - listeners -> - (horizontal, vertical) -> { - for (MouseScrollCallback listener : listeners) { - ActionResult result = listener.interact( - horizontal, - vertical - ); - - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - } - ); - - ActionResult interact(double horizontal, double vertical); -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollHandler.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollHandler.java deleted file mode 100644 index 8fd1c6e..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/MouseScrollHandler.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.minecraft.util.ActionResult; - -public class MouseScrollHandler { - - private double scrollLeftY = 0; - - private double scrollLeftX = 0; - - public boolean capturingScroll = false; - - public int takeScrollY() { - int scrolled = 0; - if (ScrollForWorldEditClient.config.scrollThresholdY <= 0) { - ScrollForWorldEditClient.config.scrollThresholdY = 1; - } - while (true) { - final double scrollLeftRounded = - ScrollForWorldEditClient.config.scrollThresholdY * - Math.floor( - scrollLeftY / - ScrollForWorldEditClient.config.scrollThresholdY - ); - if (scrollLeftRounded == 0) { - break; - } else if (scrollLeftRounded > 0) { - scrollLeftY -= ScrollForWorldEditClient.config.scrollThresholdY; - scrolled++; - } else { - scrollLeftY += ScrollForWorldEditClient.config.scrollThresholdY; - scrolled--; - } - } - return scrolled; - } - - public int takeScrollX() { - int scrolled = 0; - if (ScrollForWorldEditClient.config.scrollThresholdX <= 0) { - ScrollForWorldEditClient.config.scrollThresholdX = 1; - } - while (true) { - final double scrollLeftRounded = - ScrollForWorldEditClient.config.scrollThresholdY * - Math.floor( - scrollLeftX / - ScrollForWorldEditClient.config.scrollThresholdX - ); - if (scrollLeftRounded == 0) { - break; - } else if (scrollLeftRounded > 0) { - scrollLeftX -= ScrollForWorldEditClient.config.scrollThresholdX; - scrolled++; - } else { - scrollLeftX += ScrollForWorldEditClient.config.scrollThresholdX; - scrolled--; - } - } - return scrolled; - } - - public TakeScroll takeScroll() { - return new TakeScroll(takeScrollX(), takeScrollY()); - } - - public void updateScrollCapture() { - if (capturingScroll == false) { - scrollLeftY = 0; - } - } - - public MouseScrollHandler() { - MouseScrollCallback.EVENT.register((horizontal, vertical) -> { - if (capturingScroll) { - scrollLeftY += vertical; - scrollLeftX += horizontal; - return ActionResult.SUCCESS; - } - return ActionResult.PASS; - }); - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/ScrollForWorldEditClient.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/ScrollForWorldEditClient.java deleted file mode 100644 index c8a4886..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/ScrollForWorldEditClient.java +++ /dev/null @@ -1,267 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import com.github.hf02.scrollForWorldEdit.ScrollForWorldEdit; -import com.github.hf02.scrollForWorldEdit.config.ScrollForWorldEditConfig; -import me.shedaniel.autoconfig.AutoConfig; -import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.text.TextColor; - -public class ScrollForWorldEditClient implements ClientModInitializer { - - public KeyManager keyManager; - - public static TextRenderer textRenderer = new TextRenderer(); - public static MinecraftClient client; - public final MouseScrollHandler mouseHandler = new MouseScrollHandler(); - public static ScrollForWorldEditConfig config; - - @Override - public void onInitializeClient() { - this.keyManager = new KeyManager(this); - - AutoConfig.register( - ScrollForWorldEditConfig.class, - JanksonConfigSerializer::new - ); - config = - AutoConfig - .getConfigHolder(ScrollForWorldEditConfig.class) - .getConfig(); - - client = MinecraftClient.getInstance(); - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (client.player == null) return; - - mouseHandler.capturingScroll = - keyManager.isModeKeyActive() || keyManager.isUseKeyActive(); - textRenderer.shouldRenderText = mouseHandler.capturingScroll; - - final TakeScroll scrollTaken = mouseHandler.takeScroll(); - - if (keyManager.isModeKeyActive()) { - keyManager.setActiveKey( - (int) (keyManager.getActiveKeyIndex() - scrollTaken.scrollY) - ); - textRenderer.changingMode = true; - } else { - keyManager.processKeys(scrollTaken); - textRenderer.changingMode = false; - } - - if (textRenderer.shouldRenderText) { - switch (config.statusTextType) { - case OneLined: - textRenderer.text = - new Text[] { - Text.translatable( - "scroll-for-worldedit.hud_selector_single", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - }; - break; - case TwoLined: - textRenderer.text = - new Text[] { - Text.translatable( - "scroll-for-worldedit.hud_selector_top", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - Text.translatable( - "scroll-for-worldedit.hud_selector_bottom", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - }; - break; - case TwoLinedWheel: - MutableText scrollText = Text.empty(); - int keyIndex = keyManager.getActiveKeyIndex(); - for (int i = 0; i < keyManager.count; i++) { - if (i == keyIndex) { - scrollText.append( - Text - .translatable( - "scroll-for-worldedit.hud_selector_top_selected" - ) - .setStyle( - Style.EMPTY.withColor( - config.wheelSelectedColor - ) - ) - ); - } else { - scrollText.append( - Text - .translatable( - "scroll-for-worldedit.hud_selector_top_unselected" - ) - .setStyle( - Style.EMPTY.withColor( - config.wheelUnselectedColor - ) - ) - ); - } - } - textRenderer.text = - new Text[] { - scrollText, - Text.translatable( - "scroll-for-worldedit.hud_selector_bottom", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - }; - break; - default: - break; - } - } - }); - } - - public String getTextDirection( - float rotationX, - float rotationY, - boolean allowVerticalLook - ) { - if (allowVerticalLook) { - if (inRange(rotationX, 60, 90)) { - return "down"; - } - if (inRange(rotationX, -90, -60)) { - return "up"; - } - } - if (inRange(rotationY, 0, 45) || inRange(rotationY, 315, 360)) { - return "south"; - } - if (inRange(rotationY, 45, 135)) { - return "west"; - } - if (inRange(rotationY, 135, 225)) { - return "north"; - } - if (inRange(rotationY, 225, 315)) { - return "east"; - } - return "me"; - } - - public String getTextDirection(float rotationX, float rotationY) { - return getTextDirection(rotationX, rotationY, true); - } - - public String getTextDirection() { - return getTextDirection(getRotX(false), getRotY(false)); - } - - public String getTextDirection( - TextDirectionType directionType, - boolean reverse - ) { - float rotationX = getRotX(reverse); - float rotationY = getRotY(reverse); - switch (directionType) { - case Normal: - return getTextDirection(rotationX, rotationY); - case Horizontal: - return getTextDirection(rotationX, rotationY, false); - case Sideways: - return getTextDirection( - rotationX, - getRotY(rotationY + 90, false) - ); - case SidewaysHorizontal: - return getTextDirection( - rotationX, - getRotY(rotationY + 90, false), - false - ); - case Vertical: - return getTextDirection(reverse ? 90 : -90, 0); - default: - return getTextDirection(rotationX, rotationY); - } - } - - public String getTextDirection(TextDirectionType directionType) { - return getTextDirection(directionType, false); - } - - public String primaryTextDirection(boolean reverse) { - TextDirectionType directionType = config.primaryDirection; - if (this.keyManager.modifierKey.isPressed()) { - directionType = config.primaryDirectionModifier; - } - return getTextDirection(directionType, reverse); - } - - public String primaryTextDirection() { - return primaryTextDirection(false); - } - - public String secondaryTextDirection(boolean reverse) { - TextDirectionType directionType = config.secondaryDirection; - if (this.keyManager.modifierKey.isPressed()) { - directionType = config.secondaryDirectionModifier; - } - return getTextDirection(directionType, reverse); - } - - public String secondaryTextDirection() { - return secondaryTextDirection(false); - } - - public float getRotX(float rotation, boolean reverse) { - if (reverse) { - return -(rotation) % 180; - } else { - return (rotation) % 180; - } - } - - public float getRotX(boolean reverse) { - return getRotX(client.player.getRotationClient().x, reverse); - } - - public float getRotY(float rotation, boolean reverse) { - float rotationY; - if (reverse) { - rotationY = (rotation + 180) % 360; - } else { - rotationY = rotation % 360; - } - if (rotationY < 0) rotationY += 360; - return rotationY; - } - - public float getRotY(boolean reverse) { - return getRotY(client.player.getRotationClient().y, reverse); - } - - private boolean inRange(double number, double min, double max) { - return min <= number && number <= max; - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/StatusTextType.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/StatusTextType.java deleted file mode 100644 index e4cebf7..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/StatusTextType.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public enum StatusTextType { - OneLined, - TwoLined, - TwoLinedWheel, -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/TakeScroll.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/TakeScroll.java deleted file mode 100644 index 6ca8c08..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/TakeScroll.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public class TakeScroll { - - public final int scrollX; - public final int scrollY; - - TakeScroll(int scrollX, int scrollY) { - this.scrollX = scrollX; - this.scrollY = scrollY; - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/TextDirectionType.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/TextDirectionType.java deleted file mode 100644 index 8accea5..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/TextDirectionType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public enum TextDirectionType { - Normal, - Horizontal, - Vertical, - Sideways, - SidewaysHorizontal, -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/client/TextRenderer.java b/src/main/java/com/github/hf02/scrollForWorldEdit/client/TextRenderer.java deleted file mode 100644 index 465104c..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/client/TextRenderer.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.Window; -import net.minecraft.text.Text; - -public class TextRenderer { - - public void renderText(DrawContext context) { - int color = changingMode - ? ScrollForWorldEditClient.config.modeColor - : ScrollForWorldEditClient.config.useColor; - if (shouldRenderText == true) { - for (int i = 0; i < text.length; i++) { - Text line = text[i]; - if (changingMode || i == text.length - 1) { - drawText( - context, - line, - getTextPosX(line), - getTextPosY(line, -(text.length - i)), - color, - true - ); - } - } - } - } - - public int getTextPosX(Text text) { - MinecraftClient client = MinecraftClient.getInstance(); - Window window = client.getWindow(); - return (int) ( - (window.getScaledWidth() * 0.5f) - - (client.textRenderer.getWidth(text) * 0.5f) - ); - } - - public int getTextPosY(Text text, float offset) { - MinecraftClient client = MinecraftClient.getInstance(); - Window window = client.getWindow(); - return (int) ( - (window.getScaledHeight() * 0.5f) + - (-2 * (float) window.getScaleFactor()) + - (client.textRenderer.fontHeight * offset) - ); - } - - public void drawText( - DrawContext context, - Text text, - int textPosX, - int textPosY, - int color, - boolean shadow - ) { - MinecraftClient client = MinecraftClient.getInstance(); - context.drawText( - client.textRenderer, - text, - textPosX, - textPosY, - color, - shadow - ); - } - - public boolean shouldRenderText = true; - public boolean changingMode = false; - - public Text[] text = { Text.literal("...") }; -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/config/ModMenuIntegration.java b/src/main/java/com/github/hf02/scrollForWorldEdit/config/ModMenuIntegration.java deleted file mode 100644 index 505ee35..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/config/ModMenuIntegration.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.config; - -import com.terraformersmc.modmenu.api.ConfigScreenFactory; -import com.terraformersmc.modmenu.api.ModMenuApi; -import me.shedaniel.autoconfig.AutoConfig; - -public class ModMenuIntegration implements ModMenuApi { - - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parent -> - AutoConfig - .getConfigScreen(ScrollForWorldEditConfig.class, parent) - .get(); - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/config/ScrollForWorldEditConfig.java b/src/main/java/com/github/hf02/scrollForWorldEdit/config/ScrollForWorldEditConfig.java deleted file mode 100644 index b07d69d..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/config/ScrollForWorldEditConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.config; - -import com.github.hf02.scrollForWorldEdit.client.StatusTextType; -import com.github.hf02.scrollForWorldEdit.client.TextDirectionType; -import me.shedaniel.autoconfig.ConfigData; -import me.shedaniel.autoconfig.annotation.Config; -import me.shedaniel.autoconfig.annotation.ConfigEntry; - -@Config(name = "scroll-for-worldedit") -public class ScrollForWorldEditConfig implements ConfigData { - - public float scrollThresholdY = 1; - - public float scrollThresholdX = 1; - - @ConfigEntry.Gui.PrefixText - public TextDirectionType primaryDirection = TextDirectionType.Normal; - - public TextDirectionType primaryDirectionModifier = - TextDirectionType.Vertical; - - public TextDirectionType secondaryDirection = TextDirectionType.Sideways; - - public TextDirectionType secondaryDirectionModifier = - TextDirectionType.Vertical; - - @ConfigEntry.Gui.Tooltip - public boolean mustHoldUseKeyForModeKey = true; - - public boolean useKeyToggles = true; - public boolean modeKeyToggles = false; - - public StatusTextType statusTextType = StatusTextType.TwoLinedWheel; - - @ConfigEntry.ColorPicker - public int wheelSelectedColor = 0xffff00; - - @ConfigEntry.ColorPicker - public int wheelUnselectedColor = 0xaaaaaa; - - @ConfigEntry.ColorPicker(allowAlpha = true) - public int useColor = 0x77ffffff; - - @ConfigEntry.ColorPicker(allowAlpha = true) - public int modeColor = 0xffffff00; - - @Override - public void validatePostLoad() { - if (scrollThresholdY <= 0) scrollThresholdY = 1; - if (scrollThresholdX <= 0) scrollThresholdX = 1; - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/mixin/MouseWheelMixin.java b/src/main/java/com/github/hf02/scrollForWorldEdit/mixin/MouseWheelMixin.java deleted file mode 100644 index 24c6a48..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/mixin/MouseWheelMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.mixin; - -import com.github.hf02.scrollForWorldEdit.client.MouseScrollCallback; -import net.minecraft.client.Mouse; -import net.minecraft.util.ActionResult; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Mouse.class) -public class MouseWheelMixin { - - @Inject(at = @At("HEAD"), method = "onMouseScroll", cancellable = true) - private void onMouseScroll( - long window, - double horizontal, - double vertical, - CallbackInfo info - ) { - ActionResult result = MouseScrollCallback.EVENT - .invoker() - .interact(horizontal, vertical); - - if (result == ActionResult.SUCCESS) { - info.cancel(); - } - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldEdit/mixin/TextHudMixin.java b/src/main/java/com/github/hf02/scrollForWorldEdit/mixin/TextHudMixin.java deleted file mode 100644 index 16a3b7c..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldEdit/mixin/TextHudMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.mixin; - -import com.github.hf02.scrollForWorldEdit.client.ScrollForWorldEditClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.hud.InGameHud; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(InGameHud.class) -public class TextHudMixin { - - @Inject(at = @At("RETURN"), method = "render") - public void render( - DrawContext context, - float tickDelta, - CallbackInfo info - ) { - ScrollForWorldEditClient.textRenderer.renderText(context); - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/Key.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/Key.java deleted file mode 100644 index 4fa1f97..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/Key.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.option.KeyBinding; - -public class Key { - - public final String code; - public final String name; - public final String command; - public final KeyBinding keybinding; - public final KeyManager keyManager; - private final ScrollForWorldEditClient scrollClient; - public final KeyHandler handler; - - public Key( - KeyManager keyManager, - String code, - String command, - String name, - String keybindingName, - net.minecraft.client.util.InputUtil.Type type, - int defaultCode, - String category, - KeyHandler handler - ) { - this.keyManager = keyManager; - this.code = code; - this.command = command; - this.name = name; - this.scrollClient = keyManager.scrollClient; - this.handler = handler; - this.keybinding = - KeyBindingHelper.registerKeyBinding( - new KeyBinding(keybindingName, type, defaultCode, category) - ); - } - - public void run(TakeScroll scroll) { - boolean isActive = keyManager.isKeyActive(this.code); - if (isActive) { - scrollClient.mouseHandler.capturingScroll = true; - this.handler.callback(this, scroll); - } - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/KeyHandler.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/KeyHandler.java deleted file mode 100644 index 990d652..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/KeyHandler.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public interface KeyHandler { - void callback(Key key, TakeScroll scroll); -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/KeyManager.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/KeyManager.java deleted file mode 100644 index e4403ff..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/KeyManager.java +++ /dev/null @@ -1,257 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import com.github.hf02.scrollForWorldEdit.ScrollForWorldEdit; -import java.util.Optional; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import org.lwjgl.glfw.GLFW; - -public class KeyManager { - - private Key[] keys; - - public final int count; - - public final KeyBinding modeKey = KeyBindingHelper.registerKeyBinding( - new KeyBinding( - "key.scroll-for-worldedit.mode", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_LEFT_CONTROL, - "key.scroll-for-worldedit.main" - ) - ); - private boolean modeKeyToggle = false; - - public final KeyBinding useKey = KeyBindingHelper.registerKeyBinding( - new KeyBinding( - "key.scroll-for-worldedit.use", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_LEFT_ALT, - "key.scroll-for-worldedit.main" - ) - ); - private boolean useKeyToggle = false; - - public final KeyBinding modifierKey = KeyBindingHelper.registerKeyBinding( - new KeyBinding( - "key.scroll-for-worldedit.modifier", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_Z, - "key.scroll-for-worldedit.main" - ) - ); - - private Optional getKey(String code) { - for (Key key : keys) { - if (key.code == code) { - return Optional.of(key); - } - } - return Optional.empty(); - } - - public boolean isUseKeyActive() { - return ScrollForWorldEditClient.config.useKeyToggles - ? useKeyToggle - : useKey.isPressed(); - } - - public boolean isModeKeyActive() { - boolean modeKeyAllowed = ScrollForWorldEditClient.config.mustHoldUseKeyForModeKey - ? isUseKeyActive() - : true; - boolean modeKeyPressed = ScrollForWorldEditClient.config.modeKeyToggles - ? modeKeyToggle - : modeKey.isPressed(); - return modeKeyAllowed && modeKeyPressed; - } - - private int activeKeyIndex = 0; - private Key activeKey; - - public void setActiveKey(int index) { - activeKeyIndex = index % count; - if (activeKeyIndex < 0) { - activeKeyIndex = count + activeKeyIndex; - } - activeKey = keys[activeKeyIndex]; - } - - public Key getActiveKey() { - return activeKey; - } - - public int getActiveKeyIndex() { - return activeKeyIndex; - } - - public final ScrollForWorldEditClient scrollClient; - - public KeyManager(ScrollForWorldEditClient scrollForWorldEditClient) { - this.scrollClient = scrollForWorldEditClient; - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - while (useKey.wasPressed()) { - useKeyToggle = - ScrollForWorldEditClient.config.useKeyToggles - ? !useKeyToggle - : false; - } - while (modeKey.wasPressed()) { - modeKeyToggle = - ScrollForWorldEditClient.config.modeKeyToggles - ? !modeKeyToggle - : false; - } - }); - - keys = - new Key[] { - new Key( - this, - "move", - "/move %s %s -s", - "scroll-for-worldedit.mode.move", - "key.scroll-for-worldedit.move", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runNonNegativeMove - ), - new Key( - this, - "expand", - "/expand %s %s", - "scroll-for-worldedit.mode.expand", - "key.scroll-for-worldedit.expand", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runMove - ), - new Key( - this, - "contract", - "/contract %s %s", - "scroll-for-worldedit.mode.contract", - "key.scroll-for-worldedit.contract", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runMove - ), - new Key( - this, - "shift", - "/shift %s %s", - "scroll-for-worldedit.mode.shift", - "key.scroll-for-worldedit.shift", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runMove - ), - new Key( - this, - "stack", - "/stack %s %s -s", - "scroll-for-worldedit.mode.stack", - "key.scroll-for-worldedit.stack", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_UNKNOWN, - "key.scroll-for-worldedit.main", - this::runNonNegativeMove - ), - }; - count = keys.length; - setActiveKey(0); - } - - public boolean isKeyActive(String keyName) { - Optional key = getKey(keyName); - if (!key.isPresent()) { - ScrollForWorldEdit.LOGGER.warn( - String.format("isKeyActive(): Unknown key %s", keyName) - ); - return false; - } - if (isUseKeyActive() && activeKey == key.get()) { - return true; - } - return key.get().keybinding.isPressed(); - } - - public void processKeys(TakeScroll scroll) { - for (Key key : keys) { - key.run(scroll); - } - } - - private void sendCommand(String command) { - scrollClient.client.player.networkHandler.sendChatCommand(command); - } - - // methods to handle Keys - - private void runNonNegativeMove(Key key, TakeScroll scroll) { - if (scroll.scrollY > 0) { - sendCommand( - String.format( - key.command, - scroll.scrollY, - scrollClient.primaryTextDirection() - ) - ); - } else if (scroll.scrollY < 0) { - sendCommand( - String.format( - key.command, - -scroll.scrollY, - scrollClient.primaryTextDirection(true) - ) - ); - } - - if (scroll.scrollX > 0) { - sendCommand( - String.format( - key.command, - scroll.scrollX, - scrollClient.secondaryTextDirection() - ) - ); - } else if (scroll.scrollX < 0) { - sendCommand( - String.format( - key.command, - -scroll.scrollX, - scrollClient.secondaryTextDirection(true) - ) - ); - } - } - - private void runMove(Key key, TakeScroll scroll) { - if (scroll.scrollY != 0) { - sendCommand( - String.format( - key.command, - scroll.scrollY, - scrollClient.primaryTextDirection() - ) - ); - } - - if (scroll.scrollX != 0) { - sendCommand( - String.format( - key.command, - scroll.scrollX, - scrollClient.secondaryTextDirection() - ) - ); - } - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollCallback.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollCallback.java deleted file mode 100644 index 5b791dc..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollCallback.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.fabricmc.fabric.api.event.Event; -import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.util.ActionResult; - -/** - * callback for the mouse scrolling. - * returning SUCCESS will cancel minecraft's handling of the mouse - * wheel. - */ -public interface MouseScrollCallback { - Event EVENT = EventFactory.createArrayBacked( - MouseScrollCallback.class, - listeners -> - (horizontal, vertical) -> { - for (MouseScrollCallback listener : listeners) { - ActionResult result = listener.interact( - horizontal, - vertical - ); - - if (result != ActionResult.PASS) { - return result; - } - } - return ActionResult.PASS; - } - ); - - ActionResult interact(double horizontal, double vertical); -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollHandler.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollHandler.java deleted file mode 100644 index 8fd1c6e..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/MouseScrollHandler.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.minecraft.util.ActionResult; - -public class MouseScrollHandler { - - private double scrollLeftY = 0; - - private double scrollLeftX = 0; - - public boolean capturingScroll = false; - - public int takeScrollY() { - int scrolled = 0; - if (ScrollForWorldEditClient.config.scrollThresholdY <= 0) { - ScrollForWorldEditClient.config.scrollThresholdY = 1; - } - while (true) { - final double scrollLeftRounded = - ScrollForWorldEditClient.config.scrollThresholdY * - Math.floor( - scrollLeftY / - ScrollForWorldEditClient.config.scrollThresholdY - ); - if (scrollLeftRounded == 0) { - break; - } else if (scrollLeftRounded > 0) { - scrollLeftY -= ScrollForWorldEditClient.config.scrollThresholdY; - scrolled++; - } else { - scrollLeftY += ScrollForWorldEditClient.config.scrollThresholdY; - scrolled--; - } - } - return scrolled; - } - - public int takeScrollX() { - int scrolled = 0; - if (ScrollForWorldEditClient.config.scrollThresholdX <= 0) { - ScrollForWorldEditClient.config.scrollThresholdX = 1; - } - while (true) { - final double scrollLeftRounded = - ScrollForWorldEditClient.config.scrollThresholdY * - Math.floor( - scrollLeftX / - ScrollForWorldEditClient.config.scrollThresholdX - ); - if (scrollLeftRounded == 0) { - break; - } else if (scrollLeftRounded > 0) { - scrollLeftX -= ScrollForWorldEditClient.config.scrollThresholdX; - scrolled++; - } else { - scrollLeftX += ScrollForWorldEditClient.config.scrollThresholdX; - scrolled--; - } - } - return scrolled; - } - - public TakeScroll takeScroll() { - return new TakeScroll(takeScrollX(), takeScrollY()); - } - - public void updateScrollCapture() { - if (capturingScroll == false) { - scrollLeftY = 0; - } - } - - public MouseScrollHandler() { - MouseScrollCallback.EVENT.register((horizontal, vertical) -> { - if (capturingScroll) { - scrollLeftY += vertical; - scrollLeftX += horizontal; - return ActionResult.SUCCESS; - } - return ActionResult.PASS; - }); - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/ScrollForWorldEditClient.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/ScrollForWorldEditClient.java deleted file mode 100644 index c8a4886..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/ScrollForWorldEditClient.java +++ /dev/null @@ -1,267 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import com.github.hf02.scrollForWorldEdit.ScrollForWorldEdit; -import com.github.hf02.scrollForWorldEdit.config.ScrollForWorldEditConfig; -import me.shedaniel.autoconfig.AutoConfig; -import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer; -import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.text.TextColor; - -public class ScrollForWorldEditClient implements ClientModInitializer { - - public KeyManager keyManager; - - public static TextRenderer textRenderer = new TextRenderer(); - public static MinecraftClient client; - public final MouseScrollHandler mouseHandler = new MouseScrollHandler(); - public static ScrollForWorldEditConfig config; - - @Override - public void onInitializeClient() { - this.keyManager = new KeyManager(this); - - AutoConfig.register( - ScrollForWorldEditConfig.class, - JanksonConfigSerializer::new - ); - config = - AutoConfig - .getConfigHolder(ScrollForWorldEditConfig.class) - .getConfig(); - - client = MinecraftClient.getInstance(); - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - if (client.player == null) return; - - mouseHandler.capturingScroll = - keyManager.isModeKeyActive() || keyManager.isUseKeyActive(); - textRenderer.shouldRenderText = mouseHandler.capturingScroll; - - final TakeScroll scrollTaken = mouseHandler.takeScroll(); - - if (keyManager.isModeKeyActive()) { - keyManager.setActiveKey( - (int) (keyManager.getActiveKeyIndex() - scrollTaken.scrollY) - ); - textRenderer.changingMode = true; - } else { - keyManager.processKeys(scrollTaken); - textRenderer.changingMode = false; - } - - if (textRenderer.shouldRenderText) { - switch (config.statusTextType) { - case OneLined: - textRenderer.text = - new Text[] { - Text.translatable( - "scroll-for-worldedit.hud_selector_single", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - }; - break; - case TwoLined: - textRenderer.text = - new Text[] { - Text.translatable( - "scroll-for-worldedit.hud_selector_top", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - Text.translatable( - "scroll-for-worldedit.hud_selector_bottom", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - }; - break; - case TwoLinedWheel: - MutableText scrollText = Text.empty(); - int keyIndex = keyManager.getActiveKeyIndex(); - for (int i = 0; i < keyManager.count; i++) { - if (i == keyIndex) { - scrollText.append( - Text - .translatable( - "scroll-for-worldedit.hud_selector_top_selected" - ) - .setStyle( - Style.EMPTY.withColor( - config.wheelSelectedColor - ) - ) - ); - } else { - scrollText.append( - Text - .translatable( - "scroll-for-worldedit.hud_selector_top_unselected" - ) - .setStyle( - Style.EMPTY.withColor( - config.wheelUnselectedColor - ) - ) - ); - } - } - textRenderer.text = - new Text[] { - scrollText, - Text.translatable( - "scroll-for-worldedit.hud_selector_bottom", - Text.translatable( - keyManager.getActiveKey().name - ), - keyManager.getActiveKeyIndex() + 1, - keyManager.count - ), - }; - break; - default: - break; - } - } - }); - } - - public String getTextDirection( - float rotationX, - float rotationY, - boolean allowVerticalLook - ) { - if (allowVerticalLook) { - if (inRange(rotationX, 60, 90)) { - return "down"; - } - if (inRange(rotationX, -90, -60)) { - return "up"; - } - } - if (inRange(rotationY, 0, 45) || inRange(rotationY, 315, 360)) { - return "south"; - } - if (inRange(rotationY, 45, 135)) { - return "west"; - } - if (inRange(rotationY, 135, 225)) { - return "north"; - } - if (inRange(rotationY, 225, 315)) { - return "east"; - } - return "me"; - } - - public String getTextDirection(float rotationX, float rotationY) { - return getTextDirection(rotationX, rotationY, true); - } - - public String getTextDirection() { - return getTextDirection(getRotX(false), getRotY(false)); - } - - public String getTextDirection( - TextDirectionType directionType, - boolean reverse - ) { - float rotationX = getRotX(reverse); - float rotationY = getRotY(reverse); - switch (directionType) { - case Normal: - return getTextDirection(rotationX, rotationY); - case Horizontal: - return getTextDirection(rotationX, rotationY, false); - case Sideways: - return getTextDirection( - rotationX, - getRotY(rotationY + 90, false) - ); - case SidewaysHorizontal: - return getTextDirection( - rotationX, - getRotY(rotationY + 90, false), - false - ); - case Vertical: - return getTextDirection(reverse ? 90 : -90, 0); - default: - return getTextDirection(rotationX, rotationY); - } - } - - public String getTextDirection(TextDirectionType directionType) { - return getTextDirection(directionType, false); - } - - public String primaryTextDirection(boolean reverse) { - TextDirectionType directionType = config.primaryDirection; - if (this.keyManager.modifierKey.isPressed()) { - directionType = config.primaryDirectionModifier; - } - return getTextDirection(directionType, reverse); - } - - public String primaryTextDirection() { - return primaryTextDirection(false); - } - - public String secondaryTextDirection(boolean reverse) { - TextDirectionType directionType = config.secondaryDirection; - if (this.keyManager.modifierKey.isPressed()) { - directionType = config.secondaryDirectionModifier; - } - return getTextDirection(directionType, reverse); - } - - public String secondaryTextDirection() { - return secondaryTextDirection(false); - } - - public float getRotX(float rotation, boolean reverse) { - if (reverse) { - return -(rotation) % 180; - } else { - return (rotation) % 180; - } - } - - public float getRotX(boolean reverse) { - return getRotX(client.player.getRotationClient().x, reverse); - } - - public float getRotY(float rotation, boolean reverse) { - float rotationY; - if (reverse) { - rotationY = (rotation + 180) % 360; - } else { - rotationY = rotation % 360; - } - if (rotationY < 0) rotationY += 360; - return rotationY; - } - - public float getRotY(boolean reverse) { - return getRotY(client.player.getRotationClient().y, reverse); - } - - private boolean inRange(double number, double min, double max) { - return min <= number && number <= max; - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/StatusTextType.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/StatusTextType.java deleted file mode 100644 index e4cebf7..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/StatusTextType.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public enum StatusTextType { - OneLined, - TwoLined, - TwoLinedWheel, -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/TakeScroll.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/TakeScroll.java deleted file mode 100644 index 6ca8c08..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/TakeScroll.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public class TakeScroll { - - public final int scrollX; - public final int scrollY; - - TakeScroll(int scrollX, int scrollY) { - this.scrollX = scrollX; - this.scrollY = scrollY; - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/TextDirectionType.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/TextDirectionType.java deleted file mode 100644 index 8accea5..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/TextDirectionType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -public enum TextDirectionType { - Normal, - Horizontal, - Vertical, - Sideways, - SidewaysHorizontal, -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/client/TextRenderer.java b/src/main/java/com/github/hf02/scrollForWorldedit/client/TextRenderer.java deleted file mode 100644 index 465104c..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/client/TextRenderer.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.client; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.util.Window; -import net.minecraft.text.Text; - -public class TextRenderer { - - public void renderText(DrawContext context) { - int color = changingMode - ? ScrollForWorldEditClient.config.modeColor - : ScrollForWorldEditClient.config.useColor; - if (shouldRenderText == true) { - for (int i = 0; i < text.length; i++) { - Text line = text[i]; - if (changingMode || i == text.length - 1) { - drawText( - context, - line, - getTextPosX(line), - getTextPosY(line, -(text.length - i)), - color, - true - ); - } - } - } - } - - public int getTextPosX(Text text) { - MinecraftClient client = MinecraftClient.getInstance(); - Window window = client.getWindow(); - return (int) ( - (window.getScaledWidth() * 0.5f) - - (client.textRenderer.getWidth(text) * 0.5f) - ); - } - - public int getTextPosY(Text text, float offset) { - MinecraftClient client = MinecraftClient.getInstance(); - Window window = client.getWindow(); - return (int) ( - (window.getScaledHeight() * 0.5f) + - (-2 * (float) window.getScaleFactor()) + - (client.textRenderer.fontHeight * offset) - ); - } - - public void drawText( - DrawContext context, - Text text, - int textPosX, - int textPosY, - int color, - boolean shadow - ) { - MinecraftClient client = MinecraftClient.getInstance(); - context.drawText( - client.textRenderer, - text, - textPosX, - textPosY, - color, - shadow - ); - } - - public boolean shouldRenderText = true; - public boolean changingMode = false; - - public Text[] text = { Text.literal("...") }; -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/config/ModMenuIntegration.java b/src/main/java/com/github/hf02/scrollForWorldedit/config/ModMenuIntegration.java deleted file mode 100644 index 505ee35..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/config/ModMenuIntegration.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.config; - -import com.terraformersmc.modmenu.api.ConfigScreenFactory; -import com.terraformersmc.modmenu.api.ModMenuApi; -import me.shedaniel.autoconfig.AutoConfig; - -public class ModMenuIntegration implements ModMenuApi { - - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return parent -> - AutoConfig - .getConfigScreen(ScrollForWorldEditConfig.class, parent) - .get(); - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/config/ScrollForWorldEditConfig.java b/src/main/java/com/github/hf02/scrollForWorldedit/config/ScrollForWorldEditConfig.java deleted file mode 100644 index b07d69d..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/config/ScrollForWorldEditConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.config; - -import com.github.hf02.scrollForWorldEdit.client.StatusTextType; -import com.github.hf02.scrollForWorldEdit.client.TextDirectionType; -import me.shedaniel.autoconfig.ConfigData; -import me.shedaniel.autoconfig.annotation.Config; -import me.shedaniel.autoconfig.annotation.ConfigEntry; - -@Config(name = "scroll-for-worldedit") -public class ScrollForWorldEditConfig implements ConfigData { - - public float scrollThresholdY = 1; - - public float scrollThresholdX = 1; - - @ConfigEntry.Gui.PrefixText - public TextDirectionType primaryDirection = TextDirectionType.Normal; - - public TextDirectionType primaryDirectionModifier = - TextDirectionType.Vertical; - - public TextDirectionType secondaryDirection = TextDirectionType.Sideways; - - public TextDirectionType secondaryDirectionModifier = - TextDirectionType.Vertical; - - @ConfigEntry.Gui.Tooltip - public boolean mustHoldUseKeyForModeKey = true; - - public boolean useKeyToggles = true; - public boolean modeKeyToggles = false; - - public StatusTextType statusTextType = StatusTextType.TwoLinedWheel; - - @ConfigEntry.ColorPicker - public int wheelSelectedColor = 0xffff00; - - @ConfigEntry.ColorPicker - public int wheelUnselectedColor = 0xaaaaaa; - - @ConfigEntry.ColorPicker(allowAlpha = true) - public int useColor = 0x77ffffff; - - @ConfigEntry.ColorPicker(allowAlpha = true) - public int modeColor = 0xffffff00; - - @Override - public void validatePostLoad() { - if (scrollThresholdY <= 0) scrollThresholdY = 1; - if (scrollThresholdX <= 0) scrollThresholdX = 1; - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/mixin/MouseWheelMixin.java b/src/main/java/com/github/hf02/scrollForWorldedit/mixin/MouseWheelMixin.java deleted file mode 100644 index 24c6a48..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/mixin/MouseWheelMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.mixin; - -import com.github.hf02.scrollForWorldEdit.client.MouseScrollCallback; -import net.minecraft.client.Mouse; -import net.minecraft.util.ActionResult; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(Mouse.class) -public class MouseWheelMixin { - - @Inject(at = @At("HEAD"), method = "onMouseScroll", cancellable = true) - private void onMouseScroll( - long window, - double horizontal, - double vertical, - CallbackInfo info - ) { - ActionResult result = MouseScrollCallback.EVENT - .invoker() - .interact(horizontal, vertical); - - if (result == ActionResult.SUCCESS) { - info.cancel(); - } - } -} diff --git a/src/main/java/com/github/hf02/scrollForWorldedit/mixin/TextHudMixin.java b/src/main/java/com/github/hf02/scrollForWorldedit/mixin/TextHudMixin.java deleted file mode 100644 index 16a3b7c..0000000 --- a/src/main/java/com/github/hf02/scrollForWorldedit/mixin/TextHudMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.hf02.scrollForWorldEdit.mixin; - -import com.github.hf02.scrollForWorldEdit.client.ScrollForWorldEditClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.hud.InGameHud; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(InGameHud.class) -public class TextHudMixin { - - @Inject(at = @At("RETURN"), method = "render") - public void render( - DrawContext context, - float tickDelta, - CallbackInfo info - ) { - ScrollForWorldEditClient.textRenderer.renderText(context); - } -}