Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-03 14:50:19 +01:00
Supply a unique network ID for each recipe (#1615)
This fixes crashes in the Minecraft betas.
Dieser Commit ist enthalten in:
Ursprung
24fd7dafc5
Commit
f6a26410da
@ -41,6 +41,12 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class RecipeRegistry {
|
public class RecipeRegistry {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the last used recipe network ID. Since 1.16.200 (and for server-authoritative inventories),
|
||||||
|
* each recipe needs a unique network ID (or else in .200 the client crashes).
|
||||||
|
*/
|
||||||
|
public static int LAST_RECIPE_NET_ID = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of all possible leather armor dyeing recipes.
|
* A list of all possible leather armor dyeing recipes.
|
||||||
* Created manually.
|
* Created manually.
|
||||||
@ -79,13 +85,16 @@ public class RecipeRegistry {
|
|||||||
/**
|
/**
|
||||||
* Recipe data that, when sent to the client, enables book cloning
|
* Recipe data that, when sent to the client, enables book cloning
|
||||||
*/
|
*/
|
||||||
public static final CraftingData BOOK_CLONING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("d1ca6b84-338e-4f2f-9c6b-76cc8b4bd98d"));
|
public static final CraftingData BOOK_CLONING_RECIPE_DATA;
|
||||||
/**
|
/**
|
||||||
* Recipe data that, when sent to the client, enables tool repairing in a crafting table
|
* Recipe data that, when sent to the client, enables tool repairing in a crafting table
|
||||||
*/
|
*/
|
||||||
public static final CraftingData TOOL_REPAIRING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("00000000-0000-0000-0000-000000000001"));
|
public static final CraftingData TOOL_REPAIRING_RECIPE_DATA;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
BOOK_CLONING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("d1ca6b84-338e-4f2f-9c6b-76cc8b4bd98d"), LAST_RECIPE_NET_ID++);
|
||||||
|
TOOL_REPAIRING_RECIPE_DATA = CraftingData.fromMulti(UUID.fromString("00000000-0000-0000-0000-000000000001"), LAST_RECIPE_NET_ID++);
|
||||||
|
|
||||||
// Get all recipes that are not directly sent from a Java server
|
// Get all recipes that are not directly sent from a Java server
|
||||||
InputStream stream = FileUtils.getResource("mappings/recipes.json");
|
InputStream stream = FileUtils.getResource("mappings/recipes.json");
|
||||||
|
|
||||||
@ -154,7 +163,7 @@ public class RecipeRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return CraftingData.fromShaped(uuid.toString(), shape.get(0).length(), shape.size(),
|
return CraftingData.fromShaped(uuid.toString(), shape.get(0).length(), shape.size(),
|
||||||
inputs, new ItemData[]{output}, uuid, "crafting_table", 0);
|
inputs, new ItemData[]{output}, uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++);
|
||||||
}
|
}
|
||||||
List<ItemData> inputs = new ObjectArrayList<>();
|
List<ItemData> inputs = new ObjectArrayList<>();
|
||||||
for (JsonNode entry : node.get("input")) {
|
for (JsonNode entry : node.get("input")) {
|
||||||
@ -163,10 +172,10 @@ public class RecipeRegistry {
|
|||||||
if (node.get("type").asInt() == 5) {
|
if (node.get("type").asInt() == 5) {
|
||||||
// Shulker box
|
// Shulker box
|
||||||
return CraftingData.fromShulkerBox(uuid.toString(),
|
return CraftingData.fromShulkerBox(uuid.toString(),
|
||||||
inputs.toArray(new ItemData[0]), new ItemData[]{output}, uuid, "crafting_table", 0);
|
inputs.toArray(new ItemData[0]), new ItemData[]{output}, uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++);
|
||||||
}
|
}
|
||||||
return CraftingData.fromShapeless(uuid.toString(),
|
return CraftingData.fromShapeless(uuid.toString(),
|
||||||
inputs.toArray(new ItemData[0]), new ItemData[]{output}, uuid, "crafting_table", 0);
|
inputs.toArray(new ItemData[0]), new ItemData[]{output}, uuid, "crafting_table", 0, LAST_RECIPE_NET_ID++);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
@ -51,6 +51,8 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerDeclareRecipesPacket packet, GeyserSession session) {
|
public void translate(ServerDeclareRecipesPacket packet, GeyserSession session) {
|
||||||
|
// Get the last known network ID (first used for the pregenerated recipes) and increment from there.
|
||||||
|
int networkId = RecipeRegistry.LAST_RECIPE_NET_ID;
|
||||||
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
|
CraftingDataPacket craftingDataPacket = new CraftingDataPacket();
|
||||||
craftingDataPacket.setCleanRecipes(true);
|
craftingDataPacket.setCleanRecipes(true);
|
||||||
for (Recipe recipe : packet.getRecipes()) {
|
for (Recipe recipe : packet.getRecipes()) {
|
||||||
@ -63,7 +65,7 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
|
|||||||
for (ItemData[] inputs : inputCombinations) {
|
for (ItemData[] inputs : inputCombinations) {
|
||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(),
|
craftingDataPacket.getCraftingData().add(CraftingData.fromShapeless(uuid.toString(),
|
||||||
inputs, new ItemData[]{output}, uuid, "crafting_table", 0));
|
inputs, new ItemData[]{output}, uuid, "crafting_table", 0, networkId++));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -76,7 +78,7 @@ public class JavaDeclareRecipesTranslator extends PacketTranslator<ServerDeclare
|
|||||||
UUID uuid = UUID.randomUUID();
|
UUID uuid = UUID.randomUUID();
|
||||||
craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(),
|
craftingDataPacket.getCraftingData().add(CraftingData.fromShaped(uuid.toString(),
|
||||||
shapedRecipeData.getWidth(), shapedRecipeData.getHeight(), inputs,
|
shapedRecipeData.getWidth(), shapedRecipeData.getHeight(), inputs,
|
||||||
new ItemData[]{output}, uuid, "crafting_table", 0));
|
new ItemData[]{output}, uuid, "crafting_table", 0, networkId++));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren