public override bool NewRightClick(int i, int j) { Tile tile = Main.tile[i, j]; int left = i; int top = j; int index = GetInstance <TEItemDuct>().Find(left, top); if (index != -1) { TEItemDuct ent = (TEItemDuct)TileEntity.ByID[index]; foreach (Tuple <Item, Direction> t in ent.flowItems) { Main.NewText(t.Item1.HoverName + " " + t.Item2); } //if (ent.ductType == TEItemDuct.DuctType.In || ent.ductType == TEItemDuct.DuctType.None) { if (!MoreMechanisms.instance.ItemFilterUIVisible()) { MoreMechanisms.instance.itemFilterUIState.i = i * 16; MoreMechanisms.instance.itemFilterUIState.j = j * 16; MoreMechanisms.instance.ShowItemFilterUI(ent.filter.filterItems, ent.filter.filterWhitelist, (Item[] items, bool whitelist) => { ent.filter.filterItems = items; ent.filter.filterWhitelist = whitelist; }); } //} } return(true); }
public override bool Slope(int i, int j) { //Main.NewText("Slope"); Tile tile = Main.tile[i, j]; int left = i; int top = j; int index = GetInstance <TEItemDuct>().Find(left, top); if (index != -1) { TEItemDuct ent = (TEItemDuct)TileEntity.ByID[index]; Main.PlaySound(SoundID.Dig); //Main.NewText("ent"); switch (ent.ductType) { case TEItemDuct.DuctType.None: ent.ductType = TEItemDuct.DuctType.In; if (ent.filter.IsEmpty()) { ent.filter.filterWhitelist = true; } break; case TEItemDuct.DuctType.In: ent.ductType = TEItemDuct.DuctType.Out; if (ent.filter.IsEmpty()) { ent.filter.filterWhitelist = false; } break; case TEItemDuct.DuctType.Out: ent.ductType = TEItemDuct.DuctType.None; if (ent.filter.IsEmpty()) { ent.filter.filterWhitelist = false; } break; } ent.UpdateFrame(i, j); if (Main.netMode == 1) { NetMessage.SendTileSquare(-1, Player.tileTargetX, Player.tileTargetY, 1, TileChangeType.None); } } return(false); }
public override void Update() { if (Main.GameUpdateCount % TICK_DELAY != 0) { return; } switch (this.ductType) { case TEItemDuct.DuctType.None: break; case TEItemDuct.DuctType.In: foreach (Direction d in Direction.DIRECTIONS) { int left = Position.X + d.dx; int top = Position.Y + d.dy; Tile tile = Framing.GetTileSafely(left, top); if (SpecialConnects(tile, left, top)) { if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } IConnectable conn = Connectable.Find(left, top); if (conn != null) { Item[] items = conn.GetItems(ConnectableType.Input); Func <Item, bool> validItemFunc = (Item it) => { return(conn.Accepts(it, ConnectableType.Input)); }; for (int ind = 0; ind < items.Length; ind++) { Item i = items[ind]; if (i.active && i.type != ItemID.None && filter.FilterAccepts(i)) { if ((flowItems.Count + addItems.Count) < 4) { Item it = i.Clone(); it.stack = 1; addItems.Add(Tuple.Create(it, Direction.NONE)); if (i.stack > 1) { i.stack--; } else { i.TurnToAir(); } conn.TransferredItem(i, ind, ConnectableType.Input); break; } } } } break; } } break; case TEItemDuct.DuctType.Out: if (flowItems.Count == 0) { break; } foreach (Direction d in Direction.DIRECTIONS) { int left = Position.X + d.dx; int top = Position.Y + d.dy; Tile tile = Framing.GetTileSafely(left, top); if (SpecialConnects(tile, left, top)) { if (tile.frameX % 36 != 0) { left--; } if (tile.frameY != 0) { top--; } IConnectable conn = Connectable.Find(left, top); if (conn != null) { Item[] items = conn.GetItems(ConnectableType.Output); Func <Item, bool> validItemFunc = (Item it) => { return(conn.Accepts(it, ConnectableType.Output)); }; //Main.NewText("out searching chest"); foreach (Tuple <Item, Direction> it in flowItems) { if (!validItemFunc(it.Item1)) { continue; } int putItem = -1; Item newStack = null; for (int ind = 0; ind < items.Length; ind++) { Item i = items[ind]; if (i.active && i.type != 0) { if (i.stack < i.maxStack) { if (it.Item1.type == i.type) { //Main.NewText("out found stack"); i.stack++; removeItems.Add(it); putItem = ind; newStack = i; break; } } } } //Main.NewText("out no stack"); if (putItem == -1) { for (int ind = 0; ind < items.Length; ind++) { Item i = items[ind]; if (i.IsAir) { //Main.NewText("out put"); items[ind] = it.Item1; removeItems.Add(it); putItem = ind; newStack = it.Item1; break; } } } if (putItem != -1 && newStack != null) { conn.TransferredItem(newStack, putItem, ConnectableType.Output); } } } break; } } break; } //if(flowItems.Count > 0) Main.NewText("#" + flowItems.Count); if (ductType == DuctType.None || ductType == DuctType.In) { removeItems.AddRange(flowItems.FindAll(((Tuple <Item, Direction> ti) => { Item i = ti.Item1; //Main.NewText(i.HoverName); List <Tuple <TEItemDuct, Direction> > possible = new List <Tuple <TEItemDuct, Direction> >(); Tuple <TEItemDuct, Direction> reverse = null; foreach (Direction dir in Direction.DIRECTIONS) { Tile tile = Framing.GetTileSafely(Position.X + dir.dx, Position.Y + dir.dy); int left = Position.X + dir.dx; int top = Position.Y + dir.dy; if (tile.active() && tile.type == MoreMechanisms.instance.TileType("ItemDuctTile")) { int index = GetInstance <TEItemDuct>().Find(left, top); if (index != -1) { TEItemDuct ent = (TEItemDuct)TileEntity.ByID[index]; //Main.NewText("adjacent duct " + ((Direction)d) + " " + ent.flowItems.Count + " " + ent.addItems.Count); if ((ent.flowItems.Count + ent.addItems.Count) < 4 && ent.filter.FilterAccepts(i)) { //Main.NewText("add item"); if (ti.Item2 == dir) { reverse = Tuple.Create(ent, dir.Opposite); } else { possible.Add(Tuple.Create(ent, dir.Opposite)); } } } } } if (possible.Count > 0) { Tuple <TEItemDuct, Direction> sel = possible[Main.rand.Next(possible.Count)]; sel.Item1.addItems.Add(Tuple.Create(i, sel.Item2)); return(true); } else if (reverse != null) { reverse.Item1.addItems.Add(Tuple.Create(i, reverse.Item2)); return(true); } return(false); }))); } needUpdate.Add(this); if (changed) { NetMessage.SendData(MessageID.TileEntitySharing, -1, -1, null, ID, Position.X, Position.Y); changed = false; } }
public override bool PreDraw(int i, int k, SpriteBatch spriteBatch) { Tile tile = Main.tile[i, k]; if (tile.active() && tile.type == mod.TileType("ItemDuctTile")) { TileEntity tileEntity = default(TileEntity); if (TileEntity.ByPosition.TryGetValue(new Point16(i, k), out tileEntity)) { TEItemDuct es = tileEntity as TEItemDuct; // draw connectors Tile uTile = Framing.GetTileSafely(i, k - 1); Tile dTile = Framing.GetTileSafely(i, k + 1); Tile lTile = Framing.GetTileSafely(i - 1, k); Tile rTile = Framing.GetTileSafely(i + 1, k); bool uCon = es.SpecialConnects(uTile, i, k - 1); bool dCon = es.SpecialConnects(dTile, i, k + 1); bool lCon = es.SpecialConnects(lTile, i - 1, k); bool rCon = es.SpecialConnects(rTile, i + 1, k); if (uCon || dCon || lCon || rCon) { bool[] con = new bool[] { uCon, dCon, lCon, rCon }; Color lightCol = Lighting.GetColor(i, k); //TODO: why does the spritebatch seem to draw offset 12 tiles to the -x and -y? int oi = i; int ok = k; i += 12; k += 12; int tfrX = es.flowItems.Count > 0 ? 1 : 0; int frY = 0; switch (es.ductType) { case TEItemDuct.DuctType.In: frY = 15 * 18; break; case TEItemDuct.DuctType.Out: frY = 15 * 18 + 34; break; case TEItemDuct.DuctType.None: default: break; } Texture2D texture = (!Main.canDrawColorTile(tile.type, tile.color())) ? Main.tileTexture[tile.type] : Main.tileAltTexture[tile.type, tile.color()]; Vector2 start = new Vector2((float)(i * 16 - (32 - 16) / 2 + 16), (float)(k * 16 - (32 - 16) / 2 + 16)); for (int d = 0; d < con.Length; d++) { if (!con[d]) { continue; } float angle = new float[] { 0, 180, 270, 90 }[d]; spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); spriteBatch.Draw(texture, start - Main.screenPosition, new Rectangle(tfrX * 34, frY, 32, 32), lightCol, angle * (float)(Math.PI / 180), new Vector2(16, 16), 1f, SpriteEffects.None, 1f); spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); if (d == 0) { Util.DrawWorldTile(spriteBatch, oi, ok - 1, 12 * 16, 12 * 16); } if (d == 1) { Util.DrawWorldTile(spriteBatch, oi, ok + 1, 12 * 16, 12 * 16); } if (d == 2) { Util.DrawWorldTile(spriteBatch, oi - 1, ok, 12 * 16, 12 * 16); } if (d == 3) { Util.DrawWorldTile(spriteBatch, oi + 1, ok, 12 * 16, 12 * 16); } } } } } spriteBatch.End(); spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive); return(base.PreDraw(i, k, spriteBatch)); }