Jump to content

[1.7.10] Custom furnace inventory problems


Roboguy99

Recommended Posts

I'm having some problems with my custom furnace's inventory. The idea is that cobblestone goes in the bottom slot and fills up a meter. Items go in the slot above that and different items come out the other side. Recipes are working with it, however the cobblestone system is very broken (won't ever accept the last piece of cobblestone, if you take the last piece out it treats it weirdly and when you stack it with any other cobblestone it just deletes the other half of the stack, meaning you will always have 1 piece of cobblestone). I'd also like to try and make it so that nothing can be placed in the output slot and only cobblestone can be placed in the cobblestone slot, which so far I have failed at.

 

Here is the code for my tileentity:

 

package roboguy99.foodTech.common.tile;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import roboguy99.foodTech.GrindstoneRecipes;

public class TileGrindstone extends TileEntity implements ISidedInventory
{	
private ItemStack[] slot = new ItemStack[3];

//TODO: Remove stone system as it makes no sense
public int maxStone = 16;
public int stone = 0;
public String customName;

public void updateEntity()
{	
	ItemStack slotStone = getStackInSlot(1);

	//Check for stone in buffer and fill from itemstack in bottom slot
	if(slotStone != null && slotStone.getItem() == Item.getItemFromBlock(Blocks.cobblestone) && stone < maxStone)
	{
		this.stone++;
		slotStone.stackSize--;

		if (slotStone.stackSize <= 0)
            {
                slotStone = null;
                this.stone = 0;
            }
	}

	//Check for inventory contents and process any items
	if(!worldObj.isRemote && this.canProcess())
	{
		this.processItem();
	}
}

public int getStoneScaled(int scaled)
{
	return (int) (this.stone * scaled / this.maxStone);
}

public ItemStack decrStackSize(int i, int j) 
{
		if(this.slot[i] != null)
		{
			ItemStack itemStack;

			if(this.slot[i].stackSize <= j)
			{
				itemStack = this.slot[i];
				this.slot[i] = null;
				return itemStack;
			}
			else
			{
				itemStack = this.slot[i].splitStack(j);

				if(this.slot[i].stackSize == 0)
				{
					this.slot[i] = null;
				}

				return itemStack;
			}
		}

	return null;
}

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

public ItemStack getStackInSlot(int i) 
{
	return this.slot[i];
}

public ItemStack getStackInSlotOnClosing(int i) 
{
	if(this.slot[i] != null)
	{
		ItemStack itemStack = this.slot[i];
		this.slot[i] = null;
		return itemStack;
	}

	return null;
}

public String getInventoryName() 
{
	return this.hasCustomInventoryName() ? this.customName : "container.grindstone";
}

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

public void closeInventory() 
{

}

public int getInventoryStackLimit() 
{
	return 64;
}

public boolean isItemValidForSlot(int slot, ItemStack itemStack)
{
	return slot == 2 ? false : true;
}

public boolean isUseableByPlayer(EntityPlayer entityPlayer) 
{
	return true;
}

public void openInventory() 
{

}

public void setInventorySlotContents(int i, ItemStack itemStack) 
{
	this.slot[i] = itemStack;

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

public boolean canExtractItem(int i, ItemStack var2, int j) 
{
	return true;
}

public boolean canInsertItem(int slot, ItemStack itemStack, int side) 
{
	return this.isItemValidForSlot(slot, itemStack);
}

public int[] getAccessibleSlotsFromSide(int i) 
{
	return null;
}

public static void addRecipe()
{
	//TODO add recipes
}

/**
     * Returns true if the grindstone can smelt an item, i.e. has a source item, destination stack isn't full, etc.
     */
    private boolean canProcess()
    {
        if (this.slot[0] == null || this.stone == 0)
        {
            return false;
        }
        else
        {
            ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]);
            if (itemstack == null) return false;
            if (this.slot[2] == null) return true;
            if (!this.slot[2].isItemEqual(itemstack)) return false;
            int result = slot[2].stackSize + itemstack.stackSize;
            return result <= getInventoryStackLimit() && result <= this.slot[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
        }
    }

    /**
     * Turn one item from the grindstone source stack into the appropriate processed item in the furnace result stack
     */
    public void processItem()
    {
        if (this.canProcess())
        {
            ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]);

            if (this.slot[2] == null)
            {
                this.slot[2] = itemstack.copy();
            }
            else if (this.slot[2].getItem() == itemstack.getItem())
            {
                this.slot[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
            }

            --this.slot[0].stackSize;
            --this.stone;
            System.out.println(this.stone);

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

 

I have no idea what I'm doing.

Link to comment
Share on other sites

Remove the

this.stone=0;

line in your

updateEntity()

method, because else you will set the stone to 0 if the slot is emptied.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Your stackSize == 0 check is broken. You only set the

slotStone

variable to null, but not the slot itself. You need to call setInventorySlotContents.

Also you should call markDirty when the stack size changes (you don't need to do that if you reach 0, because setInventorySlotContents will call it).

 

Ok I've tried this but I've got the same problem I had to start with. Here's my code now:

 

package roboguy99.foodTech.common.tile;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import roboguy99.foodTech.GrindstoneRecipes;

public class TileGrindstone extends TileEntity implements ISidedInventory
{	
private ItemStack[] slot = new ItemStack[3];

private static final int MAX_STONE = 16;
public int stone = 0;
public String customName;

public void updateEntity()
{	
	ItemStack slotStone = getStackInSlot(1);

	//Check for stone in buffer and fill from itemstack in bottom slot
	if(slotStone != null && slotStone.getItem() == Item.getItemFromBlock(Blocks.cobblestone) && stone < MAX_STONE)
	{
		this.stone += MAX_STONE; //1 cobblestone = 1 full tank
		slotStone.stackSize--;

		if (slotStone.stackSize <= 0)
            {
                slotStone = null;
            }
	}

	//Check for inventory contents and process any items
	if(!worldObj.isRemote && this.canProcess() && this.stone >= 1)
	{
		this.processItem();
		this.markDirty();
	}
}

public int getStoneScaled(int scaled)
{
	return (int) (this.stone * scaled / TileGrindstone.MAX_STONE);
}

public ItemStack decrStackSize(int i, int j) 
{
		if(this.slot[i] != null)
		{
			ItemStack itemStack;

			if(this.slot[i].stackSize <= j)
			{
				itemStack = this.slot[i];
				this.slot[i] = null;
				return itemStack;
			}
			else
			{
				itemStack = this.slot[i].splitStack(j);

				if(this.slot[i].stackSize == 0)
				{
					this.slot[i] = null;
					this.setInventorySlotContents(i, itemStack);
				}

				return itemStack;
			}
		}

	return null;
}

public ItemStack getStackInSlot(int i) 
{
	return this.slot[i];
}

public ItemStack getStackInSlotOnClosing(int i) 
{
	if(this.slot[i] != null)
	{
		ItemStack itemStack = this.slot[i];
		this.slot[i] = null;
		return itemStack;
	}

	return null;
}

public boolean isItemValidForSlot(int slot, ItemStack itemStack)
{
	return slot == 2 ? false : true;
}

public boolean isUseableByPlayer(EntityPlayer entityPlayer) 
{
	return true;
}

public void setInventorySlotContents(int i, ItemStack itemStack) 
{
	this.slot[i] = itemStack;

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

public boolean canExtractItem(int i, ItemStack var2, int j) 
{
	return true;
}

public boolean canInsertItem(int slot, ItemStack itemStack, int side) 
{
	return this.isItemValidForSlot(slot, itemStack);
}

public int[] getAccessibleSlotsFromSide(int i) 
{
	return null;
}

/**
     * Returns true if the grindstone can smelt an item, i.e. has a source item, destination stack isn't full, etc.
     */
    private boolean canProcess()
    {
        if (this.slot[0] == null || this.stone == 0)
        {
            return false;
        }
        else
        {
            ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]);
            if (itemstack == null) return false;
            if (this.slot[2] == null) return true;
            if (!this.slot[2].isItemEqual(itemstack)) return false;
            int result = slot[2].stackSize + itemstack.stackSize;
            return result <= getInventoryStackLimit() && result <= this.slot[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
        }
    }

    /**
     * Turn one item from the grindstone source stack into the appropriate processed item in the furnace result stack
     */
    public void processItem()
    {
        if (this.canProcess())
        {
            ItemStack itemstack = GrindstoneRecipes.processing().getProcessResult(this.slot[0]);

            if (this.slot[2] == null)
            {
                this.slot[2] = itemstack.copy();
            }
            else if (this.slot[2].getItem() == itemstack.getItem())
            {
                this.slot[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items
            }

            --this.slot[0].stackSize;
            --this.stone;
            System.out.println(this.stone);

            if (this.slot[0].stackSize <= 0)
            {
                this.slot[0] = null;
            }
        }
    }
    
    public String getInventoryName() 
{
	return this.hasCustomInventoryName() ? this.customName : "container.grindstone";
}

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

public int getInventoryStackLimit() 
{
	return 64;
}

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

public void openInventory() {}
public void closeInventory() {}
}

 

I have no idea what I'm doing.

Link to comment
Share on other sites

Your stackSize == 0 check is broken. You only set the

slotStone

variable to null, but not the slot itself. You need to call setInventorySlotContents.

Also you should call markDirty when the stack size changes (you don't need to do that if you reach 0, because setInventorySlotContents will call it).

 

Ok I've tried this but I've got the same problem I had to start with. Here's my code now:

 

snip

 

 

I believe he is referring to the check in updateEntity()

if (slotStone.stackSize <= 0)
            {
                slotStone = null;
            }

Should be

if (slotStone.stackSize <= 0)
            {
                slotStone = null;
this.setInventorySlotContents(1, null);
            }

 

looks right but I could be wrong.

 

HOLD A MOMENT

 

ok he was probably referring to decrStackSize. notice, you put

this.setInventorySlotContents(i, itemStack);

it should be

this.setInventorySlotContents(i, null);

that sound right to the code gods?

even though he didn't mention updateEntity() i think you should probably do that anyway.

An average guy who mods Minecraft. If you need help and are willing to use your brain, don't be afraid to ask.

 

Also, check out the Unofficial Minecraft Coder Pack (MCP) Prerelease Center for the latest from the MCP Team!

 

Was I helpful? Leave some karma/thanks! :)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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