//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
/**
- * 素材製作台の効果のキーリスト
+ * 素材製作台の効果付属用のNBTRecipeのリスト
*/
- private ArrayList<String[]> materialEffectKey = new ArrayList<String[]>();
-
-
-
- /**
- * 素材製作台の効果のリスト
- */
- private ArrayList<Object[]> materialEffectValue = new ArrayList<Object[]>();
+ private ArrayList<NBTRecipe> materialNBT = new ArrayList<NBTRecipe>();
- 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);
}
}
//以下システム関連//////////////////////////////////////////////////////
+ public ArrayList<ItemStack[]> getMaterialMaterials(){
+ return materialMaterials;
+ }
+
+
+
+ public ArrayList<ItemStack> getMaterialResult(){
+ return materialResult;
+ }
+
+
+
+ public ArrayList<NBTRecipe> getMaterialNBTRecipe(){
+ return materialNBT;
+ }
+
+
+
public ChemiCraftCraftingManager getCraftingManager(){
return 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++){
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){
private TileEntityMaterialCraftingTable tileEntity;
+ private InventoryMaterialCrafting inv;
+
+
public ContainerMaterialCraftingTable(EntityPlayer par1EntityPlayer, TileEntityMaterialCraftingTable par2)
{
this.posY = par2.yCoord;
this.posZ = par2.zCoord;
this.tileEntity = par2;
+ this.inv = (InventoryMaterialCrafting) par2.getInventorys();
//GenerateInventory
this.generateSlots("Decomposition", par2.getInventorys());
//GeneratePlayerInventory
{
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;
+ }
- 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));
}
}
package chemicraft;
+import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
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;
@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
--- /dev/null
+package chemicraft;
+
+import net.minecraft.src.ItemStack;
+
+public abstract class NBTRecipe {
+
+ public abstract ItemStack[] setNBT(ItemStack[] materials, ItemStack result);
+
+}
--- /dev/null
+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;
+ }
+
+}
}
- 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;
}