Chainsaws effective on leaves, and are affected by unbreaking enchantment, along with the drills
This commit is contained in:
parent
d543554856
commit
34046e9ef4
4 changed files with 152 additions and 100 deletions
|
@ -1,11 +1,14 @@
|
|||
package techreborn.items.tools;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import me.modmuss50.jsonDestroyer.api.ITexturedItem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -23,6 +26,7 @@ import reborncore.api.power.IEnergyItemInfo;
|
|||
import reborncore.common.powerSystem.PoweredItem;
|
||||
import reborncore.common.util.TorchHelper;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.utils.OreDictUtils;
|
||||
|
||||
public class ItemChainsaw extends ItemAxe implements IEnergyItemInfo, ITexturedItem {
|
||||
|
||||
|
@ -47,12 +51,18 @@ public class ItemChainsaw extends ItemAxe implements IEnergyItemInfo, ITexturedI
|
|||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) {
|
||||
Random rand = new Random();
|
||||
if (rand.nextInt(EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)+1) == 0) {
|
||||
PoweredItem.useEnergy(cost, stack);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDigSpeed(ItemStack stack, IBlockState state) {
|
||||
if(OreDictUtils.isOre(state, "treeLeaves")&&PoweredItem.canUseEnergy(cost, stack)){
|
||||
return 40F;
|
||||
}
|
||||
if(!PoweredItem.canUseEnergy(cost, stack)){
|
||||
return unpoweredSpeed;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package techreborn.items.tools;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import me.modmuss50.jsonDestroyer.api.ITexturedItem;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
|
@ -22,7 +25,6 @@ import reborncore.api.power.IEnergyItemInfo;
|
|||
import reborncore.common.powerSystem.PoweredItem;
|
||||
import reborncore.common.util.TorchHelper;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
|
||||
public class ItemDrill extends ItemPickaxe implements IEnergyItemInfo, ITexturedItem {
|
||||
|
||||
|
@ -47,7 +49,10 @@ public class ItemDrill extends ItemPickaxe implements IEnergyItemInfo, ITextured
|
|||
|
||||
@Override
|
||||
public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) {
|
||||
Random rand = new Random();
|
||||
if (rand.nextInt(EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack)+1) == 0) {
|
||||
PoweredItem.useEnergy(cost, stack);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -68,7 +73,6 @@ public class ItemDrill extends ItemPickaxe implements IEnergyItemInfo, ITextured
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
|
||||
return TorchHelper.placeTorch(stack, playerIn, worldIn, pos.getX(), pos.getY(), pos.getZ(), side.getIndex(), hitX, hitY, hitZ);
|
||||
|
@ -79,7 +83,6 @@ public class ItemDrill extends ItemPickaxe implements IEnergyItemInfo, ITextured
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getMaxPower(ItemStack stack) {
|
||||
return maxCharge;
|
||||
|
@ -105,8 +108,7 @@ public class ItemDrill extends ItemPickaxe implements IEnergyItemInfo, ITextured
|
|||
return tier;
|
||||
}
|
||||
|
||||
@SuppressWarnings(
|
||||
{"rawtypes", "unchecked"})
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
ItemStack itemStack = new ItemStack(this, 1);
|
||||
|
|
40
src/main/java/techreborn/utils/OreDictUtils.java
Normal file
40
src/main/java/techreborn/utils/OreDictUtils.java
Normal file
|
@ -0,0 +1,40 @@
|
|||
package techreborn.utils;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class OreDictUtils {
|
||||
|
||||
public static boolean isOre(Block block, String oreName) {
|
||||
return isOre(new ItemStack(Item.getItemFromBlock(block)), oreName);
|
||||
}
|
||||
|
||||
public static boolean isOre(IBlockState state, String oreName) {
|
||||
return isOre(new ItemStack(Item.getItemFromBlock(state.getBlock()), 1, state.getBlock().getMetaFromState(state)), oreName);
|
||||
}
|
||||
|
||||
public static boolean isOre(Item item, String oreName) {
|
||||
return isOre(new ItemStack(item), oreName);
|
||||
}
|
||||
|
||||
public static boolean isOre(ItemStack stack, String oreName) {
|
||||
int id = OreDictionary.getOreID(oreName);
|
||||
|
||||
if (stack != null || stack.getItem() != null) {
|
||||
int[] ids = OreDictionary.getOreIDs(stack);
|
||||
|
||||
for (int i : ids) {
|
||||
if (id == i) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 432 B After Width: | Height: | Size: 432 B |
Loading…
Reference in a new issue