public static Vec3i GetCircuitComponentSizeFromItem(ICoreAPI api, Item item) { if (item == null) { return(null); } SignalsMod mod = api.ModLoader.GetModSystem <SignalsMod>(); JsonObject jsonObj = item.Attributes?["circuitComponent"]; if (jsonObj == null) { return(null); } Vec3i size = jsonObj["size"]?.AsObject <Vec3i>(); return(size); }
private void ComponentsFromTree(ref List <CircuitComponent> comps, ITreeAttribute tree, IWorldAccessor world) { ICoreAPI api = world.Api; if (tree == null || api == null) { return; } SignalsMod mod = api.ModLoader.GetModSystem <SignalsMod>(); foreach (KeyValuePair <string, IAttribute> kv in tree) { ITreeAttribute compTree = kv.Value as ITreeAttribute; if (compTree == null) { continue; } string className = compTree.GetString("class", null); int index = int.Parse(kv.Key); if (index < comps.Count) { if (comps[index].className == className) { comps[index].FromTreeAtributes(compTree, api.World); continue; } else { comps[index].Remove(); comps.RemoveAt(index); } } Type type = mod.getCircuitComponentType(className); if (type == null) { continue; } CircuitComponent newComponent = (CircuitComponent)Activator.CreateInstance(type, this); newComponent.FromTreeAtributes(compTree, api.World); newComponent.Initialize(api, this); comps.Add(newComponent); } }
public static CircuitComponent GetCircuitComponentFromItem(ICoreAPI api, Item item) { if (item == null) { return(null); } SignalsMod mod = api.ModLoader.GetModSystem <SignalsMod>(); JsonObject jsonObj = item.Attributes?["circuitComponent"]; if (jsonObj == null) { return(null); } string className = jsonObj["class"]?.AsString(); Type type = mod.getCircuitComponentType(className); return((CircuitComponent)Activator.CreateInstance(type)); }