/* * 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.BlockState; import net.minecraft.block.Material; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.LivingEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.PickaxeItem; import net.minecraft.item.ToolMaterials; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import reborncore.common.powerSystem.PowerSystem; import reborncore.common.util.ItemDurabilityExtensions; import reborncore.common.util.ItemUtils; import team.reborn.energy.Energy; import team.reborn.energy.EnergyHolder; import team.reborn.energy.EnergySide; import team.reborn.energy.EnergyTier; import techreborn.TechReborn; import java.util.Random; public class JackhammerItem extends PickaxeItem implements EnergyHolder, ItemDurabilityExtensions { public int maxCharge; public int cost = 250; public int transferLimit = EnergyTier.MEDIUM.getMaxInput(); public JackhammerItem(ToolMaterials material, int energyCapacity) { super(material, (int) material.getAttackDamage(), 1f, new Item.Settings().group(TechReborn.ITEMGROUP).maxCount(1)); this.maxCharge = energyCapacity; } // PickaxeItem @Override public float getMiningSpeed(ItemStack stack, BlockState state) { if (state.getMaterial() == Material.STONE && Energy.of(stack).getEnergy() >= cost) { return miningSpeed; } else { return 0.5F; } } // MiningToolItem @Override public boolean postMine(ItemStack stack, World worldIn, BlockState blockIn, BlockPos pos, LivingEntity entityLiving) { Random rand = new Random(); if (rand.nextInt(EnchantmentHelper.getLevel(Enchantments.UNBREAKING, stack) + 1) == 0) { Energy.of(stack).use(cost); } return true; } @Override public boolean postHit(ItemStack stack, LivingEntity target, LivingEntity attacker) { return true; } // ToolItem @Override public boolean canRepair(ItemStack stack, ItemStack ingredient) { return false; } // ItemDurabilityExtensions @Override public double getDurability(ItemStack stack) { return 1 - ItemUtils.getPowerForDurabilityBar(stack); } @Override public boolean showDurability(ItemStack stack) { return true; } @Override public int getDurabilityColor(ItemStack stack) { return PowerSystem.getDisplayPower().colour; } // EnergyHolder @Override public double getMaxStoredPower() { return maxCharge; } @Override public EnergyTier getTier() { return EnergyTier.MEDIUM; } @Override public double getMaxInput(EnergySide side) { return transferLimit; } @Override public double getMaxOutput(EnergySide side) { return 0; } }