Jump to content

[SOLVED] [1.10.2] Problem with saving items in my pan


Recommended Posts

Posted

Whenever I connect to the world, my item in my pan disappear.

 

Block:

 

  Reveal hidden contents

 

 

TileEntity:

 

 

  Reveal hidden contents

 

 

Model:

 

  Reveal hidden contents

 

 

Render:

 

  Reveal hidden contents

 

Posted

Where is the object located that contains the items you want to save in the pan?

Posted

Perhaps this you wonder from ItemHandler.

 

 

  Reveal hidden contents

 

Posted

I would suggest you to not do that the way you are doing it now, it just doesn't really make sense. You should instead create an internal inventory for your pan and use that to handle the stacks. This inventory can then be written to and read from NBT.

Posted

Override the method onBlockActivated in your Block class and if the held item can be cooked in the pan get your TileEntity, get the inventory inside of it and place the ItemStack in the inventory.

Posted

    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
       TileEntityPan te = (TileEntityPan) world.getTileEntity(pos);
       
       if(!world.isRemote){
           if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isBurning())
           {
               heldItem.stackSize--;
           } else{
        	   player.openGui(Main.MODID, FC2_GuiHandler.PANGUI, world, pos.getX(), pos.getY(), pos.getZ());
           }
       }
       return true;
    }

 

And now I'm finished. :D I do not know how to put the item into the slot.

Posted

    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)

    {

      TileEntityPan te = (TileEntityPan) world.getTileEntity(pos);

      Container container = te.createContainer(player.inventory, player);

      Slot slot = (Slot)container.inventorySlots.get(0);

     

      if(!world.isRemote){

          if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isBurning())

          {

              slot.putStack(heldItem);

              heldItem.stackSize--;

          } else{

          player.openGui(Main.MODID, FC2_GuiHandler.PANGUI, world, pos.getX(), pos.getY(), pos.getZ());

          }

      }

      return true;

    }

 

But slot.putStack(heldItem); give me whole stack. But I only want one item, no stack.

Posted

You do know about stack splitting, yes?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

ItemStack newstack = stack.split(1);

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I figured it out myself.

 

    public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
       TileEntityPan te = (TileEntityPan) world.getTileEntity(pos);
       Container container = te.createContainer(player.inventory, player);
       Slot slot = (Slot)container.inventorySlots.get(0);
       
       if(!world.isRemote){
           if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isBurning())
           {
        	   ItemStack is = heldItem.splitStack(1);
               slot.putStack(is);
           } else{
        	   player.openGui(Main.MODID, FC2_GuiHandler.PANGUI, world, pos.getX(), pos.getY(), pos.getZ());
           }
       }
       return true;
    }

 

Thanks.

 

But I have a problem with the render pancakes.

 

 

  Reveal hidden contents

 

 

 

Posted

I have problem with render Pancakes. This code reports an error on    if(furnaceItemStacks[2].getItem() == ItemHandler.Pancakes)

 

 

 

  Reveal hidden contents

 

 

 

  Reveal hidden contents

 

Posted

"I have a problem with render" doesn't give us any clue about what's not working correctly? Is it not rendering? Is it rendering weird? Is it upside down? Please, be more specific.

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

There's only 1 thing in the Check method that can be

null

(I'm guessing it's an NPE). Figure it out and do a proper

null

-check.

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

    public boolean Check(){  	
    	if(panItemStacks[2].getItem() == ItemHandler.Pancakes)
    	{
    		return true;
    	}
    	return false;
    }

 

Tento kód nefunguje.

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.