// This is basically a hack, needed because mining the bottom of a trap while a chest is placed on top can break the game public static bool CanMineTrap(int i, int j, ushort trap) { int y = j - (Main.tile[i, j].frameY / 18); int x = i - ((Main.tile[i, j].frameX % 36) / 18); ushort type1 = Main.tile[x, y - 1].type, type2 = Main.tile[x + 1, y - 1].type; bool cankill = !TileID.Sets.BasicChest[type2] && !TileID.Sets.BasicChest[type1] && !TileID.Sets.BasicChestFake[type1] && !TileID.Sets.BasicChestFake[type2] && !TileLoader.IsDresser(type2) && !TileLoader.IsDresser(type1); if (cankill) { if (y != j || x == i) { Main.tile[x + 1, y].type = TileID.Stone; cankill &= WorldGen.CanKillTile(x + 1, y); Main.tile[x + 1, y].type = trap; } if (y != j || x != i) { Main.tile[x, y].type = TileID.Stone; cankill &= WorldGen.CanKillTile(x, y); Main.tile[x, y].type = trap; } } return(cankill); }
public static void DamageTile(int i, int j, int damage, bool simulate = false) { var id = Main.LocalPlayer.hitTile.HitObject(i, j, 1); if (WorldGen.CanKillTile(i, j) && Main.LocalPlayer.hitTile.AddDamage(id, damage, !simulate) >= 100) { Main.LocalPlayer.hitTile.Clear(id); WorldGen.KillTile(i, j); if (Main.netMode == 1) { NetMessage.SendData(17, number2: i, number3: j); } } }
// Adapted from the vanilla Player class method public void PickTile(Player player, int x, int y) { int tileId = player.hitTile.HitObject(x, y, 1); Tile tile = Main.tile[x, y]; int actualPower = ShovelMethods.DigPower(tile.type, Shovel); if (actualPower < 100 && Pick >= Shovel) { player.PickTile(x, y, Pick); return; } else if (actualPower == 0) { player.PickTile(x, y, Math.Max(Shovel / 8, 1)); return; } if (!WorldGen.CanKillTile(x, y)) { actualPower = 0; } if (player.hitTile.AddDamage(tileId, actualPower, true) >= 100) { AchievementsHelper.CurrentlyMining = true; player.hitTile.Clear(tileId); bool wasActive = tile.active(); WorldGen.KillTile(x, y, false, false, false); if (wasActive && !tile.active()) { AchievementsHelper.HandleMining(); } AchievementsHelper.CurrentlyMining = false; } else { WorldGen.KillTile(x, y, true, false, false); } if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, x, y); } if (actualPower != 0) { player.hitTile.Prune(); } }
private bool CanGetPastTile(int x, int y) { if (WorldGen.CheckTileBreakability(x, y) != 0) { return(false); } Tile tile = Main.tile[x, y]; if (tile.active() && TileID.Sets.Falling[tile.type]) { return(false); } if (tile.active() && !WorldGen.CanKillTile(x, y)) { return(false); } return(true); }
private Point16 DrillSmartCursor(Player mountedPlayer, DrillMountData data) { Vector2 value = (mountedPlayer.whoAmI != Main.myPlayer) ? data.crosshairPosition : (Main.screenPosition + new Vector2((float)Main.mouseX, (float)Main.mouseY)); Vector2 center = mountedPlayer.Center; Vector2 value2 = value - center; float num = value2.Length(); if (num > 224f) { num = 224f; } num += 32f; value2.Normalize(); Vector2 end = center + value2 * num; Point16 tilePoint = new Point16(-1, -1); if (!Utils.PlotTileLine(center, end, 65.6f, delegate(int x, int y) { tilePoint = new Point16(x, y); for (int i = 0; i < data.beams.Length; i++) { if (data.beams[i].curTileTarget == tilePoint) { return(true); } } if (!WorldGen.CanKillTile(x, y)) { return(true); } if (Main.tile[x, y] != null && !Main.tile[x, y].inActive() && Main.tile[x, y].active()) { return(false); } return(true); })) { return(tilePoint); } return(new Point16(-1, -1)); }
/// <summary> /// <para>Hit tile with pick without needing a player.</para> /// <para>Equivalent to if an actual player hit it.</para> /// <para>Modified from Terraria's Player.PickTile code.</para> /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="pickPower"></param> public static void PickTile(int x, int y, int pickPower) { int damage = 0; int tileId = MoreMechanisms.globalHitTile.HitObject(x, y, 1); Tile tile = Main.tile[x, y]; if (Main.tileNoFail[tile.type]) { damage = 100; } if (Main.tileDungeon[tile.type] || tile.type == 25 || tile.type == 58 || tile.type == 117 || tile.type == 203) { damage += pickPower / 2; } else if (tile.type == 48 || tile.type == 232) { damage += pickPower / 4; } else if (tile.type == 226) { damage += pickPower / 4; } else if (tile.type == 107 || tile.type == 221) { damage += pickPower / 2; } else if (tile.type == 108 || tile.type == 222) { damage += pickPower / 3; } else if (tile.type == 111 || tile.type == 223) { damage += pickPower / 4; } else if (tile.type == 211) { damage += pickPower / 5; } else { TileLoader.MineDamage(pickPower, ref damage); } if (tile.type == 211 && pickPower < 200) { damage = 0; } if ((tile.type == 25 || tile.type == 203) && pickPower < 65) { damage = 0; } else if (tile.type == 117 && pickPower < 65) { damage = 0; } else if (tile.type == 37 && pickPower < 50) { damage = 0; } else if (tile.type == 404 && pickPower < 65) { damage = 0; } else { if ((tile.type == 22 || tile.type == 204) && (double)y > Main.worldSurface && pickPower < 55) { damage = 0; } else if (tile.type == 56 && pickPower < 65) { damage = 0; } else if (tile.type == 58 && pickPower < 65) { damage = 0; } else { if ((tile.type == 226 || tile.type == 237) && pickPower < 210) { damage = 0; } else if (Main.tileDungeon[tile.type] && pickPower < 65) { if ((double)x < (double)Main.maxTilesX * 0.35 || (double)x > (double)Main.maxTilesX * 0.65) { damage = 0; } } else if (tile.type == 107 && pickPower < 100) { damage = 0; } else if (tile.type == 108 && pickPower < 110) { damage = 0; } else if (tile.type == 111 && pickPower < 150) { damage = 0; } else if (tile.type == 221 && pickPower < 100) { damage = 0; } else if (tile.type == 222 && pickPower < 110) { damage = 0; } else if (tile.type == 223 && pickPower < 150) { damage = 0; } else { TileLoader.PickPowerCheck(tile, pickPower, ref damage); } } } if (tile.type == 147 || tile.type == 0 || tile.type == 40 || tile.type == 53 || tile.type == 57 || tile.type == 59 || tile.type == 123 || tile.type == 224 || tile.type == 397) { damage += pickPower; } if (tile.type == 165 || Main.tileRope[tile.type] || tile.type == 199 || Main.tileMoss[tile.type]) { damage = 100; } if (MoreMechanisms.globalHitTile.AddDamage(tileId, damage, false) >= 100 && (tile.type == 2 || tile.type == 23 || tile.type == 60 || tile.type == 70 || tile.type == 109 || tile.type == 199 || Main.tileMoss[tile.type])) { damage = 0; } if (tile.type == 128 || tile.type == 269) { if (tile.frameX == 18 || tile.frameX == 54) { x--; tile = Main.tile[x, y]; MoreMechanisms.globalHitTile.UpdatePosition(tileId, x, y); } if (tile.frameX >= 100) { damage = 0; Main.blockMouse = true; } } if (tile.type == 334) { if (tile.frameY == 0) { y++; tile = Main.tile[x, y]; MoreMechanisms.globalHitTile.UpdatePosition(tileId, x, y); } if (tile.frameY == 36) { y--; tile = Main.tile[x, y]; MoreMechanisms.globalHitTile.UpdatePosition(tileId, x, y); } int j = tile.frameX; bool flag = j >= 5000; bool cancel = false; if (!flag) { int num5 = j / 18; num5 %= 3; x -= num5; tile = Main.tile[x, y]; if (tile.frameX >= 5000) { flag = true; } } if (flag) { j = tile.frameX; int num3 = 0; while (j >= 5000) { j -= 5000; num3++; } if (num3 != 0) { cancel = true; } } if (cancel) { damage = 0; Main.blockMouse = true; } } if (!WorldGen.CanKillTile(x, y)) { damage = 0; } if (MoreMechanisms.globalHitTile.AddDamage(tileId, damage, true) >= 100) { //AchievementsHelper.CurrentlyMining = true; MoreMechanisms.globalHitTile.Clear(tileId); if (Main.netMode == 1 && Main.tileContainer[Main.tile[x, y].type]) { WorldGen.KillTile(x, y, true, false, false); NetMessage.SendData(17, -1, -1, null, 0, (float)x, (float)y, 1f, 0, 0, 0); if (Main.tile[x, y].type == 21 || (Main.tile[x, y].type >= 470 && TileID.Sets.BasicChest[Main.tile[x, y].type])) { NetMessage.SendData(34, -1, -1, null, 1, (float)x, (float)y, 0f, 0, 0, 0); } if (Main.tile[x, y].type == 467) { NetMessage.SendData(34, -1, -1, null, 5, (float)x, (float)y, 0f, 0, 0, 0); } if (TileLoader.IsDresser(Main.tile[x, y].type)) { NetMessage.SendData(34, -1, -1, null, 3, (float)x, (float)y, 0f, 0, 0, 0); } if (Main.tile[x, y].type >= 470 && TileID.Sets.BasicChest[Main.tile[x, y].type]) { NetMessage.SendData(34, -1, -1, null, 101, (float)x, (float)y, 0f, 0, Main.tile[x, y].type, 0); } if (Main.tile[x, y].type >= 470 && TileLoader.IsDresser(Main.tile[x, y].type)) { NetMessage.SendData(34, -1, -1, null, 103, (float)x, (float)y, 0f, 0, Main.tile[x, y].type, 0); } } else { int num2 = y; bool num6 = Main.tile[x, num2].active(); WorldGen.KillTile(x, num2, false, false, false); if (num6 && !Main.tile[x, num2].active()) { //AchievementsHelper.HandleMining(); } if (Main.netMode == 1) { NetMessage.SendData(17, -1, -1, null, 0, (float)x, (float)num2, 0f, 0, 0, 0); } } //AchievementsHelper.CurrentlyMining = false; } else { WorldGen.KillTile(x, y, true, false, false); if (Main.netMode == 1) { NetMessage.SendData(17, -1, -1, null, 0, (float)x, (float)y, 1f, 0, 0, 0); } } if (damage != 0) { MoreMechanisms.globalHitTile.Prune(); } }
/// <summary> /// <para>Returns true if the pickPower provided could mine the tile.</para> /// <para>Modified from Terraria's Player.PickTile code.</para> /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="pickPower"></param> public static bool CanPickTile(int x, int y, int pickPower) { int damage = 0; int tileId = MoreMechanisms.globalHitTile.HitObject(x, y, 1); Tile tile = Main.tile[x, y]; if (Main.tileNoFail[tile.type]) { damage = 100; } if (Main.tileDungeon[tile.type] || tile.type == 25 || tile.type == 58 || tile.type == 117 || tile.type == 203) { damage += pickPower / 2; } else if (tile.type == 48 || tile.type == 232) { damage += pickPower / 4; } else if (tile.type == 226) { damage += pickPower / 4; } else if (tile.type == 107 || tile.type == 221) { damage += pickPower / 2; } else if (tile.type == 108 || tile.type == 222) { damage += pickPower / 3; } else if (tile.type == 111 || tile.type == 223) { damage += pickPower / 4; } else if (tile.type == 211) { damage += pickPower / 5; } else { TileLoader.MineDamage(pickPower, ref damage); } if (tile.type == 211 && pickPower < 200) { damage = 0; } if ((tile.type == 25 || tile.type == 203) && pickPower < 65) { damage = 0; } else if (tile.type == 117 && pickPower < 65) { damage = 0; } else if (tile.type == 37 && pickPower < 50) { damage = 0; } else if (tile.type == 404 && pickPower < 65) { damage = 0; } else { if ((tile.type == 22 || tile.type == 204) && (double)y > Main.worldSurface && pickPower < 55) { damage = 0; } else if (tile.type == 56 && pickPower < 65) { damage = 0; } else if (tile.type == 58 && pickPower < 65) { damage = 0; } else { if ((tile.type == 226 || tile.type == 237) && pickPower < 210) { damage = 0; } else if (Main.tileDungeon[tile.type] && pickPower < 65) { if ((double)x < (double)Main.maxTilesX * 0.35 || (double)x > (double)Main.maxTilesX * 0.65) { damage = 0; } } else if (tile.type == 107 && pickPower < 100) { damage = 0; } else if (tile.type == 108 && pickPower < 110) { damage = 0; } else if (tile.type == 111 && pickPower < 150) { damage = 0; } else if (tile.type == 221 && pickPower < 100) { damage = 0; } else if (tile.type == 222 && pickPower < 110) { damage = 0; } else if (tile.type == 223 && pickPower < 150) { damage = 0; } else { TileLoader.PickPowerCheck(tile, pickPower, ref damage); } } } if (tile.type == 147 || tile.type == 0 || tile.type == 40 || tile.type == 53 || tile.type == 57 || tile.type == 59 || tile.type == 123 || tile.type == 224 || tile.type == 397) { damage += pickPower; } if (tile.type == 165 || Main.tileRope[tile.type] || tile.type == 199 || Main.tileMoss[tile.type]) { damage = 100; } if (/*MoreMechanisms.hitTile.AddDamage(tileId, num, false) >= 100 && */ (tile.type == 2 || tile.type == 23 || tile.type == 60 || tile.type == 70 || tile.type == 109 || tile.type == 199 || Main.tileMoss[tile.type])) { damage = 0; } if (tile.type == 128 || tile.type == 269) { if (tile.frameX == 18 || tile.frameX == 54) { x--; tile = Main.tile[x, y]; //MoreMechanisms.hitTile.UpdatePosition(tileId, x, y); } if (tile.frameX >= 100) { damage = 0; Main.blockMouse = true; } } if (tile.type == 334) { if (tile.frameY == 0) { y++; tile = Main.tile[x, y]; //MoreMechanisms.hitTile.UpdatePosition(tileId, x, y); } if (tile.frameY == 36) { y--; tile = Main.tile[x, y]; //MoreMechanisms.hitTile.UpdatePosition(tileId, x, y); } int j = tile.frameX; bool flag3 = j >= 5000; bool flag2 = false; if (!flag3) { int num5 = j / 18; num5 %= 3; x -= num5; tile = Main.tile[x, y]; if (tile.frameX >= 5000) { flag3 = true; } } if (flag3) { j = tile.frameX; int num3 = 0; while (j >= 5000) { j -= 5000; num3++; } if (num3 != 0) { flag2 = true; } } if (flag2) { damage = 0; Main.blockMouse = true; } } if (!WorldGen.CanKillTile(x, y)) { damage = 0; } return(damage != 0); }
public void MineBlock(int x, int y, int pickPower, Chest chest, HitTile hitTile) { hitTile.UpdatePosition(Main.tile[x, y].type, x, y); int num = 0; int tileId = hitTile.HitObject(x, y, 1); Tile tile = Main.tile[x, y]; if (Main.tileNoFail[(int)tile.type]) { num = 100; } if (Main.tileDungeon[(int)tile.type] || tile.type == 25 || tile.type == 58 || tile.type == 117 || tile.type == 203) { num += pickPower / 2; } else if (tile.type == 48 || tile.type == 232) { num += pickPower / 4; } else if (tile.type == 226) { num += pickPower / 4; } else if (tile.type == 107 || tile.type == 221) { num += pickPower / 2; } else if (tile.type == 108 || tile.type == 222) { num += pickPower / 3; } else if (tile.type == 111 || tile.type == 223) { num += pickPower / 4; } else if (tile.type == 211) { num += pickPower / 5; } else { TileLoader.MineDamage(pickPower, ref num); } if (tile.type == 211 && pickPower < 200) { num = 0; } if ((tile.type == 25 || tile.type == 203) && pickPower < 65) { num = 0; } else if (tile.type == 117 && pickPower < 65) { num = 0; } else if (tile.type == 37 && pickPower < 50) { num = 0; } else if (tile.type == 404 && pickPower < 65) { num = 0; } else if ((tile.type == 22 || tile.type == 204) && (double)y > Main.worldSurface && pickPower < 55) { num = 0; } else if (tile.type == 56 && pickPower < 65) { num = 0; } else if (tile.type == 58 && pickPower < 65) { num = 0; } else if ((tile.type == 226 || tile.type == 237) && pickPower < 210) { num = 0; } else if (Main.tileDungeon[(int)tile.type] && pickPower < 65) { if ((double)x < (double)Main.maxTilesX * 0.35 || (double)x > (double)Main.maxTilesX * 0.65) { num = 0; } } else if (tile.type == 107 && pickPower < 100) { num = 0; } else if (tile.type == 108 && pickPower < 110) { num = 0; } else if (tile.type == 111 && pickPower < 150) { num = 0; } else if (tile.type == 221 && pickPower < 100) { num = 0; } else if (tile.type == 222 && pickPower < 110) { num = 0; } else if (tile.type == 223 && pickPower < 150) { num = 0; } else { TileLoader.PickPowerCheck(tile, pickPower, ref num); } if (tile.type == 147 || tile.type == 0 || tile.type == 40 || tile.type == 53 || tile.type == 57 || tile.type == 59 || tile.type == 123 || tile.type == 224 || tile.type == 397) { num += pickPower; } if (tile.type == 165 || Main.tileRope[(int)tile.type] || tile.type == 199 || Main.tileMoss[(int)tile.type]) { num = 100; } if (hitTile.AddDamage(tileId, num, false) >= 100 && (tile.type == 2 || tile.type == 23 || tile.type == 60 || tile.type == 70 || tile.type == 109 || tile.type == 199 || Main.tileMoss[(int)tile.type])) { num = 0; } if (tile.type == 128 || tile.type == 269) { if (tile.frameX == 18 || tile.frameX == 54) { x--; tile = Main.tile[x, y]; hitTile.UpdatePosition(tileId, x, y); } if (tile.frameX >= 100) { num = 0; Main.blockMouse = true; } } if (tile.type == 334) { if (tile.frameY == 0) { y++; tile = Main.tile[x, y]; hitTile.UpdatePosition(tileId, x, y); } if (tile.frameY == 36) { y--; tile = Main.tile[x, y]; hitTile.UpdatePosition(tileId, x, y); } int i = (int)tile.frameX; bool flag = i >= 5000; bool flag2 = false; if (!flag) { int num2 = i / 18; num2 %= 3; x -= num2; tile = Main.tile[x, y]; if (tile.frameX >= 5000) { flag = true; } } if (flag) { i = (int)tile.frameX; int num3 = 0; while (i >= 5000) { i -= 5000; num3++; } if (num3 != 0) { flag2 = true; } } if (flag2) { num = 0; Main.blockMouse = true; } } if (!WorldGen.CanKillTile(x, y)) { num = 0; } if (hitTile.AddDamage(tileId, num, true) >= 100) { hitTile.Clear(tileId); if (Main.netMode == 2 && Main.tileContainer[(int)Main.tile[x, y].type]) { WorldGen.KillTile(x, y, true, false, false); NetMessage.SendData(17, -1, -1, "", 0, (float)x, (float)y, 1f, 0, 0, 0); if (TileLoader.IsChest((int)Main.tile[x, y].type)) { NetMessage.SendData(34, -1, -1, "", 1, (float)x, (float)y, 0f, 0, 0, 0); } if (TileLoader.IsDresser((int)Main.tile[x, y].type)) { NetMessage.SendData(34, -1, -1, "", 3, (float)x, (float)y, 0f, 0, 0, 0); } } else { int num4 = y; bool flag3 = Main.tile[x, num4].active(); WorldGen.KillTile(x, num4, false, false, false); if (Main.netMode == 2) { NetMessage.SendData(17, -1, -1, "", 0, (float)x, (float)num4, 0f, 0, 0, 0); } } } else { WorldGen.KillTile(x, y, true, false, false); if (Main.netMode == 2) { NetMessage.SendData(17, -1, -1, "", 0, (float)x, (float)y, 1f, 0, 0, 0); } } if (num != 0) { hitTile.Prune(); } }
// Adapted from the vanilla Player class method public static void SmartCursorLookup(Player player) { if (player.whoAmI != Main.myPlayer || !Main.SmartCursorEnabled || Main.SmartInteractShowingGenuine) { return; } try { Item item = player.inventory[player.selectedItem]; if (Main.SmartCursorShowing && item.pick > 0) { return; } int shovel = (item.modItem as BaseShovel)?.Shovel ?? 0; if (shovel <= 0) { return; } Vector2 MousePoss = Main.ReverseGravitySupport(Main.MouseScreen) + Main.screenPosition; int x = Utils.Clamp((int)(MousePoss.X / 16), 10, Main.maxTilesX - 10); int y = Utils.Clamp((int)(MousePoss.Y / 16), 10, Main.maxTilesY - 10); if (Main.tile[x, y] == null) { return; } bool DisableSmart = false; if (Main.tile[x, y].active()) { DisableSmart = CanDigTile(Main.tile[x, y].type, shovel); } TileLoader.DisableSmartCursor(Main.tile[x, y], ref DisableSmart); int tileBoost = item.tileBoost; int minX = (int)(player.position.X / 16) - Player.tileRangeX - tileBoost + 1; int maxX = (int)((player.position.X + player.width) / 16) + Player.tileRangeX + tileBoost - 1; int minY = (int)(player.position.Y / 16) - Player.tileRangeY - tileBoost + 1; int maxY = (int)((player.position.Y + player.height) / 16) + Player.tileRangeY + tileBoost - 2; minX = Utils.Clamp(minX, 10, Main.maxTilesX - 10); maxX = Utils.Clamp(maxX, 10, Main.maxTilesX - 10); minY = Utils.Clamp(minY, 10, Main.maxTilesY - 10); maxY = Utils.Clamp(maxY, 10, Main.maxTilesY - 10); if (DisableSmart && x >= minX && x <= maxX && y >= minY && y <= maxY) { return; } List <Tuple <int, int> > grapledTiles = new List <Tuple <int, int> >(); for (int i = 0; i < player.grapCount; i++) { Projectile projectile = Main.projectile[player.grappling[i]]; grapledTiles.Add(new Tuple <int, int>((int)(projectile.Center.X / 16), (int)(projectile.Center.Y / 16))); } int smartX = -1; int smartY = -1; if (PlayerInput.UsingGamepad) { Vector2 navigatorDirections = PlayerInput.Triggers.Current.GetNavigatorDirections(); Vector2 gamepadThumbstickLeft = PlayerInput.GamepadThumbstickLeft; Vector2 gamepadThumbstickRight = PlayerInput.GamepadThumbstickRight; if (navigatorDirections == Vector2.Zero && gamepadThumbstickLeft.Length() < 0.05f && gamepadThumbstickRight.Length() < 0.05f) { MousePoss = player.Center + new Vector2(player.direction * 1000, 0f); } } Vector2 MouseDir = MousePoss - player.Center; int leftOrRight = Math.Sign(MouseDir.X); int avobeOrBelow = Math.Sign(MouseDir.Y); if (Math.Abs(MouseDir.X) > Math.Abs(MouseDir.Y) * 3f) { avobeOrBelow = 0; MousePoss.Y = player.Center.Y; } if (Math.Abs(MouseDir.Y) > Math.Abs(MouseDir.X) * 3f) { leftOrRight = 0; MousePoss.X = player.Center.X; } int playerTileX = (int)(player.Center.X / 16); int playerTileY = (int)(player.Center.Y / 16); List <Tuple <int, int> > startTiles = new List <Tuple <int, int> >(); List <Tuple <int, int> > endTiles = new List <Tuple <int, int> >(); int notUpperCorners = avobeOrBelow == -1 && leftOrRight != 0 ? -1 : 1; int sideSearchX = (int)((player.position.X + player.width / 2 + ((player.width / 2 - 1) * leftOrRight)) / 16); int topSearchY = (int)(notUpperCorners == -1 ? (player.position.Y + player.height - 1f) / 16 : (player.position.Y + 0.1f) / 16); int widthInTiles = player.width / 16 + ((player.width % 16 == 0) ? 0 : 1); int heightInTiles = player.height / 16 + ((player.height % 16 == 0) ? 0 : 1); if (leftOrRight != 0) { for (int i = 0; i < heightInTiles; i++) { if (Main.tile[sideSearchX, topSearchY + i * notUpperCorners] == null) { return; } startTiles.Add(new Tuple <int, int>(sideSearchX, topSearchY + i * notUpperCorners)); } } if (avobeOrBelow != 0) { for (int i = 0; i < widthInTiles; i++) { if (Main.tile[(int)(player.position.X / 16f) + i, topSearchY] == null) { return; } startTiles.Add(new Tuple <int, int>((int)(player.position.X / 16f) + i, topSearchY)); } } int endX = (int)((MousePoss.X + ((player.width / 2 - 1) * leftOrRight)) / 16); int endY = (int)((MousePoss.Y + 0.1f - (player.height / 2 + 1)) / 16); if (notUpperCorners == -1) { endY = (int)((MousePoss.Y + (player.height / 2) - 1f) / 16); } if (player.gravDir == -1f && avobeOrBelow == 0) { endY++; } if (endY < 10) { endY = 10; } if (endY > Main.maxTilesY - 10) { endY = Main.maxTilesY - 10; } if (leftOrRight != 0) { for (int i = 0; i < heightInTiles; i++) { if (Main.tile[endX, endY + i * notUpperCorners] == null) { return; } endTiles.Add(new Tuple <int, int>(endX, endY + i * notUpperCorners)); } } if (avobeOrBelow != 0) { for (int i = 0; i < widthInTiles; i++) { if (Main.tile[(int)((MousePoss.X - (player.width / 2)) / 16f) + i, endY] == null) { return; } endTiles.Add(new Tuple <int, int>((int)((MousePoss.X - (player.width / 2)) / 16f) + i, endY)); } } List <Tuple <int, int> > validTiles = new List <Tuple <int, int> >(); while (startTiles.Count > 0) { Tuple <int, int> tuple = startTiles[0]; Tuple <int, int> tuple2 = endTiles[0]; if (!Collision.TupleHitLine(tuple.Item1, tuple.Item2, tuple2.Item1, tuple2.Item2, leftOrRight * (int)player.gravDir, -avobeOrBelow * (int)player.gravDir, grapledTiles, out Tuple <int, int> tuple3)) { startTiles.Remove(tuple); endTiles.Remove(tuple2); } else { if (tuple3.Item1 != tuple2.Item1 || tuple3.Item2 != tuple2.Item2) { validTiles.Add(tuple3); } Tile tile2 = Main.tile[tuple3.Item1, tuple3.Item2]; if (!tile2.inActive() && tile2.active() && Main.tileSolid[tile2.type] && !Main.tileSolidTop[tile2.type] && !grapledTiles.Contains(tuple3)) { validTiles.Add(tuple3); } startTiles.Remove(tuple); endTiles.Remove(tuple2); } } List <Tuple <int, int> > tilesToRemove = new List <Tuple <int, int> >(); for (int i = 0; i < validTiles.Count; i++) { if (DigPower(Main.tile[validTiles[i].Item1, validTiles[i].Item2].type, shovel) < 100 || !WorldGen.CanKillTile(validTiles[i].Item1, validTiles[i].Item2)) { tilesToRemove.Add(validTiles[i]); } } for (int i = 0; i < tilesToRemove.Count; i++) { validTiles.Remove(tilesToRemove[i]); } tilesToRemove.Clear(); if (validTiles.Count > 0) { float distance = -1f; Tuple <int, int> tuple4 = validTiles[0]; for (int i = 0; i < validTiles.Count; i++) { float cdistance = Vector2.DistanceSquared(new Vector2(validTiles[i].Item1, validTiles[i].Item2) * 16 + Vector2.One * 8, player.Center); if (distance == -1f || cdistance < distance) { distance = cdistance; tuple4 = validTiles[i]; } } if (Collision.InTileBounds(tuple4.Item1, tuple4.Item2, minX, minY, maxX, maxY)) { smartX = tuple4.Item1; smartY = tuple4.Item2; } } startTiles.Clear(); endTiles.Clear(); validTiles.Clear(); if (smartX != -1 && smartY != -1) { Main.SmartCursorX = (Player.tileTargetX = smartX); Main.SmartCursorY = (Player.tileTargetY = smartY); Main.SmartCursorShowing = true; } grapledTiles.Clear(); } catch { Main.SmartCursorEnabled = false; } }
private bool CanGetPastTile(int x, int y) { if (WorldGen.CheckTileBreakability(x, y) != 0) { return(false); } Tile tile = Main.tile[x, y]; return((!tile.active() || !TileID.Sets.Falling[(int)tile.type]) && (!tile.active() || WorldGen.CanKillTile(x, y))); }
private void PlaceThing(Hook.Player.orig_PlaceThing orig, Player self) { int createTile = self.HeldItem.createTile; if (createTile == TileID.Torches || (TileLoader.GetTile(createTile)?.torch ?? false)) { orig(self); return; } Tile tile = Main.tile[Player.tileTargetX, Player.tileTargetY]; Tile tile2 = Main.tile[Player.tileTargetX, Player.tileTargetY + 1]; ushort wall = tile2.wall; if (PlaceThingChecks(self) && createTile > -1 && TileCompatCheck(tile.type, tile.frameX, createTile, self.HeldItem.placeStyle) && tile.active()) { int selected = self.selectedItem; if (Main.tileHammer[tile.type]) { bool breakTile = Main.tileNoFail[tile.type]; if (!breakTile && WorldGen.CanKillTile(Player.tileTargetX, Player.tileTargetY)) { self.selectedItem = GetBestToolSlot(self, out int power, toolType: Hammer); if (tile.type == TileID.DemonAltar && (power < 80 || !Main.hardMode)) { self.Hurt(PlayerDeathReason.ByOther(4), self.statLife / 2, -self.direction); } } if (breakTile) { WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY); SetWall(tile2); if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, Player.tileTargetX, Player.tileTargetY); } } } else if (!(Main.tileAxe[tile.type] || Main.tileHammer[tile.type])) { if (!Main.tileContainer[tile.type]) { self.selectedItem = GetBestToolSlot(self, out int power, toolType: Pickaxe); self.PickTile(Player.tileTargetX, Player.tileTargetY, power); if (self.hitTile.data[0].damage > 0) { AchievementsHelper.CurrentlyMining = true; self.hitTile.Clear(0); WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY); SetWall(tile2); AchievementsHelper.HandleMining(); if (Main.netMode == NetmodeID.MultiplayerClient) { NetMessage.SendData(MessageID.TileChange, -1, -1, null, 0, Player.tileTargetX, Player.tileTargetY); } AchievementsHelper.CurrentlyMining = false; } else if (!tile.active()) { tile.ResetToType(0); tile.active(false); SetWall(tile2); } } } self.selectedItem = selected; } if (Main.netMode == NetmodeID.MultiplayerClient) { ushort t = tile.type; orig(self); if (tile.type != t) { NetMessage.SendData(MessageID.TileChange, -1, -1, null, tile.type, Player.tileTargetX, Player.tileTargetY); } } else { orig(self); } tile2.wall = wall; }