Skip to content

Commit

Permalink
Map experimental items to 'minecraft:unknown' Bedrock block
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Nov 1, 2024
1 parent dc1674f commit dd8a7a7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,17 @@ public void runCommand(@NonNull GeyserCommandSource source, @NonNull String comm
cloud.commandExecutor().executeCommand(source, command);
}

public void export(GeyserSession session, List<CommandData> bedrockCommands) {
public void export(GeyserSession session, List<CommandData> bedrockCommands, Set<String> knownAliases) {
cloud.commandTree().rootNodes().forEach(commandTree -> {
var command = commandTree.command();
// Command null happens if you register an extension command with custom Cloud parameters...
if (command == null || session.hasPermission(command.commandPermission().permissionString())) {
var rootComponent = commandTree.component();
String name = rootComponent.name();
if (!knownAliases.add(name)) {
// If the server already defined the command, let's not crash.
return;
}

LinkedHashMap<String, Set<CommandEnumConstraint>> values = new LinkedHashMap<>();
for (String s : rootComponent.aliases()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private static void registerBedrockBlocks() {
.build();
}

GeyserBedrockBlock vanillaBedrockDefinition = blockStateOrderedMap.getOrDefault(bedrockTag, airDefinition); // FIXME EEE
GeyserBedrockBlock vanillaBedrockDefinition = blockStateOrderedMap.get(bedrockTag);

GeyserBedrockBlock bedrockDefinition;
CustomBlockState blockStateOverride = BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get(javaRuntimeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -95,7 +96,7 @@
*/
public class ItemRegistryPopulator {

record PaletteVersion(String version, int protocolVersion, Map<Item, String> javaOnlyItems, Remapper remapper) {
record PaletteVersion(String version, int protocolVersion, Map<Item, Item> javaOnlyItems, Remapper remapper) {

public PaletteVersion(String version, int protocolVersion) {
this(version, protocolVersion, Collections.emptyMap(), (item, mapping) -> mapping);
Expand All @@ -109,11 +110,17 @@ interface Remapper {
}

public static void populate() {
List<Item> bundles = List.of(Items.BUNDLE, Items.BLACK_BUNDLE, Items.BLUE_BUNDLE, Items.BROWN_BUNDLE, Items.CYAN_BUNDLE, Items.GRAY_BUNDLE,
Items.GREEN_BUNDLE, Items.LIGHT_BLUE_BUNDLE, Items.LIGHT_GRAY_BUNDLE, Items.LIME_BUNDLE, Items.MAGENTA_BUNDLE, Items.ORANGE_BUNDLE, Items.RED_BUNDLE,
Items.PINK_BUNDLE, Items.PURPLE_BUNDLE, Items.WHITE_BUNDLE, Items.YELLOW_BUNDLE);
Map<Item, Item> pre1_21_2Items = new HashMap<>();
bundles.forEach(bundle -> pre1_21_2Items.put(bundle, Items.SHULKER_SHELL));

List<PaletteVersion> paletteVersions = new ArrayList<>(3);
paletteVersions.add(new PaletteVersion("1_20_80", Bedrock_v671.CODEC.getProtocolVersion(), Collections.emptyMap(), Conversion685_671::remapItem));
paletteVersions.add(new PaletteVersion("1_21_0", Bedrock_v685.CODEC.getProtocolVersion(), Collections.emptyMap(), Conversion712_685::remapItem));
paletteVersions.add(new PaletteVersion("1_21_20", Bedrock_v712.CODEC.getProtocolVersion(), Collections.emptyMap(), Conversion729_712::remapItem));
paletteVersions.add(new PaletteVersion("1_21_30", Bedrock_v729.CODEC.getProtocolVersion(), Collections.emptyMap(), Conversion748_729::remapItem));
paletteVersions.add(new PaletteVersion("1_20_80", Bedrock_v671.CODEC.getProtocolVersion(), pre1_21_2Items, Conversion685_671::remapItem));
paletteVersions.add(new PaletteVersion("1_21_0", Bedrock_v685.CODEC.getProtocolVersion(), pre1_21_2Items, Conversion712_685::remapItem));
paletteVersions.add(new PaletteVersion("1_21_20", Bedrock_v712.CODEC.getProtocolVersion(), pre1_21_2Items, Conversion729_712::remapItem));
paletteVersions.add(new PaletteVersion("1_21_30", Bedrock_v729.CODEC.getProtocolVersion(), pre1_21_2Items, Conversion748_729::remapItem));
paletteVersions.add(new PaletteVersion("1_21_40", Bedrock_v748.CODEC.getProtocolVersion()));

GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap();
Expand Down Expand Up @@ -227,7 +234,7 @@ public static void populate() {

Set<Item> javaOnlyItems = new ObjectOpenHashSet<>();
Collections.addAll(javaOnlyItems, Items.SPECTRAL_ARROW, Items.DEBUG_STICK,
Items.KNOWLEDGE_BOOK, Items.TIPPED_ARROW, Items.BUNDLE);
Items.KNOWLEDGE_BOOK, Items.TIPPED_ARROW);
if (!customItemsAllowed) {
javaOnlyItems.add(Items.FURNACE_MINECART);
}
Expand All @@ -243,9 +250,9 @@ public static void populate() {
throw new RuntimeException("Extra item in mappings? " + entry.getKey());
}
GeyserMappingItem mappingItem;
String replacementItem = palette.javaOnlyItems().get(javaItem);
Item replacementItem = palette.javaOnlyItems().get(javaItem);
if (replacementItem != null) {
mappingItem = items.get(replacementItem); // java only item, a java id fallback has been provided
mappingItem = items.get(replacementItem.javaIdentifier()); // java only item, a java id fallback has been provided
} else {
// check if any mapping changes need to be made on this version
mappingItem = palette.remapper().remap(javaItem, entry.getValue());
Expand All @@ -260,8 +267,7 @@ public static void populate() {
String bedrockIdentifier = mappingItem.getBedrockIdentifier();
ItemDefinition definition = definitions.get(bedrockIdentifier);
if (definition == null) {
definition = definitions.get("minecraft:air");
//throw new RuntimeException("Missing Bedrock ItemDefinition in version " + palette.version() + " for mapping: " + mappingItem);
throw new RuntimeException("Missing Bedrock ItemDefinition in version " + palette.version() + " for mapping: " + mappingItem);
}

BlockDefinition bedrockBlock = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void translate(GeyserSession session, ClientboundCommandsPacket packet) {
}

if (session.getGeyser().platformType() == PlatformType.STANDALONE) {
session.getGeyser().commandRegistry().export(session, commandData);
session.getGeyser().commandRegistry().export(session, commandData, knownAliases);
}

// Add our commands to the AvailableCommandsPacket for the bedrock client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public void translate(GeyserSession session, ClientboundRecipeBookAddPacket pack
for (int i = 0; i < left.size(); i++) {
List<ItemDescriptorWithCount> inputs = left.get(i);
String recipeId = contents.id() + "_" + i;
if (recipeId.equals("1318_0")) {
System.out.println(display);
}
int recipeNetworkId = netId++;
craftingDataPacket.getCraftingData().add(ShapedRecipeData.shaped(recipeId,
shapedRecipe.width(), shapedRecipe.height(), inputs,
Expand Down Expand Up @@ -268,8 +271,12 @@ private Pair<List<List<ItemDescriptorWithCount>>, ItemData> combinations(GeyserS
Pair<Item, ItemData> pair = translateToOutput(session, display.result());
if (pair == null || !pair.right().isValid()) {
// Likely modded item Bedrock will complain about
// Implementation note: ItemData#isValid() may return true for air because count might be > 0 and the air definition may not be ItemDefinition.AIR
return null;
}
if (pair.left() == Items.PALE_OAK_TRAPDOOR) {
System.out.println(pair.right());
}

ItemData output = pair.right();
if (!(pair.left() instanceof BedrockRequiresTagItem)) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/mappings
Submodule mappings updated 2 files
+ blocks.nbt
+24 −91 items.json

0 comments on commit dd8a7a7

Please sign in to comment.