3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-20 06:50:09 +01:00

Improve sign editing

Dieser Commit ist enthalten in:
Camotoy 2023-05-17 20:11:14 -04:00
Ursprung 4d8cb709da
Commit b9c568733a
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
4 geänderte Dateien mit 20 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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,9 +115,17 @@ public class SignBlockEntityTranslator extends BlockEntityTranslator {
}
signText.append(finalSignLine);
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());

Datei anzeigen

@ -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")) {

Datei anzeigen

@ -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());
}
}