Jump to content

Recommended Posts

Posted

I am trying to make a mod that has (at least) two new "furnaces". One that takes two items/blocks and combines them (the Combiner), and one that takes one item/block, and breaks it into two separate ones (the Breakdown Furnace, for now).

 

My Combiner works, but my Breakdown Furnace doesn't. I had both of them "working", but I realized that the Combiner would take _any_ two items, so I decided to make them a little more specific, and I must've broke it.

 

Here's my codes:

 

 

 

 

TileEntityBreakdown:

 

 

 

 


package com.drin.mods.enigma;

import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;

public class TileEntityBreakdown extends TileEntity implements IInventory {


private ItemStack[] inv;

public TileEntityBreakdown() {
     inv = new ItemStack[3];
     time = 0;
     freshTime = 0;
     cookTime = 0;
}

@Override
public int getSizeInventory() {
     return inv.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
     return inv[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amt) {
     ItemStack stack = getStackInSlot(slot);

     if (stack != null) {
         if (stack.stackSize <= amt) {
             setInventorySlotContents(slot, null);
         } else {
             stack = stack.splitStack(amt);
             if (stack.stackSize == 0) {
                 setInventorySlotContents(slot, null);
             }
         }
     }

     return stack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
     ItemStack stack = getStackInSlot(slot);

     if (stack != null) {
         setInventorySlotContents(slot, null);
     }

     return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
     inv[slot] = stack;

     if (stack != null && stack.stackSize > getInventoryStackLimit()) {
         stack.stackSize = getInventoryStackLimit();
     }
}

@Override
public String getInvName() {
     return "Combiner";
}

@Override
public int getInventoryStackLimit() {
     return 64;
}

@Override
public void onInventoryChanged() {
     //
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
     return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}

@Override
public void openChest() {
     //
}

@Override
public void closeChest() {
     //
}

@Override
public void readFromNBT(NBTTagCompound tagCompound) {
     super.readFromNBT(tagCompound);

     NBTTagList tagList = tagCompound.getTagList("Inventory");
     for (int i = 0; i < tagList.tagCount(); i++) {
         NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
         byte slot = tag.getByte("Slot");
         if (slot >= 0 && slot < inv.length) {
             inv[slot] = ItemStack.loadItemStackFromNBT(tag);
         }
     }
}

@Override
public void writeToNBT(NBTTagCompound tagCompound) {
     super.writeToNBT(tagCompound);

     NBTTagList itemList = new NBTTagList();
     for (int i = 0; i < inv.length; i++) {
         ItemStack stack = inv[i];
         if (stack != null) {
             NBTTagCompound tag = new NBTTagCompound();
             tag.setByte("Slot", (byte) i);
             stack.writeToNBT(tag);
             itemList.appendTag(tag);
         }
     }
     tagCompound.setTag("Inventory", itemList);
}

public int time;
public int freshTime;
public int cookTime;
private boolean isActive;

public boolean isActive() {
     return isActive;
}

public int getProgressScaled(int i) {
     return (cookTime * i) / 50;
}

public int getTimeRemainingScaled(int i) {
     if (freshTime == 0) {
         freshTime = 50;
     }

     return (time * i) / freshTime;
}

public boolean isCombining() {
     return time > 0;
}

public static boolean isItemFuel(ItemStack stack) {
     return getItemTime(stack) > 0;
}

@Override
public void updateEntity() {
     boolean flag = this.time > 0;
     boolean flag1 = false;

     if (time > 0) {
         time -= 1;
     }

     if (time == 0 && this.canBreakdown()) {
         freshTime = time = getItemTime(inv[0]);

         if (time > 0) {
             flag1 = true;

             if (inv[0] != null && inv[0].stackSize > 1) {

                 if (inv[0].stackSize == 0) {
                     Item var3 = inv[0].getItem().getContainerItem();

                     inv[0] = var3 == null ? null : new ItemStack(var3);
                 }
             }
         }
     }

     if (isCombining() && canBreakdown()) {
         cookTime += 1;

         if (cookTime == 50) {
             cookTime = 0;
             breakdownItem();
             flag1 = true;
         }
     } else {
         cookTime = 0;
     }

     if (flag != time > 0) {
         flag1 = true;
     }

     boolean check = isActive();
     isActive = isCombining();
     if (isActive != check) {
         this.worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
     }

     if (flag1) {
         this.onInventoryChanged();
     }
}

public static int getItemTime(ItemStack stack) {
     if (stack == null) {
         return 0;
     }

     int i = stack.getItem().shiftedIndex;

     if (i == Block.obsidian.blockID) {
         return 50;
     }

     return 0;
}

private boolean canBreakdown() {
     if (inv[0] == null || !isItemFuel(inv[0])) {
         return false;
     }

     ItemStack[] stacks = EnigmaRecipes.recipes().getBreakdownResult(inv[0].itemID);

     ItemStack stack1 = null;
     ItemStack stack2 = null;
    
     if (stacks != null) {
         stack1 = stacks[0];
         stack2 = stacks[1];
     }    

     if (stack1 == null && stack2 == null)
     {
         return false;
     }

     if (inv[2] == null && inv[1] == null)
     {
         return true;
     }

     if (inv[2] != null && inv[1] != null) {
         if (!inv[2].isItemEqual(stack2) && !inv[1].isItemEqual(stack1)) {
             return false;
         }
     } else if (inv[1] == null) {
         if (inv[2].stackSize == stack2.getMaxStackSize()) {
             return false;
         } else {
             return true;
         }
     } else if (inv[2] == null) {
         if (inv[1].stackSize == stack1.getMaxStackSize()) {
             return false;
         } else {
             return true;
         }
     } else {
         return true;
     }

     if ((inv[2].stackSize < getInventoryStackLimit() && inv[2].stackSize < inv[2].getMaxStackSize()) && (inv[1].stackSize < getInventoryStackLimit() && inv[1].stackSize < inv[1].getMaxStackSize()))
     {
         return true;
     }

     return inv[2].stackSize < stack2.getMaxStackSize() && inv[1].stackSize < stack1.getMaxStackSize();

}

public void breakdownItem() {
     if (canBreakdown()) {
         ItemStack[] stacks = EnigmaRecipes.recipes().getBreakdownResult(inv[0].itemID);

         ItemStack stack1 = null;
         ItemStack stack2 = null;
        
         if (stacks != null) {
             stack1 = stacks[0];
             stack2 = stacks[1];
         }

         if (inv[2] == null || inv[1] == null) {
             inv[2] = stack2.copy();
             inv[1] = stack1.copy();
         } else if (inv[2].itemID == stack2.itemID && inv[1].itemID == stack1.itemID) {
             inv[2].stackSize += 1;
             inv[1].stackSize += 1;
         }

         inv[0].stackSize -= 1;

         if (inv[0].stackSize == 0) {
             Item i = inv[0].getItem().getContainerItem();
             inv[0] = i == null ? null : new ItemStack(i);        
         }
     }
}
}

 

 

 

 

TileEntityCombiner:

 

 

 

 


package com.drin.mods.enigma;

import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;

public class TileEntityCombiner extends TileEntity implements IInventory {

private ItemStack[] inv;

public TileEntityCombiner() {
     inv = new ItemStack[3];
     time = 0;
     freshTime = 0;
     cookTime = 0;
}

@Override
public int getSizeInventory() {
     return inv.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
     return inv[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amt) {
     ItemStack stack = getStackInSlot(slot);

     if (stack != null) {
         if (stack.stackSize <= amt) {
             setInventorySlotContents(slot, null);
         } else {
             stack = stack.splitStack(amt);
             if (stack.stackSize == 0) {
                 setInventorySlotContents(slot, null);
             }
         }
     }

     return stack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
     ItemStack stack = getStackInSlot(slot);

     if (stack != null) {
         setInventorySlotContents(slot, null);
     }

     return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
     inv[slot] = stack;

     if (stack != null && stack.stackSize > getInventoryStackLimit()) {
         stack.stackSize = getInventoryStackLimit();
     }
}

@Override
public String getInvName() {
     return "Combiner";
}

@Override
public int getInventoryStackLimit() {
     return 64;
}

@Override
public void onInventoryChanged() {
     //
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
     return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}

@Override
public void openChest() {
     //
}

@Override
public void closeChest() {
     //
}

@Override
public void readFromNBT(NBTTagCompound tagCompound) {
     super.readFromNBT(tagCompound);

     NBTTagList tagList = tagCompound.getTagList("Inventory");
     for (int i = 0; i < tagList.tagCount(); i++) {
         NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
         byte slot = tag.getByte("Slot");
         if (slot >= 0 && slot < inv.length) {
             inv[slot] = ItemStack.loadItemStackFromNBT(tag);
         }
     }
}

@Override
public void writeToNBT(NBTTagCompound tagCompound) {
     super.writeToNBT(tagCompound);

     NBTTagList itemList = new NBTTagList();
     for (int i = 0; i < inv.length; i++) {
         ItemStack stack = inv[i];
         if (stack != null) {
             NBTTagCompound tag = new NBTTagCompound();
             tag.setByte("Slot", (byte) i);
             stack.writeToNBT(tag);
             itemList.appendTag(tag);
         }
     }
     tagCompound.setTag("Inventory", itemList);
}

//from stream furnace thing, needs work
//XXX

public int time;
public int freshTime;
public int cookTime;
private boolean isActive;

public boolean isActive() {
     return isActive;
}

public int getProgressScaled(int i) {
     return (cookTime * i) / 100;
}

public int getTimeRemainingScaled(int i) {
     if (freshTime == 0) {
         freshTime = 100;
     }

     return (time * i) / freshTime;
}

public boolean isCombining() {
     return time > 0;
}

public static boolean isItemFuel(ItemStack stack) {
     return getItemTime(stack) > 0;
}

@Override
public void updateEntity() {
     boolean var1 = this.time > 0;
     boolean var2 = false;

     if (time > 0) {
         time -= 1;
     }

     if (time == 0 && this.canCombine()) {
         freshTime = time = getItemTime(inv[1]);

         if (time > 0) {
             var2 = true;

             if (inv[1] != null) {
                 if (inv[1].stackSize == 0) {
                     Item var3 = inv[1].getItem().getContainerItem();

                     inv[1] = var3 == null ? null : new ItemStack(var3);
                 }
             }
         }
     }

     if (isCombining() && canCombine()) {
         cookTime += 1;

         if (cookTime == 100) {
             cookTime = 0;
             combineItem();
             var2 = true;
         }
     } else {
         cookTime = 0;
     }

     if (var1 != time > 0) {
         var2 = true;
     }

     boolean check = isActive();
     isActive = isCombining();
     if (isActive != check) {
         this.worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
     }

     if (var2) {
         this.onInventoryChanged();
     }
}

public static int getItemTime(ItemStack stack) {
     if (stack == null) {
         return 0;
     }

     int i = stack.getItem().shiftedIndex;

     if (i == Item.bucketLava.shiftedIndex) {
         return 100;
     } else if (i == Item.bucketWater.shiftedIndex) {
         return 100;
     }

     return 0;
}

private boolean canCombine() {
     if (inv[0] == null) {
         return false;
     }

     ItemStack stack = null;
    
     ItemStack slot1 = inv[0];
     ItemStack slot2 = inv[1];
     ItemStack[] stacks = {slot1, slot2};
     ItemStack[] stacksRev = {slot2, slot1};
    
     if (inv[0] != null && inv[1] != null) {
         stack = EnigmaRecipes.recipes().getCombinationResult(stacks);
     }
    
     if (stack == null && inv[0] != null && inv[1] != null) {
         stack = EnigmaRecipes.recipes().getCombinationResult(stacksRev);
     }

     if (stack == null) {
         return false;
     }

     if (inv[2] == null) {
         return true;
     }

     if (!inv[2].isItemEqual(stack)) {
         return false;
     }

     if (inv[2].stackSize < getInventoryStackLimit() && inv[2].stackSize < inv[2].getMaxStackSize()) {
         return true;
     }

     return inv[2].stackSize < stack.getMaxStackSize();

}

public void combineItem() {
     if (canCombine()) {
         ItemStack slot1 = inv[0];
         ItemStack slot2 = inv[1];
         ItemStack[] stacks = {slot1, slot2};
         ItemStack[] stacksRev = {slot2, slot1};
        
         ItemStack stack = EnigmaRecipes.recipes().getCombinationResult(stacks);
        
         if (stack == null) {
             stack = EnigmaRecipes.recipes().getCombinationResult(stacksRev);
         }
        
         if (inv[2] == null) {
             inv[2] = stack.copy();
         } else if (inv[2].itemID == stack.itemID) {
             inv[2].stackSize += 1;
         }

         inv[0].stackSize -= 1;
         inv[1].stackSize -= 1;

         if (inv[0].stackSize == 0) {
             Item i = inv[0].getItem().getContainerItem();
             inv[0] = i == null ? null : new ItemStack(i);        
         }

         if (inv[1].stackSize == 0) {
             Item i = inv[1].getItem().getContainerItem();
             inv[1] = i == null ? null : new ItemStack(i);        
         }
     }
}
}

 

 

 

 

EnigmaRecipes:

 

 

 

 


package com.drin.mods.enigma;

import java.util.HashMap;
import java.util.Map;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;

public class EnigmaRecipes {

public static final EnigmaRecipes recipes = new EnigmaRecipes();

private Map combinationList = new HashMap();
private Map breakdownList = new HashMap();
private Map exp = new HashMap();

public static final EnigmaRecipes recipes() {
     return recipes;
}

private EnigmaRecipes() {
     addCombination(new ItemStack(Item.bucketWater), new ItemStack(Item.bucketLava), new ItemStack(Block.obsidian), 0.7F);
}

public void addCombination(ItemStack item, ItemStack item2, ItemStack stack, float experience) {
     ItemStack[] combo = {item.copy(), item2.copy()};
    
     combinationList.put(combo, stack.copy());
     breakdownList.put(stack.itemID, combo);
     exp.put(Integer.valueOf(stack.itemID), Float.valueOf(experience));
}

public ItemStack getCombinationResult(ItemStack[] ids) {
     return (ItemStack)combinationList.get(ids);
}

public ItemStack[] getBreakdownResult(int id) {
     return (ItemStack[])breakdownList.get(id);
}

public Map getCombinationList() {
     return combinationList;
}

public float getExperience(int i) {
     return this.exp.containsKey(Integer.valueOf(i)) ? ((Float)exp.get(Integer.valueOf(i))).floatValue() : 0.0F;
}

public Map getBreakdownList() {
     return breakdownList;
}
}

 

 

 

 

 

 

 

For whatever reason, it looks like in canBreakdown(), stacks is always null, so therefore stack1 and stack2 are null, and then it returns false, so it never gets to the breakdownItem() method.

 

Any ideas what's going on here? Am I using those HashMaps wrong?

Posted

I did try to work on this yesterday, but to no avail...

 

I changed the inputs for the combinationList HashMap to an int[], that way (hopefully), it wouldn't have a problem with the ItemStacks, and I'm just passing it the blockID. That didn't work either :(

 

Here's the updated code:

EnigmaRecipes:

 

 

package com.drin.mods.enigma;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;

public class EnigmaRecipes {

public static final EnigmaRecipes recipes = new EnigmaRecipes();

private Map combinationList = new HashMap();
private Map breakdownList = new HashMap();
private Map exp = new HashMap();

public static final EnigmaRecipes recipes() {
	return recipes;
}

private EnigmaRecipes() {
	addCombination(new ItemStack(Item.bucketWater), new ItemStack(Item.bucketLava), new ItemStack(Block.obsidian), 0.7F);

	addCombination(new ItemStack(Item.bucketLava), new ItemStack(Item.bucketMilk), new ItemStack(Block.glass), 0.7F);
}

public void addCombination(ItemStack item, ItemStack item2, ItemStack stack, float experience) {
	int[] combo = {item.itemID, item2.itemID};
	ItemStack[] comboBreakdown = {item.copy(), item2.copy()};

	combinationList.put(combo, stack);
	breakdownList.put(stack.itemID, comboBreakdown);
	exp.put(Integer.valueOf(stack.itemID), Float.valueOf(experience));
}

public ItemStack getCombinationResult(int stack, int stack2) {
	int[] ids = {stack, stack2};

	return (ItemStack)combinationList.get(ids);
}

public ItemStack[] getBreakdownResult(int id) {
	return (ItemStack[])breakdownList.get(id);
}

public Map getCombinationList() {
	return combinationList;
}

public float getExperience(int i) {
	return this.exp.containsKey(Integer.valueOf(i)) ? ((Float)exp.get(Integer.valueOf(i))).floatValue() : 0.0F;
}

public Map getBreakdownList() {
	return breakdownList;
}
}

 

 

TileEntityBreakdown:

 

 

package com.drin.mods.enigma;

import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;

public class TileEntityBreakdown extends TileEntity implements IInventory {


private ItemStack[] inv;

public TileEntityBreakdown() {
	inv = new ItemStack[3];
	time = 0;
	freshTime = 0;
	cookTime = 0;
}

@Override
public int getSizeInventory() {
	return inv.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	return inv[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amt) {
	ItemStack stack = getStackInSlot(slot);

	if (stack != null) {
		if (stack.stackSize <= amt) {
			setInventorySlotContents(slot, null);
		} else {
			stack = stack.splitStack(amt);
			if (stack.stackSize  == 0) {
				setInventorySlotContents(slot, null);
			}
		}
	}

	return stack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	ItemStack stack = getStackInSlot(slot);

	if (stack != null) {
		setInventorySlotContents(slot, null);
	}

	return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
	inv[slot] = stack;

	if (stack != null && stack.stackSize > getInventoryStackLimit()) {
		stack.stackSize = getInventoryStackLimit();
	}
}

@Override
public String getInvName() {
	return "Combiner";
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public void onInventoryChanged() {
	//
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}

@Override
public void openChest() {
	//
}

@Override
public void closeChest() {
	//
}

@Override
public void readFromNBT(NBTTagCompound tagCompound) {
	super.readFromNBT(tagCompound);

	NBTTagList tagList = tagCompound.getTagList("Inventory");
	for (int i = 0; i < tagList.tagCount(); i++) {
		NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
		byte slot = tag.getByte("Slot");
		if (slot >= 0 && slot < inv.length) {
			inv[slot] = ItemStack.loadItemStackFromNBT(tag);
		}
	}
}

@Override
public void writeToNBT(NBTTagCompound tagCompound) {
	super.writeToNBT(tagCompound);

	NBTTagList itemList = new NBTTagList();
	for (int i = 0; i < inv.length; i++) {
		ItemStack stack = inv[i];
		if (stack != null) {
			NBTTagCompound tag = new NBTTagCompound();
			tag.setByte("Slot", (byte) i);
			stack.writeToNBT(tag);
			itemList.appendTag(tag);
		}
	}
	tagCompound.setTag("Inventory", itemList);
}

//from stream furnace thing, needs work
//XXX

public int time;
public int freshTime;
public int cookTime;
private boolean isActive;

public boolean isActive() {
	return isActive;
}

public int getProgressScaled(int i) {
	return (cookTime * i) / 50;
}

public int getTimeRemainingScaled(int i) {
	if (freshTime == 0) {
		freshTime = 50;
	}

	return (time * i) / freshTime;
}

public boolean isCombining() {
	return time > 0;
}

public static boolean isItemFuel(ItemStack stack) {
	return getItemTime(stack) > 0;
}

@Override
public void updateEntity() {
	boolean flag = this.time > 0;
	boolean flag1 = false;

	if (time > 0) {
		time -= 1;
	}

	if (time == 0 && this.canBreakdown()) {
		freshTime = time = getItemTime(inv[0]);

		if (time > 0) {
			flag1 = true;

			if (inv[0] != null && inv[0].stackSize > 1) {

				if (inv[0].stackSize == 0) {
					Item var3 = inv[0].getItem().getContainerItem();

					inv[0] = var3 == null ? null : new ItemStack(var3);
				}
			}
		}
	}

	if (isCombining() && canBreakdown()) {
		cookTime += 1;

		if (cookTime == 50) {
			cookTime = 0;
			breakdownItem();
			flag1 = true;
		}
	} else {
		cookTime = 0;
	}

	if (flag != time > 0) {
		flag1 = true;
	}

	boolean check = isActive();
	isActive = isCombining();
	if (isActive != check) {
		this.worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
	}

	if (flag1) {
		this.onInventoryChanged();
	}
}

public static int getItemTime(ItemStack stack) {
	if (stack == null) {
		return 0;
	}

	int i = stack.getItem().shiftedIndex;

	if (i == Block.obsidian.blockID) {
		return 50;
	} else if (i == Block.glass.blockID) {
		return 50;
	}

	return 0;
}

private boolean canBreakdown() {
	if (inv[0] == null || !isItemFuel(inv[0])) {
		return false;
	}

	ItemStack[] stacks = EnigmaRecipes.recipes().getBreakdownResult(inv[0].itemID);

	ItemStack stack1 = null;
	ItemStack stack2 = null;

	if (stacks != null) {
		stack1 = stacks[0];
		stack2 = stacks[1];
	}		

	if (stack1 == null && stack2 == null)
	{
		return false;
	}

	if (inv[2] == null && inv[1] == null)
	{
		return true;
	}

	if (inv[2] != null && inv[1] != null) {
		if (!inv[2].isItemEqual(stack2) && !inv[1].isItemEqual(stack1)) {
			return false;
		}
	} else if (inv[1] == null) {
		if (inv[2].stackSize == stack2.getMaxStackSize()) {
			return false;
		} else {
			return true;
		}
	} else if (inv[2] == null) {
		if (inv[1].stackSize == stack1.getMaxStackSize()) {
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}

	if ((inv[2].stackSize < getInventoryStackLimit() && inv[2].stackSize < inv[2].getMaxStackSize()) && (inv[1].stackSize < getInventoryStackLimit() && inv[1].stackSize < inv[1].getMaxStackSize()))
	{
		return true;
	}

	return inv[2].stackSize < stack2.getMaxStackSize() && inv[1].stackSize < stack1.getMaxStackSize();

}

public void breakdownItem() {
	if (canBreakdown()) {
		ItemStack[] stacks = EnigmaRecipes.recipes().getBreakdownResult(inv[0].itemID);

		ItemStack stack1 = null;
		ItemStack stack2 = null;

		if (stacks != null) {
			stack1 = stacks[0];
			stack2 = stacks[1];
		}

		if (inv[2] == null || inv[1] == null) {
			inv[2] = stack2.copy();
			inv[1] = stack1.copy();
		} else if (inv[2].itemID == stack2.itemID && inv[1].itemID == stack1.itemID) {
			inv[2].stackSize += 1;
			inv[1].stackSize += 1;
		}

		inv[0].stackSize -= 1;

		if (inv[0].stackSize == 0) {
			Item i = inv[0].getItem().getContainerItem();
			inv[0] = i == null ? null : new ItemStack(i);			
		}
	}
}
}

 

 

TileEntityCombiner:

 

 

package com.drin.mods.enigma;

import net.minecraft.src.Block;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;

public class TileEntityCombiner extends TileEntity implements IInventory {

private ItemStack[] inv;

public TileEntityCombiner() {
	inv = new ItemStack[3];
	time = 0;
	freshTime = 0;
	cookTime = 0;
}

@Override
public int getSizeInventory() {
	return inv.length;
}

@Override
public ItemStack getStackInSlot(int slot) {
	return inv[slot];
}

@Override
public ItemStack decrStackSize(int slot, int amt) {
	ItemStack stack = getStackInSlot(slot);

	if (stack != null) {
		if (stack.stackSize <= amt) {
			setInventorySlotContents(slot, null);
		} else {
			stack = stack.splitStack(amt);
			if (stack.stackSize  == 0) {
				setInventorySlotContents(slot, null);
			}
		}
	}

	return stack;
}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	ItemStack stack = getStackInSlot(slot);

	if (stack != null) {
		setInventorySlotContents(slot, null);
	}

	return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
	inv[slot] = stack;

	if (stack != null && stack.stackSize > getInventoryStackLimit()) {
		stack.stackSize = getInventoryStackLimit();
	}
}

@Override
public String getInvName() {
	return "Combiner";
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public void onInventoryChanged() {
	//
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}

@Override
public void openChest() {
	//
}

@Override
public void closeChest() {
	//
}

@Override
public void readFromNBT(NBTTagCompound tagCompound) {
	super.readFromNBT(tagCompound);

	NBTTagList tagList = tagCompound.getTagList("Inventory");
	for (int i = 0; i < tagList.tagCount(); i++) {
		NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i);
		byte slot = tag.getByte("Slot");
		if (slot >= 0 && slot < inv.length) {
			inv[slot] = ItemStack.loadItemStackFromNBT(tag);
		}
	}
}

@Override
public void writeToNBT(NBTTagCompound tagCompound) {
	super.writeToNBT(tagCompound);

	NBTTagList itemList = new NBTTagList();
	for (int i = 0; i < inv.length; i++) {
		ItemStack stack = inv[i];
		if (stack != null) {
			NBTTagCompound tag = new NBTTagCompound();
			tag.setByte("Slot", (byte) i);
			stack.writeToNBT(tag);
			itemList.appendTag(tag);
		}
	}
	tagCompound.setTag("Inventory", itemList);
}

//from stream furnace thing, needs work
//XXX

public int time;
public int freshTime;
public int cookTime;
private boolean isActive;

public boolean isActive() {
	return isActive;
}

public int getProgressScaled(int i) {
	return (cookTime * i) / 100;
}

public int getTimeRemainingScaled(int i) {
	if (freshTime == 0) {
		freshTime = 100;
	}

	return (time * i) / freshTime;
}

public boolean isCombining() {
	return time > 0;
}

public static boolean isItemFuel(ItemStack stack) {
	return getItemTime(stack) > 0;
}

@Override
public void updateEntity() {
	boolean var1 = this.time > 0;
	boolean var2 = false;

	if (time > 0) {
		time -= 1;
	}

	if (time == 0 && this.canCombine()) {
		freshTime = time = getItemTime(inv[1]);

		if (time > 0) {
			var2 = true;

			if (inv[1] != null) {
				if (inv[1].stackSize == 0) {
					Item var3 = inv[1].getItem().getContainerItem();

					inv[1] = var3 == null ? null : new ItemStack(var3);
				}
			}
		}
	}

	if (isCombining() && canCombine()) {
		cookTime += 1;

		if (cookTime == 100) {
			cookTime = 0;
			combineItem();
			var2 = true;
		}
	} else {
		cookTime = 0;
	}

	if (var1 != time > 0) {
		var2 = true;
	}

	boolean check = isActive();
	isActive = isCombining();
	if (isActive != check) {
		this.worldObj.markBlockNeedsUpdate(xCoord, yCoord, zCoord);
	}

	if (var2) {
		this.onInventoryChanged();
	}
}

public static int getItemTime(ItemStack stack) {
	if (stack == null) {
		return 0;
	}

	int i = stack.getItem().shiftedIndex;

	if (i == Item.bucketLava.shiftedIndex) {
		return 100;
	} else if (i == Item.bucketWater.shiftedIndex) {
		return 100;
	} else if (i == Item.bucketMilk.shiftedIndex) {
		return 100;
	}

	return 0;
}

private boolean canCombine() {
	if (inv[0] == null) {
		return false;
	}

	ItemStack stack = null;

	int slot1 = 0;
	int slot2 = 0;

	/*
	ItemStack[] stacks = {slot1, slot2};
	ItemStack[] stacksRev = {slot2, slot1};
	*/

	if (inv[0] != null && inv[1] != null) {
		slot1 = inv[0].itemID;
		slot2 = inv[1].itemID;
		stack = EnigmaRecipes.recipes().getCombinationResult(slot1, slot2);
	}

	if (stack == null && inv[0] != null && inv[1] != null) {
		slot1 = inv[0].itemID;
		slot2 = inv[1].itemID;
		stack = EnigmaRecipes.recipes().getCombinationResult(slot2, slot1);
	}

	if (stack == null) {
		return false;
	}

	if (inv[2] == null) {
		return true;
	}

	if (!inv[2].isItemEqual(stack)) {
		return false;
	}

	if (inv[2].stackSize < getInventoryStackLimit() && inv[2].stackSize < inv[2].getMaxStackSize()) {
		return true;
	}

	return inv[2].stackSize < stack.getMaxStackSize();

}

public void combineItem() {
	if (canCombine()) {
		int slot1 = 0;
		int slot2 = 0;

		if (inv[0] != null && inv[1] != null) {
			slot1 = inv[0].itemID;
			slot2 = inv[1].itemID;
		}
		/*
		ItemStack[] stacks = {slot1, slot2};
		ItemStack[] stacksRev = {slot2, slot1};
		*/

		ItemStack stack = EnigmaRecipes.recipes().getCombinationResult(slot1, slot2);

		if (stack == null) {
			stack = EnigmaRecipes.recipes().getCombinationResult(slot2, slot1);
		}

		if (inv[2] == null) {
			inv[2] = stack.copy();
		} else if (inv[2].itemID == stack.itemID) {
			inv[2].stackSize += 1;
		}

		inv[0].stackSize -= 1;
		inv[1].stackSize -= 1;

		if (inv[0].stackSize == 0) {
			Item i = inv[0].getItem().getContainerItem();
			inv[0] = i == null ? null : new ItemStack(i);			
		}

		if (inv[1].stackSize == 0) {
			Item i = inv[1].getItem().getContainerItem();
			inv[1] = i == null ? null : new ItemStack(i);			
		}
	}
}
}

 

 

 

The Breakdown Furnace works, just not the Combiner.

Posted

We are not gunna read all of your code to find a bug for you, you're gunna have to track it down for yourself.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Could anybody tell me how HashMaps work at least? I am trying to pass an array as the input, and I think that might be where I'm wrong. Trust me, Lex. I've poured over this, even before I posted it.

Posted

Yes sir, I do know how to use Google. HashMap accepts my array as a key, but doesn't find any value when you pass it with get(). I'll keep trying to figure it out, as it is obvious that nobody here can (or wants to, in Lex's case) help. It's actually not even that much code.

 

I'm not trying to whine here, but I was hoping for help, and I get the opposite.

Posted

The way hashmaps work isn't the problem. What you're doing would not work for any map implementation. The reason is that array equals and hashCode work on the object identity, not on the contained data. Take a look at the FurnaceRecipes class, that should show you how to do it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.