From 7b58e480dfd6c02684a570d9fd40062cb8a895e3 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 11 Jun 2016 12:23:02 +1000 Subject: [PATCH] Autoload.txt should also work with physics = 4 and physics = 5. --- Drawing/Brushes/CloudyBrush.cs | 9 ++++----- Drawing/Brushes/FrequencyBrush.cs | 22 +++++++++++----------- Drawing/Brushes/RandomBrush.cs | 6 +++--- Server/Server.Tasks.cs | 2 +- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Drawing/Brushes/CloudyBrush.cs b/Drawing/Brushes/CloudyBrush.cs index 515be3a35..42850f2a9 100644 --- a/Drawing/Brushes/CloudyBrush.cs +++ b/Drawing/Brushes/CloudyBrush.cs @@ -23,7 +23,7 @@ using MCGalaxy.Generator; namespace MCGalaxy.Drawing.Brushes { - public sealed class CloudyBrush : FrequencyBrush { + public sealed class CloudyBrush : Brush { readonly ExtBlock[] blocks; readonly int[] counts; readonly float[] thresholds; @@ -68,17 +68,16 @@ namespace MCGalaxy.Drawing.Brushes { n.Lacunarity = 2; int[] count; - ExtBlock[] toAffect = GetBlocks(args, out count, + ExtBlock[] toAffect = FrequencyBrush.GetBlocks(args, out count, Filter, arg => Handler(arg, args.Player, ref n)); if (toAffect == null) return null; return new CloudyBrush(toAffect, count, n); } - // We want to handle non block options. + // Only want to handle non block options. static bool Filter(string arg) { - if (arg.Length < 2) return true; - return arg[1] != '_'; + return arg.Length < 2 || arg[1] != '_'; } static bool Handler(string arg, Player p, ref NoiseArgs args) { diff --git a/Drawing/Brushes/FrequencyBrush.cs b/Drawing/Brushes/FrequencyBrush.cs index d0690418b..8b4033e6d 100644 --- a/Drawing/Brushes/FrequencyBrush.cs +++ b/Drawing/Brushes/FrequencyBrush.cs @@ -16,24 +16,24 @@ permissions and limitations under the Licenses. */ using System; -using System.Collections.Generic; using MCGalaxy.Commands.Building; -using MCGalaxy.Drawing.Ops; namespace MCGalaxy.Drawing.Brushes { - public abstract class FrequencyBrush : Brush { + /// Contains helper methods for brushes that have blocks with + /// optional frequency counts (e.g. random and cloudy brushes) + public static class FrequencyBrush { - protected static ExtBlock[] GetBlocks(BrushArgs args, out int[] count, - Predicate filter, Predicate handler) { - string[] parts = args.Message.Split(' '); - Player p = args.Player; + public static ExtBlock[] GetBlocks(BrushArgs args, out int[] count, + Predicate filter, Predicate handler) { + string[] parts = args.Message.Split(' '); + Player p = args.Player; ExtBlock[] blocks; GetRaw(parts, filter, args, out blocks, out count); for (int i = 0, j = 0; i < parts.Length; i++ ) { - if (parts[i] == "") continue; - + if (parts[i] == "") continue; + // Brush specific args if (!filter(parts[i])) { if (!handler(parts[i])) return null; @@ -48,6 +48,7 @@ namespace MCGalaxy.Drawing.Brushes { blocks[j].Type = type; blocks[j].ExtType = extType; if (sepIndex < 0) { j++; continue; } + int chance; if (!int.TryParse(parts[i].Substring(sepIndex + 1), out chance) || chance <= 0 || chance > 10000) { @@ -80,10 +81,9 @@ namespace MCGalaxy.Drawing.Brushes { blocks[0] = new ExtBlock(args.Type, args.ExtType); } - protected static ExtBlock[] Combine(ExtBlock[] toAffect, int[] count) { + public static ExtBlock[] Combine(ExtBlock[] toAffect, int[] count) { int sum = 0; for (int i = 0; i < count.Length; i++) sum += count[i]; - if (toAffect.Length == 1) sum += 1; ExtBlock[] blocks = new ExtBlock[sum]; for (int i = 0, index = 0; i < toAffect.Length; i++) { diff --git a/Drawing/Brushes/RandomBrush.cs b/Drawing/Brushes/RandomBrush.cs index 92306c163..0aefb36dc 100644 --- a/Drawing/Brushes/RandomBrush.cs +++ b/Drawing/Brushes/RandomBrush.cs @@ -22,7 +22,7 @@ using MCGalaxy.Drawing.Ops; namespace MCGalaxy.Drawing.Brushes { - public sealed class RandomBrush : FrequencyBrush { + public sealed class RandomBrush : Brush { readonly ExtBlock[] blocks; readonly int seed; @@ -44,10 +44,10 @@ namespace MCGalaxy.Drawing.Brushes { public static Brush Process(BrushArgs args) { int[] count; - ExtBlock[] toAffect = GetBlocks(args, out count, P => true, null); + ExtBlock[] toAffect = FrequencyBrush.GetBlocks(args, out count, P => true, null); if (toAffect == null) return null; - ExtBlock[] blocks = Combine(toAffect, count); + ExtBlock[] blocks = FrequencyBrush.Combine(toAffect, count); return new RandomBrush(blocks); } diff --git a/Server/Server.Tasks.cs b/Server/Server.Tasks.cs index 423bdda27..43c56df61 100644 --- a/Server/Server.Tasks.cs +++ b/Server/Server.Tasks.cs @@ -105,7 +105,7 @@ namespace MCGalaxy { } else { try { int temp = int.Parse(value); - if (temp >= 0 && temp <= 3) + if (temp >= 0 && temp <= 5) mainLevel.setPhysics(temp); } catch { s.Log("Physics variable invalid");