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
package chemicraft;
import java.util.ArrayList;
+import java.util.Collections;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
((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];
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;
}
private TileEntityChemicalCombinationTable tileEntity;
+ /**
+ * the inventory.
+ */
+ private IInventory inv;
+
+
public ContainerChemicalCombinationTable(EntityPlayer par1EntityPlayer, TileEntityChemicalCombinationTable par2)
{
this.posY = par2.yCoord;
this.posZ = par2.zCoord;
this.tileEntity = par2;
+ this.inv = par2.getInventorys();
//GenerateInventory
this.generateSlots("ChemicalCombination", par2.getInventorys());
//GeneratePlayerInventory
{
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);
+ }
- 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));
}
}