OSDN Git Service

Merge branch 'master' of https://scm.sourceforge.jp/gitroot/chemicraft/chemicraft
authorponkotate <ponkotate@users.sourceforge.jp>
Sat, 29 Dec 2012 02:55:38 +0000 (11:55 +0900)
committerponkotate <ponkotate@users.sourceforge.jp>
Sat, 29 Dec 2012 02:55:38 +0000 (11:55 +0900)
common/chemicraft/ChemiCraft.java
common/chemicraft/MathHelperPlus.java [new file with mode: 0644]
common/chemicraft/item/ItemGasCollectingBottle.java
common/chemicraft/util/AtomInfo.java

index 72b39b2..5b6adbb 100644 (file)
@@ -282,6 +282,12 @@ public class ChemiCraft {
                        new Character('A'), new ItemStack(this.itemAtoms, 1, 0),\r
                });\r
 \r
+               // 化合物を追加します\r
+               ChemiCraftAPI.instance.addLangCompound("ja_JP", "CarbonDioxide", "二酸化炭素");\r
+\r
+               // 化合物のレシピを追加します\r
+               ChemiCraftAPI.instance.addChemicalCombinationRecipe(new ItemStack[]{new ItemStack(this.itemAtoms, 5), new ItemStack(this.itemAtoms, 7)}, new ItemStack(this.itemCompounds, 0));\r
+\r
                //手榴弾の追加\r
                ChemiCraftAPI.instance.addMaterialRecipe(new ItemStack[]{new ItemStack(Item.gunpowder)}, new ItemStack(this.itemAtomGrenade, 16, 0), new NBTRecipeGrenade());\r
 \r
diff --git a/common/chemicraft/MathHelperPlus.java b/common/chemicraft/MathHelperPlus.java
new file mode 100644 (file)
index 0000000..8d85be2
--- /dev/null
@@ -0,0 +1,58 @@
+package chemicraft;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+public class MathHelperPlus
+{
+
+       public static MathHelperPlus instance = new MathHelperPlus();
+
+       /** 
+        * Return probability(0~).
+        */
+       public static int Probability(double... par1)
+       {
+               ArrayList<Double> var1 = new ArrayList<Double>();
+               for (int var2 = 0; var2 < par1.length; var2++){
+                       var1.add(par1[var2]);
+               }
+               return Probability(var1);
+       }
+
+       public static int Probability(int... par1)
+       {
+               ArrayList<Double> var1 = new ArrayList<Double>();
+               for (int var2 = 0; var2 < par1.length; var2++){
+                       var1.add((double)par1[var2]);
+               }
+               return Probability(var1);
+       }
+
+       public static int Probability(ArrayList<Double> par1)
+       {
+               Random var2 = new Random();
+               int var3 = var2.nextInt(100);
+               double var4 = 0.0D;
+
+               for (int var5 = 0; var5 < par1.size(); var5++) {
+                       var4 += par1.get(var5);
+               }
+
+               ArrayList<Double> var6 = new ArrayList<Double>();
+               for (int var7 = 0; var7 < par1.size(); var7++) {
+                       var6.add(par1.get(var7) / var4 * 100);
+               }
+
+               double var8 = 0.0D;
+               for (int var9 = 0; var9 < var6.size(); var9++) {
+                       if (var3 < var6.get(var9) + var8) {
+                               return var9;
+                       } else {
+                               var8 += var6.get(var9);
+                       }
+               }
+               return var3;
+       }
+
+}
index 9a0906e..b5b7836 100644 (file)
@@ -5,7 +5,8 @@ import net.minecraft.src.ItemStack;
 import net.minecraft.src.World;
 import chemicraft.ChemiCraft;
 
-public class ItemGasCollectingBottle extends ItemAtomInfoContainer {
+public class ItemGasCollectingBottle extends ItemAtomInfoContainer
+{
 
        public ItemGasCollectingBottle(int id) {
                super(id);
@@ -15,22 +16,54 @@ public class ItemGasCollectingBottle extends ItemAtomInfoContainer {
        }
 
        @Override
-       public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){
+       public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
+       {
                par1ItemStack.damageItem(1, par3EntityPlayer);
 
                this.atomInfo.update(par2World, par3EntityPlayer);
-               if(this.atomInfo.isBelowY(129)){
-            if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 7)))
-            {
-                par3EntityPlayer.dropPlayerItem(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 7));
-            }
-               }
 
+               int heightValue = par2World.getHeightValue((int) par3EntityPlayer.posX, (int) par3EntityPlayer.posZ);
+
+               int result1 = MathHelperPlus.instance.Probability(99, 1);
+               int result2 = MathHelperPlus.instance.Probability(78, 21, 1);
+               int result3 = MathHelperPlus.instance.Probability(0.032, 0.0018, 0.000012, 0.00052);
+               if (this.atomInfo.isOverY(heightValue)) {
+                       if (result1 == 0) {
+                               if (result2 == 0) {
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 6), par3EntityPlayer);
+                               } else if (result2 == 1) {
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 7), par3EntityPlayer);
+                               } else {
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 17), par3EntityPlayer);
+                               }
+                       } else {
+                               if (result3 == 0) {
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 0), par3EntityPlayer);
+                               } else if (result3 == 1) {
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 9), par3EntityPlayer);
+                               } else if (result3 == 2) {
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemCompounds, 1, 1), par3EntityPlayer);
+                               } else {
+                                       this.isStackOrDrop(new ItemStack(ChemiCraft.instance.itemAtoms, 1, 1), par3EntityPlayer);
+                               }
+                       }
+               }
+               if (par2World.isRemote) {
+                       par3EntityPlayer.addChatMessage("result1=" + result1 + " result2=" + result2 + " result3=" + result3);
+               }
                return par1ItemStack;
        }
 
+       public void isStackOrDrop(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer)
+       {
+               if (!par2EntityPlayer.inventory.addItemStackToInventory(par1ItemStack)) {
+                       par2EntityPlayer.dropPlayerItem(par1ItemStack);
+               }
+       }
+
        @Override
-       public String getTextureFile() {
+       public String getTextureFile()
+       {
                return "/chemicraft/items/items.png";
        }
 
index 89b99fc..2473ff9 100644 (file)
@@ -1,5 +1,7 @@
 package chemicraft.util;\r
 \r
+import cpw.mods.fml.common.Side;\r
+import cpw.mods.fml.common.asm.SideOnly;\r
 import net.minecraft.src.EntityPlayer;\r
 import net.minecraft.src.World;\r
 \r
@@ -116,6 +118,7 @@ public class AtomInfo {
         * @param par1\r
         * @return 指定されたY軸より高いか\r
         */\r
+       @SideOnly(Side.CLIENT)\r
        public boolean isOverY(int par1){\r
                if(this.posY >= par1){\r
                        return true;\r
@@ -131,6 +134,7 @@ public class AtomInfo {
         * @param par1\r
         * @return 指定されたY軸と同等かどうか\r
         */\r
+       @SideOnly(Side.CLIENT)\r
        public boolean isEquivalentY(int par1){\r
                if(this.posY == par1){\r
                        return true;\r
@@ -146,6 +150,7 @@ public class AtomInfo {
         * @param par1\r
         * @return 指定されたY軸より低いか\r
         */\r
+       @SideOnly(Side.CLIENT)\r
        public boolean isBelowY(int par1){\r
                if(this.posY <= par1){\r
                        return true;\r