Skip to content

Commit 1e75b88

Browse files
authored
Merge pull request GeyserMC#1 from davchoo/feature/blocky
Fix light components and overriding inventory blocks
2 parents 77d9919 + 0f0308b commit 1e75b88

5 files changed

Lines changed: 46 additions & 50 deletions

File tree

core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ public boolean prepareInventory(InventoryTranslator translator, GeyserSession se
7676
// (This could be a virtual inventory that the player is opening)
7777
if (checkInteractionPosition(session)) {
7878
// Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid
79+
// and the bedrock block is vanilla
7980
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
80-
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
81-
if (isValidBlock(javaBlockString)) {
82-
// We can safely use this block
83-
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
84-
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
85-
setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId);
86-
87-
return true;
81+
if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) {
82+
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
83+
if (isValidBlock(javaBlockString)) {
84+
// We can safely use this block
85+
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
86+
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
87+
setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId);
88+
89+
return true;
90+
}
8891
}
8992
}
9093

@@ -96,7 +99,7 @@ public boolean prepareInventory(InventoryTranslator translator, GeyserSession se
9699
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
97100
blockPacket.setDataLayer(0);
98101
blockPacket.setBlockPosition(position);
99-
blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState));
102+
blockPacket.setRuntimeId(session.getBlockMappings().getVanillaBedrockBlockId(defaultJavaBlockState));
100103
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
101104
session.sendUpstreamPacket(blockPacket);
102105
inventory.setHolderPosition(position);

core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public class BlockRegistries {
118118

119119
static {
120120
CustomSkullRegistryPopulator.populate();
121-
BlockRegistryPopulator.populate();
121+
BlockRegistryPopulator.registerJavaBlocks();
122122
COLLISIONS = IntMappedRegistry.create(Pair.of("org.geysermc.geyser.translator.collision.CollisionRemapper", "mappings/collision.json"), CollisionRegistryLoader::new);
123123
CustomBlockRegistryPopulator.registerCustomBedrockBlocks();
124124
BlockRegistryPopulator.registerBedrockBlocks();

core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ public final class BlockRegistryPopulator {
7474
*/
7575
private static JsonNode BLOCKS_JSON;
7676

77-
public static void populate() {
78-
registerJavaBlocks();
79-
// CustomBlockRegistryPopulator.registerCustomBedrockBlocks() and registerBedrockBlocks() moved to BlockRegistries to ensure correct load order
80-
81-
// Needs to be placed somewhere at some point
82-
//BLOCKS_JSON = null;
83-
}
84-
8577
public static void registerBedrockBlocks() {
8678
BiFunction<String, NbtMapBuilder, String> emptyMapper = (bedrockIdentifier, statesBuilder) -> null;
8779
ImmutableMap<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>> blockMappers = ImmutableMap.<ObjectIntPair<String>, BiFunction<String, NbtMapBuilder, String>>builder()
@@ -262,9 +254,11 @@ public static void registerBedrockBlocks() {
262254
.customBlockStateIds(customBlockStateIds)
263255
.build());
264256
}
257+
258+
BLOCKS_JSON = null;
265259
}
266260

267-
private static void registerJavaBlocks() {
261+
public static void registerJavaBlocks() {
268262
JsonNode blocksJson;
269263
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) {
270264
blocksJson = GeyserImpl.JSON_MAPPER.readTree(stream);

core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,12 @@ static NbtMap convertComponents(CustomBlockComponents components, int protocolVe
254254
}
255255
if (components.lightEmission() != null) {
256256
builder.putCompound("minecraft:light_emission", NbtMap.builder()
257-
.putInt("value", components.lightEmission())
257+
.putByte("emission", components.lightEmission().byteValue())
258258
.build());
259259
}
260-
// This is supposed to be sent as "light_dampening" since "block_light_filter" is the old value
261-
// However, it seems they forgot to actually update it on the network despite all the documentation changing
262-
// So we'll send this for now
263260
if (components.lightDampening() != null) {
264-
builder.putCompound("minecraft:block_light_filter", NbtMap.builder()
265-
.putByte("value", components.lightDampening().byteValue())
261+
builder.putCompound("minecraft:light_dampening", NbtMap.builder()
262+
.putByte("lightLevel", components.lightDampening().byteValue())
266263
.build());
267264
}
268265
if (components.rotation() != null) {

core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,32 @@ public boolean prepareInventory(GeyserSession session, Inventory inventory) {
5555
// See BlockInventoryHolder - same concept there except we're also dealing with a specific block state
5656
if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
5757
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
58-
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
59-
if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest"))
60-
&& !javaBlockString[1].contains("type=single")) {
61-
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
62-
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
63-
64-
NbtMapBuilder tag = NbtMap.builder()
65-
.putString("id", "Chest")
66-
.putInt("x", session.getLastInteractionBlockPosition().getX())
67-
.putInt("y", session.getLastInteractionBlockPosition().getY())
68-
.putInt("z", session.getLastInteractionBlockPosition().getZ())
69-
.putString("CustomName", inventory.getTitle())
70-
.putString("id", "Chest");
71-
72-
DoubleChestValue chestValue = BlockStateValues.getDoubleChestValues().get(javaBlockId);
73-
DoubleChestBlockEntityTranslator.translateChestValue(tag, chestValue,
74-
session.getLastInteractionBlockPosition().getX(), session.getLastInteractionBlockPosition().getZ());
75-
76-
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
77-
dataPacket.setData(tag.build());
78-
dataPacket.setBlockPosition(session.getLastInteractionBlockPosition());
79-
session.sendUpstreamPacket(dataPacket);
80-
81-
return true;
58+
if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) {
59+
String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\[");
60+
if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest"))
61+
&& !javaBlockString[1].contains("type=single")) {
62+
inventory.setHolderPosition(session.getLastInteractionBlockPosition());
63+
((Container) inventory).setUsingRealBlock(true, javaBlockString[0]);
64+
65+
NbtMapBuilder tag = NbtMap.builder()
66+
.putString("id", "Chest")
67+
.putInt("x", session.getLastInteractionBlockPosition().getX())
68+
.putInt("y", session.getLastInteractionBlockPosition().getY())
69+
.putInt("z", session.getLastInteractionBlockPosition().getZ())
70+
.putString("CustomName", inventory.getTitle())
71+
.putString("id", "Chest");
72+
73+
DoubleChestValue chestValue = BlockStateValues.getDoubleChestValues().get(javaBlockId);
74+
DoubleChestBlockEntityTranslator.translateChestValue(tag, chestValue,
75+
session.getLastInteractionBlockPosition().getX(), session.getLastInteractionBlockPosition().getZ());
76+
77+
BlockEntityDataPacket dataPacket = new BlockEntityDataPacket();
78+
dataPacket.setData(tag.build());
79+
dataPacket.setBlockPosition(session.getLastInteractionBlockPosition());
80+
session.sendUpstreamPacket(dataPacket);
81+
82+
return true;
83+
}
8284
}
8385
}
8486

@@ -88,7 +90,7 @@ public boolean prepareInventory(GeyserSession session, Inventory inventory) {
8890
}
8991

9092
Vector3i pairPosition = position.add(Vector3i.UNIT_X);
91-
int bedrockBlockId = session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState);
93+
int bedrockBlockId = session.getBlockMappings().getVanillaBedrockBlockId(defaultJavaBlockState);
9294

9395
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
9496
blockPacket.setDataLayer(0);

0 commit comments

Comments
 (0)