Skip to content

Commit

Permalink
update for 1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nimueller committed Jul 27, 2021
1 parent 768c21e commit 7fa2608
Show file tree
Hide file tree
Showing 24 changed files with 169 additions and 263 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ dependencies {
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
}

minecraft {
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
minecraftVersion=1.16.5
modVersion=1.2.0
forgeVersion=36.0.0
minecraftVersion=1.17.1
modVersion=1.3.0
forgeVersion=37.0.8
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pluginManagement {
repositories {
maven("https://maven.minecraftforge.net")
mavenCentral()
}
resolutionStrategy {
eachPlugin {
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/de/nekeras/borderless/BorderlessWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ExtensionPoint;
import net.minecraftforge.fml.IExtensionPoint;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.network.FMLNetworkConstants;
import org.apache.commons.lang3.tuple.Pair;
import net.minecraftforge.fmlclient.ConfigGuiHandler;
import net.minecraftforge.fmllegacy.network.FMLNetworkConstants;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -37,9 +37,8 @@ public BorderlessWindow() {
ModLoadingContext context = ModLoadingContext.get();

log.info("Enable server compatibility");
context.registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(
() -> FMLNetworkConstants.IGNORESERVERONLY,
(a, b) -> true));
context.registerExtensionPoint(IExtensionPoint.DisplayTest.class, () ->
new IExtensionPoint.DisplayTest(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true));

log.info("Register client configuration");
context.registerConfig(ModConfig.Type.CLIENT, Config.CONFIG_SPEC);
Expand All @@ -52,8 +51,8 @@ public static void onClientSetup(@Nonnull FMLClientSetupEvent event) {
ModLoadingContext context = ModLoadingContext.get();

log.info("Register client configuration screen");
context.registerExtensionPoint(ExtensionPoint.CONFIGGUIFACTORY, () ->
(mc, modListScreen) -> new ConfigScreen(modListScreen));
context.registerExtensionPoint(ConfigGuiHandler.ConfigGuiFactory.class, () ->
new ConfigGuiHandler.ConfigGuiFactory((mc, modListScreen) -> new ConfigScreen(modListScreen)));

log.info("Enqueue initialization work to main thread");
event.enqueueWork(de.nekeras.borderless.client.FullscreenDisplayModeHolder::initMinecraft);
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/de/nekeras/borderless/client/DesktopEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,9 @@ public FullscreenDisplayMode getBestFullscreenDisplayMode() {
DesktopEnvironment current = null;

switch (Platform.get()) {
case WINDOWS:
current = WINDOWS;
break;
case LINUX:
case WINDOWS -> current = WINDOWS;
case LINUX -> {
String result = System.getenv(LINUX_WINDOW_SYSTEM_VARIABLE);

if (X11_NAME.equalsIgnoreCase(result)) {
current = X11;
} else if (WAYLAND_NAME.equalsIgnoreCase(result)) {
Expand All @@ -79,11 +76,8 @@ public FullscreenDisplayMode getBestFullscreenDisplayMode() {
current = GENERIC;
log.warn("Unknown window system: {}", result);
}

break;
case MACOSX:
current = GENERIC;
break;
}
case MACOSX -> current = GENERIC;
}

CURRENT = current;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package de.nekeras.borderless.client;

import com.mojang.blaze3d.platform.Window;
import de.nekeras.borderless.client.fullscreen.FullscreenDisplayMode;
import de.nekeras.borderless.client.listener.SizeChangedWindowEventListener;
import de.nekeras.borderless.config.Config;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Optional;

/**
* Singleton class holding the current fullscreen display mode.
Expand All @@ -21,7 +19,7 @@
public class FullscreenDisplayModeHolder {

private static final Logger log = LogManager.getLogger();
private static final MainWindow window = Minecraft.getInstance().getWindow();
private static final Window window = Minecraft.getInstance().getWindow();
private static FullscreenDisplayMode currentMode;

/**
Expand All @@ -36,17 +34,6 @@ public static void initMinecraft() {
FullscreenDisplayModeHolder.setFullscreenDisplayModeFromConfig();
}

/**
* The fullscreen mode that is applied instead of the native fullscreen once the user hits
* F11 or switches to fullscreen in the video settings.
*
* @return The fullscreen mode
*/
@Nonnull
public static Optional<FullscreenDisplayMode> getFullscreenDisplayMode() {
return Optional.ofNullable(currentMode);
}

/**
* The fullscreen mode that is applied instead of the native fullscreen once the user hits
* F11 or switches to fullscreen in the video settings.
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/de/nekeras/borderless/client/GlfwUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.nekeras.borderless.client;

import net.minecraft.client.MainWindow;
import net.minecraft.client.Monitor;
import com.mojang.blaze3d.platform.Monitor;
import com.mojang.blaze3d.platform.Window;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -48,7 +48,7 @@ public static String getMonitorName(@Nonnull Monitor monitor) {
* @return The monitor wrapped in an {@link Optional}.
*/
@Nonnull
public static Optional<Monitor> tryGetMonitor(@Nonnull MainWindow window) {
public static Optional<Monitor> tryGetMonitor(@Nonnull Window window) {
Monitor monitor = window.findBestMonitor();

if (monitor == null) {
Expand All @@ -64,7 +64,7 @@ public static Optional<Monitor> tryGetMonitor(@Nonnull MainWindow window) {
* @param window The window
* @param attribute The attribute
*/
public static void enableWindowAttribute(@Nonnull MainWindow window, @Nonnull GlfwWindowAttribute attribute) {
public static void enableWindowAttribute(@Nonnull Window window, @Nonnull GlfwWindowAttribute attribute) {
log.info("Enable window attribute {}", attribute.name());
GLFW.glfwSetWindowAttrib(window.getWindow(), attribute.getBit(), GLFW.GLFW_TRUE);
}
Expand All @@ -75,7 +75,7 @@ public static void enableWindowAttribute(@Nonnull MainWindow window, @Nonnull Gl
* @param window The window
* @param attribute The attribute
*/
public static void disableWindowAttribute(@Nonnull MainWindow window, @Nonnull GlfwWindowAttribute attribute) {
public static void disableWindowAttribute(@Nonnull Window window, @Nonnull GlfwWindowAttribute attribute) {
log.info("Enable window attribute {}", attribute.name());
GLFW.glfwSetWindowAttrib(window.getWindow(), attribute.getBit(), GLFW.GLFW_FALSE);
}
Expand All @@ -85,7 +85,7 @@ public static void disableWindowAttribute(@Nonnull MainWindow window, @Nonnull G
*
* @param window The window
*/
public static void applyDefaultWindowAttributes(@Nonnull MainWindow window) {
public static void applyDefaultWindowAttributes(@Nonnull Window window) {
log.info("Resetting window attributes");

for (GlfwWindowAttribute attribute : GlfwWindowAttribute.values()) {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/de/nekeras/borderless/client/ReflectionUtils.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package de.nekeras.borderless.client;

import com.mojang.blaze3d.platform.Window;
import com.mojang.blaze3d.platform.WindowEventHandler;
import de.nekeras.borderless.util.AccessibleFieldDelegate;
import net.minecraft.client.MainWindow;
import net.minecraft.client.gui.screen.VideoSettingsScreen;
import net.minecraft.client.gui.widget.list.OptionsRowList;
import net.minecraft.client.renderer.IWindowEventListener;
import net.minecraft.client.gui.components.OptionsList;
import net.minecraft.client.gui.screens.VideoSettingsScreen;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.lwjgl.glfw.GLFWFramebufferSizeCallbackI;
Expand All @@ -21,10 +21,10 @@
@OnlyIn(Dist.CLIENT)
public final class ReflectionUtils {

private static final AccessibleFieldDelegate<MainWindow, IWindowEventListener> windowEventListenerAccessor =
makeFieldAccessible(MainWindow.class, IWindowEventListener.class);
private static final AccessibleFieldDelegate<VideoSettingsScreen, OptionsRowList> optionsRowListAccessor =
tryMakeFieldAccessible(VideoSettingsScreen.class, OptionsRowList.class, thisRef -> null);
private static final AccessibleFieldDelegate<Window, WindowEventHandler> windowEventListenerAccessor =
makeFieldAccessible(Window.class, WindowEventHandler.class);
private static final AccessibleFieldDelegate<VideoSettingsScreen, OptionsList> optionsListAccessor =
tryMakeFieldAccessible(VideoSettingsScreen.class, OptionsList.class, thisRef -> null);

private ReflectionUtils() {
}
Expand All @@ -36,6 +36,7 @@ private ReflectionUtils() {
* @param fieldType The field to access
* @throws IllegalStateException If there is no such field of type <code>F</code>
*/
@SuppressWarnings("SameParameterValue") // might be needed in future
@Nonnull
private static <C, F> AccessibleFieldDelegate<C, F> makeFieldAccessible(@Nonnull Class<C> inClass, @Nonnull Class<F> fieldType) {
try {
Expand All @@ -53,9 +54,10 @@ private static <C, F> AccessibleFieldDelegate<C, F> makeFieldAccessible(@Nonnull
* @param fieldType The field to access
* @param defaultSupplier The supplier which is called in when retrieving the value if the field was not found
*/
@SuppressWarnings("SameParameterValue") // might be needed in future
@Nonnull
private static <C, F> AccessibleFieldDelegate<C, F> tryMakeFieldAccessible(@Nonnull Class<C> inClass, @Nonnull Class<F> fieldType, @Nonnull Function<C, F> defaultSupplier) {
return new AccessibleFieldDelegate<C, F>(inClass, fieldType, defaultSupplier);
return new AccessibleFieldDelegate<>(inClass, fieldType, defaultSupplier);
}

/**
Expand All @@ -79,9 +81,9 @@ public static boolean isCalledByGlfwCallback() {
* {@link IWindowEventListener} field in the {@link MainWindow} instance
* and returns a new value that should be assigned
*/
public static void updateWindowEventListener(@Nonnull MainWindow window, @Nonnull Function<IWindowEventListener, IWindowEventListener> updateSupplier) {
IWindowEventListener oldListener = windowEventListenerAccessor.getValue(window);
IWindowEventListener newListener = updateSupplier.apply(oldListener);
public static void updateWindowEventListener(@Nonnull Window window, @Nonnull Function<WindowEventHandler, WindowEventHandler> updateSupplier) {
WindowEventHandler oldListener = windowEventListenerAccessor.getValue(window);
WindowEventHandler newListener = updateSupplier.apply(oldListener);
windowEventListenerAccessor.setValue(window, newListener);
}

Expand All @@ -93,7 +95,7 @@ public static void updateWindowEventListener(@Nonnull MainWindow window, @Nonnul
* @return The options row list if it exists
*/
@Nonnull
public static Optional<OptionsRowList> getOptionsRowList(@Nonnull VideoSettingsScreen screen) {
return Optional.ofNullable(optionsRowListAccessor.getValue(screen));
public static Optional<OptionsList> getOptionsList(@Nonnull VideoSettingsScreen screen) {
return Optional.ofNullable(optionsListAccessor.getValue(screen));
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package de.nekeras.borderless.client.fullscreen;

import com.mojang.blaze3d.platform.Monitor;
import com.mojang.blaze3d.platform.VideoMode;
import com.mojang.blaze3d.platform.Window;
import de.nekeras.borderless.client.GlfwUtils;
import de.nekeras.borderless.client.GlfwWindowAttribute;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Monitor;
import net.minecraft.client.renderer.VideoMode;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;
Expand All @@ -23,7 +23,7 @@ public class BorderlessFullscreenDisplay implements FullscreenDisplayMode {
private static final Logger log = LogManager.getLogger();

@Override
public void apply(@Nonnull MainWindow window) {
public void apply(@Nonnull Window window) {
FullscreenDisplayMode.super.apply(window);

Monitor monitor = GlfwUtils.tryGetMonitor(window).orElse(null);
Expand All @@ -46,7 +46,7 @@ public void apply(@Nonnull MainWindow window) {
}

@Override
public void reset(@Nonnull MainWindow window) {
public void reset(@Nonnull Window window) {
FullscreenDisplayMode.super.reset(window);

if (window.isFullscreen()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.nekeras.borderless.client.fullscreen;

import com.mojang.blaze3d.platform.Window;
import de.nekeras.borderless.client.GlfwUtils;
import net.minecraft.client.MainWindow;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

Expand Down Expand Up @@ -45,7 +45,7 @@ public interface FullscreenDisplayMode {
*
* @param window The window
*/
default void apply(@Nonnull MainWindow window) {
default void apply(@Nonnull Window window) {
GlfwUtils.applyDefaultWindowAttributes(window);
}

Expand All @@ -55,7 +55,7 @@ default void apply(@Nonnull MainWindow window) {
*
* @param window The window
*/
default void reset(@Nonnull MainWindow window) {
default void reset(@Nonnull Window window) {
GlfwUtils.applyDefaultWindowAttributes(window);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.nekeras.borderless.client.fullscreen;

import net.minecraft.client.MainWindow;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.nekeras.borderless.client.fullscreen;

import com.mojang.blaze3d.platform.Window;
import de.nekeras.borderless.client.GlfwUtils;
import de.nekeras.borderless.client.GlfwWindowAttribute;
import net.minecraft.client.MainWindow;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

Expand All @@ -15,7 +15,7 @@
public class NativeNonIconifyFullscreenDisplay implements FullscreenDisplayMode {

@Override
public void apply(@Nonnull MainWindow window) {
public void apply(@Nonnull Window window) {
FullscreenDisplayMode.super.apply(window);

GlfwUtils.disableWindowAttribute(window, GlfwWindowAttribute.AUTO_ICONIFY);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package de.nekeras.borderless.client.fullscreen;

import com.mojang.blaze3d.platform.Monitor;
import com.mojang.blaze3d.platform.VideoMode;
import com.mojang.blaze3d.platform.Window;
import de.nekeras.borderless.client.GlfwUtils;
import de.nekeras.borderless.client.GlfwWindowAttribute;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Monitor;
import net.minecraft.client.renderer.VideoMode;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.apache.logging.log4j.LogManager;
Expand All @@ -23,7 +23,7 @@ public class NativeWindowedFullscreenDisplay implements FullscreenDisplayMode {
private static final Logger log = LogManager.getLogger();

@Override
public void apply(@Nonnull MainWindow window) {
public void apply(@Nonnull Window window) {
FullscreenDisplayMode.super.apply(window);

GlfwUtils.disableWindowAttribute(window, GlfwWindowAttribute.AUTO_ICONIFY);
Expand All @@ -38,13 +38,13 @@ public void apply(@Nonnull MainWindow window) {
}

@Override
public void reset(@Nonnull MainWindow window) {
public void reset(@Nonnull Window window) {
FullscreenDisplayMode.super.reset(window);

GLFW.glfwSetWindowFocusCallback(window.getWindow(), null);
}

private void onFocusGained(@Nonnull MainWindow window) {
private void onFocusGained(@Nonnull Window window) {
Monitor monitor = GlfwUtils.tryGetMonitor(window).orElse(null);

if (monitor == null) {
Expand All @@ -57,7 +57,7 @@ private void onFocusGained(@Nonnull MainWindow window) {
}
}

private void onFocusLost(@Nonnull MainWindow window) {
private void onFocusLost(@Nonnull Window window) {
GLFW.glfwSetWindowMonitor(window.getWindow(), 0,
window.getX(), window.getY(),
window.getWidth(), window.getHeight(), GLFW.GLFW_DONT_CARE);
Expand Down
Loading

0 comments on commit 7fa2608

Please sign in to comment.