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;
|
||||
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.tag.IntTag;
|
||||
import com.nukkitx.nbt.tag.StringTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
|
|
@ -83,11 +85,9 @@ public class BlockEntityUtils {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static List<Tag<?>> getExtraTags(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
|
||||
List<Tag<?>> list = new ArrayList<>();
|
||||
|
||||
public static CompoundTag getExtraTags(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) {
|
||||
try {
|
||||
MAPPINGS.get(tag.get("id").getValue()).getExtraTags(tag);
|
||||
return MAPPINGS.get(tag.get("id").getValue()).getExtraTags(tag);
|
||||
} catch (Exception e) {
|
||||
int x = ((Number) tag.getValue().get("x").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());
|
||||
|
||||
list.add(new IntTag("x", x));
|
||||
list.add(new IntTag("y", y));
|
||||
list.add(new IntTag("z", z));
|
||||
|
||||
list.add(new StringTag("id", id));
|
||||
return CompoundTagBuilder.builder().intTag("x", x).intTag("y", y).intTag("z", z).stringTag("id" , id).build("");
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.nbt.tag.IntTag;
|
||||
import com.nukkitx.nbt.tag.StringTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import org.geysermc.connector.network.translators.BlockEntityUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.geysermc.connector.utils.MessageUtils;
|
||||
|
||||
public class SignDataMapper extends BlockEntityUtils.ExtraDataMapper {
|
||||
@Override
|
||||
public List<Tag<?>> getExtraTags(CompoundTag tag) {
|
||||
List<Tag<?>> list = new ArrayList<>();
|
||||
public com.nukkitx.nbt.tag.CompoundTag getExtraTags(CompoundTag tag) {
|
||||
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 y = ((Number) tag.getValue().get("y").getValue()).intValue();
|
||||
int z = ((Number) tag.getValue().get("z").getValue()).intValue();
|
||||
|
||||
String id = BlockEntityUtils.getBedrockID((String) tag.get("id").getValue());
|
||||
|
||||
list.add(new IntTag("x", x));
|
||||
list.add(new IntTag("y", y));
|
||||
list.add(new IntTag("z", z));
|
||||
System.out.println(text);
|
||||
|
||||
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.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.tag.CompoundTag;
|
||||
import com.nukkitx.nbt.tag.Tag;
|
||||
import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.BlockEntityUtils;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaUpdateTileEntityPacketTranslator extends PacketTranslator<ServerUpdateTileEntityPacket> {
|
||||
@Override
|
||||
|
|
@ -18,12 +15,8 @@ public class JavaUpdateTileEntityPacketTranslator extends PacketTranslator<Serve
|
|||
BlockEntityDataPacket bedrock = new BlockEntityDataPacket();
|
||||
|
||||
Position pos = packet.getPosition();
|
||||
Map<String, Tag<?>> map = new HashMap<>();
|
||||
|
||||
for(Tag<?> tag : BlockEntityUtils.getExtraTags(packet.getNbt())) {
|
||||
map.put(tag.getName(), tag);
|
||||
}
|
||||
bedrock.setData(new CompoundTag("", map));
|
||||
bedrock.setData(BlockEntityUtils.getExtraTags(packet.getNbt()));
|
||||
bedrock.setBlockPosition(Vector3i.from(pos.getX(), pos.getY(), pos.getZ()));
|
||||
|
||||
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.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.opennbt.tag.builtin.CompoundTag;
|
||||
import com.nukkitx.math.vector.Vector3i;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
import com.nukkitx.nbt.NbtUtils;
|
||||
import com.nukkitx.nbt.stream.NBTOutputStream;
|
||||
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 java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class ChunkUtils {
|
||||
|
||||
|
|
@ -27,30 +29,7 @@ public class ChunkUtils {
|
|||
int chunkSectionCount = chunks.length;
|
||||
chunkData.sections = new ChunkSection[chunkSectionCount];
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
List<CompoundTag> tiles = new ArrayList<>(Arrays.asList(column.getTileEntities()));
|
||||
|
||||
for (int chunkY = 0; chunkY < chunkSectionCount; chunkY++) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,22 @@ import com.google.gson.JsonParser;
|
|||
import com.google.gson.JsonPrimitive;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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) {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
|
|
@ -77,6 +90,43 @@ public class MessageUtils {
|
|||
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) {
|
||||
String base = "\u00a7";
|
||||
switch (color) {
|
||||
|
|
@ -141,28 +191,7 @@ public class MessageUtils {
|
|||
private static String getFormat(List<ChatFormat> formats) {
|
||||
String str = "";
|
||||
for (ChatFormat cf : formats) {
|
||||
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;
|
||||
}
|
||||
|
||||
str += base;
|
||||
str += getFormat(cf);
|
||||
}
|
||||
|
||||
return str;
|
||||
|
|
@ -208,4 +237,29 @@ public class MessageUtils {
|
|||
|
||||
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