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