Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
chunks. Still don't work, but hey, it doesn't crash or hang!
Dieser Commit ist enthalten in:
Ursprung
7c807740a4
Commit
de78c93b72
@ -158,6 +158,7 @@ public class GeyserSession implements PlayerSession, Player {
|
||||
public void disconnected(DisconnectedEvent event) {
|
||||
loggedIn = false;
|
||||
connector.getLogger().info(authenticationData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason());
|
||||
event.getCause().printStackTrace();
|
||||
disconnect(event.getReason());
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerU
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerOpenWindowPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerSetSlotPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.window.ServerWindowItemsPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerNotifyClientPacket;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTimePacket;
|
||||
import com.nukkitx.nbt.CompoundTagBuilder;
|
||||
@ -94,12 +95,14 @@ import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnPla
|
||||
import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator;
|
||||
import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator;
|
||||
import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator;
|
||||
import org.geysermc.connector.network.translators.java.world.JavaChunk;
|
||||
import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator;
|
||||
import org.geysermc.connector.network.translators.java.window.JavaOpenWindowTranslator;
|
||||
import org.geysermc.connector.network.translators.java.window.JavaSetSlotTranslator;
|
||||
import org.geysermc.connector.network.translators.java.JavaTitleTranslator;
|
||||
import org.geysermc.connector.network.translators.java.world.JavaUpdateTimeTranslator;
|
||||
import org.geysermc.connector.network.translators.java.window.JavaWindowItemsTranslator;
|
||||
import org.geysermc.connector.utils.Chunks;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -158,6 +161,7 @@ public class TranslatorsInit {
|
||||
Registry.registerJava(ServerPlayerHealthPacket.class, new JavaPlayerHealthTranslator());
|
||||
|
||||
Registry.registerJava(ServerNotifyClientPacket.class, new JavaNotifyClientTranslator());
|
||||
Registry.registerJava(ServerChunkDataPacket.class, new JavaChunk());
|
||||
Registry.registerJava(ServerEntityDestroyPacket.class, new JavaEntityDestroyTranslator());
|
||||
Registry.registerJava(ServerWindowItemsPacket.class, new JavaWindowItemsTranslator());
|
||||
Registry.registerJava(ServerOpenWindowPacket.class, new JavaOpenWindowTranslator());
|
||||
|
@ -26,6 +26,7 @@
|
||||
package org.geysermc.connector.network.translators.item;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
|
||||
import com.github.steveice10.mc.protocol.data.game.world.block.BlockState;
|
||||
import com.github.steveice10.mc.protocol.data.message.Message;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
@ -53,7 +54,7 @@ import java.util.Map;
|
||||
|
||||
public class ItemTranslator {
|
||||
|
||||
public ItemStack translateToJava(ItemData data) {
|
||||
public static ItemStack translateToJava(ItemData data) {
|
||||
JavaItem javaItem = getJavaItem(data);
|
||||
|
||||
if (data.getTag() == null) {
|
||||
@ -62,7 +63,7 @@ public class ItemTranslator {
|
||||
return new ItemStack(javaItem.getId(), data.getCount(), translateToJavaNBT(data.getTag()));
|
||||
}
|
||||
|
||||
public ItemData translateToBedrock(ItemStack stack) {
|
||||
public static ItemData translateToBedrock(ItemStack stack) {
|
||||
// Most likely air if null
|
||||
if (stack == null) {
|
||||
return ItemData.AIR;
|
||||
@ -75,18 +76,24 @@ public class ItemTranslator {
|
||||
return ItemData.of(bedrockItem.getId(), (short) bedrockItem.getData(), stack.getAmount(), translateToBedrockNBT(stack.getNBT()));
|
||||
}
|
||||
|
||||
public BedrockItem getBedrockItem(ItemStack stack) {
|
||||
public static BedrockItem getBedrockItem(ItemStack stack) {
|
||||
Map<String, Object> m = Remapper.JAVA_TO_BEDROCK.get(stack.getId());
|
||||
System.out.println(stack.getId());
|
||||
return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data"));
|
||||
}
|
||||
|
||||
public JavaItem getJavaItem(ItemData data) {
|
||||
public static JavaItem getJavaItem(ItemData data) {
|
||||
Map<String, Object> m = Remapper.BEDROCK_TO_JAVA.get(data.getId()).get(data.getDamage());
|
||||
return new JavaItem((String) m.get("name"), (Integer) m.get("id"));
|
||||
}
|
||||
|
||||
public String getBedrockIdentifier(String javaIdentifier) {
|
||||
public static BedrockItem getBedrockBlock(BlockState stack) {
|
||||
Map<String, Object> m = Remapper.JAVA_TO_BEDROCK_BLOCKS.get(stack.getId());
|
||||
System.out.println(stack.getId());
|
||||
return new BedrockItem((String) m.get("name"), (Integer) m.get("id"), (Integer) m.get("data"));
|
||||
}
|
||||
|
||||
public static String getBedrockIdentifier(String javaIdentifier) {
|
||||
if (!Remapper.JAVA_TO_BEDROCK.containsKey(javaIdentifier)) {
|
||||
return javaIdentifier;
|
||||
}
|
||||
@ -98,7 +105,7 @@ public class ItemTranslator {
|
||||
return (String) Remapper.JAVA_TO_BEDROCK.get(javaIdentifier).get("name");
|
||||
}
|
||||
|
||||
public String getJavaIdentifier(String bedrockIdentifier, int data) {
|
||||
public static String getJavaIdentifier(String bedrockIdentifier, int data) {
|
||||
if (!Remapper.BEDROCK_TO_JAVA.containsKey(bedrockIdentifier)) {
|
||||
return bedrockIdentifier;
|
||||
}
|
||||
@ -106,7 +113,7 @@ public class ItemTranslator {
|
||||
return (String) Remapper.BEDROCK_TO_JAVA.get(bedrockIdentifier).get(data).get("name");
|
||||
}
|
||||
|
||||
private CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
|
||||
private static CompoundTag translateToJavaNBT(com.nukkitx.nbt.tag.CompoundTag tag) {
|
||||
CompoundTag javaTag = new CompoundTag(tag.getName());
|
||||
Map<String, Tag> javaValue = javaTag.getValue();
|
||||
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
||||
@ -123,7 +130,7 @@ public class ItemTranslator {
|
||||
return javaTag;
|
||||
}
|
||||
|
||||
private Tag translateToJavaNBT(com.nukkitx.nbt.tag.Tag tag) {
|
||||
private static Tag translateToJavaNBT(com.nukkitx.nbt.tag.Tag tag) {
|
||||
if (tag instanceof com.nukkitx.nbt.tag.ByteArrayTag) {
|
||||
com.nukkitx.nbt.tag.ByteArrayTag byteArrayTag = (com.nukkitx.nbt.tag.ByteArrayTag) tag;
|
||||
return new ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());
|
||||
@ -197,7 +204,7 @@ public class ItemTranslator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private com.nukkitx.nbt.tag.CompoundTag translateToBedrockNBT(CompoundTag tag) {
|
||||
private static com.nukkitx.nbt.tag.CompoundTag translateToBedrockNBT(CompoundTag tag) {
|
||||
Map<String, com.nukkitx.nbt.tag.Tag<?>> javaValue = new HashMap<String, com.nukkitx.nbt.tag.Tag<?>>();
|
||||
if (tag.getValue() != null && !tag.getValue().isEmpty()) {
|
||||
for (String str : tag.getValue().keySet()) {
|
||||
@ -214,7 +221,7 @@ public class ItemTranslator {
|
||||
return bedrockTag;
|
||||
}
|
||||
|
||||
private com.nukkitx.nbt.tag.Tag translateToBedrockNBT(Tag tag) {
|
||||
private static com.nukkitx.nbt.tag.Tag translateToBedrockNBT(Tag tag) {
|
||||
if (tag instanceof ByteArrayTag) {
|
||||
ByteArrayTag byteArrayTag = (ByteArrayTag) tag;
|
||||
return new com.nukkitx.nbt.tag.ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue());
|
||||
|
@ -0,0 +1,28 @@
|
||||
package org.geysermc.connector.network.translators.java.world;
|
||||
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
|
||||
import org.geysermc.connector.network.session.GeyserSession;
|
||||
import org.geysermc.connector.network.translators.PacketTranslator;
|
||||
import org.geysermc.connector.utils.Chunks;
|
||||
|
||||
public class JavaChunk extends PacketTranslator<ServerChunkDataPacket> {
|
||||
@Override
|
||||
public void translate(ServerChunkDataPacket packet, GeyserSession session) {
|
||||
LevelChunkPacket p = new LevelChunkPacket();
|
||||
|
||||
Chunks.ChunkData data = Chunks.getData(packet.getColumn());
|
||||
|
||||
p.setSubChunksLength(data.count);
|
||||
|
||||
p.setData(data.bytes);
|
||||
|
||||
p.setChunkX(packet.getColumn().getX());
|
||||
p.setChunkZ(packet.getColumn().getZ());
|
||||
|
||||
System.out.println("sent");
|
||||
|
||||
session.getUpstream().sendPacketImmediately(p);
|
||||
}
|
||||
}
|
@ -2,14 +2,18 @@ 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 gnu.trove.list.TByteList;
|
||||
import gnu.trove.list.array.TByteArrayList;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.geysermc.connector.network.translators.item.ItemTranslator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Chunks {
|
||||
|
||||
public ChunkData getData(Column c) {
|
||||
public static ChunkData getData(Column c) {
|
||||
Objects.requireNonNull(c);
|
||||
|
||||
int count = 0;
|
||||
@ -20,7 +24,51 @@ public class Chunks {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
int block = 0;
|
||||
|
||||
TByteList list = new TByteArrayList(4096 * 4);
|
||||
|
||||
for(int i = 0; i < 256; i++) {
|
||||
list.add((byte) 0);
|
||||
}
|
||||
|
||||
for(Chunk chunk : c.getChunks()) {
|
||||
if (chunk != null) {
|
||||
list.add((byte) 0);
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; x < 16; x++) {
|
||||
for (int z = 0; x < 16; x++) {
|
||||
try {
|
||||
list.add((byte) ItemTranslator.getBedrockBlock(chunk.getBlocks().get(x, y, z)).getId());
|
||||
} catch (NullPointerException e) {
|
||||
list.add((byte) 0);
|
||||
}
|
||||
|
||||
block++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; x < 16; x++) {
|
||||
for (int z = 0; x < 16; x++) {
|
||||
try {
|
||||
list.add((byte) ItemTranslator.getBedrockBlock(chunk.getBlocks().get(x, y, z)).getData());
|
||||
} catch (NullPointerException e) {
|
||||
list.add((byte) 0);
|
||||
}
|
||||
|
||||
block++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list.add((byte) 0);
|
||||
list.add((byte) 0);
|
||||
|
||||
return new ChunkData(count, list.toArray());
|
||||
}
|
||||
|
||||
@AllArgsConstructor(access = AccessLevel.PACKAGE)
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren