Basic idealogy
-goal - > go to goal - > check all this and repeat
-
-
-minecart does check axis dir then -1 1 on opposite axis (x and z)
-
-minecart checks in front and above
-
-minecart checks in front and below
-
-if in front above start moving up
+keep it simple stupid
-if in front below start moving down
+make cart make noise
-minecart checks if rail in front then if not check sides and if none then stop
+make player able to push cart
-if a rail in front of minecart then when past center of node center, turn towards the available rail and then recenter self onto rail on the new axis
+make carts push each other away --repel axis
+make chest and furnace cart
-keep it simple stupid
-make cart make noise
+minetest.dir_to_facedir(dir, is6d) - to get player direction converted and to convert the minecart direction
]]--
local path = minetest.get_modpath("minecart")
rider = nil,
punched = false,
+ speed = 0,
}
return
end
local player_name = clicker:get_player_name()
+
if self.rider and player_name == self.rider then
self.rider = nil
- carts:manage_attachment(clicker, nil)
+ --carts:manage_attachment(clicker, nil)
elseif not self.rider then
self.rider = player_name
- carts:manage_attachment(clicker, self.object)
+ clicker:set_attach(self.object, "", {x=0, y=-4.5, z=0}, {x=0, y=0, z=0})
+ --player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
+ --carts:manage_attachment(clicker, self.object)
-- player_api does not update the animation
-- when the player is attached, reset to default animation
})
end
function minecart:on_punch(puncher, time_from_last_punch, tool_capabilities, dir, damage)
+ local obj = minetest.add_item(self.object:getpos(), "minecart:minecart")
+ obj:get_luaentity().collection_timer = 2
self.object:remove()
end
--repel from players on track "push"
function minecart:push(self)
local pos = self.object:getpos()
- for _,object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
- if object:is_player() then
+ for _,object in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
+ if object:is_player() and object:get_player_name() ~= self.rider then
local player_pos = object:getpos()
pos.y = 0
player_pos.y = 0
vel = vector.normalize(vel)
local distance = vector.distance(pos,player_pos)
- distance = (2-distance)*3
+ distance = (1-distance)*10
vel = vector.multiply(vel,distance)
- self.object:setvelocity(vel)
-
+ --only push if it's faster than current speed
+ if distance > self.speed then
+ self.object:setvelocity(vel)
+ self.speed = distance
+ end
end
end
end
function minecart:ride_rail(self)
-
- --floor position!!!!
-
local pos = vector.floor(vector.add(self.object:getpos(),0.5))
- local speed = 5 --change to the cart speed soon
+ local speed = self.speed
+ if self.speed > 10 then
+ self.speed = 10
+ end
local vel = self.object:getvelocity()
local x = math.abs(vel.x)
--print("up")
dir.y = speed
dir.x = xdir*speed
- end
-
+
--go down
- if dir.y == 0 and is_rail(pos.x,pos.y-1,pos.z) then
+ elseif (is_rail(pos.x,pos.y-1,pos.z) or vel.y < 0) and not is_rail(pos.x+xdir,pos.y,pos.z) then
--print("down")
dir.y = -speed
dir.x = xdir*speed
- end
--go flat
- if is_rail(pos.x,pos.y,pos.z) then --currently on rail
+ elseif is_rail(pos.x,pos.y,pos.z) then --currently on rail
+ --print("flat")
--print("forward inside")
--correct y position
if dir.y == 0 and self.object:getpos().y ~= pos.y then
--print("up")
dir.y = speed
dir.z = zdir*speed
- end
--go down
- if dir.y == 0 and is_rail(pos.x,pos.y-1,pos.z) then
+ elseif (is_rail(pos.x,pos.y-1,pos.z) or vel.y < 0) and not is_rail(pos.x,pos.y,pos.z+zdir) then
--print("down")
dir.y = -speed
dir.z = zdir*speed
- end
+
--go flat
- if is_rail(pos.x,pos.y,pos.z) then --currently on rail
+ elseif is_rail(pos.x,pos.y,pos.z) then --currently on rail
+ --print("flat")
--print("forward inside")
--correct y position
if dir.y == 0 and self.object:getpos().y ~= pos.y then
if turnx and turnz and dir.y == 0 and not vector.equals(dir, vector.new(0,0,0)) and not is_rail(pos.x+turnx,pos.y-1,pos.z+turnz) and not is_rail(pos.x+turnx,pos.y,pos.z+turnz) and not is_rail(pos.x+turnx,pos.y+1,pos.z+turnz) then
if x > z then
- if is_rail(pos.x,pos.y,pos.z+1) then
- dir.z = speed
- dir.x = 0
- --recenter on the rail
- self.object:moveto(pos)
- elseif is_rail(pos.x,pos.y,pos.z-1) then
- dir.z = -speed
- dir.x = 0
- --recenter on the rail
- self.object:moveto(pos)
+ for y = -1,1 do
+ if is_rail(pos.x,pos.y+y,pos.z+1) then
+ dir.z = speed
+ dir.x = 0
+ --recenter on the rail
+ self.object:moveto(pos)
+ elseif is_rail(pos.x,pos.y+y,pos.z-1) then
+ dir.z = -speed
+ dir.x = 0
+ --recenter on the rail
+ self.object:moveto(pos)
+ end
end
elseif z > x then
- if is_rail(pos.x+1,pos.y,pos.z) then
- dir.x = speed
- dir.z = 0
- --recenter on the rail
- self.object:moveto(pos)
- elseif is_rail(pos.x-1,pos.y,pos.z) then
- dir.x = -speed
- dir.z = 0
- --recenter on the rail
- self.object:moveto(pos)
+ for y = -1,1 do
+ if is_rail(pos.x+1,pos.y+y,pos.z) then
+ dir.x = speed
+ dir.z = 0
+ --recenter on the rail
+ self.object:moveto(pos)
+ elseif is_rail(pos.x-1,pos.y+y,pos.z) then
+ dir.x = -speed
+ dir.z = 0
+ --recenter on the rail
+ self.object:moveto(pos)
+ end
end
end
--end
self.oldpos=self.object:getpos()
-
+ --make the cart move up and down on hills
self.object:set_properties({mesh="minecart.obj"})
if vel.y <0 then
- print("down")
self.object:set_properties({mesh="minecart_down.obj"})
elseif vel.y > 0 then
- print("up")
self.object:set_properties({mesh="minecart_up.obj"})
end
- return(self.object:set_animation(anim, 1, 0))
+
+ --slow it down
+ if self.speed > 0 then
+ self.speed = self.speed - 0.01
+ end
+ if self.speed < 0 then
+ self.speed = 0
+ end
+
end
-
-
function minecart:on_step(dtime)
minecart:push(self)
minecart:ride_rail(self)
minetest.register_entity("minecart:minecart", minecart)
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
minetest.register_craftitem("minecart:minecart", {
description = "Minecart",
inventory_image = "minecartitem.png",