2015-03-16 12:58:53 +01:00
|
|
|
package mekanism.common;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-03-31 02:18:08 +02:00
|
|
|
import com.mojang.realmsclient.util.Pair;
|
|
|
|
|
2015-03-16 12:58:53 +01:00
|
|
|
import mekanism.api.Coord4D;
|
|
|
|
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.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-03-21 17:31:51 +01:00
|
|
|
import net.minecraft.util.DamageSource;
|
2015-03-16 12:58:53 +01:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.util.Vec3;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
public class LaserManager
|
|
|
|
{
|
2015-03-31 02:18:08 +02:00
|
|
|
public static LaserInfo fireLaser(TileEntity from, ForgeDirection direction, double energy, World world)
|
2015-03-16 12:58:53 +01:00
|
|
|
{
|
|
|
|
return fireLaser(new Pos3D(from).centre().translate(direction, 0.501), direction, energy, world);
|
|
|
|
}
|
|
|
|
|
2015-03-31 02:18:08 +02:00
|
|
|
public static LaserInfo fireLaser(Pos3D from, ForgeDirection direction, double energy, World world)
|
2015-03-16 12:58:53 +01:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
|
|
|
if(mop != null)
|
|
|
|
{
|
|
|
|
to = new Pos3D(mop.hitVec);
|
|
|
|
Coord4D toCoord = new Coord4D(mop.blockX, mop.blockY, mop.blockZ);
|
|
|
|
TileEntity tile = toCoord.getTileEntity(world);
|
|
|
|
|
|
|
|
if(tile instanceof ILaserReceptor)
|
|
|
|
{
|
|
|
|
if(!(((ILaserReceptor)tile).canLasersDig()))
|
|
|
|
{
|
|
|
|
((ILaserReceptor)tile).receiveLaserEnergy(energy, ForgeDirection.getOrientation(mop.sideHit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
from.translateExcludingSide(direction, -0.1);
|
|
|
|
to.translateExcludingSide(direction, 0.1);
|
2015-03-31 02:18:08 +02:00
|
|
|
|
|
|
|
boolean foundEntity = false;
|
2015-03-16 12:58:53 +01:00
|
|
|
|
|
|
|
for(Entity e : (List<Entity>)world.getEntitiesWithinAABB(Entity.class, Pos3D.getAABB(from, to)))
|
|
|
|
{
|
2015-03-31 02:18:08 +02:00
|
|
|
foundEntity = true;
|
|
|
|
|
2015-03-21 17:31:51 +01:00
|
|
|
if(!e.isImmuneToFire())
|
|
|
|
{
|
|
|
|
e.setFire((int)(energy / 1000));
|
2015-04-28 17:24:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(energy > 256)
|
|
|
|
{
|
|
|
|
e.attackEntityFrom(DamageSource.generic, (float)energy/1000F);
|
2015-03-21 17:31:51 +01:00
|
|
|
}
|
2015-03-16 12:58:53 +01:00
|
|
|
}
|
2015-03-31 02:18:08 +02:00
|
|
|
|
|
|
|
return new LaserInfo(mop, foundEntity);
|
2015-03-16 12:58:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static List<ItemStack> breakBlock(Coord4D blockCoord, boolean dropAtBlock, World world)
|
|
|
|
{
|
|
|
|
List<ItemStack> ret = null;
|
|
|
|
Block blockHit = blockCoord.getBlock(world);
|
|
|
|
|
|
|
|
if(dropAtBlock)
|
|
|
|
{
|
|
|
|
blockHit.dropBlockAsItem(world, blockCoord.xCoord, blockCoord.yCoord, blockCoord.zCoord, blockCoord.getMetadata(world), 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret = blockHit.getDrops(world, blockCoord.xCoord, blockCoord.yCoord, blockCoord.zCoord, blockCoord.getMetadata(world), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
blockHit.breakBlock(world, blockCoord.xCoord, blockCoord.yCoord, blockCoord.zCoord, blockHit, blockCoord.getMetadata(world));
|
|
|
|
world.setBlockToAir(blockCoord.xCoord, blockCoord.yCoord, blockCoord.zCoord);
|
|
|
|
world.playAuxSFX(2001, blockCoord.xCoord, blockCoord.yCoord, blockCoord.zCoord, Block.getIdFromBlock(blockHit));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-18 21:45:55 +01:00
|
|
|
public static MovingObjectPosition fireLaserClient(TileEntity from, ForgeDirection direction, double energy, World world)
|
2015-03-16 12:58:53 +01:00
|
|
|
{
|
2015-03-18 21:45:55 +01:00
|
|
|
return fireLaserClient(new Pos3D(from).centre().translate(direction, 0.501), direction, energy, world);
|
2015-03-16 12:58:53 +01:00
|
|
|
}
|
|
|
|
|
2015-03-18 21:45:55 +01:00
|
|
|
public static MovingObjectPosition fireLaserClient(Pos3D from, ForgeDirection direction, double energy, World world)
|
2015-03-16 12:58:53 +01:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
|
|
|
if(mop != null)
|
|
|
|
{
|
|
|
|
to = new Pos3D(mop.hitVec);
|
|
|
|
}
|
|
|
|
|
|
|
|
from.translate(direction, -0.501);
|
|
|
|
Mekanism.proxy.renderLaser(world, from, to, direction, energy);
|
2015-03-31 02:18:08 +02:00
|
|
|
|
2015-03-18 21:45:55 +01:00
|
|
|
return mop;
|
2015-03-16 12:58:53 +01:00
|
|
|
}
|
2015-03-31 02:18:08 +02:00
|
|
|
|
|
|
|
public static class LaserInfo
|
|
|
|
{
|
|
|
|
public MovingObjectPosition movingPos;
|
|
|
|
|
|
|
|
public boolean foundEntity;
|
|
|
|
|
|
|
|
public LaserInfo(MovingObjectPosition mop, boolean b)
|
|
|
|
{
|
|
|
|
movingPos = mop;
|
|
|
|
foundEntity = b;
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 12:58:53 +01:00
|
|
|
}
|