diff --git a/build.gradle b/build.gradle index fd54456d2..9d3e012b4 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "0.10.0-SNAPSHOT" apply false + id "dev.architectury.loom" version "0.11.0-SNAPSHOT" apply false } def writeBuildGradlePredefine(List mcVers, int mcIndex) { @@ -89,7 +89,7 @@ subprojects { p -> silentMojangMappingsLicense() if (p != project(":core")) { - accessWidenerPath.set(project(":common").file("src/main/resources/${acsessWidenerVersion}.lod.accesswidener")) + accessWidenerPath = project(":common").file("src/main/resources/${acsessWidenerVersion}.lod.accesswidener") } } @@ -159,6 +159,10 @@ allprojects { p -> // For Manifold Preprocessor maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } + + // Required for ModMenu + maven { url "https://maven.terraformersmc.com/" } + // Required for importing Modrinth mods maven { name = "Modrinth" @@ -216,8 +220,8 @@ allprojects { p -> } } } - quiltAuthors = quiltAuthors.substring(0, quiltAuthors.length() - 1); // Delete the final comma - quiltAuthors = quiltAuthors + "}"; + quiltAuthors = quiltAuthors.substring(0, quiltAuthors.length() - 1) // Delete the final comma + quiltAuthors = quiltAuthors + "}" // Put stuff from gradle.properties into the mod info @@ -304,6 +308,7 @@ allprojects { p -> // println options.compilerArgs + options.encoding = "UTF-8" // Set the java version if (p != project(":core")) { options.compilerArgs += ['-Xplugin:Manifold'] diff --git a/common/build.gradle b/common/build.gradle index e4aa8c237..c84866111 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,13 +1,5 @@ architectury { - common() -} - -afterEvaluate { - tasks { - remapJar { - remapAccessWidener.set(false) - } - } + common(rootProject.enabled_platforms.split(",")) } publishing { diff --git a/fabric-like/build.gradle b/fabric-like/build.gradle new file mode 100644 index 000000000..a2b3537a9 --- /dev/null +++ b/fabric-like/build.gradle @@ -0,0 +1,15 @@ +architectury { + common(rootProject.enabled_platforms.split(",")) +} + +dependencies { + // Use Fabric loader as both Quilt and Fabric can use it + modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" + + // Fabric API + fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version) + fabricApi.module("fabric-key-binding-api-v1", rootProject.fabric_api_version) + fabricApi.module("fabric-networking-api-v1", rootProject.fabric_api_version) + + compileClasspath(project(path: ":common", configuration: "namedElements")) { transitive false } +} diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinChunkGenerator.java b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinChunkGenerator.java similarity index 98% rename from fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinChunkGenerator.java rename to fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinChunkGenerator.java index 607f42b21..4acf1b2c6 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinChunkGenerator.java +++ b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinChunkGenerator.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.lod.fabric.mixins; +package com.seibel.lod.fabric_like.mixins; import org.spongepowered.asm.mixin.Mixin; import net.minecraft.world.level.chunk.ChunkGenerator; diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinFogRenderer.java b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinFogRenderer.java similarity index 98% rename from fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinFogRenderer.java rename to fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinFogRenderer.java index 62a2912ea..6f85e4326 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinFogRenderer.java +++ b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinFogRenderer.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.lod.fabric.mixins; +package com.seibel.lod.fabric_like.mixins; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinOptionsScreen.java b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinOptionsScreen.java similarity index 98% rename from fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinOptionsScreen.java rename to fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinOptionsScreen.java index f20fd6c9d..32a7abafd 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinOptionsScreen.java +++ b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinOptionsScreen.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.lod.fabric.mixins; +package com.seibel.lod.fabric_like.mixins; import com.seibel.lod.common.wrappers.config.ConfigGui; import com.seibel.lod.common.wrappers.config.TexturedButtonWidget; diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinWorldRenderer.java b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinWorldRenderer.java similarity index 99% rename from fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinWorldRenderer.java rename to fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinWorldRenderer.java index 8df29f4f1..d8b013af1 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/MixinWorldRenderer.java +++ b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/MixinWorldRenderer.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.lod.fabric.mixins; +package com.seibel.lod.fabric_like.mixins; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/events/MixinLightmap.java b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/events/MixinLightmap.java similarity index 95% rename from fabric/src/main/java/com/seibel/lod/fabric/mixins/events/MixinLightmap.java rename to fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/events/MixinLightmap.java index a71bc4777..24b11e51c 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/events/MixinLightmap.java +++ b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/events/MixinLightmap.java @@ -1,4 +1,4 @@ -package com.seibel.lod.fabric.mixins.events; +package com.seibel.lod.fabric_like.mixins.events; import com.mojang.blaze3d.platform.NativeImage; diff --git a/fabric/src/main/java/com/seibel/lod/fabric/mixins/unsafe/MixinThreadingDectector.java b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/unsafe/MixinThreadingDectector.java similarity index 97% rename from fabric/src/main/java/com/seibel/lod/fabric/mixins/unsafe/MixinThreadingDectector.java rename to fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/unsafe/MixinThreadingDectector.java index 03940d1e7..8e23a68d7 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/mixins/unsafe/MixinThreadingDectector.java +++ b/fabric-like/src/main/java/com/seibel/lod/fabric_like/mixins/unsafe/MixinThreadingDectector.java @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package com.seibel.lod.fabric.mixins.unsafe; +package com.seibel.lod.fabric_like.mixins.unsafe; import net.minecraft.server.level.ServerLevel; import org.spongepowered.asm.mixin.Mixin; diff --git a/fabric/src/main/resources/LICENSE-MinecraftForge.txt b/fabric-like/src/main/resources/LICENSE-MinecraftForge.txt similarity index 100% rename from fabric/src/main/resources/LICENSE-MinecraftForge.txt rename to fabric-like/src/main/resources/LICENSE-MinecraftForge.txt diff --git a/fabric-like/src/main/resources/fabric-like.lod.mixins.json b/fabric-like/src/main/resources/fabric-like.lod.mixins.json new file mode 100644 index 000000000..d35e5014d --- /dev/null +++ b/fabric-like/src/main/resources/fabric-like.lod.mixins.json @@ -0,0 +1,18 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.seibel.lod.fabric_like.mixins", + "mixins": [ + "unsafe.MixinThreadingDectector" + ], + "client": [ + "MixinOptionsScreen", + "MixinWorldRenderer", + "MixinFogRenderer", + "MixinChunkGenerator", + "events.MixinLightmap" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/fabric/build.gradle b/fabric/build.gradle index c97beb0b1..103542d8f 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "7.1.0" + id "com.github.johnrengelman.shadow" version "7.1.2" } version = rootProject.mod_version+"-"+rootProject.minecraft_version+"-"+new Date().format("yyyy_MM_dd_HH_mm") @@ -19,17 +19,6 @@ configurations { modImplementation.extendsFrom addModJar } -repositories { - // Required for ModMenu - maven { url "https://maven.terraformersmc.com/" } - - // Required for Quilt - maven { - name 'Quilt' - url 'https://maven.quiltmc.org/repository/release' - } -} - def addMod(path, enabled) { if (enabled == "2") dependencies { modImplementation(path) } @@ -38,14 +27,8 @@ def addMod(path, enabled) { } dependencies { - if (rootProject.use_quilt_rather_than_fabric == "true") { - // Quilt loader - modImplementation "org.quiltmc:quilt-loader:${rootProject.quilt_loader_version}" - modImplementation "org.quiltmc:quilt-json5:1.0.0" // Needed for quilt loader but for some reason it dosnt come with it - } else { - // Fabric loader - modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" - } + // Fabric loader + modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" // Fabric API addModJar(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version)) @@ -126,6 +109,7 @@ runClient { } shadowJar { + exclude "architectury.common.json" configurations = [project.configurations.shadowMe] relocate 'org.tukaani', 'shaded.tukaani' relocate 'org.apache.commons.compress', 'shaded.apache.commons.compress' @@ -160,15 +144,9 @@ components.java { publishing { publications { - if (rootProject.use_quilt_rather_than_fabric == "false") { - mavenFabric(MavenPublication) { - artifactId = rootProject.archives_base_name + "-" + project.name - from components.java - } - } else { - mavenJava(MavenPublication) { - from components.java - } + mavenFabric(MavenPublication) { + artifactId = rootProject.archives_base_name + "-" + project.name + from components.java } } diff --git a/fabric/src/main/resources/fabric.lod.mixins.json b/fabric/src/main/resources/fabric.lod.mixins.json index 6cfe56a60..7d9d8dcca 100644 --- a/fabric/src/main/resources/fabric.lod.mixins.json +++ b/fabric/src/main/resources/fabric.lod.mixins.json @@ -3,20 +3,14 @@ "minVersion": "0.8", "package": "com.seibel.lod.fabric.mixins", "mixins": [ - "unsafe.MixinThreadingDectector", "MixinUtilBackgroudThread", "events.MixinServerLevel" ], "client": [ "MixinMinecraft", - "MixinOptionsScreen", - "MixinWorldRenderer", - "MixinFogRenderer", - "MixinChunkGenerator", "events.MixinClientLevel", "events.MixinMinecraft", - "events.MixinBlockUpdate", - "events.MixinLightmap" + "events.MixinBlockUpdate" ], "server": [ "MixinDedicatedServer" diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index f16e47c51..b128bdd43 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -5,7 +5,7 @@ "name": "${mod_name}", "description": "${description}", - "authors": ${authors}, + "authors": $authors, "contact": { "homepage": "${homepage}", @@ -24,7 +24,8 @@ }, "mixins": [ - "fabric.lod.mixins.json" + "fabric.lod.mixins.json", + "fabric-like.lod.mixins.json" ], "accessWidener" : "lod.accesswidener", @@ -33,7 +34,7 @@ "fabric-lifecycle-events-v1": "*", "fabric-key-binding-api-v1": "*", "fabric-networking-api-v1": "*", - "minecraft": ${compatible_minecraft_versions}, + "minecraft": $compatible_minecraft_versions, "java": ">=${java_version}" }, diff --git a/forge/build.gradle b/forge/build.gradle index 8f023fda4..0c347fd4a 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -1,5 +1,5 @@ plugins { - id "com.github.johnrengelman.shadow" version "7.1.0" + id "com.github.johnrengelman.shadow" version "7.1.2" } version = rootProject.mod_version+"-"+rootProject.minecraft_version+"-"+new Date().format("yyyy_MM_dd_HH_mm") @@ -63,6 +63,7 @@ processResources { } shadowJar { + exclude "architectury.common.json" dependencies { exclude(dependency("net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}")) } diff --git a/gradle.properties b/gradle.properties index 7d01105b4..ec7253a37 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,6 @@ org.gradle.daemon=false maven_group=com.seibel.lod archives_base_name=DistantHorizons -# Switch fabric to quilt on the fabric folder -use_quilt_rather_than_fabric=true - # Mod info mod_version=1.6.3a-dev mod_name=Distant Horizons @@ -20,6 +17,7 @@ mod_issues=https://gitlab.com/jeseibel/minecraft-lod-mod/-/issues toml_version=3.6.4 manifold_version=2022.1.7 mcVersions=1.16.5,1.17.1,1.18.1,1.18.2 +enabled_platforms=quilt,fabric,forge ##### FOR IDE SUPPORT AND TELL IDE TO USE CERTIAN MC VERSION: SWITCH THIS: mcVer=1.18.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d2880ba80..41dfb8790 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/quilt/build.gradle b/quilt/build.gradle new file mode 100644 index 000000000..e9eb93ee2 --- /dev/null +++ b/quilt/build.gradle @@ -0,0 +1,134 @@ +plugins { + id "com.github.johnrengelman.shadow" version "7.1.2" +} + +version = rootProject.mod_version+"-"+rootProject.minecraft_version+"-"+new Date().format("yyyy_MM_dd_HH_mm") + +repositories { + maven { url "https://maven.quiltmc.org/repository/release/" } +} + +architectury { + platformSetupLoomIde() + loader("quilt") +} + +configurations { + common + shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this. + compileClasspath.extendsFrom common + runtimeClasspath.extendsFrom common + developmentQuilt.extendsFrom common + + addModJar + include.extendsFrom addModJar + modImplementation.extendsFrom addModJar +} + +def addMod(path, enabled) { + if (enabled == "2") + dependencies { modImplementation(path) } + else if (enabled == "1") + dependencies { modCompileOnly(path) } +} + +dependencies { + // Quilt loader + modImplementation "org.quiltmc:quilt-loader:${rootProject.quilt_loader_version}" + + // Fabric API + addModJar(fabricApi.module("fabric-lifecycle-events-v1", rootProject.fabric_api_version)) + addModJar(fabricApi.module("fabric-key-binding-api-v1", rootProject.fabric_api_version)) + addModJar(fabricApi.module("fabric-networking-api-v1", rootProject.fabric_api_version)) + + // Mod Menu + modImplementation("com.terraformersmc:modmenu:${rootProject.modmenu_version}") + + // Sodium + addMod("curse.maven:sodium-394468:${rootProject.sodium_version}", rootProject.enable_sodium) + implementation "org.joml:joml:1.10.2" + modImplementation(fabricApi.module("fabric-rendering-data-attachment-v1", rootProject.fabric_api_version)) + modImplementation(fabricApi.module("fabric-rendering-fluids-v1", rootProject.fabric_api_version)) + + + // Toml + shadowMe("com.electronwill.night-config:toml:${rootProject.toml_version}") {} + + common(project(path: ":common", configuration: "namedElements")) { transitive false } + shadowCommon(project(path: ":common", configuration: "transformProductionQuilt")) { transitive false } + common(project(path: ":fabric-like", configuration: "namedElements")) { transitive false } + shadowCommon(project(path: ":fabric-like", configuration: "transformProductionQuilt")) { transitive false } + + // Compression + common 'org.tukaani:xz:1.9' + common 'org.apache.commons:commons-compress:1.21' + shadowMe 'org.tukaani:xz:1.9' + shadowMe 'org.apache.commons:commons-compress:1.21' +} + +task deleteResources(type: Delete) { + delete file("build/resources/main") +} + +processResources { + dependsOn(copyCoreResources) + dependsOn(copyCommonResources) + dependsOn(copyAccessWidener) +} + +runClient { + dependsOn(copyCoreResources) + dependsOn(copyCommonResources) + dependsOn(copyAccessWidener) + jvmArgs "-XX:-OmitStackTraceInFastThrow" + finalizedBy(deleteResources) +} + +shadowJar { + exclude "architectury.common.json" + configurations = [project.configurations.shadowCommon] + relocate 'org.tukaani', 'shaded.tukaani' + relocate 'org.apache.commons.compress', 'shaded.apache.commons.compress' + relocate 'com.electronwill.nightconfig', 'shaded.electronwill.nightconfig' + + relocate 'com.seibel.lod.common', 'quilt.com.seibel.lod.common' + + classifier "dev-shadow" +} + +remapJar { + injectAccessWidener = true // Quilt is weird with access wideners + input.set shadowJar.archiveFile + dependsOn shadowJar + classifier null +} + +jar { + classifier "dev" +} + +sourcesJar { + def commonSources = project(":common").sourcesJar + dependsOn commonSources + from commonSources.archiveFile.map { zipTree(it) } +} + +components.java { + withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) { + skip() + } +} + +publishing { + publications { + mavenQuilt(MavenPublication) { + artifactId = rootProject.archives_base_name + "-" + project.name + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + } +} diff --git a/quilt/gradle.properties b/quilt/gradle.properties new file mode 100644 index 000000000..96758ce85 --- /dev/null +++ b/quilt/gradle.properties @@ -0,0 +1 @@ +loom.platform=quilt \ No newline at end of file diff --git a/quilt/src/main/java/com/seibel/lod/quilt/ClientProxy.java b/quilt/src/main/java/com/seibel/lod/quilt/ClientProxy.java new file mode 100644 index 000000000..70610e4b4 --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/ClientProxy.java @@ -0,0 +1,199 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt; + +import com.seibel.lod.common.wrappers.worldGeneration.BatchGenerationEnvironment; +import com.seibel.lod.core.api.ClientApi; +import com.seibel.lod.core.api.EventApi; +import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler; +import com.mojang.blaze3d.platform.InputConstants; +import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; +import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper; +import com.seibel.lod.common.wrappers.world.WorldWrapper; +import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; +import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton; + +import com.seibel.lod.quilt.mixins.MixinUtilBackgroudThread; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientChunkEvents; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; +import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; +import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.core.BlockPos; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.chunk.LevelChunk; + +import java.util.HashSet; +import java.util.List; +import java.util.function.Supplier; + +import org.lwjgl.glfw.GLFW; + +/** + * This handles all events sent to the client, + * and is the starting point for most of the mod. + * + * @author coolGi2007 + * @author Ran + * @version 11-23-2021 + */ +public class ClientProxy +{ + private final EventApi eventApi = EventApi.INSTANCE; + private final ClientApi clientApi = ClientApi.INSTANCE; + + public static Supplier isGenerationThreadChecker = null; + + /** + * Registers Fabric Events + * @author Ran + */ + public void registerEvents() { + /* Registor the mod accessor*/ + + /* World Events */ + //ServerTickEvents.START_SERVER_TICK.register(this::serverTickEvent); + ServerTickEvents.END_SERVER_TICK.register(this::serverTickEvent); + + /* World Events */ + //ServerChunkEvents.CHUNK_LOAD.register(this::chunkLoadEvent); + #if PRE_MC_1_18_1 // in 1.18+, we use mixin hook in setClientLightReady(true) + ClientChunkEvents.CHUNK_LOAD.register(this::chunkLoadEvent); + #endif + + /* World Events */ + ServerWorldEvents.LOAD.register((server, level) -> this.worldLoadEvent(level)); + ServerWorldEvents.UNLOAD.register((server, level) -> this.worldUnloadEvent(level)); + + /* The Client World Events are in the mixins + Client world load event is in MixinClientLevel + Client world unload event is in MixinMinecraft */ + /* The save events are in MixinServerLevel */ + + /* Keyboard Events */ + ClientTickEvents.END_CLIENT_TICK.register(client -> { + if (client.player != null) onKeyInput(); + }); + isGenerationThreadChecker = BatchGenerationEnvironment::isCurrentThreadDistantGeneratorThread; + + } + + + public void serverTickEvent(MinecraftServer server) + { + eventApi.serverTickEvent(); + } + + public void chunkLoadEvent(LevelAccessor level, LevelChunk chunk) + { + clientApi.clientChunkLoadEvent(new ChunkWrapper(chunk, level), + WorldWrapper.getWorldWrapper(level)); + } + + public void worldSaveEvent() + { + eventApi.worldSaveEvent(); + } + + /** This is also called when a new dimension loads */ + public void worldLoadEvent(Level level) + { + if (Minecraft.getInstance().screen instanceof TitleScreen) return; + if (level != null) { + eventApi.worldLoadEvent(WorldWrapper.getWorldWrapper(level)); + } + } + + public void worldUnloadEvent(Level level) + { + if (level != null) { + eventApi.worldUnloadEvent(WorldWrapper.getWorldWrapper(level)); + } + } + + /** + * Can someone tell me how to make this better + * @author Ran + * + * public void blockChangeEvent(BlockEventData event) { + * // we only care about certain block events + * if (event.getClass() == BlockEventData.BreakEvent.class || + * event.getClass() == BlockEventData.EntityPlaceEvent.class || + * event.getClass() == BlockEventData.EntityMultiPlaceEvent.class || + * event.getClass() == BlockEventData.FluidPlaceBlockEvent.class || + * event.getClass() == BlockEventData.PortalSpawnEvent.class) + * { + * IChunkWrapper chunk = new ChunkWrapper(event.getWorld().getChunk(event.getPos())); + * DimensionTypeWrapper dimType = DimensionTypeWrapper.getDimensionTypeWrapper(event.getWorld().dimensionType()); + * + * // recreate the LOD where the blocks were changed + * eventApi.blockChangeEvent(chunk, dimType); + * } + * } + */ + public void blockChangeEvent(LevelAccessor world, BlockPos pos) { + IChunkWrapper chunk = new ChunkWrapper(world.getChunk(pos), world); + DimensionTypeWrapper dimType = DimensionTypeWrapper.getDimensionTypeWrapper(world.dimensionType()); + + // recreate the LOD where the blocks were changed + eventApi.blockChangeEvent(chunk, dimType); + } + + private static final int[] KEY_TO_CHECK_FOR = {GLFW.GLFW_KEY_F6, GLFW.GLFW_KEY_F8}; + + HashSet previousKeyDown = new HashSet(); + + public void onKeyInput() { + ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class); + if (CONFIG.client().advanced().debugging().getDebugKeybindingsEnabled()) + { + HashSet currectKeyDown = new HashSet(); + + // Note: Minecraft's InputConstants is same as GLFW Key values + //TODO: Use mixin to hook directly into the GLFW Keyboard event in minecraft KeyboardHandler + // Check all keys we need + for (int i = GLFW.GLFW_KEY_A; i <= GLFW.GLFW_KEY_Z; i++) { + if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), i)) { + currectKeyDown.add(i); + } + } + for (int i : KEY_TO_CHECK_FOR) { + if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), i)) { + currectKeyDown.add(i); + } + } + + // Diff and trigger events + for (int c : currectKeyDown) { + if (!previousKeyDown.contains(c)) { + ClientApi.INSTANCE.keyPressedEvent(c); + } + } + + // Update the set + previousKeyDown = currectKeyDown; + } + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/Main.java b/quilt/src/main/java/com/seibel/lod/quilt/Main.java new file mode 100644 index 000000000..cb458a498 --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/Main.java @@ -0,0 +1,88 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt; + +import com.seibel.lod.common.LodCommonMain; +import com.seibel.lod.core.ModInfo; +import com.seibel.lod.core.api.ApiShared; +import com.seibel.lod.core.api.ClientApi; +import com.seibel.lod.core.handlers.dependencyInjection.ModAccessorHandler; +import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler; +import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker; +import com.seibel.lod.core.wrapperInterfaces.modAccessor.IOptifineAccessor; +import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor; +import com.seibel.lod.core.wrapperInterfaces.modAccessor.IStarlightAccessor; +import com.seibel.lod.quilt.networking.NetworkHandler; +import com.seibel.lod.quilt.wrappers.modAccessor.ModChecker; +import com.seibel.lod.quilt.wrappers.modAccessor.OptifineAccessor; +import com.seibel.lod.quilt.wrappers.modAccessor.SodiumAccessor; +import com.seibel.lod.quilt.wrappers.modAccessor.StarlightAccessor; +import com.seibel.lod.quilt.wrappers.FabricDependencySetup; + +import net.fabricmc.api.ClientModInitializer; + +/** + * Initialize and setup the Mod.
+ * If you are looking for the real start of the mod + * check out the ClientProxy. + * + * @author coolGi2007 + * @author Ran + * @version 12-1-2021 + */ +public class Main +{ + // This is a client mod so it should implement ClientModInitializer and in fabric.mod.json it should have "environment": "client" + // Once it works on servers change the implement to ModInitializer and in fabric.mod.json it should be "environment": "*" + + public static ClientProxy client_proxy; + + // This loads the mod after minecraft loads which doesn't causes a lot of issues + public static void init() { + LodCommonMain.initConfig(); + LodCommonMain.startup(null, false, new NetworkHandler()); + FabricDependencySetup.createInitialBindings(); + FabricDependencySetup.finishBinding(); + ApiShared.LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION); + + // Check if this works + client_proxy = new ClientProxy(); + client_proxy.registerEvents(); + if (SingletonHandler.get(IModChecker.class).isModLoaded("sodium")) { + ModAccessorHandler.bind(ISodiumAccessor.class, new SodiumAccessor()); + } + if (SingletonHandler.get(IModChecker.class).isModLoaded("starlight")) { + ModAccessorHandler.bind(IStarlightAccessor.class, new StarlightAccessor()); + } + if (SingletonHandler.get(IModChecker.class).isModLoaded("optifine")) { + ModAccessorHandler.bind(IOptifineAccessor.class, new OptifineAccessor()); + } + + ModAccessorHandler.finishBinding(); + } + + public static void initServer() { + LodCommonMain.initConfig(); + LodCommonMain.startup(null, true, new NetworkHandler()); + FabricDependencySetup.createInitialBindings(); + FabricDependencySetup.finishBinding(); + ApiShared.LOGGER.info(ModInfo.READABLE_NAME + ", Version: " + ModInfo.VERSION); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinDedicatedServer.java b/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinDedicatedServer.java new file mode 100644 index 000000000..8385e38fc --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinDedicatedServer.java @@ -0,0 +1,35 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.mixins; + +import com.seibel.lod.quilt.Main; +import net.minecraft.server.dedicated.DedicatedServer; +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.CallbackInfoReturnable; + +@Mixin(DedicatedServer.class) +public class MixinDedicatedServer { + @Inject(method = "initServer", at = @At("TAIL")) + public void initServer(CallbackInfoReturnable cir) { + Main.initServer(); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinMinecraft.java b/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinMinecraft.java new file mode 100644 index 000000000..d48b31f96 --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinMinecraft.java @@ -0,0 +1,40 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.mixins; + +import com.seibel.lod.quilt.Main; +import net.minecraft.client.Minecraft; +import net.minecraft.client.main.GameConfig; +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; + +/** + * Loads the mod after minecraft loads. + * @author Ran + */ +@Mixin(value = Minecraft.class) +public class MixinMinecraft { + @Inject(method = "", at = @At("TAIL")) + private void startMod(GameConfig gameConfig, CallbackInfo ci) { + Main.init(); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinUtilBackgroudThread.java b/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinUtilBackgroudThread.java new file mode 100644 index 000000000..9996b60c8 --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/mixins/MixinUtilBackgroudThread.java @@ -0,0 +1,73 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.mixins; + +import java.util.concurrent.ExecutorService; +import java.util.function.Supplier; + +import com.seibel.lod.quilt.ClientProxy; +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.CallbackInfoReturnable; + +import com.seibel.lod.core.util.DummyRunExecutorService; + +import net.minecraft.Util; + +@Mixin(Util.class) +public class MixinUtilBackgroudThread +{ + @Inject(method = "backgroundExecutor", at = @At("HEAD"), cancellable = true) + private static void overrideUtil$backgroundExecutor(CallbackInfoReturnable ci) + { + if (ClientProxy.isGenerationThreadChecker != null && ClientProxy.isGenerationThreadChecker.get()) + { + //ApiShared.LOGGER.info("util backgroundExecutor triggered"); + ci.setReturnValue(new DummyRunExecutorService()); + } + } + + #if POST_MC_1_17_1 + @Inject(method = "wrapThreadWithTaskName(Ljava/lang/String;Ljava/lang/Runnable;)Ljava/lang/Runnable;", + at = @At("HEAD"), cancellable = true) + private static void overrideUtil$wrapThreadWithTaskName(String string, Runnable r, CallbackInfoReturnable ci) + { + if (ClientProxy.isGenerationThreadChecker != null && ClientProxy.isGenerationThreadChecker.get()) + { + //ApiShared.LOGGER.info("util wrapThreadWithTaskName(Runnable) triggered"); + ci.setReturnValue(r); + } + } + #endif + #if POST_MC_1_18_1 + @Inject(method = "wrapThreadWithTaskName(Ljava/lang/String;Ljava/util/function/Supplier;)Ljava/util/function/Supplier;", + at = @At("HEAD"), cancellable = true) + private static void overrideUtil$wrapThreadWithTaskNameForSupplier(String string, Supplier r, CallbackInfoReturnable> ci) + { + if (ClientProxy.isGenerationThreadChecker != null && ClientProxy.isGenerationThreadChecker.get()) + { + //ApiShared.LOGGER.info("util wrapThreadWithTaskName(Supplier) triggered"); + ci.setReturnValue(r); + } + } + #endif + +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinBlockUpdate.java b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinBlockUpdate.java new file mode 100644 index 000000000..91973111a --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinBlockUpdate.java @@ -0,0 +1,46 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.mixins.events; + +import com.seibel.lod.quilt.Main; +import net.minecraft.client.Minecraft; +import net.minecraft.core.BlockPos; +import net.minecraft.network.protocol.game.ClientGamePacketListener; +import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * If someone has a better way to do this then please let me know. + * + * @author Ran + */ +@Mixin(ClientboundBlockUpdatePacket.class) +public abstract class MixinBlockUpdate { + @Shadow public abstract BlockPos getPos(); + + @Inject(method = "handle(Lnet/minecraft/network/protocol/game/ClientGamePacketListener;)V", at = @At("TAIL")) + private void onBlockUpdate(ClientGamePacketListener clientGamePacketListener, CallbackInfo ci) { + Main.client_proxy.blockChangeEvent(Minecraft.getInstance().player.clientLevel, this.getPos()); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinClientLevel.java b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinClientLevel.java new file mode 100644 index 000000000..f79413829 --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinClientLevel.java @@ -0,0 +1,66 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.mixins.events; + +import com.seibel.lod.quilt.Main; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.renderer.LevelRenderer; +#if POST_MC_1_18_2 +import net.minecraft.core.Holder; +#endif +import net.minecraft.resources.ResourceKey; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.dimension.DimensionType; +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; + +import java.util.function.Supplier; + +/** + * This class is used for world loading events + * @author Ran + * + * FIXME: Why does forge not have the 1.18+ onChunkLightReady mixin? + */ + +@Mixin(ClientLevel.class) +public class MixinClientLevel { + @Inject(method = "", at = @At("TAIL")) + private void loadWorldEvent(ClientPacketListener clientPacketListener, ClientLevel.ClientLevelData clientLevelData, ResourceKey resourceKey, + #if POST_MC_1_18_2 Holder holder, #else DimensionType dimensionType, #endif int i, + #if POST_MC_1_18_1 int j, #endif Supplier supplier, LevelRenderer levelRenderer, boolean bl, long l, CallbackInfo ci) { + Main.client_proxy.worldLoadEvent((ClientLevel) (Object) this); + } + + #if POST_MC_1_18_1 + @Inject(method = "setLightReady", at = @At("HEAD")) + private void onChunkLightReady(int x, int z, CallbackInfo ci) { + ClientLevel l = (ClientLevel) (Object) this; + LevelChunk chunk = l.getChunkSource().getChunk(x, z, false); + if (chunk!=null&& !chunk.isClientLightReady()) + Main.client_proxy.chunkLoadEvent(l, chunk); + } + #endif +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinMinecraft.java b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinMinecraft.java new file mode 100644 index 000000000..7490b44f9 --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinMinecraft.java @@ -0,0 +1,51 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.mixins.events; + +import com.seibel.lod.quilt.Main; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.multiplayer.ClientLevel; + +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * This class is used for world unloading events + * @author Ran + */ +@Mixin(Minecraft.class) +public class MixinMinecraft { + @Shadow @Nullable public ClientLevel level; + + @Inject(method = "setLevel", at = @At("HEAD")) + private void unloadWorldEvent_sL(ClientLevel clientLevel, CallbackInfo ci) { + if (level != null) Main.client_proxy.worldUnloadEvent(level); + } + + @Inject(method = "clearLevel(Lnet/minecraft/client/gui/screens/Screen;)V", at = @At("HEAD")) + private void unloadWorldEvent_cL(Screen screen, CallbackInfo ci) { + if (this.level != null) Main.client_proxy.worldUnloadEvent(this.level); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinServerLevel.java b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinServerLevel.java new file mode 100644 index 000000000..ae9e13e5d --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/mixins/events/MixinServerLevel.java @@ -0,0 +1,51 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.mixins.events; + +import com.seibel.lod.quilt.Main; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.ProgressListener; +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; + +/** + * This class is used for world saving events + * @author Ran + */ +@Mixin(ServerLevel.class) +public class MixinServerLevel { + #if PRE_MC_1_17_1 + @Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerChunkCache;save(Z)V", shift = At.Shift.AFTER)) + private void saveWorldEvent(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) { + Main.client_proxy.worldSaveEvent(); + } + #else + @Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;saveAll()V", shift = At.Shift.AFTER)) + private void saveWorldEvent_sA(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) { + Main.client_proxy.worldSaveEvent(); + } + @Inject(method = "save", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/entity/PersistentEntitySectionManager;autoSave()V", shift = At.Shift.AFTER)) + private void saveWorldEvent_aS(ProgressListener progressListener, boolean bl, boolean bl2, CallbackInfo ci) { + Main.client_proxy.worldSaveEvent(); + } + #endif +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/networking/NetworkHandler.java b/quilt/src/main/java/com/seibel/lod/quilt/networking/NetworkHandler.java new file mode 100644 index 000000000..8eeec6b93 --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/networking/NetworkHandler.java @@ -0,0 +1,44 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.networking; + +import com.seibel.lod.common.networking.NetworkInterface; +import com.seibel.lod.common.networking.Networking; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking; + +/** + * @author Ran + */ +public class NetworkHandler implements NetworkInterface { + @Override + public void register_Client() { + ClientPlayNetworking.registerGlobalReceiver(Networking.resourceLocation_meow, (client, handler, buf, responseSender) -> { + com.seibel.lod.common.networking.NetworkHandler.receivePacketClient(client, handler, buf); + }); + } + + @Override + public void register_Server() { + ServerPlayNetworking.registerGlobalReceiver(Networking.resourceLocation_meow, (server, player, handler, buf, responseSender) -> { + com.seibel.lod.common.networking.NetworkHandler.receivePacketServer(server, player, handler, buf); + }); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/wrappers/FabricDependencySetup.java b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/FabricDependencySetup.java new file mode 100644 index 000000000..27142accd --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/FabricDependencySetup.java @@ -0,0 +1,50 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.wrappers; + +import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler; +import com.seibel.lod.core.wrapperInterfaces.config.ILodConfigWrapperSingleton; +import com.seibel.lod.common.wrappers.config.LodConfigWrapperSingleton; +import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker; +import com.seibel.lod.quilt.wrappers.modAccessor.ModChecker; + +/** + * Binds all necessary dependencies, so we + * can access them in Core.
+ * This needs to be called before any Core classes + * are loaded. + * + * @author James Seibel + * @author Ran + * @version 3-5-2022 + */ +public class FabricDependencySetup +{ + public static void createInitialBindings() + { + SingletonHandler.bind(IModChecker.class, ModChecker.INSTANCE); + + SingletonHandler.bind(ILodConfigWrapperSingleton.class, LodConfigWrapperSingleton.INSTANCE); + } + + public static void finishBinding() { + SingletonHandler.finishBinding(); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/wrappers/config/ModMenuIntegration.java b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/config/ModMenuIntegration.java new file mode 100644 index 000000000..3e5430bad --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/config/ModMenuIntegration.java @@ -0,0 +1,38 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.wrappers.config; + +import com.seibel.lod.common.wrappers.config.ConfigGui; +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +/** + * For making the config show up in modmenu + */ +@Environment(EnvType.CLIENT) +public class ModMenuIntegration implements ModMenuApi { + // For the custom config code + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parent -> ConfigGui.getScreen(parent, ""); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/ModChecker.java b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/ModChecker.java new file mode 100644 index 000000000..1d53741dc --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/ModChecker.java @@ -0,0 +1,32 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.wrappers.modAccessor; + +import com.seibel.lod.core.wrapperInterfaces.modAccessor.IModChecker; +import org.quiltmc.loader.api.QuiltLoader; + +public class ModChecker implements IModChecker { + public static final ModChecker INSTANCE = new ModChecker(); + + @Override + public boolean isModLoaded(String modid) { + return QuiltLoader.isModLoaded(modid); + } +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/OptifineAccessor.java b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/OptifineAccessor.java new file mode 100644 index 000000000..c4b023fbe --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/OptifineAccessor.java @@ -0,0 +1,43 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.wrappers.modAccessor; + +import java.util.HashSet; + +import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper; +import com.seibel.lod.core.wrapperInterfaces.modAccessor.IOptifineAccessor; + +public class OptifineAccessor implements IOptifineAccessor +{ + + @Override + public String getModName() + { + return "Optifine-Fabric-1.18.X"; + } + + @Override + public HashSet getNormalRenderedChunks() + { + // TODO: Impl proper methods here + return null; + } + +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/SodiumAccessor.java b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/SodiumAccessor.java new file mode 100644 index 000000000..5a9ef012c --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/SodiumAccessor.java @@ -0,0 +1,117 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.wrappers.modAccessor; + +import java.util.HashSet; +import java.util.stream.Collectors; + +import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler; +import com.seibel.lod.core.wrapperInterfaces.IWrapperFactory; +import com.seibel.lod.core.wrapperInterfaces.chunk.AbstractChunkPosWrapper; +import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper; +import com.seibel.lod.core.wrapperInterfaces.modAccessor.ISodiumAccessor; + + +import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer; +import net.minecraft.client.Minecraft; +#if PRE_MC_1_17_1 +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.protocol.Packet; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.phys.AABB; +#else +import net.minecraft.world.level.LevelHeightAccessor; +#endif + +public class SodiumAccessor implements ISodiumAccessor { + private final IWrapperFactory factory = SingletonHandler.get(IWrapperFactory.class); + private final IMinecraftRenderWrapper MC_RENDER = SingletonHandler.get(IMinecraftRenderWrapper.class); + + @Override + public String getModName() { + return "Sodium-Fabric"; + } + + #if POST_MC_1_17_1 + @Override + public HashSet getNormalRenderedChunks() { + SodiumWorldRenderer renderer = SodiumWorldRenderer.instance(); + LevelHeightAccessor height = Minecraft.getInstance().level; + + #if POST_MC_1_18_1 + // 0b11 = Lighted chunk & loaded chunk + return renderer.getChunkTracker().getChunks(0b00).filter( + (long l) -> { + return true; + }).mapToObj((long l) -> { + return (AbstractChunkPosWrapper)factory.createChunkPos(l); + }).collect(Collectors.toCollection(HashSet::new)); + #else + // TODO: Maybe use a mixin to make this more efficient, and maybe ignore changes behind the camera + return MC_RENDER.getMaximumRenderedChunks().stream().filter((AbstractChunkPosWrapper chunk) -> { + return (renderer.isBoxVisible( + chunk.getMinBlockX()+1, height.getMinBuildHeight()+1, chunk.getMinBlockZ()+1, + chunk.getMinBlockX()+15, height.getMaxBuildHeight()-1, chunk.getMinBlockZ()+15)); + }).collect(Collectors.toCollection(HashSet::new)); + #endif + } + #else + @Override + public HashSet getNormalRenderedChunks() { + SodiumWorldRenderer renderer = SodiumWorldRenderer.getInstance(); + LevelAccessor height = Minecraft.getInstance().level; + // TODO: Maybe use a mixin to make this more efficient + return MC_RENDER.getMaximumRenderedChunks().stream().filter((AbstractChunkPosWrapper chunk) -> { + FakeChunkEntity AABB = new FakeChunkEntity(chunk.getX(), chunk.getZ(), height.getMaxBuildHeight()); + return (renderer.isEntityVisible(AABB)); + }).collect(Collectors.toCollection(HashSet::new)); + } + + private static class FakeChunkEntity extends Entity { + public int cx; + public int cz; + public int my; + public FakeChunkEntity(int chunkX, int chunkZ, int maxHeight) { + super(EntityType.AREA_EFFECT_CLOUD, null); + cx = chunkX; + cz = chunkZ; + my = maxHeight; + } + @Override + public AABB getBoundingBoxForCulling() { + return new AABB(cx*16+1, 1, cz*16+1, + cx*16+15, my-1, cz*16+15); + } + @Override + protected void defineSynchedData() {} + @Override + protected void readAdditionalSaveData(CompoundTag paramCompoundTag) {} + @Override + protected void addAdditionalSaveData(CompoundTag paramCompoundTag) {} + @Override + public Packet getAddEntityPacket() { + throw new UnsupportedOperationException("This is a FAKE CHUNK ENTITY... For tricking the Sodium to check a AABB."); + } + } + #endif + +} diff --git a/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/StarlightAccessor.java b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/StarlightAccessor.java new file mode 100644 index 000000000..7f799f2cf --- /dev/null +++ b/quilt/src/main/java/com/seibel/lod/quilt/wrappers/modAccessor/StarlightAccessor.java @@ -0,0 +1,35 @@ +/* + * This file is part of the Distant Horizons mod (formerly the LOD Mod), + * licensed under the GNU GPL v3 License. + * + * Copyright (C) 2020-2022 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.seibel.lod.quilt.wrappers.modAccessor; + +import com.seibel.lod.core.wrapperInterfaces.modAccessor.IStarlightAccessor; + + +public class StarlightAccessor implements IStarlightAccessor { + + @Override + public String getModName() { + return "Starlight-Fabric-1.18.X"; + } + + public StarlightAccessor() { + + } +} diff --git a/quilt/src/main/resources/quilt.lod.mixins.json b/quilt/src/main/resources/quilt.lod.mixins.json new file mode 100644 index 000000000..cebbe18e6 --- /dev/null +++ b/quilt/src/main/resources/quilt.lod.mixins.json @@ -0,0 +1,21 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.seibel.lod.quilt.mixins", + "mixins": [ + "MixinUtilBackgroudThread", + "events.MixinServerLevel" + ], + "client": [ + "MixinMinecraft", + "events.MixinClientLevel", + "events.MixinMinecraft", + "events.MixinBlockUpdate" + ], + "server": [ + "MixinDedicatedServer" + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/fabric/src/main/resources/quilt.mod.json b/quilt/src/main/resources/quilt.mod.json similarity index 79% rename from fabric/src/main/resources/quilt.mod.json rename to quilt/src/main/resources/quilt.mod.json index aa1c76bf0..3989e1cc1 100644 --- a/fabric/src/main/resources/quilt.mod.json +++ b/quilt/src/main/resources/quilt.mod.json @@ -1,5 +1,10 @@ { "schema_version": 1, + "mixins": [ + "quilt.lod.mixins.json", + "fabric-like.lod.mixins.json" + ], + "accessWidener" : "lod.accesswidener", "quilt_loader": { "group": "com.seibel.lod", "id": "lod", @@ -8,7 +13,7 @@ "metadata": { "name": "${mod_name}", "description": "${description}", - "contributors": ${quilt_authors}, + "contributors": $quilt_authors, "icon": "icon.png" }, "entrypoints": { @@ -34,10 +39,8 @@ }, { "id": "minecraft", - "versions": ${compatible_minecraft_versions} + "versions": $compatible_minecraft_versions } ] - }, - "mixin": "fabric.lod.mixins.json", - "accessWidener" : "lod.accesswidener" + } } \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 3f229b04b..40014e7c6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,13 +1,6 @@ pluginManagement { repositories { - maven { - name = 'Fabric' - url "https://maven.fabricmc.net/" - } - maven { - name = 'Quilt' - url = 'https://maven.quiltmc.org/repository/release' - } + maven { url "https://maven.fabricmc.net/" } maven { url "https://maven.architectury.dev/" } maven { url "https://maven.minecraftforge.net/" } gradlePluginPortal() @@ -15,7 +8,9 @@ pluginManagement { } include("common") +include("fabric-like") include("fabric") +include("quilt") include("forge") include("core")