package main.flowstoneenergy.enchants;

import java.util.Random;

import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class EnchantRandTeleHandler {
	@SubscribeEvent
	public void RandomTeleport(LivingAttackEvent event) {
		if(event.entity.worldObj.isRemote) return;
        if(event.source.getEntity() == null) return;
        if(!(event.source.getEntity() instanceof EntityPlayer)) return;
        teleport(world, (EntityPlayer) event.source.getEntity());
	}
	
	public void teleport(World world, Entity , double x, double y, double z) {
		if(entity.getHeldItem() == null) return;
        if(!entity.getHeldItem().isItemEnchanted());
        if(!(EnchantmentHelper.getEnchantments(entity.getHeldItem()).containsKey(HackeryMod.enchantVirus.effectId))) return;
		Random rand = new Random();
		if (rand.nextBoolean()) event.entity.posX += rand.nextDouble() + (rand.nextInt(5 - 0) + 0); else event.entity.posX -= rand.nextDouble() + (rand.nextInt(5 - 0) + 0);
		event.entity.posY += 40;
		if (rand.nextBoolean()) event.entity.posZ += rand.nextDouble() + (rand.nextInt(5 - 0) + 0); else event.entity.posZ -= rand.nextDouble() + (rand.nextInt(5 - 0) + 0);
		while (world.getBlock((int)event.entity.posX, (int)event.entity.posY - 1, (int)event.entity.posZ) == Blocks.air) {
			event.entity.posY -= 1;
		}
				
		event.entity.setPosition(event.entity.posX, event.entity.posY, event.entity.posZ);
	}
}

@@ -59,16 +59,198 @@
 andom;%0A%0A
+import main.flowstoneenergy.FlowstoneEnergy;%0Aimport net.minecraft.enchantment.EnchantmentHelper;%0Aimport net.minecraft.entity.Entity;%0Aimport net.minecraft.entity.player.EntityPlayer;%0A
 import n
@@ -543,19 +543,104 @@
 nt) %7B%0A%09%09
-if(
+EntityPlayer attacker = event.source;%0A%09%09Entity defender = event.entity;%0A%09%09World world = 
 event.en
@@ -652,16 +652,28 @@
 worldObj
+;%0A%09%09if(world
 .isRemot
@@ -691,16 +691,17 @@
         
+%09
 if(event
@@ -741,24 +741,25 @@
 rn;%0A        
+%09
 if(!(event.s
@@ -822,158 +822,20 @@
     
-teleport(world, (EntityPlayer) event.source.getEntity());%0A%09%7D%0A%09%0A%09public void teleport(World world, Entity , double x, double y, double z) %7B%0A%09%09if(entity
+%09if(attacker
 .get
@@ -874,18 +874,21 @@
     
+%09
 if(!
-entity
+attacker
 .get
@@ -926,16 +926,17 @@
         
+%09
 if(!(Enc
@@ -966,22 +966,24 @@
 ntments(
-entity
+attacker
 .getHeld
@@ -1006,31 +1006,39 @@
 Key(
-HackeryMod.e
+EnchantRegistry.randTeleE
 nchant
-Virus
 .eff
@@ -1054,16 +1054,125 @@
 return;%0A
+        %09teleport(world, event.source.getEntity());%0A%09%7D%0A%09%0A%09public void teleport(World world, Entity entity) %7B%0A
 %09%09Random
@@ -1211,38 +1211,32 @@
 .nextBoolean()) 
-event.
 entity.posX += r
@@ -1278,38 +1278,32 @@
 - 0) + 0); else 
-event.
 entity.posX -= r
@@ -1350,22 +1350,16 @@
 + 0);%0A%09%09
-event.
 entity.p
@@ -1395,22 +1395,16 @@
 lean()) 
-event.
 entity.p
@@ -1462,22 +1462,16 @@
 ); else 
-event.
 entity.p
@@ -1549,30 +1549,24 @@
 tBlock((int)
-event.
 entity.posX,
@@ -1567,30 +1567,24 @@
 .posX, (int)
-event.
 entity.posY 
@@ -1593,22 +1593,16 @@
 1, (int)
-event.
 entity.p
@@ -1626,22 +1626,16 @@
 r) %7B%0A%09%09%09
-event.
 entity.p
@@ -1655,22 +1655,16 @@
 %0A%09%09%09%09%0A%09%09
-event.
 entity.s
@@ -1674,22 +1674,16 @@
 osition(
-event.
 entity.p
@@ -1687,22 +1687,16 @@
 y.posX, 
-event.
 entity.p
@@ -1700,22 +1700,16 @@
 y.posY, 
-event.
 entity.p

Update EnchantRandTeleHandler.java