1
0
mirror of https://github.com/mt-mods/hangglider.git synced 2024-11-13 22:10:38 +01:00

up to 256 colors of glider with only one recipe

This commit is contained in:
OgelGames 2023-08-02 16:13:51 +10:00
parent 36261640d4
commit 97c655c16d
5 changed files with 111 additions and 26 deletions

View File

@ -7,4 +7,5 @@ read_globals = {
"vector", "ItemStack",
"player_monoids",
"unifieddyes",
}

101
crafts.lua Normal file
View File

@ -0,0 +1,101 @@
local get_dye_color
if minetest.get_modpath("unifieddyes") then
get_dye_color = unifieddyes.get_color_from_dye_name
else
local colors = {
white = "ffffff",
grey = "888888",
dark_grey = "444444",
black = "111111",
violet = "8000ff",
blue = "0000ff",
cyan = "00ffff",
dark_green = "005900",
green = "00ff00",
yellow = "ffff00",
brown = "592c00",
orange = "ff7f00",
red = "ff0000",
magenta = "ff00ff",
pink = "ff7f9f",
}
get_dye_color = function(name)
local color = string.match(name, "^dye:(%w+)$")
if color then
return colors[color]
end
end
end
local function get_color_name(name)
name = string.gsub(name, "^dye:", "")
name = string.gsub(name, "_", " ")
name = string.gsub(name, "(%l)(%w*)", function(a, b) return string.upper(a)..b end)
return name
end
-- This recipe is just a placeholder
do
local item = ItemStack("hangglider:hangglider")
item:get_meta():set_string("description", "Colored Glider")
minetest.register_craft({
output = item:to_string(),
recipe = {"hangglider:hangglider", "group:dye"},
type = "shapeless",
})
end
-- This is what actually creates the colored hangglider
minetest.register_on_craft(function(crafted_item, _, old_craft_grid)
if crafted_item:get_name() ~= "hangglider:hangglider" then
return
end
local wear, color, color_name
for _,stack in ipairs(old_craft_grid) do
local name = stack:get_name()
if name == "hangglider:hangglider" then
wear = stack:get_wear()
elseif minetest.get_item_group(name, "dye") ~= 0 then
color = get_dye_color(name)
color_name = get_color_name(name)
end
end
if wear and color and color_name then
if color == "ffffff" then
return ItemStack({name = "hangglider:hangglider", wear = wear})
end
local meta = crafted_item:get_meta()
meta:set_string("description", color_name.." Glider")
meta:set_string("inventory_image", "hangglider_item.png^(hangglider_color.png^[multiply:#"..color..")")
meta:set_string("hangglider_color", color)
crafted_item:set_wear(wear)
return crafted_item
end
end)
-- Repairing
minetest.register_craft({
output = "hangglider:hangglider",
recipe = {
{"default:paper", "default:paper", "default:paper"},
{"default:paper", "hangglider:hangglider", "default:paper"},
{"default:paper", "default:paper", "default:paper"},
},
})
minetest.register_craft({
output = "hangglider:hangglider",
recipe = {
{"hangglider:hangglider", "wool:white"},
},
})
-- Main craft
minetest.register_craft({
output = "hangglider:hangglider",
recipe = {
{"wool:white", "wool:white", "wool:white"},
{"default:stick", "", "default:stick"},
{"", "default:stick", ""},
}
})

View File

@ -181,6 +181,12 @@ local function hangglider_use(stack, player)
local entity = minetest.add_entity(pos, "hangglider:glider")
if entity then
entity:set_attach(player, "", vector.new(0, 10, 0), vector.new(0, 0, 0))
local color = stack:get_meta():get("hangglider_color")
if color then
entity:set_properties({
textures = {"wool_white.png^[multiply:#"..color, "default_wood.png"}
})
end
set_hud_overlay(player, name, "hangglider_overlay.png")
set_physics_overrides(player, {jump = 0, gravity = 0.25})
hanggliding_players[name] = true
@ -236,27 +242,4 @@ minetest.register_tool("hangglider:hangglider", {
on_use = hangglider_use,
})
minetest.register_craft({
output = "hangglider:hangglider",
recipe = {
{"default:paper", "default:paper", "default:paper"},
{"default:paper", "hangglider:hangglider", "default:paper"},
{"default:paper", "default:paper", "default:paper"},
},
})
minetest.register_craft({
output = "hangglider:hangglider",
recipe = {
{"hangglider:hangglider", "wool:white"},
},
})
minetest.register_craft({
output = "hangglider:hangglider",
recipe = {
{"wool:white", "wool:white", "wool:white"},
{"default:stick", "", "default:stick"},
{"", "default:stick", ""},
}
})
dofile(minetest.get_modpath("hangglider").."/crafts.lua")

View File

@ -1,4 +1,4 @@
name = hangglider
depends = default, wool
optional_depends = areas, player_monoids
depends = default, wool, dye
optional_depends = areas, player_monoids, unifieddyes
min_minetest_version = 5.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B