TechReborn/src/main/java/techreborn/items/tools/ItemJackhammer.java

142 lines
4.5 KiB
Java
Raw Normal View History

/*
* This file is part of TechReborn, licensed under the MIT License (MIT).
*
* Copyright (c) 2017 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.
*/
2016-02-28 20:18:59 +01:00
package techreborn.items.tools;
import net.minecraft.block.material.Material;
2016-02-28 20:18:59 +01:00
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
2016-03-27 18:41:56 +02:00
import net.minecraft.enchantment.EnchantmentHelper;
2016-02-28 20:18:59 +01:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
2016-02-28 20:18:59 +01:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
2017-06-11 22:22:07 +02:00
import net.minecraft.util.NonNullList;
2016-03-13 17:08:30 +01:00
import net.minecraft.util.math.BlockPos;
2016-02-28 20:18:59 +01:00
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.RebornCore;
import reborncore.api.power.IEnergyItemInfo;
2016-12-09 03:39:49 +01:00
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.PoweredItem;
2016-02-28 20:18:59 +01:00
import techreborn.client.TechRebornCreativeTab;
import techreborn.utils.OreDictUtils;
2016-03-27 18:41:56 +02:00
import java.util.List;
import java.util.Random;
public class ItemJackhammer extends ItemPickaxe implements IEnergyItemInfo {
public static int tier = 1;
public int maxCharge = 1;
public int cost = 250;
public double transferLimit = 100;
2016-10-08 21:46:16 +02:00
public ItemJackhammer(ToolMaterial material, String unlocalizedName, int energyCapacity, int tier) {
super(material);
efficiencyOnProperMaterial = 20F;
setCreativeTab(TechRebornCreativeTab.instance);
setMaxStackSize(1);
setMaxDamage(240);
setUnlocalizedName(unlocalizedName);
this.maxCharge = energyCapacity;
this.tier = tier;
}
2016-10-08 21:46:16 +02:00
@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) {
PoweredItem.useEnergy(cost, stack);
}
return true;
}
@Override
public boolean canHarvestBlock(final IBlockState state, final ItemStack stack) {
return OreDictUtils.isOre(state, "stone")
|| state.getBlock().getMaterial(state) == Material.ROCK && PoweredItem.canUseEnergy(this.cost, stack);
}
2016-10-08 21:46:16 +02:00
@Override
public float getStrVsBlock(ItemStack stack, IBlockState state) {
if ((OreDictUtils.isOre(state, "stone") || state.getBlock() == Blocks.STONE) && PoweredItem.canUseEnergy(cost, stack)) {
return efficiencyOnProperMaterial;
} else {
return 0.5F;
}
}
@Override
2016-10-08 21:46:16 +02:00
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase entityliving1) {
return true;
}
@Override
2016-10-08 21:46:16 +02:00
public boolean isRepairable() {
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxPower(ItemStack stack) {
return maxCharge;
}
@Override
2016-10-08 21:46:16 +02:00
public boolean canAcceptEnergy(ItemStack stack) {
return true;
}
@Override
2016-10-08 21:46:16 +02:00
public boolean canProvideEnergy(ItemStack stack) {
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public double getMaxTransfer(ItemStack stack) {
return transferLimit;
}
@Override
2016-10-08 21:46:16 +02:00
public int getStackTier(ItemStack stack) {
return tier;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
2017-06-11 22:22:07 +02:00
@Override
public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList<ItemStack> itemList) {
ItemStack itemStack = new ItemStack(this, 1);
itemList.add(itemStack);
ItemStack charged = new ItemStack(this, 1);
PoweredItem.setEnergy(getMaxPower(charged), charged);
itemList.add(charged);
}
2016-02-28 20:18:59 +01:00
}