|
|
|
@ -105,7 +105,8 @@ local function get_liquid_name(bucket_name)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elseif base_mcl_buckets then
|
|
|
|
|
return mcl_buckets.buckets[bucket_name].source_place
|
|
|
|
|
-- TODO: How Should I handle this then...
|
|
|
|
|
return mcl_buckets.buckets[bucket_name].source_take[1]
|
|
|
|
|
end
|
|
|
|
|
return nil
|
|
|
|
|
end
|
|
|
|
@ -118,12 +119,33 @@ local function bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local held_bucket_name = itemstack:get_name()
|
|
|
|
|
|
|
|
|
|
local is_bucket_filled = held_bucket_name ~= get_bucket_name_empty()
|
|
|
|
|
local bucket_contents = is_bucket_filled and get_liquid_name(held_bucket_name)
|
|
|
|
|
local bucket_fill_level = internal_bucket.get_liquid_level(itemstack:get_wear())
|
|
|
|
|
|
|
|
|
|
local liquid = liquid_physics.get_liquid_at(pointed_thing.under)
|
|
|
|
|
|
|
|
|
|
-- Bucket is filled and pointed at liquid is not registered
|
|
|
|
|
-- -> Don't scoop
|
|
|
|
|
if bucket_contents and liquid == nil then
|
|
|
|
|
return itemstack
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Pointed at liquid is not registered
|
|
|
|
|
-- -> Scoop via fallback
|
|
|
|
|
if liquid == nil then
|
|
|
|
|
return on_use_fallback(itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Bucket is filled and pointed at liquid is of different kind
|
|
|
|
|
-- -> Don't scoop
|
|
|
|
|
local liquid_source_name = liquid_physics.get_liquid_node_names(liquid.liquid_id)[8]
|
|
|
|
|
if bucket_contents and bucket_contents ~= liquid_source_name then
|
|
|
|
|
return itemstack
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local node = core.get_node(pointed_thing.under)
|
|
|
|
|
|
|
|
|
|
if check_protection(pointed_thing.under,
|
|
|
|
@ -132,38 +154,43 @@ local function bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local liquid_source = liquid_physics.get_liquid_node_names(liquid.liquid_id)[8]
|
|
|
|
|
local bucket_name = get_bucket_name_filled(liquid_source)
|
|
|
|
|
local bucket_name_filled = get_bucket_name_filled(liquid_source_name)
|
|
|
|
|
|
|
|
|
|
if bucket_name == nil then
|
|
|
|
|
-- Don't know how to handle
|
|
|
|
|
-- -> Fallback
|
|
|
|
|
if bucket_name_filled == nil then
|
|
|
|
|
return on_use_fallback(itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Filled Bucket
|
|
|
|
|
local bucket_item = ItemStack(bucket_name)
|
|
|
|
|
set_bucket_item_liquid_level(bucket_item, liquid.liquid_level)
|
|
|
|
|
local item_bucket = ItemStack(bucket_name_filled)
|
|
|
|
|
if not is_bucket_filled then
|
|
|
|
|
set_bucket_item_liquid_level(item_bucket, liquid.liquid_level)
|
|
|
|
|
|
|
|
|
|
local return_item = bucket_item
|
|
|
|
|
local item_count = user:get_wielded_item():get_count()
|
|
|
|
|
if item_count > 1 then
|
|
|
|
|
local inv = user:get_inventory()
|
|
|
|
|
if inv:room_for_item("main", { name = bucket_name_filled }) then
|
|
|
|
|
inv:add_item("main", item_bucket)
|
|
|
|
|
else
|
|
|
|
|
local pos = user:getpos()
|
|
|
|
|
pos.y = math.floor(pos.y + 0.5)
|
|
|
|
|
core.add_item(pos, item_bucket)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local item_count = user:get_wielded_item():get_count()
|
|
|
|
|
|
|
|
|
|
if item_count > 1 then
|
|
|
|
|
local inv = user:get_inventory()
|
|
|
|
|
if inv:room_for_item("main", { name = bucket_name }) then
|
|
|
|
|
inv:add_item("main", bucket_item)
|
|
|
|
|
else
|
|
|
|
|
local pos = user:getpos()
|
|
|
|
|
pos.y = math.floor(pos.y + 0.5)
|
|
|
|
|
core.add_item(pos, bucket_item)
|
|
|
|
|
-- set to return empty buckets minus 1
|
|
|
|
|
item_bucket = ItemStack(get_bucket_name_empty() .. tostring(item_count - 1))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- set to return empty buckets minus 1
|
|
|
|
|
return_item = ItemStack(get_bucket_name_empty() .. tostring(item_count - 1))
|
|
|
|
|
liquid_physics.set_liquid_at(pointed_thing.under, 0, 0)
|
|
|
|
|
return item_bucket
|
|
|
|
|
else
|
|
|
|
|
local give_amount = math.min(8 - bucket_fill_level, liquid.liquid_level)
|
|
|
|
|
|
|
|
|
|
set_bucket_item_liquid_level(item_bucket, bucket_fill_level + give_amount)
|
|
|
|
|
liquid_physics.set_liquid_at(pointed_thing.under, liquid.liquid_id, liquid.liquid_level - give_amount)
|
|
|
|
|
|
|
|
|
|
return item_bucket
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
liquid_physics.set_liquid_at(pointed_thing.under, 0, 0)
|
|
|
|
|
|
|
|
|
|
return return_item
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function bucket_on_place(on_place_fallback, bucket_liquid_id, source_name, itemstack, user, pointed_thing)
|
|
|
|
@ -240,24 +267,33 @@ function internal_bucket.register_empty_bucket(bucket_name)
|
|
|
|
|
|
|
|
|
|
if base_default then
|
|
|
|
|
local on_use_fallback = bucket_tool.on_use
|
|
|
|
|
local on_use_wrapper = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
core.override_item(bucket_name, { on_use = on_use_wrapper }, nil)
|
|
|
|
|
core.override_item(bucket_name, {
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
}, nil)
|
|
|
|
|
elseif base_mcl_buckets then
|
|
|
|
|
local on_use_fallback = bucket_tool.on_place
|
|
|
|
|
local on_use_wrapper = function(itemstack, user, pointed_thing)
|
|
|
|
|
local use_select_box = core.settings:get_bool("mcl_buckets_use_select_box", false)
|
|
|
|
|
if use_select_box == false then
|
|
|
|
|
-- TODO: Understand why this is nil
|
|
|
|
|
if user.get_pos == nil then
|
|
|
|
|
return itemstack
|
|
|
|
|
if core.settings:get_bool("liquid_physics_voxelibre_enable_scooping_via_use", true) then
|
|
|
|
|
core.override_item(bucket_name, {
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
pointed_thing = mcl_get_pointed_thing(user)
|
|
|
|
|
end
|
|
|
|
|
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
}, nil)
|
|
|
|
|
end
|
|
|
|
|
core.override_item(bucket_name, { on_place = on_use_wrapper }, nil)
|
|
|
|
|
core.override_item(bucket_name, {
|
|
|
|
|
on_place = function(itemstack, user, pointed_thing)
|
|
|
|
|
local use_select_box = core.settings:get_bool("mcl_buckets_use_select_box", false)
|
|
|
|
|
if use_select_box == false then
|
|
|
|
|
-- TODO: Understand why this is nil
|
|
|
|
|
if user.get_pos == nil then
|
|
|
|
|
return itemstack
|
|
|
|
|
end
|
|
|
|
|
pointed_thing = mcl_get_pointed_thing(user)
|
|
|
|
|
end
|
|
|
|
|
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
}, nil)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -276,20 +312,50 @@ function internal_bucket.register_filled_bucket(name)
|
|
|
|
|
|
|
|
|
|
if base_default then
|
|
|
|
|
local on_place_fallback = bucket_tool.on_place
|
|
|
|
|
local on_place_wrapper = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_place(on_place_fallback, bucket_liquid_id, source_name, itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
local on_use_fallback = bucket_tool.on_place
|
|
|
|
|
core.override_item(name, {
|
|
|
|
|
on_place = on_place_wrapper
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
end,
|
|
|
|
|
on_place = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_place(on_place_fallback, bucket_liquid_id, source_name, itemstack, user, pointed_thing)
|
|
|
|
|
end,
|
|
|
|
|
wear_color = {
|
|
|
|
|
blend = "linear",
|
|
|
|
|
color_stops = {
|
|
|
|
|
[0.0] = "#ff0000",
|
|
|
|
|
[0.5] = "slateblue",
|
|
|
|
|
[1.0] = { r = 0, g = 255, b = 0, a = 150 },
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
core.register_tool(":" .. name, core.registered_items[name])
|
|
|
|
|
elseif base_mcl_buckets then
|
|
|
|
|
local on_place_fallback = bucket_tool.on_place
|
|
|
|
|
local on_place_wrapper = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_place(on_place_fallback, bucket_liquid_id, source_name, itemstack, user, pointed_thing)
|
|
|
|
|
if core.settings:get_bool("liquid_physics_voxelibre_enable_scooping_via_use", true) then
|
|
|
|
|
local on_use_fallback = bucket_tool.on_use
|
|
|
|
|
core.override_item(name, {
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
|
|
|
|
end
|
|
|
|
|
}, nil)
|
|
|
|
|
end
|
|
|
|
|
core.override_item(name, {
|
|
|
|
|
on_place = on_place_wrapper
|
|
|
|
|
on_place = function(itemstack, user, pointed_thing)
|
|
|
|
|
return bucket_on_place(on_place_fallback, bucket_liquid_id, source_name, itemstack, user, pointed_thing)
|
|
|
|
|
end,
|
|
|
|
|
wear_color = {
|
|
|
|
|
blend = "linear",
|
|
|
|
|
color_stops = {
|
|
|
|
|
[0.0] = "#ff0000",
|
|
|
|
|
[0.5] = "slateblue",
|
|
|
|
|
[1.0] = { r = 0, g = 255, b = 0, a = 150 },
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
|
|
core.register_tool(":" .. name, core.registered_items[name])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|