mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 14:17:29 -04:00
And so it begins.. begin modularising out physics.
This commit is contained in:
parent
67225c5e6e
commit
2ee1158f43
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
|
||||
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
|
||||
@ -17,6 +17,7 @@
|
||||
*/
|
||||
using System;
|
||||
using MCGalaxy.BlockBehaviour;
|
||||
using MCGalaxy.BlockPhysics;
|
||||
|
||||
namespace MCGalaxy {
|
||||
|
||||
@ -37,6 +38,11 @@ namespace MCGalaxy {
|
||||
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, Check C);
|
||||
internal static HandlePhysics[] physicsHandlers = new Block.HandlePhysics[256];
|
||||
|
||||
static void SetupCoreHandlers() {
|
||||
deleteHandlers[Block.rocketstart] = DeleteBehaviour.RocketStart;
|
||||
deleteHandlers[Block.firework] = DeleteBehaviour.Firework;
|
||||
@ -64,6 +70,34 @@ namespace MCGalaxy {
|
||||
deleteHandlers[i] = DeleteBehaviour.Door;
|
||||
}
|
||||
}
|
||||
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] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.air);
|
||||
physicsHandlers[Block.birdblue] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.air);
|
||||
physicsHandlers[Block.birdkill] = (lvl, C) => HunterPhysics.DoKiller(lvl, 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.c4] = C4Physics.DoC4;
|
||||
physicsHandlers[Block.c4det] = C4Physics.DoC4Det;
|
||||
|
||||
physicsHandlers[Block.fishbetta] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.water);
|
||||
physicsHandlers[Block.fishshark] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.water);
|
||||
physicsHandlers[Block.fishlavashark] = (lvl, C) => HunterPhysics.DoKiller(lvl, C, Block.lava);
|
||||
physicsHandlers[Block.fishgold] = (lvl, C) => HunterPhysics.DoFlee(lvl, C, Block.water);
|
||||
physicsHandlers[Block.fishsalmon] = (lvl, C) => HunterPhysics.DoFlee(lvl, C, Block.water);
|
||||
physicsHandlers[Block.fishsponge] = (lvl, C) => HunterPhysics.DoFlee(lvl, C, Block.water);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ namespace MCGalaxy {
|
||||
if (PhysicsUpdate != null)
|
||||
PhysicsUpdate(x, y, z, C.time, info, this);
|
||||
if (info == "" || ExtraInfoPhysics.DoDoorsOnly(this, C, null))
|
||||
DoorPhysics.Do(this, C);
|
||||
DoorPhysics.Do(this, C, true);
|
||||
} catch {
|
||||
listCheckExists.Set(x, y, z, false);
|
||||
ListCheck.Remove(C);
|
||||
@ -284,42 +284,8 @@ namespace MCGalaxy {
|
||||
ExtLiquidPhysics.DoMagma(this, C); break;
|
||||
case Block.geyser:
|
||||
ExtLiquidPhysics.DoGeyser(this, C); break;
|
||||
case Block.birdblack:
|
||||
case Block.birdwhite:
|
||||
case Block.birdlava:
|
||||
case Block.birdwater:
|
||||
BirdPhysics.Do(this, C); break;
|
||||
case Block.snaketail:
|
||||
SnakePhysics.DoTail(this, C); break;
|
||||
case Block.snake:
|
||||
SnakePhysics.Do(this, C); break;
|
||||
case Block.birdred:
|
||||
case Block.birdblue:
|
||||
case Block.birdkill:
|
||||
HunterPhysics.DoKiller(this, C, Block.air); break;
|
||||
case Block.fishbetta:
|
||||
case Block.fishshark:
|
||||
HunterPhysics.DoKiller(this, C, Block.water); break;
|
||||
case Block.fishgold:
|
||||
case Block.fishsalmon:
|
||||
case Block.fishsponge:
|
||||
HunterPhysics.DoFlee(this, C, Block.water); break;
|
||||
case Block.fishlavashark:
|
||||
HunterPhysics.DoKiller(this, C, Block.lava); break;
|
||||
case Block.rockethead:
|
||||
RocketPhysics.Do(this, C); break;
|
||||
case Block.firework:
|
||||
FireworkPhysics.Do(this, C); break;
|
||||
case Block.zombiehead:
|
||||
ZombiePhysics.DoHead(this, C); break;
|
||||
case Block.creeper:
|
||||
ZombiePhysics.Do(this, C); break;
|
||||
case Block.c4:
|
||||
C4Physics.DoC4(this, C); break;
|
||||
case Block.c4det:
|
||||
C4Physics.DoC4Det(this, C); break;
|
||||
default:
|
||||
DoorPhysics.Do(this, C); break;
|
||||
DoorPhysics.Do(this, C, false); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ namespace MCGalaxy.BlockPhysics {
|
||||
|
||||
public static class DoorPhysics {
|
||||
|
||||
public static void Do(Level lvl, Check C) {
|
||||
public static void Do(Level lvl, Check C, bool doorsOnly) {
|
||||
switch (lvl.blocks[C.b]) {
|
||||
|
||||
//Change any door blocks nearby into door_air
|
||||
@ -84,6 +84,8 @@ namespace MCGalaxy.BlockPhysics {
|
||||
odoorPhysics(lvl, C);
|
||||
break;
|
||||
default:
|
||||
Block.HandlePhysics handler = Block.physicsHandlers[lvl.blocks[C.b]];
|
||||
if (!doorsOnly && handler != null) { handler(lvl, C); return; }
|
||||
//non special blocks are then ignored, maybe it would be better to avoid getting here and cutting down the list
|
||||
if (!(C.data is string) || !((string)C.data).Contains("wait"))
|
||||
C.time = 255;
|
||||
|
Loading…
x
Reference in New Issue
Block a user