This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Sebra's profile picture

Events for external inventory change.

Started by Sebra, 20 October 2012 - 09:22 AM
Sebra #1
Posted 20 October 2012 - 11:22 AM
Please allow turtle to get events when something from outside change it's inventory. For now you can teach turtle to know slot 1 has a stone blocks and hope nobody change it.
I do not need events for successful dig/suck/attack because turtle knows about it. But when some turtle/pipe/tube/… push to or pull from inventory turtle is unaware of it.

So I suggest events:
"stack_push","side" - when something push a stack of items to turtle's inventory from that side;
"stack_pull","side" - when something pull a stack of items from turtle's inventory from that side;
"stack_changed",slot - when some player take/place/substitute something in turtle's inventory.

Slot needed for "stack_changed" event because player can exchange water bucket with lava for example. For other events turtle can detect slots itself.
Cloudy #2
Posted 20 October 2012 - 03:15 PM
Please allow turtle to get events when something from outside change it's inventory. For now you can teach turtle to know slot 1 has a stone blocks and hope nobody change it.
I do not need events for successful dig/suck/attack because turtle knows about it. But when some turtle/pipe/tube/… push to or pull from inventory turtle is unaware of it.

So I suggest events:
"stack_push","side" - when something push a stack of items to turtle's inventory from that side;
"stack_pull","side" - when something pull a stack of items from turtle's inventory from that side;
"stack_changed",slot - when some player take/place/substitute something in turtle's inventory.

Slot needed for "stack_changed" event because player can exchange water bucket with lava for example. For other events turtle can detect slots itself.

While its possible to throw an event when a player alters an inventory (was going to do that but forgot!) it is really hard to detect if something has changed without storing what we have every tick, and finding what is different every tick.

You can do that yourself from Lua if you just monitor the levels of what has changed anyway.
ChunLing #3
Posted 20 October 2012 - 05:05 PM
You can detect all the key and mouseclick events anyway, as well as get their exact values. So you can know if a player is messing with the inventory, and which inventory slots were accessed.
Sebra #4
Posted 21 October 2012 - 08:13 AM
While its possible to throw an event when a player alters an inventory (was going to do that but forgot!) it is really hard to detect if something has changed without storing what we have every tick, and finding what is different every tick.

You can do that yourself from Lua if you just monitor the levels of what has changed anyway.
Let it be event even if player exchange one water bucket with another. Let turtle detect player access to that slot. Program can assume slot content changed after it or not changed without it. Can you throw event on player attempt to access inventory, not on inventory changed?
Push/pull events cannot alternate items in slots, only quantity. Let program trace it.

Monitor levels? You mean quantity?
You can detect all the key and mouseclick events anyway, as well as get their exact values. So you can know if a player is messing with the inventory, and which inventory slots were accessed.
1.Only turtle has inventory, but it has no mouse support.
2.Mouse support was not released yet.
3.Mouse detected only in screen borders, not around.
Thanks for such an useful answer :)/>/>
bbqroast #5
Posted 21 October 2012 - 08:32 AM
Still should be added for tubes. Also, this would be much nicer for new users than having to write their own screen monitoring system. Maybe:
itemAdd slot
itemRemove slot
Sebra #6
Posted 21 October 2012 - 09:00 AM
If I'm not mistake Item stack inserted by tube can be split to several slots. So I ask for a side only. Program should determine slots itself.
All push/pull interactions cannot change item types. So slots can be determined but side can be useful.
Player interaction however can change item type without changing quantity. So we need event with slot pointed.
I want turtle to be able to detect even an empty click on an empty slot of inventory.
ChunLing #7
Posted 21 October 2012 - 10:01 AM
Can the mouse click events be extended to cover the inventory area?
Cloudy #8
Posted 21 October 2012 - 10:14 AM
I've already explained why it can't easily be done for tubes, and how it can easily be done yourself. Player inventory change is a lot more possible, since we are in control of the GUI that displays. I'm not going to allow detection of clicks on slots since that would make no sense whatsoever - I'll just look into throwing an event when a player changes the inventory - and probably the slot number.
Sebra #9
Posted 21 October 2012 - 11:53 AM
Slot number would needed because in some cases it is undetectable by program. Thanks.
It seems I missed your explanations why it can't easily be done for tubes. I understand your full control of turtle's GUI and player's actions in it. Is it means on Java side block do not have events of its inventory altered? Just as a fact. Slots can be determined by program. Side cannot so if possible only.
Some blocks even restrict some items to be pushed into slots…
To check inventory constantly is a quite bad way. To check it in right moments is a good one.
Cloudy #10
Posted 21 October 2012 - 12:31 PM
Slot number would needed because in some cases it is undetectable by program. Thanks.
It seems I missed your explanations why it can't easily be done for tubes. I understand your full control of turtle's GUI and player's actions in it. Is it means on Java side block do not have events of its inventory altered? Just as a fact. Slots can be determined by program. Side cannot so if possible only.
Some blocks even restrict some items to be pushed into slots…
To check inventory constantly is a quite bad way. To check it in right moments is a good one.

But we would have to check the inventory constantly on our end anyway. On the java side there are no events triggered. We can't even tell which side something has come into the turtle from.

Also no blocks can restrict what comes into their slots from a pipe using the default forge and minecraft API's. Which is what we use.
Sebra #11
Posted 21 October 2012 - 02:11 PM
I can mistake but after short test…
Forestry Arboretum:
- accept only Saplings and Humus from pipes.
- No restriction but different slots from different sides on turtle drop
IC2 Miner:
- place incoming Stack to one of four Slots based on side. be it turtle drop or pipes.

Also some post #13 confuse me :)/>/>
Cloudy #12
Posted 21 October 2012 - 02:58 PM
I can mistake but after short test…
Forestry Arboretum:
- accept only Saplings and Humus from pipes.
- No restriction but different slots from different sides on turtle drop
IC2 Miner:
- place incoming Stack to one of four Slots based on side. be it turtle drop or pipes.

Also some post #13 confuse me :)/>/>

Yes - because forestry uses the Buildcraft API.

And IC2 pipe is not a restriction - our own printer puts different things in different sides.

Anyway all this is quite off topic.
Sebra #13
Posted 21 October 2012 - 04:17 PM
So Forestry use BuildCraft API for this, not Forge or MC. Anyway it weak :)/>/>
Quick test with RP2 tubes shows they are ignore that restriction. Exactly as turtle.drop()
So last hope we have here is Forge hook added for this. Would you kindly ask Forge team about it?
Cloudy #14
Posted 21 October 2012 - 07:02 PM
So Forestry use BuildCraft API for this, not Forge or MC. Anyway it weak :)/>/>
Quick test with RP2 tubes shows they are ignore that restriction. Exactly as turtle.drop()
So last hope we have here is Forge hook added for this. Would you kindly ask Forge team about it?

They are working on a solution to that. But again this is off topic :)/>/>
Sebra #15
Posted 21 October 2012 - 07:09 PM
Thanks!
GopherAtl #16
Posted 14 November 2012 - 06:38 PM
wow, this got off the rails a bit…

found this doing a quick search, I just want an event for the inventory changing, separate drop/suck events would be even better but just an inventory_changed event would be plenty, I could use it to trigger a call to turtlex.updateInventory(), as I already track my inventory all the time so updateInventory will figure out what's added/removed and tell me. This would let me make programs much more tolerant to user "interference" while running, and also allow better automated interaction with other tech mods.