Add ash tree (Thanks goodlyay)

This commit is contained in:
UnknownShadow200 2017-02-02 20:15:27 +11:00
parent 78b2d5577a
commit 2c2ebfc9c6
8 changed files with 109 additions and 14 deletions

View File

@ -122,7 +122,7 @@ namespace MCGalaxy.Commands.Building {
op.Direction = m[1].Z <= m[0].Z ? 3 : 2; op.Direction = m[1].Z <= m[0].Z ? 3 : 2;
} }
op.Level = p.level; op.SetLevel(p.level);
op.Player = p; op.Player = p;
op.Source = bmp; op.Source = bmp;
op.Layer = dArgs.layer; op.Layer = dArgs.layer;

View File

@ -58,12 +58,12 @@ namespace MCGalaxy.Drawing.Ops {
/// <remarks> Note: You should treat this as coordinates, it is a DrawOpBlock struct for performance reasons. </remarks> /// <remarks> Note: You should treat this as coordinates, it is a DrawOpBlock struct for performance reasons. </remarks>
public DrawOpBlock Coords; public DrawOpBlock Coords;
/// <summary> Level the draw operation is being performed upon. </summary>
public Level Level;
/// <summary> Player that is executing the draw operation. </summary> /// <summary> Player that is executing the draw operation. </summary>
public Player Player; public Player Player;
/// <summary> Level the draw operation is being performed upon. </summary>
public Level Level;
/// <summary> BlockDB change flags for blocks affected by this draw operation. </summary> /// <summary> BlockDB change flags for blocks affected by this draw operation. </summary>
public ushort Flags = BlockDBFlags.Drawn; public ushort Flags = BlockDBFlags.Drawn;
@ -100,6 +100,12 @@ namespace MCGalaxy.Drawing.Ops {
} }
} }
/// <summary> Sets the level associated with this draw operation. </summary>
public void SetLevel(Level lvl) {
Level = lvl;
clip = new Vec3S32(lvl.Width - 1, lvl.Height - 1, lvl.Length - 1);
}
protected DrawOpBlock Place(ushort x, ushort y, ushort z, Brush brush) { protected DrawOpBlock Place(ushort x, ushort y, ushort z, Brush brush) {
Coords.X = x; Coords.Y = y; Coords.Z = z; Coords.X = x; Coords.Y = y; Coords.Z = z;
Coords.Block = brush.NextBlock(this); Coords.Block = brush.NextBlock(this);
@ -115,10 +121,11 @@ namespace MCGalaxy.Drawing.Ops {
return Coords; return Coords;
} }
Vec3S32 clip = new Vec3S32(ushort.MaxValue);
protected Vec3U16 Clamp(Vec3S32 pos) { protected Vec3U16 Clamp(Vec3S32 pos) {
pos.X = Math.Max(0, Math.Min(pos.X, Level.Width - 1)); pos.X = Math.Max(0, Math.Min(pos.X, clip.X));
pos.Y = Math.Max(0, Math.Min(pos.Y, Level.Height - 1)); pos.Y = Math.Max(0, Math.Min(pos.Y, clip.Y));
pos.Z = Math.Max(0, Math.Min(pos.Z, Level.Length - 1)); pos.Z = Math.Max(0, Math.Min(pos.Z, clip.Z));
return new Vec3U16((ushort)pos.X, (ushort)pos.Y, (ushort)pos.Z); return new Vec3U16((ushort)pos.X, (ushort)pos.Y, (ushort)pos.Z);
} }
} }

View File

@ -44,20 +44,21 @@ namespace MCGalaxy.Drawing.Ops {
public static bool Do(DrawOp op, Brush brush, Player p, public static bool Do(DrawOp op, Brush brush, Player p,
Vec3S32[] marks, bool checkLimit = true) { Vec3S32[] marks, bool checkLimit = true) {
op.SetMarks(marks); op.SetMarks(marks);
op.Level = p == null ? null : p.level; Level lvl = p == null ? null : p.level;
op.SetLevel(lvl);
op.Player = p; op.Player = p;
if (op.Level != null && !op.Level.DrawingAllowed) { if (lvl != null && !lvl.DrawingAllowed) {
Player.Message(p, "Drawing commands are turned off on this map."); Player.Message(p, "Drawing commands are turned off on this map.");
return false; return false;
} }
if (op.Level != null && op.Level.BuildAccess.Check(p) == AccessResult.Blacklisted) { if (lvl != null && lvl.BuildAccess.Check(p) == AccessResult.Blacklisted) {
Player.Message(p, "You are blacklisted from building in this map, " + Player.Message(p, "You are blacklisted from building in this map, " +
"hence you cannot draw in this map"); "hence you cannot draw in this map");
return false; return false;
} }
long affected = op.BlocksAffected(op.Level, marks); long affected = op.BlocksAffected(lvl, marks);
if (p != null && op.AffectedByTransform) if (p != null && op.AffectedByTransform)
p.Transform.GetBlocksAffected(ref affected); p.Transform.GetBlocksAffected(ref affected);

View File

@ -51,7 +51,7 @@ namespace MCGalaxy.Drawing.Ops {
public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) { public override void Perform(Vec3S32[] marks, Brush brush, Action<DrawOpBlock> output) {
Vec3S32 p1 = Min, p2 = Max; Vec3S32 p1 = Min, p2 = Max;
baseOp.Level = Level; baseOp.SetLevel(Level);
baseOp.Player = Player; baseOp.Player = Player;
while (true) { while (true) {
@ -96,7 +96,7 @@ namespace MCGalaxy.Drawing.Ops {
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max); Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
wallOp.Min = Min; wallOp.Max = Max; wallOp.Min = Min; wallOp.Max = Max;
baseOp.Min = Min; baseOp.Max = Max; baseOp.Min = Min; baseOp.Max = Max;
wallOp.Level = Level; baseOp.Level = Level; wallOp.SetLevel(Level); baseOp.SetLevel(Level);
wallOp.Player = Player; baseOp.Player = Player; wallOp.Player = Player; baseOp.Player = Player;
while (true) { while (true) {

View File

@ -0,0 +1,82 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Generator.Foilage {
public sealed class AshTree : Tree {
int halfHeight, branchAmount;
const int widthMax = 5, branchHeightMax = 10, clusterSizeMax = 3;
List<Vec3S32> branch = new List<Vec3S32>();
public override int DefaultValue(Random rnd) { return rnd.Next(0, 11); }
public override void SetData(Random rnd, int value) {
this.rnd = rnd;
height = (byte)rnd.Next(5, 10);
halfHeight = height/4;
branchAmount = rnd.Next(10, 25);
}
public override void Generate(ushort x, ushort y, ushort z, TreeOutput output) {
// Do base trunk
Vec3S32 p1 = new Vec3S32(x, y, z);
Vec3S32 p2 = new Vec3S32(x, y + height, z);
Line(p1, p2, output);
for (int i = 0; i < branchAmount; i++) {
DoBranch(x, y, z, output);
}
}
void DoBranch(int x, int y, int z, TreeOutput output) {
int dx = rnd.Next(-widthMax, widthMax);
int dz = rnd.Next(-widthMax, widthMax);
int clusterSize = rnd.Next(1, clusterSizeMax);
int branchStart = rnd.Next(halfHeight, height);
int branchMax = branchStart + rnd.Next(3, branchHeightMax);
int R = clusterSize;
Vec3S32[] marks = new [] {
new Vec3S32(x + dx - R, y + branchMax - R, z + dz - R),
new Vec3S32(x + dx + R, y + branchMax + R, z + dz + R) };
DrawOp op = new EllipsoidDrawOp();
Brush brush = new RandomBrush(new [] { new ExtBlock(Block.leaf, 0) });
op.SetMarks(marks);
op.Perform(marks, brush, b => output(b.X, b.Y, b.Z, b.Block));
Vec3S32 p1 = new Vec3S32(x, branchStart, z);
Vec3S32 p2 = new Vec3S32(x + dx, y + branchMax, z + dz);
Line(p1, p2, output);
}
void Line(Vec3S32 p1, Vec3S32 p2, TreeOutput output) {
LineDrawOp.DrawLine(p1.X, p1.Y, p1.Z, 100, p2.X, p2.Y, p2.Z, branch);
foreach (Vec3S32 P in branch) {
output((ushort)P.X, (ushort)P.Y, (ushort)P.Z, Block.trunk);
}
branch.Clear();
}
}
}

View File

@ -61,7 +61,7 @@ namespace MCGalaxy.Generator.Foilage {
{ "Fern", () => new NormalTree() }, { "Cactus", () => new CactusTree() }, { "Fern", () => new NormalTree() }, { "Cactus", () => new CactusTree() },
{ "Notch", () => new ClassicTree() }, { "Swamp", () => new SwampTree() }, { "Notch", () => new ClassicTree() }, { "Swamp", () => new SwampTree() },
{ "Bamboo", () => new BambooTree() }, { "Palm", () => new PalmTree() }, { "Bamboo", () => new BambooTree() }, { "Palm", () => new PalmTree() },
{ "Oak", () => new OakTree() }, { "Oak", () => new OakTree() }, { "Ash", () => new AshTree() },
}; };
public static Tree Find(string name) { public static Tree Find(string name) {

View File

@ -496,6 +496,7 @@
<Compile Include="Generator\fCraft\MapGenerator.cs" /> <Compile Include="Generator\fCraft\MapGenerator.cs" />
<Compile Include="Generator\fCraft\MapGeneratorArgs.cs" /> <Compile Include="Generator\fCraft\MapGeneratorArgs.cs" />
<Compile Include="Generator\fCraft\Noise.cs" /> <Compile Include="Generator\fCraft\Noise.cs" />
<Compile Include="Generator\Foilage\AshTree.cs" />
<Compile Include="Generator\Foilage\OakTree.cs" /> <Compile Include="Generator\Foilage\OakTree.cs" />
<Compile Include="Generator\Foilage\ForesterTrees.cs" /> <Compile Include="Generator\Foilage\ForesterTrees.cs" />
<Compile Include="Generator\Foilage\StandardTrees.cs" /> <Compile Include="Generator\Foilage\StandardTrees.cs" />

View File

@ -106,6 +106,10 @@ namespace MCGalaxy {
X = x; Y = y; Z = z; X = x; Y = y; Z = z;
} }
public Vec3S32(int value) {
X = value; Y = value; Z = value;
}
public override bool Equals(object obj) { public override bool Equals(object obj) {
return (obj is Vec3S32) && Equals((Vec3S32)obj); return (obj is Vec3S32) && Equals((Vec3S32)obj);
} }