Jump to content

[1.7.2] Item not smelting!


tiffit

Recommended Posts

Yea, its me again, and yea, I need help with the furnace again. Ok, so this time, the item won't smelt. When I put my fuel in in the fuel slot and whenI put what I want to smelt in my top slot, the furnace turns on (texture change, and fire in the gui starts working). But, the progress bar in the middle of the gui doesn't work, and the item in the top slot would just stay there, not going anywhere, not smelting, just sits there.

 

Anyways, here is my code:

Gui:

package com.tiffit.MoFoodMod.PizzaOven;

import org.lwjgl.opengl.GL11;

import com.tiffit.MoFoodMod.lib.References;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.resources.I18n;

public class GuiPizzaOven extends GuiContainer{

public static final ResourceLocation texture = new ResourceLocation("mofoodmod", "textures/gui/PizzaOven.png");

public TileEntityPizzaOven pizzaOven;

public GuiPizzaOven(InventoryPlayer inventoryPlayer, TileEntityPizzaOven entity) {
	super(new ContainerPizzaOven(inventoryPlayer, entity));


	this.pizzaOven = entity;

	this.xSize = 176;
	this.ySize = 166;

}

public void drawGuiForegroundLayer(int par1, int par2){
	String name = this.pizzaOven.isInvNameLocalized() ? this.pizzaOven.getInvName() : I18n.format(this.pizzaOven.getInvName());

	this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
	this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}





protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
	GL11.glColor4f(1F, 1F, 1F, 1F);

	Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
	drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);


	if(this.pizzaOven.isBurning()){
		int k = this.pizzaOven.getBurnTimeRemainingScaled(12);
		drawTexturedModalRect(guiLeft + 56, guiTop + 36 + 12 - k, 176, 12-k, 14, k + 2);

	}

	int k = this.pizzaOven.getCookProgressScaled(24);
	drawTexturedModalRect(guiLeft + 79, guiTop + 34, 176, 14, k + 1, 20);

}





}

TileEntity

package com.tiffit.MoFoodMod.PizzaOven;

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.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

import com.tiffit.MoFoodMod.ModBase;

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 = 50;
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 "Pizza Oven";
}


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

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


@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{
		PizzaOvenRecipies.INSTANCE.addRecipe(new ItemStack(ModBase.TacoBeef), new ItemStack(ModBase.Bacon));
		ItemStack itemstack = PizzaOvenRecipies.INSTANCE.findResult(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 50;

		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;
}

public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);

	NBTTagList list = nbt.getTagList("Items", 10);
	this.slots = new ItemStack[this.getSizeInventory()];

	for(int i = 0; i < list.tagCount(); i++){
		NBTTagCompound compound = list.getCompoundTagAt(i);
		byte b = compound.getByte("Slot");

		if(b >= 0 && b < this.slots.length){
			this.slots[b] = ItemStack.loadItemStackFromNBT(compound);
		}
	}
	this.burnTime = nbt.getShort("BurnTime");
	this.cookTime = nbt.getShort("CookTime");
	this.currentItemBurnTime = getItemBurnTime(this.slots[1]);

	if(nbt.hasKey("CustomName")){
		this.localizedName= nbt.getString("CustomName");
	}
}

public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);

	nbt.setShort("BurnTime", (short) this.burnTime);
	nbt.setShort("CookTime", (short) this.cookTime);

	NBTTagList list = new NBTTagList();

	for(int i = 0; i < this.slots.length; i++){
		if(this.slots[i] != null){
			NBTTagCompound compound = new NBTTagCompound();
			compound.setByte("Slot", (byte) i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);
		}
	}
	nbt.setTag("Items", list);

	if(this.isInvNameLocalized()){
		nbt.setString("CustomName", this.localizedName);
	}

}

}

Link to comment
Share on other sites

updateEntity() has a misplaced brace, breaking the burntime update logic a bit. Look very closely at the indentation level of the TileEntityFurnace method. It should jump out at you.

Link to comment
Share on other sites

updateEntity() has a misplaced brace, breaking the burntime update logic a bit. Look very closely at the indentation level of the TileEntityFurnace method. It should jump out at you.

nope, no jumps, even highlighted each bracket to see which one is missplaced.

Link to comment
Share on other sites

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.