diff --git a/build.gradle b/build.gradle index 9436b60ed..a59d9a744 100644 --- a/build.gradle +++ b/build.gradle @@ -12,8 +12,6 @@ plugins { // Architectury is used here only as a replacement for forge's own loom id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false - - id 'xyz.wagyourtail.jvmdowngrader' version '0.4.0' apply true } @@ -104,7 +102,6 @@ subprojects { p -> // Apply plugins apply plugin: "java" apply plugin: "com.github.johnrengelman.shadow" - apply plugin: "xyz.wagyourtail.jvmdowngrader" if (isMinecraftSubProject) apply plugin: "systems.manifold.manifold-gradle-plugin" @@ -285,7 +282,7 @@ subprojects { p -> relocate "com.seibel.distanthorizons.fabriclike", "loaderCommon.${p.name}.com.seibel.distanthorizons.fabriclike" // Move the loader files to a different location } } - def librariesLocation = "distanthorizons.libraries" + def librariesLocation = "DistantHorizons.libraries" // LWJGL // Only ever shadow the dependencies we use otherwise some stuff would break when running on an external client @@ -316,22 +313,6 @@ subprojects { p -> // Using jar.finalizedBy(shadowJar) causes issues so we do this scuffed bypass jar.dependsOn(shadowJar) - // For downgrading our project to Java 8 - if (isMinecraftSubProject) { - task jarDowngrade(type: xyz.wagyourtail.jvmdg.gradle.task.DowngradeJar) { - inputFile = tasks.shadowJar.archiveFile - archiveClassifier = "downgraded-8" - } - task apiDowngrade(type: xyz.wagyourtail.jvmdg.gradle.task.ShadeAPI) { - inputFile = jarDowngrade.archiveFile - archiveClassifier = "downgraded-8-shaded" - } - - // We're using a custom downgrade task so we disable the original downgrade tasks - downgradeJar.enabled = false - shadeDowngradedApi.enabled = false - } - // Put stuff from gradle.properties into the mod info processResources { @@ -630,17 +611,14 @@ allprojects { p -> tasks.withType(JavaCompile) { if (isMinecraftSubProject) { - options.release = rootProject.java_version as Integer // Neoforge complains without this + options.release = rootProject.java_version as Integer options.compilerArgs += ["-Xplugin:Manifold"] + } else { + options.release = 8; // Core & Api should use Java 8 no matter what + //options.release = rootProject.java_version as Integer // But if you want to test some stuff, then this can be enabled } options.encoding = "UTF-8" } - - // Sets the project's actual Java version (it's recommended to use this over the `options.release` method above) - java { - sourceCompatibility = rootProject.java_version - targetCompatibility = rootProject.java_version - } java { withSourcesJar() diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/GuiHelper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/GuiHelper.java index 53b0cebaa..46fe7010d 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/GuiHelper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/gui/GuiHelper.java @@ -18,7 +18,7 @@ public class GuiHelper public static Button MakeBtn(Component base, int posX, int posZ, int width, int height, Button.OnPress action) { #if MC_VER < MC_1_19_4 - return new Button(a, b, c, d, base, action); + return new Button(posX, posZ, width, height, base, action); #else return Button.builder(base, action).bounds(posX, posZ, width, height).build(); #endif diff --git a/common/src/main/resources/1_20_2.distanthorizons.accesswidener b/common/src/main/resources/1_20_2.distanthorizons.accesswidener index a267d98a3..c793fab68 100644 --- a/common/src/main/resources/1_20_2.distanthorizons.accesswidener +++ b/common/src/main/resources/1_20_2.distanthorizons.accesswidener @@ -37,6 +37,3 @@ accessible field net/minecraft/client/gui/components/AbstractButton SPRITES Lnet accessible field net/minecraft/util/ThreadingDetector lock Ljava/util/concurrent/Semaphore; mutable field net/minecraft/util/ThreadingDetector lock Ljava/util/concurrent/Semaphore; accessible field net/minecraft/client/gui/components/AbstractSelectionList scrollAmount D # Hack to bypass vanilla's setScrollAmount's clamp - -# TODO add a separate 1.20.6 Access widner file, this is only present in 1.20.6 -accessible field net/minecraft/client/gui/screens/OptionsScreen layout Lnet/minecraft/client/gui/layouts/HeaderAndFooterLayout; diff --git a/common/src/main/resources/1_20_6.distanthorizons.accesswidener b/common/src/main/resources/1_20_6.distanthorizons.accesswidener new file mode 100644 index 000000000..427617544 --- /dev/null +++ b/common/src/main/resources/1_20_6.distanthorizons.accesswidener @@ -0,0 +1,46 @@ +accessWidener v1 named + +# used when determining where to save files to +accessible field net/minecraft/world/level/storage/DimensionDataStorage dataFolder Ljava/io/File; + +# used when rendering +accessible method net/minecraft/client/renderer/GameRenderer getFov (Lnet/minecraft/client/Camera;FZ)D + +# used for grabbing vanilla rendered chunks +accessible field net/minecraft/client/renderer/LevelRenderer visibleSections Lit/unimi/dsi/fastutil/objects/ObjectArrayList; + +#accessible method net/minecraft/client/renderer/LevelRenderer renderSectionLayer (Lnet/minecraft/client/renderer/RenderType;Lcom/mojang/blaze3d/vertex/PoseStack;DDDLorg/joml/Matrix4f;)V + +# world generation +# accessible method net/minecraft/world/level/lighting/LayerLightEngine queueSectionData (JLnet/minecraft/world/level/chunk/DataLayer;Z)V +accessible field net/minecraft/world/level/chunk/LevelChunk loaded Z +accessible field net/minecraft/world/level/lighting/LightEngine storage Lnet/minecraft/world/level/lighting/LayerLightSectionStorage; +accessible method net/minecraft/world/level/lighting/LayerLightSectionStorage lightOnInSection (J)Z + +# lod generation from save file +accessible field net/minecraft/world/level/chunk/storage/ChunkStorage worker Lnet/minecraft/world/level/chunk/storage/IOWorker; +accessible field net/minecraft/world/level/chunk/storage/IOWorker storage Lnet/minecraft/world/level/chunk/storage/RegionFileStorage; +accessible field net/minecraft/world/level/chunk/storage/RegionFileStorage regionCache Lit/unimi/dsi/fastutil/longs/Long2ObjectLinkedOpenHashMap; +accessible field net/minecraft/world/level/chunk/storage/RegionFileStorage folder Ljava/nio/file/Path; + +# grabbing textures +accessible class net/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture +accessible method net/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture getFrameX (I)I +accessible method net/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture getFrameY (I)I +accessible field net/minecraft/client/renderer/texture/SpriteContents animatedTexture Lnet/minecraft/client/renderer/texture/SpriteContents$AnimatedTexture; +accessible field net/minecraft/client/renderer/texture/SpriteContents originalImage Lcom/mojang/blaze3d/platform/NativeImage; + +# UI stuff +accessible field net/minecraft/client/gui/components/AbstractButton SPRITES Lnet/minecraft/client/gui/components/WidgetSprites; +# Handles inserting the config button +accessible field net/minecraft/client/gui/layouts/HeaderAndFooterLayout headerFrame Lnet/minecraft/client/gui/layouts/FrameLayout; +accessible field net/minecraft/client/gui/layouts/FrameLayout children Ljava/util/List; +accessible class net/minecraft/client/gui/layouts/FrameLayout$ChildContainer +accessible field net/minecraft/client/gui/layouts/LinearLayout wrapped Lnet/minecraft/client/gui/layouts/GridLayout; + +# hacky stuff +accessible field net/minecraft/util/ThreadingDetector lock Ljava/util/concurrent/Semaphore; +mutable field net/minecraft/util/ThreadingDetector lock Ljava/util/concurrent/Semaphore; +accessible field net/minecraft/client/gui/components/AbstractSelectionList scrollAmount D # Hack to bypass vanilla's setScrollAmount's clamp + + diff --git a/coreSubProjects b/coreSubProjects index d48746d4e..8c91a8479 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit d48746d4ee2b024c14d0df3a9b36c271aa3dcd83 +Subproject commit 8c91a8479595d1de04213329e550b467e32bcb20 diff --git a/fabric/build.gradle b/fabric/build.gradle index 2d3b583fc..accf863fc 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -23,8 +23,8 @@ loom { } remapJar { - inputFile = apiDowngrade.archiveFile - dependsOn apiDowngrade + inputFile = shadowJar.archiveFile + dependsOn shadowJar } diff --git a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java index fc0bbdd70..7c4116b6d 100644 --- a/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java +++ b/fabric/src/main/java/com/seibel/distanthorizons/fabric/mixins/client/MixinOptionsScreen.java @@ -23,8 +23,6 @@ import com.seibel.distanthorizons.common.wrappers.gui.GetConfigScreen; import com.seibel.distanthorizons.common.wrappers.gui.TexturedButtonWidget; import com.seibel.distanthorizons.coreapi.ModInfo; import com.seibel.distanthorizons.core.config.Config; -import net.minecraft.client.gui.GuiGraphics; -import net.minecraft.client.gui.layouts.HeaderAndFooterLayout; import net.minecraft.client.gui.screens.OptionsScreen; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -35,85 +33,113 @@ import net.minecraft.resources.ResourceLocation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; + +#if MC_VER == MC_1_20_6 +import net.minecraft.client.gui.layouts.LinearLayout; +import net.minecraft.client.gui.layouts.HeaderAndFooterLayout; +#endif /** * Adds a button to the menu to goto the config * * @author coolGi - * @version 12-02-2021 + * @version 2024-5-20 */ @Mixin(OptionsScreen.class) public class MixinOptionsScreen extends Screen { - /** Get the texture for the button */ + /** Texture used for the config opening button */ + @Unique private static final ResourceLocation ICON_TEXTURE = new ResourceLocation(ModInfo.ID, "textures/gui/button.png"); - public final TexturedButtonWidget optionsButton; + @Unique + private TexturedButtonWidget optionsButton = null; + + #if MC_VER == MC_1_20_6 @Shadow @Final protected HeaderAndFooterLayout layout; + #endif - protected MixinOptionsScreen(Component title) - { - super(title); - - this.optionsButton = new TexturedButtonWidget( - // Where the button is on the screen - this.width / 2 - 180, this.height / 6 - 12, - // Width and height of the button - 20, 20, - // texture UV Offset - 0, 0, - // Some textuary stuff - 20, ICON_TEXTURE, 20, 40, - // Create the button and tell it where to go - // For now it goes to the client option by default - (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(GetConfigScreen.getScreen(this)), - // Add a title to the utton - #if MC_VER < MC_1_19_2 - new TranslatableComponent(ModInfo.ID + ".title"))); - #else - Component.translatable(ModInfo.ID + ".title")); - #endif - } + //==============// + // constructors // + //==============// + protected MixinOptionsScreen(Component title) { super(title); } - - @Inject(at = @At("HEAD"), method = "init") + @Inject(at = @At("RETURN"), method = "init") private void lodconfig$init(CallbackInfo ci) { if (Config.Client.optionsButton.get()) { - this. #if MC_VER < MC_1_17_1 addButton #else addRenderableWidget #endif - (this.optionsButton); + #if MC_VER < MC_1_17_1 + this.addButton(this.getOptionsButton()); + #elif MC_VER < MC_1_20_6 + this.addRenderableWidget(this.getOptionsButton()); + #else - // TODO we need to add optionsButton to the UI via the layout instead so it centers correctly - // This wasn't working on James' machine - this.layout.visitChildren((x) -> - { - System.out.println(x); - }); + // add the button so it's rendered + this.addRenderableWidget(this.getOptionsButton()); + // add the button to the correct location in the UI + // TODO is there a better way to do this instead of using access transformers to inject into the exact UI elements? + LinearLayout layout = (LinearLayout) this.layout.headerFrame.children.get(0).child; + + // determine how wide the other option buttons are so we can put our botton to the left of them all + AtomicInteger width = new AtomicInteger(0); + layout.visitChildren(x -> { width.addAndGet(x.getWidth()); }); + width.addAndGet(-10); // padding between the DH button and the FOV slider + + layout.wrapped.addChild(this.getOptionsButton(), 1, 2, (settings) -> { settings.paddingLeft(width.get() * -1); }); + layout.arrangeElements(); + + #endif } } - //@Inject(method = "Lnet/minecraft/client/gui/screens/Screen;render(Lnet/minecraft/client/gui/GuiGraphics;IIF)V", at = @At(value = "INVOKE")) - //public void renderStuff(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick, CallbackInfo ci) - //{ - // int newWidth = this.width / 2 - 180; - // if (this.optionsButton.getX() != newWidth) - // { - // this.optionsButton.setX(newWidth); - // } - //} + + //================// + // helper methods // + //================// + + @Unique + public TexturedButtonWidget getOptionsButton() + { + if (this.optionsButton == null) + { + this.optionsButton + = new TexturedButtonWidget( + // Where the button is on the screen + this.width / 2 - 180, this.height / 6 - 12, + // Width and height of the button + 20, 20, + // texture UV Offset + 0, 0, + // Some textuary stuff + 20, ICON_TEXTURE, 20, 40, + // Create the button and tell it where to go + // For now it goes to the client option by default + (buttonWidget) -> Objects.requireNonNull(this.minecraft).setScreen(GetConfigScreen.getScreen(this)), + // Add a title to the button + #if MC_VER < MC_1_19_2 + new TranslatableComponent(ModInfo.ID + ".title")); + #else + Component.translatable(ModInfo.ID + ".title")); + #endif + } + + return this.optionsButton; + } } diff --git a/forge/build.gradle b/forge/build.gradle index ea30313f3..790890245 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -51,8 +51,8 @@ loom { } remapJar { - inputFile = apiDowngrade.archiveFile - dependsOn apiDowngrade + inputFile = shadowJar.archiveFile + dependsOn shadowJar } def addMod(path, enabled) { diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 4b5290e17..f5ab276fd 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -67,8 +67,8 @@ loom { } remapJar { - inputFile = apiDowngrade.archiveFile - dependsOn apiDowngrade + inputFile = shadowJar.archiveFile + dependsOn shadowJar // classifier null atAccessWideners.add("distanthorizons.accesswidener") diff --git a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java index 657b521f0..983b446dd 100644 --- a/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java +++ b/neoforge/src/main/java/com/seibel/distanthorizons/neoforge/mixins/client/MixinOptionsScreen.java @@ -30,52 +30,117 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TranslatableComponent; #endif import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.util.Objects; +import java.util.concurrent.atomic.AtomicInteger; + +#if MC_VER == MC_1_20_6 +import net.minecraft.client.gui.layouts.LinearLayout; +import net.minecraft.client.gui.layouts.HeaderAndFooterLayout; +#endif /** * Adds a button to the menu to goto the config * * @author coolGi - * @version 12-02-2021 + * @version 2024-5-20 */ @Mixin(OptionsScreen.class) public class MixinOptionsScreen extends Screen { - // Get the texture for the button + /** Texture used for the config opening button */ + @Unique private static final ResourceLocation ICON_TEXTURE = new ResourceLocation(ModInfo.ID, "textures/gui/button.png"); - protected MixinOptionsScreen(Component title) - { - super(title); - } - @Inject(at = @At("HEAD"), method = "init") + + @Unique + private TexturedButtonWidget optionsButton = null; + + #if MC_VER == MC_1_20_6 + @Shadow + @Final + protected HeaderAndFooterLayout layout; + #endif + + + + //==============// + // constructors // + //==============// + + protected MixinOptionsScreen(Component title) { super(title); } + + @Inject(at = @At("RETURN"), method = "init") private void lodconfig$init(CallbackInfo ci) { if (Config.Client.optionsButton.get()) - this. #if MC_VER < MC_1_17_1 addButton #else addRenderableWidget #endif - (new TexturedButtonWidget( - // Where the button is on the screen - this.width / 2 - 180, this.height / 6 - 12, - // Width and height of the button - 20, 20, - // Offset - 0, 0, - // Some textuary stuff - 20, ICON_TEXTURE, 20, 40, - // Create the button and tell it where to go - // For now it goes to the client option by default - (buttonWidget) -> Objects.requireNonNull(minecraft).setScreen(GetConfigScreen.getScreen(this)), - // Add a title to the button - #if MC_VER < MC_1_19_2 - new TranslatableComponent(ModInfo.ID + ".title"))); - #else - Component.translatable(ModInfo.ID + ".title"))); - #endif + { + #if MC_VER < MC_1_17_1 + this.addButton(this.getOptionsButton()); + #elif MC_VER < MC_1_20_6 + this.addRenderableWidget(this.getOptionsButton()); + #else + + // add the button so it's rendered + this.addRenderableWidget(this.getOptionsButton()); + + // add the button to the correct location in the UI + // TODO is there a better way to do this instead of using access transformers to inject into the exact UI elements? + // TODO is there a way we can put the button on the left side of the FOV bar like before? + LinearLayout layout = (LinearLayout) this.layout.headerFrame.children.get(0).child; + + // determine how wide the other option buttons are so we can put our botton to the left of them all + AtomicInteger width = new AtomicInteger(0); + layout.visitChildren(x -> { width.addAndGet(x.getWidth()); }); + width.addAndGet(-10); // padding between the DH button and the FOV slider + + layout.wrapped.addChild(this.getOptionsButton(), 1, 2, (settings) -> { settings.paddingLeft(width.get() * -1); }); + layout.arrangeElements(); + + #endif + } + } + + + + //================// + // helper methods // + //================// + + @Unique + public TexturedButtonWidget getOptionsButton() + { + if (this.optionsButton == null) + { + this.optionsButton + = new TexturedButtonWidget( + // Where the button is on the screen + this.width / 2 - 180, this.height / 6 - 12, + // Width and height of the button + 20, 20, + // texture UV Offset + 0, 0, + // Some textuary stuff + 20, ICON_TEXTURE, 20, 40, + // Create the button and tell it where to go + // For now it goes to the client option by default + (buttonWidget) -> Objects.requireNonNull(this.minecraft).setScreen(GetConfigScreen.getScreen(this)), + // Add a title to the button + #if MC_VER < MC_1_19_2 + new TranslatableComponent(ModInfo.ID + ".title")); + #else + Component.translatable(ModInfo.ID + ".title")); + #endif + } + + return this.optionsButton; } } diff --git a/settings.gradle b/settings.gradle index a76ea809a..fb99f9435 100644 --- a/settings.gradle +++ b/settings.gradle @@ -33,14 +33,6 @@ pluginManagement { name "ParchmentMC" url "https://maven.parchmentmc.org" } - maven { // Used for downgrading Java versions - name "Wagyourtail Release Repository" - url "https://maven.wagyourtail.xyz/releases" - } - maven { // Used for downgrading Java versions - name "Wagyourtail Snapshot Repository" - url "https://maven.wagyourtail.xyz/snapshots" - } mavenCentral() gradlePluginPortal() diff --git a/versionProperties/1.20.6.properties b/versionProperties/1.20.6.properties index eaea6d61a..273c66923 100644 --- a/versionProperties/1.20.6.properties +++ b/versionProperties/1.20.6.properties @@ -3,7 +3,7 @@ java_version=21 minecraft_version=1.20.6 parchment_version=1.20.6:2024.05.01 compatible_minecraft_versions=["1.20.6"] -accessWidenerVersion=1_20_2 +accessWidenerVersion=1_20_6 builds_for=fabric,neoforge # forge is broken due to gradle/build script issues