mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 18:41:09 +01:00
Add new mcl_paintings mod
This commit is contained in:
parent
72c7f01ad6
commit
52d0fa6a5c
7 changed files with 200 additions and 0 deletions
1
mods/ITEMS/mcl_paintings/depends.txt
Normal file
1
mods/ITEMS/mcl_paintings/depends.txt
Normal file
|
@ -0,0 +1 @@
|
|||
mcl_core?
|
1
mods/ITEMS/mcl_paintings/description.txt
Normal file
1
mods/ITEMS/mcl_paintings/description.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Decorative paintings which you can placed on walls.
|
150
mods/ITEMS/mcl_paintings/init.lua
Normal file
150
mods/ITEMS/mcl_paintings/init.lua
Normal file
|
@ -0,0 +1,150 @@
|
|||
-- TODO: Move all textures to mcl_paintings when finished
|
||||
|
||||
-- Intllib
|
||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
local S, NS = dofile(MP .. "/intllib.lua")
|
||||
|
||||
minetest.register_craftitem("mcl_paintings:painting", {
|
||||
description = S("Next-Gen Painting"),
|
||||
_doc_items_longdesc = S("Paintings are decorations which can be placed on walls. THIS ITEM IS INCOMPLETE."),
|
||||
wield_image = "gemalde_node.png",
|
||||
inventory_image = "gemalde_node.png",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
local under = pointed_thing.under
|
||||
local above = pointed_thing.above
|
||||
-- Am I right-clicking on something that has a custom on_rightclick set?
|
||||
if placer and not placer:get_player_control().sneak then
|
||||
if minetest.registered_nodes[under.name] and minetest.registered_nodes[under.name].on_rightclick then
|
||||
return minetest.registered_nodes[under.name].on_rightclick(pointed_thing.under, under, placer, itemstack) or itemstack
|
||||
end
|
||||
end
|
||||
|
||||
-- Can only be placed on side
|
||||
if under.y ~= above.y then
|
||||
return itemstack
|
||||
end
|
||||
-- Can only be placed on solid nodes
|
||||
local undernode = minetest.get_node(under)
|
||||
if minetest.get_item_group(undernode.name, "solid") == 0 then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Spawn painting and rotate
|
||||
local painting = minetest.add_entity(above, "mcl_paintings:painting")
|
||||
local yaw = minetest.dir_to_yaw(vector.direction(under, above))
|
||||
painting:set_yaw(yaw)
|
||||
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
itemstack:take_item()
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
-- List of painting IDs, indexed by size.
|
||||
-- Outer index: Width in node lengths
|
||||
-- Inner index: Height in node lengths
|
||||
local paintings = {
|
||||
[1] = {
|
||||
[1] = { 1, 2, 3, 4, 5, 6, 7 }, -- 1×1
|
||||
[2] = { 8, 9, 10, 11, 12 }, -- 1×2
|
||||
},
|
||||
[2] = {
|
||||
[1] = { 13, 14}, -- 2×1
|
||||
[2] = { 15, 16, 17, 18, 19, 20 }, -- 2×2
|
||||
},
|
||||
[3] = {
|
||||
[4] = { 25, 26 }, -- 3×4
|
||||
},
|
||||
[4] = {
|
||||
[2] = { 21 }, -- 4×2
|
||||
[4] = { 22, 23, 24 }, -- 4×4
|
||||
},
|
||||
}
|
||||
|
||||
-- Returns a random painting ID for the given size.
|
||||
-- x: Width in node lenghts
|
||||
-- y: Height in node lengths
|
||||
local function select_painting(x, y)
|
||||
if paintings[x] then
|
||||
local pool = paintings[x][y]
|
||||
if paintings[x][y] then
|
||||
local p = math.random(1, #pool)
|
||||
return p
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Returns the texture table for the given painting ID
|
||||
local get_textures = function(painting_id)
|
||||
return {
|
||||
"gemalde_bg.png",
|
||||
"gemalde_bg.png",
|
||||
"gemalde_bg.png",
|
||||
"gemalde_bg.png",
|
||||
"gemalde_"..tostring(painting_id)..".png",
|
||||
"gemalde_bg.png"
|
||||
}
|
||||
end
|
||||
|
||||
-- Painting entitty.
|
||||
-- Can be killed.
|
||||
-- Breaks and drops as item if punched.
|
||||
--
|
||||
minetest.register_entity("mcl_paintings:painting", {
|
||||
physical = false,
|
||||
collide_with_objects = true,
|
||||
hp_max = 1,
|
||||
-- TODO: Fix visual
|
||||
visual = "cube",
|
||||
visual_size = { x=1, y=1 },
|
||||
textures = get_textures(1),
|
||||
|
||||
_painting = nil, -- Holds the current painting ID. Initially nil for random painting
|
||||
|
||||
get_staticdata = function(self)
|
||||
local out = { _painting = self._painting }
|
||||
return minetest.serialize(out)
|
||||
end,
|
||||
on_activate = function(self, staticdata)
|
||||
if staticdata and staticdata ~= "" then
|
||||
local inp = minetest.deserialize(staticdata)
|
||||
self._painting = inp._painting
|
||||
end
|
||||
-- Initial spawn. Select random painting
|
||||
if not self._painting then
|
||||
self._painting = select_painting(1, 1)
|
||||
end
|
||||
self.object:set_properties({textures = get_textures(self._painting)})
|
||||
end,
|
||||
on_punch = function(self, puncher)
|
||||
if not puncher or not puncher:is_player() or self._removed then
|
||||
return
|
||||
end
|
||||
-- Drop painting as item on ground
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
minetest.add_item(self.object:getpos(), "mcl_paintings:painting")
|
||||
end
|
||||
self._removed = true
|
||||
self.object:remove()
|
||||
end
|
||||
})
|
||||
|
||||
--[[
|
||||
-- TODO: Add crafting when this mod works better
|
||||
if minetest.get_modpath("mcl_core") then
|
||||
minetest.register_craft({
|
||||
output = "mcl_paintings:painting",
|
||||
recipe = {
|
||||
{"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},
|
||||
{"mcl_core:stick", "group:wool", "mcl_core:stick"},
|
||||
{"mcl_core:stick", "mcl_core:stick", "mcl_core:stick"},
|
||||
}
|
||||
})
|
||||
end
|
||||
]]
|
45
mods/ITEMS/mcl_paintings/intllib.lua
Normal file
45
mods/ITEMS/mcl_paintings/intllib.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
-- Fallback functions for when `intllib` is not installed.
|
||||
-- Code released under Unlicense <http://unlicense.org>.
|
||||
|
||||
-- Get the latest version of this file at:
|
||||
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
|
||||
|
||||
local function format(str, ...)
|
||||
local args = { ... }
|
||||
local function repl(escape, open, num, close)
|
||||
if escape == "" then
|
||||
local replacement = tostring(args[tonumber(num)])
|
||||
if open == "" then
|
||||
replacement = replacement..close
|
||||
end
|
||||
return replacement
|
||||
else
|
||||
return "@"..open..num..close
|
||||
end
|
||||
end
|
||||
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
||||
end
|
||||
|
||||
local gettext, ngettext
|
||||
if minetest.get_modpath("intllib") then
|
||||
if intllib.make_gettext_pair then
|
||||
-- New method using gettext.
|
||||
gettext, ngettext = intllib.make_gettext_pair()
|
||||
else
|
||||
-- Old method using text files.
|
||||
gettext = intllib.Getter()
|
||||
end
|
||||
end
|
||||
|
||||
-- Fill in missing functions.
|
||||
|
||||
gettext = gettext or function(msgid, ...)
|
||||
return format(msgid, ...)
|
||||
end
|
||||
|
||||
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
|
||||
return format(n==1 and msgid or msgid_plural, ...)
|
||||
end
|
||||
|
||||
return gettext, ngettext
|
1
mods/ITEMS/mcl_paintings/mod.conf
Normal file
1
mods/ITEMS/mcl_paintings/mod.conf
Normal file
|
@ -0,0 +1 @@
|
|||
name = mcl_paintings
|
|
@ -9,3 +9,4 @@ gemalde
|
|||
mcl_observers
|
||||
doc_identifier
|
||||
mobs_mc
|
||||
mcl_paintings
|
||||
|
|
|
@ -18,6 +18,7 @@ local wip_items = {
|
|||
"mcl_core:cobweb",
|
||||
"mobs_mc:llama",
|
||||
"mobs_mc:totem",
|
||||
"mcl_paintings:painting",
|
||||
}
|
||||
|
||||
for i=1,#wip_items do
|
||||
|
|
Loading…
Reference in a new issue