Skip to content

Commit

Permalink
Fix banner block entity base colors with no patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Apr 29, 2024
1 parent e8c1c22 commit 88ae447
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package org.geysermc.geyser.translator.level.block.entity;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.geysermc.geyser.session.GeyserSession;
Expand All @@ -40,9 +41,13 @@ protected BlockEntityTranslator() {

public abstract void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, int blockState);

public NbtMap getBlockEntityTag(GeyserSession session, BlockEntityType type, int x, int y, int z, NbtMap javaNbt, int blockState) {
public NbtMap getBlockEntityTag(GeyserSession session, BlockEntityType type, int x, int y, int z, @Nullable NbtMap javaNbt, int blockState) {
NbtMapBuilder tagBuilder = getConstantBedrockTag(type, x, y, z);
translateTag(session, tagBuilder, javaNbt, blockState);
if (javaNbt != null || this instanceof RequiresBlockState) {
// Always process tags if the block state is part of the tag.
// See: banner base colors.
translateTag(session, tagBuilder, javaNbt, blockState);
}
return tagBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
public class SpawnerBlockEntityTranslator extends BlockEntityTranslator {

@Override
public NbtMap getBlockEntityTag(GeyserSession session, BlockEntityType type, int x, int y, int z, NbtMap javaNbt, int blockState) {
public NbtMap getBlockEntityTag(GeyserSession session, BlockEntityType type, int x, int y, int z, @Nullable NbtMap javaNbt, int blockState) {
if (javaNbt == null) {
return super.getBlockEntityTag(session, type, x, y, z, javaNbt, blockState);
}
// Sending an empty EntityIdentifier to empty the spawner is ignored by the client, so we send a whole new spawner!
// Fixes https://github.com/GeyserMC/Geyser/issues/4214
NbtMap spawnData = javaNbt.getCompound("SpawnData");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package org.geysermc.geyser.translator.level.block.entity;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
Expand All @@ -39,7 +40,10 @@
public class StructureBlockBlockEntityTranslator extends BlockEntityTranslator {

@Override
public NbtMap getBlockEntityTag(GeyserSession session, BlockEntityType type, int x, int y, int z, NbtMap javaNbt, int blockState) {
public NbtMap getBlockEntityTag(GeyserSession session, BlockEntityType type, int x, int y, int z, @Nullable NbtMap javaNbt, int blockState) {
if (javaNbt == null) {
return super.getBlockEntityTag(session, type, x, y, z, javaNbt, blockState);
}
// Sending a structure with size 0 doesn't clear the outline. Hence, we have to force it by replacing the block :/
int xStructureSize = javaNbt.getInt("sizeX");
int yStructureSize = javaNbt.getInt("sizeY");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,10 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
continue;
}

if (tag != null) {
BlockEntityTranslator blockEntityTranslator = BlockEntityUtils.getBlockEntityTranslator(type);
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(session, type, x + chunkBlockX, y, z + chunkBlockZ, tag, blockState));
} else {
// Since 1.20.5, tags can be null, but Bedrock still needs a default tag to render the item
bedrockBlockEntities.add(BlockEntityTranslator.getConstantBedrockTag(type, x + chunkBlockX, y, z + chunkBlockZ).build());
}
// Note that, since 1.20.5, tags can be null, but Bedrock still needs a default tag to render the item
// Also, some properties - like banner base colors - are part of the tag and is processed here.
BlockEntityTranslator blockEntityTranslator = BlockEntityUtils.getBlockEntityTranslator(type);
bedrockBlockEntities.add(blockEntityTranslator.getBlockEntityTag(session, type, x + chunkBlockX, y, z + chunkBlockZ, tag, blockState));

// Check for custom skulls
if (session.getPreferencesCache().showCustomSkulls() && type == BlockEntityType.SKULL && tag != null && tag.containsKey("profile")) {
Expand Down

0 comments on commit 88ae447

Please sign in to comment.