NaturesAura/src/main/java/de/ellpeck/naturesaura/packet/PacketParticleStream.java

75 lines
2.2 KiB
Java
Raw Normal View History

2018-10-16 01:36:30 +02:00
package de.ellpeck.naturesaura.packet;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
2021-12-04 15:40:09 +01:00
import net.minecraft.network.FriendlyByteBuf;
2024-02-03 14:56:07 +01:00
import net.neoforged.neoforge.network.NetworkEvent;
2018-10-16 01:36:30 +02:00
2020-01-22 01:35:47 +01:00
import java.util.function.Supplier;
2020-01-22 23:21:52 +01:00
public class PacketParticleStream {
2018-10-16 01:36:30 +02:00
private float startX;
private float startY;
private float startZ;
private float endX;
private float endY;
private float endZ;
private float speed;
private int color;
private float scale;
public PacketParticleStream(float startX, float startY, float startZ, float endX, float endY, float endZ, float speed, int color, float scale) {
this.startX = startX;
this.startY = startY;
this.startZ = startZ;
this.endX = endX;
this.endY = endY;
this.endZ = endZ;
this.speed = speed;
this.color = color;
this.scale = scale;
}
2020-01-22 23:21:52 +01:00
private PacketParticleStream() {
2018-10-16 01:36:30 +02:00
}
2021-12-04 15:40:09 +01:00
public static PacketParticleStream fromBytes(FriendlyByteBuf buf) {
2021-12-15 16:30:22 +01:00
var packet = new PacketParticleStream();
2020-01-22 01:35:47 +01:00
packet.startX = buf.readFloat();
packet.startY = buf.readFloat();
packet.startZ = buf.readFloat();
packet.endX = buf.readFloat();
packet.endY = buf.readFloat();
packet.endZ = buf.readFloat();
packet.speed = buf.readFloat();
packet.color = buf.readInt();
packet.scale = buf.readFloat();
return packet;
2018-10-16 01:36:30 +02:00
}
2021-12-04 15:40:09 +01:00
public static void toBytes(PacketParticleStream packet, FriendlyByteBuf buf) {
2020-01-22 01:35:47 +01:00
buf.writeFloat(packet.startX);
buf.writeFloat(packet.startY);
buf.writeFloat(packet.startZ);
buf.writeFloat(packet.endX);
buf.writeFloat(packet.endY);
buf.writeFloat(packet.endZ);
buf.writeFloat(packet.speed);
buf.writeInt(packet.color);
buf.writeFloat(packet.scale);
2018-10-16 01:36:30 +02:00
}
2020-01-22 23:21:52 +01:00
public static void onMessage(PacketParticleStream message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> NaturesAuraAPI.instance().spawnParticleStream(
message.startX, message.startY, message.startZ,
message.endX, message.endY, message.endZ,
message.speed, message.color, message.scale));
2018-10-16 01:36:30 +02:00
2020-01-22 23:21:52 +01:00
ctx.get().setPacketHandled(true);
2018-10-16 01:36:30 +02:00
}
2020-01-22 01:35:47 +01:00
}