minetest.register_on_joinplayer(function(player)
   local name = player:get_player_name()
   --Minetest doesn't allow for easily changing player inventories shown in the hotbar.
   --To counter this the inventory is swapped between 'main' and 'builder' depending on player mode.
   player:get_inventory():set_size('main', 32)
   player:get_inventory():set_size('builder', 32)
   player:get_inventory():set_size('clothing', 24)
   local clothing = minetest.create_detached_inventory(name..'_clothing', {
      on_put = function(inv, listname, index, stack, player)
         gamer.get_clothes(player)
      end,
      on_take = function(inv, listname, index, stack, player)
         gamer.get_clothes(player)
      end,
      on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
         gamer.get_clothes(player)
      end,
      allow_put = function(inv, listname, index, put_stack, player)
         local clothes = put_stack:get_name()
         if minetest.get_item_group(clothes, 'clothing') > 0 then
            return 1
         else
            return 0
         end
      end
   })
   clothing:set_size('slots', 18)
   gamer.player_attached[player:get_player_name()] = false
   gamer.player_set_model(player, 'gamer_model.b3d')
   player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30)
   player:hud_set_hotbar_image("gui_hotbar.png")
   player:hud_set_hotbar_selected_image("gui_hotbar_selected.png")
   player:set_formspec_prepend('bgcolor[#222222;false]')
   gamer.retrieve_clothes(player)
   gamer.get_clothes(player)
   if player.get_lighting then
      local light = player:get_lighting()
      light.shadows.intensity = 0.5
      player:set_lighting(light)
   end
end)
