Skip to content

Commit

Permalink
Adjust tools to new blockbreak code stuff. Yay for proper calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
bonii-xx committed Sep 17, 2014
1 parent 8773232 commit 619bfdb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 358 deletions.
56 changes: 2 additions & 54 deletions src/main/java/tconstruct/items/tools/Battleaxe.java
Expand Up @@ -16,11 +16,11 @@
import tconstruct.library.tools.*;
import tconstruct.tools.TinkerTools;

public class Battleaxe extends HarvestTool
public class Battleaxe extends AOEHarvestTool
{
public Battleaxe()
{
super(4);
super(4, 1,1);
this.setUnlocalizedName("InfiTool.Battleaxe");
}

Expand Down Expand Up @@ -233,56 +233,4 @@ public void onUpdate (ItemStack stack, World world, Entity entity, int par4, boo
}
}
}

@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
if (!stack.hasTagCompound())
return false;

World world = player.worldObj;
final Block block = world.getBlock(x, y, z);
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
final int meta = world.getBlockMetadata(x, y, z);
for (int yPos = y + 1; yPos < y + 9; yPos++)
{
Block localBlock = world.getBlock(x, yPos, z);
if (!(tags.getBoolean("Broken")) && localBlock != null && localBlock.getMaterial() == Material.wood)
{
int localMeta = world.getBlockMetadata(x, yPos, z);
int hlvl = localBlock.getHarvestLevel(localMeta);

if (hlvl <= tags.getInteger("HarvestLevel"))
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, x, yPos, z, player))
cancelHarvest = true;
}

if (!cancelHarvest)
{
if (localBlock != null && localBlock.getMaterial() == Material.wood)
{
if (!player.capabilities.isCreativeMode)
{
mineBlock(world, x, yPos, z, localMeta, player, localBlock);
onBlockDestroyed(stack, world, localBlock, x, yPos, z, player);
}
else
{
WorldHelper.setBlockToAir(world, x, yPos, z);
}
}
}
}
}
else
break;
}
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return super.onBlockStartBreak(stack, x, y, z, player);
}
}
116 changes: 2 additions & 114 deletions src/main/java/tconstruct/items/tools/Excavator.java
Expand Up @@ -15,11 +15,11 @@
import tconstruct.library.tools.*;
import tconstruct.tools.TinkerTools;

public class Excavator extends HarvestTool
public class Excavator extends AOEHarvestTool
{
public Excavator()
{
super(2);
super(2, 1,0);
this.setUnlocalizedName("InfiTool.Excavator");
}

Expand Down Expand Up @@ -130,118 +130,6 @@ public String getDefaultFolder ()
return "excavator";
}

/* Excavator Specific */

@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
if (!stack.hasTagCompound())
return false;

World world = player.worldObj;
final int meta = world.getBlockMetadata(x, y, z);
Block block = world.getBlock(x, y, z);
if (!stack.hasTagCompound())
return false;

if (block == null)
return super.onBlockStartBreak(stack, x, y, z, player);

float blockHardness = block.getBlockHardness(world, x, y, z);

boolean validStart = false;
for (int iter = 0; iter < materials.length; iter++)
{
if (materials[iter] == block.getMaterial())
{
validStart = true;
break;
}
}

MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(world, player, false, 5.0D);
if (mop == null || !validStart)
return super.onBlockStartBreak(stack, x, y, z, player);

int xRange = 1;
int yRange = 1;
int zRange = 1;
switch (mop.sideHit)
{
case 0:
case 1:
yRange = 0;
break;
case 2:
case 3:
zRange = 0;
break;
case 4:
case 5:
xRange = 0;
break;
}
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
for (int xPos = x - xRange; xPos <= x + xRange; xPos++)
{
for (int yPos = y - yRange; yPos <= y + yRange; yPos++)
{
for (int zPos = z - zRange; zPos <= z + zRange; zPos++)
{
if (!(tags.getBoolean("Broken")))
{
Block localBlock = world.getBlock(xPos, yPos, zPos);
int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
int hlvl = localBlock.getHarvestLevel(localMeta);
float localHardness = localBlock == null ? Float.MAX_VALUE : localBlock.getBlockHardness(world, xPos, yPos, zPos);

if (hlvl <= tags.getInteger("HarvestLevel") && localHardness - 1.5 <= blockHardness)
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
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))
{
for (int iter = 0; iter < materials.length; iter++)
{
if (materials[iter] == localBlock.getMaterial())
{
if (!player.capabilities.isCreativeMode)
{
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);
if (localHardness > 0f)
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
}
else
{
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
}
}
}
}
}
}
}
}
}
}
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return true;
}

@Override
public float breakSpeedModifier ()
{
Expand Down

0 comments on commit 619bfdb

Please sign in to comment.