forked from virt-mirrors/Sit
per player hand restrictions
* optimized code
This commit is contained in:
parent
614fddb6bd
commit
43c72ce1ba
7 changed files with 159 additions and 26 deletions
34
src/main/java/one/oth3r/sit/PacketBuilder.java
Normal file
34
src/main/java/one/oth3r/sit/PacketBuilder.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package one.oth3r.sit;
|
||||
|
||||
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 PacketByteBuf packetByteBuf = PacketByteBufs.create();
|
||||
public PacketBuilder(PacketByteBuf buf) {
|
||||
// Read any data sent in the packet
|
||||
message = StandardCharsets.UTF_8.decode(ByteBuffer.wrap(buf.array())).toString().trim();
|
||||
packetByteBuf = 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