Pallet Storage Help

Place to get help with not working mods / modding interface.

Pallet Storage Help

Postby Kynaro » Thu May 18, 2017 3:03 pm

I've made a 2x2 pallet storage as a modification of the wooden chest, and I'd like to have the item stacks in the inventory to show up in the world on top of the pallet.

Some of the code I'm starting with:

Code: Select all
--control.lua

global.pallets = global.pallets

function place_item_on_pallet(self, item)
   
   --get items from pallet inventory
   local palletItems = self.entity.inventory.get_content()

   --place items on open pallet space
   if self.entity.inventory_size > 0 and palletItems ~= nil then
      spill_item_stack(self.entity.position, palletItems(1))
   end
end


I'm not sure where to call that function - I'd prefer an event when the inventory gets changed so I'm not calling it every tick.

The idea here is that the player can simply walk over the pallet and pick up items without interacting with the inventory (which automatically removes the items out if they're picked up - I haven't gotten that far yet).

Any code references or other work I could look at would be much appreciated!
Kynaro
Burner Inserter
Burner Inserter
 
Posts: 9
Joined: Thu May 18, 2017 2:48 pm

Re: Pallet Storage Help

Postby kikker450 » Thu May 18, 2017 8:45 pm

I can assure you that properly scripting and designing that would be an absolute pain if you do any kind of stacking of items. You will need manual shadows for every stack of item of every size. If you you don't do that they will just be there, floating awkwardly. The thing you could do is do a single item and place them next to each-other for x amounts of stacks. But if you do that it would be kind of redundant because you can just press alt to see the most common items in that pallet.

To help you with your actual question, the way to do that is to check on ever tick_event whether the inventory of the pallet has changed and if it has you update the items on top of it. For the player to be able to pick it up you would need to write your own transfer system since the entities you can put on the pallet have to be custom, different entities from the actual items since they have collision.
kikker450
Inserter
Inserter
 
Posts: 29
Joined: Fri May 05, 2017 9:07 am

Re: Pallet Storage Help

Postby Kynaro » Fri May 19, 2017 3:34 am

Thanks Kikker,

The intended design is much like you suggested: single items placed for each stack in the inventory (assuming that items dropped in the world are 1/4 a grid cell, allowing up to 8 items to be dropped - which is the size of the pallet inventory). I don't mind the redundancy because of the visual cue I'm going for.

I didn't think items had collision, but that won't be a problem since I'm putting the entity on a different collision mask/layer.

I will try an event tick, test a single item, and go from there.
Kynaro
Burner Inserter
Burner Inserter
 
Posts: 9
Joined: Thu May 18, 2017 2:48 pm

Re: Pallet Storage Help

Postby Kynaro » Fri May 19, 2017 9:01 pm

I was able to get items to spill out, and in their correct values (which was interesting) for a single item. I'm working now to produce all the items placed on the pallet, position them correctly, and to not collide with the pallet entity.

I'm not getting errors from the inventory array for-loop, but it doesn't produce any spilled items.
Also an error when I build a new pallet: get_output_inventory() from the first check is nil.

Code: Select all
function place_item_on_pallet(self) --using palletInfo
if self ~= nill and self.get_output_inventory() ~= nil and hasSpilled == false then
   
local palletInventory = self.get_inventory(1)

   for item in pairs(palletInventory) do
      
      if item.valid_for_read then
         local itemName = item.name
         local itemCount = item.count
         self.surface.spill_item_stack(self.position, {name = itemName, count = itemCount})
            
         debug_log(self.name .. ": " .. itemName .. " Count: " .. itemCount)
            
      end
   end
end

function on_pallet_created(palletEntity)
   
   local palletInfo = create_pallet_info(palletEntity)
   
   table.insert(global.pallets, palletInfo)
   
   return palletInfo
end

That second function is where I try to update the list of pallets with the newly built one.

Again, any help is greatly appreciated!
Kynaro
Burner Inserter
Burner Inserter
 
Posts: 9
Joined: Thu May 18, 2017 2:48 pm

Re: Pallet Storage Help

Postby Kynaro » Sun May 21, 2017 8:57 pm

So I got everything to work as intended, except for the pallet's entity image always rendered over the spilled items. This is likely because of the collision mask I mentioned earlier - I made sure the pallet picture was a low priority, which did nothing.

In conclusion, spilling items onto the pallet isn't feasible right now. As Kikker450 said, the items placed on the pallet would actually have to be entities in the form of the item's image, with collision. Unless there's some fast way to prototype an entity that can mimic ALL of the game's items, I'll stop while I'm ahead.
Kynaro
Burner Inserter
Burner Inserter
 
Posts: 9
Joined: Thu May 18, 2017 2:48 pm

Re: Pallet Storage Help

Postby kikker450 » Sun May 21, 2017 9:15 pm

Thanks for the report, it's always nice to see conclusive posts. I didn't help with your second request because it was essentially bug fixing which you should figure out on your own.

Have tried figuring out how transport belt works so you can make a pallet that way?
kikker450
Inserter
Inserter
 
Posts: 29
Joined: Fri May 05, 2017 9:07 am

Re: Pallet Storage Help

Postby Kynaro » Sun May 21, 2017 9:36 pm

I did indeed look at transport belts! Although I couldn't find any definitive reason the belts rendered on the correct layer while my pallets wouldn't. The only working difference I could see was the entity type and that the belts are an animation while the pallet is just a sprite. Now that I think of it, I couldn't find the script defining how items get placed and moved around on belts...
Kynaro
Burner Inserter
Burner Inserter
 
Posts: 9
Joined: Thu May 18, 2017 2:48 pm


Return to Modding help

Who is online

Users browsing this forum: No registered users and 5 guests