Răsfoiți Sursa

Allow scissors modification

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 4 ani în urmă
părinte
comite
9e642f309b

+ 1 - 1
gradle.properties

@@ -5,5 +5,5 @@ minecraft_version=20w30a
 yarn_mappings=20w30a+build.3+legacy.20w09a+build.8
 loader_version=0.9.0+build.204
 fabric_version=0.15.2+build.382-1.16
-mod_version=4.8.2
+mod_version=4.8.3
 modmenu_version=1.14.6+build.31

+ 11 - 0
src/main/java/me/shedaniel/clothconfig2/api/ScissorsScreen.java

@@ -0,0 +1,11 @@
+package me.shedaniel.clothconfig2.api;
+
+import me.shedaniel.math.Rectangle;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Nullable;
+
+@ApiStatus.Experimental
+public interface ScissorsScreen {
+    @Nullable
+    Rectangle handleScissor(@Nullable Rectangle scissor);
+}

+ 13 - 0
src/main/java/me/shedaniel/clothconfig2/impl/ScissorsHandlerImpl.java

@@ -3,6 +3,7 @@ package me.shedaniel.clothconfig2.impl;
 import com.google.common.collect.Lists;
 import me.shedaniel.clothconfig2.ClothConfigInitializer;
 import me.shedaniel.clothconfig2.api.ScissorsHandler;
+import me.shedaniel.clothconfig2.api.ScissorsScreen;
 import me.shedaniel.math.Rectangle;
 import me.shedaniel.math.api.Executor;
 import net.fabricmc.api.EnvType;
@@ -76,6 +77,18 @@ public final class ScissorsHandlerImpl implements ScissorsHandler {
                 r.setBounds(r.intersection(scissorsAreas.get(i)));
             }
             r.setBounds(Math.min(r.x, r.x + r.width), Math.min(r.y, r.y + r.height), Math.abs(r.width), Math.abs(r.height));
+            if (MinecraftClient.getInstance().currentScreen instanceof ScissorsScreen)
+                _applyScissor(((ScissorsScreen) MinecraftClient.getInstance().currentScreen).handleScissor(r));
+            else _applyScissor(r);
+        } else {
+            if (MinecraftClient.getInstance().currentScreen instanceof ScissorsScreen)
+                _applyScissor(((ScissorsScreen) MinecraftClient.getInstance().currentScreen).handleScissor(null));
+            else _applyScissor(null);
+        }
+    }
+    
+    public void _applyScissor(Rectangle r) {
+        if (r != null && !r.isEmpty()) {
             Window window = MinecraftClient.getInstance().getWindow();
             double scaleFactor = window.getScaleFactor();
             GL11.glEnable(GL11.GL_SCISSOR_TEST);