From a93ef1db2c7b500fe7904f43f83f4caf82190ca8 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Fri, 5 May 2023 20:58:04 +0200 Subject: [PATCH] Add bucket register function --- basis/boiler_lib.lua | 20 +++++++++++--------- basis/liquid_lib.lua | 3 +++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/basis/boiler_lib.lua b/basis/boiler_lib.lua index bd7c566..e1202fe 100644 --- a/basis/boiler_lib.lua +++ b/basis/boiler_lib.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2023 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -24,13 +24,10 @@ local BLOCKING_TIME = 0.3 -- 300ms techage.boiler = {} local IsWater = { - ["bucket:bucket_river_water"] = true, - ["bucket:bucket_water"] = true, + ["bucket:bucket_river_water"] = "bucket:bucket_empty", } -local IsBucket = { - ["bucket:bucket_empty"] = true, -} +local IsBucket = {} local function node_description(name) name = string.split(name, " ")[1] @@ -126,12 +123,12 @@ function techage.boiler.on_punch(pos, node, puncher, pointed_thing) if IsWater[wielded_item] and nvm.num_water < MAX_WATER then mem.blocking_time = techage.SystemTime + BLOCKING_TIME nvm.num_water = nvm.num_water + 1 - puncher:set_wielded_item(ItemStack("bucket:bucket_empty")) + puncher:set_wielded_item(ItemStack(IsWater[wielded_item])) M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm)) elseif IsBucket[wielded_item] and nvm.num_water > 0 then if item_count > 1 then local inv = puncher:get_inventory() - local item = ItemStack("bucket:bucket_water") + local item = ItemStack(IsBucket[wielded_item]) if inv:room_for_item("main", item) then inv:add_item("main", item) puncher:set_wielded_item({name=wielded_item, count = item_count - 1}) @@ -141,8 +138,13 @@ function techage.boiler.on_punch(pos, node, puncher, pointed_thing) else mem.blocking_time = techage.SystemTime + BLOCKING_TIME nvm.num_water = nvm.num_water - 1 - puncher:set_wielded_item(ItemStack("bucket:bucket_water")) + puncher:set_wielded_item(ItemStack(IsBucket[wielded_item])) end M(pos):set_string("formspec", techage.boiler.formspec(pos, nvm)) end end + +function techage.register_water_bucket(empty_bucket, full_bucket) + IsWater[full_bucket] = empty_bucket + IsBucket[empty_bucket] = full_bucket +end diff --git a/basis/liquid_lib.lua b/basis/liquid_lib.lua index 1075e1a..9df0975 100644 --- a/basis/liquid_lib.lua +++ b/basis/liquid_lib.lua @@ -101,6 +101,9 @@ function techage.register_liquid(full_container, empty_container, container_size ContainerDef[empty_container] = ContainerDef[empty_container] or {} ContainerDef[empty_container][inv_item] = full_container IsLiquid[inv_item] = true + if inv_item == "techage:water" and container_size == 1 then + techage.register_water_bucket(empty_container, full_container) + end end local function get_liquid_def(full_container)