use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.
the class ConfigFile method syncToClient.
public void syncToClient(ServerPlayerEntity playerEntity, ConfigEnvironment environment, ConfigScope scope, ConfigOrigin origin) {
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeEnumConstant(origin);
packetByteBuf.writeString(name);
write(packetByteBuf, environment, scope, origin);
ServerSidePacketRegistry.INSTANCE.sendToPlayer(playerEntity, Tweed.CONFIG_SYNC_S2C_PACKET, packetByteBuf);
}
use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.
the class ConfigFile method syncToServer.
public void syncToServer(ConfigEnvironment environment, ConfigScope scope) {
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeString(name);
packetByteBuf.writeEnumConstant(environment);
packetByteBuf.writeEnumConstant(scope);
write(packetByteBuf, environment, scope, ConfigOrigin.MAIN);
ClientSidePacketRegistry.INSTANCE.sendToServer(Tweed.TWEED_CLOTH_SYNC_C2S_PACKET, packetByteBuf);
}
use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createCustomPacketStc.
// you can input a lambda expression and it will be invoked remotely
// but java serialization is not stable
@Deprecated
public static CustomPayloadS2CPacket createCustomPacketStc(ICustomStcPacket serializable) {
// it copies the data twice but as the packet is small it's of no problem
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream stream = null;
try {
stream = new ObjectOutputStream(byteArrayOutputStream);
stream.writeObject(serializable);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
ByteBuf buffer = Unpooled.buffer();
buffer.writeBytes(byteArrayOutputStream.toByteArray());
PacketByteBuf buf = new PacketByteBuf(buffer);
return new CustomPayloadS2CPacket(id_stcCustom, buf);
}
use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createStcDimensionConfirm.
public static CustomPayloadS2CPacket createStcDimensionConfirm(DimensionType dimensionType, Vec3d pos) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(dimensionType.getRawId());
buf.writeDouble(pos.x);
buf.writeDouble(pos.y);
buf.writeDouble(pos.z);
return new CustomPayloadS2CPacket(id_stcDimensionConfirm, buf);
}
use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.
the class MyNetwork method createRedirectedMessage.
public static CustomPayloadS2CPacket createRedirectedMessage(DimensionType dimension, Packet packet) {
int messageType = 0;
try {
messageType = NetworkState.PLAY.getPacketId(NetworkSide.CLIENTBOUND, packet);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeInt(dimension.getRawId());
buf.writeInt(messageType);
try {
packet.write(buf);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return new CustomPayloadS2CPacket(id_stcRedirected, buf);
}
Aggregations