OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/chemicraft/chemicraft
[chemicraft/chemicraft.git] / common / chemicraft / item / ItemGasCollectingBottle.java
1 package chemicraft.item;\r
2 \r
3 import net.minecraft.block.Block;\r
4 import net.minecraft.block.BlockFire;\r
5 import net.minecraft.entity.player.EntityPlayer;\r
6 import net.minecraft.item.ItemStack;\r
7 import net.minecraft.world.World;\r
8 import chemicraft.ChemiCraft;\r
9 import chemicraft.ChemiCraftAPI;\r
10 import chemicraft.util.MathHelperPlus;\r
11 \r
12 public class ItemGasCollectingBottle extends ItemAtomInfoContainer\r
13 {\r
14 \r
15         public ItemGasCollectingBottle(int id) {\r
16                 super(id);\r
17                 this.setMaxStackSize(1);\r
18                 this.setMaxDamage(2);\r
19                 this.setCreativeTab(ChemiCraft.instance.creativeTab);\r
20         }\r
21 \r
22         @Override\r
23         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)\r
24         {\r
25                 par1ItemStack.damageItem(1, par3EntityPlayer);\r
26 \r
27                 this.atomInfo.update(par2World, par3EntityPlayer);\r
28 \r
29                 int heightValue = par2World.getHeightValue((int) par3EntityPlayer.posX, (int) par3EntityPlayer.posZ);\r
30 \r
31                 int result1 = MathHelperPlus.probability(99, 1);\r
32                 int result2 = MathHelperPlus.probability(78, 21, 1);\r
33                 int result3 = MathHelperPlus.probability(0.032, 0.0018, 0.000012, 0.00052);\r
34                 if (this.atomInfo.isOverY(heightValue)) {\r
35                         if (result1 == 0) {\r
36                                 if (result2 == 0) {\r
37                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 6), par3EntityPlayer);\r
38                                 } else if (result2 == 1) {\r
39                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 7), par3EntityPlayer);\r
40                                 } else {\r
41                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 17), par3EntityPlayer);\r
42                                 }\r
43                         } else {\r
44                                 if (result3 == 0) {\r
45                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.getInstance().getCompound("CarbonDioxide")), par3EntityPlayer);\r
46                                 } else if (result3 == 1) {\r
47                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 9), par3EntityPlayer);\r
48                                 } else if (result3 == 2) {\r
49                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 1), par3EntityPlayer);\r
50                                 } else {\r
51                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 1), par3EntityPlayer);\r
52                                 }\r
53                         }\r
54                 }\r
55 \r
56                 // デバッグ用\r
57                 if (par2World.isRemote) {\r
58                         par3EntityPlayer.addChatMessage("result1=" + result1 + " result2=" + result2 + " result3=" + result3);\r
59                         par3EntityPlayer.addChatMessage("このメッセージは開発版のみの表示ですが、もし製品版で表示されていた場合はご連絡ください。");\r
60                 }\r
61 \r
62                 return par1ItemStack;\r
63         }\r
64 \r
65         protected void isStackOrDrop(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer)\r
66         {\r
67                 if (!par2EntityPlayer.inventory.addItemStackToInventory(par1ItemStack)) {\r
68                         par2EntityPlayer.dropPlayerItem(par1ItemStack);\r
69                 }\r
70         }\r
71 \r
72         @Override\r
73         public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)\r
74         {\r
75                 int blockID = par3World.getBlockId(par4, par5, par6);\r
76                 Block block = Block.blocksList[blockID];\r
77 \r
78                 int uniqueBlockID = par3World.getBlockId(par4, par5 + 1, par6);\r
79                 Block uniqueBlock = Block.blocksList[uniqueBlockID];\r
80 \r
81                 if (uniqueBlock instanceof BlockFire){\r
82                         par1ItemStack.damageItem(1, par2EntityPlayer);\r
83 \r
84                         int result1 = MathHelperPlus.probability(90, 10);\r
85 \r
86                         if (result1 == 0) {\r
87                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.getInstance().getCompound("CarbonDioxide")), par2EntityPlayer);\r
88                         } else {\r
89                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.getInstance().getCompound("CarbonMonoxide")), par2EntityPlayer);\r
90                         }\r
91 \r
92                         return true;\r
93                 }\r
94                 return false;\r
95         }\r
96 \r
97         @Override\r
98         public String getTextureFile()\r
99         {\r
100                 return "/chemicraft/items/items.png";\r
101         }\r
102 \r
103 }\r