2023-11-21 23:21:47 -06:00
|
|
|
package one.oth3r.sit;
|
|
|
|
|
2023-12-05 13:56:56 -06:00
|
|
|
import io.netty.buffer.ByteBuf;
|
2023-11-21 23:21:47 -06:00
|
|
|
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;
|
2023-12-05 13:56:56 -06:00
|
|
|
private final PacketByteBuf packetByteBuf = PacketByteBufs.create();
|
|
|
|
public PacketBuilder(ByteBuf buf) {
|
2023-11-21 23:21:47 -06:00
|
|
|
// Read any data sent in the packet
|
2023-11-30 17:58:16 -06:00
|
|
|
message = buf.toString(StandardCharsets.UTF_8);
|
2023-12-05 13:56:56 -06:00
|
|
|
packetByteBuf.writeBytes(buf);
|
2023-11-21 23:21:47 -06:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|