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,
Vec3S32[] marks, bool checkLimit = true) {
op.Origin = marks[0]; op.Min = marks[0]; op.Max = marks[0];
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.SetMarks(marks);
op.Level = p == null ? null : p.level;
if (op.Level != null && !op.Level.DrawingAllowed) {
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() {
//TotalAffected = 0;
TotalModified = 0;

View File

@ -38,6 +38,7 @@ namespace MCGalaxy.Drawing.Ops {
public int Type;
public const int T_Tree = 0, T_NotchTree = 1, T_NotchSwamp = 2, T_Cactus = 3;
static Brush defBrush = new SolidBrush(Block.leaf, 0);
byte height, top, size;
public override long GetBlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
@ -50,9 +51,33 @@ namespace MCGalaxy.Drawing.Ops {
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) {
byte height = (byte)random.Next(5, 8);
short top = (short)(height - random.Next(2, 4));
for (ushort dy = 0; dy < top + height - 1; dy++) {
ushort yy = (ushort)(y + dy);
if (overwrite || lvl.GetTile(x, yy, z) == Block.air || (yy == y && lvl.GetTile(x, yy, z) == Block.shrub))
@ -74,8 +99,6 @@ namespace MCGalaxy.Drawing.Ops {
}
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++) {
ushort yy = (ushort)(y + dy);
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) {
byte height = (byte)random.Next(4, 8);
byte top = (byte)(height - 2);
for (int dy = 0; dy <= height; dy++) {
ushort yy = (ushort)(y + dy);
byte tile = lvl.GetTile(x, yy, z);
@ -138,7 +159,6 @@ namespace MCGalaxy.Drawing.Ops {
}
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++) {
if (overwrite || lvl.GetTile(z, (ushort)(y + dy), z) == Block.air)
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)) {
treeDrawer.Type = genParams.UseCactus ? TreeDrawOp.T_Cactus : TreeDrawOp.T_Tree;
treeCoords[0].X = x; treeCoords[0].Y = (ushort)(y + 1); treeCoords[0].Z = z;
treeDrawer.SetMarks(treeCoords);
treeDrawer.Perform(treeCoords, null, Lvl, null);
}
}

View File

@ -123,7 +123,9 @@ namespace MCGalaxy.BlockPhysics {
TreeDrawOp op = new TreeDrawOp();
op.random = rand;
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;
}