From a3064c12cd559c2a677ae72b19cf254d51f35473 Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Fri, 7 Nov 2014 18:51:18 +0100 Subject: [PATCH] quarries and mining wells emit blockbreakevents now (for #2162), quarry speed fixed --- common/buildcraft/factory/TileMiningWell.java | 12 ++++++++++++ common/buildcraft/factory/TileQuarry.java | 14 ++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/common/buildcraft/factory/TileMiningWell.java b/common/buildcraft/factory/TileMiningWell.java index 6491ee84..7414d70c 100644 --- a/common/buildcraft/factory/TileMiningWell.java +++ b/common/buildcraft/factory/TileMiningWell.java @@ -10,11 +10,14 @@ package buildcraft.factory; import java.util.List; +import buildcraft.core.proxy.CoreProxy; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.event.world.BlockEvent.BreakEvent; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftFactory; import buildcraft.api.tiles.IHasWork; @@ -64,6 +67,15 @@ public class TileMiningWell extends TileBuildCraft implements IHasWork, IPipeCon return; } + BreakEvent breakEvent = new BreakEvent(xCoord, depth, zCoord, worldObj, world.getBlock(xCoord, depth, zCoord), + world.getBlockMetadata(xCoord, depth, zCoord), CoreProxy.proxy.getBuildCraftPlayer((WorldServer) world).get()); + MinecraftForge.EVENT_BUS.post(breakEvent); + + if (breakEvent.isCanceled()) { + isDigging = false; + return; + } + boolean wasAir = world.isAirBlock(xCoord, depth, zCoord); List stacks = BlockUtil.getItemStackFromBlock((WorldServer) worldObj, xCoord, depth, zCoord); diff --git a/common/buildcraft/factory/TileQuarry.java b/common/buildcraft/factory/TileQuarry.java index 19a895ef..31cbfc85 100644 --- a/common/buildcraft/factory/TileQuarry.java +++ b/common/buildcraft/factory/TileQuarry.java @@ -28,6 +28,7 @@ import net.minecraft.world.WorldServer; import net.minecraftforge.common.ForgeChunkManager; import net.minecraftforge.common.ForgeChunkManager.Ticket; import net.minecraftforge.common.ForgeChunkManager.Type; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftFactory; @@ -50,6 +51,7 @@ import buildcraft.core.network.PacketUpdate; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.BlockUtil; import buildcraft.core.utils.Utils; +import net.minecraftforge.event.world.BlockEvent; public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedInventory { @@ -172,10 +174,10 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI } else if (stage == Stage.IDLE) { dig(); } else if (stage == Stage.DIGGING) { - int energyToUse = 20 + Math.round(getBattery().getEnergyStored() / 500); + int energyToUse = 20 + (int) Math.ceil(getBattery().getEnergyStored() / 500); if (this.consumeEnergy(energyToUse)) { - speed = 0.1 + energyToUse / 200F; + speed = 0.1 + energyToUse / 2000F; moveHead(speed); } } @@ -406,8 +408,12 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI Block block = worldObj.getBlock(i, j, k); int meta = worldObj.getBlockMetadata(i, j, k); - - if (isQuarriableBlock(i, j, k)) { + + BlockEvent.BreakEvent breakEvent = new BlockEvent.BreakEvent(i, j, k, worldObj, block, meta, + CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj).get()); + MinecraftForge.EVENT_BUS.post(breakEvent); + + if (!breakEvent.isCanceled() && isQuarriableBlock(i, j, k)) { // Share this with mining well! List stacks = BlockUtil.getItemStackFromBlock((WorldServer) worldObj, i, j, k);