From 4c5287c25698f964b923b7f29c7e3d0d51987f5f Mon Sep 17 00:00:00 2001 From: Sokomine Date: Wed, 17 Sep 2014 21:59:25 +0200 Subject: [PATCH] added paint roller based on Krocks mod --- init.lua | 20 ++++++++++-- paint_roller.lua | 62 ++++++++++++++++++++++++++++++++++++++ textures/paint_roller.png | Bin 0 -> 417 bytes 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 paint_roller.lua create mode 100644 textures/paint_roller.png diff --git a/init.lua b/init.lua index 72cbcce..ed8e39e 100644 --- a/init.lua +++ b/init.lua @@ -23,6 +23,7 @@ -- Version 0.5 -- Changelog: +-- 17.09.14 Added a modified version of Krocks paintroller from his paint_roller mod. -- 03.09.14 Added a second block type menu. -- Updated dependency list. -- Added support for homedecor kitchen chairs, beds and bathroom tiles. Changed sorting order of blocks. @@ -1150,6 +1151,7 @@ end colormachine.get_node_name_painted = function( old_node_name, dye_node_name ) local possible_blocks = {}; local unpainted_block = ""; + local old_dye = ""; for k,v in pairs( colormachine.data ) do if( old_node_name == v.block and colormachine.data[ k ].installed==1) then table.insert( possible_blocks, k ); @@ -1167,6 +1169,18 @@ colormachine.get_node_name_painted = function( old_node_name, dye_node_name ) return; end unpainted_block = colormachine.data[ found_color_data_block.blocktype ].block; + old_dye = found_color_data_block.found_name; + + -- figure out how the dye this block was painted with was called + local cdata = colormachine.decode_color_name( nil, old_dye ); + if( cdata ) then + old_dye = colormachine.translate_color_name( nil, 'unifieddyes_', old_dye, cdata.c, cdata.s, cdata.g, 1 ); + if( not( old_dye ) or old_dye == '' ) then + old_dye = colormachine.translate_color_name( nil, 'dye_', old_dye, cdata.c, cdata.s, cdata.g, 1 ); + end + else + old_dye = ''; + end end if( unpainted_block ~= "" and #possible_blocks < 1 ) then for k,v in pairs( colormachine.data ) do @@ -1178,7 +1192,7 @@ colormachine.get_node_name_painted = function( old_node_name, dye_node_name ) -- remove paint if( not( dye_node_name ) or dye_node_name == "") then - return {unpainted_block}; + return {possible={unpainted_block},old_dye = old_dye}; end -- decode dye name @@ -1208,7 +1222,7 @@ colormachine.get_node_name_painted = function( old_node_name, dye_node_name ) if( #found < 1 ) then return; end - return found; + return { possible=found, old_dye = old_dye }; end @@ -1885,3 +1899,5 @@ minetest.register_craft({ { 'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot' } } }) + +dofile( minetest.get_modpath('colormachine')..'/paint_roller.lua'); diff --git a/paint_roller.lua b/paint_roller.lua new file mode 100644 index 0000000..4214e65 --- /dev/null +++ b/paint_roller.lua @@ -0,0 +1,62 @@ +-- This is based upon the paint_roller mod by Krock. + +minetest.register_tool("colormachine:paint_roller", { + description = "Paint roller", + inventory_image = "paint_roller.png", + on_use = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return + end + local idx = placer:get_wield_index() + 1 + if idx > 7 then --copied from explorer tools moo-ha-ha + return + end + if minetest.is_protected(pointed_thing.under, placer:get_player_name()) then + minetest.record_protection_violation(pointed_thing.under, placer:get_player_name()) + return + end + local node = minetest.get_node(pointed_thing.under); + local node_name = node.name + + local inv = placer:get_inventory() + local stack = inv:get_stack("main", idx) --dye + local stack_name = stack:get_name() + + local res = colormachine.get_node_name_painted( node_name, stack_name ); + + if( not( res) or not( res.possible ) or #res.possible < 1 or (#res.possible==1 and res.possible[1]==node_name)) then + return; + end + local index = 1; + for i,v in ipairs( res.possible ) do + if( v==node_name and i < #res.possible and #res.possible[i+1]) then + index = i+1; + end + end + + -- return the old dye + if( res.old_dye and res.old_dye ~= stack_name ) then + inv:add_item( 'main', res.old_dye..' 1' ); + end + + -- consume one dye + if( stack_name and stack_name ~= '' and (not(res.old_dye) or res.old_dye~=stack_name)) then + inv:remove_item( 'main', stack_name..' 1'); + end + + -- paint the node + minetest.set_node(pointed_thing.under, {name=res.possible[ index ], param2=node.param2}) + + --itemstack:add_wear( 65535 / 30 ); + return itemstack + end +}) + +minetest.register_craft({ + output = "colormachine:paint_roller", + recipe = { + {"wool:white", "wool:white", "default:steel_ingot"}, + {"", "default:steel_ingot", ""}, + {"", "default:steel_ingot", ""}, + } +}) diff --git a/textures/paint_roller.png b/textures/paint_roller.png new file mode 100644 index 0000000000000000000000000000000000000000..45b9b28dda6c978ce859c334f09e0681838c7e89 GIT binary patch literal 417 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}Ea{HEjtmSN z`?>!lvVv45dj$D1FjT2AFf_C-L15RjOeSEA?V8lq5UtY@lcXz2dg$sDNa ziKmNWNQC>_sRwxvEAY5p{(GaLb(f3(-ts2BKttx@fWIDn3J%@6JeC3{gIp&3f6RV+ zyTBo{uZ#?>#d;ZTYh2&ATZk#V+Z)dLWS?1sVcPci%ZwQT5!vPLeeniT3{{*A9b04@ z*qUNI7~J9xWi$7@U=C&XD!oco(TNk^J&7I zxR5sP1j`LF5qv(S58|b#l{kOXnPJtlqj_2CfAK>Gv)9EhcRmR8FN3G6pUXO@geCxi Cgp{@b literal 0 HcmV?d00001