Skip to content

Commit

Permalink
Merge branch 'forge-1.20.1' of github.com:JDKDigital/InvTweaksRefoxed…
Browse files Browse the repository at this point in the history
… into neoforge-1.20.6

# Conflicts:
#	build.gradle
#	gradle.properties
#	src/main/java/invtweaks/config/InvTweaksConfig.java
#	src/main/java/invtweaks/events/ClientEvents.java
#	src/main/java/invtweaks/events/ServerEvents.java
#	src/main/java/invtweaks/network/PacketSortInv.java
#	src/main/java/invtweaks/network/PacketUpdateConfig.java
#	src/main/java/invtweaks/util/Sorting.java
#	src/main/resources/META-INF/accesstransformer.cfg
#	src/main/resources/META-INF/mods.toml
  • Loading branch information
JaisDK committed May 7, 2024
2 parents 2213b99 + f17c34a commit ca2146d
Show file tree
Hide file tree
Showing 27 changed files with 647 additions and 606 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Java CI with Gradle

on:
push:
branches: [ main ]
branches: [ forge-1.20.1 ]
pull_request:
types: [ opened, synchronize, reopened ]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
java-version: '21x'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
Expand Down
41 changes: 19 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,13 @@ plugins {
id 'idea'
id 'maven-publish'
id 'org.gradle.crypto.checksum' version '1.4.0'
id 'net.neoforged.gradle.userdev' version '7.0.80'
id 'net.neoforged.gradle.userdev' version '7.0.105'
}

// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
java.toolchain.languageVersion = JavaLanguageVersion.of(21)

minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg')

repositories {
mavenLocal()
exclusiveContent {
forRepository {
maven {
name "CurseMaven"
url "https://www.cursemaven.com"
}
}
filter {
includeGroup "curse.maven"
}
}
}

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
// applies to all the run configs below
configureEach {
Expand Down Expand Up @@ -79,7 +61,22 @@ sourceSets.main.resources { srcDir 'src/generated/resources' }
dependencies {
implementation "net.neoforged:neoforge:${neo_version}"

implementation "curse.maven:jei-238222:5101381"
// implementation "curse.maven:jei-238222:5101381"
}

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_credits: mod_credits, mod_description: mod_description,
]
inputs.properties replaceProperties

filesMatching(['META-INF/neoforge.mods.toml']) {
expand replaceProperties + [project: project]
}
}

// Example for how to get properties into the manifest for reading at runtime.
Expand All @@ -88,7 +85,7 @@ tasks.named('jar', Jar).configure {
manifest {
attributes([
"Specification-Title" : mod_id,
"Specification-Vendor" : group,
"Specification-Vendor" : mod_group_id,
"Specification-Version" : "1", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
Expand Down
47 changes: 40 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,47 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

neogradle.subsystems.parchment.minecraftVersion=1.20.3
neogradle.subsystems.parchment.mappingsVersion=2023.12.31
#neogradle.subsystems.parchment.minecraftVersion=1.20.6
#neogradle.subsystems.parchment.mappingsVersion=2023.12.31

minecraft_version=1.20.4
neo_version=20.4.80-beta
minecraft_version=1.20.6
neo_version=20.6.43-beta
mapping_channel=official
mapping_version=1.20.4
mapping_version=1.20.6

group=invtweaks
## 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.6
# 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.20.6,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.6.42-beta
# The Neo version range can use any version of Neo as bounds
neo_version_range=[20.6,)
# The loader version range can only use the major version of FML as bounds
loader_version_range=[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=invtweaks
version=1.0.0
# The human-readable display name for the mod.
mod_name=Inventory Tweaks Refoxed
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=Apache License, Version 2.0
# The mod version. See https://semver.org/
mod_version=1.20.6-1.0.0
# 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=invtweaks
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=LobsterJonn (Current maintainer)
mod_credits=MutantGumdrop (Porting to modern), Yuitakaa (Maintainer), StanleyMines (Contributor), Landmaster (Original Author), JimeoWan, Kobata for the original 1.12.2 mod
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Inventory Tweaks, but for modern versions of Minecraft.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
29 changes: 17 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# 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"'
# 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

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,26 +131,29 @@ 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.
if ! command -v java >/dev/null 2>&1
then
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
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
# shellcheck disable=SC2039,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
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -197,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# 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.

# 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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,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 +57,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
6 changes: 5 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ pluginManagement {
mavenLocal()
gradlePluginPortal()
maven { url = 'https://maven.neoforged.net/releases' }
maven {
name = 'ParchmentMC'
url = 'https://maven.parchmentmc.org'
}
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}

rootProject.name = mod_id
7 changes: 4 additions & 3 deletions src/main/java/invtweaks/InvTweaksMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import invtweaks.config.InvTweaksConfig;
import invtweaks.network.NetworkDispatcher;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.config.ModConfig;
Expand All @@ -15,9 +17,8 @@ public class InvTweaksMod {
public static final String MODID = "invtweaks";
public static final Logger LOGGER = LogManager.getLogger(InvTweaksMod.MODID);

@SuppressWarnings("java:S1118")
public InvTweaksMod() {
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, InvTweaksConfig.CLIENT_CONFIG);
public InvTweaksMod(IEventBus modEventBus, ModContainer modContainer) {
modContainer.registerConfig(ModConfig.Type.CLIENT, InvTweaksConfig.CLIENT_CONFIG);

InvTweaksConfig.loadConfig(InvTweaksConfig.CLIENT_CONFIG, FMLPaths.CONFIGDIR.get().resolve("invtweaks-client.toml"));
}
Expand Down
90 changes: 90 additions & 0 deletions src/main/java/invtweaks/config/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package invtweaks.config;

import com.electronwill.nightconfig.core.CommentedConfig;
import invtweaks.InvTweaksMod;
import net.minecraft.ResourceLocationException;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;

import java.util.*;
import java.util.function.Predicate;
import java.util.stream.IntStream;

public class Category {
private final List<String> spec;
private final List<List<Predicate<ItemStack>>> compiledSpec = new ArrayList<>();

public Category(List<String> spec) {
this.spec = spec;
for (String subspec : spec) {
List<Predicate<ItemStack>> compiledSubspec = new ArrayList<>();
for (String clause : subspec.split("\\s*;\\s*")) {
compileClause(clause).ifPresent(compiledSubspec::add);
}
compiledSpec.add(compiledSubspec);
}
}

public Category(String... spec) {
this(Arrays.asList(spec));
}

private static Optional<Predicate<ItemStack>> compileClause(String clause) {
if (clause.startsWith("!")) {
return compileClause(clause.substring(1)).map(Predicate::negate);
}

String[] parts = clause.split(":", 2);
if (parts[0].equals("/tag")) {
TagKey<Item> itemKey = TagKey.create(BuiltInRegistries.ITEM.key(), new ResourceLocation(parts[1]));
TagKey<Block> blockKey = TagKey.create(BuiltInRegistries.BLOCK.key(), new ResourceLocation(parts[1]));

return Optional.of(stack -> stack.is(itemKey) || (
stack.getItem() instanceof BlockItem blockItem
&& blockItem.getBlock().defaultBlockState().is(blockKey))
);
} else if (parts[0].equals("/instanceof") || parts[0].equals("/class")) { // use this for e.g. pickaxes
try {
Class<?> clazz = Class.forName(parts[1]);
if (parts[0].equals("/instanceof")) {
return Optional.of(st -> clazz.isInstance(st.getItem()));
} else {
return Optional.of(st -> st.getItem().getClass().equals(clazz));
}
} catch (ClassNotFoundException e) {
InvTweaksMod.LOGGER.warn("Class not found! Ignoring clause");
return Optional.empty();
}
} else if (parts[0].equals("/isFood")) {
return Optional.of(stack -> stack.getFoodProperties(null) != null);
} else { // default to standard item checking
try {
return Optional.of(
st -> Objects.equals(BuiltInRegistries.ITEM.getKey(st.getItem()), new ResourceLocation(clause)));
} catch (ResourceLocationException e) {
InvTweaksMod.LOGGER.warn("Invalid item resource location found.");
return Optional.empty();
}
}
}

// returns an index for sorting within a category
public int checkStack(ItemStack stack) {
return IntStream.range(0, compiledSpec.size())
.filter(idx -> compiledSpec.get(idx).stream().allMatch(pr -> pr.test(stack)))
.findFirst()
.orElse(-1);
}

public CommentedConfig toConfig(String catName) {
CommentedConfig result = CommentedConfig.inMemory();
result.set("name", catName);
result.set("spec", spec);
return result;
}
}
Loading

0 comments on commit ca2146d

Please sign in to comment.