From 14a1f50abf886e16e74ab1c60e0e4ba3f041da26 Mon Sep 17 00:00:00 2001 From: LOOHP Date: Wed, 1 Dec 2021 00:55:27 +0000 Subject: [PATCH] Minecraft 1.18 --- pom.xml | 4 +- src/main/java/com/loohp/limbo/Limbo.java | 4 +- .../limbo/player/PlayerInteractManager.java | 8 +- .../com/loohp/limbo/registry/Registry.java | 84 + .../loohp/limbo/server/ClientConnection.java | 2 +- .../ClientboundLevelChunkWithLightPacket.java | 304 + .../packets/PacketPlayOutLightUpdate.java | 130 - .../server/packets/PacketPlayOutLogin.java | 9 +- .../server/packets/PacketPlayOutMapChunk.java | 212 - src/main/resources/LimboDefaultCmd.jar | Bin 4488 -> 0 bytes src/main/resources/mapping.json | 5 +- src/main/resources/registries.json | 13064 ++++++++++++++++ 12 files changed, 13469 insertions(+), 357 deletions(-) create mode 100644 src/main/java/com/loohp/limbo/registry/Registry.java create mode 100644 src/main/java/com/loohp/limbo/server/packets/ClientboundLevelChunkWithLightPacket.java delete mode 100644 src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLightUpdate.java delete mode 100644 src/main/java/com/loohp/limbo/server/packets/PacketPlayOutMapChunk.java delete mode 100644 src/main/resources/LimboDefaultCmd.jar create mode 100644 src/main/resources/registries.json diff --git a/pom.xml b/pom.xml index b47b8ae..22dde70 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.loohp Limbo Limbo - 0.6.4-ALPHA + 0.6.5-ALPHA Standalone Limbo Minecraft Server. https://github.com/LOOHP/Limbo @@ -117,7 +117,7 @@ - ${project.artifactId}-${project.version}-1.17.1 + ${project.artifactId}-${project.version}-1.18 diff --git a/src/main/java/com/loohp/limbo/Limbo.java b/src/main/java/com/loohp/limbo/Limbo.java index dbd76f0..2588732 100644 --- a/src/main/java/com/loohp/limbo/Limbo.java +++ b/src/main/java/com/loohp/limbo/Limbo.java @@ -106,8 +106,8 @@ public class Limbo { //=========================== - public final String serverImplementationVersion = "1.17.1"; - public final int serverImplmentationProtocol = 756; + public final String serverImplementationVersion = "1.18"; + public final int serverImplmentationProtocol = 757; public final String limboImplementationVersion; private AtomicBoolean isRunning; diff --git a/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java b/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java index 3b7eef6..d9de954 100644 --- a/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java +++ b/src/main/java/com/loohp/limbo/player/PlayerInteractManager.java @@ -15,8 +15,7 @@ import com.loohp.limbo.entity.Entity; import com.loohp.limbo.location.Location; import com.loohp.limbo.server.packets.PacketPlayOutEntityDestroy; import com.loohp.limbo.server.packets.PacketPlayOutEntityMetadata; -import com.loohp.limbo.server.packets.PacketPlayOutLightUpdate; -import com.loohp.limbo.server.packets.PacketPlayOutMapChunk; +import com.loohp.limbo.server.packets.ClientboundLevelChunkWithLightPacket; import com.loohp.limbo.server.packets.PacketPlayOutSpawnEntity; import com.loohp.limbo.server.packets.PacketPlayOutSpawnEntityLiving; import com.loohp.limbo.server.packets.PacketPlayOutUnloadChunk; @@ -112,9 +111,6 @@ public class PlayerInteractManager { for (Chunk chunk : chunksInRange) { if (!chunks.containsKey(chunk)) { int[] chunkPos = world.getChunkXZ(chunk); - PacketPlayOutMapChunk packet0 = new PacketPlayOutMapChunk(chunkPos[0], chunkPos[1], chunk, world.getEnvironment()); - player.clientConnection.sendPacket(packet0); - List blockChunk = world.getLightEngineBlock().getBlockLightBitMask(chunkPos[0], chunkPos[1]); if (blockChunk == null) { blockChunk = new ArrayList<>(); @@ -126,7 +122,7 @@ public class PlayerInteractManager { if (skyChunk == null) { skyChunk = new ArrayList<>(); } - PacketPlayOutLightUpdate chunkdata = new PacketPlayOutLightUpdate(chunkPos[0], chunkPos[1], true, skyChunk, blockChunk); + ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos[0], chunkPos[1], chunk, world.getEnvironment(), true, skyChunk, blockChunk); player.clientConnection.sendPacket(chunkdata); } } diff --git a/src/main/java/com/loohp/limbo/registry/Registry.java b/src/main/java/com/loohp/limbo/registry/Registry.java new file mode 100644 index 0000000..6ce8f9c --- /dev/null +++ b/src/main/java/com/loohp/limbo/registry/Registry.java @@ -0,0 +1,84 @@ +package com.loohp.limbo.registry; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import com.loohp.limbo.Limbo; +import com.loohp.limbo.utils.NamespacedKey; + +public class Registry { + + public static final BlockEntityRegistry BLOCK_ENTITY_TYPE; + + static { + String name = "registries.json"; + File file = new File(Limbo.getInstance().getInternalDataFolder(), name); + if (!file.exists()) { + try (InputStream in = Limbo.class.getClassLoader().getResourceAsStream(name)) { + Files.copy(in, file.toPath()); + } catch (IOException e) { + e.printStackTrace(); + } + } + + Map blockEntityType = new HashMap<>(); + try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) { + JSONObject json = (JSONObject) new JSONParser().parse(reader); + + JSONObject blockEntityJson = (JSONObject) ((JSONObject) json.get("minecraft:block_entity_type")).get("entries"); + for (Object obj : blockEntityJson.keySet()) { + String key = obj.toString(); + int id = (int) (long) ((JSONObject) blockEntityJson.get(key)).get("protocol_id"); + blockEntityType.put(new NamespacedKey(key), id); + } + } catch (IOException | ParseException e) { + e.printStackTrace(); + } + BLOCK_ENTITY_TYPE = new BlockEntityRegistry(blockEntityType); + } + + public static class BlockEntityRegistry { + + private Map blockEntityType; + + private BlockEntityRegistry(Map blockEntityType) { + this.blockEntityType = blockEntityType; + } + + public int getId(NamespacedKey key) { + Integer exact = blockEntityType.get(key); + if (exact != null) { + return exact; + } + List toTest = new LinkedList<>(); + toTest.add(key.getKey()); + if (key.getKey().contains("head")) { + toTest.add("skull"); + } + for (Entry entry : blockEntityType.entrySet()) { + NamespacedKey namespacedKey = entry.getKey(); + for (String each : toTest) { + if (namespacedKey.getNamespace().equals(key.getNamespace()) && (each.contains(namespacedKey.getKey()) || namespacedKey.getKey().contains(each))) { + return entry.getValue(); + } + } + } + return -1; + } + } + +} diff --git a/src/main/java/com/loohp/limbo/server/ClientConnection.java b/src/main/java/com/loohp/limbo/server/ClientConnection.java index 96d3dd4..7068d4a 100644 --- a/src/main/java/com/loohp/limbo/server/ClientConnection.java +++ b/src/main/java/com/loohp/limbo/server/ClientConnection.java @@ -374,7 +374,7 @@ public class ClientConnection extends Thread { worldSpawn = joinEvent.getSpawnLocation(); World world = worldSpawn.getWorld(); - PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, properties.getDefaultGamemode(), Limbo.getInstance().getWorlds(), Limbo.getInstance().getDimensionRegistry().getCodec(), world, 0, (byte) properties.getMaxPlayers(), 8, properties.isReducedDebugInfo(), true, false, true); + PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, properties.getDefaultGamemode(), Limbo.getInstance().getWorlds(), Limbo.getInstance().getDimensionRegistry().getCodec(), world, 0, (byte) properties.getMaxPlayers(), 8, 8, properties.isReducedDebugInfo(), true, false, true); sendPacket(join); Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, properties.getDefaultGamemode()); diff --git a/src/main/java/com/loohp/limbo/server/packets/ClientboundLevelChunkWithLightPacket.java b/src/main/java/com/loohp/limbo/server/packets/ClientboundLevelChunkWithLightPacket.java new file mode 100644 index 0000000..36cdaa1 --- /dev/null +++ b/src/main/java/com/loohp/limbo/server/packets/ClientboundLevelChunkWithLightPacket.java @@ -0,0 +1,304 @@ +package com.loohp.limbo.server.packets; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import com.loohp.limbo.registry.Registry; +import com.loohp.limbo.utils.BitsUtils; +import com.loohp.limbo.utils.DataTypeIO; +import com.loohp.limbo.utils.NamespacedKey; +import com.loohp.limbo.world.Environment; +import com.loohp.limbo.world.GeneratedBlockDataMappings; + +import net.querz.mca.Chunk; +import net.querz.mca.Section; +import net.querz.nbt.tag.CompoundTag; +import net.querz.nbt.tag.ListTag; + +public class ClientboundLevelChunkWithLightPacket extends PacketOut { + + private int chunkX; + private int chunkZ; + private Chunk chunk; + private Environment environment; + private boolean trustEdges; + private long[] skyLightBitMasks; + private long[] blockLightBitMasks; + private long[] skyLightBitMasksEmpty; + private long[] blockLightBitMasksEmpty; + private List skylightArrays; + private List blocklightArrays; + + public ClientboundLevelChunkWithLightPacket(int chunkX, int chunkZ, Chunk chunk, Environment environment, boolean trustEdges, List skylightArrays, List blocklightArrays) { + this.chunkX = chunkX; + this.chunkZ = chunkZ; + this.chunk = chunk; + this.environment = environment; + this.chunkX = chunkX; + this.chunkZ = chunkZ; + this.trustEdges = trustEdges; + this.skylightArrays = skylightArrays; + this.blocklightArrays = blocklightArrays; + + BitSet skyLightBitSet = new BitSet(); + BitSet skyLightBitSetInverse = new BitSet(); + for (int i = Math.min(17, skylightArrays.size() - 1); i >= 0; i--) { + skyLightBitSet.set(i, skylightArrays.get(i) != null); + skyLightBitSetInverse.set(i, skylightArrays.get(i) == null); + } + skyLightBitMasks = skyLightBitSet.toLongArray(); + skyLightBitMasksEmpty = skyLightBitSetInverse.toLongArray(); + + BitSet blockLightBitSet = new BitSet(); + BitSet blockLightBitSetInverse = new BitSet(); + for (int i = Math.min(17, blocklightArrays.size() - 1); i >= 0; i--) { + blockLightBitSet.set(i, blocklightArrays.get(i) != null); + blockLightBitSetInverse.set(i, blocklightArrays.get(i) == null); + } + blockLightBitMasks = blockLightBitSet.toLongArray(); + blockLightBitMasksEmpty = blockLightBitSetInverse.toLongArray(); + } + + public Chunk getChunk() { + return chunk; + } + + public int getChunkX() { + return chunkX; + } + + public int getChunkZ() { + return chunkZ; + } + + public Environment getEnvironment() { + return environment; + } + + public boolean isTrustEdges() { + return trustEdges; + } + + public long[] getSkyLightBitMasks() { + return skyLightBitMasks; + } + + public long[] getBlockLightBitMasks() { + return blockLightBitMasks; + } + + public List getSkylightArrays() { + return skylightArrays; + } + + public List getBlocklightArrays() { + return blocklightArrays; + } + + @Override + public byte[] serializePacket() throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + + DataOutputStream output = new DataOutputStream(buffer); + output.writeByte(Packet.getPlayOut().get(getClass())); + + output.writeInt(chunkX); + output.writeInt(chunkZ); + DataTypeIO.writeCompoundTag(output, chunk.getHeightMaps()); + + ByteArrayOutputStream dataBuffer = new ByteArrayOutputStream(); + DataOutputStream dataOut = new DataOutputStream(dataBuffer); + for (int i = 0; i < 16; i++) { + Section section = chunk.getSection(i); + if (section != null) { + int counter = 0; + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + for (int y = 0; y < 16; y++) { + CompoundTag tag = section.getBlockStateAt(x, y, z); + if (tag != null && !tag.getString("Name").equals("minecraft:air")) { + counter++; + } + } + } + } + dataOut.writeShort(counter); + + int newBits = 32 - Integer.numberOfLeadingZeros(section.getPalette().size() - 1); + newBits = Math.max(newBits, 4); + //Limbo.getInstance().getConsole().sendMessage(i + " " + newBits); + if (newBits <= 8) { + /* + if (newBits == 4) { + dataOut.writeByte(4); + } else { + newBits = 8; + ChunkDataUtils.adjustBlockStateBits(newBits, section, chunk.getDataVersion()); + dataOut.writeByte(8); + } + */ + dataOut.writeByte(newBits); + + DataTypeIO.writeVarInt(dataOut, section.getPalette().size()); + //Limbo.getInstance().getConsole().sendMessage(section.getPalette().size()); + Iterator itr1 = section.getPalette().iterator(); + //Limbo.getInstance().getConsole().sendMessage("Nonnull -> " + i + " " + newBits); + while (itr1.hasNext()) { + CompoundTag tag = itr1.next(); + DataTypeIO.writeVarInt(dataOut, GeneratedBlockDataMappings.getGlobalPaletteIDFromState(tag)); + //Limbo.getInstance().getConsole().sendMessage(tag + " -> " + GeneratedDataUtils.getGlobalPaletteIDFromState(tag)); + } + + BitSet bits = BitSet.valueOf(section.getBlockStates()); + int shift = 64 % newBits; + int longsNeeded = (int) Math.ceil(4096 / (double) (64 / newBits)); + for (int u = 64; u <= bits.length(); u += 64) { + bits = BitsUtils.shiftAfter(bits, u - shift, shift); + } + + long[] formattedLongs = bits.toLongArray(); + //Limbo.getInstance().getConsole().sendMessage(longsNeeded + ""); + + DataTypeIO.writeVarInt(dataOut, longsNeeded); + for (int u = 0; u < longsNeeded; u++) { + if (u < formattedLongs.length) { + dataOut.writeLong(formattedLongs[u]); + } else { + dataOut.writeLong(0); + } + //Limbo.getInstance().getConsole().sendMessage(Arrays.toString(section.getBlockStates())); + } + } else { + try { + dataOut.writeByte(15); + section.getBlockStates(); + int longsNeeded = 1024; + List list = new LinkedList<>(); + for (int y = 0; y < 16; y++) { + for (int z = 0; z < 16; z++) { + for (int x = 0; x < 16; x++) { + list.add(GeneratedBlockDataMappings.getGlobalPaletteIDFromState(section.getBlockStateAt(x, y, z))); + } + } + } + List globalLongs = new ArrayList<>(); + long currentLong = 0; + int pos = 0; + int u = 0; + while (pos < longsNeeded) { + if (u == 3) { + globalLongs.add(currentLong); + currentLong = 0; + u = 0; + pos++; + } else { + u++; + } + int id = list.isEmpty() ? 0 : list.remove(0); + currentLong = currentLong << 15; + currentLong |= (long) id; + } + DataTypeIO.writeVarInt(dataOut, longsNeeded); + for (int j = 0; j < longsNeeded; j++) { + if (j < globalLongs.size()) { + dataOut.writeLong(globalLongs.get(j)); + } else { + dataOut.writeLong(0); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } else { + dataOut.writeShort(0); + dataOut.writeByte(0); + DataTypeIO.writeVarInt(dataOut, 0); + DataTypeIO.writeVarInt(dataOut, 0); + } + int biome; + if (environment.equals(Environment.END)) { + biome = 9; //the_end + } else if (environment.equals(Environment.NETHER)) { + biome = 8; //nether_waste + } else if (environment.equals(Environment.NORMAL)) { + biome = 1; //plains + } else { + biome = 1; //plains + } + dataOut.writeByte(0); + DataTypeIO.writeVarInt(dataOut, biome); + DataTypeIO.writeVarInt(dataOut, 0); + } + + byte[] data = dataBuffer.toByteArray(); + DataTypeIO.writeVarInt(output, data.length); + output.write(data); + + ListTag tileEntities = chunk.getTileEntities(); + DataTypeIO.writeVarInt(output, tileEntities.size()); + for (CompoundTag each : tileEntities) { + int x = each.getInt("x") % 16; + int y = each.getInt("y"); + int z = each.getInt("z") % 16; + output.writeByte((x << 4) | z); + output.writeShort(y); + Integer id = Registry.BLOCK_ENTITY_TYPE.getId(new NamespacedKey(chunk.getBlockStateAt(x, y, z).getString("Name"))); + System.out.println(chunk.getBlockStateAt(x, y, z).toString()); + System.out.println(each.toString()); + DataTypeIO.writeVarInt(output, id == null ? -1 : id); + DataTypeIO.writeCompoundTag(output, each); + } + + output.writeBoolean(trustEdges); + DataTypeIO.writeVarInt(output, skyLightBitMasks.length); + for (long l : skyLightBitMasks) { + output.writeLong(l); + } + DataTypeIO.writeVarInt(output, blockLightBitMasks.length); + for (long l : blockLightBitMasks) { + output.writeLong(l); + } + DataTypeIO.writeVarInt(output, skyLightBitMasksEmpty.length); + for (long l : skyLightBitMasksEmpty) { + output.writeLong(l); + } + DataTypeIO.writeVarInt(output, blockLightBitMasksEmpty.length); + for (long l : blockLightBitMasksEmpty) { + output.writeLong(l); + } + + DataTypeIO.writeVarInt(output, skylightArrays.stream().mapToInt(each -> each == null ? 0 : 1).sum()); + for (int i = skylightArrays.size() - 1; i >= 0; i--) { + Byte[] array = skylightArrays.get(i); + if (array != null) { + DataTypeIO.writeVarInt(output, 2048); + //System.out.println(Arrays.toString(ArrayUtils.toPrimitive(array))); + for (int u = 0; u < array.length; u++) { + output.writeByte(array[u]); + } + } + } + + DataTypeIO.writeVarInt(output, blocklightArrays.stream().mapToInt(each -> each == null ? 0 : 1).sum()); + for (int i = blocklightArrays.size() - 1; i >= 0; i--) { + Byte[] array = blocklightArrays.get(i); + if (array != null) { + DataTypeIO.writeVarInt(output, 2048); + //System.out.println(Arrays.toString(ArrayUtils.toPrimitive(array))); + for (int u = 0; u < array.length; u++) { + output.writeByte(array[u]); + } + } + } + + return buffer.toByteArray(); + } + +} diff --git a/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLightUpdate.java b/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLightUpdate.java deleted file mode 100644 index 4dd9b07..0000000 --- a/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLightUpdate.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.loohp.limbo.server.packets; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.BitSet; -import java.util.List; - -import com.loohp.limbo.utils.DataTypeIO; - -public class PacketPlayOutLightUpdate extends PacketOut { - - private int chunkX; - private int chunkZ; - private boolean trustEdges; - private long[] skyLightBitMasks; - private long[] blockLightBitMasks; - private long[] skyLightBitMasksEmpty; - private long[] blockLightBitMasksEmpty; - private List skylightArrays; - private List blocklightArrays; - - public PacketPlayOutLightUpdate(int chunkX, int chunkZ, boolean trustEdges, List skylightArrays, List blocklightArrays) { - this.chunkX = chunkX; - this.chunkZ = chunkZ; - this.trustEdges = trustEdges; - this.skylightArrays = skylightArrays; - this.blocklightArrays = blocklightArrays; - - BitSet skyLightBitSet = new BitSet(); - BitSet skyLightBitSetInverse = new BitSet(); - for (int i = Math.min(17, skylightArrays.size() - 1); i >= 0; i--) { - skyLightBitSet.set(i, skylightArrays.get(i) != null); - skyLightBitSetInverse.set(i, skylightArrays.get(i) == null); - } - skyLightBitMasks = skyLightBitSet.toLongArray(); - skyLightBitMasksEmpty = skyLightBitSetInverse.toLongArray(); - - BitSet blockLightBitSet = new BitSet(); - BitSet blockLightBitSetInverse = new BitSet(); - for (int i = Math.min(17, blocklightArrays.size() - 1); i >= 0; i--) { - blockLightBitSet.set(i, blocklightArrays.get(i) != null); - blockLightBitSetInverse.set(i, blocklightArrays.get(i) == null); - } - blockLightBitMasks = blockLightBitSet.toLongArray(); - blockLightBitMasksEmpty = blockLightBitSetInverse.toLongArray(); - } - - public int getChunkX() { - return chunkX; - } - - public int getChunkZ() { - return chunkZ; - } - - public boolean isTrustEdges() { - return trustEdges; - } - - public long[] getSkyLightBitMasks() { - return skyLightBitMasks; - } - - public long[] getBlockLightBitMasks() { - return blockLightBitMasks; - } - - public List getSkylightArrays() { - return skylightArrays; - } - - public List getBlocklightArrays() { - return blocklightArrays; - } - - @Override - public byte[] serializePacket() throws IOException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - DataOutputStream output = new DataOutputStream(buffer); - output.writeByte(Packet.getPlayOut().get(getClass())); - DataTypeIO.writeVarInt(output, chunkX); - DataTypeIO.writeVarInt(output, chunkZ); - output.writeBoolean(trustEdges); - DataTypeIO.writeVarInt(output, skyLightBitMasks.length); - for (long l : skyLightBitMasks) { - output.writeLong(l); - } - DataTypeIO.writeVarInt(output, blockLightBitMasks.length); - for (long l : blockLightBitMasks) { - output.writeLong(l); - } - DataTypeIO.writeVarInt(output, skyLightBitMasksEmpty.length); - for (long l : skyLightBitMasksEmpty) { - output.writeLong(l); - } - DataTypeIO.writeVarInt(output, blockLightBitMasksEmpty.length); - for (long l : blockLightBitMasksEmpty) { - output.writeLong(l); - } - - DataTypeIO.writeVarInt(output, skylightArrays.stream().mapToInt(each -> each == null ? 0 : 1).sum()); - for (int i = skylightArrays.size() - 1; i >= 0; i--) { - Byte[] array = skylightArrays.get(i); - if (array != null) { - DataTypeIO.writeVarInt(output, 2048); - //System.out.println(Arrays.toString(ArrayUtils.toPrimitive(array))); - for (int u = 0; u < array.length; u++) { - output.writeByte(array[u]); - } - } - } - - DataTypeIO.writeVarInt(output, blocklightArrays.stream().mapToInt(each -> each == null ? 0 : 1).sum()); - for (int i = blocklightArrays.size() - 1; i >= 0; i--) { - Byte[] array = blocklightArrays.get(i); - if (array != null) { - DataTypeIO.writeVarInt(output, 2048); - //System.out.println(Arrays.toString(ArrayUtils.toPrimitive(array))); - for (int u = 0; u < array.length; u++) { - output.writeByte(array[u]); - } - } - } - - return buffer.toByteArray(); - } - -} diff --git a/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLogin.java b/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLogin.java index d6eee67..3a26c75 100644 --- a/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLogin.java +++ b/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutLogin.java @@ -27,12 +27,13 @@ public class PacketPlayOutLogin extends PacketOut { private long hashedSeed; private byte maxPlayers; private int viewDistance; + private int simulationDistance; private boolean reducedDebugInfo; private boolean enableRespawnScreen; private boolean isDebug; private boolean isFlat; - public PacketPlayOutLogin(int entityId, boolean isHardcore, GameMode gamemode, List worlds, CompoundTag dimensionCodec, World world, long hashedSeed, byte maxPlayers, int viewDistance, boolean reducedDebugInfo, boolean enableRespawnScreen, boolean isDebug, boolean isFlat) { + public PacketPlayOutLogin(int entityId, boolean isHardcore, GameMode gamemode, List worlds, CompoundTag dimensionCodec, World world, long hashedSeed, byte maxPlayers, int viewDistance, int simulationDistance, boolean reducedDebugInfo, boolean enableRespawnScreen, boolean isDebug, boolean isFlat) { this.entityId = entityId; this.isHardcore = isHardcore; this.gamemode = gamemode; @@ -43,6 +44,7 @@ public class PacketPlayOutLogin extends PacketOut { this.hashedSeed = hashedSeed; this.maxPlayers = maxPlayers; this.viewDistance = viewDistance; + this.simulationDistance = simulationDistance; this.reducedDebugInfo = reducedDebugInfo; this.enableRespawnScreen = enableRespawnScreen; this.isDebug = isDebug; @@ -88,6 +90,10 @@ public class PacketPlayOutLogin extends PacketOut { public int getViewDistance() { return viewDistance; } + + public int getSimulationDistance() { + return simulationDistance; + } public boolean isReducedDebugInfo() { return reducedDebugInfo; @@ -133,6 +139,7 @@ public class PacketPlayOutLogin extends PacketOut { output.writeLong(hashedSeed); DataTypeIO.writeVarInt(output, maxPlayers); DataTypeIO.writeVarInt(output, viewDistance); + DataTypeIO.writeVarInt(output, simulationDistance); output.writeBoolean(reducedDebugInfo); output.writeBoolean(enableRespawnScreen); output.writeBoolean(isDebug); diff --git a/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutMapChunk.java b/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutMapChunk.java deleted file mode 100644 index de3f1ad..0000000 --- a/src/main/java/com/loohp/limbo/server/packets/PacketPlayOutMapChunk.java +++ /dev/null @@ -1,212 +0,0 @@ -package com.loohp.limbo.server.packets; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.BitSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import com.loohp.limbo.utils.BitsUtils; -import com.loohp.limbo.utils.DataTypeIO; -import com.loohp.limbo.world.Environment; -import com.loohp.limbo.world.GeneratedBlockDataMappings; - -import net.querz.mca.Chunk; -import net.querz.mca.Section; -import net.querz.nbt.tag.CompoundTag; -import net.querz.nbt.tag.ListTag; - -public class PacketPlayOutMapChunk extends PacketOut { - - private int chunkX; - private int chunkZ; - private Chunk chunk; - private Environment environment; - - public PacketPlayOutMapChunk(int chunkX, int chunkZ, Chunk chunk, Environment environment) { - this.chunkX = chunkX; - this.chunkZ = chunkZ; - this.chunk = chunk; - this.environment = environment; - } - - @Deprecated - public PacketPlayOutMapChunk(int chunkX, int chunkZ, Chunk chunk) { - this(chunkZ, chunkZ, chunk, Environment.NORMAL); - } - - public Chunk getChunk() { - return chunk; - } - - public int getChunkX() { - return chunkX; - } - - public int getChunkZ() { - return chunkZ; - } - - public Environment getEnvironment() { - return environment; - } - - @Override - public byte[] serializePacket() throws IOException { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - - DataOutputStream output = new DataOutputStream(buffer); - output.writeByte(Packet.getPlayOut().get(getClass())); - - output.writeInt(chunkX); - output.writeInt(chunkZ); - BitSet chunkPresent = new BitSet(); - for (int i = 0; i < 16; i++) { - Section section = chunk.getSection(i); - chunkPresent.set(i, section != null); - } - long[] bitmasks = chunkPresent.toLongArray(); - DataTypeIO.writeVarInt(output, bitmasks.length); - for (long l : bitmasks) { - output.writeLong(l); - } - DataTypeIO.writeCompoundTag(output, chunk.getHeightMaps()); - - DataTypeIO.writeVarInt(output, 1024); - int biome; - if (environment.equals(Environment.END)) { - biome = 9; //the_end - } else if (environment.equals(Environment.NETHER)) { - biome = 8; //nether_waste - } else if (environment.equals(Environment.NORMAL)) { - biome = 1; //plains - } else { - biome = 1; //plains - } - for (int i = 0; i < 1024; i++) { - DataTypeIO.writeVarInt(output, biome); - } - - ByteArrayOutputStream dataBuffer = new ByteArrayOutputStream(); - DataOutputStream dataOut = new DataOutputStream(dataBuffer); - for (int i = 0; i < 16; i++) { - Section section = chunk.getSection(i); - if (section != null) { - int counter = 0; - for (int x = 0; x < 16; x++) { - for (int z = 0; z < 16; z++) { - for (int y = 0; y < 16; y++) { - CompoundTag tag = section.getBlockStateAt(x, y, z); - if (tag != null && !tag.getString("Name").equals("minecraft:air")) { - counter++; - } - } - } - } - dataOut.writeShort(counter); - - int newBits = 32 - Integer.numberOfLeadingZeros(section.getPalette().size() - 1); - newBits = Math.max(newBits, 4); - //Limbo.getInstance().getConsole().sendMessage(i + " " + newBits); - if (newBits <= 8) { - /* - if (newBits == 4) { - dataOut.writeByte(4); - } else { - newBits = 8; - ChunkDataUtils.adjustBlockStateBits(newBits, section, chunk.getDataVersion()); - dataOut.writeByte(8); - } - */ - dataOut.writeByte(newBits); - - DataTypeIO.writeVarInt(dataOut, section.getPalette().size()); - //Limbo.getInstance().getConsole().sendMessage(section.getPalette().size()); - Iterator itr1 = section.getPalette().iterator(); - //Limbo.getInstance().getConsole().sendMessage("Nonnull -> " + i + " " + newBits); - while (itr1.hasNext()) { - CompoundTag tag = itr1.next(); - DataTypeIO.writeVarInt(dataOut, GeneratedBlockDataMappings.getGlobalPaletteIDFromState(tag)); - //Limbo.getInstance().getConsole().sendMessage(tag + " -> " + GeneratedDataUtils.getGlobalPaletteIDFromState(tag)); - } - - BitSet bits = BitSet.valueOf(section.getBlockStates()); - int shift = 64 % newBits; - int longsNeeded = (int) Math.ceil(4096 / (double) (64 / newBits)); - for (int u = 64; u <= bits.length(); u += 64) { - bits = BitsUtils.shiftAfter(bits, u - shift, shift); - } - - long[] formattedLongs = bits.toLongArray(); - //Limbo.getInstance().getConsole().sendMessage(longsNeeded + ""); - - DataTypeIO.writeVarInt(dataOut, longsNeeded); - for (int u = 0; u < longsNeeded; u++) { - if (u < formattedLongs.length) { - dataOut.writeLong(formattedLongs[u]); - } else { - dataOut.writeLong(0); - } - //Limbo.getInstance().getConsole().sendMessage(Arrays.toString(section.getBlockStates())); - } - } else { - try { - dataOut.writeByte(15); - section.getBlockStates(); - int longsNeeded = 1024; - List list = new LinkedList<>(); - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - for (int x = 0; x < 16; x++) { - list.add(GeneratedBlockDataMappings.getGlobalPaletteIDFromState(section.getBlockStateAt(x, y, z))); - } - } - } - List globalLongs = new ArrayList<>(); - long currentLong = 0; - int pos = 0; - int u = 0; - while (pos < longsNeeded) { - if (u == 3) { - globalLongs.add(currentLong); - currentLong = 0; - u = 0; - pos++; - } else { - u++; - } - int id = list.isEmpty() ? 0 : list.remove(0); - currentLong = currentLong << 15; - currentLong |= (long) id; - } - DataTypeIO.writeVarInt(dataOut, longsNeeded); - for (int j = 0; j < longsNeeded; j++) { - if (j < globalLongs.size()) { - dataOut.writeLong(globalLongs.get(j)); - } else { - dataOut.writeLong(0); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } - byte[] data = dataBuffer.toByteArray(); - DataTypeIO.writeVarInt(output, data.length); - output.write(data); - - ListTag tileEntities = chunk.getTileEntities(); - DataTypeIO.writeVarInt(output, tileEntities.size()); - for (CompoundTag each : tileEntities) { - DataTypeIO.writeCompoundTag(output, each); - } - - return buffer.toByteArray(); - } - -} diff --git a/src/main/resources/LimboDefaultCmd.jar b/src/main/resources/LimboDefaultCmd.jar deleted file mode 100644 index 5fa0d06585b8f5858f88531749d3acc9b1538376..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4488 zcmb7Ic{J4T_n*j?Wyr`_lig^HA$w%WSZ9oVP4>tzcE*ylNDNYTlGJ1;LkJ0DiD3}g zcUh`YghI-f@AsTvKEHFme|+!zJmP|pb$!Lf3=zHu>9Q8!V(Pt zZN$JxjHda@cbJOjaH0RNz{T=^7Jwb@x?+7`7%bM)4~FsbalyK|dpHMUf?R#vV8%!O z<^T9PK5jCu80Wyia%-kY&CfawglJ{@%X&URdK_rE>AhCc!c3~~EcJFs= z&d$}onwbv-4#ZUU~1{xUcA1@%XrT&BU{TgE058>ue??B@qXS?q;(y= zWj$S|M?OQr{ADA_)1eRes6Z|p4IwLT-}i$^Ygqn-?Qj`9n=_rqe4b0$DPxRzn;;q& z%gU#4)#-TH7$;A%R9I{!9jb`ej@+Hh{cDohCDa$rlt=` ziz-YP@EyuMcpm8cH&t%b)pR;SBWN7PRYH6al16Xop75Nu(_5LHkd&qn;`FQRe4n$s z+z+qJ3js6`i&SPjA7gW@p)m+N;r*;y3jOPnU1mzMr5po;eUw*kZ+1qX$`CXWA*w$i z7A(D`sLnnj0*ygPpNX%rNK?tb!*yy>E;HyhuMU)B+OYkd{ecF~q#u!GN+5>j3*A+g zKQlBb7NQ~Un#p~SiKULNYc2H&IQes_$ZdaReHEnBe#`KXtbiUPi)}?0AKu1WQV^KM zk&f_UD^LEpz(AAtJU^?*${$3V?VAv5TjXpqaJ!X7aWkVrHXEAL$M4}7J#8JEZ5?h( z_LwV6>K;qB_ZUvVO@&%*j$e8IV><+vM6ie$l$0$v@J*PxUPF8m=FhLD_sv=(`=w0> zPzo|+!P@0|zgN7P;?Q?}coDx7_nwG(qAxCSUD;qy_LA=>xbzH&m~ON##T&#lL$*m9 zAZ<*f$MMLEO4~;F@!lf3vwHmgfY1kf)y|VI)Htc&#;5hLN-kv&<_W(!Uktu1p?9Tg zgILM=dGYb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