OSDN Git Service

ChemiCraftAPI.instance.getCompound(String)でダメージ値が返ってくるようにした。(…多分w)
authorponkotate <ponkotate@users.sourceforge.jp>
Tue, 1 Jan 2013 09:13:52 +0000 (18:13 +0900)
committerponkotate <ponkotate@users.sourceforge.jp>
Tue, 1 Jan 2013 09:13:52 +0000 (18:13 +0900)
common/chemicraft/ChemiCraftAPI.java
common/chemicraft/item/ItemGasCollectingBottle.java
common/chemicraft/util/MathHelperPlus.java

index 6499720..2a826e8 100644 (file)
@@ -1,6 +1,7 @@
 package chemicraft;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 
 import net.minecraft.src.ItemStack;
 import chemicraft.system.ChemiCraftCraftingManager;
@@ -47,6 +48,12 @@ public class ChemiCraftAPI {
 
 
        /**
+        * 化合物の文字列をダメージ値に変換します。
+        */
+       private HashMap<String, Integer> compoundHash = new HashMap<String, Integer>();
+
+
+       /**
         * List of item name of handler to compounds.
         */
        private ArrayList<String> compoundHandlerItemNames = new ArrayList<String>();
@@ -118,6 +125,7 @@ public class ChemiCraftAPI {
        public int getDamageByName(String englishName){
                for(int i = 0;i < compoundsNameList.size();i++){
                        if(englishName.equals(compoundsNameList.get(i))){
+                               compoundHash.put(englishName, i);
                                return i;
                        }
                }
@@ -126,6 +134,16 @@ public class ChemiCraftAPI {
 
 
 
+       public int getCompound(String key){
+               if(compoundHash.get(key) != null){
+                       return compoundHash.get(key);
+               } else {
+                       return -1;
+               }
+       }
+
+
+
        /**
         * setting compound handler.
         * @param handlerItemName
index 83119a8..73e408a 100644 (file)
@@ -1,9 +1,12 @@
 package chemicraft.item;
 
+import net.minecraft.src.Block;
+import net.minecraft.src.BlockFire;
 import net.minecraft.src.EntityPlayer;
 import net.minecraft.src.ItemStack;
 import net.minecraft.src.World;
 import chemicraft.ChemiCraft;
+import chemicraft.ChemiCraftAPI;
 import chemicraft.util.MathHelperPlus;
 
 public class ItemGasCollectingBottle extends ItemAtomInfoContainer
@@ -39,7 +42,7 @@ public class ItemGasCollectingBottle extends ItemAtomInfoContainer
                                }
                        } else {
                                if (result3 == 0) {
-                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 0), par3EntityPlayer);
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance.getCompound("CarbonDioxide")), par3EntityPlayer);
                                } else if (result3 == 1) {
                                        this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 9), par3EntityPlayer);
                                } else if (result3 == 2) {
@@ -49,9 +52,12 @@ public class ItemGasCollectingBottle extends ItemAtomInfoContainer
                                }
                        }
                }
+
+               // デバッグ用
                if (par2World.isRemote) {
                        par3EntityPlayer.addChatMessage("result1=" + result1 + " result2=" + result2 + " result3=" + result3);
                }
+
                return par1ItemStack;
        }
 
@@ -63,6 +69,28 @@ public class ItemGasCollectingBottle extends ItemAtomInfoContainer
        }
 
        @Override
+       public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
+       {
+               int var11 = par3World.getBlockId(par4, par5, par6);
+               Block block = Block.blocksList[var11];
+
+               if (block instanceof BlockFire){
+                       par1ItemStack.damageItem(1, par2EntityPlayer);
+
+                       int result1 = MathHelperPlus.probability(99, 1);
+
+                       if (result1 == 0) {
+                               this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, ChemiCraftAPI.instance.getCompound("CarbonDioxide")), par2EntityPlayer);
+                       } else {
+                               this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 17), par2EntityPlayer);
+                       }
+
+                       return true;
+               }
+               return false;
+       }
+
+       @Override
        public String getTextureFile()
        {
                return "/chemicraft/items/items.png";
index 96cff62..a4fbb2b 100644 (file)
@@ -41,7 +41,7 @@ public class MathHelperPlus
                                var8 += var6.get(var9);
                        }
                }
-               return var3;
+               return -1;
        }
 
 }