This commit is contained in:
Camotoy 2023-04-02 16:42:44 -04:00
parent 5871ca3f22
commit 0f99abc3a4
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
1 changed files with 15 additions and 1 deletions

View File

@ -70,7 +70,7 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
/**
* 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("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
@ -99,6 +99,10 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
// Strip NBT - tools won't appear in the recipe book otherwise
output = output.toBuilder().tag(null).build();
ItemDescriptorWithCount[][] inputCombinations = combinations(session, shapelessRecipeData.getIngredients());
if (inputCombinations == null) {
continue;
}
for (ItemDescriptorWithCount[] inputs : inputCombinations) {
UUID uuid = UUID.randomUUID();
craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(),
@ -116,6 +120,9 @@ public class JavaUpdateRecipesTranslator extends PacketTranslator<ClientboundUpd
// See above
output = output.toBuilder().tag(null).build();
ItemDescriptorWithCount[][] inputCombinations = combinations(session, shapedRecipeData.getIngredients());
if (inputCombinations == null) {
continue;
}
for (ItemDescriptorWithCount[] inputs : inputCombinations) {
UUID uuid = UUID.randomUUID();
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
*/
private ItemDescriptorWithCount[][] combinations(GeyserSession session, Ingredient[] ingredients) {
boolean empty = true;
Map<Set<ItemDescriptorWithCount>, IntSet> squashedOptions = new HashMap<>();
for (int i = 0; i < ingredients.length; i++) {
if (ingredients[i].getOptions().length == 0) {
squashedOptions.computeIfAbsent(Collections.singleton(ItemDescriptorWithCount.EMPTY), k -> new IntOpenHashSet()).add(i);
continue;
}
empty = false;
Ingredient ingredient = ingredients[i];
Map<GroupedItem, List<ItemDescriptorWithCount>> groupedByIds = Arrays.stream(ingredient.getOptions())
.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);
}
if (empty) {
// Crashes Bedrock 1.19.70 otherwise
// Fixes https://github.com/GeyserMC/Geyser/issues/3549
return null;
}
int totalCombinations = 1;
for (Set<ItemDescriptorWithCount> optionSet : squashedOptions.keySet()) {
totalCombinations *= optionSet.size();