-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoneRemover.cs
87 lines (85 loc) · 2.2 KB
/
StoneRemover.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using Sandbox.Game;
using Sandbox.Game.Entities;
using Sandbox.Game.World;
using Sandbox.ModAPI;
using VRage;
using VRage.Game;
using VRage.Game.Entity;
namespace AutoRemoveStone
{
public static class StoneRemover
{
public static void EnableMode(Mode voidMode = Mode.Off)
{
if (!Enabled && voidMode != Mode.Off)
{
VoidMode = voidMode;
Enabled = true;
MySession.Static.AddUpdateCallback(new MyUpdateCallback(new Func<bool>(Update)));
return;
}
Enabled = false;
VoidMode = Mode.Off;
}
public static bool Update()
{
if (!Enabled)
{
VoidMode = Mode.Off;
Counter = 0;
return true;
}
if (Counter > 0)
{
Counter--;
return false;
}
Counter = 300;
if (MySession.Static.ControlledEntity is MyCubeBlock)
{
HashSet<MyCubeBlock> inventories = (MySession.Static.ControlledEntity as MyCubeBlock).CubeGrid.Inventories;
for (int i = 0; i < inventories.Count; i++)
{
MyInventory inventory = inventories.ElementAt(i).GetInventory(0);
List<MyPhysicalInventoryItem> items = inventory.GetItems();
if (items.Count != 0)
{
for (int j = 0; j < items.Count; j++)
{
if (VoidMode == Mode.Stone || VoidMode == Mode.Both)
{
if (items[j].Content.TypeId.ToString().Contains("Ore") && items[j].Content.SubtypeName.Contains("Stone"))
{
inventory.RemoveItemsAt(inventory.GetItemIndexById(items[j].ItemId), new MyFixedPoint?(items[j].Amount), true, false, null);
}
}
if (VoidMode == Mode.Ice || VoidMode == Mode.Both)
{
if (items[j].Content.TypeId.ToString().Contains("Ore") && items[j].Content.SubtypeName.Contains("Ice"))
{
inventory.RemoveItemsAt(inventory.GetItemIndexById(items[j].ItemId), new MyFixedPoint?(items[j].Amount), true, false, null);
}
}
}
}
}
return false;
}
Enabled = false;
return true;
}
public static bool Enabled = false;
public static Mode VoidMode { get; private set; } = Mode.Off;
public static int Counter { get; private set; } = 0;
public enum Mode
{
Off,
Stone,
Ice,
Both
};
}
}