forked from GeyserMC/Geyser
Fix regressions from 1.16.100 (#1558)
* Fix regressions from 1.16.100 - Update mappings to fix recipe regressions and item differences - Villager trading NBT now prefers the String identifier and not the integer ID * Fix lodestone compass breaking
This commit is contained in:
parent
99558b61a6
commit
199778faea
10 changed files with 28 additions and 45 deletions
|
@ -98,14 +98,12 @@ public class ItemFrameEntity extends Entity {
|
|||
ItemEntry itemEntry = ItemRegistry.getItem((ItemStack) entityMetadata.getValue());
|
||||
NbtMapBuilder builder = NbtMap.builder();
|
||||
|
||||
String blockName = ItemRegistry.getBedrockIdentifier(itemEntry);
|
||||
|
||||
builder.putByte("Count", (byte) itemData.getCount());
|
||||
if (itemData.getTag() != null) {
|
||||
builder.put("tag", itemData.getTag().toBuilder().build());
|
||||
}
|
||||
builder.putShort("Damage", itemData.getDamage());
|
||||
builder.putString("Name", blockName);
|
||||
builder.putString("Name", itemEntry.getBedrockIdentifier());
|
||||
NbtMapBuilder tag = getDefaultTag().toBuilder();
|
||||
tag.put("Item", builder.build());
|
||||
tag.putFloat("ItemDropChance", 1.0f);
|
||||
|
|
|
@ -34,9 +34,10 @@ import lombok.ToString;
|
|||
@ToString
|
||||
public class ItemEntry {
|
||||
|
||||
public static ItemEntry AIR = new ItemEntry("minecraft:air", 0, 0, 0, false);
|
||||
public static ItemEntry AIR = new ItemEntry("minecraft:air", "minecraft:air", 0, 0, 0, false);
|
||||
|
||||
private final String javaIdentifier;
|
||||
private final String bedrockIdentifier;
|
||||
private final int javaId;
|
||||
private final int bedrockId;
|
||||
private final int bedrockData;
|
||||
|
|
|
@ -103,6 +103,9 @@ public class ItemRegistry {
|
|||
TypeReference<List<JsonNode>> itemEntriesType = new TypeReference<List<JsonNode>>() {
|
||||
};
|
||||
|
||||
// Used to get the Bedrock namespaced ID (in instances where there are small differences)
|
||||
Int2ObjectMap<String> bedrockIdToIdentifier = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
List<JsonNode> itemEntries;
|
||||
try {
|
||||
itemEntries = GeyserConnector.JSON_MAPPER.readValue(stream, itemEntriesType);
|
||||
|
@ -114,6 +117,7 @@ public class ItemRegistry {
|
|||
|
||||
for (JsonNode entry : itemEntries) {
|
||||
ITEMS.add(new StartGamePacket.ItemEntry(entry.get("name").textValue(), (short) entry.get("id").intValue()));
|
||||
bedrockIdToIdentifier.put(entry.get("id").intValue(), entry.get("name").textValue());
|
||||
if (entry.get("name").textValue().equals("minecraft:lodestone_compass")) {
|
||||
lodestoneCompassId = entry.get("id").intValue();
|
||||
}
|
||||
|
@ -132,28 +136,29 @@ public class ItemRegistry {
|
|||
Iterator<Map.Entry<String, JsonNode>> iterator = items.fields();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, JsonNode> entry = iterator.next();
|
||||
int bedrockId = entry.getValue().get("bedrock_id").intValue();
|
||||
String bedrockIdentifier = bedrockIdToIdentifier.get(bedrockId);
|
||||
if (bedrockIdentifier == null) {
|
||||
throw new RuntimeException("Missing Bedrock ID in mappings!: " + bedrockId);
|
||||
}
|
||||
if (entry.getValue().has("tool_type")) {
|
||||
if (entry.getValue().has("tool_tier")) {
|
||||
ITEM_ENTRIES.put(itemIndex, new ToolItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getKey(), bedrockIdentifier, itemIndex, bedrockId,
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("tool_type").textValue(),
|
||||
entry.getValue().get("tool_tier").textValue(),
|
||||
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
|
||||
} else {
|
||||
ITEM_ENTRIES.put(itemIndex, new ToolItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getKey(), bedrockIdentifier, itemIndex, bedrockId,
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("tool_type").textValue(),
|
||||
"",
|
||||
entry.getValue().get("is_block").booleanValue()));
|
||||
"", entry.getValue().get("is_block").booleanValue()));
|
||||
}
|
||||
} else {
|
||||
ITEM_ENTRIES.put(itemIndex, new ItemEntry(
|
||||
entry.getKey(), itemIndex,
|
||||
entry.getValue().get("bedrock_id").intValue(),
|
||||
entry.getKey(), bedrockIdentifier, itemIndex, bedrockId,
|
||||
entry.getValue().get("bedrock_data").intValue(),
|
||||
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
|
||||
}
|
||||
|
@ -197,7 +202,7 @@ public class ItemRegistry {
|
|||
}
|
||||
|
||||
// Add the loadstone compass since it doesn't exist on java but we need it for item conversion
|
||||
ITEM_ENTRIES.put(itemIndex, new ItemEntry("minecraft:lodestone_compass", itemIndex,
|
||||
ITEM_ENTRIES.put(itemIndex, new ItemEntry("minecraft:lodestone_compass", "minecraft:lodestone_compass", itemIndex,
|
||||
lodestoneCompassId, 0, false));
|
||||
|
||||
/* Load creative items */
|
||||
|
@ -269,23 +274,6 @@ public class ItemRegistry {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Bedrock string identifier of an ItemEntry
|
||||
*
|
||||
* @param entry the ItemEntry to search for
|
||||
* @return the Bedrock identifier
|
||||
*/
|
||||
public static String getBedrockIdentifier(ItemEntry entry) {
|
||||
String blockName = "";
|
||||
for (StartGamePacket.ItemEntry startGamePacketItemEntry : ItemRegistry.ITEMS) {
|
||||
if (startGamePacketItemEntry.getId() == (short) entry.getBedrockId()) {
|
||||
blockName = startGamePacketItemEntry.getIdentifier(); // Find the Bedrock string name
|
||||
break;
|
||||
}
|
||||
}
|
||||
return blockName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Bedrock {@link ItemData} from a {@link JsonNode}
|
||||
* @param itemNode the JSON node that contains ProxyPass-compatible Bedrock item data
|
||||
|
|
|
@ -34,16 +34,13 @@ import com.nukkitx.nbt.NbtType;
|
|||
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.ItemRemapper;
|
||||
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
|
||||
import org.geysermc.connector.utils.FileUtils;
|
||||
import org.geysermc.connector.utils.LanguageUtils;
|
||||
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.*;
|
||||
|
|
|
@ -32,8 +32,8 @@ public class ToolItemEntry extends ItemEntry {
|
|||
private final String toolType;
|
||||
private final String toolTier;
|
||||
|
||||
public ToolItemEntry(String javaIdentifier, int javaId, int bedrockId, int bedrockData, String toolType, String toolTier, boolean isBlock) {
|
||||
super(javaIdentifier, javaId, bedrockId, bedrockData, isBlock);
|
||||
public ToolItemEntry(String javaIdentifier, String bedrockIdentifier, int javaId, int bedrockId, int bedrockData, String toolType, String toolTier, boolean isBlock) {
|
||||
super(javaIdentifier, bedrockIdentifier, javaId, bedrockId, bedrockData, isBlock);
|
||||
this.toolType = toolType;
|
||||
this.toolTier = toolTier;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class CompassTranslator extends ItemTranslator {
|
|||
Tag lodestoneTag = itemStack.getNbt().get("LodestoneTracked");
|
||||
if (lodestoneTag instanceof ByteTag) {
|
||||
// Get the fake lodestonecompass entry
|
||||
itemEntry = ItemRegistry.getItemEntry("minecraft:lodestonecompass");
|
||||
itemEntry = ItemRegistry.getItemEntry("minecraft:lodestone_compass");
|
||||
|
||||
// Get the loadstone pos
|
||||
CompoundTag loadstonePos = itemStack.getNbt().get("LodestonePos");
|
||||
|
@ -83,7 +83,7 @@ public class CompassTranslator extends ItemTranslator {
|
|||
@Override
|
||||
public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) {
|
||||
boolean isLoadstone = false;
|
||||
if (itemEntry.getJavaIdentifier().equals("minecraft:lodestonecompass")) {
|
||||
if (itemEntry.getBedrockIdentifier().equals("minecraft:lodestone_compass")) {
|
||||
// Revert the entry back to the compass
|
||||
itemEntry = ItemRegistry.getItemEntry("minecraft:compass");
|
||||
|
||||
|
|
|
@ -45,15 +45,15 @@ public class CrossbowTranslator extends NbtItemStackTranslator {
|
|||
if (!chargedProjectiles.getValue().isEmpty()) {
|
||||
CompoundTag projectile = (CompoundTag) chargedProjectiles.getValue().get(0);
|
||||
|
||||
ItemEntry entry = ItemRegistry.getItemEntry((String) projectile.get("id").getValue());
|
||||
if (entry == null) return;
|
||||
ItemEntry projectileEntry = ItemRegistry.getItemEntry((String) projectile.get("id").getValue());
|
||||
if (projectileEntry == null) return;
|
||||
CompoundTag tag = projectile.get("tag");
|
||||
ItemStack itemStack = new ItemStack(itemEntry.getJavaId(), (byte) projectile.get("Count").getValue(), tag);
|
||||
ItemData itemData = ItemTranslator.translateToBedrock(session, itemStack);
|
||||
|
||||
CompoundTag newProjectile = new CompoundTag("chargedItem");
|
||||
newProjectile.put(new ByteTag("Count", (byte) itemData.getCount()));
|
||||
newProjectile.put(new StringTag("Name", ItemRegistry.getBedrockIdentifier(entry)));
|
||||
newProjectile.put(new StringTag("Name", projectileEntry.getBedrockIdentifier()));
|
||||
|
||||
newProjectile.put(new ShortTag("Damage", itemData.getDamage()));
|
||||
|
||||
|
|
|
@ -50,9 +50,8 @@ public class ShulkerBoxItemTranslator extends NbtItemStackTranslator {
|
|||
boxItemTag.put(new ByteTag("WasPickedUp", (byte) 0)); // ???
|
||||
|
||||
ItemEntry boxItemEntry = ItemRegistry.getItemEntry(((StringTag) itemData.get("id")).getValue());
|
||||
String blockName = ItemRegistry.getBedrockIdentifier(boxItemEntry);
|
||||
|
||||
boxItemTag.put(new StringTag("Name", blockName));
|
||||
boxItemTag.put(new StringTag("Name", boxItemEntry.getBedrockIdentifier()));
|
||||
boxItemTag.put(new ShortTag("Damage", (short) boxItemEntry.getBedrockData()));
|
||||
boxItemTag.put(new ByteTag("Count", ((ByteTag) itemData.get("Count")).getValue()));
|
||||
if (itemData.contains("tag")) {
|
||||
|
|
|
@ -139,7 +139,7 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
|
|||
NbtMapBuilder builder = NbtMap.builder();
|
||||
builder.putByte("Count", (byte) (Math.max(itemData.getCount() + specialPrice, 1)));
|
||||
builder.putShort("Damage", itemData.getDamage());
|
||||
builder.putShort("id", (short) itemEntry.getBedrockId());
|
||||
builder.putString("Name", itemEntry.getBedrockIdentifier());
|
||||
if (itemData.getTag() != null) {
|
||||
NbtMap tag = itemData.getTag().toBuilder().build();
|
||||
builder.put("tag", tag);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 5c1da92b7144096449fc02c42a1adcd3fba7f52f
|
||||
Subproject commit 618a9b981398647125b1b63494cb49ad93433243
|
Loading…
Reference in a new issue