Adjust tools to new blockbreak code stuff. Yay for proper calls.

This commit is contained in:
Bernhard Bonigl committed 2014-09-17 15:32:51 +02:00
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 ()
{
@@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.util.MovingObjectPosition;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
@@ -49,7 +50,11 @@ public abstract class AOEHarvestTool extends HarvestTool {
// the code below initiates block breaks, which again call this function. But we don't want to do the aoe-break-stuff again. This is to prevent recursive, infinite-range aoe blockbreaking.
if(originalBlock) {
antiRecurse = true;
int sideHit = Minecraft.getMinecraft().objectMouseOver.sideHit;
MovingObjectPosition mop = AbilityHelper.raytraceFromEntity(player.worldObj, player, false, 4.5d);
if(mop == null)
return super.onBlockStartBreak(stack, x,y,z, player);
int sideHit = mop.sideHit;
//int sideHit = Minecraft.getMinecraft().objectMouseOver.sideHit;
// we successfully destroyed a block. time to do AOE!
int xRange = breakRadius;
@@ -20,49 +20,33 @@ public abstract class DualHarvestTool extends HarvestTool
}
@Override
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
{
public int getHarvestLevel(ItemStack stack, String toolClass) {
// well, we can only get the harvestlevel if we have an item to get it from!
if(stack == null || !(stack.getItem() instanceof HarvestTool))
return -1;
// invalid query or wrong toolclass
if(toolClass == null)
return -1;
if(!stack.hasTagCompound())
return -1;
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
World world = player.worldObj;
int meta = world.getBlockMetadata(x, y, z);
Block block = player.worldObj.getBlock(x, y, z);
if (block == null || block == Blocks.air)
return false;
int hlvl = -1;
int shlvl = -1;
if (block.getHarvestTool(meta) == null || block.getHarvestTool(meta).equals(getHarvestType()))
hlvl = block.getHarvestLevel(meta);
if (block.getHarvestTool(meta) == null || block.getHarvestTool(meta).equals(getSecondHarvestType()))
shlvl = block.getHarvestLevel(meta);
// broken tools suck.
if (tags.getBoolean("Broken"))
return -1;
if (hlvl <= tags.getInteger("HarvestLevel") && shlvl <= tags.getInteger("HarvestLevel2"))
{
boolean cancelHarvest = false;
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
{
if (mod.beforeBlockBreak(this, stack, x, y, z, player))
cancelHarvest = true;
}
if(this.getHarvestType().equals(toolClass))
return tags.getInteger("HarvestLevel");
else if(this.getSecondHarvestType().equals(toolClass))
return tags.getInteger("HarvestLevel2");
return cancelHarvest;
}
else
{
if (!player.capabilities.isCreativeMode)
{
mineBlock(world, x, y, z, meta, player, block);
}
WorldHelper.setBlockToAir(world, x, y, z);
if (!world.isRemote)
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
return true;
}
return -1;
}
@Override
public float getDigSpeed (ItemStack stack, Block block, int meta)
{
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
if (tags.getBoolean("Broken"))
return 0.1f;
@@ -250,37 +250,4 @@ public abstract class HarvestTool extends ToolCore
// the code above, executed on the server, sends a block-updates that give us the correct state of the block we destroy.
pcmp.onPlayerDestroyBlock(x, y, z, sidehit);
}
// The Scythe is not a HarvestTool and can't call this method, if you change something here you might change it there too.
public void mineBlock (World world, int x, int y, int z, int meta, EntityPlayer player, Block block)
{
TConstruct.logger.info("CCCCC: " + world.isRemote);
// Workaround for dropping experience
boolean silktouch = EnchantmentHelper.getSilkTouchModifier(player);
int fortune = EnchantmentHelper.getFortuneModifier(player);
int exp = block.getExpDrop(world, meta, fortune);
block.onBlockHarvested(world, x, y, z, meta, player);
if (block.removedByPlayer(world, player, x, y, z, true))
{
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
block.harvestBlock(world, player, x, y, z, meta);
// Workaround for dropping experience
if (!silktouch)
block.dropXpOnBlockBreak(world, x, y, z, exp);
if (world.isRemote)
{
INetHandler handler = FMLClientHandler.instance().getClientPlayHandler();
if (handler != null && handler instanceof NetHandlerPlayClient)
{
NetHandlerPlayClient handlerClient = (NetHandlerPlayClient) handler;
handlerClient.addToSendQueue(new C07PacketPlayerDigging(0, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
handlerClient.addToSendQueue(new C07PacketPlayerDigging(2, x, y, z, Minecraft.getMinecraft().objectMouseOver.sideHit));
}
}
}
}
}