diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java index 6a4db5655..b60b811a2 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java @@ -54,18 +54,18 @@ public class CreativeItemRegistryPopulator { (identifier, data) -> identifier.equals("minecraft:bordure_indented_banner_pattern") || identifier.equals("minecraft:field_masoned_banner_pattern") ); - static void populate(Map.Entry version, Map definitions, Consumer itemConsumer) { + static void populate(ItemRegistryPopulator.PaletteVersion palette, Map definitions, Consumer itemConsumer) { GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap(); // Load creative items JsonNode creativeItemEntries; - try (InputStream stream = bootstrap.getResource(String.format("bedrock/creative_items.%s.json", version.getKey()))) { + try (InputStream stream = bootstrap.getResource(String.format("bedrock/creative_items.%s.json", palette.version()))) { creativeItemEntries = GeyserImpl.JSON_MAPPER.readTree(stream).get("items"); } catch (Exception e) { throw new AssertionError("Unable to load creative items", e); } - BlockMappings blockMappings = BlockRegistries.BLOCKS.forVersion(version.getValue().protocolVersion()); + BlockMappings blockMappings = BlockRegistries.BLOCKS.forVersion(palette.protocolVersion()); for (JsonNode itemNode : creativeItemEntries) { ItemData.Builder itemBuilder = createItemData(itemNode, blockMappings, definitions); if (itemBuilder == null) { diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java index d4cef1035..cccdff853 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java @@ -68,10 +68,10 @@ import java.util.concurrent.atomic.AtomicInteger; */ public class ItemRegistryPopulator { - record PaletteVersion(int protocolVersion, Map javaOnlyItems, Remapper remapper) { + record PaletteVersion(String version, int protocolVersion, Map javaOnlyItems, Remapper remapper) { - public PaletteVersion(int protocolVersion) { - this(protocolVersion, Collections.emptyMap(), (item, mapping) -> mapping); + public PaletteVersion(String version, int protocolVersion) { + this(version, protocolVersion, Collections.emptyMap(), (item, mapping) -> mapping); } } @@ -88,8 +88,8 @@ public class ItemRegistryPopulator { legacyJavaOnly.put(Items.PITCHER_POD, "minecraft:beetroot"); legacyJavaOnly.put(Items.SNIFFER_EGG, "minecraft:sniffer_spawn_egg"); // the BlockItem of the sniffer egg block - Map paletteVersions = new Object2ObjectOpenHashMap<>(); - paletteVersions.put("1_19_80", new PaletteVersion(Bedrock_v582.CODEC.getProtocolVersion(), legacyJavaOnly, (item, mapping) -> { + List paletteVersions = new ArrayList<>(2); + paletteVersions.add(new PaletteVersion("1_19_80", Bedrock_v582.CODEC.getProtocolVersion(), legacyJavaOnly, (item, mapping) -> { String id = item.javaIdentifier(); if (id.endsWith("pottery_sherd")) { return mapping.withBedrockIdentifier(id.replace("sherd", "shard")); @@ -101,7 +101,7 @@ public class ItemRegistryPopulator { return mapping; })); - paletteVersions.put("1_20_0", new PaletteVersion(Bedrock_v589.CODEC.getProtocolVersion())); + paletteVersions.add(new PaletteVersion("1_20_0", Bedrock_v589.CODEC.getProtocolVersion())); GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap(); @@ -131,11 +131,11 @@ public class ItemRegistryPopulator { boolean firstMappingsPass = true; /* Load item palette */ - for (Map.Entry palette : paletteVersions.entrySet()) { + for (PaletteVersion palette : paletteVersions) { TypeReference> paletteEntriesType = new TypeReference<>() {}; List itemEntries; - try (InputStream stream = bootstrap.getResource(String.format("bedrock/runtime_item_states.%s.json", palette.getKey()))) { + try (InputStream stream = bootstrap.getResource(String.format("bedrock/runtime_item_states.%s.json", palette.version()))) { itemEntries = GeyserImpl.JSON_MAPPER.readValue(stream, paletteEntriesType); } catch (Exception e) { throw new AssertionError("Unable to load Bedrock runtime item IDs", e); @@ -193,7 +193,7 @@ public class ItemRegistryPopulator { } }); - BlockMappings blockMappings = BlockRegistries.BLOCKS.forVersion(palette.getValue().protocolVersion()); + BlockMappings blockMappings = BlockRegistries.BLOCKS.forVersion(palette.protocolVersion()); Set javaOnlyItems = new ObjectOpenHashSet<>(); Collections.addAll(javaOnlyItems, Items.SPECTRAL_ARROW, Items.DEBUG_STICK, @@ -202,7 +202,7 @@ public class ItemRegistryPopulator { javaOnlyItems.add(Items.FURNACE_MINECART); } // Java-only items for this version - javaOnlyItems.addAll(palette.getValue().javaOnlyItems().keySet()); + javaOnlyItems.addAll(palette.javaOnlyItems().keySet()); Int2ObjectMap customIdMappings = new Int2ObjectOpenHashMap<>(); Set registeredItemNames = new ObjectOpenHashSet<>(); // This is used to check for duplicate item names @@ -213,12 +213,12 @@ public class ItemRegistryPopulator { throw new RuntimeException("Extra item in mappings? " + entry.getKey()); } GeyserMappingItem mappingItem; - String replacementItem = palette.getValue().javaOnlyItems().get(javaItem); + String replacementItem = palette.javaOnlyItems().get(javaItem); if (replacementItem != null) { mappingItem = items.get(replacementItem); // 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.getValue().remapper().remap(javaItem, entry.getValue()); + mappingItem = palette.remapper().remap(javaItem, entry.getValue()); } if (customItemsAllowed && javaItem == Items.FURNACE_MINECART) { @@ -230,7 +230,7 @@ public class ItemRegistryPopulator { String bedrockIdentifier = mappingItem.getBedrockIdentifier(); ItemDefinition definition = definitions.get(bedrockIdentifier); if (definition == null) { - throw new RuntimeException("Missing Bedrock ItemDefinition in version " + palette.getKey() + " for mapping: " + mappingItem); + throw new RuntimeException("Missing Bedrock ItemDefinition in version " + palette.version() + " for mapping: " + mappingItem); } BlockDefinition bedrockBlock = null; @@ -515,7 +515,7 @@ public class ItemRegistryPopulator { .customIdMappings(customIdMappings) .build(); - Registries.ITEMS.register(palette.getValue().protocolVersion(), itemMappings); + Registries.ITEMS.register(palette.protocolVersion(), itemMappings); firstMappingsPass = false; }