Drill now doesn't break TileEntities with 3x3 or 5x5 Upgrade, also breaks middle block first, then blocks around that to prevent bugs when the Drill is almost out of fuel

This commit is contained in:
Ellpeck 2015-07-09 00:43:54 +02:00
parent 5077fed341
commit 1b36e7c19a

View file

@ -211,15 +211,36 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
zRange = radius; zRange = radius;
} }
//Break Middle Block first
int use = this.getEnergyUsePerBlock(stack);
if(this.getEnergyStored(stack) >= use){
this.tryHarvestBlock(world, x, y, z, false, stack, player, use);
}
else return;
//Break Blocks around
if(radius > 0){
for(int xPos = x-xRange; xPos <= x+xRange; xPos++){ for(int xPos = x-xRange; xPos <= x+xRange; xPos++){
for(int yPos = y-yRange; yPos <= y+yRange; yPos++){ for(int yPos = y-yRange; yPos <= y+yRange; yPos++){
for(int zPos = z-zRange; zPos <= z+zRange; zPos++){ for(int zPos = z-zRange; zPos <= z+zRange; zPos++){
int use = this.getEnergyUsePerBlock(stack); if(!(x == xPos && y == yPos && z == zPos)){
if(this.getEnergyStored(stack) >= use){ if(this.getEnergyStored(stack) >= use){
this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use);
}
else return;
}
}
}
}
}
}
}
private void tryHarvestBlock(World world, int xPos, int yPos, int zPos, boolean isExtra, ItemStack stack, EntityPlayer player, int use){
Block block = world.getBlock(xPos, yPos, zPos); Block block = world.getBlock(xPos, yPos, zPos);
float hardness = block.getBlockHardness(world, xPos, yPos, zPos); float hardness = block.getBlockHardness(world, xPos, yPos, zPos);
int meta = world.getBlockMetadata(xPos, yPos, zPos); int meta = world.getBlockMetadata(xPos, yPos, zPos);
if(hardness > -1.0F && ((x == xPos && y == yPos && z == zPos) || this.canHarvestBlock(block, stack))){ if(hardness >= 0.0F && (!isExtra || (this.canHarvestBlock(block, stack) && !block.hasTileEntity(meta)))){
this.extractEnergy(stack, use, false); this.extractEnergy(stack, use, false);
block.onBlockHarvested(world, xPos, yPos, zPos, meta, player); block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
@ -231,18 +252,12 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player))); block.dropXpOnBlockBreak(world, xPos, yPos, zPos, block.getExpDrop(world, meta, EnchantmentHelper.getFortuneModifier(player)));
} }
if(!(xPos == x && yPos == y && zPos == z)){ if(isExtra){
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12)); world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
} }
} }
} }
} }
else return;
}
}
}
}
}
@Override @Override
public String getName(){ public String getName(){