Jump to content

Shelf doesn't display Custom Items


zetake

Recommended Posts

Hi, I can put Custom Items on Shelves and take them back, but Shelf doesn't display their textures...

My guess is it doesn't take atlas from mod, but I don't know how to solve this or from where to begin...

Any ideas?

Link to comment
Share on other sites

I managed to do it in sorf of different way, but it works...

Spoiler

I made another idle animation for displaying items on shelves. (With different pivot_y)

in custom prefab fn()


	inst.bankname =	"name_of_bank"
	inst.buildname = "name_of_build"

in modmain

Spoiler


local function SetImage(inst, ent, slot)

    local src = ent
    local bank = nil
    local build = nil

    if src ~= nil and src.components.inventoryitem ~= nil then
        build = #(ent.buildname or "") > 0 and
            ent.buildname
        bank = #(ent.bankname or "") > 0 and
            ent.bankname
    end 

    if build ~= nil and bank ~= nil then 
        inst.AnimState:OverrideSymbol(slot, build, bank)
        inst.imagename = src ~= nil or ""
    else
        inst.imagename = ""
        inst.AnimState:ClearOverrideSymbol(slot)
    end
end 

AddClassPostConstruct("components/shelfer", function(self, inst)
	if self.buildandbank == nil then	-- to prevent running copies of this in this mod or other ones
		local SetArt = self.SetArt
		function self:SetArt()
			SetArt(self)
			
			local item = self.shelf.components.container:GetItemInSlot(self.slotindex)

			if item and item.buildname ~= nil and item.bankname ~= nil then
				SetImage(self.shelf, item, self.slot)
				self.inst:SetPrefabNameOverride(item.components.inspectable.nameoverride or item.prefab)
			end
		end
		self.buildandbank = true		-- to prevent running copies of this in this mod or other ones
	end
end)

 

 

So, mister Ultroman, it is okay to overrite it like this?

Link to comment
Share on other sites

On 8/7/2019 at 11:47 AM, zetake said:

I managed to do it in sorf of different way, but it works...

  Reveal hidden contents

I made another idle animation for displaying items on shelves. (With different pivot_y)

in custom prefab fn()



	inst.bankname =	"name_of_bank"
	inst.buildname = "name_of_build"

in modmain

  Reveal hidden contents



local function SetImage(inst, ent, slot)

    local src = ent
    local bank = nil
    local build = nil

    if src ~= nil and src.components.inventoryitem ~= nil then
        build = #(ent.buildname or "") > 0 and
            ent.buildname
        bank = #(ent.bankname or "") > 0 and
            ent.bankname
    end 

    if build ~= nil and bank ~= nil then 
        inst.AnimState:OverrideSymbol(slot, build, bank)
        inst.imagename = src ~= nil or ""
    else
        inst.imagename = ""
        inst.AnimState:ClearOverrideSymbol(slot)
    end
end 

AddClassPostConstruct("components/shelfer", function(self, inst)
	if self.buildandbank == nil then	-- to prevent running copies of this in this mod or other ones
		local SetArt = self.SetArt
		function self:SetArt()
			SetArt(self)
			
			local item = self.shelf.components.container:GetItemInSlot(self.slotindex)

			if item and item.buildname ~= nil and item.bankname ~= nil then
				SetImage(self.shelf, item, self.slot)
				self.inst:SetPrefabNameOverride(item.components.inspectable.nameoverride or item.prefab)
			end
		end
		self.buildandbank = true		-- to prevent running copies of this in this mod or other ones
	end
end)

 

 

So, mister Ultroman, it is okay to overrite it like this?

Oof, I wish I had found this post sooner to help you with this before you went through so much trouble. Klei actually (albeit possibly unintentionally) implemented a way to add shelf art for modded items awhile back through a simple override which they made to use for items with differing appearence depending on world (ex. logs, snakeskin, bannanas etc.). If memory serves, the line is something like "inst.shelfart = youranimfolder/yourprefabsanim", which you then put in your prefabs main function. You can just check the prefabs for the formerly mentioned items to get the exact line if I'm wrong, but this did the trick for me in a still currently unreleased mod of mine that I should probably get back to at some point. Hope this helped!

EDIT: Ignore this. When I wrote this I was less knowledgable about modding and didn't know exactly how shelfer worked. Turns out the only reason this solution worked for me was because the image I wanted was already in inventoryimages.tex at the time so it was really using that instead of mine. Apologies to whomever I confused with this.

Link to comment
Share on other sites

It doesn't work for me... shelfart is just alternative imagename...

And like I said: in my case AnimState can't access atlas from my mod.

So, animation instead of atlas and texture is my way...

 

Moreover I have more than 1 item texture in texture/animation...

Thus, it requires two names not one the same...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...