And fix all the compile errors. Now comes the fun part of testing everything.

This commit is contained in:
UnknownShadow200 2018-02-05 16:27:35 +11:00
parent dd57ed8f67
commit 2a19154580
54 changed files with 285 additions and 264 deletions

View File

@ -55,12 +55,11 @@ namespace MCGalaxy.Gui {
if (!blockPropsChanged[i].Changed) continue;
Block.Props[i] = blockPropsChanged[i];
}
foreach (BlockPerms perms in blockPermsChanged) {
BlockPerms.List[perms.Block] = perms;
if (perms.Block < Block.CpeCount) {
BlockPerms.ResendAllBlockPermissions();
}
BlockPerms.List[perms.ID] = perms;
}
BlockPerms.ResendAllBlockPermissions();
BlockProps.Save("core", Block.Props, Block.CorePropsLock, null);
BlockPerms.Save();
@ -79,7 +78,7 @@ namespace MCGalaxy.Gui {
void blk_list_SelectedIndexChanged(object sender, EventArgs e) {
blockID = Block.Byte(blk_list.SelectedItem.ToString());
blockPermsOrig = BlockPerms.List[blockID];
blockPerms = blockPermsChanged.Find(p => p.Block == blockID);
blockPerms = blockPermsChanged.Find(p => p.ID == blockID);
BlockInitSpecificArrays();
blockSupressEvents = true;

View File

@ -18,6 +18,7 @@
using MCGalaxy.Blocks.Physics;
using System;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Blocks {
@ -66,7 +67,7 @@ namespace MCGalaxy.Blocks {
}
// Use red wool to detonate c4
ushort held = p.BlockBindings[p.RawHeldBlock.RawID];
BlockID held = p.BlockBindings[(BlockRaw)p.RawHeldBlock];
if (held == Block.Red) {
Player.Message(p, "Placed detonator block, delete it to detonate.");
C4Det(p, Block.C4Detonator, x, y, z); return;

View File

@ -38,11 +38,15 @@ namespace MCGalaxy {
}
public static string GetName(Player p, BlockID block) {
if (!Player.IsSuper(p)) return p.level.BlockName(block);
if (block < Block.Extended) return coreNames[block];
BlockDefinition def;
if (!Player.IsSuper(p) && !IsPhysicsType(block)) {
def = p.level.GetBlockDef(block);
if (def != null) return def.Name.Replace(" ", "");
}
if (block < Block.Extended) return coreNames[block];
BlockRaw raw = (BlockRaw)block;
BlockDefinition def = BlockDefinition.GlobalDefs[raw];
def = BlockDefinition.GlobalDefs[raw];
return def != null ? def.Name.Replace(" ", "") : raw.ToString();
}

View File

@ -86,12 +86,6 @@ namespace MCGalaxy {
return false;
}
public static bool BuildIn(byte block) {
if (block == Op_Water || block == Op_Lava || Props[block].IsPortal || Props[block].IsMessageBlock) return false;
block = Convert(block);
return block >= Water && block <= StillLava;
}
public static bool LightPass(BlockID block) {
switch (Convert(block)) {
case Air:
@ -108,8 +102,7 @@ namespace MCGalaxy {
return false;
}
public static bool NeedRestart(byte block)
{
public static bool NeedRestart(BlockID block) {
switch (block)
{
case Train:
@ -187,8 +180,16 @@ namespace MCGalaxy {
return (BlockID)(raw | (extended ? Block.Extended : Block.Air));
}
public static BlockID MapOldRaw(BlockID raw) {
return IsPhysicsType(raw) ? ((BlockID)(Block.Extended | raw)) : raw;
}
public static bool IsPhysicsType(BlockID block) {
return block >= Block.CpeCount && block < Block.Extended;
}
public static bool VisuallyEquals(BlockID a, BlockID b) {
return Block.Convert(a) == Block.Convert(b);
}
}
}

View File

@ -20,6 +20,8 @@ using System.IO;
using MCGalaxy.Blocks;
using MCGalaxy.Network;
using Newtonsoft.Json;
using BlockID_ = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
public sealed class BlockDefinition {
@ -145,20 +147,21 @@ namespace MCGalaxy {
public static void UpdateGlobalBlockProps() {
for (int i = 0; i < GlobalProps.Length; i++) {
ushort block = Block.FromRaw((byte)i);
BlockID_ block = Block.FromRaw((byte)i);
GlobalProps[i] = BlockProps.MakeDefault();
GlobalProps[i] = DefaultProps(block);
}
BlockProps.Load("global", GlobalProps, GlobalPropsLock, false);
}
internal static BlockProps DefaultProps(ushort block) {
internal static BlockProps DefaultProps(BlockID_ block) {
BlockRaw raw = (BlockRaw)block;
if (Block.IsPhysicsType(block)) {
return Block.Props[block];
} else if (!block.IsCustomType && GlobalDefs[block.RawID] == null) {
return Block.Props[block.RawID];
} else if (block < Block.Extended && GlobalDefs[raw] == null) {
return Block.Props[raw];
} else {
return GlobalProps[block.RawID];
return GlobalProps[raw];
}
}
@ -168,16 +171,16 @@ namespace MCGalaxy {
for (int i = 0; i < lvl.CustomBlockDefs.Length; i++) {
if (lvl.CustomBlockDefs[i] != oldGlobalDefs[i]) continue;
ushort block = Block.FromRaw((byte)i);
BlockID_ block = Block.FromRaw((byte)i);
lvl.Props[block] = DefaultProps(block);
lvl.UpdateCustomBlock(block.RawID, GlobalDefs[i]);
lvl.UpdateCustomBlock((BlockRaw)block, GlobalDefs[i]);
}
}
}
public static void Add(BlockDefinition def, BlockDefinition[] defs, Level level) {
byte raw = def.BlockID;
BlockRaw raw = def.BlockID;
bool global = defs == GlobalDefs;
if (global) UpdateGlobalCustom(raw, def);
@ -199,7 +202,7 @@ namespace MCGalaxy {
}
public static void Remove(BlockDefinition def, BlockDefinition[] defs, Level level) {
byte raw = def.BlockID;
BlockRaw raw = def.BlockID;
bool global = defs == GlobalDefs;
if (global) UpdateGlobalCustom(raw, null);
@ -232,7 +235,7 @@ namespace MCGalaxy {
}
}
static void UpdateGlobalCustom(byte raw, BlockDefinition def) {
static void UpdateGlobalCustom(BlockRaw raw, BlockDefinition def) {
Level[] loaded = LevelInfo.Loaded.Items;
foreach (Level lvl in loaded) {
if (lvl.CustomBlockDefs[raw] != GlobalDefs[raw]) continue;
@ -249,8 +252,8 @@ namespace MCGalaxy {
return def.BlockID;
}
byte id;
if (!byte.TryParse(msg, out id) || defs[id] == null) return -1;
BlockRaw id;
if (!BlockRaw.TryParse(msg, out id) || defs[id] == null) return -1;
return id;
}
@ -293,14 +296,14 @@ namespace MCGalaxy {
}
}
public static void UpdateFallback(bool global, byte block, Level level) {
public static void UpdateFallback(bool global, BlockRaw raw, Level level) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (!global && pl.level != level) continue;
if (pl.hasBlockDefs) continue;
// if custom block is replacing core block, need to always reload for fallback
if (block >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue;
if (raw >= Block.CpeCount && !pl.level.MayHaveCustomBlocks) continue;
LevelActions.ReloadMap(pl, pl, false);
}

View File

@ -106,9 +106,9 @@ namespace MCGalaxy.Blocks {
w.WriteLine("");
foreach (BlockPerms perms in list) {
if (Block.Undefined(perms.Block)) continue;
if (Block.Undefined(perms.ID)) continue;
string line = perms.Block + " : " + (int)perms.MinRank + " : "
string line = perms.ID + " : " + (int)perms.MinRank + " : "
+ CommandPerms.JoinPerms(perms.Disallowed) + " : " + CommandPerms.JoinPerms(perms.Allowed);
w.WriteLine(line);
}
@ -140,8 +140,8 @@ namespace MCGalaxy.Blocks {
// Format is - Name/ID : Lowest : Disallow : Allow
line.Replace(" ", "").FixedSplit(args, ':');
ushort block;
if (!ushort.TryParse(args[0], out block)) {
BlockID block;
if (!BlockID.TryParse(args[0], out block)) {
block = Block.Byte(args[0]);
}
if (block == Block.Invalid) continue;
@ -163,10 +163,11 @@ namespace MCGalaxy.Blocks {
}
static void SetDefaultPerms() {
for (int i = 0; i < Block.Count; i++) {
BlockProps defProps = BlockProps.MakeDefault();
for (int i = 0; i < Block.ExtendedCount; i++) {
BlockPerms perms = new BlockPerms();
perms.Block = (byte)i;
BlockProps props = Block.Props[i];
perms.ID = (BlockID)i;
BlockProps props = i < Block.Count ? Block.Props[i] : defProps;
if (i == Block.Invalid) {
perms.MinRank = LevelPermission.Admin;

View File

@ -164,7 +164,8 @@ namespace MCGalaxy.Blocks {
scope[idx].AnimalAI = (AnimalAI)ai;
}
if (parts.Length > 11) {
byte.TryParse(parts[11], out scope[idx].StackBlock); // TODO: this is raw ID, need to fixup
BlockID.TryParse(parts[11], out scope[idx].StackBlock);
scope[idx].StackBlock = Block.MapOldRaw(scope[idx].StackBlock);
}
if (parts.Length > 12) {
bool.TryParse(parts[12], out scope[idx].OPBlock);

View File

@ -18,6 +18,7 @@
using System;
using System.Text;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Blocks {
@ -27,7 +28,7 @@ namespace MCGalaxy.Blocks {
/// <summary> Constructs a custom block, with the default properties of the given classic/CPE block. </summary>
public static BlockDefinition MakeCustomBlock(BlockID b) {
BlockDefinition def = new BlockDefinition();
def.BlockID = b;
def.BlockID = (BlockRaw)b;
def.Name = Name(b);
def.CollideType = Collide(b);
def.Speed = 1;
@ -47,7 +48,7 @@ namespace MCGalaxy.Blocks {
def.FogDensity = FogDensity(b);
ColorDesc fog = FogColor(b);
def.FogR = fog.R; def.FogG = fog.G; def.FogB = fog.B;
def.FallBack = b;
def.FallBack = (BlockRaw)b;
def.MaxX = 16; def.MaxZ = Height(b); def.MaxY = 16;
def.Version2 = true;

View File

@ -17,6 +17,7 @@
*/
using System;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Blocks.Physics {
public static class ActivateablePhysics {
@ -84,9 +85,9 @@ namespace MCGalaxy.Blocks.Physics {
internal static PhysicsArgs GetDoorArgs(BlockID block, out byte physForm) {
PhysicsArgs args = default(PhysicsArgs);
args.Type1 = PhysicsArgs.Wait; args.Value1 = 16 - 1;
args.Type2 = PhysicsArgs.Revert; args.Value2 = block.RawID;
args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)block;
args.Door = true;
args.ExtBlock = block.BlockID == Block.custom_block;
args.ExtBlock = block >= Block.Extended;
physForm = Block.Door_Log_air; // air
if (block == Block.Door_Air || block == Block.Door_AirActivatable) {
@ -102,9 +103,9 @@ namespace MCGalaxy.Blocks.Physics {
internal static PhysicsArgs GetTDoorArgs(BlockID block) {
PhysicsArgs args = default(PhysicsArgs);
args.Type1 = PhysicsArgs.Wait; args.Value1 = 16;
args.Type2 = PhysicsArgs.Revert; args.Value2 = block.RawID;
args.Type2 = PhysicsArgs.Revert; args.Value2 = (BlockRaw)block;
args.Door = true;
args.ExtBlock = block.BlockID == Block.custom_block;
args.ExtBlock = block >= Block.Extended;
return args;
}
@ -121,7 +122,7 @@ namespace MCGalaxy.Blocks.Physics {
internal static void CheckAt(Level lvl, int index) {
if (index == -1) return;
byte block = lvl.blocks[index];
byte convBlock = Block.Convert(block);
BlockID convBlock = Block.Convert(block);
if (convBlock == Block.Water || convBlock == Block.Lava ||
(block >= Block.Red && block <= Block.White)) {
lvl.AddCheck(index); return;

View File

@ -16,6 +16,7 @@
permissions and limitations under the Licenses.
*/
using System;
using BlockID = System.UInt16;
namespace MCGalaxy.Blocks.Physics {
@ -71,7 +72,7 @@ namespace MCGalaxy.Blocks.Physics {
static void FloodAir(Level lvl, int index, byte block) {
if (index == -1) return;
byte curBlock = Block.Convert(lvl.blocks[index]);
BlockID curBlock = Block.Convert(lvl.blocks[index]);
if (curBlock == Block.Water || curBlock == Block.Lava)
lvl.AddUpdate(index, block);
}

View File

@ -67,7 +67,7 @@ namespace MCGalaxy.Blocks.Physics {
for (int zz = z - (size + 1); zz <= z + (size + 1); ++zz)
for (int xx = x - (size + 1); xx <= x + (size + 1); ++xx)
{
if (lvl.IsAirAt((ushort)xx, (ushort)yy, (ushort)zz, out index) && rand.Next(1, 40) < 2) {
if (lvl.IsAirAt((ushort)xx, (ushort)yy, (ushort)zz, out index) && rand.Next(1, 40) < 2) {
PhysicsArgs args = default(PhysicsArgs);
args.Type1 = PhysicsArgs.Drop; args.Value1 = 100;
args.Type2 = PhysicsArgs.Dissipate; args.Value2 = 25;

View File

@ -69,13 +69,15 @@ namespace MCGalaxy.Blocks.Physics {
}
public static void DoFloatwood(Level lvl, ref Check C) {
int index = lvl.IntOffset(C.b, 0, -1, 0);
if (lvl.GetTile(index) == Block.Air) {
ushort x, y, z;
lvl.IntToPos(C.b, out x, out y, out z);
int index;
if (lvl.GetBlock(x, (ushort)(y - 1), z, out index) == Block.Air) {
lvl.AddUpdate(C.b, Block.Air);
lvl.AddUpdate(index, Block.FloatWood);
} else {
index = lvl.IntOffset(C.b, 0, 1, 0);
byte above = lvl.GetTile(index);
BlockID above = lvl.GetBlock(x, (ushort)(y + 1), z, out index);
if (above == Block.StillWater || Block.Convert(above) == Block.Water) {
lvl.AddUpdate(C.b, lvl.blocks[index]);
lvl.AddUpdate(index, Block.FloatWood);

View File

@ -135,7 +135,7 @@ namespace MCGalaxy.Commands.CPE {
if (!CheckBlock(p, parts[1], out block)) return;
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
BlockDefinition def = defs[block.RawID];
BlockDefinition def = defs[(BlockRaw)block];
if (!ExistsInScope(def, block, global)) { MessageNoBlock(p, block, global, cmd); return; }
Player.Message(p, "About {0} ({1})", def.Name, def.BlockID);
@ -193,7 +193,7 @@ namespace MCGalaxy.Commands.CPE {
if (!CheckBlock(p, parts[1], out block)) return;
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
BlockDefinition def = defs[block.RawID];
BlockDefinition def = defs[(BlockRaw)block];
if (!ExistsInScope(def, block, global)) { MessageNoBlock(p, block, global, cmd); return; }
RemoveBlockProps(global, block, p);
@ -202,7 +202,7 @@ namespace MCGalaxy.Commands.CPE {
string scope = global ? "global" : "level";
Player.Message(p, "Removed " + scope + " custom block " + def.Name + "(" + def.BlockID + ")");
BlockDefinition globalDef = BlockDefinition.GlobalDefs[block.RawID];
BlockDefinition globalDef = BlockDefinition.GlobalDefs[(BlockRaw)block];
if (!global && globalDef != null)
BlockDefinition.Add(globalDef, defs, p.level);
}
@ -313,8 +313,10 @@ namespace MCGalaxy.Commands.CPE {
BlockID block;
if (!CheckBlock(p, parts[1], out block)) return;
BlockRaw raw = (BlockRaw)block;
BlockDefinition[] defs = global ? BlockDefinition.GlobalDefs : p.level.CustomBlockDefs;
BlockDefinition def = defs[block.RawID], globalDef = BlockDefinition.GlobalDefs[block.RawID];
BlockDefinition def = defs[raw], globalDef = BlockDefinition.GlobalDefs[raw];
if (def == null && block < Block.CpeCount) {
def = DefaultSet.MakeCustomBlock(block);
@ -418,7 +420,7 @@ namespace MCGalaxy.Commands.CPE {
if (fallback == Block.Invalid) return;
changedFallback = true;
value = Block.Name(fallback);
value = Block.GetName(p, fallback);
def.FallBack = fallback; break;
case "order":
@ -462,7 +464,7 @@ namespace MCGalaxy.Commands.CPE {
}
return false;
}
def.BlockID = block.RawID;
def.BlockID = (BlockRaw)block;
}
string scope = global ? "global" : "level";
@ -474,7 +476,7 @@ namespace MCGalaxy.Commands.CPE {
return true;
}
static byte GetFallback(Player p, string value) {
static BlockRaw GetFallback(Player p, string value) {
BlockID block;
if (!CommandParser.GetBlock(p, value, out block)) return Block.Invalid;
@ -486,7 +488,7 @@ namespace MCGalaxy.Commands.CPE {
Player.Message(p, "&cPhysics block cannot be used as fallback blocks.");
return Block.Invalid;
}
return block.BlockID;
return (BlockRaw)block;
}
@ -508,13 +510,13 @@ namespace MCGalaxy.Commands.CPE {
static void MessageNoBlock(Player p, BlockID block, bool global, string cmd) {
string scope = global ? "global" : "level";
Player.Message(p, "&cThere is no {1} custom block with the id \"{0}\".", block.RawID, scope);
Player.Message(p, "&cThere is no {1} custom block with the id \"{0}\".", (BlockRaw)block, scope);
Player.Message(p, "Type \"%T{0} list\" %Sto see a list of {1} custom blocks.", cmd, scope);
}
static void MessageAlreadyBlock(Player p, BlockID block, bool global, string cmd) {
string scope = global ? "global" : "level";
Player.Message(p, "&cThere is already a {1} custom block with the id \"{0}\".", block.RawID, scope);
Player.Message(p, "&cThere is already a {1} custom block with the id \"{0}\".", (BlockRaw)block, scope);
Player.Message(p, "Type \"%T{0} list\" %Sto see a list of {1} custom blocks.", cmd, scope);
}
@ -558,7 +560,7 @@ namespace MCGalaxy.Commands.CPE {
return;
}
BlockRaw raw = (BlockRaw)block;
BlockRaw raw = (BlockRaw)block;
BlockDefinition.GlobalProps[raw] = props;
Level[] loaded = LevelInfo.Loaded.Items;
@ -616,7 +618,7 @@ namespace MCGalaxy.Commands.CPE {
}
static bool ExistsInScope(BlockDefinition def, BlockID block, bool global) {
return def != null && (global ? true : def != BlockDefinition.GlobalDefs[block.RawID]);
return def != null && (global ? true : def != BlockDefinition.GlobalDefs[(BlockRaw)block]);
}

View File

@ -106,8 +106,8 @@ namespace MCGalaxy.Commands {
}
if (value < min || value > max) {
Player.Message(p, "{0} must be between {1} and {2}", argName,
min.ToString("F4"), max.ToString("F4"));
Player.Message(p, "{0} must be between {1} and {2}", argName,
min.ToString("F4"), max.ToString("F4"));
return false;
}
result = value; return true;

View File

@ -21,6 +21,7 @@ using System.IO;
using MCGalaxy.Games;
using MCGalaxy.Maths;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Commands.Fun {
public sealed class CmdCTF : Command {
@ -148,7 +149,7 @@ namespace MCGalaxy.Commands.Fun {
block = p.level.GetBlock((ushort)P.X, (ushort)P.Y, (ushort)P.Z);
if (block == Block.Air) block = Block.Blue;
cfg.BlueFlagBlock = block.RawID;
cfg.BlueFlagBlock = (BlockRaw)block;
Player.Message(p, "Set flag block of blue team to {0}", Block.GetName(p, block));
UpdateConfig(p, cfg);
@ -163,7 +164,7 @@ namespace MCGalaxy.Commands.Fun {
block = p.level.GetBlock((ushort)P.X, (ushort)P.Y, (ushort)P.Z);
if (block == Block.Air) block = Block.Red;
cfg.RedFlagBlock = block.RawID;
cfg.RedFlagBlock = (BlockRaw)block;
Player.Message(p, "Set flag block of red team to {0}", Block.GetName(p, block));
UpdateConfig(p, cfg);

View File

@ -174,7 +174,7 @@ namespace MCGalaxy.Commands.Fun {
return;
}
string opt = args[2], value = args.Length > 3 ? args[3] : "";
string opt = args[2], value = args.Length > 3 ? args[3] : "";
TimeSpan span = default(TimeSpan);
if (opt.CaselessEq("sendafkmain")) {
Server.lava.sendAfkMain = !Server.lava.sendAfkMain;

View File

@ -200,9 +200,9 @@ namespace MCGalaxy.Commands.Fun {
}
void HandleList(Player p, string[] args) {
string modifier = args.Length > 1 ? args[1] : "";
string modifier = args.Length > 1 ? args[1] : "";
MultiPageOutput.Output(p, Team.Teams, team => team.Color + team.Name,
"team list", "teams", modifier, false);
"team list", "teams", modifier, false);
}
public override void Help(Player p) {

View File

@ -191,7 +191,7 @@ namespace MCGalaxy.Commands.Fun {
if (ending == WeaponType.Destroy) {
bool fireKills = block != Block.Air && p.level.Props[block].LavaKills;
if ((!fireKills && !Block.NeedRestart(block.BlockID)) && block != Block.Glass) {
if ((!fireKills && !Block.NeedRestart(block)) && block != Block.Glass) {
return true;
}
} else if (p.level.physics >= 3) {

View File

@ -22,6 +22,7 @@ using MCGalaxy.DB;
using MCGalaxy.Maths;
using MCGalaxy.SQL;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Commands.Info {
public sealed class CmdAbout : Command {
@ -65,7 +66,7 @@ namespace MCGalaxy.Commands.Info {
string blockName = Block.GetName(p, block);
Player.Message(p, "Block ({0}, {1}, {2}): &f{3} = {4}%S.",
x, y, z, block.RawID, blockName);
x, y, z, (BlockRaw)block, blockName);
if (HasExtraPerm(p, 1)) {
BlockDBChange.OutputMessageBlock(p, block, x, y, z);

View File

@ -59,7 +59,7 @@ namespace MCGalaxy.Commands.Info {
if (!Player.IsSuper(p)) {
for (int id = Block.CpeCount; id < Block.Count; id++) {
if (p.level.CustomBlockDefs[id] == null) continue;
blocks.Add(new ushort(Block.custom_block, (byte)id));
blocks.Add((BlockID)(Block.Extended | id));
}
}

View File

@ -42,13 +42,13 @@ namespace MCGalaxy.Commands.Maintenance {
if (cmd == "bs") {
if (!CommandParser.GetInt(p, args[1], "Blocks per interval", ref value, 0)) return;
BlockQueue.blockupdates = value;
Player.Message(p, "Blocks per interval is now {0}.", BlockQueue.blockupdates);
BlockQueue.UpdatesPerTick = value;
Player.Message(p, "Blocks per interval is now {0}.", BlockQueue.UpdatesPerTick);
} else if (cmd == "ts") {
if (!CommandParser.GetInt(p, args[1], "Block interval", ref value, 50)) return;
BlockQueue.time = value;
Player.Message(p, "Block interval is now {0}.", BlockQueue.time);
BlockQueue.Interval = value;
Player.Message(p, "Block interval is now {0}.", BlockQueue.Interval);
} else if (cmd == "net") {
if (!CommandParser.GetInt(p, args[1], "value", ref value, 2, 1000)) return;
@ -68,12 +68,12 @@ namespace MCGalaxy.Commands.Maintenance {
}
static void Set(int updates, int time) {
BlockQueue.blockupdates = updates;
BlockQueue.time = time;
BlockQueue.UpdatesPerTick = updates;
BlockQueue.Interval = time;
}
static void SendEstimation(Player p) {
int updates = BlockQueue.blockupdates, time = BlockQueue.time, count = PlayerInfo.Online.Count;
int updates = BlockQueue.UpdatesPerTick, time = BlockQueue.Interval, count = PlayerInfo.Online.Count;
Player.Message(p, "{0} blocks every {1} milliseconds = {2} blocks per second.", updates, time, updates * (1000 / time));
Player.Message(p, "Using ~{0}KB/s times {1} player(s) = ~{2}KB/s", (updates * (1000 / time) * 8) / 1000, count, count * ((updates * (1000 / time) * 8) / 1000));
}

View File

@ -90,7 +90,7 @@ namespace MCGalaxy.Commands.Maintenance {
v => who.TimesBeenKicked = v, UpdateDB);
} else if (opt == "messages") {
SetInteger(p, args, PlayerData.ColumnMessages, 16777215, who,
v => who.TotalMessagesSent = v, UpdateDB);
v => who.TotalMessagesSent = v, UpdateDB);
} else if (opt == "timespent") {
SetTimespan(p, args, PlayerData.ColumnTimeSpent, who, v => who.TotalTime = v);
} else if (opt == "color") {

View File

@ -53,9 +53,9 @@ namespace MCGalaxy.Commands.Moderation {
}
if (p.hidden) {
if (announceToOps && !p.otherRankHidden) {
if (announceToOps && !p.otherRankHidden) {
Chat.MessageOps("To Ops -" + p.ColoredName + "%S- is now &finvisible%S.");
}
}
string discMsg = PlayerDB.GetLogoutMessage(p);
Chat.MessageGlobal(p, "&c- " + p.FullName + " %S" + discMsg, false);

View File

@ -59,7 +59,7 @@ namespace MCGalaxy.Commands.Moderation {
if (!CheckExtraPerm(p, 1)) return;
string[] users = Directory.GetFiles("extra/reported", "*.txt");
for (int i = 0; i < users.Length; i++) {
users[i] = Path.GetFileNameWithoutExtension(users[i]);
users[i] = Path.GetFileNameWithoutExtension(users[i]);
}
if (users.Length > 0) {
@ -141,13 +141,13 @@ namespace MCGalaxy.Commands.Moderation {
List<string> reports = new List<string>();
if (File.Exists("extra/reported/" + target + ".txt")) {
reports = new List<string>(File.ReadAllLines("extra/reported/" + target + ".txt"));
reports = new List<string>(File.ReadAllLines("extra/reported/" + target + ".txt"));
}
if (reports.Count >= 5) {
LevelPermission checkRank = CommandExtraPerms.Find(name, 1).MinRank;
Player.Message(p, "{0} &calready has 5 pending reports! Please wait until an {1}%c+ has reviewed these reports first!",
PlayerInfo.GetColoredName(p, target), Group.GetColoredName(checkRank));
PlayerInfo.GetColoredName(p, target), Group.GetColoredName(checkRank));
return;
}

View File

@ -138,10 +138,10 @@ namespace MCGalaxy.Commands.Moderation {
}
void OnChangedZone(Zone zone) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.ZoneIn == zone) pl.OnChangedZone();
}
Player[] players = PlayerInfo.Online.Items;
foreach (Player pl in players) {
if (pl.ZoneIn == zone) pl.OnChangedZone();
}
}
public override void Help(Player p) {

View File

@ -18,6 +18,7 @@
using System;
using MCGalaxy.Blocks;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Commands.World {
public sealed class CmdBlockProperties : Command {
@ -92,7 +93,7 @@ namespace MCGalaxy.Commands.World {
}
static int GetIndex(BlockProps[] scope, BlockID block) {
return scope == BlockDefinition.GlobalProps ? block.RawID : block;
return scope == BlockDefinition.GlobalProps ? (BlockRaw)block : block;
}
@ -139,18 +140,15 @@ namespace MCGalaxy.Commands.World {
}
static void Toggle(Player p, BlockProps[] scope, BlockID block,
string type, ref bool on) {
static void Toggle(Player p, BlockProps[] scope, BlockID block, string type, ref bool on) {
on = !on;
Level lvl = Player.IsSuper(p) ? null : p.level;
Player.Message(p, "Block {0} is {1}: {2}",
BlockName(scope, lvl, block),
type, on ? "&aYes" : "&cNo");
Player.Message(p, "Block {0} is {1}: {2}",
BlockName(scope, lvl, block), type, on ? "&aYes" : "&cNo");
OnPropsChanged(scope, lvl, block);
}
static void SetEnum(Player p, BlockProps[] scope, BlockID block,
int i, string msg) {
static void SetEnum(Player p, BlockProps[] scope, BlockID block, int i, string msg) {
Level lvl = Player.IsSuper(p) ? null : p.level;
AnimalAI ai = AnimalAI.None;
if (!CommandParser.GetEnum(p, msg, "Animal AI", ref ai)) return;
@ -161,8 +159,7 @@ namespace MCGalaxy.Commands.World {
OnPropsChanged(scope, lvl, block);
}
static void SetDeathMessage(Player p, BlockProps[] scope, BlockID block,
int i, string msg) {
static void SetDeathMessage(Player p, BlockProps[] scope, BlockID block, int i, string msg) {
scope[i].DeathMessage = msg;
Level lvl = Player.IsSuper(p) ? null : p.level;
@ -176,8 +173,7 @@ namespace MCGalaxy.Commands.World {
OnPropsChanged(scope, lvl, block);
}
static void SetStackId(Player p, BlockProps[] scope, BlockID block,
int i, string msg) {
static void SetStackId(Player p, BlockProps[] scope, BlockID block, int i, string msg) {
Level lvl = Player.IsSuper(p) ? null : p.level;
BlockID stackBlock;
@ -191,10 +187,8 @@ namespace MCGalaxy.Commands.World {
if (stackBlock == Block.Air) {
Player.Message(p, "Removed stack block for {0}", BlockName(scope, lvl, block));
} else {
string stackBlockName = Player.IsSuper(p) ?
BlockName(scope, lvl, stackBlock) : p.level.BlockName(stackBlock);
Player.Message(p, "Stack block for {0} set to: {1}",
BlockName(scope, lvl, block), stackBlockName);
BlockName(scope, lvl, block), Block.GetName(p, stackBlock));
}
OnPropsChanged(scope, lvl, block);
}
@ -218,12 +212,14 @@ namespace MCGalaxy.Commands.World {
}
static void OnPropsChanged(BlockProps[] scope, Level level, BlockID block) {
scope[GetIndex(scope, block)].Changed = true;
scope[GetIndex(scope, block)].Changed = true;
BlockRaw raw = (BlockRaw)block;
if (scope == Block.Props) {
BlockProps.Save("core", scope, Block.CorePropsLock, null);
Level[] loaded = LevelInfo.Loaded.Items;
if (!block.IsPhysicsType) {
BlockDefinition.GlobalProps[block.RawID] = BlockDefinition.DefaultProps(block);
if (!Block.IsPhysicsType(block)) {
BlockDefinition.GlobalProps[raw] = BlockDefinition.DefaultProps(block);
}
foreach (Level lvl in loaded) {
@ -236,7 +232,6 @@ namespace MCGalaxy.Commands.World {
Level[] loaded = LevelInfo.Loaded.Items;
BlockProps.Save("global", scope, BlockDefinition.GlobalPropsLock, null);
byte raw = block.RawID;
foreach (Level lvl in loaded) {
if (lvl.CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw]) continue;
if (lvl.HasCustomProps(block)) continue;
@ -250,20 +245,19 @@ namespace MCGalaxy.Commands.World {
}
}
static bool SelectLevel(Level lvl, int i) {
return lvl.HasCustomProps((ushort)i);
}
static bool SelectLevel(Level lvl, int i) { return lvl.HasCustomProps((BlockID)i); }
static string BlockName(BlockProps[] scope, Level lvl, BlockID block) {
if (scope == Block.Props) return Block.Name(block.RawID);
BlockRaw raw = (BlockRaw)block;
if (scope == Block.Props) return Block.Name(raw);
BlockDefinition def = null;
if (scope == BlockDefinition.GlobalProps) {
def = BlockDefinition.GlobalDefs[block.RawID];
def = BlockDefinition.GlobalDefs[raw];
} else {
def = lvl.CustomBlockDefs[block.RawID];
def = lvl.CustomBlockDefs[raw];
}
return def == null ? block.RawID.ToString() : def.Name.Replace(" ", "");
return def == null ? raw.ToString() : def.Name.Replace(" ", "");
}

View File

@ -45,10 +45,10 @@ namespace MCGalaxy.Commands.World {
}
void Import(Player p, string path, string name, IMapImporter importer) {
if (LevelInfo.MapExists(name)) {
Player.Message(p, "&cMap {0} already exists. Try renaming the file to something else before importing.", name);
return;
}
if (LevelInfo.MapExists(name)) {
Player.Message(p, "&cMap {0} already exists. Try renaming the file to something else before importing.", name);
return;
}
try {
Level lvl = importer.Read(path + importer.Extension, name, true);
try {

View File

@ -74,11 +74,11 @@ namespace MCGalaxy.Commands.World {
static void OutputBackups(Player p) {
string backupPath = LevelInfo.BackupBasePath(p.level.name);
if (!Directory.Exists(backupPath)) {
if (!Directory.Exists(backupPath)) {
Player.Message(p, p.level.ColoredName + " %Shas no backups yet."); return;
}
string[] dirs = Directory.GetDirectories(backupPath);
string[] dirs = Directory.GetDirectories(backupPath);
Player.Message(p, p.level.ColoredName + " %Shas &b" + dirs.Length + " %Sbackups.");
int count = 0;
StringBuilder custom = new StringBuilder();

View File

@ -80,8 +80,8 @@ namespace MCGalaxy.Commands.Building {
Player.Message(p, "Palette {0} does not exist.", args[1]); return;
}
byte block = GetBlock(p, args[2]);
if (block == Block.Invalid) return;
BlockID block;
if (!CommandParser.GetBlock(p, args[2], out block)) return;
ColorDesc rgb = default(ColorDesc);
if (!CommandParser.GetHex(p, args[3], ref rgb)) return;
@ -108,13 +108,13 @@ namespace MCGalaxy.Commands.Building {
Player.Message(p, "Palette {0} does not exist.", args[1]); return;
}
byte block = GetBlock(p, args[2]);
if (block == Block.Invalid) return;
BlockID block;
if (!CommandParser.GetBlock(p, args[2], out block)) return;
RemoveEntry(p, palette, block);
}
static void RemoveEntry(Player p, ImagePalette palette, byte block) {
static void RemoveEntry(Player p, ImagePalette palette, BlockID block) {
PaletteEntry[] entries = palette.Entries;
if (entries == null) {
Player.Message(p, "Block not found in entries of palette {0}", palette.Name);
@ -122,7 +122,7 @@ namespace MCGalaxy.Commands.Building {
List<PaletteEntry> newEntries = new List<PaletteEntry>();
foreach (PaletteEntry entry in entries) {
if (entry.Raw == block) continue;
if (entry.Block == block) continue;
newEntries.Add(entry);
}
@ -134,17 +134,6 @@ namespace MCGalaxy.Commands.Building {
palette.Save();
Player.Message(p, "Removed block from entries of palette {0}", palette.Name);
}
static byte GetBlock(Player p, string name) {
BlockID block;
if (!CommandParser.GetBlock(p, name, out block)) return Block.Invalid;
if (Block.IsPhysicsType(block)) {
Player.Message(p, "Physics blocks may not be used for palettes."); return Block.Invalid;
}
return block.RawID;
}
void HandleEntries(Player p, string[] args) {
if (args.Length < 2 || args.Length > 3) { Help(p); return; }
@ -160,8 +149,7 @@ namespace MCGalaxy.Commands.Building {
}
static string FormatEntry(PaletteEntry e, Player p) {
BlockID block = Block.FromRaw(e.Raw);
return Block.GetName(p, block) + " - " + Utils.Hex(e.R, e.G, e.B);
return Block.GetName(p, e.Block) + " - " + Utils.Hex(e.R, e.G, e.B);
}
public override void Help(Player p) {

View File

@ -35,8 +35,8 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) {
if (p.CurrentCopySlot >= p.CopySlots.Count || p.CopySlots[p.CurrentCopySlot] == null) {
Player.Message(p, "You haven't copied anything yet"); return;
}
Player.Message(p, "You haven't copied anything yet"); return;
}
BrushArgs args = new BrushArgs(p, message, Block.Air);
Brush brush = BrushFactory.Find("paste").Construct(args);
@ -47,7 +47,7 @@ namespace MCGalaxy.Commands.Building {
}
bool DoPaste(Player p, Vec3S32[] m, object state, ushort block) {
CopyState cState = p.CopySlots[p.CurrentCopySlot];
CopyState cState = p.CopySlots[p.CurrentCopySlot];
m[0] += cState.Offset;
PasteDrawOp op = new PasteDrawOp();

View File

@ -20,6 +20,7 @@ using System.Collections.Generic;
using MCGalaxy.Blocks.Physics;
using MCGalaxy.Maths;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Commands.Building {
public sealed class CmdRestartPhysics : Command {
@ -66,11 +67,11 @@ namespace MCGalaxy.Commands.Building {
bool Parse(Player p, string name, string arg, ref byte type, ref byte value, ref bool isExt) {
if (name == "revert") {
ushort block;
BlockID block;
if (!CommandParser.GetBlock(p, arg, out block)) return false;
type = PhysicsArgs.Revert; value = block.RawID;
isExt = block.BlockID == Block.custom_block;
type = PhysicsArgs.Revert; value = (BlockRaw)block;
isExt = block >= Block.Extended;
return true;
}

View File

@ -32,8 +32,8 @@ namespace MCGalaxy.Commands.Building {
public override void Use(Player p, string message) {
if (message.Length == 0) message = "y";
if (p.CurrentCopySlot >= p.CopySlots.Count || p.CopySlots[p.CurrentCopySlot] == null) {
Player.Message(p, "You haven't copied anything yet"); return;
}
Player.Message(p, "You haven't copied anything yet"); return;
}
CopyState cState = p.CopySlots[p.CurrentCopySlot];
string opt = message.ToLower();

View File

@ -166,7 +166,7 @@ namespace MCGalaxy.Core {
p.Kick(null, ServerConfig.DefaultBanMessage, true);
return false;
}
if (group.Permission == LevelPermission.Banned) {
string banner, reason, prevRank;
DateTime time;

View File

@ -21,7 +21,7 @@ using System.IO;
namespace MCGalaxy.DB {
/// <summary> Stores per-player persistent data. </summary>
/// <summary> Stores per-player persistent data. </summary>
public static class PlayerDB {
public static string LoginPath(string name) {

View File

@ -24,6 +24,7 @@ using MCGalaxy.Drawing.Ops;
using MCGalaxy.Network;
using MCGalaxy.Undo;
using MCGalaxy.Maths;
using BlockRaw = System.Byte;
namespace MCGalaxy.Drawing {
internal struct PendingDrawOp {
@ -174,14 +175,13 @@ namespace MCGalaxy.Drawing.Ops {
if (old == b.Block || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block)) return;
// Set the block (inlined)
lvl.blocks[index] = b.Block.BlockID;
lvl.blocks[index] = b.Block >= Block.Extended ? Block.custom_block : (BlockRaw)b.Block;
lvl.Changed = true;
if (old.BlockID == Block.custom_block && b.Block.BlockID != Block.custom_block) {
if (b.Block >= Block.Extended) {
lvl.SetExtTileNoCheck(b.X, b.Y, b.Z, (BlockRaw)b.Block);
} else if (old >= Block.Extended) {
lvl.RevertExtTileNoCheck(b.X, b.Y, b.Z);
}
if (b.Block.BlockID == Block.custom_block) {
lvl.SetExtTileNoCheck(b.X, b.Y, b.Z, b.Block.ExtID);
}
if (p != null) {
lvl.BlockDB.Cache.Add(p, b.X, b.Y, b.Z, op.Flags, old, b.Block);
@ -197,7 +197,7 @@ namespace MCGalaxy.Drawing.Ops {
lock (lvl.queueLock)
lvl.blockqueue.Clear();
} else if (op.TotalModified < reloadThreshold) {
if (!old.VisuallyEquals(b.Block)) BlockQueue.Addblock(p, index, b.Block);
if (!Block.VisuallyEquals(old, b.Block)) BlockQueue.Add(p, index, b.Block);
if (lvl.physics > 0) {
if (old == Block.Sponge && b.Block != Block.Sponge)

View File

@ -17,13 +17,14 @@
*/
using System;
using System.Drawing;
using BlockID = System.UInt16;
namespace MCGalaxy.Drawing {
public interface IPaletteMatcher {
void SetPalette(PaletteEntry[] front, PaletteEntry[] back);
byte BestMatch(byte R, byte G, byte B);
byte BestMatch(byte R, byte G, byte B, out bool backLayer);
BlockID BestMatch(byte R, byte G, byte B);
BlockID BestMatch(byte R, byte G, byte B, out bool backLayer);
}
public sealed class RgbPaletteMatcher : IPaletteMatcher {
@ -33,19 +34,19 @@ namespace MCGalaxy.Drawing {
this.front = front; this.back = back;
}
public byte BestMatch(byte R, byte G, byte B) {
public BlockID BestMatch(byte R, byte G, byte B) {
int pos;
MinDist(R, G, B, front, out pos);
return front[pos].Raw;
return front[pos].Block;
}
public byte BestMatch(byte R, byte G, byte B, out bool backLayer) {
public BlockID BestMatch(byte R, byte G, byte B, out bool backLayer) {
int frontPos, backPos;
int frontDist = MinDist(R, G, B, front, out frontPos);
int backDist = MinDist(R, G, B, back, out backPos);
backLayer = backDist < frontDist;
return backLayer ? back[backPos].Raw : front[frontPos].Raw;
return backLayer ? back[backPos].Block : front[frontPos].Block;
}
@ -73,7 +74,7 @@ namespace MCGalaxy.Drawing {
this.palette[i] = RgbToLab(front[i]);
}
public byte BestMatch(byte R, byte G, byte B) {
public BlockID BestMatch(byte R, byte G, byte B) {
double minDist = int.MaxValue; int pos = 0;
LabColor col = RgbToLab(R, G, B);
@ -89,7 +90,7 @@ namespace MCGalaxy.Drawing {
return palette[pos].Block;
}
public byte BestMatch(byte R, byte G, byte B, out bool backLayer) {
public BlockID BestMatch(byte R, byte G, byte B, out bool backLayer) {
backLayer = false;
return BestMatch(R, G, B);
}
@ -97,12 +98,12 @@ namespace MCGalaxy.Drawing {
struct LabColor {
public double L, A, B;
public byte Block;
public BlockID Block;
}
LabColor RgbToLab(PaletteEntry cur) {
LabColor lab = RgbToLab(cur.R, cur.G, cur.B);
lab.Block = cur.Raw;
lab.Block = cur.Block;
return lab;
}

View File

@ -17,6 +17,7 @@
*/
using System.Collections.Generic;
using System.IO;
using BlockID = System.UInt16;
namespace MCGalaxy.Drawing {
@ -76,8 +77,12 @@ namespace MCGalaxy.Drawing {
}
static PaletteEntry ParseEntry(string[] parts) {
byte r = byte.Parse(parts[1]), g = byte.Parse(parts[2]);
byte b = byte.Parse(parts[3]), block = byte.Parse(parts[0]);
BlockID block = BlockID.Parse(parts[0]);
block = Block.MapOldRaw(block);
byte r = byte.Parse(parts[1]);
byte g = byte.Parse(parts[2]);
byte b = byte.Parse(parts[3]);
return new PaletteEntry(r, g, b, block);
}
@ -88,7 +93,7 @@ namespace MCGalaxy.Drawing {
if (Entries == null) return;
foreach (PaletteEntry e in Entries)
w.WriteLine(e.Raw + ":" + e.R + ":" + e.G + ":" + e.B);
w.WriteLine(e.Block + ":" + e.R + ":" + e.G + ":" + e.B);
}
}
@ -150,10 +155,11 @@ namespace MCGalaxy.Drawing {
}
public struct PaletteEntry {
public byte R, G, B, Raw;
public byte R, G, B;
public BlockID Block;
public PaletteEntry(byte r, byte g, byte b, byte block) {
R = r; G = g; B = b; Raw = block;
public PaletteEntry(byte r, byte g, byte b, BlockID block) {
R = r; G = g; B = b; Block = block;
}
}
}

View File

@ -21,6 +21,7 @@ using System.IO;
using Draw = System.Drawing;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Maths;
using BlockID = System.UInt16;
namespace MCGalaxy.Drawing.Ops {
@ -85,8 +86,7 @@ namespace MCGalaxy.Drawing.Ops {
for (int i = 0; i < Palette.Entries.Length; i++) {
PaletteEntry entry = Palette.Entries[i];
ushort block = Block.FromRaw(entry.Raw);
BlockDefinition def = Level.GetBlockDef(block);
BlockDefinition def = Level.GetBlockDef(entry.Block);
if (def != null && def.FullBright) {
front[i] = Multiply(entry, Colors.ParseHex("FFFFFF"));
@ -117,18 +117,18 @@ namespace MCGalaxy.Drawing.Ops {
ushort z = (ushort)(Origin.Z + dx.Z * xx + dy.Z * yy);
if (P.A < 20) { output(Place(x, y, z, Block.Air)); continue; }
byte raw = 0;
BlockID block;
if (!DualLayer) {
raw = selector.BestMatch(P.R, P.G, P.B);
block = selector.BestMatch(P.R, P.G, P.B);
} else {
bool backLayer;
raw = selector.BestMatch(P.R, P.G, P.B, out backLayer);
block = selector.BestMatch(P.R, P.G, P.B, out backLayer);
if (backLayer) {
x = (ushort)(x + adj.X);
z = (ushort)(z + adj.Z);
}
}
output(Place(x, y, z, Block.FromRaw(raw)));
output(Place(x, y, z, block));
}
}

View File

@ -20,6 +20,7 @@ using System.Collections.Generic;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Drawing.Ops;
using MCGalaxy.Maths;
using BlockRaw = System.Byte;
namespace MCGalaxy.Generator.Foliage {
public sealed class AshTree : Tree {
@ -68,7 +69,7 @@ namespace MCGalaxy.Generator.Foliage {
DrawOp op = new EllipsoidDrawOp();
Brush brush = new RandomBrush(new ushort[] { Block.Leaves });
op.SetMarks(marks);
op.Perform(marks, brush, b => output(b.X, b.Y, b.Z, b.Block.BlockID));
op.Perform(marks, brush, b => output(b.X, b.Y, b.Z, (BlockRaw)b.Block));
Vec3S32 p1 = new Vec3S32(x, y + branchStart, z);
Vec3S32 p2 = new Vec3S32(x + dx, y + branchMax, z + dz);

View File

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using MCGalaxy.Drawing.Brushes;
using BlockID = System.UInt16;
namespace MCGalaxy.Generator.Foliage {
@ -55,8 +56,8 @@ namespace MCGalaxy.Generator.Foliage {
for (int dz = -size; dz <= size; ++dz)
for (int dx = -size; dx <= size; ++dx)
{
byte tile = lvl.GetTile((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz));
if (tile == Block.Log || tile == Block.Green) return true;
BlockID block = lvl.GetBlock((ushort)(x + dx), (ushort)(y + dy), (ushort)(z + dz));
if (block == Block.Log || block == Block.Green) return true;
}
return false;
}

View File

@ -134,7 +134,7 @@ namespace MCGalaxy.Generator {
if (genParams.GenTrees && overlay[index] < 0.65f && overlay2[index] < treeDens) {
if (Lvl.IsAirAt(x, (ushort)(y + 1), z)) {
if (Lvl.GetTile(x, y, z) == Block.Grass || genParams.UseCactus) {
if (Lvl.GetBlock(x, y, z) == Block.Grass || genParams.UseCactus) {
if (rand.Next(13) == 0 && !Tree.TreeCheck(Lvl, x, y, z, treeDist)) {
Tree tree = null;
if (genParams.UseCactus) tree = new CactusTree();

View File

@ -1,6 +1,7 @@
// Part of fCraft | Copyright 2009-2015 Matvei Stefarov <me@matvei.org> | BSD-3 | See LICENSE.txt
using System;
using MCGalaxy.Commands;
using BlockID = System.UInt16;
namespace MCGalaxy.Generator {
@ -286,7 +287,7 @@ namespace MCGalaxy.Generator {
for( int z = 0; z < map.Length; z++ )
for( int y = args.WaterLevel; y <= args.WaterLevel + args.BeachHeight; y++ )
{
if( map.GetTile( (ushort)x, (ushort)y, (ushort)z ) != bGroundSurface ) continue;
if( map.GetBlock( (ushort)x, (ushort)y, (ushort)z ) != bGroundSurface ) continue;
bool found = false;
for( int dx = -args.BeachExtent; !found && dx <= args.BeachExtent; dx++ )
for( int dz = -args.BeachExtent; !found && dz <= args.BeachExtent; dz++ )
@ -296,7 +297,7 @@ namespace MCGalaxy.Generator {
int xx = x + dx, yy = y + dy, zz = z + dz;
if( xx < 0 || xx >= map.Width || yy < 0 || yy >= map.Height || zz < 0 || zz >= map.Length ) continue;
byte block = map.GetTile( (ushort)xx, (ushort)yy, (ushort)zz );
BlockID block = map.GetBlock( (ushort)xx, (ushort)yy, (ushort)zz );
if( block == bWater || block == bWaterSurface ) {
found = true;
break;
@ -305,7 +306,7 @@ namespace MCGalaxy.Generator {
if( found ) {
map.SetTile( (ushort)x, (ushort)y, (ushort)z, bSeaFloor );
if( y > 0 && map.GetTile( (ushort)x, (ushort)(y - 1), (ushort)z ) == bGround ) {
if( y > 0 && map.GetBlock( (ushort)x, (ushort)(y - 1), (ushort)z ) == bGround ) {
map.SetTile( (ushort)x, (ushort)(y - 1), (ushort)z, bSeaFloor );
}
}
@ -332,7 +333,7 @@ namespace MCGalaxy.Generator {
if( nx < 0 || nx >= map.Width || nz < 0 || nz >= map.Length ) continue;
int ny = shadows[nx, nz];
if( (map.GetTile( (ushort)nx, (ushort)ny, (ushort)nz ) == bGroundSurface) && slopemap[nx, nz] < .5 ) {
if( (map.GetBlock( (ushort)nx, (ushort)ny, (ushort)nz ) == bGroundSurface) && slopemap[nx, nz] < .5 ) {
// Pick a random height for the tree between Min and Max,
// discarding this tree if it would breach the top of the map
int nh;
@ -354,8 +355,9 @@ namespace MCGalaxy.Generator {
if( rn.NextDouble() > odds && Math.Abs( dx ) == Math.Abs( dz ) && Math.Abs( dx ) == radius )
continue;
// By default only replace an existing block if its air
if( map.GetTile( (ushort)(nx + dx), (ushort)(ny + nh + i), (ushort)(nz + dz) ) == Block.Air )
if( map.GetBlock( (ushort)(nx + dx), (ushort)(ny + nh + i), (ushort)(nz + dz) ) == Block.Air ) {
map.SetTile( (ushort)(nx + dx), (ushort)(ny + nh + i), (ushort)(nz + dz), Block.Leaves );
}
}
}
}

View File

@ -24,9 +24,10 @@ namespace MCGalaxy {
public static class BlockQueue {
public static int time = 100;
public static int blockupdates = 750;
public static int Interval = 100;
public static int UpdatesPerTick = 750;
static BufferedBlockSender bulkSender = new BufferedBlockSender();
public const int BlockMask = 0x1FF;
public static void Loop(SchedulerTask task) {
Level[] loaded = LevelInfo.Loaded.Items;
@ -36,10 +37,10 @@ namespace MCGalaxy {
}
bulkSender.level = null;
task.Delay = TimeSpan.FromMilliseconds(time);
task.Delay = TimeSpan.FromMilliseconds(Interval);
}
public static void Addblock(Player p, int index, BlockID block) {
public static void Add(Player p, int index, BlockID block) {
if (index == -1) return;
// Bit packing format
// 32-63: index
@ -48,8 +49,7 @@ namespace MCGalaxy {
// 0-7: raw type
ulong flags = (ulong)index << 32;
flags |= (ulong)p.SessionID << 9;
flags |= (block.BlockID == Block.custom_block ? 0x100UL : 0x000UL);
flags |= (block.BlockID == Block.custom_block ? block.ExtID : block.BlockID);
flags |= (ulong)block & BlockMask;
lock (p.level.queueLock)
p.level.blockqueue.Add(flags);
@ -61,16 +61,15 @@ namespace MCGalaxy {
if (!lvl.HasPlayers()) { lvl.blockqueue.Clear(); return; }
bulkSender.level = lvl;
int count = blockupdates;
if (lvl.blockqueue.Count < blockupdates)
int count = UpdatesPerTick;
if (lvl.blockqueue.Count < UpdatesPerTick)
count = lvl.blockqueue.Count;
for (int i = 0; i < count; i++) {
ulong flags = lvl.blockqueue[i];
int index = (int)(flags >> 32);
byte block = (flags & 0x100) != 0 ? Block.custom_block : (byte)flags;
byte extBlock = (flags & 0x100) != 0 ? (byte)flags : Block.Air;
bulkSender.Add(index, block, extBlock);
BlockID block = (BlockID)(flags & BlockMask);
bulkSender.Add(index, block);
}
bulkSender.Send(true);
lvl.blockqueue.RemoveRange(0, count);

View File

@ -23,6 +23,7 @@ using MCGalaxy.DB;
using MCGalaxy.Games;
using MCGalaxy.Maths;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
@ -41,12 +42,6 @@ namespace MCGalaxy {
}
}
public byte GetTile(ushort x, ushort y, ushort z) {
int index = PosToInt(x, y, z);
if (index < 0 || blocks == null) return Block.Invalid;
return blocks[index];
}
/// <summary> Gets the block at the given coordinates. </summary>
/// <returns> Block.Invalid if coordinates outside map. </returns>
public BlockID GetBlock(ushort x, ushort y, ushort z) {
@ -80,7 +75,10 @@ namespace MCGalaxy {
public byte GetTile(int b) {
ushort x = 0, y = 0, z = 0;
IntToPos(b, out x, out y, out z);
return GetTile(x, y, z);
int index = PosToInt(x, y, z);
if (index < 0 || blocks == null) return Block.Invalid;
return blocks[index];
}
public byte GetExtTile(ushort x, ushort y, ushort z) {
@ -189,8 +187,14 @@ namespace MCGalaxy {
return access == AccessResult.Whitelisted || access == AccessResult.Allowed;
}
internal bool BuildIn(BlockID block) {
if (block == Block.Op_Water || block == Block.Op_Lava || Props[block].IsPortal || Props[block].IsMessageBlock) return false;
block = Block.Convert(block);
return block >= Block.Water && block <= Block.StillLava;
}
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z, BlockID old, BlockID block) {
if (!p.group.Blocks[old] && !Block.AllowBreak(old.BlockID) && !Block.BuildIn(old.BlockID)) return false;
if (!p.group.Blocks[old] && !Block.AllowBreak(old) && !BuildIn(old)) return false;
if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref block)) return false;
Zone[] zones = Zones.Items;
if (zones.Length == 0) return CheckRank(p);
@ -261,20 +265,22 @@ namespace MCGalaxy {
else p.TotalPlaced++;
errorLocation = "Setting tile";
SetTile(x, y, z, block.BlockID);
if (old.BlockID == Block.custom_block && block.BlockID != Block.custom_block)
BlockRaw raw = block >= Block.Extended ? Block.custom_block : (BlockRaw)block;
SetTile(x, y, z, raw);
if (block >= Block.Extended) {
SetExtTileNoCheck(x, y, z, (BlockRaw)block);
} else if (old >= Block.Extended) {
RevertExtTileNoCheck(x, y, z);
if (block.BlockID == Block.custom_block)
SetExtTileNoCheck(x, y, z, block.ExtID);
}
errorLocation = "Adding physics";
if (p.PlayingTntWars && block.BlockID == Block.TNT_Small) AddTntCheck(PosToInt(x, y, z), p);
if (p.PlayingTntWars && block == Block.TNT_Small) AddTntCheck(PosToInt(x, y, z), p);
if (physics > 0 && ActivatesPhysics(block)) AddCheck(PosToInt(x, y, z));
Changed = true;
backedup = false;
return old.VisuallyEquals(block) ? 1 : 2;
return Block.VisuallyEquals(old, block) ? 1 : 2;
} catch (Exception e) {
Logger.LogError(e);
Chat.MessageOps(p.name + " triggered a non-fatal error on " + ColoredName + ", %Sat location: " + errorLocation);
@ -311,9 +317,8 @@ namespace MCGalaxy {
internal bool DoPhysicsBlockchange(int b, BlockID block, bool overRide = false,
PhysicsArgs data = default(PhysicsArgs), bool addUndo = true) {
if (blocks == null || b < 0 || b >= blocks.Length) return false;
ushort old;
old.BlockID = blocks[b];
old.ExtID = old.BlockID == Block.custom_block ? GetExtTile(b) : Block.Air;
BlockID old = blocks[b];
old = old != Block.custom_block ? old : (BlockID)(Block.Extended | GetExtTile(b));
try
{
@ -321,10 +326,10 @@ namespace MCGalaxy {
if (Props[old].OPBlock || (Props[block].OPBlock && data.Raw != 0)) return false;
}
if (old == Block.Sponge && physics > 0 && block != Block.Sponge) {
if (old == Block.Sponge && physics > 0 && block != Block.Sponge) {
OtherPhysics.DoSpongeRemoved(this, b, false);
}
if (old == Block.LavaSponge && physics > 0 && block != Block.LavaSponge) {
if (old == Block.LavaSponge && physics > 0 && block != Block.LavaSponge) {
OtherPhysics.DoSpongeRemoved(this, b, true);
}
@ -343,24 +348,25 @@ namespace MCGalaxy {
currentUndo++;
}
blocks[b] = block.BlockID;
blocks[b] = block >= Block.Extended ? Block.custom_block : (BlockRaw)block;
Changed = true;
if (block.BlockID == Block.custom_block) {
if (block >= Block.Extended) {
ushort x, y, z;
IntToPos(b, out x, out y, out z);
SetExtTileNoCheck(x, y, z, block.ExtID);
} else if (old.BlockID == Block.custom_block) {
SetExtTileNoCheck(x, y, z, (BlockRaw)block);
} else if (old >= Block.Extended) {
ushort x, y, z;
IntToPos(b, out x, out y, out z);
RevertExtTileNoCheck(x, y, z);
}
if (physics > 0 && (ActivatesPhysics(block) || data.Raw != 0))
if (physics > 0 && (ActivatesPhysics(block) || data.Raw != 0)) {
AddCheck(b, false, data);
}
// Save bandwidth sending identical looking blocks, like air/op_air changes.
return !old.VisuallyEquals(block);
return !Block.VisuallyEquals(old, block);
} catch {
blocks[b] = block.BlockID;
blocks[b] = block >= Block.Extended ? Block.custom_block : (BlockRaw)block;
return false;
}
}
@ -403,12 +409,12 @@ namespace MCGalaxy {
if (type == 1) return; // not different visually
int index = PosToInt(x, y, z);
if (buffered) BlockQueue.Addblock(p, index, block);
if (buffered) BlockQueue.Add(p, index, block);
else Player.GlobalBlockchange(this, x, y, z, block);
}
public BlockDefinition GetBlockDef(BlockID block) {
if (block.BlockID == Block.custom_block) return CustomBlockDefs[block.ExtID];
if (block >= Block.Extended) return CustomBlockDefs[(BlockRaw)block];
if (block == Block.Air) return null;
if (block >= Block.CpeCount) {
@ -418,14 +424,6 @@ namespace MCGalaxy {
}
}
public string BlockName(BlockID block) {
if (block.IsPhysicsType) return Block.Name(block);
BlockDefinition def = GetBlockDef(block);
if (def != null) return def.Name.Replace(" ", "");
return block.BlockID != Block.custom_block ? Block.Name(block) : block.ExtID.ToString();
}
public byte CollideType(BlockID block) {
BlockDefinition def = GetBlockDef(block);
byte collide = def != null ? def.CollideType : MCGalaxy.Blocks.CollideType.Solid;

View File

@ -29,6 +29,7 @@ using MCGalaxy.Generator;
using MCGalaxy.Levels.IO;
using MCGalaxy.Util;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
public enum LevelPermission {
@ -445,12 +446,13 @@ namespace MCGalaxy {
internal bool HasCustomProps(BlockID block) {
if (Block.IsPhysicsType(block)) return false;
return CustomBlockDefs[block.RawID] != BlockDefinition.GlobalDefs[block.RawID];
BlockRaw raw = (BlockRaw)block;
return CustomBlockDefs[raw] != BlockDefinition.GlobalDefs[raw];
}
void LoadCoreProps() {
for (int i = 0; i < Props.Length; i++) {
BlockID block = (BlockID)i;
BlockID block = (BlockID)i;
if (!HasCustomProps(block)) {
Props[i] = BlockDefinition.DefaultProps(block);
} else {
@ -466,7 +468,7 @@ namespace MCGalaxy {
public void UpdateBlockHandlers() {
for (int i = 0; i < Props.Length; i++) {
UpdateBlockHandler((ushort)i);
UpdateBlockHandler((ushort)i);
}
}

View File

@ -21,6 +21,7 @@ using MCGalaxy.Commands.Building;
using MCGalaxy.Network;
using MCGalaxy.Blocks;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
public static class LevelEnv {
@ -114,7 +115,7 @@ namespace MCGalaxy {
}
static bool CheckBlock(Player p, string value, string variable, ref byte modify) {
static bool CheckBlock(Player p, string value, string variable, ref BlockRaw modify) {
BlockID block;
if (!CommandParser.GetBlock(p, value, out block)) return false;
@ -123,7 +124,7 @@ namespace MCGalaxy {
}
string name = Block.GetName(p, block);
modify = block.RawID;
modify = (BlockRaw)block;
Player.Message(p, "Set {0} for {1} %Sto {2}", variable, p.level.ColoredName, name);
return true;
}

View File

@ -21,6 +21,7 @@ using MCGalaxy.Events;
using MCGalaxy.Events.PlayerEvents;
using MCGalaxy.Network;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
public partial class Player : IDisposable {
@ -262,11 +263,11 @@ namespace MCGalaxy {
NetUtils.WriteU16(y, buffer, 3);
NetUtils.WriteU16(z, buffer, 5);
byte raw;
if (block.BlockID == Block.custom_block) {
raw = hasBlockDefs ? block.ExtID : level.RawFallback(block.ExtID);
BlockRaw raw;
if (block >= Block.Extended) {
raw = hasBlockDefs ? (BlockRaw)block : level.RawFallback((BlockRaw)block);
} else {
raw = Block.Convert(block.BlockID);
raw = (BlockRaw)Block.Convert(block);
}
if (!hasCustomBlocks) raw = Block.ConvertCPE(raw); // client doesn't support CPE

View File

@ -17,6 +17,7 @@
*/
using System;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy.Network {
/// <summary> Combines block changes and sends them as either a single CPE BulkBlockUpdate packet,
@ -45,9 +46,13 @@ namespace MCGalaxy.Network {
/// number of buffered block changes has reached the limit. </summary>
/// <returns> Whether block change packets were actually sent. </returns>
public bool Add(int index, BlockID block) {
indices[count] = index;
if (block == Block.custom_block) types[count] = extBlock;
else types[count] = Block.Convert(block);
indices[count] = index;
if (Block.IsPhysicsType(block)) {
types[count] = (BlockRaw)Block.Convert(block);
} else {
types[count] = (BlockRaw)block;
}
count++;
return Send(false);
}

View File

@ -90,8 +90,10 @@ namespace MCGalaxy.Network {
// Store on stack instead of performing function call for every block in map
byte* conv = stackalloc byte[Block.Count];
byte* convCPE = stackalloc byte[Block.Count];
for (int i = 0; i < 256; i++)
conv[i] = Block.Convert((byte)i);
for (int i = 0; i < 256; i++) {
conv[i] = (byte)Block.Convert((byte)i);
if (conv[i] > Block.CpeCount) conv[i] = Block.Orange;
}
// Convert custom blocks (that overwrote core blocks) to their fallbacks
if (!p.hasBlockDefs) {

View File

@ -19,6 +19,7 @@ using System;
using System.Collections.Generic;
using MCGalaxy.Blocks;
using MCGalaxy.Network;
using BlockID = System.UInt16;
namespace MCGalaxy {
public partial class Player {

View File

@ -28,6 +28,7 @@ using MCGalaxy.Network;
using MCGalaxy.SQL;
using MCGalaxy.Util;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
public partial class Player : IDisposable {
@ -109,7 +110,7 @@ namespace MCGalaxy {
}
BlockID held = block;
block = BlockBindings[block.RawID];
if (!Block.IsPhysicsType(block)) block = BlockBindings[(BlockRaw)block];
if (!CheckManualChange(old, block, deletingBlock)) {
RevertBlock(x, y, z); return;
}
@ -118,7 +119,7 @@ namespace MCGalaxy {
//Ignores updating blocks that are the same and revert block back only to the player
BlockID newB = deletingBlock ? Block.Air : block;
if (old == newB) {
if (painting || !old.VisuallyEquals(held)) RevertBlock(x, y, z);
if (painting || !Block.VisuallyEquals(old, held)) RevertBlock(x, y, z);
return;
}
@ -133,7 +134,7 @@ namespace MCGalaxy {
}
internal bool CheckManualChange(BlockID old, BlockID block, bool deleteMode) {
if (!BlockPerms.UsableBy(this, old) && !Block.BuildIn(old.BlockID) && !Block.AllowBreak(old.BlockID)) {
if (!BlockPerms.UsableBy(this, old) && !level.BuildIn(old) && !Block.AllowBreak(old)) {
string action = deleteMode ? "delete" : "replace";
BlockPerms.List[old].MessageCannotUse(this, action);
return false;
@ -294,9 +295,10 @@ namespace MCGalaxy {
RevertBlock(x, y, z); return;
}
if (held.BlockID == Block.custom_block) {
if (!hasBlockDefs || level.CustomBlockDefs[held.ExtID] == null) {
SendMessage("Invalid block type: " + held.ExtID);
if (held >= Block.Extended) {
BlockRaw raw = (BlockRaw)held;
if (!hasBlockDefs || level.CustomBlockDefs[raw] == null) {
SendMessage("Invalid block type: " + raw);
RevertBlock(x, y, z); return;
}
}

View File

@ -28,6 +28,7 @@ using MCGalaxy.Network;
using MCGalaxy.Tasks;
using MCGalaxy.Maths;
using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
public class ChatMessage {
@ -90,9 +91,9 @@ namespace MCGalaxy {
return Rank >= target.Rank;
}
public ushort GetHeldBlock() {
public BlockID GetHeldBlock() {
if (ModeBlock != Block.Air) return ModeBlock;
return BlockBindings[RawHeldBlock.RawID];
return BlockBindings[(BlockRaw)RawHeldBlock];
}
public void SetPrefix() {
@ -471,7 +472,7 @@ namespace MCGalaxy {
SelectionHandler callback = selCallback;
ClearSelection();
if (!block.IsPhysicsType) block = p.BlockBindings[block.RawID];
if (!Block.IsPhysicsType(block)) block = p.BlockBindings[(BlockRaw)block];
bool canRepeat = callback(this, selMarks, state, block);
if (canRepeat && staticCommands) {

View File

@ -131,7 +131,7 @@ namespace MCGalaxy {
InitZombieSurvival();
InitLavaSurvival();
MainScheduler.QueueRepeat(BlockQueue.Loop, null,
TimeSpan.FromMilliseconds(BlockQueue.time));
TimeSpan.FromMilliseconds(BlockQueue.Interval));
Critical.QueueRepeat(ServerTasks.LocationChecks, null,
TimeSpan.FromMilliseconds(20));

View File

@ -267,9 +267,5 @@ namespace MCGalaxy.Tasks {
bulk.Commit();
}
}
internal static void UpgradeZones(SchedulerTask task) {
}
}
}