Ok, i do something but are some issues...
Here Packet class:
public class EmitParticlesPacket {
private int entityID;
private IParticleData particle;
private int lifeTime;
public <T extends IParticleData> EmitParticlesPacket(Entity entityIn, T particleIn, int lifeTimeIn) {
this.entityID = entityIn.getEntityId();
this.particle = particleIn;
this.lifeTime = lifeTimeIn;
}
public EmitParticlesPacket(PacketBuffer bufIn) throws IOException {
ParticleType<?> particleType = Registry.PARTICLE_TYPE.getByValue(bufIn.readInt());
if(particleType == null) {
particleType = ParticleTypes.BARRIER;
}
this.entityID = bufIn.readInt();
this.lifeTime = bufIn.readInt();
this.particle = readParticle(bufIn, particleType);
}
public void encoder(EmitParticlesPacket msg, PacketBuffer bufIn) throws IOException {
bufIn.writeInt(Registry.PARTICLE_TYPE.getId(this.particle.getType()));
bufIn.writeInt(this.entityID);
bufIn.writeInt(this.lifeTime);
this.particle.write(bufIn);
}
private <T extends IParticleData> T readParticle(PacketBuffer bufIn, ParticleType<T> particleType) {
return particleType.getDeserializer().read(particleType, bufIn);
}
public int getEntityID() {
return this.entityID;
}
public IParticleData getParticle() {
return this.particle;
}
public int getLifeTime() {
return this.lifeTime;
}
public static void handle(EmitParticlesPacket msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if(ctx.get().getDirection().getReceptionSide().equals(LogicalSide.CLIENT)) {
Minecraft client = Minecraft.getInstance();
client.particles.emitParticleAtEntity(client.world.getEntityByID(msg.getEntityID()), msg.getParticle(), msg.getLifeTime());
}
});
ctx.get().setPacketHandled(true);
}
}
Here the PacketHandler... here eclipse gives some errors at ISTANCE.registerMessage():
2 arg: The type EmitParticlesPacket does not define encoder(MSG, PacketBuffer) that is applicable here
3 arg: The constructed object of type EmitParticlesPacket is incompatible with the descriptor's return type: MSG
4 arg: The type EmitParticlesPacket does not define handle(MSG, Supplier<NetworkEvent.Context>) that is applicable here
Here the class of Packet Handler:
public class ModPacketHandler {
private static final String PROTOCOL_VER = "1";
public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
new ResourceLocation(FurtherPotionsMain.MODID, "main"),
() -> PROTOCOL_VER,
PROTOCOL_VER::equals,
PROTOCOL_VER::equals
);
public static void register() {
int ID = 0;
INSTANCE.registerMessage(ID++, EmitParticlesPacket.class, EmitParticlesPacket::encoder, EmitParticlesPacket::new, EmitParticlesPacket::handle);
}
}