mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 14:54:12 -04:00
Core: Start working on a command that allows changing the properties of blocks. (Still a major WIP)
This commit is contained in:
parent
4843c64bc8
commit
ae122ffb41
@ -16,35 +16,40 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.BlockBehaviour;
|
||||
using MCGalaxy.BlockPhysics;
|
||||
|
||||
namespace MCGalaxy {
|
||||
namespace MCGalaxy.Blocks {
|
||||
|
||||
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);
|
||||
|
||||
/// <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];
|
||||
|
||||
/// <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];
|
||||
internal static void SetupCoreHandlers() {
|
||||
for (int i = 0; i < 256; i++) {
|
||||
deleteHandlers[i] = null;
|
||||
placeHandlers[i] = null;
|
||||
walkthroughHandlers[i] = null;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
@ -62,12 +67,12 @@ namespace MCGalaxy {
|
||||
walkthroughHandlers[Block.train] = WalkthroughBehaviour.Train;
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
if (Props[i].IsMessageBlock) {
|
||||
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 (Props[i].IsPortal) {
|
||||
} 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) =>
|
||||
@ -76,7 +81,7 @@ namespace MCGalaxy {
|
||||
|
||||
if (Block.Props[i].IsTDoor) {
|
||||
deleteHandlers[i] = DeleteBehaviour.RevertDoor;
|
||||
} else if (Props[i].ODoorId != Block.Zero) {
|
||||
} else if (Block.Props[i].ODoorId != Block.Zero) {
|
||||
deleteHandlers[i] = DeleteBehaviour.ODoor;
|
||||
} else if (Block.Props[i].IsDoor) {
|
||||
deleteHandlers[i] = DeleteBehaviour.Door;
|
||||
@ -86,10 +91,9 @@ namespace MCGalaxy {
|
||||
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() {
|
||||
internal static void SetupCorePhysicsHandlers() {
|
||||
physicsHandlers[Block.birdblack] = BirdPhysics.Do;
|
||||
physicsHandlers[Block.birdwhite] = BirdPhysics.Do;
|
||||
physicsHandlers[Block.birdlava] = BirdPhysics.Do;
|
@ -18,7 +18,7 @@
|
||||
using System;
|
||||
using MCGalaxy.BlockPhysics;
|
||||
|
||||
namespace MCGalaxy.BlockBehaviour {
|
||||
namespace MCGalaxy.Blocks {
|
||||
|
||||
internal static class DeleteBehaviour {
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
using MCGalaxy.BlockPhysics;
|
||||
using System;
|
||||
|
||||
namespace MCGalaxy.BlockBehaviour {
|
||||
namespace MCGalaxy.Blocks {
|
||||
|
||||
internal static class PlaceBehaviour {
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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");
|
||||
|
86
MCGalaxy/Commands/World/CmdBlockProperties.cs
Normal file
86
MCGalaxy/Commands/World/CmdBlockProperties.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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" />
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user