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 void OnUseOver(IPlayer byPlayer, Vec3i voxelHitPos, Vec3i voxelBoxPos, BlockFacing facing, ItemStack itemStack, bool mouseBreakMode) { Item heldItem = itemStack?.Item; if (heldItem?.Code?.ToString() == "signals:el_wire") { if (mouseBreakMode) { if (wiring.OnRemove(voxelHitPos)) { AvailableWireVoxels++; if (AvailableWireVoxels >= 25) { byPlayer.InventoryManager.TryGiveItemstack(new ItemStack(heldItem)); AvailableWireVoxels = 0; } } return; } if (canPlaceWireAt(voxelHitPos.AddCopy(facing))) { if (AvailableWireVoxels == 0) { AvailableWireVoxels = 25; //slot.TakeOut(1); //slot.MarkDirty(); } wiring.OnAdd(voxelHitPos.AddCopy(facing)); AvailableWireVoxels--; } return; } CircuitComponent comp = SignalsUtils.GetCircuitComponentFromItem(api, heldItem); if (comp != null) { comp.Pos = voxelBoxPos.Clone(); comp.myCircuit = this; comp.Initialize(api, this); components.Add(comp); } }