mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-20 00:13:21 +02:00
parent
be158c66ed
commit
4ec37db7b0
3 changed files with 47 additions and 26 deletions
35
src/main/java/one/oth3r/sit/PacketBuilder.java
Normal file
35
src/main/java/one/oth3r/sit/PacketBuilder.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
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