Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 07:40:10 +01:00
Small optimizations; use array for Java -> Bedrock block mappings
Java runtime IDs are in order starting from 0; an array is all that is needed to map Java IDs to Bedrock IDs.
Dieser Commit ist enthalten in:
Ursprung
3c18eb44aa
Commit
bb92c89273
@ -32,6 +32,8 @@ import com.nukkitx.protocol.bedrock.v440.Bedrock_v440;
|
|||||||
import com.nukkitx.protocol.bedrock.v448.Bedrock_v448;
|
import com.nukkitx.protocol.bedrock.v448.Bedrock_v448;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||||
|
import it.unimi.dsi.fastutil.ints.IntList;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
@ -137,7 +139,7 @@ public class BlockRegistryPopulator {
|
|||||||
|
|
||||||
BiFunction<String, NbtMapBuilder, String> stateMapper = STATE_MAPPER.getOrDefault(palette.getKey(), (i, s) -> null);
|
BiFunction<String, NbtMapBuilder, String> stateMapper = STATE_MAPPER.getOrDefault(palette.getKey(), (i, s) -> null);
|
||||||
|
|
||||||
Int2IntMap javaToBedrockBlockMap = new Int2IntOpenHashMap();
|
IntList javaToBedrockBlockMap = new IntArrayList();
|
||||||
Int2IntMap bedrockToJavaBlockMap = new Int2IntOpenHashMap();
|
Int2IntMap bedrockToJavaBlockMap = new Int2IntOpenHashMap();
|
||||||
|
|
||||||
Map<String, NbtMap> flowerPotBlocks = new Object2ObjectOpenHashMap<>();
|
Map<String, NbtMap> flowerPotBlocks = new Object2ObjectOpenHashMap<>();
|
||||||
@ -189,7 +191,7 @@ public class BlockRegistryPopulator {
|
|||||||
javaIdentifierToBedrockTag.put(cleanJavaIdentifier.intern(), blocksTag.get(bedrockRuntimeId));
|
javaIdentifierToBedrockTag.put(cleanJavaIdentifier.intern(), blocksTag.get(bedrockRuntimeId));
|
||||||
}
|
}
|
||||||
|
|
||||||
javaToBedrockBlockMap.put(javaRuntimeId, bedrockRuntimeId);
|
javaToBedrockBlockMap.add(bedrockRuntimeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandBlockRuntimeId == -1) {
|
if (commandBlockRuntimeId == -1) {
|
||||||
@ -218,7 +220,7 @@ public class BlockRegistryPopulator {
|
|||||||
|
|
||||||
BlockRegistries.BLOCKS.register(PALETTE_VERSIONS.getInt(palette.getKey()), builder.blockStateVersion(stateVersion)
|
BlockRegistries.BLOCKS.register(PALETTE_VERSIONS.getInt(palette.getKey()), builder.blockStateVersion(stateVersion)
|
||||||
.emptyChunkSection(new ChunkSection(new BlockStorage[]{new BlockStorage(airRuntimeId)}))
|
.emptyChunkSection(new ChunkSection(new BlockStorage[]{new BlockStorage(airRuntimeId)}))
|
||||||
.javaToBedrockBlockMap(javaToBedrockBlockMap)
|
.javaToBedrockBlockMap(javaToBedrockBlockMap.toIntArray())
|
||||||
.bedrockToJavaBlockMap(bedrockToJavaBlockMap)
|
.bedrockToJavaBlockMap(bedrockToJavaBlockMap)
|
||||||
.javaIdentifierToBedrockTag(javaIdentifierToBedrockTag)
|
.javaIdentifierToBedrockTag(javaIdentifierToBedrockTag)
|
||||||
.itemFrames(itemFrames)
|
.itemFrames(itemFrames)
|
||||||
|
@ -45,7 +45,7 @@ public class BlockMappings {
|
|||||||
|
|
||||||
ChunkSection emptyChunkSection;
|
ChunkSection emptyChunkSection;
|
||||||
|
|
||||||
Int2IntMap javaToBedrockBlockMap;
|
int[] javaToBedrockBlockMap;
|
||||||
Int2IntMap bedrockToJavaBlockMap;
|
Int2IntMap bedrockToJavaBlockMap;
|
||||||
|
|
||||||
NbtList<NbtMap> bedrockBlockStates;
|
NbtList<NbtMap> bedrockBlockStates;
|
||||||
@ -62,7 +62,10 @@ public class BlockMappings {
|
|||||||
Map<String, NbtMap> flowerPotBlocks;
|
Map<String, NbtMap> flowerPotBlocks;
|
||||||
|
|
||||||
public int getBedrockBlockId(int state) {
|
public int getBedrockBlockId(int state) {
|
||||||
return this.javaToBedrockBlockMap.get(state);
|
if (state >= this.javaToBedrockBlockMap.length) {
|
||||||
|
return bedrockAirId;
|
||||||
|
}
|
||||||
|
return this.javaToBedrockBlockMap[state];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getJavaBlockState(int bedrockId) {
|
public int getJavaBlockState(int bedrockId) {
|
||||||
|
@ -257,8 +257,9 @@ public class ChunkUtils {
|
|||||||
while (i < blockEntities.length) {
|
while (i < blockEntities.length) {
|
||||||
CompoundTag tag = blockEntities[i];
|
CompoundTag tag = blockEntities[i];
|
||||||
String tagName;
|
String tagName;
|
||||||
if (tag.contains("id")) {
|
Tag idTag = tag.get("id");
|
||||||
tagName = (String) tag.get("id").getValue();
|
if (idTag != null) {
|
||||||
|
tagName = (String) idTag.getValue();
|
||||||
} else {
|
} else {
|
||||||
tagName = "Empty";
|
tagName = "Empty";
|
||||||
// Sometimes legacy tags have their ID be a StringTag with empty value
|
// Sometimes legacy tags have their ID be a StringTag with empty value
|
||||||
@ -277,18 +278,20 @@ public class ChunkUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String id = BlockEntityUtils.getBedrockBlockEntityId(tagName);
|
String id = BlockEntityUtils.getBedrockBlockEntityId(tagName);
|
||||||
Position pos = new Position((int) tag.get("x").getValue(), (int) tag.get("y").getValue(), (int) tag.get("z").getValue());
|
int x = (int) tag.get("x").getValue();
|
||||||
|
int y = (int) tag.get("y").getValue();
|
||||||
|
int z = (int) tag.get("z").getValue();
|
||||||
|
|
||||||
// Get Java blockstate ID from block entity position
|
// Get Java blockstate ID from block entity position
|
||||||
int blockState = 0;
|
int blockState = 0;
|
||||||
Chunk section = column.getChunks()[(pos.getY() >> 4) - yOffset];
|
Chunk section = column.getChunks()[(y >> 4) - yOffset];
|
||||||
if (section != null) {
|
if (section != null) {
|
||||||
blockState = section.get(pos.getX() & 0xF, pos.getY() & 0xF, pos.getZ() & 0xF);
|
blockState = section.get(x & 0xF, y & 0xF, z & 0xF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tagName.equals("minecraft:lectern") && BlockStateValues.getLecternBookStates().get(blockState)) {
|
if (tagName.equals("minecraft:lectern") && BlockStateValues.getLecternBookStates().get(blockState)) {
|
||||||
// If getLecternBookStates is false, let's just treat it like a normal block entity
|
// If getLecternBookStates is false, let's just treat it like a normal block entity
|
||||||
bedrockBlockEntities[i] = session.getConnector().getWorldManager().getLecternDataAt(session, pos.getX(), pos.getY(), pos.getZ(), true);
|
bedrockBlockEntities[i] = session.getConnector().getWorldManager().getLecternDataAt(session, x, y, z, true);
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren