dofile_once("data/scripts/lib/utilities.lua")
dofile( "mods/spellbound_bundle/files/scripts/utils.lua" )
local brush_entity = GetUpdatedEntityID()

local brush_radius = EntityGetVariable(brush_entity, "brush_radius", "int") or 5
local brush_capacity = EntityGetVariable(brush_entity, "brush_capacity", "int") or 2000

for x = -brush_radius / 2, brush_radius / 2, 0.5 do
	if x % 1 ~= 0 then
		for y = -brush_radius / 2, brush_radius / 2, 0.5 do
			if y % 1 ~= 0 then
				local distance = math.sqrt(x*x + y*y)
				if distance <= (brush_radius / 2) - 0.4 then
					local comp = EntityAddComponent2(brush_entity, "ParticleEmitterComponent", {
						_enabled=false,
						count_max=1,
						count_min=1,
						emission_interval_max_frames=0,
						emission_interval_min_frames=0,
						emit_cosmetic_particles=false,
						create_real_particles=true,
						is_emitting=true,
						use_material_inventory=true,
						set_magic_creation=true,
					})

					EntitySetComponentIsEnabled(brush_entity, comp, false)
					
					ComponentSetValue2(comp, "offset", x, y)
				end
				
			end
		end
	end
end

local material_suckers = EntityGetComponentIncludingDisabled(brush_entity, "MaterialSuckerComponent")
for i,v in ipairs(material_suckers) do
	ComponentSetValue(v, "barrel_size", brush_capacity)
	--ComponentSetValue2(v, "randomized_position", -(brush_radius / 2), (brush_radius / 2), -(brush_radius / 2), (brush_radius / 2))	
	EntitySetComponentIsEnabled(brush_entity, v, false)
end

local material_inventory = EntityGetFirstComponentIncludingDisabled(brush_entity, "MaterialInventoryComponent")
if material_inventory ~= nil then
	ComponentSetValue(material_inventory, "max_capacity", brush_capacity)
end