Applied-Energistics-2-tiler.../core/sync/packets/PacketMatterCannon.java

90 lines
2.1 KiB
Java
Raw Normal View History

package appeng.core.sync.packets;
2014-02-09 02:34:52 +01:00
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
2014-02-09 02:34:52 +01:00
import net.minecraft.init.Items;
import net.minecraft.world.World;
2014-07-07 04:04:58 +02:00
import appeng.client.render.effects.MatterCannonFX;
import appeng.core.sync.AppEngPacket;
2014-02-09 02:34:52 +01:00
import appeng.core.sync.network.INetworkInfo;
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 {
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)
{
try
{
World world = FMLClientHandler.instance().getClient().theWorld;
for (int a = 1; a < len; a++)
{
2014-07-07 04:04:58 +02:00
MatterCannonFX fx = new MatterCannonFX( world, x + dx * a, y + dy * a, z + dz * a, Items.diamond );
Minecraft.getMinecraft().effectRenderer.addEffect( (EntityFX) fx );
}
}
catch (Exception err)
{
}
}
// 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();
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 );
}
}