Skip to content

Commit 5b2a896

Browse files
Ferkparamat
authored andcommittedNov 2, 2016
Bucket: Allow buckets to trigger the on_punch of entities and nodes
The purpose of this is to allow mods to be able to interact (e.g. fill up) an empty bucket when it is used to punch a node that's not a liquid source or when punching a custom entity (e.g. milking a cow).
1 parent 56d6eae commit 5b2a896

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
 

Diff for: ‎game_api.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Bucket API
1919

2020
The bucket API allows registering new types of buckets for non-default liquids.
2121

22-
2322
bucket.register_liquid(
2423
"default:lava_source", -- name of the source node
2524
"default:lava_flowing", -- name of the flowing node
@@ -32,6 +31,9 @@ The bucket API allows registering new types of buckets for non-default liquids.
3231
-- Needed to avoid creating holes in sloping rivers.
3332
)
3433

34+
The filled bucket item is returned to the player that uses an empty bucket pointing to the given liquid source.
35+
When punching with an empty bucket pointing to an entity or a non-liquid node, the on_punch of the entity or node will be triggered.
36+
3537
Beds API
3638
--------
3739

Diff for: ‎mods/bucket/init.lua

+12-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,11 @@ minetest.register_craftitem("bucket:bucket_empty", {
115115
stack_max = 99,
116116
liquids_pointable = true,
117117
on_use = function(itemstack, user, pointed_thing)
118-
-- Must be pointing to node
119-
if pointed_thing.type ~= "node" then
118+
if pointed_thing.type == "object" then
119+
pointed_thing.ref:punch(user, 1.0, { full_punch_interval=1.0 }, nil)
120+
return user:get_wielded_item()
121+
elseif pointed_thing.type ~= "node" then
122+
-- do nothing if it's neither object nor node
120123
return
121124
end
122125
-- Check if pointing to a liquid source
@@ -165,6 +168,13 @@ minetest.register_craftitem("bucket:bucket_empty", {
165168
end
166169

167170
return ItemStack(giving_back)
171+
else
172+
-- non-liquid nodes will have their on_punch triggered
173+
local node_def = minetest.registered_nodes[node.name]
174+
if node_def then
175+
node_def.on_punch(pointed_thing.under, node, user, pointed_thing)
176+
end
177+
return user:get_wielded_item()
168178
end
169179
end,
170180
})

0 commit comments

Comments
 (0)
Please sign in to comment.