Jump to content

Recommended Posts

I need helps with my mod Pageable Backpack . 

When I run a game without cave , it worked well. When I run a game with cave enabled,some code doesn't work.

I use "AddComponentPostInit("container", modContainer)" to rewrite some function about take/swap items in container slot, but these function worked like I never rewrote them.

local function modContainer( self )
    local old_TakeActiveItemFromAllOfSlot = self.TakeActiveItemFromAllOfSlot
    local old_SwapActiveItemWithSlot = self.SwapActiveItemWithSlot
    local old_MoveItemFromAllOfSlot = self.MoveItemFromAllOfSlot
    -----------------------------------------
    local containers = require("containers")
    -- -------rewite function--------
    self.TakeActiveItemFromAllOfSlot = function ( self, slot )
        local item = self:GetItemInSlot(slot)
        if item == nil then return end
        if item.prefab == "qh_button" then
            item.components.page:NextPage()
            return
        end
        if item.prefab == "sx_button" then

            return
        end
        old_TakeActiveItemFromAllOfSlot(self, slot)
    end
    ---------
    self.SwapActiveItemWithSlot = function ( self, slot )
        local item = self:GetItemInSlot(slot)
        if item == nil then return end
        if item.prefab == "qh_button" then
            item.components.page:NextPage()
            return
        end
        if item.prefab == "sx_button" then

            return
        end
        old_SwapActiveItemWithSlot(self, slot)
    end
    ---------
    self.MoveItemFromAllOfSlot = function ( self, slot, container )
        local item = self:GetItemInSlot(slot)
        if item == nil then return end
        if item.prefab == "qh_button" then
            item.components.page:NextPage()
            return
        end
        if item.prefab == "sx_button" then

            return
        end
        old_MoveItemFromAllOfSlot(self, slot, container)
    end
    ---------
    ---------
end

 

modmain.lua

Don't have time to look at your problem, but if your question is "how to mod replicas", maybe this code about builder component replica is helpful:
 

-- builder mod for client
AddClassPostConstruct("components/builder_replica",  function(self)
	local _CanLearn = self.CanLearn
	self.CanLearn = function(self, recname)
        local recipe = GLOBAL.GetValidRecipe(recname)
        if recipe~=nil and not recipetestfn(recname,recipe,self.inst) then -- add a custom recipetestfn test
            return false
        else
            return _CanLearn(self, recname) 
        end
	end
end)

 

Edited by Serpens

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...