mirror of
				https://github.com/minetest-mods/item_drop.git
				synced 2025-11-01 00:15:27 +01:00 
			
		
		
		
	Compare commits
	
		
			90 Commits
		
	
	
		
			master
			...
			c6a80bd4fa
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c6a80bd4fa | |||
|  | fadfbf7e05 | ||
|  | 5611b4d639 | ||
|  | 26d0532cbd | ||
|  | becdfd113a | ||
|  | 934ebff45a | ||
|  | 5069afa834 | ||
|  | 70b3386322 | ||
|  | 1e9e73e978 | ||
|  | f7d62113ff | ||
|  | 3a9a506011 | ||
|  | 427117d786 | ||
| c1637b1975 | |||
| e10486d2aa | |||
|  | 532a3cb0d0 | ||
|  | 56d2eeda5c | ||
|  | c52ff0ea55 | ||
|  | 8e89c148be | ||
|  | 726b5f4872 | ||
|  | 8e1878d101 | ||
|  | f6b8bcd7a7 | ||
|  | 6b7ed8e7ca | ||
|  | 2730deca16 | ||
|  | fc89b2d2b4 | ||
|  | f5187108f1 | ||
|  | 902daba7cf | ||
|  | 3c9c0e34e3 | ||
|  | eaa44e2a36 | ||
|  | a69bdd2275 | ||
|  | 1b0bc8461c | ||
|  | b42a64cfa4 | ||
|  | d51b468428 | ||
|  | 293fd77614 | ||
|  | 3e6a731cab | ||
|  | 760acbc593 | ||
|  | d282d1ab0c | ||
|  | 8e6b386fe3 | ||
|  | 31bdc51b42 | ||
|  | c688119069 | ||
|  | 376439b214 | ||
|  | 49b7bb19ef | ||
|  | 4c66b76937 | ||
|  | 29df36b2af | ||
|  | 2aff58ee02 | ||
|  | 92d68aa48a | ||
|  | 7afe3723e4 | ||
|  | 69f0c08561 | ||
|  | 6f8a37bd10 | ||
|  | 19ad20305f | ||
|  | e7b8d02922 | ||
|  | 0f903cd0b0 | ||
|  | bf9931d6db | ||
|  | 739a62a6c6 | ||
|  | 271a577881 | ||
|  | 729397b6c9 | ||
|  | 4912d3c828 | ||
|  | 057966141a | ||
|  | 78ef2a50f6 | ||
|  | c4365cd4de | ||
|  | bf0bb807fb | ||
|  | 22763d3b06 | ||
|  | 169d83840f | ||
|  | da2fb1df20 | ||
|  | 3bc3a4bd25 | ||
|  | 55e89d3710 | ||
|  | 4b5e362395 | ||
|  | bc5ef09e21 | ||
|  | bab3c733fa | ||
|  | 69a68cb247 | ||
|  | b56c1792de | ||
|  | 544381bbfe | ||
|  | 9f54694931 | ||
|  | fb2c076b92 | ||
|  | 46959e79d2 | ||
|  | e84433d41c | ||
|  | 884824989f | ||
|  | 962d0a3889 | ||
|  | 81d32527f3 | ||
|  | 8a14503372 | ||
|  | a7b7c71d50 | ||
|  | 5a6f79a5d2 | ||
|  | 363b56fc03 | ||
|  | 189fea5eff | ||
|  | 1f9ceb3eb3 | ||
|  | 6befa68ef8 | ||
|  | d336a226cd | ||
|  | 16210c79f7 | ||
|  | 2c60ac7ab0 | ||
|  | a666252f1c | ||
|  | d9581ec795 | 
							
								
								
									
										11
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							| @@ -1,11 +0,0 @@ | |||||||
| on: [push, pull_request] |  | ||||||
| name: build |  | ||||||
| jobs: |  | ||||||
|   lint: |  | ||||||
|     runs-on: ubuntu-latest |  | ||||||
|     steps: |  | ||||||
|       - uses: actions/checkout@master |  | ||||||
|       - name: lint |  | ||||||
|         uses: Roang-zero1/factorio-mod-luacheck@master |  | ||||||
|         with: |  | ||||||
|           luacheckrc_url: https://raw.githubusercontent.com/minetest-mods/item_drop/master/.luacheckrc |  | ||||||
							
								
								
									
										19
									
								
								.luacheckrc
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								.luacheckrc
									
									
									
									
									
								
							| @@ -1,19 +0,0 @@ | |||||||
| unused_args = false |  | ||||||
| allow_defined_top = true |  | ||||||
| max_line_length = 999 |  | ||||||
|  |  | ||||||
| ignore = { |  | ||||||
|     "name", "drops", "i", |  | ||||||
| } |  | ||||||
|  |  | ||||||
| globals = { |  | ||||||
|     "minetest", |  | ||||||
| } |  | ||||||
|  |  | ||||||
| read_globals = { |  | ||||||
|     string = {fields = {"split", "trim"}}, |  | ||||||
|     table = {fields = {"copy", "getn"}}, |  | ||||||
|  |  | ||||||
|     "vector", "ItemStack", |  | ||||||
|     "dump", |  | ||||||
| } |  | ||||||
| @@ -1,14 +1,15 @@ | |||||||
| # Item Drop [](https://github.com/minetest-mods/item_drop/actions) [](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html) | # item_drop | ||||||
|  |  | ||||||
| A highly configurable mod providing item magnet and in-world node drops\ |  | ||||||
| By [PilzAdam](https://github.com/PilzAdam), | By [PilzAdam](https://github.com/PilzAdam), | ||||||
| [texmex](https://github.com/tacotexmex/), [hybriddog](https://github.com/hybriddog/). | [texmex](https://github.com/tacotexmex/), [hybriddog](https://github.com/hybriddog/). | ||||||
|  |  | ||||||
|  | ## Description | ||||||
|  | A highly configurable mod providing item magnet and in-world node drops | ||||||
|  |  | ||||||
| ## Licensing | ## Licensing | ||||||
| LGPLv2.1/CC BY-SA 3.0. Particle code from WCILA mod by Aurailus, originally licensed MIT. | LGPLv2.1/CC BY-SA 3.0. Particle code from WCILA mod by Aurailus, originally licensed MIT. | ||||||
|  |  | ||||||
| ## Notes | ## Notes | ||||||
| `item_drop` can be played with Minetest 0.4.16 or above. It was originally | item_drop can be played with Minetest 0.4.16 or above. It was originally | ||||||
| developed by [PilzAdam](https://github.com/PilzAdam/item_drop). | developed by [PilzAdam](https://github.com/PilzAdam/item_drop). | ||||||
|  |  | ||||||
| ## List of features | ## List of features | ||||||
|   | |||||||
							
								
								
									
										75
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										75
									
								
								init.lua
									
									
									
									
									
								
							| @@ -93,46 +93,34 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", | |||||||
| 		flowingliquid = true, | 		flowingliquid = true, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	-- Get an image string from a tile definition |  | ||||||
| 	local function tile_to_image(tile, fallback_image) |  | ||||||
| 		if not tile then |  | ||||||
| 			return fallback_image |  | ||||||
| 		end |  | ||||||
| 		local tile_type = type(tile) |  | ||||||
| 		if tile_type == "string" then |  | ||||||
| 			return tile |  | ||||||
| 		end |  | ||||||
| 		assert(tile_type == "table", "Tile definition is not a string or table") |  | ||||||
| 		local image = tile.name or tile.image |  | ||||||
| 		assert(image, "Tile definition has no image file specified") |  | ||||||
| 		if tile.color then |  | ||||||
| 			local colorstr = minetest.colorspec_to_colorstring(tile.color) |  | ||||||
| 			if colorstr then |  | ||||||
| 				return image .. "^[multiply:" .. colorstr |  | ||||||
| 			end |  | ||||||
| 		end |  | ||||||
| 		return image |  | ||||||
| 	end |  | ||||||
|  |  | ||||||
| 	-- adds the item to the inventory and removes the object | 	-- adds the item to the inventory and removes the object | ||||||
| 	local function collect_item(ent, pos, player) | 	local function collect_item(ent, pos, player) | ||||||
| 		item_drop.before_collect(ent, pos, player) | 		item_drop.before_collect(ent, pos, player) | ||||||
| 		minetest.sound_play("item_drop_pickup", { | 		minetest.sound_play("item_drop_pickup", { | ||||||
| 			pos = pos, | 			pos = pos, | ||||||
| 			gain = pickup_gain, | 			gain = pickup_gain, | ||||||
| 		}, true) | 		}) | ||||||
| 		if pickup_particle then | 		if pickup_particle then | ||||||
| 			local item = minetest.registered_nodes[ | 			local item = minetest.registered_nodes[ | ||||||
| 				ent.itemstring:gsub("(.*)%s.*$", "%1")] | 				ent.itemstring:gsub("(.*)%s.*$", "%1")] | ||||||
| 			local image | 			local image = "" | ||||||
| 			if item and item.tiles and item.tiles[1] then | 			if item and item.tiles and item.tiles[1] then | ||||||
| 				if inventorycube_drawtypes[item.drawtype] then | 				if inventorycube_drawtypes[item.drawtype] then | ||||||
| 					local tiles = item.tiles | 					local tiles = item.tiles | ||||||
| 					-- color in the tile definition is handled by tile_to_image. |  | ||||||
| 					-- color in the node definition is not yet supported here. | 					local top = tiles[1] | ||||||
| 					local top = tile_to_image(tiles[1]) | 					if type(top) == "table" then | ||||||
| 					local left = tile_to_image(tiles[3], top) | 						top = top.name | ||||||
| 					local right = tile_to_image(tiles[5], left) | 					end | ||||||
|  | 					local left = tiles[3] or top | ||||||
|  | 					if type(left) == "table" then | ||||||
|  | 						left = left.name | ||||||
|  | 					end | ||||||
|  | 					local right = tiles[5] or left | ||||||
|  | 					if type(right) == "table" then | ||||||
|  | 						right = right.name | ||||||
|  | 					end | ||||||
|  |  | ||||||
| 					image = minetest.inventorycube(top, left, right) | 					image = minetest.inventorycube(top, left, right) | ||||||
| 				else | 				else | ||||||
| 					image = item.inventory_image or item.tiles[1] | 					image = item.inventory_image or item.tiles[1] | ||||||
| @@ -213,9 +201,9 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", | |||||||
| 			local itemdef = minetest.registered_entities["__builtin:item"] | 			local itemdef = minetest.registered_entities["__builtin:item"] | ||||||
| 			local old_on_step = itemdef.on_step | 			local old_on_step = itemdef.on_step | ||||||
| 			local function do_nothing() end | 			local function do_nothing() end | ||||||
| 			function itemdef.on_step(self, ...) | 			function itemdef.on_step(self, dtime) | ||||||
| 				if not self.is_magnet_item then | 				if not self.is_magnet_item then | ||||||
| 					return old_on_step(self, ...) | 					return old_on_step(self, dtime) | ||||||
| 				end | 				end | ||||||
| 				ObjectRef = ObjectRef or getmetatable(self.object) | 				ObjectRef = ObjectRef or getmetatable(self.object) | ||||||
| 				local old_funcs = {} | 				local old_funcs = {} | ||||||
| @@ -224,7 +212,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", | |||||||
| 					old_funcs[method] = ObjectRef[method] | 					old_funcs[method] = ObjectRef[method] | ||||||
| 					ObjectRef[method] = do_nothing | 					ObjectRef[method] = do_nothing | ||||||
| 				end | 				end | ||||||
| 				old_on_step(self, ...) | 				old_on_step(self, dtime) | ||||||
| 				for i = 1, #blocked_methods do | 				for i = 1, #blocked_methods do | ||||||
| 					local method = blocked_methods[i] | 					local method = blocked_methods[i] | ||||||
| 					ObjectRef[method] = old_funcs[method] | 					ObjectRef[method] = old_funcs[method] | ||||||
| @@ -264,13 +252,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", | |||||||
| 		return keys_pressed ~= key_invert | 		return keys_pressed ~= key_invert | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	local function is_inside_map(pos) |  | ||||||
| 		local bound = 31000 |  | ||||||
| 		return -bound < pos.x and pos.x < bound |  | ||||||
| 			and -bound < pos.y and pos.y < bound |  | ||||||
| 			and -bound < pos.z and pos.z < bound |  | ||||||
| 	end |  | ||||||
|  |  | ||||||
| 	-- called for each player to possibly collect an item, returns true if so | 	-- called for each player to possibly collect an item, returns true if so | ||||||
| 	local function pickupfunc(player) | 	local function pickupfunc(player) | ||||||
| 		if not has_keys_pressed(player) | 		if not has_keys_pressed(player) | ||||||
| @@ -280,12 +261,8 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", | |||||||
| 		end | 		end | ||||||
|  |  | ||||||
| 		local pos = player:get_pos() | 		local pos = player:get_pos() | ||||||
| 		if not is_inside_map(pos) then |  | ||||||
| 			-- get_objects_inside_radius crashes for too far positions |  | ||||||
| 			return |  | ||||||
| 		end |  | ||||||
| 		pos.y = pos.y+0.5 | 		pos.y = pos.y+0.5 | ||||||
| 		local inv = player:get_inventory() | 		local inv | ||||||
|  |  | ||||||
| 		local objectlist = minetest.get_objects_inside_radius(pos, | 		local objectlist = minetest.get_objects_inside_radius(pos, | ||||||
| 			magnet_mode and magnet_radius or pickup_radius) | 			magnet_mode and magnet_radius or pickup_radius) | ||||||
| @@ -294,6 +271,14 @@ if legacy_setting_getbool("item_drop.enable_item_pickup", | |||||||
| 			local ent = opt_get_ent(object) | 			local ent = opt_get_ent(object) | ||||||
| 			if ent | 			if ent | ||||||
| 			and item_drop.can_pickup(ent, player) then | 			and item_drop.can_pickup(ent, player) then | ||||||
|  | 				if not inv then | ||||||
|  | 					inv = player:get_inventory() | ||||||
|  | 					if not inv then | ||||||
|  | 						minetest.log("error", "[item_drop] Couldn't " .. | ||||||
|  | 							"get inventory") | ||||||
|  | 						return | ||||||
|  | 					end | ||||||
|  | 				end | ||||||
| 				local item = ItemStack(ent.itemstring) | 				local item = ItemStack(ent.itemstring) | ||||||
| 				if inv:room_for_item("main", item) then | 				if inv:room_for_item("main", item) then | ||||||
| 					local flying_item | 					local flying_item | ||||||
| @@ -390,7 +375,7 @@ and not minetest.settings:get_bool("creative_mode") then | |||||||
|  |  | ||||||
| 	local old_handle_node_drops = minetest.handle_node_drops | 	local old_handle_node_drops = minetest.handle_node_drops | ||||||
| 	function minetest.handle_node_drops(pos, drops, player) | 	function minetest.handle_node_drops(pos, drops, player) | ||||||
| 		if not player or player.is_fake_player then | 		if player.is_fake_player then | ||||||
| 			-- Node Breaker or similar machines should receive items in the | 			-- Node Breaker or similar machines should receive items in the | ||||||
| 			-- inventory | 			-- inventory | ||||||
| 			return old_handle_node_drops(pos, drops, player) | 			return old_handle_node_drops(pos, drops, player) | ||||||
| @@ -432,5 +417,5 @@ local msg = "[item_drop] loaded after ca. " .. time .. " seconds." | |||||||
| if time > 0.01 then | if time > 0.01 then | ||||||
| 	print(msg) | 	print(msg) | ||||||
| else | else | ||||||
| 	minetest.log("info", msg) | 	minetest.log("action", msg) | ||||||
| end | end | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user