Skip to content

Commit 0a79f4c

Browse files
Allow doing gb/lb copy to a non-existent block ID.
1 parent c4890d8 commit 0a79f4c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

fCraft/Commands/CommandReader.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,18 @@ public bool NextBlock([CanBeNull] Player player, bool allowNoneBlock, out Block
229229
return ParseBlock(blockName, player, allowNoneBlock, ref block);
230230
}
231231

232+
public bool NextRawBlock([CanBeNull] Player player, out Block block) {
233+
string name = Next();
234+
block = Block.None;
235+
if (name == null) return false;
236+
237+
byte raw;
238+
if (byte.TryParse(name, out raw)) { block = (Block)raw; return true; }
239+
240+
return ParseBlock(name, player, false, ref block);
241+
}
232242

233-
bool ParseBlock(string blockName, [CanBeNull] Player player, bool allowNoneBlock, ref Block block) {
243+
static bool ParseBlock(string blockName, [CanBeNull] Player player, bool allowNoneBlock, ref Block block) {
234244
World world = player == null ? null : player.World;
235245
if (Map.GetBlockByName(world, blockName, true, out block)) {
236246
if (block != Block.None || allowNoneBlock) {

fCraft/Commands/CpeCommands.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,8 +1659,8 @@ static void CustomBlockDuplicateHandler(Player p, CommandReader cmd, bool global
16591659
string scope = global ? "global" : "level";
16601660
string name = global ? "/gb" : "/lb";
16611661

1662-
if (!cmd.NextBlock(p, false, out srcBlock)) return;
1663-
if (!cmd.NextBlock(p, false, out dstBlock)) return;
1662+
if (!cmd.NextRawBlock(p, out srcBlock)) return;
1663+
if (!cmd.NextRawBlock(p, out dstBlock)) return;
16641664
if (dstBlock == Block.Air || dstBlock == Block.None) {
16651665
p.Message("Destination block cannot have 0 or 255 ID."); return;
16661666
}
@@ -1699,7 +1699,7 @@ static void CustomBlockEditHandler(Player p, CommandReader cmd, bool global, Blo
16991699
string scope = global ? "global" : "level";
17001700
string name = global ? "/gb" : "/lb";
17011701

1702-
if (!cmd.NextBlock(p, false, out blockID)) return;
1702+
if (!cmd.NextRawBlock(p, out blockID)) return;
17031703

17041704
BlockDefinition def = GetCustomBlock(global, defs, (byte)blockID);
17051705
if (def == null) {

0 commit comments

Comments
 (0)