Whether a block drowns people is now a block property.

This commit is contained in:
UnknownShadow200 2017-08-26 16:45:04 +10:00
parent a03f1e616c
commit 3637009ab1
5 changed files with 44 additions and 29 deletions

View File

@ -89,6 +89,8 @@ namespace MCGalaxy {
Props[Red].IsRails = true; Props[Op_Air].IsRails = true;
Props[Slab].StackId = DoubleSlab;
Props[CobblestoneSlab].StackId = Cobblestone;
Props[Water].Drownable = true; Props[StillWater].Drownable = true;
Props[Lava].Drownable = true; Props[StillLava].Drownable = true;
// Block specific physics properties
Props[Block.Bird_Black].AnimalAI = AnimalAI.Fly;
@ -246,8 +248,12 @@ namespace MCGalaxy {
SetDeath(Block.Fish_LavaShark, "@p %Swas eaten by a ... LAVA SHARK?!");
SetDeath(Block.Snake, "@p %Swas bit by a deadly snake.");
const string drowned = "@p %S&cdrowned.";
SetDeath(Block.Air, "@p %Shit the floor &chard.", false);
SetDeath(Block.Water, "@p %S&cdrowned.", false);
SetDeath(Block.Water, drowned, false);
SetDeath(Block.StillWater, drowned, false);
SetDeath(Block.Lava, drowned, false);
SetDeath(Block.StillLava, drowned, false);
SetDeath(Block.Invalid, "@p %Swas &cterminated.", false);
}

View File

@ -45,6 +45,7 @@ namespace MCGalaxy.Blocks {
public bool IsMessageBlock;
/// <summary> Whether this block is considered a portal. </summary>
public bool IsPortal;
/// <summary> Whether this block is overwritten/killed by water blocks. </summary>
public bool WaterKills;
/// <summary> Whether this block is overwritten/killed by lava blocks. </summary>
@ -63,6 +64,9 @@ namespace MCGalaxy.Blocks {
/// <remarks> e.g. slabs and cobblestone slabs. </remarks>
public byte StackId;
/// <summary> Whether players can drown inside this block (e.g. water). </summary>
public bool Drownable;
/// <summary> Whether the properties for this block have been modified and hence require saving. </summary>
public bool Changed;
@ -81,7 +85,7 @@ namespace MCGalaxy.Blocks {
w.WriteLine("# This represents the physics properties for blocks, in the format of:");
w.WriteLine("# id : Is rails : Is tdoor : Is door : Is message block : Is portal : " +
"Killed by water : Killed by lava : Kills players : death message : " +
"Animal AI type : Stack block : Is OP block");
"Animal AI type : Stack block : Is OP block : oDoor block : Drownable");
for (int i = 0; i < scope.Length; i++) {
if (!scope[i].Changed || (selector != null && !selector(i))) continue;
BlockProps props = scope[i];
@ -89,10 +93,11 @@ namespace MCGalaxy.Blocks {
int id = i >= Block.Count ? (i - Block.Count) : i;
string deathMsg = props.DeathMessage == null ? "" : props.DeathMessage.Replace(":", "\\;");
w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":"
w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":"
+ props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":"
+ props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg + ":"
+ (byte)props.AnimalAI + ":" + props.StackId + ":" + props.OPBlock + ":" + props.oDoorIndex);
+ props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg + ":"
+ (byte)props.AnimalAI + ":" + props.StackId + ":" + props.OPBlock + ":"
+ props.oDoorIndex + ":" + props.Drownable);
}
}
}
@ -149,6 +154,9 @@ namespace MCGalaxy.Blocks {
ushort oDoor; ushort.TryParse(parts[13], out oDoor);
scope[idx].oDoorIndex = oDoor;
}
if (parts.Length > 14) {
bool.TryParse(parts[14], out scope[idx].Drownable);
}
}
}
}

View File

@ -105,8 +105,7 @@ namespace MCGalaxy.Blocks.Physics {
lvl.IntToPos(C.b, out x, out y, out z);
byte below = lvl.GetTile(x, (ushort)(y - 1), z);
switch (below)
{
switch (below) {
case Block.Air:
lvl.AddUpdate(lvl.PosToInt(x, (ushort)(y - 1), z), Block.WaterDown);
if (!C.data.HasWait) C.data.Data = PhysicsArgs.RemoveFromChecks;
@ -116,6 +115,7 @@ namespace MCGalaxy.Blocks.Physics {
case Block.StillWater:
case Block.WaterDown:
break;
default:
byte block = lvl.blocks[C.b];
LiquidPhysics.PhysWater(lvl, (ushort)(x + 1), y, z, block);

View File

@ -136,6 +136,9 @@ namespace MCGalaxy.Commands.World {
} else if (prop == "odoor") {
string odoor = args.Length > 3 ? args[3] : null;
SetODoor(p, scope, block, i, odoor);
} else if (prop == "drownable" || prop == "drown") {
scope[i].Drownable = !scope[i].Drownable;
OnToggleSet(p, scope, block, "drowns players", scope[i].Drownable);
} else {
Help(p);
}
@ -270,7 +273,7 @@ namespace MCGalaxy.Commands.World {
Player.Message(p, "%H[scope] can be: %Score, global, level");
Player.Message(p, "%Hproperties: %Sportal, messageblock, rails, waterkills, " +
"lavakills, door, tdoor, killer, deathmessage, animalai, stackblock, opblock, odoor");
"lavakills, door, tdoor, killer, deathmessage, animalai, stackblock, opblock, odoor, drownable");
Player.Message(p, "%HType %T/Help BlockProps [property] %Hfor more details");
}
@ -306,7 +309,10 @@ namespace MCGalaxy.Commands.World {
"and can't be replaced in games when build type is ModifyOnly.");
} else if (message.CaselessEq("odoor")) {
Player.Message(p, "%HSets the block that this block is changed into, when activated by a neighbouring door.");
} else {
} else if (message.CaselessEq("drownable")) {
Player.Message(p, "%HSets whether this block can drown players.");
Player.Message(p, "%T/Map death %Hmust be enabled for players to drown.");
} else {
Player.Message(p, "&cUnrecognised property \"{0}\"", message);
}
}

View File

@ -91,27 +91,22 @@ namespace MCGalaxy.Blocks.Physics {
ExtBlock bHead = GetSurvivalBlock(p, P.X, P.Y, P.Z);
if (bHead.IsPhysicsType) bHead.BlockID = Block.Convert(bHead.BlockID);
switch (bHead.BlockID) {
case Block.Water:
case Block.StillWater:
case Block.Lava:
case Block.StillLava:
p.startFallY = -1;
DateTime now = DateTime.UtcNow;
// level drown is in 10ths of a second
if (p.drownTime == DateTime.MaxValue)
p.drownTime = now.AddSeconds(p.level.Config.DrownTime / 10.0);
if (now > p.drownTime) {
p.HandleDeath((ExtBlock)Block.Water);
p.drownTime = DateTime.MaxValue;
}
break;
default:
bool isGas = p.level.CollideType(bHead) == CollideType.WalkThrough;
if (!isGas) p.startFallY = -1;
if (p.level.BlockProps[bHead.Index].Drownable) {
p.startFallY = -1;
DateTime now = DateTime.UtcNow;
// level drown is in 10ths of a second
if (p.drownTime == DateTime.MaxValue) {
p.drownTime = now.AddSeconds(p.level.Config.DrownTime / 10.0);
}
if (now > p.drownTime) {
p.HandleDeath(bHead);
p.drownTime = DateTime.MaxValue;
break;
}
} else {
bool isGas = p.level.CollideType(bHead) == CollideType.WalkThrough;
if (!isGas) p.startFallY = -1;
p.drownTime = DateTime.MaxValue;
}
}