Jump to content

Recommended Posts

Posted

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.

Posted

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/

Posted

Well this made stone act normally, but the last one in the stack still eternally remains and eternally fills up the meter. Thanks so far though.

I have no idea what I'm doing.

Posted

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.

Posted

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! :)

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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