diff --git a/.gitignore b/.gitignore index 3c37caf..7a06e82 100644 --- a/.gitignore +++ b/.gitignore @@ -114,5 +114,7 @@ gradle-app.setting # Common working directory run/ +runs/ + # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar diff --git a/LICENSE b/LICENSE index d70a3dd..df1dd1f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,52 +1,13 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ +Copyright 2024 -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at -1. Definitions. +http://www.apache.org/licenses/LICENSE-2.0 -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - - You must give any other recipients of the Work or Derivative Works a copy of this License; and - You must cause any modified files to carry prominent notices stating that You changed the files; and - You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. - -You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/README.md b/README.md deleted file mode 100644 index eb9fa49..0000000 --- a/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# FastRandom -Source Code and issues for [Faster Random](https://modrinth.com/mod/faster-random) - -Requires a JVM that supports `RandomGenerator` and the LXM generators. Some JRE's don't support this. - -Licensed under Apache 2.0 diff --git a/build.gradle b/build.gradle index 072c21a..15129f3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,91 +1,141 @@ -//file:noinspection GroovyAccessibility -//file:noinspection GroovyAssignabilityCheck - plugins { - id 'fabric-loom' version '1.2-SNAPSHOT' + id 'java-library' + id 'eclipse' + id 'idea' id 'maven-publish' + id 'net.neoforged.gradle.userdev' version '7.0.74' } -version = project.mod_version -group = project.maven_group +version = mod_version +group = mod_group_id -runClient { - jvmArgs "-Dmixin.debug.export=true" +repositories { + mavenLocal() } -repositories { - // Add repositories to retrieve artifacts from in here. - // You should only use this when depending on other mods because - // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. - // See https://docs.gradle.org/current/userguide/declaring_repositories.html - // for more information about repositories. +base { + archivesName = mod_id } -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" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +java.toolchain.languageVersion = JavaLanguageVersion.of(17) - include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixin_extras_version}"))) -} +//minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg') +//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager + +// Default run configurations. +// These can be tweaked, removed, or duplicated as needed. +runs { + // applies to all the run configs below + configureEach { + // Recommended logging data for a userdev environment + // The markers can be added/remove as needed separated by commas. + // "SCAN": For mods scan. + // "REGISTRIES": For firing of registry events. + // "REGISTRYDUMP": For getting the contents of all registries. + systemProperty 'forge.logging.markers', 'REGISTRIES' -processResources { - inputs.property "version", project.version - inputs.property "minecraft_version", project.minecraft_version - inputs.property "loader_version", project.loader_version - filteringCharset "UTF-8" + // Recommended logging level for the console + // You can set various levels here. + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels + systemProperty 'forge.logging.console.level', 'debug' - filesMatching("fabric.mod.json") { - expand "version": project.version, - "minecraft_version": project.minecraft_version, - "loader_version": project.loader_version + modSource project.sourceSets.main } -} -def targetJavaVersion = 17 -tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. - it.options.encoding = "UTF-8" - if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { - it.options.release = targetJavaVersion + client { + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + } + + server { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id + programArgument '--nogui' } -} -java { - def javaVersion = JavaVersion.toVersion(targetJavaVersion) - if (JavaVersion.current() < javaVersion) { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + // This run config launches GameTestServer and runs all registered gametests, then exits. + // By default, the server will crash when no gametests are provided. + // The gametest system is also enabled by default for other run configs under the /test command. + gameTestServer { + systemProperty 'forge.enabledGameTestNamespaces', project.mod_id } - archivesBaseName = project.archives_base_name - // 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() + + data { + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it + // workingDirectory project.file('run-data') + + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() + } +} + +// Include resources generated by data generators. +sourceSets.main.resources { srcDir 'src/generated/resources' } + + +dependencies { + // Specify the version of Minecraft to use. + // Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above. + // The group for userdev is net.neoforge, the module name is neoforge, and the version is the same as the neoforge version. + // You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader. + // And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version. + // For all intends and purposes: You can treat this dependency as if it is a normal library you would use. + implementation "net.neoforged:neoforge:${neo_version}" + + // Example mod dependency with JEI + // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime + // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" + // compileOnly "mezz.jei:jei-${mc_version}-forge-api:${jei_version}" + // runtimeOnly "mezz.jei:jei-${mc_version}-forge:${jei_version}" + + // Example mod dependency using a mod jar from ./libs with a flat dir repository + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar + // The group id is ignored when searching -- in this case, it is "blank" + // implementation "blank:coolmod-${mc_version}:${coolmod_version}" + + // Example mod dependency using a file as dependency + // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") + + // Example project dependency using a sister or child project: + // implementation project(":myproject") + + // For more info: + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html + // http://www.gradle.org/docs/current/userguide/dependency_management.html } -jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}" } +// This block of code expands all declared replace properties in the specified resource targets. +// A missing property will result in an error. Properties are expanded using ${} Groovy notation. +// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments. +// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html +tasks.withType(ProcessResources).configureEach { + var replaceProperties = [ + minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, + neo_version : neo_version, neo_version_range: neo_version_range, + loader_version_range: loader_version_range, + mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, + mod_authors : mod_authors, mod_description: mod_description, + ] + inputs.properties replaceProperties + + filesMatching(['META-INF/mods.toml']) { + expand replaceProperties + [project: project] } } -// configure the maven publication +// Example configuration to allow publishing using the maven-publish plugin publishing { publications { - mavenJava(MavenPublication) { + register('mavenJava', MavenPublication) { 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. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. + maven { + url "file://${project.projectDir}/repo" + } } } + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation +} diff --git a/gradle.properties b/gradle.properties index 8afb824..46d8790 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,43 @@ -# Gradle settings -# Increase memory available to Gradle, enable parallelism, and enable caching -org.gradle.jvmargs=-Xmx1G -org.gradle.parallel=true -org.gradle.caching=true +# Sets default memory used for gradle commands. Can be overridden by user or command line properties. +org.gradle.jvmargs=-Xmx2G +org.gradle.daemon=false +org.gradle.debug=false -# Fabric properties -# Check these on https://modmuss50.me/fabric.html +## Environment Properties +# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge +# The Minecraft version must agree with the Neo version to get a valid artifact minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 -loader_version=0.15.1 -# Mod properties -mod_version=3.0.3 -maven_group=com.github.anopensaucedev -archives_base_name=fasterrandom +# The Minecraft version range can use any release version of Minecraft as bounds. +# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly +# as they do not follow standard versioning conventions. +minecraft_version_range=[1.19,1.21) +# The Neo version must agree with the Minecraft version to get a valid artifact +neo_version=20.4.223 +# The Neo version range can use any version of Neo as bounds +neo_version_range=[20,) +# The loader version range can only use the major version of FML as bounds +loader_version_range=[2,) + +# Uncomment this to activate parchment +#neogradle.subsystems.parchment.minecraftVersion=1.20.4 +#neogradle.subsystems.parchment.mappingsVersion=SET_ME -# Dependencies -mixin_extras_version=0.2.2 +## Mod Properties + +# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63} +# Must match the String constant located in the main mod class annotated with @Mod. +mod_id=faster_random_forge +# The human-readable display name for the mod. +mod_name=Faster Random: (Neo)Forge Edition +# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. +mod_license=Apache-2.0 +# The mod version. See https://semver.org/ +mod_version=3.0.3 +# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. +# This should match the base package used for the mod sources. +# See https://maven.apache.org/guides/mini/guide-naming-conventions.html +mod_group_id=com.github.anopensaucedev +# The authors of the mod. This is a simple text string that is used for display purposes in the mod list. +mod_authors=AnOpenSauceDev, Steveplays28 +# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list. +mod_description=An experimental NeoForge port of Faster Random. diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index c1962a7..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d..0564365 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip -networkTimeout=10000 -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip diff --git a/gradlew b/gradlew deleted file mode 100755 index aeb74cb..0000000 --- a/gradlew +++ /dev/null @@ -1,245 +0,0 @@ -#!/bin/sh - -# -# Copyright © 2015-2021 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. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -############################################################################## -# -# Gradle start up script for POSIX generated by Gradle. -# -# Important for running: -# -# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is -# noncompliant, but you have some other compliant shell such as ksh or -# bash, then to run this script, type that shell name before the whole -# command line, like: -# -# ksh Gradle -# -# Busybox and similar reduced shells will NOT work, because this script -# requires all of these POSIX shell features: -# * functions; -# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», -# «${var#prefix}», «${var%suffix}», and «$( cmd )»; -# * compound commands having a testable exit status, especially «case»; -# * various built-in commands including «command», «set», and «ulimit». -# -# Important for patching: -# -# (2) This script targets any POSIX shell, so it avoids extensions provided -# by Bash, Ksh, etc; in particular arrays are avoided. -# -# The "traditional" practice of packing multiple parameters into a -# space-separated string is a well documented source of bugs and security -# problems, so this is (mostly) avoided, by progressively accumulating -# options in "$@", and eventually passing that to Java. -# -# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, -# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; -# see the in-line comments for details. -# -# There are tweaks for specific operating systems such as AIX, CygWin, -# 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 -# within the Gradle project. -# -# You can find Gradle at https://github.com/gradle/gradle/. -# -############################################################################## - -# Attempt to set APP_HOME - -# Resolve links: $0 may be a link -app_path=$0 - -# Need this for daisy-chained symlinks. -while - APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path - [ -h "$app_path" ] -do - ls=$( ls -ld "$app_path" ) - link=${ls#*' -> '} - case $link in #( - /*) app_path=$link ;; #( - *) app_path=$APP_HOME$link ;; - esac -done - -# This is normally unused -# shellcheck disable=SC2034 -APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD=maximum - -warn () { - echo "$*" -} >&2 - -die () { - echo - echo "$*" - echo - exit 1 -} >&2 - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "$( uname )" in #( - CYGWIN* ) cygwin=true ;; #( - Darwin* ) darwin=true ;; #( - MSYS* | MINGW* ) msys=true ;; #( - NONSTOP* ) nonstop=true ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD=$JAVA_HOME/jre/sh/java - else - JAVACMD=$JAVA_HOME/bin/java - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then - case $MAX_FD in #( - max*) - # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - MAX_FD=$( ulimit -H -n ) || - warn "Could not query maximum file descriptor limit" - esac - case $MAX_FD in #( - '' | soft) :;; #( - *) - # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 - ulimit -n "$MAX_FD" || - warn "Could not set maximum file descriptor limit to $MAX_FD" - esac -fi - -# Collect all arguments for the java command, stacking in reverse order: -# * args from the command line -# * the main class name -# * -classpath -# * -D...appname settings -# * --module-path (only if needed) -# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. - -# 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" ) - - # Now convert the arguments - kludge to limit ourselves to /bin/sh - for arg do - if - case $arg in #( - -*) false ;; # don't mess with options #( - /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath - [ -e "$t" ] ;; #( - *) false ;; - esac - then - arg=$( cygpath --path --ignore --mixed "$arg" ) - fi - # Roll the args list around exactly as many times as the number of - # args, so each arg winds up back in the position where it started, but - # possibly modified. - # - # NB: a `for` loop captures its iteration list before it begins, so - # changing the positional parameters here affects neither the number of - # iterations, nor the values presented in `arg`. - shift # remove old arg - set -- "$@" "$arg" # push replacement arg - done -fi - - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' - -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. - -set -- \ - "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - 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. -# -# In Bash we could simply go: -# -# readarray ARGS < <( xargs -n1 <<<"$var" ) && -# set -- "${ARGS[@]}" "$@" -# -# but POSIX shell has neither arrays nor command substitution, so instead we -# post-process each arg (as a line of input to sed) to backslash-escape any -# character that might be a shell metacharacter, then use eval to reverse -# that process (while maintaining the separation between arguments), and wrap -# the whole thing up as a single "set" statement. -# -# This will of course break if any of these variables contains a newline or -# an unmatched quote. -# - -eval "set -- $( - printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | - xargs -n1 | - sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | - tr '\n' ' ' - )" '"$@"' - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index 6689b85..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,92 +0,0 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -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. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -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. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -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! -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 - -:omega diff --git a/settings.gradle b/settings.gradle index f91a4fe..b359a59 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,9 +1,11 @@ pluginManagement { repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } + mavenLocal() gradlePluginPortal() + maven { url = 'https://maven.neoforged.net/releases' } } } + +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' +} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandom/FasterRandom.java b/src/main/java/com/github/anopensaucedev/fasterrandom/FasterRandom.java deleted file mode 100644 index 8123617..0000000 --- a/src/main/java/com/github/anopensaucedev/fasterrandom/FasterRandom.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.github.anopensaucedev.fasterrandom; - -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.util.math.random.Random; -import net.minecraft.util.math.random.RandomSeed; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.concurrent.ThreadLocalRandom; -import java.util.random.RandomGenerator; -import java.util.random.RandomGeneratorFactory; - -public class FasterRandom implements ModInitializer { - public static final String MOD_ID = "faster-random"; - - - public static final String MOD_VERSION = FabricLoader.getInstance().getModContainer(MOD_ID).get().getMetadata().getVersion().getFriendlyString(); - public static final String MOD_NAME = "Faster Random"; - public static final Logger LOGGER = LoggerFactory.getLogger(MOD_NAME); - public static final RandomGeneratorFactory RANDOM_GENERATOR_FACTORY = RandomGeneratorFactory.of( - "L64X128MixRandom"); - - @Override - public void onInitialize() { - LOGGER.info("{} {} has loaded! \\0_0/", MOD_NAME,MOD_VERSION); - LOGGER.warn( - "While terrain generation will \"function\" properly, cave generation will have a different seed (in singleplayer / if this mod is on the server), which may or may not be noticeable. Keep this in mind."); - LOGGER.warn("If you have any terrain-related issues, make sure to mention me (AnOpenSauceDev) in an issue just to be sure!"); - LOGGER.info("Faster Random Issue Tracker: https://github.com/AnOpenSauceDev/FastRandom/issues"); - - - //run random benchmarks - if(FabricLoader.getInstance().isDevelopmentEnvironment()){ - //LegacyBenchmark(); // older benchmark from Methane, where CheckedRandom is 100x slower than Threadlocal? - //RandBench.StartBenchmark(); - } - - } - - // I have absolutely no idea why it's slower in this case. - public static void LegacyBenchmark(){ - - int iterations = 1000000000; - - ThreadLocalRandom random = ThreadLocalRandom.current(); - - long time = System.nanoTime(); - - for(int x = 0; x < iterations; x++ ){ - random.nextFloat(); - } - - long finaltime = System.nanoTime() - time; - - LOGGER.info("Random Benchmark Results (ThreadLocal): " + RandBench.toSeconds(finaltime)); - - Random random2 = Random.create(RandomSeed.getSeed()); //seeded or not, this is always slower - - long time2 = System.nanoTime(); - - for(int x = 0; x < iterations; x++ ){ - random2.nextFloat(); - } - - - long finaltime2 = System.nanoTime() - time2; - - LOGGER.info("Random Benchmark Results (Random): " + RandBench.toSeconds(finaltime2)); - - if(finaltime < finaltime2){ - LOGGER.info("ThreadLocal was faster!"); - } - - } -} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandom/FasterRandomPrelaunch.java b/src/main/java/com/github/anopensaucedev/fasterrandom/FasterRandomPrelaunch.java deleted file mode 100644 index 88f4a0f..0000000 --- a/src/main/java/com/github/anopensaucedev/fasterrandom/FasterRandomPrelaunch.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.anopensaucedev.fasterrandom; - -import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FasterRandomPrelaunch implements PreLaunchEntrypoint { - - public static Logger logger = LoggerFactory.getLogger("Faster Random Prelaunch"); - - public static final String SYSTEM_PROPERTY_JVM_STRING = "java.vm.vendor"; - - @Override - public void onPreLaunch() { - - logger.info("preparing to launch Faster Random!"); - logger.warn("If Minecraft crashes past this point, your JVM is not supported."); - FasterRandom.RANDOM_GENERATOR_FACTORY.create(); - logger.info("Your JVM seems to be supported!"); - - } - -} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandom/RandBench.java b/src/main/java/com/github/anopensaucedev/fasterrandom/RandBench.java deleted file mode 100644 index b870052..0000000 --- a/src/main/java/com/github/anopensaucedev/fasterrandom/RandBench.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.github.anopensaucedev.fasterrandom; - -import net.minecraft.util.math.random.CheckedRandom; -import net.minecraft.util.math.random.RandomSeed; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Random; -import java.util.concurrent.ThreadLocalRandom; - -// random number generation benchmarking -public class RandBench { - - private static Logger benchmarkLogger = LoggerFactory.getLogger("Faster Random RandBench"); - - private static CheckedRandom vanillaRandom = new CheckedRandom(RandomSeed.getSeed()); - private static Random oldRandom = new Random(RandomSeed.getSeed()); - - private static final int ITERATIONS = 100_000_000; // stress testing! Lower when actual development needs to happen - - private static ArrayList values = new ArrayList<>(); - private static final String[] generatorNames = {"vanilla","java.util.random","ThreadLocalRandom","LXM"}; // generator names in order - - public static void StartBenchmark(){ - benchmarkLogger.info("Starting Random benchmark!"); - - // Vanilla random - benchmarkLogger.info("Vanilla benchmark"); - var vanillaStart = System.nanoTime(); - for (int i = 0; i < ITERATIONS; i++) { - vanillaRandom.nextFloat(); - vanillaRandom.nextInt(); - vanillaRandom.nextDouble(); - vanillaRandom.nextGaussian(); - vanillaRandom.nextLong(); - vanillaRandom.nextBoolean(); - } - var vanillaFinish = toSeconds(System.nanoTime() - vanillaStart); - benchmarkLogger.info("Vanilla benchmark time: {}s, mean: {}s",vanillaFinish, (float) (vanillaFinish/ITERATIONS)); - values.add(vanillaFinish); //0 - - // Java.util.random - benchmarkLogger.info("java.util.random"); - var oldRandomStart = System.nanoTime(); - for (int i = 0; i < ITERATIONS; i++) { - oldRandom.nextFloat(); - oldRandom.nextInt(); - oldRandom.nextDouble(); - oldRandom.nextGaussian(); - oldRandom.nextLong(); - oldRandom.nextBoolean(); - } - var oldRandomFinish = toSeconds(System.nanoTime() - oldRandomStart); - benchmarkLogger.info("java.util.random time: {}s, mean: {}s",oldRandomFinish,(float) (oldRandomFinish/ITERATIONS)); - values.add(oldRandomFinish); //1 - - // ThreadLocalRandom ("100X faster" than the old CheckedRandom) - //TODO: add old CheckedRandom impl as a benchmark too. - benchmarkLogger.info("ThreadLocalRandom"); - var threadLocalRandom = ThreadLocalRandom.current(); - var threadLocalStart = System.nanoTime(); - for (int i = 0; i < ITERATIONS; i++) { - threadLocalRandom.nextFloat(); - threadLocalRandom.nextInt(); - threadLocalRandom.nextDouble(); - threadLocalRandom.nextGaussian(); - threadLocalRandom.nextLong(); - threadLocalRandom.nextBoolean(); - } - var threadLocalFinish = toSeconds(System.nanoTime() - threadLocalStart); - benchmarkLogger.info("ThreadLocalRandom time: {}s, mean: {}s",threadLocalFinish,(float) (threadLocalFinish/ITERATIONS)); - values.add(threadLocalFinish); // 2 - - // LXM random - benchmarkLogger.info("LXM"); - var generator = FasterRandom.RANDOM_GENERATOR_FACTORY.create(); - var lxmStart = System.nanoTime(); - for (int i = 0; i < ITERATIONS; i++) { - generator.nextFloat(); - generator.nextInt(); - generator.nextDouble(); - generator.nextGaussian(); - generator.nextLong(); - generator.nextBoolean(); - } - var lxmFinish = toSeconds(System.nanoTime() - lxmStart); - benchmarkLogger.info("LXM Time: {}s, mean: {}s",lxmFinish,(float) (lxmFinish/ITERATIONS)); - values.add(lxmFinish); // 3 - - benchmarkLogger.info("overall winner: {}s, from random generator: {}",Collections.min(values),generatorNames[values.indexOf(Collections.min(values))]); - - } - - public static double toSeconds(double value){ - return (value / 1e9); - } - -} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandom/mixin/ChunkRandomMixin.java b/src/main/java/com/github/anopensaucedev/fasterrandom/mixin/ChunkRandomMixin.java deleted file mode 100644 index a61299a..0000000 --- a/src/main/java/com/github/anopensaucedev/fasterrandom/mixin/ChunkRandomMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.anopensaucedev.fasterrandom.mixin; - -import net.minecraft.util.math.random.CheckedRandom; -import net.minecraft.util.math.random.ChunkRandom; -import net.minecraft.util.math.random.Random; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Mutable; -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; - -@Mixin(ChunkRandom.class) -public class ChunkRandomMixin { - - @Mutable - @Shadow - @Final - private Random baseRandom; - - @Inject(method = "(Lnet/minecraft/util/math/random/Random;)V",at = @At("RETURN")) - private void fasterrandom$fixBetterX(Random baseRandom, CallbackInfo ci){ - this.baseRandom = new CheckedRandom(0); - } - - -} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandom/mixin/RandomMixin.java b/src/main/java/com/github/anopensaucedev/fasterrandom/mixin/RandomMixin.java deleted file mode 100644 index 3218f05..0000000 --- a/src/main/java/com/github/anopensaucedev/fasterrandom/mixin/RandomMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.anopensaucedev.fasterrandom.mixin; - -import com.github.anopensaucedev.fasterrandom.RandomGeneratorRandom; -import net.minecraft.util.math.random.Random; -import net.minecraft.util.math.random.RandomSeed; -import org.jetbrains.annotations.NotNull; -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(Random.class) -public interface RandomMixin { - @Inject(method = "create(J)Lnet/minecraft/util/math/random/Random;", at = @At(value = "HEAD"), cancellable = true) - private static void fasterrandom$createInject(long seed, @NotNull CallbackInfoReturnable cir) { - cir.setReturnValue(new RandomGeneratorRandom(seed)); - } - - @Inject(method = "createLocal", at = @At(value = "HEAD"), cancellable = true) - private static void fasterrandom$createLocalInject(@NotNull CallbackInfoReturnable cir) { - cir.setReturnValue(new RandomGeneratorRandom(RandomSeed.getSeed())); - } - - @Inject(method = "createThreadSafe", at = @At(value = "HEAD"), cancellable = true) - private static void fasterrandom$createThreadSafeInject(@NotNull CallbackInfoReturnable cir) { - cir.setReturnValue(new RandomGeneratorRandom(RandomSeed.getSeed())); - } -} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandomforge/FasterRandomForge.java b/src/main/java/com/github/anopensaucedev/fasterrandomforge/FasterRandomForge.java new file mode 100644 index 0000000..6acbf54 --- /dev/null +++ b/src/main/java/com/github/anopensaucedev/fasterrandomforge/FasterRandomForge.java @@ -0,0 +1,59 @@ +package com.github.anopensaucedev.fasterrandomforge; + +import com.mojang.logging.LogUtils; +import net.minecraft.client.Minecraft; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.CreativeModeTabs; +import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.material.MapColor; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.ModLoadingContext; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; +import net.neoforged.neoforge.event.server.ServerStartingEvent; +import net.neoforged.neoforge.registries.DeferredBlock; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredItem; +import net.neoforged.neoforge.registries.DeferredRegister; +import org.slf4j.Logger; + +import java.util.random.RandomGenerator; +import java.util.random.RandomGeneratorFactory; + +// The value here should match an entry in the META-INF/mods.toml file +@Mod(FasterRandomForge.MODID) +public class FasterRandomForge +{ + public static final RandomGeneratorFactory RANDOM_GENERATOR_FACTORY = RandomGeneratorFactory.of( + "L64X128MixRandom"); + + // Define mod id in a common place for everything to reference + public static final String MODID = "faster_random_forge"; + // Directly reference a slf4j logger + private static final Logger LOGGER = LogUtils.getLogger(); + + + // The constructor for the mod class is the first code that is run when your mod is loaded. + // FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically. + public FasterRandomForge(IEventBus modEventBus) + { + + LOGGER.info("Faster Random has loaded!"); + + } + + +} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandom/RandomGeneratorRandom.java b/src/main/java/com/github/anopensaucedev/fasterrandomforge/RandomGeneratorRandom.java similarity index 74% rename from src/main/java/com/github/anopensaucedev/fasterrandom/RandomGeneratorRandom.java rename to src/main/java/com/github/anopensaucedev/fasterrandomforge/RandomGeneratorRandom.java index 2e28e22..c152e4a 100644 --- a/src/main/java/com/github/anopensaucedev/fasterrandom/RandomGeneratorRandom.java +++ b/src/main/java/com/github/anopensaucedev/fasterrandomforge/RandomGeneratorRandom.java @@ -1,12 +1,14 @@ -package com.github.anopensaucedev.fasterrandom; +package com.github.anopensaucedev.fasterrandomforge; -import net.minecraft.util.math.random.*; +import net.minecraft.world.level.levelgen.BitRandomSource; +import net.minecraft.world.level.levelgen.LegacyRandomSource; +import net.minecraft.world.level.levelgen.PositionalRandomFactory; import java.util.random.RandomGenerator; -import static com.github.anopensaucedev.fasterrandom.FasterRandom.RANDOM_GENERATOR_FACTORY; +import static com.github.anopensaucedev.fasterrandomforge.FasterRandomForge.RANDOM_GENERATOR_FACTORY; -public class RandomGeneratorRandom implements BaseRandom { +public class RandomGeneratorRandom implements BitRandomSource { private static final int INT_BITS = 48; private static final long SEED_MASK = 0xFFFFFFFFFFFFL; private static final long MULTIPLIER = 25214903917L; @@ -26,14 +28,14 @@ public RandomGeneratorRandom(long seed, RandomGenerator.SplittableGenerator rand } @Override - public Random split() { + public BitRandomSource fork() { return new RandomGeneratorRandom(seed, randomGenerator.split()); } @Override - public RandomSplitter nextSplitter() { + public PositionalRandomFactory forkPositional() { // TODO: Should this use this.seed instead of nextLong()? - return new CheckedRandom.Splitter(nextLong()); + return new LegacyRandomSource.LegacyPositionalRandomFactory(nextLong()); } @Override diff --git a/src/main/java/com/github/anopensaucedev/fasterrandomforge/mixin/ChunkRandomMixin.java b/src/main/java/com/github/anopensaucedev/fasterrandomforge/mixin/ChunkRandomMixin.java new file mode 100644 index 0000000..1ac817f --- /dev/null +++ b/src/main/java/com/github/anopensaucedev/fasterrandomforge/mixin/ChunkRandomMixin.java @@ -0,0 +1,30 @@ +package com.github.anopensaucedev.fasterrandomforge.mixin; + +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.levelgen.LegacyRandomSource; +import net.minecraft.world.level.levelgen.WorldgenRandom; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +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; + +import java.util.Random; + +@Mixin(WorldgenRandom.class) +public class ChunkRandomMixin { + + @Mutable + @Shadow + @Final + private RandomSource randomSource; + + @Inject(method = "",at = @At("RETURN")) + private void fasterrandom$fixBetterX(RandomSource p_224680_, CallbackInfo ci){ + this.randomSource = new LegacyRandomSource(0); + } + + +} diff --git a/src/main/java/com/github/anopensaucedev/fasterrandomforge/mixin/RandomMixin.java b/src/main/java/com/github/anopensaucedev/fasterrandomforge/mixin/RandomMixin.java new file mode 100644 index 0000000..8c8b93a --- /dev/null +++ b/src/main/java/com/github/anopensaucedev/fasterrandomforge/mixin/RandomMixin.java @@ -0,0 +1,29 @@ +package com.github.anopensaucedev.fasterrandomforge.mixin; + +import com.github.anopensaucedev.fasterrandomforge.RandomGeneratorRandom; +import net.minecraft.util.RandomSource; +import net.minecraft.world.level.levelgen.RandomSupport; +import org.jetbrains.annotations.NotNull; +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(RandomSource.class) +public interface RandomMixin { + @Inject(method = "create(J)Lnet/minecraft/util/RandomSource;", at = @At(value = "HEAD"), cancellable = true) + private static void fasterrandom$createInject(long seed, @NotNull CallbackInfoReturnable cir) { + cir.setReturnValue(new RandomGeneratorRandom(seed)); + } + + @Inject(method = "createNewThreadLocalInstance", at = @At(value = "HEAD"), cancellable = true) + private static void fasterrandom$createLocalInject(@NotNull CallbackInfoReturnable cir) { + cir.setReturnValue(new RandomGeneratorRandom(RandomSupport.generateUniqueSeed())); + } + + @Inject(method = "createThreadSafe", at = @At(value = "HEAD"), cancellable = true) + private static void fasterrandom$createThreadSafeInject(@NotNull CallbackInfoReturnable cir) { + cir.setReturnValue(new RandomGeneratorRandom(RandomSupport.generateUniqueSeed())); + } +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..d25bb8d --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,64 @@ +# This is an example mods.toml file. It contains the data relating to the loading mods. +# There are several mandatory fields (#mandatory), and many more that are optional (#optional). +# The overall format is standard TOML format, v0.5.0. +# Note that there are a couple of TOML lists in this file. +# Find more information on toml format here: https://github.com/toml-lang/toml +# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml +modLoader="javafml" #mandatory +# A version range to match for said mod loader - for regular FML @Mod it will be the the FML version. This is currently 47. +loaderVersion="${loader_version_range}" #mandatory +# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. +# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. +license="${mod_license}" +# A URL to refer people to when problems occur with this mod +issueTrackerURL="https://github.com/AnOpenSauceDev/FastRandom/issues" #optional +# A list of mods - how many allowed here is determined by the individual mod loader +[[mods]] #mandatory +# The modid of the mod +modId="${mod_id}" #mandatory + +# The description text for the mod (multi line!) (#mandatory) +description='''${mod_description}''' + +# The version number of the mod +version="${mod_version}" #mandatory +# A display name for the mod +displayName="${mod_name}" #mandatory +# A URL to query for updates for this mod. See the JSON update specification https://docs.neoforge.net/docs/misc/updatechecker/ +#updateJSONURL="https://change.me.example.invalid/updates.json" #optional +# A URL for the "homepage" for this mod, displayed in the mod UI +#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional +# A file name (in the root of the mod JAR) containing a logo for display +#logoFile="fasterrandomforge.png" #optional +# A text field displayed in the mod UI +#credits="" #optional +# A text field displayed in the mod UI +authors="${mod_authors}" #optional +# Display Test controls the display for your mod in the server connection screen +# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod. +# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod. +# IGNORE_ALL_VERSION means that your mod will not cause a red X if it's present on the client or the server. This is a special case and should only be used if your mod has no server component. +# NONE means that no display test is set on your mod. You need to do this yourself, see IExtensionPoint.DisplayTest for more information. You can define any scheme you wish with this value. +# IMPORTANT NOTE: this is NOT an instruction as to which environments (CLIENT or DEDICATED SERVER) your mod loads on. Your mod should load (and maybe do nothing!) whereever it finds itself. +#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional) + +[[mixins]] +config="fasterrandomforge.mixins.json" + + +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. + +[[dependencies."${mod_id}"]] +modId="minecraft" +type="required" +mandatory=true +# This version range declares a minimum of the current minecraft version up to but not including the next major version +versionRange="${minecraft_version_range}" +ordering="NONE" +side="BOTH" + +# Features are specific properties of the game environment, that you may want to declare you require. This example declares +# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't +# stop your mod loading on the server for example. +#[features."${mod_id}"] +#openGLVersion="[3.2,)" diff --git a/src/main/resources/assets/fasterrandom/icon.png b/src/main/resources/assets/fasterrandom/icon.png deleted file mode 100644 index 733a32b..0000000 Binary files a/src/main/resources/assets/fasterrandom/icon.png and /dev/null differ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json deleted file mode 100644 index 7c181b9..0000000 --- a/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "schemaVersion": 1, - "id": "faster-random", - "version": "${version}", - "name": "Faster Random", - "description": "Makes your game randomly faster!", - "authors": ["AnOpenSauceDev"], - "contact": { - "repo": "https://github.com/AnOpenSauceDev/FastRandom" - }, - "license": "Apache-2.0", - "icon": "assets/fasterrandom/icon.png", - "environment": "*", - "entrypoints": { - "main": [ - "com.github.anopensaucedev.fasterrandom.FasterRandom" - ], - "preLaunch": [ - "com.github.anopensaucedev.fasterrandom.FasterRandomPrelaunch" - ] - }, - "mixins": [ - "fasterrandom.mixins.json" - ], - "depends": { - "fabricloader": ">=${loader_version}", - "minecraft": ">=1.19" - } -} diff --git a/src/main/resources/fasterrandom.mixins.json b/src/main/resources/fasterrandom.mixins.json deleted file mode 100644 index 49bde5d..0000000 --- a/src/main/resources/fasterrandom.mixins.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "com.github.anopensaucedev.fasterrandom.mixin", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "ChunkRandomMixin", - "RandomMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} diff --git a/src/main/resources/fasterrandomforge.mixins.json b/src/main/resources/fasterrandomforge.mixins.json new file mode 100644 index 0000000..c42e1b5 --- /dev/null +++ b/src/main/resources/fasterrandomforge.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "com.github.anopensaucedev.fasterrandomforge.mixin", + "compatibilityLevel": "JAVA_8", + "refmap": "FasterRandomForge.refmap.json", + "mixins": [ + "ChunkRandomMixin", + "RandomMixin" + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/pack.mcmeta b/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..f0e613a --- /dev/null +++ b/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "faster random forge resources", + "pack_format": 26 + } +} diff --git a/stats.png b/stats.png deleted file mode 100644 index 14ed3a2..0000000 Binary files a/stats.png and /dev/null differ