
Update things Fix some more things Update once more Refactoring and removing unnecessary null checks Woops Fix Nother fix Moar fix Fix imports Update ItemBindable.java
171 lines
7.7 KiB
Java
171 lines
7.7 KiB
Java
package WayofTime.bloodmagic.item;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.state.IBlockState;
|
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
|
import net.minecraft.enchantment.EnchantmentHelper;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.init.Blocks;
|
|
import net.minecraft.init.Enchantments;
|
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
import net.minecraftforge.event.world.BlockEvent;
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
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;
|
|
|
|
import com.google.common.collect.HashMultiset;
|
|
import com.google.common.collect.Multimap;
|
|
import com.google.common.collect.Sets;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
public class ItemBoundPickaxe extends ItemBoundTool implements IMeshProvider
|
|
{
|
|
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.double_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);
|
|
|
|
public ItemBoundPickaxe()
|
|
{
|
|
super("pickaxe", 5, EFFECTIVE_ON);
|
|
}
|
|
|
|
@Override
|
|
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState block, BlockPos pos, EntityLivingBase entityLiving)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean canHarvestBlock(IBlockState blockIn)
|
|
{
|
|
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)
|
|
: this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2);
|
|
}
|
|
|
|
@Override
|
|
public float getStrVsBlock(ItemStack stack, IBlockState state)
|
|
{
|
|
if (!getActivated(stack))
|
|
return 1.0F;
|
|
|
|
return state.getMaterial() != Material.iron && state.getMaterial() != Material.anvil && state.getMaterial() != Material.rock ? super.getStrVsBlock(stack, state) : this.efficiencyOnProperMaterial;
|
|
}
|
|
|
|
@Override
|
|
protected void onBoundRelease(ItemStack stack, World world, EntityPlayer player, int charge)
|
|
{
|
|
if (world.isRemote)
|
|
return;
|
|
|
|
boolean silkTouch = EnchantmentHelper.getEnchantmentLevel(Enchantments.silkTouch, stack) > 0;
|
|
int fortuneLvl = EnchantmentHelper.getEnchantmentLevel(Enchantments.fortune, stack);
|
|
int range = (charge / 6); //Charge is a max of 30 - want 5 to be the max
|
|
|
|
HashMultiset<ItemStackWrapper> drops = HashMultiset.create();
|
|
|
|
BlockPos playerPos = player.getPosition();
|
|
|
|
for (int i = -range; i <= range; i++)
|
|
{
|
|
for (int j = 0; j <= 2 * range; j++)
|
|
{
|
|
for (int k = -range; k <= range; k++)
|
|
{
|
|
BlockPos blockPos = playerPos.add(i, j, k);
|
|
BlockStack blockStack = BlockStack.getStackFromPos(world, blockPos);
|
|
|
|
if (blockStack.getBlock().isAir(blockStack.getState(), world, blockPos))
|
|
continue;
|
|
|
|
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(world, blockPos, blockStack.getState(), player);
|
|
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
|
|
continue;
|
|
|
|
if (blockStack.getBlock() != null && blockStack.getBlock().getBlockHardness(blockStack.getState(), world, blockPos) != -1)
|
|
{
|
|
float strengthVsBlock = getStrVsBlock(stack, blockStack.getState());
|
|
|
|
if (strengthVsBlock > 1.1F && world.canMineBlockBody(player, blockPos))
|
|
{
|
|
if (silkTouch && blockStack.getBlock().canSilkHarvest(world, blockPos, world.getBlockState(blockPos), player))
|
|
drops.add(new ItemStackWrapper(blockStack));
|
|
else
|
|
{
|
|
List<ItemStack> itemDrops = blockStack.getBlock().getDrops(world, blockPos, world.getBlockState(blockPos), fortuneLvl);
|
|
|
|
if (itemDrops != null)
|
|
for (ItemStack stacks : itemDrops)
|
|
drops.add(ItemStackWrapper.getHolder(stacks));
|
|
}
|
|
|
|
world.setBlockToAir(blockPos);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
NetworkHelper.getSoulNetwork(player).syphonAndDamage(player, (int) (charge * charge * charge / 2.7));
|
|
world.createExplosion(player, playerPos.getX(), playerPos.getY(), playerPos.getZ(), 0.5F, false);
|
|
dropStacks(drops, world, playerPos.add(0, 1, 0));
|
|
}
|
|
|
|
@Override
|
|
public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
|
|
{
|
|
Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
|
|
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));
|
|
}
|
|
return multimap;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public ItemMeshDefinition getMeshDefinition()
|
|
{
|
|
return new CustomMeshDefinitionActivatable("ItemBoundPickaxe");
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public ResourceLocation getCustomLocation()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public List<String> getVariants()
|
|
{
|
|
List<String> ret = new ArrayList<String>();
|
|
ret.add("active=true");
|
|
ret.add("active=false");
|
|
return ret;
|
|
}
|
|
}
|