Skip to content

Commit

Permalink
Bump to 5.0.0 and fix the copper rail
Browse files Browse the repository at this point in the history
moreores only adds the copper rail when the 'carts' mod was found
  • Loading branch information
SmallJoker committed Oct 18, 2019
1 parent e4edb96 commit ae33bd7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 51 deletions.
24 changes: 9 additions & 15 deletions cart_entity.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

local HAVE_MESECONS_ENABLED = minetest.global_exists("mesecon")

function boost_cart:on_rail_step(entity, pos, distance)
-- Play rail sound
if entity.sound_counter <= 0 then
Expand All @@ -13,7 +11,7 @@ function boost_cart:on_rail_step(entity, pos, distance)
end
entity.sound_counter = entity.sound_counter - distance

if HAVE_MESECONS_ENABLED then
if boost_cart.MESECONS then
boost_cart:signal_detector_rail(pos)
end
end
Expand All @@ -40,7 +38,7 @@ local cart_entity = {
}

-- Model and textures
if boost_cart.mtg_compat then
if boost_cart.MTG_CARTS then
cart_entity.initial_properties.mesh = "carts_cart.b3d"
cart_entity.initial_properties.textures = {"carts_cart.png"}
end
Expand Down Expand Up @@ -289,7 +287,7 @@ function cart_entity:on_step(dtime)
acc = speed_mod * 10
end
end
if acc == nil and boost_cart.mtg_compat then
if acc == nil and boost_cart.MTG_CARTS then
-- MTG Cart API adaption
local rail_node = minetest.get_node(vector.round(pos))
local railparam = carts.railparams[rail_node.name]
Expand Down Expand Up @@ -380,18 +378,14 @@ function cart_entity:on_step(dtime)

-- Change player model rotation, depending on the Y direction
if player and dir.y ~= old_y_dir then
local feet = {x=0, y=0, z=0}
local feet = {x=0, y=-4, z=0}
local eye = {x=0, y=-4, z=0}
feet.y = boost_cart.old_player_model and 6 or -4

if dir.y ~= 0 then
-- TODO: Find a better way to calculate this
if boost_cart.old_player_model then
feet.y = feet.y + 2
feet.z = -dir.y * 6
else
feet.y = feet.y + 4
feet.z = -dir.y * 2
end
feet.y = feet.y + 4
feet.z = -dir.y * 2

eye.z = -dir.y * 8
end
player:set_attach(self.object, "", feet,
Expand All @@ -414,7 +408,7 @@ end
minetest.register_entity(":carts:cart", cart_entity)

-- Register item to place the entity
if not boost_cart.mtg_compat then
if not boost_cart.MTG_CARTS then
minetest.register_craftitem(":carts:cart", {
description = "Cart (Sneak+Click to pick up)",
inventory_image = minetest.inventorycube(
Expand Down
4 changes: 0 additions & 4 deletions depends.txt

This file was deleted.

1 change: 0 additions & 1 deletion description.txt

This file was deleted.

16 changes: 7 additions & 9 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ function boost_cart:manage_attachment(player, obj)
if not player then
return
end
local status = obj ~= nil
local wants_attach = obj ~= nil
local attached = player:get_attach() ~= nil

local player_name = player:get_player_name()
if default.player_attached[player_name] == status then
boost_cart.player_attached[player_name] = attached or wants_attach
if attached == wants_attach then
return
end
default.player_attached[player_name] = status

if status then
local y_pos = self.old_player_model and 6 or -4
if player:get_properties().visual == "upright_sprite" then
y_pos = -4
end
player:set_attach(obj, "", {x=0, y=y_pos, z=0}, {x=0, y=0, z=0})
if wants_attach then
player:set_attach(obj, "", {x=0, y=-4, z=0}, {x=0, y=0, z=0})
player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
else
player:set_detach()
Expand Down
30 changes: 14 additions & 16 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

boost_cart = {}
boost_cart.modpath = minetest.get_modpath("boost_cart")


if not minetest.settings then
if not minetest.features.object_use_texture_alpha then
error("[boost_cart] Your Minetest version is no longer supported."
.. " (Version <= 0.4.15)")
.. " (Version < 5.0.0)")
end

boost_cart = {}
boost_cart.modpath = minetest.get_modpath("boost_cart")
boost_cart.MESECONS = minetest.global_exists("mesecon")
boost_cart.MTG_CARTS = minetest.global_exists("carts") and carts.pathfinder
boost_cart.PLAYER_API = minetest.global_exists("player_api")
boost_cart.player_attached = {}

local function getNum(setting)
return tonumber(minetest.settings:get(setting))
end
Expand All @@ -20,27 +23,22 @@ boost_cart.punch_speed_max = getNum("boost_cart.punch_speed_max") or 7
boost_cart.path_distance_max = 3


-- Support for non-default games
if not default.player_attached then
default.player_attached = {}
if boost_cart.PLAYER_API then
-- This is a table reference!
boost_cart.player_attached = player_api.player_attached
end

minetest.after(0, function()
boost_cart.old_player_model = not minetest.global_exists("player_api")
end)

dofile(boost_cart.modpath.."/functions.lua")
dofile(boost_cart.modpath.."/rails.lua")

if minetest.global_exists("mesecon") then
if boost_cart.MESECONS then
dofile(boost_cart.modpath.."/detector.lua")
--else
-- minetest.register_alias("carts:powerrail", "boost_cart:detectorrail")
-- minetest.register_alias("carts:powerrail", "boost_cart:detectorrail_on")
end

boost_cart.mtg_compat = minetest.global_exists("carts") and carts.pathfinder
if boost_cart.mtg_compat then
if boost_cart.MTG_CARTS then
minetest.log("action", "[boost_cart] Overwriting definitions of similar carts mod")
end
dofile(boost_cart.modpath.."/cart_entity.lua")
8 changes: 7 additions & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
name = boost_cart
name = boost_cart
description = """
Boost Cart
The mod that add a cart and new kinds of rails to your world.
"""
depends = default
optional_depends = mesecons, moreores, carts, player_api
13 changes: 8 additions & 5 deletions rails.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ boost_cart:register_rail(":"..regular_rail_itemname, {
})

-- Moreores' copper rail
local copperrail_registered = false
if minetest.get_modpath("moreores") then
minetest.register_alias("carts:copperrail", "moreores:copper_rail")

if minetest.raillike_group then
local raildef = minetest.registered_nodes["moreores:copper_rail"]
if raildef and minetest.raillike_group then
-- Ensure that this rail uses the same connect_to_raillike
local new_groups = minetest.registered_nodes["moreores:copper_rail"].groups
new_groups.connect_to_raillike = minetest.raillike_group("rail")
raildef.groups.connect_to_raillike = minetest.raillike_group("rail")
minetest.override_item("moreores:copper_rail", {
groups = new_groups
groups = raildef.groups
})
copperrail_registered = true
end
else
end
if not copperrail_registered then
boost_cart:register_rail(":carts:copperrail", {
description = "Copper rail",
tiles = {
Expand Down

0 comments on commit ae33bd7

Please sign in to comment.