2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.sync.packets;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.particle.EntityFX;
|
2014-01-05 09:39:48 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Items;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import appeng.client.render.effects.MatterCannonEffect;
|
|
|
|
import appeng.core.sync.AppEngPacket;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.core.sync.network.INetworkInfo;
|
2013-12-27 23:59:59 +01:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
public class PacketMatterCannon extends AppEngPacket
|
|
|
|
{
|
|
|
|
|
|
|
|
final double x;
|
|
|
|
final double y;
|
|
|
|
final double z;
|
|
|
|
final double dx;
|
|
|
|
final double dy;
|
|
|
|
final double dz;
|
|
|
|
final byte len;
|
|
|
|
|
|
|
|
// automatic.
|
2014-02-09 02:34:52 +01:00
|
|
|
public PacketMatterCannon(ByteBuf stream) throws IOException {
|
2013-12-27 23:59:59 +01:00
|
|
|
x = stream.readFloat();
|
|
|
|
y = stream.readFloat();
|
|
|
|
z = stream.readFloat();
|
|
|
|
dx = stream.readFloat();
|
|
|
|
dy = stream.readFloat();
|
|
|
|
dz = stream.readFloat();
|
|
|
|
len = stream.readByte();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2014-02-09 02:34:52 +01:00
|
|
|
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
World world = FMLClientHandler.instance().getClient().theWorld;
|
|
|
|
for (int a = 1; a < len; a++)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
MatterCannonEffect fx = new MatterCannonEffect( world, x + dx * a, y + dy * a, z + dz * a, Items.diamond );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
|
|
|
|
}
|
2014-01-05 09:39:48 +01:00
|
|
|
}
|
|
|
|
catch (Exception err)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// api
|
|
|
|
public PacketMatterCannon(double x, double y, double z, float dx, float dy, float dz, byte len) throws IOException {
|
|
|
|
float dl = dx * dx + dy * dy + dz * dz;
|
|
|
|
float dlz = (float) Math.sqrt( dl );
|
|
|
|
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
|
|
|
this.dx = dx / dlz;
|
|
|
|
this.dy = dy / dlz;
|
|
|
|
this.dz = dz / dlz;
|
|
|
|
this.len = len;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
ByteBuf data = Unpooled.buffer();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
data.writeInt( getPacketID() );
|
|
|
|
data.writeFloat( (float) x );
|
|
|
|
data.writeFloat( (float) y );
|
|
|
|
data.writeFloat( (float) z );
|
|
|
|
data.writeFloat( (float) this.dx );
|
|
|
|
data.writeFloat( (float) this.dy );
|
|
|
|
data.writeFloat( (float) this.dz );
|
|
|
|
data.writeByte( len );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
configureWrite( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|