forked from mtcontrib/boost_cart
		
	Compare commits
	
		
			1 Commits
		
	
	
		
			d3a0b0e2c2
			...
			rotationte
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 792756c003 | 
							
								
								
									
										50
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,50 +0,0 @@ | |||||||
| # Boost Cart |  | ||||||
| Based on (and fully compatible with) the mod "carts" by PilzAdam |  | ||||||
| and the one contained in the subgame "minetest_game". |  | ||||||
| Target: Run smoothly as possible, even on laggy servers. |  | ||||||
|  |  | ||||||
| ## Features |  | ||||||
| - A fast cart for your railway or roller coaster |  | ||||||
| - Easily configurable cart speed using the Advanced Settings |  | ||||||
| - Boost and brake rails |  | ||||||
| - By mesecons controlled Start-Stop rails |  | ||||||
| - Detector rails that send a mesecons signal when the cart drives over them |  | ||||||
| - Rail junction switching with the 'right/left' walking keys |  | ||||||
| - Handbrake with the 'back' key |  | ||||||
| - Support for non-minetest_game subgames |  | ||||||
| - Descend from cart using the `sneak` key |  | ||||||
|  |  | ||||||
| ## Settings |  | ||||||
| This mod can be adjusted to fit the preference of a player or server. Use the `Settings -> All Settings` dialog in the main menu or tune your |  | ||||||
| minetest.conf file manually: |  | ||||||
|  |  | ||||||
| #### `boost_cart.speed_max = 10` |  | ||||||
| * Maximal speed of the cart in m/s |  | ||||||
| * Possible values: 1 ... 100 |  | ||||||
|  |  | ||||||
| #### `boost_cart.punch_speed_max = 7` |  | ||||||
| * Maximal speed to which the driving player can accelerate the cart by punching from inside the cart. |  | ||||||
| * Possible values: -1 ... 100 |  | ||||||
| * Value `-1` will disable this feature. |  | ||||||
|  |  | ||||||
| ## License for everything |  | ||||||
| CC-0, if not specified otherwise below |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  Authors |  | ||||||
| --------- |  | ||||||
| Various authors |  | ||||||
| - carts_rail_*.png |  | ||||||
|  |  | ||||||
| kddekadenz |  | ||||||
| - cart_bottom.png |  | ||||||
| - cart_side.png |  | ||||||
| - cart_top.png |  | ||||||
|  |  | ||||||
| klankbeeld (CC-BY 3.0) |  | ||||||
| - http://freesound.org/people/klankbeeld/sounds/174042/ |  | ||||||
| - cart_rail.*.ogg |  | ||||||
|  |  | ||||||
| Zeg9 |  | ||||||
| - cart.x |  | ||||||
| - cart.png |  | ||||||
							
								
								
									
										57
									
								
								README.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								README.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | |||||||
|  |  Minetest mod: boost_cart | ||||||
|  | ========================== | ||||||
|  | Based on (and fully compatible with) the mod "carts" by PilzAdam | ||||||
|  | and the one contained in the subgame "minetest_game". | ||||||
|  | Target: Run smoothly as possible, even on laggy servers. | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  Features | ||||||
|  | ---------- | ||||||
|  | - A fast cart for your railway or roller coaster | ||||||
|  | - Easily configurable cart speed using the Advanced Settings | ||||||
|  | - Boost and brake rails | ||||||
|  | - By mesecons controlled Start-Stop rails | ||||||
|  | - Detector rails that send a mesecons signal when the cart drives over them | ||||||
|  | - Rail junction switching with the 'right/left' walking keys | ||||||
|  | - Handbrake with the 'back' key | ||||||
|  | - Support for non-minetest_game subgames | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  Settings | ||||||
|  | ---------- | ||||||
|  | This mod can be adjusted to fit the conditions of a player or server. | ||||||
|  | Use the Advanced Settings dialog in the main menu or tune your | ||||||
|  | minetest.conf file manually: | ||||||
|  |  | ||||||
|  | boost_cart.speed_max = 10 | ||||||
|  |    ^ Possible values: 1 ... 100 | ||||||
|  |    ^ Maximal speed of the cart in m/s | ||||||
|  |  | ||||||
|  | boost_cart.punch_speed_max = 7 | ||||||
|  |    ^ Possible values: -1 ... 100 | ||||||
|  |    ^ Maximal speed to which the driving player can accelerate the cart | ||||||
|  |      by punching from inside the cart. -1 will disable this feature. | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  License for everything | ||||||
|  | ------------------------ | ||||||
|  | CC-0, if not specified otherwise below | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  Authors | ||||||
|  | --------- | ||||||
|  | Various authors | ||||||
|  | 	carts_rail_*.png | ||||||
|  |  | ||||||
|  | kddekadenz | ||||||
|  | 	cart_bottom.png | ||||||
|  | 	cart_side.png | ||||||
|  | 	cart_top.png | ||||||
|  |  | ||||||
|  | klankbeeld (CC-BY 3.0) | ||||||
|  | 	http://freesound.org/people/klankbeeld/sounds/174042/ | ||||||
|  | 	cart_rail.*.ogg | ||||||
|  |  | ||||||
|  | Zeg9 | ||||||
|  | 	cart.x | ||||||
|  | 	cart.png | ||||||
							
								
								
									
										135
									
								
								cart_entity.lua
									
									
									
									
									
								
							
							
						
						
									
										135
									
								
								cart_entity.lua
									
									
									
									
									
								
							| @@ -1,4 +1,6 @@ | |||||||
|  |  | ||||||
|  | local HAVE_MESECONS_ENABLED = minetest.global_exists("mesecon") | ||||||
|  |  | ||||||
| function boost_cart:on_rail_step(entity, pos, distance) | function boost_cart:on_rail_step(entity, pos, distance) | ||||||
| 	-- Play rail sound | 	-- Play rail sound | ||||||
| 	if entity.sound_counter <= 0 then | 	if entity.sound_counter <= 0 then | ||||||
| @@ -11,20 +13,18 @@ function boost_cart:on_rail_step(entity, pos, distance) | |||||||
| 	end | 	end | ||||||
| 	entity.sound_counter = entity.sound_counter - distance | 	entity.sound_counter = entity.sound_counter - distance | ||||||
|  |  | ||||||
| 	if boost_cart.MESECONS then | 	if HAVE_MESECONS_ENABLED then | ||||||
| 		boost_cart:signal_detector_rail(pos) | 		boost_cart:signal_detector_rail(pos) | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| local cart_entity = { | local cart_entity = { | ||||||
| 	initial_properties = { | 	physical = false, | ||||||
| 		physical = false, | 	collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, | ||||||
| 		collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, | 	visual = "mesh", | ||||||
| 		visual = "mesh", | 	mesh = "cart.x", | ||||||
| 		mesh = "cart.x", | 	visual_size = {x=1, y=1}, | ||||||
| 		visual_size = {x=1, y=1}, | 	textures = {"cart.png"}, | ||||||
| 		textures = {"cart.png"}, |  | ||||||
| 	}, |  | ||||||
|  |  | ||||||
| 	driver = nil, | 	driver = nil, | ||||||
| 	punched = false, -- used to re-send velocity and position | 	punched = false, -- used to re-send velocity and position | ||||||
| @@ -34,13 +34,15 @@ local cart_entity = { | |||||||
| 	old_switch = 0, | 	old_switch = 0, | ||||||
| 	sound_counter = 0, | 	sound_counter = 0, | ||||||
| 	railtype = nil, | 	railtype = nil, | ||||||
| 	attached_items = {} | 	attached_items = {}, | ||||||
|  | 	automatic_face_movement_dir = -90.0, | ||||||
|  | 	automatic_face_movement_max_rotation_per_sec = 360 * 4, | ||||||
| } | } | ||||||
|  |  | ||||||
| -- Model and textures | -- Model and textures | ||||||
| if boost_cart.MTG_CARTS then | if boost_cart.mtg_compat then | ||||||
| 	cart_entity.initial_properties.mesh = "carts_cart.b3d" | 	cart_entity.mesh = "carts_cart.b3d" | ||||||
| 	cart_entity.initial_properties.textures = {"carts_cart.png"} | 	cart_entity.textures = {"carts_cart.png"} | ||||||
| end | end | ||||||
|  |  | ||||||
| function cart_entity:on_rightclick(clicker) | function cart_entity:on_rightclick(clicker) | ||||||
| @@ -54,12 +56,6 @@ function cart_entity:on_rightclick(clicker) | |||||||
| 	elseif not self.driver then | 	elseif not self.driver then | ||||||
| 		self.driver = player_name | 		self.driver = player_name | ||||||
| 		boost_cart:manage_attachment(clicker, self.object) | 		boost_cart:manage_attachment(clicker, self.object) | ||||||
|  |  | ||||||
| 		if default.player_set_animation then |  | ||||||
| 			-- player_api(/default) does not update the animation |  | ||||||
| 			-- when the player is attached, reset to default animation |  | ||||||
| 			default.player_set_animation(clicker, "stand") |  | ||||||
| 		end |  | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -75,30 +71,18 @@ function cart_entity:on_activate(staticdata, dtime_s) | |||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| 	self.railtype = data.railtype | 	self.railtype = data.railtype | ||||||
| 	self.old_dir = data.old_dir or self.old_dir | 	if data.old_dir then | ||||||
| 	self.old_pos = data.old_pos or self.old_pos | 		self.old_dir = data.old_dir | ||||||
| 	-- Correct the position when the cart drives further after the last 'step()' |  | ||||||
| 	if self.old_pos and boost_cart:is_rail(self.old_pos, self.railtype) then |  | ||||||
| 		self.object:set_pos(self.old_pos) |  | ||||||
| 	end | 	end | ||||||
| end | end | ||||||
|  |  | ||||||
| function cart_entity:get_staticdata() | function cart_entity:get_staticdata() | ||||||
| 	return minetest.serialize({ | 	return minetest.serialize({ | ||||||
| 		railtype = self.railtype, | 		railtype = self.railtype, | ||||||
| 		old_dir = self.old_dir, | 		old_dir = self.old_dir | ||||||
| 		old_pos = self.old_pos |  | ||||||
| 	}) | 	}) | ||||||
| end | end | ||||||
|  |  | ||||||
| -- 0.5.x and later: When the driver leaves |  | ||||||
| function cart_entity:on_detach_child(child) |  | ||||||
| 	if child and child:get_player_name() == self.driver then |  | ||||||
| 		self.driver = nil |  | ||||||
| 		boost_cart:manage_attachment(child, nil) |  | ||||||
| 	end |  | ||||||
| end |  | ||||||
|  |  | ||||||
| function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) | function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) | ||||||
| 	local pos = self.object:get_pos() | 	local pos = self.object:get_pos() | ||||||
| 	local vel = self.object:get_velocity() | 	local vel = self.object:get_velocity() | ||||||
| @@ -234,12 +218,11 @@ function cart_entity:on_step(dtime) | |||||||
| 	) | 	) | ||||||
| 	local dir_changed = not vector.equals(dir, self.old_dir) | 	local dir_changed = not vector.equals(dir, self.old_dir) | ||||||
|  |  | ||||||
| 	local acc = 0 | 	local new_acc = {x=0, y=0, z=0} | ||||||
| 	if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then | 	if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then | ||||||
| 		vel = {x=0, y=0, z=0} | 		vel = {x=0, y=0, z=0} | ||||||
| 		local pos_r = vector.round(pos) | 		local pos_r = vector.round(pos) | ||||||
| 		if not boost_cart:is_rail(pos_r, self.railtype) | 		if not boost_cart:is_rail(pos_r, self.railtype) then | ||||||
| 				and self.old_pos then |  | ||||||
| 			pos = self.old_pos | 			pos = self.old_pos | ||||||
| 		elseif not stop_wiggle then | 		elseif not stop_wiggle then | ||||||
| 			pos = pos_r | 			pos = pos_r | ||||||
| @@ -251,7 +234,7 @@ function cart_entity:on_step(dtime) | |||||||
| 	else | 	else | ||||||
| 		-- Direction change detected | 		-- Direction change detected | ||||||
| 		if dir_changed then | 		if dir_changed then | ||||||
| 			vel = vector.multiply(dir, math.abs(vel.x + vel.z)) | 			vel = vector.multiply(dir, v3_len(vel)) | ||||||
| 			update.vel = true | 			update.vel = true | ||||||
| 			if dir.y ~= self.old_dir.y then | 			if dir.y ~= self.old_dir.y then | ||||||
| 				pos = vector.round(pos) | 				pos = vector.round(pos) | ||||||
| @@ -269,7 +252,7 @@ function cart_entity:on_step(dtime) | |||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		-- Calculate current cart acceleration | 		-- Calculate current cart acceleration | ||||||
| 		acc = nil | 		local acc = nil | ||||||
|  |  | ||||||
| 		local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration") | 		local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration") | ||||||
| 		if acc_meta == "halt" and not self.punched then | 		if acc_meta == "halt" and not self.punched then | ||||||
| @@ -288,7 +271,7 @@ function cart_entity:on_step(dtime) | |||||||
| 				acc = speed_mod * 10 | 				acc = speed_mod * 10 | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
| 		if acc == nil and boost_cart.MTG_CARTS then | 		if acc == nil and boost_cart.mtg_compat then | ||||||
| 			-- MTG Cart API adaption | 			-- MTG Cart API adaption | ||||||
| 			local rail_node = minetest.get_node(vector.round(pos)) | 			local rail_node = minetest.get_node(vector.round(pos)) | ||||||
| 			local railparam = carts.railparams[rail_node.name] | 			local railparam = carts.railparams[rail_node.name] | ||||||
| @@ -304,12 +287,6 @@ function cart_entity:on_step(dtime) | |||||||
| 				acc = -0.4 | 				acc = -0.4 | ||||||
| 			end | 			end | ||||||
| 		end | 		end | ||||||
| 		if ctrl and ctrl.sneak then |  | ||||||
| 			-- Descend when sneak is pressed |  | ||||||
| 			boost_cart:manage_attachment(player, nil) |  | ||||||
| 			player = nil |  | ||||||
| 			ctrl = nil |  | ||||||
| 		end |  | ||||||
|  |  | ||||||
| 		if acc then | 		if acc then | ||||||
| 			-- Slow down or speed up, depending on Y direction | 			-- Slow down or speed up, depending on Y direction | ||||||
| @@ -317,20 +294,21 @@ function cart_entity:on_step(dtime) | |||||||
| 		else | 		else | ||||||
| 			acc = 0 | 			acc = 0 | ||||||
| 		end | 		end | ||||||
|  |  | ||||||
|  | 		new_acc = vector.multiply(dir, acc) | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	-- Limit cart speed | 	-- Limits | ||||||
| 	local vel_len = vector.length(vel) | 	local max_vel = boost_cart.speed_max | ||||||
| 	if vel_len > boost_cart.speed_max then | 	for _,v in pairs({"x","y","z"}) do | ||||||
| 		vel = vector.multiply(vel, boost_cart.speed_max / vel_len) | 		if math.abs(vel[v]) > max_vel then | ||||||
| 		update.vel = true | 			vel[v] = boost_cart:get_sign(vel[v]) * max_vel | ||||||
| 	end | 			new_acc[v] = 0 | ||||||
| 	if vel_len >= boost_cart.speed_max and acc > 0 then | 			update.vel = true | ||||||
| 		acc = 0 | 		end | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	self.object:set_acceleration(vector.multiply(dir, acc)) | 	self.object:set_acceleration(new_acc) | ||||||
|  |  | ||||||
| 	self.old_pos = vector.round(pos) | 	self.old_pos = vector.round(pos) | ||||||
| 	local old_y_dir = self.old_dir.y | 	local old_y_dir = self.old_dir.y | ||||||
| 	if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then | 	if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then | ||||||
| @@ -346,13 +324,10 @@ function cart_entity:on_step(dtime) | |||||||
| 	if self.punched then | 	if self.punched then | ||||||
| 		-- Collect dropped items | 		-- Collect dropped items | ||||||
| 		for _, obj_ in pairs(minetest.get_objects_inside_radius(pos, 1)) do | 		for _, obj_ in pairs(minetest.get_objects_inside_radius(pos, 1)) do | ||||||
| 			local ent = obj_:get_luaentity() | 			if not obj_:is_player() and | ||||||
| 			-- Careful here: physical_state and disable_physics are item-internal APIs | 					obj_:get_luaentity() and | ||||||
| 			if ent and ent.name == "__builtin:item" and ent.physical_state then | 					not obj_:get_luaentity().physical_state and | ||||||
| 				-- Check API to support 5.2.0 and older | 					obj_:get_luaentity().name == "__builtin:item" then | ||||||
| 				if ent.disable_physics then |  | ||||||
| 					ent:disable_physics() |  | ||||||
| 				end |  | ||||||
|  |  | ||||||
| 				obj_:set_attach(self.object, "", {x=0, y=0, z=0}, {x=0, y=0, z=0}) | 				obj_:set_attach(self.object, "", {x=0, y=0, z=0}, {x=0, y=0, z=0}) | ||||||
| 				self.attached_items[#self.attached_items + 1] = obj_ | 				self.attached_items[#self.attached_items + 1] = obj_ | ||||||
| @@ -368,15 +343,17 @@ function cart_entity:on_step(dtime) | |||||||
| 	-- Re-use "dir", localize self.old_dir | 	-- Re-use "dir", localize self.old_dir | ||||||
| 	dir = self.old_dir | 	dir = self.old_dir | ||||||
|  |  | ||||||
| 	local yaw = 0 | 	if stop_wiggle then | ||||||
| 	if dir.x < 0 then | 		local yaw = 0 | ||||||
| 		yaw = 0.5 | 		if dir.x < 0 then | ||||||
| 	elseif dir.x > 0 then | 			yaw = 0.5 | ||||||
| 		yaw = 1.5 | 		elseif dir.x > 0 then | ||||||
| 	elseif dir.z < 0 then | 			yaw = 1.5 | ||||||
| 		yaw = 1 | 		elseif dir.z < 0 then | ||||||
|  | 			yaw = 1 | ||||||
|  | 		end | ||||||
|  | 		self.object:set_yaw(yaw * math.pi) | ||||||
| 	end | 	end | ||||||
| 	self.object:set_yaw(yaw * math.pi) |  | ||||||
|  |  | ||||||
| 	local anim = {x=0, y=0} | 	local anim = {x=0, y=0} | ||||||
| 	if dir.y == -1 then | 	if dir.y == -1 then | ||||||
| @@ -388,14 +365,18 @@ function cart_entity:on_step(dtime) | |||||||
|  |  | ||||||
| 	-- Change player model rotation, depending on the Y direction | 	-- Change player model rotation, depending on the Y direction | ||||||
| 	if player and dir.y ~= old_y_dir then | 	if player and dir.y ~= old_y_dir then | ||||||
| 		local feet = {x=0, y=-4, z=0} | 		local feet = {x=0, y=0, z=0} | ||||||
| 		local eye = {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 | 		if dir.y ~= 0 then | ||||||
| 			-- TODO: Find a better way to calculate this | 			-- TODO: Find a better way to calculate this | ||||||
| 			feet.y = feet.y + 4 | 			if boost_cart.old_player_model then | ||||||
| 			feet.z = -dir.y * 2 | 				feet.y = feet.y + 2 | ||||||
|  | 				feet.z = -dir.y * 6 | ||||||
|  | 			else | ||||||
|  | 				feet.y = feet.y + 4 | ||||||
|  | 				feet.z = -dir.y * 2 | ||||||
|  | 			end | ||||||
| 			eye.z = -dir.y * 8 | 			eye.z = -dir.y * 8 | ||||||
| 		end | 		end | ||||||
| 		player:set_attach(self.object, "", feet, | 		player:set_attach(self.object, "", feet, | ||||||
| @@ -418,7 +399,7 @@ end | |||||||
| minetest.register_entity(":carts:cart", cart_entity) | minetest.register_entity(":carts:cart", cart_entity) | ||||||
|  |  | ||||||
| -- Register item to place the entity | -- Register item to place the entity | ||||||
| if not boost_cart.MTG_CARTS then | if not boost_cart.mtg_compat then | ||||||
| 	minetest.register_craftitem(":carts:cart", { | 	minetest.register_craftitem(":carts:cart", { | ||||||
| 		description = "Cart (Sneak+Click to pick up)", | 		description = "Cart (Sneak+Click to pick up)", | ||||||
| 		inventory_image = minetest.inventorycube( | 		inventory_image = minetest.inventorycube( | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								depends.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								depends.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | default | ||||||
|  | mesecons? | ||||||
|  | moreores? | ||||||
|  | carts? | ||||||
							
								
								
									
										1
									
								
								description.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								description.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | This mod offers improved minecarts and a few more rail types. | ||||||
| @@ -1,71 +0,0 @@ | |||||||
| boost_cart API |  | ||||||
| ============== |  | ||||||
|  |  | ||||||
| This file provides information about the API of boost_cart for the use in |  | ||||||
| mods. The API might change slightly when the development goes on, so avoid |  | ||||||
| using internal tables or functions which are not documented here. |  | ||||||
|  |  | ||||||
|  |  | ||||||
| Types |  | ||||||
| ----- |  | ||||||
|  |  | ||||||
| * `SwitchIgnore` -> `number/nil` |  | ||||||
| 	* Specifies which player control was pressed. This value is used to prefer |  | ||||||
| 	  straight rails instead of preferring left and right rail checks. |  | ||||||
| 		* `1`: Ignore left rail |  | ||||||
| 		* `2`: Ignore right rail |  | ||||||
| 		* `nil`: Ignore no rail |  | ||||||
|  |  | ||||||
|  |  | ||||||
| Entity movement |  | ||||||
| --------------- |  | ||||||
| These functions are grouped so that they make sense and then sorted alphabetically. |  | ||||||
|  |  | ||||||
| * `boost_cart:manage_attachment(player, obj)` |  | ||||||
| 	* Attaches or detaches the player to/from an object, depending on what is |  | ||||||
| 	  supplied to `obj`. |  | ||||||
| 	* `player`: `ObjectRef` of the player |  | ||||||
| 	* `obj`: `ObjectRef` (to attach) or `nil` (to detach) |  | ||||||
| * `boost_cart:get_sign(n)` -> `number` |  | ||||||
| 	* Returns the sign for the given number. Values: `-1`, `0`, `1` |  | ||||||
| 	* `n`: any `number` |  | ||||||
| * `boost_cart:velocity_to_dir(vel)` -> `vector` |  | ||||||
| 	* Returns the cart direction depending on `vel`. Each coordinate can have |  | ||||||
| 	  one of the `get_sign()` return values. |  | ||||||
| 	* `vel`: velocity as `vector` |  | ||||||
| * `boost_cart:boost_rail(pos, amount)` |  | ||||||
| 	* Sets the rail acceleration for the given position to `amount` and punches |  | ||||||
| 	  carts which are at the given position. |  | ||||||
| 	* `pos`: `vector`, rail position |  | ||||||
| 	* `amount`: `number`, negative to brake, positive to boost |  | ||||||
| * `boost_cart:get_rail_direction(pos, dir, ctrl, old_switch, railtype)` |  | ||||||
| 	-> `vector, SwitchIgnore` |  | ||||||
| 	* Returns the direction to where the next rail is, and which player control that |  | ||||||
| 	  should be ignored in the next call. |  | ||||||
| 	* `pos`: `vector`, position of the cart |  | ||||||
| 	* `dir`: `vector`, movement direction of the cart (see `velocity_to_dir()`) |  | ||||||
| 	* `ctrl`: Player controls table or `nil` (no player) |  | ||||||
| 	* `old_switch`: `SwitchIgnore` |  | ||||||
| 	* `railtype`: (optional) `number`, gets passed indirectly to `is_rail()` |  | ||||||
|  |  | ||||||
|  |  | ||||||
| Rail helper functions |  | ||||||
| --------------------- |  | ||||||
| * `boost_cart:get_rail_groups(groups)` -> `table` |  | ||||||
| 	* Returns a group table with preset values for a common rail node |  | ||||||
| 	* `groups`: (optional) `table`, additional groups append (or overwrite) |  | ||||||
| 	* Hint: To register an incompatible rail type, set the group |  | ||||||
| 	  `connect_to_raillike` to the value returned by |  | ||||||
| 	  `minetest.raillike_group(new_rail_type)` |  | ||||||
| * `boost_cart:is_rail(pos, [railtype])` -> `boolean` |  | ||||||
| 	* Returns whether the node at `pos` is a rail. When `railtype` is specified, |  | ||||||
| 	  `true` is only returned when the node is in the same rail group. |  | ||||||
| 	* `pos`: `vector` of the node to check |  | ||||||
| 	* `railtype`: (optional) `number`, rail group number |  | ||||||
| * `boost_cart:register_rail(name, def)` |  | ||||||
| 	* Registers a new rail with preset node definition defaults as fallback |  | ||||||
| 	* `name`: `string`, node name of the new rail |  | ||||||
| 	* `def`: Node definition table, containing at least the following keys: |  | ||||||
| 		* `description` |  | ||||||
| 		* `groups` |  | ||||||
| 		* `tiles` |  | ||||||
| @@ -10,18 +10,16 @@ function boost_cart:manage_attachment(player, obj) | |||||||
| 	if not player then | 	if not player then | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
| 	local wants_attach = obj ~= nil | 	local status = obj ~= nil | ||||||
| 	local attached = player:get_attach() ~= nil | 	local player_name = player:get_player_name() | ||||||
|  | 	if default.player_attached[player_name] == status then | ||||||
| 	if attached == wants_attach then |  | ||||||
| 		return | 		return | ||||||
| 	end | 	end | ||||||
|  | 	default.player_attached[player_name] = status | ||||||
|  |  | ||||||
| 	local player_name = player:get_player_name() | 	if status then | ||||||
| 	boost_cart.player_attached[player_name] = wants_attach | 		local y_pos = self.old_player_model and 6 or -4 | ||||||
|  | 		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}) | 		player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0}) | ||||||
| 	else | 	else | ||||||
| 		player:set_detach() | 		player:set_detach() | ||||||
| @@ -106,16 +104,6 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype) | |||||||
| 		right.z = -dir.x | 		right.z = -dir.x | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	local straight_priority = ctrl and dir.y ~= 0 |  | ||||||
|  |  | ||||||
| 	-- Normal, to disallow rail switching up- & downhill |  | ||||||
| 	if straight_priority then |  | ||||||
| 		cur = self:check_front_up_down(pos, dir, true, railtype) |  | ||||||
| 		if cur then |  | ||||||
| 			return cur |  | ||||||
| 		end |  | ||||||
| 	end |  | ||||||
|  |  | ||||||
| 	if ctrl then | 	if ctrl then | ||||||
| 		if old_switch == 1 then | 		if old_switch == 1 then | ||||||
| 			left_check = false | 			left_check = false | ||||||
| @@ -139,11 +127,9 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype) | |||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	-- Normal | 	-- Normal | ||||||
| 	if not straight_priority then | 	cur = self:check_front_up_down(pos, dir, true, railtype) | ||||||
| 		cur = self:check_front_up_down(pos, dir, true, railtype) | 	if cur then | ||||||
| 		if cur then | 		return cur | ||||||
| 			return cur |  | ||||||
| 		end |  | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	-- Left, if not already checked | 	-- Left, if not already checked | ||||||
| @@ -222,9 +208,6 @@ function boost_cart:boost_rail(pos, amount) | |||||||
| end | end | ||||||
|  |  | ||||||
| function boost_cart:register_rail(name, def_overwrite) | function boost_cart:register_rail(name, def_overwrite) | ||||||
| 	local sound_func = default.node_sound_metal_defaults |  | ||||||
| 		or default.node_sound_defaults |  | ||||||
|  |  | ||||||
| 	local def = { | 	local def = { | ||||||
| 		drawtype = "raillike", | 		drawtype = "raillike", | ||||||
| 		paramtype = "light", | 		paramtype = "light", | ||||||
| @@ -234,8 +217,7 @@ function boost_cart:register_rail(name, def_overwrite) | |||||||
| 		selection_box = { | 		selection_box = { | ||||||
| 			type = "fixed", | 			type = "fixed", | ||||||
| 			fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, | 			fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, | ||||||
| 		}, | 		} | ||||||
| 		sounds = sound_func() |  | ||||||
| 	} | 	} | ||||||
| 	for k, v in pairs(def_overwrite) do | 	for k, v in pairs(def_overwrite) do | ||||||
| 		def[k] = v | 		def[k] = v | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										30
									
								
								init.lua
									
									
									
									
									
								
							| @@ -1,15 +1,12 @@ | |||||||
|  |  | ||||||
| if not minetest.features.object_use_texture_alpha then |  | ||||||
| 	error("[boost_cart] Your Minetest version is no longer supported." |  | ||||||
| 		.. " (Version < 5.0.0)") |  | ||||||
| end |  | ||||||
|  |  | ||||||
| boost_cart = {} | boost_cart = {} | ||||||
| boost_cart.modpath = minetest.get_modpath("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") | if not minetest.settings then | ||||||
| boost_cart.player_attached = {} | 	error("[boost_cart] Your Minetest version is no longer supported." | ||||||
|  | 		.. " (Version <= 0.4.15)") | ||||||
|  | end | ||||||
|  |  | ||||||
| local function getNum(setting) | local function getNum(setting) | ||||||
| 	return tonumber(minetest.settings:get(setting)) | 	return tonumber(minetest.settings:get(setting)) | ||||||
| @@ -23,22 +20,27 @@ boost_cart.punch_speed_max = getNum("boost_cart.punch_speed_max") or 7 | |||||||
| boost_cart.path_distance_max = 3 | boost_cart.path_distance_max = 3 | ||||||
|  |  | ||||||
|  |  | ||||||
| if boost_cart.PLAYER_API then | -- Support for non-default games | ||||||
| 	-- This is a table reference! | if not default.player_attached then | ||||||
| 	boost_cart.player_attached = player_api.player_attached | 	default.player_attached = {} | ||||||
| end | end | ||||||
|  |  | ||||||
|  | minetest.after(1, function() | ||||||
|  | 	boost_cart.old_player_model = type(player_api) ~= "table" | ||||||
|  | end) | ||||||
|  |  | ||||||
| dofile(boost_cart.modpath.."/functions.lua") | dofile(boost_cart.modpath.."/functions.lua") | ||||||
| dofile(boost_cart.modpath.."/rails.lua") | dofile(boost_cart.modpath.."/rails.lua") | ||||||
|  |  | ||||||
| if boost_cart.MESECONS then | if minetest.global_exists("mesecon") then | ||||||
| 	dofile(boost_cart.modpath.."/detector.lua") | 	dofile(boost_cart.modpath.."/detector.lua") | ||||||
| --else | --else | ||||||
| --	minetest.register_alias("carts:powerrail", "boost_cart:detectorrail") | --	minetest.register_alias("carts:powerrail", "boost_cart:detectorrail") | ||||||
| --	minetest.register_alias("carts:powerrail", "boost_cart:detectorrail_on") | --	minetest.register_alias("carts:powerrail", "boost_cart:detectorrail_on") | ||||||
| end | end | ||||||
|  |  | ||||||
| if boost_cart.MTG_CARTS then | boost_cart.mtg_compat = minetest.global_exists("carts") and carts.pathfinder | ||||||
|  | if boost_cart.mtg_compat then | ||||||
| 	minetest.log("action", "[boost_cart] Overwriting definitions of similar carts mod") | 	minetest.log("action", "[boost_cart] Overwriting definitions of similar carts mod") | ||||||
| end | end | ||||||
| dofile(boost_cart.modpath.."/cart_entity.lua") | dofile(boost_cart.modpath.."/cart_entity.lua") | ||||||
|   | |||||||
							
								
								
									
										8
									
								
								mod.conf
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								mod.conf
									
									
									
									
									
								
							| @@ -1,7 +1 @@ | |||||||
| 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 |  | ||||||
							
								
								
									
										32
									
								
								rails.lua
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								rails.lua
									
									
									
									
									
								
							| @@ -16,21 +16,9 @@ boost_cart:register_rail(":"..regular_rail_itemname, { | |||||||
| }) | }) | ||||||
|  |  | ||||||
| -- Moreores' copper rail | -- Moreores' copper rail | ||||||
| local copperrail_registered = false |  | ||||||
| if minetest.get_modpath("moreores") then | if minetest.get_modpath("moreores") then | ||||||
| 	minetest.register_alias("carts:copperrail", "moreores:copper_rail") | 	minetest.register_alias("carts:copperrail", "moreores:copper_rail") | ||||||
|  | else | ||||||
| 	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 |  | ||||||
| 		raildef.groups.connect_to_raillike = minetest.raillike_group("rail") |  | ||||||
| 		minetest.override_item("moreores:copper_rail", { |  | ||||||
| 			groups = raildef.groups |  | ||||||
| 		}) |  | ||||||
| 		copperrail_registered = true |  | ||||||
| 	end |  | ||||||
| end |  | ||||||
| if not copperrail_registered then |  | ||||||
| 	boost_cart:register_rail(":carts:copperrail", { | 	boost_cart:register_rail(":carts:copperrail", { | ||||||
| 		description = "Copper rail", | 		description = "Copper rail", | ||||||
| 		tiles = { | 		tiles = { | ||||||
| @@ -75,6 +63,15 @@ boost_cart:register_rail(":carts:powerrail", { | |||||||
| 	}, | 	}, | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | 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"}, | ||||||
|  | 	} | ||||||
|  | }) | ||||||
|  |  | ||||||
| -- Brake rail | -- Brake rail | ||||||
| boost_cart:register_rail(":carts:brakerail", { | boost_cart:register_rail(":carts:brakerail", { | ||||||
| 	description = "Brake rail", | 	description = "Brake rail", | ||||||
| @@ -100,6 +97,15 @@ boost_cart:register_rail(":carts:brakerail", { | |||||||
| 	}, | 	}, | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | 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"}, | ||||||
|  | 	} | ||||||
|  | }) | ||||||
|  |  | ||||||
| boost_cart:register_rail("boost_cart:startstoprail", { | boost_cart:register_rail("boost_cart:startstoprail", { | ||||||
| 	description = "Start-stop rail", | 	description = "Start-stop rail", | ||||||
| 	tiles = { | 	tiles = { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user