fixes for cargo boat

master
Izzy 2018-07-07 00:55:12 -06:00
parent af05dec084
commit faff60c626
2 changed files with 96 additions and 29 deletions

View File

@ -597,10 +597,45 @@ if type(boat_data.entities) ~= "table" then
boat_data.entities = {}
end
-- recreate detached inventories
for id,v in pairs(boat_data.entities) do
local inv1 = minetest.create_detached_inventory("boats_steel_boat_"..id.."_hold1")
local inv2 = minetest.create_detached_inventory("boats_steel_boat_"..id.."_hold2")
local inv3 = minetest.create_detached_inventory("boats_steel_boat_"..id.."_hold3")
inv1:set_size(5 * 8)
inv2:set_size(5 * 8)
inv3:set_size(5 * 8)
if v.inventories then
inv1:set_lists(v.inventories[1])
inv2:set_lists(v.inventories[2])
inv3:set_lists(v.inventories[3])
end
end
local function serialize_inventory(id, n)
local inv = minetest.get_inventory({type="detached", name="boats_steel_boat_"..id.."_hold"..n})
return inv:get_lists()
end
local function save_data()
--print("saving")
mod_storage:set_int("next_entity", boat_data.next_entity);
for id,v in pairs(boat_data.entities) do
v.inventories[1] = serialize_inventory(id, 1)
v.inventories[2] = serialize_inventory(id, 2)
v.inventories[3] = serialize_inventory(id, 3)
end
mod_storage:set_string("entities", minetest.serialize(boat_data.entities))
end
@ -616,12 +651,18 @@ local function deploy_boat(boat)
boat_data.entities[id] = {
id = id,
inventories = {
},
inventories = {}
}
local inv1 = minetest.create_detached_inventory("boats_steel_boat_"..id.."_hold1")
local inv2 = minetest.create_detached_inventory("boats_steel_boat_"..id.."_hold2")
local inv3 = minetest.create_detached_inventory("boats_steel_boat_"..id.."_hold3")
inv1:set_size(5 * 8)
inv2:set_size(5 * 8)
inv3:set_size(5 * 8)
save_data()
end
@ -666,6 +707,28 @@ local function get_steel_boat_formspec()
end
local function get_steel_boat_inv_formspec(boat, hold)
local state_str = "Sailing"
return "size[8,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;hold;4,2;3,2;]"..
"image[2,2.5;1,1;default_furnace_fire_bg.png]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
"listring[context;dst]"..
"listring[current_player;main]"..
"listring[context;src]"..
"listring[current_player;main]"..
"listring[context;fuel]"..
"listring[current_player;main]"..
default.get_hotbar_bg(0, 4.25)
end
function boat_steel.on_rightclick(self, clicker)
if not clicker or not clicker:is_player() then
return
@ -694,7 +757,8 @@ end
local function splitname(name)
local c = string.find(name, "Q")
print("c " ..c)
if c == nil then return nil, nil end
--print("c " ..c)
return string.sub(name, 1, c - 1), string.sub(name, c + 1, string.len(name))
end
@ -704,7 +768,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local formprefix, id = splitname(formname)
if formprefix ~= "boats:steel_boat_form" then
print("wrong prefix: " .. formname .. " - " .. formprefix)
--print("wrong prefix: " .. formname .. " - " .. formprefix)
return
end
@ -722,6 +786,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
enter_boat(boat, player)
end
return
elseif fields.hold_a then
minetest.show_formspec(player:get_player_name(), "boats:steel_boat_formQ"..self.data.id, get_steel_boat_inv_formspec(self, "a"))
end
end)
@ -853,17 +920,17 @@ function boat_steel.on_step(self, dtime)
end
end
local drift = {x=0,y=0,z=0}
if speed < .1 then
print("drifting")
-- float away randomly
drift = {
x = math.random(5.1, 10.9),
y = 0,
z = math.random(5.1, 10.9),
}
end
-- local drift = {x=0,y=0,z=0}
-- if speed < .1 then
-- print("drifting")
-- -- float away randomly
-- drift = {
-- x = math.random(5.1, 10.9),
-- y = 0,
-- z = math.random(5.1, 10.9),
-- }
-- end
--
if self.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then
@ -923,7 +990,7 @@ function boat_steel.on_step(self, dtime)
end
end
end
self.object:setvelocity(vector.add(new_velo, drift))
self.object:setvelocity(new_velo)
self.object:setacceleration(new_acce)

View File

@ -45,7 +45,7 @@ local function grab_fuel(inv)
local list = inv:get_list("fuel")
for i,st in ipairs(list) do
print(st:get_name())
--print(st:get_name())
local fuel, remains
fuel, remains = minetest.get_craft_result({
method = "fuel",
@ -93,13 +93,13 @@ end
local function put_item(pos, item)
local meta = minetest.get_meta(pos)
if meta == nil then
print("af: wasting item for lack of output")
--print("af: wasting item for lack of output")
return
end
local inv = meta:get_inventory()
if inv == nil then
print("af: wasting item for lack of output inventory")
--print("af: wasting item for lack of output inventory")
return
end
@ -128,9 +128,9 @@ local function af_on_timer(pos, elapsed)
local burned = elapsed
local turn_off = false
print("\n\naf timer")
print("fuel_burned: " .. fuel_burned)
print("fuel_time: " .. fuel_time)
--print("\n\naf timer")
--print("fuel_burned: " .. fuel_burned)
--print("fuel_time: " .. fuel_time)
-- if fuel_burned <= fuel_time or fuel_time == 0 then
-- -- use fuel
@ -173,19 +173,19 @@ local function af_on_timer(pos, elapsed)
if cooked ~= nil then
cook_item = cooked.item:to_table()
cook_time_remaining = cooked.time
print(cook_item)
--print(cook_item)
meta:set_string("cook_item", minetest.serialize(cook_item))
meta:set_float("cook_time_remaining", cooked.time)
else
-- nothing to cook, carry on
print("nothing to cook")
--print("nothing to cook")
cook_item = nil
meta:set_string("cook_item", "")
end
else
print(cook_item)
--print(cook_item)
cook_item = minetest.deserialize(cook_item)
end
@ -193,11 +193,11 @@ local function af_on_timer(pos, elapsed)
if cook_item ~= nil and burned > 0 then
local remain = cook_time_remaining - burned
print("remain: ".. remain);
--print("remain: ".. remain);
if remain > 0 then
meta:set_float("cook_time_remaining", remain)
else
print("finished")
--print("finished")
-- cooking is finished
put_item({x=pos.x, y=pos.y - 1, z=pos.z}, cook_item.name .. " " .. (cook_item.count or 1))