From ae122ffb415115dd9feb090aa7e947378f00bc7a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 5 Oct 2016 09:32:40 +1100 Subject: [PATCH] Core: Start working on a command that allows changing the properties of blocks. (Still a major WIP) --- .../{Block.Behaviour.cs => BlockBehaviour.cs} | 364 +++++++++--------- MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs | 2 +- MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs | 2 +- .../Blocks/Behaviour/WalkthroughBehaviour.cs | 2 +- MCGalaxy/Blocks/Block.CoreProps.cs | 4 +- MCGalaxy/Blocks/Block.Permissions.cs | 4 +- MCGalaxy/Blocks/Block.cs | 2 +- MCGalaxy/Blocks/BlockProperties.cs | 6 +- MCGalaxy/Commands/Information/CmdBlocks.cs | 2 +- MCGalaxy/Commands/World/CmdBlockProperties.cs | 86 +++++ MCGalaxy/Commands/World/CmdMain.cs | 6 +- MCGalaxy/Commands/building/CmdMessageBlock.cs | 2 +- MCGalaxy/Levels/Level.Physics.cs | 7 +- MCGalaxy/Levels/Physics/TrainPhysics.cs | 4 +- MCGalaxy/MCGalaxy_.csproj | 3 +- MCGalaxy/Player/Player.Handlers.cs | 9 +- 16 files changed, 300 insertions(+), 205 deletions(-) rename MCGalaxy/Blocks/Behaviour/{Block.Behaviour.cs => BlockBehaviour.cs} (78%) create mode 100644 MCGalaxy/Commands/World/CmdBlockProperties.cs diff --git a/MCGalaxy/Blocks/Behaviour/Block.Behaviour.cs b/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs similarity index 78% rename from MCGalaxy/Blocks/Behaviour/Block.Behaviour.cs rename to MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs index d8999dbb3..301bf8210 100644 --- a/MCGalaxy/Blocks/Behaviour/Block.Behaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs @@ -1,180 +1,184 @@ -/* - Copyright 2015 MCGalaxy - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. - */ -using System; -using MCGalaxy.BlockBehaviour; -using MCGalaxy.BlockPhysics; - -namespace MCGalaxy { - - public sealed partial class Block { - - /// Returns whether this block handles the player placing a block at the given coordinates. - /// If this returns true, the usual 'dirt/grass below' behaviour and 'adding to the BlockDB' is skipped. - public delegate bool HandleDelete(Player p, byte oldBlock, ushort x, ushort y, ushort z); - internal static HandleDelete[] deleteHandlers = new HandleDelete[256]; - - /// Returns whether this block handles the player deleting a block at the given coordinates. - /// If this returns true, the usual 'checking dirt/grass below' and 'adding to the BlockDB' is skipped. - public delegate bool HandlePlace(Player p, byte oldBlock, ushort x, ushort y, ushort z); - internal static HandlePlace[] placeHandlers = new Block.HandlePlace[256]; - - /// Returns whether this block handles the player walking through this block at the given coordinates. - /// If this returns true, the usual 'death check' behaviour is skipped. - public delegate bool HandleWalkthrough(Player p, byte block, ushort x, ushort y, ushort z); - internal static HandleWalkthrough[] walkthroughHandlers = new Block.HandleWalkthrough[256]; - - /// Called to handle the physics for this particular block. - /// If this returns true, the usual 'death check' behaviour is skipped. - public delegate void HandlePhysics(Level lvl, ref Check C); - internal static HandlePhysics[] physicsHandlers = new Block.HandlePhysics[256]; - internal static HandlePhysics[] physicsDoorsHandlers = new Block.HandlePhysics[256]; - - static void SetupCoreHandlers() { - deleteHandlers[Block.rocketstart] = DeleteBehaviour.RocketStart; - deleteHandlers[Block.firework] = DeleteBehaviour.Firework; - deleteHandlers[Block.c4det] = DeleteBehaviour.C4Det; - - placeHandlers[Block.dirt] = PlaceBehaviour.Dirt; - placeHandlers[Block.grass] = PlaceBehaviour.Grass; - placeHandlers[Block.staircasestep] = PlaceBehaviour.Stairs; - placeHandlers[Block.c4] = PlaceBehaviour.C4; - placeHandlers[Block.c4det] = PlaceBehaviour.C4Det; - - walkthroughHandlers[Block.checkpoint] = WalkthroughBehaviour.Checkpoint; - walkthroughHandlers[Block.air_switch] = WalkthroughBehaviour.Door; - walkthroughHandlers[Block.water_door] = WalkthroughBehaviour.Door; - walkthroughHandlers[Block.lava_door] = WalkthroughBehaviour.Door; - walkthroughHandlers[Block.train] = WalkthroughBehaviour.Train; - - for (int i = 0; i < 256; i++) { - if (Props[i].IsMessageBlock) { - walkthroughHandlers[i] = (p, block, x, y, z) => - WalkthroughBehaviour.MessageBlock(p, block, x, y, z, true); - deleteHandlers[i] = (p, block, x, y, z) => - WalkthroughBehaviour.MessageBlock(p, block, x, y, z, false); - } else if (Props[i].IsPortal) { - walkthroughHandlers[i] = (p, block, x, y, z) => - WalkthroughBehaviour.Portal(p, block, x, y, z, true); - deleteHandlers[i] = (p, block, x, y, z) => - WalkthroughBehaviour.Portal(p, block, x, y, z, false); - } - - if (Block.Props[i].IsTDoor) { - deleteHandlers[i] = DeleteBehaviour.RevertDoor; - } else if (Props[i].ODoorId != Block.Zero) { - deleteHandlers[i] = DeleteBehaviour.ODoor; - } else if (Block.Props[i].IsDoor) { - deleteHandlers[i] = DeleteBehaviour.Door; - } - } - - deleteHandlers[Block.door_tree_air] = DeleteBehaviour.RevertDoor; - deleteHandlers[Block.door_tnt_air] = DeleteBehaviour.RevertDoor; - deleteHandlers[Block.door_green_air] = DeleteBehaviour.RevertDoor; - SetupCorePhysicsHandlers(); - } - - static void SetupCorePhysicsHandlers() { - physicsHandlers[Block.birdblack] = BirdPhysics.Do; - physicsHandlers[Block.birdwhite] = BirdPhysics.Do; - physicsHandlers[Block.birdlava] = BirdPhysics.Do; - physicsHandlers[Block.birdwater] = BirdPhysics.Do; - physicsHandlers[Block.birdred] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air); - physicsHandlers[Block.birdblue] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air); - physicsHandlers[Block.birdkill] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air); - - physicsHandlers[Block.snaketail] = SnakePhysics.DoTail; - physicsHandlers[Block.snake] = SnakePhysics.Do; - physicsHandlers[Block.rockethead] = RocketPhysics.Do; - physicsHandlers[Block.firework] = FireworkPhysics.Do; - physicsHandlers[Block.zombiebody] = ZombiePhysics.Do; - physicsHandlers[Block.zombiehead] = ZombiePhysics.DoHead; - physicsHandlers[Block.creeper] = ZombiePhysics.Do; - - physicsHandlers[Block.fishbetta] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.water); - physicsHandlers[Block.fishshark] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.water); - physicsHandlers[Block.fishlavashark] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.lava); - physicsHandlers[Block.fishgold] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water); - physicsHandlers[Block.fishsalmon] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water); - physicsHandlers[Block.fishsponge] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water); - - physicsHandlers[Block.water] = SimpleLiquidPhysics.DoWater; - physicsHandlers[Block.activedeathwater] = SimpleLiquidPhysics.DoWater; - physicsHandlers[Block.lava] = SimpleLiquidPhysics.DoLava; - physicsHandlers[Block.activedeathlava] = SimpleLiquidPhysics.DoLava; - physicsHandlers[Block.WaterDown] = ExtLiquidPhysics.DoWaterfall; - physicsHandlers[Block.LavaDown] = ExtLiquidPhysics.DoLavafall; - physicsHandlers[Block.WaterFaucet] = (Level lvl, ref Check C) => - ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.WaterDown); - physicsHandlers[Block.LavaFaucet] = (Level lvl, ref Check C) => - ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.LavaDown); - physicsHandlers[Block.finiteWater] = FinitePhysics.DoWaterOrLava; - physicsHandlers[Block.finiteLava] = FinitePhysics.DoWaterOrLava; - physicsHandlers[Block.finiteFaucet] = FinitePhysics.DoFaucet; - physicsHandlers[Block.magma] = ExtLiquidPhysics.DoMagma; - physicsHandlers[Block.geyser] = ExtLiquidPhysics.DoGeyser; - physicsHandlers[Block.lava_fast] = SimpleLiquidPhysics.DoFastLava; - physicsHandlers[Block.fastdeathlava] = SimpleLiquidPhysics.DoFastLava; - - physicsHandlers[Block.air] = AirPhysics.DoAir; - physicsHandlers[Block.dirt] = OtherPhysics.DoDirt; - physicsHandlers[Block.leaf] = LeafPhysics.DoLeaf; - physicsHandlers[Block.shrub] = OtherPhysics.DoShrub; - physicsHandlers[Block.fire] = FirePhysics.Do; - physicsHandlers[Block.lava_fire] = FirePhysics.Do; - physicsHandlers[Block.sand] = OtherPhysics.DoFalling; - physicsHandlers[Block.gravel] = OtherPhysics.DoFalling; - physicsHandlers[Block.cobblestoneslab] = OtherPhysics.DoStairs; - physicsHandlers[Block.staircasestep] = OtherPhysics.DoStairs; - physicsHandlers[Block.wood_float] = OtherPhysics.DoFloatwood; - - physicsHandlers[Block.sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, false); - physicsHandlers[Block.lava_sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, true); - - //Special blocks that are not saved - physicsHandlers[Block.air_flood] = (Level lvl, ref Check C) => - AirPhysics.DoFlood(lvl, ref C, AirFlood.Full, Block.air_flood); - physicsHandlers[Block.air_flood_layer] = (Level lvl, ref Check C) => - AirPhysics.DoFlood(lvl, ref C, AirFlood.Layer, Block.air_flood_layer); - physicsHandlers[Block.air_flood_down] = (Level lvl, ref Check C) => - AirPhysics.DoFlood(lvl, ref C, AirFlood.Down, Block.air_flood_down); - physicsHandlers[Block.air_flood_up] = (Level lvl, ref Check C) => - AirPhysics.DoFlood(lvl, ref C, AirFlood.Up, Block.air_flood_up); - - physicsHandlers[Block.smalltnt] = TntPhysics.DoSmallTnt; - physicsHandlers[Block.bigtnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 1); - physicsHandlers[Block.nuketnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 4); - physicsHandlers[Block.tntexplosion] = TntPhysics.DoTntExplosion; - physicsHandlers[Block.train] = TrainPhysics.Do; - - for (int i = 0; i < 256; i++) { - //Adv physics updating anything placed next to water or lava - if ((i >= Block.red && i <= Block.redmushroom) || i == Block.wood || - i == Block.trunk || i == Block.bookcase) { - physicsHandlers[i] = OtherPhysics.DoOther; - continue; - } - - if (Block.odoor((byte)i) != Block.Zero) { - physicsHandlers[i] = DoorPhysics.oDoor; - physicsDoorsHandlers[i] = DoorPhysics.oDoor; - } - } - } - } -} +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using MCGalaxy.BlockPhysics; + +namespace MCGalaxy.Blocks { + + /// Returns whether this block handles the player placing a block at the given coordinates. + /// If this returns true, the usual 'dirt/grass below' behaviour and 'adding to the BlockDB' is skipped. + public delegate bool HandleDelete(Player p, byte oldBlock, ushort x, ushort y, ushort z); + + /// Returns whether this block handles the player deleting a block at the given coordinates. + /// If this returns true, the usual 'checking dirt/grass below' and 'adding to the BlockDB' is skipped. + public delegate bool HandlePlace(Player p, byte oldBlock, ushort x, ushort y, ushort z); + + /// Returns whether this block handles the player walking through this block at the given coordinates. + /// If this returns true, the usual 'death check' behaviour is skipped. + public delegate bool HandleWalkthrough(Player p, byte block, ushort x, ushort y, ushort z); + + /// Called to handle the physics for this particular block. + /// If this returns true, the usual 'death check' behaviour is skipped. + public delegate void HandlePhysics(Level lvl, ref Check C); + + public static class BlockBehaviour { + internal static HandleDelete[] deleteHandlers = new HandleDelete[256]; + internal static HandlePlace[] placeHandlers = new HandlePlace[256]; + internal static HandleWalkthrough[] walkthroughHandlers = new HandleWalkthrough[256]; + internal static HandlePhysics[] physicsHandlers = new HandlePhysics[256]; + internal static HandlePhysics[] physicsDoorsHandlers = new HandlePhysics[256]; + + internal static void SetupCoreHandlers() { + for (int i = 0; i < 256; i++) { + deleteHandlers[i] = null; + placeHandlers[i] = null; + walkthroughHandlers[i] = null; + } + + deleteHandlers[Block.rocketstart] = DeleteBehaviour.RocketStart; + deleteHandlers[Block.firework] = DeleteBehaviour.Firework; + deleteHandlers[Block.c4det] = DeleteBehaviour.C4Det; + + placeHandlers[Block.dirt] = PlaceBehaviour.Dirt; + placeHandlers[Block.grass] = PlaceBehaviour.Grass; + placeHandlers[Block.staircasestep] = PlaceBehaviour.Stairs; + placeHandlers[Block.c4] = PlaceBehaviour.C4; + placeHandlers[Block.c4det] = PlaceBehaviour.C4Det; + + walkthroughHandlers[Block.checkpoint] = WalkthroughBehaviour.Checkpoint; + walkthroughHandlers[Block.air_switch] = WalkthroughBehaviour.Door; + walkthroughHandlers[Block.water_door] = WalkthroughBehaviour.Door; + walkthroughHandlers[Block.lava_door] = WalkthroughBehaviour.Door; + walkthroughHandlers[Block.train] = WalkthroughBehaviour.Train; + + for (int i = 0; i < 256; i++) { + if (Block.Props[i].IsMessageBlock) { + walkthroughHandlers[i] = (p, block, x, y, z) => + WalkthroughBehaviour.MessageBlock(p, block, x, y, z, true); + deleteHandlers[i] = (p, block, x, y, z) => + WalkthroughBehaviour.MessageBlock(p, block, x, y, z, false); + } else if (Block.Props[i].IsPortal) { + walkthroughHandlers[i] = (p, block, x, y, z) => + WalkthroughBehaviour.Portal(p, block, x, y, z, true); + deleteHandlers[i] = (p, block, x, y, z) => + WalkthroughBehaviour.Portal(p, block, x, y, z, false); + } + + if (Block.Props[i].IsTDoor) { + deleteHandlers[i] = DeleteBehaviour.RevertDoor; + } else if (Block.Props[i].ODoorId != Block.Zero) { + deleteHandlers[i] = DeleteBehaviour.ODoor; + } else if (Block.Props[i].IsDoor) { + deleteHandlers[i] = DeleteBehaviour.Door; + } + } + + deleteHandlers[Block.door_tree_air] = DeleteBehaviour.RevertDoor; + deleteHandlers[Block.door_tnt_air] = DeleteBehaviour.RevertDoor; + deleteHandlers[Block.door_green_air] = DeleteBehaviour.RevertDoor; + } + + internal static void SetupCorePhysicsHandlers() { + physicsHandlers[Block.birdblack] = BirdPhysics.Do; + physicsHandlers[Block.birdwhite] = BirdPhysics.Do; + physicsHandlers[Block.birdlava] = BirdPhysics.Do; + physicsHandlers[Block.birdwater] = BirdPhysics.Do; + physicsHandlers[Block.birdred] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air); + physicsHandlers[Block.birdblue] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air); + physicsHandlers[Block.birdkill] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air); + + physicsHandlers[Block.snaketail] = SnakePhysics.DoTail; + physicsHandlers[Block.snake] = SnakePhysics.Do; + physicsHandlers[Block.rockethead] = RocketPhysics.Do; + physicsHandlers[Block.firework] = FireworkPhysics.Do; + physicsHandlers[Block.zombiebody] = ZombiePhysics.Do; + physicsHandlers[Block.zombiehead] = ZombiePhysics.DoHead; + physicsHandlers[Block.creeper] = ZombiePhysics.Do; + + physicsHandlers[Block.fishbetta] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.water); + physicsHandlers[Block.fishshark] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.water); + physicsHandlers[Block.fishlavashark] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.lava); + physicsHandlers[Block.fishgold] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water); + physicsHandlers[Block.fishsalmon] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water); + physicsHandlers[Block.fishsponge] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water); + + physicsHandlers[Block.water] = SimpleLiquidPhysics.DoWater; + physicsHandlers[Block.activedeathwater] = SimpleLiquidPhysics.DoWater; + physicsHandlers[Block.lava] = SimpleLiquidPhysics.DoLava; + physicsHandlers[Block.activedeathlava] = SimpleLiquidPhysics.DoLava; + physicsHandlers[Block.WaterDown] = ExtLiquidPhysics.DoWaterfall; + physicsHandlers[Block.LavaDown] = ExtLiquidPhysics.DoLavafall; + physicsHandlers[Block.WaterFaucet] = (Level lvl, ref Check C) => + ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.WaterDown); + physicsHandlers[Block.LavaFaucet] = (Level lvl, ref Check C) => + ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.LavaDown); + physicsHandlers[Block.finiteWater] = FinitePhysics.DoWaterOrLava; + physicsHandlers[Block.finiteLava] = FinitePhysics.DoWaterOrLava; + physicsHandlers[Block.finiteFaucet] = FinitePhysics.DoFaucet; + physicsHandlers[Block.magma] = ExtLiquidPhysics.DoMagma; + physicsHandlers[Block.geyser] = ExtLiquidPhysics.DoGeyser; + physicsHandlers[Block.lava_fast] = SimpleLiquidPhysics.DoFastLava; + physicsHandlers[Block.fastdeathlava] = SimpleLiquidPhysics.DoFastLava; + + physicsHandlers[Block.air] = AirPhysics.DoAir; + physicsHandlers[Block.dirt] = OtherPhysics.DoDirt; + physicsHandlers[Block.leaf] = LeafPhysics.DoLeaf; + physicsHandlers[Block.shrub] = OtherPhysics.DoShrub; + physicsHandlers[Block.fire] = FirePhysics.Do; + physicsHandlers[Block.lava_fire] = FirePhysics.Do; + physicsHandlers[Block.sand] = OtherPhysics.DoFalling; + physicsHandlers[Block.gravel] = OtherPhysics.DoFalling; + physicsHandlers[Block.cobblestoneslab] = OtherPhysics.DoStairs; + physicsHandlers[Block.staircasestep] = OtherPhysics.DoStairs; + physicsHandlers[Block.wood_float] = OtherPhysics.DoFloatwood; + + physicsHandlers[Block.sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, false); + physicsHandlers[Block.lava_sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, true); + + //Special blocks that are not saved + physicsHandlers[Block.air_flood] = (Level lvl, ref Check C) => + AirPhysics.DoFlood(lvl, ref C, AirFlood.Full, Block.air_flood); + physicsHandlers[Block.air_flood_layer] = (Level lvl, ref Check C) => + AirPhysics.DoFlood(lvl, ref C, AirFlood.Layer, Block.air_flood_layer); + physicsHandlers[Block.air_flood_down] = (Level lvl, ref Check C) => + AirPhysics.DoFlood(lvl, ref C, AirFlood.Down, Block.air_flood_down); + physicsHandlers[Block.air_flood_up] = (Level lvl, ref Check C) => + AirPhysics.DoFlood(lvl, ref C, AirFlood.Up, Block.air_flood_up); + + physicsHandlers[Block.smalltnt] = TntPhysics.DoSmallTnt; + physicsHandlers[Block.bigtnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 1); + physicsHandlers[Block.nuketnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 4); + physicsHandlers[Block.tntexplosion] = TntPhysics.DoTntExplosion; + physicsHandlers[Block.train] = TrainPhysics.Do; + + for (int i = 0; i < 256; i++) { + //Adv physics updating anything placed next to water or lava + if ((i >= Block.red && i <= Block.redmushroom) || i == Block.wood || + i == Block.trunk || i == Block.bookcase) { + physicsHandlers[i] = OtherPhysics.DoOther; + continue; + } + + if (Block.odoor((byte)i) != Block.Zero) { + physicsHandlers[i] = DoorPhysics.oDoor; + physicsDoorsHandlers[i] = DoorPhysics.oDoor; + } + } + } + } +} diff --git a/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs b/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs index 152ab8794..149edcb1d 100644 --- a/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/DeleteBehaviour.cs @@ -18,7 +18,7 @@ using System; using MCGalaxy.BlockPhysics; -namespace MCGalaxy.BlockBehaviour { +namespace MCGalaxy.Blocks { internal static class DeleteBehaviour { diff --git a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs index 5524282e6..4d4f03b43 100644 --- a/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/PlaceBehaviour.cs @@ -18,7 +18,7 @@ using MCGalaxy.BlockPhysics; using System; -namespace MCGalaxy.BlockBehaviour { +namespace MCGalaxy.Blocks { internal static class PlaceBehaviour { diff --git a/MCGalaxy/Blocks/Behaviour/WalkthroughBehaviour.cs b/MCGalaxy/Blocks/Behaviour/WalkthroughBehaviour.cs index 96ed03472..c40caa259 100644 --- a/MCGalaxy/Blocks/Behaviour/WalkthroughBehaviour.cs +++ b/MCGalaxy/Blocks/Behaviour/WalkthroughBehaviour.cs @@ -21,7 +21,7 @@ using System.Data; using MCGalaxy.BlockPhysics; using MCGalaxy.SQL; -namespace MCGalaxy.BlockBehaviour { +namespace MCGalaxy.Blocks { internal static class WalkthroughBehaviour { internal static bool Door(Player p, byte block, ushort x, ushort y, ushort z) { diff --git a/MCGalaxy/Blocks/Block.CoreProps.cs b/MCGalaxy/Blocks/Block.CoreProps.cs index 05f927b1d..fd9cd243a 100644 --- a/MCGalaxy/Blocks/Block.CoreProps.cs +++ b/MCGalaxy/Blocks/Block.CoreProps.cs @@ -23,12 +23,12 @@ namespace MCGalaxy { public sealed partial class Block { - public static BlockProperties[] Props = new BlockProperties[256]; + public static BlockProps[] Props = new BlockProps[256]; public static Dictionary Aliases = new Dictionary(); static void SetCoreProperties() { for (int i = 0; i < 256; i++) - Props[i] = new BlockProperties((byte)i); + Props[i] = new BlockProps((byte)i); for (int i = 0; i < 256; i++) { // Fallback for unrecognised physics blocks if (i >= CpeCount) Props[i].ConvertId = Block.orange; diff --git a/MCGalaxy/Blocks/Block.Permissions.cs b/MCGalaxy/Blocks/Block.Permissions.cs index ce874dfef..48f0eaac9 100644 --- a/MCGalaxy/Blocks/Block.Permissions.cs +++ b/MCGalaxy/Blocks/Block.Permissions.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; using System.IO; +using MCGalaxy.Blocks; namespace MCGalaxy { @@ -47,7 +48,8 @@ namespace MCGalaxy public static void SetBlocks() { SetCoreProperties(); - SetupCoreHandlers(); + BlockBehaviour.SetupCoreHandlers(); + BlockBehaviour.SetupCorePhysicsHandlers(); InitDefaults(); // Custom permissions set by the user. diff --git a/MCGalaxy/Blocks/Block.cs b/MCGalaxy/Blocks/Block.cs index d4be57856..b49ec18f0 100644 --- a/MCGalaxy/Blocks/Block.cs +++ b/MCGalaxy/Blocks/Block.cs @@ -104,7 +104,7 @@ namespace MCGalaxy return block >= water && block <= lavastill; } - public static bool Mover(byte block) { return walkthroughHandlers[block] != null; } + public static bool Mover(byte block) { return BlockBehaviour.walkthroughHandlers[block] != null; } public static bool FireKill(byte block) { return block != air && Props[block].LavaKills; } diff --git a/MCGalaxy/Blocks/BlockProperties.cs b/MCGalaxy/Blocks/BlockProperties.cs index 8ddc67720..ca15fc014 100644 --- a/MCGalaxy/Blocks/BlockProperties.cs +++ b/MCGalaxy/Blocks/BlockProperties.cs @@ -19,7 +19,7 @@ using System; namespace MCGalaxy.Blocks { - public struct BlockProperties { + public struct BlockProps { /// ID of block these properties are associated with. public byte BlockId; @@ -64,8 +64,8 @@ namespace MCGalaxy.Blocks { /// Whether this block should allow trains to go over them. public bool IsRails; - public BlockProperties(byte block) { - this = default(BlockProperties); + public BlockProps(byte block) { + this = default(BlockProps); BlockId = block; ConvertId = block; SaveConvertId = block; diff --git a/MCGalaxy/Commands/Information/CmdBlocks.cs b/MCGalaxy/Commands/Information/CmdBlocks.cs index 44106a032..4e95a6f74 100644 --- a/MCGalaxy/Commands/Information/CmdBlocks.cs +++ b/MCGalaxy/Commands/Information/CmdBlocks.cs @@ -115,7 +115,7 @@ namespace MCGalaxy.Commands } } static void OutputBlockProps(Player p, byte b) { - BlockProperties props = Block.Props[b]; + BlockProps props = Block.Props[b]; if (Block.LightPass(b, 0, BlockDefinition.GlobalDefs)) Player.Message(p, "Block will allow light through"); diff --git a/MCGalaxy/Commands/World/CmdBlockProperties.cs b/MCGalaxy/Commands/World/CmdBlockProperties.cs new file mode 100644 index 000000000..1170dc1bc --- /dev/null +++ b/MCGalaxy/Commands/World/CmdBlockProperties.cs @@ -0,0 +1,86 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; +using MCGalaxy.Blocks; + +namespace MCGalaxy.Commands.World { + public sealed class CmdBlockProperties : Command { + public override string name { get { return "blockproperties"; } } + public override string shortcut { get { return "blockprops"; } } + public override string type { get { return CommandTypes.World; } } + public override bool museumUsable { get { return true; } } + public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } + + public override void Use(Player p, string message) { + if (message == "") { Help(p); return; } + string[] args = message.SplitSpaces(4); + if (args.Length < 3) { Help(p); return; } + + string scope = args[0].ToLower(); + if (scope != "core" && scope != "global" && scope != "level") { + Player.Message(p, "&cScope must \"core\", \"global\", or \"level\""); return; + } + byte id; + if (!byte.TryParse(args[1], out id)) { + Player.Message(p, "&c\"{0}\" is not a valid block id.", id); return; + } + string prop = args[2].ToLower(); + + // TODO: global and level custom blocks + // TODO: adding core blocks, changing core block names + if (scope != "core") { + Player.Message(p, "Sorry! Custom blocks still a WIP."); return; + } + if (Block.Name(id).CaselessEq("unknown")) { + Player.Message(p, "Sorry! Adding blocks still a WIP."); return; + } + + if (prop == "portal") { + ToggleBool(p, id, "a portal", + (ref BlockProps props) => props.IsPortal = !props.IsPortal, + (BlockProps props) => props.IsPortal); + } else if (prop == "rails") { + ToggleBool(p, id, "train rails", + (ref BlockProps props) => props.IsRails = !props.IsRails, + (BlockProps props) => props.IsRails); + } else if (prop == "mb" || prop == "messageblock") { + ToggleBool(p, id, "a message block", + (ref BlockProps props) => props.IsMessageBlock = !props.IsMessageBlock, + (BlockProps props) => props.IsMessageBlock); + } + } + + delegate void BoolSetter(ref BlockProps props); + static void ToggleBool(Player p, byte id, string name, BoolSetter setter, + Func getter) { + BlockProps props = Block.Props[id]; + setter(ref props); + Block.Props[id] = props; + + Player.Message(p, "Block {0} is {1}: {2}", Block.Name(id), + name, getter(props) ? "&aYes" : "&cNo"); + BlockBehaviour.SetupCoreHandlers(); + } + + public override void Help(Player p) { + Player.Message(p, "%T/blockprops [scope] [id] [property] "); + Player.Message(p, "%HSets various properties for blocks."); + Player.Message(p, "%H[scope] can be \"core\", \"global\", or \"level"); + } + } +} diff --git a/MCGalaxy/Commands/World/CmdMain.cs b/MCGalaxy/Commands/World/CmdMain.cs index f3e60b5b3..8d671005c 100644 --- a/MCGalaxy/Commands/World/CmdMain.cs +++ b/MCGalaxy/Commands/World/CmdMain.cs @@ -52,10 +52,10 @@ namespace MCGalaxy.Commands.World { oldMain.unload = true; Server.mainLevel.unload = false; - Server.level = map; + Server.level = map; - SrvProperties.Save(); - Player.Message(p, "Set main level to \"{0}\"", map); + SrvProperties.Save(); + Player.Message(p, "Set main level to \"{0}\"", map); } } diff --git a/MCGalaxy/Commands/building/CmdMessageBlock.cs b/MCGalaxy/Commands/building/CmdMessageBlock.cs index 0cce95c33..610db6e8c 100644 --- a/MCGalaxy/Commands/building/CmdMessageBlock.cs +++ b/MCGalaxy/Commands/building/CmdMessageBlock.cs @@ -18,7 +18,7 @@ using System; using System.Collections.Generic; using System.Data; -using MCGalaxy.BlockBehaviour; +using MCGalaxy.Blocks; using MCGalaxy.SQL; namespace MCGalaxy.Commands.Building { diff --git a/MCGalaxy/Levels/Level.Physics.cs b/MCGalaxy/Levels/Level.Physics.cs index 66a5a4399..3d3274fb1 100644 --- a/MCGalaxy/Levels/Level.Physics.cs +++ b/MCGalaxy/Levels/Level.Physics.cs @@ -17,6 +17,7 @@ */ using System; using System.Threading; +using MCGalaxy.Blocks; using MCGalaxy.BlockPhysics; using MCGalaxy.Games; @@ -131,10 +132,10 @@ namespace MCGalaxy { lastCheck = ListCheck.Count; const uint mask = PhysicsArgs.TypeMask; - Block.HandlePhysics[] handlers = Block.physicsHandlers; + HandlePhysics[] handlers = BlockBehaviour.physicsHandlers; ExtraInfoHandler extraHandler = ExtraInfoPhysics.DoNormal; if (physics == 5) { - handlers = Block.physicsDoorsHandlers; + handlers = BlockBehaviour.physicsDoorsHandlers; extraHandler = ExtraInfoPhysics.DoDoorsOnly; } @@ -146,7 +147,7 @@ namespace MCGalaxy { PhysicsUpdate(x, y, z, C.data, this); OnPhysicsUpdateEvent.Call(x, y, z, C.data, this); if ((C.data.Raw & mask) == 0 || extraHandler(this, ref C)) { - Block.HandlePhysics handler = handlers[blocks[C.b]]; + HandlePhysics handler = handlers[blocks[C.b]]; if (handler != null) { handler(this, ref C); } else if ((C.data.Raw & mask) == 0 || !C.data.HasWait) { diff --git a/MCGalaxy/Levels/Physics/TrainPhysics.cs b/MCGalaxy/Levels/Physics/TrainPhysics.cs index eda65150c..eb8e90dc1 100644 --- a/MCGalaxy/Levels/Physics/TrainPhysics.cs +++ b/MCGalaxy/Levels/Physics/TrainPhysics.cs @@ -34,14 +34,14 @@ namespace MCGalaxy.BlockPhysics { for (int cz = -dirZ; cz != 2 * dirZ; cz += dirZ) { byte tileBelow = lvl.GetTile((ushort)(x + cx),(ushort)(y + cy - 1), (ushort)(z + cz)); - byte tile = lvl.GetTile((ushort)(x + cx),(ushort)(y + cy), (ushort)(z + cz)); + byte tile = lvl.GetTile((ushort)(x + cx), (ushort)(y + cy), (ushort)(z + cz)); if (Block.Props[tileBelow].IsRails && (tile == Block.air || tile == Block.water)) { lvl.AddUpdate(lvl.PosToInt((ushort)(x + cx), (ushort)(y + cy), (ushort)(z + cz)), Block.train); lvl.AddUpdate(C.b, Block.air); - byte newBlock = tileBelow == Block.red ? Block.obsidian : Block.glass; + byte newBlock = tileBelow == Block.op_air ? Block.glass : Block.obsidian; PhysicsArgs args = default(PhysicsArgs); args.Type1 = PhysicsArgs.Wait; args.Value1 = 5; args.Type2 = PhysicsArgs.Revert; args.Value2 = tileBelow; diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 8df0f7684..2fb122bc4 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -87,7 +87,7 @@ - + @@ -370,6 +370,7 @@ + diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index 064dd4f78..e854a0dfc 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -18,6 +18,7 @@ using System.IO; using System.Text; using System.Text.RegularExpressions; using System.Threading; +using MCGalaxy.Blocks; using MCGalaxy.BlockPhysics; using MCGalaxy.Commands; using MCGalaxy.Games; @@ -133,7 +134,7 @@ namespace MCGalaxy { if (deleteMode) { return ChangeBlock(x, y, z, Block.air, 0); } bool changed = true; - Block.HandleDelete handler = Block.deleteHandlers[old]; + HandleDelete handler = BlockBehaviour.deleteHandlers[old]; if (handler != null) { if (handler(this, old, x, y, z)) return false; } else { @@ -153,7 +154,7 @@ namespace MCGalaxy { return true; } - Block.HandlePlace handler = Block.placeHandlers[block]; + HandlePlace handler = BlockBehaviour.placeHandlers[block]; if (handler != null) { if (handler(this, old, x, y, z)) return false; } else { @@ -367,11 +368,11 @@ namespace MCGalaxy { byte bHead = level.GetTile(x, y, z); byte bFeet = level.GetTile(x, (ushort)(y - 1), z); - Block.HandleWalkthrough handler = Block.walkthroughHandlers[bHead]; + HandleWalkthrough handler = BlockBehaviour.walkthroughHandlers[bHead]; if (handler != null && handler(this, bHead, x, y, z)) { lastWalkthrough = level.PosToInt(x, y, z); return; } - handler = Block.walkthroughHandlers[bFeet]; + handler = BlockBehaviour.walkthroughHandlers[bFeet]; if (handler != null && handler(this, bFeet, x, (ushort)(y - 1), z)) { lastWalkthrough = level.PosToInt(x, (ushort)(y - 1), z); return; }