2021-07-13 01:19:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.registry.populator;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import com.nukkitx.nbt.NbtMap;
|
|
|
|
import com.nukkitx.nbt.NbtMapBuilder;
|
|
|
|
import com.nukkitx.nbt.NbtType;
|
|
|
|
import com.nukkitx.nbt.NbtUtils;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.SoundEvent;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ComponentItemData;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
|
|
|
import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
|
2021-10-18 00:24:27 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.v465.Bedrock_v465;
|
|
|
|
import com.nukkitx.protocol.bedrock.v471.Bedrock_v471;
|
2021-11-15 01:15:25 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.*;
|
2021-07-13 01:19:40 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.*;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.inventory.item.StoredItemMappings;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.registry.BlockRegistries;
|
|
|
|
import org.geysermc.geyser.registry.Registries;
|
|
|
|
import org.geysermc.geyser.registry.type.*;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.util.FileUtils;
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.util.*;
|
|
|
|
|
2021-07-22 02:14:00 +00:00
|
|
|
/**
|
|
|
|
* Populates the item registries.
|
|
|
|
*/
|
2021-07-13 01:19:40 +00:00
|
|
|
public class ItemRegistryPopulator {
|
2021-07-14 00:48:45 +00:00
|
|
|
private static final Map<String, PaletteVersion> PALETTE_VERSIONS;
|
|
|
|
|
|
|
|
static {
|
|
|
|
PALETTE_VERSIONS = new Object2ObjectOpenHashMap<>();
|
2021-09-19 19:20:42 +00:00
|
|
|
PALETTE_VERSIONS.put("1_17_30", new PaletteVersion(Bedrock_v465.V465_CODEC.getProtocolVersion(), Collections.emptyMap()));
|
2021-10-18 00:24:27 +00:00
|
|
|
PALETTE_VERSIONS.put("1_17_40", new PaletteVersion(Bedrock_v471.V471_CODEC.getProtocolVersion(), Collections.emptyMap()));
|
2021-07-14 00:48:45 +00:00
|
|
|
}
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-10-04 12:58:33 +00:00
|
|
|
private record PaletteVersion(int protocolVersion, Map<String, String> additionalTranslatedItems) {
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void populate() {
|
|
|
|
// Load item mappings from Java Edition to Bedrock Edition
|
|
|
|
InputStream stream = FileUtils.getResource("mappings/items.json");
|
|
|
|
|
2021-09-19 19:20:42 +00:00
|
|
|
TypeReference<Map<String, GeyserMappingItem>> mappingItemsType = new TypeReference<>() { };
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
Map<String, GeyserMappingItem> items;
|
|
|
|
try {
|
2021-11-20 21:34:30 +00:00
|
|
|
items = GeyserImpl.JSON_MAPPER.readValue(stream, mappingItemsType);
|
2021-07-13 01:19:40 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AssertionError("Unable to load Java runtime item IDs", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load item palette */
|
|
|
|
for (Map.Entry<String, PaletteVersion> palette : PALETTE_VERSIONS.entrySet()) {
|
|
|
|
stream = FileUtils.getResource(String.format("bedrock/runtime_item_states.%s.json", palette.getKey()));
|
|
|
|
|
2021-09-22 19:11:14 +00:00
|
|
|
TypeReference<List<PaletteItem>> paletteEntriesType = new TypeReference<>() {};
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
// Used to get the Bedrock namespaced ID (in instances where there are small differences)
|
|
|
|
Object2IntMap<String> bedrockIdentifierToId = new Object2IntOpenHashMap<>();
|
2021-07-18 17:47:02 +00:00
|
|
|
bedrockIdentifierToId.defaultReturnValue(Short.MIN_VALUE);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
List<String> itemNames = new ArrayList<>();
|
|
|
|
|
|
|
|
List<PaletteItem> itemEntries;
|
|
|
|
try {
|
2021-11-20 21:34:30 +00:00
|
|
|
itemEntries = GeyserImpl.JSON_MAPPER.readValue(stream, paletteEntriesType);
|
2021-07-13 01:19:40 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AssertionError("Unable to load Bedrock runtime item IDs", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, StartGamePacket.ItemEntry> entries = new Object2ObjectOpenHashMap<>();
|
|
|
|
|
|
|
|
for (PaletteItem entry : itemEntries) {
|
|
|
|
entries.put(entry.getName(), new StartGamePacket.ItemEntry(entry.getName(), (short) entry.getId()));
|
|
|
|
bedrockIdentifierToId.put(entry.getName(), entry.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
Object2IntMap<String> bedrockBlockIdOverrides = new Object2IntOpenHashMap<>();
|
|
|
|
Object2IntMap<String> blacklistedIdentifiers = new Object2IntOpenHashMap<>();
|
|
|
|
|
|
|
|
// Load creative items
|
|
|
|
// We load this before item mappings to get overridden block runtime ID mappings
|
|
|
|
stream = FileUtils.getResource(String.format("bedrock/creative_items.%s.json", palette.getKey()));
|
|
|
|
|
|
|
|
JsonNode creativeItemEntries;
|
|
|
|
try {
|
2021-11-20 21:34:30 +00:00
|
|
|
creativeItemEntries = GeyserImpl.JSON_MAPPER.readTree(stream).get("items");
|
2021-07-13 01:19:40 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AssertionError("Unable to load creative items", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
IntList boats = new IntArrayList();
|
|
|
|
IntList buckets = new IntArrayList();
|
|
|
|
IntList spawnEggs = new IntArrayList();
|
|
|
|
List<ItemData> carpets = new ObjectArrayList<>();
|
|
|
|
|
|
|
|
Int2ObjectMap<ItemMapping> mappings = new Int2ObjectOpenHashMap<>();
|
|
|
|
// Temporary mapping to create stored items
|
|
|
|
Map<String, ItemMapping> identifierToMapping = new Object2ObjectOpenHashMap<>();
|
|
|
|
|
|
|
|
int netId = 1;
|
|
|
|
List<ItemData> creativeItems = new ArrayList<>();
|
|
|
|
for (JsonNode itemNode : creativeItemEntries) {
|
|
|
|
int count = 1;
|
|
|
|
int damage = 0;
|
|
|
|
int blockRuntimeId = 0;
|
|
|
|
NbtMap tag = null;
|
|
|
|
JsonNode damageNode = itemNode.get("damage");
|
|
|
|
if (damageNode != null) {
|
|
|
|
damage = damageNode.asInt();
|
|
|
|
}
|
|
|
|
JsonNode countNode = itemNode.get("count");
|
|
|
|
if (countNode != null) {
|
|
|
|
count = countNode.asInt();
|
|
|
|
}
|
|
|
|
JsonNode blockRuntimeIdNode = itemNode.get("blockRuntimeId");
|
|
|
|
if (blockRuntimeIdNode != null) {
|
|
|
|
blockRuntimeId = blockRuntimeIdNode.asInt();
|
|
|
|
}
|
|
|
|
JsonNode nbtNode = itemNode.get("nbt_b64");
|
|
|
|
if (nbtNode != null) {
|
|
|
|
byte[] bytes = Base64.getDecoder().decode(nbtNode.asText());
|
|
|
|
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
|
|
|
|
try {
|
|
|
|
tag = (NbtMap) NbtUtils.createReaderLE(bais).readTag();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String identifier = itemNode.get("id").textValue();
|
2021-11-12 14:42:35 +00:00
|
|
|
if (identifier.equals("minecraft:debug_stick")) {
|
2021-11-08 13:33:16 +00:00
|
|
|
// Just shows an empty texture; either way it doesn't exist in the creative menu on Java
|
|
|
|
continue;
|
2021-10-04 12:58:33 +00:00
|
|
|
}
|
2021-07-13 01:19:40 +00:00
|
|
|
StartGamePacket.ItemEntry entry = entries.get(identifier);
|
|
|
|
int id = -1;
|
|
|
|
if (entry != null) {
|
|
|
|
id = entry.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (id == -1) {
|
|
|
|
throw new RuntimeException("Unable to find matching Bedrock item for " + identifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
creativeItems.add(ItemData.builder()
|
|
|
|
.id(id)
|
|
|
|
.damage(damage)
|
|
|
|
.count(count)
|
|
|
|
.blockRuntimeId(blockRuntimeId)
|
|
|
|
.tag(tag)
|
|
|
|
.netId(netId++)
|
|
|
|
.build());
|
|
|
|
|
|
|
|
if (blockRuntimeId != 0) {
|
|
|
|
// Add override for item mapping, unless it already exists... then we know multiple states can exist
|
|
|
|
if (!blacklistedIdentifiers.containsKey(identifier)) {
|
|
|
|
if (bedrockBlockIdOverrides.containsKey(identifier)) {
|
|
|
|
bedrockBlockIdOverrides.removeInt(identifier);
|
|
|
|
// Save this as a blacklist, but also as knowledge of what the block state name should be
|
|
|
|
blacklistedIdentifiers.put(identifier, blockRuntimeId);
|
|
|
|
} else {
|
|
|
|
// Unless there's multiple possibilities for this one state, let this be
|
|
|
|
bedrockBlockIdOverrides.put(identifier, blockRuntimeId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-04 12:58:33 +00:00
|
|
|
BlockMappings blockMappings = BlockRegistries.BLOCKS.forVersion(palette.getValue().protocolVersion());
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
int itemIndex = 0;
|
|
|
|
int javaFurnaceMinecartId = 0;
|
2021-11-20 21:34:30 +00:00
|
|
|
boolean usingFurnaceMinecart = GeyserImpl.getInstance().getConfig().isAddNonBedrockItems();
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
Set<String> javaOnlyItems = new ObjectOpenHashSet<>();
|
|
|
|
Collections.addAll(javaOnlyItems, "minecraft:spectral_arrow", "minecraft:debug_stick",
|
|
|
|
"minecraft:knowledge_book", "minecraft:tipped_arrow", "minecraft:trader_llama_spawn_egg",
|
2021-07-16 16:28:11 +00:00
|
|
|
"minecraft:bundle");
|
2021-07-13 01:19:40 +00:00
|
|
|
if (!usingFurnaceMinecart) {
|
|
|
|
javaOnlyItems.add("minecraft:furnace_minecart");
|
|
|
|
}
|
|
|
|
// Java-only items for this version
|
2021-10-04 12:58:33 +00:00
|
|
|
javaOnlyItems.addAll(palette.getValue().additionalTranslatedItems().keySet());
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
for (Map.Entry<String, GeyserMappingItem> entry : items.entrySet()) {
|
2021-08-12 00:16:10 +00:00
|
|
|
String javaIdentifier = entry.getKey().intern();
|
2021-07-13 01:19:40 +00:00
|
|
|
GeyserMappingItem mappingItem;
|
2021-10-04 12:58:33 +00:00
|
|
|
String replacementItem = palette.getValue().additionalTranslatedItems().get(javaIdentifier);
|
2021-07-13 01:19:40 +00:00
|
|
|
if (replacementItem != null) {
|
|
|
|
mappingItem = items.get(replacementItem);
|
|
|
|
} else {
|
|
|
|
// This items has a mapping specifically for this version of the game
|
|
|
|
mappingItem = entry.getValue();
|
|
|
|
}
|
2021-11-12 14:42:35 +00:00
|
|
|
if (javaIdentifier.equals("minecraft:sculk_sensor")) {
|
|
|
|
// TODO fix in mappings
|
2021-07-16 16:28:11 +00:00
|
|
|
mappingItem.setBedrockIdentifier("minecraft:sculk_sensor");
|
2021-11-19 01:44:03 +00:00
|
|
|
} else if (javaIdentifier.equals("minecraft:music_disc_otherside") && palette.getValue().protocolVersion() <= Bedrock_v471.V471_CODEC.getProtocolVersion()) {
|
|
|
|
mappingItem.setBedrockIdentifier("minecraft:music_disc_pigstep");
|
2021-07-16 16:28:11 +00:00
|
|
|
}
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-08-12 00:16:10 +00:00
|
|
|
if (usingFurnaceMinecart && javaIdentifier.equals("minecraft:furnace_minecart")) {
|
2021-07-13 01:19:40 +00:00
|
|
|
javaFurnaceMinecartId = itemIndex;
|
|
|
|
itemIndex++;
|
|
|
|
continue;
|
|
|
|
}
|
2021-08-12 00:16:10 +00:00
|
|
|
String bedrockIdentifier = mappingItem.getBedrockIdentifier().intern();
|
2021-07-13 01:19:40 +00:00
|
|
|
int bedrockId = bedrockIdentifierToId.getInt(bedrockIdentifier);
|
2021-07-18 17:47:02 +00:00
|
|
|
if (bedrockId == Short.MIN_VALUE) {
|
|
|
|
throw new RuntimeException("Missing Bedrock ID in mappings: " + bedrockIdentifier);
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
2021-07-17 22:09:55 +00:00
|
|
|
int stackSize = mappingItem.getStackSize();
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
int bedrockBlockId = -1;
|
2021-07-17 22:09:55 +00:00
|
|
|
Integer firstBlockRuntimeId = entry.getValue().getFirstBlockRuntimeId();
|
|
|
|
if (firstBlockRuntimeId != null) {
|
2021-07-13 01:19:40 +00:00
|
|
|
int blockIdOverride = bedrockBlockIdOverrides.getOrDefault(bedrockIdentifier, -1);
|
|
|
|
if (blockIdOverride != -1) {
|
|
|
|
// Straight from BDS is our best chance of getting an item that doesn't run into issues
|
|
|
|
bedrockBlockId = blockIdOverride;
|
|
|
|
} else {
|
|
|
|
// Try to get an example block runtime ID from the creative contents packet, for Bedrock identifier obtaining
|
|
|
|
int aValidBedrockBlockId = blacklistedIdentifiers.getOrDefault(bedrockIdentifier, -1);
|
|
|
|
if (aValidBedrockBlockId == -1) {
|
|
|
|
// Fallback
|
2021-07-17 22:09:55 +00:00
|
|
|
bedrockBlockId = blockMappings.getBedrockBlockId(firstBlockRuntimeId);
|
2021-07-13 01:19:40 +00:00
|
|
|
} else {
|
|
|
|
// As of 1.16.220, every item requires a block runtime ID attached to it.
|
|
|
|
// This is mostly for identifying different blocks with the same item ID - wool, slabs, some walls.
|
|
|
|
// However, in order for some visuals and crafting to work, we need to send the first matching block state
|
|
|
|
// as indexed by Bedrock's block palette
|
|
|
|
// There are exceptions! But, ideally, the block ID override should take care of those.
|
|
|
|
NbtMapBuilder requiredBlockStatesBuilder = NbtMap.builder();
|
|
|
|
String correctBedrockIdentifier = blockMappings.getBedrockBlockStates().get(aValidBedrockBlockId).getString("name");
|
|
|
|
boolean firstPass = true;
|
2021-07-17 22:09:55 +00:00
|
|
|
// Block states are all grouped together. In the mappings, we store the first block runtime ID in order,
|
|
|
|
// and the last, if relevant. We then iterate over all those values and get their Bedrock equivalents
|
|
|
|
Integer lastBlockRuntimeId = entry.getValue().getLastBlockRuntimeId() == null ? firstBlockRuntimeId : entry.getValue().getLastBlockRuntimeId();
|
|
|
|
for (int i = firstBlockRuntimeId; i <= lastBlockRuntimeId; i++) {
|
|
|
|
int bedrockBlockRuntimeId = blockMappings.getBedrockBlockId(i);
|
|
|
|
NbtMap blockTag = blockMappings.getBedrockBlockStates().get(bedrockBlockRuntimeId);
|
|
|
|
String bedrockName = blockTag.getString("name");
|
|
|
|
if (!bedrockName.equals(correctBedrockIdentifier)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NbtMap states = blockTag.getCompound("states");
|
|
|
|
|
|
|
|
if (firstPass) {
|
|
|
|
firstPass = false;
|
|
|
|
if (states.size() == 0) {
|
|
|
|
// No need to iterate and find all block states - this is the one, as there can't be any others
|
|
|
|
bedrockBlockId = bedrockBlockRuntimeId;
|
2021-07-13 01:19:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-17 22:09:55 +00:00
|
|
|
requiredBlockStatesBuilder.putAll(states);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (Map.Entry<String, Object> nbtEntry : states.entrySet()) {
|
|
|
|
Object value = requiredBlockStatesBuilder.get(nbtEntry.getKey());
|
|
|
|
if (value != null && !nbtEntry.getValue().equals(value)) { // Null means this value has already been removed/deemed as unneeded
|
|
|
|
// This state can change between different block states, and therefore is not required
|
|
|
|
// to build a successful block state of this
|
|
|
|
requiredBlockStatesBuilder.remove(nbtEntry.getKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (requiredBlockStatesBuilder.size() == 0) {
|
|
|
|
// There are no required block states
|
|
|
|
// E.G. there was only a direction property that is no longer in play
|
|
|
|
// (States that are important include color for glass)
|
|
|
|
break;
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NbtMap requiredBlockStates = requiredBlockStatesBuilder.build();
|
|
|
|
if (bedrockBlockId == -1) {
|
|
|
|
int i = -1;
|
|
|
|
// We need to loop around again (we can't cache the block tags above) because Bedrock can include states that we don't have a pairing for
|
|
|
|
// in it's "preferred" block state - I.E. the first matching block state in the list
|
|
|
|
for (NbtMap blockTag : blockMappings.getBedrockBlockStates()) {
|
|
|
|
i++;
|
|
|
|
if (blockTag.getString("name").equals(correctBedrockIdentifier)) {
|
|
|
|
NbtMap states = blockTag.getCompound("states");
|
|
|
|
boolean valid = true;
|
|
|
|
for (Map.Entry<String, Object> nbtEntry : requiredBlockStates.entrySet()) {
|
|
|
|
if (!states.get(nbtEntry.getKey()).equals(nbtEntry.getValue())) {
|
|
|
|
// A required block state doesn't match - this one is not valid
|
|
|
|
valid = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (valid) {
|
|
|
|
bedrockBlockId = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (bedrockBlockId == -1) {
|
|
|
|
throw new RuntimeException("Could not find a block match for " + entry.getKey());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because we have replaced the Bedrock block ID, we also need to replace the creative contents block runtime ID
|
|
|
|
// That way, creative items work correctly for these blocks
|
|
|
|
for (int j = 0; j < creativeItems.size(); j++) {
|
|
|
|
ItemData itemData = creativeItems.get(j);
|
|
|
|
if (itemData.getId() == bedrockId) {
|
|
|
|
if (itemData.getDamage() != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NbtMap states = blockMappings.getBedrockBlockStates().get(itemData.getBlockRuntimeId()).getCompound("states");
|
|
|
|
boolean valid = true;
|
|
|
|
for (Map.Entry<String, Object> nbtEntry : requiredBlockStates.entrySet()) {
|
|
|
|
if (!states.get(nbtEntry.getKey()).equals(nbtEntry.getValue())) {
|
|
|
|
// A required block state doesn't match - this one is not valid
|
|
|
|
valid = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (valid) {
|
|
|
|
creativeItems.set(j, itemData.toBuilder().blockRuntimeId(bedrockBlockId).build());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemMapping.ItemMappingBuilder mappingBuilder = ItemMapping.builder()
|
2021-08-12 00:16:10 +00:00
|
|
|
.javaIdentifier(javaIdentifier)
|
2021-07-13 01:19:40 +00:00
|
|
|
.javaId(itemIndex)
|
|
|
|
.bedrockIdentifier(bedrockIdentifier)
|
|
|
|
.bedrockId(bedrockId)
|
|
|
|
.bedrockData(mappingItem.getBedrockData())
|
|
|
|
.bedrockBlockId(bedrockBlockId)
|
2021-11-15 01:15:25 +00:00
|
|
|
.stackSize(stackSize)
|
|
|
|
.maxDamage(mappingItem.getMaxDamage());
|
|
|
|
|
|
|
|
if (mappingItem.getRepairMaterials() != null) {
|
|
|
|
mappingBuilder = mappingBuilder.repairMaterials(new ObjectOpenHashSet<>(mappingItem.getRepairMaterials()));
|
|
|
|
}
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
if (mappingItem.getToolType() != null) {
|
|
|
|
if (mappingItem.getToolTier() != null) {
|
2021-08-12 00:16:10 +00:00
|
|
|
mappingBuilder = mappingBuilder.toolType(mappingItem.getToolType().intern())
|
|
|
|
.toolTier(mappingItem.getToolTier().intern());
|
2021-07-13 01:19:40 +00:00
|
|
|
} else {
|
2021-08-12 00:16:10 +00:00
|
|
|
mappingBuilder = mappingBuilder.toolType(mappingItem.getToolType().intern())
|
2021-07-13 01:19:40 +00:00
|
|
|
.toolTier("");
|
|
|
|
}
|
|
|
|
}
|
2021-08-12 00:16:10 +00:00
|
|
|
if (javaOnlyItems.contains(javaIdentifier)) {
|
2021-07-13 01:19:40 +00:00
|
|
|
// These items don't exist on Bedrock, so set up a variable that indicates they should have custom names
|
|
|
|
mappingBuilder = mappingBuilder.translationString((bedrockBlockId != -1 ? "block." : "item.") + entry.getKey().replace(":", "."));
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug("Adding " + entry.getKey() + " as an item that needs to be translated.");
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ItemMapping mapping = mappingBuilder.build();
|
|
|
|
|
2021-08-12 00:16:10 +00:00
|
|
|
if (javaIdentifier.contains("boat")) {
|
2021-07-13 01:19:40 +00:00
|
|
|
boats.add(bedrockId);
|
2021-08-12 00:16:10 +00:00
|
|
|
} else if (javaIdentifier.contains("bucket") && !javaIdentifier.contains("milk")) {
|
2021-07-13 01:19:40 +00:00
|
|
|
buckets.add(bedrockId);
|
2021-08-12 00:16:10 +00:00
|
|
|
} else if (javaIdentifier.contains("_carpet") && !javaIdentifier.contains("moss")) {
|
2021-07-13 01:19:40 +00:00
|
|
|
// This should be the numerical order Java sends as an integer value for llamas
|
|
|
|
carpets.add(ItemData.builder()
|
|
|
|
.id(mapping.getBedrockId())
|
|
|
|
.damage(mapping.getBedrockData())
|
|
|
|
.count(1)
|
|
|
|
.blockRuntimeId(mapping.getBedrockBlockId())
|
|
|
|
.build());
|
2021-11-19 01:44:03 +00:00
|
|
|
} else if (javaIdentifier.startsWith("minecraft:music_disc_") && !javaIdentifier.equals("minecraft:music_disc_otherside")) { // TODO TEMPORARY
|
2021-07-13 01:19:40 +00:00
|
|
|
// The Java record level event uses the item ID as the "key" to play the record
|
|
|
|
Registries.RECORDS.register(itemIndex, SoundEvent.valueOf("RECORD_" +
|
2021-10-12 01:14:06 +00:00
|
|
|
javaIdentifier.replace("minecraft:music_disc_", "").toUpperCase(Locale.ENGLISH)));
|
2021-08-12 00:16:10 +00:00
|
|
|
} else if (javaIdentifier.endsWith("_spawn_egg")) {
|
2021-07-13 01:19:40 +00:00
|
|
|
spawnEggs.add(mapping.getBedrockId());
|
|
|
|
}
|
|
|
|
|
|
|
|
mappings.put(itemIndex, mapping);
|
2021-08-12 00:16:10 +00:00
|
|
|
identifierToMapping.put(javaIdentifier, mapping);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
2021-08-12 00:16:10 +00:00
|
|
|
itemNames.add(javaIdentifier);
|
2021-07-13 01:19:40 +00:00
|
|
|
|
|
|
|
itemIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
itemNames.add("minecraft:furnace_minecart");
|
|
|
|
|
|
|
|
int lodestoneCompassId = entries.get("minecraft:lodestone_compass").getId();
|
|
|
|
if (lodestoneCompassId == 0) {
|
|
|
|
throw new RuntimeException("Lodestone compass not found in item palette!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the lodestone compass since it doesn't exist on java but we need it for item conversion
|
|
|
|
ItemMapping lodestoneEntry = ItemMapping.builder()
|
|
|
|
.javaIdentifier("minecraft:lodestone_compass")
|
|
|
|
.bedrockIdentifier("minecraft:lodestone_compass")
|
|
|
|
.javaId(itemIndex)
|
|
|
|
.bedrockId(lodestoneCompassId)
|
|
|
|
.bedrockData(0)
|
|
|
|
.bedrockBlockId(-1)
|
|
|
|
.stackSize(1)
|
|
|
|
.build();
|
|
|
|
mappings.put(itemIndex, lodestoneEntry);
|
|
|
|
identifierToMapping.put(lodestoneEntry.getJavaIdentifier(), lodestoneEntry);
|
|
|
|
|
|
|
|
ComponentItemData furnaceMinecartData = null;
|
|
|
|
if (usingFurnaceMinecart) {
|
|
|
|
// Add the furnace minecart as a custom item
|
|
|
|
int furnaceMinecartId = mappings.size() + 1;
|
|
|
|
|
|
|
|
entries.put("geysermc:furnace_minecart", new StartGamePacket.ItemEntry("geysermc:furnace_minecart", (short) furnaceMinecartId, true));
|
|
|
|
|
|
|
|
mappings.put(javaFurnaceMinecartId, ItemMapping.builder()
|
|
|
|
.javaIdentifier("geysermc:furnace_minecart")
|
|
|
|
.bedrockIdentifier("geysermc:furnace_minecart")
|
|
|
|
.javaId(javaFurnaceMinecartId)
|
|
|
|
.bedrockId(furnaceMinecartId)
|
|
|
|
.bedrockData(0)
|
|
|
|
.bedrockBlockId(-1)
|
|
|
|
.stackSize(1)
|
|
|
|
.build());
|
|
|
|
|
|
|
|
creativeItems.add(ItemData.builder()
|
|
|
|
.netId(netId)
|
|
|
|
.id(furnaceMinecartId)
|
|
|
|
.count(1).build());
|
|
|
|
|
|
|
|
NbtMapBuilder builder = NbtMap.builder();
|
|
|
|
builder.putString("name", "geysermc:furnace_minecart")
|
|
|
|
.putInt("id", furnaceMinecartId);
|
|
|
|
|
2021-09-22 19:11:14 +00:00
|
|
|
NbtMapBuilder itemProperties = NbtMap.builder();
|
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
NbtMapBuilder componentBuilder = NbtMap.builder();
|
|
|
|
// Conveniently, as of 1.16.200, the furnace minecart has a texture AND translation string already.
|
2021-09-22 19:11:14 +00:00
|
|
|
// 1.17.30 moves the icon to the item properties section
|
2021-10-04 12:58:33 +00:00
|
|
|
(palette.getValue().protocolVersion() >= Bedrock_v465.V465_CODEC.getProtocolVersion() ?
|
2021-09-22 19:11:14 +00:00
|
|
|
itemProperties : componentBuilder).putCompound("minecraft:icon", NbtMap.builder()
|
|
|
|
.putString("texture", "minecart_furnace")
|
|
|
|
.putString("frame", "0.000000")
|
|
|
|
.putInt("frame_version", 1)
|
|
|
|
.putString("legacy_id", "").build());
|
2021-07-13 01:19:40 +00:00
|
|
|
componentBuilder.putCompound("minecraft:display_name", NbtMap.builder().putString("value", "item.minecartFurnace.name").build());
|
|
|
|
|
|
|
|
// Indicate that the arm animation should play on rails
|
|
|
|
List<NbtMap> useOnTag = Collections.singletonList(NbtMap.builder().putString("tags", "q.any_tag('rail')").build());
|
|
|
|
componentBuilder.putCompound("minecraft:entity_placer", NbtMap.builder()
|
|
|
|
.putList("dispense_on", NbtType.COMPOUND, useOnTag)
|
|
|
|
.putString("entity", "minecraft:minecart")
|
|
|
|
.putList("use_on", NbtType.COMPOUND, useOnTag)
|
|
|
|
.build());
|
|
|
|
|
|
|
|
// We always want to allow offhand usage when we can - matches Java Edition
|
|
|
|
itemProperties.putBoolean("allow_off_hand", true);
|
|
|
|
itemProperties.putBoolean("hand_equipped", false);
|
|
|
|
itemProperties.putInt("max_stack_size", 1);
|
|
|
|
itemProperties.putString("creative_group", "itemGroup.name.minecart");
|
|
|
|
itemProperties.putInt("creative_category", 4); // 4 - "Items"
|
|
|
|
|
|
|
|
componentBuilder.putCompound("item_properties", itemProperties.build());
|
|
|
|
builder.putCompound("components", componentBuilder.build());
|
|
|
|
furnaceMinecartData = new ComponentItemData("geysermc:furnace_minecart", builder.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemMappings itemMappings = ItemMappings.builder()
|
|
|
|
.items(mappings)
|
|
|
|
.creativeItems(creativeItems.toArray(new ItemData[0]))
|
|
|
|
.itemEntries(new ArrayList<>(entries.values()))
|
|
|
|
.itemNames(itemNames.toArray(new String[0]))
|
|
|
|
.storedItems(new StoredItemMappings(identifierToMapping))
|
|
|
|
.javaOnlyItems(javaOnlyItems)
|
|
|
|
.bucketIds(buckets)
|
|
|
|
.boatIds(boats)
|
|
|
|
.spawnEggIds(spawnEggs)
|
|
|
|
.carpets(carpets)
|
|
|
|
.furnaceMinecartData(furnaceMinecartData)
|
|
|
|
.build();
|
|
|
|
|
2021-10-04 12:58:33 +00:00
|
|
|
Registries.ITEMS.register(palette.getValue().protocolVersion(), itemMappings);
|
2021-07-13 01:19:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|