mirror of
				https://github.com/mt-mods/unifieddyes.git
				synced 2025-11-04 01:25:28 +01:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			71d7e3c954
			...
			2020-12-02
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					eb5610fc10 | ||
| 
						 | 
					30c55bec6d | ||
| 
						 | 
					e2c35e6694 | ||
| 
						 | 
					c91c68e0f5 | ||
| 
						 | 
					09f95729c5 | 
							
								
								
									
										44
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								init.lua
									
									
									
									
									
								
							@@ -166,14 +166,11 @@ minetest.register_on_placenode(
 | 
				
			|||||||
			return false
 | 
								return false
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if not string.find(itemstack:to_string(), "palette_index") then
 | 
					 | 
				
			||||||
		local param2
 | 
							local param2
 | 
				
			||||||
			local color = 0
 | 
							if not string.find(itemstack:to_string(), "palette_index") then
 | 
				
			||||||
 | 
					 | 
				
			||||||
			if def.palette == "unifieddyes_palette_extended.png"
 | 
								if def.palette == "unifieddyes_palette_extended.png"
 | 
				
			||||||
			  and def.paramtype2 == "color" then
 | 
								  and def.paramtype2 == "color" then
 | 
				
			||||||
				param2 = 240
 | 
									param2 = 240
 | 
				
			||||||
				color = 240
 | 
					 | 
				
			||||||
			elseif def.palette == "unifieddyes_palette_colorwallmounted.png"
 | 
								elseif def.palette == "unifieddyes_palette_colorwallmounted.png"
 | 
				
			||||||
			  and def.paramtype2 == "colorwallmounted" then
 | 
								  and def.paramtype2 == "colorwallmounted" then
 | 
				
			||||||
				param2 = newnode.param2 % 8
 | 
									param2 = newnode.param2 % 8
 | 
				
			||||||
@@ -184,17 +181,21 @@ minetest.register_on_placenode(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if param2 then
 | 
								if param2 then
 | 
				
			||||||
				minetest.swap_node(pos, {name = newnode.name, param2 = param2})
 | 
									minetest.swap_node(pos, {name = newnode.name, param2 = param2})
 | 
				
			||||||
				minetest.get_meta(pos):set_int("palette_index", color)
 | 
					 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if def.palette ~= "" then
 | 
				
			||||||
 | 
								minetest.get_meta(pos):set_int("palette_index", param2 or 240)
 | 
				
			||||||
 | 
							end
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- The complementary function:  strip-off the color if the node being dug is still white/neutral
 | 
					-- The complementary function:  strip-off the color if the node being dug is still white/neutral
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function move_item(item, pos, inv, digger)
 | 
					local function move_item(item, pos, inv, digger, fix_color)
 | 
				
			||||||
	if not digger then return end
 | 
						if not (digger and digger:is_player()) then return end
 | 
				
			||||||
	local creative = creative_mode or minetest.check_player_privs(digger, "creative")
 | 
						local creative = creative_mode or minetest.check_player_privs(digger, "creative")
 | 
				
			||||||
 | 
						item = unifieddyes.fix_bad_color_info(item, fix_color)
 | 
				
			||||||
	if inv:room_for_item("main", item)
 | 
						if inv:room_for_item("main", item)
 | 
				
			||||||
	  and (not creative or not inv:contains_item("main", item, true)) then
 | 
						  and (not creative or not inv:contains_item("main", item, true)) then
 | 
				
			||||||
		inv:add_item("main", item)
 | 
							inv:add_item("main", item)
 | 
				
			||||||
@@ -214,20 +215,21 @@ function unifieddyes.on_dig(pos, node, digger)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	local oldparam2 = minetest.get_node(pos).param2
 | 
						local oldparam2 = minetest.get_node(pos).param2
 | 
				
			||||||
	local def = minetest.registered_items[node.name]
 | 
						local def = minetest.registered_items[node.name]
 | 
				
			||||||
	local del_color
 | 
						local fix_color
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if def.paramtype2 == "color" and oldparam2 == 240 and def.palette == "unifieddyes_palette_extended.png" then
 | 
						if def.paramtype2 == "color" and oldparam2 == 240 and def.palette == "unifieddyes_palette_extended.png" then
 | 
				
			||||||
		del_color = true
 | 
							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
 | 
						elseif def.paramtype2 == "colorwallmounted" and math.floor(oldparam2 / 8) == 0 and def.palette == "unifieddyes_palette_colorwallmounted.png" then
 | 
				
			||||||
		del_color = true
 | 
							fix_color = 0
 | 
				
			||||||
	elseif def.paramtype2 == "colorfacedir" and math.floor(oldparam2 / 32) == 0 and string.find(def.palette, "unifieddyes_palette_") then
 | 
						elseif def.paramtype2 == "colorfacedir" and math.floor(oldparam2 / 32) == 0 and string.find(def.palette, "unifieddyes_palette_") then
 | 
				
			||||||
		del_color = true
 | 
							fix_color = 0
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local inv = digger:get_inventory()
 | 
						local inv = digger:get_inventory()
 | 
				
			||||||
 | 
						if fix_color then
 | 
				
			||||||
	if del_color then
 | 
							move_item(node.name, pos, inv, digger, fix_color)
 | 
				
			||||||
		move_item(node.name, pos, inv, digger)
 | 
					 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		return minetest.node_dig(pos, node, digger)
 | 
							return minetest.node_dig(pos, node, digger)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
@@ -273,11 +275,14 @@ end
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
-- This helper function creates a colored itemstack
 | 
					-- 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)
 | 
					function unifieddyes.make_colored_itemstack(item, palette, color)
 | 
				
			||||||
	local paletteidx = unifieddyes.getpaletteidx(color, palette)
 | 
						local paletteidx = unifieddyes.getpaletteidx(color, palette)
 | 
				
			||||||
	local stack = ItemStack(item)
 | 
						return unifieddyes.fix_bad_color_info(item, paletteidx), paletteidx
 | 
				
			||||||
	stack:get_meta():set_int("palette_index", paletteidx)
 | 
					 | 
				
			||||||
	return stack:to_string(),paletteidx
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- these helper functions register all of the recipes needed to create colored
 | 
					-- these helper functions register all of the recipes needed to create colored
 | 
				
			||||||
@@ -1147,10 +1152,11 @@ minetest.register_tool("unifieddyes:airbrush", {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		unifieddyes.player_last_right_clicked[player_name] = {pos = pos, node = node, def = def}
 | 
							unifieddyes.player_last_right_clicked[player_name] = {pos = pos, node = node, def = def}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if not keys.sneak then
 | 
							if (not keys.sneak) and def.on_rightclick then
 | 
				
			||||||
 | 
								return def.on_rightclick(pos, node, placer, itemstack, pointed_thing)
 | 
				
			||||||
 | 
							elseif not keys.sneak then
 | 
				
			||||||
			unifieddyes.show_airbrush_form(placer)
 | 
								unifieddyes.show_airbrush_form(placer)
 | 
				
			||||||
		elseif keys.sneak then
 | 
							elseif keys.sneak then
 | 
				
			||||||
 | 
					 | 
				
			||||||
			if not pos or not def then return end
 | 
								if not pos or not def then return end
 | 
				
			||||||
			local newcolor = unifieddyes.color_to_name(node.param2, def)
 | 
								local newcolor = unifieddyes.color_to_name(node.param2, def)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user