Skip to content

Commit

Permalink
More fixes to AOE block harvesting. effective materials etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 17, 2014
1 parent 0e76fa9 commit 8773232
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/main/java/tconstruct/library/tools/AOEHarvestTool.java
@@ -1,5 +1,6 @@
package tconstruct.library.tools;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -26,6 +27,11 @@ public AOEHarvestTool(int baseDamage, int breakRadius, int breakDepth) {

@Override
public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
// only effective materials matter. We don't want to aoe when beraking dirt with a hammer.
Block block = player.worldObj.getBlock(x,y,z);
if(block == null || !isEffective(block.getMaterial()))
return super.onBlockStartBreak(stack, x,y,z, player);

boolean originalBlock = true;
// check if we're breaking the block we hit, or if this call belongs to one of the surrounding blocks broken by the AOE
if(player.worldObj.isRemote)
Expand Down
27 changes: 14 additions & 13 deletions src/main/java/tconstruct/library/tools/HarvestTool.java
@@ -1,28 +1,19 @@
package tconstruct.library.tools;

import cpw.mods.fml.client.FMLClientHandler;
import mantle.world.WorldHelper;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.*;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetHandler;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.common.ForgeHooks;
import tconstruct.TConstruct;
import tconstruct.library.*;
import tconstruct.util.network.AOEBlockBreakProgressPacket;
import tconstruct.util.network.PacketPipeline;

/* Base class for tools that should be harvesting blocks */

Expand Down Expand Up @@ -232,6 +223,16 @@ protected void breakExtraBlock(World world, int x, int y, int z, int sidehit, En

// check if the block can be broken, since extra block breaks shouldn't instantly break stuff like obsidian
// or precious ores you can't harvest while mining stone
Block block = world.getBlock(x,y,z);
int meta = world.getBlockMetadata(x,y,z);

// only effective materials
if(!isEffective(block.getMaterial()))
return;

// only harvestable blocks that aren't impossibly slow to harvest
if(!ForgeHooks.canHarvestBlock(block, player, meta) || ForgeHooks.blockStrength(block, player, world, x,y,z) <= 0.0001f)
return;

// this should only be called on the client
if(!world.isRemote) {
Expand Down

0 comments on commit 8773232

Please sign in to comment.