// 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 void PlaceThing(Hook.Player.orig_PlaceThing orig, Player self) { if (disableMod && IsNetSynced) { return; } 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]; if (!tile.active()) { orig(self); return; } ushort oldType = tile.type; ushort wall = tile2.wall; Chest chest = null; int targetOffsetX = 0; int targetOffsetY = 0; int targetSizeX = 0; int targetSizeY = 0; byte oldSlope = tile.slope(); bool oldHalfBrick = tile.halfBrick(); short oldFrameX = -1; short oldFrameY = -1; if (Main.tileFrameImportant[tile.type]) //TileID.Sets.Platforms[tile.type] { oldFrameX = tile.frameX; oldFrameY = tile.frameY; } bool chestSwapping = false; if (PlaceThingChecks(self) && createTile > -1 && TileCompatCheck(tile, createTile, self.HeldItem.placeStyle) && tile.active()) { int selected = self.selectedItem; if (!(Main.tileAxe[tile.type] || Main.tileHammer[tile.type])) { if (Main.tileContainer[tile.type] && Main.tileContainer[createTile]) { TileObjectData objectData = TileObjectData.GetTileData(tile.type, 0); int cIndex = Chest.FindChest(Player.tileTargetX, Player.tileTargetY - (objectData.Height - 1)); if (cIndex != -1) { targetSizeX = objectData.Width - 1; targetSizeY = objectData.Height - 1; targetOffsetY = -targetSizeY; if ((IsNetSynced || Main.netMode == 0) && Chest.UsingChest(cIndex) == -1 && !Chest.isLocked(Player.tileTargetX, Player.tileTargetY - 1)) { chest = Main.chest[cIndex]; chest.y++; chestSwapping = true; } else { orig(self); return; } } } self.selectedItem = GetBestToolSlot(self, out int power, toolType: Pickaxe); if (power <= 0) { orig(self); return; } clientSwapping = true; try { blockKillTileChestCheck = true; if (!chestSwapping) { self.PickTile(Player.tileTargetX, Player.tileTargetY, power); } if (chestSwapping || hitTileLastDamage > 0 || (Sets.Grass[oldType] && tile.type == Dirt)) { AchievementsHelper.CurrentlyMining = true; //if(hitID > -1)self.hitTile.Clear(hitID); if (Main.netMode == NetmodeID.MultiplayerClient) { clientSwapping = false; } if (tile.active()) { self.PickTile(Player.tileTargetX, Player.tileTargetY, ushort.MaxValue); } if (Main.netMode == NetmodeID.SinglePlayer) { clientSwapping = false; } //WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY); SetWall(tile2); AchievementsHelper.HandleMining(); AchievementsHelper.CurrentlyMining = false; }/* else if(!tile.active()) { * SetWall(tile2); * }*/ else { self.itemTime = 0; BlockSwapPlayer.triggerItemTime = true; } } finally { blockKillTileChestCheck = false; clientSwapping = false; } } self.selectedItem = selected; } if (Main.netMode == NetmodeID.MultiplayerClient) { if (chestSwapping) { int tSX = targetSizeX + 1; int tSY = targetSizeY + 1; int x = Player.tileTargetX + targetOffsetX; int y = Player.tileTargetY + targetOffsetY; for (int i = 0; i < tSX; i++) { for (int j = 0; j < tSY; j++) { if (Main.tile[x + i, y + j].type == oldType) { Main.tile[x + i, y + j].type = 0; Main.tile[x + i, y + j].active(false); } } } } try { blockChestHooks = true; orig(self); } finally { blockChestHooks = false; } if (tile.type != oldType || (Main.tileFrameImportant[tile.type] && (oldFrameX == tile.frameX || oldFrameY == tile.frameY))) { tile2.wall = wall; tile.slope(oldSlope); tile.halfBrick(oldHalfBrick); if (TileID.Sets.Platforms[tile.type]) { tile.frameX = oldFrameX; } WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY); NetMessage.SendTileRange(Main.myPlayer, Player.tileTargetX + targetOffsetX, Player.tileTargetY + targetOffsetY, targetSizeX, targetSizeY); if (chestSwapping) { targetSizeX++; targetSizeY++; ModPacket packet = GetPacket(1 + (4 * 2) + (targetSizeX * targetSizeY * 3 * 2)); packet.Write((byte)0); int x = Player.tileTargetX + targetOffsetX; int y = Player.tileTargetY + targetOffsetY; packet.Write((short)x); packet.Write((short)y); packet.Write((short)targetSizeX); packet.Write((short)targetSizeY); for (int i = 0; i < targetSizeX; i++) { for (int j = 0; j < targetSizeY; j++) { packet.Write(Main.tile[x + i, y + j].type); packet.Write(Main.tile[x + i, y + j].frameX); packet.Write(Main.tile[x + i, y + j].frameY); Main.tile[x + i, y + j].active(true); } } packet.Send(); } //NetMessage.SendData(MessageID.TileChange, -1, -1, null, GetTileNetType(tile.type), Player.tileTargetX, Player.tileTargetY); } } else { orig(self); if (tile.type != oldType || (Main.tileFrameImportant[tile.type] && (oldFrameX == tile.frameX || oldFrameY == tile.frameY))) { tile2.wall = wall; tile.slope(oldSlope); tile.halfBrick(oldHalfBrick); if (TileID.Sets.Platforms[tile.type]) { tile.frameX = oldFrameX; } WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY); } } if (!(chest is null)) { chest.y--; } }
public void PickTile2(int x, int y, int pickPower, Tiles.AutoPicker autoPicker) { int num8 = 0; int tileId = hitTile.HitObject(x, y, 1); Tile tile = Main.tile[x, y]; if (Main.tileNoFail[tile.type]) { num8 = 100; } if (Main.tileDungeon[tile.type] || tile.type == 25 || tile.type == 58 || tile.type == 117 || tile.type == 203) { num8 += pickPower / 2; } else if (tile.type == 48 || tile.type == 232) { num8 += pickPower / 4; } else if (tile.type == 226) { num8 += pickPower / 4; } else if (tile.type == 107 || tile.type == 221) { num8 += pickPower / 2; } else if (tile.type == 108 || tile.type == 222) { num8 += pickPower / 3; } else if (tile.type == 111 || tile.type == 223) { num8 += pickPower / 4; } else if (tile.type == 211) { num8 += pickPower / 5; } else { TileLoader.MineDamage(pickPower, ref num8); } if (tile.type == 211 && pickPower < 200) { num8 = 0; } if ((tile.type == 25 || tile.type == 203) && pickPower < 65) { num8 = 0; } else if (tile.type == 117 && pickPower < 65) { num8 = 0; } else if (tile.type == 37 && pickPower < 50) { num8 = 0; } else if (tile.type == 404 && pickPower < 65) { num8 = 0; } else if ((tile.type == 22 || tile.type == 204) && (double)y > Main.worldSurface && pickPower < 55) { num8 = 0; } else if (tile.type == 56 && pickPower < 65) { num8 = 0; } else if (tile.type == 58 && pickPower < 65) { num8 = 0; } else if ((tile.type == 226 || tile.type == 237) && pickPower < 210) { num8 = 0; } else if (Main.tileDungeon[tile.type] && pickPower < 65) { if ((double)x < (double)Main.maxTilesX * 0.35 || (double)x > (double)Main.maxTilesX * 0.65) { num8 = 0; } } else if (tile.type == 107 && pickPower < 100) { num8 = 0; } else if (tile.type == 108 && pickPower < 110) { num8 = 0; } else if (tile.type == 111 && pickPower < 150) { num8 = 0; } else if (tile.type == 221 && pickPower < 100) { num8 = 0; } else if (tile.type == 222 && pickPower < 110) { num8 = 0; } else if (tile.type == 223 && pickPower < 150) { num8 = 0; } else { TileLoader.PickPowerCheck(tile, pickPower, ref num8); } 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) { num8 += pickPower; } if (tile.type == 165 || Main.tileRope[tile.type] || tile.type == 199 || Main.tileMoss[tile.type]) { num8 = 100; } if (hitTile.AddDamage(tileId, num8, updateAmount: false) >= 100 && (tile.type == 2 || tile.type == 23 || tile.type == 60 || tile.type == 70 || tile.type == 109 || tile.type == 199 || Main.tileMoss[tile.type])) { num8 = 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) { num8 = 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 j = tile.frameX; bool flag3 = j >= 5000; bool flag2 = false; if (!flag3) { int num7 = j / 18; num7 %= 3; x -= num7; tile = Main.tile[x, y]; if (tile.frameX >= 5000) { flag3 = true; } } if (flag3) { j = tile.frameX; int num5 = 0; while (j >= 5000) { j -= 5000; num5++; } if (num5 != 0) { flag2 = true; } } if (flag2) { num8 = 0; Main.blockMouse = true; } } if (!Terraria.WorldGen.CanKillTile(x, y)) { num8 = 0; } if (hitTile.AddDamage(tileId, num8) >= 100) { AchievementsHelper.CurrentlyMining = true; hitTile.Clear(tileId); if (Main.netMode == 1 && Main.tileContainer[Main.tile[x, y].type]) { WorldGen.AutoPicker.KillTile2(autoPicker, x, y, fail: true); NetMessage.SendData(17, -1, -1, null, 0, x, y, 1f); 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, x, y); } if (Main.tile[x, y].type == 467) { NetMessage.SendData(34, -1, -1, null, 5, x, y); } if (TileLoader.IsDresser(Main.tile[x, y].type)) { NetMessage.SendData(34, -1, -1, null, 3, x, y); } if (Main.tile[x, y].type >= 470 && TileID.Sets.BasicChest[Main.tile[x, y].type]) { NetMessage.SendData(34, -1, -1, null, 101, x, y, 0f, 0, Main.tile[x, y].type); } if (Main.tile[x, y].type >= 470 && TileLoader.IsDresser(Main.tile[x, y].type)) { NetMessage.SendData(34, -1, -1, null, 103, x, y, 0f, 0, Main.tile[x, y].type); } } else { int num4 = y; bool num9 = Main.tile[x, num4].active(); WorldGen.AutoPicker.KillTile2(autoPicker, x, num4); if (num9 && !Main.tile[x, num4].active()) { AchievementsHelper.HandleMining(); } if (Main.netMode == 1) { NetMessage.SendData(17, -1, -1, null, 0, x, num4); } } AchievementsHelper.CurrentlyMining = false; } else { WorldGen.AutoPicker.KillTile2(autoPicker, x, y, fail: true); if (Main.netMode == 1) { NetMessage.SendData(17, -1, -1, null, 0, x, y, 1f); } } if (num8 != 0) { hitTile.Prune(); } }
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; }