Jump to content

Recommended Posts

Posted

So recently i have been working on a block in my mod that when clicked with a book will insert that book inside and you can then remove the book with another click.

 

i have been able to add and remove the book as well as add a renderer for it. The problem is though that when i click the block with more then the max number for the inventory it takes all of them but doesn't give back the extra like it is supposed to.

 

Block Code:

 

  Reveal hidden contents

 

 

TileEntity Code:

 

  Reveal hidden contents

 

 

P.S. I know i shouldn't use Language Registry it is just i haven't got around to making a .lang file which has mostly been me being lazy.

BaseMod Code(Trimmed):

 

  Reveal hidden contents
Posted

1st: change topic name, your mod is not crashing

2nd: tell me if i got it right, you want to when a player insert a book on the block, but the block is already full, you want the block to drop all items + the overflowed item that the player placed in?

Posted

 

  Reveal hidden contents

 

TO

 

  Reveal hidden contents

 

Posted

Ok I think that if what you had doesn't work I may have discovered that on my add book method when I check if there are any books currently in the inventory it says no and then sets a book inside aswell as returning 0 so then my place book see that it is returning 0 so it removes the stack. I had it like this because it used to be able to hold 64 books but changed it to hold 1 because I felt 64 unnecessary. However when it was 64 and it had no books inside it, it knew it could hold as many where in the players hand so it didn't need to check how many where in his hand and just simply would always return 0 since the player couldn't hold more than 64.

Posted

working code:

 

Block:

	 public boolean placeBook(EntityPlayer entityPlayer, TileEntityDesk tileEntityDesk)
 {
	 ItemStack book = entityPlayer.getHeldItem();
	 if(book != null)
	 {
		 Item bookTest = book.getItem();
		 if(bookTest instanceof ItemBook)
		 {
			 int bookReturn = tileEntityDesk.addBook(book);
			 if(bookReturn == 0)
			 {
				 entityPlayer.inventory.mainInventory[entityPlayer.inventory.currentItem] = null;

			 }
			 if(bookReturn > 0)
			 {
				 book.stackSize = bookReturn;
				 entityPlayer.inventory.mainInventory[entityPlayer.inventory.currentItem] = book;
				 return true;
			 }
		 }
	 }

 

TileEntity:

        public int addBook(ItemStack book)
        {
        	if(book != null)
        	{
        		ItemStack deskBook = getStackInSlot(0);
        		if(deskBook == null && book.stackSize == getInventoryStackLimit())
        		{
        			setInventorySlotContents(0, book);
        			return 0;
        		}
        		if(deskBook == null && book.stackSize > getInventoryStackLimit())
        		{
        			int bookSize = book.stackSize;
        			book.stackSize -= getInventoryStackLimit();
        			setInventorySlotContents(0,book);
        			book.stackSize = bookSize;
        			return book.stackSize - getInventoryStackLimit();
        		}
        	}
        	else
    		{
    			setInventorySlotContents(0, book);
    			return 0;
    		}
        	return -1;
        }

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



×
×
  • Create New...

Important Information

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