Terraria 1.4.0.5 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-26 12:45:26 -04:00
commit 05205f009e
1059 changed files with 563450 additions and 0 deletions

388
WorldBuilding/Actions.cs Normal file
View file

@ -0,0 +1,388 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.Actions
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Terraria.DataStructures;
using Terraria.GameContent;
namespace Terraria.WorldBuilding
{
public static class Actions
{
public static GenAction Chain(params GenAction[] actions)
{
for (int index = 0; index < actions.Length - 1; ++index)
actions[index].NextAction = actions[index + 1];
return actions[0];
}
public static GenAction Continue(GenAction action) => (GenAction) new Actions.ContinueWrapper(action);
public class ContinueWrapper : GenAction
{
private GenAction _action;
public ContinueWrapper(GenAction action) => this._action = action;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
this._action.Apply(origin, x, y, args);
return this.UnitApply(origin, x, y, args);
}
}
public class Count : GenAction
{
private Ref<int> _count;
public Count(Ref<int> count) => this._count = count;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
++this._count.Value;
return this.UnitApply(origin, x, y, args);
}
}
public class Scanner : GenAction
{
private Ref<int> _count;
public Scanner(Ref<int> count) => this._count = count;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
++this._count.Value;
return this.UnitApply(origin, x, y, args);
}
}
public class TileScanner : GenAction
{
private ushort[] _tileIds;
private Dictionary<ushort, int> _tileCounts;
public TileScanner(params ushort[] tiles)
{
this._tileIds = tiles;
this._tileCounts = new Dictionary<ushort, int>();
for (int index = 0; index < tiles.Length; ++index)
this._tileCounts[this._tileIds[index]] = 0;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
Tile tile = GenBase._tiles[x, y];
if (tile.active() && this._tileCounts.ContainsKey(tile.type))
this._tileCounts[tile.type]++;
return this.UnitApply(origin, x, y, args);
}
public Actions.TileScanner Output(Dictionary<ushort, int> resultsOutput)
{
this._tileCounts = resultsOutput;
for (int index = 0; index < this._tileIds.Length; ++index)
{
if (!this._tileCounts.ContainsKey(this._tileIds[index]))
this._tileCounts[this._tileIds[index]] = 0;
}
return this;
}
public Dictionary<ushort, int> GetResults() => this._tileCounts;
public int GetCount(ushort tileId) => !this._tileCounts.ContainsKey(tileId) ? -1 : this._tileCounts[tileId];
}
public class Blank : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args) => this.UnitApply(origin, x, y, args);
}
public class Custom : GenAction
{
private GenBase.CustomPerUnitAction _perUnit;
public Custom(GenBase.CustomPerUnitAction perUnit) => this._perUnit = perUnit;
public override bool Apply(Point origin, int x, int y, params object[] args) => this._perUnit(x, y, args) | this.UnitApply(origin, x, y, args);
}
public class ClearMetadata : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].ClearMetadata();
return this.UnitApply(origin, x, y, args);
}
}
public class Clear : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].ClearEverything();
return this.UnitApply(origin, x, y, args);
}
}
public class ClearTile : GenAction
{
private bool _frameNeighbors;
public ClearTile(bool frameNeighbors = false) => this._frameNeighbors = frameNeighbors;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
WorldUtils.ClearTile(x, y, this._frameNeighbors);
return this.UnitApply(origin, x, y, args);
}
}
public class ClearWall : GenAction
{
private bool _frameNeighbors;
public ClearWall(bool frameNeighbors = false) => this._frameNeighbors = frameNeighbors;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
WorldUtils.ClearWall(x, y, this._frameNeighbors);
return this.UnitApply(origin, x, y, args);
}
}
public class HalfBlock : GenAction
{
private bool _value;
public HalfBlock(bool value = true) => this._value = value;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].halfBrick(this._value);
return this.UnitApply(origin, x, y, args);
}
}
public class SetTile : GenAction
{
private ushort _type;
private bool _doFraming;
private bool _doNeighborFraming;
public SetTile(ushort type, bool setSelfFrames = false, bool setNeighborFrames = true)
{
this._type = type;
this._doFraming = setSelfFrames;
this._doNeighborFraming = setNeighborFrames;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].Clear(~(TileDataType.Wiring | TileDataType.Actuator));
GenBase._tiles[x, y].type = this._type;
GenBase._tiles[x, y].active(true);
if (this._doFraming)
WorldUtils.TileFrame(x, y, this._doNeighborFraming);
return this.UnitApply(origin, x, y, args);
}
}
public class SetTileKeepWall : GenAction
{
private ushort _type;
private bool _doFraming;
private bool _doNeighborFraming;
public SetTileKeepWall(ushort type, bool setSelfFrames = false, bool setNeighborFrames = true)
{
this._type = type;
this._doFraming = setSelfFrames;
this._doNeighborFraming = setNeighborFrames;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
ushort wall = GenBase._tiles[x, y].wall;
int wallFrameX = GenBase._tiles[x, y].wallFrameX();
int wallFrameY = GenBase._tiles[x, y].wallFrameY();
GenBase._tiles[x, y].Clear(~(TileDataType.Wiring | TileDataType.Actuator));
GenBase._tiles[x, y].type = this._type;
GenBase._tiles[x, y].active(true);
if (wall > (ushort) 0)
{
GenBase._tiles[x, y].wall = wall;
GenBase._tiles[x, y].wallFrameX(wallFrameX);
GenBase._tiles[x, y].wallFrameY(wallFrameY);
}
if (this._doFraming)
WorldUtils.TileFrame(x, y, this._doNeighborFraming);
return this.UnitApply(origin, x, y, args);
}
}
public class DebugDraw : GenAction
{
private Color _color;
private SpriteBatch _spriteBatch;
public DebugDraw(SpriteBatch spriteBatch, Color color = default (Color))
{
this._spriteBatch = spriteBatch;
this._color = color;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
this._spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Microsoft.Xna.Framework.Rectangle((x << 4) - (int) Main.screenPosition.X, (y << 4) - (int) Main.screenPosition.Y, 16, 16), this._color);
return this.UnitApply(origin, x, y, args);
}
}
public class SetSlope : GenAction
{
private int _slope;
public SetSlope(int slope) => this._slope = slope;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
WorldGen.SlopeTile(x, y, this._slope);
return this.UnitApply(origin, x, y, args);
}
}
public class SetHalfTile : GenAction
{
private bool _halfTile;
public SetHalfTile(bool halfTile) => this._halfTile = halfTile;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].halfBrick(this._halfTile);
return this.UnitApply(origin, x, y, args);
}
}
public class PlaceTile : GenAction
{
private ushort _type;
private int _style;
public PlaceTile(ushort type, int style = 0)
{
this._type = type;
this._style = style;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
WorldGen.PlaceTile(x, y, (int) this._type, true, style: this._style);
return this.UnitApply(origin, x, y, args);
}
}
public class RemoveWall : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].wall = (ushort) 0;
return this.UnitApply(origin, x, y, args);
}
}
public class PlaceWall : GenAction
{
private ushort _type;
private bool _neighbors;
public PlaceWall(ushort type, bool neighbors = true)
{
this._type = type;
this._neighbors = neighbors;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].wall = this._type;
WorldGen.SquareWallFrame(x, y);
if (this._neighbors)
{
WorldGen.SquareWallFrame(x + 1, y);
WorldGen.SquareWallFrame(x - 1, y);
WorldGen.SquareWallFrame(x, y - 1);
WorldGen.SquareWallFrame(x, y + 1);
}
return this.UnitApply(origin, x, y, args);
}
}
public class SetLiquid : GenAction
{
private int _type;
private byte _value;
public SetLiquid(int type = 0, byte value = 255)
{
this._value = value;
this._type = type;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._tiles[x, y].liquidType(this._type);
GenBase._tiles[x, y].liquid = this._value;
return this.UnitApply(origin, x, y, args);
}
}
public class SwapSolidTile : GenAction
{
private ushort _type;
public SwapSolidTile(ushort type) => this._type = type;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
Tile tile = GenBase._tiles[x, y];
if (!WorldGen.SolidTile(tile))
return this.Fail();
tile.ResetToType(this._type);
return this.UnitApply(origin, x, y, args);
}
}
public class SetFrames : GenAction
{
private bool _frameNeighbors;
public SetFrames(bool frameNeighbors = false) => this._frameNeighbors = frameNeighbors;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
WorldUtils.TileFrame(x, y, this._frameNeighbors);
return this.UnitApply(origin, x, y, args);
}
}
public class Smooth : GenAction
{
private bool _applyToNeighbors;
public Smooth(bool applyToNeighbors = false) => this._applyToNeighbors = applyToNeighbors;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
Tile.SmoothSlope(x, y, this._applyToNeighbors);
return this.UnitApply(origin, x, y, args);
}
}
}
}

View file

@ -0,0 +1,56 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.Conditions
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.WorldBuilding
{
public static class Conditions
{
public class IsTile : GenCondition
{
private ushort[] _types;
public IsTile(params ushort[] types) => this._types = types;
protected override bool CheckValidity(int x, int y)
{
if (GenBase._tiles[x, y].active())
{
for (int index = 0; index < this._types.Length; ++index)
{
if ((int) GenBase._tiles[x, y].type == (int) this._types[index])
return true;
}
}
return false;
}
}
public class Continue : GenCondition
{
protected override bool CheckValidity(int x, int y) => false;
}
public class MysticSnake : GenCondition
{
protected override bool CheckValidity(int x, int y) => GenBase._tiles[x, y].active() && !Main.tileCut[(int) GenBase._tiles[x, y].type] && GenBase._tiles[x, y].type != (ushort) 504;
}
public class IsSolid : GenCondition
{
protected override bool CheckValidity(int x, int y) => WorldGen.InWorld(x, y, 10) && GenBase._tiles[x, y].active() && Main.tileSolid[(int) GenBase._tiles[x, y].type];
}
public class HasLava : GenCondition
{
protected override bool CheckValidity(int x, int y) => GenBase._tiles[x, y].liquid > (byte) 0 && GenBase._tiles[x, y].liquidType() == (byte) 1;
}
public class NotNull : GenCondition
{
protected override bool CheckValidity(int x, int y) => GenBase._tiles[x, y] != null;
}
}
}

View file

@ -0,0 +1,40 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenAction
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
namespace Terraria.WorldBuilding
{
public abstract class GenAction : GenBase
{
public GenAction NextAction;
public ShapeData OutputData;
private bool _returnFalseOnFailure = true;
public abstract bool Apply(Point origin, int x, int y, params object[] args);
protected bool UnitApply(Point origin, int x, int y, params object[] args)
{
if (this.OutputData != null)
this.OutputData.Add(x - origin.X, y - origin.Y);
return this.NextAction == null || this.NextAction.Apply(origin, x, y, args);
}
public GenAction IgnoreFailures()
{
this._returnFalseOnFailure = false;
return this;
}
protected bool Fail() => !this._returnFalseOnFailure;
public GenAction Output(ShapeData data)
{
this.OutputData = data;
return this;
}
}
}

23
WorldBuilding/GenBase.cs Normal file
View file

@ -0,0 +1,23 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenBase
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Terraria.Utilities;
namespace Terraria.WorldBuilding
{
public class GenBase
{
protected static UnifiedRandom _random => WorldGen.genRand;
protected static Tile[,] _tiles => Main.tile;
protected static int _worldWidth => Main.maxTilesX;
protected static int _worldHeight => Main.maxTilesY;
public delegate bool CustomPerUnitAction(int x, int y, params object[] args);
}
}

View file

@ -0,0 +1,78 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenCondition
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.WorldBuilding
{
public abstract class GenCondition : GenBase
{
private bool InvertResults;
private int _width;
private int _height;
private GenCondition.AreaType _areaType = GenCondition.AreaType.None;
public bool IsValid(int x, int y)
{
switch (this._areaType)
{
case GenCondition.AreaType.And:
for (int x1 = x; x1 < x + this._width; ++x1)
{
for (int y1 = y; y1 < y + this._height; ++y1)
{
if (!this.CheckValidity(x1, y1))
return this.InvertResults;
}
}
return !this.InvertResults;
case GenCondition.AreaType.Or:
for (int x2 = x; x2 < x + this._width; ++x2)
{
for (int y2 = y; y2 < y + this._height; ++y2)
{
if (this.CheckValidity(x2, y2))
return !this.InvertResults;
}
}
return this.InvertResults;
case GenCondition.AreaType.None:
return this.CheckValidity(x, y) ^ this.InvertResults;
default:
return true;
}
}
public GenCondition Not()
{
this.InvertResults = !this.InvertResults;
return this;
}
public GenCondition AreaOr(int width, int height)
{
this._areaType = GenCondition.AreaType.Or;
this._width = width;
this._height = height;
return this;
}
public GenCondition AreaAnd(int width, int height)
{
this._areaType = GenCondition.AreaType.And;
this._width = width;
this._height = height;
return this;
}
protected abstract bool CheckValidity(int x, int y);
private enum AreaType
{
And,
Or,
None,
}
}
}

View file

@ -0,0 +1,15 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenModShape
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.WorldBuilding
{
public abstract class GenModShape : GenShape
{
protected ShapeData _data;
public GenModShape(ShapeData data) => this._data = data;
}
}

49
WorldBuilding/GenPass.cs Normal file
View file

@ -0,0 +1,49 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenPass
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System;
using Terraria.IO;
namespace Terraria.WorldBuilding
{
public abstract class GenPass : GenBase
{
public string Name;
public float Weight;
private Action<GenPass> _onComplete;
private Action<GenPass> _onBegin;
public GenPass(string name, float loadWeight)
{
this.Name = name;
this.Weight = loadWeight;
}
protected abstract void ApplyPass(GenerationProgress progress, GameConfiguration configuration);
public void Apply(GenerationProgress progress, GameConfiguration configuration)
{
if (this._onBegin != null)
this._onBegin(this);
this.ApplyPass(progress, configuration);
if (this._onComplete == null)
return;
this._onComplete(this);
}
public GenPass OnBegin(Action<GenPass> beginAction)
{
this._onBegin = beginAction;
return this;
}
public GenPass OnComplete(Action<GenPass> completionAction)
{
this._onComplete = completionAction;
return this;
}
}
}

View file

@ -0,0 +1,41 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenSearch
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
namespace Terraria.WorldBuilding
{
public abstract class GenSearch : GenBase
{
public static Point NOT_FOUND = new Point(int.MaxValue, int.MaxValue);
private bool _requireAll = true;
private GenCondition[] _conditions;
public GenSearch Conditions(params GenCondition[] conditions)
{
this._conditions = conditions;
return this;
}
public abstract Point Find(Point origin);
protected bool Check(int x, int y)
{
for (int index = 0; index < this._conditions.Length; ++index)
{
if (this._requireAll ^ this._conditions[index].IsValid(x, y))
return !this._requireAll;
}
return this._requireAll;
}
public GenSearch RequireAll(bool mode)
{
this._requireAll = mode;
return this;
}
}
}

37
WorldBuilding/GenShape.cs Normal file
View file

@ -0,0 +1,37 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenShape
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
namespace Terraria.WorldBuilding
{
public abstract class GenShape : GenBase
{
private ShapeData _outputData;
protected bool _quitOnFail;
public abstract bool Perform(Point origin, GenAction action);
protected bool UnitApply(GenAction action, Point origin, int x, int y, params object[] args)
{
if (this._outputData != null)
this._outputData.Add(x - origin.X, y - origin.Y);
return action.Apply(origin, x, y, args);
}
public GenShape Output(ShapeData outputData)
{
this._outputData = outputData;
return this;
}
public GenShape QuitOnFail(bool value = true)
{
this._quitOnFail = value;
return this;
}
}
}

View file

@ -0,0 +1,20 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenShapeActionPair
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.WorldBuilding
{
public struct GenShapeActionPair
{
public readonly GenShape Shape;
public readonly GenAction Action;
public GenShapeActionPair(GenShape shape, GenAction action)
{
this.Shape = shape;
this.Action = action;
}
}
}

View file

@ -0,0 +1,15 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenStructure
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
namespace Terraria.WorldBuilding
{
public abstract class GenStructure : GenBase
{
public abstract bool Place(Point origin, StructureMap structures);
}
}

View file

@ -0,0 +1,45 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.GenerationProgress
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.WorldBuilding
{
public class GenerationProgress
{
private string _message = "";
private float _value;
private float _totalProgress;
public float TotalWeight;
public float CurrentPassWeight = 1f;
public string Message
{
get => string.Format(this._message, (object) this.Value);
set => this._message = value.Replace("%", "{0:0.0%}");
}
public float Value
{
set => this._value = Utils.Clamp<float>(value, 0.0f, 1f);
get => this._value;
}
public float TotalProgress => (double) this.TotalWeight == 0.0 ? 0.0f : (this.Value * this.CurrentPassWeight + this._totalProgress) / this.TotalWeight;
public void Set(float value) => this.Value = value;
public void Start(float weight)
{
this.CurrentPassWeight = weight;
this._value = 0.0f;
}
public void End()
{
this._totalProgress += this.CurrentPassWeight;
this._value = 0.0f;
}
}
}

View file

@ -0,0 +1,12 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.MicroBiome
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
namespace Terraria.WorldBuilding
{
public abstract class MicroBiome : GenStructure
{
}
}

130
WorldBuilding/ModShapes.cs Normal file
View file

@ -0,0 +1,130 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.ModShapes
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.DataStructures;
namespace Terraria.WorldBuilding
{
public static class ModShapes
{
public class All : GenModShape
{
public All(ShapeData data)
: base(data)
{
}
public override bool Perform(Point origin, GenAction action)
{
foreach (Point16 point16 in this._data.GetData())
{
if (!this.UnitApply(action, origin, (int) point16.X + origin.X, (int) point16.Y + origin.Y) && this._quitOnFail)
return false;
}
return true;
}
}
public class OuterOutline : GenModShape
{
private static readonly int[] POINT_OFFSETS = new int[16]
{
1,
0,
-1,
0,
0,
1,
0,
-1,
1,
1,
1,
-1,
-1,
1,
-1,
-1
};
private bool _useDiagonals;
private bool _useInterior;
public OuterOutline(ShapeData data, bool useDiagonals = true, bool useInterior = false)
: base(data)
{
this._useDiagonals = useDiagonals;
this._useInterior = useInterior;
}
public override bool Perform(Point origin, GenAction action)
{
int num = this._useDiagonals ? 16 : 8;
foreach (Point16 point16 in this._data.GetData())
{
if (this._useInterior && !this.UnitApply(action, origin, (int) point16.X + origin.X, (int) point16.Y + origin.Y) && this._quitOnFail)
return false;
for (int index = 0; index < num; index += 2)
{
if (!this._data.Contains((int) point16.X + ModShapes.OuterOutline.POINT_OFFSETS[index], (int) point16.Y + ModShapes.OuterOutline.POINT_OFFSETS[index + 1]) && !this.UnitApply(action, origin, origin.X + (int) point16.X + ModShapes.OuterOutline.POINT_OFFSETS[index], origin.Y + (int) point16.Y + ModShapes.OuterOutline.POINT_OFFSETS[index + 1]) && this._quitOnFail)
return false;
}
}
return true;
}
}
public class InnerOutline : GenModShape
{
private static readonly int[] POINT_OFFSETS = new int[16]
{
1,
0,
-1,
0,
0,
1,
0,
-1,
1,
1,
1,
-1,
-1,
1,
-1,
-1
};
private bool _useDiagonals;
public InnerOutline(ShapeData data, bool useDiagonals = true)
: base(data)
{
this._useDiagonals = useDiagonals;
}
public override bool Perform(Point origin, GenAction action)
{
int num = this._useDiagonals ? 16 : 8;
foreach (Point16 point16 in this._data.GetData())
{
bool flag = false;
for (int index = 0; index < num; index += 2)
{
if (!this._data.Contains((int) point16.X + ModShapes.InnerOutline.POINT_OFFSETS[index], (int) point16.Y + ModShapes.InnerOutline.POINT_OFFSETS[index + 1]))
{
flag = true;
break;
}
}
if (flag && !this.UnitApply(action, origin, (int) point16.X + origin.X, (int) point16.Y + origin.Y) && this._quitOnFail)
return false;
}
return true;
}
}
}
}

469
WorldBuilding/Modifiers.cs Normal file
View file

@ -0,0 +1,469 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.Modifiers
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
namespace Terraria.WorldBuilding
{
public static class Modifiers
{
public class ShapeScale : GenAction
{
private int _scale;
public ShapeScale(int scale) => this._scale = scale;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
bool flag = false;
for (int index1 = 0; index1 < this._scale; ++index1)
{
for (int index2 = 0; index2 < this._scale; ++index2)
flag |= !this.UnitApply(origin, (x - origin.X << 1) + index1 + origin.X, (y - origin.Y << 1) + index2 + origin.Y);
}
return !flag;
}
}
public class Expand : GenAction
{
private int _xExpansion;
private int _yExpansion;
public Expand(int expansion)
{
this._xExpansion = expansion;
this._yExpansion = expansion;
}
public Expand(int xExpansion, int yExpansion)
{
this._xExpansion = xExpansion;
this._yExpansion = yExpansion;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
bool flag = false;
for (int index1 = -this._xExpansion; index1 <= this._xExpansion; ++index1)
{
for (int index2 = -this._yExpansion; index2 <= this._yExpansion; ++index2)
flag |= !this.UnitApply(origin, x + index1, y + index2, args);
}
return !flag;
}
}
public class RadialDither : GenAction
{
private float _innerRadius;
private float _outerRadius;
public RadialDither(float innerRadius, float outerRadius)
{
this._innerRadius = innerRadius;
this._outerRadius = outerRadius;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
Vector2 vector2 = new Vector2((float) origin.X, (float) origin.Y);
float num = Math.Max(0.0f, Math.Min(1f, (float) (((double) Vector2.Distance(new Vector2((float) x, (float) y), vector2) - (double) this._innerRadius) / ((double) this._outerRadius - (double) this._innerRadius))));
return GenBase._random.NextDouble() > (double) num ? this.UnitApply(origin, x, y, args) : this.Fail();
}
}
public class Blotches : GenAction
{
private int _minX;
private int _minY;
private int _maxX;
private int _maxY;
private double _chance;
public Blotches(int scale = 2, double chance = 0.3)
{
this._minX = scale;
this._minY = scale;
this._maxX = scale;
this._maxY = scale;
this._chance = chance;
}
public Blotches(int xScale, int yScale, double chance = 0.3)
{
this._minX = xScale;
this._maxX = xScale;
this._minY = yScale;
this._maxY = yScale;
this._chance = chance;
}
public Blotches(int leftScale, int upScale, int rightScale, int downScale, double chance = 0.3)
{
this._minX = leftScale;
this._maxX = rightScale;
this._minY = upScale;
this._maxY = downScale;
this._chance = chance;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
GenBase._random.NextDouble();
if (GenBase._random.NextDouble() >= this._chance)
return this.UnitApply(origin, x, y, args);
bool flag = false;
int num1 = GenBase._random.Next(1 - this._minX, 1);
int num2 = GenBase._random.Next(0, this._maxX);
int num3 = GenBase._random.Next(1 - this._minY, 1);
int num4 = GenBase._random.Next(0, this._maxY);
for (int index1 = num1; index1 <= num2; ++index1)
{
for (int index2 = num3; index2 <= num4; ++index2)
flag |= !this.UnitApply(origin, x + index1, y + index2, args);
}
return !flag;
}
}
public class InShape : GenAction
{
private readonly ShapeData _shapeData;
public InShape(ShapeData shapeData) => this._shapeData = shapeData;
public override bool Apply(Point origin, int x, int y, params object[] args) => !this._shapeData.Contains(x - origin.X, y - origin.Y) ? this.Fail() : this.UnitApply(origin, x, y, args);
}
public class NotInShape : GenAction
{
private readonly ShapeData _shapeData;
public NotInShape(ShapeData shapeData) => this._shapeData = shapeData;
public override bool Apply(Point origin, int x, int y, params object[] args) => this._shapeData.Contains(x - origin.X, y - origin.Y) ? this.Fail() : this.UnitApply(origin, x, y, args);
}
public class Conditions : GenAction
{
private readonly GenCondition[] _conditions;
public Conditions(params GenCondition[] conditions) => this._conditions = conditions;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
bool flag = true;
for (int index = 0; index < this._conditions.Length; ++index)
flag &= this._conditions[index].IsValid(x, y);
return flag ? this.UnitApply(origin, x, y, args) : this.Fail();
}
}
public class OnlyWalls : GenAction
{
private ushort[] _types;
public OnlyWalls(params ushort[] types) => this._types = types;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
for (int index = 0; index < this._types.Length; ++index)
{
if ((int) GenBase._tiles[x, y].wall == (int) this._types[index])
return this.UnitApply(origin, x, y, args);
}
return this.Fail();
}
}
public class OnlyTiles : GenAction
{
private ushort[] _types;
public OnlyTiles(params ushort[] types) => this._types = types;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
if (!GenBase._tiles[x, y].active())
return this.Fail();
for (int index = 0; index < this._types.Length; ++index)
{
if ((int) GenBase._tiles[x, y].type == (int) this._types[index])
return this.UnitApply(origin, x, y, args);
}
return this.Fail();
}
}
public class IsTouching : GenAction
{
private static readonly int[] DIRECTIONS = new int[16]
{
0,
-1,
1,
0,
-1,
0,
0,
1,
-1,
-1,
1,
-1,
-1,
1,
1,
1
};
private bool _useDiagonals;
private ushort[] _tileIds;
public IsTouching(bool useDiagonals, params ushort[] tileIds)
{
this._useDiagonals = useDiagonals;
this._tileIds = tileIds;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
int num = this._useDiagonals ? 16 : 8;
for (int index1 = 0; index1 < num; index1 += 2)
{
Tile tile = GenBase._tiles[x + Modifiers.IsTouching.DIRECTIONS[index1], y + Modifiers.IsTouching.DIRECTIONS[index1 + 1]];
if (tile.active())
{
for (int index2 = 0; index2 < this._tileIds.Length; ++index2)
{
if ((int) tile.type == (int) this._tileIds[index2])
return this.UnitApply(origin, x, y, args);
}
}
}
return this.Fail();
}
}
public class NotTouching : GenAction
{
private static readonly int[] DIRECTIONS = new int[16]
{
0,
-1,
1,
0,
-1,
0,
0,
1,
-1,
-1,
1,
-1,
-1,
1,
1,
1
};
private bool _useDiagonals;
private ushort[] _tileIds;
public NotTouching(bool useDiagonals, params ushort[] tileIds)
{
this._useDiagonals = useDiagonals;
this._tileIds = tileIds;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
int num = this._useDiagonals ? 16 : 8;
for (int index1 = 0; index1 < num; index1 += 2)
{
Tile tile = GenBase._tiles[x + Modifiers.NotTouching.DIRECTIONS[index1], y + Modifiers.NotTouching.DIRECTIONS[index1 + 1]];
if (tile.active())
{
for (int index2 = 0; index2 < this._tileIds.Length; ++index2)
{
if ((int) tile.type == (int) this._tileIds[index2])
return this.Fail();
}
}
}
return this.UnitApply(origin, x, y, args);
}
}
public class IsTouchingAir : GenAction
{
private static readonly int[] DIRECTIONS = new int[16]
{
0,
-1,
1,
0,
-1,
0,
0,
1,
-1,
-1,
1,
-1,
-1,
1,
1,
1
};
private bool _useDiagonals;
public IsTouchingAir(bool useDiagonals = false) => this._useDiagonals = useDiagonals;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
int num = this._useDiagonals ? 16 : 8;
for (int index = 0; index < num; index += 2)
{
if (!GenBase._tiles[x + Modifiers.IsTouchingAir.DIRECTIONS[index], y + Modifiers.IsTouchingAir.DIRECTIONS[index + 1]].active())
return this.UnitApply(origin, x, y, args);
}
return this.Fail();
}
}
public class SkipTiles : GenAction
{
private ushort[] _types;
public SkipTiles(params ushort[] types) => this._types = types;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
if (!GenBase._tiles[x, y].active())
return this.UnitApply(origin, x, y, args);
for (int index = 0; index < this._types.Length; ++index)
{
if ((int) GenBase._tiles[x, y].type == (int) this._types[index])
return this.Fail();
}
return this.UnitApply(origin, x, y, args);
}
}
public class HasLiquid : GenAction
{
private int _liquidType;
private int _liquidLevel;
public HasLiquid(int liquidLevel = -1, int liquidType = -1)
{
this._liquidType = liquidType;
this._liquidLevel = liquidLevel;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
Tile tile = GenBase._tiles[x, y];
return (this._liquidType == -1 || this._liquidType == (int) tile.liquidType()) && (this._liquidLevel == -1 && tile.liquid != (byte) 0 || this._liquidLevel == (int) tile.liquid) ? this.UnitApply(origin, x, y, args) : this.Fail();
}
}
public class SkipWalls : GenAction
{
private ushort[] _types;
public SkipWalls(params ushort[] types) => this._types = types;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
for (int index = 0; index < this._types.Length; ++index)
{
if ((int) GenBase._tiles[x, y].wall == (int) this._types[index])
return this.Fail();
}
return this.UnitApply(origin, x, y, args);
}
}
public class IsEmpty : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args) => !GenBase._tiles[x, y].active() ? this.UnitApply(origin, x, y, args) : this.Fail();
}
public class IsSolid : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args) => GenBase._tiles[x, y].active() && WorldGen.SolidOrSlopedTile(x, y) ? this.UnitApply(origin, x, y, args) : this.Fail();
}
public class IsNotSolid : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args) => !GenBase._tiles[x, y].active() || !WorldGen.SolidOrSlopedTile(x, y) ? this.UnitApply(origin, x, y, args) : this.Fail();
}
public class RectangleMask : GenAction
{
private int _xMin;
private int _yMin;
private int _xMax;
private int _yMax;
public RectangleMask(int xMin, int xMax, int yMin, int yMax)
{
this._xMin = xMin;
this._yMin = yMin;
this._xMax = xMax;
this._yMax = yMax;
}
public override bool Apply(Point origin, int x, int y, params object[] args) => x >= this._xMin + origin.X && x <= this._xMax + origin.X && y >= this._yMin + origin.Y && y <= this._yMax + origin.Y ? this.UnitApply(origin, x, y, args) : this.Fail();
}
public class Offset : GenAction
{
private int _xOffset;
private int _yOffset;
public Offset(int x, int y)
{
this._xOffset = x;
this._yOffset = y;
}
public override bool Apply(Point origin, int x, int y, params object[] args) => this.UnitApply(origin, x + this._xOffset, y + this._yOffset, args);
}
public class Dither : GenAction
{
private double _failureChance;
public Dither(double failureChance = 0.5) => this._failureChance = failureChance;
public override bool Apply(Point origin, int x, int y, params object[] args) => GenBase._random.NextDouble() >= this._failureChance ? this.UnitApply(origin, x, y, args) : this.Fail();
}
public class Flip : GenAction
{
private bool _flipX;
private bool _flipY;
public Flip(bool flipX, bool flipY)
{
this._flipX = flipX;
this._flipY = flipY;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
if (this._flipX)
x = origin.X * 2 - x;
if (this._flipY)
y = origin.Y * 2 - y;
return this.UnitApply(origin, x, y, args);
}
}
}
}

68
WorldBuilding/Passes.cs Normal file
View file

@ -0,0 +1,68 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.Passes
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Terraria.IO;
namespace Terraria.WorldBuilding
{
public static class Passes
{
public class Clear : GenPass
{
public Clear()
: base("clear", 1f)
{
}
protected override void ApplyPass(
GenerationProgress progress,
GameConfiguration configuration)
{
for (int index1 = 0; index1 < GenBase._worldWidth; ++index1)
{
for (int index2 = 0; index2 < GenBase._worldHeight; ++index2)
{
if (GenBase._tiles[index1, index2] == null)
GenBase._tiles[index1, index2] = new Tile();
else
GenBase._tiles[index1, index2].ClearEverything();
}
}
}
}
public class ScatterCustom : GenPass
{
private GenBase.CustomPerUnitAction _perUnit;
private int _count;
public ScatterCustom(
string name,
float loadWeight,
int count,
GenBase.CustomPerUnitAction perUnit = null)
: base(name, loadWeight)
{
this._perUnit = perUnit;
this._count = count;
}
public void SetCustomAction(GenBase.CustomPerUnitAction perUnit) => this._perUnit = perUnit;
protected override void ApplyPass(
GenerationProgress progress,
GameConfiguration configuration)
{
int count = this._count;
while (count > 0)
{
if (this._perUnit(GenBase._random.Next(1, GenBase._worldWidth), GenBase._random.Next(1, GenBase._worldHeight), new object[0]))
--count;
}
}
}
}
}

108
WorldBuilding/Searches.cs Normal file
View file

@ -0,0 +1,108 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.Searches
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
namespace Terraria.WorldBuilding
{
public static class Searches
{
public static GenSearch Chain(GenSearch search, params GenCondition[] conditions) => search.Conditions(conditions);
public class Left : GenSearch
{
private int _maxDistance;
public Left(int maxDistance) => this._maxDistance = maxDistance;
public override Point Find(Point origin)
{
for (int index = 0; index < this._maxDistance; ++index)
{
if (this.Check(origin.X - index, origin.Y))
return new Point(origin.X - index, origin.Y);
}
return GenSearch.NOT_FOUND;
}
}
public class Right : GenSearch
{
private int _maxDistance;
public Right(int maxDistance) => this._maxDistance = maxDistance;
public override Point Find(Point origin)
{
for (int index = 0; index < this._maxDistance; ++index)
{
if (this.Check(origin.X + index, origin.Y))
return new Point(origin.X + index, origin.Y);
}
return GenSearch.NOT_FOUND;
}
}
public class Down : GenSearch
{
private int _maxDistance;
public Down(int maxDistance) => this._maxDistance = maxDistance;
public override Point Find(Point origin)
{
for (int index = 0; index < this._maxDistance; ++index)
{
if (this.Check(origin.X, origin.Y + index))
return new Point(origin.X, origin.Y + index);
}
return GenSearch.NOT_FOUND;
}
}
public class Up : GenSearch
{
private int _maxDistance;
public Up(int maxDistance) => this._maxDistance = maxDistance;
public override Point Find(Point origin)
{
for (int index = 0; index < this._maxDistance; ++index)
{
if (this.Check(origin.X, origin.Y - index))
return new Point(origin.X, origin.Y - index);
}
return GenSearch.NOT_FOUND;
}
}
public class Rectangle : GenSearch
{
private int _width;
private int _height;
public Rectangle(int width, int height)
{
this._width = width;
this._height = height;
}
public override Point Find(Point origin)
{
for (int index1 = 0; index1 < this._width; ++index1)
{
for (int index2 = 0; index2 < this._height; ++index2)
{
if (this.Check(origin.X + index1, origin.Y + index2))
return new Point(origin.X + index1, origin.Y + index2);
}
}
return GenSearch.NOT_FOUND;
}
}
}
}

View file

@ -0,0 +1,68 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.ShapeData
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.DataStructures;
namespace Terraria.WorldBuilding
{
public class ShapeData
{
private HashSet<Point16> _points;
public int Count => this._points.Count;
public ShapeData() => this._points = new HashSet<Point16>();
public ShapeData(ShapeData original) => this._points = new HashSet<Point16>((IEnumerable<Point16>) original._points);
public void Add(int x, int y) => this._points.Add(new Point16(x, y));
public void Remove(int x, int y) => this._points.Remove(new Point16(x, y));
public HashSet<Point16> GetData() => this._points;
public void Clear() => this._points.Clear();
public bool Contains(int x, int y) => this._points.Contains(new Point16(x, y));
public void Add(ShapeData shapeData, Point localOrigin, Point remoteOrigin)
{
foreach (Point16 point16 in shapeData.GetData())
this.Add(remoteOrigin.X - localOrigin.X + (int) point16.X, remoteOrigin.Y - localOrigin.Y + (int) point16.Y);
}
public void Subtract(ShapeData shapeData, Point localOrigin, Point remoteOrigin)
{
foreach (Point16 point16 in shapeData.GetData())
this.Remove(remoteOrigin.X - localOrigin.X + (int) point16.X, remoteOrigin.Y - localOrigin.Y + (int) point16.Y);
}
public static Microsoft.Xna.Framework.Rectangle GetBounds(
Point origin,
params ShapeData[] shapes)
{
int val1_1 = (int) shapes[0]._points.First<Point16>().X;
int val1_2 = val1_1;
int val1_3 = (int) shapes[0]._points.First<Point16>().Y;
int val1_4 = val1_3;
for (int index = 0; index < shapes.Length; ++index)
{
foreach (Point16 point in shapes[index]._points)
{
val1_1 = Math.Max(val1_1, (int) point.X);
val1_2 = Math.Min(val1_2, (int) point.X);
val1_3 = Math.Max(val1_3, (int) point.Y);
val1_4 = Math.Min(val1_4, (int) point.Y);
}
}
return new Microsoft.Xna.Framework.Rectangle(val1_2 + origin.X, val1_4 + origin.Y, val1_1 - val1_2, val1_3 - val1_4);
}
}
}

194
WorldBuilding/Shapes.cs Normal file
View file

@ -0,0 +1,194 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.Shapes
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
namespace Terraria.WorldBuilding
{
public static class Shapes
{
public class Circle : GenShape
{
private int _verticalRadius;
private int _horizontalRadius;
public Circle(int radius)
{
this._verticalRadius = radius;
this._horizontalRadius = radius;
}
public Circle(int horizontalRadius, int verticalRadius)
{
this._horizontalRadius = horizontalRadius;
this._verticalRadius = verticalRadius;
}
public void SetRadius(int radius)
{
this._verticalRadius = radius;
this._horizontalRadius = radius;
}
public override bool Perform(Point origin, GenAction action)
{
int num1 = (this._horizontalRadius + 1) * (this._horizontalRadius + 1);
for (int y = origin.Y - this._verticalRadius; y <= origin.Y + this._verticalRadius; ++y)
{
float num2 = (float) this._horizontalRadius / (float) this._verticalRadius * (float) (y - origin.Y);
int num3 = Math.Min(this._horizontalRadius, (int) Math.Sqrt((double) num1 - (double) num2 * (double) num2));
for (int x = origin.X - num3; x <= origin.X + num3; ++x)
{
if (!this.UnitApply(action, origin, x, y) && this._quitOnFail)
return false;
}
}
return true;
}
}
public class HalfCircle : GenShape
{
private int _radius;
public HalfCircle(int radius) => this._radius = radius;
public override bool Perform(Point origin, GenAction action)
{
int num1 = (this._radius + 1) * (this._radius + 1);
for (int y = origin.Y - this._radius; y <= origin.Y; ++y)
{
int num2 = Math.Min(this._radius, (int) Math.Sqrt((double) (num1 - (y - origin.Y) * (y - origin.Y))));
for (int x = origin.X - num2; x <= origin.X + num2; ++x)
{
if (!this.UnitApply(action, origin, x, y) && this._quitOnFail)
return false;
}
}
return true;
}
}
public class Slime : GenShape
{
private int _radius;
private float _xScale;
private float _yScale;
public Slime(int radius)
{
this._radius = radius;
this._xScale = 1f;
this._yScale = 1f;
}
public Slime(int radius, float xScale, float yScale)
{
this._radius = radius;
this._xScale = xScale;
this._yScale = yScale;
}
public override bool Perform(Point origin, GenAction action)
{
float radius = (float) this._radius;
int num1 = (this._radius + 1) * (this._radius + 1);
for (int y = origin.Y - (int) ((double) radius * (double) this._yScale); y <= origin.Y; ++y)
{
float num2 = (float) (y - origin.Y) / this._yScale;
int num3 = (int) Math.Min((float) this._radius * this._xScale, this._xScale * (float) Math.Sqrt((double) num1 - (double) num2 * (double) num2));
for (int x = origin.X - num3; x <= origin.X + num3; ++x)
{
if (!this.UnitApply(action, origin, x, y) && this._quitOnFail)
return false;
}
}
for (int y = origin.Y + 1; y <= origin.Y + (int) ((double) radius * (double) this._yScale * 0.5) - 1; ++y)
{
float num4 = (float) (y - origin.Y) * (2f / this._yScale);
int num5 = (int) Math.Min((float) this._radius * this._xScale, this._xScale * (float) Math.Sqrt((double) num1 - (double) num4 * (double) num4));
for (int x = origin.X - num5; x <= origin.X + num5; ++x)
{
if (!this.UnitApply(action, origin, x, y) && this._quitOnFail)
return false;
}
}
return true;
}
}
public class Rectangle : GenShape
{
private Microsoft.Xna.Framework.Rectangle _area;
public Rectangle(Microsoft.Xna.Framework.Rectangle area) => this._area = area;
public Rectangle(int width, int height) => this._area = new Microsoft.Xna.Framework.Rectangle(0, 0, width, height);
public void SetArea(Microsoft.Xna.Framework.Rectangle area) => this._area = area;
public override bool Perform(Point origin, GenAction action)
{
for (int x = origin.X + this._area.Left; x < origin.X + this._area.Right; ++x)
{
for (int y = origin.Y + this._area.Top; y < origin.Y + this._area.Bottom; ++y)
{
if (!this.UnitApply(action, origin, x, y) && this._quitOnFail)
return false;
}
}
return true;
}
}
public class Tail : GenShape
{
private float _width;
private Vector2 _endOffset;
public Tail(float width, Vector2 endOffset)
{
this._width = width * 16f;
this._endOffset = endOffset * 16f;
}
public override bool Perform(Point origin, GenAction action)
{
Vector2 start = new Vector2((float) (origin.X << 4), (float) (origin.Y << 4));
return Utils.PlotTileTale(start, start + this._endOffset, this._width, (Utils.TileActionAttempt) ((x, y) => this.UnitApply(action, origin, x, y) || !this._quitOnFail));
}
}
public class Mound : GenShape
{
private int _halfWidth;
private int _height;
public Mound(int halfWidth, int height)
{
this._halfWidth = halfWidth;
this._height = height;
}
public override bool Perform(Point origin, GenAction action)
{
int height = this._height;
float halfWidth = (float) this._halfWidth;
for (int index1 = -this._halfWidth; index1 <= this._halfWidth; ++index1)
{
int num = Math.Min(this._height, (int) (-((double) (this._height + 1) / ((double) halfWidth * (double) halfWidth)) * ((double) index1 + (double) halfWidth) * ((double) index1 - (double) halfWidth)));
for (int index2 = 0; index2 < num; ++index2)
{
if (!this.UnitApply(action, origin, index1 + origin.X, origin.Y - index2) && this._quitOnFail)
return false;
}
}
return true;
}
}
}
}

View file

@ -0,0 +1,91 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.SimpleStructure
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
namespace Terraria.WorldBuilding
{
public class SimpleStructure : GenStructure
{
private int[,] _data;
private int _width;
private int _height;
private GenAction[] _actions;
private bool _xMirror;
private bool _yMirror;
public int Width => this._width;
public int Height => this._height;
public SimpleStructure(params string[] data) => this.ReadData(data);
public SimpleStructure(string data) => this.ReadData(data.Split('\n'));
private void ReadData(string[] lines)
{
this._height = lines.Length;
this._width = lines[0].Length;
this._data = new int[this._width, this._height];
for (int index1 = 0; index1 < this._height; ++index1)
{
for (int index2 = 0; index2 < this._width; ++index2)
{
int num = (int) lines[index1][index2];
switch (num)
{
case 48:
case 49:
case 50:
case 51:
case 52:
case 53:
case 54:
case 55:
case 56:
case 57:
this._data[index2, index1] = num - 48;
break;
default:
this._data[index2, index1] = -1;
break;
}
}
}
}
public SimpleStructure SetActions(params GenAction[] actions)
{
this._actions = actions;
return this;
}
public SimpleStructure Mirror(bool horizontalMirror, bool verticalMirror)
{
this._xMirror = horizontalMirror;
this._yMirror = verticalMirror;
return this;
}
public override bool Place(Point origin, StructureMap structures)
{
if (!structures.CanPlace(new Microsoft.Xna.Framework.Rectangle(origin.X, origin.Y, this._width, this._height)))
return false;
for (int index1 = 0; index1 < this._width; ++index1)
{
for (int index2 = 0; index2 < this._height; ++index2)
{
int num1 = this._xMirror ? -index1 : index1;
int num2 = this._yMirror ? -index2 : index2;
if (this._data[index1, index2] != -1 && !this._actions[this._data[index1, index2]].Apply(origin, num1 + origin.X, num2 + origin.Y))
return false;
}
}
structures.AddProtectedStructure(new Microsoft.Xna.Framework.Rectangle(origin.X, origin.Y, this._width, this._height));
return true;
}
}
}

View file

@ -0,0 +1,88 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.StructureMap
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.ID;
namespace Terraria.WorldBuilding
{
public class StructureMap
{
private readonly List<Microsoft.Xna.Framework.Rectangle> _structures = new List<Microsoft.Xna.Framework.Rectangle>(2048);
private readonly List<Microsoft.Xna.Framework.Rectangle> _protectedStructures = new List<Microsoft.Xna.Framework.Rectangle>(2048);
private readonly object _lock = new object();
public bool CanPlace(Microsoft.Xna.Framework.Rectangle area, int padding = 0) => this.CanPlace(area, TileID.Sets.GeneralPlacementTiles, padding);
public bool CanPlace(Microsoft.Xna.Framework.Rectangle area, bool[] validTiles, int padding = 0)
{
lock (this._lock)
{
if (area.X < 0 || area.Y < 0 || area.X + area.Width > Main.maxTilesX - 1 || area.Y + area.Height > Main.maxTilesY - 1)
return false;
Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle(area.X - padding, area.Y - padding, area.Width + padding * 2, area.Height + padding * 2);
for (int index = 0; index < this._protectedStructures.Count; ++index)
{
if (rectangle.Intersects(this._protectedStructures[index]))
return false;
}
for (int x = rectangle.X; x < rectangle.X + rectangle.Width; ++x)
{
for (int y = rectangle.Y; y < rectangle.Y + rectangle.Height; ++y)
{
if (Main.tile[x, y].active())
{
ushort type = Main.tile[x, y].type;
if (!validTiles[(int) type])
return false;
}
}
}
return true;
}
}
public Microsoft.Xna.Framework.Rectangle GetBoundingBox()
{
lock (this._lock)
{
if (this._structures.Count == 0)
return Microsoft.Xna.Framework.Rectangle.Empty;
Point point1 = new Point(this._structures.Min<Microsoft.Xna.Framework.Rectangle>((Func<Microsoft.Xna.Framework.Rectangle, int>) (rect => rect.Left)), this._structures.Min<Microsoft.Xna.Framework.Rectangle>((Func<Microsoft.Xna.Framework.Rectangle, int>) (rect => rect.Top)));
Point point2 = new Point(this._structures.Max<Microsoft.Xna.Framework.Rectangle>((Func<Microsoft.Xna.Framework.Rectangle, int>) (rect => rect.Right)), this._structures.Max<Microsoft.Xna.Framework.Rectangle>((Func<Microsoft.Xna.Framework.Rectangle, int>) (rect => rect.Bottom)));
return new Microsoft.Xna.Framework.Rectangle(point1.X, point1.Y, point2.X - point1.X, point2.Y - point1.Y);
}
}
public void AddStructure(Microsoft.Xna.Framework.Rectangle area, int padding = 0)
{
lock (this._lock)
{
area.Inflate(padding, padding);
this._structures.Add(area);
}
}
public void AddProtectedStructure(Microsoft.Xna.Framework.Rectangle area, int padding = 0)
{
lock (this._lock)
{
area.Inflate(padding, padding);
this._structures.Add(area);
this._protectedStructures.Add(area);
}
}
public void Reset()
{
lock (this._lock)
this._protectedStructures.Clear();
}
}
}

838
WorldBuilding/TileFont.cs Normal file
View file

@ -0,0 +1,838 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.TileFont
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
namespace Terraria.WorldBuilding
{
public class TileFont
{
private static readonly Dictionary<char, byte[]> MicroFont = new Dictionary<char, byte[]>()
{
{
'A',
new byte[5]
{
(byte) 124,
(byte) 68,
(byte) 68,
(byte) 124,
(byte) 68
}
},
{
'B',
new byte[5]
{
(byte) 124,
(byte) 68,
(byte) 120,
(byte) 68,
(byte) 124
}
},
{
'C',
new byte[5]
{
(byte) 124,
(byte) 64,
(byte) 64,
(byte) 64,
(byte) 124
}
},
{
'D',
new byte[5]
{
(byte) 120,
(byte) 68,
(byte) 68,
(byte) 68,
(byte) 120
}
},
{
'E',
new byte[5]
{
(byte) 124,
(byte) 64,
(byte) 120,
(byte) 64,
(byte) 124
}
},
{
'F',
new byte[5]
{
(byte) 124,
(byte) 64,
(byte) 112,
(byte) 64,
(byte) 64
}
},
{
'G',
new byte[5]
{
(byte) 124,
(byte) 64,
(byte) 76,
(byte) 68,
(byte) 124
}
},
{
'H',
new byte[5]
{
(byte) 68,
(byte) 68,
(byte) 124,
(byte) 68,
(byte) 68
}
},
{
'I',
new byte[5]
{
(byte) 124,
(byte) 16,
(byte) 16,
(byte) 16,
(byte) 124
}
},
{
'J',
new byte[5]
{
(byte) 12,
(byte) 4,
(byte) 4,
(byte) 68,
(byte) 124
}
},
{
'K',
new byte[5]
{
(byte) 68,
(byte) 72,
(byte) 112,
(byte) 72,
(byte) 68
}
},
{
'L',
new byte[5]
{
(byte) 64,
(byte) 64,
(byte) 64,
(byte) 64,
(byte) 124
}
},
{
'M',
new byte[5]
{
(byte) 68,
(byte) 108,
(byte) 84,
(byte) 68,
(byte) 68
}
},
{
'N',
new byte[5]
{
(byte) 68,
(byte) 100,
(byte) 84,
(byte) 76,
(byte) 68
}
},
{
'O',
new byte[5]
{
(byte) 124,
(byte) 68,
(byte) 68,
(byte) 68,
(byte) 124
}
},
{
'P',
new byte[5]
{
(byte) 120,
(byte) 68,
(byte) 120,
(byte) 64,
(byte) 64
}
},
{
'Q',
new byte[5]
{
(byte) 124,
(byte) 68,
(byte) 68,
(byte) 124,
(byte) 16
}
},
{
'R',
new byte[5]
{
(byte) 120,
(byte) 68,
(byte) 120,
(byte) 68,
(byte) 68
}
},
{
'S',
new byte[5]
{
(byte) 124,
(byte) 64,
(byte) 124,
(byte) 4,
(byte) 124
}
},
{
'T',
new byte[5]
{
(byte) 124,
(byte) 16,
(byte) 16,
(byte) 16,
(byte) 16
}
},
{
'U',
new byte[5]
{
(byte) 68,
(byte) 68,
(byte) 68,
(byte) 68,
(byte) 124
}
},
{
'V',
new byte[5]
{
(byte) 68,
(byte) 68,
(byte) 40,
(byte) 40,
(byte) 16
}
},
{
'W',
new byte[5]
{
(byte) 68,
(byte) 68,
(byte) 84,
(byte) 84,
(byte) 40
}
},
{
'X',
new byte[5]
{
(byte) 68,
(byte) 40,
(byte) 16,
(byte) 40,
(byte) 68
}
},
{
'Y',
new byte[5]
{
(byte) 68,
(byte) 68,
(byte) 40,
(byte) 16,
(byte) 16
}
},
{
'Z',
new byte[5]
{
(byte) 124,
(byte) 8,
(byte) 16,
(byte) 32,
(byte) 124
}
},
{
'a',
new byte[5]
{
(byte) 56,
(byte) 4,
(byte) 60,
(byte) 68,
(byte) 60
}
},
{
'b',
new byte[5]
{
(byte) 64,
(byte) 120,
(byte) 68,
(byte) 68,
(byte) 120
}
},
{
'c',
new byte[5]
{
(byte) 56,
(byte) 68,
(byte) 64,
(byte) 68,
(byte) 56
}
},
{
'd',
new byte[5]
{
(byte) 4,
(byte) 60,
(byte) 68,
(byte) 68,
(byte) 60
}
},
{
'e',
new byte[5]
{
(byte) 56,
(byte) 68,
(byte) 124,
(byte) 64,
(byte) 60
}
},
{
'f',
new byte[5]
{
(byte) 28,
(byte) 32,
(byte) 120,
(byte) 32,
(byte) 32
}
},
{
'g',
new byte[5]
{
(byte) 56,
(byte) 68,
(byte) 60,
(byte) 4,
(byte) 120
}
},
{
'h',
new byte[5]
{
(byte) 64,
(byte) 64,
(byte) 120,
(byte) 68,
(byte) 68
}
},
{
'i',
new byte[5]
{
(byte) 16,
(byte) 0,
(byte) 16,
(byte) 16,
(byte) 16
}
},
{
'j',
new byte[5]
{
(byte) 4,
(byte) 4,
(byte) 4,
(byte) 4,
(byte) 120
}
},
{
'k',
new byte[5]
{
(byte) 64,
(byte) 72,
(byte) 112,
(byte) 72,
(byte) 68
}
},
{
'l',
new byte[5]
{
(byte) 64,
(byte) 64,
(byte) 64,
(byte) 64,
(byte) 60
}
},
{
'm',
new byte[5]
{
(byte) 40,
(byte) 84,
(byte) 84,
(byte) 84,
(byte) 84
}
},
{
'n',
new byte[5]
{
(byte) 120,
(byte) 68,
(byte) 68,
(byte) 68,
(byte) 68
}
},
{
'o',
new byte[5]
{
(byte) 56,
(byte) 68,
(byte) 68,
(byte) 68,
(byte) 56
}
},
{
'p',
new byte[5]
{
(byte) 56,
(byte) 68,
(byte) 68,
(byte) 120,
(byte) 64
}
},
{
'q',
new byte[5]
{
(byte) 56,
(byte) 68,
(byte) 68,
(byte) 60,
(byte) 4
}
},
{
'r',
new byte[5]
{
(byte) 88,
(byte) 100,
(byte) 64,
(byte) 64,
(byte) 64
}
},
{
's',
new byte[5]
{
(byte) 60,
(byte) 64,
(byte) 56,
(byte) 4,
(byte) 120
}
},
{
't',
new byte[5]
{
(byte) 64,
(byte) 112,
(byte) 64,
(byte) 68,
(byte) 56
}
},
{
'u',
new byte[5]
{
(byte) 0,
(byte) 68,
(byte) 68,
(byte) 68,
(byte) 56
}
},
{
'v',
new byte[5]
{
(byte) 0,
(byte) 68,
(byte) 68,
(byte) 40,
(byte) 16
}
},
{
'w',
new byte[5]
{
(byte) 84,
(byte) 84,
(byte) 84,
(byte) 84,
(byte) 40
}
},
{
'x',
new byte[5]
{
(byte) 68,
(byte) 68,
(byte) 56,
(byte) 68,
(byte) 68
}
},
{
'y',
new byte[5]
{
(byte) 68,
(byte) 68,
(byte) 60,
(byte) 4,
(byte) 120
}
},
{
'z',
new byte[5]
{
(byte) 124,
(byte) 4,
(byte) 56,
(byte) 64,
(byte) 124
}
},
{
'0',
new byte[5]
{
(byte) 124,
(byte) 76,
(byte) 84,
(byte) 100,
(byte) 124
}
},
{
'1',
new byte[5]
{
(byte) 16,
(byte) 48,
(byte) 16,
(byte) 16,
(byte) 56
}
},
{
'2',
new byte[5]
{
(byte) 120,
(byte) 4,
(byte) 56,
(byte) 64,
(byte) 124
}
},
{
'3',
new byte[5]
{
(byte) 124,
(byte) 4,
(byte) 56,
(byte) 4,
(byte) 124
}
},
{
'4',
new byte[5]
{
(byte) 64,
(byte) 64,
(byte) 80,
(byte) 124,
(byte) 16
}
},
{
'5',
new byte[5]
{
(byte) 124,
(byte) 64,
(byte) 120,
(byte) 4,
(byte) 120
}
},
{
'6',
new byte[5]
{
(byte) 124,
(byte) 64,
(byte) 124,
(byte) 68,
(byte) 124
}
},
{
'7',
new byte[5]
{
(byte) 124,
(byte) 4,
(byte) 8,
(byte) 16,
(byte) 16
}
},
{
'8',
new byte[5]
{
(byte) 124,
(byte) 68,
(byte) 124,
(byte) 68,
(byte) 124
}
},
{
'9',
new byte[5]
{
(byte) 124,
(byte) 68,
(byte) 124,
(byte) 4,
(byte) 124
}
},
{
'-',
new byte[5]
{
(byte) 0,
(byte) 0,
(byte) 124,
(byte) 0,
(byte) 0
}
},
{
' ',
new byte[5]
}
};
public static void DrawString(Point start, string text, TileFont.DrawMode mode)
{
Point position = start;
foreach (char key in text)
{
if (key == '\n')
{
position.X = start.X;
position.Y += 6;
}
byte[] charData;
if (TileFont.MicroFont.TryGetValue(key, out charData))
{
TileFont.DrawChar(position, charData, mode);
position.X += 6;
}
}
}
private static void DrawChar(Point position, byte[] charData, TileFont.DrawMode mode)
{
if (mode.HasBackground)
{
for (int index1 = -1; index1 < charData.Length + 1; ++index1)
{
for (int index2 = -1; index2 < 6; ++index2)
{
Main.tile[position.X + index2, position.Y + index1].ResetToType(mode.BackgroundTile);
WorldGen.TileFrame(position.X + index2, position.Y + index1);
}
}
}
for (int index3 = 0; index3 < charData.Length; ++index3)
{
int num = (int) charData[index3] << 1;
for (int index4 = 0; index4 < 5; ++index4)
{
if ((num & 128) == 128)
{
Main.tile[position.X + index4, position.Y + index3].ResetToType(mode.ForegroundTile);
WorldGen.TileFrame(position.X + index4, position.Y + index3);
}
num <<= 1;
}
}
}
public static Point MeasureString(string text)
{
Point zero = Point.Zero;
Point point1 = zero;
Point point2 = new Point(0, 5);
foreach (char key in text)
{
if (key == '\n')
{
point1.X = zero.X;
point1.Y += 6;
point2.Y = point1.Y + 5;
}
if (TileFont.MicroFont.TryGetValue(key, out byte[] _))
{
point1.X += 6;
point2.X = Math.Max(point2.X, point1.X - 1);
}
}
return point2;
}
public static void HLineLabel(
Point start,
int width,
string text,
TileFont.DrawMode mode,
bool rightSideText = false)
{
Point point = TileFont.MeasureString(text);
for (int x = start.X; x < start.X + width; ++x)
{
Main.tile[x, start.Y].ResetToType(mode.ForegroundTile);
WorldGen.TileFrame(x, start.Y);
}
TileFont.DrawString(new Point(rightSideText ? start.X + width + 1 : start.X - point.X - 1, start.Y - point.Y / 2), text, mode);
}
public static void VLineLabel(
Point start,
int height,
string text,
TileFont.DrawMode mode,
bool bottomText = false)
{
Point point = TileFont.MeasureString(text);
for (int y = start.Y; y < start.Y + height; ++y)
{
Main.tile[start.X, y].ResetToType(mode.ForegroundTile);
WorldGen.TileFrame(start.X, y);
}
TileFont.DrawString(new Point(start.X - point.X / 2, bottomText ? start.Y + height + 1 : start.Y - point.Y - 1), text, mode);
}
public struct DrawMode
{
public readonly ushort ForegroundTile;
public readonly ushort BackgroundTile;
public readonly bool HasBackground;
public DrawMode(ushort foregroundTile)
{
this.ForegroundTile = foregroundTile;
this.HasBackground = false;
this.BackgroundTile = (ushort) 0;
}
public DrawMode(ushort foregroundTile, ushort backgroundTile)
{
this.ForegroundTile = foregroundTile;
this.BackgroundTile = backgroundTile;
this.HasBackground = true;
}
}
}
}

View file

@ -0,0 +1,50 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.WorldGenConfiguration
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Reflection;
using Terraria.IO;
namespace Terraria.WorldBuilding
{
public class WorldGenConfiguration : GameConfiguration
{
private readonly JObject _biomeRoot;
private readonly JObject _passRoot;
public WorldGenConfiguration(JObject configurationRoot)
: base(configurationRoot)
{
this._biomeRoot = (JObject) configurationRoot["Biomes"] ?? new JObject();
this._passRoot = (JObject) configurationRoot["Passes"] ?? new JObject();
}
public T CreateBiome<T>() where T : MicroBiome, new() => this.CreateBiome<T>(typeof (T).Name);
public T CreateBiome<T>(string name) where T : MicroBiome, new()
{
JToken jtoken;
return this._biomeRoot.TryGetValue(name, ref jtoken) ? jtoken.ToObject<T>() : new T();
}
public GameConfiguration GetPassConfiguration(string name)
{
JToken jtoken;
return this._passRoot.TryGetValue(name, ref jtoken) ? new GameConfiguration((JObject) jtoken) : new GameConfiguration(new JObject());
}
public static WorldGenConfiguration FromEmbeddedPath(string path)
{
using (Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path))
{
using (StreamReader streamReader = new StreamReader(manifestResourceStream))
return new WorldGenConfiguration(JsonConvert.DeserializeObject<JObject>(streamReader.ReadToEnd()));
}
}
}
}

View file

@ -0,0 +1,61 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.WorldGenRange
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Terraria.Utilities;
namespace Terraria.WorldBuilding
{
public class WorldGenRange
{
public static readonly WorldGenRange Empty = new WorldGenRange(0, 0);
[JsonProperty("Min")]
public readonly int Minimum;
[JsonProperty("Max")]
public readonly int Maximum;
[JsonProperty]
[JsonConverter(typeof (StringEnumConverter))]
public readonly WorldGenRange.ScalingMode ScaleWith;
public int ScaledMinimum => this.ScaleValue(this.Minimum);
public int ScaledMaximum => this.ScaleValue(this.Maximum);
public WorldGenRange(int minimum, int maximum)
{
this.Minimum = minimum;
this.Maximum = maximum;
}
public int GetRandom(UnifiedRandom random) => random.Next(this.ScaledMinimum, this.ScaledMaximum + 1);
private int ScaleValue(int value)
{
float num = 1f;
switch (this.ScaleWith)
{
case WorldGenRange.ScalingMode.None:
num = 1f;
break;
case WorldGenRange.ScalingMode.WorldArea:
num = (float) (Main.maxTilesX * Main.maxTilesY) / 5040000f;
break;
case WorldGenRange.ScalingMode.WorldWidth:
num = (float) Main.maxTilesX / 4200f;
break;
}
return (int) ((double) num * (double) value);
}
public enum ScalingMode
{
None,
WorldArea,
WorldWidth,
}
}
}

View file

@ -0,0 +1,56 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.WorldGenerator
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System.Collections.Generic;
using System.Diagnostics;
using Terraria.Utilities;
namespace Terraria.WorldBuilding
{
public class WorldGenerator
{
private readonly List<GenPass> _passes = new List<GenPass>();
private float _totalLoadWeight;
private readonly int _seed;
private readonly WorldGenConfiguration _configuration;
public static GenerationProgress CurrentGenerationProgress;
public WorldGenerator(int seed, WorldGenConfiguration configuration)
{
this._seed = seed;
this._configuration = configuration;
}
public void Append(GenPass pass)
{
this._passes.Add(pass);
this._totalLoadWeight += pass.Weight;
}
public void GenerateWorld(GenerationProgress progress = null)
{
Stopwatch stopwatch = new Stopwatch();
float num = 0.0f;
foreach (GenPass pass in this._passes)
num += pass.Weight;
if (progress == null)
progress = new GenerationProgress();
WorldGenerator.CurrentGenerationProgress = progress;
progress.TotalWeight = num;
foreach (GenPass pass in this._passes)
{
WorldGen._genRand = new UnifiedRandom(this._seed);
Main.rand = new UnifiedRandom(this._seed);
stopwatch.Start();
progress.Start(pass.Weight);
pass.Apply(progress, this._configuration.GetPassConfiguration(pass.Name));
progress.End();
stopwatch.Reset();
}
WorldGenerator.CurrentGenerationProgress = (GenerationProgress) null;
}
}
}

119
WorldBuilding/WorldUtils.cs Normal file
View file

@ -0,0 +1,119 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.WorldBuilding.WorldUtils
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
namespace Terraria.WorldBuilding
{
public static class WorldUtils
{
public static Microsoft.Xna.Framework.Rectangle ClampToWorld(
World world,
Microsoft.Xna.Framework.Rectangle tileRectangle)
{
int x = Math.Max(0, Math.Min(tileRectangle.Left, world.TileColumns));
int y = Math.Max(0, Math.Min(tileRectangle.Top, world.TileRows));
int num1 = Math.Max(0, Math.Min(tileRectangle.Right, world.TileColumns));
int num2 = Math.Max(0, Math.Min(tileRectangle.Bottom, world.TileRows));
return new Microsoft.Xna.Framework.Rectangle(x, y, num1 - x, num2 - y);
}
public static bool Gen(Point origin, GenShape shape, GenAction action) => shape.Perform(origin, action);
public static bool Gen(Point origin, GenShapeActionPair pair) => pair.Shape.Perform(origin, pair.Action);
public static bool Find(Point origin, GenSearch search, out Point result)
{
result = search.Find(origin);
return !(result == GenSearch.NOT_FOUND);
}
public static void ClearTile(int x, int y, bool frameNeighbors = false)
{
Main.tile[x, y].ClearTile();
if (!frameNeighbors)
return;
WorldGen.TileFrame(x + 1, y);
WorldGen.TileFrame(x - 1, y);
WorldGen.TileFrame(x, y + 1);
WorldGen.TileFrame(x, y - 1);
}
public static void ClearWall(int x, int y, bool frameNeighbors = false)
{
Main.tile[x, y].wall = (ushort) 0;
if (!frameNeighbors)
return;
WorldGen.SquareWallFrame(x + 1, y);
WorldGen.SquareWallFrame(x - 1, y);
WorldGen.SquareWallFrame(x, y + 1);
WorldGen.SquareWallFrame(x, y - 1);
}
public static void TileFrame(int x, int y, bool frameNeighbors = false)
{
WorldGen.TileFrame(x, y, true);
if (!frameNeighbors)
return;
WorldGen.TileFrame(x + 1, y, true);
WorldGen.TileFrame(x - 1, y, true);
WorldGen.TileFrame(x, y + 1, true);
WorldGen.TileFrame(x, y - 1, true);
}
public static void ClearChestLocation(int x, int y)
{
WorldUtils.ClearTile(x, y, true);
WorldUtils.ClearTile(x - 1, y, true);
WorldUtils.ClearTile(x, y - 1, true);
WorldUtils.ClearTile(x - 1, y - 1, true);
}
public static void WireLine(Point start, Point end)
{
Point point1 = start;
Point point2 = end;
if (end.X < start.X)
Utils.Swap<int>(ref end.X, ref start.X);
if (end.Y < start.Y)
Utils.Swap<int>(ref end.Y, ref start.Y);
for (int x = start.X; x <= end.X; ++x)
WorldGen.PlaceWire(x, point1.Y);
for (int y = start.Y; y <= end.Y; ++y)
WorldGen.PlaceWire(point2.X, y);
}
public static void DebugRegen()
{
WorldGen.clearWorld();
WorldGen.GenerateWorld(Main.ActiveWorldFileData.Seed);
Main.NewText("World Regen Complete.");
}
public static void DebugRotate()
{
int num1 = 0;
int num2 = 0;
int maxTilesY = Main.maxTilesY;
for (int index1 = 0; index1 < Main.maxTilesX / Main.maxTilesY; ++index1)
{
for (int index2 = 0; index2 < maxTilesY / 2; ++index2)
{
for (int index3 = index2; index3 < maxTilesY - index2; ++index3)
{
Tile tile = Main.tile[index3 + num1, index2 + num2];
Main.tile[index3 + num1, index2 + num2] = Main.tile[index2 + num1, maxTilesY - index3 + num2];
Main.tile[index2 + num1, maxTilesY - index3 + num2] = Main.tile[maxTilesY - index3 + num1, maxTilesY - index2 + num2];
Main.tile[maxTilesY - index3 + num1, maxTilesY - index2 + num2] = Main.tile[maxTilesY - index2 + num1, index3 + num2];
Main.tile[maxTilesY - index2 + num1, index3 + num2] = tile;
}
}
num1 += maxTilesY;
}
}
}
}