added paint roller based on Krocks mod

This commit is contained in:
Sokomine 2014-09-17 21:59:25 +02:00
parent 6ad7ba2be7
commit 4c5287c256
3 changed files with 80 additions and 2 deletions

View File

@ -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');

62
paint_roller.lua Normal file
View File

@ -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", ""},
}
})

BIN
textures/paint_roller.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 B