summaryrefslogtreecommitdiff
path: root/technic
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-12-01 04:22:40 -0500
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-12-01 04:22:40 -0500
commit2922421f4a88e56a0a1c819f62bf2bc287835388 (patch)
treeb6dafb3d00ef05778e456716c03544279c2978fa /technic
parent67d414d2f9aa5999e3f1755543a68455b4bb6d99 (diff)
downloaddreambuilder_modpack-2922421f4a88e56a0a1c819f62bf2bc287835388.tar
dreambuilder_modpack-2922421f4a88e56a0a1c819f62bf2bc287835388.tar.gz
dreambuilder_modpack-2922421f4a88e56a0a1c819f62bf2bc287835388.tar.bz2
dreambuilder_modpack-2922421f4a88e56a0a1c819f62bf2bc287835388.tar.xz
dreambuilder_modpack-2922421f4a88e56a0a1c819f62bf2bc287835388.zip
Update several mods:
biome_lib, boost_cart, building_blocks, castle, homedecor, glooptest, currency, roads, invsaw, maptools, mesecons, moreblocks, nixie_tubes, pipeworks, signs_lib, technic, unified_inventory, unifiedbricks, worldedit, xban2
Diffstat (limited to 'technic')
-rw-r--r--technic/helpers.lua155
-rw-r--r--technic/machines/MV/wind_mill.lua21
-rw-r--r--technic/machines/other/frames.lua2
-rw-r--r--technic/tools/mining_lasers.lua12
4 files changed, 131 insertions, 59 deletions
diff --git a/technic/helpers.lua b/technic/helpers.lua
index 164cf7e..5780f27 100644
--- a/technic/helpers.lua
+++ b/technic/helpers.lua
@@ -63,64 +63,129 @@ technic.tube_inject_item = pipeworks.tube_inject_item or function(pos, start_pos
end
--- Based on code by Uberi: https://gist.github.com/Uberi/3125280
+--- Iterates over the node positions along the specified ray.
+-- The returned positions will not include the starting position.
function technic.trace_node_ray(pos, dir, range)
- local p = vector.round(pos)
- local x_step, y_step, z_step = 0, 0, 0
- local x_component, y_component, z_component = 0, 0, 0
- local x_intersect, y_intersect, z_intersect = 0, 0, 0
-
- if dir.x == 0 then
- x_intersect = math.huge
- elseif dir.x > 0 then
- x_step = 1
- x_component = 1 / dir.x
- x_intersect = x_component
- else
- x_step = -1
- x_component = 1 / -dir.x
- end
- if dir.y == 0 then
- y_intersect = math.huge
- elseif dir.y > 0 then
- y_step = 1
- y_component = 1 / dir.y
- y_intersect = y_component
- else
- y_step = -1
- y_component = 1 / -dir.y
- end
- if dir.z == 0 then
- z_intersect = math.huge
- elseif dir.z > 0 then
- z_step = 1
- z_component = 1 / dir.z
- z_intersect = z_component
- else
- z_step = -1
- z_component = 1 / -dir.z
- end
+ local x_step = dir.x > 0 and 1 or -1
+ local y_step = dir.y > 0 and 1 or -1
+ local z_step = dir.z > 0 and 1 or -1
+
+ local i = 1
+ return function(p)
+ -- Approximation of where we should be if we weren't rounding
+ -- to nodes. This moves forward a bit faster then we do.
+ -- A correction is done below.
+ local real_x = pos.x + (dir.x * i)
+ local real_y = pos.y + (dir.y * i)
+ local real_z = pos.z + (dir.z * i)
+
+ -- How far off we've gotten from where we should be.
+ local dx = math.abs(real_x - p.x)
+ local dy = math.abs(real_y - p.y)
+ local dz = math.abs(real_z - p.z)
- return function()
- if x_intersect < y_intersect then
- if x_intersect < z_intersect then
+ -- If the real position moves ahead too fast, stop it so we
+ -- can catch up. If it gets too far ahead it will smooth
+ -- out our movement too much and we won't turn fast enough.
+ if dx + dy + dz < 2 then
+ i = i + 1
+ end
+
+ -- Step in whichever direction we're most off course in.
+ if dx > dy then
+ if dx > dz then
p.x = p.x + x_step
- x_intersect = x_intersect + x_component
else
p.z = p.z + z_step
- z_intersect = z_intersect + z_component
end
- elseif y_intersect < z_intersect then
+ elseif dy > dz then
p.y = p.y + y_step
- y_intersect = y_intersect + y_component
else
p.z = p.z + z_step
- z_intersect = z_intersect + z_component
end
if vector.distance(pos, p) > range then
return nil
end
return p
- end
+ end, vector.round(pos)
+end
+
+
+--- Like trace_node_ray, but includes extra positions close to the ray.
+function technic.trace_node_ray_fat(pos, dir, range)
+ local x_step = dir.x > 0 and 1 or -1
+ local y_step = dir.y > 0 and 1 or -1
+ local z_step = dir.z > 0 and 1 or -1
+
+ local next_poses = {}
+
+ local i = 1
+ return function(p)
+ local ni, np = next(next_poses)
+ if np then
+ next_poses[ni] = nil
+ return np
+ end
+
+ -- Approximation of where we should be if we weren't rounding
+ -- to nodes. This moves forward a bit faster then we do.
+ -- A correction is done below.
+ local real_x = pos.x + (dir.x * i)
+ local real_y = pos.y + (dir.y * i)
+ local real_z = pos.z + (dir.z * i)
+
+ -- How far off we've gotten from where we should be.
+ local dx = math.abs(real_x - p.x)
+ local dy = math.abs(real_y - p.y)
+ local dz = math.abs(real_z - p.z)
+
+ -- If the real position moves ahead too fast, stop it so we
+ -- can catch up. If it gets too far ahead it will smooth
+ -- out our movement too much and we won't turn fast enough.
+ if dx + dy + dz < 2 then
+ i = i + 1
+ end
+
+ -- Step in whichever direction we're most off course in.
+ local sx, sy, sz -- Whether we've already stepped along each axis
+ if dx > dy then
+ if dx > dz then
+ sx = true
+ p.x = p.x + x_step
+ else
+ sz = true
+ p.z = p.z + z_step
+ end
+ elseif dy > dz then
+ sy = true
+ p.y = p.y + y_step
+ else
+ sz = true
+ p.z = p.z + z_step
+ end
+
+ if vector.distance(pos, p) > range then
+ return nil
+ end
+
+ -- Add other positions that we're significantly off on.
+ -- We can just use fixed integer keys here because the
+ -- table will be completely cleared before we reach this
+ -- code block again.
+ local dlen = math.sqrt(dx*dx + dy*dy + dz*dz)
+ -- Normalized axis deltas
+ local dxn, dyn, dzn = dx / dlen, dy / dlen, dz / dlen
+ if not sx and dxn > 0.5 then
+ next_poses[1] = vector.new(p.x + x_step, p.y, p.z)
+ end
+ if not sy and dyn > 0.5 then
+ next_poses[2] = vector.new(p.x, p.y + y_step, p.z)
+ end
+ if not sz and dzn > 0.5 then
+ next_poses[3] = vector.new(p.x, p.y, p.z + z_step)
+ end
+
+ return p
+ end, vector.round(pos)
end
diff --git a/technic/machines/MV/wind_mill.lua b/technic/machines/MV/wind_mill.lua
index 1377c67..28a075d 100644
--- a/technic/machines/MV/wind_mill.lua
+++ b/technic/machines/MV/wind_mill.lua
@@ -33,8 +33,15 @@ local function check_wind_mill(pos)
if pos.y < 30 then
return false
end
+ pos = {x=pos.x, y=pos.y, z=pos.z}
for i = 1, 20 do
- local node = minetest.get_node({x=pos.x, y=pos.y-i, z=pos.z})
+ pos.y = pos.y - 1
+ local node = minetest.get_node_or_nil(pos)
+ if not node then
+ -- we reached CONTENT_IGNORE, we can assume, that nothing changed
+ -- as the user will have to load the block to change it
+ return
+ end
if node.name ~= "technic:wind_mill_frame" then
return false
end
@@ -45,17 +52,17 @@ end
local run = function(pos, node)
local meta = minetest.get_meta(pos)
local machine_name = S("Wind %s Generator"):format("MV")
- local power = math.min(pos.y * 100, 5000)
- if not check_wind_mill(pos) then
+ local check = check_wind_mill(pos)
+ if check == false then
meta:set_int("MV_EU_supply", 0)
meta:set_string("infotext", S("%s Improperly Placed"):format(machine_name))
- return
- else
+ elseif check == true then
+ local power = math.min(pos.y * 100, 5000)
meta:set_int("MV_EU_supply", power)
+ meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.pretty_num(power)))
end
-
- meta:set_string("infotext", S("@1 (@2 EU)", machine_name, technic.pretty_num(power)))
+ -- check == nil: assume nothing has changed
end
minetest.register_node("technic:wind_mill", {
diff --git a/technic/machines/other/frames.lua b/technic/machines/other/frames.lua
index b3f39b9..2d630a2 100644
--- a/technic/machines/other/frames.lua
+++ b/technic/machines/other/frames.lua
@@ -320,7 +320,7 @@ local nodeboxes= {
else
--local pointed_thing = {type = "node", under = pos}
if pointed_thing then
- minetest.item_place_node(itemstack, placer, pointed_thing)
+ return minetest.item_place_node(itemstack, placer, pointed_thing)
end
end
end,
diff --git a/technic/tools/mining_lasers.lua b/technic/tools/mining_lasers.lua
index c09aa92..ef1eecb 100644
--- a/technic/tools/mining_lasers.lua
+++ b/technic/tools/mining_lasers.lua
@@ -38,8 +38,8 @@ local function laser_node(pos, node, player)
minetest.remove_node(pos)
minetest.add_particle({
pos = pos,
- vel = {x=0, y=2, z=0},
- acc = {x=0, y=-1, z=0},
+ velocity = {x=0, y=2, z=0},
+ acceleration = {x=0, y=-1, z=0},
expirationtime = 1.5,
size = 6 + math.random() * 2,
texture = "smoke_puff.png^[transform" .. math.random(0, 7),
@@ -61,17 +61,17 @@ local function laser_shoot(player, range, particle_texture, sound)
local start_pos = vector.new(player_pos)
-- Adjust to head height
- start_pos.y = start_pos.y + 1.9
+ start_pos.y = start_pos.y + 1.6
minetest.add_particle({
pos = startpos,
- vel = dir,
- acc = vector.multiply(dir, 50),
+ velocity = dir,
+ acceleration = vector.multiply(dir, 50),
expirationtime = range / 11,
size = 1,
texture = particle_texture .. "^[transform" .. math.random(0, 7),
})
minetest.sound_play(sound, {pos = player_pos, max_hear_distance = range})
- for pos in technic.trace_node_ray(start_pos, dir, range) do
+ for pos in technic.trace_node_ray_fat(start_pos, dir, range) do
if minetest.is_protected(pos, player_name) then
minetest.record_protection_violation(pos, player_name)
break