2015-06-12 19:12:06 +02:00
|
|
|
package ellpeck.actuallyadditions.items.tools;
|
2015-07-06 19:52:27 +02:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
import ellpeck.actuallyadditions.util.INameableItem;
|
2015-06-18 13:14:57 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ItemUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.KeyUtil;
|
2015-06-12 19:12:06 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
2015-07-07 14:32:10 +02:00
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.ItemTool;
|
2015-06-12 19:12:06 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.player.UseHoeEvent;
|
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.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
public class ItemAllToolAA extends ItemTool implements INameableItem{
|
|
|
|
|
2015-07-07 14:32:10 +02:00
|
|
|
public static final Set axeSet = Sets.newHashSet(Blocks.planks, Blocks.bookshelf, Blocks.log, Blocks.log2, Blocks.chest, Blocks.pumpkin, Blocks.lit_pumpkin);
|
|
|
|
public static final Set pickSet = Sets.newHashSet(Blocks.cobblestone, Blocks.double_stone_slab, Blocks.stone_slab, Blocks.stone, Blocks.sandstone, Blocks.mossy_cobblestone, Blocks.iron_ore, Blocks.iron_block, Blocks.coal_ore, Blocks.gold_block, Blocks.gold_ore, Blocks.diamond_ore, Blocks.diamond_block, Blocks.ice, Blocks.netherrack, Blocks.lapis_ore, Blocks.lapis_block, Blocks.redstone_ore, Blocks.lit_redstone_ore, Blocks.rail, Blocks.detector_rail, Blocks.golden_rail, Blocks.activator_rail);
|
|
|
|
public static final Set shovelSet = Sets.newHashSet(Blocks.grass, Blocks.dirt, Blocks.sand, Blocks.gravel, Blocks.snow_layer, Blocks.snow, Blocks.clay, Blocks.farmland, Blocks.soul_sand, Blocks.mycelium);
|
2015-06-12 19:12:06 +02:00
|
|
|
|
|
|
|
private static final Set allSet = Sets.newHashSet();
|
|
|
|
static{
|
|
|
|
allSet.addAll(axeSet);
|
|
|
|
allSet.addAll(pickSet);
|
|
|
|
allSet.addAll(shovelSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
private EnumRarity rarity;
|
2015-07-12 22:05:34 +02:00
|
|
|
private String repairItem;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
2015-07-12 22:05:34 +02:00
|
|
|
public ItemAllToolAA(ToolMaterial toolMat, String repairItem, String unlocalizedName, EnumRarity rarity){
|
2015-06-12 19:12:06 +02:00
|
|
|
super(5.0F, toolMat, allSet);
|
|
|
|
|
|
|
|
this.repairItem = repairItem;
|
|
|
|
this.name = unlocalizedName;
|
|
|
|
this.rarity = rarity;
|
|
|
|
|
|
|
|
this.setMaxDamage(this.getMaxDamage()*4);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float func_150893_a(ItemStack stack, Block block){
|
|
|
|
return block.getMaterial() != Material.iron && block.getMaterial() != Material.anvil && block.getMaterial() != Material.rock && block.getMaterial() != Material.wood && block.getMaterial() != Material.plants && block.getMaterial() != Material.vine ? super.func_150893_a(stack, block) : this.efficiencyOnProperMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean func_150897_b(Block block){
|
|
|
|
return 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));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) {
|
2015-06-18 13:14:57 +02:00
|
|
|
if(KeyUtil.isShiftPressed()){
|
|
|
|
list.add(StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".paxel.desc"));
|
|
|
|
list.add(StatCollector.translateToLocal("tooltip." + ModUtil.MOD_ID_LOWER + ".durability.desc") + ": " + (this.getMaxDamage()-this.getDamage(stack)) + "/" + this.getMaxDamage());
|
|
|
|
}
|
|
|
|
else list.add(ItemUtil.shiftForInfo());
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ){
|
2015-06-18 13:14:57 +02:00
|
|
|
if (!player.canPlayerEdit(x, y, z, side, stack)) return false;
|
2015-06-12 19:12:06 +02:00
|
|
|
else{
|
|
|
|
UseHoeEvent event = new UseHoeEvent(player, stack, world, x, y, z);
|
|
|
|
if(MinecraftForge.EVENT_BUS.post(event)) return false;
|
|
|
|
if(event.getResult() == Event.Result.ALLOW){
|
|
|
|
stack.damageItem(1, player);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Block block = world.getBlock(x, y, z);
|
2015-06-18 13:14:57 +02:00
|
|
|
if(side != 0 && world.getBlock(x, y + 1, z).isAir(world, x, y + 1, z) && (block == Blocks.grass || block == Blocks.dirt)){
|
2015-06-12 19:12:06 +02:00
|
|
|
Block block1 = Blocks.farmland;
|
2015-06-18 13:14:57 +02:00
|
|
|
world.playSoundEffect((double)((float)x + 0.5F), (double)((float)y + 0.5F), (double)((float)z + 0.5F), block1.stepSound.getStepResourcePath(), (block1.stepSound.getVolume() + 1.0F) / 2.0F, block1.stepSound.getPitch() * 0.8F);
|
|
|
|
if (world.isRemote) return true;
|
2015-06-12 19:12:06 +02:00
|
|
|
else{
|
|
|
|
world.setBlock(x, y, z, block1);
|
|
|
|
stack.damageItem(1, player);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getIsRepairable(ItemStack itemToRepair, ItemStack stack){
|
2015-07-12 22:05:34 +02:00
|
|
|
int[] idsStack = OreDictionary.getOreIDs(stack);
|
|
|
|
for(int id : idsStack){
|
|
|
|
if(OreDictionary.getOreName(id).equals(repairItem)) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-06-12 19:12:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return this.rarity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IIcon getIcon(ItemStack stack, int pass){
|
|
|
|
return this.itemIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconReg){
|
|
|
|
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2015-06-21 02:28:49 +02:00
|
|
|
@Override
|
|
|
|
public Set<String> getToolClasses(ItemStack stack){
|
|
|
|
HashSet<String> hashSet = new HashSet<String>();
|
|
|
|
hashSet.add("pickaxe");
|
|
|
|
hashSet.add("axe");
|
|
|
|
hashSet.add("shovel");
|
|
|
|
return hashSet;
|
|
|
|
}
|
2015-07-06 19:52:27 +02:00
|
|
|
}
|