Made the Drill actually work

This commit is contained in:
Ellpeck 2015-07-20 22:06:08 +02:00
parent 71ec3d543f
commit bd997a10de
2 changed files with 49 additions and 41 deletions

View file

@ -272,14 +272,14 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
* @param z The Z Coord of the main Block to break * @param z The Z Coord of the main Block to break
* @param player The Player who breaks the Blocks * @param player The Player who breaks the Blocks
*/ */
public void breakBlocks(ItemStack stack, int radius, World world, int x, int y, int z, EntityPlayer player){ public boolean breakBlocks(ItemStack stack, int radius, World world, int x, int y, int z, EntityPlayer player){
int xRange = radius; int xRange = radius;
int yRange = radius; int yRange = radius;
int zRange = 0; int zRange = 0;
//Block hit //Block hit
MovingObjectPosition pos = WorldUtil.getNearestBlockWithDefaultReachDistance(world, player); MovingObjectPosition pos = WorldUtil.getNearestBlockWithDefaultReachDistance(world, player);
if(pos != null){ if(pos == null) return false;
//Corrects Blocks to hit depending on Side of original Block hit //Corrects Blocks to hit depending on Side of original Block hit
int side = pos.sideHit; int side = pos.sideHit;
@ -298,9 +298,9 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
//Break Middle Block first //Break Middle Block first
int use = this.getEnergyUsePerBlock(stack); int use = this.getEnergyUsePerBlock(stack);
if(this.getEnergyStored(stack) >= use){ if(this.getEnergyStored(stack) >= use){
this.tryHarvestBlock(world, x, y, z, false, stack, player, use); if(!this.tryHarvestBlock(world, x, y, z, false, stack, player, use)) return false;
} }
else return; else return false;
//Break Blocks around //Break Blocks around
if(radius > 0){ if(radius > 0){
@ -314,13 +314,13 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use); this.tryHarvestBlock(world, xPos, yPos, zPos, true, stack, player, use);
} }
} }
else return; else return false;
}
} }
} }
} }
} }
} }
return true;
} }
/** /**
@ -336,11 +336,12 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
* @param player The Player breaking the Blocks * @param player The Player breaking the Blocks
* @param use The Energy that should be extracted per Block * @param use The Energy that should be extracted per Block
*/ */
private void tryHarvestBlock(World world, int xPos, int yPos, int zPos, boolean isExtra, ItemStack stack, EntityPlayer player, int use){ private boolean 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 >= 0.0F && (this.canHarvestBlock(block, stack) && (!isExtra || !block.hasTileEntity(meta)))){ boolean canHarvest = this.canHarvestBlock(block, stack) && (!isExtra || this.getDigSpeed(stack, block, meta) > 1.0F);
if(hardness >= 0.0F && (!isExtra || (canHarvest && !block.hasTileEntity(meta)))){
this.extractEnergy(stack, use, false); this.extractEnergy(stack, use, false);
if(!world.isRemote){ if(!world.isRemote){
@ -352,14 +353,18 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12)); world.playAuxSFX(2001, xPos, yPos, zPos, Block.getIdFromBlock(block)+(meta << 12));
} }
//If the Block was actually "removed", meaning it will drop an Item
boolean removed = block.removedByPlayer(world, player, xPos, yPos, zPos, canHarvest);
//Actually removes the Block from the World //Actually removes the Block from the World
if(block.removedByPlayer(world, player, xPos, yPos, zPos, true)){ if(removed){
//Before the Block is destroyed, special cases //Before the Block is destroyed, special cases
block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta); block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
if(!world.isRemote && !player.capabilities.isCreativeMode){ if(!world.isRemote && !player.capabilities.isCreativeMode){
//Actually drops the Block's Items etc. //Actually drops the Block's Items etc.
if(canHarvest){
block.harvestBlock(world, player, xPos, yPos, zPos, meta); block.harvestBlock(world, player, xPos, yPos, zPos, meta);
}
//Only drop XP when no Silk Touch is applied //Only drop XP when no Silk Touch is applied
if(!EnchantmentHelper.getSilkTouchModifier(player)){ if(!EnchantmentHelper.getSilkTouchModifier(player)){
//Drop XP depending on Fortune Level //Drop XP depending on Fortune Level
@ -376,7 +381,9 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
//Check the Server if a Block that changed on the Client really changed, if not, revert the change //Check the Server if a Block that changed on the Client really changed, if not, revert the change
Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, xPos, yPos, zPos, Minecraft.getMinecraft().objectMouseOver.sideHit)); Minecraft.getMinecraft().getNetHandler().addToSendQueue(new C07PacketPlayerDigging(2, xPos, yPos, zPos, Minecraft.getMinecraft().objectMouseOver.sideHit));
} }
return removed;
} }
return false;
} }
@Override @Override
@ -386,6 +393,7 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
@Override @Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player){ public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player){
boolean toReturn = true;
int use = this.getEnergyUsePerBlock(stack); int use = this.getEnergyUsePerBlock(stack);
if(this.getEnergyStored(stack) >= use){ if(this.getEnergyStored(stack) >= use){
//Enchants the Drill depending on the Upgrades it has //Enchants the Drill depending on the Upgrades it has
@ -399,11 +407,11 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
//Breaks the Blocks //Breaks the Blocks
if(!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){ if(!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){ if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
this.breakBlocks(stack, 2, player.worldObj, x, y, z, player); toReturn = this.breakBlocks(stack, 2, player.worldObj, x, y, z, player);
} }
else this.breakBlocks(stack, 1, player.worldObj, x, y, z, player); else toReturn = this.breakBlocks(stack, 1, player.worldObj, x, y, z, player);
} }
else this.breakBlocks(stack, 0, player.worldObj, x, y, z, player); else toReturn = this.breakBlocks(stack, 0, player.worldObj, x, y, z, player);
//Removes Enchantments added above //Removes Enchantments added above
NBTTagList ench = stack.getEnchantmentTagList(); NBTTagList ench = stack.getEnchantmentTagList();
@ -416,7 +424,7 @@ public class ItemDrill extends ItemEnergy implements INameableItem{
} }
} }
} }
return true; return toReturn;
} }
@Override @Override

View file

@ -51,7 +51,7 @@ public class ItemAllToolAA extends ItemTool implements INameableItem{
@Override @Override
public boolean canHarvestBlock(Block block, ItemStack stack){ public boolean canHarvestBlock(Block block, ItemStack stack){
return block.getMaterial().isToolNotRequired() || (block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2))); return block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() == 3 : (block != Blocks.diamond_block && block != Blocks.diamond_ore ? (block != Blocks.emerald_ore && block != Blocks.emerald_block ? (block != Blocks.gold_block && block != Blocks.gold_ore ? (block != Blocks.iron_block && block != Blocks.iron_ore ? (block != Blocks.lapis_block && block != Blocks.lapis_ore ? (block != Blocks.redstone_ore && block != Blocks.lit_redstone_ore ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2));
} }
@Override @Override