diff --git a/depends.txt b/depends.txt index 331d858..20aa884 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,2 @@ -default \ No newline at end of file +default +mesecons? \ No newline at end of file diff --git a/init.lua b/init.lua index e155b10..ad478f2 100644 --- a/init.lua +++ b/init.lua @@ -1,12 +1,10 @@ --- TODO: --- Fix way-up +-- TODO: -- Add rail-cross switching -- Prevent from floating carts --- Speed up and brake rails boost_cart = {} boost_cart.modpath = minetest.get_modpath("boost_cart") -boost_cart.speed_max = 20 +boost_cart.speed_max = 10 function vector.floor(v) return { @@ -65,16 +63,16 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti end end self.object:remove() - puncher:get_inventory():add_item("main", "boost_cart:cart") + puncher:get_inventory():add_item("main", "carts:cart") return end local vel = self.velocity - --[[if puncher:get_player_name() == self.driver then + if puncher:get_player_name() == self.driver then if math.abs(vel.x) + math.abs(vel.z) > 6 then return end - end]] + end local cart_dir = boost_cart:velocity_to_dir(direction) if cart_dir.x == 0 and cart_dir.z == 0 then @@ -120,29 +118,24 @@ function boost_cart.cart:on_step(dtime) if vector.equals(flo_pos, flo_old) then return end - local expected_pos = vector.add(self.old_pos, self.old_dir) - local diff = vector.subtract(expected_pos, pos) - diff = { - x = math.abs(diff.x), - y = math.abs(diff.y), - z = math.abs(diff.z) - } + local diff = vector.subtract(self.old_pos, pos) - if diff.x > math.abs(self.old_dir.x) or - diff.y > math.abs(self.old_dir.y) or - diff.z > math.abs(self.old_dir.z) then - pos = vector.new(expected_pos) - --minetest.log("action", "Cart moving too fast at "..minetest.pos_to_string(pos)) - self.punch = true + for _,v in ipairs({"x","y","z"}) do + if math.abs(diff[v]) > 1.4 then + pos = vector.add(self.old_pos, self.old_dir) + self.punch = true + --minetest.log("action", "Cart moving too fast at "..minetest.pos_to_string(pos)) + break + end end end - local ro_vel = vector.round(vel) local cart_dir = { x = boost_cart:get_sign(ro_vel.x), y = boost_cart:get_sign(ro_vel.y), z = boost_cart:get_sign(ro_vel.z) } + local max_vel = boost_cart.speed_max local dir = boost_cart:get_rail_direction(pos, cart_dir) if vector.equals(dir, {x=0, y=0, z=0}) then vel = {x=0, y=0, z=0} @@ -170,7 +163,24 @@ function boost_cart.cart:on_step(dtime) end -- Slow down or speed up.. - local acc = (dir.y * -2) - 0.4 + local acc = dir.y * -2 + + local speed_mod = tonumber(minetest.get_meta(pos):get_string("cart_acceleration")) + if speed_mod and speed_mod ~= 0 then + if speed_mod > 0 then + local is_limit = false + for _,v in ipairs({"x","y","z"}) do + if math.abs(vel[v]) >= max_vel then + speed_mod = 0 + break + end + end + end + acc = acc + (speed_mod * 6) + else + acc = acc - 0.4 + end + local new_acc = { x = dir.x * acc, y = dir.y * acc, @@ -185,8 +195,8 @@ function boost_cart.cart:on_step(dtime) -- Limits for _,v in ipairs({"x","y","z"}) do - if math.abs(vel[v]) > boost_cart.speed_max then - vel[v] = boost_cart:get_sign(vel[v]) * boost_cart.speed_max + if math.abs(vel[v]) > max_vel then + vel[v] = boost_cart:get_sign(vel[v]) * max_vel self.punch = true end end @@ -215,8 +225,8 @@ function boost_cart.cart:on_step(dtime) self.punch = false end -minetest.register_entity("boost_cart:cart", boost_cart.cart) -minetest.register_craftitem("boost_cart:cart", { +minetest.register_entity(":carts:cart", boost_cart.cart) +minetest.register_craftitem(":carts:cart", { description = "Cart", inventory_image = minetest.inventorycube("cart_top.png", "cart_side.png", "cart_side.png"), wield_image = "cart_side.png", @@ -225,9 +235,9 @@ minetest.register_craftitem("boost_cart:cart", { return end if boost_cart:is_rail(pointed_thing.under) then - minetest.add_entity(pointed_thing.under, "boost_cart:cart") + minetest.add_entity(pointed_thing.under, "carts:cart") elseif boost_cart:is_rail(pointed_thing.above) then - minetest.add_entity(pointed_thing.above, "boost_cart:cart") + minetest.add_entity(pointed_thing.above, "carts:cart") else return end itemstack:take_item() diff --git a/rails.lua b/rails.lua index 0cdac7a..20a8cea 100644 --- a/rails.lua +++ b/rails.lua @@ -13,4 +13,121 @@ minetest.register_node(":default:rail", { fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, }, groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1}, +}) + +-- Copper rail +minetest.register_node(":carts:copperrail", { + description = "Copper rail", + drawtype = "raillike", + tiles = {"carts_rail_cp.png", "carts_rail_curved_cp.png", "carts_rail_t_junction_cp.png", "carts_rail_crossing_cp.png"}, + inventory_image = "carts_rail_cp.png", + wield_image = "carts_rail_cp.png", + paramtype = "light", + is_ground_content = true, + walkable = false, + selection_box = { + type = "fixed", + -- but how to specify the dimensions for curved and sideways rails? + fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, + }, + groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1}, +}) + +minetest.register_craft({ + output = "carts:copperrail 12", + recipe = { + {"default:copper_ingot", "group:stick", "default:copper_ingot"}, + {"default:copper_ingot", "group:stick", "default:copper_ingot"}, + {"default:copper_ingot", "group:stick", "default:copper_ingot"}, + } +}) + +-- Speed up + +minetest.register_node(":carts:powerrail", { + description = "Powered rail", + drawtype = "raillike", + tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"}, + inventory_image = "carts_rail_pwr.png", + wield_image = "carts_rail_pwr.png", + paramtype = "light", + is_ground_content = true, + walkable = false, + selection_box = { + type = "fixed", + -- but how to specify the dimensions for curved and sideways rails? + fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, + }, + groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1}, + + after_place_node = function(pos, placer, itemstack) + if not mesecon then + minetest.get_meta(pos):set_string("cart_acceleration", "0.5") + end + end, + + mesecons = { + effector = { + action_on = function(pos, node) + minetest.get_meta(pos):set_string("cart_acceleration", "0.5") + end, + + action_off = function(pos, node) + minetest.get_meta(pos):set_string("cart_acceleration", "0") + end, + }, + }, +}) + +minetest.register_craft({ + output = "carts:powerrail 6", + recipe = { + {"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"}, + {"default:steel_ingot", "group:stick", "default:steel_ingot"}, + {"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"}, + } +}) + +minetest.register_node(":carts:brakerail", { + description = "Brake rail", + drawtype = "raillike", + tiles = {"carts_rail_brk.png", "carts_rail_curved_brk.png", "carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png"}, + inventory_image = "carts_rail_brk.png", + wield_image = "carts_rail_brk.png", + paramtype = "light", + is_ground_content = true, + walkable = false, + selection_box = { + type = "fixed", + -- but how to specify the dimensions for curved and sideways rails? + fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, + }, + groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1}, + + after_place_node = function(pos, placer, itemstack) + if not mesecon then + minetest.get_meta(pos):set_string("cart_acceleration", "-0.2") + end + end, + + mesecons = { + effector = { + action_on = function(pos, node) + minetest.get_meta(pos):set_string("cart_acceleration", "-0.2") + end, + + action_off = function(pos, node) + minetest.get_meta(pos):set_string("cart_acceleration", "0") + end, + }, + }, +}) + +minetest.register_craft({ + output = "carts:brakerail 6", + recipe = { + {"default:steel_ingot", "default:coal_lump", "default:steel_ingot"}, + {"default:steel_ingot", "group:stick", "default:steel_ingot"}, + {"default:steel_ingot", "default:coal_lump", "default:steel_ingot"}, + } }) \ No newline at end of file diff --git a/textures/carts_rail_brk.png b/textures/carts_rail_brk.png new file mode 100644 index 0000000..f3e0ff9 Binary files /dev/null and b/textures/carts_rail_brk.png differ diff --git a/textures/carts_rail_cp.png b/textures/carts_rail_cp.png new file mode 100644 index 0000000..a826d94 Binary files /dev/null and b/textures/carts_rail_cp.png differ diff --git a/textures/carts_rail_crossing_brk.png b/textures/carts_rail_crossing_brk.png new file mode 100644 index 0000000..3ace508 Binary files /dev/null and b/textures/carts_rail_crossing_brk.png differ diff --git a/textures/carts_rail_crossing_cp.png b/textures/carts_rail_crossing_cp.png new file mode 100644 index 0000000..6b55059 Binary files /dev/null and b/textures/carts_rail_crossing_cp.png differ diff --git a/textures/carts_rail_crossing_pwr.png b/textures/carts_rail_crossing_pwr.png new file mode 100644 index 0000000..d63f133 Binary files /dev/null and b/textures/carts_rail_crossing_pwr.png differ diff --git a/textures/carts_rail_curved_brk.png b/textures/carts_rail_curved_brk.png new file mode 100644 index 0000000..5a84918 Binary files /dev/null and b/textures/carts_rail_curved_brk.png differ diff --git a/textures/carts_rail_curved_cp.png b/textures/carts_rail_curved_cp.png new file mode 100644 index 0000000..7364d22 Binary files /dev/null and b/textures/carts_rail_curved_cp.png differ diff --git a/textures/carts_rail_curved_pwr.png b/textures/carts_rail_curved_pwr.png new file mode 100644 index 0000000..e2ac67a Binary files /dev/null and b/textures/carts_rail_curved_pwr.png differ diff --git a/textures/carts_rail_pwr.png b/textures/carts_rail_pwr.png new file mode 100644 index 0000000..95f33f6 Binary files /dev/null and b/textures/carts_rail_pwr.png differ diff --git a/textures/carts_rail_t_junction_brk.png b/textures/carts_rail_t_junction_brk.png new file mode 100644 index 0000000..0c2c1cb Binary files /dev/null and b/textures/carts_rail_t_junction_brk.png differ diff --git a/textures/carts_rail_t_junction_cp.png b/textures/carts_rail_t_junction_cp.png new file mode 100644 index 0000000..27d96cd Binary files /dev/null and b/textures/carts_rail_t_junction_cp.png differ diff --git a/textures/carts_rail_t_junction_pwr.png b/textures/carts_rail_t_junction_pwr.png new file mode 100644 index 0000000..7f97fc7 Binary files /dev/null and b/textures/carts_rail_t_junction_pwr.png differ