/*public override void PreUpdate() * { * TorchTimerSin = (float)Math.Sin((float)Main.GameUpdateCount * 0.01); * //Main.NewText(TorchTimerSin); * * int gravelType1 = mod.TileEntityType<Tiles.GravelEntity>(); * * //if (Main.netMode == 0) * //{ * //1/4 the speed * if (DoubleToggle1)//hacky gravel that works but corrupts worlds with TEs * { * if (DoubleToggle2) * { * * foreach (var item in TileEntity.ByID.ToList()) * { * if (item.Value.type == gravelType1) * { * var gravel1 = item.Value as Tiles.GravelEntity; * Vector2 entityPos = gravel1.TileEntPos(); * * * * //Checks if within world bounds * if (entityPos.X > 10 && entityPos.X < Main.maxTilesX - 10 && entityPos.Y > 10 && entityPos.Y < Main.maxTilesY - 10) * { * //Down * if (WorldGen.EmptyTileCheck((int)entityPos.X, (int)entityPos.X, (int)entityPos.Y + 1, (int)entityPos.Y + 1)) * { * if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.Gravel>()) * {//Gravel * WorldGen.PlaceTile((int)entityPos.X, (int)entityPos.Y + 1, mod.TileType<Tiles.Gravel>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * else if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.SandRed>()) * {//Red Sand * WorldGen.PlaceTile((int)entityPos.X, (int)entityPos.Y + 1, mod.TileType<Tiles.SandRed>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * * ModTileEntity.PlaceEntityNet((int)entityPos.X, (int)entityPos.Y + 1, mod.TileEntityType<Tiles.GravelEntity>()); * * WorldGen.KillTile((int)entityPos.X, (int)entityPos.Y, false, false, true); //sound is the break sound for tile, use custom * NetMessage.SendData(17, -1, -1, null, 0, (float)(int)entityPos.X, (float)(int)entityPos.Y, 0f, 0, 0, 0); * } * else //If not down then this * { * switch (WorldGen.genRand.Next(2)) //choose to fall downleft or down right * { * case 0://Down left, and then down right if fail * if (WorldGen.EmptyTileCheck((int)entityPos.X - 1, (int)entityPos.X - 1, (int)entityPos.Y + 1, (int)entityPos.Y + 1)) * { * if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.Gravel>()) * {//Gravel * WorldGen.PlaceTile((int)entityPos.X - 1, (int)entityPos.Y + 1, mod.TileType<Tiles.Gravel>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * else if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.SandRed>()) * {//Red Sand * WorldGen.PlaceTile((int)entityPos.X - 1, (int)entityPos.Y + 1, mod.TileType<Tiles.SandRed>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * ModTileEntity.PlaceEntityNet((int)entityPos.X - 1, (int)entityPos.Y + 1, mod.TileEntityType<Tiles.GravelEntity>()); * * WorldGen.KillTile((int)entityPos.X, (int)entityPos.Y, false, false, true); * NetMessage.SendData(17, -1, -1, null, 0, (float)(int)entityPos.X, (float)(int)entityPos.Y, 0f, 0, 0, 0); * } * else if (WorldGen.EmptyTileCheck((int)entityPos.X + 1, (int)entityPos.X + 1, (int)entityPos.Y + 1, (int)entityPos.Y + 1)) * { * if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.Gravel>()) * {//Gravel * WorldGen.PlaceTile((int)entityPos.X + 1, (int)entityPos.Y + 1, mod.TileType<Tiles.Gravel>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * else if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.SandRed>()) * {//Red Sand * WorldGen.PlaceTile((int)entityPos.X + 1, (int)entityPos.Y + 1, mod.TileType<Tiles.SandRed>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * ModTileEntity.PlaceEntityNet((int)entityPos.X + 1, (int)entityPos.Y + 1, mod.TileEntityType<Tiles.GravelEntity>()); * * WorldGen.KillTile((int)entityPos.X, (int)entityPos.Y, false, false, true); * NetMessage.SendData(17, -1, -1, null, 0, (float)(int)entityPos.X, (float)(int)entityPos.Y, 0f, 0, 0, 0); * } * break; * case 1://Down right, and then down left if fail * if (WorldGen.EmptyTileCheck((int)entityPos.X + 1, (int)entityPos.X + 1, (int)entityPos.Y + 1, (int)entityPos.Y + 1)) * { * if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.Gravel>()) * {//Gravel * WorldGen.PlaceTile((int)entityPos.X + 1, (int)entityPos.Y + 1, mod.TileType<Tiles.Gravel>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * else if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.SandRed>()) * {//Red Sand * WorldGen.PlaceTile((int)entityPos.X + 1, (int)entityPos.Y + 1, mod.TileType<Tiles.SandRed>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * ModTileEntity.PlaceEntityNet((int)entityPos.X + 1, (int)entityPos.Y + 1, mod.TileEntityType<Tiles.GravelEntity>()); * * WorldGen.KillTile((int)entityPos.X, (int)entityPos.Y, false, false, true); * NetMessage.SendData(17, -1, -1, null, 0, (float)(int)entityPos.X, (float)(int)entityPos.Y, 0f, 0, 0, 0); * } * else if (WorldGen.EmptyTileCheck((int)entityPos.X - 1, (int)entityPos.X - 1, (int)entityPos.Y + 1, (int)entityPos.Y + 1)) * { * if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.Gravel>()) * {//Gravel * WorldGen.PlaceTile((int)entityPos.X - 1, (int)entityPos.Y + 1, mod.TileType<Tiles.Gravel>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * else if (Main.tile[(int)entityPos.X, (int)entityPos.Y].type == mod.TileType<Tiles.SandRed>()) * {//Red Sand * WorldGen.PlaceTile((int)entityPos.X - 1, (int)entityPos.Y + 1, mod.TileType<Tiles.SandRed>(), true, true); * WorldGen.SquareTileFrame((int)entityPos.X, (int)entityPos.Y, true); * NetMessage.SendTileSquare(-1, (int)entityPos.X, (int)entityPos.Y, 2, TileChangeType.None); * } * ModTileEntity.PlaceEntityNet((int)entityPos.X - 1, (int)entityPos.Y + 1, mod.TileEntityType<Tiles.GravelEntity>()); * * WorldGen.KillTile((int)entityPos.X, (int)entityPos.Y, false, false, true); * NetMessage.SendData(17, -1, -1, null, 0, (float)(int)entityPos.X, (float)(int)entityPos.Y, 0f, 0, 0, 0); * } * break; * } * } * //else * //{ * //Main.NewText("Occupied (Y - 1)" + (int)entityPos.X + ", " + (int)entityPos.Y); * //} * } * } * } * DoubleToggle2 = false; * } * else * { * DoubleToggle2 = true; * } * DoubleToggle1 = false; * } * else * { * DoubleToggle1 = true; * } * //} * }*/ /*public override void PostDrawTiles() //gravel version, debug * { * Main.spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); * Vector2 zero = new Vector2(Main.offScreenRange, Main.offScreenRange); * int gravelType1 = mod.TileEntityType<Tiles.GravelEntity>(); * foreach (var item in TileEntity.ByID) * { * if(item.Value.type == gravelType1) * { * var gravel1 = item.Value as Tiles.GravelEntity; * Vector2 entityPos = gravel1.TileEntPos(); * //Main.NewText("Draw Ship" + entityPos.X + entityPos.Y); * //ErrorLogger.Log("DrawShip" + entityPos.X + entityPos.Y); * Texture2D texture = mod.GetTexture("Items/FlagRed"); * VisualPlayer modPlayer = Main.LocalPlayer.GetModPlayer<VisualPlayer>(); * * if (modPlayer.ShowBlocks) * { * Main.spriteBatch.Draw(texture, new Vector2(entityPos.X * 16 - (int)Main.screenPosition.X - 204, (entityPos.Y * 16 - (int)Main.screenPosition.Y) - 220) + zero, new Rectangle(0, 0, texture.Width, texture.Height), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); * } * } * } * Main.spriteBatch.End(); * }*/ public override void PostDrawTiles() { Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); Rectangle screenRect = new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight); Vector2 zero = new Vector2(Main.offScreenRange, Main.offScreenRange); const int range = 50; int shipType1 = ModContent.TileEntityType <Tiles.EntityT1>(); foreach (var item in TileEntity.ByID) { if (item.Value.type == shipType1) { var ship1 = item.Value as Tiles.EntityT1; Vector2 entityPos = ship1.TileEntPos(); Rectangle DrawArea = new Rectangle(((int)entityPos.X + 1) * 16 - range * 16, ((int)entityPos.Y + 1) * 16 - range * 16, range * 16 * 2, range * 16 * 2); //Main.NewText("Draw Ship" + entityPos.X + entityPos.Y); //ErrorLogger.Log("DrawShip" + entityPos.X + entityPos.Y); if (screenRect.Intersects(DrawArea)) { Texture2D texture = mod.GetTexture("Tiles/T1"); Main.spriteBatch.Draw(texture, new Vector2(entityPos.X * 16 - (int)Main.screenPosition.X - 752, (entityPos.Y * 16 - (int)Main.screenPosition.Y) - 200) + zero, new Rectangle(0, 0, texture.Width, texture.Height), Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } } } Main.spriteBatch.End(); }
public override void NPCLoot(NPC npc) { if (npc.lastInteraction == 255) { //Main.NewText("Accidental Death, score unchanged"); return; } int TEScoreBoardType = ModContent.TileEntityType <TEScoreBoard>(); foreach (TileEntity current in TileEntity.ByID.Values) { if (current.type == TEScoreBoardType) { //QuickBox is a neat tool for visualizing things while modding. //Dust.QuickBox(npc.position, npc.position + new Vector2(npc.width, npc.height), 1, Color.White, null); var scoreboard = current as TEScoreBoard; if (scoreboard.GetPlayArea().Intersects(npc.getRect())) { Player scoringPlayer = Main.player[npc.lastInteraction]; int score = 0; // Using HalfVector2 and ReinterpretCast.UIntAsFloat is a way to pack a Vector2 into a single float variable. HalfVector2 halfVector = new HalfVector2((current.Position.X + 1) * 16, (current.Position.Y + 1) * 16); Projectile.NewProjectile(npc.Center, Vector2.Zero, ModContent.ProjectileType <Projectiles.ScorePoint>(), 0, 0, Main.myPlayer, ReLogic.Utilities.ReinterpretCast.UIntAsFloat(halfVector.PackedValue), npc.lastInteraction); scoreboard.scores.TryGetValue(scoringPlayer.name, out score); scoreboard.scores[scoringPlayer.name] = score + 1; if (Main.dedServ) { NetworkText text = NetworkText.FromFormattable("{0}: {1}", scoringPlayer.name, scoreboard.scores[scoringPlayer.name]); NetMessage.BroadcastChatMessage(text, Color.White); } else { Main.NewText(scoringPlayer.name + ": " + scoreboard.scores[scoringPlayer.name]); } scoreboard.scoresChanged = true; } } } }
// In ExampleMod, we use PostDrawTiles to draw the TEScoreBoard area. PostDrawTiles draws before players, npc, and projectiles, so it works well. public override void PostDrawTiles() { Main.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, Main.DefaultSamplerState, DepthStencilState.None, Main.instance.Rasterizer, null, Main.GameViewMatrix.TransformationMatrix); var screenRect = new Rectangle((int)Main.screenPosition.X, (int)Main.screenPosition.Y, Main.screenWidth, Main.screenHeight); screenRect.Inflate(TEScoreBoard.drawBorderWidth, TEScoreBoard.drawBorderWidth); int scoreBoardType = ModContent.TileEntityType <TEScoreBoard>(); foreach (var item in TileEntity.ByID) { if (item.Value.type == scoreBoardType) { var scoreBoard = item.Value as TEScoreBoard; Rectangle scoreBoardArea = scoreBoard.GetPlayArea(); // We only want to draw while the area is visible. if (screenRect.Intersects(scoreBoardArea)) { scoreBoardArea.Offset((int)-Main.screenPosition.X, (int)-Main.screenPosition.Y); DrawBorderedRect(Main.spriteBatch, Color.LightBlue * 0.1f, Color.Blue * 0.3f, scoreBoardArea.TopLeft(), scoreBoardArea.Size(), TEScoreBoard.drawBorderWidth); } } } Main.spriteBatch.End(); }
public static bool Spawn(int i, int j) { bool success = WorldGen.PlaceTile(i, j, ModContent.TileType <CrimsonPustuleTile>(), style: Main.rand.Next(3)); if (!success) { return(false); } ModContent.GetInstance <CrimsonPustuleTileEntity>().Place(i, j); if (Main.netMode == NetmodeID.Server) { NetMessage.SendData(MessageID.TileEntityPlacement, -1, -1, null, i, j, ModContent.TileEntityType <CrimsonPustuleTileEntity>(), 0f, 0, 0, 0); NetMessage.SendTileSquare(-1, i, j, 2); } return(true); }
//public override void ModifySunLightColor(ref Color tileColor, ref Color backgroundColor) //{ // //int worldID = GetCurrentWorldID(); // //if (worldID == -1)//ship // //{ // // backgroundColor = Color.Black; // //} // //else if (planetArray[worldID].blackSky)//else, if subworld has blacksky set to true // //{ // // backgroundColor = Color.Black; // //}; //} public override void MidUpdateTimeWorld() { if (Subworld.AnyActive <PlanetMod>()) //lotta stuff copied from vanilla { Main.UpdateSundial(); Main.time += Main.dayRate; Terraria.GameContent.Events.BirthdayParty.UpdateTime(); Terraria.GameContent.Events.DD2Event.UpdateTime(); if (Main.time > 54000 && Main.dayTime) //replace main.daytime with speed adjust (add/mult) { Main.time = 0; Main.dayTime = !Main.dayTime; } else if (Main.time > 32400 && !Main.dayTime) { if (Main.fastForwardTime) { Main.fastForwardTime = false; Main.UpdateSundial(); } Main.checkXMas(); Main.checkHalloween(); Main.AnglerQuestSwap(); Terraria.GameContent.Events.BirthdayParty.CheckMorning(); Main.time = 0; Main.dayTime = !Main.dayTime; if (Main.sundialCooldown > 0) { Main.sundialCooldown--; } Main.moonPhase++; if (Main.moonPhase >= 8) { Main.moonPhase = 0; } } UpdateTime_SpawnTownNPCs(); //not 100% sure if this is the right place } if (IsTeleporting) { if (TeleportTimer >= TeleportTimerMax - 1) { //planetWorld.IsTeleporting = false; //these are now set in Init() in modworld //TeleportTimer = 0; if (Main.netMode != NetmodeID.MultiplayerClient) { TeleportCorrectWorld(true); //teleports after animation ends } } else { TeleportTimer++; } } //this is gonna desync, but I dont think it will be an issue, maybe only run on single or multi client int tileEntityType = ModContent.TileEntityType <Tiles.PlasmaEntity>(); foreach (var item in TileEntity.ByID) { if (item.Value.type == tileEntityType) { var currentEntity = item.Value as Tiles.PlasmaEntity; Point16 curEntPos = currentEntity.EntityPosition(); if (Main.tile[curEntPos.X, curEntPos.Y].frameX == 0) { currentEntity.PlasmaInstance.UpdatePlasma(); } } } SelectedPlanet = (ushort)PlanetID.Moon; //debug }
public override bool?UseItem(Player player) { Tile tile = Framing.GetTileSafely(Player.tileTargetX, Player.tileTargetY); if (tile.TileType == TileID.Containers || TileID.Sets.BasicChest[tile.TileType]) { int xOff = tile.TileFrameX % 36 / 18; int yOff = tile.TileFrameY % 36 / 18; if (player.altFunctionUse == 2) { if (TileEntity.ByPosition.ContainsKey(new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff))) { var chestEntity = TileEntity.ByPosition[new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff)] as ChestEntity; UIRenderer.ChestCustomizer.ruleElements.Clear(); for (int k = 0; k < chestEntity.rules.Count; k++) { var rule = chestEntity.rules[k].Clone(); var elem = new ChestRuleElement(rule); if (rule is ChestRuleGuaranteed) { elem = new GuaranteedRuleElement(rule); } if (rule is ChestRuleChance) { elem = new ChanceRuleElement(rule); } if (rule is ChestRulePool) { elem = new PoolRuleElement(rule); } if (rule is ChestRulePoolChance) { elem = new PoolChanceRuleElement(rule); } UIRenderer.ChestCustomizer.ruleElements.Add(elem); } } else { UIRenderer.ChestCustomizer.ruleElements.Clear(); } Main.NewText($"Copied chest rules from chest at {new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff)}"); } else { bool overwrite = TileEntity.ByPosition.ContainsKey(new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff)); TileEntity.PlaceEntityNet(Player.tileTargetX - xOff, Player.tileTargetY - yOff, ModContent.TileEntityType <ChestEntity>()); bool cleared = !UIRenderer.ChestCustomizer.SetData(TileEntity.ByPosition[new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff)] as ChestEntity); if (overwrite) { if (cleared) { Main.NewText($"Removed chest rules for chest at {new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff)}", Color.Orange); } else { Main.NewText($"Overwritten chest rules for chest at {new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff)}", Color.Yellow); } } else if (!cleared) { Main.NewText($"Set chest rules for chest at {new Point16(Player.tileTargetX - xOff, Player.tileTargetY - yOff)}", Color.GreenYellow); } } } if (player.altFunctionUse == 2) { ChestCustomizerState.Visible = true; } return(true); }