Jump to content




[CC 1.5 | MC 1.4.7] Inventory Manager


  • You cannot reply to this topic
53 replies to this topic

#1 BombStrike

  • Members
  • 14 posts
  • LocationTokyo, Japan

Posted 14 January 2013 - 06:09 PM

Inventory Manager

As the name suggest, this is a set of peripherals oriented to managing inventories, it comes with 2 peripherals:
  • Player Manager
  • Inventory Manager
Player Manager

The player manager is a plate, connected to a computer on the side, and an inventory under it, that can detect players walking on it and manipulate their inventory.

Recipe:
Posted Image

Screenshots showing respectively the offline (no computer nearby), online (computer nearby but no player on plate) and active (player on the plate with computer nearby) states of the plate:
Spoiler

With this, you can do stuff like automatically detecting ores the player and send them to smelting, here is a video of a small contraption I made (click on the image):
Spoiler

Automatic Player Manager

This version of the player manager doesn't connect to computers, but can still be used by BuildCraft pipes, RedPower Sorting Machines and other mods manipulating inventories.

Recipe:
Posted Image

Inventory Manager

This block can connect to any inventory and pipe in 6 directions (beside the direction is connected from).
It has a 1 slot sized buffer for piped in items, accessible through a special inventory name: "buffer".

Recipe:
Posted Image

API

Ok so there is the current state of the API, if you have any remark please feel free to make a comment

APIs:
The mod adds an API in rom/apis named "invmanager" with a single method wrap() that will check the wrapped device type and map methods through a special wrapper.
See mods/invmanager-lua/invmanager.lua (created when you launch the game with the mod for the first time) for more details.

Methods:

size(direction)

Direction is a valid direction or inventory name, see below for a list of directions

read(direction, slot)

Read the item at the specified slot, returning details about the stack in this slot. Slot IDs start from 1 to the inventory size.

See below for the details on the details table.

move(directionFrom, directionTo, slotFrom = nil, slotTo = nil, amount = STACK_SIZE)

Moves a stack from the source inventory to a target inventory, with an optionally specified source and target slot, as well as a specified amount.

If slotFrom is not provided, finds the first item in the inventory and moves it.

If slotTo is not provided, finds the first available spot, if specified, try that spot first, then try the other slots.

Returns the same details as read() with an additional property moved that contains the amount of items moved by the command.

send(directionFrom, directionTo, slotFrom = 1, amount = STACK_SIZE)

Send a stack into a pipe, allowing you to chose from which slot and how much to send.

If slotFrom is not provided, finds the first item in the inventory and moves it.

Returns the same details as read() with an additional property sent that contains the amount of items sent into the pipe.

isInventory(direction)

Is the block at the given direction is a valid inventory?

isPipe(direction)

Is the block at the given direction is a valid pipe?


Types:

direction is either one of "player", "north", "east", "south", "west", "up", "down", "buffer". The plate only accepts "player" and "bottom", the inventory manager accept all but "player".

item A description of a stack, returned by read()

id The ID of the item

name The raw name of the item in the MC engine

display The actual translated name of the item (for display purposes)

amount The amount of items in the stack

damage The damage of the item


Events:
invmanager_in
Called when an item is piped inside an inventory manager. Use move or send with "buffer" as a source to move the received items where you want. The buffer has only 1 slot and the block will refuse any item entering as long as it is not cleared. The event provides the item description, see the example below .

Examples:

Show the details of every items in the player inventory:
-- see the usage of "invmanager" instead of "peripheral"
-- trying to use peripheral will prevent the methods from returning correctly
-- unless you manually listen for the event "invmanager_task"
m = invmanager.wrap("right")
-- read the player inventory size, then iterate on every slots
size = m.size("player")
for i=0,size-1 do
  -- read item in slot
  item = m.read("player", i)
  -- returns 0 if no item in the slot
  if item ~= 0 then
	print(item.amount, " ", item.display, " (", item.id, ") in slot ", i)
  end
end

Move everything from the player inventory to the inventory under the plate:
m = invmanager.wrap("right")
-- read the player inventory size, then iterate on every slots
size = m.size("player")
for i=0,size-1 do
  -- move stack in slot i
  item = m.move("player", i, "down")
end

Equip the first armor found in the inventory under it:
m = peripheral.wrap("right")
size = m.size("down")
-- armor slots
armor = {
  helmet = { slot = 39, equipped = false },
  chestplate = { slot = 38, equipped = false },
  leggings = { slot = 37, equipped = false },
  boots = { slot = 36, equipped = false }
}

-- check if the player already has some equipment
for k, v in pairs(armor) do
  if m.read("player", v.slot) ~= 0 then
	armor[k]["equipped"] = true
  end
end

-- try to equip the player
for i=0,size-1 do
  item = m.read("down", i)
  if item ~= 0 then
	for k, v in pairs(armor) do
	  if v.equipped == false and string.sub(item.name, 0, 5 + string.len(k)) == "item."..k then
		-- move armor from chest to player inventory
		res = m.move("down", i, "player", v.slot)
		print("Equipped "..item.display)
		v.equipped = true
	  end
	end
  end
end


Route piped items (like a diamond pipe)
-- wrap manager
m = invmanager.wrap("back")

-- our sorting function, for testing purposes route everything up
function sort(item)
  print("Routing "...item.display)
  m.send("buffer", "up")
end

-- if the buffer already has items
if m.read("buffer", 1) ~= 0 then
  m.send("buffer", "up")
end

-- wait for items to be piped in
while true do
  local event, item = os.pullEvent("invmanager_in")
  sort(item)
end

Download

Current version may not be 100% bug-free, even though it was tested by a panel of experts, I will not be responsible for lost items, chunk resets, explosions, lost limbs, demon spawning and other side effects that could occur while using the plates.

Current version (1.2.3): http://www.mediafire...ttvmqc10mf4ycfl
Previous versions:

Please report any bug you find in this thread, and I'll make sure to fix them as soon as possible.

Changelog

1.2.3 - API rewritten, inventory manager finally added
1.0 - First version, adds the player manager

Source Code

The source code is now hosted on https://github.com/c...ventory-manager
Feel free to do pull-request, assign me issues, etc...

Edited by BombStrike, 17 February 2013 - 04:57 PM.


#2 Mikeemoo

  • Members
  • 732 posts
  • LocationLondon, UK

Posted 14 January 2013 - 08:08 PM

Really neat idea!

#3 SilverSatin

  • Members
  • 10 posts

Posted 15 January 2013 - 06:15 AM

Awesome !

this is the only thing I need to complete my ( almost a month now ) stalled Banking system project.

I even re-started last weeekend to use and modify the CC-Bank scripts by "Scripter" which uses turtles.

But inventory manager wil give a way better support to A LOT of projects that are currently relying on turtles or redpower(cable) redstone signals.

can the player plate also import items into the players inventory ?

#4 BombStrike

  • Members
  • 14 posts
  • LocationTokyo, Japan

Posted 15 January 2013 - 12:34 PM

View PostSilverSatin, on 15 January 2013 - 06:15 AM, said:

can the player plate also import items into the players inventory ?

Yep, it can import anything located in the inventory under it, and put it in a defined slot (if the slot is not available, it will try to put it in the first available one)

#5 SilverSatin

  • Members
  • 10 posts

Posted 18 January 2013 - 05:22 AM

View PostBombStrike, on 15 January 2013 - 12:34 PM, said:

View PostSilverSatin, on 15 January 2013 - 06:15 AM, said:

can the player plate also import items into the players inventory ?

Yep, it can import anything located in the inventory under it, and put it in a defined slot (if the slot is not available, it will try to put it in the first available one)

absolute genius ! when this is done i would definitly want to be using this maybe even record & upload my first youtube video EVER :P
keep up the good work man when you make your release please quote on anything i say ( just so i get notified ) or send me a PM cause i really dont wanna mis this wonderful creation.

#6 Meni

  • Members
  • 59 posts

Posted 22 January 2013 - 02:50 PM

Awesome work guy! But can we remove for example a hat? Would be awesome to quick remove like a quantum suit and start to charging it or just change your clothes!
Im wating anxious for the download link!
Thank you.

#7 NeverCast

  • Members
  • 400 posts
  • LocationChristchurch, New Zealand

Posted 22 January 2013 - 05:29 PM

This is bloody brilliant! And since you provide both the ID, Display name and in game name, I can combine this with OpenCCSensors to easily teach the system about items. Just walk over it with items and it learns and my turtles are automagically updated with this new knowledge.

Sir! You are indeed, a Genius!
Fantastic! +1

#8 BombStrike

  • Members
  • 14 posts
  • LocationTokyo, Japan

Posted 23 January 2013 - 01:20 AM

I should be able to release a first version this weekend, I added a mod that allows it to work without a computer (using some kind of fuel) and tested it with RP2 Sorting Machines and Logistic Pipes successfully :D

View PostMeni, on 22 January 2013 - 02:50 PM, said:

Awesome work guy! But can we remove for example a hat? Would be awesome to quick remove like a quantum suit and start to charging it or just change your clothes!
Im wating anxious for the download link!
Thank you.

Yes you can read and move out/in armor slots (they are numbered slot 36 to 39).

#9 Ruffa-Duffa

  • Members
  • 42 posts

Posted 24 January 2013 - 09:16 PM

I clicked on this thinking it would be really boring... but now I can't wait for the download link! Thank you BombStrike! Is +1 a sorta a like thing or something? Well I hope so, +1 :P

#10 Simon

  • Members
  • 58 posts
  • LocationSeattle

Posted 27 January 2013 - 12:05 PM

Wow, can't wait for download ;)

#11 BombStrike

  • Members
  • 14 posts
  • LocationTokyo, Japan

Posted 27 January 2013 - 11:15 PM

Experimental version is ready to download, added a non computer-craft plate for operating with buildcraft pipes and similar mods, see OP for more details.

#12 Frederikam

  • Members
  • 112 posts
  • LocationDenmark

Posted 28 January 2013 - 01:13 AM

I like the idea, but I think the API needs a little more explanation.

#13 BombStrike

  • Members
  • 14 posts
  • LocationTokyo, Japan

Posted 28 January 2013 - 03:15 AM

I added a bunch of examples under the API, I hope that helps

#14 Frederikam

  • Members
  • 112 posts
  • LocationDenmark

Posted 28 January 2013 - 05:07 AM

Also is an object the same as an array?

#15 Meni

  • Members
  • 59 posts

Posted 28 January 2013 - 11:09 AM

I have a sugetion if inventory manager (todo) yould be cool if i culd interact with redpower pneumatic tubes by coloring they. Just an idea that i had.
Im traveling but when i get home i will test player inventory apears to be awesome!

#16 BombStrike

  • Members
  • 14 posts
  • LocationTokyo, Japan

Posted 28 January 2013 - 12:31 PM

View PostMeni, on 28 January 2013 - 11:09 AM, said:

I have a sugetion if inventory manager (todo) yould be cool if i culd interact with redpower pneumatic tubes by coloring they. Just an idea that i had.
Im traveling but when i get home i will test player inventory apears to be awesome!

Elooram doesn't allow mods to interact natively with it's tubes, you will need to have a setup with a sorting machine, relay or filters to do it.

#17 Ruffa-Duffa

  • Members
  • 42 posts

Posted 28 January 2013 - 03:59 PM

View PostFrederikam, on 28 January 2013 - 05:07 AM, said:

Also is an object the same as an array?
I could be completely wrong but I don't think either of those exist in lua... I'm at least fairly sure that in lua an array is called a table. As for an object if they're the same as they are in java then I don't think I've seen them in any computercraft programming. And since java has both objects and arrays I don't see why they would be the same. I think at least in java though you use objects exclusively for functions and there's no index thingies for objects. I haven't done anything in java but look over a bit of my old code in about 6 months so I'm probably not very reliable. I'm just kinda speaking off a 6 month old memory.

#18 BombStrike

  • Members
  • 14 posts
  • LocationTokyo, Japan

Posted 28 January 2013 - 04:01 PM

View PostFrederikam, on 28 January 2013 - 05:07 AM, said:

Also is an object the same as an array?

View PostRuffa-Duffa, on 28 January 2013 - 03:59 PM, said:

View PostFrederikam, on 28 January 2013 - 05:07 AM, said:

Also is an object the same as an array?
I could be completely wrong but I don't think either of those exist in lua... I'm at least fairly sure that in lua an array is called a table. As for an object if they're the same as they are in java then I don't think I've seen them in any computercraft programming. And since java has both objects and arrays I don't see why they would be the same. I think at least in java though you use objects exclusively for functions and there's no index thingies for objects. I haven't done anything in java but look over a bit of my old code in about 6 months so I'm probably not very reliable. I'm just kinda speaking off a 6 month old memory.

Yes sorry about that, they are just tables, I'm just not that used to LUA. I'll amend the documentation

#19 Frederikam

  • Members
  • 112 posts
  • LocationDenmark

Posted 28 January 2013 - 10:55 PM

View PostBombStrike, on 28 January 2013 - 04:01 PM, said:

View PostFrederikam, on 28 January 2013 - 05:07 AM, said:

Also is an object the same as an array?

View PostRuffa-Duffa, on 28 January 2013 - 03:59 PM, said:

View PostFrederikam, on 28 January 2013 - 05:07 AM, said:

Also is an object the same as an array?
I could be completely wrong but I don't think either of those exist in lua... I'm at least fairly sure that in lua an array is called a table. As for an object if they're the same as they are in java then I don't think I've seen them in any computercraft programming. And since java has both objects and arrays I don't see why they would be the same. I think at least in java though you use objects exclusively for functions and there's no index thingies for objects. I haven't done anything in java but look over a bit of my old code in about 6 months so I'm probably not very reliable. I'm just kinda speaking off a 6 month old memory.

Yes sorry about that, they are just tables, I'm just not that used to LUA. I'll amend the documentation

Thanks, also Lua is spelled "Lua" not "LUA" :P
As seen here: http://www.lua.org/about.html
But that's a minor detail.

#20 Meni

  • Members
  • 59 posts

Posted 31 January 2013 - 02:29 PM

When you use the .size("player") function and is no player on the inventory manager it returns:

Quote

java.lang.Exception: no player connected

You might use error() :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users