ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemDrill.java

491 lines
20 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("ItemDrill.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.items;
2015-06-15 22:06:07 +02:00
import com.google.common.collect.Multimap;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheColoredLampColors;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityInventoryBase;
import de.ellpeck.actuallyadditions.mod.util.*;
2015-06-15 22:06:07 +02:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
2015-06-15 22:06:07 +02:00
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
2015-06-21 02:28:49 +02:00
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
2016-03-18 23:47:22 +01:00
import net.minecraft.init.Enchantments;
import net.minecraft.inventory.EntityEquipmentSlot;
2015-06-15 22:06:07 +02:00
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.*;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
2015-06-15 22:06:07 +02:00
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeHooks;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-06-15 22:06:07 +02:00
import java.util.HashSet;
import java.util.List;
2015-06-15 22:06:07 +02:00
import java.util.Set;
public class ItemDrill extends ItemEnergy{
2015-06-15 22:06:07 +02:00
public static final int HARVEST_LEVEL = 4;
2016-07-07 17:59:45 +02:00
private static final int ENERGY_USE = 100;
public ItemDrill(String name){
2016-11-21 13:38:43 +01:00
super(250000, 1000, name);
this.setMaxDamage(0);
2015-12-01 18:27:40 +01:00
this.setHasSubtypes(true);
//For Iguana Tweaks author
//
//You know what? It's bad, when you know
//There is already getHarvestLevel(), yo
//But then Iguana comes and fucks with you
//So that you need to use setHarvestLevel() too.
this.setHarvestLevel("shovel", HARVEST_LEVEL);
this.setHarvestLevel("pickaxe", HARVEST_LEVEL);
}
2016-06-17 23:50:38 +02:00
/**
* Gets all of the Slots from NBT
*
* @param stack The Drill
*/
public static void loadSlotsFromNBT(ItemStackHandlerCustom slots, ItemStack stack){
2016-06-17 23:50:38 +02:00
NBTTagCompound compound = stack.getTagCompound();
if(compound != null){
TileEntityInventoryBase.loadSlots(slots, compound);
}
}
/**
* Writes all of the Slots to NBT
*
* @param slots The Slots
* @param stack The Drill
*/
public static void writeSlotsToNBT(ItemStackHandlerCustom slots, ItemStack stack){
2016-06-17 23:50:38 +02:00
NBTTagCompound compound = stack.getTagCompound();
if(compound == null){
compound = new NBTTagCompound();
}
TileEntityInventoryBase.saveSlots(slots, compound);
stack.setTagCompound(compound);
}
2015-06-21 02:28:49 +02:00
@Override
//Places Blocks if the Placing Upgrade is installed
2016-11-19 21:11:17 +01:00
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ){
ItemStack stack = player.getHeldItem(hand);
2015-06-21 02:28:49 +02:00
ItemStack upgrade = this.getHasUpgradeAsStack(stack, ItemDrillUpgrade.UpgradeType.PLACER);
if(StackUtil.isValid(upgrade)){
2015-06-21 02:28:49 +02:00
int slot = ItemDrillUpgrade.getSlotToPlaceFrom(upgrade);
2015-06-22 18:09:00 +02:00
if(slot >= 0 && slot < InventoryPlayer.getHotbarSize()){
ItemStack equip = player.inventory.getStackInSlot(slot);
if(StackUtil.isValid(equip) && equip != stack){
ItemStack toPlaceStack = equip.copy();
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack);
//tryPlaceItemIntoWorld could throw an Exception
try{
//Places the Block into the World
if(toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){
if(!player.capabilities.isCreativeMode){
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, StackUtil.validateCopy(toPlaceStack));
2015-06-22 18:09:00 +02:00
}
2015-06-21 02:28:49 +02:00
}
}
//Notify the Player and log the Exception
catch(Exception e){
ModUtil.LOGGER.error("Player "+player.getName()+" who should place a Block using a Drill at "+player.posX+", "+player.posY+", "+player.posZ+" in World "+world.provider.getDimension()+" threw an Exception! Don't let that happen again!");
2015-10-02 16:48:01 +02:00
}
player.inventory.setInventorySlotContents(slot, player.getHeldItem(hand));
WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, stack);
return EnumActionResult.SUCCESS;
2015-06-21 02:28:49 +02:00
}
}
}
2016-03-18 23:47:22 +01:00
return EnumActionResult.FAIL;
2015-06-21 02:28:49 +02:00
}
2015-10-03 10:19:40 +02:00
/**
* Checks if a certain Upgrade is installed and returns it as an ItemStack
*
* @param stack The Drill
* @param upgrade The Upgrade to be checked
* @return The Upgrade, if it's installed
*/
public ItemStack getHasUpgradeAsStack(ItemStack stack, ItemDrillUpgrade.UpgradeType upgrade){
NBTTagCompound compound = stack.getTagCompound();
if(compound == null){
2017-11-02 22:49:53 +01:00
return StackUtil.getEmpty();
2015-10-03 10:19:40 +02:00
}
ItemStackHandlerCustom inv = new ItemStackHandlerCustom(ContainerDrill.SLOT_AMOUNT);
loadSlotsFromNBT(inv, stack);
for(int i = 0; i < inv.getSlots(); i++){
ItemStack slotStack = inv.getStackInSlot(i);
if(StackUtil.isValid(slotStack) && slotStack.getItem() instanceof ItemDrillUpgrade){
if(((ItemDrillUpgrade)slotStack.getItem()).type == upgrade){
return slotStack;
2015-10-03 10:19:40 +02:00
}
}
}
2017-11-02 22:49:53 +01:00
return StackUtil.getEmpty();
2015-10-03 10:19:40 +02:00
}
@Override
2016-11-19 21:11:17 +01:00
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
if(!world.isRemote && player.isSneaking() && hand == EnumHand.MAIN_HAND){
2015-10-03 10:19:40 +02:00
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.DRILL.ordinal(), world, (int)player.posX, (int)player.posY, (int)player.posZ);
}
2016-11-19 21:11:17 +01:00
return new ActionResult<ItemStack>(EnumActionResult.PASS, player.getHeldItem(hand));
2015-10-03 10:19:40 +02:00
}
2015-12-01 19:48:09 +01:00
@Override
public int getMetadata(int damage){
return damage;
}
2015-10-03 10:19:40 +02:00
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase entity1, EntityLivingBase entity2){
int use = this.getEnergyUsePerBlock(stack);
if(!(entity2 instanceof EntityPlayer) || !((EntityPlayer)entity2).capabilities.isCreativeMode){
if(this.getEnergyStored(stack) >= use){
this.extractEnergyInternal(stack, use, false);
}
2015-10-03 10:19:40 +02:00
}
return true;
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC;
2015-10-03 10:19:40 +02:00
}
2016-05-02 17:09:23 +02:00
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack){
2016-03-19 11:42:11 +01:00
Multimap<String, AttributeModifier> map = super.getAttributeModifiers(slot, stack);
if(slot == EntityEquipmentSlot.MAINHAND){
2016-11-26 21:32:27 +01:00
map.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Drill Modifier", this.getEnergyStored(stack) >= ENERGY_USE ? 8.0F : 0.1F, 0));
map.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Tool Modifier", -2.5F, 0));
2016-03-19 11:42:11 +01:00
}
2015-10-03 10:19:40 +02:00
return map;
}
@Override
2017-11-16 00:11:17 +01:00
public float getDestroySpeed(ItemStack stack, IBlockState state){
return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) ? (this.hasExtraWhitelist(state.getBlock()) || state.getBlock().getHarvestTool(state) == null || state.getBlock().getHarvestTool(state).isEmpty() || this.getToolClasses(stack).contains(state.getBlock().getHarvestTool(state)) ? this.getEfficiencyFromUpgrade(stack) : 1.0F) : 0.1F;
2015-10-03 10:19:40 +02:00
}
@Override
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, EntityPlayer player){
boolean toReturn = false;
2015-10-03 10:19:40 +02:00
int use = this.getEnergyUsePerBlock(stack);
if(this.getEnergyStored(stack) >= use){
//Enchants the Drill depending on the Upgrades it has
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)){
2016-04-20 21:39:03 +02:00
ItemUtil.addEnchantment(stack, Enchantments.SILK_TOUCH, 1);
2015-10-03 10:19:40 +02:00
}
else{
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)){
2016-04-20 21:39:03 +02:00
ItemUtil.addEnchantment(stack, Enchantments.FORTUNE, this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II) ? 3 : 1);
2015-10-03 10:19:40 +02:00
}
}
//Block hit
2016-11-26 21:32:27 +01:00
RayTraceResult ray = WorldUtil.getNearestBlockWithDefaultReachDistance(player.world, player);
if(ray != null){
int side = ray.sideHit.ordinal();
//Breaks the Blocks
if(!player.isSneaking() && this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
2016-11-26 21:32:27 +01:00
toReturn = this.breakBlocks(stack, 2, player.world, side != 0 && side != 1 ? pos.up() : pos, side, player);
}
else{
2016-11-26 21:32:27 +01:00
toReturn = this.breakBlocks(stack, 1, player.world, pos, side, player);
}
2015-10-02 16:48:01 +02:00
}
else{
2016-11-26 21:32:27 +01:00
toReturn = this.breakBlocks(stack, 0, player.world, pos, side, player);
2015-10-02 16:48:01 +02:00
}
2015-10-03 10:19:40 +02:00
//Removes Enchantments added above
ItemUtil.removeEnchantment(stack, Enchantments.SILK_TOUCH);
ItemUtil.removeEnchantment(stack, Enchantments.FORTUNE);
}
2015-06-15 22:06:07 +02:00
}
2015-10-03 10:19:40 +02:00
return toReturn;
}
@Override
public boolean canHarvestBlock(IBlockState state, ItemStack stack){
2016-03-18 23:47:22 +01:00
Block block = state.getBlock();
return this.getEnergyStored(stack) >= this.getEnergyUsePerBlock(stack) && (this.hasExtraWhitelist(block) || state.getMaterial().isToolNotRequired() || (block == Blocks.SNOW_LAYER || block == Blocks.SNOW || (block == Blocks.OBSIDIAN ? HARVEST_LEVEL >= 3 : (block != Blocks.DIAMOND_BLOCK && block != Blocks.DIAMOND_ORE ? (block != Blocks.EMERALD_ORE && block != Blocks.EMERALD_BLOCK ? (block != Blocks.GOLD_BLOCK && block != Blocks.GOLD_ORE ? (block != Blocks.IRON_BLOCK && block != Blocks.IRON_ORE ? (block != Blocks.LAPIS_BLOCK && block != Blocks.LAPIS_ORE ? (block != Blocks.REDSTONE_ORE && block != Blocks.LIT_REDSTONE_ORE ? (state.getMaterial() == Material.ROCK || (state.getMaterial() == Material.IRON || state.getMaterial() == Material.ANVIL)) : HARVEST_LEVEL >= 2) : HARVEST_LEVEL >= 1) : HARVEST_LEVEL >= 1) : HARVEST_LEVEL >= 2) : HARVEST_LEVEL >= 2) : HARVEST_LEVEL >= 2))));
2015-10-03 10:19:40 +02:00
}
@Override
public Set<String> getToolClasses(ItemStack stack){
HashSet<String> hashSet = new HashSet<String>();
hashSet.add("pickaxe");
hashSet.add("shovel");
return hashSet;
}
@Override
2016-11-26 21:32:27 +01:00
public int getHarvestLevel(ItemStack stack, String toolClass, EntityPlayer player, IBlockState blockState){
return HARVEST_LEVEL;
2015-06-18 13:14:57 +02:00
}
2015-06-15 22:06:07 +02:00
/**
* Gets the Energy that is used per Block broken
2015-10-02 16:48:01 +02:00
*
* @param stack The Drill
* @return The Energy use per Block
*/
2015-06-18 13:14:57 +02:00
public int getEnergyUsePerBlock(ItemStack stack){
int use = ENERGY_USE;
2015-06-21 02:28:49 +02:00
//Speed
2015-06-21 02:28:49 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED)){
use += 50;
2015-06-21 02:28:49 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_II)){
use += 75;
2015-10-02 16:48:01 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_III)){
use += 175;
2015-10-02 16:48:01 +02:00
}
2015-06-15 22:06:07 +02:00
}
}
//Silk Touch
2015-10-02 16:48:01 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SILK_TOUCH)){
use += 100;
2015-10-02 16:48:01 +02:00
}
2015-06-21 02:28:49 +02:00
//Fortune
2015-06-21 02:28:49 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE)){
use += 40;
2015-10-02 16:48:01 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FORTUNE_II)){
use += 80;
2015-10-02 16:48:01 +02:00
}
2015-06-15 22:06:07 +02:00
}
//Size
2015-06-21 02:28:49 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
use += 10;
2015-10-02 16:48:01 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
use += 30;
2015-10-02 16:48:01 +02:00
}
2015-06-15 22:06:07 +02:00
}
2015-06-21 02:28:49 +02:00
return use;
2015-06-15 22:06:07 +02:00
}
/**
* Checks if a certain Upgrade is applied
2015-10-02 16:48:01 +02:00
*
* @param stack The Drill
* @param upgrade The Upgrade to be checked
* @return Is the Upgrade applied?
*/
2015-06-15 22:06:07 +02:00
public boolean getHasUpgrade(ItemStack stack, ItemDrillUpgrade.UpgradeType upgrade){
return StackUtil.isValid(this.getHasUpgradeAsStack(stack, upgrade));
2015-06-21 02:28:49 +02:00
}
2015-06-15 22:06:07 +02:00
2016-02-01 17:49:55 +01:00
@Override
protected void registerRendering(){
for(int i = 0; i < 16; i++){
2016-11-19 23:12:22 +01:00
String name = this.getRegistryName()+"_"+TheColoredLampColors.values()[i].regName;
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this, 1, i), new ResourceLocation(name), "inventory");
2016-02-01 17:49:55 +01:00
}
}
2015-12-01 19:48:09 +01:00
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(CreativeTabs tabs, NonNullList<ItemStack> list){
if(this.isInCreativeTab(tabs)){
2017-06-17 00:48:49 +02:00
for(int i = 0; i < 16; i++){
this.addDrillStack(list, i);
}
2015-12-01 19:48:09 +01:00
}
}
private void addDrillStack(List<ItemStack> list, int meta){
2015-12-01 19:48:09 +01:00
ItemStack stackFull = new ItemStack(this, 1, meta);
this.setEnergy(stackFull, this.getMaxEnergyStored(stackFull));
list.add(stackFull);
ItemStack stackEmpty = new ItemStack(this, 1, meta);
this.setEnergy(stackEmpty, 0);
list.add(stackEmpty);
}
/**
2015-10-03 10:19:40 +02:00
* Gets the Mining Speed of the Drill
2015-10-02 16:48:01 +02:00
*
2015-10-03 10:19:40 +02:00
* @param stack The Drill
* @return The Mining Speed depending on the Speed Upgrades
*/
2015-10-03 10:19:40 +02:00
public float getEfficiencyFromUpgrade(ItemStack stack){
float efficiency = 8.0F;
2015-10-03 10:19:40 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED)){
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_II)){
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.SPEED_III)){
efficiency += 37.0F;
}
else{
efficiency += 25.0F;
2015-06-15 22:06:07 +02:00
}
}
2015-10-03 10:19:40 +02:00
else{
efficiency += 8.0F;
}
2015-06-15 22:06:07 +02:00
}
2016-06-09 21:14:43 +02:00
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.THREE_BY_THREE)){
efficiency *= 0.5F;
if(this.getHasUpgrade(stack, ItemDrillUpgrade.UpgradeType.FIVE_BY_FIVE)){
efficiency *= 0.35F;
}
}
2015-10-03 10:19:40 +02:00
return efficiency;
2015-06-15 22:06:07 +02:00
}
/**
* Breaks Blocks in a certain Radius
* Has to be called on both Server and Client
2015-10-02 16:48:01 +02:00
*
* @param stack The Drill
* @param radius The Radius to break Blocks in (0 means only 1 Block will be broken!)
2015-10-02 16:48:01 +02:00
* @param world The World
* @param player The Player who breaks the Blocks
*/
public boolean breakBlocks(ItemStack stack, int radius, World world, BlockPos aPos, int side, EntityPlayer player){
2015-06-15 22:06:07 +02:00
int xRange = radius;
int yRange = radius;
int zRange = 0;
2015-07-20 22:06:08 +02:00
//Corrects Blocks to hit depending on Side of original Block hit
if(side == 0 || side == 1){
zRange = radius;
yRange = 0;
}
if(side == 4 || side == 5){
xRange = 0;
zRange = radius;
}
2015-06-15 22:06:07 +02:00
2015-07-20 22:06:08 +02:00
//Not defined later because main Block is getting broken below
2016-07-04 20:15:41 +02:00
IBlockState state = world.getBlockState(aPos);
float mainHardness = state.getBlockHardness(world, aPos);
2015-07-20 22:06:08 +02:00
//Break Middle Block first
int use = this.getEnergyUsePerBlock(stack);
if(this.getEnergyStored(stack) >= use){
2016-01-08 13:31:58 +01:00
if(!this.tryHarvestBlock(world, aPos, false, stack, player, use)){
2015-10-03 10:16:18 +02:00
return false;
}
2015-07-20 22:06:08 +02:00
}
2015-10-02 16:48:01 +02:00
else{
return false;
}
2015-07-20 22:06:08 +02:00
//Break Blocks around
if(radius > 0 && mainHardness >= 0.2F){
for(int xPos = aPos.getX()-xRange; xPos <= aPos.getX()+xRange; xPos++){
for(int yPos = aPos.getY()-yRange; yPos <= aPos.getY()+yRange; yPos++){
for(int zPos = aPos.getZ()-zRange; zPos <= aPos.getZ()+zRange; zPos++){
if(!(aPos.getX() == xPos && aPos.getY() == yPos && aPos.getZ() == zPos)){
2015-07-20 22:06:08 +02:00
if(this.getEnergyStored(stack) >= use){
//Only break Blocks around that are (about) as hard or softer
2016-01-08 13:31:58 +01:00
BlockPos thePos = new BlockPos(xPos, yPos, zPos);
2016-07-04 20:15:41 +02:00
IBlockState theState = world.getBlockState(thePos);
if(theState.getBlockHardness(world, thePos) <= mainHardness+5.0F){
this.tryHarvestBlock(world, thePos, true, stack, player, use);
}
2015-06-15 22:06:07 +02:00
}
2015-10-02 16:48:01 +02:00
else{
return false;
}
2015-06-15 22:06:07 +02:00
}
}
}
}
}
2015-07-20 22:06:08 +02:00
return true;
}
/**
* Tries to harvest a certain Block
* Breaks the Block, drops Particles etc.
* Has to be called on both Server and Client
2015-10-02 16:48:01 +02:00
*
* @param world The World
* @param isExtra If the Block is the Block that was looked at when breaking or an additional Block
2015-10-02 16:48:01 +02:00
* @param stack The Drill
* @param player The Player breaking the Blocks
* @param use The Energy that should be extracted per Block
*/
2016-01-08 13:31:58 +01:00
private boolean tryHarvestBlock(World world, BlockPos pos, boolean isExtra, ItemStack stack, EntityPlayer player, int use){
2016-03-18 23:47:22 +01:00
IBlockState state = world.getBlockState(pos);
2016-07-04 20:15:41 +02:00
Block block = state.getBlock();
float hardness = state.getBlockHardness(world, pos);
2017-11-16 00:11:17 +01:00
boolean canHarvest = (ForgeHooks.canHarvestBlock(block, player, world, pos) || this.canHarvestBlock(state, stack)) && (!isExtra || this.getDestroySpeed(stack, world.getBlockState(pos)) > 1.0F);
2016-01-08 13:31:58 +01:00
if(hardness >= 0.0F && (!isExtra || (canHarvest && !block.hasTileEntity(world.getBlockState(pos))))){
if(!player.capabilities.isCreativeMode){
this.extractEnergyInternal(stack, use, false);
}
//Break the Block
return WorldUtil.playerHarvestBlock(stack, world, player, pos);
}
2015-07-20 22:06:08 +02:00
return false;
2015-06-15 22:06:07 +02:00
}
private boolean hasExtraWhitelist(Block block){
if(block != null){
ResourceLocation location = block.getRegistryName();
if(location != null){
String name = location.toString();
if(name != null){
for(String s : ConfigStringListValues.DRILL_EXTRA_MINING_WHITELIST.getValue()){
if(s != null && s.equals(name)){
return true;
}
}
2015-10-03 10:16:18 +02:00
}
}
}
return false;
}
2017-08-12 00:15:09 +02:00
@Override
public boolean shouldCauseBlockBreakReset(ItemStack oldStack, ItemStack newStack) {
return !(newStack.isItemEqual(oldStack));
}
2015-06-15 22:06:07 +02:00
}