package org.cyclops.cyclopscore.network.packet;

import net.minecraft.client.particle.EntityFlameFX;
import net.minecraft.client.particle.EntityLavaFX;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.cyclops.cyclopscore.CyclopsCore;
import org.cyclops.cyclopscore.helper.LocationHelpers;
import org.cyclops.cyclopscore.network.CodecField;
import org.cyclops.cyclopscore.network.PacketCodec;

/**
 * Packet for sending and showing the ring of fire.
 * 
 * @author rubensworks
 *
 */
public class RingOfFirePacket extends PacketCodec {
	
	private static final int RANGE = 3000;
    private static final double RING_AREA = 0.9F;
	
    @CodecField
	private String displayName;

	/**
	 * Creates a packet with no content
	 */
	public RingOfFirePacket() {
		
	}
	
	/**
	 * Creates a FartPacket which contains the player data.
	 * @param player The player data.
	 */
	public RingOfFirePacket(EntityPlayer player) {
		this.displayName = player.getDisplayName().getFormattedText();
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void actionClient(World world, EntityPlayer player) {
		if(!player.getDisplayNameString().equals(displayName)) {
			player = world.getPlayerEntityByName(displayName);
		}
		if(player != null) {
			showFireRing(player);
		}
	}
    
	@SideOnly(Side.CLIENT)
    private static void showFireRing(Entity entity) {
        double area = RING_AREA;
        World world = entity.worldObj;
        int points = 40;
        for(double point = -points; point <= points; point++) {
            double u = 2 * Math.PI * (point / points);

            double xOffset = Math.cos(u) * area;
            double yOffset = 0F;
            double zOffset = Math.sin(u) * area;

            double xCoord = entity.posX;
            double yCoord = entity.posY - 1;
            double zCoord = entity.posZ;

            double particleX = xCoord + xOffset + world.rand.nextFloat() / 5;
            double particleY = yCoord + yOffset + world.rand.nextFloat() / 5;
            double particleZ = zCoord + zOffset + world.rand.nextFloat() / 5;

            float particleMotionX = (float)xOffset / 5;
            float particleMotionY = 0.25F;
            float particleMotionZ = (float)zOffset / 5;

            if(world.rand.nextInt(20) == 0) {
                FMLClientHandler.instance().getClient().effectRenderer.addEffect(
                        new EntityLavaFX.Factory().getEntityFX(EnumParticleTypes.LAVA.getParticleID(), world, particleX, particleY, particleZ,
                                particleMotionX, particleMotionY, particleMotionZ, 0)
                        );
            } else {
                FMLClientHandler.instance().getClient().effectRenderer.addEffect(
                        new EntityFlameFX.Factory().getEntityFX(0, world, particleX, particleY, particleZ, 0, 0, 0)
                        );
            }
        }
    }

	@Override
	public void actionServer(World world, EntityPlayerMP player) {
		CyclopsCore._instance.getPacketHandler().sendToAllAround(new RingOfFirePacket(player),
                LocationHelpers.createTargetPointFromEntityPosition(player, RANGE));
	}
}

@@ -1278,27 +1278,14 @@
 Name
-().getFormattedText
+String
 ();%0A

Fix RingOfFirePacket calling client-side only methods