From f13e56327e4ee3a78a95160142a5191bc3c5cb19 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 15 Apr 2019 20:40:58 -0400 Subject: [PATCH] updated to use new canvas features --- builder/viewer.lua | 53 +++++++++++++++++----------------------------- neural/Scanner.lua | 21 ++++++++++++------ neural/ores.lua | 9 ++++++++ 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/builder/viewer.lua b/builder/viewer.lua index 2411442..451bd77 100644 --- a/builder/viewer.lua +++ b/builder/viewer.lua @@ -1,3 +1,11 @@ +local Builder = require('builder.builder') +local Schematic = require('builder.schematic') +local TableDB = require('core.tableDB') +local Util = require('util') + +local fs = _G.fs +local peripheral = _G.peripheral + local n = peripheral.find "neuralInterface" if not n then error "run on neural interface" end @@ -5,38 +13,8 @@ if not n then error "run on neural interface" end if not n.hasModule "plethora:glasses" then error "needs overlay glasses" end if not n.hasModule "plethora:sensor" or not n.hasModule "plethora:introspection" or not n.getMetaOwner then error "needs entity sensor + bound introspection module" end -local itemDB = require('core.itemDB') -local Schematic = require('builder.schematic') -local TableDB = require('core.tableDB') -local Util = require('util') - -local colors = _G.colors -local fs = _G.fs - local BUILDER_DIR = 'usr/builder' -local Builder = require('builder.builder') - -Builder.schematic = Schematic() - -local function convertSingleBack(item) - if item then - item.id = item.name - item.dmg = item.damage - item.qty = item.count - item.max_size = item.maxCount - item.display_name = item.displayName - end - return item -end - -local function convertBack(t) - for _,v in pairs(t) do - convertSingleBack(v) - end - return t -end - --[[-- SubDB --]]-- local subDB = TableDB({ fileName = fs.combine(BUILDER_DIR, 'sub.db'), @@ -140,6 +118,7 @@ end subDB:load() print('Loading schematic') +Builder.schematic = Schematic() Builder.schematic:load(args[1]) print('Substituting blocks') @@ -149,11 +128,17 @@ Builder:substituteBlocks(Util.throttle()) local cn = n.canvas3d().create() local pos = n.getMetaOwner().withinBlock -cn.recenter({-pos.x, -pos.y, -pos.z}) +cn.recenter({-(pos.x + .5), -(pos.y + 2) + .5, -(pos.z + .5) }) + for i = 1, #Builder.schematic.blocks do - b = Builder.schematic:getComputedBlock(i) - if b.id ~= "minecraft:air" then - cn.addBox(b.x, b.y-10, b.z, 0xffffff40).setDepthTested(false) + local b = Builder.schematic:getComputedBlock(i) + if b.id ~= "minecraft:air" and b.id ~= 'minecraft:water' then + local s, m = pcall(function() + cn.addItem({ b.x, b.y, b.z }, b.id, b.dmg) + end) + if not s and m then + printError(m) + end end end diff --git a/neural/Scanner.lua b/neural/Scanner.lua index 3a3915a..766988b 100644 --- a/neural/Scanner.lua +++ b/neural/Scanner.lua @@ -136,11 +136,20 @@ function page.detail:show(blocks, entry) for _, b in pairs(blocks) do if not projecting[b.id] then projecting[b.id] = b - b.box = canvas.addBox( - pos.x - offset.x + b.x + -(pos.x % 1) + .25, - pos.y - offset.y + b.y + -(pos.y % 1) + .25, - pos.z - offset.z + b.z + -(pos.z % 1) + .25, - .5, .5, .5) + pcall(function() + b.box = canvas.addItem({ + pos.x - offset.x + b.x + -(pos.x % 1) + .5, + pos.y - offset.y + b.y + -(pos.y % 1) + .5, + pos.z - offset.z + b.z + -(pos.z % 1) + .5 }, + b.name, b.damage, .5) + end) + if not b.box then + b.box = canvas.addBox( + pos.x - offset.x + b.x + -(pos.x % 1) + .25, + pos.y - offset.y + b.y + -(pos.y % 1) + .25, + pos.z - offset.z + b.z + -(pos.z % 1) + .25, + .5, .5, .5) + end b.box.setDepthTested(false) end end @@ -190,4 +199,4 @@ UI:pullEvents() if canvas then canvas:clear() -end +end \ No newline at end of file diff --git a/neural/ores.lua b/neural/ores.lua index 5c1f5b0..2a8518a 100644 --- a/neural/ores.lua +++ b/neural/ores.lua @@ -90,6 +90,7 @@ local function update() for _, b in pairs(blocks) do if not projecting[b.id] then projecting[b.id] = b + --[[ b.box = canvas.addFrame({ pos.x - offset.x + b.x + -(pos.x % 1) + .5, pos.y - offset.y + b.y + -(pos.y % 1) + .5, @@ -97,6 +98,14 @@ local function update() }) b.box.setDepthTested(false) b.box.addItem({ 0, 0 }, b.name, b.damage, 2) + --]] + + b.box = canvas.addItem({ + pos.x - offset.x + b.x + -(pos.x % 1) + .5, + pos.y - offset.y + b.y + -(pos.y % 1) + .5, + pos.z - offset.z + b.z + -(pos.z % 1) + .5, + }, b.name, b.damage, .5) + b.box.setDepthTested(false) end end