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

84 lines
2.5 KiB
Java
Raw Normal View History

2018-10-16 01:36:30 +02:00
package de.ellpeck.naturesaura.packet;
import de.ellpeck.naturesaura.NaturesAura;
2018-11-11 13:26:19 +01:00
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
2018-10-16 01:36:30 +02:00
import io.netty.buffer.ByteBuf;
2020-01-22 01:35:47 +01:00
import net.minecraft.network.PacketBuffer;
2019-10-20 22:30:49 +02:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
2020-01-22 01:35:47 +01:00
import net.minecraftforge.fml.network.NetworkEvent;
2018-10-16 01:36:30 +02:00
2020-01-22 01:35:47 +01:00
import java.util.function.Supplier;
public class PacketParticleStream implements IPacket {
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;
}
public PacketParticleStream() {
}
2020-01-22 01:35:47 +01:00
public static PacketParticleStream fromBytes(PacketBuffer buf) {
PacketParticleStream packet = new PacketParticleStream();
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
}
2020-01-22 01:35:47 +01:00
public static void toBytes(PacketParticleStream packet, PacketBuffer buf) {
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 01:35:47 +01:00
public static class Handler {
2018-10-16 01:36:30 +02:00
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
2020-01-22 01:35:47 +01:00
public static void onMessage(PacketParticleStream message, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> NaturesAuraAPI.instance().spawnParticleStream(
2018-11-13 00:36:47 +01:00
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 01:35:47 +01:00
ctx.get().setPacketHandled(true);
2018-10-16 01:36:30 +02:00
}
}
2020-01-22 01:35:47 +01:00
}