OSDN Git Service

素材製作台のレシピ実装
authormozipi <mozipi@users.sourceforge.jp>
Sat, 22 Dec 2012 05:40:50 +0000 (14:40 +0900)
committermozipi <mozipi@users.sourceforge.jp>
Sat, 22 Dec 2012 05:40:50 +0000 (14:40 +0900)
疲れた。

common/chemicraft/ChemiCraft.java
common/chemicraft/ChemiCraftAPI.java
common/chemicraft/ChemiCraftCraftingManager.java
common/chemicraft/ContainerChemicalCombinationTable.java
common/chemicraft/ContainerMaterialCraftingTable.java
common/chemicraft/InventoryMaterialCrafting.java
common/chemicraft/NBTRecipe.java [new file with mode: 0644]
common/chemicraft/NBTRecipeGrenade.java [new file with mode: 0644]
common/chemicraft/TileEntityMaterialCraftingTable.java

index 087a68f..416eba4 100644 (file)
@@ -208,6 +208,19 @@ public class ChemiCraft {
                //Textureをpreloadします\r
                proxy.registerTextures();\r
 \r
+               ChemiCraftAPI.instance.addChemicalCombinationRecipe(new ItemStack[]{new ItemStack(Block.stone)}, new ItemStack(Block.dirt));\r
+\r
+               ChemiCraftAPI.instance.addMaterialRecipe(new ItemStack[]{new ItemStack(Block.dirt)}, new ItemStack(Block.stone), new NBTRecipeGrenade());\r
+\r
        }\r
 \r
+       public final static int HYDROGEN = 0;\r
+       public final static int HELIUM = 1;\r
+       public final static int LITHIUM = 2;\r
+       public final static int BERYLLIUM = 3;\r
+       public final static int BORON = 4;\r
+       public final static int CARBON = 5;\r
+       public final static int NITROGEN = 6;\r
+       public final static int URANIUM = 92;\r
+\r
 }
\ No newline at end of file
index 8111626..246ce1c 100644 (file)
@@ -95,16 +95,9 @@ public class ChemiCraftAPI {
 
 
        /**
-        * 素材製作台の効果のキーリスト
+        * 素材製作台の効果付属用のNBTRecipeのリスト
         */
-       private ArrayList<String[]> materialEffectKey = new ArrayList<String[]>();
-
-
-
-       /**
-        * 素材製作台の効果のリスト
-        */
-       private ArrayList<Object[]> materialEffectValue = new ArrayList<Object[]>();
+       private ArrayList<NBTRecipe> materialNBT = new ArrayList<NBTRecipe>();
 
 
 
@@ -185,18 +178,13 @@ public class ChemiCraftAPI {
 
 
 
-       public void addMaterialRecipe(ItemStack[] materials, ItemStack[] effectMaterials,ItemStack result, String[] key, Object[] value){
+       public void addMaterialRecipe(ItemStack[] materials, ItemStack result, NBTRecipe nbtRecipe){
                if(materials.length <= 9){
-                       if(effectMaterials.length <= 3){
-                               materialMaterials.add(materials);
-                               materialResult.add(result);
-                               materialEffectKey.add(key);
-                               materialEffectValue.add(value);
-                       }else{
-                               System.err.println("ChemiCraft内でエラー:addMaterialRecipeの引数effectMaterialsの要素数が3を超えています。" + "Material:" + materials + " Result:" + result + " key" + key + " value:" + value);
-                       }
+                       materialMaterials.add(materials);
+                       materialResult.add(result);
+                       materialNBT.add(nbtRecipe);
                }else{
-                       System.err.println("ChemiCraft内でエラー:addMaterialRecipeの引数materialsの要素数が9を超えています。" + "Material:" + materials + " Result:" + result + " key" + key + " value:" + value);
+                       System.err.println("ChemiCraft内でエラー:addMaterialRecipeの引数materialsの要素数が9を超えています。" + "Material:" + materials + " Result:" + result);
                }
        }
        //以下システム関連//////////////////////////////////////////////////////
@@ -261,6 +249,24 @@ public class ChemiCraftAPI {
 
 
 
+       public ArrayList<ItemStack[]> getMaterialMaterials(){
+               return materialMaterials;
+       }
+
+
+
+       public ArrayList<ItemStack> getMaterialResult(){
+               return materialResult;
+       }
+
+
+
+       public ArrayList<NBTRecipe> getMaterialNBTRecipe(){
+               return materialNBT;
+       }
+
+
+
        public ChemiCraftCraftingManager getCraftingManager(){
                return chemiCraftCraftingManager;
        }
index d7d0e30..2503469 100644 (file)
@@ -129,6 +129,89 @@ public class ChemiCraftCraftingManager {
 
 
 
+       public ItemStack getMaterialResult(IInventory par1IInventory){
+               ((InventoryMaterialCrafting) par1IInventory).setFlag(false);
+
+               ItemStack result = null;
+
+               for(int i = 0;i < ChemiCraftAPI.instance.getMaterialMaterials().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>();
+                       ArrayList<ItemStack> effectMaterial = new ArrayList<ItemStack>();
+
+                       //Just loop of recipe size of recipe index i.
+                       for(int j = 0;j < ChemiCraftAPI.instance.getMaterialMaterials().get(i).length;j++){
+                               //Adding the recipe ID & Damage.
+                               recipeID.add(ChemiCraftAPI.instance.getMaterialMaterials().get(i)[j].itemID);
+                               recipeDamage.add(ChemiCraftAPI.instance.getMaterialMaterials().get(i)[j].getItemDamage());
+                       }
+                       //Just loop of 9.
+                       for(int j = 0;j < 9;j++){
+                               //Null check
+                               if(par1IInventory.getStackInSlot(j+3) != null){
+                                       //Adding the materialID & Damage.
+                                       materialID.add(par1IInventory.getStackInSlot(j+3).itemID);
+                                       materialDamage.add(par1IInventory.getStackInSlot(j+3).getItemDamage());
+                               }
+                       }
+
+                       for(int j = 0;j < 3;j++){
+                               if(par1IInventory.getStackInSlot(j) != null){
+                                       effectMaterial.add(par1IInventory.getStackInSlot(j));
+                               }
+                       }
+
+                       //trimToSize & sorting.
+                       materialID.trimToSize();
+                       materialDamage.trimToSize();
+                       recipeID.trimToSize();
+                       recipeDamage.trimToSize();
+                       effectMaterial.trimToSize();
+                       Collections.sort(materialID);
+                       Collections.sort(materialDamage);
+                       Collections.sort(recipeID);
+                       Collections.sort(recipeDamage);
+
+                       //Size check.
+                       if(materialID.size() != recipeID.size()){ match = false;}
+                       //Just loop of materialID.size().
+                       for(int j = 0;j < materialID.size();j++){
+                               //ID check.
+                               if(materialID.get(j) != recipeID.get(j)){ match = false;}
+                               //Damage check.
+                               if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
+                       }
+
+                       //if "match == true"
+                       if(match){
+                               //Assignment to the result.
+                               result =
+                                               new ItemStack(
+                                                               ChemiCraftAPI.instance.getMaterialResult().get(i).itemID,
+                                                               ChemiCraftAPI.instance.getMaterialResult().get(i).stackSize,
+                                                               ChemiCraftAPI.instance.getMaterialResult().get(i).getItemDamage()
+                                                               );
+
+                               ItemStack[] useItems = ChemiCraftAPI.instance.getMaterialNBTRecipe().get(i).setNBT(effectMaterial.toArray(new ItemStack[3]), result);
+
+                               ((InventoryMaterialCrafting) par1IInventory).subtractStack(0, 3, useItems);
+
+                               ((InventoryMaterialCrafting) par1IInventory).setFlag2(false);
+
+                               //return the result.
+                               return result;
+                       }
+               }
+
+               return null;
+       }
+
+
+
        private void clearResults(IInventory par1IInventory, int par2){
                ((InventoryDecomposition)par1IInventory).setFlag(false);
                for(int i = 0;i < par2;i++){
index bfbde2a..379d35a 100644 (file)
@@ -96,6 +96,24 @@ public class ContainerChemicalCombinationTable extends Container {
                return null;
        }
 
+       @Override
+       public ItemStack slotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer)
+       {
+               super.slotClick(par1, par2, par3, par4EntityPlayer);
+               if(par1 == 16){
+                       for(int i = 0;i < 16;i++){
+                               if(this.inv.getStackInSlot(i) != null){
+                                       if(this.inv.getStackInSlot(i).stackSize >= 1){
+                                               this.putStackInSlot(i, new ItemStack(this.inv.getStackInSlot(i).itemID, --this.inv.getStackInSlot(i).stackSize, this.inv.getStackInSlot(i).getItemDamage()));
+                                       }else{
+                                               this.putStackInSlot(i, null);
+                                       }
+                               }
+                       }
+               }
+               return null;
+       }
+
 
 
        private void generateSlots(String activeTabs, IInventory inventorys){
index 35a4ce7..3163827 100644 (file)
@@ -29,6 +29,9 @@ public class ContainerMaterialCraftingTable extends Container {
        private TileEntityMaterialCraftingTable tileEntity;
 
 
+       private InventoryMaterialCrafting inv;
+
+
 
        public ContainerMaterialCraftingTable(EntityPlayer par1EntityPlayer, TileEntityMaterialCraftingTable par2)
        {
@@ -38,6 +41,7 @@ public class ContainerMaterialCraftingTable extends Container {
                this.posY = par2.yCoord;
                this.posZ = par2.zCoord;
                this.tileEntity = par2;
+               this.inv = (InventoryMaterialCrafting) par2.getInventorys();
                //GenerateInventory
                this.generateSlots("Decomposition", par2.getInventorys());
                //GeneratePlayerInventory
@@ -55,12 +59,39 @@ public class ContainerMaterialCraftingTable extends Container {
                {
                        this.addSlotToContainer(new Slot(par1EntityPlayer.inventory, var3, 8 + var3 * 18, 143));
                }
+
+               ((InventoryMaterialCrafting) par2.getInventorys()).setEventHandler(this);
+
+       }
+
+
+
+       @Override
+       public void onCraftMatrixChanged(IInventory par1IInventory){
+               par1IInventory.setInventorySlotContents(12, ChemiCraftAPI.instance.getCraftingManager().getMaterialResult(par1IInventory));
+               ((InventoryMaterialCrafting) par1IInventory).setFlag(true);
        }
 
 
 
        @Override
-       public void onCraftMatrixChanged(IInventory par1IInventory){}
+       public ItemStack slotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer)
+       {
+               super.slotClick(par1, par2, par3, par4EntityPlayer);
+               if(par1 == 12){
+                       ((InventoryMaterialCrafting) this.tileEntity.getInventorys()).setFlag2(true);
+                       for(int i = 0;i < 9;i++){
+                               if(this.inv.getStackInSlot(i+3) != null){
+                                       if(this.inv.getStackInSlot(i+3).stackSize >= 1){
+                                               this.putStackInSlot(i+3, new ItemStack(this.inv.getStackInSlot(i+3).itemID, --this.inv.getStackInSlot(i+3).stackSize, this.inv.getStackInSlot(i+3).getItemDamage()));
+                                       }else{
+                                               this.putStackInSlot(i+3, null);
+                                       }
+                               }
+                       }
+               }
+               return null;
+       }
 
 
 
@@ -85,19 +116,19 @@ public class ContainerMaterialCraftingTable extends Container {
 
 
 
-       private void generateSlots(String activeTabs, IInventory[] inventorys){
+       private void generateSlots(String activeTabs, IInventory inventorys){
                int count = 0;
                for(int i = 0;i < 3;i++){
-                       this.addSlotToContainer(new Slot(inventorys[0], count, 30 + 18 * i, 7));
+                       this.addSlotToContainer(new Slot(inventorys, count, 30 + 18 * i, 7));
                        count++;
                }
                for(int i = 0;i < 3;i++){
                        for(int j = 0;j < 3;j++){
-                               this.addSlotToContainer(new Slot(inventorys[0], count, 30 + 18 * j, 27 + 18 * i));
+                               this.addSlotToContainer(new Slot(inventorys, count, 30 + 18 * j, 27 + 18 * i));
                                count++;
                        }
                }
-               this.addSlotToContainer(new SlotMaterialCraftingResult(inventorys[0], count, 123, 33));
+               this.addSlotToContainer(new SlotMaterialCraftingResult(inventorys, count, 123, 33));
        }
 
 }
index c9504de..7484f3a 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,25 @@ public class InventoryMaterialCrafting implements IInventory {
 
        private ItemStack[] inventory = new ItemStack[3+9+1];
 
+       private boolean flag;
+
+       private boolean flag2;
+
+       private Container eventHandelr;
+
+       public void setEventHandler(Container par1Container){
+               this.eventHandelr = par1Container;
+               this.flag = true;
+       }
+
+       public void setFlag(boolean par1){
+               this.flag = par1;
+       }
+
+       public void setFlag2(boolean par1){
+               this.flag2 = par1;
+       }
+
        @Override
        public int getSizeInventory() {
                return inventory.length;
@@ -65,7 +85,23 @@ public class InventoryMaterialCrafting implements IInventory {
 
        @Override
        public void onInventoryChanged() {
+               if(flag){
+                       this.eventHandelr.onCraftMatrixChanged(this);
+               }
+       }
 
+       public void subtractStack(int par1, int par2, ItemStack[] par3ItemStack){
+               if(flag2){
+                       for(int i = 0;i < par2;i++){
+                               if(par3ItemStack[i] != null){
+                                       if(par3ItemStack[i].stackSize >= 1){
+                                               this.setInventorySlotContents(i, new ItemStack(par3ItemStack[i].itemID, --par3ItemStack[i].stackSize, par3ItemStack[i].getItemDamage()));
+                                       }else{
+                                               this.setInventorySlotContents(i, null);
+                                       }
+                               }
+                       }
+               }
        }
 
        @Override
diff --git a/common/chemicraft/NBTRecipe.java b/common/chemicraft/NBTRecipe.java
new file mode 100644 (file)
index 0000000..48f4e4f
--- /dev/null
@@ -0,0 +1,9 @@
+package chemicraft;
+
+import net.minecraft.src.ItemStack;
+
+public abstract class NBTRecipe {
+
+       public abstract ItemStack[] setNBT(ItemStack[] materials, ItemStack result);
+
+}
diff --git a/common/chemicraft/NBTRecipeGrenade.java b/common/chemicraft/NBTRecipeGrenade.java
new file mode 100644 (file)
index 0000000..9eb7469
--- /dev/null
@@ -0,0 +1,38 @@
+package chemicraft;
+
+import java.util.ArrayList;
+
+import net.minecraft.src.ItemStack;
+import net.minecraft.src.NBTTagCompound;
+
+public class NBTRecipeGrenade extends NBTRecipe {
+
+       @Override
+       public ItemStack[] setNBT(ItemStack[] materials, ItemStack result) {
+
+               ItemStack[] useItems = new ItemStack[3];
+
+               if(result.stackTagCompound == null){
+                       result.stackTagCompound = new NBTTagCompound();
+               }
+
+               for(int i = 0;i < materials.length;i++){
+                       if(materials[i] != null){
+                               if(materials[i].itemID-256 == ChemiCraft.instance.atomsID && materials[i].getItemDamage() == ChemiCraft.HYDROGEN){
+                                       result.getTagCompound().setString("GrenadeEffect", "Hydrogen");
+                                       useItems[i] = materials[i];
+                               }
+                               if(materials[i].itemID-256 == ChemiCraft.instance.atomsID && materials[i].getItemDamage() == ChemiCraft.CARBON){
+                                       result.getTagCompound().setString("GrenadeEffect", "Carbon");
+                                       useItems[i] = materials[i];
+                               }
+                               if(materials[i].itemID-256 == ChemiCraft.instance.atomsID && materials[i].getItemDamage() == ChemiCraft.URANIUM){
+                                       result.getTagCompound().setString("GrenadeEffect", "Uranium");
+                                       useItems[i] = materials[i];
+                               }
+                       }
+               }
+               return useItems;
+       }
+
+}
index 139263f..c63e89a 100644 (file)
@@ -67,10 +67,8 @@ public class TileEntityMaterialCraftingTable extends TileEntity {
        }
 
 
-       public IInventory[] getInventorys(){
-               ArrayList<IInventory> inventorys = new ArrayList<IInventory>();
-               inventorys.add(this.materialCraftingInv);
-               return inventorys.toArray(new IInventory[1]);
+       public IInventory getInventorys(){
+               return (InventoryMaterialCrafting) this.materialCraftingInv;
        }