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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • My journey with Wizard Web Recovery began with skepticism, as I had already been burned once. However, desperate times called for desperate measures. I reached out to them, and from the onset, their professionalism was evident. They took  time to understand my situation, reassured me of their expertise, and provided a detailed plan on how they intended to recover my lost Bitcoin. Wizard Web Recovery stands out for several reasons. Firstly, their team comprises highly skilled professionals who specialize in blockchain technology and cyber forensics. This expertise is crucial when dealing with the complexities of cryptocurrency theft. They explained every step of the process to me, ensuring I was well-informed and comfortable with their approach. Communication with Wizard Web Recovery was seamless. They maintained regular updates, keeping me in the loop about the progress they were making. This transparency was something I had not experienced with other firms I had contacted. It built my confidence in their ability to deliver on their promises. Another significant aspect of Wizard Web Recovery is its ethical approach. They operate with integrity, ensuring that every action they take is within legal boundaries. In a field rife with scams and false promises, their commitment to ethical practices is a breath of fresh air. They provided me with all necessary documentation and evidence of their progress, which further reassured me of their legitimacy. The actual recovery process was nothing short of impressive. Wizard Web Recovery used advanced techniques to trace the stolen Bitcoin through the blockchain. They were able to identify the wallets it had been transferred to and worked tirelessly to negotiate the return of my funds. The level of detail and precision they demonstrated was extraordinary. By the end of the process, Wizard Web Recovery had successfully recovered my lost Bitcoin. The relief and gratitude I felt were overwhelming. It was not just about the money but about restoring my faith in the possibility of justice and recovery in the cryptocurrency world. Wizard Web Recovery turned my nightmare into a success story. Their expertise, transparency, ethical approach, and relentless effort make them the best in the business. If you are in a similar situation, do not hesitate to reach out to them. They are proof that amidst the darkness of scams, there are still trustworthy experts dedicated to helping you recover your digital assets.  
    • My journey with Wizard Web Recovery began with skepticism, as I had already been burned once. However, desperate times called for desperate measures. I reached out to them, and from the onset, their professionalism was evident. They took  time to understand my situation, reassured me of their expertise, and provided a detailed plan on how they intended to recover my lost Bitcoin. Wizard Web Recovery stands out for several reasons. Firstly, their team comprises highly skilled professionals who specialize in blockchain technology and cyber forensics. This expertise is crucial when dealing with the complexities of cryptocurrency theft. They explained every step of the process to me, ensuring I was well-informed and comfortable with their approach. Communication with Wizard Web Recovery was seamless. They maintained regular updates, keeping me in the loop about the progress they were making. This transparency was something I had not experienced with other firms I had contacted. It built my confidence in their ability to deliver on their promises. Another significant aspect of Wizard Web Recovery is its ethical approach. They operate with integrity, ensuring that every action they take is within legal boundaries. In a field rife with scams and false promises, their commitment to ethical practices is a breath of fresh air. They provided me with all necessary documentation and evidence of their progress, which further reassured me of their legitimacy. The actual recovery process was nothing short of impressive. Wizard Web Recovery used advanced techniques to trace the stolen Bitcoin through the blockchain. They were able to identify the wallets it had been transferred to and worked tirelessly to negotiate the return of my funds. The level of detail and precision they demonstrated was extraordinary. By the end of the process, Wizard Web Recovery had successfully recovered my lost Bitcoin. The relief and gratitude I felt were overwhelming. It was not just about the money but about restoring my faith in the possibility of justice and recovery in the cryptocurrency world. Wizard Web Recovery turned my nightmare into a success story. Their expertise, transparency, ethical approach, and relentless effort make them the best in the business. If you are in a similar situation, do not hesitate to reach out to them. They are proof that amidst the darkness of scams, there are still trustworthy experts dedicated to helping you recover your digital assets.   Contact Below:   Mail - wizard webrecovery@ programmer . net
    • Well don't I feel dumb, thank you as always @TileEntity you're the GOAT
    • Here is my code: @Mod.EventBusSubscriber(modid = Mod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class PlayerRenderModifications { @SubscribeEvent public static void prePlayerRender(RenderPlayerEvent.Pre evt) { RenderSystem.setShaderColor(0.0F, 1.0F, 1.0F, 1.0F); } @SubscribeEvent public static void postPlayerRender(RenderPlayerEvent.Post evt) { RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); } } This code is supposed to tint the player blue, however it doesn't tint the player at all (yes i know it only runs in f5 mode or when rendering players in multiplayer). I had also done some testing and it seems if I remove "postPlayerRender" then it tints the player, and also tints everything else that renders after the player (like other entities, clouds, etc.)   If you need me to provide other information then go ahead and ask!
  • Topics

×
×
  • Create New...

Important Information

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