3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 16:40:14 +01:00
Dieser Commit ist enthalten in:
Camotoy 2023-04-02 16:42:44 -04:00
Ursprung 5871ca3f22
Commit 0f99abc3a4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F

Datei anzeigen

@ -70,7 +70,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
/** /**
* Required to use the specified cartography table recipes * Required to use the specified cartography table recipes
*/ */
private static final List<CraftingData> CARTOGRAPHY_RECIPES = Arrays.asList( private static final List<CraftingData> CARTOGRAPHY_RECIPES = List.of(
CraftingData.fromMulti(UUID.fromString("8b36268c-1829-483c-a0f1-993b7156a8f2"), ++LAST_RECIPE_NET_ID), // Map extending CraftingData.fromMulti(UUID.fromString("8b36268c-1829-483c-a0f1-993b7156a8f2"), ++LAST_RECIPE_NET_ID), // Map extending
CraftingData.fromMulti(UUID.fromString("442d85ed-8272-4543-a6f1-418f90ded05d"), ++LAST_RECIPE_NET_ID), // Map cloning CraftingData.fromMulti(UUID.fromString("442d85ed-8272-4543-a6f1-418f90ded05d"), ++LAST_RECIPE_NET_ID), // Map cloning
CraftingData.fromMulti(UUID.fromString("98c84b38-1085-46bd-b1ce-dd38c159e6cc"), ++LAST_RECIPE_NET_ID), // Map upgrading CraftingData.fromMulti(UUID.fromString("98c84b38-1085-46bd-b1ce-dd38c159e6cc"), ++LAST_RECIPE_NET_ID), // Map upgrading
@ -99,6 +99,10 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
// Strip NBT - tools won't appear in the recipe book otherwise // Strip NBT - tools won't appear in the recipe book otherwise
output = output.toBuilder().tag(null).build(); output = output.toBuilder().tag(null).build();
ItemDescriptorWithCount[][] inputCombinations = combinations(session, shapelessRecipeData.getIngredients()); ItemDescriptorWithCount[][] inputCombinations = combinations(session, shapelessRecipeData.getIngredients());
if (inputCombinations == null) {
continue;
}
for (ItemDescriptorWithCount[] inputs : inputCombinations) { for (ItemDescriptorWithCount[] inputs : inputCombinations) {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(), craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(),
@ -116,6 +120,9 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
// See above // See above
output = output.toBuilder().tag(null).build(); output = output.toBuilder().tag(null).build();
ItemDescriptorWithCount[][] inputCombinations = combinations(session, shapedRecipeData.getIngredients()); ItemDescriptorWithCount[][] inputCombinations = combinations(session, shapedRecipeData.getIngredients());
if (inputCombinations == null) {
continue;
}
for (ItemDescriptorWithCount[] inputs : inputCombinations) { for (ItemDescriptorWithCount[] inputs : inputCombinations) {
UUID uuid = UUID.randomUUID(); UUID uuid = UUID.randomUUID();
craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(), craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(),
@ -216,12 +223,14 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
* @return the Java ingredient list as an array that Bedrock can understand * @return the Java ingredient list as an array that Bedrock can understand
*/ */
private ItemDescriptorWithCount[][] combinations(GeyserSession session, Ingredient[] ingredients) { private ItemDescriptorWithCount[][] combinations(GeyserSession session, Ingredient[] ingredients) {
boolean empty = true;
Map<Set<ItemDescriptorWithCount>, IntSet> squashedOptions = new HashMap<>(); Map<Set<ItemDescriptorWithCount>, IntSet> squashedOptions = new HashMap<>();
for (int i = 0; i < ingredients.length; i++) { for (int i = 0; i < ingredients.length; i++) {
if (ingredients[i].getOptions().length == 0) { if (ingredients[i].getOptions().length == 0) {
squashedOptions.computeIfAbsent(Collections.singleton(ItemDescriptorWithCount.EMPTY), k -> new IntOpenHashSet()).add(i); squashedOptions.computeIfAbsent(Collections.singleton(ItemDescriptorWithCount.EMPTY), k -> new IntOpenHashSet()).add(i);
continue; continue;
} }
empty = false;
Ingredient ingredient = ingredients[i]; Ingredient ingredient = ingredients[i];
Map<GroupedItem, List<ItemDescriptorWithCount>> groupedByIds = Arrays.stream(ingredient.getOptions()) Map<GroupedItem, List<ItemDescriptorWithCount>> groupedByIds = Arrays.stream(ingredient.getOptions())
.map(item -> ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, item))) .map(item -> ItemDescriptorWithCount.fromItem(ItemTranslator.translateToBedrock(session, item)))
@ -249,6 +258,11 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
} }
squashedOptions.computeIfAbsent(optionSet, k -> new IntOpenHashSet()).add(i); squashedOptions.computeIfAbsent(optionSet, k -> new IntOpenHashSet()).add(i);
} }
if (empty) {
// Crashes Bedrock 1.19.70 otherwise
// Fixes https://github.com/GeyserMC/Geyser/issues/3549
return null;
}
int totalCombinations = 1; int totalCombinations = 1;
for (Set<ItemDescriptorWithCount> optionSet : squashedOptions.keySet()) { for (Set<ItemDescriptorWithCount> optionSet : squashedOptions.keySet()) {
totalCombinations *= optionSet.size(); totalCombinations *= optionSet.size();