Skip to content

Commit

Permalink
Update to 1.20.1
Browse files Browse the repository at this point in the history
Sync IntegerUtil#getDivisorNumbers from Starlight. Although,
DataConverter's version already included the fix, rather the
sync is important for the comments about usage.

Additionally, update loom to 1.2.7 and update the gradle
wrapper.
  • Loading branch information
Spottedleaf committed Jun 16, 2023
1 parent 6c8d100 commit 5a0cefb
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 22 deletions.
45 changes: 36 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.2.7'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
/*
* Gets the version name from the latest Git tag
*/
// https://stackoverflow.com/questions/28498688/gradle-script-to-autoversion-and-include-the-commit-hash-in-android
def getGitCommit = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

archivesBaseName = project.archives_base_name
version = project.mod_version
version = project.mod_version + "+fabric." + getGitCommit()
group = project.maven_group

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
//mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
//modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
// You may need to force-disable transitiveness on them.
Expand All @@ -36,18 +49,32 @@ tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

loom {
accessWidenerPath = file("src/main/resources/dataconverter.accesswidener")
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}
java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
jar {
from "LICENSE"
}

// make build reproducible
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

// configure the maven publication
publishing {
publications {
Expand All @@ -67,4 +94,4 @@ publishing {
// uncomment to publish to the local maven
// mavenLocal()
}
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx2G
org.gradle.daemon=false
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20-rc1
yarn_mappings=1.20-rc1+build.2
minecraft_version=1.20.1
yarn_mappings=1.20.1+build.2
loader_version=0.14.21
# Mod Properties
mod_version=1.0.0-SNAPSHOT
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,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 6 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 8 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginManagement {
repositories {
jcenter()
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,8 @@ public final class MCVersions {
public static final int V1_20_PRE6 = 3460;
public static final int V1_20_PRE7 = 3461;
public static final int V1_20_RC1 = 3462;
public static final int V1_20 = 3463;
public static final int V1_20_1_RC1 = 3464;
public static final int V1_20_1 = 3465;

}
20 changes: 18 additions & 2 deletions src/main/java/ca/spottedleaf/dataconverter/util/IntegerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static int getDivisorShift(final long numbers) {
}

public static long getDivisorNumbers(final int d) {
final int ad = Math.abs(d);
final int ad = branchlessAbs(d);

if (ad < 2) {
throw new IllegalArgumentException("|number| must be in [2, 2^31 -1], not: " + d);
Expand All @@ -103,6 +103,22 @@ public static long getDivisorNumbers(final int d) {
final int two31 = 0x80000000;
final long mask = 0xFFFFFFFFL; // mask for enforcing unsigned behaviour

/*
Signed usage:
int number;
long magic = getDivisorNumbers(div);
long mul = magic >>> 32;
int sign = number >> 31;
int result = (int)(((long)number * mul) >>> magic) - sign;
*/
/*
Unsigned usage:
int number;
long magic = getDivisorNumbers(div);
long mul = magic >>> 32;
int result = (int)(((long)number * mul) >>> magic);
*/

int p = 31;

// all these variables are UNSIGNED!
Expand Down Expand Up @@ -135,7 +151,7 @@ public static long getDivisorNumbers(final int d) {
if (d < 0) {
magicNum = -magicNum;
}
int shift = p - 32;
int shift = p;
return ((long)magicNum << 32) | shift;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/dataconverter.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accessWidener v1 named

2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dataconverter.mixins.json"
],
"depends": {
"fabricloader": ">=0.14.6",
"fabricloader": ">=0.14.19",
"minecraft": "*"
}
}

0 comments on commit 5a0cefb

Please sign in to comment.