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

156 lines
4.8 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.
*/
2015-04-12 23:45:13 +02:00
package techreborn.items.tools;
2016-03-13 19:38:41 +01:00
import net.minecraft.block.state.IBlockState;
2015-11-08 14:59:36 +01:00
import net.minecraft.creativetab.CreativeTabs;
2016-03-27 18:41:56 +02:00
import net.minecraft.enchantment.Enchantment;
2016-05-16 00:03:13 +02:00
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityLivingBase;
2015-04-12 23:45:13 +02:00
import net.minecraft.entity.player.EntityPlayer;
2016-05-16 00:03:13 +02:00
import net.minecraft.init.Enchantments;
2015-04-12 23:45:13 +02:00
import net.minecraft.init.Items;
2015-11-08 14:59:36 +01:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
2015-04-12 23:45:13 +02:00
import net.minecraft.item.ItemStack;
2016-12-09 03:39:49 +01:00
import net.minecraft.util.NonNullList;
2016-05-16 00:03:13 +02:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2015-11-23 20:19:18 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.api.power.IEnergyItemInfo;
2016-12-09 03:39:49 +01:00
import reborncore.common.powerSystem.PowerSystem;
import reborncore.common.powerSystem.PoweredItem;
2015-04-12 23:45:13 +02:00
import techreborn.client.TechRebornCreativeTab;
2015-04-13 20:50:35 +02:00
import techreborn.config.ConfigTechReborn;
2016-12-09 03:39:49 +01:00
import techreborn.init.ModItems;
2015-07-02 20:51:24 +02:00
2016-12-05 10:19:16 +01:00
import javax.annotation.Nullable;
2016-05-16 00:03:13 +02:00
import java.util.Random;
2016-12-12 08:03:51 +01:00
public class ItemRockCutter extends ItemPickaxe implements IEnergyItemInfo {
public static final int maxCharge = ConfigTechReborn.RockCutterCharge;
public static final int tier = ConfigTechReborn.RockCutterTier;
public int cost = 500;
2016-10-08 21:46:16 +02:00
public ItemRockCutter() {
super(ToolMaterial.DIAMOND);
setUnlocalizedName("techreborn.rockcutter");
setCreativeTab(TechRebornCreativeTab.instance);
setMaxStackSize(1);
efficiencyOnProperMaterial = 16F;
}
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();
2016-10-08 21:46:16 +02:00
if (rand.nextInt(EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack) + 1) == 0) {
PoweredItem.useEnergy(cost, stack);
}
return true;
}
2016-10-08 21:46:16 +02:00
@Override
public boolean canHarvestBlock(IBlockState state) {
if (Items.DIAMOND_PICKAXE.canHarvestBlock(state)) {
return true;
}
return false;
}
2016-10-08 21:46:16 +02:00
@Override
2016-12-05 10:19:16 +01:00
public int getHarvestLevel(ItemStack stack,
String toolClass,
@Nullable
EntityPlayer player,
@Nullable
IBlockState blockState) {
2016-10-08 21:46:16 +02:00
if (!stack.isItemEnchanted()) {
stack.addEnchantment(Enchantment.getEnchantmentByID(33), 1);
}
2016-12-05 10:19:16 +01:00
return super.getHarvestLevel(stack, toolClass, player, blockState);
}
2016-10-08 21:46:16 +02:00
@Override
public float getStrVsBlock(ItemStack stack, IBlockState state) {
if (!PoweredItem.canUseEnergy(cost, stack)) {
return 2F;
2016-10-08 21:46:16 +02:00
} else {
return Items.DIAMOND_PICKAXE.getStrVsBlock(stack, state);
}
}
2016-10-08 21:46:16 +02:00
@Override
public boolean isRepairable() {
return false;
}
2016-10-08 21:46:16 +02:00
@Override
public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) {
stack.addEnchantment(Enchantments.SILK_TOUCH, 1);
}
2016-10-08 21:46:16 +02:00
@Override
public double getMaxPower(ItemStack stack) {
return maxCharge;
}
2016-10-08 21:46:16 +02:00
@Override
public boolean canAcceptEnergy(ItemStack stack) {
return true;
}
2016-10-08 21:46:16 +02:00
@Override
public boolean canProvideEnergy(ItemStack stack) {
return false;
}
2016-10-08 21:46:16 +02:00
@Override
public double getMaxTransfer(ItemStack stack) {
return 200;
}
2016-10-08 21:46:16 +02:00
@Override
public int getStackTier(ItemStack stack) {
return 2;
}
2016-10-08 21:46:16 +02:00
@SuppressWarnings({ "rawtypes", "unchecked" })
@SideOnly(Side.CLIENT)
public void getSubItems(Item item,
2016-12-09 03:39:49 +01:00
CreativeTabs par2CreativeTabs, NonNullList itemList) {
ItemStack uncharged = new ItemStack(ModItems.ROCK_CUTTER);
ItemStack charged = new ItemStack(ModItems.ROCK_CUTTER);
PoweredItem.setEnergy(getMaxPower(charged), charged);
2016-12-09 03:39:49 +01:00
itemList.add(uncharged);
itemList.add(charged);
}
2015-04-12 23:45:13 +02:00
}