Skip to content

Commit

Permalink
Improve /blocks to also include custom blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Sep 4, 2020
1 parent 9a81d0e commit 04589ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
7 changes: 5 additions & 2 deletions MCGalaxy/Blocks/Block.Convert.cs
Expand Up @@ -25,9 +25,12 @@ public static partial class Block {
internal static string[] coreNames = new string[Block.Count];
public static bool Undefined(BlockID block) { return IsPhysicsType(block) && coreNames[block].CaselessEq("unknown"); }

public static bool ExistsGlobal(BlockID b) {
public static bool ExistsGlobal(BlockID b) { return ExistsFor(Player.Console, b); }

public static bool ExistsFor(Player p, BlockID b) {
if (b < Block.Count) return !Undefined(b);
if (b >= Block.Extended && b < Block.Extended + Block.CpeCount) return false;

if (!p.IsSuper) return p.level.GetBlockDef(b) != null;
return BlockDefinition.GlobalDefs[b] != null;
}

Expand Down
31 changes: 19 additions & 12 deletions MCGalaxy/Commands/Information/CmdBlocks.cs
Expand Up @@ -32,39 +32,46 @@ public sealed class CmdBlocks : Command2 {

public override void Use(Player p, string message, CommandData data) {
string[] args = message.SplitSpaces();
string modifier = args.Length > 1 ? args[1] : "";
string modifier = args.Length > 1 ? args[1] : "";
string type = args[0];
BlockID block;

if (type.Length == 0 || type.CaselessEq("basic")) {
p.Message("Basic blocks: ");
MultiPageOutput.Output(p, BasicBlocks(),
b => FormatBlockName(p, b),
"Blocks basic", "blocks", modifier, false);
OutputBlocks(p, "basic", modifier,
b => !Block.IsPhysicsType(b));
} else if (type.CaselessEq("all") || type.CaselessEq("complex")) {
p.Message("Complex blocks: ");
MultiPageOutput.Output(p, ComplexBlocks(),
b => FormatBlockName(p, b),
"Blocks complex", "blocks", modifier, false);
OutputBlocks(p, "complex", modifier,
b => Block.IsPhysicsType(b));
} else if ((block = Block.Parse(p, type)) != Block.Invalid) {
OutputBlockInfo(p, block);
} else if (Group.Find(type) != null) {
Group grp = Group.Find(type);
p.Message("Blocks which {0} %Scan place: ", grp.ColoredName);
MultiPageOutput.Output(p, RankBlocks(grp.Permission),
b => FormatBlockName(p, b),
"Blocks " + type, "blocks", modifier, false);
OutputBlocks(p, type, modifier,
b => grp.Blocks[b]);
} else if (args.Length > 1) {
Help(p);
} else {
p.Message("Unable to find block or rank");
}
}

static void OutputBlocks(Player p, string type, string modifier, Predicate<BlockID> selector) {
List<BlockID> blocks = new List<BlockID>(Block.ExtendedCount);
for (BlockID b = 0; b < Block.ExtendedCount; b++) {
if (Block.ExistsFor(p, b) && selector(b)) blocks.Add(b);
}

MultiPageOutput.Output(p, blocks, b => FormatBlockName(p, b),
"Blocks " + type, "blocks", modifier, false);
}

static List<BlockID> BasicBlocks() {
List<BlockID> blocks = new List<BlockID>(Block.CpeCount);
for (BlockID block = Block.Air; block < Block.CpeCount; block++) {
blocks.Add(block);
for (BlockID block = Block.Air; block < Block.CpeCount; block++) {
blocks.Add(block);
}
return blocks;
}
Expand Down

0 comments on commit 04589ff

Please sign in to comment.