/* * This file is part of TechReborn, licensed under the MIT License (MIT). * * Copyright (c) 2018 TechReborn * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package techreborn.items.tool; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.init.Enchantments; import net.minecraft.item.Item; import net.minecraft.item.ItemPickaxe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemTier; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.capabilities.ICapabilityProvider; import reborncore.api.power.IEnergyItemInfo; import reborncore.common.powerSystem.ExternalPowerSystems; import reborncore.common.powerSystem.PowerSystem; import reborncore.common.powerSystem.PoweredItemContainerProvider; import reborncore.common.powerSystem.forge.ForgePowerItemManager; import reborncore.common.util.ItemUtils; import techreborn.TechReborn; import techreborn.utils.TagUtils; import javax.annotation.Nullable; import java.util.Random; public class ItemJackhammer extends ItemPickaxe implements IEnergyItemInfo { public int maxCharge = 1; public int cost = 250; public int transferLimit = 100; public ItemJackhammer(ItemTier material, int energyCapacity) { super(material, (int) material.getAttackDamage(), 1f, new Item.Properties().group(TechReborn.ITEMGROUP).maxStackSize(1)); efficiency = 20F; this.maxCharge = energyCapacity; } // ItemPickaxe @Override public float getDestroySpeed(ItemStack stack, IBlockState state) { if ((TagUtils.isOre(state, "stone") || state.getBlock() == Blocks.STONE) && new ForgePowerItemManager(stack).getEnergyStored() >= cost) { return efficiency; } else { return 0.5F; } } // ItemTool @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos, EntityLivingBase entityLiving) { Random rand = new Random(); if (rand.nextInt(EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack) + 1) == 0) { ForgePowerItemManager capEnergy = new ForgePowerItemManager(stack); capEnergy.extractEnergy(cost, false); ExternalPowerSystems.requestEnergyFromArmor(capEnergy, entityLiving); } return true; } @Override public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase entityliving1) { return true; } // Item @Override public boolean canHarvestBlock( final ItemStack stack, final IBlockState state) { return TagUtils.isOre(state, "stone") || state.getMaterial() == Material.ROCK && new ForgePowerItemManager(stack).getEnergyStored() >= cost; } @Override public boolean isRepairable() { return false; } @Override public double getDurabilityForDisplay(ItemStack stack) { return 1 - ItemUtils.getPowerForDurabilityBar(stack); } @Override public boolean showDurabilityBar(ItemStack stack) { return true; } @Override public int getRGBDurabilityForDisplay(ItemStack stack) { return PowerSystem.getDisplayPower().colour; } @Override @Nullable public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) { return new PoweredItemContainerProvider(stack); } @Override public boolean shouldCauseBlockBreakReset(ItemStack oldStack, ItemStack newStack) { return !(newStack.isItemEqual(oldStack)); } // IEnergyItemInfo @Override public int getCapacity() { return maxCharge; } @Override public int getMaxInput() { return transferLimit; } @Override public int getMaxOutput() { return 0; } }