mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-19 03:49:29 +00:00
Adjust tools to new blockbreak code stuff. Yay for proper calls.
This commit is contained in:
1 parent
8773232660
commit
619bfdb1f1
6 files changed
+81
-366
No files matched your search
@@ -16,11 +16,11 @@ import tconstruct.library.*;
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -233,56 +233,4 @@ public class Battleaxe extends HarvestTool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,11 @@ import tconstruct.library.*;
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -130,118 +130,6 @@ public class Excavator extends HarvestTool
|
||||
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 ()
|
||||
{
|
||||
|
||||
@@ -15,11 +15,11 @@ import tconstruct.library.*;
|
||||
import tconstruct.library.tools.*;
|
||||
import tconstruct.tools.TinkerTools;
|
||||
|
||||
public class LumberAxe extends HarvestTool
|
||||
public class LumberAxe extends AOEHarvestTool
|
||||
{
|
||||
public LumberAxe()
|
||||
{
|
||||
super(0);
|
||||
super(0, 1,1);
|
||||
this.setUnlocalizedName("InfiTool.LumberAxe");
|
||||
}
|
||||
|
||||
@@ -86,69 +86,62 @@ public class LumberAxe extends HarvestTool
|
||||
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
|
||||
{
|
||||
if (!stack.hasTagCompound())
|
||||
return false;
|
||||
return super.onBlockStartBreak(stack, x, y, z, player);
|
||||
|
||||
World world = player.worldObj;
|
||||
final Block wood = world.getBlock(x, y, z);
|
||||
;
|
||||
if (wood == null)
|
||||
{
|
||||
return super.onBlockStartBreak(stack, x, y, z, player);
|
||||
}
|
||||
if (wood.isWood(world, x, y, z) || wood.getMaterial() == Material.sponge)
|
||||
{
|
||||
int height = y;
|
||||
boolean foundTop = false;
|
||||
do
|
||||
{
|
||||
height++;
|
||||
Block block = world.getBlock(x, height, z);
|
||||
if (block != wood)
|
||||
{
|
||||
height--;
|
||||
foundTop = true;
|
||||
}
|
||||
} while (!foundTop);
|
||||
|
||||
int numLeaves = 0;
|
||||
if (height - y < 50)
|
||||
{
|
||||
for (int xPos = x - 1; xPos <= x + 1; xPos++)
|
||||
{
|
||||
for (int yPos = height - 1; yPos <= height + 1; yPos++)
|
||||
{
|
||||
for (int zPos = z - 1; zPos <= z + 1; zPos++)
|
||||
{
|
||||
Block leaves = world.getBlock(xPos, yPos, zPos);
|
||||
if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos))
|
||||
numLeaves++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wood == null)
|
||||
return super.onBlockStartBreak(stack, x, y, z, player);
|
||||
|
||||
if (wood.isWood(world, x, y, z) || wood.getMaterial() == Material.sponge)
|
||||
if(detectTree(world, x,y,z, wood)) {
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
breakTree(world, x, y, z, stack, tags, wood, meta, player);
|
||||
// custom block breaking code, don't call vanilla code
|
||||
return true;
|
||||
}
|
||||
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
if (numLeaves > 3)
|
||||
breakTree(world, x, y, z, stack, tags, wood, meta, player);
|
||||
else
|
||||
destroyWood(world, x, y, z, stack, tags, player);
|
||||
|
||||
if (!world.isRemote)
|
||||
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
|
||||
}
|
||||
else if (wood.getMaterial() == Material.wood)
|
||||
{
|
||||
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
destroyWood(world, x, y, z, stack, tags, player);
|
||||
if (!world.isRemote)
|
||||
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(wood) + (meta << 12));
|
||||
}
|
||||
return super.onBlockStartBreak(stack, x, y, z, player);
|
||||
}
|
||||
|
||||
void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, Block bID, int meta, EntityPlayer player)
|
||||
private boolean detectTree(World world, int x, int y, int z, Block wood)
|
||||
{
|
||||
int height = y;
|
||||
boolean foundTop = false;
|
||||
do
|
||||
{
|
||||
height++;
|
||||
Block block = world.getBlock(x, height, z);
|
||||
if (block != wood)
|
||||
{
|
||||
height--;
|
||||
foundTop = true;
|
||||
}
|
||||
} while (!foundTop);
|
||||
|
||||
int numLeaves = 0;
|
||||
if (height - y < 50)
|
||||
{
|
||||
for (int xPos = x - 1; xPos <= x + 1; xPos++)
|
||||
{
|
||||
for (int yPos = height - 1; yPos <= height + 1; yPos++)
|
||||
{
|
||||
for (int zPos = z - 1; zPos <= z + 1; zPos++)
|
||||
{
|
||||
Block leaves = world.getBlock(xPos, yPos, zPos);
|
||||
if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos))
|
||||
numLeaves++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return numLeaves > 3;
|
||||
}
|
||||
|
||||
private void breakTree (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, Block bID, int meta, EntityPlayer player)
|
||||
{
|
||||
for (int xPos = x - 1; xPos <= x + 1; xPos++)
|
||||
{
|
||||
@@ -188,41 +181,16 @@ public class LumberAxe extends HarvestTool
|
||||
{
|
||||
if (localBlock == bID && localMeta % 4 == meta % 4)
|
||||
{
|
||||
/*
|
||||
* world.setBlock(xPos, yPos, zPos, 0,
|
||||
* 0, 3); if
|
||||
* (!player.capabilities.isCreativeMode)
|
||||
* {
|
||||
* Block.blocksList[bID].harvestBlock(world
|
||||
* , player, xPos, yPos, zPos, meta);
|
||||
* onBlockDestroyed(stack, world, bID,
|
||||
* xPos, yPos, zPos, player); }
|
||||
*/
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);
|
||||
localBlock.harvestBlock(world, player, x,y,z, localMeta);
|
||||
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
|
||||
}
|
||||
else
|
||||
{
|
||||
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
|
||||
}
|
||||
|
||||
world.setBlockToAir(xPos, yPos, zPos);
|
||||
if (!world.isRemote)
|
||||
breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
|
||||
}
|
||||
/*
|
||||
* else { Block leaves =
|
||||
* Block.blocksList[localID]; if (leaves !=
|
||||
* null && leaves.isLeaves(world, xPos,
|
||||
* yPos, zPos)) {
|
||||
* WorldHelper.setBlockToAir(world, xPos,
|
||||
* yPos, zPos); if
|
||||
* (!player.capabilities.isCreativeMode) {
|
||||
* Block.blocksList[bID].harvestBlock(world,
|
||||
* player, xPos, yPos, zPos, meta);
|
||||
* onBlockDestroyed(stack, world, bID, xPos,
|
||||
* yPos, zPos, player); } } }
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,51 +199,6 @@ public class LumberAxe extends HarvestTool
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void destroyWood (World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, EntityPlayer player)
|
||||
{
|
||||
for (int xPos = x - 1; xPos <= x + 1; xPos++)
|
||||
{
|
||||
for (int yPos = y - 1; yPos <= y + 1; yPos++)
|
||||
{
|
||||
for (int zPos = z - 1; zPos <= z + 1; 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 (localBlock != null && localBlock.getMaterial() == Material.wood && !(localHardness < 0))
|
||||
{
|
||||
if (hlvl <= tags.getInteger("HarvestLevel"))
|
||||
{
|
||||
boolean cancelHarvest = false;
|
||||
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
|
||||
{
|
||||
if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
|
||||
cancelHarvest = true;
|
||||
}
|
||||
|
||||
if (!cancelHarvest)
|
||||
{
|
||||
if (!player.capabilities.isCreativeMode)
|
||||
{
|
||||
mineBlock(world, xPos, yPos, zPos, localMeta, player, localBlock);
|
||||
onBlockDestroyed(stack, world, localBlock, xPos, yPos, zPos, player);
|
||||
}
|
||||
WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
|
||||
world.func_147479_m(xPos, yPos, zPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getHeadItem ()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user