Skip to content

Commit

Permalink
Fire blockbreak event
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 2, 2014
1 parent 5bc9534 commit f6e6798
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/main/java/tconstruct/items/tools/Excavator.java
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.AbilityHelper;
Expand Down Expand Up @@ -206,6 +208,12 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
cancelHarvest = true;
}

// send blockbreak event
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, localBlock, localMeta, player);
event.setCanceled(cancelHarvest);
MinecraftForge.EVENT_BUS.post(event);
cancelHarvest = event.isCanceled();

if (!cancelHarvest)
{
if (localBlock != null && !(localHardness < 0))
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/tconstruct/items/tools/Hammer.java
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.ToolBuilder;
Expand Down Expand Up @@ -296,7 +298,7 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
int hlvl = -1;
if (localBlock.getHarvestTool(localMeta) != null && localBlock.getHarvestTool(localMeta).equals(this.getHarvestType()))
hlvl = localBlock.getHarvestLevel(localMeta);
float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos);
float localHardness = localBlock.getBlockHardness(world, xPos, yPos, zPos);

//Choose blocks that aren't too much harder than the first block. Stone: 2.0, Ores: 3.0
if (hlvl <= toolLevel && localHardness - 1.5 <= blockHardness)
Expand All @@ -308,6 +310,12 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
cancelHarvest = true;
}

// send blockbreak event
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, localBlock, localMeta, player);
event.setCanceled(cancelHarvest);
MinecraftForge.EVENT_BUS.post(event);
cancelHarvest = event.isCanceled();

if (!cancelHarvest)
{
if (localBlock != null && !(localHardness < 0))
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/tconstruct/items/tools/LumberAxe.java
Expand Up @@ -9,6 +9,8 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.tools.AbilityHelper;
Expand Down Expand Up @@ -176,6 +178,12 @@ void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompoun
cancelHarvest = true;
}

// send blockbreak event
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, localBlock, localMeta, player);
event.setCanceled(cancelHarvest);
MinecraftForge.EVENT_BUS.post(event);
cancelHarvest = event.isCanceled();

if (cancelHarvest)
{
breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
Expand Up @@ -17,6 +17,8 @@
import net.minecraft.network.INetHandler;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import tconstruct.library.ActiveToolMod;
import tconstruct.library.TConstructRegistry;

Expand Down Expand Up @@ -59,6 +61,12 @@ public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPl
cancelHarvest = true;
}

// send blockbreak event
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player);
event.setCanceled(cancelHarvest);
MinecraftForge.EVENT_BUS.post(event);
cancelHarvest = event.isCanceled();

if (!cancelHarvest)
{
if (block != null)
Expand Down

0 comments on commit f6e6798

Please sign in to comment.