Use unifieddyes' version of some functions

This commit is contained in:
Carter Kolwey 2017-01-25 12:58:49 -06:00
parent 3c8abcdb4a
commit a675b3b277
3 changed files with 4 additions and 107 deletions

@ -1,2 +1,3 @@
homedecor homedecor
moreblocks moreblocks
unifieddyes

110
init.lua

@ -1,77 +1,3 @@
local function getpaletteidx(color)
local aliases = {
["pink"] = "light_red",
["brown"] = "dark_orange",
}
local grayscale = {
["white"] = 1,
["light_grey"] = 2,
["grey"] = 3,
["dark_grey"] = 4,
["black"] = 5,
}
local hues = {
["red"] = 1,
["orange"] = 2,
["yellow"] = 3,
["lime"] = 4,
["green"] = 5,
["aqua"] = 6,
["cyan"] = 7,
["skyblue"] = 8,
["blue"] = 9,
["violet"] = 10,
["magenta"] = 11,
["redviolet"] = 12,
}
local shades = {
[""] = 1,
["s50"] = 2,
["light"] = 3,
["medium"] = 4,
["mediums50"] = 5,
["dark"] = 6,
["darks50"] = 7,
}
if string.sub(color,1,4) == "dye:" then
color = string.sub(color,5,-1)
elseif string.sub(color,1,12) == "unifieddyes:" then
color = string.sub(color,13,-1)
else
return
end
color = aliases[color] or color
if grayscale[color] then
return(grayscale[color])
end
local shade = ""
if string.sub(color,1,6) == "light_" then
shade = "light"
color = string.sub(color,7,-1)
elseif string.sub(color,1,7) == "medium_" then
shade = "medium"
color = string.sub(color,8,-1)
elseif string.sub(color,1,5) == "dark_" then
shade = "dark"
color = string.sub(color,6,-1)
end
if string.sub(color,-4,-1) == "_s50" then
shade = shade.."s50"
color = string.sub(color,1,-5)
end
if hues[color] and shades[shade] then
return(hues[color] * 8 + shades[shade])
end
end
minetest.register_node("plasticbox:plasticbox", { minetest.register_node("plasticbox:plasticbox", {
description = "Plastic Box", description = "Plastic Box",
tiles = {"plasticbox_white.png"}, tiles = {"plasticbox_white.png"},
@ -79,39 +5,9 @@ minetest.register_node("plasticbox:plasticbox", {
groups = {choppy=1, snappy=1, oddly_breakable_by_hand=1}, groups = {choppy=1, snappy=1, oddly_breakable_by_hand=1},
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
paramtype2 = "color", paramtype2 = "color",
palette = "plasticbox_ud_palette.png", palette = "unifieddyes_palette.png",
on_destruct = function(pos) on_destruct = unifieddyes.on_destruct,
local meta = minetest.get_meta(pos) on_rightclick = unifieddyes.on_rightclick,
local prevdye = meta:get_string("dye")
if minetest.registered_items[prevdye] then
minetest.add_item(pos,prevdye)
end
end,
on_rightclick = function(pos,node,player,stack)
local name = player:get_player_name()
if minetest.is_protected(pos,name) and not minetest.check_player_privs(name,{protection_bypass=true}) then
minetest.record_protection_violation(pos,name)
return stack
end
local name = stack:get_name()
local paletteidx = getpaletteidx(name)
if paletteidx then
local meta = minetest.get_meta(pos)
local prevdye = meta:get_string("dye")
if minetest.registered_items[prevdye] then
local inv = player:get_inventory()
if inv:room_for_item("main",prevdye) then
inv:add_item("main",prevdye)
else
minetest.add_item(pos,prevdye)
end
end
meta:set_string("dye",name)
stack:take_item()
node.param2 = paletteidx
minetest.swap_node(pos,node)
end
end,
}) })
stairsplus:register_all("plasticbox", "plasticbox", "plasticbox:plasticbox", { stairsplus:register_all("plasticbox", "plasticbox", "plasticbox:plasticbox", {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 443 B