1
0
mirror of https://github.com/mt-mods/unifieddyes.git synced 2025-07-22 18:20:25 +02:00

Compare commits

...

13 Commits

Author SHA1 Message Date
3fc82f9245 Add zh_CN translation (#24) 2025-06-16 07:16:56 +02:00
82f026fc7e Replace depracated use_texture_alpha boolean value with "opaque"... (#22)
...for newer servers
2025-01-09 07:01:00 +01:00
de6e2e0e35 Fix nil crash when calling unifieddyes.on_dig() w/o PlayerRef (#21) 2024-04-19 15:41:56 +02:00
3e45f316a3 coloured nodes aren't ground content (#19) 2024-03-07 07:14:22 +01:00
ecd05bfd90 Bump min_minetest_version to "5.5.0" (#17)
closes #16
2023-11-27 22:04:35 +11:00
5af9254c3a fix logic of unifieddyes.on_dig to conform w/ documentation (#15) 2023-11-23 17:05:42 +01:00
36c8bb5f5b fix https://github.com/mt-mods/unifieddyes/issues/11#issuecomment-1469934442 - syntac formating for translation files(remove whitespace) - make wuzzy happy 2023-03-15 22:11:08 -07:00
96a939c069 Airbrush: Fix dye selection by not relying on internal behaviour of minetest.serialize (#10) 2022-09-11 11:49:23 +02:00
878377301f respect the shift click convention and fix unreachable if else(if) tree 2022-05-29 10:29:47 -04:00
2af4f1fb98 Revert "workaround for engine bug in crafting, placing, digging items with a palette index of 0"
This reverts commit eb5610fc10.
2022-05-07 16:50:23 +10:00
c079888023 workaround patch for https://github.com/minetest-mods/i3/issues/68 closes https://github.com/mt-mods/unifieddyes/issues/7 2022-04-23 22:37:55 -04:00
ed895734f2 fix luacheck error 2022-04-15 17:58:13 -04:00
26994e39f2 fix https://github.com/mt-mods/unifieddyes/issues/6 2022-03-29 23:01:55 -04:00
8 changed files with 390 additions and 218 deletions

View File

@ -455,14 +455,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return
end
else
local s1 = string.sub(minetest.serialize(fields), 11)
local s3 = string.sub(s1,1, string.find(s1, '"')-1)
local color, _ = next(fields)
local inv = player:get_inventory()
local creative = minetest.is_creative_enabled(player_name)
local dye = "dye:"..s3
local dye = "dye:"..color
if (showall or unifieddyes.palette_has_color[nodepalette.."_"..s3]) and
if (showall or unifieddyes.palette_has_color[nodepalette.."_"..color]) and
(creative or inv:contains_item("main", dye)) then
unifieddyes.player_selected_dye[player_name] = dye
unifieddyes.show_airbrush_form(player)
@ -474,7 +473,7 @@ end)
minetest.register_tool("unifieddyes:airbrush", {
description = S("Dye Airbrush"),
inventory_image = "unifieddyes_airbrush.png",
use_texture_alpha = true,
use_texture_alpha = core.features.use_texture_alpha_string_modes and "opaque" or true,
tool_capabilities = {
full_punch_interval=0.1,
},
@ -490,6 +489,10 @@ minetest.register_tool("unifieddyes:airbrush", {
if pos then node = minetest.get_node(pos) end
if node then def = minetest.registered_items[node.name] end
if keys.sneak and def and def.on_rightclick then
return def.on_rightclick(pos, node, placer, itemstack, pointed_thing)
end
unifieddyes.player_last_right_clicked[player_name] = {pos = pos, node = node, def = def}
if not keys.aux1 then
@ -504,8 +507,6 @@ minetest.register_tool("unifieddyes:airbrush", {
else
minetest.chat_send_player(player_name, "*** That node is uncolored.")
end
elseif def.on_rightclick then
return def.on_rightclick(pos, node, placer, itemstack, pointed_thing)
end
end
})

View File

@ -1,5 +1,7 @@
if minetest.get_modpath("dye") then
minetest.register_alias("dye:light_red", "dye:pink")
minetest.register_alias("dye:medium_orange", "dye:brown")
end
minetest.register_alias("unifieddyes:black", "dye:black")
minetest.register_alias("unifieddyes:dark_grey", "dye:dark_grey")

163
api.lua
View File

@ -21,11 +21,14 @@ minetest.register_on_placenode(
return false
end
local param2
if not string.find(itemstack:to_string(), "palette_index") then
local param2
local color = 0
if def.palette == "unifieddyes_palette_extended.png"
and def.paramtype2 == "color" then
param2 = 240
color = 240
elseif def.palette == "unifieddyes_palette_colorwallmounted.png"
and def.paramtype2 == "colorwallmounted" then
param2 = newnode.param2 % 8
@ -36,57 +39,135 @@ minetest.register_on_placenode(
if param2 then
minetest.swap_node(pos, {name = newnode.name, param2 = param2})
minetest.get_meta(pos):set_int("palette_index", color)
end
end
if def.palette ~= "" then
minetest.get_meta(pos):set_int("palette_index", param2 or 240)
end
end
)
-- The complementary function: strip-off the color if the node being dug is still white/neutral
-- adapted from
-- https://github.com/minetest/minetest/blob/fe8d04d0b3c2e3af7c406fb6527f1b5230a30137/builtin/game/item.lua#L460-L562
local function node_dig_without_color(pos, node, digger)
if not digger then return false end
local diggername = digger:get_player_name()
local function move_item(item, pos, inv, digger, fix_color)
if not (digger and digger:is_player()) then return end
local creative = minetest.is_creative_enabled(digger:get_player_name())
item = unifieddyes.fix_bad_color_info(item, fix_color)
if inv:room_for_item("main", item)
and (not creative or not inv:contains_item("main", item, true)) then
inv:add_item("main", item)
elseif not creative then
minetest.item_drop(ItemStack(item), digger, pos)
local def = ItemStack(node.name):get_definition()
-- Copy pos because the callback could modify it
if not def.diggable or (def.can_dig and not def.can_dig(vector.copy(pos), digger)) then
minetest.log("info", diggername .. " tried to dig "
.. node.name .. " which is not diggable "
.. minetest.pos_to_string(pos))
return false
end
if minetest.is_protected(pos, diggername) then
minetest.log("action", diggername
.. " tried to dig " .. node.name
.. " at protected position "
.. minetest.pos_to_string(pos))
minetest.record_protection_violation(pos, diggername)
return false
end
minetest.log('action', diggername .. " digs "
.. node.name .. " at " .. minetest.pos_to_string(pos))
local wielded = digger and digger:get_wielded_item()
local drops = {node.name} -- this is instead of asking minetest to generate the node drops
if wielded then
local wdef = wielded:get_definition()
local tp = wielded:get_tool_capabilities()
local dp = minetest.get_dig_params(def and def.groups, tp, wielded:get_wear())
if wdef and wdef.after_use then
wielded = wdef.after_use(wielded, digger, node, dp) or wielded
else
-- Wear out tool
if not minetest.is_creative_enabled(diggername) then
wielded:add_wear(dp.wear)
if wielded:get_count() == 0 and wdef.sound and wdef.sound.breaks then
minetest.sound_play(wdef.sound.breaks, {
pos = pos,
gain = 0.5
}, true)
end
end
end
digger:set_wielded_item(wielded)
end
-- Check to see if metadata should be preserved.
if def and def.preserve_metadata then
local oldmeta = minetest.get_meta(pos):to_table().fields
-- Copy pos and node because the callback can modify them.
local pos_copy = vector.copy(pos)
local node_copy = { name = node.name, param1 = node.param1, param2 = node.param2 }
local drop_stacks = {}
for k, v in pairs(drops) do
drop_stacks[k] = ItemStack(v)
end
drops = drop_stacks
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
end
-- Handle drops
minetest.handle_node_drops(pos, drops, digger)
local oldmetadata
if def and def.after_dig_node then
oldmetadata = minetest.get_meta(pos):to_table()
end
-- Remove node and update
minetest.remove_node(pos)
-- Play sound if it was done by a player
if diggername ~= "" and def and def.sounds and def.sounds.dug then
minetest.sound_play(def.sounds.dug, {
pos = pos,
exclude_player = diggername,
}, true)
end
-- Run callback
if def and def.after_dig_node then
-- Copy pos and node because callback can modify them
local pos_copy = vector.copy(pos)
local node_copy = { name = node.name, param1 = node.param1, param2 = node.param2 }
def.after_dig_node(pos_copy, node_copy, oldmetadata, digger)
end
-- Run script hook
for _, callback in ipairs(minetest.registered_on_dignodes) do
local origin = minetest.callback_origins[callback]
minetest.set_last_run_mod(origin.mod)
-- Copy pos and node because callback can modify them
local pos_copy = vector.copy(pos)
local node_copy = { name = node.name, param1 = node.param1, param2 = node.param2 }
callback(pos_copy, node_copy, digger)
end
return true
end
function unifieddyes.on_dig(pos, node, digger)
if not digger then return end
local playername = digger:get_player_name()
if minetest.is_protected(pos, playername) then
minetest.record_protection_violation(pos, playername)
return
end
local oldparam2 = minetest.get_node(pos).param2
local param2 = minetest.get_node(pos).param2
local def = minetest.registered_items[node.name]
local fix_color
local del_color
if def.paramtype2 == "color" and oldparam2 == 240 and def.palette == "unifieddyes_palette_extended.png" then
fix_color = 240
elseif def.paramtype2 == "color" and oldparam2 == 0 and def.palette == "unifieddyes_palette_extended.png" then
fix_color = 0
elseif def.paramtype2 == "colorwallmounted" and math.floor(oldparam2 / 8) == 0
and def.palette == "unifieddyes_palette_colorwallmounted.png" then
fix_color = 0
elseif def.paramtype2 == "colorfacedir" and math.floor(oldparam2 / 32) == 0
and string.find(def.palette, "unifieddyes_palette_") then
fix_color = 0
if def.paramtype2 == "color" and param2 == 240 and def.palette == "unifieddyes_palette_extended.png" then
del_color = true
elseif (def.paramtype2 == "colorwallmounted" or def.paramtype2 == "colorfacedir")
and minetest.strip_param2_color(param2, def.paramtype2) == 0
and string.find(def.palette, "unifieddyes_palette_")
then
del_color = true
end
local inv = digger:get_inventory()
if fix_color then
move_item(node.name, pos, inv, digger, fix_color)
if del_color then
return node_dig_without_color(pos, node, digger)
else
return minetest.node_dig(pos, node, digger)
end
@ -117,6 +198,7 @@ function unifieddyes.generate_split_palette_nodes(name, def, drop)
def2.palette = "unifieddyes_palette_"..color.."s.png"
def2.paramtype2 = "colorfacedir"
def2.groups.ud_param2_colorable = 1
def2.is_ground_content = false
if drop then
def2.drop = {
@ -132,14 +214,11 @@ end
-- This helper function creates a colored itemstack
function unifieddyes.fix_bad_color_info(item, paletteidx)
local stack=minetest.itemstring_with_color(item, paletteidx)
return string.gsub(stack, "u0001color", "u0001palette_index")
end
function unifieddyes.make_colored_itemstack(item, palette, color)
local paletteidx = unifieddyes.getpaletteidx(color, palette)
return unifieddyes.fix_bad_color_info(item, paletteidx), paletteidx
local stack = ItemStack(item)
stack:get_meta():set_int("palette_index", paletteidx)
return stack:to_string(),paletteidx
end
-- these helper functions register all of the recipes needed to create colored

View File

@ -31,7 +31,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
unifieddyes = {}
local S = minetest.get_translator("unifieddyes")
local modpath=minetest.get_modpath(minetest.get_current_modname())
dofile(modpath.."/color-tables.lua")
@ -40,5 +39,5 @@ dofile(modpath.."/airbrush.lua")
dofile(modpath.."/dyes-crafting.lua")
dofile(modpath.."/aliases.lua")
print(S("[UnifiedDyes] Loaded!"))
print("[UnifiedDyes] Loaded!")
unifieddyes.init = true

View File

@ -0,0 +1,91 @@
# textdomain: unifieddyes
# Translation by W0rr1z
Lime Dye=柠檬黄染料
Aqua Dye=水蓝染料
Sky-blue Dye=天蓝染料
Red-violet Dye=红紫染料
Light Grey Dye=浅灰染料
Dark Red Dye (low saturation)=深红染料(低饱和度)
Dark Orange Dye (low saturation)=深橙染料(低饱和度)
Dark Yellow Dye (low saturation)=深黄染料(低饱和度)
Dark Lime Dye (low saturation)=深柠檬黄染料(低饱和度)
Dark Green Dye (low saturation)=深绿染料(低饱和度)
Dark Aqua Dye (low saturation)=深水蓝染料(低饱和度)
Dark Cyan Dye (low saturation)=深青蓝染料(低饱和度)
Dark Sky-blue Dye (low saturation)=深天蓝染料(低饱和度)
Dark Blue Dye (low saturation)=深蓝染料(低饱和度)
Dark Violet Dye (low saturation)=深紫染料(低饱和度)
Dark Magenta Dye (low saturation)=深品红染料(低饱和度)
Dark Red-violet Dye (low saturation)=深红紫染料(低饱和度)
Dark Red Dye=深红染料
Dark Orange Dye=深橙染料
Dark Yellow Dye=深黄染料
Dark Lime Dye=深柠檬黄染料
Dark Green Dye=深绿染料
Dark Aqua Dye=深水蓝染料
Dark Cyan Dye=深青蓝染料
Dark Sky-blue Dye=深天蓝染料
Dark Blue Dye=深蓝染料
Dark Violet Dye=深紫染料
Dark Magenta Dye=深品红染料
Dark Red-violet Dye=深红紫染料
Medium Red Dye (low saturation)=中红染料(低饱和度)
Medium Orange Dye (low saturation)=中橙染料(低饱和度)
Medium Yellow Dye (low saturation)=中黄染料(低饱和度)
Medium Lime Dye (low saturation)=中柠檬黄染料(低饱和度)
Medium Green Dye (low saturation)=中绿染料(低饱和度)
Medium Aqua Dye (low saturation)=中水蓝染料(低饱和度)
Medium Cyan Dye (low saturation)=中青蓝染料(低饱和度)
Medium Sky-blue Dye (low saturation)=中天蓝染料(低饱和度)
Medium Blue Dye (low saturation)=中蓝染料(低饱和度)
Medium Violet Dye (low saturation)=中紫染料(低饱和度)
Medium Magenta Dye (low saturation)=中品红染料(低饱和度)
Medium Red-violet Dye (low saturation)=中红紫染料(低饱和度)
Medium Red Dye=中红染料
Medium Orange Dye=中橙染料
Medium Yellow Dye=中黄染料
Medium Lime Dye=中柠檬黄染料
Medium Green Dye=中绿染料
Medium Aqua Dye=中水蓝染料
Medium Cyan Dye=中青蓝染料
Medium Sky-blue=中天蓝染料
Medium Blue Dye=中蓝染料
Medium Violet Dye=中紫染料
Medium Magenta Dye=中品红染料
Medium Red-violet Dye=中红紫染料
Red Dye (low saturation)=红染料(低饱和度)
Orange Dye (low saturation)=橙染料(低饱和度)
Yellow Dye (low saturation)=黄染料(低饱和度)
Lime Dye (low saturation)=柠檬黄染料(低饱和度)
Green Dye (low saturation)=绿染料(低饱和度)
Aqua Dye (low saturation)=水蓝染料(低饱和度)
Cyan Dye (low saturation)=青蓝染料(低饱和度)
Sky-blue Dye (low saturation)=天蓝染料(低饱和度)
Blue Dye (low saturation)=蓝染料(低饱和度)
Violet Dye (low saturation)=紫染料(低饱和度)
Magenta Dye (low saturation)=品红染料(低饱和度)
Red-violet Dye (low saturation)=红紫染料(低饱和度)
[UnifiedDyes] Loaded!=[UnifiedDyes] 已加载!
Dye Airbrush=染料喷枪
Select a color:=选择颜色:
(Right-clicked a node that supports all 256 colors, showing them all)=已右键支持256色的方块显示全部颜色
(Right-clicked a node not supported by the Airbrush, showing all colors)=(已右键不支持喷枪的方块,显示全部颜色)
Dyes=染料
Your selection=当前选择
Your selection:=当前选择:
Cancel=取消
Accept=应用
Show Available=显示可用颜色
(Currently showing all 256 colors)=当前显示全部256色
Show All Colors=显示所有颜色
(Currently only showing what the right-clicked node can use)=(当前仅显示右键方块可用颜色)

View File

@ -1,4 +1,4 @@
name = unifieddyes
description = Unified Dyes expands the standard dye set from 15 to 90 colors.
optional_depends = default, dye, basic_materials
min_minetest_version = 5.3.0
min_minetest_version = 5.5.0