OSDN Git Service

8f07fa61b90600c1ae7ca9a436668007b43c8bbe
[chemicraft/chemicraft.git] / common / chemicraft / item / ItemGasCollectingBottle.java
1 package chemicraft.item;
2
3 import net.minecraft.src.Block;
4 import net.minecraft.src.BlockFire;
5 import net.minecraft.src.EntityPlayer;
6 import net.minecraft.src.ItemStack;
7 import net.minecraft.src.World;
8 import chemicraft.ChemiCraft;
9 import chemicraft.ChemiCraftAPI;
10 import chemicraft.util.MathHelperPlus;
11
12 public class ItemGasCollectingBottle extends ItemAtomInfoContainer
13 {
14
15         public ItemGasCollectingBottle(int id) {
16                 super(id);
17                 this.setMaxStackSize(1);
18                 this.setMaxDamage(2);
19                 this.setCreativeTab(ChemiCraft.instance.creativeTab);
20         }
21
22         @Override
23         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
24         {
25                 par1ItemStack.damageItem(1, par3EntityPlayer);
26
27                 this.atomInfo.update(par2World, par3EntityPlayer);
28
29                 int heightValue = par2World.getHeightValue((int) par3EntityPlayer.posX, (int) par3EntityPlayer.posZ);
30
31                 int result1 = MathHelperPlus.probability(99, 1);
32                 int result2 = MathHelperPlus.probability(78, 21, 1);
33                 int result3 = MathHelperPlus.probability(0.032, 0.0018, 0.000012, 0.00052);
34                 if (this.atomInfo.isOverY(heightValue)) {
35                         if (result1 == 0) {
36                                 if (result2 == 0) {
37                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 6), par3EntityPlayer);
38                                 } else if (result2 == 1) {
39                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 7), par3EntityPlayer);
40                                 } else {
41                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 17), par3EntityPlayer);
42                                 }
43                         } else {
44                                 if (result3 == 0) {
45                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.getInstance().getCompound("CarbonDioxide")), par3EntityPlayer);
46                                 } else if (result3 == 1) {
47                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 9), par3EntityPlayer);
48                                 } else if (result3 == 2) {
49                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 1), par3EntityPlayer);
50                                 } else {
51                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 1), par3EntityPlayer);
52                                 }
53                         }
54                 }
55
56                 // デバッグ用
57                 if (par2World.isRemote) {
58                         par3EntityPlayer.addChatMessage("result1=" + result1 + " result2=" + result2 + " result3=" + result3);
59                 }
60
61                 return par1ItemStack;
62         }
63
64         public void isStackOrDrop(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer)
65         {
66                 if (!par2EntityPlayer.inventory.addItemStackToInventory(par1ItemStack)) {
67                         par2EntityPlayer.dropPlayerItem(par1ItemStack);
68                 }
69         }
70
71         @Override
72         public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
73         {
74                 int var11 = par3World.getBlockId(par4, par5, par6);
75                 Block block = Block.blocksList[var11];
76
77                 if (block instanceof BlockFire){
78                         par1ItemStack.damageItem(1, par2EntityPlayer);
79
80                         int result1 = MathHelperPlus.probability(99, 1);
81
82                         if (result1 == 0) {
83                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.getInstance().getCompound("CarbonDioxide")), par2EntityPlayer);
84                         } else {
85                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 17), par2EntityPlayer);
86                         }
87
88                         return true;
89                 }
90                 return false;
91         }
92
93         @Override
94         public String getTextureFile()
95         {
96                 return "/chemicraft/items/items.png";
97         }
98
99 }