Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Fix crashes.
Dieser Commit ist enthalten in:
Ursprung
2d079b2ddf
Commit
b2f366f7b4
@ -30,6 +30,7 @@ import com.flowpowered.math.vector.Vector2i;
|
|||||||
import com.flowpowered.math.vector.Vector3f;
|
import com.flowpowered.math.vector.Vector3f;
|
||||||
import com.flowpowered.math.vector.Vector3i;
|
import com.flowpowered.math.vector.Vector3i;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket;
|
||||||
|
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.CompoundTag;
|
import com.nukkitx.nbt.tag.CompoundTag;
|
||||||
@ -38,14 +39,33 @@ import com.nukkitx.protocol.bedrock.data.GamePublishSetting;
|
|||||||
import com.nukkitx.protocol.bedrock.data.GameRule;
|
import com.nukkitx.protocol.bedrock.data.GameRule;
|
||||||
import com.nukkitx.protocol.bedrock.packet.*;
|
import com.nukkitx.protocol.bedrock.packet.*;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufOutputStream;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import org.geysermc.connector.utils.GeyserUtils;
|
import org.geysermc.connector.utils.GeyserUtils;
|
||||||
import org.geysermc.connector.utils.Toolbox;
|
import org.geysermc.connector.utils.Toolbox;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class TranslatorsInit {
|
public class TranslatorsInit {
|
||||||
|
private static final CompoundTag EMPTY_TAG = CompoundTagBuilder.builder().buildRootTag();
|
||||||
|
private static final byte[] EMPTY_LEVEL_CHUNK_DATA;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
|
outputStream.write(new byte[258]); // Biomes + Border Size + Extra Data Size
|
||||||
|
|
||||||
|
try (NBTOutputStream stream = NbtUtils.createNetworkWriter(outputStream)) {
|
||||||
|
stream.write(EMPTY_TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
EMPTY_LEVEL_CHUNK_DATA = outputStream.toByteArray();
|
||||||
|
}catch (IOException e) {
|
||||||
|
throw new AssertionError("Unable to generate empty level chunk data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void start() {
|
public static void start() {
|
||||||
addLoginPackets();
|
addLoginPackets();
|
||||||
}
|
}
|
||||||
@ -72,16 +92,16 @@ public class TranslatorsInit {
|
|||||||
startGamePacket.setDifficulty(1);
|
startGamePacket.setDifficulty(1);
|
||||||
startGamePacket.setDefaultSpawn(new Vector3i(0, 0, 0));
|
startGamePacket.setDefaultSpawn(new Vector3i(0, 0, 0));
|
||||||
startGamePacket.setAcheivementsDisabled(true);
|
startGamePacket.setAcheivementsDisabled(true);
|
||||||
startGamePacket.setTime(1300);
|
startGamePacket.setTime(0);
|
||||||
startGamePacket.setEduLevel(false);
|
startGamePacket.setEduLevel(false);
|
||||||
startGamePacket.setEduFeaturesEnabled(false);
|
startGamePacket.setEduFeaturesEnabled(false);
|
||||||
startGamePacket.setRainLevel(0);
|
startGamePacket.setRainLevel(0);
|
||||||
startGamePacket.setLightningLevel(0);
|
startGamePacket.setLightningLevel(0);
|
||||||
startGamePacket.setMultiplayerGame(false);
|
startGamePacket.setMultiplayerGame(true);
|
||||||
startGamePacket.setBroadcastingToLan(true);
|
startGamePacket.setBroadcastingToLan(true);
|
||||||
startGamePacket.getGamerules().add((new GameRule("showcoordinates", true)));
|
startGamePacket.getGamerules().add(new GameRule<>("showcoordinates", true));
|
||||||
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
|
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
|
||||||
startGamePacket.setXblBroadcastMode(GamePublishSetting.FRIENDS_OF_FRIENDS);
|
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
|
||||||
startGamePacket.setCommandsEnabled(true);
|
startGamePacket.setCommandsEnabled(true);
|
||||||
startGamePacket.setTexturePacksRequired(false);
|
startGamePacket.setTexturePacksRequired(false);
|
||||||
startGamePacket.setBonusChestEnabled(false);
|
startGamePacket.setBonusChestEnabled(false);
|
||||||
@ -99,19 +119,13 @@ public class TranslatorsInit {
|
|||||||
startGamePacket.setLevelId("oerjhii");
|
startGamePacket.setLevelId("oerjhii");
|
||||||
startGamePacket.setWorldName("world");
|
startGamePacket.setWorldName("world");
|
||||||
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
|
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
|
||||||
startGamePacket.setCurrentTick(1);
|
startGamePacket.setCurrentTick(0);
|
||||||
startGamePacket.setEnchantmentSeed(1);
|
startGamePacket.setEnchantmentSeed(0);
|
||||||
startGamePacket.setMultiplayerCorrelationId("");
|
startGamePacket.setMultiplayerCorrelationId("");
|
||||||
startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE);
|
startGamePacket.setCachedPalette(Toolbox.CACHED_PALLETE);
|
||||||
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
startGamePacket.setItemEntries(Toolbox.ITEMS);
|
||||||
|
|
||||||
session.getUpstream().sendPacketImmediately(startGamePacket);
|
session.getUpstream().sendPacket(startGamePacket);
|
||||||
|
|
||||||
BiomeDefinitionListPacket biomeDefListPacket = new BiomeDefinitionListPacket();
|
|
||||||
session.getUpstream().sendPacketImmediately(biomeDefListPacket);
|
|
||||||
|
|
||||||
AvailableEntityIdentifiersPacket availableEntityPacket = new AvailableEntityIdentifiersPacket();
|
|
||||||
session.getUpstream().sendPacketImmediately(availableEntityPacket);
|
|
||||||
|
|
||||||
Vector3f pos = new Vector3f(0, 0, 0);
|
Vector3f pos = new Vector3f(0, 0, 0);
|
||||||
|
|
||||||
@ -126,38 +140,9 @@ public class TranslatorsInit {
|
|||||||
LevelChunkPacket data = new LevelChunkPacket();
|
LevelChunkPacket data = new LevelChunkPacket();
|
||||||
data.setChunkX(chunkX + x);
|
data.setChunkX(chunkX + x);
|
||||||
data.setChunkZ(chunkZ + z);
|
data.setChunkZ(chunkZ + z);
|
||||||
|
data.setSubChunksLength(0);
|
||||||
|
|
||||||
ByteBuf buf = Unpooled.buffer();
|
data.setData(EMPTY_LEVEL_CHUNK_DATA);
|
||||||
|
|
||||||
data.setSubChunksLength(16);
|
|
||||||
|
|
||||||
for(int i = 0; i < 1; i++) {
|
|
||||||
GeyserUtils.writeEmptySubChunk(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 256; i++) {
|
|
||||||
buf.writeByte(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.writeZero(1);
|
|
||||||
|
|
||||||
VarInts.writeInt(buf, 0);
|
|
||||||
|
|
||||||
ByteArrayOutputStream s = new ByteArrayOutputStream();
|
|
||||||
|
|
||||||
NBTOutputStream stream = NbtUtils.createNetworkWriter(s);
|
|
||||||
|
|
||||||
try {
|
|
||||||
stream.write(new CompoundTag("", new HashMap<>()));
|
|
||||||
s.close();
|
|
||||||
stream.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
buf.writeBytes(s.toByteArray());
|
|
||||||
|
|
||||||
data.setData(new byte[0]);
|
|
||||||
|
|
||||||
session.getUpstream().sendPacketImmediately(data);
|
session.getUpstream().sendPacketImmediately(data);
|
||||||
|
|
||||||
|
@ -27,11 +27,12 @@ public class Toolbox {
|
|||||||
|
|
||||||
ByteBuf b = Unpooled.buffer();
|
ByteBuf b = Unpooled.buffer();
|
||||||
|
|
||||||
VarInts.writeInt(b, entries.size());
|
VarInts.writeUnsignedInt(b, entries.size());
|
||||||
|
|
||||||
for (Map<String, Object> e : entries) {
|
for (Map<String, Object> e : entries) {
|
||||||
BedrockUtils.writeString(b, (String) e.get("name"));
|
BedrockUtils.writeString(b, (String) e.get("name"));
|
||||||
b.writeShortLE((Integer) e.get("data"));
|
b.writeShortLE((int) e.get("data"));
|
||||||
|
b.writeShortLE((int) e.get("id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
CACHED_PALLETE = b;
|
CACHED_PALLETE = b;
|
||||||
@ -56,7 +57,7 @@ public class Toolbox {
|
|||||||
ArrayList<StartGamePacket.ItemEntry> l = new ArrayList<>();
|
ArrayList<StartGamePacket.ItemEntry> l = new ArrayList<>();
|
||||||
|
|
||||||
for(HashMap e : s) {
|
for(HashMap e : s) {
|
||||||
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), ((Integer) e.get("id")).shortValue()));
|
l.add(new StartGamePacket.ItemEntry((String) e.get("name"), (short) ((int) e.get("id"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
ITEMS = l;
|
ITEMS = l;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren