Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-03 14:50:19 +01:00
Fix NPE when no item can be found from a block (#1718)
This commit also removes an old map previously used for block entity translators
Dieser Commit ist enthalten in:
Ursprung
c92150013f
Commit
d69896b381
@ -30,15 +30,18 @@ import com.google.common.collect.BiMap;
|
|||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.nukkitx.nbt.*;
|
import com.nukkitx.nbt.*;
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.*;
|
||||||
import it.unimi.dsi.fastutil.objects.*;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.network.translators.world.block.entity.BlockEntity;
|
|
||||||
import org.geysermc.connector.utils.FileUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class BlockTranslator {
|
public class BlockTranslator {
|
||||||
/**
|
/**
|
||||||
@ -65,8 +68,6 @@ public class BlockTranslator {
|
|||||||
// Bedrock carpet ID, used in LlamaEntity.java for decoration
|
// Bedrock carpet ID, used in LlamaEntity.java for decoration
|
||||||
public static final int CARPET = 171;
|
public static final int CARPET = 171;
|
||||||
|
|
||||||
private static final Int2ObjectMap<String> JAVA_ID_TO_BLOCK_ENTITY_MAP = new Int2ObjectOpenHashMap<>();
|
|
||||||
|
|
||||||
public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap();
|
public static final Int2DoubleMap JAVA_RUNTIME_ID_TO_HARDNESS = new Int2DoubleOpenHashMap();
|
||||||
public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap();
|
public static final Int2BooleanMap JAVA_RUNTIME_ID_TO_CAN_HARVEST_WITH_HAND = new Int2BooleanOpenHashMap();
|
||||||
public static final Int2ObjectMap<String> JAVA_RUNTIME_ID_TO_TOOL_TYPE = new Int2ObjectOpenHashMap<>();
|
public static final Int2ObjectMap<String> JAVA_RUNTIME_ID_TO_TOOL_TYPE = new Int2ObjectOpenHashMap<>();
|
||||||
@ -175,18 +176,6 @@ public class BlockTranslator {
|
|||||||
|
|
||||||
JAVA_ID_BLOCK_MAP.put(javaId, javaRuntimeId);
|
JAVA_ID_BLOCK_MAP.put(javaId, javaRuntimeId);
|
||||||
|
|
||||||
// Used for adding all "special" Java block states to block state map
|
|
||||||
String identifier;
|
|
||||||
String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText();
|
|
||||||
for (Class<?> clazz : ref.getTypesAnnotatedWith(BlockEntity.class)) {
|
|
||||||
identifier = clazz.getAnnotation(BlockEntity.class).regex();
|
|
||||||
// Endswith, or else the block bedrock gets picked up for bed
|
|
||||||
if (bedrockIdentifier.endsWith(identifier) && !identifier.equals("")) {
|
|
||||||
JAVA_ID_TO_BLOCK_ENTITY_MAP.put(javaRuntimeId, clazz.getAnnotation(BlockEntity.class).name());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockStateValues.storeBlockStateValues(entry, javaRuntimeId);
|
BlockStateValues.storeBlockStateValues(entry, javaRuntimeId);
|
||||||
|
|
||||||
String cleanJavaIdentifier = entry.getKey().split("\\[")[0];
|
String cleanJavaIdentifier = entry.getKey().split("\\[")[0];
|
||||||
@ -196,6 +185,8 @@ public class BlockTranslator {
|
|||||||
JAVA_ID_TO_JAVA_IDENTIFIER_MAP.put(uniqueJavaId, cleanJavaIdentifier);
|
JAVA_ID_TO_JAVA_IDENTIFIER_MAP.put(uniqueJavaId, cleanJavaIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String bedrockIdentifier = entry.getValue().get("bedrock_identifier").asText();
|
||||||
|
|
||||||
if (!cleanJavaIdentifier.equals(bedrockIdentifier)) {
|
if (!cleanJavaIdentifier.equals(bedrockIdentifier)) {
|
||||||
JAVA_TO_BEDROCK_IDENTIFIERS.put(cleanJavaIdentifier, bedrockIdentifier);
|
JAVA_TO_BEDROCK_IDENTIFIERS.put(cleanJavaIdentifier, bedrockIdentifier);
|
||||||
}
|
}
|
||||||
@ -356,10 +347,6 @@ public class BlockTranslator {
|
|||||||
return JAVA_ID_BLOCK_MAP.get(javaId);
|
return JAVA_ID_BLOCK_MAP.get(javaId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getBlockEntityString(int javaId) {
|
|
||||||
return JAVA_ID_TO_BLOCK_ENTITY_MAP.get(javaId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isWaterlogged(int state) {
|
public static boolean isWaterlogged(int state) {
|
||||||
return WATERLOGGED.contains(state);
|
return WATERLOGGED.contains(state);
|
||||||
}
|
}
|
||||||
|
@ -219,12 +219,17 @@ public class InventoryUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ItemEntry entry = ItemRegistry.getItemEntry(itemName);
|
||||||
|
if (entry != null) {
|
||||||
ClientCreativeInventoryActionPacket actionPacket = new ClientCreativeInventoryActionPacket(slot,
|
ClientCreativeInventoryActionPacket actionPacket = new ClientCreativeInventoryActionPacket(slot,
|
||||||
new ItemStack(ItemRegistry.getItemEntry(itemName).getJavaId()));
|
new ItemStack(entry.getJavaId()));
|
||||||
if ((slot - 36) != session.getInventory().getHeldItemSlot()) {
|
if ((slot - 36) != session.getInventory().getHeldItemSlot()) {
|
||||||
setHotbarItem(session, slot);
|
setHotbarItem(session, slot);
|
||||||
}
|
}
|
||||||
session.sendDownstreamPacket(actionPacket);
|
session.sendDownstreamPacket(actionPacket);
|
||||||
|
} else {
|
||||||
|
session.getConnector().getLogger().debug("Cannot find item for block " + itemName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren