public override bool CanCombine(Point16 orig, Point16 dir) { NetworkCollection.HasFluidPipeAt(orig + dir, out FluidNetwork thisNet); NetworkCollection.HasFluidPipeAt(orig - dir, out FluidNetwork otherNet); var otherAxis = new Point16(dir.Y, dir.X); NetworkCollection.HasFluidPipeAt(orig + otherAxis, out FluidNetwork axisNet); NetworkCollection.HasFluidPipeAt(orig - otherAxis, out FluidNetwork otherAxisNet); Tile center = Framing.GetTileSafely(orig); if (ModContent.GetModTile(center.type) is TransportJunction) { //At this point, only one axis is being handled, so that's fine JunctionMerge merge = JunctionMergeable.mergeTypes[center.frameX / 18]; if (((merge & JunctionMerge.Fluids_LeftRight) != 0 && dir.X != 0) || ((merge & JunctionMerge.Fluids_UpDown) != 0 && dir.Y != 0)) { return(otherNet is null || (otherNet.liquidType == thisNet.liquidType && otherNet.gasType == thisNet.gasType)); } return(false); } //Not a junction at the center. Need to check every direction //All directions just need to be checked against this one bool hasConnOther = otherNet != null; bool hasConnAxis = axisNet != null; bool hasConnAxisOther = otherAxisNet != null; return((!hasConnOther || (otherNet.liquidType == thisNet.liquidType && otherNet.gasType == thisNet.gasType)) && (!hasConnAxis || (axisNet.liquidType == thisNet.liquidType && axisNet.gasType == thisNet.gasType)) && (!hasConnAxisOther || (otherAxisNet.liquidType == thisNet.liquidType && otherAxisNet.gasType == thisNet.gasType))); }
private static string GetModeText(JunctionMerge mode) { if (mode == JunctionMerge.None) { return("None"); } if (mode == JunctionMerge.Wires_All) { return("Wires"); } if (mode == JunctionMerge.Items_All) { return("Items"); } if (mode == JunctionMerge.Fluids_All) { return("Fluids"); } string text = ""; if ((mode & JunctionMerge.Wires_UpDown) != 0) { text += "Wires Up & Down"; } if ((mode & JunctionMerge.Items_UpDown) != 0) { text += "Items Up & Down"; } if ((mode & JunctionMerge.Fluids_UpDown) != 0) { text += "Fluids Up & Down"; } if ((mode & JunctionMerge.Wires_LeftRight) != 0) { if (text != "") { text += ", "; } text += "Wires Left & Right"; } if ((mode & JunctionMerge.Items_LeftRight) != 0) { if (text != "") { text += ", "; } text += "Items Left & Right"; } if ((mode & JunctionMerge.Fluids_LeftRight) != 0) { if (text != "") { text += ", "; } text += "Fluids Left & Right"; } return(text); }
internal static int FindMergeIndex(JunctionMerge type) => Array.FindIndex(mergeTypes, m => m == type);
private bool CheckTileMerge(int i, int j, int dirX, int dirY) { if (MergeType == JunctionType.None) { return(false); } if ((dirX == 0 && dirY == 0) || (dirX != 0 && dirY != 0)) { return(false); } if (dirX < -1 || dirX > 1 || dirY < -1 || dirY > 1) { return(false); } int targetX = i + dirX; int targetY = j + dirY; if (targetX < 0 || targetX >= Main.maxTilesX || targetY < 0 || targetY >= Main.maxTilesY) { return(false); } Tile target = Framing.GetTileSafely(targetX, targetY); ModTile targetModTile = ModContent.GetModTile(target.type); if (!target.active()) { return(false); } //If this merge type is "Items" and the tile is a chest, merge if (MergeType == JunctionType.Items && (TileID.Sets.BasicChest[target.type] || (targetModTile != null && (targetModTile.adjTiles.Contains(TileID.Containers) || targetModTile.adjTiles.Contains(TileID.Containers2))))) { return(true); } if (target.type < TileID.Count) { return(false); } if (targetModTile is JunctionMergeable merge) { bool hasSameMerge = merge.MergeType == MergeType; //Need to check if the target is a pump and the pump is pointing in the right direction if (merge is ItemPumpTile || merge is FluidPumpTile) { int frame = target.frameX / 18; return(hasSameMerge && ((dirY == 1 && frame == 0) || (dirX == 1 && frame == 1) || (dirY == -1 && frame == 2) || (dirX == -1 && frame == 3))); } else { return(hasSameMerge); } } else if (targetModTile is TransportJunction) { int frameX = target.frameX / 18; //Junction has the default frame? Don't let them merge... if (frameX == 0) { return(false); } //Invalid frame? Don't merge if (frameX < 0 || frameX > junctionColumns) { return(false); } //dirX == -1 means the junction must have a frame showing this mergetype on its right edge //dirX == 1 means the junction must have a frame showing this mergetype on its left edge //dirY == -1 means the junction must have a frame showing this mergetype on its bottom edge //dirY == 1 means the junction must have a frame showing this mergetype on its top edge //See Content/Tiles/TransportJunction.png for reference JunctionMerge otherMerge = mergeTypes[frameX]; int shift = ((int)MergeType - 1) * 4; int mask = 0; if (dirX == -1) { mask |= 0x4; } else if (dirX == 1) { mask |= 0x2; } if (dirY == -1) { mask |= 0x08; } else if (dirY == 1) { mask |= 0x01; } mask <<= shift; return(((int)otherMerge & mask) != 0); } else if (targetModTile is Machine && TileUtils.tileToEntity.TryGetValue(targetModTile.Type, out MachineEntity entity)) { return((MergeType == JunctionType.Wires && entity is PoweredMachineEntity) || (MergeType == JunctionType.Items && (entity.GetInputSlots().Length > 0 || entity.GetOutputSlots().Length > 0)) || (MergeType == JunctionType.Fluids && (entity is ILiquidMachine || entity is IGasMachine))); } else if (((MergeType == JunctionType.Items && targetModTile is ItemPumpTile) || (MergeType == JunctionType.Fluids && targetModTile is FluidPumpTile)) && ((dirX == -1 && target.frameX / 18 == 3) || (dirX == 1 && target.frameX / 18 == 1) || (dirY == -1 && target.frameX / 18 == 2) || (dirY == 1 && target.frameX / 18 == 0))) { return(true); } //Tile wasn't a junction-mergeable tile return(false); }