001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.server.packets.play.out; 019 020import io.netty.buffer.ByteBuf; 021import net.tridentsdk.base.Position; 022import net.tridentsdk.effect.particle.ParticleEffectType; 023import net.tridentsdk.server.netty.Codec; 024import net.tridentsdk.server.netty.packet.OutPacket; 025import net.tridentsdk.util.Vector; 026 027public class PacketPlayOutParticle extends OutPacket { 028 protected ParticleEffectType particle; 029 protected boolean distance; 030 protected Position loc; 031 protected Vector offset; // d - (d * Random#nextGaussian()) 032 protected float particleData; 033 protected int count; 034 protected int[] data; 035 036 @Override 037 public int id() { 038 return 0x2A; 039 } 040 041 public ParticleEffectType particle() { 042 return this.particle; 043 } 044 045 public boolean isDistance() { 046 return this.distance; 047 } 048 049 public Position location() { 050 return this.loc; 051 } 052 053 public Vector offset() { 054 return this.offset; 055 } 056 057 public float particleData() { 058 return this.particleData; 059 } 060 061 public int count() { 062 return this.count; 063 } 064 065 public int[] data() { 066 return this.data; 067 } 068 069 @Override 070 public void encode(ByteBuf buf) { 071 buf.writeInt(this.particle.id()); 072 buf.writeBoolean(this.distance); 073 074 buf.writeFloat((float) this.loc.x()); 075 buf.writeFloat((float) this.loc.y()); 076 buf.writeFloat((float) this.loc.z()); 077 078 buf.writeFloat((float) this.offset.x()); 079 buf.writeFloat((float) this.offset.y()); 080 buf.writeFloat((float) this.offset.z()); 081 082 buf.writeFloat(this.particleData); 083 buf.writeInt(this.count); 084 085 for (int i : this.data) { 086 Codec.writeVarInt32(buf, i); 087 } 088 } 089}