OSDN Git Service

Merge branch 'master' of https://scm.sourceforge.jp/gitroot/chemicraft/chemicraft
[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 <<<<<<< HEAD:common/pcc/chemicraft/item/ItemGasCollectingBottle.java
11 import pcc.chemicraft.util.Auxiliary.Probability;
12 =======
13 import pcc.chemicraft.util.MathHelperPlus;
14 >>>>>>> a5e4a5c40b9001657f1e36ece533651f63183fbe:common/pcc/chemicraft/item/ItemGasCollectingBottle.java
15
16 public class ItemGasCollectingBottle extends ItemAtomInfoContainer
17 {
18
19         public Probability probability = new Probability();
20
21         public ItemGasCollectingBottle(int id) {
22                 super(id);
23                 this.setMaxStackSize(1);
24                 this.setMaxDamage(2);
25                 this.setCreativeTab(ChemiCraft.instance.creativeTab);
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 result1 = probability.getProbability(99.0D, 1.0D);
38                 int result2 = probability.getProbability(78.0D, 21.0D, 1.0D);
39                 int result3 = probability.getProbability(0.032D, 0.0018D, 0.000012D, 0.00052D);
40                 if (this.atomInfo.isOverY(heightValue)) {
41                         if (result1 == 0) {
42                                 if (result2 == 0) {
43                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 6), par3EntityPlayer);
44                                 } else if (result2 == 1) {
45                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 7), par3EntityPlayer);
46                                 } else {
47                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 17), par3EntityPlayer);
48                                 }
49                         } else {
50                                 if (result3 == 0) {
51                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance().getCompound("CarbonDioxide")), par3EntityPlayer);
52                                 } else if (result3 == 1) {
53                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 9), par3EntityPlayer);
54                                 } else if (result3 == 2) {
55                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 1), par3EntityPlayer);
56                                 } else {
57                                         this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 1), par3EntityPlayer);
58                                 }
59                         }
60                 }
61
62                 // デバッグ用
63                 if (par2World.isRemote) {
64                         par3EntityPlayer.addChatMessage("result1=" + result1 + " result2=" + result2 + " result3=" + result3);
65                 }
66
67                 return par1ItemStack;
68         }
69
70         protected void isStackOrDrop(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer)
71         {
72                 if (!par2EntityPlayer.inventory.addItemStackToInventory(par1ItemStack)) {
73                         par2EntityPlayer.dropPlayerItem(par1ItemStack);
74                 }
75         }
76
77         @Override
78         public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
79         {
80                 int blockID = par3World.getBlockId(par4, par5, par6);
81                 Block block = Block.blocksList[blockID];
82
83                 int uniqueBlockID = par3World.getBlockId(par4, par5 + 1, par6);
84                 Block uniqueBlock = Block.blocksList[uniqueBlockID];
85
86                 if (uniqueBlock instanceof BlockFire){
87                         par1ItemStack.damageItem(1, par2EntityPlayer);
88
89                         int result1 = probability.getProbability(99, 1);
90
91                         if (result1 == 0) {
92                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance().getCompound("CarbonDioxide")), par2EntityPlayer);
93                         } else {
94                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance().getCompound("CarbonMonoxide")), par2EntityPlayer);
95                         }
96
97                         return true;
98                 }
99                 return false;
100         }
101
102         @Override
103         public String getTextureFile()
104         {
105                 return "/chemicraft/items/items.png";
106         }
107
108 }