Compare commits

..

No commits in common. "main" and "0.3" have entirely different histories.
main ... 0.3

4 changed files with 55 additions and 122 deletions

View File

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

View File

@ -20,11 +20,11 @@ internal_bucket.register_empty_bucket("bucket:bucket_empty")
-- Settings -- Settings
if core.settings:get_bool("liquid_physics_enable_water_physics", true) then if core.settings:get_bool("liquid_physics_enable_water_physics", false) then
liquid_physics.register_liquid("default", "water_source", "water_flowing") liquid_physics.register_liquid("default", "water_source", "water_flowing")
internal_bucket.register_filled_bucket("bucket:bucket_water") internal_bucket.register_filled_bucket("bucket:bucket_water")
end end
if core.settings:get_bool("liquid_physics_enable_lava_physics", true) then if core.settings:get_bool("liquid_physics_enable_lava_physics", false) then
liquid_physics.register_liquid("default", "lava_source", "lava_flowing") liquid_physics.register_liquid("default", "lava_source", "lava_flowing")
internal_bucket.register_filled_bucket("bucket:bucket_lava") internal_bucket.register_filled_bucket("bucket:bucket_lava")
end end

View File

@ -20,11 +20,11 @@ internal_bucket.register_empty_bucket("mcl_buckets:bucket_empty")
-- Settings -- Settings
if core.settings:get_bool("liquid_physics_enable_water_physics", true) then if core.settings:get_bool("liquid_physics_enable_water_physics", false) then
liquid_physics.register_liquid("mcl_core", "water_source", "water_flowing") liquid_physics.register_liquid("mcl_core", "water_source", "water_flowing")
internal_bucket.register_filled_bucket("mcl_buckets:bucket_water") internal_bucket.register_filled_bucket("mcl_buckets:bucket_water")
end end
if core.settings:get_bool("liquid_physics_enable_lava_physics", true) then if core.settings:get_bool("liquid_physics_enable_lava_physics", false) then
liquid_physics.register_liquid("mcl_core", "lava_source", "lava_flowing") liquid_physics.register_liquid("mcl_core", "lava_source", "lava_flowing")
internal_bucket.register_filled_bucket("mcl_buckets:bucket_lava") internal_bucket.register_filled_bucket("mcl_buckets:bucket_lava")
end end

View File

@ -1,3 +1,2 @@
liquid_physics_enable_water_physics (Enable Physics For Water) 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_enable_lava_physics (Enable physics for lava) bool true
liquid_physics_voxelibre_enable_scooping_via_use (VoxeLibre: Enable Scooping Via Use/Punch) bool true