-
-
Notifications
You must be signed in to change notification settings - Fork 819
Re-register dynamic recipes cleanly, allow for NBT in output #6233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
valaphee
wants to merge
1
commit into
GeyserMC:master
Choose a base branch
from
valaphee:clean-dynamic-recipes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−138
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,12 +28,13 @@ | |
| import com.google.gson.JsonObject; | ||
| import io.netty.channel.Channel; | ||
| import io.netty.channel.EventLoop; | ||
| import it.unimi.dsi.fastutil.Pair; | ||
| import it.unimi.dsi.fastutil.ints.Int2ObjectMap; | ||
| import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; | ||
| import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; | ||
| import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
| import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
| import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; | ||
| import it.unimi.dsi.fastutil.objects.ObjectIntPair; | ||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
@@ -76,14 +77,20 @@ | |
| import org.cloudburstmc.protocol.bedrock.data.command.CommandPermission; | ||
| import org.cloudburstmc.protocol.bedrock.data.command.SoftEnumUpdateType; | ||
| import org.cloudburstmc.protocol.bedrock.data.definitions.DimensionDefinition; | ||
| import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition; | ||
| import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; | ||
| import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; | ||
| import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.CraftingRecipeData; | ||
| import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.RecipeUnlockingRequirement; | ||
| import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.ShapelessRecipeData; | ||
| import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.recipe.SmithingTransformRecipeData; | ||
| import org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.DefaultDescriptor; | ||
| import org.cloudburstmc.protocol.bedrock.data.inventory.descriptor.ItemDescriptorWithCount; | ||
| import org.cloudburstmc.protocol.bedrock.packet.AvailableEntityIdentifiersPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.BiomeDefinitionListPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.CameraPresetsPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.ChunkRadiusUpdatedPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.CraftingDataPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.CreativeContentPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.DimensionDataPacket; | ||
| import org.cloudburstmc.protocol.bedrock.packet.EmoteListPacket; | ||
|
|
@@ -150,6 +157,8 @@ | |
| import org.geysermc.geyser.inventory.recipe.GeyserRecipe; | ||
| import org.geysermc.geyser.inventory.recipe.GeyserSmithingRecipe; | ||
| import org.geysermc.geyser.inventory.recipe.GeyserStonecutterData; | ||
| import org.geysermc.geyser.inventory.recipe.RecipeUtil; | ||
| import org.geysermc.geyser.inventory.recipe.TrimRecipe; | ||
| import org.geysermc.geyser.item.Items; | ||
| import org.geysermc.geyser.item.type.BlockItem; | ||
| import org.geysermc.geyser.level.BedrockDimension; | ||
|
|
@@ -158,6 +167,7 @@ | |
| import org.geysermc.geyser.network.netty.LocalSession; | ||
| import org.geysermc.geyser.registry.Registries; | ||
| import org.geysermc.geyser.registry.type.BlockMappings; | ||
| import org.geysermc.geyser.registry.type.ItemMapping; | ||
| import org.geysermc.geyser.registry.type.ItemMappings; | ||
| import org.geysermc.geyser.session.auth.AuthData; | ||
| import org.geysermc.geyser.session.auth.BedrockClientData; | ||
|
|
@@ -190,6 +200,7 @@ | |
| import org.geysermc.geyser.skin.SkinManager; | ||
| import org.geysermc.geyser.text.GeyserLocale; | ||
| import org.geysermc.geyser.translator.inventory.InventoryTranslator; | ||
| import org.geysermc.geyser.translator.item.ItemTranslator; | ||
| import org.geysermc.geyser.translator.text.MessageTranslator; | ||
| import org.geysermc.geyser.util.ChunkUtils; | ||
| import org.geysermc.geyser.util.CooldownUtils; | ||
|
|
@@ -214,6 +225,7 @@ | |
| import org.geysermc.mcprotocollib.protocol.data.game.entity.player.HandPreference; | ||
| import org.geysermc.mcprotocollib.protocol.data.game.entity.player.PlayerAction; | ||
| import org.geysermc.mcprotocollib.protocol.data.game.entity.player.ResolvableProfile; | ||
| import org.geysermc.mcprotocollib.protocol.data.game.item.ItemStack; | ||
| import org.geysermc.mcprotocollib.protocol.data.game.setting.ChatVisibility; | ||
| import org.geysermc.mcprotocollib.protocol.data.game.setting.ParticleStatus; | ||
| import org.geysermc.mcprotocollib.protocol.data.game.setting.SkinPart; | ||
|
|
@@ -521,16 +533,14 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { | |
| private final Int2ObjectMap<List<String>> javaToBedrockRecipeIds; | ||
|
|
||
| private final Int2ObjectMap<GeyserRecipe> craftingRecipes; | ||
| @Setter | ||
| private Pair<CraftingRecipeData, GeyserRecipe> lastCreatedRecipe = null; // TODO try to prevent sending duplicate recipes | ||
| private final AtomicInteger lastRecipeNetId; | ||
|
|
||
| /** | ||
| * Saves a list of all stonecutter recipes, for use in a stonecutter inventory. | ||
| * The key is the Bedrock recipe net ID; the values are their respective output and button ID. | ||
| */ | ||
| @Setter | ||
| private Int2ObjectMap<GeyserStonecutterData> stonecutterRecipes; | ||
| private Int2ObjectMap<GeyserStonecutterData> stonecutterRecipes = Int2ObjectMaps.emptyMap(); | ||
valaphee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final List<GeyserSmithingRecipe> smithingRecipes = new ArrayList<>(); | ||
|
|
||
| /** | ||
|
|
@@ -2525,4 +2535,57 @@ public void sendNetworkLatencyStackPacket(long timestamp, boolean ensureEventLoo | |
| public String getDebugInfo() { | ||
| return "Username: %s, DeviceOs: %s, Version: %s".formatted(bedrockUsername(), platform(), version()); | ||
| } | ||
|
|
||
| public CraftingDataPacket getCraftingDataPacket() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we rename this to avoid confusion with getters for fields? e.g. a create prefix would be, imo, clearer |
||
| CraftingDataPacket craftingDataPacket = new CraftingDataPacket(); | ||
| craftingDataPacket.setCleanRecipes(true); | ||
| craftingDataPacket.getCraftingData().addAll(RecipeUtil.CARTOGRAPHY_RECIPES); | ||
| // Potion mixes are registered by default, as they are needed to be able to put ingredients into the brewing stand. | ||
| craftingDataPacket.getPotionMixData().addAll(Registries.POTION_MIXES.forVersion(getUpstream().getProtocolVersion())); | ||
| for (GeyserRecipe recipe : craftingRecipes.values()) { | ||
| craftingDataPacket.getCraftingData().addAll(recipe.asRecipeData(this)); | ||
| } | ||
|
Comment on lines
+2545
to
+2547
|
||
| for (GeyserSmithingRecipe recipe : smithingRecipes) { | ||
| craftingDataPacket.getCraftingData().addAll(recipe.asRecipeData(this)); | ||
| } | ||
| if (oldSmithingTable) { | ||
| ItemMapping template = itemMappings.getStoredItems().upgradeTemplate(); | ||
|
|
||
| for (ObjectIntPair<String> identifierAndNetId : TrimRecipe.NETHERITE_UPGRADES) { | ||
| craftingDataPacket.getCraftingData().add(SmithingTransformRecipeData.of(identifierAndNetId.left() + "_smithing", | ||
| getDescriptorFromId(this, template.getBedrockIdentifier()), | ||
| getDescriptorFromId(this, identifierAndNetId.left().replace("netherite", "diamond")), | ||
| getDescriptorFromId(this, "minecraft:netherite_ingot"), | ||
| ItemData.builder().definition(Objects.requireNonNull(itemMappings.getDefinition(identifierAndNetId.left()))).count(1).build(), | ||
| "smithing_table", | ||
| identifierAndNetId.rightInt())); | ||
| } | ||
| } else { | ||
| craftingDataPacket.getCraftingData().add(TrimRecipe.RECIPE); | ||
| } | ||
| for (Int2ObjectMap.Entry<GeyserStonecutterData> recipe : stonecutterRecipes.int2ObjectEntrySet()) { | ||
| int buttonId = recipe.getValue().buttonId(); | ||
| int javaInput = recipe.getValue().input(); | ||
| ItemMapping mapping = itemMappings.getMapping(javaInput); | ||
| ItemDescriptorWithCount descriptor = new ItemDescriptorWithCount(new DefaultDescriptor(mapping.getBedrockDefinition(), mapping.getBedrockData()), 1); | ||
| ItemStack javaOutput = recipe.getValue().output(); | ||
| ItemData output = ItemTranslator.translateToBedrock(this, javaOutput); | ||
| int recipeNetId = recipe.getIntKey(); | ||
| UUID uuid = UUID.randomUUID(); | ||
| // We need to register stonecutting recipes, so they show up on Bedrock | ||
| // (Implementation note: recipe ID creates the order which stonecutting recipes are shown in stonecutter) | ||
| craftingDataPacket.getCraftingData().add(ShapelessRecipeData.shapeless("stonecutter_" + javaInput + "_" + buttonId, | ||
| Collections.singletonList(descriptor), Collections.singletonList(output), uuid, "stonecutter", 0, recipeNetId, RecipeUnlockingRequirement.INVALID)); | ||
valaphee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return craftingDataPacket; | ||
| } | ||
|
|
||
| private ItemDescriptorWithCount getDescriptorFromId(GeyserSession session, String bedrockId) { | ||
| ItemDefinition bedrockDefinition = session.getItemMappings().getDefinition(bedrockId); | ||
| if (bedrockDefinition != null) { | ||
| return ItemDescriptorWithCount.fromItem(ItemData.builder().definition(bedrockDefinition).count(1).build()); | ||
| } | ||
| GeyserImpl.getInstance().getLogger().debug("Unable to find item with identifier " + bedrockId); | ||
| return ItemDescriptorWithCount.EMPTY; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is input the java item id? Would be lovely to clarify in Javadocs