mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-26 23:02:04 -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
@ -1,180 +1,184 @@
|
|||||||
/*
|
/*
|
||||||
Copyright 2015 MCGalaxy
|
Copyright 2015 MCGalaxy
|
||||||
|
|
||||||
Dual-licensed under the Educational Community License, Version 2.0 and
|
Dual-licensed under the Educational Community License, Version 2.0 and
|
||||||
the GNU General Public License, Version 3 (the "Licenses"); you may
|
the GNU General Public License, Version 3 (the "Licenses"); you may
|
||||||
not use this file except in compliance with the Licenses. You may
|
not use this file except in compliance with the Licenses. You may
|
||||||
obtain a copy of the Licenses at
|
obtain a copy of the Licenses at
|
||||||
|
|
||||||
http://www.opensource.org/licenses/ecl2.php
|
http://www.opensource.org/licenses/ecl2.php
|
||||||
http://www.gnu.org/licenses/gpl-3.0.html
|
http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing,
|
Unless required by applicable law or agreed to in writing,
|
||||||
software distributed under the Licenses are distributed on an "AS IS"
|
software distributed under the Licenses are distributed on an "AS IS"
|
||||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
or implied. See the Licenses for the specific language governing
|
or implied. See the Licenses for the specific language governing
|
||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using MCGalaxy.BlockBehaviour;
|
using MCGalaxy.BlockPhysics;
|
||||||
using MCGalaxy.BlockPhysics;
|
|
||||||
|
namespace MCGalaxy.Blocks {
|
||||||
namespace MCGalaxy {
|
|
||||||
|
/// <summary> Returns whether this block handles the player placing a block at the given coordinates. </summary>
|
||||||
public sealed partial class Block {
|
/// <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>
|
/// <summary> Returns whether this block handles the player deleting a block at the given coordinates. </summary>
|
||||||
public delegate bool HandleDelete(Player p, byte oldBlock, ushort x, ushort y, ushort z);
|
/// <remarks>If this returns true, the usual 'checking dirt/grass below' and 'adding to the BlockDB' is skipped. </remarks>
|
||||||
internal static HandleDelete[] deleteHandlers = new HandleDelete[256];
|
public delegate bool HandlePlace(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>
|
/// <summary> Returns whether this block handles the player walking through this 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>
|
/// <remarks>If this returns true, the usual 'death check' behaviour is skipped. </remarks>
|
||||||
public delegate bool HandlePlace(Player p, byte oldBlock, ushort x, ushort y, ushort z);
|
public delegate bool HandleWalkthrough(Player p, byte block, ushort x, ushort y, ushort z);
|
||||||
internal static HandlePlace[] placeHandlers = new Block.HandlePlace[256];
|
|
||||||
|
/// <summary> Called to handle the physics for this particular block. </summary>
|
||||||
/// <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>
|
||||||
/// <remarks>If this returns true, the usual 'death check' behaviour is skipped. </remarks>
|
public delegate void HandlePhysics(Level lvl, ref Check C);
|
||||||
public delegate bool HandleWalkthrough(Player p, byte block, ushort x, ushort y, ushort z);
|
|
||||||
internal static HandleWalkthrough[] walkthroughHandlers = new Block.HandleWalkthrough[256];
|
public static class BlockBehaviour {
|
||||||
|
internal static HandleDelete[] deleteHandlers = new HandleDelete[256];
|
||||||
/// <summary> Called to handle the physics for this particular block. </summary>
|
internal static HandlePlace[] placeHandlers = new HandlePlace[256];
|
||||||
/// <remarks>If this returns true, the usual 'death check' behaviour is skipped. </remarks>
|
internal static HandleWalkthrough[] walkthroughHandlers = new HandleWalkthrough[256];
|
||||||
public delegate void HandlePhysics(Level lvl, ref Check C);
|
internal static HandlePhysics[] physicsHandlers = new HandlePhysics[256];
|
||||||
internal static HandlePhysics[] physicsHandlers = new Block.HandlePhysics[256];
|
internal static HandlePhysics[] physicsDoorsHandlers = new HandlePhysics[256];
|
||||||
internal static HandlePhysics[] physicsDoorsHandlers = new Block.HandlePhysics[256];
|
|
||||||
|
internal static void SetupCoreHandlers() {
|
||||||
static void SetupCoreHandlers() {
|
for (int i = 0; i < 256; i++) {
|
||||||
deleteHandlers[Block.rocketstart] = DeleteBehaviour.RocketStart;
|
deleteHandlers[i] = null;
|
||||||
deleteHandlers[Block.firework] = DeleteBehaviour.Firework;
|
placeHandlers[i] = null;
|
||||||
deleteHandlers[Block.c4det] = DeleteBehaviour.C4Det;
|
walkthroughHandlers[i] = null;
|
||||||
|
}
|
||||||
placeHandlers[Block.dirt] = PlaceBehaviour.Dirt;
|
|
||||||
placeHandlers[Block.grass] = PlaceBehaviour.Grass;
|
deleteHandlers[Block.rocketstart] = DeleteBehaviour.RocketStart;
|
||||||
placeHandlers[Block.staircasestep] = PlaceBehaviour.Stairs;
|
deleteHandlers[Block.firework] = DeleteBehaviour.Firework;
|
||||||
placeHandlers[Block.c4] = PlaceBehaviour.C4;
|
deleteHandlers[Block.c4det] = DeleteBehaviour.C4Det;
|
||||||
placeHandlers[Block.c4det] = PlaceBehaviour.C4Det;
|
|
||||||
|
placeHandlers[Block.dirt] = PlaceBehaviour.Dirt;
|
||||||
walkthroughHandlers[Block.checkpoint] = WalkthroughBehaviour.Checkpoint;
|
placeHandlers[Block.grass] = PlaceBehaviour.Grass;
|
||||||
walkthroughHandlers[Block.air_switch] = WalkthroughBehaviour.Door;
|
placeHandlers[Block.staircasestep] = PlaceBehaviour.Stairs;
|
||||||
walkthroughHandlers[Block.water_door] = WalkthroughBehaviour.Door;
|
placeHandlers[Block.c4] = PlaceBehaviour.C4;
|
||||||
walkthroughHandlers[Block.lava_door] = WalkthroughBehaviour.Door;
|
placeHandlers[Block.c4det] = PlaceBehaviour.C4Det;
|
||||||
walkthroughHandlers[Block.train] = WalkthroughBehaviour.Train;
|
|
||||||
|
walkthroughHandlers[Block.checkpoint] = WalkthroughBehaviour.Checkpoint;
|
||||||
for (int i = 0; i < 256; i++) {
|
walkthroughHandlers[Block.air_switch] = WalkthroughBehaviour.Door;
|
||||||
if (Props[i].IsMessageBlock) {
|
walkthroughHandlers[Block.water_door] = WalkthroughBehaviour.Door;
|
||||||
walkthroughHandlers[i] = (p, block, x, y, z) =>
|
walkthroughHandlers[Block.lava_door] = WalkthroughBehaviour.Door;
|
||||||
WalkthroughBehaviour.MessageBlock(p, block, x, y, z, true);
|
walkthroughHandlers[Block.train] = WalkthroughBehaviour.Train;
|
||||||
deleteHandlers[i] = (p, block, x, y, z) =>
|
|
||||||
WalkthroughBehaviour.MessageBlock(p, block, x, y, z, false);
|
for (int i = 0; i < 256; i++) {
|
||||||
} else if (Props[i].IsPortal) {
|
if (Block.Props[i].IsMessageBlock) {
|
||||||
walkthroughHandlers[i] = (p, block, x, y, z) =>
|
walkthroughHandlers[i] = (p, block, x, y, z) =>
|
||||||
WalkthroughBehaviour.Portal(p, block, x, y, z, true);
|
WalkthroughBehaviour.MessageBlock(p, block, x, y, z, true);
|
||||||
deleteHandlers[i] = (p, block, x, y, z) =>
|
deleteHandlers[i] = (p, block, x, y, z) =>
|
||||||
WalkthroughBehaviour.Portal(p, block, x, y, z, false);
|
WalkthroughBehaviour.MessageBlock(p, block, x, y, z, false);
|
||||||
}
|
} else if (Block.Props[i].IsPortal) {
|
||||||
|
walkthroughHandlers[i] = (p, block, x, y, z) =>
|
||||||
if (Block.Props[i].IsTDoor) {
|
WalkthroughBehaviour.Portal(p, block, x, y, z, true);
|
||||||
deleteHandlers[i] = DeleteBehaviour.RevertDoor;
|
deleteHandlers[i] = (p, block, x, y, z) =>
|
||||||
} else if (Props[i].ODoorId != Block.Zero) {
|
WalkthroughBehaviour.Portal(p, block, x, y, z, false);
|
||||||
deleteHandlers[i] = DeleteBehaviour.ODoor;
|
}
|
||||||
} else if (Block.Props[i].IsDoor) {
|
|
||||||
deleteHandlers[i] = DeleteBehaviour.Door;
|
if (Block.Props[i].IsTDoor) {
|
||||||
}
|
deleteHandlers[i] = DeleteBehaviour.RevertDoor;
|
||||||
}
|
} else if (Block.Props[i].ODoorId != Block.Zero) {
|
||||||
|
deleteHandlers[i] = DeleteBehaviour.ODoor;
|
||||||
deleteHandlers[Block.door_tree_air] = DeleteBehaviour.RevertDoor;
|
} else if (Block.Props[i].IsDoor) {
|
||||||
deleteHandlers[Block.door_tnt_air] = DeleteBehaviour.RevertDoor;
|
deleteHandlers[i] = DeleteBehaviour.Door;
|
||||||
deleteHandlers[Block.door_green_air] = DeleteBehaviour.RevertDoor;
|
}
|
||||||
SetupCorePhysicsHandlers();
|
}
|
||||||
}
|
|
||||||
|
deleteHandlers[Block.door_tree_air] = DeleteBehaviour.RevertDoor;
|
||||||
static void SetupCorePhysicsHandlers() {
|
deleteHandlers[Block.door_tnt_air] = DeleteBehaviour.RevertDoor;
|
||||||
physicsHandlers[Block.birdblack] = BirdPhysics.Do;
|
deleteHandlers[Block.door_green_air] = DeleteBehaviour.RevertDoor;
|
||||||
physicsHandlers[Block.birdwhite] = BirdPhysics.Do;
|
}
|
||||||
physicsHandlers[Block.birdlava] = BirdPhysics.Do;
|
|
||||||
physicsHandlers[Block.birdwater] = BirdPhysics.Do;
|
internal static void SetupCorePhysicsHandlers() {
|
||||||
physicsHandlers[Block.birdred] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air);
|
physicsHandlers[Block.birdblack] = BirdPhysics.Do;
|
||||||
physicsHandlers[Block.birdblue] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air);
|
physicsHandlers[Block.birdwhite] = BirdPhysics.Do;
|
||||||
physicsHandlers[Block.birdkill] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air);
|
physicsHandlers[Block.birdlava] = BirdPhysics.Do;
|
||||||
|
physicsHandlers[Block.birdwater] = BirdPhysics.Do;
|
||||||
physicsHandlers[Block.snaketail] = SnakePhysics.DoTail;
|
physicsHandlers[Block.birdred] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air);
|
||||||
physicsHandlers[Block.snake] = SnakePhysics.Do;
|
physicsHandlers[Block.birdblue] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air);
|
||||||
physicsHandlers[Block.rockethead] = RocketPhysics.Do;
|
physicsHandlers[Block.birdkill] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.air);
|
||||||
physicsHandlers[Block.firework] = FireworkPhysics.Do;
|
|
||||||
physicsHandlers[Block.zombiebody] = ZombiePhysics.Do;
|
physicsHandlers[Block.snaketail] = SnakePhysics.DoTail;
|
||||||
physicsHandlers[Block.zombiehead] = ZombiePhysics.DoHead;
|
physicsHandlers[Block.snake] = SnakePhysics.Do;
|
||||||
physicsHandlers[Block.creeper] = ZombiePhysics.Do;
|
physicsHandlers[Block.rockethead] = RocketPhysics.Do;
|
||||||
|
physicsHandlers[Block.firework] = FireworkPhysics.Do;
|
||||||
physicsHandlers[Block.fishbetta] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.water);
|
physicsHandlers[Block.zombiebody] = ZombiePhysics.Do;
|
||||||
physicsHandlers[Block.fishshark] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.water);
|
physicsHandlers[Block.zombiehead] = ZombiePhysics.DoHead;
|
||||||
physicsHandlers[Block.fishlavashark] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.lava);
|
physicsHandlers[Block.creeper] = ZombiePhysics.Do;
|
||||||
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.fishbetta] = (Level lvl, ref Check C) => HunterPhysics.DoKiller(lvl, ref C, Block.water);
|
||||||
physicsHandlers[Block.fishsponge] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(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.water] = SimpleLiquidPhysics.DoWater;
|
physicsHandlers[Block.fishgold] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water);
|
||||||
physicsHandlers[Block.activedeathwater] = SimpleLiquidPhysics.DoWater;
|
physicsHandlers[Block.fishsalmon] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water);
|
||||||
physicsHandlers[Block.lava] = SimpleLiquidPhysics.DoLava;
|
physicsHandlers[Block.fishsponge] = (Level lvl, ref Check C) => HunterPhysics.DoFlee(lvl, ref C, Block.water);
|
||||||
physicsHandlers[Block.activedeathlava] = SimpleLiquidPhysics.DoLava;
|
|
||||||
physicsHandlers[Block.WaterDown] = ExtLiquidPhysics.DoWaterfall;
|
physicsHandlers[Block.water] = SimpleLiquidPhysics.DoWater;
|
||||||
physicsHandlers[Block.LavaDown] = ExtLiquidPhysics.DoLavafall;
|
physicsHandlers[Block.activedeathwater] = SimpleLiquidPhysics.DoWater;
|
||||||
physicsHandlers[Block.WaterFaucet] = (Level lvl, ref Check C) =>
|
physicsHandlers[Block.lava] = SimpleLiquidPhysics.DoLava;
|
||||||
ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.WaterDown);
|
physicsHandlers[Block.activedeathlava] = SimpleLiquidPhysics.DoLava;
|
||||||
physicsHandlers[Block.LavaFaucet] = (Level lvl, ref Check C) =>
|
physicsHandlers[Block.WaterDown] = ExtLiquidPhysics.DoWaterfall;
|
||||||
ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.LavaDown);
|
physicsHandlers[Block.LavaDown] = ExtLiquidPhysics.DoLavafall;
|
||||||
physicsHandlers[Block.finiteWater] = FinitePhysics.DoWaterOrLava;
|
physicsHandlers[Block.WaterFaucet] = (Level lvl, ref Check C) =>
|
||||||
physicsHandlers[Block.finiteLava] = FinitePhysics.DoWaterOrLava;
|
ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.WaterDown);
|
||||||
physicsHandlers[Block.finiteFaucet] = FinitePhysics.DoFaucet;
|
physicsHandlers[Block.LavaFaucet] = (Level lvl, ref Check C) =>
|
||||||
physicsHandlers[Block.magma] = ExtLiquidPhysics.DoMagma;
|
ExtLiquidPhysics.DoFaucet(lvl, ref C, Block.LavaDown);
|
||||||
physicsHandlers[Block.geyser] = ExtLiquidPhysics.DoGeyser;
|
physicsHandlers[Block.finiteWater] = FinitePhysics.DoWaterOrLava;
|
||||||
physicsHandlers[Block.lava_fast] = SimpleLiquidPhysics.DoFastLava;
|
physicsHandlers[Block.finiteLava] = FinitePhysics.DoWaterOrLava;
|
||||||
physicsHandlers[Block.fastdeathlava] = SimpleLiquidPhysics.DoFastLava;
|
physicsHandlers[Block.finiteFaucet] = FinitePhysics.DoFaucet;
|
||||||
|
physicsHandlers[Block.magma] = ExtLiquidPhysics.DoMagma;
|
||||||
physicsHandlers[Block.air] = AirPhysics.DoAir;
|
physicsHandlers[Block.geyser] = ExtLiquidPhysics.DoGeyser;
|
||||||
physicsHandlers[Block.dirt] = OtherPhysics.DoDirt;
|
physicsHandlers[Block.lava_fast] = SimpleLiquidPhysics.DoFastLava;
|
||||||
physicsHandlers[Block.leaf] = LeafPhysics.DoLeaf;
|
physicsHandlers[Block.fastdeathlava] = SimpleLiquidPhysics.DoFastLava;
|
||||||
physicsHandlers[Block.shrub] = OtherPhysics.DoShrub;
|
|
||||||
physicsHandlers[Block.fire] = FirePhysics.Do;
|
physicsHandlers[Block.air] = AirPhysics.DoAir;
|
||||||
physicsHandlers[Block.lava_fire] = FirePhysics.Do;
|
physicsHandlers[Block.dirt] = OtherPhysics.DoDirt;
|
||||||
physicsHandlers[Block.sand] = OtherPhysics.DoFalling;
|
physicsHandlers[Block.leaf] = LeafPhysics.DoLeaf;
|
||||||
physicsHandlers[Block.gravel] = OtherPhysics.DoFalling;
|
physicsHandlers[Block.shrub] = OtherPhysics.DoShrub;
|
||||||
physicsHandlers[Block.cobblestoneslab] = OtherPhysics.DoStairs;
|
physicsHandlers[Block.fire] = FirePhysics.Do;
|
||||||
physicsHandlers[Block.staircasestep] = OtherPhysics.DoStairs;
|
physicsHandlers[Block.lava_fire] = FirePhysics.Do;
|
||||||
physicsHandlers[Block.wood_float] = OtherPhysics.DoFloatwood;
|
physicsHandlers[Block.sand] = OtherPhysics.DoFalling;
|
||||||
|
physicsHandlers[Block.gravel] = OtherPhysics.DoFalling;
|
||||||
physicsHandlers[Block.sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, false);
|
physicsHandlers[Block.cobblestoneslab] = OtherPhysics.DoStairs;
|
||||||
physicsHandlers[Block.lava_sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, true);
|
physicsHandlers[Block.staircasestep] = OtherPhysics.DoStairs;
|
||||||
|
physicsHandlers[Block.wood_float] = OtherPhysics.DoFloatwood;
|
||||||
//Special blocks that are not saved
|
|
||||||
physicsHandlers[Block.air_flood] = (Level lvl, ref Check C) =>
|
physicsHandlers[Block.sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, false);
|
||||||
AirPhysics.DoFlood(lvl, ref C, AirFlood.Full, Block.air_flood);
|
physicsHandlers[Block.lava_sponge] = (Level lvl, ref Check C) => OtherPhysics.DoSponge(lvl, ref C, true);
|
||||||
physicsHandlers[Block.air_flood_layer] = (Level lvl, ref Check C) =>
|
|
||||||
AirPhysics.DoFlood(lvl, ref C, AirFlood.Layer, Block.air_flood_layer);
|
//Special blocks that are not saved
|
||||||
physicsHandlers[Block.air_flood_down] = (Level lvl, ref Check C) =>
|
physicsHandlers[Block.air_flood] = (Level lvl, ref Check C) =>
|
||||||
AirPhysics.DoFlood(lvl, ref C, AirFlood.Down, Block.air_flood_down);
|
AirPhysics.DoFlood(lvl, ref C, AirFlood.Full, Block.air_flood);
|
||||||
physicsHandlers[Block.air_flood_up] = (Level lvl, ref Check C) =>
|
physicsHandlers[Block.air_flood_layer] = (Level lvl, ref Check C) =>
|
||||||
AirPhysics.DoFlood(lvl, ref C, AirFlood.Up, Block.air_flood_up);
|
AirPhysics.DoFlood(lvl, ref C, AirFlood.Layer, Block.air_flood_layer);
|
||||||
|
physicsHandlers[Block.air_flood_down] = (Level lvl, ref Check C) =>
|
||||||
physicsHandlers[Block.smalltnt] = TntPhysics.DoSmallTnt;
|
AirPhysics.DoFlood(lvl, ref C, AirFlood.Down, Block.air_flood_down);
|
||||||
physicsHandlers[Block.bigtnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 1);
|
physicsHandlers[Block.air_flood_up] = (Level lvl, ref Check C) =>
|
||||||
physicsHandlers[Block.nuketnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 4);
|
AirPhysics.DoFlood(lvl, ref C, AirFlood.Up, Block.air_flood_up);
|
||||||
physicsHandlers[Block.tntexplosion] = TntPhysics.DoTntExplosion;
|
|
||||||
physicsHandlers[Block.train] = TrainPhysics.Do;
|
physicsHandlers[Block.smalltnt] = TntPhysics.DoSmallTnt;
|
||||||
|
physicsHandlers[Block.bigtnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 1);
|
||||||
for (int i = 0; i < 256; i++) {
|
physicsHandlers[Block.nuketnt] = (Level lvl, ref Check C) => TntPhysics.DoLargeTnt(lvl, ref C, 4);
|
||||||
//Adv physics updating anything placed next to water or lava
|
physicsHandlers[Block.tntexplosion] = TntPhysics.DoTntExplosion;
|
||||||
if ((i >= Block.red && i <= Block.redmushroom) || i == Block.wood ||
|
physicsHandlers[Block.train] = TrainPhysics.Do;
|
||||||
i == Block.trunk || i == Block.bookcase) {
|
|
||||||
physicsHandlers[i] = OtherPhysics.DoOther;
|
for (int i = 0; i < 256; i++) {
|
||||||
continue;
|
//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) {
|
||||||
if (Block.odoor((byte)i) != Block.Zero) {
|
physicsHandlers[i] = OtherPhysics.DoOther;
|
||||||
physicsHandlers[i] = DoorPhysics.oDoor;
|
continue;
|
||||||
physicsDoorsHandlers[i] = DoorPhysics.oDoor;
|
}
|
||||||
}
|
|
||||||
}
|
if (Block.odoor((byte)i) != Block.Zero) {
|
||||||
}
|
physicsHandlers[i] = DoorPhysics.oDoor;
|
||||||
}
|
physicsDoorsHandlers[i] = DoorPhysics.oDoor;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using MCGalaxy.BlockPhysics;
|
using MCGalaxy.BlockPhysics;
|
||||||
|
|
||||||
namespace MCGalaxy.BlockBehaviour {
|
namespace MCGalaxy.Blocks {
|
||||||
|
|
||||||
internal static class DeleteBehaviour {
|
internal static class DeleteBehaviour {
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
using MCGalaxy.BlockPhysics;
|
using MCGalaxy.BlockPhysics;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MCGalaxy.BlockBehaviour {
|
namespace MCGalaxy.Blocks {
|
||||||
|
|
||||||
internal static class PlaceBehaviour {
|
internal static class PlaceBehaviour {
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ using System.Data;
|
|||||||
using MCGalaxy.BlockPhysics;
|
using MCGalaxy.BlockPhysics;
|
||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
|
|
||||||
namespace MCGalaxy.BlockBehaviour {
|
namespace MCGalaxy.Blocks {
|
||||||
internal static class WalkthroughBehaviour {
|
internal static class WalkthroughBehaviour {
|
||||||
|
|
||||||
internal static bool Door(Player p, byte block, ushort x, ushort y, ushort z) {
|
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 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>();
|
public static Dictionary<string, byte> Aliases = new Dictionary<string, byte>();
|
||||||
|
|
||||||
static void SetCoreProperties() {
|
static void SetCoreProperties() {
|
||||||
for (int i = 0; i < 256; i++)
|
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++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
// Fallback for unrecognised physics blocks
|
// Fallback for unrecognised physics blocks
|
||||||
if (i >= CpeCount) Props[i].ConvertId = Block.orange;
|
if (i >= CpeCount) Props[i].ConvertId = Block.orange;
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using MCGalaxy.Blocks;
|
||||||
|
|
||||||
namespace MCGalaxy
|
namespace MCGalaxy
|
||||||
{
|
{
|
||||||
@ -47,7 +48,8 @@ namespace MCGalaxy
|
|||||||
|
|
||||||
public static void SetBlocks() {
|
public static void SetBlocks() {
|
||||||
SetCoreProperties();
|
SetCoreProperties();
|
||||||
SetupCoreHandlers();
|
BlockBehaviour.SetupCoreHandlers();
|
||||||
|
BlockBehaviour.SetupCorePhysicsHandlers();
|
||||||
InitDefaults();
|
InitDefaults();
|
||||||
|
|
||||||
// Custom permissions set by the user.
|
// Custom permissions set by the user.
|
||||||
|
@ -104,7 +104,7 @@ namespace MCGalaxy
|
|||||||
return block >= water && block <= lavastill;
|
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; }
|
public static bool FireKill(byte block) { return block != air && Props[block].LavaKills; }
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ using System;
|
|||||||
|
|
||||||
namespace MCGalaxy.Blocks {
|
namespace MCGalaxy.Blocks {
|
||||||
|
|
||||||
public struct BlockProperties {
|
public struct BlockProps {
|
||||||
|
|
||||||
/// <summary> ID of block these properties are associated with. </summary>
|
/// <summary> ID of block these properties are associated with. </summary>
|
||||||
public byte BlockId;
|
public byte BlockId;
|
||||||
@ -64,8 +64,8 @@ namespace MCGalaxy.Blocks {
|
|||||||
/// <summary> Whether this block should allow trains to go over them. </summary>
|
/// <summary> Whether this block should allow trains to go over them. </summary>
|
||||||
public bool IsRails;
|
public bool IsRails;
|
||||||
|
|
||||||
public BlockProperties(byte block) {
|
public BlockProps(byte block) {
|
||||||
this = default(BlockProperties);
|
this = default(BlockProps);
|
||||||
BlockId = block;
|
BlockId = block;
|
||||||
ConvertId = block;
|
ConvertId = block;
|
||||||
SaveConvertId = block;
|
SaveConvertId = block;
|
||||||
|
@ -115,7 +115,7 @@ namespace MCGalaxy.Commands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void OutputBlockProps(Player p, byte b) {
|
static void OutputBlockProps(Player p, byte b) {
|
||||||
BlockProperties props = Block.Props[b];
|
BlockProps props = Block.Props[b];
|
||||||
|
|
||||||
if (Block.LightPass(b, 0, BlockDefinition.GlobalDefs))
|
if (Block.LightPass(b, 0, BlockDefinition.GlobalDefs))
|
||||||
Player.Message(p, "Block will allow light through");
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -52,10 +52,10 @@ namespace MCGalaxy.Commands.World {
|
|||||||
|
|
||||||
oldMain.unload = true;
|
oldMain.unload = true;
|
||||||
Server.mainLevel.unload = false;
|
Server.mainLevel.unload = false;
|
||||||
Server.level = map;
|
Server.level = map;
|
||||||
|
|
||||||
SrvProperties.Save();
|
SrvProperties.Save();
|
||||||
Player.Message(p, "Set main level to \"{0}\"", map);
|
Player.Message(p, "Set main level to \"{0}\"", map);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using MCGalaxy.BlockBehaviour;
|
using MCGalaxy.Blocks;
|
||||||
using MCGalaxy.SQL;
|
using MCGalaxy.SQL;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.Building {
|
namespace MCGalaxy.Commands.Building {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using MCGalaxy.Blocks;
|
||||||
using MCGalaxy.BlockPhysics;
|
using MCGalaxy.BlockPhysics;
|
||||||
using MCGalaxy.Games;
|
using MCGalaxy.Games;
|
||||||
|
|
||||||
@ -131,10 +132,10 @@ namespace MCGalaxy {
|
|||||||
lastCheck = ListCheck.Count;
|
lastCheck = ListCheck.Count;
|
||||||
const uint mask = PhysicsArgs.TypeMask;
|
const uint mask = PhysicsArgs.TypeMask;
|
||||||
|
|
||||||
Block.HandlePhysics[] handlers = Block.physicsHandlers;
|
HandlePhysics[] handlers = BlockBehaviour.physicsHandlers;
|
||||||
ExtraInfoHandler extraHandler = ExtraInfoPhysics.DoNormal;
|
ExtraInfoHandler extraHandler = ExtraInfoPhysics.DoNormal;
|
||||||
if (physics == 5) {
|
if (physics == 5) {
|
||||||
handlers = Block.physicsDoorsHandlers;
|
handlers = BlockBehaviour.physicsDoorsHandlers;
|
||||||
extraHandler = ExtraInfoPhysics.DoDoorsOnly;
|
extraHandler = ExtraInfoPhysics.DoDoorsOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +147,7 @@ namespace MCGalaxy {
|
|||||||
PhysicsUpdate(x, y, z, C.data, this);
|
PhysicsUpdate(x, y, z, C.data, this);
|
||||||
OnPhysicsUpdateEvent.Call(x, y, z, C.data, this);
|
OnPhysicsUpdateEvent.Call(x, y, z, C.data, this);
|
||||||
if ((C.data.Raw & mask) == 0 || extraHandler(this, ref C)) {
|
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) {
|
if (handler != null) {
|
||||||
handler(this, ref C);
|
handler(this, ref C);
|
||||||
} else if ((C.data.Raw & mask) == 0 || !C.data.HasWait) {
|
} 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)
|
for (int cz = -dirZ; cz != 2 * dirZ; cz += dirZ)
|
||||||
{
|
{
|
||||||
byte tileBelow = lvl.GetTile((ushort)(x + cx),(ushort)(y + cy - 1), (ushort)(z + cz));
|
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)) {
|
if (Block.Props[tileBelow].IsRails && (tile == Block.air || tile == Block.water)) {
|
||||||
lvl.AddUpdate(lvl.PosToInt((ushort)(x + cx),
|
lvl.AddUpdate(lvl.PosToInt((ushort)(x + cx),
|
||||||
(ushort)(y + cy), (ushort)(z + cz)), Block.train);
|
(ushort)(y + cy), (ushort)(z + cz)), Block.train);
|
||||||
lvl.AddUpdate(C.b, Block.air);
|
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);
|
PhysicsArgs args = default(PhysicsArgs);
|
||||||
args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
|
args.Type1 = PhysicsArgs.Wait; args.Value1 = 5;
|
||||||
args.Type2 = PhysicsArgs.Revert; args.Value2 = tileBelow;
|
args.Type2 = PhysicsArgs.Revert; args.Value2 = tileBelow;
|
||||||
|
@ -87,7 +87,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="API\WhoWas.cs" />
|
<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\DeleteBehaviour.cs" />
|
||||||
<Compile Include="Blocks\Behaviour\PlaceBehaviour.cs" />
|
<Compile Include="Blocks\Behaviour\PlaceBehaviour.cs" />
|
||||||
<Compile Include="Blocks\Behaviour\WalkthroughBehaviour.cs" />
|
<Compile Include="Blocks\Behaviour\WalkthroughBehaviour.cs" />
|
||||||
@ -370,6 +370,7 @@
|
|||||||
<Compile Include="Commands\Scripting\CmdPLoad.cs" />
|
<Compile Include="Commands\Scripting\CmdPLoad.cs" />
|
||||||
<Compile Include="Commands\Scripting\CmdPUnload.cs" />
|
<Compile Include="Commands\Scripting\CmdPUnload.cs" />
|
||||||
<Compile Include="Commands\World\CmdBlockDB.cs" />
|
<Compile Include="Commands\World\CmdBlockDB.cs" />
|
||||||
|
<Compile Include="Commands\World\CmdBlockProperties.cs" />
|
||||||
<Compile Include="Commands\World\CmdCopyLVL.cs" />
|
<Compile Include="Commands\World\CmdCopyLVL.cs" />
|
||||||
<Compile Include="Commands\World\CmdDeleteLvl.cs" />
|
<Compile Include="Commands\World\CmdDeleteLvl.cs" />
|
||||||
<Compile Include="Commands\World\CmdFixGrass.cs" />
|
<Compile Include="Commands\World\CmdFixGrass.cs" />
|
||||||
|
@ -18,6 +18,7 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using MCGalaxy.Blocks;
|
||||||
using MCGalaxy.BlockPhysics;
|
using MCGalaxy.BlockPhysics;
|
||||||
using MCGalaxy.Commands;
|
using MCGalaxy.Commands;
|
||||||
using MCGalaxy.Games;
|
using MCGalaxy.Games;
|
||||||
@ -133,7 +134,7 @@ namespace MCGalaxy {
|
|||||||
if (deleteMode) { return ChangeBlock(x, y, z, Block.air, 0); }
|
if (deleteMode) { return ChangeBlock(x, y, z, Block.air, 0); }
|
||||||
bool changed = true;
|
bool changed = true;
|
||||||
|
|
||||||
Block.HandleDelete handler = Block.deleteHandlers[old];
|
HandleDelete handler = BlockBehaviour.deleteHandlers[old];
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
if (handler(this, old, x, y, z)) return false;
|
if (handler(this, old, x, y, z)) return false;
|
||||||
} else {
|
} else {
|
||||||
@ -153,7 +154,7 @@ namespace MCGalaxy {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Block.HandlePlace handler = Block.placeHandlers[block];
|
HandlePlace handler = BlockBehaviour.placeHandlers[block];
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
if (handler(this, old, x, y, z)) return false;
|
if (handler(this, old, x, y, z)) return false;
|
||||||
} else {
|
} else {
|
||||||
@ -367,11 +368,11 @@ namespace MCGalaxy {
|
|||||||
byte bHead = level.GetTile(x, y, z);
|
byte bHead = level.GetTile(x, y, z);
|
||||||
byte bFeet = level.GetTile(x, (ushort)(y - 1), 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)) {
|
if (handler != null && handler(this, bHead, x, y, z)) {
|
||||||
lastWalkthrough = level.PosToInt(x, y, z); return;
|
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)) {
|
if (handler != null && handler(this, bFeet, x, (ushort)(y - 1), z)) {
|
||||||
lastWalkthrough = level.PosToInt(x, (ushort)(y - 1), z); return;
|
lastWalkthrough = level.PosToInt(x, (ushort)(y - 1), z); return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user