diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index 1a298841e..42cdecd12 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -138,13 +138,3 @@ function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype) return {x=0, y=0, z=0} end -function mcl_minecarts:boost_rail(pos, amount) - minetest.get_meta(pos):set_string("cart_acceleration", tostring(amount)) - for _,obj_ in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do - if not obj_:is_player() and - obj_:get_luaentity() and - obj_:get_luaentity().name == "mcl_minecarts:minecart" then - obj_:get_luaentity():on_punch() - end - end -end diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index 23a95e725..5333613b3 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -31,6 +31,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) _start_pos = nil, -- Used to calculate distance for “On A Rail” achievement _old_dir = {x=0, y=0, z=0}, _old_pos = nil, + _old_vel = {x=0, y=0, z=0}, _old_switch = 0, _railtype = nil, } @@ -128,6 +129,18 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) ctrl = player:get_player_control() end end + + -- Stop cart if velocity vector flips + if self._old_vel and self._old_vel.y == 0 and + (self._old_vel.x * vel.x < 0 or self._old_vel.z * vel.z < 0) then + self._old_vel = {x = 0, y = 0, z = 0} + self._old_pos = pos + self.object:setvelocity(vector.new()) + self.object:setacceleration(vector.new()) + return + end + self._old_vel = vector.new(vel) + if self._old_pos then local diff = vector.subtract(self._old_pos, pos) for _,v in ipairs({"x","y","z"}) do @@ -187,17 +200,9 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) -- Slow down or speed up local acc = dir.y * -1.8 - local speed_mod = tonumber(minetest.get_meta(pos):get_string("cart_acceleration")) + local speed_mod = minetest.registered_nodes[minetest.get_node(pos).name]._rail_acceleration if speed_mod and speed_mod ~= 0 then - if speed_mod > 0 then - 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 * 8) + acc = acc + speed_mod else acc = acc - 0.4 end @@ -214,6 +219,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) for _,v in ipairs({"x","y","z"}) do if math.abs(vel[v]) > max_vel then vel[v] = mcl_minecarts:get_sign(vel[v]) * max_vel + new_acc[v] = 0 update.vel = true end end diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index f68a738c9..fb2a97b12 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -33,11 +33,26 @@ minetest.register_craft({ } }) --- Rail to speed up -minetest.register_node("mcl_minecarts:golden_rail", { +-- Function that get the input/output rules of the powered rails +local get_input_rules = function() + return { + {x = -1, y = 0, z = 0}, + {x = 1, y = 0, z = 0}, + {x = 0, y = 0, z = -1}, + {x = 0, y = 0, z = 1}, + } +end + +local get_output_rules = function() + return {} +end + +-- Powered rail + +local powered_rail_template = { description = "Powered Rail", - _doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Powered rails will accelerate moving minecarts, up to a maximum speed.", - _doc_items_usagehelp = railuse, + _doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Powered rails are able to accelerate and brake minecarts.", + _doc_items_usagehelp = railuse .. "\n" .. "Without redstone power, the rail will brake minecarts. To make this rail accelerate minecarts, power it with redstone power.", 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", @@ -47,31 +62,61 @@ minetest.register_node("mcl_minecarts:golden_rail", { 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 = {handy=1,pickaxey=1, attached_node = 1, rail = 1, connect_to_raillike = 1, dig_by_water = 1,destroy_by_lava_flow=1, transport = 1}, - - after_place_node = function(pos, placer, itemstack) - if not mesecon then - minetest.get_meta(pos):set_string("cart_acceleration", "0.5") - end - end, + sounds = mcl_sounds.node_sound_metal_defaults(), mesecons = { effector = { action_on = function(pos, node) - mcl_minecarts:boost_rail(pos, 0.5) - end, - - action_off = function(pos, node) - minetest.get_meta(pos):set_string("cart_acceleration", "0") + minetest.swap_node(pos, {name = "mcl_minecarts:golden_rail_on", param2 = node.param2 }) + mesecon:receptor_on(pos, get_input_rules()) end, }, + receptor = { + state = mesecon.state.off, + rules = get_output_rules, + }, }, + + _rail_acceleration = -3, _mcl_blast_resistance = 3.5, _mcl_hardness = 0.7, -}) +} +minetest.register_node("mcl_minecarts:golden_rail", powered_rail_template) + + +-- Powered rail (activated by redstone) +local powered_rail_on = table.copy(powered_rail_template) +powered_rail_on.description = nil +powered_rail_on._doc_items_create_entry = false +powered_rail_on._doc_items_longdesc = nil +powered_rail_on._doc_items_usagehelp = nil +powered_rail_on.tiles = {"mcl_minecarts_rail_golden_powered.png", "mcl_minecarts_rail_golden_curved_powered.png", "mcl_minecarts_rail_golden_t_junction_powered.png", "mcl_minecarts_rail_golden_crossing_powered.png"} +powered_rail_on.inventory_image = "mcl_minecarts_rail_golden_powered.png" +powered_rail_on.wield_image = "mcl_minecarts_rail_golden_powered.png" +powered_rail_on.groups.not_in_creative_inventory = 1 +powered_rail_on.groups.transport = nil +powered_rail_on.mesecons = { + effector = { + action_off = function(pos, node) + minetest.swap_node(pos, {name = "mcl_minecarts:golden_rail", param2 = node.param2 }) + mesecon:receptor_off(pos, get_input_rules()) + end, + }, + receptor = { + state = mesecon.state.on, + rules = get_output_rules, + } +} +powered_rail_on._rail_acceleration = 4 + +minetest.register_node("mcl_minecarts:golden_rail_on", powered_rail_on) + +if minetest.get_modpath("doc") then + doc.add_entry_alias("nodes", "mcl_minecarts:golden_rail", "nodes", "mcl_minecarts:golden_rail_on") +end minetest.register_craft({ output = "mcl_minecarts:golden_rail 6", diff --git a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_crossing_pwr.png b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_crossing_pwr.png index 9ea9335d6..df8f6bfbe 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_crossing_pwr.png and b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_crossing_pwr.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_curved_pwr.png b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_curved_pwr.png index a9ab6eeb4..d557a358a 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_curved_pwr.png and b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_curved_pwr.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_pwr.png b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_pwr.png index 712820326..87a0b7bd5 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_pwr.png and b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_pwr.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_t_junction_pwr.png b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_t_junction_pwr.png index 962d0a702..042f3d1be 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_t_junction_pwr.png and b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_t_junction_pwr.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/default_rail_crossing.png b/mods/ENTITIES/mcl_minecarts/textures/default_rail_crossing.png index 22556d38d..409f14b82 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/default_rail_crossing.png and b/mods/ENTITIES/mcl_minecarts/textures/default_rail_crossing.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/default_rail_t_junction.png b/mods/ENTITIES/mcl_minecarts/textures/default_rail_t_junction.png index fc5b3ba31..f25c510f5 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/default_rail_t_junction.png and b/mods/ENTITIES/mcl_minecarts/textures/default_rail_t_junction.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_crossing_powered.png b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_crossing_powered.png new file mode 100644 index 000000000..81526029d Binary files /dev/null and b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_crossing_powered.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_curved_powered.png b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_curved_powered.png new file mode 100644 index 000000000..ff1b917e2 Binary files /dev/null and b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_curved_powered.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_powered.png b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_powered.png new file mode 100644 index 000000000..c118032ef Binary files /dev/null and b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_powered.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_t_junction_powered.png b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_t_junction_powered.png new file mode 100644 index 000000000..6a4af0209 Binary files /dev/null and b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_t_junction_powered.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/rail_detector.png b/mods/ENTITIES/mcl_minecarts/textures/rail_detector.png index d4548bc21..88eef9f6d 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/rail_detector.png and b/mods/ENTITIES/mcl_minecarts/textures/rail_detector.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/rail_detector_powered.png b/mods/ENTITIES/mcl_minecarts/textures/rail_detector_powered.png index 07369867b..ae1083d20 100644 Binary files a/mods/ENTITIES/mcl_minecarts/textures/rail_detector_powered.png and b/mods/ENTITIES/mcl_minecarts/textures/rail_detector_powered.png differ diff --git a/mods/ENTITIES/mcl_minecarts/textures/rail_golden_powered.png b/mods/ENTITIES/mcl_minecarts/textures/rail_golden_powered.png deleted file mode 100644 index 9d7b9d58a..000000000 Binary files a/mods/ENTITIES/mcl_minecarts/textures/rail_golden_powered.png and /dev/null differ