From 11e21e1957fa69104592096e10201263c0556f1d Mon Sep 17 00:00:00 2001 From: Ben Spiers Date: Mon, 14 Jul 2014 01:34:26 +0100 Subject: [PATCH] Start on implementation of lasers. --- .../mekanism/api/lasers/LaserManager.java | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/java/mekanism/api/lasers/LaserManager.java b/src/main/java/mekanism/api/lasers/LaserManager.java index 084866110..e61db4776 100644 --- a/src/main/java/mekanism/api/lasers/LaserManager.java +++ b/src/main/java/mekanism/api/lasers/LaserManager.java @@ -2,12 +2,48 @@ package mekanism.api.lasers; import mekanism.api.Coord4D; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.Vec3; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class LaserManager { - public static void fireLaser(Coord4D from, ForgeDirection direction, double energy) + public static int range = 100; + + public static void fireLaser(Coord4D from, ForgeDirection direction, double energy, World world) { - //TODO: Implement this + Coord4D to = from.getFromSide(direction, range); + MovingObjectPosition mop = world.rayTraceBlocks(Vec3.createVectorHelper(from.xCoord, from.yCoord, from.zCoord), Vec3.createVectorHelper(to.xCoord, to.yCoord, to.zCoord)); + + if(mop != null) + { + TileEntity tile = world.getTileEntity(mop.blockX, mop.blockY, mop.blockZ); + + if(tile instanceof ILaserReceptor) + { + if(((ILaserReceptor)tile).canLasersDig() && energy > ((ILaserReceptor)tile).energyToDig()) + { + //TODO dig block + } + else + { + ((ILaserReceptor)tile).receiveLaserEnergy(energy, ForgeDirection.getOrientation(mop.sideHit)); + } + } + + renderLaser(from, new Coord4D(mop.blockX, mop.blockY, mop.blockZ)); + } + else + { + renderLaser(from, to); + } + } + + public static void renderLaser(Coord4D from, Coord4D to) + { + //TODO Particle effects } }