Move block breaking function into LaserManager.

This commit is contained in:
Ben Spiers 2014-09-15 03:47:59 +01:00
parent 44d852ee9b
commit 944e288f89
4 changed files with 24 additions and 13 deletions

View file

@ -7,7 +7,9 @@ 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;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
@ -53,6 +55,24 @@ public class LaserManager
return mop;
}
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;
}
public static void fireLaserClient(TileEntity from, ForgeDirection direction, double energy, World world)
{
fireLaserClient(new Pos3D(from).centre().translate(direction, 0.501), direction, energy, world);

View file

@ -73,11 +73,8 @@ public class TileEntityLaser extends TileEntityElectricBlock
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);
LaserManager.breakBlock(hitCoord, true, worldObj);
diggingProgress = 0;
Minecraft.getMinecraft().effectRenderer.addBlockDestroyEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, blockHit, hitCoord.getMetadata(worldObj));
}
else
{

View file

@ -88,7 +88,7 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
Mekanism.packetHandler.sendToAllAround(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), Coord4D.get(this).getTargetPoint(50D));
}
MovingObjectPosition mop =LaserManager.fireLaser(this, ForgeDirection.getOrientation(facing), firing, worldObj);
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))
@ -108,11 +108,8 @@ public class TileEntityLaserAmplifier extends TileEntityContainerBlock implement
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);
LaserManager.breakBlock(hitCoord, true, worldObj);
diggingProgress = 0;
Minecraft.getMinecraft().effectRenderer.addBlockDestroyEffects(hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, blockHit, hitCoord.getMetadata(worldObj));
}
else
{

View file

@ -96,12 +96,9 @@ public class TileEntityLaserTractorBeam extends TileEntityContainerBlock impleme
if(diggingProgress >= hardness * general.laserEnergyNeededPerHardness)
{
List<ItemStack> drops = blockHit.getDrops(worldObj, hitCoord.xCoord, hitCoord.yCoord, hitCoord.zCoord, hitCoord.getMetadata(worldObj), 0);
List<ItemStack> drops = LaserManager.breakBlock(hitCoord, false, worldObj);
if(drops != null) receiveDrops(drops);
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
{