reprap = {}
-- adds <material> to each node in a line from <from_position> to <to_position>
function reprap.drawline3d(from_position, to_position, material)
--modified from https://github.com/ryanramage/bresenham3d/blob/master/index.js
--lua port by jin_xi
local temp
local x0 = math.floor(from_position.x)
local y0 = math.floor(from_position.y)
local z0 = math.floor(from_position.z)
local x1 = math.floor(to_position.x)
local y1 = math.floor(to_position.y)
local z1 = math.floor(to_position.z)
--'steep' xy Line, make longest delta x plane
local swap_xy = math.abs(y1 - y0) > math.abs(x1 - x0)
if swap_xy then
temp = x0; x0 = y0; y0 = temp --swap(x0, y0);
temp = x1; x1 = y1; y1 = temp --swap(x1, y1);
end
local swap_xz = math.abs(z1 - z0) > math.abs(x1 - x0)
if swap_xz then
temp = x0; x0 = z0; z0 = temp --swap(x0, z0);
temp = x1; x1 = z1; z1 = temp --swap(x1, z1);
end
--delta is Length in each plane
local delta_x = math.abs(x1 - x0)
local delta_y = math.abs(y1 - y0)
local delta_z = math.abs(z1 - z0)
--drift controls when to step in 'shallow' planes
--starting value keeps Line centred
local drift_xy = (delta_x / 2)
local drift_xz = (delta_x / 2)
--direction of line
local step_x = 1
if x0 > x1 then step_x = -1 end
local step_y = 1
if y0 > y1 then step_y = -1 end
local step_z = 1
if z0 > z1 then step_z = -1 end
--starting point
local y = y0
local z = z0
--step through longest delta (which we have swapped to x)
local cx, cy, cz
for x = x0, x1, step_x do
--copy position
cx = x; cy = y; cz = z
--unswap (in reverse)
if swap_xz then
temp = cx; cx = cz; cz = temp --swap(cx, cz)
end
if swap_xy then
temp = cx; cx = cy; cy = temp --swap(cx, cy)
end
print("drawing dot: "..cx..', '..cy..', '..cz)
minetest.env:add_node({ x = cx, y = cy, z = cz }, { name=material, param2=2 })
--update progress in other planes
drift_xy = drift_xy - delta_y
drift_xz = drift_xz - delta_z
--step in y plane
if drift_xy < 0 then
y = y + step_y
drift_xy = drift_xy + delta_x
end
--same in z
if (drift_xz < 0) then
z = z + step_z
drift_xz = drift_xz + delta_x
end
end
end
-- process a gcode file <filename> placing <material> on each point touched by the machine
function reprap.process_gcode(filename, material, center)
local path = minetest.get_modpath("reprap").."/"..filename
local f = io.open(path)
local line
local cmd, param = "", ""
local lastx, lasty, lastz
local cmdx, cmdy, cmdz
lastx = 0
lasty = 0
lastz = 0
for line in f:lines() do
if (line ~= "") and (line:sub(1,1) ~= ";") then
if string.find(line, "G1 ") then
cmdx = lastx
cmdy = lasty
cmdz = lastz
for cmd, param in string.gmatch(line, "(%w)([0-9.-]+)") do
param = tonumber(param)
if cmd == "X" then
cmdx = param
elseif cmd == "Y" then
cmdz = param
elseif cmd == "Z" then
cmdy = param
end
end
reprap.drawline3d(
{ x = center.x + lastx, y = center.y + lasty, z = center.z + lastz },
{ x = center.x + cmdx, y = center.y + cmdy, z = center.z + cmdz },
material
)
lastx = cmdx
lasty = cmdy
lastz = cmdz
end
end
end
end
minetest.register_chatcommand("reprap", {
params = "<gcodefilename>,<material>,<x>,<y>,<z>",
description = "start printing a gcode file",
privs = {},
func = function(name, param)
local paramlist
print(param)
paramlist = string.split(param, ",")
print(paramlist[1])
print(paramlist[2])
print(paramlist[3])
print(paramlist[4])
print(paramlist[5])
filename = paramlist[1]
material = paramlist[2]
drawx = tonumber(paramlist[3])
drawy = tonumber(paramlist[4])
drawz = tonumber(paramlist[5])
reprap.process_gcode(filename, material, { x=drawx, y=drawy, z=drawz })
-- reprap.process_gcode("column.gcode", "default:mese", { x=-65, y=0, z=77 })
end
}
)
aldobr wrote:@stu you might be interested in my g-ode interpreter code for your builder npc:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
reprap = {}
-- adds <material> to each node in a line from <from_position> to <to_position>
function reprap.drawline3d(from_position, to_position, material)
--modified from https://github.com/ryanramage/bresenham3d/blob/master/index.js
--lua port by jin_xi
local temp
local x0 = math.floor(from_position.x)
local y0 = math.floor(from_position.y)
local z0 = math.floor(from_position.z)
local x1 = math.floor(to_position.x)
local y1 = math.floor(to_position.y)
local z1 = math.floor(to_position.z)
--'steep' xy Line, make longest delta x plane
local swap_xy = math.abs(y1 - y0) > math.abs(x1 - x0)
if swap_xy then
temp = x0; x0 = y0; y0 = temp --swap(x0, y0);
temp = x1; x1 = y1; y1 = temp --swap(x1, y1);
end
local swap_xz = math.abs(z1 - z0) > math.abs(x1 - x0)
if swap_xz then
temp = x0; x0 = z0; z0 = temp --swap(x0, z0);
temp = x1; x1 = z1; z1 = temp --swap(x1, z1);
end
--delta is Length in each plane
local delta_x = math.abs(x1 - x0)
local delta_y = math.abs(y1 - y0)
local delta_z = math.abs(z1 - z0)
--drift controls when to step in 'shallow' planes
--starting value keeps Line centred
local drift_xy = (delta_x / 2)
local drift_xz = (delta_x / 2)
--direction of line
local step_x = 1
if x0 > x1 then step_x = -1 end
local step_y = 1
if y0 > y1 then step_y = -1 end
local step_z = 1
if z0 > z1 then step_z = -1 end
--starting point
local y = y0
local z = z0
--step through longest delta (which we have swapped to x)
local cx, cy, cz
for x = x0, x1, step_x do
--copy position
cx = x; cy = y; cz = z
--unswap (in reverse)
if swap_xz then
temp = cx; cx = cz; cz = temp --swap(cx, cz)
end
if swap_xy then
temp = cx; cx = cy; cy = temp --swap(cx, cy)
end
print("drawing dot: "..cx..', '..cy..', '..cz)
minetest.env:add_node({ x = cx, y = cy, z = cz }, { name=material, param2=2 })
--update progress in other planes
drift_xy = drift_xy - delta_y
drift_xz = drift_xz - delta_z
--step in y plane
if drift_xy < 0 then
y = y + step_y
drift_xy = drift_xy + delta_x
end
--same in z
if (drift_xz < 0) then
z = z + step_z
drift_xz = drift_xz + delta_x
end
end
end
-- process a gcode file <filename> placing <material> on each point touched by the machine
function reprap.process_gcode(filename, material, center)
local path = minetest.get_modpath("reprap").."/"..filename
local f = io.open(path)
local line
local cmd, param = "", ""
local lastx, lasty, lastz
local cmdx, cmdy, cmdz
lastx = 0
lasty = 0
lastz = 0
for line in f:lines() do
if (line ~= "") and (line:sub(1,1) ~= ";") then
if string.find(line, "G1 ") then
cmdx = lastx
cmdy = lasty
cmdz = lastz
for cmd, param in string.gmatch(line, "(%w)([0-9.-]+)") do
param = tonumber(param)
if cmd == "X" then
cmdx = param
elseif cmd == "Y" then
cmdz = param
elseif cmd == "Z" then
cmdy = param
end
end
reprap.drawline3d(
{ x = center.x + lastx, y = center.y + lasty, z = center.z + lastz },
{ x = center.x + cmdx, y = center.y + cmdy, z = center.z + cmdz },
material
)
lastx = cmdx
lasty = cmdy
lastz = cmdz
end
end
end
end
minetest.register_chatcommand("reprap", {
params = "<gcodefilename>,<material>,<x>,<y>,<z>",
description = "start printing a gcode file",
privs = {},
func = function(name, param)
local paramlist
print(param)
paramlist = string.split(param, ",")
print(paramlist[1])
print(paramlist[2])
print(paramlist[3])
print(paramlist[4])
print(paramlist[5])
filename = paramlist[1]
material = paramlist[2]
drawx = tonumber(paramlist[3])
drawy = tonumber(paramlist[4])
drawz = tonumber(paramlist[5])
reprap.process_gcode(filename, material, { x=drawx, y=drawy, z=drawz })
-- reprap.process_gcode("column.gcode", "default:mese", { x=-65, y=0, z=77 })
end
}
)
it allows reading a gcode file, generated from cad models, like a virtul 3d printer (reprap)
stu wrote:LuxAtheris wrote:So hows the bug fixing?
There are no bugs I am currently aware of, at least none that are within my control (lua wise).
Work on this mod is pretty much on hold until entities are properly fixed in minetest.jenova99sephiros wrote:Please battler mob!
Get the goods when you win them!
For this sort of thing you should look at Simple Mobs or Mob Framework.
CheerfulCherub wrote:Can anyone help me set up the 3d or class Characters, I download it to my mod folder and extracted and name the right name but I don't exactly know how to put the character in 3d and I tried the command for class but no luck either, I know it's not the mod it's me. Please any help in greatly appreciated. I am using 0.49minetest, love this game, making a big castle in singleplayer.
Cheerful Cherub
14:45:28: ACTION[ServerThread]: kinkinkijkin digs base:grass at (-389,42,207)
14:45:36: ACTION[ServerThread]: CHAT: <hoodedice> And because we have >10 players, there might be rarely any lag
14:45:44: ACTION[ServerThread]: Zen places node npcf:guard_npc_spawner at (-459,22,-97)
14:45:44: ACTION[ServerThread]: facedir: 3
14:45:49: ACTION[ServerThread]: hoodedice leaves game. List of players: Zen kinkinkijkin
14:45:49: ERROR[main]: ServerError: .../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:108: attempt to index local 'npc_name' (a nil value)
14:45:49: ERROR[main]: stack traceback:
14:45:49: ERROR[main]: .../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:108: in function 'get_valid_npc_name'
14:45:49: ERROR[main]: .../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:334: in function <.../../games/nodetopia/mods/minetest-npcf/npcf/npcf.lua:326>
AL lib: FreeContext: (0x2c86420) Deleting 3 Source(s)
Esteban wrote:Stu I wonder that Is it possible to remove the name feature and checking? If so, could you please tell me what should I remove.
stu wrote:
Unfortunately the naming system is pretty fundamental to how this mod works so
I don't see an easy way it can be removed. You might be better off with sapier's mobf npcs
To be honest, I have not really worked on this for some time, it was written at
a time when my understanding of the minetest entity system (and the Lua language itself)
were a little bit naive, at best.
I have just pushed a couple of changes which should fix that bug reported in January (sorry I missed that)
and removed the duplicate entity checking as it should not be needed anymore and didn't work that well anyway.
balthazariv wrote:How do I remove them ?
I hit them but they resistent.
Esteban wrote:/npc remove npcsname
SAMIAMNOT wrote:Hey, I got two issues,
#1 Only Guards and Deco NPCs move
#2 I can't kill any of the NPCs.
How do you fix this? I made a hotel complete with a cafeteria but I can't go in cause this NPC is blocking the way. Cant kill him either.
EDIT 1: Never mind. Esteban fixed it. But still, how do you make them move?
SAMIAMNOT wrote:I issued the command twice and nothing happened.
SAMIAMNOT wrote:Thanks! It worked! Goodbye Ken! ;)
Esteban wrote:Info npcs and trader npcs do not move. The builder moves as he builds the basic_hut.we.
Its not a bug or problem, they were coded that way.
SAMIAMNOT wrote:How do blacklists and whitelists work?
kidmondo wrote:my only question is what do i save it as?
Ikishida wrote:Hey man,can I Please use this for my Sword Art Online/Gun Gale Online Mod I wanna make a comeback mod
Users browsing this forum: No registered users and 2 guests