OSDN Git Service

ca3870734061ccb3037488a8a2e2e81c3dd7f36d
[chemicraft/chemicraft.git] / common / pcc / chemicraft / base / item / ItemOreSerarcher.java
1 package pcc.chemicraft.base.item;
2
3 import cpw.mods.fml.common.registry.LanguageRegistry;
4 import cpw.mods.fml.relauncher.SideOnly;
5 import pcc.chemicraft.ChemiCraft;
6 import pcc.chemicraft.base.ChemiCraftBase;
7 import pcc.chemicraft.core.ChemiCraftCore;
8 import net.minecraft.client.renderer.texture.IconRegister;
9 import net.minecraft.entity.player.EntityPlayer;
10 import net.minecraft.item.Item;
11 import net.minecraft.item.ItemStack;
12 import net.minecraft.nbt.NBTTagCompound;
13 import net.minecraft.util.StringTranslate;
14 import net.minecraft.world.World;
15
16 public class ItemOreSerarcher extends Item {
17
18         public ItemOreSerarcher(int par1) {
19                 super(par1);
20                 this.setHasSubtypes(true);
21                 this.setMaxStackSize(1);
22                 this.setMaxDamage(0);
23                 this.setCreativeTab(ChemiCraftCore.creativeTabChemiCraft);
24         }
25
26         @Override
27         public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) {
28                 for (int i = 0; i < ChemiCraftBase.instance.atomOresID.length; i++) {
29                         if (par3World.getBlockId(par4, par5, par6) == ChemiCraftBase.instance.atomOresID[i]) {
30                                 if (par1ItemStack.getTagCompound() == null) {
31                                         par1ItemStack.stackTagCompound = new NBTTagCompound();
32                                 }
33                                 if (par3World.isRemote) {
34                                         this.changeItem(par2EntityPlayer);
35                                 }
36                                 String blockName = ChemiCraftBase.instance.apiBase.getAtomOreEnglishName(
37                                                 (Math.abs(ChemiCraftBase.instance.atomOresID[ChemiCraftBase.instance.atomOresID.length-1] -
38                                                                 (par3World.getBlockId(par4, par5, par6) + 3))) * 16 +
39                                                                 par3World.getBlockMetadata(par4, par5, par6));
40                                 par1ItemStack.getTagCompound().setString("OreName", blockName);
41                         }
42                 }
43                 return true;
44         }
45
46         public void changeItem(EntityPlayer par1EntityPlayer) {
47                 par1EntityPlayer.inventory.inventoryChanged = true;
48         }
49
50         @Override
51         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
52                 this.changeItem(par3EntityPlayer);
53                 return par1ItemStack;
54         }
55
56         public String getItemDisplayName(ItemStack par1ItemStack) {
57                 if (par1ItemStack.getTagCompound() != null) {
58                         return "OreSearcher:" + par1ItemStack.getTagCompound().getString("OreName");
59                 }
60                 return "OreSearcher";
61         }
62
63         @Override
64         public boolean getShareTag() {
65                 return true;
66         }
67
68         @Override
69         public void updateIcons(IconRegister par1IconRegister){
70                 this.iconIndex = par1IconRegister.registerIcon(ChemiCraft.ITEM_TEXTURE + "ItemOreSearcher");
71         }
72
73 }