Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/build_artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
uses: gradle/actions/setup-gradle@v5
with:
cache-read-only: false

Expand All @@ -30,20 +30,23 @@ jobs:
- name: Generate resources with Gradle
run: ./gradlew runDatagenClient
env:
CUSTOM_VERSION: ${{ env.short_commit_hash }}
PRESERVE_PRERELEASE_VERSION: true
DISABLE_PROPERTIES_UPDATE: true
VERSION_SUFFIX: ${{ env.short_commit_hash }}

- name: Build with Gradle
run: ./gradlew build
env:
CUSTOM_VERSION: ${{ env.short_commit_hash }}
PRESERVE_PRERELEASE_VERSION: true
DISABLE_PROPERTIES_UPDATE: true
VERSION_SUFFIX: ${{ env.short_commit_hash }}

- name: Publish to Maven
run: ./gradlew publishMavenPublicationToOffsetMonkey538Repository
env:
CUSTOM_VERSION: ${{ env.short_commit_hash }}
PRESERVE_PRERELEASE_VERSION: true
DISABLE_PROPERTIES_UPDATE: true
VERSION_SUFFIX: ${{ env.short_commit_hash }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}

Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
uses: gradle/actions/setup-gradle@v5
with:
cache-read-only: false

Expand All @@ -32,29 +32,35 @@ jobs:
- name: Generate resources with Gradle
run: ./gradlew runDatagenClient
env:
IS_RELEASE: true
DISABLE_PROPERTIES_UPDATE: true


- name: Build with Gradle
run: ./gradlew build
env:
IS_RELEASE: true
DISABLE_PROPERTIES_UPDATE: true

- name: Upload to Modrinth
run: ./gradlew modrinth
env:
IS_RELEASE: true
DISABLE_PROPERTIES_UPDATE: true
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
VERSION_NAME: ${{ github.event.release.name }}
VERSION_IS_PRERELEASE: ${{ github.event.release.prerelease }}
VERSION_CHANGELOG: ${{ github.event.release.body }}

- name: Upload to GitHub
uses: softprops/action-gh-release@v2
with:
files: build/libs/*.jar

- name: Publish to Maven
run: ./gradlew publishMavenPublicationToOffsetMonkey538Repository
env:
IS_RELEASE: true
DISABLE_PROPERTIES_UPDATE: true
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}

- name: Upload to GitHub
uses: softprops/action-gh-release@v2
with:
files: build/libs/*.jar
56 changes: 33 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,47 @@
import dex.plugins.outlet.v2.util.ReleaseType

import java.nio.file.Files

plugins {
id 'fabric-loom' version '1.11-SNAPSHOT'
id 'io.github.dexman545.outlet' version '1.6.1'
id 'com.modrinth.minotaur' version '2.+'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = "loot-table-modifier"
group = "top.offsetmonkey538.loottablemodifier"
ext {
versionPrefix = rootProject.mod_version
if (!Boolean.parseBoolean(System.getenv("IS_RELEASE"))) {
String preReleaseVersion = System.currentTimeMillis()

if (Boolean.parseBoolean(System.getenv("PRESERVE_PRERELEASE_VERSION"))) {
var preReleaseVersionFile = file("preReleaseVersion.txt").toPath()
if (Files.exists(preReleaseVersionFile)) preReleaseVersion = Files.readString(preReleaseVersionFile)
Files.writeString(preReleaseVersionFile, preReleaseVersion)
}

version = project.mod_version
var separator = "-"
if (versionPrefix.contains("-")) separator = "."
versionPrefix = "${versionPrefix}${separator}${preReleaseVersion}"
}
final String versionSuffix = System.getenv("VERSION_SUFFIX")
if (versionSuffix != null && !versionSuffix.isEmpty()) {
versionPrefix = "${versionPrefix}+${versionSuffix}"
}

if ("true".equalsIgnoreCase(System.getenv("IS_DEBUG"))) {
version = "${version}-${System.currentTimeMillis()}"
System.out.println("Version Prefix: " + versionPrefix)
}

final String customVersion = System.getenv("CUSTOM_VERSION")
if (customVersion != null && !customVersion.isEmpty()) {
version = "${version}-${customVersion}"
allprojects {
group = "top.offsetmonkey538.loottablemodifier"
base.archivesName = "mesh-lib" // todo: move to subprojects and give em different suffixes
version = "${rootProject.versionPrefix}+${project.property("minecraft_version")}" // todo: again, move to subprojects
}

version = "${project.version}+${project.minecraft_version}"
println "Version: ${version}"

outlet {
maintainPropertiesFile = System.getenv("DISABLE_PROPERTIES_UPDATE") == null
mcVersionRange = project.supported_minecraft_versions
allowedReleaseTypes = Set.of(ReleaseType.RELEASE)
allowedReleaseTypes = [ReleaseType.RELEASE]
propertiesData = [
'fapi_version': outlet.fapiVersion(project.minecraft_version),
'yarn_version': outlet.yarnVersion(project.minecraft_version),
Expand Down Expand Up @@ -168,8 +178,8 @@ tasks.named("javadoc", Javadoc) {
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}" }
from("${rootProject.projectDir}/LICENSE") {
rename { "${it}" }
}
}

Expand All @@ -178,26 +188,26 @@ modrinth {
token = System.getenv("MODRINTH_TOKEN")
projectId = "loot-table-modifier"
gameVersions = outlet.mcVersions()
loaders = ["fabric"]

// Version stuff
def customVersionName = System.getenv("VERSION_NAME")
if (customVersionName != null) versionName = customVersionName

versionNumber = "${project.version}"

def isPreRelease = System.getenv("VERSION_IS_PRERELEASE")
versionType = "true".equalsIgnoreCase(isPreRelease) ? "beta" : "release"
versionType = Boolean.parseBoolean(System.getenv("VERSION_IS_PRERELEASE")) ? "beta" : "release"

if (project.mod_version.contains("beta")) versionType = "beta"
else if (project.mod_version.contains("alpha")) versionType = "alpha"
if (rootProject.mod_version.contains("beta")) versionType = "beta"
if (rootProject.mod_version.contains("alpha")) versionType = "alpha"


// Files
uploadFile = remapJar.archiveFile
//additionalFiles = [sourcesJar.archiveFile, javadocJar.archiveFile]
additionalFiles = [sourcesJar.archiveFile]


// Project info
syncBodyFrom = rootProject.file("README.md").text
def changelogEnv = System.getenv("VERSION_CHANGELOG")
if (changelogEnv != null) changelog = changelogEnv
Expand Down Expand Up @@ -227,7 +237,7 @@ publishing {
}
publications {
maven(MavenPublication) {
artifactId = "loot-table-modifier"
artifactId = base.archivesName.get()

from(components["java"])
}
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ minecraft_version = 1.21.8

# These should be automatically updated, unless the environment
# variable "DISABLE_PROPERTIES_UPDATE" is set.
fapi_version = 0.129.0+1.21.8
fapi_version = 0.136.0+1.21.8
yarn_version = 1.21.8+build.1
loader_version = 0.16.14
loader_version = 0.18.0

# Dependencies
## DevAuth, check at https://github.com/DJtheRedstoner/DevAuth
devauth_version = 1.2.1

# Mod Properties
mod_version = 2.0.0-alpha.1
mod_version = 2.0.0-alpha.2
supported_minecraft_versions = >=1.21.5 <=1.21.8
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionSha256Sum=df67a32e86e3276d011735facb1535f64d0d88df84fa87521e90becc2d735444
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
5 changes: 1 addition & 4 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -114,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac

CLASSPATH="\\\"\\\""


# Determine the Java command to use to start the JVM.
Expand Down Expand Up @@ -172,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )

JAVACMD=$( cygpath --unix "$JAVACMD" )

Expand Down Expand Up @@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"

Expand Down
3 changes: 1 addition & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ goto fail
:execute
@rem Setup the command line

set CLASSPATH=


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.minecraft.util.JsonHelper;
import org.apache.commons.io.file.PathUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.offsetmonkey538.loottablemodifier.api.resource.action.LootModifierActionTypes;
Expand Down Expand Up @@ -94,19 +93,18 @@ public static void runModification(ResourceManager resourceManager, Registry<Loo

tableModified = false;

final List<LootPool> poolsCopy = new LinkedList<>(table.pools);
int poolsSize = Math.max(1, poolsCopy.size());
final LootPool[] poolsCopy = table.pools.toArray(LootPool[]::new);
int poolsSize = Math.max(1, poolsCopy.length); // Run loop at least once
for (int i = 0; i < poolsSize; i++) {
final @Nullable LootPool pool = poolsCopy.isEmpty() ? null : poolsCopy.get(i);
final LootPool pool = poolsCopy.length == 0 ? null : poolsCopy[i];
poolModified = false;

final List<LootPoolEntry> entriesCopy = pool == null ? List.of() : new LinkedList<>(pool.entries);
int entriesSize = Math.max(1, entriesCopy.size());
final LootPoolEntry[] entriesCopy = pool == null ? new LootPoolEntry[]{} : pool.entries.toArray(LootPoolEntry[]::new);
int entriesSize = Math.max(1, entriesCopy.length); // Run loop at least once
for (int j = 0; j < entriesSize; j++) {
final @Nullable LootPoolEntry entry = entriesCopy.isEmpty() ? null : entriesCopy.get(j);
final LootPoolEntry entry = entriesCopy.length == 0 ? null : entriesCopy[j];

for (Map.Entry<Identifier, LootModifier> modifierEntry : modifiers.entrySet()) {
// Everything is so fast anyway that there's probably no point in doing what the to-do here said
final LootModifierContext context = new LootModifierContext(table, tableId, pool, entry, tableModified, poolModified);

final LootModifier modifier = modifierEntry.getValue();
Expand Down Expand Up @@ -229,7 +227,7 @@ public static Identifier id(String path) {
}

/*
In 1.21.4, the 'Registry' class extends 'RegistryWrapper' and inherits the 'streamEntries' method from *it*.
In 1.21.4, the 'Registry' class extends 'RegistryWrapper' and inherits the 'streamEntries' method from it.
In 1.20.5, the 'Registry' class *doesn't* extend the 'RegistryWrapper' and implements its own 'streamEntries' method.
Compiling on both versions works, because the names of the methods are the same, but they compile to different intermediary names, thus a jar compiled for 1.20.5 doesn't work on 1.21.4 and vice versa.
Solution: Turn the 'Registry' into a 'RegistryWrapper' as its 'streamEntries' retains the same intermediary on both versions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import top.offsetmonkey538.loottablemodifier.api.resource.action.condition.ConditionAddAction;
import top.offsetmonkey538.loottablemodifier.api.resource.action.entry.EntryAddAction;
import top.offsetmonkey538.loottablemodifier.api.resource.action.entry.EntryRemoveAction;
import top.offsetmonkey538.loottablemodifier.api.resource.action.pool.PoolAddAction;
Expand Down Expand Up @@ -45,6 +46,11 @@ private LootModifierActionTypes() {
*/
public static final LootModifierActionType ENTRY_ITEM_SET = register(id("entry_item_set"), EntryItemSetAction.CODEC);

/**
* Type of {@link ConditionAddAction}
*/
public static final LootModifierActionType CONDITION_ADD = register(id("condition_add"), ConditionAddAction.CODEC);

private static LootModifierActionType register(final @NotNull Identifier id, final @NotNull MapCodec<? extends LootModifierAction> codec) {
return Registry.register(LootModifierActionType.REGISTRY, id, new LootModifierActionType(codec));
}
Expand Down
Loading