Lasers can dig blocks now.
They have a tendency to set the items they drop on fire, might make a digging-specific variant later.
This commit is contained in:
parent
355209d2e3
commit
7fd5a28d61
7 changed files with 100 additions and 27 deletions
|
@ -34,7 +34,8 @@ public class MekanismConfig
|
|||
public static double FROM_IC2;
|
||||
public static double FROM_BC;
|
||||
public static double FROM_TE;
|
||||
public static int laserRange = 100;
|
||||
public static int laserRange;
|
||||
public static double laserEnergyNeededPerHardness;
|
||||
}
|
||||
|
||||
public static class client
|
||||
|
|
|
@ -7,6 +7,4 @@ public interface ILaserReceptor
|
|||
public void receiveLaserEnergy(double energy, ForgeDirection side);
|
||||
|
||||
public boolean canLasersDig();
|
||||
|
||||
public double energyToDig();
|
||||
}
|
||||
|
|
|
@ -238,6 +238,7 @@ public class CommonProxy
|
|||
general.FROM_TE = general.FROM_BC/10;
|
||||
|
||||
general.laserRange = Mekanism.configuration.get("general", "LaserRange", 100).getInt(100);
|
||||
general.laserEnergyNeededPerHardness = Mekanism.configuration.get("general", "LaserRange", 100000).getInt(100000);
|
||||
|
||||
usage.enrichmentChamberUsage = Mekanism.configuration.get("usage", "EnrichmentChamberUsage", 50D).getDouble(50D);
|
||||
usage.osmiumCompressorUsage = Mekanism.configuration.get("usage", "OsmiumCompressorUsage", 100D).getDouble(100D);
|
||||
|
|
|
@ -7,6 +7,7 @@ import mekanism.api.MekanismConfig.general;
|
|||
import mekanism.api.Pos3D;
|
||||
import mekanism.api.lasers.ILaserReceptor;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
|
@ -16,14 +17,15 @@ import net.minecraftforge.common.util.ForgeDirection;
|
|||
|
||||
public class LaserManager
|
||||
{
|
||||
public static void fireLaser(TileEntity from, ForgeDirection direction, double energy, World world)
|
||||
public static MovingObjectPosition fireLaser(TileEntity from, ForgeDirection direction, double energy, World world)
|
||||
{
|
||||
fireLaser(new Pos3D(from).centre().translate(direction, 0.501), direction, energy, world);
|
||||
return fireLaser(new Pos3D(from).centre().translate(direction, 0.501), direction, energy, world);
|
||||
}
|
||||
|
||||
public static void fireLaser(Pos3D from, ForgeDirection direction, double energy, World world)
|
||||
public static MovingObjectPosition fireLaser(Pos3D from, ForgeDirection direction, double energy, World world)
|
||||
{
|
||||
Pos3D to = from.clone().translate(direction, general.laserRange);
|
||||
|
||||
MovingObjectPosition mop = world.rayTraceBlocks(Vec3.createVectorHelper(from.xPos, from.yPos, from.zPos), Vec3.createVectorHelper(to.xPos, to.yPos, to.zPos));
|
||||
|
||||
if(mop != null)
|
||||
|
@ -34,11 +36,7 @@ public class LaserManager
|
|||
|
||||
if(tile instanceof ILaserReceptor)
|
||||
{
|
||||
if(((ILaserReceptor)tile).canLasersDig() && energy > ((ILaserReceptor)tile).energyToDig())
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
if(!(((ILaserReceptor)tile).canLasersDig()))
|
||||
{
|
||||
((ILaserReceptor)tile).receiveLaserEnergy(energy, ForgeDirection.getOrientation(mop.sideHit));
|
||||
}
|
||||
|
@ -52,6 +50,8 @@ public class LaserManager
|
|||
{
|
||||
if(!e.isImmuneToFire()) e.setFire((int)(energy / 1000));
|
||||
}
|
||||
|
||||
return mop;
|
||||
}
|
||||
|
||||
public static void fireLaserClient(TileEntity from, ForgeDirection direction, double energy, World world)
|
||||
|
|
|
@ -3,12 +3,20 @@ package mekanism.common.tile;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.MekanismConfig.general;
|
||||
import mekanism.api.MekanismConfig.usage;
|
||||
import mekanism.api.lasers.ILaserReceptor;
|
||||
import mekanism.common.LaserManager;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.particle.EffectRenderer;
|
||||
import net.minecraft.client.renderer.EntityRenderer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
@ -16,6 +24,8 @@ import io.netty.buffer.ByteBuf;
|
|||
public class TileEntityLaser extends TileEntityElectricBlock
|
||||
{
|
||||
public boolean on;
|
||||
public Coord4D digging;
|
||||
public double diggingProgress;
|
||||
|
||||
public TileEntityLaser()
|
||||
{
|
||||
|
@ -45,7 +55,39 @@ public class TileEntityLaser extends TileEntityElectricBlock
|
|||
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
|
||||
}
|
||||
|
||||
LaserManager.fireLaser(this, ForgeDirection.getOrientation(facing), usage.laserUsage, worldObj);
|
||||
MovingObjectPosition mop = LaserManager.fireLaser(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)
|
||||
{
|
||||
blockHit.dropBlockAsItem(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, hitCoord.getMetadata(worldObj), 0);
|
||||
blockHit.breakBlock(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, blockHit, hitCoord.getMetadata(worldObj));
|
||||
worldObj.setBlockToAir(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord);
|
||||
diggingProgress = 0;
|
||||
Minecraft.getMinecraft().effectRenderer.addBlockDestroyEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, blockHit, hitCoord.getMetadata(worldObj));
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getMinecraft().effectRenderer.addBlockHitEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, mop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setEnergy(getEnergy() - usage.laserUsage);
|
||||
}
|
||||
else if(on)
|
||||
|
|
|
@ -3,12 +3,18 @@ package mekanism.common.tile;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.api.MekanismConfig.general;
|
||||
import mekanism.api.MekanismConfig.usage;
|
||||
import mekanism.api.lasers.ILaserReceptor;
|
||||
import mekanism.common.LaserManager;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
@ -28,6 +34,9 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
|
|||
public boolean poweredLastTick = false;
|
||||
public boolean on = false;
|
||||
|
||||
public Coord4D digging;
|
||||
public double diggingProgress;
|
||||
|
||||
public TileEntityLaserAmplifier()
|
||||
{
|
||||
super("LaserAmplifier");
|
||||
|
@ -46,12 +55,6 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double energyToDig()
|
||||
{
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate()
|
||||
{
|
||||
|
@ -83,9 +86,43 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
|
|||
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
|
||||
}
|
||||
|
||||
LaserManager.fireLaser(this, ForgeDirection.getOrientation(facing), toFire(), worldObj);
|
||||
setEnergy(getEnergy() - toFire());
|
||||
lastFired = toFire();
|
||||
double firing = toFire();
|
||||
|
||||
MovingObjectPosition mop =LaserManager.fireLaser(this, ForgeDirection.getOrientation(facing), firing, 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 += firing;
|
||||
|
||||
if(diggingProgress >= hardness * general.laserEnergyNeededPerHardness)
|
||||
{
|
||||
blockHit.dropBlockAsItem(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, hitCoord.getMetadata(worldObj), 0);
|
||||
blockHit.breakBlock(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, blockHit, hitCoord.getMetadata(worldObj));
|
||||
worldObj.setBlockToAir(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord);
|
||||
diggingProgress = 0;
|
||||
Minecraft.getMinecraft().effectRenderer.addBlockDestroyEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, blockHit, hitCoord.getMetadata(worldObj));
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getMinecraft().effectRenderer.addBlockHitEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, mop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setEnergy(getEnergy() - firing);
|
||||
lastFired = firing;
|
||||
}
|
||||
else if(on)
|
||||
{
|
||||
|
|
|
@ -26,10 +26,4 @@ public class TileEntityReactorLaserFocusMatrix extends TileEntityReactorBlock im
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double energyToDig()
|
||||
{
|
||||
return Double.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue