Skip to content
Permalink
Browse files

Initial support for custom blocks replacing core blocks.

  • Loading branch information...
UnknownShadow200 committed Aug 12, 2017
1 parent b400a3b commit b412bb969c71516e5915f96125650ee9090916bf
@@ -765,22 +765,16 @@ private static void WallsHandler(Player player, CommandReader cmd)
};

private static void DisPlace(Player player, CommandReader cmd) {
Block block;
if (cmd.CountRemaining < 2) {
CdDisPlace.PrintUsage(player);
return;
}
string tryBlock = cmd.Next();
if (!Map.GetBlockByName(player.World, tryBlock, false, out block)) {
player.Message("Invalid block name/id: {0}", tryBlock);
return;
}
}

Block block;
if (!cmd.NextBlock(player, false, out block)) return;
int dis;
string tryInt = cmd.Next();
if (!int.TryParse(tryInt, out dis)) {
player.Message("Invalid distance: {0}", tryInt);
return;
}
if (!cmd.NextInt(out dis)) return;

dis = dis * 32;
byte yaw = player.Position.R, pitch = player.Position.L;
Vector3I Pos;
@@ -857,26 +851,16 @@ private static void WallsHandler(Player player, CommandReader cmd)
Vector3I coords;
int x, y, z;
if (cmd.NextInt(out x) && cmd.NextInt(out y) && cmd.NextInt(out z)) {
if (cmd.HasNext) {
string last = cmd.Next();
if (!Map.GetBlockByName(player.World, last, false, out block)) {
player.Message("\"{0}\" is not a valid block type", last);
return;
}
}
if (cmd.HasNext && !cmd.NextBlock(player, false, out block)) return;

coords = new Vector3I(x, y, z);
} else if (isConsole) {
player.Message("Invalid coordinates!");
return;
} else {
cmd.Rewind();
if (cmd.HasNext) {
string last = cmd.Next();
if (!Map.GetBlockByName(player.World, last, false, out block)) {
player.Message("\"{0}\" is not a valid block type", last);
return;
}
}
if (cmd.HasNext && !cmd.NextBlock(player, false, out block)) return;

coords = new Vector3I(player.Position.BlockX, player.Position.BlockY, (player.Position.Z - 64) / 32);
}
World world;
@@ -1369,15 +1369,11 @@ static class CpeCommands {
}

static void CustomBlockInfoHandler(Player p, CommandReader cmd, bool global, BlockDefinition[] defs) {
string input = cmd.Next() ?? "n/a";
string scope = global ? "global" : "level";
string name = global ? "/gb" : "/lb";

Block id;
if (!Map.GetBlockByName(p.World, input, false, out id) || id < Map.MaxCustomBlockType) {
p.Message("No blocks by that name or id!");
return;
}
if (!cmd.NextBlock(p, false, out id)) return;

BlockDefinition def = GetCustomBlock(global, defs, (byte)id);
if (def == null) {
@@ -1429,14 +1425,11 @@ static class CpeCommands {
}

static void CustomBlockRemoveHandler(Player p, CommandReader cmd, bool global, BlockDefinition[] defs) {
string input = cmd.Next() ?? "n/a";
Block blockID;
string scope = global ? "global" : "level";
string name = global ? "/gb" : "/lb";
if (!Map.GetBlockByName(p.World, input, false, out blockID) || blockID < Map.MaxCustomBlockType) {
p.Message("No blocks by that Name/ID!");
return;
}
if (!cmd.NextBlock(p, false, out blockID)) return;

BlockDefinition def = GetCustomBlock(global, defs, (byte)blockID);
if (def == null) {
p.Message("There is no {0} custom block with that name/id.", scope);
@@ -1664,22 +1657,20 @@ static class CpeCommands {
}

static void CustomBlockDuplicateHandler(Player p, CommandReader cmd, bool global, BlockDefinition[] defs) {
string input1 = cmd.Next() ?? "n/a", input2 = cmd.Next() ?? "n/a";
Block srcBlock = Block.None;
byte dstBlock = (byte)Block.None;
Block srcBlock, dstBlock;
string scope = global ? "global" : "level";
string name = global ? "/gb" : "/lb";

if (!Map.GetBlockByName(p.World, input1, false, out srcBlock) || srcBlock <= Map.MaxCustomBlockType) {
p.Message("There is no {1} custom block with the id or name: &a{0}", input1, scope);
p.Message("Use \"&h{1} list&S\" to see a list of {0} custom blocks.", scope, name);
return;
}
if (!Byte.TryParse(input2, out dstBlock) || dstBlock <= (byte)Map.MaxCustomBlockType) {
p.Message("Destination must be a numerical id and greater than 65."); return;
if (!cmd.NextBlock(p, false, out srcBlock)) return;
if (!cmd.NextBlock(p, false, out dstBlock)) return;
if (dstBlock == Block.Air || dstBlock == Block.None) {
p.Message("Destination block cannot have 0 or 255 ID."); return;
}

BlockDefinition srcDef = GetCustomBlock(global, defs, (byte)srcBlock);
if (srcDef == null && srcBlock <= Map.MaxCustomBlockType)
srcDef = DefaultSet.MakeCustomBlock(srcBlock);

if (srcDef == null) {
p.Message("There is no {1} custom block with the id: &a{0}", (byte)srcBlock, scope);
p.Message("Use \"&H{1} list&S\" to see a list of {0} custom blocks.", scope, name);
@@ -1706,16 +1697,13 @@ static class CpeCommands {
}

static void CustomBlockEditHandler(Player p, CommandReader cmd, bool global, BlockDefinition[] defs) {
string input = cmd.Next() ?? "n/a";
Block blockID;
if (!Map.GetBlockByName(p.World, input, false, out blockID) || blockID < Map.MaxCustomBlockType) {
p.Message("No blocks by that Name/ID!");
return;
}

BlockDefinition def = GetCustomBlock(global, defs, (byte)blockID);
string scope = global ? "global" : "level";
string name = global ? "/gb" : "/lb";

if (!cmd.NextBlock(p, false, out blockID)) return;

BlockDefinition def = GetCustomBlock(global, defs, (byte)blockID);
if (def == null) {
p.Message("There is no {0} custom block with that Name/ID", scope); return;
}
@@ -2017,8 +2005,8 @@ static class CpeCommands {
p.Message("Provided block id is not a number.");
return false;
}
if (blockId <= 65 || blockId >= 255) {
p.Message("Block id must be between 65-254");
if (blockId == 0 || blockId >= 255) {
p.Message("Block id must be between 1-254");
return false;
}
return true;
@@ -373,7 +373,7 @@ public sealed partial class Player {

// Holding an invalid block
Block held = (Block)id;
if (held > Block.StoneBrick && World.BlockDefs[id] == null) {
if (held > Map.MaxCustomBlockType && World.BlockDefs[id] == null) {
HeldBlock = Block.Stone; return;
}
if (HeldBlock == held) return;
@@ -1253,7 +1253,7 @@ bool LoginSequence()

if (!supportsBlockDefs) return;
BlockDefinition[] defs = World.BlockDefs;
for (int i = (int)Map.MaxCustomBlockType + 1; i < defs.Length; i++) {
for (int i = (int)Block.Air + 1; i < defs.Length; i++) {
if (defs[i] == null) continue;
Send(Packet.MakeSetBlockPermission((Block)i, build, delete));
}
@@ -123,7 +123,7 @@ public sealed class BlockDefinition {

internal static void SendNowRemoveOldBlocks(Player p, World oldWorld) {
BlockDefinition[] defs = oldWorld.BlockDefs;
for (int i = (int)Map.MaxCustomBlockType + 1; i < defs.Length; i++) {
for (int i = (int)Block.Air + 1; i < defs.Length; i++) {
BlockDefinition def = defs[i];
if (def == null || def == GlobalDefs[i]) continue;
p.SendNow(Packet.MakeRemoveBlockDefinition((byte)i));
@@ -132,7 +132,7 @@ public sealed class BlockDefinition {

internal static void SendNowBlocks(Player p) {
BlockDefinition[] defs = p.World.BlockDefs;
for (int i = (int)Map.MaxCustomBlockType + 1; i < defs.Length; i++) {
for (int i = (int)Block.Air + 1; i < defs.Length; i++) {
BlockDefinition def = defs[i];
if (def == null) continue;
p.SendNow(GetPacket(p, def));

0 comments on commit b412bb9

Please sign in to comment.
You can’t perform that action at this time.