Tree draw op now sets appropriate bounds, meaning cloudy brush works properly for /tree.

This commit is contained in:
UnknownShadow200 2016-06-19 23:01:47 +10:00
parent 95fb7603f6
commit 86e45cd165
5 changed files with 45 additions and 18 deletions

View File

@ -43,11 +43,7 @@ namespace MCGalaxy.Drawing.Ops {
public static bool DoDrawOp(DrawOp op, Brush brush, Player p, public static bool DoDrawOp(DrawOp op, Brush brush, Player p,
Vec3S32[] marks, bool checkLimit = true) { Vec3S32[] marks, bool checkLimit = true) {
op.Origin = marks[0]; op.Min = marks[0]; op.Max = marks[0]; op.SetMarks(marks);
for (int i = 1; i < marks.Length; i++) {
op.Min = Vec3S32.Min(op.Min, marks[i]);
op.Max = Vec3S32.Max(op.Max, marks[i]);
}
op.Level = p == null ? null : p.level; op.Level = p == null ? null : p.level;
if (op.Level != null && !op.Level.DrawingAllowed) { if (op.Level != null && !op.Level.DrawingAllowed) {
Player.Message(p, "Drawing commands are turned off on this map."); Player.Message(p, "Drawing commands are turned off on this map.");

View File

@ -84,6 +84,14 @@ namespace MCGalaxy.Drawing.Ops {
} }
} }
public virtual void SetMarks(Vec3S32[] marks) {
Origin = marks[0]; Min = marks[0]; Max = marks[0];
for (int i = 1; i < marks.Length; i++) {
Min = Vec3S32.Min(Min, marks[i]);
Max = Vec3S32.Max(Max, marks[i]);
}
}
public virtual void Reset() { public virtual void Reset() {
//TotalAffected = 0; //TotalAffected = 0;
TotalModified = 0; TotalModified = 0;

View File

@ -35,24 +35,49 @@ namespace MCGalaxy.Drawing.Ops {
public Random random; public Random random;
public bool overwrite = false; public bool overwrite = false;
public int Type; public int Type;
public const int T_Tree = 0, T_NotchTree = 1, T_NotchSwamp = 2, T_Cactus = 3; public const int T_Tree = 0, T_NotchTree = 1, T_NotchSwamp = 2, T_Cactus = 3;
static Brush defBrush = new SolidBrush(Block.leaf, 0); static Brush defBrush = new SolidBrush(Block.leaf, 0);
byte height, top, size;
public override long GetBlocksAffected(Level lvl, Vec3S32[] marks) { return -1; } public override long GetBlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
public override void Perform(Vec3S32[] marks, Player p, Level lvl, Brush brush) { public override void Perform(Vec3S32[] marks, Player p, Level lvl, Brush brush) {
if (brush == null) brush = defBrush; if (brush == null) brush = defBrush;
Vec3U16 P = Clamp(marks[0]); Vec3U16 P = Clamp(marks[0]);
if (Type == T_Tree) AddTree(p, lvl, P.X, P.Y, P.Z, brush); if (Type == T_Tree) AddTree(p, lvl, P.X, P.Y, P.Z, brush);
if (Type == T_NotchTree) AddNotchTree(p, lvl, P.X, P.Y, P.Z, brush); if (Type == T_NotchTree) AddNotchTree(p, lvl, P.X, P.Y, P.Z, brush);
if (Type == T_NotchSwamp) AddNotchSwampTree(p, lvl, P.X, P.Y, P.Z, brush); if (Type == T_NotchSwamp) AddNotchSwampTree(p, lvl, P.X, P.Y, P.Z, brush);
if (Type == T_Cactus) AddCactus(p, lvl, P.X, P.Y, P.Z); if (Type == T_Cactus) AddCactus(p, lvl, P.X, P.Y, P.Z);
} }
public override void SetMarks(Vec3S32[] marks) {
base.SetMarks(marks);
switch (Type) {
case T_Tree:
height = (byte)random.Next(5, 8);
top = (byte)(height - random.Next(2, 4));
size = top; break;
case T_NotchTree:
height = (byte)random.Next(3, 7);
top = (byte)(height - 2);
size = 2; break;
case T_NotchSwamp:
height = (byte)random.Next(4, 8);
top = (byte)(height - 2);
size = 3; break;
case T_Cactus:
height = (byte)random.Next(3, 6);
top = 0;
size = 0; break;
}
Max.Y += height;
Min.X -= size; Min.Z -= size;
Max.X += size; Max.Z += size;
}
void AddTree(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) { void AddTree(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) {
byte height = (byte)random.Next(5, 8);
short top = (short)(height - random.Next(2, 4));
for (ushort dy = 0; dy < top + height - 1; dy++) { for (ushort dy = 0; dy < top + height - 1; dy++) {
ushort yy = (ushort)(y + dy); ushort yy = (ushort)(y + dy);
if (overwrite || lvl.GetTile(x, yy, z) == Block.air || (yy == y && lvl.GetTile(x, yy, z) == Block.shrub)) if (overwrite || lvl.GetTile(x, yy, z) == Block.air || (yy == y && lvl.GetTile(x, yy, z) == Block.shrub))
@ -68,14 +93,12 @@ namespace MCGalaxy.Drawing.Ops {
ushort xx = (ushort)(x + dx), yy = (ushort)(y + dy + height), zz = (ushort)(z + dz); ushort xx = (ushort)(x + dx), yy = (ushort)(y + dy + height), zz = (ushort)(z + dz);
if ((xx != x || zz != z || dy >= top - 1) && (overwrite || lvl.GetTile(xx, yy, zz) == Block.air)) if ((xx != x || zz != z || dy >= top - 1) && (overwrite || lvl.GetTile(xx, yy, zz) == Block.air))
PlaceBlock(p, lvl, xx, yy, zz, brush); PlaceBlock(p, lvl, xx, yy, zz, brush);
} }
} }
} }
void AddNotchTree(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) { void AddNotchTree(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) {
byte height = (byte)random.Next(3, 7);
byte top = (byte)(height - 2);
for (int dy = 0; dy <= height; dy++) { for (int dy = 0; dy <= height; dy++) {
ushort yy = (ushort)(y + dy); ushort yy = (ushort)(y + dy);
byte tile = lvl.GetTile(x, yy, z); byte tile = lvl.GetTile(x, yy, z);
@ -106,8 +129,6 @@ namespace MCGalaxy.Drawing.Ops {
} }
void AddNotchSwampTree(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) { void AddNotchSwampTree(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) {
byte height = (byte)random.Next(4, 8);
byte top = (byte)(height - 2);
for (int dy = 0; dy <= height; dy++) { for (int dy = 0; dy <= height; dy++) {
ushort yy = (ushort)(y + dy); ushort yy = (ushort)(y + dy);
byte tile = lvl.GetTile(x, yy, z); byte tile = lvl.GetTile(x, yy, z);
@ -131,14 +152,13 @@ namespace MCGalaxy.Drawing.Ops {
if (random.Next(2) == 0) if (random.Next(2) == 0)
PlaceBlock(p, lvl, xx, yy, zz, brush); PlaceBlock(p, lvl, xx, yy, zz, brush);
} else { } else {
PlaceBlock(p, lvl, xx, yy, zz, brush); PlaceBlock(p, lvl, xx, yy, zz, brush);
} }
} }
} }
} }
void AddCactus(Player p, Level lvl, ushort x, ushort y, ushort z) { void AddCactus(Player p, Level lvl, ushort x, ushort y, ushort z) {
byte height = (byte)random.Next(3, 6);
for (ushort dy = 0; dy <= height; dy++) { for (ushort dy = 0; dy <= height; dy++) {
if (overwrite || lvl.GetTile(z, (ushort)(y + dy), z) == Block.air) if (overwrite || lvl.GetTile(z, (ushort)(y + dy), z) == Block.air)
PlaceBlock(p, lvl, x, (ushort)(y + dy), z, Block.green, 0); PlaceBlock(p, lvl, x, (ushort)(y + dy), z, Block.green, 0);

View File

@ -148,6 +148,7 @@ namespace MCGalaxy {
if (rand.Next(13) == 0 && !TreeDrawOp.TreeCheck(Lvl, x, y, z, treeDist)) { if (rand.Next(13) == 0 && !TreeDrawOp.TreeCheck(Lvl, x, y, z, treeDist)) {
treeDrawer.Type = genParams.UseCactus ? TreeDrawOp.T_Cactus : TreeDrawOp.T_Tree; treeDrawer.Type = genParams.UseCactus ? TreeDrawOp.T_Cactus : TreeDrawOp.T_Tree;
treeCoords[0].X = x; treeCoords[0].Y = (ushort)(y + 1); treeCoords[0].Z = z; treeCoords[0].X = x; treeCoords[0].Y = (ushort)(y + 1); treeCoords[0].Z = z;
treeDrawer.SetMarks(treeCoords);
treeDrawer.Perform(treeCoords, null, Lvl, null); treeDrawer.Perform(treeCoords, null, Lvl, null);
} }
} }

View File

@ -123,7 +123,9 @@ namespace MCGalaxy.BlockPhysics {
TreeDrawOp op = new TreeDrawOp(); TreeDrawOp op = new TreeDrawOp();
op.random = rand; op.random = rand;
op.method = DrawOp.M_BlockChange; op.method = DrawOp.M_BlockChange;
op.Perform(new [] { new Vec3S32(x, y, z) }, null, lvl, null); Vec3S32[] marks = new [] { new Vec3S32(x, y, z) };
op.SetMarks(marks);
op.Perform(marks, null, lvl, null);
C.data.Data = 255; C.data.Data = 255;
} }