diff options
Diffstat (limited to 'lua')
| -rwxr-xr-x | lua/api.lua | 37 | ||||
| -rwxr-xr-x | lua/helpers.lua | 30 | ||||
| -rwxr-xr-x | lua/visual.lua | 26 | 
3 files changed, 83 insertions, 10 deletions
| diff --git a/lua/api.lua b/lua/api.lua index ba0550c..6c9df78 100755 --- a/lua/api.lua +++ b/lua/api.lua @@ -68,6 +68,11 @@ end  -- destruct drawer  function drawers.drawer_on_destruct(pos)  	drawers.remove_visuals(pos) + +	-- clean up visual cache +	if drawers.drawer_visuals[core.serialize(pos)] then +		drawers.drawer_visuals[core.serialize(pos)] = nil +	end  end  -- drop all items @@ -157,28 +162,56 @@ function drawers.register_drawer(name, def)  	def1.description = def.description .. " Drawer"  	def1.tiles = def.tiles or def.tiles1  	def1.tiles1 = nil +	def1.tiles2 = nil  	def1.tiles4 = nil  	def1.groups.drawer = 1  	core.register_node(name .. "1", def1)  	core.register_alias(name, name .. "1") -- 1x1 drawer is the default one +	-- 1x2 = 2 +	def2 = table.copy(def) +	def2.description = def.description .. " Drawers (1x2)" +	def2.tiles = def.tiles2 +	def2.tiles1 = nil +	def2.tiles2 = nil +	def2.tiles4 = nil +	def2.groups.drawer = 2 +	core.register_node(name .. "2", def2) +  	-- 2x2 = 4  	def4 = table.copy(def)  	def4.description = def.description .. " Drawers (2x2)"  	def4.tiles = def.tiles4  	def4.tiles1 = nil +	def4.tiles2 = nil  	def4.tiles4 = nil  	def4.groups.drawer = 4  	core.register_node(name .. "4", def4)  	if (not def.no_craft) and def.material then  		core.register_craft({ -			output = name, +			output = name .. "1",  			recipe = {  				{def.material, def.material, def.material}, -				{"", drawers.CHEST_ITEMSTRING, ""}, +				{    "", drawers.CHEST_ITEMSTRING,  ""   },  				{def.material, def.material, def.material}  			}  		}) +		core.register_craft({ +			output = name .. "2 2", +			recipe = { +				{def.material, drawers.CHEST_ITEMSTRING, def.material}, +				{def.material,       def.material,       def.material}, +				{def.material, drawers.CHEST_ITEMSTRING, def.material} +			} +		}) +		core.register_craft({ +			output = name .. "4 4", +			recipe = { +				{drawers.CHEST_ITEMSTRING, def.material, drawers.CHEST_ITEMSTRING}, +				{      def.material,       def.material,       def.material      }, +				{drawers.CHEST_ITEMSTRING, def.material, drawers.CHEST_ITEMSTRING} +			} +		})  	end  end diff --git a/lua/helpers.lua b/lua/helpers.lua index 374cd95..b94b0a8 100755 --- a/lua/helpers.lua +++ b/lua/helpers.lua @@ -90,6 +90,36 @@ function drawers.spawn_visuals(pos)  		if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end  		drawers.last_texture = nil +	elseif drawerType == 2 then +		local bdir = core.facedir_to_dir(node.param2) + +		local fdir1 +		local fdir2 +		if node.param2 == 2 or node.param2 == 0 then +			fdir1 = vector.new(-bdir.x, 0.5, -bdir.z) +			fdir2 = vector.new(-bdir.x, -0.5, -bdir.z) +		else +			fdir1 = vector.new(-bdir.x, 0.5, -bdir.z) +			fdir2 = vector.new(-bdir.x, -0.5, -bdir.z) +		end + +		objs = {} + +		drawers.last_visual_id = 1 +		drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name1")) +		local pos1 = vector.add(pos, vector.multiply(fdir1, 0.438)) +		objs[1] = core.add_entity(pos1, "drawers:visual") + +		drawers.last_visual_id = 2 +		drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name2")) +		local pos2 = vector.add(pos, vector.multiply(fdir2, 0.438)) +		objs[2] = core.add_entity(pos2, "drawers:visual") + +		for i,obj in pairs(objs) do +			if bdir.x < 0 then obj:setyaw(0.5 * math.pi) end +			if bdir.z < 0 then obj:setyaw(math.pi) end +			if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end +		end  	else -- 2x2 drawer  		local bdir = core.facedir_to_dir(node.param2) diff --git a/lua/visual.lua b/lua/visual.lua index e85bd53..43eb81f 100755 --- a/lua/visual.lua +++ b/lua/visual.lua @@ -85,14 +85,24 @@ core.register_entity("drawers:visual", {  		local node = core.get_node(self.drawer_pos)  		-- collisionbox -		local colbox = {-0.4374, -0.4374, 0,  0.4374, 0.4374, 0} -- for param2 = 0 or 2 -		if node.param2 == 1 or node.param2 == 3 then -			colbox = {0, -0.4374, -0.4374,  0, 0.4374, 0.4374} -		end -		-- only half the size if it's a small drawer -		if self.drawerType >= 2 then -			for i,j in pairs(colbox) do -				colbox[i] = j * 0.5 +		local colbox +		if self.drawerType ~= 2 then +			if node.param2 == 1 or node.param2 == 3 then +				colbox = {0, -0.4374, -0.4374,  0, 0.4374, 0.4374} +			else +				colbox = {-0.4374, -0.4374, 0,  0.4374, 0.4374, 0} -- for param2 = 0 or 2 +			end +			-- only half the size if it's a small drawer +			if self.drawerType > 1 then +				for i,j in pairs(colbox) do +					colbox[i] = j * 0.5 +				end +			end +		else +			if node.param2 == 1 or node.param2 == 3 then +				colbox = {0, -0.2187, -0.4374,  0, 0.2187, 0.4374} +			else +				colbox = {-0.4374, -0.2187, 0,  0.4374, 0.2187, 0} -- for param2 = 0 or 2  			end  		end | 
