Skip to content

Commit 8128fb9

Browse files
committed
Fix text on signs, remove unused Minecart entity property
1 parent d7f77e8 commit 8128fb9

File tree

5 files changed

+29
-36
lines changed

5 files changed

+29
-36
lines changed

Diff for: core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,8 @@ public final class EntityDefinitions {
544544
.addTranslator(MetadataTypes.FLOAT, (minecartEntity, entityMetadata) ->
545545
// Power in Java, hurt ticks in Bedrock
546546
minecartEntity.getDirtyMetadata().put(EntityDataTypes.HURT_TICKS, Math.min((int) ((FloatEntityMetadata) entityMetadata).getPrimitiveValue(), 15)))
547-
.addTranslator(MetadataTypes.INT, MinecartEntity::setCustomBlock)
547+
.addTranslator(MetadataTypes.OPTIONAL_BLOCK_STATE, MinecartEntity::setCustomBlock)
548548
.addTranslator(MetadataTypes.INT, MinecartEntity::setCustomBlockOffset)
549-
.addTranslator(MetadataTypes.BOOLEAN, MinecartEntity::setShowCustomBlock)
550549
.build();
551550
CHEST_MINECART = EntityDefinition.inherited(MINECART.factory(), MINECART)
552551
.type(EntityType.CHEST_MINECART)

Diff for: core/src/main/java/org/geysermc/geyser/entity/type/DefaultBlockMinecartEntity.java

+5-14
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525

2626
package org.geysermc.geyser.entity.type;
2727

28-
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
29-
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
3028
import org.cloudburstmc.math.vector.Vector3f;
3129
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
3230
import org.geysermc.geyser.entity.EntityDefinition;
3331
import org.geysermc.geyser.session.GeyserSession;
32+
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
3433

3534
import java.util.UUID;
3635

@@ -58,9 +57,13 @@ public void spawnEntity() {
5857
@Override
5958
public void setCustomBlock(IntEntityMetadata entityMetadata) {
6059
customBlock = entityMetadata.getPrimitiveValue();
60+
showCustomBlock = entityMetadata.getPrimitiveValue() != 0;
6161

6262
if (showCustomBlock) {
6363
dirtyMetadata.put(EntityDataTypes.DISPLAY_BLOCK_STATE, session.getBlockMappings().getBedrockBlock(customBlock));
64+
dirtyMetadata.put(EntityDataTypes.DISPLAY_OFFSET, customBlockOffset);
65+
} else {
66+
updateDefaultBlockMetadata();
6467
}
6568
}
6669

@@ -73,18 +76,6 @@ public void setCustomBlockOffset(IntEntityMetadata entityMetadata) {
7376
}
7477
}
7578

76-
@Override
77-
public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) {
78-
if (entityMetadata.getPrimitiveValue()) {
79-
showCustomBlock = true;
80-
dirtyMetadata.put(EntityDataTypes.DISPLAY_BLOCK_STATE, session.getBlockMappings().getBedrockBlock(customBlock));
81-
dirtyMetadata.put(EntityDataTypes.DISPLAY_OFFSET, customBlockOffset);
82-
} else {
83-
showCustomBlock = false;
84-
updateDefaultBlockMetadata();
85-
}
86-
}
87-
8879
public void updateDefaultBlockMetadata() {
8980
}
9081
}

Diff for: core/src/main/java/org/geysermc/geyser/entity/type/MinecartEntity.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.geysermc.geyser.util.InteractiveTag;
3838
import org.geysermc.geyser.util.MathUtils;
3939
import org.geysermc.mcprotocollib.protocol.data.game.entity.MinecartStep;
40-
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
4140
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
4241
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
4342
import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.entity.ClientboundMoveMinecartPacket;
@@ -65,19 +64,16 @@ public MinecartEntity(GeyserSession session, int entityId, long geyserId, UUID u
6564
}
6665

6766
public void setCustomBlock(IntEntityMetadata entityMetadata) {
67+
// Optional block state -> "0" is air, aka none
68+
// Sets whether the custom block should be enabled
69+
dirtyMetadata.put(EntityDataTypes.CUSTOM_DISPLAY, (byte) (entityMetadata.getPrimitiveValue() != 0 ? 1 : 0));
6870
dirtyMetadata.put(EntityDataTypes.DISPLAY_BLOCK_STATE, session.getBlockMappings().getBedrockBlock(entityMetadata.getPrimitiveValue()));
6971
}
7072

7173
public void setCustomBlockOffset(IntEntityMetadata entityMetadata) {
7274
dirtyMetadata.put(EntityDataTypes.DISPLAY_OFFSET, entityMetadata.getPrimitiveValue());
7375
}
7476

75-
public void setShowCustomBlock(BooleanEntityMetadata entityMetadata) {
76-
// If the custom block should be enabled
77-
// Needs a byte based off of Java's boolean
78-
dirtyMetadata.put(EntityDataTypes.CUSTOM_DISPLAY, (byte) (entityMetadata.getPrimitiveValue() ? 1 : 0));
79-
}
80-
8177
@Override
8278
public void tick() {
8379
if (!session.isUsingExperimentalMinecartLogic()) {

Diff for: core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SignBlockEntityTranslator.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,20 @@ public int signWidthMax() {
7575

7676
@Override
7777
public void translateTag(GeyserSession session, NbtMapBuilder bedrockNbt, NbtMap javaNbt, BlockState blockState) {
78-
bedrockNbt.putCompound("FrontText", translateSide(javaNbt.getCompound("front_text")));
79-
bedrockNbt.putCompound("BackText", translateSide(javaNbt.getCompound("back_text")));
78+
bedrockNbt.putCompound("FrontText", translateSide(session, javaNbt.getCompound("front_text")));
79+
bedrockNbt.putCompound("BackText", translateSide(session, javaNbt.getCompound("back_text")));
8080
bedrockNbt.putBoolean("IsWaxed", javaNbt.getBoolean("is_waxed"));
8181
}
8282

83-
private NbtMap translateSide(NbtMap javaNbt) {
83+
private NbtMap translateSide(GeyserSession session, NbtMap javaNbt) {
8484
NbtMapBuilder builder = NbtMap.builder();
8585

8686
StringBuilder signText = new StringBuilder();
87-
List<String> messages = javaNbt.getList("messages", NbtType.STRING);
87+
List<?> rawMessages = javaNbt.getList("messages", NbtType.COMPOUND);
88+
if (rawMessages.isEmpty()) {
89+
rawMessages = javaNbt.getList("messages", NbtType.STRING);
90+
}
91+
List<String> messages = MessageTranslator.signTextFromNbtTag(session, rawMessages);
8892
if (!messages.isEmpty()) {
8993
var it = messages.iterator();
9094
while (it.hasNext()) {

Diff for: core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525

2626
package org.geysermc.geyser.translator.text;
2727

28-
import java.util.ArrayList;
29-
import java.util.List;
3028
import net.kyori.adventure.text.Component;
3129
import net.kyori.adventure.text.JoinConfiguration;
3230
import net.kyori.adventure.text.ScoreComponent;
@@ -57,6 +55,9 @@
5755
import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatType;
5856
import org.geysermc.mcprotocollib.protocol.data.game.chat.ChatTypeDecoration;
5957

58+
import java.util.ArrayList;
59+
import java.util.List;
60+
6061
public class MessageTranslator {
6162
// These are used for handling the translations of the messages
6263
// Custom instead of TranslatableComponentRenderer#usingTranslationSource so we don't need to worry about finding a Locale class
@@ -202,13 +203,6 @@ private static String convertMessage(Component message, String locale, boolean a
202203
}
203204
}
204205

205-
/**
206-
* Convenience method for locale getting.
207-
*/
208-
public static String convertJsonMessage(GeyserSession session, String message) {
209-
return convertJsonMessage(message, session.locale());
210-
}
211-
212206
public static String convertJsonMessage(String message, String locale) {
213207
return convertMessage(GSON_SERIALIZER.deserialize(message), locale);
214208
}
@@ -448,6 +442,15 @@ public static Component componentFromNbtTag(Object nbtTag) {
448442
return componentFromNbtTag(nbtTag, Style.empty());
449443
}
450444

445+
public static List<String> signTextFromNbtTag(GeyserSession session, List<?> nbtTag) {
446+
var components = componentsFromNbtList(nbtTag, Style.empty());
447+
List<String> messages = new ArrayList<>();
448+
for (Component component : components) {
449+
messages.add(convertMessageRaw(component, session.locale()));
450+
}
451+
return messages;
452+
}
453+
451454
private static Component componentFromNbtTag(Object nbtTag, Style style) {
452455
if (nbtTag instanceof String literal) {
453456
return Component.text(literal).style(style);

0 commit comments

Comments
 (0)