Jump to content

Recommended Posts

Posted

Ok, so heres the problem, I have a custom furnace, and its pretty much finished, except there is one problem. The itemstack isn't working. So when I place an item in a slot in the furnace it duplicates. So then there is one item in the slot and one item my mouse is holding. Also, I cannot stack items.

 

My TileEntityClass (You probably don't need this):

package com.tiffit.MoFoodMod.PizzaOven;

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntity;

public class TileEntityPizzaOven extends TileEntity implements ISidedInventory{

private String localizedName;

private static final int[] slots_top = new int[]{0};
private static final int[] slots_bottom = new int[]{2, 1};
private static final int[] slots_side = new int[]{1};

private ItemStack[] slots = new ItemStack[3];

public int furnaceSpeed = 800;
public int burnTime;
public int currentItemBurnTime;
public int cookTime;



public int getSizeInventory(){
	return this.slots.length;
}


public String getInvName(){
	return this.isInvNameLocalized() ? this.localizedName : "container.PizzaOven" ;
}

public boolean isInvNameLocalized(){
	return this.localizedName != null && this.localizedName.length() > 0;
}

public void setGuiDisplayName(String displayName) {
	this.localizedName = displayName;

}


@Override
public ItemStack getStackInSlot(int var1) {
	return this.slots[var1];
}


@Override
public ItemStack decrStackSize(int var1, int var2) {
	if(this.slots[var1] != null){
		ItemStack itemstack;

		if(this.slots[var1].stackSize <= var2){
			itemstack = this.slots[var1];

			this.slots[var1] = null;
			return itemstack;
		}else{
		itemstack = this.slots[var1].splitStack(var2);	

		if(this.slots[var1].stackSize == 0){
			this.slots[var1] = null;
		}
		return itemstack;
		}
	}
	return null;
}


@Override
public ItemStack getStackInSlotOnClosing(int i) {
	if(this.slots[i] != null){
		ItemStack itemstack = this.slots[i];
		this.slots[i] = null;
		return itemstack;
	}

	return null;
}


@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
	this.slots[i] = itemstack;

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


@Override
public String getInventoryName() {
	return null;
}


@Override
public boolean hasCustomInventoryName() {
	return false;
}


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


@Override
public boolean isUseableByPlayer(EntityPlayer var1) {
	return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : var1.getDistanceSq((double)this.xCoord + 0.5D,(double) this.yCoord + 0.5D,(double) this.zCoord + 0.5D) <= 64.0D;
}


@Override
public void openInventory() {

}


@Override
public void closeInventory() {

}

public boolean isBurning(){
	return this.burnTime > 0;
}

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

	if(isBurning()){
		this.burnTime--;
	}

	if(!this.worldObj.isRemote){
		if(this.burnTime == 0 && this.canSmelt()){
			this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[1]);

			if(isBurning()){
				flag1 = true;

				if(this.slots[1] != null){
					this.slots[1].stackSize--;

					if(this.slots[1].stackSize == 0){
						this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
					}
				}
			}
			if(this.isBurning() && this.canSmelt()){
				this.cookTime++;

				if(this.cookTime == this.furnaceSpeed){
					this.cookTime = 0; 
					this.smeltItem();
					flag1 = true;
				}

			}else{
				this.cookTime = 0;
			}

		}
		if(flag != this.burnTime > 0){
			flag1 = true;
			PizzaOven.updatePizzaOvenBlockState(this.burnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
		}
	}
	if(flag1){
		this.markDirty();
	}
}


private void smeltItem() {
	if(this.canSmelt()){
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if(this.slots[2] == null){
			this.slots[2] = itemstack.copy();
		}else if(this.slots[2].isItemEqual(itemstack)){
			this.slots[2].stackSize += itemstack.stackSize;
		}
		this.slots[0].stackSize--;

		if(this.slots[0].stackSize <= 0){
			this.slots[0] = null;
		}
	}
}


private boolean canSmelt() {
	if(this.slots[0] == null){
		return false;
	}else{
		ItemStack itemstack = FurnaceRecipes.smelting().getSmeltingResult(this.slots[0]);

		if(itemstack == null) return false;
		if(this.slots[2] == null) return true;
		if(!this.slots[2].isItemEqual(itemstack)) return false;

		int result  = this.slots[2].stackSize + itemstack.stackSize;

		return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
	}
}


public static int getItemBurnTime(ItemStack itemstack){
	if(itemstack == null){

		return 0;

	}else{

		Item item = itemstack.getItem();

		if(itemstack.getItem() == Items.coal)return 400;

		return 0;
	}
}

public static boolean isItemFuel(ItemStack itemstack){
	return getItemBurnTime (itemstack) > 0;
}


@Override
public boolean isItemValidForSlot(int var1, ItemStack itemstack) {
	return var1 == 2 ? false :(var1 == 1 ? isItemFuel(itemstack): true);
}


@Override
public int[] getAccessibleSlotsFromSide(int var1) {
	return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_side);
}


@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
	return this.isItemValidForSlot(i, itemstack);
}


@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
	return j != 0 || i != 1 || itemstack.getItem() == Items.bucket;
}


public int getBurnTimeRemainingScaled(int i) {
	if(this.currentItemBurnTime == 0){
		this.currentItemBurnTime = this.furnaceSpeed;
	}

	return this.burnTime * i / this.currentItemBurnTime;
}


public int getCookProgressScaled(int i) {
	return this.cookTime * i / this.furnaceSpeed;
}

}

 

 

My container class:

package com.tiffit.MoFoodMod.PizzaOven;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnace;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ContainerPizzaOven extends Container{

private TileEntityPizzaOven pizzaOven;
public int lastBurnTime;
public int lastItemBurnTime;
public int lastCookTime;


public ContainerPizzaOven(InventoryPlayer inventory, TileEntityPizzaOven tileentity){
	this.pizzaOven = tileentity;

	this.addSlotToContainer(new Slot(tileentity, 0, 56, 17));
	this.addSlotToContainer(new Slot(tileentity, 1, 56, 53));
	this.addSlotToContainer(new SlotFurnace(inventory.player, tileentity, 2, 116, 35));

	for(int i = 0; i < 3; i++){
		for(int j = 0; j < 9; j++){
			this.addSlotToContainer(new Slot(inventory, j + i*9 + 9, 8 + j*18, 84 + i*18));
		}
	}

	for(int i = 0; i < 9; i++){
		this.addSlotToContainer(new Slot (inventory, i, 8 + i*18, 142));
	}

}

public void addCraftingToCrafters(ICrafting icrafting){
	super.addCraftingToCrafters(icrafting);
	icrafting.sendProgressBarUpdate(this, 0, this.pizzaOven.cookTime);
	icrafting.sendProgressBarUpdate(this, 1, this.pizzaOven.burnTime);
	icrafting.sendProgressBarUpdate(this, 2, this.pizzaOven.currentItemBurnTime);
}

public void detectAndSendChanges(){
	super.detectAndSendChanges();
}

@SideOnly(Side.CLIENT)
public void updateProgressBar(int slot, int newValue){
	if(slot == 0)this.pizzaOven.cookTime = newValue;
	if(slot == 1)this.pizzaOven.burnTime = newValue;
	if(slot == 2)this.pizzaOven.currentItemBurnTime = newValue;
}


public ItemStack transferStackInSlot(EntityPlayer player, int slot){
	return null;
}

public boolean canInteractWith(EntityPlayer var1) {
	return this.pizzaOven.isUseableByPlayer(var1);
}

}

 

Posted

OH DERP!

I forgot to set getInventoryStackLimit()

to 64 instead of 0.

Any moderator mind if they could remove this topic?

Posted

Why removing it? Someone with a similar problem might come here and find the solution.

You can lock the topic though if you think it is solved.

Locking it seems great

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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