-
-
Save Jordach/27dd69534bf4f0966fb38a033c7b4787 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bucket = {} | |
bucket.place = {} -- list of liquids to place | |
bucket.fill = {} -- list of liquids to loop over and set to air | |
bucket.name = {} -- list of bucket names to return after using the empty bucket | |
function bucket.give_filled(itemstack2, user2, ltype) | |
local inv = user2:get_inventory() | |
if inv:room_for_item("main", {name=ltype}) then | |
inv:add_item("main", ltype) | |
else | |
local pos = user:getpos() | |
pos.y = math.floor(pos.y + 0.5) | |
core.add_item(pos, ltype) | |
end | |
end | |
minetest.register_craftitem("bucket:bucket", { | |
description = "Empty Bucket", | |
inventory_image = "bucket_bucket.png", | |
liquids_pointable = true, | |
stack_max = 256, | |
on_place = function(itemstack, user, pointed_thing) | |
local loop = 0 | |
local return_item = tostring(user:get_wielded_item()).." "..tostring(user:get_wielded_item():get_count()) | |
local stack_count = user:get_wielded_item():get_count() | |
print(tostring(minetest.get_node(pointed_thing.under).name)) | |
if pointed_thing.type ~= "node" then --sanity checks, or autonomous nodes acting as players ;) | |
return | |
end | |
while bucket.count >= loop do | |
loop = loop + 1 | |
if minetest.get_node(pointed_thing.under).name == bucket.fill[loop] then | |
return_item = bucket.name[loop].." 1" | |
if user:get_wielded_item():get_count() > 1 then | |
bucket.give_filled(itemstack, user, bucket.name[loop]) | |
return_item = "bucket:bucket "..tostring(stack_count-1) | |
end | |
end | |
end | |
minetest.add_node(pointed_thing.under, {name="air"}) | |
return ItemStack(return_item) | |
end, | |
}) | |
-- how to register a filled bucket: | |
--[[ | |
name (string) refers to the item name of the bucket, eg: | |
"lava", "water", "decay_water", the after result will look like this, eg: | |
"bucket:lava", "bucket:water", "bucket:decay_water" | |
image (string) refers to the inventory image used to display the bucket, eg: | |
"bucket_water.png" or "bucket_empty.png^water_overlay.png" | |
liquid_source (string) is the node name of the liquid source block that the | |
empty bucket should pick up, eg: | |
"core:water_source", "core:lava_source", "core:acid_source" | |
desc (string) is the description of the filled bucket, eg: | |
"Lava Bucket", "Bucket of Water", "Bucket of Lava" | |
to_place (string) is the node name of the water source that the bucket should place, | |
eg: "core:water_source" "core:lava_source" | |
]]-- | |
bucket.count = 0 | |
function bucket.register_bucket(name, image, liquid_source, desc, to_place) | |
bucket.count = bucket.count + 1 | |
bucket.fill[bucket.count] = liquid_source | |
bucket.place[bucket.count] = to_place | |
bucket.name[bucket.count] = "bucket:"..name.."_bucket", | |
minetest.register_craftitem("bucket:"..name.."_bucket", { | |
description = desc, | |
inventory_image = image, | |
stack_max = 1, | |
liquids_pointable = true, | |
}) | |
end | |
bucket.register_bucket("water", "bucket_water.png", "core:water_source", "Bucket of Water", "core:water_source") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment