diff --git a/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs b/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs index 7af095c0c..9348430d9 100644 --- a/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs @@ -42,11 +42,11 @@ namespace MCGalaxy.Blocks { switch (block.BlockID) { case Block.dirt: return PlaceBehaviour.Dirt; case Block.grass: return PlaceBehaviour.Grass; - case Block.staircasestep: return PlaceBehaviour.Stairs; - case Block.cobblestoneslab: return PlaceBehaviour.CobbleStairs; case Block.c4: return PlaceBehaviour.C4; case Block.c4det: return PlaceBehaviour.C4Det; } + + if (props[block.Index].StackId != Block.air) return PlaceBehaviour.Stack(block); return null; } @@ -129,8 +129,6 @@ namespace MCGalaxy.Blocks { case Block.lava_fire: return FirePhysics.Do; case Block.sand: return OtherPhysics.DoFalling; case Block.gravel: return OtherPhysics.DoFalling; - case Block.cobblestoneslab: return OtherPhysics.DoStairs; - case Block.staircasestep: return OtherPhysics.DoStairs; case Block.wood_float: return OtherPhysics.DoFloatwood; case Block.sponge: return (Level lvl, ref Check C) => diff --git a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs index bb3bf764e..373ed46d0 100644 --- a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs @@ -44,27 +44,18 @@ namespace MCGalaxy.Blocks { p.ChangeBlock(x, y, z, block); } - - internal static void Stairs(Player p, ExtBlock block, ushort x, ushort y, ushort z) { - if (!(p.level.physics == 0 || p.level.physics == 5) - || p.level.GetBlock(x, (ushort)(y - 1), z) != (ExtBlock)Block.staircasestep) { - p.ChangeBlock(x, y, z, (ExtBlock)Block.staircasestep); return; + internal static HandlePlace Stack(ExtBlock block) { + return (p, b, x, y, z) => Stack(p, block, x, y, z); + } + static void Stack(Player p, ExtBlock block, ushort x, ushort y, ushort z) { + if (p.level.GetBlock(x, (ushort)(y - 1), z) != block) { + p.ChangeBlock(x, y, z, block); return; } p.SendBlockchange(x, y, z, ExtBlock.Air); // send the air block back only to the user - p.ChangeBlock(x, (ushort)(y - 1), z, (ExtBlock)Block.staircasefull); - } - - internal static void CobbleStairs(Player p, ExtBlock block, ushort x, ushort y, ushort z) { - if (!(p.level.physics == 0 || p.level.physics == 5) - || p.level.GetBlock(x, (ushort)(y - 1), z) != (ExtBlock)Block.cobblestoneslab) { - p.ChangeBlock(x, y, z, (ExtBlock)Block.cobblestoneslab); return; - } - - p.SendBlockchange(x, y, z, ExtBlock.Air); // send the air block back only to the user - p.ChangeBlock(x, (ushort)(y - 1), z, (ExtBlock)Block.stone); - } - + byte stack = p.level.BlockProps[block.Index].StackId; + p.ChangeBlock(x, (ushort)(y - 1), z, ExtBlock.FromRaw(stack)); + } internal static void C4(Player p, ExtBlock block, ushort x, ushort y, ushort z) { if (p.level.physics == 0 || p.level.physics == 5) { diff --git a/MCGalaxy/Blocks/Block.CoreProps.cs b/MCGalaxy/Blocks/Block.CoreProps.cs index 0abf52853..1a4a19684 100644 --- a/MCGalaxy/Blocks/Block.CoreProps.cs +++ b/MCGalaxy/Blocks/Block.CoreProps.cs @@ -83,6 +83,8 @@ namespace MCGalaxy { Props[sponge].LavaKills = true; Props[bookcase].LavaKills = true; Props[leaf].LavaKills = true; Props[crate].LavaKills = true; Props[red].IsRails = true; Props[op_air].IsRails = true; + Props[staircasestep].StackId = staircasefull; + Props[cobblestoneslab].StackId = stone; // Block specific physics properties Props[Block.birdblack].AnimalAI = AnimalAI.Fly; diff --git a/MCGalaxy/Blocks/BlockProperties.cs b/MCGalaxy/Blocks/BlockProperties.cs index 45167e48d..08f96050d 100644 --- a/MCGalaxy/Blocks/BlockProperties.cs +++ b/MCGalaxy/Blocks/BlockProperties.cs @@ -63,6 +63,10 @@ namespace MCGalaxy.Blocks { /// Animal AI behaviour of this block. public AnimalAI AnimalAI; + /// ID of the block that is placed when two of this block are placed on top of each other. + /// e.g. slabs and cobblestone slabs. + public byte StackId; + /// Whether the properties for this block have been modified and hence require saving. public bool Changed; @@ -92,7 +96,7 @@ namespace MCGalaxy.Blocks { w.WriteLine(id + ":" + props.IsRails + ":" + props.IsTDoor + ":" + props.IsDoor + ":" + props.IsMessageBlock + ":" + props.IsPortal + ":" + props.WaterKills + ":" + props.LavaKills + ":" + props.KillerBlock + ":" + deathMsg + ":" - + (byte)props.AnimalAI); + + (byte)props.AnimalAI + ":" + props.StackId); } } } @@ -138,6 +142,10 @@ namespace MCGalaxy.Blocks { byte ai; byte.TryParse(parts[10], out ai); scope[idx].AnimalAI = (AnimalAI)ai; } + if (parts.Length > 11) { + byte stackId; byte.TryParse(parts[11], out stackId); + scope[idx].StackId = stackId; + } } } } diff --git a/MCGalaxy/Blocks/Physics/OtherPhysics.cs b/MCGalaxy/Blocks/Physics/OtherPhysics.cs index 7500d2d6a..889572274 100644 --- a/MCGalaxy/Blocks/Physics/OtherPhysics.cs +++ b/MCGalaxy/Blocks/Physics/OtherPhysics.cs @@ -66,22 +66,6 @@ namespace MCGalaxy.Blocks.Physics { } C.data.Data = PhysicsArgs.RemoveFromChecks; } - - public static void DoStairs(Level lvl, ref Check C) { - int indexBelow = lvl.IntOffset(C.b, 0, -1, 0); - byte block = lvl.blocks[C.b]; - byte below = Block.Invalid; - if (indexBelow >= 0) below = lvl.blocks[indexBelow]; - - if (below == Block.staircasestep && block == Block.staircasestep) { - lvl.AddUpdate(C.b, Block.air); - lvl.AddUpdate(indexBelow, Block.staircasefull); - } else if (below == Block.cobblestoneslab && block == Block.cobblestoneslab) { - lvl.AddUpdate(C.b, Block.air); - lvl.AddUpdate(indexBelow, Block.stone); - } - C.data.Data = PhysicsArgs.RemoveFromChecks; - } public static void DoFloatwood(Level lvl, ref Check C) { int index = lvl.IntOffset(C.b, 0, -1, 0); diff --git a/MCGalaxy/Commands/World/CmdBlockProperties.cs b/MCGalaxy/Commands/World/CmdBlockProperties.cs index afe75b9bd..76a3ef1d2 100644 --- a/MCGalaxy/Commands/World/CmdBlockProperties.cs +++ b/MCGalaxy/Commands/World/CmdBlockProperties.cs @@ -126,6 +126,9 @@ namespace MCGalaxy.Commands.World { } else if (prop == "animalai" || prop == "animal") { string msg = args.Length > 3 ? args[3] : null; SetEnum(p, scope, block, msg); + } else if (prop == "stackid" || prop == "stackblock") { + string msg = args.Length > 3 ? args[3] : null; + SetStackId(p, scope, block, msg); } else { Help(p); } @@ -173,6 +176,20 @@ namespace MCGalaxy.Commands.World { OnPropsChanged(scope, lvl, block); } + static void SetStackId(Player p, BlockProps[] scope, ExtBlock block, string msg) { + Level lvl = Player.IsSuper(p) ? null : p.level; + ExtBlock stackBlock; + if (!CommandParser.GetBlock(p, msg, out stackBlock)) return; + + scope[block.Index].StackId = stackBlock.RawID; + 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); + OnPropsChanged(scope, lvl, block); + } + static void OnPropsChanged(BlockProps[] scope, Level level, ExtBlock block) { scope[block.Index].Changed = true; @@ -231,7 +248,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"); + "lavakills, door, tdoor, killer, deathmessage, animalai, stackblock"); Player.Message(p, "%HType %T/help blockprops [property] %Hfor more details"); }