forked from virt-mirrors/Sit
1.20.4 packet fix
This commit is contained in:
parent
0810fd64e8
commit
9d6cc9b785
6 changed files with 82 additions and 103 deletions
39
src/main/java/one/oth3r/sit/packet/PacketSender.java
Normal file
39
src/main/java/one/oth3r/sit/packet/PacketSender.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package one.oth3r.sit.packet;
|
||||
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketSender {
|
||||
private final PacketByteBuf data;
|
||||
private final PacketType type;
|
||||
|
||||
public PacketSender(PacketType type, String data) {
|
||||
this.type = type;
|
||||
this.data = PacketByteBufs.create()
|
||||
.writeBytes(ByteBuffer.wrap(data.getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
public void sendToPlayer(ServerPlayerEntity player) {
|
||||
ServerPlayNetworking.send(player,getIdentifier(type),data);
|
||||
}
|
||||
|
||||
public void sendToServer() {
|
||||
ClientPlayNetworking.send(getIdentifier(type),data);
|
||||
}
|
||||
|
||||
public static Identifier getIdentifier(PacketType packetType) {
|
||||
return new Identifier(Data.MOD_ID, packetType.getId());
|
||||
}
|
||||
|
||||
public static String getPacketData(PacketByteBuf buf) {
|
||||
return buf.toString(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue