-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnableCrateItemProviderSystem.cs
46 lines (42 loc) · 1.49 KB
/
EnableCrateItemProviderSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Kitchen;
using KitchenMods;
using Unity.Collections;
using Unity.Entities;
namespace KitchenOverstocked
{
class EnableCrateItemProviderSystem : FranchiseSystem, IModSystem
{
private EntityQuery crateShelvesWithoutCrateProvider;
protected override void Initialise()
{
base.Initialise();
crateShelvesWithoutCrateProvider = GetEntityQuery(
new QueryHelper()
.All(typeof(CPersistentItemStorageLocation), typeof(CItemHolder))
.None(typeof(CCrateItemProvider))
);
RequireForUpdate(crateShelvesWithoutCrateProvider);
}
protected override void OnUpdate()
{
if (Mod.AutoRestock)
{
using var garageShelves = crateShelvesWithoutCrateProvider.ToEntityArray(
Allocator.Temp
);
foreach (var garageShelve in garageShelves)
{
if (
Require(garageShelve, out CItemHolder itemHolder)
&& itemHolder.HeldItem != default(Entity)
&& Require(itemHolder.HeldItem, out CUpgrade crate)
)
{
Mod.LogInfo("Setting crate provider to be " + crate.ID);
Set(garageShelve, new CCrateItemProvider { applianceId = crate.ID });
}
}
}
}
}
}