From ad8065d9ca6fa0bceb92ec3cad55309c324ce130 Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Wed, 18 Jan 2017 17:34:16 +0100 Subject: [PATCH] initial work --- npcf_builder/depends.txt | 1 + npcf_builder/init.lua | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/npcf_builder/depends.txt b/npcf_builder/depends.txt index b093c1a..d341ce5 100644 --- a/npcf_builder/depends.txt +++ b/npcf_builder/depends.txt @@ -1 +1,2 @@ npcf +schemlib? diff --git a/npcf_builder/init.lua b/npcf_builder/init.lua index 9685554..07a81bf 100644 --- a/npcf_builder/init.lua +++ b/npcf_builder/init.lua @@ -5,6 +5,7 @@ local MAX_POS = 1000 local DEFAULT_NODE = {name="air"} local SCHEMS = {"basic_hut.we"} local INSTABUILD_PATH = minetest.get_modpath("instabuild") +local SCHEMLIB_PATH = minetest.get_modpath("schemlib") if INSTABUILD_PATH then for _,v in ipairs({"factory.we", "large_warehouse.we", "small_farm.we", "tall_tower.we", "large_farm.we", "mansion.we", "small_house.we", "large_house.we", "modern_house.we", @@ -44,12 +45,25 @@ end local function load_schematic(self, filename) local input = nil + local fullpath if INSTABUILD_PATH then - input = io.open(INSTABUILD_PATH.."/models/"..filename, "r") - end - if not input then - input = io.open(MODPATH.."/schems/"..filename, "r") + fullpath = INSTABUILD_PATH.."/models/"..filename + else + fullpath = MODPATH.."/schems/"..filename end + + if SCHEMLIB_PATH then + self.schemlib_plan = schemlib.plan.new() + self.schemlib_plan:read_from_schem_file(fullpath) + self.build_plan.anchor_pos = self.metadata.build_pos + --TODO: + --self.var.nodedata[i] = {pos=pos, node=node, item_name=item_name} --?? + --self.var.nodelist[item_name] = self.var.nodelist[item_name] + 1 + --self.metadata.inventory[item_name] = self.metadata.inventory[item_name] or 0 + + else --non-schemlib + input = io.open(fullpath, "r") + if input then local data = minetest.deserialize(input:read('*all')) io.close(input) @@ -97,6 +111,7 @@ local function load_schematic(self, filename) end end end + end --non-schemlib end local function show_build_form(self, player_name) @@ -213,6 +228,7 @@ npcf:register_npc("npcf_builder:npc" ,{ local speed = 0 if self.metadata.building == true then local nodedata = self.var.nodedata[self.metadata.index] + -- TODO: nodedata analog aufbauen aus "get_next" pos.y = math.floor(pos.y) local acceleration = {x=0, y=-10, z=0} if pos.y < nodedata.pos.y then