Improve sign editing

This commit is contained in:
Camotoy 2023-05-17 20:11:14 -04:00
parent 4d8cb709da
commit b9c568733a
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
4 changed files with 20 additions and 6 deletions

View File

@ -61,6 +61,10 @@ public final class WorldCache {
private int currentSequence;
private final Object2IntMap<Vector3i> unverifiedPredictions = new Object2IntOpenHashMap<>(1);
@Getter
@Setter
private boolean editingSignOnFront;
public WorldCache(GeyserSession session) {
this.session = session;
this.scoreboard = new Scoreboard(session);

View File

@ -84,8 +84,9 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
StringBuilder signText = new StringBuilder();
Tag messages = signData.get("messages");
if (messages instanceof ListTag listTag) {
for (int i = 0; i < listTag.size(); i++) {
String signLine = (String) listTag.get(i).getValue();
var it = listTag.iterator();
while (it.hasNext()) {
String signLine = (String) it.next().getValue();
signLine = MessageTranslator.convertMessageLenient(signLine);
// Check the character width on the sign to ensure there is no overflow that is usually hidden
@ -114,10 +115,18 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
}
signText.append(finalSignLine);
signText.append("\n");
if (it.hasNext()) {
signText.append("\n");
}
}
}
// Trim extra newlines - this makes editing difficult if preserved because the cursor starts at the bottom,
// Which can easily go over the screen
while (!signText.isEmpty() && signText.charAt(signText.length() - 1) == '\n') {
signText.deleteCharAt(signText.length() - 1);
}
builder.putString("Text", signText.toString());
// Java Edition 1.14 added the ability to change the text color of the whole sign using dye

View File

@ -44,9 +44,8 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
NbtMap tag = packet.getData();
String id = tag.getString("id");
if (id.equals("Sign")) {
// The other side is called... you guessed it... BackText
String text = MessageTranslator.convertToPlainText(
tag.getCompound("FrontText").getString("Text"));
tag.getCompound(session.getWorldCache().isEditingSignOnFront() ? "FrontText" : "BackText").getString("Text"));
// Note: as of 1.18.30, only one packet is sent from Bedrock when the sign is finished.
// Previous versions did not have this behavior.
StringBuilder newMessage = new StringBuilder();
@ -108,7 +107,7 @@ public class BedrockBlockEntityDataTranslator extends PacketTranslator<BlockEnti
// Put the final line on since it isn't done in the for loop
if (iterator < lines.length) lines[iterator] = newMessage.toString();
Vector3i pos = Vector3i.from(tag.getInt("x"), tag.getInt("y"), tag.getInt("z"));
ServerboundSignUpdatePacket signUpdatePacket = new ServerboundSignUpdatePacket(pos, lines, true);
ServerboundSignUpdatePacket signUpdatePacket = new ServerboundSignUpdatePacket(pos, lines, session.getWorldCache().isEditingSignOnFront());
session.sendDownstreamPacket(signUpdatePacket);
} else if (id.equals("JigsawBlock")) {

View File

@ -40,5 +40,7 @@ public class JavaOpenSignEditorTranslator extends PacketTranslator<ClientboundOp
openSignPacket.setPosition(packet.getPosition());
openSignPacket.setFrontSide(packet.isFrontText());
session.sendUpstreamPacket(openSignPacket);
session.getWorldCache().setEditingSignOnFront(packet.isFrontText());
}
}