Compare commits
9 Commits
9fd665aaa5
...
bbe7a14401
| Author | SHA1 | Date | |
|---|---|---|---|
| bbe7a14401 | |||
| ad521ce2b7 | |||
| 0d986dafd5 | |||
| f34c12c59f | |||
| 89bc05d2cb | |||
| 99093493c0 | |||
| 31d66277ae | |||
| 93d4b3145c | |||
| ed9a80b2cf |
@@ -10,13 +10,87 @@ local defMerge = function(...)
|
|||||||
return table.merge(...)
|
return table.merge(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param nodeDef Node.NodeDefinition
|
||||||
|
local function registerSlab(nodeDef)
|
||||||
|
nodeDef = table.copy_with_metatables(nodeDef)
|
||||||
|
|
||||||
|
local settings = nodeDef.settings
|
||||||
|
assert(settings.groups ~= nil)
|
||||||
|
settings._title = nil
|
||||||
|
settings._description = nil
|
||||||
|
settings.name = settings.name..'_slab'
|
||||||
|
settings.node_box = {
|
||||||
|
type = 'fixed',
|
||||||
|
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
|
||||||
|
}
|
||||||
|
settings.drawtype = 'nodebox'
|
||||||
|
settings.paramtype = 'light'
|
||||||
|
settings.paramtype2 = 'facedir'
|
||||||
|
settings.groups['segments'] = nil
|
||||||
|
settings.groups['slabs'] = 1
|
||||||
|
if nodeDef.callbacks ~= nil then
|
||||||
|
nodeDef.callbacks.on_place = core.rotate_and_place
|
||||||
|
else
|
||||||
|
nodeDef.callbacks = {on_place = core.rotate_and_place}
|
||||||
|
end
|
||||||
|
|
||||||
|
Node:new(nodeDef)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param nodeDef Node.NodeDefinition
|
||||||
|
local function registerStair(nodeDef)
|
||||||
|
nodeDef = table.copy_with_metatables(nodeDef)
|
||||||
|
|
||||||
|
local settings = nodeDef.settings
|
||||||
|
assert(settings.groups ~= nil)
|
||||||
|
settings._title = nil
|
||||||
|
settings._description = nil
|
||||||
|
settings.name = settings.name..'_stair'
|
||||||
|
settings.node_box = {
|
||||||
|
type = 'fixed',
|
||||||
|
fixed = {
|
||||||
|
{-0.5, -0.5, -0.5, 0.5, 0.0, 0.5},
|
||||||
|
{-0.5, 0.0, 0.0, 0.5, 0.5, 0.5},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
settings.drawtype = 'nodebox'
|
||||||
|
settings.paramtype = 'light'
|
||||||
|
settings.paramtype2 = 'facedir'
|
||||||
|
settings.groups['segments'] = nil
|
||||||
|
settings.groups['slabs'] = 1
|
||||||
|
if nodeDef.callbacks ~= nil then
|
||||||
|
nodeDef.callbacks.on_place = core.rotate_and_place
|
||||||
|
else
|
||||||
|
nodeDef.callbacks = {on_place = core.rotate_and_place}
|
||||||
|
end
|
||||||
|
|
||||||
|
Node:new(nodeDef)
|
||||||
|
end
|
||||||
|
|
||||||
---@param nodeDef Node.NodeDefinition
|
---@param nodeDef Node.NodeDefinition
|
||||||
---@return Node
|
---@return Node
|
||||||
function Node:new(nodeDef)
|
function Node:new(nodeDef)
|
||||||
---Adding default parameters
|
-- Adding default parameters.
|
||||||
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
nodeDef = defMerge(nodeDef, self.defaultDef, true)
|
||||||
|
|
||||||
nodeDef.settings._type = 'node'
|
local settings = nodeDef.settings
|
||||||
|
settings._type = 'node'
|
||||||
|
|
||||||
|
-- Registration of segmented blocks.
|
||||||
|
-- If you specify a specific group with a specific index for a node,
|
||||||
|
-- the slabs and stairs will be registered automatically.
|
||||||
|
local segmentsIndex = settings.groups and settings.groups['segments']
|
||||||
|
if segmentsIndex == 1 then
|
||||||
|
-- Only slabs
|
||||||
|
registerSlab(nodeDef)
|
||||||
|
elseif segmentsIndex == 2 then
|
||||||
|
-- Only stairs
|
||||||
|
registerStair(nodeDef)
|
||||||
|
elseif segmentsIndex == 3 then
|
||||||
|
-- Slabs & stairs
|
||||||
|
registerSlab(nodeDef)
|
||||||
|
registerStair(nodeDef)
|
||||||
|
end
|
||||||
|
|
||||||
---@type Node
|
---@type Node
|
||||||
local instance = Item:new(nodeDef)
|
local instance = Item:new(nodeDef)
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__core__player
|
name = smc__core__player
|
||||||
depends = smc__system__system_loader
|
depends = smc__system__system_loader, smc__ui__player_inventory
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ core.register_on_joinplayer(function(player)
|
|||||||
inv:set_size('equip_torso', 2)
|
inv:set_size('equip_torso', 2)
|
||||||
inv:set_size('equip_legs', 2)
|
inv:set_size('equip_legs', 2)
|
||||||
inv:set_size('equip_feet', 2)
|
inv:set_size('equip_feet', 2)
|
||||||
|
inv:set_size('listring_equip', 1) -- Slot for correct listring.
|
||||||
end)
|
end)
|
||||||
|
|
||||||
core.register_chatcommand('show_inv',
|
core.register_chatcommand('show_inv',
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ local MapGen = mapGenRequire('MapGen')
|
|||||||
sylite = 'rocks:sylite',
|
sylite = 'rocks:sylite',
|
||||||
syliteGray = 'rocks:sylite_gray',
|
syliteGray = 'rocks:sylite_gray',
|
||||||
syliteBlack = 'rocks:sylite_black',
|
syliteBlack = 'rocks:sylite_black',
|
||||||
tauitite = 'rocks:tauitite',
|
--tauitite = 'rocks:tauitite',
|
||||||
iyellite = 'rocks:iyellite',
|
--iyellite = 'rocks:iyellite',
|
||||||
falmyte = 'rocks:falmyte',
|
--falmyte = 'rocks:falmyte',
|
||||||
hapcoryte = 'rocks:hapcoryte',
|
--hapcoryte = 'rocks:hapcoryte',
|
||||||
burcite = 'rocks:burcite',
|
--burcite = 'rocks:burcite',
|
||||||
felhor = 'rocks:felhor',
|
--felhor = 'rocks:felhor',
|
||||||
malachite = 'rocks:malachite',
|
--malachite = 'rocks:malachite',
|
||||||
|
|
||||||
-- Liquids
|
-- Liquids
|
||||||
water = 'liquids:water_source',
|
water = 'liquids:water_source',
|
||||||
|
|||||||
@@ -4,20 +4,61 @@ local EquipTileSheet = TileSheet:new('equipment_sheet.png', 16, 16)
|
|||||||
|
|
||||||
Item:new({
|
Item:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = 'test_helmet',
|
name = 'linothorax',
|
||||||
inventory_image = EquipTileSheet:t(0, 0),
|
inventory_image = EquipTileSheet:t(0, 1),
|
||||||
groups = {
|
groups = {
|
||||||
equip_head = 2
|
equip_torso = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Item:new({
|
Item:new({
|
||||||
settings = {
|
settings = {
|
||||||
name = 'test_armor',
|
name = 'copper_lamellar_armor',
|
||||||
inventory_image = EquipTileSheet:t(1, 0),
|
inventory_image = EquipTileSheet:t(1, 1),
|
||||||
groups = {
|
groups = {
|
||||||
equip_torso = 2
|
equip_torso = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Item:new({
|
||||||
|
settings = {
|
||||||
|
name = 'bronze_breastplate',
|
||||||
|
inventory_image = EquipTileSheet:t(2, 1),
|
||||||
|
groups = {
|
||||||
|
equip_torso = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Item:new({
|
||||||
|
settings = {
|
||||||
|
name = 'bronze_knee_pads',
|
||||||
|
inventory_image = EquipTileSheet:t(2, 2),
|
||||||
|
groups = {
|
||||||
|
equip_legs = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Item:new({
|
||||||
|
settings = {
|
||||||
|
name = 'steel_boots',
|
||||||
|
inventory_image = EquipTileSheet:t(3, 3),
|
||||||
|
groups = {
|
||||||
|
equip_feet = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Item:new({
|
||||||
|
settings = {
|
||||||
|
name = 'steel_helmet',
|
||||||
|
inventory_image = EquipTileSheet:t(3, 0),
|
||||||
|
groups = {
|
||||||
|
equip_head = 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 24 KiB |
@@ -2,88 +2,173 @@ local Node, TileSheet = Smc.requireNode(), Smc.requireTileSheet()
|
|||||||
|
|
||||||
local PrimitiveCraftHandler = Smc.requireCraftSystemPrimitiveCraftHandler()
|
local PrimitiveCraftHandler = Smc.requireCraftSystemPrimitiveCraftHandler()
|
||||||
|
|
||||||
---@type Node.NodeDefinition
|
---@type TileSheet
|
||||||
local defaultRockDef = {
|
local rocksTileSheet = TileSheet:new("rocks_sheet.png", 16, 16)
|
||||||
|
|
||||||
|
---@class RockDef
|
||||||
|
---@field rarity Item.Rarity?
|
||||||
|
|
||||||
|
local function registerSegmentsCrafts(name, craftGroup)
|
||||||
|
PrimitiveCraftHandler:registerCraft(name..'_slab', {
|
||||||
|
recipe = {name},
|
||||||
|
output = name..'_slab',
|
||||||
|
group = craftGroup
|
||||||
|
})
|
||||||
|
|
||||||
|
PrimitiveCraftHandler:registerCraft(name..'_stair', {
|
||||||
|
recipe = {name},
|
||||||
|
output = name..'_stair',
|
||||||
|
group = craftGroup
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param name string
|
||||||
|
---@param y number
|
||||||
|
---@param def RockDef?
|
||||||
|
---@param staff {block:boolean?,bricks:boolean?,pillar:boolean?}
|
||||||
|
local function registerRock(name, y, def, staff)
|
||||||
|
if def == nil then
|
||||||
|
def = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local modPrefix = Mod.getInfo().shortName..':'
|
||||||
|
local craftGroup = 'rocks_'..name..'_staff'
|
||||||
|
|
||||||
|
-- Default rock
|
||||||
|
local defaultRock = Node:getExtended({
|
||||||
settings = {
|
settings = {
|
||||||
name = '',
|
name = '',
|
||||||
tiles = {},
|
_rarity = def.rarity,
|
||||||
groups = {
|
groups = {
|
||||||
|
rocks = 1,
|
||||||
dig_immediate = 2,
|
dig_immediate = 2,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Solid rock
|
||||||
|
defaultRock:new({
|
||||||
|
settings = {
|
||||||
|
name = name,
|
||||||
|
tiles = {{ name = rocksTileSheet:t(0, y), align_style='world'}},
|
||||||
|
groups = {
|
||||||
|
segments = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
registerSegmentsCrafts(modPrefix..name, craftGroup)
|
||||||
|
|
||||||
|
-- Chipped rock
|
||||||
|
local chippedRockName = name..'_chipped'
|
||||||
|
defaultRock:new({
|
||||||
|
settings = {
|
||||||
|
name = chippedRockName,
|
||||||
|
tiles = {{ name = rocksTileSheet:t(1, y), align_style='world'}},
|
||||||
|
groups = {
|
||||||
|
segments = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
registerSegmentsCrafts(modPrefix..chippedRockName, craftGroup)
|
||||||
|
|
||||||
|
if staff.block == true then
|
||||||
|
-- Solid rock block
|
||||||
|
local blockName = name..'_block'
|
||||||
|
defaultRock:new({
|
||||||
|
settings = {
|
||||||
|
name = name..'_block',
|
||||||
|
tiles = {{ name = rocksTileSheet:t(3, y), align_style='world'}},
|
||||||
|
groups = {
|
||||||
|
segments = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
registerSegmentsCrafts(modPrefix..blockName, craftGroup)
|
||||||
|
|
||||||
|
PrimitiveCraftHandler:registerCraft(blockName, {
|
||||||
|
recipe = {modPrefix..name},
|
||||||
|
output = modPrefix..blockName,
|
||||||
|
group = craftGroup,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
if staff.bricks == true then
|
||||||
|
-- Solid rock bricks
|
||||||
|
local bricksName = name..'_bricks'
|
||||||
|
defaultRock:new({
|
||||||
|
settings = {
|
||||||
|
name = bricksName,
|
||||||
|
tiles = {{ name = rocksTileSheet:t(4, y), align_style='world'}},
|
||||||
|
groups = {
|
||||||
|
segments = 3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
registerSegmentsCrafts(modPrefix..bricksName, craftGroup)
|
||||||
|
|
||||||
|
PrimitiveCraftHandler:registerCraft(bricksName, {
|
||||||
|
recipe = {modPrefix..name},
|
||||||
|
output = modPrefix..bricksName,
|
||||||
|
group = craftGroup,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
if staff.pillar == true then
|
||||||
|
local columnTopTexture = rocksTileSheet:t(9, y)
|
||||||
|
|
||||||
|
-- Fluted column
|
||||||
|
defaultRock:new({
|
||||||
|
settings = {
|
||||||
|
name = name..'_fluted_column',
|
||||||
|
tiles = {
|
||||||
|
columnTopTexture,
|
||||||
|
columnTopTexture,
|
||||||
|
rocksTileSheet:t(6, y)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
---@type Node
|
-- Ionic chapiter
|
||||||
local defaultRock = Node:getExtended(defaultRockDef)
|
defaultRock:new({
|
||||||
|
settings = {
|
||||||
local rockFactory = defaultRock:getFactory()
|
name = name..'_ionic_chapiter',
|
||||||
|
tiles = {
|
||||||
---@type TileSheet
|
rocksTileSheet:t(3, y),
|
||||||
local ts = TileSheet:new("rocks_sheet.png", 16, 16)
|
columnTopTexture,
|
||||||
|
rocksTileSheet:t(7, y),
|
||||||
local function registerRocksTypes(postfix, x)
|
rocksTileSheet:t(7, y),
|
||||||
rockFactory:registerNodesByShortDef({
|
rocksTileSheet:t(8, y),
|
||||||
{"sylite"..postfix, {ts:t(x, 0)}},
|
rocksTileSheet:t(8, y)
|
||||||
{"sylite_gray"..postfix, {ts:t(x, 1)}},
|
}
|
||||||
{"sylite_black"..postfix, {ts:t(x, 2)}},
|
}
|
||||||
{"tauitite_light"..postfix, {ts:t(x, 3)}},
|
|
||||||
{"tauitite_pink"..postfix, {ts:t(x, 4)}},
|
|
||||||
{"tauitite"..postfix, {ts:t(x, 5)}},
|
|
||||||
{"falmyte_light"..postfix, {ts:t(x, 6)}},
|
|
||||||
{"falmyte_yellow"..postfix, {ts:t(x, 7)}},
|
|
||||||
{"falmyte_red"..postfix, {ts:t(x, 8)}},
|
|
||||||
{"falmyte_dark"..postfix, {ts:t(x, 9)}},
|
|
||||||
{"iyellite"..postfix, {ts:t(x, 14)}},
|
|
||||||
{"falmyte"..postfix, {ts:t(x, 14)}},
|
|
||||||
{"hapcoryte"..postfix, {ts:t(x, 14)}},
|
|
||||||
{"burcite"..postfix, {ts:t(x, 14)}},
|
|
||||||
{"felhor"..postfix, {ts:t(x, 14)}},
|
|
||||||
{"malachite"..postfix, {ts:t(x, 14)}}
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function registerPilarStaff(rock, y)
|
|
||||||
local columnTop = ts:t(9, y)
|
|
||||||
|
|
||||||
rockFactory:registerNodesByShortDef({
|
|
||||||
{rock..'_fluted_column', {columnTop, columnTop, ts:t(6, y)}},
|
|
||||||
{rock..'_ionic_chapiter', {
|
|
||||||
ts:t(3, y),
|
|
||||||
columnTop,
|
|
||||||
ts:t(7, y),
|
|
||||||
ts:t(7, y),
|
|
||||||
ts:t(8, y),
|
|
||||||
ts:t(8, y)}},
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
registerPilarStaff('sylite', 0)
|
-- Sylite group
|
||||||
registerPilarStaff('sylite_gray', 1)
|
registerRock('sylite', 0, {}, {block = true, bricks = true, pillar = true})
|
||||||
registerPilarStaff('sylite_black', 2)
|
registerRock('sylite_gray', 1, {}, {block = true, bricks = true, pillar = true})
|
||||||
|
registerRock('sylite_black', 2, {}, {block = true, bricks = true, pillar = true})
|
||||||
|
|
||||||
registerRocksTypes('', 0)
|
-- Tauitite group
|
||||||
registerRocksTypes('_chipped', 1)
|
registerRock('tauitite_light', 3, {}, {block = true, bricks = true})
|
||||||
registerRocksTypes('_block', 3)
|
registerRock('tauitite_pink', 4, {}, {block = true, bricks = true})
|
||||||
registerRocksTypes('_bricks', 4)
|
registerRock('tauitite_black', 5, {}, {block = true, bricks = true})
|
||||||
registerRocksTypes('_bricks_2', 5)
|
|
||||||
|
|
||||||
PrimitiveCraftHandler:registerCraft('rocks:sylite_fluted_column', {
|
-- Falmyte group
|
||||||
recipe = {
|
registerRock('falmyte_light', 6, {}, {block = true, bricks = true})
|
||||||
'rocks:sylite'
|
registerRock('falmyte_yellow', 7, {}, {block = true, bricks = true})
|
||||||
},
|
registerRock('falmyte_red', 8, {}, {block = true, bricks = true})
|
||||||
output = 'rocks:sylite_fluted_column',
|
registerRock('falmyte_dark', 9, {}, {block = true, bricks = true})
|
||||||
})
|
|
||||||
|
|
||||||
PrimitiveCraftHandler:registerCraft('rocks:sylite_ionic_chapiter', {
|
-- TODO:
|
||||||
recipe = {
|
-- iyellite
|
||||||
'rocks:sylite'
|
-- falmyte
|
||||||
},
|
-- hapcoryte
|
||||||
output = 'rocks:sylite_ionic_chapiter',
|
-- burcite
|
||||||
})
|
-- felhor
|
||||||
|
-- malachite
|
||||||
PrimitiveCraftHandler:registerCraft('rocks:sylite_bricks_2', {
|
|
||||||
recipe = {
|
|
||||||
'rocks:sylite'
|
|
||||||
},
|
|
||||||
output = 'rocks:sylite_bricks_2',
|
|
||||||
})
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 151 KiB After Width: | Height: | Size: 151 KiB |
@@ -116,6 +116,7 @@ local function registerWood(name, x, def)
|
|||||||
},
|
},
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
_rarity = def.rarity,
|
_rarity = def.rarity,
|
||||||
|
groups = {segments = 1}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -219,6 +220,7 @@ local function registerWood(name, x, def)
|
|||||||
name = name..'_planks',
|
name = name..'_planks',
|
||||||
tiles = { woodTileSheet:t(x, 6) },
|
tiles = { woodTileSheet:t(x, 6) },
|
||||||
_rarity = def.rarity,
|
_rarity = def.rarity,
|
||||||
|
groups = {segments = 3},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
name = smc__ui__player_inventory
|
name = smc__ui__player_inventory
|
||||||
depends = smc__core__formspec
|
depends = smc__core__formspec, smc__core__tilesheet
|
||||||
|
|||||||
@@ -449,4 +449,132 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('.+::craft_item', function(play
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
---Automatically places equipment items into their corresponding slots.
|
||||||
|
---@param player Player
|
||||||
|
---@param inventory InvRef
|
||||||
|
---@param fromList string
|
||||||
|
---@param fromIndex integer
|
||||||
|
local function equipListring(player, inventory, fromList, fromIndex)
|
||||||
|
local itemStack = inventory:get_stack(fromList, fromIndex)
|
||||||
|
assert(itemStack ~= nil)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
|
||||||
|
-- We check whether the item has a group that matches the equipment slot.
|
||||||
|
-- If so, we move the item to the slot.
|
||||||
|
--
|
||||||
|
-- We also check if the target slot is empty.
|
||||||
|
-- If it's already occupied, we prevent items from being moved.
|
||||||
|
--
|
||||||
|
-- TODO: дописать автолистринг для одежды
|
||||||
|
if core.get_item_group(itemStack:get_name(), 'equip_head') == 2 then
|
||||||
|
if not inventory:get_stack('equip_head', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_head', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif core.get_item_group(itemStack:get_name(), 'equip_torso') == 2 then
|
||||||
|
if not inventory:get_stack('equip_torso', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_torso', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif core.get_item_group(itemStack:get_name(), 'equip_legs') == 2 then
|
||||||
|
if not inventory:get_stack('equip_legs', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_legs', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
elseif core.get_item_group(itemStack:get_name(), 'equip_feet') == 2 then
|
||||||
|
if not inventory:get_stack('equip_feet', 2):is_empty() then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
inventory:set_stack('equip_feet', 2, itemStack)
|
||||||
|
inventory:set_stack(fromList, fromIndex, nil)
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
return
|
||||||
|
|
||||||
|
else
|
||||||
|
-- If an item does not have any equipment groups,
|
||||||
|
-- then we prohibit its movement (the item remains in its original location)
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We only allow items to be placed in equipment slot
|
||||||
|
-- that have groups that match the slot name and index.
|
||||||
|
core.register_allow_player_inventory_action(function(player, action, inventory, inventoryInfo)
|
||||||
|
if action == 'move' then
|
||||||
|
-- If the move occurs in a special slot, then we add the item to the desired slot.
|
||||||
|
-- This is necessary to bypass the standard listring[] limitation.
|
||||||
|
-- Equipment items will automatically place themselves in their slots
|
||||||
|
-- when you hold down the shift key.
|
||||||
|
if inventoryInfo.to_list == 'listring_equip' then
|
||||||
|
return equipListring(player, inventory, inventoryInfo.from_list, inventoryInfo.from_index)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Checking if a slot is an equipment slot.
|
||||||
|
local equipGroup = string.match(inventoryInfo.to_list, 'equip_%S+')
|
||||||
|
if equipGroup == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We receive the item that the player wants to place in the equipment slot.
|
||||||
|
local itemStack = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index)
|
||||||
|
assert(itemStack ~= nil)
|
||||||
|
|
||||||
|
if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.to_index then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
elseif action == 'put' then
|
||||||
|
-- Checking if a slot is an equipment slot.
|
||||||
|
local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+')
|
||||||
|
if equipGroup == nil then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- We receive the item that the player wants to place in the equipment slot.
|
||||||
|
local itemStack = inventory:get_stack(inventoryInfo.listname, inventoryInfo.index)
|
||||||
|
assert(itemStack ~= nil)
|
||||||
|
|
||||||
|
if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.index then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Update the interface if the player has moved something from the equipment slots
|
||||||
|
-- (this enables and disables the slot overlay).
|
||||||
|
core.register_on_player_inventory_action(function(player, action, inventory, inventoryInfo)
|
||||||
|
local playerName = player:get_player_name()
|
||||||
|
if action == 'move' then
|
||||||
|
local equipGroup = string.match(inventoryInfo.to_list, 'equip_%S+') or string.match(inventoryInfo.from_list, 'equip_%S+')
|
||||||
|
if equipGroup ~= nil then
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end
|
||||||
|
elseif action == 'put' then
|
||||||
|
local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+')
|
||||||
|
if equipGroup ~= nil then
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end
|
||||||
|
elseif action == 'take' then
|
||||||
|
local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+')
|
||||||
|
if equipGroup ~= nil then
|
||||||
|
PlayerInventoryUI:showForm(playerName)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
return PlayerInventoryUI
|
return PlayerInventoryUI
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
local Formspec = Smc.requireFormspec()
|
local Formspec, TileSheet = Smc.requireFormspec(), Smc.requireTileSheet()
|
||||||
|
|
||||||
|
local slotsOverlayTileSheet = TileSheet:new('player_inventory_equip_tab_armor_slots_overlay_sheet.png', 16, 16)
|
||||||
|
|
||||||
---@param self PlayerInventoryUI
|
---@param self PlayerInventoryUI
|
||||||
---@param playerName string
|
---@param playerName string
|
||||||
@@ -19,46 +21,44 @@ local function getEquipTab(self, playerName, tabType)
|
|||||||
:list('current_player', 'equip_torso', equipListsX, 2.25, 2, 1)
|
:list('current_player', 'equip_torso', equipListsX, 2.25, 2, 1)
|
||||||
:list('current_player', 'equip_legs', equipListsX, 3.5, 2, 1)
|
:list('current_player', 'equip_legs', equipListsX, 3.5, 2, 1)
|
||||||
:list('current_player', 'equip_feet', equipListsX, 4.75, 2, 1)
|
:list('current_player', 'equip_feet', equipListsX, 4.75, 2, 1)
|
||||||
|
-- Hidden equipment slot for correct listing
|
||||||
|
-- (distribute equipment across its slots while holding shift):
|
||||||
|
:list('current_player', 'listring_equip', 0, 0, 1, 1)
|
||||||
|
:listring({
|
||||||
|
{'current_player', 'main'},
|
||||||
|
{'current_player', 'listring_equip'},
|
||||||
|
{'current_player', 'main'},
|
||||||
|
{'current_player', 'equip_head'},
|
||||||
|
{'current_player', 'main'},
|
||||||
|
{'current_player', 'equip_torso'},
|
||||||
|
{'current_player', 'main'},
|
||||||
|
{'current_player', 'equip_legs'},
|
||||||
|
{'current_player', 'main'},
|
||||||
|
{'current_player', 'equip_feet'},
|
||||||
|
{'current_player', 'main'},
|
||||||
|
})
|
||||||
|
|
||||||
|
local player = core.get_player_by_name(playerName)
|
||||||
|
assert(player)
|
||||||
|
|
||||||
|
local inv = player:get_inventory()
|
||||||
|
|
||||||
|
-- If the equipment slots are empty, then we apply an overlay.
|
||||||
|
-- TODO: оверлей одежды
|
||||||
|
if inv:get_stack('equip_head', 2):is_empty() then
|
||||||
|
EquipTab:image(equipListsX+1.25, 1, 1, 1, slotsOverlayTileSheet:t(0,0))
|
||||||
|
end
|
||||||
|
if inv:get_stack('equip_torso', 2):is_empty() then
|
||||||
|
EquipTab:image(equipListsX+1.25, 2.25, 1, 1, slotsOverlayTileSheet:t(0,1))
|
||||||
|
end
|
||||||
|
if inv:get_stack('equip_legs', 2):is_empty() then
|
||||||
|
EquipTab:image(equipListsX+1.25, 3.5, 1, 1, slotsOverlayTileSheet:t(0,2))
|
||||||
|
end
|
||||||
|
if inv:get_stack('equip_feet', 2):is_empty() then
|
||||||
|
EquipTab:image(equipListsX+1.25, 4.75, 1, 1, slotsOverlayTileSheet:t(0,3))
|
||||||
|
end
|
||||||
|
|
||||||
return EquipTab
|
return EquipTab
|
||||||
end
|
end
|
||||||
|
|
||||||
-- We only allow items to be placed in equipment slot
|
|
||||||
-- that have groups that match the slot name and index.
|
|
||||||
core.register_allow_player_inventory_action(function(player, action, inventory, inventoryInfo)
|
|
||||||
if action == 'move' then
|
|
||||||
-- Checking if a slot is an equipment slot.
|
|
||||||
local equipGroup = string.match(inventoryInfo.to_list, 'equip_%S+')
|
|
||||||
if equipGroup == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- We receive the item that the player wants to place in the equipment slot.
|
|
||||||
local itemStack = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index)
|
|
||||||
assert(itemStack ~= nil)
|
|
||||||
|
|
||||||
if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.to_index then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
elseif action == 'put' then
|
|
||||||
-- Checking if a slot is an equipment slot.
|
|
||||||
local equipGroup = string.match(inventoryInfo.listname, 'equip_%S+')
|
|
||||||
if equipGroup == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- We receive the item that the player wants to place in the equipment slot.
|
|
||||||
local itemStack = inventory:get_stack(inventoryInfo.listname, inventoryInfo.index)
|
|
||||||
assert(itemStack ~= nil)
|
|
||||||
|
|
||||||
if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.index then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return getEquipTab
|
return getEquipTab
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
Submodule util/ide-helper updated: 19803a076d...8b995b5176
Reference in New Issue
Block a user