diff --git a/src/main/java/mekanism/common/LaserManager.java b/src/main/java/mekanism/common/LaserManager.java index 6d44963fc..0836807cb 100644 --- a/src/main/java/mekanism/common/LaserManager.java +++ b/src/main/java/mekanism/common/LaserManager.java @@ -75,12 +75,12 @@ public class LaserManager return ret; } - public static void fireLaserClient(TileEntity from, ForgeDirection direction, double energy, World world) + public static MovingObjectPosition fireLaserClient(TileEntity from, ForgeDirection direction, double energy, World world) { - fireLaserClient(new Pos3D(from).centre().translate(direction, 0.501), direction, energy, world); + return fireLaserClient(new Pos3D(from).centre().translate(direction, 0.501), direction, energy, world); } - public static void fireLaserClient(Pos3D from, ForgeDirection direction, double energy, World world) + public static MovingObjectPosition fireLaserClient(Pos3D from, ForgeDirection direction, double energy, World world) { Pos3D to = from.clone().translate(direction, general.laserRange - 0.002); MovingObjectPosition mop = world.rayTraceBlocks(Vec3.createVectorHelper(from.xPos, from.yPos, from.zPos), Vec3.createVectorHelper(to.xPos, to.yPos, to.zPos)); @@ -92,5 +92,6 @@ public class LaserManager from.translate(direction, -0.501); Mekanism.proxy.renderLaser(world, from, to, direction, energy); + return mop; } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/tile/TileEntityLaser.java b/src/main/java/mekanism/common/tile/TileEntityLaser.java index aa765197d..ce7ddcfb5 100644 --- a/src/main/java/mekanism/common/tile/TileEntityLaser.java +++ b/src/main/java/mekanism/common/tile/TileEntityLaser.java @@ -47,7 +47,31 @@ public class TileEntityLaser extends TileEntityNoisyElectricBlock implements IAc { if(isActive) { - LaserManager.fireLaserClient(this, ForgeDirection.getOrientation(facing), usage.laserUsage, worldObj); + MovingObjectPosition mop = LaserManager.fireLaserClient(this, ForgeDirection.getOrientation(facing), usage.laserUsage, worldObj); + Coord4D hitCoord = mop == null ? null : new Coord4D(mop.blockX, mop.blockY, mop.blockZ); + + if(hitCoord == null || !hitCoord.equals(digging)) + { + digging = hitCoord; + diggingProgress = 0; + } + + if(hitCoord != null) + { + Block blockHit = hitCoord.getBlock(worldObj); + TileEntity tileHit = hitCoord.getTileEntity(worldObj); + float hardness = blockHit.getBlockHardness(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord); + + if(!(hardness < 0 || (tileHit instanceof ILaserReceptor && !((ILaserReceptor)tileHit).canLasersDig()))) + { + diggingProgress += usage.laserUsage; + + if(diggingProgress < hardness*general.laserEnergyNeededPerHardness) + { + Mekanism.proxy.addHitEffects(hitCoord, mop); + } + } + } } } else { @@ -79,9 +103,6 @@ public class TileEntityLaser extends TileEntityNoisyElectricBlock implements IAc LaserManager.breakBlock(hitCoord, true, worldObj); diggingProgress = 0; } - else { - Minecraft.getMinecraft().effectRenderer.addBlockHitEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, mop); - } } } @@ -127,7 +148,7 @@ public class TileEntityLaser extends TileEntityNoisyElectricBlock implements IAc @Override public boolean lightUpdate() { - return true; + return false; } @Override diff --git a/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java b/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java index 7fb870869..27bb32527 100644 --- a/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java +++ b/src/main/java/mekanism/common/tile/TileEntityLaserAmplifier.java @@ -61,7 +61,32 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement { if(on) { - LaserManager.fireLaserClient(this, ForgeDirection.getOrientation(facing), lastFired, worldObj); + MovingObjectPosition mop = LaserManager.fireLaserClient(this, ForgeDirection.getOrientation(facing), lastFired, worldObj); + Coord4D hitCoord = mop == null ? null : new Coord4D(mop.blockX, mop.blockY, mop.blockZ); + + if(hitCoord == null || !hitCoord.equals(digging)) + { + digging = hitCoord; + diggingProgress = 0; + } + + if(hitCoord != null) + { + Block blockHit = hitCoord.getBlock(worldObj); + TileEntity tileHit = hitCoord.getTileEntity(worldObj); + float hardness = blockHit.getBlockHardness(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord); + + if(!(hardness < 0 || (tileHit instanceof ILaserReceptor && !((ILaserReceptor)tileHit).canLasersDig()))) + { + diggingProgress += lastFired; + + if(diggingProgress < hardness*general.laserEnergyNeededPerHardness) + { + Mekanism.proxy.addHitEffects(hitCoord, mop); + } + } + } + } } else { @@ -108,9 +133,6 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement LaserManager.breakBlock(hitCoord, true, worldObj); diggingProgress = 0; } - else { - Mekanism.proxy.addHitEffects(hitCoord, mop); - } } } diff --git a/src/main/java/mekanism/common/tile/TileEntityLaserTractorBeam.java b/src/main/java/mekanism/common/tile/TileEntityLaserTractorBeam.java index f3d41d602..7858a1098 100644 --- a/src/main/java/mekanism/common/tile/TileEntityLaserTractorBeam.java +++ b/src/main/java/mekanism/common/tile/TileEntityLaserTractorBeam.java @@ -60,7 +60,31 @@ public class TileEntityLaserTractorBeam extends TileEntityContainerBlock impleme { if(on) { - LaserManager.fireLaserClient(this, ForgeDirection.getOrientation(facing), lastFired, worldObj); + MovingObjectPosition mop = LaserManager.fireLaserClient(this, ForgeDirection.getOrientation(facing), lastFired, worldObj); + Coord4D hitCoord = mop == null ? null : new Coord4D(mop.blockX, mop.blockY, mop.blockZ); + + if(hitCoord == null || !hitCoord.equals(digging)) + { + digging = hitCoord; + diggingProgress = 0; + } + + if(hitCoord != null) + { + Block blockHit = hitCoord.getBlock(worldObj); + TileEntity tileHit = hitCoord.getTileEntity(worldObj); + float hardness = blockHit.getBlockHardness(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord); + if(!(hardness < 0 || (tileHit instanceof ILaserReceptor && !((ILaserReceptor)tileHit).canLasersDig()))) + { + diggingProgress += lastFired; + + if(diggingProgress < hardness * general.laserEnergyNeededPerHardness) + { + Mekanism.proxy.addHitEffects(hitCoord, mop); + } + } + } + } } else @@ -100,10 +124,6 @@ public class TileEntityLaserTractorBeam extends TileEntityContainerBlock impleme if(drops != null) receiveDrops(drops); diggingProgress = 0; } - else - { - Minecraft.getMinecraft().effectRenderer.addBlockHitEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, mop); - } } }