WIP separate functions into different files

This commit is contained in:
AFCMS 2021-03-27 11:52:54 +01:00
parent b4033ddfc9
commit 297d4e707c
4 changed files with 95 additions and 69 deletions

View File

@ -0,0 +1 @@
mcl_cauldrons.registered_cauldrons = {}

View File

@ -1,22 +1,16 @@
local S = minetest.get_translator("mcl_cauldron") local S = minetest.get_translator("mcl_cauldron")
local modpath = minetest.get_modpath(minetest.get_current_modname())
mcl_cauldrons = {} mcl_cauldrons = {}
-- Cauldron mod, adds cauldrons. -- Cauldron mod, adds cauldrons.
dofile(modpath.."/utils.lua")
dofile(modpath.."/api.lua")
dofile(modpath.."/register.lua")
local function give_item(user, itemstack) local function give_item(user, itemstack)
local inv = user:get_inventory() local inv = user:get_inventory()
if inv then if inv then
--[[if false then --minetest.is_creative_enabled(user:get_player_name()) then
if inv:contains_item("main", itemstack) then
return false
else
if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack)
else
minetest.add_item(user:get_pos(), itemstack)
end
end
else]]
if inv:room_for_item("main", itemstack) then if inv:room_for_item("main", itemstack) then
inv:add_item("main", itemstack) inv:add_item("main", itemstack)
else else
@ -64,7 +58,7 @@ for w=0,3 do
cauldron_nodeboxes[w] = create_cauldron_nodebox(w) cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
end end
mcl_cauldrons.registered_cauldrons = {}
--local cauldrons_list = {} --local cauldrons_list = {}
-- Empty cauldron -- Empty cauldron
minetest.register_node("mcl_cauldrons:cauldron", { minetest.register_node("mcl_cauldrons:cauldron", {
@ -101,11 +95,12 @@ function mcl_cauldrons.get_cauldron_level(pos)
end end
function mcl_cauldrons.add_cauldron_level(pos, type, number) function mcl_cauldrons.add_cauldron_level(pos, type, number)
local number = mcl_cauldrons.get_cauldron_level(pos) + number local current = mcl_cauldrons.get_cauldron_level(pos)
local number = current + number
if number > 4 then number = 4 end if number > 4 then number = 4 end
if number < 1 then number = 1 end if number < 1 then number = 1 end
mcl_cauldrons.set_cauldron_level(pos, type, number) mcl_cauldrons.set_cauldron_level(pos, type, number)
return number return number, not current == number
end end
function mcl_cauldrons.is_cauldron(name) function mcl_cauldrons.is_cauldron(name)
@ -135,8 +130,8 @@ function mcl_cauldrons.take_small_cauldron(pos, itemstack, user, sounds)
local nn = minetest.get_node(pos) local nn = minetest.get_node(pos)
if mcl_cauldrons.registered_cauldrons[nn.name] and mcl_cauldrons.registered_cauldrons[nn.name].bottle then if mcl_cauldrons.registered_cauldrons[nn.name] and mcl_cauldrons.registered_cauldrons[nn.name].bottle then
if user and not minetest.is_creative_enabled(user:get_player_name()) then if user and not minetest.is_creative_enabled(user:get_player_name()) then
local number = mcl_cauldrons.add_cauldron_level(pos, mcl_cauldrons.registered_cauldrons[nn.name].name, -1) local number, changed = mcl_cauldrons.add_cauldron_level(pos, mcl_cauldrons.registered_cauldrons[nn.name].name, -1)
if number ~= 0 then if changed then
if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end if sounds then minetest.sound_play(sounds.dug, {gain=1.0, pos = pos, pitch = 1 + math.random(-10, 10)*0.005}, true) end
local item_name = mcl_cauldrons.registered_cauldrons[nn.name].bottle local item_name = mcl_cauldrons.registered_cauldrons[nn.name].bottle
local inv = placer:get_inventory() local inv = placer:get_inventory()
@ -149,12 +144,7 @@ function mcl_cauldrons.take_small_cauldron(pos, itemstack, user, sounds)
elseif itemstack:get_count() == 1 then elseif itemstack:get_count() == 1 then
return item_name return item_name
else else
if inv:room_for_item("main", item_name) then return give_item(user, ItemStack(mcl_cauldrons.registered_cauldrons[nn.name].bucket))
inv:add_item("main", item_name)
else
minetest.add_item(placer:get_pos(), item_name)
end
itemstack:take_item()
end end
end end
else else
@ -216,50 +206,3 @@ function mcl_cauldrons.register_cauldron_type(def)
end end
end end
end end
mcl_cauldrons.register_cauldron_type({
name = "water",
bucket = "mcl_buckets:bucket_water",
bottle = "mcl_potions:water",
desc = S("Cauldron (%s/3 Water)"),
texture = "default_water_source_animated.png"
})
if minetest.get_modpath("mclx_core") then
--register_filled_cauldron(1, S("Cauldron (1/3 River Water)"), true)
--register_filled_cauldron(2, S("Cauldron (2/3 River Water)"), true)
--register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true)
end
minetest.register_craft({
output = "mcl_cauldrons:cauldron",
recipe = {
{ "mcl_core:iron_ingot", "", "mcl_core:iron_ingot" },
{ "mcl_core:iron_ingot", "", "mcl_core:iron_ingot" },
{ "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" },
}
})
minetest.register_abm({
label = "cauldrons",
nodenames = {"group:cauldron_filled"},
interval = 0.5,
chance = 1,
action = function(pos, node)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.4)) do
if mcl_burning.is_burning(obj) then
mcl_burning.extinguish(obj)
local new_group = minetest.get_item_group(node.name, "cauldron_filled") - 1
minetest.swap_node(pos, {name = "mcl_cauldrons:cauldron" .. (new_group == 0 and "" or "_" .. new_group)})
break
end
end
end
})
for i = 1, 3 do --Backward compatibility
minetest.register_alias("mcl_cauldrons:cauldron_"..i, "mcl_cauldrons:cauldron_water_"..i)
end
for i = 1, 3 do
minetest.register_alias("mcl_cauldrons:cauldron_"..i.."r", "mcl_cauldrons:cauldron_river_water_"..i)
end

View File

@ -0,0 +1,47 @@
local S = minetest.get_translator(minetest.get_current_modname())
mcl_cauldrons.register_cauldron_type({
name = "water",
bucket = "mcl_buckets:bucket_water",
bottle = "mcl_potions:water",
desc = S("Cauldron (%s/3 Water)"),
texture = "default_water_source_animated.png"
})
if minetest.get_modpath("mclx_core") then
--register_filled_cauldron(1, S("Cauldron (1/3 River Water)"), true)
--register_filled_cauldron(2, S("Cauldron (2/3 River Water)"), true)
--register_filled_cauldron(3, S("Cauldron (3/3 River Water)"), true)
end
minetest.register_craft({
output = "mcl_cauldrons:cauldron",
recipe = {
{ "mcl_core:iron_ingot", "", "mcl_core:iron_ingot" },
{ "mcl_core:iron_ingot", "", "mcl_core:iron_ingot" },
{ "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" },
}
})
minetest.register_abm({
label = "cauldrons",
nodenames = {"group:cauldron_filled"},
interval = 0.5,
chance = 1,
action = function(pos, node)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.4)) do
if mcl_burning.is_burning(obj) then
mcl_burning.extinguish(obj)
local new_group = minetest.get_item_group(node.name, "cauldron_filled") - 1
minetest.swap_node(pos, {name = "mcl_cauldrons:cauldron" .. (new_group == 0 and "" or "_" .. new_group)})
break
end
end
end
})
for i = 1, 3 do --Backward compatibility
minetest.register_alias("mcl_cauldrons:cauldron_"..i, "mcl_cauldrons:cauldron_water_"..i)
end
for i = 1, 3 do
minetest.register_alias("mcl_cauldrons:cauldron_"..i.."r", "mcl_cauldrons:cauldron_river_water_"..i)
end

View File

@ -0,0 +1,35 @@
local create_cauldron_nodebox = function(water_level)
local floor_y
if water_level == 0 then -- empty
floor_y = -0.1875
elseif water_level == 1 then -- 1/3 filled
floor_y = 1/16
elseif water_level == 2 then -- 2/3 filled
floor_y = 4/16
elseif water_level == 3 then -- full
floor_y = 7/16
end
return {
type = "fixed",
fixed = {
{-0.5, -0.1875, -0.5, -0.375, 0.5, 0.5}, -- Left wall
{0.375, -0.1875, -0.5, 0.5, 0.5, 0.5}, -- Right wall
{-0.375, -0.1875, 0.375, 0.375, 0.5, 0.5}, -- Back wall
{-0.375, -0.1875, -0.5, 0.375, 0.5, -0.375}, -- Front wall
{-0.5, -0.3125, -0.5, 0.5, floor_y, 0.5}, -- Floor
{-0.5, -0.5, -0.5, -0.375, -0.3125, -0.25}, -- Left front foot, part 1
{-0.375, -0.5, -0.5, -0.25, -0.3125, -0.375}, -- Left front foot, part 2
{-0.5, -0.5, 0.25, -0.375, -0.3125, 0.5}, -- Left back foot, part 1
{-0.375, -0.5, 0.375, -0.25, -0.3125, 0.5}, -- Left back foot, part 2
{0.375, -0.5, 0.25, 0.5, -0.3125, 0.5}, -- Right back foot, part 1
{0.25, -0.5, 0.375, 0.375, -0.3125, 0.5}, -- Right back foot, part 2
{0.375, -0.5, -0.5, 0.5, -0.3125, -0.25}, -- Right front foot, part 1
{0.25, -0.5, -0.5, 0.375, -0.3125, -0.375}, -- Right front foot, part 2
}
}
end
mcl_cauldrons.cauldron_nodeboxes = {}
for w=0,3 do
mcl_cauldrons.cauldron_nodeboxes[w] = create_cauldron_nodebox(w)
end