94 lines
4.1 KiB
Lua
94 lines
4.1 KiB
Lua
-- ^ and : need escaping if they are in parentheses...
|
|
local texmod_escape = function(s)
|
|
local p_c = 0 -- parentheses_count
|
|
local n_s = ""
|
|
for i = 0, #s do
|
|
local c = s:sub(i,i)
|
|
if c == "(" then
|
|
p_c = p_c + 1
|
|
elseif c == ")" then
|
|
p_c = p_c - 1
|
|
elseif c == "^" and p_c > 0 then
|
|
c = ("\\"):rep(math.pow(2, p_c-1)) .. c
|
|
elseif c == ":" and p_c > 0 then
|
|
c = ("\\"):rep(math.pow(2, p_c-1)) .. c
|
|
end
|
|
n_s = n_s .. c
|
|
end
|
|
return n_s
|
|
end
|
|
|
|
hidden_doors.create_door_texture = function (texture, resolution)
|
|
-- in case of a high-res texturepack, but a low-res texture from another mod, we need to upscale the given texture
|
|
texture = "doors_trapdoor.png^[opacity:0^" .. texture
|
|
|
|
local base = "doors_door_wood.png^[opacity:0"
|
|
-- in case of a low-res texturepack, but a high-res texture from another mod we have to upscale the door image
|
|
if resolution and resolution > 16 then
|
|
local width = resolution * 38 / 16
|
|
local height = resolution * 2
|
|
base = base .. ("^[fill:%i,%i:0,0:#0000)"):format(width, height)
|
|
end
|
|
|
|
-- ------------------------------------------------------------------------------------------------------------
|
|
-- see snippet_create_texture.lua for the idea behind this
|
|
|
|
-- flip the texture around y, place it onto the base texture, flip the whole texture again
|
|
local t_2 = ("%s^[combine:0x0:0,0=(%s^[transform6)^[transform6"):format(base, texture)
|
|
-- t1 can be placed and is already in the correct position
|
|
local t_12 = ("%s^[combine:0x0:0,0=(%s)"):format(t_2, texture)
|
|
|
|
-- idea: flip t_12 around y and rotate 2x
|
|
-- first rotation brings the textures to places 1 & 3
|
|
local t_34_rot = ("%s^[combine:0x0:0,0=(%s^[transform6^[transform3)"):format(base, t_12)
|
|
local t_34 = ("%s^[combine:0x0:0,0=(%s^[transform3)"):format(base, t_34_rot)
|
|
|
|
-- 5 & 6 are only the sides of the door, it should be good enough to mirror t_12
|
|
local t_56 = ("%s^[transform4"):format(t_12)
|
|
|
|
-- t_34 and t_56 overlap, make sure t_34 is on top
|
|
local img = ("%s^[combine:0x0:0,0=(%s):0,0=(%s):0,0=(%s)"):format(base, t_56, t_34, t_12)
|
|
|
|
return texmod_escape(img)
|
|
-- return texmod_escape(img)
|
|
end
|
|
|
|
hidden_doors.create_inventory_image = function (texture, resolution)
|
|
-- in case of a high-res texturepack, but a low-res texture from another mod, we need to upscale the given texture
|
|
texture = "doors_trapdoor.png^[opacity:0^" .. texture
|
|
|
|
local base = "doors_door_wood.png^[opacity:0"
|
|
-- in case of a low-res texturepack, but a high-res texture from another mod we have to upscale the door image
|
|
if resolution and resolution > 16 then
|
|
base = base .. ("^[fill:%i,%i:0,0:#0000)"):format(resolution, resolution * 2)
|
|
end
|
|
|
|
-- flip the texture around y, place it onto the base texture, flip the whole texture again
|
|
local t_2 = ("%s^[combine:0x0:0,0=(%s^[transform6)^[transform6"):format(base, texture)
|
|
-- t1 can be placed and is already in the correct position
|
|
local t_12 = ("%s^[combine:0x0:0,0=%s"):format(t_2, texture)
|
|
|
|
return texmod_escape(t_12)
|
|
end
|
|
|
|
|
|
hidden_doors.register_from_node = function (name, basenode, resolution, recipe)
|
|
local basedef = core.registered_nodes[basenode]
|
|
if not basedef then print(basenode) return end
|
|
|
|
doors.register(name, {
|
|
description = ("hidden %s door"):format(basedef.description),
|
|
inventory_image = hidden_doors.create_inventory_image(basedef.tiles[1], resolution),
|
|
tiles = {{ name = hidden_doors.create_door_texture(basedef.tiles[1], resolution), backface_culling = true }},
|
|
groups = {
|
|
door = 1,
|
|
dig_immediate = basedef.groups.dig_immediate,
|
|
crumbly = basedef.groups.crumbly,
|
|
cracky = basedef.groups.cracky,
|
|
snappy = basedef.groups.snappy,
|
|
choppy = basedef.groups.choppy,
|
|
},
|
|
sound_open = (basedef.groups.crumbly and "hidden_doors_stone_door_open.ogg"),
|
|
sound_close = (basedef.groups.crumbly and "hidden_doors_stone_door_close.ogg"),
|
|
})
|
|
end |