Skip to content

Commit

Permalink
Minecraft 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Jun 10, 2022
1 parent 0f909c4 commit 8b37a26
Show file tree
Hide file tree
Showing 25 changed files with 149,278 additions and 135,803 deletions.
16 changes: 8 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>com.loohp</groupId>
<artifactId>Limbo</artifactId>
<name>Limbo</name>
<version>0.6.15-ALPHA</version>
<version>0.6.16-ALPHA</version>

<description>Standalone Limbo Minecraft Server.</description>
<url>https://github.com/LOOHP/Limbo</url>
Expand Down Expand Up @@ -136,7 +136,7 @@
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}-1.18.2</finalName>
<finalName>${project.artifactId}-${project.version}-1.19</finalName>
</build>

<profiles>
Expand Down Expand Up @@ -231,7 +231,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -256,31 +256,31 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>4.9.3</version>
<version>4.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.9.3</version>
<version>4.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-plain</artifactId>
<version>4.9.3</version>
<version>4.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.9.3</version>
<version>4.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-nbt</artifactId>
<version>4.9.3</version>
<version>4.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/loohp/limbo/Limbo.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public static Limbo getInstance() {

//===========================

public final String SERVER_IMPLEMENTATION_VERSION = "1.18.2";
public final int SERVER_IMPLEMENTATION_PROTOCOL = 758;
public final String SERVER_IMPLEMENTATION_VERSION = "1.19";
public final int SERVER_IMPLEMENTATION_PROTOCOL = 759;
public final String LIMBO_IMPLEMENTATION_VERSION;

private AtomicBoolean isRunning;
Expand Down Expand Up @@ -216,7 +216,7 @@ public Limbo() throws IOException, ParseException, NumberFormatException, ClassN

console.sendMessage("Loading packet id mappings from mapping.json ...");

InputStreamReader reader = new InputStreamReader(new FileInputStream(mappingFile), StandardCharsets.UTF_8);
InputStreamReader reader = new InputStreamReader(Files.newInputStream(mappingFile.toPath()), StandardCharsets.UTF_8);
JSONObject json = (JSONObject) new JSONParser().parse(reader);
reader.close();

Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/loohp/limbo/network/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import com.loohp.limbo.network.protocol.packets.PacketStatusInRequest;
import com.loohp.limbo.network.protocol.packets.PacketStatusOutPong;
import com.loohp.limbo.network.protocol.packets.PacketStatusOutResponse;
import com.loohp.limbo.network.protocol.packets.ServerboundChatCommandPacket;
import com.loohp.limbo.player.Player;
import com.loohp.limbo.player.PlayerInteractManager;
import com.loohp.limbo.utils.BungeecordAdventureConversionUtils;
Expand Down Expand Up @@ -201,6 +202,7 @@ public void sendPluginMessage(String channel, byte[] data) throws IOException {
}

public synchronized void sendPacket(PacketOut packet) throws IOException {
System.out.println(packet.getClass());
if (channel.writePacket(packet)) {
setLastPacketTimestamp(System.currentTimeMillis());
}
Expand Down Expand Up @@ -626,11 +628,10 @@ public void run() {
sendPacket(response);
} else if (packetIn instanceof PacketPlayInChat) {
PacketPlayInChat chat = (PacketPlayInChat) packetIn;
if (chat.getMessage().startsWith("/")) {
Limbo.getInstance().dispatchCommand(player, chat.getMessage());
} else {
player.chat(chat.getMessage(), true);
}
player.chat(chat.getMessage(), true, chat.getSignature(), chat.getTime());
} else if (packetIn instanceof ServerboundChatCommandPacket) {
ServerboundChatCommandPacket command = (ServerboundChatCommandPacket) packetIn;
Limbo.getInstance().dispatchCommand(player, "/" + command.getCommand());
} else if (packetIn instanceof PacketPlayInHeldItemChange) {
PacketPlayInHeldItemChange change = (PacketPlayInHeldItemChange) packetIn;
PlayerSelectedSlotChangeEvent event = Limbo.getInstance().getEventsManager().callEvent(new PlayerSelectedSlotChangeEvent(player, (byte) change.getSlot()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@

package com.loohp.limbo.network.protocol.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;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.LinkedList;
import java.util.List;

public class ClientboundLevelChunkWithLightPacket extends PacketOut {

private int chunkX;
Expand Down Expand Up @@ -165,7 +163,7 @@ public byte[] serializePacket() throws IOException {
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);
BitsUtils.shiftAfter(bits, u - shift, shift);
}

long[] formattedLongs = bits.toLongArray();
Expand All @@ -182,7 +180,7 @@ public byte[] serializePacket() throws IOException {
}
} else {
try {
dataOut.writeByte(15);
dataOut.writeByte(16);
section.getBlockStates();
int longsNeeded = 1024;
List<Integer> list = new LinkedList<>();
Expand All @@ -207,7 +205,7 @@ public byte[] serializePacket() throws IOException {
u++;
}
int id = list.isEmpty() ? 0 : list.remove(0);
currentLong = currentLong << 15;
currentLong = currentLong << 16;
currentLong |= id;
}
DataTypeIO.writeVarInt(dataOut, longsNeeded);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* This file is part of Limbo.
*
* Copyright (C) 2022. LoohpJames <[email protected]>
* Copyright (C) 2022. Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.loohp.limbo.network.protocol.packets;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Optional;
import java.util.UUID;

import com.loohp.limbo.utils.DataTypeIO;

import com.loohp.limbo.utils.NetworkEncryptionUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;

public class ClientboundPlayerChatPacket extends PacketOut {

private Component signedContent;
private Optional<Component> unsignedContent;
private int position;
private UUID sender;
private Instant time;
private NetworkEncryptionUtils.SignatureData saltSignature;

public ClientboundPlayerChatPacket(Component signedContent, Optional<Component> unsignedContent, int position, UUID sender, Instant time, NetworkEncryptionUtils.SignatureData saltSignature) {
this.signedContent = signedContent;
this.unsignedContent = unsignedContent;
this.position = position;
this.sender = sender;
this.time = time;
this.saltSignature = saltSignature;
}

public Component getSignedContent() {
return signedContent;
}

public Optional<Component> getUnsignedContent() {
return unsignedContent;
}

public int getPosition() {
return position;
}

public UUID getSender() {
return sender;
}

public Instant getTime() {
return time;
}

public NetworkEncryptionUtils.SignatureData getSaltSignature() {
return saltSignature;
}

@Override
public byte[] serializePacket() throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();

DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(signedContent), StandardCharsets.UTF_8);
if (unsignedContent.isPresent()) {
output.writeBoolean(true);
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(unsignedContent.get()), StandardCharsets.UTF_8);
} else {
output.writeBoolean(false);
}
DataTypeIO.writeVarInt(output, position);
DataTypeIO.writeUUID(output, sender);
output.writeLong(time.toEpochMilli());
NetworkEncryptionUtils.SignatureData.write(output, saltSignature);

return buffer.toByteArray();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,23 @@

package com.loohp.limbo.network.protocol.packets;

import com.loohp.limbo.utils.DataTypeIO;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

import com.loohp.limbo.utils.DataTypeIO;
public class ClientboundSystemChatPacket extends PacketOut {

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;

public class PacketPlayOutChat extends PacketOut {

private Component message;
private int position;
private UUID sender;

public PacketPlayOutChat(Component message, int position, UUID sender) {

public ClientboundSystemChatPacket(Component message, int position) {
this.message = message;
this.position = position;
this.sender = sender;
}

public Component getMessage() {
Expand All @@ -49,10 +45,6 @@ public Component getMessage() {
public int getPosition() {
return position;
}

public UUID getSender() {
return sender;
}

@Override
public byte[] serializePacket() throws IOException {
Expand All @@ -61,8 +53,7 @@ public byte[] serializePacket() throws IOException {
DataOutputStream output = new DataOutputStream(buffer);
output.writeByte(Packet.getPlayOut().get(getClass()));
DataTypeIO.writeString(output, GsonComponentSerializer.gson().serialize(message), StandardCharsets.UTF_8);
output.writeByte(position);
DataTypeIO.writeUUID(output, sender);
DataTypeIO.writeVarInt(output, position);

return buffer.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ public PacketLoginInLoginStart(String username) {
}

public PacketLoginInLoginStart(DataInputStream in) throws IOException {
this(DataTypeIO.readString(in, StandardCharsets.UTF_8));
this.username = DataTypeIO.readString(in, StandardCharsets.UTF_8);
boolean hasSigData = in.readBoolean();
if (hasSigData) {
in.readLong();
int publicKeyLength = DataTypeIO.readVarInt(in);
in.readFully(new byte[publicKeyLength]);
int signatureLength = DataTypeIO.readVarInt(in);
in.readFully(new byte[signatureLength]);
}
}

public String getUsername() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public byte[] serializePacket() throws IOException {
output.writeByte(Packet.getLoginOut().get(getClass()));
DataTypeIO.writeUUID(output, uuid);
DataTypeIO.writeString(output, username, StandardCharsets.UTF_8);
DataTypeIO.writeVarInt(output, 0);

return buffer.toByteArray();
}
Expand Down
Loading

0 comments on commit 8b37a26

Please sign in to comment.