Destination inventory for on_picked_up_item
Destination inventory for on_picked_up_item
I'd like this event to also have one of the inventory defines (http://lua-api.factorio.com/latest/defi ... .inventory) specifying where the item went.
Re: Destination inventory for on_picked_up_item
The game doesn't know that until after it finishes the transfer and even then the place that fires the code doesn't know where it ended up.
Virtually nothing in the game knows information like that which makes it near impossible to add it to an event without a ton of reworking which I'm not willing to do.
Virtually nothing in the game knows information like that which makes it near impossible to add it to an event without a ton of reworking which I'm not willing to do.
If you want to get ahold of me I'm almost always on Discord.
Re: Destination inventory for on_picked_up_item
Sorry if I come across as rude, I'm just not a terribly social person. With respect, that information is contextual based on where the event is being fired, and since the event is fired after the item is already in the inventory I would think it should know that from where the dispatch is.
I know the event fires after the item was added to it's destination inventory because I can just look for it in the event handler itself:
Pastebin to make it easier to read: https://paste.whitefire.in/view/IzjqxogpC5
So I would think your event's control flow (psuedo-code) looks something like...
Pastebin https://paste.whitefire.in/view/9GWmw8R7Gi
How is the event being fired in such a way that the item has already been placed into it's destination inventory, but the destination is somehow unknown to the event dispatch? Perhaps I'm missing something obvious, but I can't imagine how your event system works if this information isn't available at that point.
Asking for clarification purely out of curiosity about what's going on internally. If it's impossible to reasonably implement so be it
EDIT: Unrelated, maybe you should look into some kind of code highlighting plugin. It's pretty difficult to read a block here. I added Pastebin links.
I know the event fires after the item was added to it's destination inventory because I can just look for it in the event handler itself:
Pastebin to make it easier to read: https://paste.whitefire.in/view/IzjqxogpC5
Code: Select all
script.on_event(defines.events.on_picked_up_item, function(event)
if(event.item_stack.name ~= 'fre_factory_transit') then
return
end
local player = game.players[event.player_index]
local item = nil
local check = {defines.inventory.player_main, defines.inventory.player_quickbar}
local inven = nil
for _, inv_id in pairs(check) do
inven = player.get_inventory(inv_id)
item = inven.find_item_stack('fre_factory_transit')
if(item ~= nil) then
break
end
end
if(item == nil) then
error('Failed to locate factory transit')
return
end
end)
Pastebin https://paste.whitefire.in/view/9GWmw8R7Gi
Code: Select all
-- recover the item this stack entity is holding
item_stack = entity.stack
if(item_stack.prototype.flags['goes-to-quickbar'] == true) then
inventory = player.get_inventory(quickbar)
else
inventory = player.get_inventory(hotbar)
end
if(inventory.can_insert(item_stack)) then
-- destroy the item_stack entity on the ground
entity.destroy()
-- place the item_stack in the inventory
inventory.insert(transform_SimpleItemStack_to_LuaItemStack(item_stack))
-- dispatch the event
event.dispatch(defines.events.on_picked_up_item, item_stack=item_stack)
end
Asking for clarification purely out of curiosity about what's going on internally. If it's impossible to reasonably implement so be it
EDIT: Unrelated, maybe you should look into some kind of code highlighting plugin. It's pretty difficult to read a block here. I added Pastebin links.
Re: Destination inventory for on_picked_up_item
What you've got there is a far simplified version of what actually ends up happening.
- Say you've got this super simple setup: http://imgur.com/ZirZHoe
- You press "F" to pick it up and it hits this line of code: http://imgur.com/YNHEwNi
- That does a virtual dispatch to the class that owns the builder interface (because it can be owned by a standalone character, character attached to a player, or the god controller) to transfer the item into what ever wants it.
- Deep inside the destination after several more virtual dispatches (because inventories have multiple types and where an item ends up depends on the item flags/health/durability/inventory state of whoever wants it (filters/existing items)) you end up here: http://imgur.com/cduZV2x
- Then after all of the transfer is finished you go back to the builder interface and it does the event dispatch of the item if it was actually transferred and it has absolutely no idea where it ended up because that's not part of the code in that class.
If you want to get ahold of me I'm almost always on Discord.
Re: Destination inventory for on_picked_up_item
That makes sense. It'd take a lot of refactoring to clean that up.
Thanks for the explanation.
Thanks for the explanation.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Destination inventory for on_picked_up_item
@Sirenfal see if this code is any help - I was mainly interested in when an item was dropped rather than picked up, but it could be refactored to work the other way, ie. when something is picked up.
viewtopic.php?p=213673#p213673
viewtopic.php?p=213673#p213673
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.
Re: Destination inventory for on_picked_up_item
I've been able to hack around these things successfully, it's just messyaubergine18 wrote:@Sirenfal see if this code is any help - I was mainly interested in when an item was dropped rather than picked up, but it could be refactored to work the other way, ie. when something is picked up.
viewtopic.php?p=213673#p213673
In this case I just checked all the inventories the item could have gone into. I don't think it's really avoidable, sadly