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

92 lines
3 KiB
Java
Raw Normal View History

2018-10-14 14:27:18 +02:00
package de.ellpeck.naturesaura.packet;
import de.ellpeck.naturesaura.NaturesAura;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class PacketParticles implements IMessage {
2018-10-16 01:36:30 +02:00
private float posX;
private float posY;
private float posZ;
private float motionX;
private float motionY;
private float motionZ;
2018-10-14 14:27:18 +02:00
private int color;
private float scale;
2018-10-16 01:36:30 +02:00
private int maxAge;
private float gravity;
private boolean collision;
private boolean fade;
2018-10-14 14:27:18 +02:00
2018-10-16 01:36:30 +02:00
public PacketParticles(float posX, float posY, float posZ, float motionX, float motionY, float motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) {
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
this.motionX = motionX;
this.motionY = motionY;
this.motionZ = motionZ;
2018-10-14 14:27:18 +02:00
this.color = color;
this.scale = scale;
2018-10-16 01:36:30 +02:00
this.maxAge = maxAge;
this.gravity = gravity;
this.collision = collision;
this.fade = fade;
2018-10-14 14:27:18 +02:00
}
public PacketParticles() {
}
@Override
public void fromBytes(ByteBuf buf) {
2018-10-16 01:36:30 +02:00
this.posX = buf.readFloat();
this.posY = buf.readFloat();
this.posZ = buf.readFloat();
this.motionX = buf.readFloat();
this.motionY = buf.readFloat();
this.motionZ = buf.readFloat();
2018-10-14 14:27:18 +02:00
this.color = buf.readInt();
this.scale = buf.readFloat();
2018-10-16 01:36:30 +02:00
this.maxAge = buf.readInt();
this.gravity = buf.readFloat();
this.collision = buf.readBoolean();
this.fade = buf.readBoolean();
2018-10-14 14:27:18 +02:00
}
@Override
public void toBytes(ByteBuf buf) {
2018-10-16 01:36:30 +02:00
buf.writeFloat(this.posX);
buf.writeFloat(this.posY);
buf.writeFloat(this.posZ);
buf.writeFloat(this.motionX);
buf.writeFloat(this.motionY);
buf.writeFloat(this.motionZ);
2018-10-14 14:27:18 +02:00
buf.writeInt(this.color);
buf.writeFloat(this.scale);
2018-10-16 01:36:30 +02:00
buf.writeInt(this.maxAge);
buf.writeFloat(this.gravity);
buf.writeBoolean(this.collision);
buf.writeBoolean(this.fade);
2018-10-14 14:27:18 +02:00
}
public static class Handler implements IMessageHandler<PacketParticles, IMessage> {
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(PacketParticles message, MessageContext ctx) {
2018-10-16 01:36:30 +02:00
NaturesAura.proxy.scheduleTask(() ->
NaturesAura.proxy.spawnMagicParticle(Minecraft.getMinecraft().world,
message.posX, message.posY, message.posZ,
message.motionX, message.motionY, message.motionZ,
message.color, message.scale, message.maxAge, message.gravity, message.collision, message.fade));
2018-10-14 14:27:18 +02:00
return null;
}
}
}