Add scraping-off capability to axe
This commit is contained in:
parent
160c7f3ae3
commit
14021754ab
@ -479,8 +479,32 @@ minetest.register_tool(
|
||||
groups = { shovel = 1 },
|
||||
})
|
||||
|
||||
|
||||
-- Axes
|
||||
|
||||
-- Scrape off color of painted node
|
||||
local scrape = function(max_uses)
|
||||
return function(itemstack, placer, pointed_thing)
|
||||
-- Handle pointed node handlers and protection
|
||||
local handled, handled_itemstack = util.on_place_pointed_node_handler(itemstack, placer, pointed_thing)
|
||||
if handled then
|
||||
return handled_itemstack
|
||||
end
|
||||
if util.handle_node_protection(placer, pointed_thing) then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Scrape off color
|
||||
local pos = pointed_thing.under
|
||||
if rp_paint.scrape_color(pos) then
|
||||
if not minetest.is_creative_enabled(placer:get_player_name()) then
|
||||
itemstack:add_wear_by_uses(max_uses)
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_tool(
|
||||
"rp_default:axe_wood",
|
||||
{
|
||||
@ -497,6 +521,7 @@ minetest.register_tool(
|
||||
},
|
||||
sound = sound_tool,
|
||||
groups = { axe = 1 },
|
||||
on_place = scrape(10),
|
||||
})
|
||||
|
||||
minetest.register_tool(
|
||||
@ -515,6 +540,7 @@ minetest.register_tool(
|
||||
},
|
||||
sound = sound_tool,
|
||||
groups = { axe = 1 },
|
||||
on_place = scrape(60),
|
||||
})
|
||||
|
||||
minetest.register_tool(
|
||||
@ -533,6 +559,7 @@ minetest.register_tool(
|
||||
},
|
||||
sound = sound_tool,
|
||||
groups = { axe = 1 },
|
||||
on_place = scrape(135),
|
||||
})
|
||||
|
||||
minetest.register_tool(
|
||||
@ -551,6 +578,7 @@ minetest.register_tool(
|
||||
},
|
||||
sound = sound_tool,
|
||||
groups = { axe = 1 },
|
||||
on_place = scrape(270),
|
||||
})
|
||||
|
||||
minetest.register_tool(
|
||||
@ -569,6 +597,7 @@ minetest.register_tool(
|
||||
},
|
||||
sound = sound_tool,
|
||||
groups = { axe = 1 },
|
||||
on_place = scrape(360),
|
||||
})
|
||||
|
||||
minetest.register_tool(
|
||||
@ -587,6 +616,7 @@ minetest.register_tool(
|
||||
},
|
||||
sound = sound_tool,
|
||||
groups = { axe = 1 },
|
||||
on_place = scrape(420),
|
||||
})
|
||||
|
||||
-- Spears
|
||||
|
@ -85,7 +85,7 @@ about to be set for this node.
|
||||
This function must return a boolean value: `true` if painting is allowed
|
||||
or `false` to disallow/deny the painting.
|
||||
|
||||
## Setting and getting color
|
||||
## Functions
|
||||
|
||||
The color of nodes can be set and gotten programmatically by using
|
||||
a color ID (see below).
|
||||
@ -104,6 +104,22 @@ on failure.
|
||||
Note that for nodes with `paramtype2="colorfacedir"`, an approximate
|
||||
color might be chosen.
|
||||
|
||||
### `rp_paint.remove_color(pos)`
|
||||
|
||||
Removes color of a paintable node at `pos`, returning it to its
|
||||
“neutral”/unpainted state.
|
||||
Returns `true` on success, `false` on failure or if node was not painted
|
||||
or if node does not support an unpainted state.
|
||||
|
||||
### `rp_paint.scrape_color(pos)`
|
||||
|
||||
Same as `rp_paint.remove_color`, but will also play a “scraping-off”
|
||||
sound effect (`_rp_scrape`).
|
||||
|
||||
Recommended to be used by tools.
|
||||
|
||||
Other effects may be added in future versions of this mod.
|
||||
|
||||
### Color IDs
|
||||
|
||||
Each color has an unique numeric ID. The following IDs are available:
|
||||
|
@ -144,6 +144,45 @@ rp_paint.set_color = function(pos, color)
|
||||
return false
|
||||
end
|
||||
|
||||
rp_paint.remove_color = function(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local paintable = minetest.get_item_group(node.name, "paintable")
|
||||
if paintable == 1 and string.sub(node.name, -8, -1) == "_painted" then
|
||||
local newname = string.sub(node.name, 1, -9)
|
||||
local newdef = minetest.registered_nodes[newname]
|
||||
local olddef = minetest.registered_nodes[node.name]
|
||||
if olddef and newdef then
|
||||
local param2 = 0
|
||||
if olddef.paramtype2 == "color4dir" then
|
||||
param2 = node.param2 % 4
|
||||
elseif olddef.paramtype2 == "colorwallmounted" then
|
||||
param2 = node.param2 % 8
|
||||
elseif olddef.paramtype2 == "colorfacedir" then
|
||||
param2 = node.param2 % 32
|
||||
end
|
||||
minetest.swap_node(pos, {name=newname, param2=param2})
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
rp_paint.scrape_color = function(pos)
|
||||
local scraped = rp_paint.remove_color(pos)
|
||||
if scraped then
|
||||
local node = minetest.get_node(pos)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
if not def then
|
||||
return false
|
||||
end
|
||||
if def.sounds and def.sounds._rp_scrape then
|
||||
minetest.sound_play(def.sounds._rp_scrape, {pos=pos, max_hear_distance=8}, true)
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_tool("rp_paint:brush", {
|
||||
description = S("Paint Brush"),
|
||||
_tt_help = S("Changes color of paintable blocks").."\n"..S("Punch paint bucket to change brush color"),
|
||||
|
@ -58,6 +58,13 @@ These are the available functions:
|
||||
* `rp_sounds.node_sound_water_defaults(table)`: Water
|
||||
* `rp_sounds.node_sound_snow_defaults(table)`: Snow (incomplete, not recommended)
|
||||
|
||||
#### Custom sound events
|
||||
|
||||
Apart from the builtin sound events like `footstep`, `dig`, `dug`, etc. this mod supports
|
||||
custom sound events as well:
|
||||
|
||||
* `_rp_scrape`: When something is scraped off the block (like removing paint)
|
||||
|
||||
### Helper functions
|
||||
|
||||
#### `rp_sounds.play_place_failed_sound(player)`
|
||||
|
@ -159,6 +159,8 @@ List of sounds and credits:
|
||||
* rp_sounds_fall_gravel.*.ogg
|
||||
* rp_sounds_fall_grass.*.ogg
|
||||
* rp_sounds_fall_plant.*.ogg
|
||||
* rp_sounds_scrape_wood.*.ogg
|
||||
* rp_sounds_scrape_glass.*.ogg
|
||||
* default_water_footstep.*.ogg
|
||||
* by Wuzzy
|
||||
* License: CC0
|
||||
|
@ -18,6 +18,8 @@ function rp_sounds.node_sound_defaults(table)
|
||||
{name="default_place_node_hard", gain=0.8}
|
||||
table.place_failed = table.place_failed or
|
||||
{name="rp_sounds_place_failed", gain=PLACE_FAILED_GAIN}
|
||||
table._rp_scrape = table._rp_scrape or
|
||||
{name="rp_sounds_scrape_wood", gain=0.3}
|
||||
return table
|
||||
end
|
||||
|
||||
@ -143,6 +145,8 @@ function rp_sounds.node_sound_wood_defaults(table)
|
||||
{name="rp_sounds_dig_wood", gain=0.5}
|
||||
table.dug = table.dug or
|
||||
{name="rp_sounds_dug_wood", gain=1.0}
|
||||
table._rp_scrape = table._rp_scrape or
|
||||
{name="rp_sounds_scrape_wood", gain=0.3}
|
||||
rp_sounds.node_sound_defaults(table)
|
||||
return table
|
||||
end
|
||||
@ -157,6 +161,8 @@ function rp_sounds.node_sound_planks_defaults(table)
|
||||
{name="rp_sounds_dug_planks", gain=0.7}
|
||||
table.place = table.place or
|
||||
{name="rp_sounds_place_planks", gain=1.0}
|
||||
table._rp_scrape = table._rp_scrape or
|
||||
{name="rp_sounds_scrape_wood", gain=0.3}
|
||||
rp_sounds.node_sound_defaults(table)
|
||||
return table
|
||||
end
|
||||
@ -231,6 +237,8 @@ function rp_sounds.node_sound_glass_defaults(table)
|
||||
{name="rp_sounds_dug_glass", gain=1.0}
|
||||
table.place = table.place or
|
||||
{name="rp_sounds_place_glass", gain=1.0}
|
||||
table._rp_scrape = table._rp_scrape or
|
||||
{name="rp_sounds_scrape_glass", gain=0.4}
|
||||
rp_sounds.node_sound_defaults(table)
|
||||
return table
|
||||
end
|
||||
|
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_glass.1.ogg
Normal file
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_glass.1.ogg
Normal file
Binary file not shown.
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_glass.2.ogg
Normal file
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_glass.2.ogg
Normal file
Binary file not shown.
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_glass.3.ogg
Normal file
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_glass.3.ogg
Normal file
Binary file not shown.
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_wood.1.ogg
Normal file
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_wood.1.ogg
Normal file
Binary file not shown.
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_wood.2.ogg
Normal file
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_wood.2.ogg
Normal file
Binary file not shown.
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_wood.3.ogg
Normal file
BIN
mods/rp_sounds/sounds/rp_sounds_scrape_wood.3.ogg
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user