Make Lasers better at server-side

This commit is contained in:
Ben Spiers 2015-03-18 20:45:55 +00:00
parent 0307acc7eb
commit a21e679a1d
4 changed files with 81 additions and 17 deletions

View file

@ -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;
}
}

View file

@ -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

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}