1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package ihl.enviroment;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import ic2.api.event.LaserEvent;
import ic2.core.item.tool.EntityMiningLaser;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class LaserHitMirrorEventHandler
{
public LaserHitMirrorEventHandler(){}
@SubscribeEvent
public void onLaserHit(LaserEvent.LaserHitsBlockEvent event)
{
TileEntity te = event.world.getTileEntity(event.x, event.y, event.z);
if(te instanceof MirrorTileEntity)
{
ForgeDirection mirrorDirection = ForgeDirection.getOrientation(((MirrorTileEntity)te).getFacing());
Entity ls = event.lasershot;
if((ls.motionX*mirrorDirection.offsetX+ls.motionY*mirrorDirection.offsetY+ls.motionZ*mirrorDirection.offsetZ)<0)
{
if(mirrorDirection.offsetX!=0)
{
ls.motionX=-ls.motionX;
}
if(mirrorDirection.offsetY!=0)
{
ls.motionY=-ls.motionY;
}
if(mirrorDirection.offsetZ!=0)
{
ls.motionZ=-ls.motionZ;
}
if(!event.world.isRemote)
{
EntityMiningLaser tLaser = new EntityMiningLaser(event.world, event.owner, event.range, event.power, event.blockBreaks, event.explosive, 0, 0, ls.posY);
tLaser.setPosition(ls.posX, ls.posY, ls.posZ);
tLaser.setLaserHeading(ls.motionX, ls.motionY, ls.motionZ, 1d);
ls.setDead();
event.world.spawnEntityInWorld(tLaser);
}
event.setCanceled(true);
}
}
}
}
|