mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-20 00:13:21 +02:00
new packet system 1.20.5
This commit is contained in:
parent
40d55a1ca3
commit
fdd7aeaf4f
3 changed files with 26 additions and 47 deletions
|
@ -1,35 +0,0 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketBuilder {
|
||||
public static final String SETTINGS = "settings_v1.0";
|
||||
private final String message;
|
||||
private final PacketByteBuf packetByteBuf = PacketByteBufs.create();
|
||||
public PacketBuilder(ByteBuf buf) {
|
||||
// Read any data sent in the packet
|
||||
message = buf.toString(StandardCharsets.UTF_8);
|
||||
packetByteBuf.writeBytes(buf);
|
||||
}
|
||||
public PacketBuilder(String message) {
|
||||
this.message = message;
|
||||
packetByteBuf.writeBytes(ByteBuffer.wrap(message.getBytes(StandardCharsets.UTF_8)).array());
|
||||
}
|
||||
public static Identifier getIdentifier() {
|
||||
// only 1 packet rn
|
||||
return new Identifier(Sit.MOD_ID, SETTINGS);
|
||||
}
|
||||
public void send() {
|
||||
ClientPlayNetworking.send(getIdentifier(), packetByteBuf);
|
||||
}
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue