Now /mode supports custom blocks, remove obsolete p.allowTnt

This commit is contained in:
UnknownShadow200 2017-05-18 15:43:25 +10:00
parent 9fee23ebe6
commit 2c1698d7b6
14 changed files with 33 additions and 48 deletions

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.Blocks {
if (!lvl.GrassGrow || !(lvl.physics == 0 || lvl.physics == 5)) { if (!lvl.GrassGrow || !(lvl.physics == 0 || lvl.physics == 5)) {
p.ChangeBlock(x, y, z, block); return; p.ChangeBlock(x, y, z, block); return;
} }
if (p.modeType == Block.dirt || p.modeType == Block.grass) { if (p.ModeBlock.BlockID == Block.dirt || p.ModeBlock.BlockID == Block.grass) {
p.ChangeBlock(x, y, z, block); return; p.ChangeBlock(x, y, z, block); return;
} }

View File

@ -39,12 +39,13 @@ namespace MCGalaxy {
/// <summary> Returns whether the type of this extended block is a fully custom block. </summary> /// <summary> Returns whether the type of this extended block is a fully custom block. </summary>
/// <remarks> Note that core/original/vanilla blocks can be replaced with custom blocks. </remarks> /// <remarks> Note that core/original/vanilla blocks can be replaced with custom blocks. </remarks>
public bool IsCustomType { public bool IsCustomType { get { return BlockID == Block.custom_block; } }
get { return BlockID == Block.custom_block; }
}
/// <summary> Returns whether the type of this extended block is an invalid block. </summary> /// <summary> Returns whether the type of this extended block is the invald block. </summary>
public bool IsInvalidType { get { return BlockID == Block.Invalid; } } public bool IsInvalid { get { return BlockID == Block.Invalid; } }
/// <summary> Returns whether the type of this extended block is the air block. </summary>
public bool IsAir { get { return BlockID == Block.air; } }
/// <summary> Returns the raw (for client side) block ID of this block. </summary> /// <summary> Returns the raw (for client side) block ID of this block. </summary>

View File

@ -62,16 +62,10 @@ namespace MCGalaxy.Commands.Fun {
EndType GetEnd(Player p, string mode) { EndType GetEnd(Player p, string mode) {
if (mode == "") return EndType.Normal; if (mode == "") return EndType.Normal;
if (mode.CaselessEq("destroy")) return EndType.Destroy; if (mode.CaselessEq("destroy")) return EndType.Destroy;
if (mode.CaselessEq("tp") || mode.CaselessEq("teleport")) return EndType.Teleport; if (mode.CaselessEq("tp") || mode.CaselessEq("teleport")) return EndType.Teleport;
if (mode.CaselessEq("explode")) return EndType.Explode;
if (mode.CaselessEq("laser")) return EndType.Laser;
if (mode.CaselessEq("explode")) {
if (!p.allowTnt) Player.Message(p, "Tnt usage is currently disallowed, switching to normal gun.");
return p.allowTnt ? EndType.Explode : EndType.Destroy;
}
if (mode.CaselessEq("laser")) {
if (!p.allowTnt) Player.Message(p, "Tnt usage is currently disallowed, switching to normal gun.");
return p.allowTnt ? EndType.Laser : EndType.Destroy;
}
Help(p); Help(p);
return EndType.Invalid; return EndType.Invalid;
} }
@ -166,9 +160,8 @@ namespace MCGalaxy.Commands.Fun {
return true; return true;
} }
} else if (p.level.physics >= 3) { } else if (p.level.physics >= 3) {
if (type != Block.glass && p.allowTnt) { if (type != Block.glass && doExplode) {
if (doExplode) p.level.MakeExplosion(pos.X, pos.Y, pos.Z, 1);
p.level.MakeExplosion(pos.X, pos.Y, pos.Z, 1);
return true; return true;
} }
} else { } else {

View File

@ -43,7 +43,7 @@ namespace MCGalaxy.Commands.Info {
void PlacedBlock(Player p, ushort x, ushort y, ushort z, ExtBlock block) { void PlacedBlock(Player p, ushort x, ushort y, ushort z, ExtBlock block) {
if (!p.staticCommands) p.ClearBlockchange(); if (!p.staticCommands) p.ClearBlockchange();
block = p.level.GetExtBlock(x, y, z); block = p.level.GetExtBlock(x, y, z);
if (block.IsInvalidType) return; if (block.IsInvalid) return;
p.RevertBlock(x, y, z); p.RevertBlock(x, y, z);
Dictionary<int, string> names = new Dictionary<int, string>(); Dictionary<int, string> names = new Dictionary<int, string>();

View File

@ -33,7 +33,7 @@ namespace MCGalaxy.Commands.Building {
p.cmdTimer = false; p.cmdTimer = false;
p.staticCommands = false; p.staticCommands = false;
p.deleteMode = false; p.deleteMode = false;
p.modeType = 0; p.ModeBlock = ExtBlock.Air;
p.aiming = false; p.aiming = false;
p.onTrain = false; p.onTrain = false;
p.isFlying = false; p.isFlying = false;

View File

@ -42,7 +42,7 @@ namespace MCGalaxy.Commands.Building {
string[] args = message.SplitSpaces(2); string[] args = message.SplitSpaces(2);
string block = args[0].ToLower(); string block = args[0].ToLower();
data.Block = GetBlock(p, block, ref allMessage); data.Block = GetBlock(p, block, ref allMessage);
if (data.Block.IsInvalidType) return; if (data.Block.IsInvalid) return;
if (!CommandParser.IsBlockAllowed(p, "place a message block of ", data.Block)) return; if (!CommandParser.IsBlockAllowed(p, "place a message block of ", data.Block)) return;
if (allMessage) { if (allMessage) {

View File

@ -42,35 +42,26 @@ namespace MCGalaxy.Commands.Building {
} }
if (message == "") { if (message == "") {
if (p.modeType != 0) { if (p.ModeBlock != ExtBlock.Air) {
Player.Message(p, "&b{0} %Smode: &cOFF", Block.Name(p.modeType).Capitalize()); Player.Message(p, "&b{0} %Smode: &cOFF", p.level.BlockName(p.ModeBlock));
p.modeType = 0; p.ModeBlock = ExtBlock.Air;
} else { } else {
Help(p); Help(p);
} }
return; return;
} }
byte block = Block.Byte(message); ExtBlock block;
if (block == Block.Invalid) { Player.Message(p, "Could not find block given."); return; } if (!CommandParser.GetBlock(p, message, out block)) return;
if (block == Block.air) { Player.Message(p, "Cannot use Air Mode."); return; } if (block == ExtBlock.Air) { Player.Message(p, "Cannot use Air Mode."); return; }
if (!p.allowTnt && (block == Block.tnt || block == Block.bigtnt || block == Block.smalltnt
|| block == Block.nuketnt || block == Block.tntexplosion)) {
Player.Message(p, "Tnt usage is not allowed at the moment"); return;
}
if (!p.allowTnt && block == Block.fire) {
Player.Message(p, "Tnt usage is not allowed at the moment, fire is a lighter for tnt and is also disabled"); return;
}
if (!CommandParser.IsBlockAllowed(p, "place ", (ExtBlock)block)) return; if (!CommandParser.IsBlockAllowed(p, "place ", (ExtBlock)block)) return;
string name = Block.Name(block).Capitalize(); if (p.ModeBlock == block) {
if (p.modeType == block) { Player.Message(p, "&b{0} %Smode: &cOFF", p.level.BlockName(p.ModeBlock));
Player.Message(p, "&b{0} %Smode: &cOFF", name); p.ModeBlock = ExtBlock.Air;
p.modeType = 0;
} else { } else {
p.modeType = block; p.ModeBlock = block;
Player.Message(p, "&b{0} %Smode: &aON", name); Player.Message(p, "&b{0} %Smode: &aON", p.level.BlockName(p.ModeBlock));
} }
} }

View File

@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Building {
string type = p.painting ? "&aON" : "&cOFF"; string type = p.painting ? "&aON" : "&cOFF";
Player.Message(p, "Painting mode: " + type + "%S."); Player.Message(p, "Painting mode: " + type + "%S.");
p.modeType = 0; p.ModeBlock = ExtBlock.Air;
} }
public override void Help(Player p) { public override void Help(Player p) {

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
p.staticCommands = !p.staticCommands; p.staticCommands = !p.staticCommands;
p.ClearBlockchange(); p.ClearBlockchange();
p.modeType = 0; p.ModeBlock = ExtBlock.Air;
Player.Message(p, "Static mode: &a" + p.staticCommands); Player.Message(p, "Static mode: &a" + p.staticCommands);
if (message == "" || !p.staticCommands) return; if (message == "" || !p.staticCommands) return;

View File

@ -33,7 +33,7 @@ namespace MCGalaxy.Drawing.Brushes {
GetRaw(parts, filter, args, out blocks, out count); GetRaw(parts, filter, args, out blocks, out count);
// check if we're allowed to place the held block // check if we're allowed to place the held block
if (blocks[0].IsInvalidType && !CommandParser.IsBlockAllowed(p, "draw with ", blocks[0])) return null; if (blocks[0].IsInvalid && !CommandParser.IsBlockAllowed(p, "draw with ", blocks[0])) return null;
for (int i = 0, j = 0; i < parts.Length; i++ ) { for (int i = 0, j = 0; i < parts.Length; i++ ) {
if (parts[i] == "") continue; if (parts[i] == "") continue;

View File

@ -441,7 +441,7 @@ namespace MCGalaxy {
BlockDefinition def = GetBlockDef(block); BlockDefinition def = GetBlockDef(block);
if (def != null) return def.Name.Replace(" ", ""); if (def != null) return def.Name.Replace(" ", "");
return block.BlockID != Block.custom_block ? Block.Name(block.BlockID) : block.ExtID.ToString(); return block.BlockID != Block.custom_block ? Block.Name(block.BlockID).Capitalize() : block.ExtID.ToString();
} }
public bool LightPasses(ExtBlock block) { public bool LightPasses(ExtBlock block) {

View File

@ -215,7 +215,7 @@ namespace MCGalaxy {
//Games //Games
public DateTime lastDeath = DateTime.UtcNow; public DateTime lastDeath = DateTime.UtcNow;
public byte modeType; public ExtBlock ModeBlock;
public ExtBlock RawHeldBlock = (ExtBlock)Block.rock; public ExtBlock RawHeldBlock = (ExtBlock)Block.rock;
public ExtBlock[] BlockBindings = new ExtBlock[Block.Count]; public ExtBlock[] BlockBindings = new ExtBlock[Block.Count];
public string[] CmdBindings = new string[10]; public string[] CmdBindings = new string[10];

View File

@ -122,7 +122,7 @@ namespace MCGalaxy {
} }
} }
if (modeType != 0) block = (ExtBlock)modeType; if (!ModeBlock.IsAir) block = ModeBlock;
if (doDelete) { if (doDelete) {
bool deleted = DeleteBlock(oldB, x, y, z, block); bool deleted = DeleteBlock(oldB, x, y, z, block);
} else { } else {

View File

@ -95,7 +95,7 @@ namespace MCGalaxy {
public ExtBlock GetHeldBlock() { public ExtBlock GetHeldBlock() {
if (modeType != 0) return (ExtBlock)modeType; if (!ModeBlock.IsAir) return ModeBlock;
return BlockBindings[RawHeldBlock.RawID]; return BlockBindings[RawHeldBlock.RawID];
} }