OSDN Git Service

分解レシピの修正
authormozipi <mozipi@users.sourceforge.jp>
Thu, 20 Dec 2012 10:14:13 +0000 (19:14 +0900)
committermozipi <mozipi@users.sourceforge.jp>
Thu, 20 Dec 2012 10:14:13 +0000 (19:14 +0900)
化合レシピの実装
化合レシピは
ChemiCraftAPI.instance.addChemicalCombinationRecipe(ItemStack[] materials, ItemStack result);

不定形です

common/chemicraft/ChemiCraft.java
common/chemicraft/ChemiCraftCraftingManager.java
common/chemicraft/ContainerChemicalCombinationTable.java
common/chemicraft/InventoryChemicalCombination.java
common/chemicraft/TileEntityChemicalCombinationTable.java

index 2b3e8f8..19971f7 100644 (file)
@@ -207,7 +207,12 @@ public class ChemiCraft {
                NetworkRegistry.instance().registerGuiHandler(instance, proxy);\r
 \r
                //分解レシピを追加します\r
-               ChemiCraftAPI.instance.addDecompositionRecipe(new ItemStack(Block.dirt, 1, 0), new ItemStack[]{new ItemStack(Block.stone, 16, 0)});\r
+               ChemiCraftAPI.instance.addDecompositionRecipe(new ItemStack(Block.dirt, 1, 0), new ItemStack[]{new ItemStack(Block.stone, 16, 0),new ItemStack(Block.dispenser)});\r
+               ChemiCraftAPI.instance.addDecompositionRecipe(new ItemStack(Block.stone, 1, 0), new ItemStack[]{new ItemStack(Block.stone, 16, 0)});\r
+\r
+               //化合レシピを追加します\r
+               ChemiCraftAPI.instance.addChemicalCombinationRecipe(new ItemStack[]{new ItemStack(Block.dirt), new ItemStack(Block.stone)}, new ItemStack(Block.stone));\r
+               ChemiCraftAPI.instance.addChemicalCombinationRecipe(new ItemStack[]{new ItemStack(Block.stone)}, new ItemStack(Block.dirt));\r
 \r
                //Textureをpreloadします\r
                proxy.registerTextures();\r
index d70f203..7ea81cc 100644 (file)
@@ -1,6 +1,7 @@
 package chemicraft;
 
 import java.util.ArrayList;
+import java.util.Collections;
 
 import net.minecraft.src.IInventory;
 import net.minecraft.src.ItemStack;
@@ -11,6 +12,7 @@ public class ChemiCraftCraftingManager {
                ((InventoryDecomposition)par1IInventory).setFlag(false);
                ItemStack[] results = null;
                for(int i1 = 0;i1 < ChemiCraftAPI.instance.getDecompositionMaterial().size();i1++){
+                       boolean match = true;
                        ArrayList<Integer> materialID = new ArrayList<Integer>();
                        ArrayList<Integer> materialDamage = new ArrayList<Integer>();
                        results  = new ItemStack[ChemiCraftAPI.instance.getDecompositionResult().get(i1).length];
@@ -18,19 +20,70 @@ public class ChemiCraftCraftingManager {
                        materialID.add(ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).itemID);
                        materialDamage.add(ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).getItemDamage());
                        if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
-                       if(materialID.get(0) != par1IInventory.getStackInSlot(16).itemID){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
-                       if(materialDamage.get(0) != par1IInventory.getStackInSlot(16).getItemDamage()){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
+                       if(materialID.get(0) != par1IInventory.getStackInSlot(16).itemID){ match = false;}
+                       if(materialDamage.get(0) != par1IInventory.getStackInSlot(16).getItemDamage()){ match = false;}
 
-                       for(int i = 0;i < ChemiCraftAPI.instance.getDecompositionResult().get(i1).length;i++){
+                       if(match){
+                               for(int i = 0;i < ChemiCraftAPI.instance.getDecompositionResult().get(i1).length;i++){
+                                       results[i] = new ItemStack(
+                                                       ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].itemID,
+                                                       ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].stackSize,
+                                                       ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].getItemDamage()
+                                                       );
+                               }
+                               return results;
+                       }
+               }
+               return null;
+       }
+
+
+
+       public ItemStack getChemicalCombinationResult(IInventory par1IInventory){
+               ((InventoryChemicalCombination) par1IInventory).setFlag(false);
+               ItemStack result = null;
+               for(int i = 0;i < ChemiCraftAPI.instance.getChemicalCombinationMaterial().size();i++){
+                       boolean match = true;
+                       ArrayList<Integer> materialID = new ArrayList<Integer>();
+                       ArrayList<Integer> materialDamage = new ArrayList<Integer>();
+                       ArrayList<Integer> recipeID = new ArrayList<Integer>();
+                       ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
+                       for(int j = 0;j < ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i).length;j++){
+                               materialID.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].itemID);
+                               materialDamage.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].getItemDamage());
+                       }
+                       for(int j = 0;j < 16;j++){
+                               if(par1IInventory.getStackInSlot(j) != null){
+                                       recipeID.add(par1IInventory.getStackInSlot(j).itemID);
+                                       recipeDamage.add(par1IInventory.getStackInSlot(j).getItemDamage());
+                               }
+                       }
+                       materialID.trimToSize();
+                       materialDamage.trimToSize();
+                       recipeID.trimToSize();
+                       recipeDamage.trimToSize();
+                       Collections.sort(materialID);
+                       Collections.sort(materialDamage);
+                       Collections.sort(recipeID);
+                       Collections.sort(recipeDamage);
+                       if(materialID.size() != recipeID.size()){ match = false;}
+                       for(int j = 0;j < materialID.size();j++){
+                               if(recipeID.size() <= j){match = false; break;}
+                               if(materialID.get(j) != recipeID.get(j)){ match = false;}
+                               if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
+                       }
 
-                               results[i] = new ItemStack(
-                                               ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].itemID,
-                                               ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].stackSize,
-                                               ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].getItemDamage()
-                                               );
+                       if(match){
+                               result =
+                                               new ItemStack(
+                                                               ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).itemID,
+                                                               ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).stackSize,
+                                                               ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).getItemDamage()
+                                                               );
+                               return result;
                        }
                }
-               return results;
+               return null;
        }
 
 
index 6c1ddfc..bfbde2a 100644 (file)
@@ -29,6 +29,12 @@ public class ContainerChemicalCombinationTable extends Container {
        private TileEntityChemicalCombinationTable tileEntity;
 
 
+       /**
+        * the inventory.
+        */
+       private IInventory inv;
+
+
 
        public ContainerChemicalCombinationTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCombinationTable par2)
        {
@@ -38,6 +44,7 @@ public class ContainerChemicalCombinationTable extends Container {
                this.posY = par2.yCoord;
                this.posZ = par2.zCoord;
                this.tileEntity = par2;
+               this.inv = par2.getInventorys();
                //GenerateInventory
                this.generateSlots("ChemicalCombination", par2.getInventorys());
                //GeneratePlayerInventory
@@ -55,12 +62,18 @@ public class ContainerChemicalCombinationTable extends Container {
                {
                        this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var3, 8 + var3 * 18, 143));
                }
+
+               this.tileEntity.getInventorys().setEventHandler(this);
+
        }
 
 
 
        @Override
-       public void onCraftMatrixChanged(IInventory par1IInventory){}
+       public void onCraftMatrixChanged(IInventory par1IInventory){
+               this.putStackInSlot(16, ChemiCraftAPI.instance.getCraftingManager().getChemicalCombinationResult(par1IInventory));
+               ((InventoryChemicalCombination) par1IInventory).setFlag(true);
+       }
 
 
 
@@ -85,14 +98,14 @@ public class ContainerChemicalCombinationTable extends Container {
 
 
 
-       private void generateSlots(String activeTabs, IInventory[] inventorys){
+       private void generateSlots(String activeTabs, IInventory inventorys){
                int count = 0;
                for(int i = 0;i < 4;i++){
                        for(int j = 0;j < 4;j++){
-                               this.addSlotToContainer(new Slot(inventorys[0], count, 16 + 18 * j, 8 + 18 * i));
+                               this.addSlotToContainer(new Slot(inventorys, count, 16 + 18 * j, 8 + 18 * i));
                                count++;
                        }
                }
-               this.addSlotToContainer(new SlotChemicalCombinationResult(inventorys[0], count, 123, 33));
+               this.addSlotToContainer(new SlotChemicalCombinationResult(inventorys, count, 123, 33));
        }
 }
index 8dfd3cd..b0b1c44 100644 (file)
@@ -1,5 +1,6 @@
 package chemicraft;
 
+import net.minecraft.src.Container;
 import net.minecraft.src.EntityPlayer;
 import net.minecraft.src.IInventory;
 import net.minecraft.src.ItemStack;
@@ -8,6 +9,19 @@ public class InventoryChemicalCombination implements IInventory {
 
        private ItemStack[] inventory = new ItemStack[16+1];
 
+       private Container eventHandler;
+
+       private boolean flag;
+
+       public void setEventHandler(Container par1Container){
+               this.eventHandler = par1Container;
+               this.flag = true;
+       }
+
+       public void setFlag(boolean par1){
+               this.flag = par1;
+       }
+
        @Override
        public int getSizeInventory() {
                return inventory.length;
@@ -65,7 +79,9 @@ public class InventoryChemicalCombination implements IInventory {
 
        @Override
        public void onInventoryChanged() {
-
+               if(flag){
+                       this.eventHandler.onCraftMatrixChanged(this);
+               }
        }
 
        @Override
index 38bc5f1..39e84c1 100644 (file)
@@ -67,10 +67,8 @@ public class TileEntityChemicalCombinationTable extends TileEntity {
        }
 
 
-       public IInventory[] getInventorys(){
-               ArrayList<IInventory> inventorys = new ArrayList<IInventory>();
-               inventorys.add(this.chemicalCombinationInv);
-               return inventorys.toArray(new IInventory[1]);
+       public InventoryChemicalCombination getInventorys(){
+               return (InventoryChemicalCombination) this.chemicalCombinationInv;
        }