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

@@ -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));
}
}
}
}
}