From 417f4923e7d94dfb7da93554fc989afc205a7119 Mon Sep 17 00:00:00 2001 From: Abdulmujeeb Raji Date: Wed, 13 Nov 2024 12:06:34 +0000 Subject: [PATCH] feat: coal world gen + world gen test framework --- Content/Systems/WorldGenSystem.cs | 54 ++++++++++++++++++++++++ Content/Tiles/CoalTile.cs | 2 + Localization/en-US_Mods.continuity.hjson | 3 +- Properties/launchSettings.json | 28 ++++++------ Utilities/WorldGenWorld.cs | 33 +++++++++++++++ continuity.csproj | 3 -- 6 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 Content/Systems/WorldGenSystem.cs create mode 100644 Utilities/WorldGenWorld.cs diff --git a/Content/Systems/WorldGenSystem.cs b/Content/Systems/WorldGenSystem.cs new file mode 100644 index 0000000..6525fcf --- /dev/null +++ b/Content/Systems/WorldGenSystem.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Terraria.ID; +using Terraria; +using Terraria.IO; +using Terraria.Localization; +using Terraria.ModLoader; +using Terraria.WorldBuilding; +using continuity.Content.Tiles; + +namespace continuity.Content.Systems +{ + public class WorldGenSystem : ModSystem + { + public static LocalizedText CoalGenMessage { get; private set; } + + public override void SetStaticDefaults() + { + CoalGenMessage = Language.GetOrRegister(Mod.GetLocalizationKey($"WorldGen.{nameof(CoalGenMessage)}")); + } + + public override void ModifyWorldGenTasks(List tasks, ref double totalWeight) + { + int ShiniesIndex = tasks.FindIndex(genpass => genpass.Name.Equals("Shinies")); + if (ShiniesIndex != -1) + { + tasks.Insert(ShiniesIndex + 1, new CoalGenPass("Adding Coal to the surface layer of the world", 100)); + } + } + } + + public class CoalGenPass : GenPass + { + public CoalGenPass(string name, float loadWeight) : base(name, loadWeight) { } + + protected override void ApplyPass(GenerationProgress progress, GameConfiguration configuration) + { + progress.Message = WorldGenSystem.CoalGenMessage.Value; + + for (int k = 0; k < (int)((Main.maxTilesX * Main.maxTilesY) * 1E-03); k++) + { + int x = WorldGen.genRand.Next(0, Main.maxTilesX); + int y = WorldGen.genRand.Next((int)GenVars.rockLayerHigh, Main.maxTilesY); + + WorldGen.OreRunner(x, y, 8, 2, (ushort)ModContent.TileType()); + } + } + } + +} + diff --git a/Content/Tiles/CoalTile.cs b/Content/Tiles/CoalTile.cs index b8c6d9d..44e61d0 100644 --- a/Content/Tiles/CoalTile.cs +++ b/Content/Tiles/CoalTile.cs @@ -8,6 +8,7 @@ using Terraria; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; +using Terraria.WorldBuilding; namespace continuity.Content.Tiles { @@ -30,4 +31,5 @@ namespace continuity.Content.Tiles HitSound = SoundID.Tink; } } + } diff --git a/Localization/en-US_Mods.continuity.hjson b/Localization/en-US_Mods.continuity.hjson index 53e334d..ecdd739 100644 --- a/Localization/en-US_Mods.continuity.hjson +++ b/Localization/en-US_Mods.continuity.hjson @@ -28,4 +28,5 @@ Items: { } } -Tiles.CoalTile.MapEntry: Coal Tile +Tiles.CoalTile.MapEntry: Coal +WorldGen.CoalGenMessage: "Industrializing the World" diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json index b441563..f59c54c 100644 --- a/Properties/launchSettings.json +++ b/Properties/launchSettings.json @@ -1,16 +1,16 @@ { - "profiles": { - "Terraria": { - "commandName": "Executable", - "executablePath": "/etc/profiles/per-user/devraza/bin/dotnet", - "commandLineArgs": "$(tMLPath)", - "workingDirectory": "$(tMLSteamPath)" - }, - "TerrariaServer": { - "commandName": "Executable", - "executablePath": "/etc/profiles/per-user/devraza/bin/dotnet", - "commandLineArgs": "$(tMLServerPath)", - "workingDirectory": "$(tMLSteamPath)" - } - } + "profiles": { + "Terraria": { + "commandName": "Executable", + "executablePath": "$(DotNetName)", + "commandLineArgs": "$(tMLPath)", + "workingDirectory": "$(tMLSteamPath)" + }, + "TerrariaServer": { + "commandName": "Executable", + "executablePath": "/etc/profiles/per-user/devraza/bin/dotnet", + "commandLineArgs": "$(tMLServerPath)", + "workingDirectory": "$(tMLSteamPath)" + } + } } \ No newline at end of file diff --git a/Utilities/WorldGenWorld.cs b/Utilities/WorldGenWorld.cs new file mode 100644 index 0000000..f1afa16 --- /dev/null +++ b/Utilities/WorldGenWorld.cs @@ -0,0 +1,33 @@ +// DEBUG WorldGen System for testing +using Terraria; +using Terraria.ModLoader; +using Microsoft.Xna.Framework.Input; +using Terraria.ID; +using Microsoft.Xna.Framework; +using Terraria.GameContent.Generation; +using continuity.Content.Tiles; + +#if DEBUG +namespace continuity.Utilities +{ + public class WorldGenWorld : ModSystem + { + public static bool JustPressed(Keys key) { + return Main.keyState.IsKeyDown(key) && !Main.oldKeyState.IsKeyDown(key); + } + + public override void PostUpdateWorld() { + if (JustPressed(Keys.D1)) + TestMethod((int)Main.MouseWorld.X / 16, (int)Main.MouseWorld.Y / 16); + } + + // implement whatever test code you want here. + private void TestMethod(int x, int y) { + Dust.QuickBox(new Vector2(x, y) * 16, new Vector2(x + 1, y + 1) * 16, 2, Color.YellowGreen, null); + + // Code to test placed here: + WorldGen.OreRunner(x, y, 8, 2, (ushort)ModContent.TileType()); + } + } +} +#endif diff --git a/continuity.csproj b/continuity.csproj index 726c74f..ed5bc9b 100644 --- a/continuity.csproj +++ b/continuity.csproj @@ -9,8 +9,5 @@ - - - \ No newline at end of file