2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2017-01-10 20:28:12 +01:00
|
|
|
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;
|
2016-09-27 19:27:40 +02:00
|
|
|
import net.minecraft.init.Blocks;
|
2016-12-10 02:01:19 +01:00
|
|
|
import net.minecraft.init.Enchantments;
|
2016-02-28 20:18:59 +01:00
|
|
|
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.api.power.IEnergyItemInfo;
|
2016-08-10 01:29:47 +02:00
|
|
|
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.Random;
|
|
|
|
|
2016-12-10 02:01:19 +01:00
|
|
|
public class ItemJackhammer extends ItemPickaxe implements IEnergyItemInfo {
|
2016-08-10 01:29:47 +02:00
|
|
|
|
|
|
|
public int maxCharge = 1;
|
|
|
|
public int cost = 250;
|
|
|
|
public double transferLimit = 100;
|
|
|
|
|
2017-06-12 21:06:15 +02:00
|
|
|
public ItemJackhammer(ToolMaterial material, String unlocalizedName, int energyCapacity) {
|
2016-08-10 01:29:47 +02:00
|
|
|
super(material);
|
|
|
|
efficiencyOnProperMaterial = 20F;
|
|
|
|
setCreativeTab(TechRebornCreativeTab.instance);
|
|
|
|
setMaxStackSize(1);
|
|
|
|
setMaxDamage(240);
|
|
|
|
setUnlocalizedName(unlocalizedName);
|
|
|
|
this.maxCharge = energyCapacity;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState blockIn, BlockPos pos,
|
|
|
|
EntityLivingBase entityLiving) {
|
2016-08-10 01:29:47 +02:00
|
|
|
Random rand = new Random();
|
2016-12-10 02:01:19 +01:00
|
|
|
if (rand.nextInt(EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack) + 1) == 0) {
|
2016-08-10 01:29:47 +02:00
|
|
|
PoweredItem.useEnergy(cost, stack);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-02-04 13:47:26 +01:00
|
|
|
public boolean canHarvestBlock(final IBlockState state, final ItemStack stack) {
|
|
|
|
return OreDictUtils.isOre(state, "stone")
|
2017-06-12 15:23:32 +02:00
|
|
|
|| state.getBlock().getMaterial(state) == Material.ROCK && PoweredItem.canUseEnergy(this.cost, stack);
|
2016-08-10 01:29:47 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 01:29:47 +02:00
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean hitEntity(ItemStack itemstack, EntityLivingBase entityliving, EntityLivingBase entityliving1) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isRepairable() {
|
2016-08-10 01:29:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxPower(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return maxCharge;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canAcceptEnergy(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canProvideEnergy(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxTransfer(ItemStack stack) {
|
2016-08-10 01:29:47 +02:00
|
|
|
return transferLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
|
|
@SideOnly(Side.CLIENT)
|
2017-06-11 22:22:07 +02:00
|
|
|
@Override
|
|
|
|
public void getSubItems(CreativeTabs par2CreativeTabs, NonNullList<ItemStack> itemList) {
|
2017-06-12 18:30:21 +02:00
|
|
|
if(!func_194125_a(par2CreativeTabs)){
|
|
|
|
return;
|
|
|
|
}
|
2016-08-10 01:29:47 +02:00
|
|
|
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
|
|
|
}
|