forked from minetest-mods/item_drop
		
	Merge remote-tracking branch 'upstream/master' into nalc-1.2-dev
This commit is contained in:
		
							
								
								
									
										11
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
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
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								.luacheckrc
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
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,15 +1,14 @@
 | 
			
		||||
# item_drop
 | 
			
		||||
# Item Drop [](https://github.com/minetest-mods/item_drop/actions) [](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html)
 | 
			
		||||
 | 
			
		||||
A highly configurable mod providing item magnet and in-world node drops\
 | 
			
		||||
By [PilzAdam](https://github.com/PilzAdam),
 | 
			
		||||
[texmex](https://github.com/tacotexmex/), [hybriddog](https://github.com/hybriddog/).
 | 
			
		||||
 | 
			
		||||
## Description
 | 
			
		||||
A highly configurable mod providing item magnet and in-world node drops
 | 
			
		||||
 | 
			
		||||
## Licensing
 | 
			
		||||
LGPLv2.1/CC BY-SA 3.0. Particle code from WCILA mod by Aurailus, originally licensed MIT.
 | 
			
		||||
 | 
			
		||||
## 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).
 | 
			
		||||
 | 
			
		||||
## List of features
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										47
									
								
								init.lua
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								init.lua
									
									
									
									
									
								
							@@ -103,7 +103,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
 | 
			
		||||
		if pickup_particle then
 | 
			
		||||
			local item = minetest.registered_nodes[
 | 
			
		||||
				ent.itemstring:gsub("(.*)%s.*$", "%1")]
 | 
			
		||||
			local image = ""
 | 
			
		||||
			local image
 | 
			
		||||
			if item and item.tiles and item.tiles[1] then
 | 
			
		||||
				if inventorycube_drawtypes[item.drawtype] then
 | 
			
		||||
					local tiles = item.tiles
 | 
			
		||||
@@ -201,9 +201,9 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
 | 
			
		||||
			local itemdef = minetest.registered_entities["__builtin:item"]
 | 
			
		||||
			local old_on_step = itemdef.on_step
 | 
			
		||||
			local function do_nothing() end
 | 
			
		||||
			function itemdef.on_step(self, dtime)
 | 
			
		||||
			function itemdef.on_step(self, ...)
 | 
			
		||||
				if not self.is_magnet_item then
 | 
			
		||||
					return old_on_step(self, dtime)
 | 
			
		||||
					return old_on_step(self, ...)
 | 
			
		||||
				end
 | 
			
		||||
				ObjectRef = ObjectRef or getmetatable(self.object)
 | 
			
		||||
				local old_funcs = {}
 | 
			
		||||
@@ -212,7 +212,7 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
 | 
			
		||||
					old_funcs[method] = ObjectRef[method]
 | 
			
		||||
					ObjectRef[method] = do_nothing
 | 
			
		||||
				end
 | 
			
		||||
				old_on_step(self, dtime)
 | 
			
		||||
				old_on_step(self, ...)
 | 
			
		||||
				for i = 1, #blocked_methods do
 | 
			
		||||
					local method = blocked_methods[i]
 | 
			
		||||
					ObjectRef[method] = old_funcs[method]
 | 
			
		||||
@@ -252,6 +252,13 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
 | 
			
		||||
		return keys_pressed ~= key_invert
 | 
			
		||||
	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
 | 
			
		||||
	local function pickupfunc(player)
 | 
			
		||||
		if not has_keys_pressed(player)
 | 
			
		||||
@@ -261,8 +268,12 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		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
 | 
			
		||||
		local inv
 | 
			
		||||
		local inv = player:get_inventory()
 | 
			
		||||
 | 
			
		||||
		local objectlist = minetest.get_objects_inside_radius(pos,
 | 
			
		||||
			magnet_mode and magnet_radius or pickup_radius)
 | 
			
		||||
@@ -271,14 +282,6 @@ if legacy_setting_getbool("item_drop.enable_item_pickup",
 | 
			
		||||
			local ent = opt_get_ent(object)
 | 
			
		||||
			if ent
 | 
			
		||||
			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)
 | 
			
		||||
				if inv:room_for_item("main", item) then
 | 
			
		||||
					local flying_item
 | 
			
		||||
@@ -409,8 +412,24 @@ and not minetest.settings:get_bool("creative_mode") then
 | 
			
		||||
			end
 | 
			
		||||
		end
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
	local function pickup_step()
 | 
			
		||||
		local got_item
 | 
			
		||||
		local players = minetest.get_connected_players()
 | 
			
		||||
		for i = 1,#players do
 | 
			
		||||
			got_item = got_item or pickupfunc(players[i])
 | 
			
		||||
		end
 | 
			
		||||
		-- lower step if takeable item(s) were found
 | 
			
		||||
		local time
 | 
			
		||||
		if got_item then
 | 
			
		||||
			time = 0.02
 | 
			
		||||
		else
 | 
			
		||||
			time = 0.2
 | 
			
		||||
		end
 | 
			
		||||
		minetest.after(time, pickup_step)
 | 
			
		||||
	end
 | 
			
		||||
	minetest.after(3.0, pickup_step)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local time = (minetest.get_us_time() - load_time_start) / 1000000
 | 
			
		||||
local msg = "[item_drop] loaded after ca. " .. time .. " seconds."
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user