Core: Start working on a command that allows changing the properties of blocks. (Still a major WIP)

This commit is contained in:
UnknownShadow200 2016-10-05 09:32:40 +11:00
parent 4843c64bc8
commit ae122ffb41
16 changed files with 300 additions and 205 deletions

View File

@ -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 {
/// <summary> Returns whether this block handles the player placing a block at the given coordinates. </summary>
/// <remarks>If this returns true, the usual 'dirt/grass below' behaviour and 'adding to the BlockDB' is skipped. </remarks>
public delegate bool HandleDelete(Player p, byte oldBlock, ushort x, ushort y, ushort z);
internal static HandleDelete[] deleteHandlers = new HandleDelete[256];
/// <summary> Returns whether this block handles the player deleting a block at the given coordinates. </summary>
/// <remarks>If this returns true, the usual 'checking dirt/grass below' and 'adding to the BlockDB' is skipped. </remarks>
public delegate bool HandlePlace(Player p, byte oldBlock, ushort x, ushort y, ushort z);
internal static HandlePlace[] placeHandlers = new Block.HandlePlace[256];
/// <summary> Returns whether this block handles the player walking through this block at the given coordinates. </summary>
/// <remarks>If this returns true, the usual 'death check' behaviour is skipped. </remarks>
public delegate bool HandleWalkthrough(Player p, byte block, ushort x, ushort y, ushort z);
internal static HandleWalkthrough[] walkthroughHandlers = new Block.HandleWalkthrough[256];
/// <summary> Called to handle the physics for this particular block. </summary>
/// <remarks>If this returns true, the usual 'death check' behaviour is skipped. </remarks>
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 {
/// <summary> Returns whether this block handles the player placing a block at the given coordinates. </summary>
/// <remarks>If this returns true, the usual 'dirt/grass below' behaviour and 'adding to the BlockDB' is skipped. </remarks>
public delegate bool HandleDelete(Player p, byte oldBlock, ushort x, ushort y, ushort z);
/// <summary> Returns whether this block handles the player deleting a block at the given coordinates. </summary>
/// <remarks>If this returns true, the usual 'checking dirt/grass below' and 'adding to the BlockDB' is skipped. </remarks>
public delegate bool HandlePlace(Player p, byte oldBlock, ushort x, ushort y, ushort z);
/// <summary> Returns whether this block handles the player walking through this block at the given coordinates. </summary>
/// <remarks>If this returns true, the usual 'death check' behaviour is skipped. </remarks>
public delegate bool HandleWalkthrough(Player p, byte block, ushort x, ushort y, ushort z);
/// <summary> Called to handle the physics for this particular block. </summary>
/// <remarks>If this returns true, the usual 'death check' behaviour is skipped. </remarks>
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;
}
}
}
}
}

View File

@ -18,7 +18,7 @@
using System;
using MCGalaxy.BlockPhysics;
namespace MCGalaxy.BlockBehaviour {
namespace MCGalaxy.Blocks {
internal static class DeleteBehaviour {

View File

@ -18,7 +18,7 @@
using MCGalaxy.BlockPhysics;
using System;
namespace MCGalaxy.BlockBehaviour {
namespace MCGalaxy.Blocks {
internal static class PlaceBehaviour {

View File

@ -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) {

View File

@ -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<string, byte> Aliases = new Dictionary<string, byte>();
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;

View File

@ -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.

View File

@ -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; }

View File

@ -19,7 +19,7 @@ using System;
namespace MCGalaxy.Blocks {
public struct BlockProperties {
public struct BlockProps {
/// <summary> ID of block these properties are associated with. </summary>
public byte BlockId;
@ -64,8 +64,8 @@ namespace MCGalaxy.Blocks {
/// <summary> Whether this block should allow trains to go over them. </summary>
public bool IsRails;
public BlockProperties(byte block) {
this = default(BlockProperties);
public BlockProps(byte block) {
this = default(BlockProps);
BlockId = block;
ConvertId = block;
SaveConvertId = block;

View File

@ -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");

View File

@ -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<BlockProps, bool> 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] <value>");
Player.Message(p, "%HSets various properties for blocks.");
Player.Message(p, "%H[scope] can be \"core\", \"global\", or \"level");
}
}
}

View File

@ -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);
}
}

View File

@ -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 {

View File

@ -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) {

View File

@ -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;

View File

@ -87,7 +87,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="API\WhoWas.cs" />
<Compile Include="Blocks\Behaviour\Block.Behaviour.cs" />
<Compile Include="Blocks\Behaviour\BlockBehaviour.cs" />
<Compile Include="Blocks\Behaviour\DeleteBehaviour.cs" />
<Compile Include="Blocks\Behaviour\PlaceBehaviour.cs" />
<Compile Include="Blocks\Behaviour\WalkthroughBehaviour.cs" />
@ -370,6 +370,7 @@
<Compile Include="Commands\Scripting\CmdPLoad.cs" />
<Compile Include="Commands\Scripting\CmdPUnload.cs" />
<Compile Include="Commands\World\CmdBlockDB.cs" />
<Compile Include="Commands\World\CmdBlockProperties.cs" />
<Compile Include="Commands\World\CmdCopyLVL.cs" />
<Compile Include="Commands\World\CmdDeleteLvl.cs" />
<Compile Include="Commands\World\CmdFixGrass.cs" />

View File

@ -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;
}