OSDN Git Service

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