OSDN Git Service

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