OSDN Git Service

ChemiCraft.java修正
[chemicraft/chemicraft.git] / common / chemicraft / item / ItemGasCollectingBottle.java
1 package 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 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                         par3EntityPlayer.addChatMessage("このメッセージは開発版のみの表示ですが、もし製品版で表示されていた場合はご連絡ください。");
60                 }
61
62                 return par1ItemStack;
63         }
64
65         protected void isStackOrDrop(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer)
66         {
67                 if (!par2EntityPlayer.inventory.addItemStackToInventory(par1ItemStack)) {
68                         par2EntityPlayer.dropPlayerItem(par1ItemStack);
69                 }
70         }
71
72         @Override
73         public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
74         {
75                 int blockID = par3World.getBlockId(par4, par5, par6);
76                 Block block = Block.blocksList[blockID];
77
78                 int uniqueBlockID = par3World.getBlockId(par4, par5 + 1, par6);
79                 Block uniqueBlock = Block.blocksList[uniqueBlockID];
80
81                 if (uniqueBlock instanceof BlockFire){
82                         par1ItemStack.damageItem(1, par2EntityPlayer);
83
84                         int result1 = MathHelperPlus.probability(90, 10);
85
86                         if (result1 == 0) {
87                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.getInstance().getCompound("CarbonDioxide")), par2EntityPlayer);
88                         } else {
89                                 this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.getInstance().getCompound("CarbonMonoxide")), par2EntityPlayer);
90                         }
91
92                         return true;
93                 }
94                 return false;
95         }
96
97         @Override
98         public String getTextureFile()
99         {
100                 return "/chemicraft/items/items.png";
101         }
102
103 }