Nathan.S wrote:How do I go about finding a node to the left or right of the placed node, I can find nodes behind, in front, above and below, but I need to figure out a node to the side so I can modify either the node next in line or the node being placed.
local function vectorCross(v1, v2)
return { x = v1.y * v2.z - v1.z * v2.y,
y = v1.z * v2.x - v1.x * v2.z,
z = v1.x * v2.y - v1.y * v2.x };
end;
local upDir = { x = 0, y = 0, z = 1 }; -- EDIT: oops! no, should be {x=0,y=1,z=0}
local rightDir = vector.normalize(vectorCross(forwardDir, upDir)); -- EDIT: oops! no, should reverse forward/up
local function cardinalDirection(vec)
local x, y = vec.x, vec.y;
local xm, ym = math.abs(x), math.abs(y);
if xm >= ym then
return { x = x / xm, y = 0, z = 0 };
else
return { x = 0, y = y / ym, z = 0 };
end;
end;
prestidigitator wrote:Nathan.S wrote:How do I go about finding a node to the left or right of the placed node, I can find nodes behind, in front, above and below, but I need to figure out a node to the side so I can modify either the node next in line or the node being placed.
It sort of depends on what you mean by, "left/right." Probably a vector cross product (not included in Minetest's 'vector.*' API) will be helpful: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
local function vectorCross(v1, v2)
return { x = v1.y * v2.z - v1.z * v2.y,
y = v1.z * v2.x - v1.x * v2.z,
z = v1.x * v2.y - v1.y * v2.x };
end;
Then you'd want to cross the "forward" direction with the "up" direction. If "forward" and "up" aren't perpendicular (for example if "forward" is the direction the player is looking), you'd want to normalize the result: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
local upDir = { x = 0, y = 0, z = 1 };
local rightDir = vector.normalize(vectorCross(forwardDir, upDir));
(Things would be more complicated if you were allowed to tip your head to the side like touching your ear to your shoulder, but by design this never happens in Minetest.) Now you have a vector pointing straight to the camera's right. To find a node "in that direction" you PROBABLY want to figure out which of the x or y coordinates has the biggest magnitude (unless you want to consider diagonals...?):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
local function cardinalDirection(vec)
local x, y = vec.x, vec.y;
local xm, ym = math.abs(x), math.abs(y);
if xm >= ym then
return { x = x / xm, y = 0, z = 0 };
else
return { x = 0, y = y / ym, z = 0 };
end;
end;
Don wrote:Any chance you could give a link to the lua? I don't understand what you are doing here. I would love to learn it
Hybrid Dog wrote:prestigator: Does this use the cross product in some way too?
viewtopic.php?p=174387#p174387
math.abs(dir.x) < math.abs(dir.z)right_pos.x = right_pos.x+dir.z/math.abs(dir.z)
-- or
right_pos.z = right_pos.z-dir.x/math.abs(dir.x)local forwardDir = placer:get_look_dir();
local upDir = { x = 0, y = 1, z = 0 }; -- fixed
local rightDir = vector.normalize(vectorCross(upDir, forwardDir)); -- fixed
local rightInc = cardinalDirection(rightDir);
local rightPos = vector.add(pos, rightInc);local forwardDir = placer:get_look_dir();
local upDir = { x = 0, y = 1, z = 0 }; -- fixed
local rightVec = vectorCross(upDir, forwardDir); -- fixed
local rightInc = cardinalDirection(rightVec);
local rightPos = vector.add(pos, rightInc);local function rightDir()
local ang = (player:get_look_yaw() - 0.25*math.pi) % (2*math.pi);
if ang < 0.5*math.pi then
return { x = 1, y = 0, z = 0 };
elseif ang < math.pi then
return { x = 0, y = 0, z = 1 };
elseif ang < 1.5*math.pi then
return { x = -1, y = 0, z = 0 };
else
return { x = 0, y = 0, z = -1 };
end;
end;
local rightPos = vector.add(pos, rightDir());
rubenwardy wrote:Why is using a left handed coordinate system stupid?
Hybrid Dog wrote:as far as l know its impossible to look exactly straight up or down
prestidigitator wrote:Don wrote:Any chance you could give a link to the lua? I don't understand what you are doing here. I would love to learn it
I wrote the Lua for the response. I'd be happy to help with bits that are unclear though, if you elaborate on what is unclear.
-- If torch or plants touching water then drop as item
minetest.register_abm({
nodenames = {"default:torch", "group:flora"},
neighbors = {"group:water"},
interval = 5,
chance = 1,
action = function(pos, node)
local num = #minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z}, {x=pos.x+1, y=pos.y, z=pos.z}, {"group:water"})
num = num + #minetest.find_nodes_in_area({x=pos.x, y=pos.y, z=pos.z-1}, {x=pos.x, y=pos.y, z=pos.z+1}, {"group:water"})
num = num + #minetest.find_nodes_in_area({x=pos.x, y=pos.y+1, z=pos.z}, {x=pos.x, y=pos.y+1, z=pos.z}, {"group:water"})
if num > 0 then
minetest.set_node(pos, {name="default:water_flowing"})
minetest.add_item(pos, {name = node.name})
end
end,
})BrunoMine wrote:How can I check if a player in coordinated (100, 100, 100)?
local position = player:getpos()
if math.floor(position.x) == 100 and math.floor(position.y) == 100 and math.floor(position.z) == 100 then
end
local player = minetest.get_player_by_name("player12")
BrunoMine wrote:Is there a simpler way? I want to prevent a player can put a block in on a coordinate that there is already a player.
note: players use this technique to view caves through the wall (x scann).
local protected = minetest.is_protected
function minetest.is_protected(pos, ...)
local v = protected(pos, ...)
if v then
return v
end
for _,player in pairs(minetest.get_connected_players()) do
local ppos = vector.round(player:getpos())
local in_node = vector.equals(ppos, pos)
if not in_node then
ppos.y = ppos.y+1
in_node = vector.equals(ppos, pos)
end
if in_node then
return true
end
end
return v
end
Hybrid Dog wrote:BrunoMine wrote:Is there a simpler way? I want to prevent a player can put a block in on a coordinate that there is already a player.
note: players use this technique to view caves through the wall (x scann).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
local protected = minetest.is_protected
function minetest.is_protected(pos, ...)
local v = protected(pos, ...)
if v then
return v
end
for _,player in pairs(minetest.get_connected_players()) do
local ppos = vector.round(player:getpos())
local in_node = vector.equals(ppos, pos)
if not in_node then
ppos.y = ppos.y+1
in_node = vector.equals(ppos, pos)
end
if in_node then
return true
end
end
return v
end
local protected = minetest.is_protected
function minetest.is_protected(pos)
local v = protected(pos)
if v then
return v
end
if pos.y > 80 then
return v
end
for _,player in pairs(minetest.get_connected_players()) do
local ppos = vector.round(player:getpos())
local in_node = vector.equals(ppos, pos)
if not in_node then
ppos.y = ppos.y+1
in_node = vector.equals(ppos, pos)
end
if in_node then
return true
end
end
return v
end
minetest.register_node("tnt:tnt", {
description = "TNT",
tiles = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png"},
groups = {dig_immediate=2, mesecon=2},
sounds = default.node_sound_wood_defaults(),
on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "default:torch" then
if minetest.get_player_privs(puncher).use_tnt then
minetest.sound_play("tnt_ignite", {pos=pos})
minetest.set_node(pos, {name="tnt:tnt_burning"})
minetest.get_node_timer(pos):start(4)
return
else then
minetest.chat_send_player(puncher, "You don't have the required priv to use tnt.")
return
end
end
end,
mesecons = {effector = {action_on = boom}},
}afeys wrote:I'm (at least trying to) making a mod which puts content (small buildings, ruins, hidden treasures,....) in the game. But I'd like to put other content in a desert than in a jungle, so I'd like to find out the biome for node at x,y,z.
CWz wrote:Hello again i am trying to set up tnt so it will require a priv but it seems to crashYour 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
minetest.register_node("tnt:tnt", {
description = "TNT",
tiles = {"tnt_top.png", "tnt_bottom.png", "tnt_side.png"},
groups = {dig_immediate=2, mesecon=2},
sounds = default.node_sound_wood_defaults(),
on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "default:torch" then
if minetest.get_player_privs(puncher).use_tnt then
minetest.sound_play("tnt_ignite", {pos=pos})
minetest.set_node(pos, {name="tnt:tnt_burning"})
minetest.get_node_timer(pos):start(4)
return
else then
minetest.chat_send_player(puncher, "You don't have the required priv to use tnt.")
return
end
end
end,
mesecons = {effector = {action_on = boom}},
}
#mgv6_np_biome = 0, 1, (250, 250, 250), 9130, 3, 0.50, 2.0
#mgv6_np_humidity = 0.5, 0.5, (500, 500, 500), 72384, 4, 0.66, 2.0paramat wrote:However biome noise has an offset added, so for (x, z) calculate noise at (x + 150, z + 50)
prestidigitator wrote:Huh? An arbitrary offset was just added for some reason? That's really screwed up. I hope there's a bugfix request for that....
Users browsing this forum: No registered users and 5 guests