]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/minecart/init.lua
Rebalance sounds pt 1
[Crafter.git] / mods / minecart / init.lua
index d2995f65acc45e4057a2e3e038cf3ee55daa04f2..3016b041330b4e0bf1145bad4ddec3fa195e42bf 100644 (file)
@@ -2,27 +2,18 @@
 
 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
+keep it simple stupid
 
-if in front above start moving up
+make cart make noise
 
-if in front below start moving down
+make player able to push cart
 
-minecart checks if rail in front then if not check sides and if none then stop
+make carts push each other away --repel axis
 
-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 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")
@@ -39,7 +30,7 @@ local minecart = {
                physical = false, -- otherwise going uphill breaks
                collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},--{-0.5, -0.4, -0.5, 0.5, 0.25, 0.5},
                visual = "mesh",
-               mesh = "minecart.b3d",
+               mesh = "minecart.obj",
                visual_size = {x=1, y=1},
                textures = {"minecart.png"},
                automatic_face_movement_dir = 90.0,
@@ -47,6 +38,7 @@ local minecart = {
 
        rider = nil,
        punched = false,
+       speed = 0,
        
 }
 
@@ -55,12 +47,15 @@ function minecart:on_rightclick(clicker)
                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
@@ -89,6 +84,8 @@ function minecart:get_staticdata()
        })
 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
 
@@ -100,8 +97,8 @@ 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
@@ -110,22 +107,25 @@ function minecart:push(self)
                        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)
@@ -146,17 +146,16 @@ function minecart:ride_rail(self)
                        --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
@@ -177,17 +176,17 @@ function minecart:ride_rail(self)
                        --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
@@ -199,43 +198,69 @@ function minecart:ride_rail(self)
                end
        end
        --turn
-       if dir.y == 0 then
-               self.object:moveto(self.oldpos)
+       local turnx = 0
+       local turnz = 0
+       
+       if vel.x>0 then turnx=1 elseif vel.x<0 then turnx=-1 end
+       if vel.z>0 then turnz=1 elseif vel.z<0 then turnz=-1 end
+       
+
+       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 = 1
-                               dir.x = 0
-                               --recenter on the rail
-                               self.object:moveto(pos)
-                       elseif is_rail(pos.x,pos.y,pos.z-1) then
-                               dir.z = -1
-                               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 = 1
-                               dir.z = 0
-                               --recenter on the rail
-                               self.object:moveto(pos)
-                       elseif is_rail(pos.x-1,pos.y,pos.z) then
-                               dir.x = -1
-                               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
        --apply
        --if not vector.equals(dir,vector.new(0,0,0)) then
        self.object:setvelocity(dir)
        --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
+               self.object:set_properties({mesh="minecart_down.obj"})
+       elseif vel.y > 0 then
+               self.object:set_properties({mesh="minecart_up.obj"})
+       end
+       
+       --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)
@@ -244,24 +269,6 @@ end
 minetest.register_entity("minecart:minecart", minecart)
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
 minetest.register_craftitem("minecart:minecart", {
        description = "Minecart",
        inventory_image = "minecartitem.png",