3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 16:12:46 +01:00

Fix some villager block trades being unable to stack

Dieser Commit ist enthalten in:
Camotoy 2021-03-08 15:53:47 -05:00
Ursprung 44e9dba759
Commit 3f14624d46
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 31 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -44,6 +44,7 @@ import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -140,6 +141,12 @@ public class JavaTradeListTranslator extends PacketTranslator<ServerTradeListPac
NbtMap tag = itemData.getTag().toBuilder().build(); NbtMap tag = itemData.getTag().toBuilder().build();
builder.put("tag", tag); builder.put("tag", tag);
} }
NbtMap blockTag = BlockTranslator.getBedrockBlockNbt(itemEntry.getJavaIdentifier());
if (blockTag != null) {
// This fixes certain blocks being unable to stack after grabbing one
builder.putCompound("Block", blockTag);
builder.putShort("Damage", (short) 0);
}
return builder.build(); return builder.build();
} }
} }

Datei anzeigen

@ -98,6 +98,12 @@ public class BlockTranslator {
public static final int JAVA_RUNTIME_SPAWNER_ID; public static final int JAVA_RUNTIME_SPAWNER_ID;
/**
* Contains a map of Java blocks to their respective Bedrock block tag, if the Java identifier is different from Bedrock.
* Required to fix villager trades with these blocks.
*/
private static final Map<String, NbtMap> JAVA_IDENTIFIER_TO_BEDROCK_TAG;
private static final int BLOCK_STATE_VERSION = 17825808; private static final int BLOCK_STATE_VERSION = 17825808;
static { static {
@ -112,6 +118,8 @@ public class BlockTranslator {
throw new AssertionError("Unable to get blocks from runtime block states", e); throw new AssertionError("Unable to get blocks from runtime block states", e);
} }
JAVA_IDENTIFIER_TO_BEDROCK_TAG = new Object2ObjectOpenHashMap<>(blocksTag.size());
// New since 1.16.100 - find the block runtime ID by the order given to us in the block palette, // New since 1.16.100 - find the block runtime ID by the order given to us in the block palette,
// as we no longer send a block palette // as we no longer send a block palette
Object2IntMap<NbtMap> blockStateOrderedMap = new Object2IntOpenHashMap<>(blocksTag.size()); Object2IntMap<NbtMap> blockStateOrderedMap = new Object2IntOpenHashMap<>(blocksTag.size());
@ -188,15 +196,19 @@ public class BlockTranslator {
BlockStateValues.storeBlockStateValues(entry.getKey(), javaRuntimeId, entry.getValue()); BlockStateValues.storeBlockStateValues(entry.getKey(), javaRuntimeId, entry.getValue());
String cleanJavaIdentifier = entry.getKey().split("\\[")[0]; String cleanJavaIdentifier = entry.getKey().split("\\[")[0];
String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText();
boolean javaIdentifierSameAsBedrock = cleanJavaIdentifier.equals(bedrockIdentifier);
if (!JAVA_ID_TO_JAVA_IDENTIFIER_MAP.containsValue(cleanJavaIdentifier)) { if (!JAVA_ID_TO_JAVA_IDENTIFIER_MAP.containsValue(cleanJavaIdentifier)) {
uniqueJavaId++; uniqueJavaId++;
JAVA_ID_TO_JAVA_IDENTIFIER_MAP.put(uniqueJavaId, cleanJavaIdentifier); JAVA_ID_TO_JAVA_IDENTIFIER_MAP.put(uniqueJavaId, cleanJavaIdentifier);
if (!javaIdentifierSameAsBedrock) {
JAVA_IDENTIFIER_TO_BEDROCK_TAG.put(cleanJavaIdentifier, blockTag);
}
} }
String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText(); if (!javaIdentifierSameAsBedrock) {
if (!cleanJavaIdentifier.equals(bedrockIdentifier)) {
JAVA_TO_BEDROCK_IDENTIFIERS.put(cleanJavaIdentifier, bedrockIdentifier); JAVA_TO_BEDROCK_IDENTIFIERS.put(cleanJavaIdentifier, bedrockIdentifier);
} }
@ -393,4 +405,13 @@ public class BlockTranslator {
public static String[] getAllBlockIdentifiers() { public static String[] getAllBlockIdentifiers() {
return JAVA_ID_TO_JAVA_IDENTIFIER_MAP.values().toArray(new String[0]); return JAVA_ID_TO_JAVA_IDENTIFIER_MAP.values().toArray(new String[0]);
} }
/**
* @param cleanJavaIdentifier the clean Java identifier of the block to look up
*
* @return the block tag of the block name mapped from Java to Bedrock.
*/
public static NbtMap getBedrockBlockNbt(String cleanJavaIdentifier) {
return JAVA_IDENTIFIER_TO_BEDROCK_TAG.get(cleanJavaIdentifier);
}
} }