Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

Feature/sign fix #552

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public static String translate(Message message) {
}
StringBuilder builder = new StringBuilder();

builder.append(toBedrockFormat(message.getStyle().getFormats()));
builder.append(toBedrockColor(message.getStyle().getColor()));
builder.append(toBedrockFormat(message.getStyle().getFormats()));
builder.append(message.getText());
builder.append(toBedrockColor(ChatColor.NONE));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
package org.dragonet.proxy.network.translator.misc.tile;

import com.github.steveice10.mc.protocol.data.message.ChatColor;
import com.github.steveice10.mc.protocol.data.message.Message;
import com.github.steveice10.mc.protocol.data.message.MessageStyle;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.nukkitx.nbt.CompoundTagBuilder;
import lombok.extern.log4j.Log4j2;
james090500 marked this conversation as resolved.
Show resolved Hide resolved
import org.dragonet.proxy.network.translator.misc.MessageTranslator;
import org.dragonet.proxy.util.DyeColor;
import org.dragonet.proxy.util.registry.BlockEntityRegisterInfo;

@Log4j2
@BlockEntityRegisterInfo(bedrockId = "Sign")

public class SignBlockEntityTranslator implements IBlockEntityTranslator {

@Override
public void translateToBedrock(CompoundTagBuilder builder, CompoundTag javaTag, String javaId) {
StringBuilder signText = new StringBuilder();
for(int i = 0; i < 4; i++) {
int currentLine = i+1;
Message message = Message.fromString(javaTag.get("Text" + currentLine).getValue().toString());

//Signs have different color names than chat color ugh
String color = ChatColor.BLACK.toString();
if(javaTag.contains("color")) {
color = javaTag.get("Color").getValue().toString()
.replaceAll("\\bblue\\b", "dark_blue")
.replaceAll("\\bgray\\b", "dark_gray")
.replaceAll("\\blight_blue\\b", "blue")
.replaceAll("\\blight_gray\\b", "gray");
String signColor = javaTag.get("Color").getValue().toString().toUpperCase();
if(!signColor.equalsIgnoreCase("BLACK")) {
message.getExtra().forEach(messageExtra -> {
messageExtra.setStyle(new MessageStyle().setColor(DyeColor.valueOf(signColor).getChatColor()));
});
}

//Lambda requiring stupid stuff
String finalColor = color;
String signLine = MessageTranslator.translate(message);

Message message = Message.fromString(javaTag.get("Text" + currentLine).getValue().toString());
message.getExtra().forEach(messageExtra -> {
messageExtra.setStyle(new MessageStyle().setColor(ChatColor.byName(finalColor)));
});
signText.append(MessageTranslator.translate(message)).append("\n");
if(signLine.contains("="))
signLine = signLine.substring(0, Math.min(signLine.length(), 18));

signText.append(signLine).append("\n");
}

builder.stringTag("Text", signText.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public void translateToBedrock(CompoundTagBuilder builder, CompoundTag javaTag,

String skullType = javaId.substring(0, javaId.indexOf("[")).replace("minecraft:", "");
if(javaId.contains("wall")) {
skullType = skullType.replace("_wall_head", "").toUpperCase();
builder.byteTag("SkullType", (byte) SkullType.valueOf(skullType).getId());
skullType = skullType.replace("_wall_skull", "_skull");
skullType = skullType.replace("_wall_head", "");
builder.byteTag("SkullType", (byte) SkullType.valueOf(skullType.toUpperCase()).getId());
} else {
skullType = skullType.replace("_head", "").toUpperCase();
float rotation = getRotation(Float.parseFloat(javaId.substring(javaId.indexOf("rotation=") + 9, javaId.indexOf("]"))));
Expand Down
39 changes: 22 additions & 17 deletions proxy/src/main/java/org/dragonet/proxy/util/DyeColor.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package org.dragonet.proxy.util;

import com.github.steveice10.mc.protocol.data.message.ChatColor;
import lombok.Getter;

public enum DyeColor {
WHITE(0, "white"),
ORANGE(1, "orange"),
MAGENTA(2, "magenta"),
LIGHT_BLUE(3, "light_blue"),
YELLOW(4, "yellow"),
LIME(5, "lime"),
PINK(6, "pink"),
GRAY(7, "gray"),
LIGHT_GRAY(8, "light_gray"),
CYAN(9, "cyan"),
PURPLE(10, "purple"),
BLUE(11, "blue"),
BROWN(12, "brown"),
GREEN(13, "green"),
RED(14, "red"),
BLACK(15, "black");
WHITE(0, "white", ChatColor.WHITE),
ORANGE(1, "orange", ChatColor.GOLD),
MAGENTA(2, "magenta", ChatColor.LIGHT_PURPLE),
LIGHT_BLUE(3, "light_blue", ChatColor.BLUE),
YELLOW(4, "yellow", ChatColor.YELLOW),
LIME(5, "lime", ChatColor.GREEN),
PINK(6, "pink", ChatColor.LIGHT_PURPLE),
GRAY(7, "gray", ChatColor.DARK_GRAY),
LIGHT_GRAY(8, "light_gray", ChatColor.GRAY),
CYAN(9, "cyan", ChatColor.DARK_AQUA),
PURPLE(10, "purple", ChatColor.DARK_PURPLE),
BLUE(11, "blue", ChatColor.DARK_BLUE),
BROWN(12, "brown", ChatColor.BLACK),
GREEN(13, "green", ChatColor.DARK_GREEN),
RED(14, "red", ChatColor.RED),
BLACK(15, "black", ChatColor.BLACK);

@Getter
private int id;
private String name;

DyeColor(int id, String name) {
@Getter
private ChatColor chatColor;

DyeColor(int id, String name, ChatColor chatColor) {
this.id = id;
this.name = name;
this.chatColor = chatColor;
}
}