Enable Wear for Buckets
This commit is contained in:
parent
606a215f77
commit
6a021676b9
115
bucket.lua
115
bucket.lua
@ -118,12 +118,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 +153,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 return_item = bucket_item
|
||||
local item_bucket = ItemStack(bucket_name_filled)
|
||||
if not is_bucket_filled then
|
||||
set_bucket_item_liquid_level(item_bucket, liquid.liquid_level)
|
||||
|
||||
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)
|
||||
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, bucket_item)
|
||||
core.add_item(pos, item_bucket)
|
||||
end
|
||||
|
||||
-- set to return empty buckets minus 1
|
||||
return_item = ItemStack(get_bucket_name_empty() .. tostring(item_count - 1))
|
||||
item_bucket = ItemStack(get_bucket_name_empty() .. tostring(item_count - 1))
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
return return_item
|
||||
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
|
||||
end
|
||||
|
||||
local function bucket_on_place(on_place_fallback, bucket_liquid_id, source_name, itemstack, user, pointed_thing)
|
||||
@ -240,13 +266,22 @@ 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)
|
||||
core.override_item(bucket_name, {
|
||||
on_use = 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)
|
||||
}, nil)
|
||||
elseif base_mcl_buckets then
|
||||
local on_use_fallback = bucket_tool.on_place
|
||||
local on_use_wrapper = function(itemstack, user, pointed_thing)
|
||||
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
|
||||
}, nil)
|
||||
end
|
||||
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
|
||||
@ -257,7 +292,7 @@ function internal_bucket.register_empty_bucket(bucket_name)
|
||||
end
|
||||
return bucket_on_use(on_use_fallback, itemstack, user, pointed_thing)
|
||||
end
|
||||
core.override_item(bucket_name, { on_place = on_use_wrapper }, nil)
|
||||
}, nil)
|
||||
end
|
||||
end
|
||||
|
||||
@ -276,20 +311,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
|
||||
|
||||
|
@ -1,2 +1,3 @@
|
||||
liquid_physics_enable_water_physics (Enable physics for water) bool true
|
||||
liquid_physics_enable_lava_physics (Enable physics for lava) bool true
|
||||
liquid_physics_enable_water_physics (Enable Physics For Water) bool true
|
||||
liquid_physics_enable_lava_physics (Enable Physics For Lava) bool true
|
||||
liquid_physics_voxelibre_enable_scooping_via_use (VoxeLibre: Enable Scooping Via Use/Punch) bool true
|
||||
|
Loading…
Reference in New Issue
Block a user