Skip to content

Commit b6c39d8

Browse files
committed
Don't add items to the creative inventory that we don't have a Java mapping for
1 parent 7bf937a commit b6c39d8

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.geysermc.geyser.registry.BlockRegistries;
3838
import org.geysermc.geyser.registry.type.BlockMappings;
3939
import org.geysermc.geyser.registry.type.GeyserBedrockBlock;
40+
import org.geysermc.geyser.registry.type.GeyserMappingItem;
4041

4142
import java.io.ByteArrayInputStream;
4243
import java.io.IOException;
@@ -50,12 +51,10 @@
5051
public class CreativeItemRegistryPopulator {
5152
private static final List<BiPredicate<String, Integer>> JAVA_ONLY_ITEM_FILTER = List.of(
5253
// Bedrock-only as its own item
53-
(identifier, data) -> identifier.equals("minecraft:empty_map") && data == 2,
54-
// Bedrock-only banner patterns
55-
(identifier, data) -> identifier.equals("minecraft:bordure_indented_banner_pattern") || identifier.equals("minecraft:field_masoned_banner_pattern")
54+
(identifier, data) -> identifier.equals("minecraft:empty_map") && data == 2
5655
);
5756

58-
static void populate(ItemRegistryPopulator.PaletteVersion palette, Map<String, ItemDefinition> definitions, Consumer<ItemData.Builder> itemConsumer) {
57+
static void populate(ItemRegistryPopulator.PaletteVersion palette, Map<String, ItemDefinition> definitions, Map<String, GeyserMappingItem> items, Consumer<ItemData.Builder> itemConsumer) {
5958
GeyserBootstrap bootstrap = GeyserImpl.getInstance().getBootstrap();
6059

6160
// Load creative items
@@ -68,7 +67,7 @@ static void populate(ItemRegistryPopulator.PaletteVersion palette, Map<String, I
6867

6968
BlockMappings blockMappings = BlockRegistries.BLOCKS.forVersion(palette.protocolVersion());
7069
for (JsonNode itemNode : creativeItemEntries) {
71-
ItemData.Builder itemBuilder = createItemData(itemNode, blockMappings, definitions);
70+
ItemData.Builder itemBuilder = createItemData(itemNode, items, blockMappings, definitions);
7271
if (itemBuilder == null) {
7372
continue;
7473
}
@@ -77,7 +76,7 @@ static void populate(ItemRegistryPopulator.PaletteVersion palette, Map<String, I
7776
}
7877
}
7978

80-
private static ItemData.@Nullable Builder createItemData(JsonNode itemNode, BlockMappings blockMappings, Map<String, ItemDefinition> definitions) {
79+
private static ItemData.@Nullable Builder createItemData(JsonNode itemNode, Map<String, GeyserMappingItem> items, BlockMappings blockMappings, Map<String, ItemDefinition> definitions) {
8180
int count = 1;
8281
int damage = 0;
8382
NbtMap tag = null;
@@ -89,6 +88,23 @@ static void populate(ItemRegistryPopulator.PaletteVersion palette, Map<String, I
8988
}
9089
}
9190

91+
// Attempt to remove items that do not exist in Java (1.21.50 has 1.21.4 items, that don't exist on 1.21.2)
92+
// we still add the lodestone compass - we're going to translate it.
93+
if (!items.containsKey(identifier) && !identifier.equals("minecraft:lodestone_compass")) {
94+
// bedrock identifier not found, let's make sure it's not just different
95+
boolean found = false;
96+
for (var mapping : items.values()) {
97+
if (mapping.getBedrockIdentifier().equals(identifier)) {
98+
found = true;
99+
break;
100+
}
101+
}
102+
103+
if (!found) {
104+
return null;
105+
}
106+
}
107+
92108
JsonNode damageNode = itemNode.get("damage");
93109
if (damageNode != null) {
94110
damage = damageNode.asInt();

core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public static void populate() {
194194
noBlockDefinitions.add("minecraft:structure_void");
195195

196196
AtomicInteger creativeNetId = new AtomicInteger();
197-
CreativeItemRegistryPopulator.populate(palette, definitions, itemBuilder -> {
197+
CreativeItemRegistryPopulator.populate(palette, definitions, items, itemBuilder -> {
198198
ItemData item = itemBuilder.netId(creativeNetId.incrementAndGet()).build();
199199
creativeItems.add(item);
200200

0 commit comments

Comments
 (0)