Merge pull request #6 from everamzah/master

Don't continue to add and subtract if dst is full
This commit is contained in:
Dragonop 2016-01-19 11:57:01 -03:00
commit d8c9f54d2f
2 changed files with 18 additions and 47 deletions

@ -1,4 +1,3 @@
-- --
-- Formspecs -- Formspecs
-- --
@ -61,7 +60,6 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
if listname == "fuel" then -- "Water" if listname == "fuel" then -- "Water"
--if minetest.get_craft_result({method="fuel", width=1, items={stack}}).time ~= 0 then
if minetest.get_item_group(stack:get_name(), "h2o") > 0 then if minetest.get_item_group(stack:get_name(), "h2o") > 0 then
if inv:is_empty("src") then if inv:is_empty("src") then
meta:set_string("infotext", "Claycrafter is empty") meta:set_string("infotext", "Claycrafter is empty")
@ -112,7 +110,7 @@ minetest.register_node("claycrafter:claycrafter", {
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take
}) })
minetest.register_node("claycrafter:claycrafter_active", { minetest.register_node("claycrafter:claycrafter_active", {
@ -129,7 +127,7 @@ minetest.register_node("claycrafter:claycrafter_active", {
aspect_w = 16, aspect_w = 16,
aspect_h = 16, aspect_h = 16,
length = 1.5 length = 1.5
}, }
} }
}, },
paramtype2 = "facedir", paramtype2 = "facedir",
@ -144,7 +142,7 @@ minetest.register_node("claycrafter:claycrafter_active", {
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take
}) })
-- --
@ -194,29 +192,11 @@ minetest.register_abm({
-- Cooking -- Cooking
-- --
--[[
-- Check if we have cookable content
--local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
local cooked, aftercooked = minetest.get_item_group(inv:get_stack("src", 1):get_name(), "h2o")
local cookable = true
print(inv:get_stack("fuel", 1):get_name())
print(cooked)
--if cooked.time == 0 then
if cooked == 0 then
cookable = false
end
--]]
local cooked, aftercooked
local cooktime = minetest.get_item_group(inv:get_stack("fuel", 1):get_name(), "h2o") local cooktime = minetest.get_item_group(inv:get_stack("fuel", 1):get_name(), "h2o")
--print("cooktime: " .. cooktime)
local cookable = true local cookable = true
--print(inv:get_stack("src", 1):get_name())
if inv:get_stack("src", 1):get_name() ~= "claycrafter:compressed_dirt" then if inv:get_stack("src", 1):get_name() ~= "claycrafter:compressed_dirt" then
cookable = false cookable = false
end end
--print(tostring(cookable))
-- Check if we have enough fuel to burn -- Check if we have enough fuel to burn
if fuel_time < fuel_totaltime then if fuel_time < fuel_totaltime then
@ -226,26 +206,22 @@ minetest.register_abm({
-- If there is a cookable item then check if it is ready yet -- If there is a cookable item then check if it is ready yet
if cookable then if cookable then
src_time = src_time + 1 src_time = src_time + 1
--print("src_time: " .. src_time) if src_time >= cooktime then
if src_time >= cooktime then --cooked.time then
-- Place result in dst list if possible -- Place result in dst list if possible
--if inv:room_for_item("dst", ItemStack({name = "default:clay 4"})) then --cooked.item) then if inv:room_for_item("dst", ItemStack({name = "default:clay", count = 4})) then
inv:add_item("dst", {name = "default:clay", count = 4}) --cooked.item) print("Apparently, there's room.")
--inv:set_stack("src", 1, aftercooked.items[1]) inv:add_item("dst", {name = "default:clay", count = 4})
inv:remove_item("src", inv:get_stack("src", 1):get_name()) inv:remove_item("src", inv:get_stack("src", 1):get_name())
src_time = 0 src_time = 0
--end end
end end
end end
else else
-- Furnace ran out of fuel -- Furnace ran out of fuel
if cookable then if cookable then
-- We need to get new fuel -- We need to get new fuel
--local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
local fueltime = minetest.get_item_group(inv:get_stack("fuel", 1):get_name(), "h2o") local fueltime = minetest.get_item_group(inv:get_stack("fuel", 1):get_name(), "h2o")
--print("fueltime var is: " .. fueltime)
--if fuel.time == 0 then
if fueltime == 0 then if fueltime == 0 then
-- No valid fuel in fuel list -- No valid fuel in fuel list
fuel_totaltime = 0 fuel_totaltime = 0
@ -254,14 +230,10 @@ minetest.register_abm({
else else
-- Take fuel from fuel list -- Take fuel from fuel list
if inv:room_for_item("dst", ItemStack({name = "vessels:drinking_glass"})) then
inv:remove_item("fuel", inv:get_stack("fuel", 1):get_name()) inv:remove_item("fuel", inv:get_stack("fuel", 1):get_name())
inv:add_item("fuel", inv:add_item("dst", {name = "vessels:drinking_glass"})) inv:add_item("dst", {name = "vessels:drinking_glass"})
end
--inv:set_stack("fuel", 1, afterfuel.items[1])
--inv:add_item("fuel", 1, ItemStack({name = "vessels:drinking_glass"}))
--print("rund out?")
--inv:get_stack("fuel", 1):take_item()
fuel_totaltime = fueltime fuel_totaltime = fueltime
fuel_time = 0 fuel_time = 0
@ -282,13 +254,13 @@ minetest.register_abm({
local item_state = "" local item_state = ""
local item_percent = 0 local item_percent = 0
if cookable then if cookable then
item_percent = math.floor(src_time / cooktime * 100) --cooked.time * 100) item_percent = math.floor(src_time / cooktime * 100)
item_state = item_percent .. "%" item_state = item_percent .. "%"
else else
if srclist[1]:is_empty() then if srclist[1]:is_empty() then
item_state = "Empty" item_state = "Empty"
else else
item_state = "Not cookable" item_state = "No water"
end end
end end
@ -317,5 +289,5 @@ minetest.register_abm({
meta:set_float("src_time", src_time) meta:set_float("src_time", src_time)
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec)
meta:set_string("infotext", infotext) meta:set_string("infotext", infotext)
end, end
}) })

@ -15,12 +15,10 @@ minetest.register_craft({
}) })
--Glass of water --Glass of water
-- Water glasses, might should have stack_max = 1, change this if you preffer
minetest.register_craftitem("claycrafter:glass_of_water", { minetest.register_craftitem("claycrafter:glass_of_water", {
description = "Glass of Water", description = "Glass of Water",
inventory_image = "claycrafter_glass_of_water.png", inventory_image = "claycrafter_glass_of_water.png",
groups = {h2o = 1}, -- How much compressed dirt will turn to clay groups = {h2o = 1}, -- How much time to convert 1 compressed dirt to 4 clay
--stack_max = 1
}) })
minetest.register_craft({ minetest.register_craft({
@ -40,8 +38,9 @@ minetest.register_craft({
recipe = { recipe = {
{"group:wood", "default:steel_ingot", "group:wood"}, {"group:wood", "default:steel_ingot", "group:wood"},
{"group:wood", "default:glass", "group:wood"}, {"group:wood", "default:glass", "group:wood"},
{"default:stick", "bucket:bucket_water", "default:stick"}, {"default:stick", "bucket:bucket_water", "default:stick"}
} }
}) })
dofile(minetest.get_modpath("claycrafter") .. "/claycrafter.lua") dofile(minetest.get_modpath("claycrafter") .. "/claycrafter.lua")