2015-12-29 14:32:35 -05:00
|
|
|
package WayofTime.bloodmagic.item;
|
|
|
|
|
2016-03-17 16:47:15 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2015-12-29 14:32:35 -05:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2016-03-18 16:31:55 -04:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-03-15 22:48:01 -07:00
|
|
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
2015-12-29 14:32:35 -05:00
|
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
2016-03-15 19:38:45 -07:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-12-29 14:32:35 -05:00
|
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
2016-03-18 16:31:55 -04:00
|
|
|
import net.minecraft.init.Enchantments;
|
|
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
2015-12-29 14:32:35 -05:00
|
|
|
import net.minecraft.item.ItemStack;
|
2016-03-20 23:21:07 -07:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2016-03-17 16:47:15 -04:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2015-12-29 14:32:35 -05:00
|
|
|
import net.minecraft.world.World;
|
2016-02-25 08:54:18 -05:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.world.BlockEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
2016-03-15 22:48:01 -07:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-03-17 16:47:15 -04:00
|
|
|
import WayofTime.bloodmagic.api.BlockStack;
|
|
|
|
import WayofTime.bloodmagic.api.ItemStackWrapper;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
|
|
|
import WayofTime.bloodmagic.client.IMeshProvider;
|
|
|
|
import WayofTime.bloodmagic.client.mesh.CustomMeshDefinitionActivatable;
|
2015-12-29 14:32:35 -05:00
|
|
|
|
2016-03-17 16:47:15 -04:00
|
|
|
import com.google.common.collect.HashMultiset;
|
|
|
|
import com.google.common.collect.Multimap;
|
|
|
|
import com.google.common.collect.Sets;
|
2016-03-17 13:00:44 -07:00
|
|
|
|
2016-03-20 23:21:07 -07:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2016-03-15 22:48:01 -07:00
|
|
|
public class ItemBoundPickaxe extends ItemBoundTool implements IMeshProvider
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-04-24 10:06:28 -07:00
|
|
|
private static final Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.ACTIVATOR_RAIL, Blocks.COAL_ORE, Blocks.COBBLESTONE, Blocks.DETECTOR_RAIL, Blocks.DIAMOND_BLOCK, Blocks.DIAMOND_ORE, Blocks.STONE_SLAB, Blocks.GOLDEN_RAIL, Blocks.GOLD_BLOCK, Blocks.GOLD_ORE, Blocks.ICE, Blocks.IRON_BLOCK, Blocks.IRON_ORE, Blocks.LAPIS_BLOCK, Blocks.LAPIS_ORE, Blocks.LIT_REDSTONE_ORE, Blocks.MOSSY_COBBLESTONE, Blocks.NETHERRACK, Blocks.PACKED_ICE, Blocks.RAIL, Blocks.REDSTONE_ORE, Blocks.SANDSTONE, Blocks.RED_SANDSTONE, Blocks.STONE, Blocks.STONE_SLAB);
|
2015-12-29 14:32:35 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public ItemBoundPickaxe()
|
|
|
|
{
|
2016-03-15 19:38:45 -07:00
|
|
|
super("pickaxe", 5, EFFECTIVE_ON);
|
2015-12-29 14:32:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-15 19:38:45 -07:00
|
|
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2015-12-29 14:32:35 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-15 19:38:45 -07:00
|
|
|
@Override
|
2016-03-18 16:31:55 -04:00
|
|
|
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState block, BlockPos pos, EntityLivingBase entityLiving)
|
2016-03-15 19:38:45 -07:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 16:31:55 -04:00
|
|
|
public boolean canHarvestBlock(IBlockState blockIn)
|
2016-03-15 19:38:45 -07:00
|
|
|
{
|
2016-04-24 10:06:28 -07:00
|
|
|
return blockIn == Blocks.OBSIDIAN ? this.toolMaterial.getHarvestLevel() == 3
|
|
|
|
: (blockIn != Blocks.DIAMOND_BLOCK && blockIn != Blocks.DIAMOND_ORE ? (blockIn != Blocks.EMERALD_ORE && blockIn != Blocks.EMERALD_BLOCK ? (blockIn != Blocks.GOLD_BLOCK && blockIn != Blocks.GOLD_ORE ? (blockIn != Blocks.IRON_BLOCK && blockIn != Blocks.IRON_ORE ? (blockIn != Blocks.LAPIS_BLOCK && blockIn != Blocks.LAPIS_ORE ? (blockIn != Blocks.REDSTONE_ORE && blockIn != Blocks.LIT_REDSTONE_ORE ? (blockIn.getMaterial() == Material.ROCK || (blockIn.getMaterial() == Material.IRON || blockIn.getMaterial() == Material.ANVIL)) : this.toolMaterial.getHarvestLevel() >= 2)
|
2016-03-16 18:41:06 -04:00
|
|
|
: this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2);
|
2016-03-15 19:38:45 -07:00
|
|
|
}
|
|
|
|
|
2015-12-29 14:32:35 -05:00
|
|
|
@Override
|
2016-03-18 16:31:55 -04:00
|
|
|
public float getStrVsBlock(ItemStack stack, IBlockState state)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-03-15 19:38:45 -07:00
|
|
|
if (!getActivated(stack))
|
|
|
|
return 1.0F;
|
|
|
|
|
2016-05-02 20:56:32 -04:00
|
|
|
return state.getMaterial() != Material.IRON && state.getMaterial() != Material.ANVIL && state.getMaterial() != Material.ROCK ? super.getStrVsBlock(stack, state) : this.efficiencyOnProperMaterial;
|
2015-12-29 14:32:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge)
|
|
|
|
{
|
2016-01-03 08:56:31 -05:00
|
|
|
if (world.isRemote)
|
|
|
|
return;
|
|
|
|
|
2016-04-24 10:06:28 -07:00
|
|
|
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0;
|
|
|
|
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack);
|
2016-04-11 19:57:23 -04:00
|
|
|
int range = (charge / 6); //Charge is a max of 30 - want 5 to be the max
|
2015-12-29 14:32:35 -05:00
|
|
|
|
|
|
|
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
|
|
|
|
|
2016-01-03 08:56:31 -05:00
|
|
|
BlockPos playerPos = player.getPosition();
|
2015-12-29 14:32:35 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
for (int i = -range; i <= range; i++)
|
|
|
|
{
|
2016-01-03 08:56:31 -05:00
|
|
|
for (int j = 0; j <= 2 * range; j++)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
for (int k = -range; k <= range; k++)
|
|
|
|
{
|
2015-12-29 14:32:35 -05:00
|
|
|
BlockPos blockPos = playerPos.add(i, j, k);
|
2016-01-09 17:42:48 -08:00
|
|
|
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
|
2015-12-29 14:32:35 -05:00
|
|
|
|
2016-03-18 16:31:55 -04:00
|
|
|
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
|
2016-03-15 18:37:34 -07:00
|
|
|
continue;
|
2016-02-08 14:17:56 -08:00
|
|
|
|
|
|
|
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
|
|
|
|
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
2016-03-15 18:37:34 -07:00
|
|
|
continue;
|
2016-02-08 14:17:56 -08:00
|
|
|
|
2016-03-18 16:31:55 -04:00
|
|
|
if (blockStack.getBlock() != null && blockStack.getBlock().getBlockHardness(blockStack.getState(), world, blockPos) != -1)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-03-18 16:31:55 -04:00
|
|
|
float strengthVsBlock = getStrVsBlock(stack, blockStack.getState());
|
2015-12-29 14:32:35 -05:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos))
|
|
|
|
{
|
2016-01-09 17:42:48 -08:00
|
|
|
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
|
|
|
|
drops.add(new ItemStackWrapper(blockStack));
|
2015-12-30 15:34:40 -05:00
|
|
|
else
|
|
|
|
{
|
2016-01-09 17:42:48 -08:00
|
|
|
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
|
2015-12-29 14:32:35 -05:00
|
|
|
|
|
|
|
if (itemDrops != null)
|
|
|
|
for (ItemStack stacks : itemDrops)
|
|
|
|
drops.add(ItemStackWrapper.getHolder(stacks));
|
|
|
|
}
|
|
|
|
|
|
|
|
world.setBlockToAir(blockPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-15 19:38:45 -07:00
|
|
|
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
|
2015-12-29 14:32:35 -05:00
|
|
|
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
|
|
|
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-18 16:31:55 -04:00
|
|
|
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-03-18 16:31:55 -04:00
|
|
|
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
|
2016-03-18 18:01:52 -04:00
|
|
|
if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
|
|
|
|
{
|
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", 5, 0));
|
|
|
|
multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getAttributeUnlocalizedName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool modifier", -2.5, 0));
|
|
|
|
}
|
2015-12-29 14:32:35 -05:00
|
|
|
return multimap;
|
|
|
|
}
|
2016-03-15 22:48:01 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public ItemMeshDefinition getMeshDefinition()
|
|
|
|
{
|
|
|
|
return new CustomMeshDefinitionActivatable("ItemBoundPickaxe");
|
|
|
|
}
|
|
|
|
|
2016-03-20 23:21:07 -07:00
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getCustomLocation()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-03-15 22:48:01 -07:00
|
|
|
@Override
|
|
|
|
public List<String> getVariants()
|
|
|
|
{
|
|
|
|
List<String> ret = new ArrayList<String>();
|
|
|
|
ret.add("active=true");
|
|
|
|
ret.add("active=false");
|
|
|
|
return ret;
|
|
|
|
}
|
2015-12-29 14:32:35 -05:00
|
|
|
}
|