Update loom (and gradle), create basic recipes when there are too many possible combinations, update adapters

This commit is contained in:
onebeastchris 2024-12-10 01:26:36 +08:00
parent 1210639087
commit 94c258a4c9
6 changed files with 68 additions and 14 deletions

View file

@ -26,8 +26,6 @@ dependencies {
} }
repositories { repositories {
// mavenLocal()
mavenCentral() mavenCentral()
// Floodgate, Cumulus etc. // Floodgate, Cumulus etc.
@ -69,4 +67,6 @@ repositories {
// For Adventure snapshots // For Adventure snapshots
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
//mavenLocal()
} }

View file

@ -28,6 +28,7 @@ package org.geysermc.geyser.translator.protocol.java;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.IntComparators;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.Nullable; 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.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@Translator(packet = ClientboundRecipeBookAddPacket.class) @Translator(packet = ClientboundRecipeBookAddPacket.class)
public class JavaRecipeBookAddTranslator extends PacketTranslator<ClientboundRecipeBookAddPacket> { public class JavaRecipeBookAddTranslator extends PacketTranslator<ClientboundRecipeBookAddPacket> {
@ -386,10 +389,64 @@ public class JavaRecipeBookAddTranslator extends PacketTranslator<ClientboundRec
return Pair.of(Lists.cartesianProduct(inputs), output); return Pair.of(Lists.cartesianProduct(inputs), output);
} }
} }
// TODO:
return Pair.of( int totalSimpleRecipes = inputs.stream().mapToInt(List::size).max().orElse(1);
Collections.singletonList(inputs.stream().map(descriptors -> descriptors.get(0)).toList()),
output // 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<List<ItemDescriptorWithCount>> 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<ItemDescriptorWithCount> {
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);
}
} }
} }

View file

@ -6,9 +6,6 @@ org.gradle.parallel=true
org.gradle.caching=true org.gradle.caching=true
org.gradle.vfs.watch=false org.gradle.vfs.watch=false
# TODO remove once architectury loom updates to 1.8
loom.ignoreDependencyLoomVersionValidation=true
group=org.geysermc group=org.geysermc
id=geyser id=geyser
version=2.6.0-SNAPSHOT version=2.6.0-SNAPSHOT

View file

@ -25,7 +25,7 @@ jline = "3.21.0"
terminalconsoleappender = "1.2.0" terminalconsoleappender = "1.2.0"
folia = "1.19.4-R0.1-SNAPSHOT" folia = "1.19.4-R0.1-SNAPSHOT"
viaversion = "4.9.2" viaversion = "4.9.2"
adapters = "1.15-SNAPSHOT" adapters = "1.16-SNAPSHOT"
cloud = "2.0.0-rc.2" cloud = "2.0.0-rc.2"
cloud-minecraft = "2.0.0-beta.9" cloud-minecraft = "2.0.0-beta.9"
cloud-minecraft-modded = "2.0.0-beta.10" cloud-minecraft-modded = "2.0.0-beta.10"
@ -46,7 +46,7 @@ mockito = "5.+"
indra = "3.1.3" indra = "3.1.3"
shadow = "8.1.1" shadow = "8.1.1"
architectury-plugin = "3.4-SNAPSHOT" architectury-plugin = "3.4-SNAPSHOT"
architectury-loom = "1.7-SNAPSHOT" architectury-loom = "1.9-SNAPSHOT"
minotaur = "2.8.7" minotaur = "2.8.7"
lombok = "8.4" lombok = "8.4"
blossom = "2.1.0" blossom = "2.1.0"

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

2
gradlew vendored
View file

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (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. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.