OSDN Git Service

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