From 94c258a4c910ffe39e6ca3c09ec3ff492713f0c1 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Tue, 10 Dec 2024 01:26:36 +0800 Subject: [PATCH] Update loom (and gradle), create basic recipes when there are too many possible combinations, update adapters --- .../kotlin/geyser.base-conventions.gradle.kts | 4 +- .../java/JavaRecipeBookAddTranslator.java | 67 +++++++++++++++++-- gradle.properties | 3 - gradle/libs.versions.toml | 4 +- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 2 +- 6 files changed, 68 insertions(+), 14 deletions(-) diff --git a/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts b/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts index 093f0a8c0..045015fe1 100644 --- a/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/geyser.base-conventions.gradle.kts @@ -26,8 +26,6 @@ dependencies { } repositories { - // mavenLocal() - mavenCentral() // Floodgate, Cumulus etc. @@ -69,4 +67,6 @@ repositories { // For Adventure snapshots maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") + + //mavenLocal() } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java index 96c5951d5..8e83c9f55 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaRecipeBookAddTranslator.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.protocol.java; import com.google.common.collect.Lists; import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.IntComparators; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.kyori.adventure.key.Key; import org.checkerframework.checker.nullness.qual.Nullable; @@ -75,12 +76,14 @@ import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.Clientbound import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; @Translator(packet = ClientboundRecipeBookAddPacket.class) public class JavaRecipeBookAddTranslator extends PacketTranslator { @@ -386,10 +389,64 @@ public class JavaRecipeBookAddTranslator extends PacketTranslator descriptors.get(0)).toList()), - output - ); + + int totalSimpleRecipes = inputs.stream().mapToInt(List::size).max().orElse(1); + + // Sort inputs to create "uniform" simple recipes, if possible + inputs = inputs.stream() + .map(descriptors -> descriptors.stream() + .sorted(ItemDescriptorWithCountComparator.INSTANCE) + .collect(Collectors.toList())) + .collect(Collectors.toList()); + + List> finalRecipes = new ArrayList<>(totalSimpleRecipes); + for (int i = 0; i < totalSimpleRecipes; i++) { + int current = i; + finalRecipes.add(inputs.stream().map(descriptors -> { + if (descriptors.size() > current) { + return descriptors.get(current); + } + return descriptors.get(0); + }).toList()); + } + + return Pair.of(finalRecipes, output); + } + + static class ItemDescriptorWithCountComparator implements Comparator { + + static ItemDescriptorWithCountComparator INSTANCE = new ItemDescriptorWithCountComparator(); + + @Override + public int compare(ItemDescriptorWithCount o1, ItemDescriptorWithCount o2) { + String tag1 = null, tag2 = null; + + // Collect item tags first + if (o1.getDescriptor() instanceof ItemTagDescriptor itemTagDescriptor) { + tag1 = itemTagDescriptor.getItemTag(); + } + + if (o2.getDescriptor() instanceof ItemTagDescriptor itemTagDescriptor) { + tag2 = itemTagDescriptor.getItemTag(); + } + + if (tag1 != null || tag2 != null) { + if (tag1 != null && tag2 != null) { + return tag1.compareTo(tag2); // Just sort based on their string id + } + + if (tag1 != null) { + return -1; + } + + return 1; // the second is an item tag; which should be r + } + + if (o1.getDescriptor() instanceof DefaultDescriptor defaultDescriptor1 && o2.getDescriptor() instanceof DefaultDescriptor defaultDescriptor2) { + return IntComparators.NATURAL_COMPARATOR.compare(defaultDescriptor1.getItemId().getRuntimeId(), defaultDescriptor2.getItemId().getRuntimeId()); + } + + throw new IllegalStateException("Unable to compare unknown item descriptors: " + o1 + " and " + o2); + } } } diff --git a/gradle.properties b/gradle.properties index 473c104f4..c380ec371 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,9 +6,6 @@ org.gradle.parallel=true org.gradle.caching=true org.gradle.vfs.watch=false -# TODO remove once architectury loom updates to 1.8 -loom.ignoreDependencyLoomVersionValidation=true - group=org.geysermc id=geyser version=2.6.0-SNAPSHOT diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 686064926..1166bab35 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ jline = "3.21.0" terminalconsoleappender = "1.2.0" folia = "1.19.4-R0.1-SNAPSHOT" viaversion = "4.9.2" -adapters = "1.15-SNAPSHOT" +adapters = "1.16-SNAPSHOT" cloud = "2.0.0-rc.2" cloud-minecraft = "2.0.0-beta.9" cloud-minecraft-modded = "2.0.0-beta.10" @@ -46,7 +46,7 @@ mockito = "5.+" indra = "3.1.3" shadow = "8.1.1" architectury-plugin = "3.4-SNAPSHOT" -architectury-loom = "1.7-SNAPSHOT" +architectury-loom = "1.9-SNAPSHOT" minotaur = "2.8.7" lombok = "8.4" blossom = "2.1.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a4413138c..94113f200 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 1aa94a426..b740cf133 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/.