diff options
author | h-v-smacker <hans-von-smacker+github@gmail.com> | 2018-08-09 10:01:09 +0300 |
---|---|---|
committer | h-v-smacker <hans-von-smacker+github@gmail.com> | 2018-08-09 10:01:09 +0300 |
commit | 0ea43eb6d5217bf696371e8df22b07f34bf2abfa (patch) | |
tree | 2ae4ed5f3749f074e26fe7984ab1cc7382af9ece | |
parent | ae654ad22f7aacde093f99d66501a9a218c13595 (diff) |
code cleanup
-rw-r--r-- | technic/tools/spray_painter.lua | 87 |
1 files changed, 24 insertions, 63 deletions
diff --git a/technic/tools/spray_painter.lua b/technic/tools/spray_painter.lua index ce2e88b..ff7ce04 100644 --- a/technic/tools/spray_painter.lua +++ b/technic/tools/spray_painter.lua @@ -140,45 +140,36 @@ local function spray_paint(itemstack, user, pointed_thing, ptype) local target = minetest.get_node_or_nil(pointed_thing.under) - -- if pointing at plastic blocks + local paintable = false - if target and minetest.get_item_group(target.name, "paintable_plastic_block") > 0 then - - local p2 = target.param2 - local orientation = p2 % 8 - local cindex = (p2 - orientation) / 8 - local new_cindex = cindex + 1 - if new_cindex < color_modes[meta.mode].index - 1 then - new_cindex = color_modes[meta.mode].index - 1 - end - if new_cindex > color_modes[meta.mode].index + (color_modes[meta.mode].n - 1) - 1 then - new_cindex = color_modes[meta.mode].index - 1 - end + -- target-specific code + if target then + + -- if pointing at ehlphabet block (regular or colored) + if (target.name == "ehlphabet:block" or target.name == "ehlphabet:block_color") then - minetest.swap_node(pointed_thing.under, { - name = target.name, - param2 = new_cindex*8 + orientation - }) + if target.name == "ehlphabet:block" then + minetest.swap_node(pointed_thing.under, { name = "ehlphabet:block_color" }) + target = minetest.get_node_or_nil(pointed_thing.under) + end + + paintable = true + + -- if pointing at plastic blocks + elseif minetest.get_item_group(target.name, "paintable_plastic_block") > 0 then + + paintable = true - if not technic.creative_mode then - meta.charge = meta.charge - spray_painter_cpa - technic.set_RE_wear(itemstack, meta.charge, spray_painter_max_charge) - itemstack:set_metadata(minetest.serialize(meta)) + -- if the tool is pointed at a layer of paint -> cycling colors + elseif target.name == paint_name then + + paintable = true + end - - return itemstack end - - - -- if pointing at ehlphabet block (regular or colored) - - if target and (target.name == "ehlphabet:block" or target.name == "ehlphabet:block_color") then - - if target.name == "ehlphabet:block" then - minetest.swap_node(pointed_thing.under, { name = "ehlphabet:block_color" }) - target = minetest.get_node_or_nil(pointed_thing.under) - end + + if paintable then local p2 = target.param2 local orientation = p2 % 8 @@ -206,36 +197,6 @@ local function spray_paint(itemstack, user, pointed_thing, ptype) return itemstack end - - -- if the tool is pointed at a layer of paint -> cycling colors - - if target and target.name == paint_name then - - local p2 = target.param2 - local orientation = p2 % 8 - local cindex = (p2 - orientation) / 8 - local new_cindex = cindex + 1 - if new_cindex < color_modes[meta.mode].index - 1 then - new_cindex = color_modes[meta.mode].index - 1 - end - if new_cindex > color_modes[meta.mode].index + (color_modes[meta.mode].n - 1) - 1 then - new_cindex = color_modes[meta.mode].index - 1 - end - - minetest.swap_node(pointed_thing.under, { - name = target.name, - param2 = new_cindex*8 + orientation - }) - - if not technic.creative_mode then - meta.charge = meta.charge - spray_painter_cpa - technic.set_RE_wear(itemstack, meta.charge, spray_painter_max_charge) - itemstack:set_metadata(minetest.serialize(meta)) - end - - return itemstack - end - -- otherwise, spray some paint anew target = minetest.get_node_or_nil(pointed_thing.above) |