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



  • 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!
    • Instructions on how to install newer Java can be found in the FAQ
  • Topics

×
×
  • Create New...

Important Information

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