2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.library.tools;
|
|
|
|
|
|
2014-08-23 22:04:07 +02:00
|
|
|
import cpw.mods.fml.client.FMLClientHandler;
|
2014-01-16 01:36:18 -05:00
|
|
|
import mantle.world.WorldHelper;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.material.Material;
|
2014-08-23 22:04:07 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
import net.minecraft.client.network.NetHandlerPlayClient;
|
2014-07-28 00:39:37 +03:00
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-01-07 13:50:35 -05:00
|
|
|
import net.minecraft.init.Blocks;
|
2014-09-09 18:30:15 +10:00
|
|
|
import net.minecraft.item.*;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-08-23 22:04:07 +02:00
|
|
|
import net.minecraft.network.INetHandler;
|
|
|
|
|
import net.minecraft.network.play.client.C07PacketPlayerDigging;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.world.World;
|
2014-09-02 17:02:03 +02:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
|
import net.minecraftforge.event.world.BlockEvent;
|
2014-09-09 18:30:15 +10:00
|
|
|
import tconstruct.library.*;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
/* Base class for tools that should be harvesting blocks */
|
|
|
|
|
|
|
|
|
|
public abstract class HarvestTool extends ToolCore
|
|
|
|
|
{
|
2013-12-31 11:58:36 -05:00
|
|
|
public HarvestTool(int baseDamage)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-12-31 11:58:36 -05:00
|
|
|
super(baseDamage);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-09-09 18:30:15 +10:00
|
|
|
|
2014-07-21 15:07:16 -04:00
|
|
|
@Override
|
|
|
|
|
public boolean onBlockStartBreak (ItemStack stack, int x, int y, int z, EntityPlayer player)
|
|
|
|
|
{
|
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
World world = player.worldObj;
|
|
|
|
|
Block block = player.worldObj.getBlock(x, y, z);
|
|
|
|
|
int meta = world.getBlockMetadata(x, y, z);
|
|
|
|
|
// Block block = Block.blocksList[bID];
|
|
|
|
|
if (block == null || block == Blocks.air)
|
|
|
|
|
return false;
|
|
|
|
|
int hlvl = -1;
|
|
|
|
|
if (!(tags.getBoolean("Broken")))
|
|
|
|
|
{
|
|
|
|
|
if (block.getHarvestTool(meta) != null && block.getHarvestTool(meta).equals(this.getHarvestType()))
|
|
|
|
|
hlvl = block.getHarvestLevel(meta);
|
|
|
|
|
int toolLevel = tags.getInteger("HarvestLevel");
|
|
|
|
|
float blockHardness = block.getBlockHardness(world, x, y, z);
|
|
|
|
|
|
2014-07-30 21:33:42 +02:00
|
|
|
if (hlvl <= toolLevel)
|
2014-07-21 15:07:16 -04:00
|
|
|
{
|
|
|
|
|
boolean cancelHarvest = false;
|
|
|
|
|
for (ActiveToolMod mod : TConstructRegistry.activeModifiers)
|
|
|
|
|
{
|
|
|
|
|
if (mod.beforeBlockBreak(this, stack, x, y, z, player))
|
|
|
|
|
cancelHarvest = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-02 17:02:03 +02:00
|
|
|
// send blockbreak event
|
|
|
|
|
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(x, y, z, world, block, meta, player);
|
|
|
|
|
event.setCanceled(cancelHarvest);
|
|
|
|
|
MinecraftForge.EVENT_BUS.post(event);
|
|
|
|
|
cancelHarvest = event.isCanceled();
|
|
|
|
|
|
2014-07-21 15:07:16 -04:00
|
|
|
if (!cancelHarvest)
|
|
|
|
|
{
|
2014-07-30 21:33:42 +02:00
|
|
|
if (block != null)
|
2014-07-21 15:07:16 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
boolean isEffective = false;
|
|
|
|
|
|
|
|
|
|
for (int iter = 0; iter < getEffectiveMaterials().length; iter++)
|
|
|
|
|
{
|
2014-07-30 21:33:42 +02:00
|
|
|
if (getEffectiveMaterials()[iter] == block.getMaterial() || block == Blocks.monster_egg)
|
2014-07-21 15:07:16 -04:00
|
|
|
{
|
|
|
|
|
isEffective = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-30 21:33:42 +02:00
|
|
|
// Microblocks are registered as rock but no HarvestTool is set
|
|
|
|
|
if (block.getMaterial().isToolNotRequired() || block.getHarvestTool(meta) == null)
|
2014-07-21 15:07:16 -04:00
|
|
|
{
|
|
|
|
|
isEffective = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!player.capabilities.isCreativeMode)
|
|
|
|
|
{
|
|
|
|
|
if (isEffective)
|
|
|
|
|
{
|
2014-07-30 21:33:42 +02:00
|
|
|
mineBlock(world, x, y, z, meta, player, block);
|
2014-07-21 15:07:16 -04:00
|
|
|
if (blockHardness > 0f)
|
2014-07-30 21:33:42 +02:00
|
|
|
onBlockDestroyed(stack, world, block, x, y, z, player);
|
2014-07-21 15:07:16 -04:00
|
|
|
world.func_147479_m(x, y, z);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WorldHelper.setBlockToAir(world, x, y, z);
|
|
|
|
|
world.func_147479_m(x, y, z);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WorldHelper.setBlockToAir(world, x, y, z);
|
|
|
|
|
world.func_147479_m(x, y, z);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!world.isRemote)
|
|
|
|
|
world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block) + (meta << 12));
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
@Override
|
2014-02-03 10:02:49 -05:00
|
|
|
public float getDigSpeed (ItemStack stack, Block block, int meta)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
if (!stack.hasTagCompound())
|
|
|
|
|
return 1.0f;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
if (tags.getBoolean("Broken"))
|
|
|
|
|
return 0.1f;
|
|
|
|
|
|
|
|
|
|
Material[] materials = getEffectiveMaterials();
|
|
|
|
|
for (int i = 0; i < materials.length; i++)
|
|
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
if (materials[i] == block.getMaterial())
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-09-17 22:39:49 -07:00
|
|
|
return calculateStrength(tags, block, meta);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2014-09-09 18:30:15 +10:00
|
|
|
if (this.getHarvestType().equals(block.getHarvestTool(meta)) && block.getHarvestLevel(meta) > 0)
|
2013-09-17 22:39:49 -07:00
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
return calculateStrength(tags, block, meta); // No issue if the
|
|
|
|
|
// harvest level is
|
|
|
|
|
// too low
|
2013-09-17 22:39:49 -07:00
|
|
|
}
|
2014-02-03 10:02:49 -05:00
|
|
|
return super.getDigSpeed(stack, block, meta);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2013-11-10 13:57:35 -08:00
|
|
|
|
2014-07-15 20:59:11 +02:00
|
|
|
public float calculateStrength (NBTTagCompound tags, Block block, int meta)
|
2013-09-17 22:39:49 -07:00
|
|
|
{
|
|
|
|
|
|
2014-02-01 15:17:30 -05:00
|
|
|
int hlvl = block.getHarvestLevel(meta);
|
2014-08-28 14:26:57 +02:00
|
|
|
if (hlvl > tags.getInteger("HarvestLevel"))
|
|
|
|
|
return 0.1f;
|
2013-09-17 22:39:49 -07:00
|
|
|
|
2014-08-28 14:26:57 +02:00
|
|
|
return AbilityHelper.calcToolSpeed(this, tags);
|
2013-09-17 22:39:49 -07:00
|
|
|
}
|
2014-08-28 14:26:57 +02:00
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
public float breakSpeedModifier ()
|
2014-04-14 20:08:09 -08:00
|
|
|
{
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2014-09-09 18:30:15 +10:00
|
|
|
|
|
|
|
|
public float stoneboundModifier ()
|
2014-04-14 20:08:09 -08:00
|
|
|
{
|
|
|
|
|
return 72f;
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-03-19 19:55:37 +03:00
|
|
|
@Override
|
2014-03-19 19:38:35 +03:00
|
|
|
public boolean func_150897_b (Block block)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-05 08:28:53 -05:00
|
|
|
if (block.getMaterial().isToolNotRequired())
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-07-15 21:18:09 +02:00
|
|
|
return isEffective(block.getMaterial());
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-03-19 19:55:37 +03:00
|
|
|
@Override
|
2014-04-03 22:28:37 -04:00
|
|
|
public boolean canHarvestBlock (Block block, ItemStack itemStack)
|
2014-03-19 19:55:37 +03:00
|
|
|
{
|
|
|
|
|
return func_150897_b(block);
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
@Override
|
2014-06-30 22:26:00 -08:00
|
|
|
public String[] getTraits ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
return new String[] { "harvest" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract Material[] getEffectiveMaterials ();
|
|
|
|
|
|
|
|
|
|
protected abstract String getHarvestType ();
|
2014-03-15 07:11:06 -04:00
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
public boolean isEffective (Material material)
|
2014-07-15 21:18:09 +02:00
|
|
|
{
|
2014-09-09 18:30:15 +10:00
|
|
|
for (Material m : getEffectiveMaterials())
|
|
|
|
|
if (m == material)
|
2014-07-15 21:18:09 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-15 07:11:06 -04:00
|
|
|
//Right-click
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onItemUse (ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float clickX, float clickY, float clickZ)
|
|
|
|
|
{
|
|
|
|
|
/*if (world.isRemote)
|
|
|
|
|
return true;*/
|
|
|
|
|
|
|
|
|
|
boolean used = false;
|
|
|
|
|
int hotbarSlot = player.inventory.currentItem;
|
|
|
|
|
int itemSlot = hotbarSlot == 0 ? 8 : hotbarSlot + 1;
|
|
|
|
|
ItemStack nearbyStack = null;
|
|
|
|
|
|
|
|
|
|
if (hotbarSlot < 8)
|
|
|
|
|
{
|
|
|
|
|
nearbyStack = player.inventory.getStackInSlot(itemSlot);
|
|
|
|
|
if (nearbyStack != null)
|
|
|
|
|
{
|
|
|
|
|
Item item = nearbyStack.getItem();
|
|
|
|
|
if (item instanceof ItemBlock)
|
|
|
|
|
{
|
|
|
|
|
int posX = x;
|
|
|
|
|
int posY = y;
|
|
|
|
|
int posZ = z;
|
|
|
|
|
int playerPosX = (int) Math.floor(player.posX);
|
|
|
|
|
int playerPosY = (int) Math.floor(player.posY);
|
|
|
|
|
int playerPosZ = (int) Math.floor(player.posZ);
|
|
|
|
|
if (side == 0)
|
|
|
|
|
{
|
|
|
|
|
--posY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (side == 1)
|
|
|
|
|
{
|
|
|
|
|
++posY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (side == 2)
|
|
|
|
|
{
|
|
|
|
|
--posZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (side == 3)
|
|
|
|
|
{
|
|
|
|
|
++posZ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (side == 4)
|
|
|
|
|
{
|
|
|
|
|
--posX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (side == 5)
|
|
|
|
|
{
|
|
|
|
|
++posX;
|
|
|
|
|
}
|
|
|
|
|
if (posX == playerPosX && (posY == playerPosY || posY == playerPosY + 1 || posY == playerPosY - 1) && posZ == playerPosZ)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
used = item.onItemUse(nearbyStack, player, world, x, y, z, side, clickX, clickY, clickZ);
|
|
|
|
|
if (nearbyStack.stackSize < 1)
|
|
|
|
|
{
|
|
|
|
|
nearbyStack = null;
|
|
|
|
|
player.inventory.setInventorySlotContents(itemSlot, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (used) //Update client
|
|
|
|
|
{
|
|
|
|
|
Packet103SetSlot packet = new Packet103SetSlot(player.openContainer.windowId, itemSlot, nearbyStack);
|
|
|
|
|
((EntityPlayerMP)player).playerNetServerHandler.sendPacketToPlayer(packet);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
return used;
|
|
|
|
|
}
|
2014-07-28 00:39:37 +03:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getHarvestLevel (ItemStack stack, String toolClass)
|
|
|
|
|
{
|
|
|
|
|
if (!(stack.getItem() instanceof HarvestTool) || !getHarvestType().equals(toolClass))
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
|
|
|
|
|
int harvestLvl = tags.getInteger("HarvestLevel");
|
|
|
|
|
return harvestLvl;
|
|
|
|
|
}
|
2014-07-30 21:33:42 +02:00
|
|
|
|
|
|
|
|
// The Scythe is not a HarvestTool and can't call this method, if you change something here you might change it there too.
|
2014-09-09 18:30:15 +10:00
|
|
|
public void mineBlock (World world, int x, int y, int z, int meta, EntityPlayer player, Block block)
|
2014-07-30 21:33:42 +02:00
|
|
|
{
|
2014-08-23 22:04:07 +02:00
|
|
|
// Workaround for dropping experience
|
|
|
|
|
boolean silktouch = EnchantmentHelper.getSilkTouchModifier(player);
|
|
|
|
|
int fortune = EnchantmentHelper.getFortuneModifier(player);
|
|
|
|
|
int exp = block.getExpDrop(world, meta, fortune);
|
2014-07-30 21:33:42 +02:00
|
|
|
|
2014-08-23 22:04:07 +02:00
|
|
|
block.onBlockHarvested(world, x, y, z, meta, player);
|
|
|
|
|
if (block.removedByPlayer(world, player, x, y, z, true))
|
2014-07-30 21:33:42 +02:00
|
|
|
{
|
|
|
|
|
block.onBlockDestroyedByPlayer(world, x, y, z, meta);
|
2014-08-23 22:04:07 +02:00
|
|
|
block.harvestBlock(world, player, x, y, z, meta);
|
|
|
|
|
// Workaround for dropping experience
|
|
|
|
|
if (!silktouch)
|
|
|
|
|
block.dropXpOnBlockBreak(world, x, y, z, exp);
|
|
|
|
|
|
2014-09-09 18:30:15 +10:00
|
|
|
if (world.isRemote)
|
|
|
|
|
{
|
2014-08-23 22:04:49 +02:00
|
|
|
INetHandler handler = FMLClientHandler.instance().getClientPlayHandler();
|
2014-09-09 18:30:15 +10:00
|
|
|
if (handler != null && handler instanceof NetHandlerPlayClient)
|
|
|
|
|
{
|
2014-08-23 22:04:49 +02:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-07-30 21:33:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|