Skip to content

Commit

Permalink
Switch mappings to mojmap with YALMM.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Jul 30, 2024
1 parent d35b7ea commit bbefb88
Show file tree
Hide file tree
Showing 56 changed files with 537 additions and 516 deletions.
122 changes: 121 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import com.modrinth.minotaur.dependencies.ModDependency
import net.darkhax.curseforgegradle.TaskPublishCurseForge
import net.fabricmc.loom.api.mappings.layered.MappingContext
import net.fabricmc.loom.api.mappings.layered.MappingLayer
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace
import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec
import net.fabricmc.loom.configuration.providers.mappings.intermediary.IntermediaryMappingLayer
import net.fabricmc.loom.configuration.providers.mappings.utils.DstNameFilterMappingVisitor
import net.fabricmc.loom.util.download.DownloadException
import net.fabricmc.mappingio.MappingVisitor
import net.fabricmc.mappingio.adapter.MappingDstNsReorder
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch
import net.fabricmc.mappingio.format.proguard.ProGuardFileReader
import net.fabricmc.mappingio.tree.MemoryMappingTree
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
import java.util.regex.Pattern

plugins {
id("fabric-loom").version("1.7.+")
Expand Down Expand Up @@ -98,6 +114,10 @@ repositories {
name = "grondag"
url = uri("https://maven.dblsaiko.net/")
}
maven {
name = "ParchmentMC"
url = uri("https://maven.parchmentmc.org")
}
exclusiveContent {
forRepository {
maven {
Expand All @@ -116,9 +136,109 @@ loom {
runtimeOnlyLog4j = true
}

// Based off Loom, this is required as the releases at the time of writing this buildscript have
// a flaw with the mapping layering preventing the usage of the usual MojangMappingLayer.
@Suppress("UnstableApiUsage")
internal data class MojangMappingLayer(
val clientMappings: Path, val serverMappings: Path, val nameSyntheticMembers: Boolean,
val intermediaryMappings: MemoryMappingTree, val logger: Logger
) : MappingLayer {
@Throws(IOException::class)
override fun visit(mappingVisitor: MappingVisitor) {
val mojmap = MemoryMappingTree()

// Filter out field names matching the pattern
val nameFilter = DstNameFilterMappingVisitor(mojmap, SYNTHETIC_NAME_PATTERN)

// Make official the source namespace
val nsSwitch = MappingSourceNsSwitch(if (nameSyntheticMembers) mojmap else nameFilter, MappingsNamespace.OFFICIAL.toString())

Files.newBufferedReader(clientMappings).use { clientBufferedReader ->
Files.newBufferedReader(serverMappings).use { serverBufferedReader ->
ProGuardFileReader.read(
clientBufferedReader,
MappingsNamespace.NAMED.toString(),
MappingsNamespace.OFFICIAL.toString(),
nsSwitch
)
ProGuardFileReader.read(
serverBufferedReader,
MappingsNamespace.NAMED.toString(),
MappingsNamespace.OFFICIAL.toString(),
nsSwitch
)
}
}

intermediaryMappings.accept(MappingDstNsReorder(mojmap, MappingsNamespace.INTERMEDIARY.toString()))

val switch = MappingSourceNsSwitch(MappingDstNsReorder(mappingVisitor, MappingsNamespace.NAMED.toString()), MappingsNamespace.INTERMEDIARY.toString(), true)
mojmap.accept(switch)
}

override fun getSourceNamespace(): MappingsNamespace {
return MappingsNamespace.INTERMEDIARY
}

override fun dependsOn(): List<Class<out MappingLayer?>> {
return listOf(IntermediaryMappingLayer::class.java)
}

companion object {
private val SYNTHETIC_NAME_PATTERN: Pattern = Pattern.compile("^(access|this|val\\\$this|lambda\\$.*)\\$[0-9]+$")
}
}

@Suppress("UnstableApiUsage")
internal data class MojangMappingsSpec(val nameSyntheticMembers: Boolean) : MappingsSpec<MojangMappingLayer?> {
override fun createLayer(context: MappingContext): MojangMappingLayer {
val versionInfo = context.minecraftProvider().versionInfo
val clientDownload = versionInfo.download(MANIFEST_CLIENT_MAPPINGS)
val serverDownload = versionInfo.download(MANIFEST_SERVER_MAPPINGS)

if (clientDownload == null) {
throw RuntimeException("Failed to find official mojang mappings for " + context.minecraftVersion())
}

val clientMappings = context.workingDirectory("mojang").resolve("client.txt")
val serverMappings = context.workingDirectory("mojang").resolve("server.txt")

try {
context.download(clientDownload.url())
.sha1(clientDownload.sha1())
.downloadPath(clientMappings)

context.download(serverDownload.url())
.sha1(serverDownload.sha1())
.downloadPath(serverMappings)
} catch (e: DownloadException) {
throw UncheckedIOException("Failed to download mappings", e)
}

return MojangMappingLayer(
clientMappings,
serverMappings,
nameSyntheticMembers,
context.intermediaryTree().get(),
context.logger
)
}

companion object {
// Keys in dependency manifest
private const val MANIFEST_CLIENT_MAPPINGS = "client_mappings"
private const val MANIFEST_SERVER_MAPPINGS = "server_mappings"
}
}

dependencies {
minecraft(libs.minecraft)
mappings("net.fabricmc:yarn:${minecraftVersion}+build.${project.property("yarn_mappings")}:v2")
@Suppress("UnstableApiUsage")
mappings(loom.layered {
addLayer(MojangMappingsSpec(false))
parchment("org.parchmentmc.data:parchment-$minecraftVersion:${libs.versions.mappings.parchment.get()}@zip")
mappings("dev.lambdaurora:yalmm:$minecraftVersion+build.${libs.versions.mappings.yalmm.get()}")
})
modImplementation(libs.fabric.loader)

modImplementation(libs.fabric.api)
Expand Down
6 changes: 1 addition & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/use
yarn_mappings=2

# Mod Properties
mod_version = 2.3.4
mod_version = 3.0.0-alpha.1
maven_group = dev.lambdaurora
archives_base_name = lambdynamiclights
modrinth_id=yBW8D80W
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
minecraft = "1.21"
fabric-loader = "0.15.11"
fabric-api = "0.100.4+1.21"
mappings-yalmm = "8"
mappings-parchment = "2024.07.07"

# Dependencies
spruceui = "5.1.0+1.21"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
22 changes: 12 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down Expand Up @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

package dev.lambdaurora.lambdynlights;

import net.minecraft.client.render.WorldRenderer;
import net.minecraft.world.World;
import net.minecraft.client.renderer.LevelRenderer;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* Represents a dynamic light source.
*
* @author LambdAurora
* @version 1.3.3
* @version 3.0.0
* @since 1.0.0
*/
public interface DynamicLightSource {
Expand Down Expand Up @@ -48,7 +48,7 @@ public interface DynamicLightSource {
*
* @return the world instance
*/
World getDynamicLightWorld();
Level getDynamicLightLevel();

/**
* Returns whether the dynamic light is enabled or not.
Expand Down Expand Up @@ -97,7 +97,7 @@ default void setDynamicLightEnabled(boolean enabled) {
*/
boolean shouldUpdateDynamicLight();

boolean lambdynlights$updateDynamicLight(@NotNull WorldRenderer renderer);
boolean lambdynlights$updateDynamicLight(@NotNull LevelRenderer renderer);

void lambdynlights$scheduleTrackedChunksRebuild(@NotNull WorldRenderer renderer);
void lambdynlights$scheduleTrackedChunksRebuild(@NotNull LevelRenderer renderer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import dev.lambdaurora.spruceui.option.SpruceCyclingOption;
import dev.lambdaurora.spruceui.option.SpruceOption;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Text;
import org.jetbrains.annotations.NotNull;

import java.nio.file.Path;
Expand Down Expand Up @@ -71,7 +71,7 @@ public DynamicLightsConfig(@NotNull LambDynLights mod) {
Text.translatable("lambdynlights.tooltip.self_light_source"))
.withOnSet(value -> {
if (!value) this.mod.removeLightSources(source ->
source instanceof ClientPlayerEntity && source == MinecraftClient.getInstance().player
source instanceof LocalPlayer && source == Minecraft.getInstance().player
);
});
this.blockEntitiesLightSource = new BooleanSettingEntry("light_sources.block_entities", DEFAULT_BLOCK_ENTITIES_LIGHT_SOURCE, this.config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import dev.lambdaurora.spruceui.SpruceTexts;
import dev.lambdaurora.spruceui.util.Nameable;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.TextFormatting;
import net.minecraft.network.chat.Text;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
Expand All @@ -26,17 +26,17 @@
* @since 1.0.0
*/
public enum DynamicLightsMode implements Nameable {
OFF(0, Formatting.RED, SpruceTexts.OPTIONS_OFF),
FASTEST(500, Formatting.GOLD, SpruceTexts.OPTIONS_GENERIC_FASTEST),
FAST(250, Formatting.YELLOW, SpruceTexts.OPTIONS_GENERIC_FAST),
FANCY(0, Formatting.GREEN, SpruceTexts.OPTIONS_GENERIC_FANCY);
OFF(0, TextFormatting.RED, SpruceTexts.OPTIONS_OFF),
FASTEST(500, TextFormatting.GOLD, SpruceTexts.OPTIONS_GENERIC_FASTEST),
FAST(250, TextFormatting.YELLOW, SpruceTexts.OPTIONS_GENERIC_FAST),
FANCY(0, TextFormatting.GREEN, SpruceTexts.OPTIONS_GENERIC_FANCY);

private final int delay;
private final Text translatedText;

DynamicLightsMode(int delay, @NotNull Formatting formatting, @NotNull Text translatedText) {
DynamicLightsMode(int delay, @NotNull TextFormatting formatting, @NotNull Text translatedText) {
this.delay = delay;
this.translatedText = translatedText.copy().formatted(formatting);
this.translatedText = translatedText.copy().withStyle(formatting);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import dev.lambdaurora.spruceui.SpruceTexts;
import dev.lambdaurora.spruceui.util.Nameable;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.TextFormatting;
import net.minecraft.network.chat.Text;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
Expand All @@ -26,14 +26,14 @@
* @since 1.2.1
*/
public enum ExplosiveLightingMode implements Nameable {
OFF(Formatting.RED, SpruceTexts.OPTIONS_OFF),
SIMPLE(Formatting.YELLOW, SpruceTexts.OPTIONS_GENERIC_SIMPLE),
FANCY(Formatting.GREEN, SpruceTexts.OPTIONS_GENERIC_FANCY);
OFF(TextFormatting.RED, SpruceTexts.OPTIONS_OFF),
SIMPLE(TextFormatting.YELLOW, SpruceTexts.OPTIONS_GENERIC_SIMPLE),
FANCY(TextFormatting.GREEN, SpruceTexts.OPTIONS_GENERIC_FANCY);

private final Text translatedText;

ExplosiveLightingMode(@NotNull Formatting formatting, @NotNull Text translatedText) {
this.translatedText = translatedText.copy().formatted(formatting);
ExplosiveLightingMode(@NotNull TextFormatting formatting, @NotNull Text translatedText) {
this.translatedText = translatedText.copy().withStyle(formatting);
}

/**
Expand Down
Loading

0 comments on commit bbefb88

Please sign in to comment.