Jump to content

Recommended Posts

Posted

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

}

}

Posted

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.

Posted

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi,  I'm using Forge 47.3.0 for Minecraft 1.20.1 I apologise if this is obvious I am very new to modding for Minecraft. I sucessfully made a mod that launched without errors or crashes (without it doing anything) but in order to add the features I need, I need to add "Custom Portal API [Forge]" as a dependency. However no matter the way I've tried to acheive this, it crashes. I am pretty sure it's not the way I'm putting it in the repositories, the dependencies or the way I'm refrencing it, as I've a hundred diffrent combinations and multiple Maven methods. And on all those diffrent variations I still get this crash: pastebin.com/UhumzZCZ Any tips would be invaluable as I've been loosing my mind over this!
    • Hi, i'm really having problems trying to set the texture to my custom item. I thought i'm doing everything correctly, but all i see is the missing texture block for my item. I am trying this for over a week now and getting really frustrated. The only time i could make the texture work, was when i used an older Forge version (52.0.1) for Minecraft (1.21.4). Was there a fundamental change for textures and models somewhere between versions that i'm missing? I started with Forge 54.1.0 and had this problem, so in my frustration i tried many things: Upgrading to Forge 54.1.1, created multiple new projects, workspaces, redownloaded everything and setting things up multiple times, as it was suggested in an older thread. Therea are no errors in the console logs, but maybe i'm blind, so i pasted the console logs to pastebin anyway: https://pastebin.com/zAM8RiUN The only time i see an error is when i change the models JSON file to an incorrect JSON which makes sense and that suggests to me it is actually reading the JSON file.   I set the github repository to public, i would be so thankful if anyone could take a look and tell me what i did wrong: https://github.com/xLorkin/teleport_pug_forge   As a note: i'm pretty new to modding, this is my first mod ever. But i'm used to programming. I had some up and downs, but through reading the documentation, using google and experimenting, i could solve all other problems. I only started modding for Minecraft because my son is such a big fan and wanted this mod.
    • Please read the FAQ (link in orange bar at top of page), and post logs as described there.
    • Hello fellow Minecrafters! I recently returned to Minecraft and realized I needed a wiki that displays basic information easily and had great user navigation. That’s why I decided to build: MinecraftSearch — a site by a Minecraft fan, for Minecraft fans. Key Features So Far Straight-to-the-Point Info: No extra fluff; just the essentials on items, mobs, recipes, loot and more. Clean & Intuitive Layout: Easy navigation so you spend less time scrolling and more time playing. Optimized Search: Search for anything—items, mobs, blocks—and get results instantly. What I’m Thinking of Adding More data/information: Catch chances for fishing rod, traveling villager trades, biomes info and a lot more. The website is still under development and need a lot more data added. Community Contributions: Potential for user-uploaded tips for items/mobs/blocks in the future. Feature Requests Welcome: Your ideas could shape how the wiki evolves! You can see my roadmap at the About page https://minecraftsearch.com/about I’d love for you to check out MinecraftSearch and see if it helps you find the info you need faster. Feedback is crucial—I want to develop this further based on what the community needs most, so please let me know what you think. Thanks, and happy crafting!
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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