OSDN Git Service

集気ビンを右クリックで確率に応じた気体を入手可能。
[chemicraft/chemicraft.git] / common / chemicraft / ItemGasCollectingBottle.java
1 package chemicraft;
2
3 import java.util.Random;
4
5 import net.minecraft.src.*;
6
7 public class ItemGasCollectingBottle extends ItemAtomInfoContainer
8 {
9
10         public ItemGasCollectingBottle(int id) {
11                 super(id);
12                 this.setMaxStackSize(1);
13                 this.setMaxDamage(2);
14                 this.setCreativeTab(ChemiCraft.instance.creativeTab);
15         }
16
17         @Override
18         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
19         {
20                 par1ItemStack.damageItem(1, par3EntityPlayer);
21
22                 this.atomInfo.update(par2World, par3EntityPlayer);
23
24                 int heightValue = par2World.getHeightValue((int) par3EntityPlayer.posX, (int) par3EntityPlayer.posZ);
25
26                 int result1 = MathHelperPlus.instance.Probability(99, 1);
27                 int result2 = MathHelperPlus.instance.Probability(78, 21, 1);
28                 int result3 = MathHelperPlus.instance.Probability(0.032, 0.0018, 0.000012, 0.00052);
29                 if (this.atomInfo.isOverY(heightValue)) {
30                         if (result1 == 0) {
31                                 if (result2 == 0) {
32                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 6), par3EntityPlayer);
33                                 } else if (result2 == 1) {
34                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 7), par3EntityPlayer);
35                                 } else {
36                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 17), par3EntityPlayer);
37                                 }
38                         } else {
39                                 if (result3 == 0) {
40                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 0), par3EntityPlayer);
41                                 } else if (result3 == 1) {
42                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 9), par3EntityPlayer);
43                                 } else if (result3 == 2) {
44                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 1), par3EntityPlayer);
45                                 } else {
46                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 1), par3EntityPlayer);
47                                 }
48                         }
49                 }
50                 if (par2World.isRemote) {
51                         par3EntityPlayer.addChatMessage("result1=" + result1 + " result2=" + result2 + " result3=" + result3);
52                 }
53                 return par1ItemStack;
54         }
55
56         public void isStackOrDrop(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer)
57         {
58                 if (!par2EntityPlayer.inventory.addItemStackToInventory(par1ItemStack)) {
59                         par2EntityPlayer.dropPlayerItem(par1ItemStack);
60                 }
61         }
62
63         @Override
64         public String getTextureFile()
65         {
66                 return "/chemicraft/items/items.png";
67         }
68
69 }