Get a inventory's (Tile entity) max slot for looping through slots purpose

Started by Linkdeous on

Topic category: Help with modding (Java Edition)

Last seen on 17:09, 12. Mar 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Get a inventory's (Tile entity) max slot for looping through slots purpose

Hello! Im searching how to get a inventory's max number of slot from a tile entity !
What i'm trying to do is to make a entity that can grab/deposit from containers, and for that i need to check each slot of any given chest,hopper,container,modded,vanilla, .... and try to grab a item if there is one, or deposit one if there is space/a slot that fit the item the entity is holding

So far i'm trying to use custom code snippets, but as always, making them work is such a pain in the ass, i'm trying to make use of the getSizeInventory(), but so far, can't make it work at all
This is the code i had so far, but doesnt work
 

 

 

I would really like any help if possible !!!! 
 

 

 

Last seen on 17:09, 12. Mar 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
found a solution thanks to…
Tue, 08/29/2023 - 14:30

found a solution thanks to Van over discord, here's a custom snippet for anyone that would need to get the slot number ! 
say your local variable for max slot of block at x,y,z is named numb : 


BlockPos pos = new BlockPos((int) x, (int) y,(int) z);
BlockEntity blockEntity = world.getBlockEntity(pos);
 if (blockEntity instanceof Container) {
   numb = (((Container) blockEntity).getContainerSize())-1;
 } else numb=-1;

it will return slot 0 for a inventory with 1 slot (because the slot count starts at 0), and -1 if it doesnt have an inventory, usefull for checking if you should do or not your inventory checks !

Last seen on 17:09, 12. Mar 2024
Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(and of course it will…
Tue, 08/29/2023 - 14:31

(and of course it will return 26 for the max slot of a chest, 2 for the max slot of a furnace, any number of max slot for a modded container,...!)

Last seen on 10:35, 14. May 2024
Joined Jan 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
if i tryed it, i cannot find…
Mon, 11/27/2023 - 18:08

if i tryed it, i cannot find out what i need to import. Can you say me what things i need to have imported?