OSDN Git Service

修正・変更
[chemicraft/chemicraft.git] / common / pcc / chemicraft / item / ItemGasCollectingBottle.java
1 package pcc.chemicraft.item;
2
3 import net.minecraft.block.Block;
4 import net.minecraft.block.BlockFire;
5 import net.minecraft.entity.player.EntityPlayer;
6 import net.minecraft.item.ItemStack;
7 import net.minecraft.world.World;
8 import pcc.chemicraft.ChemiCraft;
9 import pcc.chemicraft.ChemiCraftAPI;
10 import pcc.chemicraft.ChemiCraftData;
11 import pcc.chemicraft.util.Auxiliary.Probability;
12
13 public class ItemGasCollectingBottle extends ItemAtomInfoContainer
14 {
15
16         public Probability probability = new Probability();
17
18         public ItemGasCollectingBottle(int id)
19         {
20                 super(id);
21                 this.setMaxStackSize(1);
22                 this.setMaxDamage(2);
23                 this.setCreativeTab(ChemiCraft.instance.creativeTabChemiCraft);
24         }
25
26         @Override
27         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
28         {
29                 par1ItemStack.damageItem(1, par3EntityPlayer);
30
31                 this.atomInfo.update(par2World, par3EntityPlayer);
32
33                 int heightValue = par2World.getHeightValue((int)par3EntityPlayer.posX, (int)par3EntityPlayer.posZ);
34
35                 int result = probability.getProbability(78.0D, 21.0D, 1.0D, 0.032D, 0.0018D, 0.000012D, 0.00052D, 0.000114D, 0.000087D);
36                 if (this.atomInfo.isOverY(heightValue)) {
37                         if (result == 0) {
38                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, ChemiCraftData.NITROGEN), par3EntityPlayer);
39                         } else if (result == 1) {
40                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, ChemiCraftData.OXYGEN), par3EntityPlayer);
41                         } else if (result == 2) {
42                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, ChemiCraftData.ARGON), par3EntityPlayer);
43                         } else if (result == 3) {
44                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance().getCompound("CarbonDioxide")), par3EntityPlayer);
45                         } else if (result == 4) {
46                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, ChemiCraftData.NEON), par3EntityPlayer);
47                         } else if (result == 5) {
48                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance().getCompound("CarbonMonoxide")), par3EntityPlayer);
49                         } else if (result == 6) {
50                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, ChemiCraftData.LITHIUM), par3EntityPlayer);
51                         } else if (result == 7) {
52                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, ChemiCraftData.KRYPTON), par3EntityPlayer);
53                         } else {
54                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, ChemiCraftData.XENON), par3EntityPlayer);
55                         }
56                 }
57
58                 return par1ItemStack;
59         }
60
61         protected void isStackOrDrop(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer)
62         {
63                 if (!par2EntityPlayer.inventory.addItemStackToInventory(par1ItemStack)) {
64                         par2EntityPlayer.dropPlayerItem(par1ItemStack);
65                 }
66         }
67
68         @Override
69         public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
70         {
71                 int blockID = par3World.getBlockId(par4, par5, par6);
72                 Block block = Block.blocksList[blockID];
73
74                 int uniqueBlockID = par3World.getBlockId(par4, par5 + 1, par6);
75                 Block uniqueBlock = Block.blocksList[uniqueBlockID];
76
77                 if (uniqueBlock instanceof BlockFire) {
78                         par1ItemStack.damageItem(1, par2EntityPlayer);
79
80                         int result1 = probability.getProbability(99, 1);
81
82                         if (result1 == 0) {
83                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance().getCompound("CarbonDioxide")), par2EntityPlayer);
84                         } else {
85                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance().getCompound("CarbonMonoxide")), par2EntityPlayer);
86                         }
87
88                         return true;
89                 }
90                 return false;
91         }
92
93         @Override
94         public String getTextureFile()
95         {
96                 return ChemiCraft.instance.ITEM_TEXTURE;
97         }
98
99 }