Merge remote-tracking branch 'remotes/upstream/master' into inventory

# Conflicts:
#	connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaBlockChangeTranslator.java
#	connector/src/main/java/org/geysermc/connector/utils/Toolbox.java
This commit is contained in:
AJ Ferguson 2019-12-23 16:58:59 -09:00
commit 8061e2d76d
18 changed files with 128 additions and 184 deletions

View file

@ -13,39 +13,31 @@ Geyser is a bridge between Minecraft: Bedrock Edition and Minecraft: Java Editio
Geyser is a proxy, bridging the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition servers. Geyser is a proxy, bridging the gap between Minecraft: Bedrock Edition and Minecraft: Java Edition servers.
The ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible. The ultimate goal of this project is to allow Minecraft: Bedrock Edition users to join Minecraft: Java Edition servers as seamlessly as possible.
### Please note, this project is still a work in progress and should not be used on production. ### Please note, this project is still a work in progress and should not be used on production. Expect bugs!
## Setting Up ## Setting Up
Please note, Geyser is **not** a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up. Please note, Geyser is **not** (currently) a plugin. Watch the video below or take a look [here](https://github.com/GeyserMC/Geyser/wiki#Setup) for how to set it up.
[![YouTube Video](https://img.youtube.com/vi/OmLxwl7_UzQ/0.jpg)](https://www.youtube.com/watch?v=OmLxwl7_UzQ) [![YouTube Video](https://img.youtube.com/vi/U7dZZ8w7Gi4/0.jpg)](https://www.youtube.com/watch?v=U7dZZ8w7Gi4)
Links: ## Links:
- Website: https://geysermc.org - Website: https://geysermc.org
- Docs: https://github.com/GeyserMC/Geyser/wiki - Docs: https://github.com/GeyserMC/Geyser/wiki
- Download: http://ci.geysermc.org - Download: http://ci.geysermc.org
- Discord: http://discord.geysermc.org/ - Discord: http://discord.geysermc.org/
- Donate: https://patreon.com/GeyserMC
## What's Completed ## What's Left to be Added/Fixed
- [x] Server recognized in server list - Inventories ([#67](https://github.com/GeyserMC/Geyser/pull/67))
- [x] Join detection from remote - Crafting ([#67](https://github.com/GeyserMC/Geyser/pull/67))
- [x] Online mode/auth support - Creative Mode ([#67](https://github.com/GeyserMC/Geyser/pull/67))
- [x] Chat/command support - Sounds
- [x] Scoreboard - Block Particles
- [ ] Inventory support - Block Entities ([`block-entities`](https://github.com/GeyserMC/Geyser/tree/block-entities))
- [x] Inventory viewing - Biome Colors
- [x] NBT data - Some Entity Flags
- [ ] Inventory movement (transactions) - Proper Movement
- [x] Player movement support - Support to be Ran as a Plugin ([`plugin`](https://github.com/GeyserMC/Geyser/tree/plugin))
- [x] Entity support
- [x] Player support
- [ ] Chunks
- [x] Block translation (may be missing mappings)
- [x] Block updates
- [ ] Block entities
- [x] Extra data
- [ ] Biome colors
- [x] Block break/place support
## Compiling ## Compiling
1. Clone the repo to your computer 1. Clone the repo to your computer

View file

@ -66,8 +66,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.nukkitx.protocol</groupId> <groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v388</artifactId> <artifactId>bedrock-v389</artifactId>
<version>2.4.2</version> <version>2.4.4</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -27,7 +27,7 @@ package org.geysermc.connector;
import com.nukkitx.protocol.bedrock.BedrockPacketCodec; import com.nukkitx.protocol.bedrock.BedrockPacketCodec;
import com.nukkitx.protocol.bedrock.BedrockServer; import com.nukkitx.protocol.bedrock.BedrockServer;
import com.nukkitx.protocol.bedrock.v388.Bedrock_v388; import com.nukkitx.protocol.bedrock.v389.Bedrock_v389;
import lombok.Getter; import lombok.Getter;
import org.fusesource.jansi.AnsiConsole; import org.fusesource.jansi.AnsiConsole;
@ -67,8 +67,7 @@ import java.util.concurrent.TimeUnit;
@Getter @Getter
public class GeyserConnector implements Connector { public class GeyserConnector implements Connector {
public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v388.V388_CODEC; public static final BedrockPacketCodec BEDROCK_PACKET_CODEC = Bedrock_v389.V389_CODEC;
public static final int BEDROCK_1_14_PROTOCOL_VERSION = 389;
public static final String NAME = "Geyser"; public static final String NAME = "Geyser";
public static final String VERSION = "1.0-SNAPSHOT"; public static final String VERSION = "1.0-SNAPSHOT";

View file

@ -45,7 +45,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
@Override @Override
public boolean handle(LoginPacket loginPacket) { public boolean handle(LoginPacket loginPacket) {
if (loginPacket.getProtocolVersion() != GeyserConnector.BEDROCK_1_14_PROTOCOL_VERSION) { if (loginPacket.getProtocolVersion() != GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion()) {
session.getUpstream().disconnect("Unsupported Bedrock version. Are you running an outdated version?"); session.getUpstream().disconnect("Unsupported Bedrock version. Are you running an outdated version?");
return true; return true;
} }
@ -72,7 +72,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler {
ResourcePackStackPacket stack = new ResourcePackStackPacket(); ResourcePackStackPacket stack = new ResourcePackStackPacket();
stack.setExperimental(false); stack.setExperimental(false);
stack.setForcedToAccept(false); stack.setForcedToAccept(false);
stack.setGameVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion()); stack.setGameVersion("*");
session.getUpstream().sendPacket(stack); session.getUpstream().sendPacket(stack);
break; break;
default: default:

View file

@ -331,7 +331,7 @@ public class GeyserSession implements Player {
startGamePacket.setMultiplayerCorrelationId(""); startGamePacket.setMultiplayerCorrelationId("");
startGamePacket.setBlockPalette(Toolbox.BLOCKS); startGamePacket.setBlockPalette(Toolbox.BLOCKS);
startGamePacket.setItemEntries(Toolbox.ITEMS); startGamePacket.setItemEntries(Toolbox.ITEMS);
startGamePacket.setVanillaVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getMinecraftVersion()); startGamePacket.setVanillaVersion("*");
// startGamePacket.setMovementServerAuthoritative(true); // startGamePacket.setMovementServerAuthoritative(true);
upstream.sendPacket(startGamePacket); upstream.sendPacket(startGamePacket);
} }

View file

@ -79,7 +79,7 @@ public class ChunkCache {
Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ()); Position blockPosition = chunkPosition.getChunkBlock(position.getX(), position.getY(), position.getZ());
if (chunk != null) { if (chunk != null) {
BlockState blockState = chunk.get(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); BlockState blockState = chunk.get(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
return TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState); return TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
} }
return BlockEntry.AIR; return BlockEntry.AIR;

View file

@ -25,23 +25,30 @@
package org.geysermc.connector.network.translators.block; package org.geysermc.connector.network.translators.block;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@Getter @Getter
@AllArgsConstructor
public class BlockEntry { public class BlockEntry {
public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0, 0); public static BlockEntry AIR = new BlockEntry("minecraft:air", 0, 0);
private String javaIdentifier; private final String javaIdentifier;
private int javaId; private final int javaId;
private final int bedrockRuntimeId;
private final boolean waterlogged;
private int bedrockId; public BlockEntry(String javaIdentifier, int javaId, int bedrockRuntimeId) {
private int bedrockData; this.javaIdentifier = javaIdentifier;
this.javaId = javaId;
this.bedrockRuntimeId = bedrockRuntimeId;
this.waterlogged = (javaIdentifier.contains("waterlogged=true")
|| javaIdentifier.startsWith("minecraft:kelp")
|| javaIdentifier.contains("seagrass")
|| javaIdentifier.startsWith("minecraft:bubble_column"));
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj == this || (obj instanceof BlockEntry && ((BlockEntry) obj).getBedrockId() == this.getBedrockId() && ((BlockEntry) obj).getJavaIdentifier().equals(this.getJavaIdentifier())); return obj == this || (obj instanceof BlockEntry && ((BlockEntry) obj).getBedrockRuntimeId() == this.getBedrockRuntimeId() && ((BlockEntry) obj).getJavaIdentifier().equals(this.getJavaIdentifier()));
} }
} }

View file

@ -3,9 +3,18 @@ package org.geysermc.connector.network.translators.block;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import org.geysermc.connector.utils.Toolbox; import org.geysermc.connector.utils.Toolbox;
public class BlockTranslator { import java.util.HashMap;
import java.util.Map;
public BlockEntry getBedrockBlock(BlockState state) { public class BlockTranslator {
private final Map<String, BlockEntry> javaIdentifierMap = new HashMap<>();
public BlockEntry getBlockEntry(BlockState state) {
return Toolbox.BLOCK_ENTRIES.get(state.getId()); return Toolbox.BLOCK_ENTRIES.get(state.getId());
} }
public BlockEntry getBlockEntry(String javaIdentifier) {
return javaIdentifierMap.computeIfAbsent(javaIdentifier, key -> Toolbox.BLOCK_ENTRIES.values()
.stream().filter(blockEntry -> blockEntry.getJavaIdentifier().equals(key)).findFirst().orElse(null));
}
} }

View file

@ -26,13 +26,9 @@
package org.geysermc.connector.network.translators.java.entity.player; package org.geysermc.connector.network.translators.java.entity.player;
import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerActionAckPacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayerActionAckPacket> { public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayerActionAckPacket> {
@ -40,18 +36,7 @@ public class JavaPlayerActionAckTranslator extends PacketTranslator<ServerPlayer
public void translate(ServerPlayerActionAckPacket packet, GeyserSession session) { public void translate(ServerPlayerActionAckPacket packet, GeyserSession session) {
switch (packet.getAction()) { switch (packet.getAction()) {
case FINISH_DIGGING: case FINISH_DIGGING:
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket(); ChunkUtils.updateBlock(session, packet.getNewState(), packet.getPosition());
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(Vector3i.from(
packet.getPosition().getX(),
packet.getPosition().getY(),
packet.getPosition().getZ()));
BlockEntry itemEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(packet.getNewState());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(itemEntry.getBedrockId() << 4 | itemEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
break; break;
} }
} }

View file

@ -1,31 +1,14 @@
package org.geysermc.connector.network.translators.java.world; package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerBlockChangePacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChangePacket> { public class JavaBlockChangeTranslator extends PacketTranslator<ServerBlockChangePacket> {
@Override @Override
public void translate(ServerBlockChangePacket packet, GeyserSession session) { public void translate(ServerBlockChangePacket packet, GeyserSession session) {
BlockChangeRecord record = packet.getRecord(); ChunkUtils.updateBlock(session, packet.getRecord().getBlock(), packet.getRecord().getPosition());
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(Vector3i.from(
record.getPosition().getX(),
record.getPosition().getY(),
record.getPosition().getZ()
));
BlockEntry itemEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(itemEntry.getBedrockId() << 4 | itemEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
} }
} }

View file

@ -27,32 +27,16 @@ package org.geysermc.connector.network.translators.java.world;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord; import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMultiBlockChangePacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.utils.ChunkUtils;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMultiBlockChangePacket> { public class JavaMultiBlockChangeTranslator extends PacketTranslator<ServerMultiBlockChangePacket> {
@Override @Override
public void translate(ServerMultiBlockChangePacket packet, GeyserSession session) { public void translate(ServerMultiBlockChangePacket packet, GeyserSession session) {
for (BlockChangeRecord record : packet.getRecords()) { for (BlockChangeRecord record : packet.getRecords()) {
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket(); ChunkUtils.updateBlock(session, record.getBlock(), record.getPosition());
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(Vector3i.from(
record.getPosition().getX(),
record.getPosition().getY(),
record.getPosition().getZ()
));
BlockEntry blockEntry = TranslatorsInit.getBlockTranslator().getBedrockBlock(record.getBlock());
updateBlockPacket.setRuntimeId(GlobalBlockPalette.getOrCreateRuntimeId(blockEntry.getBedrockId() << 4 | blockEntry.getBedrockData()));
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
} }
} }
} }

View file

@ -2,13 +2,17 @@ package org.geysermc.connector.utils;
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
import com.github.steveice10.mc.protocol.data.game.chunk.Column; import com.github.steveice10.mc.protocol.data.game.chunk.Column;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockChangeRecord;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.TranslatorsInit;
import org.geysermc.connector.network.translators.block.BlockEntry; import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.world.chunk.ChunkSection; import org.geysermc.connector.world.chunk.ChunkSection;
public class ChunkUtils { public class ChunkUtils {
public static ChunkData translateToBedrock(Column column) { public static ChunkData translateToBedrock(Column column) {
ChunkData chunkData = new ChunkData(); ChunkData chunkData = new ChunkData();
@ -29,14 +33,14 @@ public class ChunkUtils {
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
BlockState blockState = chunk.get(x, y, z); BlockState blockState = chunk.get(x, y, z);
BlockEntry block = TranslatorsInit.getBlockTranslator().getBedrockBlock(blockState); BlockEntry block = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z), section.getBlockStorageArray()[0].setFullBlock(ChunkSection.blockPosition(x, y, z),
block.getBedrockId() << 4 | block.getBedrockData()); block.getBedrockRuntimeId());
if (block.getJavaIdentifier().contains("waterlogged=true")) { if (block.isWaterlogged()) {
section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
9 << 4); // water id section.getBlockStorageArray()[1].setFullBlock(ChunkSection.blockPosition(x, y, z), water.getBedrockRuntimeId());
} }
} }
} }
@ -45,6 +49,29 @@ public class ChunkUtils {
return chunkData; return chunkData;
} }
public static void updateBlock(GeyserSession session, BlockState blockState, Position position) {
BlockEntry blockEntry = TranslatorsInit.getBlockTranslator().getBlockEntry(blockState);
Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ());
UpdateBlockPacket updateBlockPacket = new UpdateBlockPacket();
updateBlockPacket.setDataLayer(0);
updateBlockPacket.setBlockPosition(pos);
updateBlockPacket.setRuntimeId(blockEntry.getBedrockRuntimeId());
updateBlockPacket.getFlags().add(UpdateBlockPacket.Flag.NEIGHBORS);
session.getUpstream().sendPacket(updateBlockPacket);
UpdateBlockPacket waterPacket = new UpdateBlockPacket();
waterPacket.setDataLayer(1);
waterPacket.setBlockPosition(pos);
if (blockEntry.isWaterlogged()) {
BlockEntry water = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:water[level=0]");
waterPacket.setRuntimeId(water.getBedrockRuntimeId());
} else {
waterPacket.setRuntimeId(0);
}
session.getUpstream().sendPacket(waterPacket);
}
public static final class ChunkData { public static final class ChunkData {
public ChunkSection[] sections; public ChunkSection[] sections;

View file

@ -6,6 +6,7 @@ import com.nukkitx.nbt.stream.NBTInputStream;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.nbt.tag.ListTag; import com.nukkitx.nbt.tag.ListTag;
import com.nukkitx.protocol.bedrock.data.ItemData; import com.nukkitx.protocol.bedrock.data.ItemData;
import com.nukkitx.nbt.tag.Tag;
import com.nukkitx.protocol.bedrock.packet.StartGamePacket; import com.nukkitx.protocol.bedrock.packet.StartGamePacket;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
@ -14,7 +15,6 @@ import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.console.GeyserLogger; import org.geysermc.connector.console.GeyserLogger;
import org.geysermc.connector.network.translators.block.BlockEntry; import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.ItemEntry;
import org.geysermc.connector.world.GlobalBlockPalette;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
@ -34,7 +34,6 @@ public class Toolbox {
throw new AssertionError("Unable to find bedrock/runtime_block_states.dat"); throw new AssertionError("Unable to find bedrock/runtime_block_states.dat");
} }
Map<String, Integer> blockIdToIdentifier = new HashMap<>();
ListTag<CompoundTag> blocksTag; ListTag<CompoundTag> blocksTag;
NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream); NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(stream);
@ -46,15 +45,6 @@ public class Toolbox {
throw new AssertionError(ex); throw new AssertionError(ex);
} }
for (CompoundTag entry : blocksTag.getValue()) {
String name = entry.getAsCompound("block").getAsString("name");
int id = entry.getAsShort("id");
int data = entry.getAsShort("meta");
blockIdToIdentifier.put(name, id);
GlobalBlockPalette.registerMapping(id << 4 | data);
}
BLOCKS = blocksTag; BLOCKS = blocksTag;
InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/items.json"); InputStream stream2 = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/items.json");
if (stream2 == null) { if (stream2 == null) {
@ -99,16 +89,38 @@ public class Toolbox {
ex.printStackTrace(); ex.printStackTrace();
} }
int blockIndex = 0; int javaIndex = -1;
for (Map.Entry<String, Map<String, Object>> itemEntry : blocks.entrySet()) { javaLoop:
if (!blockIdToIdentifier.containsKey(itemEntry.getValue().get("bedrock_identifier"))) { for (Map.Entry<String, Map<String, Object>> javaEntry : blocks.entrySet()) {
GeyserLogger.DEFAULT.debug("Mapping " + itemEntry.getValue().get("bedrock_identifier") + " was not found for bedrock edition!"); javaIndex++;
BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, 248, 0)); // update block String wantedIdentifier = (String) javaEntry.getValue().get("bedrock_identifier");
} else { Map<String, Object> wantedStates = (Map<String, Object>) javaEntry.getValue().get("bedrock_states");
BLOCK_ENTRIES.put(blockIndex, new BlockEntry(itemEntry.getKey(), blockIndex, blockIdToIdentifier.get(itemEntry.getValue().get("bedrock_identifier")), (int) itemEntry.getValue().get("bedrock_data")));
}
blockIndex++; int bedrockIndex = -1;
bedrockLoop:
for (CompoundTag bedrockEntry : BLOCKS.getValue()) {
bedrockIndex++;
CompoundTag blockTag = bedrockEntry.getAsCompound("block");
if (blockTag.getAsString("name").equals(wantedIdentifier)) {
if (wantedStates != null) {
Map<String, Tag<?>> bedrockStates = blockTag.getAsCompound("states").getValue();
for (Map.Entry<String, Object> stateEntry : wantedStates.entrySet()) {
Tag<?> bedrockStateTag = bedrockStates.get(stateEntry.getKey());
if (bedrockStateTag == null)
continue bedrockLoop;
Object bedrockStateValue = bedrockStateTag.getValue();
if (bedrockStateValue instanceof Byte)
bedrockStateValue = ((Byte) bedrockStateValue).intValue();
if (!stateEntry.getValue().equals(bedrockStateValue))
continue bedrockLoop;
}
}
BlockEntry blockEntry = new BlockEntry(javaEntry.getKey(), javaIndex, bedrockIndex);
BLOCK_ENTRIES.put(javaIndex, blockEntry);
continue javaLoop;
}
}
GeyserLogger.DEFAULT.debug("Mapping " + javaEntry.getKey() + " was not found for bedrock edition!");
} }
InputStream creativeItemStream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/creative_items.json"); InputStream creativeItemStream = Toolbox.class.getClassLoader().getResourceAsStream("bedrock/creative_items.json");

View file

@ -1,47 +0,0 @@
package org.geysermc.connector.world;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Adapted from NukkitX: https://github.com/NukkitX/Nukkit
*/
public class GlobalBlockPalette {
private static final Int2IntMap legacyToRuntimeId = new Int2IntOpenHashMap();
private static final Int2IntMap runtimeIdToLegacy = new Int2IntOpenHashMap();
private static final AtomicInteger runtimeIdAllocator = new AtomicInteger(0);
static {
legacyToRuntimeId.defaultReturnValue(-1);
runtimeIdToLegacy.defaultReturnValue(-1);
}
public static int getOrCreateRuntimeId(int id, int meta) {
return getOrCreateRuntimeId((id << 4) | meta);
}
public static int getOrCreateRuntimeId(int legacyId) throws NoSuchElementException {
int runtimeId = legacyToRuntimeId.get(legacyId);
if (!legacyToRuntimeId.containsKey(legacyId) || runtimeId == -1) {
//runtimeId = registerMapping(runtimeIdAllocator.incrementAndGet(), legacyId);
// throw new NoSuchElementException("Unmapped block registered id:" + (legacyId >>> 4) + " meta:" + (legacyId & 0xf));
return 0;
}
return runtimeId;
}
public static int registerMapping(int legacyId) {
int runtimeId = runtimeIdAllocator.getAndIncrement();
runtimeIdToLegacy.put(runtimeId, legacyId);
legacyToRuntimeId.put(legacyId, runtimeId);
return runtimeId;
}
public static int getLegacyId(int runtimeId) {
return runtimeIdToLegacy.get(runtimeId);
}
}

View file

@ -4,7 +4,6 @@ import com.nukkitx.network.VarInts;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import org.geysermc.connector.world.GlobalBlockPalette;
import org.geysermc.connector.world.chunk.bitarray.BitArray; import org.geysermc.connector.world.chunk.bitarray.BitArray;
import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion; import org.geysermc.connector.world.chunk.bitarray.BitArrayVersion;
@ -44,11 +43,11 @@ public class BlockStorage {
} }
public synchronized int getFullBlock(int index) { public synchronized int getFullBlock(int index) {
return this.legacyIdFor(this.bitArray.get(index)); return this.palette.getInt(this.bitArray.get(index));
} }
public synchronized void setFullBlock(int index, int legacyId) { public synchronized void setFullBlock(int index, int runtimeId) {
int idx = this.idFor(legacyId); int idx = this.idFor(runtimeId);
this.bitArray.set(index, idx); this.bitArray.set(index, idx);
} }
@ -72,8 +71,7 @@ public class BlockStorage {
this.bitArray = newBitArray; this.bitArray = newBitArray;
} }
private int idFor(int legacyId) { private int idFor(int runtimeId) {
int runtimeId = GlobalBlockPalette.getOrCreateRuntimeId(legacyId);
int index = this.palette.indexOf(runtimeId); int index = this.palette.indexOf(runtimeId);
if (index != -1) { if (index != -1) {
return index; return index;
@ -91,11 +89,6 @@ public class BlockStorage {
return index; return index;
} }
private int legacyIdFor(int index) {
int runtimeId = this.palette.get(index);
return GlobalBlockPalette.getLegacyId(runtimeId);
}
public boolean isEmpty() { public boolean isEmpty() {
if (this.palette.size() == 1) { if (this.palette.size() == 1) {
return true; return true;

@ -1 +1 @@
Subproject commit 0f3d65b65076b16fc7dc9226230b31291b8f2cde Subproject commit 582fb1609ffde735e514b99550362a9a533fc88a