1
0
mirror of https://github.com/mt-mods/unifieddyes.git synced 2025-06-28 06:20:36 +02:00

Compare commits

..

3 Commits

Author SHA1 Message Date
9271f07f12 fix incorrect drop behavior when stipping bogus color
in the case of full inv.

Should be the same as normal Minetest behavior now:

In survival mode, the node is deleted, then:

* If there is room in your inv, you get whatever the node
  would normally give you.

* If there's no room, the node drops to the ground as an item
  entity.

In creative mode, the node is deleted, then:

* If you don't already have one of the item, you get one.

* If you already have one, or if there's no room in your
  inventory, "you'll get nothing and LIKE it!" :-)

Also: made sure to check for creative priv as well as proper
creative mode.
2019-09-15 23:57:58 -04:00
0082b1513a remove an obsolete function reference 2019-07-20 04:29:31 -04:00
d59ccd3298 document the new on_dig function 2019-07-20 04:28:53 -04:00
2 changed files with 15 additions and 7 deletions

12
API.md
View File

@ -12,7 +12,8 @@ minetest.register_node("mymod:colored_node", {
paramtype2 = "color",
palette = "unifieddyes_palette_extended.png",
groups = {snappy = 1, cracky = 2, ud_param2_colorable = 1}
airbrush_replacement_node = "mymod:my_other_colored_node"
airbrush_replacement_node = "mymod:my_other_colored_node",
on_dig = unifieddyes.on_dig
})
```
@ -35,6 +36,10 @@ If your node if of the kind where you need the split palette, but you need to pu
#### Function calls
**`unifieddyes.on_dig(pos, node, digger)`**
Set in a node definition's `on_dig` callback, this makes sure that if the player digs a neutral node, i.e. a colorable node that was left uncolored/white after placing, they receive a version of that item that has been stripped of its itemstack color setting, so that it is identical to what would have been in their inventory when that node was originally placed. This prevents the engine splitting stacks of that item due to technically-different but visually-identical itemstack coloring. This function is only needed in the definition of colorable versions of a node, not any uncolored counterparts. For example, if you have a mod that has a simple, wooden chair, and the mod turns it into one with a colored seat cushion when you airbrush or craft it with dye, then only that latter colored-seat version needs this function.
**`unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)`
`unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)`**
@ -120,7 +125,6 @@ Makes a colored itemstack out of the given `itemstack` and `color` (as a dye, e.
Does just what it sounds like - it registers all the nodes that are needed for a given base node (`def`) to be able to use the split palette, each named according to `name`, with the palette hue appended. If a custom drop is needed, it can be passed along (only a string is allowed here, specifying a single item).
#### Tables
In addition to the above API calls, Unified Dyes provides several useful tables
@ -144,8 +148,8 @@ If your mod used the old paradigm where you craft a neutral-colored item, place
```lua
place_param2 = 240,
after_dig_node = unifieddyes.after_dig_node,
after_place_node = unifieddyes.recolor_on_place,
ud_replacement_node = "mod:some_node"
ud_replacement_node = "mod:some_node",
on_dig = unifieddyes.on_dig
```
* Add the `airbrush_replacement_node` key to the node definition, if needed.

View File

@ -197,9 +197,13 @@ minetest.register_on_placenode(
-- The complementary function: strip-off the color if the node being dug is still white/neutral
local function move_item(item, pos, inv)
if not creative_mode or not inv:contains_item("main", item, true) then
local function move_item(item, pos, inv, digger)
local creative = creative_mode or minetest.check_player_privs(digger, "creative")
if inv:room_for_item("main", item)
and (not creative or not inv:contains_item("main", item, true)) then
inv:add_item("main", item)
elseif not creative then
minetest.item_drop(item, digger, pos)
end
minetest.remove_node(pos)
end
@ -227,7 +231,7 @@ function unifieddyes.on_dig(pos, node, digger)
local inv = digger:get_inventory()
if del_color then
if inv:room_for_item("main", node.name) then move_item(node.name, pos, inv) end
move_item(node.name, pos, inv, digger)
else
return minetest.node_dig(pos, node, digger)
end