2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("ItemAllToolAA.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.items.base;
|
2015-07-06 19:52:27 +02:00
|
|
|
|
2016-01-08 20:51:03 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
2015-06-12 19:12:06 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-06-12 19:12:06 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
2016-03-18 18:38:39 +01:00
|
|
|
import net.minecraft.init.Items;
|
2015-07-07 14:32:10 +02:00
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.ItemTool;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.BlockPos;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-01-08 20:51:03 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2015-06-12 19:12:06 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-01-07 18:20:59 +01:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-07-12 22:05:34 +02:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
2015-06-21 02:28:49 +02:00
|
|
|
import java.util.HashSet;
|
2015-06-12 19:12:06 +02:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
2015-12-19 10:30:39 +01:00
|
|
|
public class ItemAllToolAA extends ItemTool{
|
2015-06-12 19:12:06 +02:00
|
|
|
|
2015-10-25 23:19:01 +01:00
|
|
|
private int color;
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
private String name;
|
|
|
|
private EnumRarity rarity;
|
2015-12-31 15:05:27 +01:00
|
|
|
private ItemStack repairItem;
|
|
|
|
private String repairOredict;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity, int color){
|
|
|
|
this(toolMat, (ItemStack)null, unlocalizedName, rarity, color);
|
|
|
|
this.repairOredict = repairItem;
|
|
|
|
}
|
|
|
|
|
2015-12-31 15:05:27 +01:00
|
|
|
public ItemAllToolAA(ToolMaterial toolMat, ItemStack repairItem, String unlocalizedName, EnumRarity rarity, int color){
|
2016-01-10 20:16:19 +01:00
|
|
|
super(4.0F, toolMat, new HashSet<Block>());
|
2015-06-12 19:12:06 +02:00
|
|
|
|
|
|
|
this.repairItem = repairItem;
|
|
|
|
this.name = unlocalizedName;
|
|
|
|
this.rarity = rarity;
|
2015-10-25 23:19:01 +01:00
|
|
|
this.color = color;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
|
|
|
this.setMaxDamage(this.getMaxDamage()*4);
|
2015-12-03 20:15:07 +01:00
|
|
|
|
|
|
|
this.register();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void register(){
|
2016-03-18 18:38:39 +01:00
|
|
|
ItemUtil.registerItem(this, this.getBaseName(), this.shouldAddCreative());
|
2016-01-08 16:52:53 +01:00
|
|
|
|
2016-01-08 20:51:03 +01:00
|
|
|
this.registerRendering();
|
|
|
|
}
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
protected String getBaseName(){
|
|
|
|
return this.name;
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
public boolean shouldAddCreative(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-01 17:49:55 +01:00
|
|
|
protected void registerRendering(){
|
|
|
|
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this), new ResourceLocation(ModUtil.MOD_ID_LOWER, "itemPaxel"));
|
|
|
|
ActuallyAdditions.proxy.addRenderVariant(this, new ResourceLocation(ModUtil.MOD_ID_LOWER, "itemPaxel"));
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ){
|
2016-03-18 18:38:39 +01:00
|
|
|
return Items.iron_hoe.onItemUse(stack, playerIn, worldIn, pos, side, hitX, hitY, hitZ);
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
2015-10-28 14:46:04 +01:00
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getColorFromItemStack(ItemStack stack, int pass){
|
|
|
|
return pass > 0 ? this.color : super.getColorFromItemStack(stack, pass);
|
|
|
|
}
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return this.rarity;
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public boolean canHarvestBlock(Block block, ItemStack stack){
|
2015-11-05 21:44:27 +01:00
|
|
|
return this.hasExtraWhitelist(block) || block.getMaterial().isToolNotRequired() || (block == Blocks.snow_layer || block == Blocks.snow || (block == Blocks.obsidian ? this.toolMaterial.getHarvestLevel() >= 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 ? (block.getMaterial() == Material.rock || (block.getMaterial() == Material.iron || block.getMaterial() == Material.anvil)) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 1) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2) : this.toolMaterial.getHarvestLevel() >= 2)));
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 22:13:57 +02:00
|
|
|
private boolean hasExtraWhitelist(Block block){
|
2016-01-07 21:41:28 +01:00
|
|
|
String name = block.getRegistryName();
|
2015-10-03 22:13:57 +02:00
|
|
|
if(name != null){
|
|
|
|
for(String list : ConfigValues.paxelExtraMiningWhitelist){
|
|
|
|
if(list.equals(name)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public boolean getIsRepairable(ItemStack itemToRepair, ItemStack stack){
|
2015-12-31 15:05:27 +01:00
|
|
|
if(this.repairItem != null){
|
|
|
|
return ItemUtil.areItemsEqual(this.repairItem, stack, false);
|
|
|
|
}
|
|
|
|
else if(this.repairOredict != null){
|
|
|
|
int[] idsStack = OreDictionary.getOreIDs(stack);
|
|
|
|
for(int id : idsStack){
|
|
|
|
if(OreDictionary.getOreName(id).equals(this.repairOredict)){
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-21 02:28:49 +02:00
|
|
|
@Override
|
|
|
|
public Set<String> getToolClasses(ItemStack stack){
|
2015-07-17 23:22:10 +02:00
|
|
|
HashSet<String> hashSet = new HashSet<String>();
|
2015-06-21 02:28:49 +02:00
|
|
|
hashSet.add("pickaxe");
|
|
|
|
hashSet.add("axe");
|
|
|
|
hashSet.add("shovel");
|
|
|
|
return hashSet;
|
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
|
|
|
@Override
|
2016-01-07 21:41:28 +01:00
|
|
|
public float getDigSpeed(ItemStack stack, IBlockState state){
|
|
|
|
return this.hasExtraWhitelist(state.getBlock()) || state.getBlock().getHarvestTool(state) == null || state.getBlock().getHarvestTool(state).isEmpty() || this.getToolClasses(stack).contains(state.getBlock().getHarvestTool(state)) ? this.efficiencyOnProperMaterial : 1.0F;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
2015-07-06 19:52:27 +02:00
|
|
|
}
|