2019-08-29 18:23:06 +02:00
|
|
|
local S = minetest.get_translator("default")
|
|
|
|
|
2019-08-31 14:06:32 +02:00
|
|
|
local water_buckets = {
|
2019-12-05 10:30:46 +01:00
|
|
|
{ "water", S("Water Bucket"), "default_bucket_water.png", "default:water_source", S("Places a water source") },
|
|
|
|
{ "river_water", S("River Water Bucket"), "default_bucket_river_water.png", "default:river_water_source", S("Places a river water source") },
|
|
|
|
{ "swamp_water", S("Swamp Water Bucket"), "default_bucket_swamp_water.png", "default:swamp_water_source", S("Places a swamp water source") },
|
2019-08-29 18:23:06 +02:00
|
|
|
}
|
|
|
|
|
2019-08-31 14:06:32 +02:00
|
|
|
for b=1, #water_buckets do
|
|
|
|
local bucket = water_buckets[b]
|
2019-08-29 18:23:06 +02:00
|
|
|
minetest.register_craftitem(
|
2019-08-29 18:40:21 +02:00
|
|
|
"default:bucket_"..bucket[1],
|
2019-08-29 18:23:06 +02:00
|
|
|
{
|
|
|
|
description = bucket[2],
|
2019-12-05 10:30:46 +01:00
|
|
|
_tt_help = bucket[5],
|
2019-08-29 18:23:06 +02:00
|
|
|
inventory_image = bucket[3],
|
|
|
|
stack_max = 1,
|
|
|
|
wield_scale = {x=1,y=1,z=2},
|
|
|
|
liquids_pointable = true,
|
2019-08-31 14:06:32 +02:00
|
|
|
groups = { bucket = 2, bucket_water = 1 },
|
2019-08-29 18:23:06 +02:00
|
|
|
on_place = function(itemstack, user, pointed_thing)
|
2019-09-25 21:54:22 +02:00
|
|
|
if pointed_thing.type ~= "node" then return itemstack end
|
2019-08-29 18:23:06 +02:00
|
|
|
|
|
|
|
local pos_protected = minetest.get_pointed_thing_position(pointed_thing, true)
|
2019-09-25 21:54:22 +02:00
|
|
|
if minetest.is_protected(pos_protected, user:get_player_name()) and
|
|
|
|
not minetest.check_player_privs(user, "protection_bypass") then
|
|
|
|
minetest.record_protection_violation(pos_protected, user:get_player_name())
|
|
|
|
return itemstack
|
|
|
|
end
|
2019-08-29 18:23:06 +02:00
|
|
|
|
|
|
|
local inv=user:get_inventory()
|
|
|
|
|
2019-08-31 00:07:26 +02:00
|
|
|
if not minetest.settings:get_bool("creative_mode") then
|
|
|
|
if itemstack:get_count() == 1 then
|
|
|
|
itemstack:set_name("default:bucket")
|
|
|
|
elseif inv:room_for_item("main", {name="default:bucket"}) then
|
|
|
|
itemstack:take_item()
|
|
|
|
inv:add_item("main", "default:bucket")
|
|
|
|
else
|
|
|
|
itemstack:take_item()
|
|
|
|
local pos = user:get_pos()
|
|
|
|
pos.y = math.floor(pos.y + 0.5)
|
|
|
|
minetest.add_item(pos, "default:bucket")
|
|
|
|
end
|
2019-08-29 18:23:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local pos = pointed_thing.above
|
|
|
|
local above_nodedef = minetest.registered_nodes[minetest.get_node(pointed_thing.above).name]
|
|
|
|
local under_nodedef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
|
|
|
|
|
|
|
|
if under_nodedef.buildable_to then
|
|
|
|
pos=pointed_thing.under
|
|
|
|
end
|
|
|
|
|
|
|
|
if not above_nodedef.walkable then
|
|
|
|
minetest.add_node(pos, {name = bucket[4]})
|
2020-04-07 01:00:55 +02:00
|
|
|
minetest.sound_play({name="default_place_node_water", gain=1.0}, {pos=pos}, true)
|
2019-08-29 18:23:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_craftitem(
|
|
|
|
"default:bucket",
|
|
|
|
{
|
|
|
|
description = S("Empty Bucket"),
|
2019-12-05 10:30:46 +01:00
|
|
|
_tt_help = S("Place it to collect a liquid source"),
|
2019-08-29 18:23:06 +02:00
|
|
|
inventory_image = "default_bucket.png",
|
|
|
|
stack_max = 10,
|
|
|
|
wield_scale = {x=1,y=1,z=2},
|
|
|
|
liquids_pointable = true,
|
2019-08-31 14:06:32 +02:00
|
|
|
groups = { bucket = 1 },
|
2019-08-29 18:23:06 +02:00
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
if pointed_thing.type ~= "node" then return end
|
|
|
|
|
2019-09-25 21:54:22 +02:00
|
|
|
local pos_protected = minetest.get_pointed_thing_position(pointed_thing, true)
|
|
|
|
if minetest.is_protected(pos_protected, user:get_player_name()) and
|
|
|
|
not minetest.check_player_privs(user, "protection_bypass") then
|
|
|
|
minetest.record_protection_violation(pos_protected, user:get_player_name())
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-08-29 18:23:06 +02:00
|
|
|
local nodename=minetest.get_node(pointed_thing.under).name
|
|
|
|
|
2019-08-29 18:27:37 +02:00
|
|
|
local replace_bucket = function(itemstack, new_bucket)
|
2019-08-31 00:07:26 +02:00
|
|
|
if minetest.settings:get_bool("creative_mode") then
|
|
|
|
-- no-op
|
|
|
|
elseif itemstack:get_count() == 1 then
|
2019-08-29 18:27:37 +02:00
|
|
|
itemstack:set_name(new_bucket)
|
2019-08-29 18:23:06 +02:00
|
|
|
else
|
2019-08-29 18:27:37 +02:00
|
|
|
itemstack:take_item()
|
|
|
|
|
|
|
|
local inv=user:get_inventory()
|
|
|
|
|
|
|
|
if inv:room_for_item("main", {name="default:bucket_water"}) then
|
|
|
|
inv:add_item("main", "default:bucket_water")
|
|
|
|
else
|
|
|
|
local pos = user:get_pos()
|
|
|
|
pos.y = math.floor(pos.y + 0.5)
|
|
|
|
minetest.add_item(pos, "default:bucket_water")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
minetest.remove_node(pointed_thing.under)
|
2020-04-07 01:00:55 +02:00
|
|
|
minetest.sound_play({name="default_dug_water", gain=1.0}, {pos=pointed_thing.pos}, true)
|
2019-08-29 18:27:37 +02:00
|
|
|
return itemstack
|
|
|
|
end
|
2019-08-29 18:23:06 +02:00
|
|
|
|
2019-08-29 18:27:37 +02:00
|
|
|
if nodename == "default:water_source" then
|
|
|
|
itemstack = replace_bucket(itemstack, "default:bucket_water")
|
2019-08-29 18:23:06 +02:00
|
|
|
elseif nodename == "default:river_water_source" then
|
2019-08-29 18:27:37 +02:00
|
|
|
itemstack = replace_bucket(itemstack, "default:bucket_river_water")
|
2019-08-29 18:23:06 +02:00
|
|
|
elseif nodename == "default:swamp_water_source" then
|
2019-08-29 18:27:37 +02:00
|
|
|
itemstack = replace_bucket(itemstack, "default:bucket_swamp_water")
|
2019-08-29 18:23:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
|
|
|
})
|
2019-08-29 19:51:23 +02:00
|
|
|
|
|
|
|
default.log("bucket", "loaded")
|