feat: coal world gen + world gen test framework

This commit is contained in:
Abdulmujeeb Raji 2024-11-13 12:06:34 +00:00
parent 082bcba90c
commit 417f4923e7
Signed by untrusted user: midnadimple
GPG key ID: EB02C582F8C3962B
6 changed files with 105 additions and 18 deletions

View file

@ -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<GenPass> 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<CoalTile>());
}
}
}
}

View file

@ -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;
}
}
}

View file

@ -28,4 +28,5 @@ Items: {
}
}
Tiles.CoalTile.MapEntry: Coal Tile
Tiles.CoalTile.MapEntry: Coal
WorldGen.CoalGenMessage: "Industrializing the World"

View file

@ -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)"
}
}
}

View file

@ -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<CoalTile>());
}
}
}
#endif

View file

@ -9,8 +9,5 @@
</PropertyGroup>
<!-- References -->
<ItemGroup>
</ItemGroup>
</Project>