mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-23 04:34:58 -04:00
Initial work on survival test
This commit is contained in:
parent
98d435b110
commit
cc54c6bc80
@ -73,6 +73,7 @@ namespace ClassicalSharp {
|
||||
public const byte Pillar = 63;
|
||||
public const byte Crate = 64;
|
||||
public const byte StoneBrick = 65;
|
||||
public const byte Invalid = 0xFF;
|
||||
|
||||
public const string Names = "Air Stone Grass Dirt Cobblestone Wood Sapling Bedrock Water StillWater Lava" +
|
||||
" StillLava Sand Gravel GoldOre IronOre CoalOre Log Leaves Sponge Glass Red Orange Yellow Lime Green" +
|
||||
|
@ -57,7 +57,7 @@ namespace ClassicalSharp.Blocks {
|
||||
|
||||
|
||||
public static byte Draw(byte b) {
|
||||
if (b == Block.Air) return DrawType.Gas;
|
||||
if (b == Block.Air || b == Block.Invalid) return DrawType.Gas;
|
||||
if (b == Block.Leaves) return DrawType.TransparentThick;
|
||||
|
||||
if (b == Block.Ice || b == Block.Water || b == Block.StillWater)
|
||||
|
@ -204,6 +204,9 @@
|
||||
<Compile Include="MeshBuilder\NormalBuilder.cs" />
|
||||
<Compile Include="MeshBuilder\AdvLightingBuilder.cs" />
|
||||
<Compile Include="MeshBuilder\TileDrawer.cs" />
|
||||
<Compile Include="Mode\Creative.cs" />
|
||||
<Compile Include="Mode\IGameMode.cs" />
|
||||
<Compile Include="Mode\Survival.cs" />
|
||||
<Compile Include="Network\CPESupport.cs" />
|
||||
<Compile Include="Network\Protocols\BlockDefs.cs" />
|
||||
<Compile Include="Network\Protocols\Classic.cs" />
|
||||
@ -346,6 +349,7 @@
|
||||
<Folder Include="Math\Physics" />
|
||||
<Folder Include="MeshBuilder" />
|
||||
<Folder Include="Network\Protocols" />
|
||||
<Folder Include="Mode" />
|
||||
<Folder Include="Platform" />
|
||||
<Folder Include="Particles" />
|
||||
<Folder Include="GraphicsAPI" />
|
||||
|
@ -64,17 +64,17 @@ namespace ClassicalSharp.Commands {
|
||||
if (Utils.CaselessEquals(args[1], "yes")) { persist = true; return true; }
|
||||
|
||||
int temp = -1;
|
||||
byte blockID = 0;
|
||||
byte block = 0;
|
||||
if ((temp = game.BlockInfo.FindID(args[1])) != -1) {
|
||||
blockID = (byte)temp;
|
||||
} else if (!byte.TryParse(args[1], out blockID)) {
|
||||
block = (byte)temp;
|
||||
} else if (!byte.TryParse(args[1], out block)) {
|
||||
game.Chat.Add("&eCuboid: &c\"" + args[1] + "\" is not a valid block name or id."); return false;
|
||||
}
|
||||
|
||||
if (blockID >= Block.CpeCount && game.BlockInfo.Name[blockID] == "Invalid") {
|
||||
if (block >= Block.CpeCount && game.BlockInfo.Name[block] == "Invalid") {
|
||||
game.Chat.Add("&eCuboid: &cThere is no block with id \"" + args[1] + "\"."); return false;
|
||||
}
|
||||
block = blockID;
|
||||
block = block;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -102,14 +102,15 @@ namespace ClassicalSharp.Commands {
|
||||
Vector3I min = Vector3I.Min(mark1, mark2);
|
||||
Vector3I max = Vector3I.Max(mark1, mark2);
|
||||
if (!game.World.IsValidPos(min) || !game.World.IsValidPos(max)) return;
|
||||
byte id = block;
|
||||
|
||||
if (id == 0xFF) id = (byte)game.Inventory.HeldBlock;
|
||||
byte toPlace = block;
|
||||
if (toPlace == Block.Invalid) toPlace = game.Inventory.HeldBlock;
|
||||
|
||||
for (int y = min.Y; y <= max.Y; y++)
|
||||
for (int z = min.Z; z <= max.Z; z++)
|
||||
for (int x = min.X; x <= max.X; x++)
|
||||
{
|
||||
game.UpdateBlock(x, y, z, id);
|
||||
game.UpdateBlock(x, y, z, toPlace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ using ClassicalSharp.Entities;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using ClassicalSharp.Gui.Screens;
|
||||
using ClassicalSharp.Map;
|
||||
using ClassicalSharp.Mode;
|
||||
using ClassicalSharp.Model;
|
||||
using ClassicalSharp.Network;
|
||||
using ClassicalSharp.Particles;
|
||||
@ -44,8 +45,14 @@ namespace ClassicalSharp {
|
||||
ETags.Load();
|
||||
LastModified.Load();
|
||||
|
||||
if (Options.GetBool(OptionsKey.SurvivalMode, false)) {
|
||||
Mode = AddComponent(new SurvivalGameMode());
|
||||
} else {
|
||||
Mode = AddComponent(new CreativeGameMode());
|
||||
}
|
||||
|
||||
Input = new InputHandler(this);
|
||||
defaultIb = Graphics.MakeDefaultIb();
|
||||
defaultIb = Graphics.MakeDefaultIb();
|
||||
ParticleManager = AddComponent(new ParticleManager());
|
||||
TabList = AddComponent(new TabList());
|
||||
LoadOptions();
|
||||
|
@ -11,6 +11,7 @@ using ClassicalSharp.Events;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using ClassicalSharp.Gui;
|
||||
using ClassicalSharp.Map;
|
||||
using ClassicalSharp.Mode;
|
||||
using ClassicalSharp.Model;
|
||||
using ClassicalSharp.Network;
|
||||
using ClassicalSharp.Particles;
|
||||
@ -52,6 +53,9 @@ namespace ClassicalSharp {
|
||||
/// <summary> Abstracts the underlying 3D graphics rendering API. </summary>
|
||||
public IGraphicsApi Graphics;
|
||||
|
||||
/// <summary> Handles game mode specific functionality. </summary>
|
||||
public IGameMode Mode;
|
||||
|
||||
/// <summary> Contains the block data and metadata/properties for the player's current world. </summary>
|
||||
public World World;
|
||||
|
||||
|
@ -243,9 +243,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
} else if (key == Keys[KeyBind.PauseOrExit] && !game.World.IsNotLoaded) {
|
||||
game.Gui.SetNewScreen(new PauseScreen(game));
|
||||
} else if (key == Keys[KeyBind.Inventory]) {
|
||||
game.Gui.SetNewScreen(new InventoryScreen(game));
|
||||
} else {
|
||||
} else if (!game.Mode.HandlesKeyDown(key)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -21,16 +21,12 @@ namespace ClassicalSharp {
|
||||
Game game;
|
||||
public bool CanChangeHeldBlock = true;
|
||||
|
||||
public byte[] Hotbar = new byte[] { Block.Stone,
|
||||
Block.Cobblestone, Block.Brick, Block.Dirt, Block.Wood,
|
||||
Block.Log, Block.Leaves, Block.Grass, Block.Slab };
|
||||
public byte[] Count = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
|
||||
|
||||
public byte[] Hotbar = new byte[9];
|
||||
public InventoryPermissions CanPlace = new InventoryPermissions();
|
||||
public InventoryPermissions CanDelete = new InventoryPermissions();
|
||||
|
||||
/// <summary> Gets or sets the index of the held block.
|
||||
/// Fails if the server has forbidden up from changing the held block. </summary>
|
||||
/// Fails if the server has forbidden user from changing the held block. </summary>
|
||||
public int HeldBlockIndex {
|
||||
get { return hotbarIndex; }
|
||||
set {
|
||||
@ -44,7 +40,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
/// <summary> Gets or sets the block currently held by the player.
|
||||
/// Fails if the server has forbidden up from changing the held block. </summary>
|
||||
/// Fails if the server has forbidden user from changing the held block. </summary>
|
||||
public byte HeldBlock {
|
||||
get { return Hotbar[hotbarIndex]; }
|
||||
set {
|
||||
|
38
ClassicalSharp/Mode/Creative.cs
Normal file
38
ClassicalSharp/Mode/Creative.cs
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
using System;
|
||||
using ClassicalSharp.Gui.Screens;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp.Mode {
|
||||
|
||||
public sealed class CreativeGameMode : IGameMode {
|
||||
|
||||
Game game;
|
||||
|
||||
public bool HandlesKeyDown(Key key) {
|
||||
if (key == game.Input.Keys[KeyBind.Inventory]) {
|
||||
game.Gui.SetNewScreen(new InventoryScreen(game));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnNewMapLoaded(Game game) {
|
||||
if (game.Server.IsSinglePlayer)
|
||||
game.Chat.Add("&ePlaying single player", MessageType.Status1);
|
||||
}
|
||||
|
||||
public void Init(Game game) {
|
||||
this.game = game;
|
||||
game.Inventory.Hotbar = new byte[] { Block.Stone,
|
||||
Block.Cobblestone, Block.Brick, Block.Dirt, Block.Wood,
|
||||
Block.Log, Block.Leaves, Block.Grass, Block.Slab };
|
||||
}
|
||||
|
||||
|
||||
public void Ready(Game game) { }
|
||||
public void Reset(Game game) { }
|
||||
public void OnNewMap(Game game) { }
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
11
ClassicalSharp/Mode/IGameMode.cs
Normal file
11
ClassicalSharp/Mode/IGameMode.cs
Normal file
@ -0,0 +1,11 @@
|
||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
using System;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp.Mode {
|
||||
|
||||
public interface IGameMode : IGameComponent {
|
||||
|
||||
bool HandlesKeyDown(Key key);
|
||||
}
|
||||
}
|
32
ClassicalSharp/Mode/Survival.cs
Normal file
32
ClassicalSharp/Mode/Survival.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||
using System;
|
||||
using OpenTK.Input;
|
||||
|
||||
namespace ClassicalSharp.Mode {
|
||||
|
||||
public sealed class SurvivalGameMode : IGameMode {
|
||||
|
||||
Game game;
|
||||
int score = 0;
|
||||
byte[] invCount = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 10 };
|
||||
|
||||
public bool HandlesKeyDown(Key key) { return false; }
|
||||
|
||||
public void OnNewMapLoaded(Game game) {
|
||||
game.Chat.Add("&fScore: &e" + score, MessageType.Status1);
|
||||
}
|
||||
|
||||
public void Init(Game game) {
|
||||
this.game = game;
|
||||
for (int i = 0; i < game.Inventory.Hotbar.Length; i++)
|
||||
game.Inventory.Hotbar[i] = Block.Invalid;
|
||||
game.Inventory.Hotbar[8] = Block.TNT;
|
||||
}
|
||||
|
||||
|
||||
public void Ready(Game game) { }
|
||||
public void Reset(Game game) { }
|
||||
public void OnNewMap(Game game) { }
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
@ -101,7 +101,6 @@ namespace ClassicalSharp.Singleplayer {
|
||||
}
|
||||
|
||||
generator = null;
|
||||
game.Chat.Add("&ePlaying single player", MessageType.Status1);
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ namespace ClassicalSharp {
|
||||
public const string EntityShadow = "entityshadow";
|
||||
public const string RenderType = "normal";
|
||||
public const string SmoothLighting = "gfx-smoothlighting";
|
||||
public const string SurvivalMode = "game-survivalmode";
|
||||
|
||||
public const string HacksEnabled = "hacks-hacksenabled";
|
||||
public const string FieldOfView = "hacks-fov";
|
||||
|
Loading…
x
Reference in New Issue
Block a user