summaryrefslogtreecommitdiff
path: root/ihl/enviroment/LaserHitMirrorEventHandler.java
diff options
context:
space:
mode:
authorFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
committerFoghrye4 <foghrye4@gmail.com>2016-04-11 19:44:54 +0300
commit05c78126859231a68e199dc34613689bd0978e2f (patch)
tree050bea104a18c72905095d29f31bec2935a27a24 /ihl/enviroment/LaserHitMirrorEventHandler.java
Initial commit
Diffstat (limited to 'ihl/enviroment/LaserHitMirrorEventHandler.java')
-rw-r--r--ihl/enviroment/LaserHitMirrorEventHandler.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/ihl/enviroment/LaserHitMirrorEventHandler.java b/ihl/enviroment/LaserHitMirrorEventHandler.java
new file mode 100644
index 0000000..9baee2d
--- /dev/null
+++ b/ihl/enviroment/LaserHitMirrorEventHandler.java
@@ -0,0 +1,48 @@
+package ihl.enviroment;
+
+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;
+import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+
+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);
+ }
+ }
+ }
+}