From 86e45cd165afae6338cf52e6d0a330612a6a693c Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 19 Jun 2016 23:01:47 +1000 Subject: [PATCH] Tree draw op now sets appropriate bounds, meaning cloudy brush works properly for /tree. --- Drawing/DrawOps/DrawOp.Performer.cs | 6 +--- Drawing/DrawOps/DrawOp.cs | 8 ++++++ Drawing/DrawOps/TreeDrawOp.cs | 44 +++++++++++++++++++++-------- Generator/RealisticMapGen.cs | 1 + Levels/Physics/OtherPhysics.cs | 4 ++- 5 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Drawing/DrawOps/DrawOp.Performer.cs b/Drawing/DrawOps/DrawOp.Performer.cs index 7aa16506f..19210d5e4 100644 --- a/Drawing/DrawOps/DrawOp.Performer.cs +++ b/Drawing/DrawOps/DrawOp.Performer.cs @@ -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."); diff --git a/Drawing/DrawOps/DrawOp.cs b/Drawing/DrawOps/DrawOp.cs index 6d4aaadfa..5c63bbf58 100644 --- a/Drawing/DrawOps/DrawOp.cs +++ b/Drawing/DrawOps/DrawOp.cs @@ -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; diff --git a/Drawing/DrawOps/TreeDrawOp.cs b/Drawing/DrawOps/TreeDrawOp.cs index a9329fbc0..38242b1ac 100644 --- a/Drawing/DrawOps/TreeDrawOp.cs +++ b/Drawing/DrawOps/TreeDrawOp.cs @@ -35,24 +35,49 @@ namespace MCGalaxy.Drawing.Ops { public Random random; 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; static Brush defBrush = new SolidBrush(Block.leaf, 0); + byte height, top, size; public override long GetBlocksAffected(Level lvl, Vec3S32[] marks) { return -1; } public override void Perform(Vec3S32[] marks, Player p, Level lvl, Brush brush) { - if (brush == null) brush = defBrush; - Vec3U16 P = Clamp(marks[0]); + if (brush == null) brush = defBrush; + Vec3U16 P = Clamp(marks[0]); 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_NotchSwamp) AddNotchSwampTree(p, lvl, P.X, P.Y, P.Z, brush); 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)) @@ -68,14 +93,12 @@ namespace MCGalaxy.Drawing.Ops { 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)) - 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) { - 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); @@ -131,14 +152,13 @@ namespace MCGalaxy.Drawing.Ops { if (random.Next(2) == 0) PlaceBlock(p, lvl, xx, yy, zz, brush); } 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) { - 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); diff --git a/Generator/RealisticMapGen.cs b/Generator/RealisticMapGen.cs index 27da76830..f9896824e 100644 --- a/Generator/RealisticMapGen.cs +++ b/Generator/RealisticMapGen.cs @@ -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); } } diff --git a/Levels/Physics/OtherPhysics.cs b/Levels/Physics/OtherPhysics.cs index 517eb2593..aefd01ef9 100644 --- a/Levels/Physics/OtherPhysics.cs +++ b/Levels/Physics/OtherPhysics.cs @@ -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; }