summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-06-29 19:14:30 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-06-29 19:14:30 +0200
commit043022f536141c998738fb41927dfaa9e130ac83 (patch)
tree75e0a3ec93eec683a6f3fba26aa8d553fc45860e
parent539c2b8329f98b87fe227261ae28d156c02f870a (diff)
downloadwalkway-043022f536141c998738fb41927dfaa9e130ac83.tar.gz
walkway-043022f536141c998738fb41927dfaa9e130ac83.tar.bz2
walkway-043022f536141c998738fb41927dfaa9e130ac83.zip
Added slopes
-rw-r--r--init.lua161
-rw-r--r--models/moreblocks_slope_half.obj56
-rw-r--r--models/moreblocks_slope_half_raised.obj72
-rw-r--r--textures/factory_belt_side.pngbin18872 -> 3019 bytes
-rw-r--r--textures/factory_belt_top_animation_down.pngbin0 -> 3002 bytes
5 files changed, 280 insertions, 9 deletions
diff --git a/init.lua b/init.lua
index e1da76f..3453d43 100644
--- a/init.lua
+++ b/init.lua
@@ -1,5 +1,70 @@
walkway = {}
+
+
+-- taken from moreblocks
+local box_slope_half = {
+ type = "fixed",
+ fixed = {
+ {-0.5, -0.5, -0.5, 0.5, -0.375, 0.5},
+ {-0.5, -0.375, -0.25, 0.5, -0.25, 0.5},
+ {-0.5, -0.25, 0, 0.5, -0.125, 0.5},
+ {-0.5, -0.125, 0.25, 0.5, 0, 0.5},
+ }
+}
+
+local box_slope_half_raised = {
+ type = "fixed",
+ fixed = {
+ {-0.5, -0.5, -0.5, 0.5, 0.125, 0.5},
+ {-0.5, 0.125, -0.25, 0.5, 0.25, 0.5},
+ {-0.5, 0.25, 0, 0.5, 0.375, 0.5},
+ {-0.5, 0.375, 0.25, 0.5, 0.5, 0.5},
+ }
+}
+local function same_sign(x, y)
+ return (x > 0 and y > 0) or (x < 0 and y < 0)
+end
+local function diff_sign(x, y)
+ return (x > 0 and y < 0) or (x < 0 and y > 0)
+end
+local function abs(x)
+ if x > 0 then
+ return x
+ else
+ return -x
+ end
+end
local speed = 0.4
+local function generate_velocity_vector(vx, vz, node)
+ local vy=0
+ local p = 1
+ local dir = vector.new(minetest.facedir_to_dir(node.param2))
+ if node.name=="walkway:slope_1" or node.name=="walkway:slope_2" then
+ p = 1
+ vx=0
+ vz=0
+ if same_sign(dir.x/speed+vx,dir.x) or same_sign(dir.z/speed+vz,dir.z) then
+-- minetest.chat_send_all("CASE 1")
+ vy = 1
+ elseif diff_sign(dir.x/speed+vx,dir.x) or diff_sign(dir.z/speed+vz,dir.z) then
+ vy = -1
+ end
+ elseif node.name=="walkway:slope_1_down" or node.name=="walkway:slope_2_down" then
+ vx=0 -- dirty fix
+ vz=0
+ p = -1
+ if same_sign(dir.x/speed+vx,dir.x) or same_sign(dir.z/speed+vz,dir.z) then
+ vy = -1
+ elseif diff_sign(dir.x/speed+vx,dir.x) or diff_sign(dir.z/speed+vz,dir.z) then
+ vy = 1
+ end
+
+ end
+-- minetest.chat_send_all(dir.x..";"..p*(dir.x / speed+vx)..",".. vy*(abs((dir.x +dir.z)/speed+vx+vz))/2 ..","..p*(dir.z / speed+vz)..";"..dir.z)
+ return {x = p*(dir.x / speed+vx), y = vy*(abs((dir.x +dir.z)/speed))/2, z = p*(dir.z / speed+vz)}
+end
+
+
minetest.register_entity("walkway:moving_dummy",{
initial_properties = {
hp_max = 1,
@@ -76,16 +141,24 @@ minetest.register_entity("walkway:moving_dummy",{
end
- if napos.name == "walkway:belt_straight" then
- self.object:setvelocity({x = dir.x / speed, y = 0, z = dir.z / speed})
- elseif napos.name == "walkway:belt" then
-
+ -- if napos.name == "walkway:belt_straight" then
+ -- self.object:setvelocity({x = dir.x / speed, y = 0, z = dir.z / speed})
+ if napos.name == "air" then
+ napos = minetest.get_node({x = pos.x, y = pos.y -1, z = pos.z})
+ dir = vector.new(minetest.facedir_to_dir(napos.param2))
+ elseif not string.sub(napos.name,1,string.len("walkway:")) == "walkway:" then
+ napos = minetest.get_node({x = pos.x, y = pos.y + 1, z = pos.z})
+ dir = vector.new(minetest.facedir_to_dir(napos.param2))
+ end
+-- minetest.chat_send_all(napos.name)
+
+ if string.sub(napos.name,1,string.len("walkway:")) == "walkway:" then
if dir.x == 0 then
dir.x = (math.floor(pos.x + 0.5) - pos.x) * 2
elseif dir.z == 0 then
dir.z = (math.floor(pos.z + 0.5) - pos.z) * 2
end
- self.object:setvelocity({x = dir.x / speed + vx, y = 0, z = dir.z / speed+vz})
+ self.object:setvelocity(generate_velocity_vector(vx, vz, napos))
else
if self.player then
local veldir = self.object:getvelocity();
@@ -115,9 +188,79 @@ minetest.register_node("walkway:belt", {
legacy_facedir_simple = true,
node_box = {
type = "fixed",
- fixed = {{-0.5,-0.5,-0.5,0.5,0.0625,0.5},}
+ fixed = {{-0.5,-0.5,-0.5,0.5,0.0,0.5},}
},
})
+minetest.register_node("walkway:slope_1",
+ {description = "Moving Walkway",
+ tiles = {{name="factory_belt_top_animation.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_side.png",
+ "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"},
+ groups = {cracky=1},
+
+ drawtype = "mesh",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ on_place = minetest.rotate_node,
+ description = desc,
+ is_ground_content = true,
+ legacy_facedir_simple = true,
+ mesh = "moreblocks_slope_half.obj",
+ collision_box = box_slope_half,
+ selection_box = box_slope_half,
+})
+minetest.register_node("walkway:slope_2",
+ {description = "Moving Walkway",
+ tiles = {{name="factory_belt_top_animation.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_side.png",
+ "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"},
+ groups = {cracky=1},
+
+ drawtype = "mesh",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ on_place = minetest.rotate_node,
+ description = desc,
+ is_ground_content = true,
+ legacy_facedir_simple = true,
+ mesh = "moreblocks_slope_half_raised.obj",
+ collision_box = box_slope_half_raised,
+ selection_box = box_slope_half_raised,
+})
+minetest.register_node("walkway:slope_1_down",
+ {description = "Moving Walkway",
+ tiles = {{name="factory_belt_top_animation_down.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_side.png",
+ "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"},
+ groups = {cracky=1},
+
+ drawtype = "mesh",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ on_place = minetest.rotate_node,
+ description = desc,
+ is_ground_content = true,
+ legacy_facedir_simple = true,
+ mesh = "moreblocks_slope_half.obj",
+ collision_box = box_slope_half,
+ selection_box = box_slope_half,
+})
+minetest.register_node("walkway:slope_2_down",
+ {description = "Moving Walkway",
+ tiles = {{name="factory_belt_top_animation_down.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_side.png",
+ "factory_belt_side.png", "factory_belt_side.png", "factory_belt_side.png"},
+ groups = {cracky=1},
+
+ drawtype = "mesh",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ on_place = minetest.rotate_node,
+ description = desc,
+ is_ground_content = true,
+ legacy_facedir_simple = true,
+ mesh = "moreblocks_slope_half_raised.obj",
+ collision_box = box_slope_half_raised,
+ selection_box = box_slope_half_raised,
+})
+
+
-- minetest.register_node("walkway:belt_straight", {
-- description = "straight Conveyor Belt",
@@ -154,13 +297,14 @@ minetest.register_abm({
})
minetest.register_abm({
- nodenames = {"walkway:belt", "walkway:belt_straight"},
+ nodenames = {"walkway:belt", "walkway:belt_straight", "walkway:slope_1", "walkway:slope_2", "walkway:slope_1_down", "walkway:slope_2_down"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local all_objects = minetest.get_objects_inside_radius(pos, 1)
local _,obj
+-- minetest.chat_send_all(node.name)
for _,obj in ipairs(all_objects) do
if obj:is_player() and not obj:get_attach() then
@@ -171,8 +315,7 @@ minetest.register_abm({
default.player_attached[name] = true
elseif obj:get_luaentity() and string.sub(obj:get_luaentity().name,1,string.len("mobs_animal")) == "mobs_animal" then
local napos = minetest.get_node(pos)
- local dir = vector.new(minetest.facedir_to_dir(napos.param2))
- obj:setvelocity({x = dir.x / speed, y = 0, z = dir.z / speed})
+ obj:setvelocity(generate_velocity_vector(0, 0, node))
-- dum = walkway.do_moving_dummy({x = pos.x, y = pos.y + 0.15, z = pos.z}, obj):get_luaentity()
-- dum.player = obj
-- obj:set_attach(dum.object, "", {x=0,y=-1,z=0}, {x=0,y=0,z=0})
diff --git a/models/moreblocks_slope_half.obj b/models/moreblocks_slope_half.obj
new file mode 100644
index 0000000..1fa631c
--- /dev/null
+++ b/models/moreblocks_slope_half.obj
@@ -0,0 +1,56 @@
+g top
+v 0.500000 -0.000000 0.500000
+v -0.500000 -0.000000 0.500000
+v -0.500000 -0.500000 -0.500000
+v 0.500000 -0.500000 -0.500000
+vt 1.0000 1.0000
+vt 0.0000 1.0000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn 0.0000 0.8944 -0.4472
+s off
+f 2/1/1 1/2/1 4/3/1 3/4/1
+g bottom
+v -0.500000 -0.500000 0.500000
+v 0.500000 -0.500000 0.500000
+v -0.500000 -0.500000 -0.500000
+v 0.500000 -0.500000 -0.500000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vt 1.0000 1.0000
+vt 0.0000 1.0000
+vn 0.0000 -1.0000 -0.0000
+s off
+f 6/5/2 5/6/2 7/7/2 8/8/2
+g right
+v -0.500000 -0.000000 0.500000
+v -0.500000 -0.500000 0.500000
+v -0.500000 -0.500000 -0.500000
+vt 1.0000 0.5000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn -1.0000 0.0000 0.0000
+s off
+f 9/9/3 11/10/3 10/11/3
+g left
+v 0.500000 -0.000000 0.500000
+v 0.500000 -0.500000 0.500000
+v 0.500000 -0.500000 -0.500000
+vt 0.0000 0.5000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn 1.0000 0.0000 0.0000
+s off
+f 12/12/4 13/13/4 14/14/4
+g back
+v 0.500000 -0.000000 0.500000
+v -0.500000 -0.000000 0.500000
+v -0.500000 -0.500000 0.500000
+v 0.500000 -0.500000 0.500000
+vt 1.0000 0.5000
+vt 0.0000 0.5000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn 0.0000 -0.0000 1.0000
+s off
+f 15/15/5 16/16/5 17/17/5 18/18/5
diff --git a/models/moreblocks_slope_half_raised.obj b/models/moreblocks_slope_half_raised.obj
new file mode 100644
index 0000000..86139d7
--- /dev/null
+++ b/models/moreblocks_slope_half_raised.obj
@@ -0,0 +1,72 @@
+g top
+v -0.500000 0.500000 0.500000
+v -0.500000 0.000000 -0.500000
+v 0.500000 0.000000 -0.500000
+v 0.500000 0.500000 0.500000
+vt 1.0000 0.0000
+vt 1.0000 1.0000
+vt 0.0000 1.0000
+vt 0.0000 0.0000
+vn 0.0000 0.8944 -0.4472
+s off
+f 2/1/1 1/2/1 4/3/1 3/4/1
+g bottom
+v -0.500000 -0.500000 -0.500000
+v -0.500000 -0.500000 0.500000
+v 0.500000 -0.500000 -0.500000
+v 0.500000 -0.500000 0.500000
+vt 1.0000 0.0000
+vt 1.0000 1.0000
+vt 0.0000 1.0000
+vt 0.0000 0.0000
+vn 0.0000 -1.0000 -0.0000
+s off
+f 6/5/2 5/6/2 7/7/2 8/8/2
+g right
+v -0.500000 0.500000 0.500000
+v -0.500000 0.000000 -0.500000
+v -0.500000 -0.500000 -0.500000
+v -0.500000 -0.500000 0.500000
+vt 1.0000 1.0000
+vt 0.0000 0.5000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn -1.0000 0.0000 0.0000
+s off
+f 9/9/3 10/10/3 11/11/3 12/12/3
+g left
+v 0.500000 0.000000 -0.500000
+v 0.500000 -0.500000 -0.500000
+v 0.500000 0.500000 0.500000
+v 0.500000 -0.500000 0.500000
+vt 1.0000 0.5000
+vt 0.0000 1.0000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn 1.0000 0.0000 0.0000
+s off
+f 13/13/4 15/14/4 16/15/4 14/16/4
+g back
+v -0.500000 0.500000 0.500000
+v -0.500000 -0.500000 0.500000
+v 0.500000 0.500000 0.500000
+v 0.500000 -0.500000 0.500000
+vt 1.0000 1.0000
+vt 0.0000 1.0000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn 0.0000 -0.0000 1.0000
+s off
+f 19/17/5 17/18/5 18/19/5 20/20/5
+g front
+v -0.500000 0.000000 -0.500000
+v -0.500000 -0.500000 -0.500000
+v 0.500000 0.000000 -0.500000
+v 0.500000 -0.500000 -0.500000
+vt 1.0000 0.5000
+vt 0.0000 0.5000
+vt 0.0000 0.0000
+vt 1.0000 0.0000
+vn 0.0000 0.0000 -1.0000
+s off
+f 21/21/6 23/22/6 24/23/6 22/24/6
diff --git a/textures/factory_belt_side.png b/textures/factory_belt_side.png
index 6d60e06..b5ade8d 100644
--- a/textures/factory_belt_side.png
+++ b/textures/factory_belt_side.png
Binary files differ
diff --git a/textures/factory_belt_top_animation_down.png b/textures/factory_belt_top_animation_down.png
new file mode 100644
index 0000000..9f87009
--- /dev/null
+++ b/textures/factory_belt_top_animation_down.png
Binary files differ