Skip to content

Commit

Permalink
Don't add items to the creative inventory that we don't have a Java m…
Browse files Browse the repository at this point in the history
…apping for
  • Loading branch information
onebeastchris committed Dec 3, 2024
1 parent 7bf937a commit b6c39d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.registry.type.BlockMappings;
import org.geysermc.geyser.registry.type.GeyserBedrockBlock;
import org.geysermc.geyser.registry.type.GeyserMappingItem;

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

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

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

BlockMappings blockMappings = BlockRegistries.BLOCKS.forVersion(palette.protocolVersion());
for (JsonNode itemNode : creativeItemEntries) {
ItemData.Builder itemBuilder = createItemData(itemNode, blockMappings, definitions);
ItemData.Builder itemBuilder = createItemData(itemNode, items, blockMappings, definitions);
if (itemBuilder == null) {
continue;
}
Expand All @@ -77,7 +76,7 @@ static void populate(ItemRegistryPopulator.PaletteVersion palette, Map<String, I
}
}

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

// 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)
// we still add the lodestone compass - we're going to translate it.
if (!items.containsKey(identifier) && !identifier.equals("minecraft:lodestone_compass")) {
// bedrock identifier not found, let's make sure it's not just different
boolean found = false;
for (var mapping : items.values()) {
if (mapping.getBedrockIdentifier().equals(identifier)) {
found = true;
break;
}
}

if (!found) {
return null;
}
}

JsonNode damageNode = itemNode.get("damage");
if (damageNode != null) {
damage = damageNode.asInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static void populate() {
noBlockDefinitions.add("minecraft:structure_void");

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

Expand Down

0 comments on commit b6c39d8

Please sign in to comment.