Fix Block IDs

Quick fix. Might have a different method for getting block IDs in the future
This commit is contained in:
AJ Ferguson 2020-02-12 22:29:44 -09:00
parent b1a0ed3e91
commit bf1835e691
4 changed files with 25 additions and 13 deletions

View file

@ -48,6 +48,7 @@ public class BlockTranslator {
private static final Int2IntMap JAVA_TO_BEDROCK_BLOCK_MAP = new Int2IntOpenHashMap(); private static final Int2IntMap JAVA_TO_BEDROCK_BLOCK_MAP = new Int2IntOpenHashMap();
private static final Int2ObjectMap<BlockState> BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>(); private static final Int2ObjectMap<BlockState> BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>();
private static final Map<String, BlockState> JAVA_ID_BLOCK_MAP = new HashMap<>();
private static final IntSet WATERLOGGED = new IntOpenHashSet(); private static final IntSet WATERLOGGED = new IntOpenHashSet();
private static final int BLOCK_STATE_VERSION = 17760256; private static final int BLOCK_STATE_VERSION = 17760256;
@ -89,18 +90,21 @@ public class BlockTranslator {
javaRuntimeId++; javaRuntimeId++;
Map.Entry<String, JsonNode> entry = blocksIterator.next(); Map.Entry<String, JsonNode> entry = blocksIterator.next();
String javaId = entry.getKey(); String javaId = entry.getKey();
BlockState javaBlockState = new BlockState(javaRuntimeId);
CompoundTag blockTag = buildBedrockState(entry.getValue()); CompoundTag blockTag = buildBedrockState(entry.getValue());
JAVA_ID_BLOCK_MAP.put(javaId, javaBlockState);
if ("minecraft:water[level=0]".equals(javaId)) { if ("minecraft:water[level=0]".equals(javaId)) {
waterRuntimeId = bedrockRuntimeId; waterRuntimeId = bedrockRuntimeId;
} }
boolean waterlogged = entry.getValue().has("waterlogged") && entry.getValue().get("waterlogged").booleanValue(); boolean waterlogged = entry.getValue().has("waterlogged") && entry.getValue().get("waterlogged").booleanValue();
if (waterlogged) { if (waterlogged) {
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId | 1 << 31, new BlockState(javaRuntimeId)); BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId | 1 << 31, javaBlockState);
WATERLOGGED.add(javaRuntimeId); WATERLOGGED.add(javaRuntimeId);
} else { } else {
BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, new BlockState(javaRuntimeId)); BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId, javaBlockState);
} }
CompoundTag runtimeTag = blockStateMap.remove(blockTag); CompoundTag runtimeTag = blockStateMap.remove(blockTag);
@ -175,6 +179,10 @@ public class BlockTranslator {
return BEDROCK_TO_JAVA_BLOCK_MAP.get(bedrockId); return BEDROCK_TO_JAVA_BLOCK_MAP.get(bedrockId);
} }
public static BlockState getJavaBlockState(String javaId) {
return JAVA_ID_BLOCK_MAP.get(javaId);
}
public static boolean isWaterlogged(BlockState state) { public static boolean isWaterlogged(BlockState state) {
return WATERLOGGED.contains(state.getId()); return WATERLOGGED.contains(state.getId());
} }

View file

@ -25,10 +25,11 @@
package org.geysermc.connector.network.translators.inventory; package org.geysermc.connector.network.translators.inventory;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.nukkitx.protocol.bedrock.data.ContainerType; import com.nukkitx.protocol.bedrock.data.ContainerType;
import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.block.BlockTranslator;
import org.geysermc.connector.network.translators.inventory.holder.BlockInventoryHolder; import org.geysermc.connector.network.translators.inventory.holder.BlockInventoryHolder;
import org.geysermc.connector.network.translators.inventory.holder.InventoryHolder; import org.geysermc.connector.network.translators.inventory.holder.InventoryHolder;
import org.geysermc.connector.network.translators.inventory.updater.InventoryUpdater; import org.geysermc.connector.network.translators.inventory.updater.InventoryUpdater;
@ -39,7 +40,8 @@ public class BlockInventoryTranslator extends BaseInventoryTranslator {
public BlockInventoryTranslator(int size, String javaBlockIdentifier, ContainerType containerType, InventoryUpdater updater) { public BlockInventoryTranslator(int size, String javaBlockIdentifier, ContainerType containerType, InventoryUpdater updater) {
super(size); super(size);
final int blockId = TranslatorsInit.getBlockTranslator().getBlockEntry(javaBlockIdentifier).getBedrockRuntimeId(); BlockState javaBlockState = BlockTranslator.getJavaBlockState(javaBlockIdentifier);
int blockId = BlockTranslator.getBedrockBlockId(javaBlockState);
this.holder = new BlockInventoryHolder(blockId, containerType); this.holder = new BlockInventoryHolder(blockId, containerType);
this.updater = updater; this.updater = updater;
} }

View file

@ -26,6 +26,7 @@
package org.geysermc.connector.network.translators.inventory; package org.geysermc.connector.network.translators.inventory;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.data.ContainerType; import com.nukkitx.protocol.bedrock.data.ContainerType;
@ -34,8 +35,7 @@ import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket;
import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.TranslatorsInit; import org.geysermc.connector.network.translators.block.BlockTranslator;
import org.geysermc.connector.network.translators.block.BlockEntry;
import org.geysermc.connector.network.translators.inventory.updater.ChestInventoryUpdater; import org.geysermc.connector.network.translators.inventory.updater.ChestInventoryUpdater;
import org.geysermc.connector.network.translators.inventory.updater.InventoryUpdater; import org.geysermc.connector.network.translators.inventory.updater.InventoryUpdater;
@ -45,7 +45,8 @@ public class DoubleChestInventoryTranslator extends BaseInventoryTranslator {
public DoubleChestInventoryTranslator(int size) { public DoubleChestInventoryTranslator(int size) {
super(size); super(size);
this.blockId = TranslatorsInit.getBlockTranslator().getBlockEntry("minecraft:chest[facing=north,type=single,waterlogged=false]").getBedrockRuntimeId(); BlockState javaBlockState = BlockTranslator.getJavaBlockState("minecraft:chest[facing=north,type=single,waterlogged=false]");
this.blockId = BlockTranslator.getBedrockBlockId(javaBlockState);
this.updater = new ChestInventoryUpdater(54); this.updater = new ChestInventoryUpdater(54);
} }
@ -111,11 +112,11 @@ public class DoubleChestInventoryTranslator extends BaseInventoryTranslator {
public void closeInventory(GeyserSession session, Inventory inventory) { public void closeInventory(GeyserSession session, Inventory inventory) {
Vector3i holderPos = inventory.getHolderPosition(); Vector3i holderPos = inventory.getHolderPosition();
Position pos = new Position(holderPos.getX(), holderPos.getY(), holderPos.getZ()); Position pos = new Position(holderPos.getX(), holderPos.getY(), holderPos.getZ());
BlockEntry realBlock = session.getChunkCache().getBlockAt(pos); BlockState realBlock = session.getChunkCache().getBlockAt(pos);
UpdateBlockPacket blockPacket = new UpdateBlockPacket(); UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0); blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(holderPos); blockPacket.setBlockPosition(holderPos);
blockPacket.setRuntimeId(realBlock.getBedrockRuntimeId()); blockPacket.setRuntimeId(BlockTranslator.getBedrockBlockId(realBlock));
session.getUpstream().sendPacket(blockPacket); session.getUpstream().sendPacket(blockPacket);
holderPos = holderPos.add(Vector3i.UNIT_X); holderPos = holderPos.add(Vector3i.UNIT_X);
@ -124,7 +125,7 @@ public class DoubleChestInventoryTranslator extends BaseInventoryTranslator {
blockPacket = new UpdateBlockPacket(); blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0); blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(holderPos); blockPacket.setBlockPosition(holderPos);
blockPacket.setRuntimeId(realBlock.getBedrockRuntimeId()); blockPacket.setRuntimeId(BlockTranslator.getBedrockBlockId(realBlock));
session.getUpstream().sendPacket(blockPacket); session.getUpstream().sendPacket(blockPacket);
} }

View file

@ -26,6 +26,7 @@
package org.geysermc.connector.network.translators.inventory.holder; package org.geysermc.connector.network.translators.inventory.holder;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
import com.nukkitx.math.vector.Vector3i; import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.tag.CompoundTag; import com.nukkitx.nbt.tag.CompoundTag;
import com.nukkitx.protocol.bedrock.data.ContainerType; import com.nukkitx.protocol.bedrock.data.ContainerType;
@ -35,7 +36,7 @@ import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.geysermc.connector.inventory.Inventory; import org.geysermc.connector.inventory.Inventory;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.block.BlockEntry; import org.geysermc.connector.network.translators.block.BlockTranslator;
import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
@AllArgsConstructor @AllArgsConstructor
@ -80,11 +81,11 @@ public class BlockInventoryHolder extends InventoryHolder {
public void closeInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) { public void closeInventory(InventoryTranslator translator, GeyserSession session, Inventory inventory) {
Vector3i holderPos = inventory.getHolderPosition(); Vector3i holderPos = inventory.getHolderPosition();
Position pos = new Position(holderPos.getX(), holderPos.getY(), holderPos.getZ()); Position pos = new Position(holderPos.getX(), holderPos.getY(), holderPos.getZ());
BlockEntry realBlock = session.getChunkCache().getBlockAt(pos); BlockState realBlock = session.getChunkCache().getBlockAt(pos);
UpdateBlockPacket blockPacket = new UpdateBlockPacket(); UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0); blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(holderPos); blockPacket.setBlockPosition(holderPos);
blockPacket.setRuntimeId(realBlock.getBedrockRuntimeId()); blockPacket.setRuntimeId(BlockTranslator.getBedrockBlockId(realBlock));
session.getUpstream().sendPacket(blockPacket); session.getUpstream().sendPacket(blockPacket);
} }
} }