From fdc9f82d4c4c83c3b6fae4175ce48e6a3bc8f720 Mon Sep 17 00:00:00 2001 From: ByteDevEs Date: Sun, 8 Oct 2023 02:35:04 +0200 Subject: [PATCH] Fabric & Forge port 1.20.1 Made the mod work with forge and fabric, modification of commit #470 Co-Authored-By: Louis <82884007+dev0louis@users.noreply.github.com> --- common/build.gradle | 2 +- fabric/src/main/resources/fabric.mod.json | 2 +- forge/build.gradle | 130 ++++++++++++++ forge/gradle.properties | 1 + .../client/forge/TileTextureMapImpl.java | 168 ++++++++++++++++++ .../gui/forge/AntiqueAtlasConfigMenu.java | 17 ++ .../atlas/forge/AntiqueAtlasModForge.java | 29 +++ .../mixin/forge/VolatileMixinPluginImpl.java | 10 ++ forge/src/main/resources/META-INF/mods.toml | 44 +++++ .../main/resources/antiqueatlas.mixins.json | 13 ++ forge/src/main/resources/pack.mcmeta | 6 + gradle.properties | 9 +- 12 files changed, 427 insertions(+), 4 deletions(-) create mode 100644 forge/build.gradle create mode 100644 forge/gradle.properties create mode 100644 forge/src/main/java/hunternif/mc/impl/atlas/client/forge/TileTextureMapImpl.java create mode 100644 forge/src/main/java/hunternif/mc/impl/atlas/client/gui/forge/AntiqueAtlasConfigMenu.java create mode 100644 forge/src/main/java/hunternif/mc/impl/atlas/forge/AntiqueAtlasModForge.java create mode 100644 forge/src/main/java/hunternif/mc/impl/atlas/mixin/forge/VolatileMixinPluginImpl.java create mode 100644 forge/src/main/resources/META-INF/mods.toml create mode 100644 forge/src/main/resources/antiqueatlas.mixins.json create mode 100644 forge/src/main/resources/pack.mcmeta diff --git a/common/build.gradle b/common/build.gradle index 847ce7918..53f60a904 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,5 +1,5 @@ architectury { - common(rootProject.enabled_platforms) + common(rootProject.enabled_platforms.split(",")) } loom { diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 869ee8141..e74f59058 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -5,7 +5,7 @@ "description": "Antique Atlas is a book that acts like a map featuring infinite scrolling, zoom and custom labeled markers. The map is generated around the player by calculating the average biome in each 16x16 chunk.", "version": "${version}", "authors": ["Hunternif", "tyra314"], - "contributors": ["coolAlias", "Kenkron", "TheCodeWarrior", "Localizations by crafteverywhere", "CapoFantasma97", "Mazdallier", "mankra", "Zerotiger"], + "contributors": ["coolAlias", "Kenkron", "TheCodeWarrior", "Localizations by crafteverywhere", "CapoFantasma97", "Mazdallier", "mankra", "Zerotiger", "Dev0Louis"], "entrypoints": { "main": [ "hunternif.mc.impl.atlas.fabric.AntiqueAtlasModFabric" diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 000000000..980e69799 --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,130 @@ +plugins { + id "com.github.johnrengelman.shadow" version "7.1.2" + id "me.shedaniel.unified-publishing" +} + +architectury { + platformSetupLoomIde() + forge() +} + +loom { + accessWidenerPath = project(":common").loom.accessWidenerPath + + forge { + convertAccessWideners = true + extraAccessWideners.add loom.accessWidenerPath.get().asFile.name + + mixinConfig "antiqueatlas-common.mixins.json" + mixinConfig "antiqueatlas.mixins.json" + } +} + + +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 + developmentForge.extendsFrom common +} + +dependencies { + forge "net.minecraftforge:forge:${rootProject.forge_version}" + + modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}" + modApi "me.shedaniel.cloth:cloth-config-forge:${rootProject.cloth_config_version}" + + common(project(path: ":common", configuration: "namedElements")) { transitive false } + shadowCommon(project(path: ":common", configuration: "transformProductionForge")) { transitive = false } +} + +processResources { + inputs.property "version", project.version + + filesMatching("META-INF/mods.toml") { + expand "version": project.version + } +} + +shadowJar { + exclude "fabric.mod.json" + exclude "architectury.common.json" + + configurations = [project.configurations.shadowCommon] + classifier "dev-shadow" +} + +remapJar { + 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 { + mavenForge(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. + } +} + +unifiedPublishing { + project { + gameVersions = ["1.18.2"] + gameLoaders = ["forge"] + releaseType = "release" + + mainPublication tasks.remapJar + + relations { + depends { + curseforge = "cloth-config" + modrinth = "cloth-config" + } + depends { + curseforge = "architectury-api" + modrinth = "architectury-api" + } + } + + var cfToken = System.getenv("CF_TOKEN") + if (cfToken != null) { + curseforge { + token = cfToken + id = rootProject.curseforge_id + gameVersions.addAll "Java 17" + } + } + + var mrToken = System.getenv("MODRINTH_TOKEN") + if (mrToken != null) { + modrinth { + token = mrToken + id = rootProject.modrinth_id + } + } + } +} \ No newline at end of file diff --git a/forge/gradle.properties b/forge/gradle.properties new file mode 100644 index 000000000..32f842a63 --- /dev/null +++ b/forge/gradle.properties @@ -0,0 +1 @@ +loom.platform=forge \ No newline at end of file diff --git a/forge/src/main/java/hunternif/mc/impl/atlas/client/forge/TileTextureMapImpl.java b/forge/src/main/java/hunternif/mc/impl/atlas/client/forge/TileTextureMapImpl.java new file mode 100644 index 000000000..45cb2fbdc --- /dev/null +++ b/forge/src/main/java/hunternif/mc/impl/atlas/client/forge/TileTextureMapImpl.java @@ -0,0 +1,168 @@ +package hunternif.mc.impl.atlas.client.forge; + +import hunternif.mc.impl.atlas.AntiqueAtlasMod; +import hunternif.mc.impl.atlas.client.TileTextureMap; +import net.minecraft.client.MinecraftClient; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.BiomeTags; +import net.minecraft.util.Identifier; +import net.minecraft.registry.Registry; +import net.minecraft.registry.entry.RegistryEntry; +import net.minecraft.registry.RegistryKey; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.common.Tags; + +import java.util.Optional; + +@OnlyIn(Dist.CLIENT) +public class TileTextureMapImpl { + static public Optional guessFittingTextureSet(RegistryKey biome) { + if (MinecraftClient.getInstance().world == null) + return Optional.empty(); + + RegistryEntry.Reference biomeTag = MinecraftClient.getInstance().world.getRegistryManager().get(RegistryKeys.BIOME).entryOf(biome); + + if (biomeTag.isIn(BiomeTags.IS_END)) { +// if (biomeTag.isIn(Tags.Biomes.END) || biomeTag.isIn(ConventionalBiomeTags.VEGETATION_SPARSE)) { +// return Optional.of(AntiqueAtlasMod.id("end_island_plants")); +// } else { + return Optional.of(AntiqueAtlasMod.id("end_island")); +// } + } + + if (biomeTag.isIn(BiomeTags.IS_NETHER)) { + return Optional.of(AntiqueAtlasMod.id("soul_sand_valley")); + } + + if (biomeTag.isIn(Tags.Biomes.IS_VOID)) { + return Optional.of(AntiqueAtlasMod.id("end_void")); + } + + if (biomeTag.isIn(Tags.Biomes.IS_SWAMP)) { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("swamp_hills")); + } else { + return Optional.of(AntiqueAtlasMod.id("swamp")); + } + } + + if (biomeTag.isIn(BiomeTags.IS_OCEAN) + || biomeTag.isIn(BiomeTags.IS_DEEP_OCEAN) + || biomeTag.isIn(BiomeTags.IS_RIVER) + || biomeTag.isIn(Tags.Biomes.IS_WATER)) { + if (biomeTag.isIn(Tags.Biomes.IS_COLD) || biomeTag.isIn(Tags.Biomes.IS_SNOWY)) + return Optional.of(AntiqueAtlasMod.id("ice")); + + return Optional.of(AntiqueAtlasMod.id("water")); + } + + if (biomeTag.isIn(BiomeTags.IS_BEACH) || biomeTag.isIn(BiomeTags.IS_BEACH)) { + return Optional.of(AntiqueAtlasMod.id("shore")); + } + + if (biomeTag.isIn(BiomeTags.IS_JUNGLE)) { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("jungle_hills")); + } else { + return Optional.of(AntiqueAtlasMod.id("jungle")); + } + } + + if (biomeTag.isIn(BiomeTags.IS_SAVANNA)) { + return Optional.of(AntiqueAtlasMod.id("savana")); + } + + if (biomeTag.isIn((Tags.Biomes.IS_PLATEAU))) { + return Optional.of(AntiqueAtlasMod.id("plateau_mesa")); + } + + if (biomeTag.isIn(BiomeTags.IS_FOREST) + || biomeTag.isIn(Tags.Biomes.IS_DENSE) + || biomeTag.isIn(Tags.Biomes.IS_SPARSE) + ) { + if (biomeTag.isIn(Tags.Biomes.IS_COLD) || biomeTag.isIn(Tags.Biomes.IS_SNOWY)) { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("snow_pines_hills")); + } else { + return Optional.of(AntiqueAtlasMod.id("snow_pines")); + } + } else { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("forest_hills")); + } else { + return Optional.of(AntiqueAtlasMod.id("forest")); + } + } + } + + if (biomeTag.isIn(Tags.Biomes.IS_PLAINS)) { + if (biomeTag.isIn(Tags.Biomes.IS_COLD) + || biomeTag.isIn(Tags.Biomes.IS_SNOWY) + ) { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("snow_hills")); + } else { + return Optional.of(AntiqueAtlasMod.id("snow")); + } + } else { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("hills")); + } else { + return Optional.of(AntiqueAtlasMod.id("plains")); + } + } + } + + if (biomeTag.isIn(Tags.Biomes.IS_COLD)) { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("mountains_snow_caps")); + } else { + return Optional.of(AntiqueAtlasMod.id("ice_spikes")); + } + } + + if (biomeTag.isIn(Tags.Biomes.IS_HOT)) { + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("desert_hills")); + } else { + return Optional.of(AntiqueAtlasMod.id("desert")); + } + } + +// if (biomeTag.isIn(Tags.Biomes.TAIGA)) { +// return Optional.of(AntiqueAtlasMod.id("snow")); +// } + +// if (biomeTag.isIn(Tags.Biomes.EXTREME_HILLS)) { +// return Optional.of(AntiqueAtlasMod.id("hills")); +// } + + if (biomeTag.isIn(Tags.Biomes.IS_SLOPE)) { + return Optional.of(AntiqueAtlasMod.id("mountains")); + } + + if (biomeTag.isIn(Tags.Biomes.IS_PEAK)) { + return Optional.of(AntiqueAtlasMod.id("mountains_snow_caps")); + } + + if (biomeTag.isIn(Tags.Biomes.IS_MUSHROOM)) { + return Optional.of(AntiqueAtlasMod.id("mushroom")); + } + + if (biomeTag.isIn(BiomeTags.IS_BADLANDS)) { + return Optional.of(AntiqueAtlasMod.id("mesa")); + } + + if (biomeTag.isIn(BiomeTags.IS_HILL)) { + return Optional.of(AntiqueAtlasMod.id("hills")); + } + + if (biomeTag.isIn(Tags.Biomes.IS_UNDERGROUND)) { + AntiqueAtlasMod.LOG.warn("Underground biomes aren't supported yet."); + } + + return TileTextureMap.guessFittingTextureSetFallback(biomeTag); + } +} diff --git a/forge/src/main/java/hunternif/mc/impl/atlas/client/gui/forge/AntiqueAtlasConfigMenu.java b/forge/src/main/java/hunternif/mc/impl/atlas/client/gui/forge/AntiqueAtlasConfigMenu.java new file mode 100644 index 000000000..e37f92ce2 --- /dev/null +++ b/forge/src/main/java/hunternif/mc/impl/atlas/client/gui/forge/AntiqueAtlasConfigMenu.java @@ -0,0 +1,17 @@ +package hunternif.mc.impl.atlas.client.gui.forge; + +import hunternif.mc.impl.atlas.AntiqueAtlasConfig; +import me.shedaniel.autoconfig.AutoConfig; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.ConfigScreenHandler; +import net.minecraftforge.fml.ModLoadingContext; + +@OnlyIn(Dist.CLIENT) +public class AntiqueAtlasConfigMenu { + public static void init() { + ModLoadingContext.get().registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, + () -> new ConfigScreenHandler.ConfigScreenFactory((mc, parent) -> AutoConfig.getConfigScreen(AntiqueAtlasConfig.class, parent).get()) + ); + } +} \ No newline at end of file diff --git a/forge/src/main/java/hunternif/mc/impl/atlas/forge/AntiqueAtlasModForge.java b/forge/src/main/java/hunternif/mc/impl/atlas/forge/AntiqueAtlasModForge.java new file mode 100644 index 000000000..8850084ba --- /dev/null +++ b/forge/src/main/java/hunternif/mc/impl/atlas/forge/AntiqueAtlasModForge.java @@ -0,0 +1,29 @@ +package hunternif.mc.impl.atlas.forge; + +import dev.architectury.platform.Platform; +import dev.architectury.platform.forge.EventBuses; +import dev.architectury.utils.Env; +import hunternif.mc.impl.atlas.AntiqueAtlasMod; +import hunternif.mc.impl.atlas.AntiqueAtlasModClient; +import hunternif.mc.impl.atlas.client.gui.forge.AntiqueAtlasConfigMenu; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; + +@Mod(AntiqueAtlasMod.ID) +public class AntiqueAtlasModForge +{ + public AntiqueAtlasModForge() + { + // Submit our event bus to let architectury register our content on the right time + EventBuses.registerModEventBus(AntiqueAtlasMod.ID, + FMLJavaModLoadingContext.get().getModEventBus()); + + AntiqueAtlasMod.init(); + + if (Platform.getEnvironment() == Env.CLIENT) + { + AntiqueAtlasModClient.init(); + AntiqueAtlasConfigMenu.init(); + } + } +} diff --git a/forge/src/main/java/hunternif/mc/impl/atlas/mixin/forge/VolatileMixinPluginImpl.java b/forge/src/main/java/hunternif/mc/impl/atlas/mixin/forge/VolatileMixinPluginImpl.java new file mode 100644 index 000000000..7e5d0e257 --- /dev/null +++ b/forge/src/main/java/hunternif/mc/impl/atlas/mixin/forge/VolatileMixinPluginImpl.java @@ -0,0 +1,10 @@ +package hunternif.mc.impl.atlas.mixin.forge; + +import net.minecraftforge.fml.loading.FMLEnvironment; + +public class VolatileMixinPluginImpl +{ + public static boolean isDevelopmentEnvironment() { + return !FMLEnvironment.production; + } +} \ No newline at end of file diff --git a/forge/src/main/resources/META-INF/mods.toml b/forge/src/main/resources/META-INF/mods.toml new file mode 100644 index 000000000..b98ff7a2b --- /dev/null +++ b/forge/src/main/resources/META-INF/mods.toml @@ -0,0 +1,44 @@ +modLoader="javafml" +loaderVersion="[40,)" +license="GNU GENERAL PUBLIC LICENSE" +issueTrackerURL="https://github.com/AntiqueAtlasTeam/AntiqueAtlas/issues" + +[[mods]] +modId="antiqueatlas" +version="${version}" +logoFile="antiqueatlas_icon.png" +displayName="Antique Atlas" +displayURL="https://www.curseforge.com/minecraft/mc-mods/antique-atlas" +credits="Hunternif, Kenkron, osipxd, thecodewarrior, TehNut, crafteverywhere, coolAlias, Ruukas97, Mazdallier, chesterccj305, asiekierka, sam-kirby, esotericist, dadodollabela, Yulife, Waterrail, The-Fireplace, TBM13, Rikshy, GirafiStudios, DrCopernicus, DBotThePony, AugiteSoul, Stereowalker, ByteDevES" +authors="Hunternif, tyra314" +description=''' +Antique Atlas is a book that acts like a map featuring infinite scrolling, zoom and custom labeled markers. The map is generated around the player by calculating the average biome in each 16x16 chunk. +''' + +[[dependencies.antiqueatlas]] +modId="forge" +mandatory=true +versionRange="[47,)" +ordering="NONE" +side="BOTH" + +[[dependencies.antiqueatlas]] +modId="minecraft" +mandatory=true +versionRange="[1.20.1,)" +ordering="NONE" +side="BOTH" + +[[dependencies.antiqueatlas]] +modId="cloth_config" +mandatory=true +versionRange="[11.1.106,)" +ordering="NONE" +side="BOTH" + +[[dependencies.antiqueatlas]] +modId = "architectury" +mandatory = true +versionRange = "[9.1.12,)" +ordering = "AFTER" +side = "BOTH" diff --git a/forge/src/main/resources/antiqueatlas.mixins.json b/forge/src/main/resources/antiqueatlas.mixins.json new file mode 100644 index 000000000..dc4307faf --- /dev/null +++ b/forge/src/main/resources/antiqueatlas.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "package": "hunternif.mc.impl.atlas.mixin.forge", + "compatibilityLevel": "JAVA_17", + "mixins": [ + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + }, + "minVersion": "0.1" +} diff --git a/forge/src/main/resources/pack.mcmeta b/forge/src/main/resources/pack.mcmeta new file mode 100644 index 000000000..36fe8a59b --- /dev/null +++ b/forge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "AntiqueAtlas", + "pack_format": 15 + } +} diff --git a/gradle.properties b/gradle.properties index 7760c6da4..d775ecb50 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,8 @@ org.gradle.jvmargs=-Xmx2G minecraft_version = 1.20.1 yarn_mappings = 1.20.1+build.10 fabric_loader_version = 0.14.22 -enabled_platforms = fabric +forge_version = 1.20.1-47.1.0 +enabled_platforms = fabric,forge # Mod Properties mod_version = 7.1.1 @@ -16,4 +17,8 @@ archives_base_name = antiqueatlas architectury_version = 9.1.12 cloth_config_version = 11.1.106 fabric_api_version = 0.88.1+1.20.1 -mod_menu_version = 7.2.2 \ No newline at end of file +mod_menu_version = 7.2.2 + +# Publishing +curseforge_id = 227795 +modrinth_id = wHODup9j \ No newline at end of file