OSDN Git Service

素材製作台(減算処理・NBT処理抜き)を製作
authormozipi <mozipi@users.sourceforge.jp>
Sat, 29 Dec 2012 06:43:41 +0000 (15:43 +0900)
committermozipi <mozipi@users.sourceforge.jp>
Sat, 29 Dec 2012 06:43:41 +0000 (15:43 +0900)
common/chemicraft/ChemiCraft.java
common/chemicraft/container/ContainerChemicalCraftingTable.java
common/chemicraft/item/ItemAtomGrenade.java
common/chemicraft/system/ChemiCraftCraftingManager.java
common/chemicraft/tileentity/TileEntityChemicalCraftingTable.java
common/chemicraft/util/ComparatorItemStack.java [moved from common/chemicraft/util/ComparaterItemStackID.java with 63% similarity]
common/chemicraft/util/MaterialRecipe.java

index 0384d3f..991b668 100644 (file)
@@ -294,7 +294,7 @@ public class ChemiCraft {
                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.addSharplessMaterialRecipe(new ItemStack[]{new ItemStack(Item.gunpowder)}, new ItemStack(this.itemAtomGrenade, 16, 0), new NBTRecipeGrenade());\r
+               ChemiCraftAPI.instance.addMaterialRecipe(new ItemStack[]{new ItemStack(Item.gunpowder), new ItemStack(Block.stone)}, new ItemStack(this.itemAtomGrenade, 16, 0), new NBTRecipeGrenade());\r
 \r
        }\r
 \r
index 7ceb4e4..613614f 100644 (file)
@@ -13,6 +13,7 @@ import chemicraft.inventory.InventoryChemicalCraftingNBT;
 import chemicraft.inventory.InventoryChemicalCraftingResult;
 import chemicraft.slot.SlotChemicalCraftingResult;
 import chemicraft.tileentity.TileEntityChemicalCraftingTable;
+import chemicraft.util.ChemicalNBTRecipe;
 
 public class ContainerChemicalCraftingTable extends Container {
 
@@ -40,6 +41,8 @@ public class ContainerChemicalCraftingTable extends Container {
        private InventoryChemicalCraftingResult invr;
        private InventoryChemicalCraftingNBT invn;
 
+       private ChemicalNBTRecipe useNBT;
+
 
 
        public ContainerChemicalCraftingTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCraftingTable par2)
@@ -74,7 +77,7 @@ public class ContainerChemicalCraftingTable extends Container {
                this.invm.setEventHandler(this);
                this.invr.setEventHandler(this);
                this.invn.setEventHandler(this);
-
+               this.onCraftMatrixChanged(invm);
        }
 
 
index cc94898..4ea937d 100644 (file)
@@ -25,22 +25,23 @@ public class ItemAtomGrenade extends Item {
                boolean var2 = false;
                boolean var3 = false;
 
-               NBTTagList var4 = par1ItemStack.getTagCompound().getTagList("Effect");
+               if(par1ItemStack.stackTagCompound != null){
+                       NBTTagList var4 = par1ItemStack.getTagCompound().getTagList("Effect");
 
-               for(int i = 0;i < 3;i++){
-                       if(!((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("")){
-                               if(((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("Hydrogen")){
-                                       var1 = true;
-                               }
-                               if(((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("Carbon")){
-                                       var2 = true;
-                               }
-                               if(((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("Uranium")){
-                                       var3 = true;
+                       for(int i = 0;i < 3;i++){
+                               if(!((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("")){
+                                       if(((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("Hydrogen")){
+                                               var1 = true;
+                                       }
+                                       if(((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("Carbon")){
+                                               var2 = true;
+                                       }
+                                       if(((NBTTagCompound)var4.tagAt(0)).getString("GrenadeEffect" + i).equals("Uranium")){
+                                               var3 = true;
+                                       }
                                }
                        }
                }
-
                EntityAtomGrenade entity = new EntityAtomGrenade(par2World, par3EntityPlayer, var1, var2, var3);
                par2World.spawnEntityInWorld(entity);
                par1ItemStack.stackSize--;
index 6945d93..5ecf8c5 100644 (file)
@@ -11,6 +11,7 @@ import chemicraft.inventory.InventoryChemicalCraftingMaterial;
 import chemicraft.inventory.InventoryChemicalCraftingNBT;
 import chemicraft.inventory.InventoryChemicalCraftingResult;
 import chemicraft.inventory.InventoryDecomposition;
+import chemicraft.util.ChemicalNBTRecipe;
 
 public class ChemiCraftCraftingManager {
 
@@ -135,38 +136,24 @@ public class ChemiCraftCraftingManager {
 
 
 
-       public void chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
+       public ChemicalNBTRecipe chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
                ChemiCraftAPI api = ChemiCraftAPI.instance;
-               int[] materialID = new int[par1IInventory.getSizeInventory()];
-               int[] materialDamage = new int[par1IInventory.getSizeInventory()];
-               int[] resultID = new int[par2IInventory.getSizeInventory()];
-               int[] resultDamage = new int[par2IInventory.getSizeInventory()];
-               int[] nbtID = new int[par3IInventory.getSizeInventory()];
-               int[] nbtDamage = new int[par3IInventory.getSizeInventory()];
-               //ItemID,ItemDamageの格納
-               for(int j = 0;j < par1IInventory.getSizeInventory();j++){
-                       if(par1IInventory.getStackInSlot(j) != null){
-                               materialID[j] = par1IInventory.getStackInSlot(j).itemID;
-                               materialDamage[j] = par1IInventory.getStackInSlot(j).getItemDamage();
-                       }
-               }
-               for(int j = 0;j < par2IInventory.getSizeInventory();j++){
-                       if(par2IInventory.getStackInSlot(j) != null){
-                               resultID[j] = par2IInventory.getStackInSlot(j).itemID;
-                               resultDamage[j] = par2IInventory.getStackInSlot(j).getItemDamage();
-                       }
-               }
-               for(int j = 0;j < par3IInventory.getSizeInventory();j++){
-                       if(par3IInventory.getStackInSlot(j) != null){
-                               nbtID[j] = par3IInventory.getStackInSlot(j).itemID;
-                               nbtDamage[j] = par3IInventory.getStackInSlot(j).getItemDamage();
-                       }
-               }
-
+               ChemicalNBTRecipe returnObj = null;
                for(int i = 0;i < api.getMaterialRecipe().size();i++){
-                       api.getMaterialRecipe().get(i).match(par1IInventory);
+                       ItemStack result = api.getMaterialRecipe().get(i).match(par1IInventory);
+                       ItemStack resultArg = null;
+                       if(result != null){
+                               resultArg = new ItemStack(result.itemID, result.stackSize, result.getItemDamage());
+                               ItemStack[] nbtInv = new ItemStack[par3IInventory.getSizeInventory()];
+                               for(int j = 0;j < par3IInventory.getSizeInventory();j++){
+                                       nbtInv[j] = par3IInventory.getStackInSlot(j);
+                               }
+                               api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
+                               returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
+                       }
+                       par2IInventory.setInventorySlotContents(0, resultArg);
                }
-               return;
+               return returnObj;
        }
 
 
index 983205e..3f80541 100644 (file)
@@ -54,9 +54,9 @@ public class TileEntityChemicalCraftingTable extends TileEntity {
                        NBTTagCompound var4 = (NBTTagCompound)var6.tagAt(var7);
                        int var5 = var4.getByte("Slot2") & 255;
 
-                       if (var5 >= 0 && var5 < this.chemicalCraftingInvMaterial.getSizeInventory())
+                       if (var5 >= 0 && var5 < this.chemicalCraftingInvResult.getSizeInventory())
                        {
-                               this.chemicalCraftingInvMaterial.setInventorySlotContents(var5, ItemStack.loadItemStackFromNBT(var4));
+                               this.chemicalCraftingInvResult.setInventorySlotContents(var5, ItemStack.loadItemStackFromNBT(var4));
                        }
                }
 
@@ -5,12 +5,15 @@ import java.util.Comparator;
 import net.minecraft.src.ItemStack;
 
 
-public class ComparaterItemStackID implements Comparator {
+public class ComparatorItemStack implements Comparator {
 
        @Override
        public int compare(Object o1, Object o2) {
                ItemStack i1 = (ItemStack) o1;
                ItemStack i2 = (ItemStack) o2;
+               if(i1.itemID == i2.itemID){
+                       return i1.getItemDamage() > i2.getItemDamage() ? 1 : -1;
+               }
                return i1.itemID > i2.itemID ? 1 : -1;
        }
 
index 276f92d..6d26e7d 100644 (file)
@@ -1,9 +1,7 @@
 package chemicraft.util;
 
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 
 import net.minecraft.src.ItemStack;
 import chemicraft.ChemiCraft;
@@ -34,16 +32,56 @@ public class MaterialRecipe {
                invItems = (ItemStack[]) ChemiCraft.instance.arrayAuxiliary.deleteNull(invItems);
 
                if(isSharpless){
-                       Arrays.sort(invItems, new ComparaterItemStackID());
-
+                       Arrays.sort(invItems, new ComparatorItemStack());
+                       Arrays.sort(this.material, new ComparatorItemStack());
+                       if(invItems.length != this.material.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i].itemID != invItems[i].itemID) return null;
+                               if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                       }
+                       return this.result;
                }else{
-
+                       if(this.material.length != invItems.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i] == null && invItems[i] != null) return null;
+                               if(this.material[i] != null && invItems[i] == null) return null;
+                               if(this.material[i] != null && invItems[i] != null){
+                                       if(this.material[i].itemID != invItems[i].itemID) return null;
+                                       if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                               }
+                       }
+                       return this.result;
                }
-               return null;
        }
 
-       public ItemStack[] nbtMatch(InventoryChemicalCraftingNBT par1IInventory){
-               return null;
+       public ChemicalNBTRecipe nbtMatch(InventoryChemicalCraftingMaterial par1IInventory){
+               ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
+               ItemStack[] invItems;
+               for(int i = 0;i < par1IInventory.getSizeInventory();i++){
+                       invItemsArray.add(par1IInventory.getStackInSlot(i));
+               }
+               invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
+               invItems = (ItemStack[]) ChemiCraft.instance.arrayAuxiliary.deleteNull(invItems);
+
+               if(isSharpless){
+                       Arrays.sort(invItems, new ComparatorItemStack());
+                       Arrays.sort(this.material, new ComparatorItemStack());
+                       if(invItems.length != this.material.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i].itemID != invItems[i].itemID) return null;
+                               if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                       }
+                       return this.nbtRecipe;
+               }else{
+                       if(this.material.length != invItems.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i] != null && invItems[i] != null){
+                                       if(this.material[i].itemID != invItems[i].itemID) return null;
+                                       if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                               }
+                       }
+                       return this.nbtRecipe;
+               }
        }
 
 }