mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Attempt to fix signs. Partly worked
This commit is contained in:
parent
c389e0e170
commit
c307b91b10
5 changed files with 127 additions and 85 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
package org.geysermc.connector.network.translators;
|
package org.geysermc.connector.network.translators;
|
||||||
|
|
||||||
|
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||||
|
import com.nukkitx.nbt.tag.CompoundTag;
|
||||||
import com.nukkitx.nbt.tag.IntTag;
|
import com.nukkitx.nbt.tag.IntTag;
|
||||||
import com.nukkitx.nbt.tag.StringTag;
|
import com.nukkitx.nbt.tag.StringTag;
|
||||||
import com.nukkitx.nbt.tag.Tag;
|
import com.nukkitx.nbt.tag.Tag;
|
||||||
|
|
@ -83,11 +85,9 @@ public class BlockEntityUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Tag<?>> getExtraTags(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
|
public static CompoundTag getExtraTags(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
|
||||||
List<Tag<?>> list = new ArrayList<>();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MAPPINGS.get(tag.get("id").getValue()).getExtraTags(tag);
|
return MAPPINGS.get(tag.get("id").getValue()).getExtraTags(tag);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
int x = ((Number) tag.getValue().get("x").getValue()).intValue();
|
int x = ((Number) tag.getValue().get("x").getValue()).intValue();
|
||||||
int y = ((Number) tag.getValue().get("y").getValue()).intValue();
|
int y = ((Number) tag.getValue().get("y").getValue()).intValue();
|
||||||
|
|
@ -95,17 +95,11 @@ public class BlockEntityUtils {
|
||||||
|
|
||||||
String id = BlockEntityUtils.getBedrockID((String) tag.get("id").getValue());
|
String id = BlockEntityUtils.getBedrockID((String) tag.get("id").getValue());
|
||||||
|
|
||||||
list.add(new IntTag("x", x));
|
return CompoundTagBuilder.builder().intTag("x", x).intTag("y", y).intTag("z", z).stringTag("id" , id).build("");
|
||||||
list.add(new IntTag("y", y));
|
|
||||||
list.add(new IntTag("z", z));
|
|
||||||
|
|
||||||
list.add(new StringTag("id", id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class ExtraDataMapper {
|
public static abstract class ExtraDataMapper {
|
||||||
public abstract List<Tag<?>> getExtraTags(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag);
|
public abstract CompoundTag getExtraTags(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,37 @@
|
||||||
package org.geysermc.connector.network.translators.blockentity;
|
package org.geysermc.connector.network.translators.blockentity;
|
||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.nukkitx.nbt.tag.IntTag;
|
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||||
import com.nukkitx.nbt.tag.StringTag;
|
|
||||||
import com.nukkitx.nbt.tag.Tag;
|
|
||||||
import org.geysermc.connector.network.translators.BlockEntityUtils;
|
import org.geysermc.connector.network.translators.BlockEntityUtils;
|
||||||
|
import org.geysermc.connector.utils.MessageUtils;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class SignDataMapper extends BlockEntityUtils.ExtraDataMapper {
|
public class SignDataMapper extends BlockEntityUtils.ExtraDataMapper {
|
||||||
@Override
|
@Override
|
||||||
public List<Tag<?>> getExtraTags(CompoundTag tag) {
|
public com.nukkitx.nbt.tag.CompoundTag getExtraTags(CompoundTag tag) {
|
||||||
List<Tag<?>> list = new ArrayList<>();
|
String text = c(tag.get("Text1").getValue().toString()) + "\n" +
|
||||||
|
c(tag.get("Text2").getValue().toString()) + "\n" +
|
||||||
|
c(tag.get("Text3").getValue().toString()) + "\n" +
|
||||||
|
c(tag.get("Text4").getValue().toString());
|
||||||
|
|
||||||
list.add(new StringTag("Text", tag.get("Text1").getValue().toString() + "\n" +
|
|
||||||
tag.get("Text2").getValue().toString() + "\n" +
|
|
||||||
tag.get("Text3").getValue().toString() + "\n" +
|
|
||||||
tag.get("Text4").getValue().toString()));
|
|
||||||
int x = ((Number) tag.getValue().get("x").getValue()).intValue();
|
int x = ((Number) tag.getValue().get("x").getValue()).intValue();
|
||||||
int y = ((Number) tag.getValue().get("y").getValue()).intValue();
|
int y = ((Number) tag.getValue().get("y").getValue()).intValue();
|
||||||
int z = ((Number) tag.getValue().get("z").getValue()).intValue();
|
int z = ((Number) tag.getValue().get("z").getValue()).intValue();
|
||||||
|
|
||||||
String id = BlockEntityUtils.getBedrockID((String) tag.get("id").getValue());
|
String id = BlockEntityUtils.getBedrockID((String) tag.get("id").getValue());
|
||||||
|
|
||||||
list.add(new IntTag("x", x));
|
System.out.println(text);
|
||||||
list.add(new IntTag("y", y));
|
|
||||||
list.add(new IntTag("z", z));
|
|
||||||
|
|
||||||
list.add(new StringTag("id", id));
|
return CompoundTagBuilder.builder()
|
||||||
|
.stringTag("id", id)
|
||||||
|
.stringTag("Text", text)
|
||||||
|
.intTag("x", x)
|
||||||
|
.intTag("y", y)
|
||||||
|
.intTag("z", z)
|
||||||
|
.build("");
|
||||||
|
}
|
||||||
|
|
||||||
return list;
|
//One letter name because I rly don't want to make the code at the top more than whats already there.
|
||||||
|
private String c(String string) {
|
||||||
|
return MessageUtils.getBedrockMessage(string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,10 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
import com.nukkitx.nbt.tag.CompoundTag;
|
import com.nukkitx.nbt.tag.CompoundTag;
|
||||||
import com.nukkitx.nbt.tag.Tag;
|
|
||||||
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.BlockEntityUtils;
|
import org.geysermc.connector.network.translators.BlockEntityUtils;
|
||||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class JavaUpdateTileEntityPacketTranslator extends PacketTranslator<ServerUpdateTileEntityPacket> {
|
public class JavaUpdateTileEntityPacketTranslator extends PacketTranslator<ServerUpdateTileEntityPacket> {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -18,12 +15,8 @@ public class JavaUpdateTileEntityPacketTranslator extends PacketTranslator<Serve
|
||||||
BlockEntityDataPacket bedrock = new BlockEntityDataPacket();
|
BlockEntityDataPacket bedrock = new BlockEntityDataPacket();
|
||||||
|
|
||||||
Position pos = packet.getPosition();
|
Position pos = packet.getPosition();
|
||||||
Map<String, Tag<?>> map = new HashMap<>();
|
|
||||||
|
|
||||||
for(Tag<?> tag : BlockEntityUtils.getExtraTags(packet.getNbt())) {
|
bedrock.setData(BlockEntityUtils.getExtraTags(packet.getNbt()));
|
||||||
map.put(tag.getName(), tag);
|
|
||||||
}
|
|
||||||
bedrock.setData(new CompoundTag("", map));
|
|
||||||
bedrock.setBlockPosition(Vector3i.from(pos.getX(), pos.getY(), pos.getZ()));
|
bedrock.setBlockPosition(Vector3i.from(pos.getX(), pos.getY(), pos.getZ()));
|
||||||
|
|
||||||
session.getUpstream().sendPacketImmediately(bedrock);
|
session.getUpstream().sendPacketImmediately(bedrock);
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,11 @@ package org.geysermc.connector.utils;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
import com.github.steveice10.mc.protocol.data.game.chunk.Chunk;
|
||||||
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
import com.github.steveice10.mc.protocol.data.game.chunk.Column;
|
||||||
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
|
||||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.nukkitx.math.vector.Vector3i;
|
||||||
|
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||||
import com.nukkitx.nbt.NbtUtils;
|
import com.nukkitx.nbt.NbtUtils;
|
||||||
import com.nukkitx.nbt.stream.NBTOutputStream;
|
import com.nukkitx.nbt.stream.NBTOutputStream;
|
||||||
import com.nukkitx.nbt.tag.IntTag;
|
import com.nukkitx.nbt.tag.IntTag;
|
||||||
|
|
@ -15,8 +18,7 @@ import org.geysermc.connector.network.translators.block.BlockEntry;
|
||||||
import org.geysermc.connector.world.chunk.ChunkSection;
|
import org.geysermc.connector.world.chunk.ChunkSection;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ChunkUtils {
|
public class ChunkUtils {
|
||||||
|
|
||||||
|
|
@ -27,30 +29,7 @@ public class ChunkUtils {
|
||||||
int chunkSectionCount = chunks.length;
|
int chunkSectionCount = chunks.length;
|
||||||
chunkData.sections = new ChunkSection[chunkSectionCount];
|
chunkData.sections = new ChunkSection[chunkSectionCount];
|
||||||
|
|
||||||
|
List<CompoundTag> tiles = new ArrayList<>(Arrays.asList(column.getTileEntities()));
|
||||||
for(CompoundTag tag : column.getTileEntities()) {
|
|
||||||
System.out.println(tag.get("id").getValue());
|
|
||||||
}
|
|
||||||
//Start work on block entities
|
|
||||||
try {
|
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
||||||
NBTOutputStream nbtStream = NbtUtils.createNetworkWriter(stream);
|
|
||||||
|
|
||||||
for (CompoundTag tag : column.getTileEntities()) {
|
|
||||||
Map<String, Tag<?>> map = new HashMap<>();
|
|
||||||
|
|
||||||
for(Tag<?> extra : BlockEntityUtils.getExtraTags(tag)) {
|
|
||||||
map.put(extra.getName(), extra);
|
|
||||||
}
|
|
||||||
|
|
||||||
nbtStream.write(new com.nukkitx.nbt.tag.CompoundTag("", map));
|
|
||||||
}
|
|
||||||
|
|
||||||
chunkData.blockEntities = stream.toByteArray();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) {
|
for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) {
|
||||||
chunkData.sections[chunkY] = new ChunkSection();
|
chunkData.sections[chunkY] = new ChunkSection();
|
||||||
|
|
@ -78,6 +57,26 @@ public class ChunkUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Start work on block entities
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
|
NBTOutputStream nbtStream = NbtUtils.createNetworkWriter(stream);
|
||||||
|
|
||||||
|
for (CompoundTag tag : tiles) {
|
||||||
|
try {
|
||||||
|
nbtStream.write(BlockEntityUtils.getExtraTags(tag));
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chunkData.blockEntities = stream.toByteArray();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
return chunkData;
|
return chunkData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,22 @@ import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
static {
|
||||||
|
Map<String, ChatFormat> pre = new HashMap<>();
|
||||||
|
|
||||||
|
for(ChatFormat format : ChatFormat.values()) {
|
||||||
|
pre.put(format.name().toLowerCase(), format);
|
||||||
|
}
|
||||||
|
|
||||||
|
FORMATS = pre;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Map<String, ChatFormat> FORMATS;
|
||||||
|
|
||||||
public static List<String> getTranslationParams(Message[] messages) {
|
public static List<String> getTranslationParams(Message[] messages) {
|
||||||
List<String> strings = new ArrayList<String>();
|
List<String> strings = new ArrayList<String>();
|
||||||
|
|
@ -77,6 +90,43 @@ public class MessageUtils {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getBedrockMessage(String message) {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
JsonObject object = parser.parse(message).getAsJsonObject();
|
||||||
|
|
||||||
|
String ret = "";
|
||||||
|
|
||||||
|
if(object.has("color")) {
|
||||||
|
ret+=ChatColor.valueOf(object.getAsJsonObject().get("color").getAsString().toUpperCase());
|
||||||
|
}
|
||||||
|
for(String string : FORMATS.keySet()) {
|
||||||
|
if(object.has(string) && object.get(string).getAsBoolean()) {
|
||||||
|
ret+=getFormat(FORMATS.get(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(object.has("extra")) {
|
||||||
|
for(JsonElement element : object.get("extra").getAsJsonArray()) {
|
||||||
|
if(element.isJsonObject()) {
|
||||||
|
if(object.has("color")) {
|
||||||
|
ret+=ChatColor.valueOf(object.getAsJsonObject().get("color").getAsString().toUpperCase());
|
||||||
|
}
|
||||||
|
for(String string : FORMATS.keySet()) {
|
||||||
|
if(object.has(string) && object.get(string).getAsBoolean()) {
|
||||||
|
ret+=getFormat(FORMATS.get(string));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ret+=element.getAsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret+=object.get("text").getAsString();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
private static String getColor(ChatColor color) {
|
private static String getColor(ChatColor color) {
|
||||||
String base = "\u00a7";
|
String base = "\u00a7";
|
||||||
switch (color) {
|
switch (color) {
|
||||||
|
|
@ -141,28 +191,7 @@ public class MessageUtils {
|
||||||
private static String getFormat(List<ChatFormat> formats) {
|
private static String getFormat(List<ChatFormat> formats) {
|
||||||
String str = "";
|
String str = "";
|
||||||
for (ChatFormat cf : formats) {
|
for (ChatFormat cf : formats) {
|
||||||
String base = "\u00a7";
|
str += getFormat(cf);
|
||||||
switch (cf) {
|
|
||||||
case OBFUSCATED:
|
|
||||||
base += "k";
|
|
||||||
break;
|
|
||||||
case BOLD:
|
|
||||||
base += "l";
|
|
||||||
break;
|
|
||||||
case STRIKETHROUGH:
|
|
||||||
base += "m";
|
|
||||||
break;
|
|
||||||
case UNDERLINED:
|
|
||||||
base += "n";
|
|
||||||
break;
|
|
||||||
case ITALIC:
|
|
||||||
base += "o";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
str += base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
|
@ -208,4 +237,29 @@ public class MessageUtils {
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final String getFormat(ChatFormat cf) {
|
||||||
|
String base = "\u00a7";
|
||||||
|
switch (cf) {
|
||||||
|
case OBFUSCATED:
|
||||||
|
base += "k";
|
||||||
|
break;
|
||||||
|
case BOLD:
|
||||||
|
base += "l";
|
||||||
|
break;
|
||||||
|
case STRIKETHROUGH:
|
||||||
|
base += "m";
|
||||||
|
break;
|
||||||
|
case UNDERLINED:
|
||||||
|
base += "n";
|
||||||
|
break;
|
||||||
|
case ITALIC:
|
||||||
|
base += "o";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue