]> git.lizzy.rs Git - Crafter.git/commitdiff
Add in ability to drive train
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 5 Jul 2020 21:55:15 +0000 (17:55 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 5 Jul 2020 21:55:15 +0000 (17:55 -0400)
mods/player_api/init.lua
mods/player_mechanics/player_mechanics.lua
mods/train/init.lua
mods/train/models/blends/steam_train.blend
mods/train/models/blends/steam_train.blend1 [new file with mode: 0644]

index 7e0c30f48200a983699aa7e22971211cc016aa62..dd7829b2d3b96e1e65bd3272ac3ad0b3531721f1 100644 (file)
@@ -152,6 +152,13 @@ player_is_attached = function(player,truth)
        pool[name].attached = truth
 end
 
+local name
+get_if_player_attached = function(player)
+       name = player:get_player_name()
+       return(pool[name].attached)
+end
+
+
 local name
 player_is_sleeping = function(player,truth)
        name = player:get_player_name()
index 27e785502ba085f2fd840e4cd4ba4c8177b50a01..0431a408888c6f949643248bbdd6f290dbd5574e 100644 (file)
@@ -95,6 +95,9 @@ local in_water
 local swim_unlock
 local swim_bump
 local control_state = function(player)
+       if get_if_player_attached(player) then
+               return
+       end
        hunger    = get_player_hunger(player)
        name      = player:get_player_name()
        temp_pool = pool[name]
index 0e278884ab2ecb72125618087be327521efd75bc..d937fc064b07ccef3ac36783560a46dcd1504168 100644 (file)
@@ -115,8 +115,16 @@ local function direction_snap(self)
        local pitch = 0
        if dir.y == 1 then pitch = math.pi/4 end
        if dir.y == -1 then pitch = -math.pi/4 end
+
        local yaw = minetest.dir_to_yaw(dir)
+
+       if self.driver then
+               self.driver:set_look_vertical(pitch)
+               self.driver:set_look_horizontal(yaw)
+       end
        self.object:set_rotation(vector.new(pitch,yaw,0))
+
+       
 end
 
 local function turn_snap(pos,self,dir,dir2)
@@ -214,12 +222,14 @@ local function coupling_logic(self)
        
        local pos2 = self.coupler1:get_pos()
 
+       local coupler_goal = self.coupler1:get_luaentity().coupler_distance
+
        if self.axis_lock == "x" then
                local velocity_real = self.object:get_velocity()
                local distance = vector.distance(pos,pos2)
                local new_vel = vector.new(0,0,0)
-               if distance > 1.5 then
-                       local velocity = (distance-1)
+               if distance > coupler_goal then
+                       local velocity = (distance-coupler_goal)
                        local dir = vector.direction(vector.new(pos.x,0,0),vector.new(pos2.x,0,0))
                        self.dir = dir
                        new_vel = vector.multiply(dir,velocity)
@@ -231,8 +241,8 @@ local function coupling_logic(self)
                local velocity_real = self.object:get_velocity()
                local distance = vector.distance(pos,pos2)
                local new_vel = vector.new(0,0,0)
-               if distance > 1.5 then
-                       local velocity = (distance-1)
+               if distance > coupler_goal then
+                       local velocity = (distance-coupler_goal)
                        local dir = vector.direction(vector.new(0,0,pos.z),vector.new(0,0,pos2.z))
                        self.dir = dir
                        new_vel = vector.multiply(dir,velocity)
@@ -300,7 +310,18 @@ train.power            = data.power
 train.coupler_distance = data.coupler_distance
 train.is_car           = data.is_car
 train.is_engine        = data.is_engine
-train.speed_max        = data.speed_max
+train.max_speed        = data.max_speed
+train.driver           = nil
+
+train.initial_properties = {
+       physical = false, -- otherwise going uphill breaks
+       collisionbox = {-0.4, -0.5, -0.4, 0.4, 0.45, 0.4},
+       visual = "mesh",
+       mesh = data.mesh,
+       visual_size = {x=1, y=1},
+       textures = {data.texture},
+}
+
 
 train.on_step = function(self,dtime)
        if dtime > 0.1 then
@@ -358,7 +379,7 @@ end
 
 
 train.on_rightclick = function(self,clicker)
-       local pos = self.object:get_pos()
+       --[[
        if clicker:get_wielded_item():get_name() == "utility:furnace" then
                local obj = minetest.add_entity(pos, "train:furnace")
                obj:set_attach(self.object,"",vector.new(0,0,0),vector.new(0,0,0))
@@ -371,11 +392,27 @@ train.on_rightclick = function(self,clicker)
                self.furnace = true
                return
        end
-
-       if not clicker:get_wielded_item():get_name() == "train:wrench" then
+       ]]--
+
+       if clicker:get_wielded_item():get_name() ~= "train:wrench" then
+               if self.is_engine then
+                       print("jump on in")
+                       clicker:set_attach(self.object, "", data.body_pos, data.body_rotation)
+                       clicker:set_eye_offset(data.eye_offset,{x=0,y=0,z=0})
+                       player_is_attached(clicker,true)
+                       set_player_animation(clicker,"stand",0)
+                       local rotation = self.object:get_rotation()
+                       clicker:set_look_vertical(0)
+                       clicker:set_look_horizontal(rotation.y)
+                       self.object:set_velocity(vector.multiply(self.dir,self.max_speed))
+                       self.driver = clicker
+                       return
+               end
                return
        end
 
+       local pos = self.object:get_pos()
+
        local name = clicker:get_player_name()
        if not pool[name] then
                if not self.coupler2 then
@@ -437,33 +474,37 @@ train.get_staticdata = function(self)
        })
 end
 
-
-
-train.initial_properties = {
-       physical = false, -- otherwise going uphill breaks
-       collisionbox = {-0.4, -0.5, -0.4, 0.4, 0.45, 0.4},--{-0.5, -0.4, -0.5, 0.5, 0.25, 0.5},
-       visual = "mesh",
-       mesh = "steam_train.b3d",
-       visual_size = {x=1, y=1},
-       textures = {"steam_train.png"},
-}
-
-       
-
 minetest.register_entity(name, train)
 
 end
 
+--[[
+███████╗███╗   ██╗██████╗ 
+██╔════╝████╗  ██║██╔══██╗
+█████╗  ██╔██╗ ██║██║  ██║
+██╔══╝  ██║╚██╗██║██║  ██║
+███████╗██║ ╚████║██████╔╝
+╚══════╝╚═╝  ╚═══╝╚═════╝ 
+]]--
 
 
 
 
+register_train("train:steam_train",{
+       mesh = "steam_train.b3d",
+       texture = "steam_train.png",
+       is_engine = true,
+       power = 6,
+       max_speed = 6,
+       coupler_distance = 2,
+       body_pos = vector.new(0,0,-15),
+       body_rotation = vector.new(0,0,0),
+       eye_offset = vector.new(6,-1,-10)
+})
 
 
 
-
-
-minetest.register_craftitem("train:minecart", {
+minetest.register_craftitem("train:train", {
        description = "train",
        inventory_image = "minecartitem.png",
        wield_image = "minecartitem.png",
@@ -480,7 +521,7 @@ minetest.register_craftitem("train:minecart", {
                end
                
                if minetest.get_item_group(minetest.get_node(pointed_thing.under).name, "rail")>0 then
-                       minetest.add_entity(pointed_thing.under, "train:train")
+                       minetest.add_entity(pointed_thing.under, "train:steam_train")
                else
                        return
                end
index bb8bd8d52afd3b3ee386ee85d6d563e0e8bf948e..af0fb08d3e56d0e2a56a5e5b9a9386c0c3245601 100644 (file)
Binary files a/mods/train/models/blends/steam_train.blend and b/mods/train/models/blends/steam_train.blend differ
diff --git a/mods/train/models/blends/steam_train.blend1 b/mods/train/models/blends/steam_train.blend1
new file mode 100644 (file)
index 0000000..8f26d82
Binary files /dev/null and b/mods/train/models/blends/steam_train.blend1 differ