This repository was archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 889
Expand file tree
/
Copy pathMyInventory_ModAPI.cs
More file actions
202 lines (174 loc) · 7.15 KB
/
Copy pathMyInventory_ModAPI.cs
File metadata and controls
202 lines (174 loc) · 7.15 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using Sandbox.Common.ObjectBuilders;
using Sandbox.Game.GameSystems;
using Sandbox.Game.GameSystems.Conveyors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VRage.Game;
using VRage.Game.Entity;
using VRage.ModAPI;
using VRage.Game.ModAPI.Ingame;
using VRage.ObjectBuilders;
namespace Sandbox.Game
{
partial class MyInventory : IMyInventory, VRage.Game.ModAPI.IMyInventory
{
bool IMyInventory.IsFull
{
get { return IsFull;}
}
VRageMath.Vector3 IMyInventory.Size
{
get { return VRageMath.Vector3.MaxValue; }
}
bool VRage.Game.ModAPI.IMyInventory.Empty()
{
return Empty();
}
void VRage.Game.ModAPI.IMyInventory.Clear(bool sync)
{
Clear(sync);
}
bool IMyInventory.IsItemAt(int position)
{
return IsItemAt(position);
}
bool IMyInventory.CanItemsBeAdded(VRage.MyFixedPoint amount, SerializableDefinitionId contentId)
{
return CanItemsBeAdded(amount, contentId);
}
bool IMyInventory.ContainItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject ob)
{
return ContainItems(amount, ob);
}
void VRage.Game.ModAPI.IMyInventory.AddItems(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, int index)
{
AddItems(amount, objectBuilder, null, index);
}
VRage.MyFixedPoint IMyInventory.GetItemAmount(SerializableDefinitionId contentId, MyItemFlags flags)
{
return GetItemAmount(contentId,flags);
}
void VRage.Game.ModAPI.IMyInventory.RemoveItemsOfType(VRage.MyFixedPoint amount, MyObjectBuilder_PhysicalObject objectBuilder, bool spawn)
{
RemoveItemsOfType(amount, objectBuilder, spawn);
}
void VRage.Game.ModAPI.IMyInventory.RemoveItemsOfType(VRage.MyFixedPoint amount, SerializableDefinitionId contentId, MyItemFlags flags, bool spawn)
{
RemoveItemsOfType(amount, contentId, flags, spawn);
}
void VRage.Game.ModAPI.IMyInventory.RemoveItemsAt(int itemIndex, VRage.MyFixedPoint? amount, bool sendEvent, bool spawn)
{
RemoveItemsAt(itemIndex, amount, sendEvent, spawn);
}
void VRage.Game.ModAPI.IMyInventory.RemoveItems(uint itemId, VRage.MyFixedPoint? amount, bool sendEvent, bool spawn)
{
RemoveItems(itemId, amount, sendEvent, spawn);
}
bool IMyInventory.TransferItemTo(IMyInventory dst, int sourceItemIndex, int? targetItemIndex, bool? stackIfPossible, VRage.MyFixedPoint? amount)
{
return TransferItemsTo(dst, sourceItemIndex, targetItemIndex, amount,true);
}
private bool TransferItemsTo(IMyInventory dst, int sourceItemIndex, int? targetItemIndex, VRage.MyFixedPoint? amount,bool useConveyor)
{
MyInventory dstInventory = dst as MyInventory;
if (dstInventory != null)
{
if (sourceItemIndex < 0 || sourceItemIndex >= this.m_items.Count || (useConveyor == true && IsConnected(dstInventory) == false))
{
return false;
}
Transfer(this as MyInventory, dstInventory, this.GetItems()[sourceItemIndex].ItemId, targetItemIndex.HasValue ? targetItemIndex.Value : -1, amount);
return true;
}
return false;
}
private bool IsConnected(MyInventory dstInventory)
{
var srcConveyor = (this.Owner as IMyConveyorEndpointBlock);
if (srcConveyor != null)
{
var reachableVertices = new List<IMyConveyorEndpoint>();
MyGridConveyorSystem.FindReachable(srcConveyor.ConveyorEndpoint, reachableVertices, (vertex) => vertex.CubeBlock != null);
foreach (var vertex in reachableVertices)
{
if (dstInventory.Owner == vertex.CubeBlock)
{
return true;
}
}
}
return false;
}
bool IMyInventory.TransferItemFrom(IMyInventory sourceInventory, int sourceItemIndex, int? targetItemIndex, bool? stackIfPossible, VRage.MyFixedPoint? amount)
{
return TransferItemsFrom(sourceInventory, sourceItemIndex, targetItemIndex, stackIfPossible, amount,true);
}
private bool TransferItemsFrom(IMyInventory sourceInventory, int sourceItemIndex, int? targetItemIndex, bool? stackIfPossible, VRage.MyFixedPoint? amount,bool useConveyors)
{
MyInventory srcInventory = sourceInventory as MyInventory;
if (srcInventory != null && (useConveyors == false || IsConnected(srcInventory) == true))
{
TransferItemFrom(srcInventory, sourceItemIndex, targetItemIndex, stackIfPossible, amount);
return true;
}
return false;
}
VRage.MyFixedPoint IMyInventory.CurrentMass
{
get { return CurrentMass; }
}
VRage.MyFixedPoint IMyInventory.MaxVolume
{
get { return MaxVolume; }
}
VRage.MyFixedPoint IMyInventory.CurrentVolume
{
get { return CurrentVolume; }
}
IMyInventoryOwner IMyInventory.Owner
{
get { return Owner as IMyInventoryOwner; }
}
List<IMyInventoryItem> IMyInventory.GetItems()
{
return m_items.OfType<IMyInventoryItem>().ToList(); ;
}
IMyInventoryItem IMyInventory.GetItemByID(uint id)
{
MyPhysicalInventoryItem? item = GetItemByID(id);
if (item != null)
{
return item.Value;
}
return null;
}
IMyInventoryItem IMyInventory.FindItem(SerializableDefinitionId contentId)
{
MyPhysicalInventoryItem? item = FindItem(contentId);
if (item != null)
{
return item.Value;
}
return null;
}
bool VRage.Game.ModAPI.IMyInventory.TransferItemTo(IMyInventory dst, int sourceItemIndex, int? targetItemIndex = null, bool? stackIfPossible = null, VRage.MyFixedPoint? amount = null, bool checkConnection = false)
{
return TransferItemsTo(dst, sourceItemIndex, targetItemIndex, amount, checkConnection);
}
bool VRage.Game.ModAPI.IMyInventory.TransferItemFrom(IMyInventory sourceInventory, int sourceItemIndex, int? targetItemIndex = null, bool? stackIfPossible = null, VRage.MyFixedPoint? amount = null, bool checkConnection = false)
{
return TransferItemsFrom(sourceInventory, sourceItemIndex, targetItemIndex, stackIfPossible, amount, checkConnection);
}
bool IMyInventory.IsConnectedTo(IMyInventory dst)
{
MyInventory dstInventory = dst as MyInventory;
if (dstInventory != null)
{
return IsConnected(dstInventory);
}
return false;
}
}
}