public override void SplitDataAcrossNetworks(Point16 splitOrig) { NetworkCollection.HasWireAt(splitOrig + new Point16(0, -1), out WireNetwork upNet); NetworkCollection.HasWireAt(splitOrig + new Point16(-1, 0), out WireNetwork leftNet); NetworkCollection.HasWireAt(splitOrig + new Point16(1, 0), out WireNetwork rightNet); NetworkCollection.HasWireAt(splitOrig + new Point16(0, 1), out WireNetwork downNet); List <WireNetwork> nets = new List <WireNetwork>(); if (upNet != null) { nets.Add(upNet); } if (leftNet != null && !nets.Contains(leftNet)) { nets.Add(leftNet); } if (rightNet != null && !nets.Contains(rightNet)) { nets.Add(rightNet); } if (downNet != null && !nets.Contains(downNet)) { nets.Add(downNet); } nets = nets.OrderBy(n => (float)n.Capacity).Distinct().ToList(); foreach (var net in nets) { net.StoredFlux = new TerraFlux(Math.Min((float)StoredFlux, (float)net.Capacity)); StoredFlux -= net.StoredFlux; if ((float)StoredFlux <= 0) { break; } } }
public override void PlaceInWorld(int i, int j, Item item) { // TODO: TileObject.CanPlace is throwing null-ref exceptions. why??? MachineItem mItem = item.modItem as MachineItem; GetDefaultParams(out _, out uint width, out uint height, out _); Point16 tePos = new Point16(i, j) - new Point16((int)width / 2, (int)height - 1); int type = (item.modItem as MachineItem).TileType; MachineEntity entity = TileUtils.tileToEntity[type]; if (entity.Find(tePos.X, tePos.Y) < 0) { int id = entity.Place(tePos.X, tePos.Y); if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.TileEntitySharing, remoteClient: -1, ignoreClient: Main.myPlayer, number: id); } } //Restore the saved data, if it exists MachineEntity placed = TileEntity.ByPosition[tePos] as MachineEntity; if (mItem.entityData != null) { placed.Load(mItem.entityData); } //If this structure has a powered entity on it, try to connect it to nearby networks Point16 checkOrig = tePos - new Point16(1, 1); bool canUseWires = placed is PoweredMachineEntity; bool canUseItemPipes = placed.SlotsCount > 0; bool canUseFluidPipes = placed is ILiquidMachine || placed is IGasMachine; for (int cx = checkOrig.X; cx < checkOrig.X + width + 2; cx++) { for (int cy = checkOrig.Y; cy < checkOrig.Y + height + 2; cy++) { WorldGen.TileFrame(cx, cy); //Ignore the corners if ((cx == 0 && cy == 0) || (cx == width + 1 && cy == 0) || (cx == 0 && cy == height + 1) || (cx == width + 1 && cy == height + 1)) { continue; } Point16 test = new Point16(cx, cy); if (canUseWires && NetworkCollection.HasWireAt(test, out WireNetwork wireNet)) { wireNet.AddMachine(placed); } if (canUseItemPipes && NetworkCollection.HasItemPipeAt(test, out ItemNetwork itemNet)) { itemNet.AddMachine(placed); itemNet.pipesConnectedToMachines.Add(test); } if (canUseFluidPipes && NetworkCollection.HasFluidPipeAt(test, out FluidNetwork fluidNet)) { fluidNet.AddMachine(placed); } } } if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendTileRange(Main.myPlayer, checkOrig.X, checkOrig.Y, (int)width + 1, (int)height + 1); } }
public override void PostDrawTiles() { bool began = false; //Draw any junction stuff if (Main.LocalPlayer.HeldItem.modItem is TransportJunctionItem) { if (!string.IsNullOrWhiteSpace(TransportJunctionItem.display) && TransportJunctionItem.displayTimer >= 0) { Vector2 measure = Main.fontMouseText.MeasureString(TransportJunctionItem.display); Vector2 position = Main.LocalPlayer.Top - new Vector2(0, 20) - Main.screenPosition; Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null); began = true; Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, TransportJunctionItem.display, position.X, position.Y, Color.Yellow, Color.Black, measure / 2f); } if (TransportJunctionItem.displayTimer >= 0) { TransportJunctionItem.displayTimer--; } } else { TransportJunctionItem.display = null; TransportJunctionItem.displayTimer = -1; } if (!TechMod.debugging) { if (began) { Main.spriteBatch.End(); } return; } if (Main.LocalPlayer.HeldItem.type != ModContent.ItemType <DebugTool>() || Main.LocalPlayer.inventory[58].type == ModContent.ItemType <DebugTool>()) { if (began) { Main.spriteBatch.End(); } return; } Point16 mouse = Main.MouseWorld.ToTileCoordinates16(); bool hasWire = NetworkCollection.HasWireAt(mouse, out WireNetwork wireNet); bool hasItem = NetworkCollection.HasItemPipeAt(mouse, out ItemNetwork itemNet); bool hasFluid = NetworkCollection.HasFluidPipeAt(mouse, out FluidNetwork fluidNet); if (!hasWire && !hasItem && !hasFluid) { if (began) { Main.spriteBatch.End(); } return; } if (!began) { Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null); } //For every wire on-screen in the network the player's mouse is hovering over, draw an indicator if (hasWire) { DrawNetTiles(wireNet.GetEntries(), Color.Blue * 0.45f); } if (hasItem) { DrawNetTiles(itemNet.GetEntries(), Color.Green * 0.45f); } if (hasFluid) { DrawNetTiles(fluidNet.GetEntries(), Color.Red * 0.45f); } //Then draw what network is being targeted Vector2 offset = Main.MouseScreen + new Vector2(20, 20); bool hasOffset = false; if (wireNet != null) { hasOffset = true; Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Targeting Wire Network (ID: {wireNet.ID})", offset.X, offset.Y, Color.Blue, Color.Black, Vector2.Zero); Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Stored TF: {(float)wireNet.StoredFlux :0.##} / {(float)wireNet.Capacity :0.##} TF", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Exported Flux: {(float)wireNet.totalExportedFlux :0.##} TF/t ({(float)wireNet.totalExportedFlux * 60 :0.##} TF/s)", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); } if (itemNet != null) { Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Targeting Item Network (ID: {itemNet.ID})", offset.X, !hasOffset ? offset.Y : (offset.Y += 20), Color.Green, Color.Black, Vector2.Zero); hasOffset = true; Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Item Stacks in Network: {itemNet.paths.Count}", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Connected Chests: {itemNet.chests.Count}", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Pipes Connected to Chests: {itemNet.pipesConnectedToChests.Count}", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Pipes Connected to Machines: {itemNet.pipesConnectedToMachines.Count}", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); } if (fluidNet != null) { Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Targeting Fluid Network (ID: {fluidNet.ID})", offset.X, !hasOffset ? offset.Y : (offset.Y += 20), Color.Red, Color.Black, Vector2.Zero); Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Fluid Type: {(fluidNet.liquidType != MachineLiquidID.None ? fluidNet.liquidType.ProperEnumName() : fluidNet.gasType.ProperEnumName())}", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); Utils.DrawBorderStringFourWay(Main.spriteBatch, Main.fontMouseText, $"Stored Fluid: {fluidNet.StoredFluid :0.##} / {fluidNet.Capacity :0.##} L", offset.X, offset.Y += 20, Color.White, Color.Black, Vector2.Zero); } Main.spriteBatch.End(); }