mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 17:12:25 -05:00
Abstract BlockInfo, use DefaultPlugin.Network namespace instead of ClassicalSharp in various classes in the default plugin.
This commit is contained in:
parent
9b742f9d71
commit
2db1414370
17 changed files with 234 additions and 168 deletions
|
@ -145,7 +145,7 @@ namespace ClassicalSharp {
|
||||||
|
|
||||||
void RecreateBlockTextures() {
|
void RecreateBlockTextures() {
|
||||||
int blocksCount = 0;
|
int blocksCount = 0;
|
||||||
for( int i = 0; i < BlockInfo.BlocksCount; i++ ) {
|
for( int i = 0; i < Window.BlockInfo.BlocksCount; i++ ) {
|
||||||
if( Window.CanPlace[i] || Window.CanDelete[i] ) {
|
if( Window.CanPlace[i] || Window.CanDelete[i] ) {
|
||||||
blocksCount++;
|
blocksCount++;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ namespace ClassicalSharp {
|
||||||
blocksTable = new BlockDrawInfo[blocksCount];
|
blocksTable = new BlockDrawInfo[blocksCount];
|
||||||
|
|
||||||
int tableIndex = 0;
|
int tableIndex = 0;
|
||||||
for( int tile = 1; tile < BlockInfo.BlocksCount; tile++ ) {
|
for( int tile = 1; tile < Window.BlockInfo.BlocksCount; tile++ ) {
|
||||||
if( Window.CanPlace[tile] || Window.CanDelete[tile] ) {
|
if( Window.CanPlace[tile] || Window.CanDelete[tile] ) {
|
||||||
Block block = (Block)tile;
|
Block block = (Block)tile;
|
||||||
int texId = Window.BlockInfo.GetOptimTextureLoc( (byte)block, TileSide.Left );
|
int texId = Window.BlockInfo.GetOptimTextureLoc( (byte)block, TileSide.Left );
|
||||||
|
|
|
@ -2,149 +2,55 @@
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace ClassicalSharp {
|
||||||
|
|
||||||
public partial class BlockInfo {
|
public abstract class BlockInfo {
|
||||||
|
|
||||||
bool[] isTransparent = new bool[BlocksCount];
|
|
||||||
bool[] isTranslucent = new bool[BlocksCount];
|
|
||||||
bool[] isOpaque = new bool[BlocksCount];
|
|
||||||
bool[] isSprite = new bool[BlocksCount];
|
|
||||||
bool[] isLiquid = new bool[BlocksCount];
|
|
||||||
float[] heights = new float[BlocksCount];
|
|
||||||
bool[] blocksLight = new bool[BlocksCount];
|
|
||||||
public const byte MaxDefinedBlock = (byte)Block.StoneBrick;
|
|
||||||
public const byte BlocksCount = MaxDefinedBlock + 1;
|
|
||||||
|
|
||||||
public void Init() {
|
public BlockInfo( Game window ) {
|
||||||
for( int tile = 1; tile < BlocksCount; tile++ ) {
|
|
||||||
heights[tile] = 1f;
|
|
||||||
blocksLight[tile] = true;
|
|
||||||
isOpaque[tile] = true;
|
|
||||||
}
|
|
||||||
SetupOptimTextures();
|
|
||||||
|
|
||||||
SetIsTranslucent( Block.StillWater, Block.Water );
|
|
||||||
SetIsTransparent( Block.Glass, Block.Leaves, Block.Sapling,
|
|
||||||
Block.RedMushroom, Block.BrownMushroom, Block.Rose,
|
|
||||||
Block.Dandelion, Block.Slab );
|
|
||||||
SetIsSprite( Block.Rose, Block.Sapling, Block.Dandelion,
|
|
||||||
Block.BrownMushroom, Block.RedMushroom );
|
|
||||||
SetBlockHeight( 8 / 16f, Block.Slab );
|
|
||||||
SetBlocksLight( false, Block.Glass, Block.Leaves, Block.Sapling,
|
|
||||||
Block.RedMushroom, Block.BrownMushroom, Block.Rose,
|
|
||||||
Block.Dandelion );
|
|
||||||
SetIsLiquid( Block.StillWater, Block.Water, Block.StillLava, Block.Lava );
|
|
||||||
|
|
||||||
SetIsTransparent( Block.Snow, Block.Fire, Block.Rope, Block.CobblestoneSlab );
|
|
||||||
SetBlocksLight( false, Block.Fire, Block.Rope );
|
|
||||||
SetIsTranslucent( Block.Ice );
|
|
||||||
SetIsSprite( Block.Rope, Block.Fire );
|
|
||||||
SetBlockHeight( 8 / 16f, Block.CobblestoneSlab );
|
|
||||||
SetBlockHeight( 2 / 16f, Block.Snow );
|
|
||||||
SetupCullingCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDefaultBlockPermissions( bool[] canPlace, bool[] canDelete ) {
|
public abstract byte BlocksCount { get; }
|
||||||
for( int tile = (int)Block.Stone; tile <= (int)Block.Obsidian; tile++ ) {
|
|
||||||
canPlace[tile] = true;
|
|
||||||
canDelete[tile] = true;
|
|
||||||
}
|
|
||||||
canPlace[(int)Block.Grass] = false;
|
|
||||||
canPlace[(int)Block.Lava] = false;
|
|
||||||
canPlace[(int)Block.Water] = false;
|
|
||||||
canPlace[(int)Block.StillLava] = false;
|
|
||||||
canPlace[(int)Block.StillWater] = false;
|
|
||||||
canPlace[(int)Block.Bedrock] = false;
|
|
||||||
|
|
||||||
canDelete[(int)Block.Bedrock] = false;
|
|
||||||
canDelete[(int)Block.Lava] = false;
|
|
||||||
canDelete[(int)Block.Water] = false;
|
|
||||||
canDelete[(int)Block.StillWater] = false;
|
|
||||||
canDelete[(int)Block.StillLava] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetIsTransparent( params Block[] ids ) {
|
public abstract void Init();
|
||||||
for( int i = 0; i < ids.Length; i++ ) {
|
|
||||||
isTransparent[(int)ids[i]] = true;
|
|
||||||
isOpaque[(int)ids[i]] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetIsSprite( params Block[] ids ) {
|
public abstract void SetDefaultBlockPermissions( bool[] canPlace, bool[] canDelete );
|
||||||
for( int i = 0; i < ids.Length; i++ ) {
|
|
||||||
isSprite[(int)ids[i]] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetIsTranslucent( params Block[] ids ) {
|
|
||||||
for( int i = 0; i < ids.Length; i++ ) {
|
|
||||||
isTranslucent[(int)ids[i]] = true;
|
|
||||||
isOpaque[(int)ids[i]] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetIsLiquid( params Block[] ids ) {
|
|
||||||
for( int i = 0; i < ids.Length; i++ ) {
|
|
||||||
isLiquid[(int)ids[i]] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetBlockHeight( float height, params Block[] ids ) {
|
|
||||||
for( int i = 0; i < ids.Length; i++ ) {
|
|
||||||
heights[(int)ids[i]] = height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetBlocksLight( bool blocks, params Block[] ids ) {
|
|
||||||
for( int i = 0; i < ids.Length; i++ ) {
|
|
||||||
blocksLight[(int)ids[i]] = blocks;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the given block id is opaque/not see through. </summary>
|
/// <summary> Gets whether the given block id is opaque/not see through. </summary>
|
||||||
public bool IsOpaque( byte id ) {
|
public abstract bool IsOpaque( byte id );
|
||||||
return isOpaque[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the given block id is opaque/not see through,
|
/// <summary> Gets whether the given block id is opaque/not see through,
|
||||||
/// and occupies a full block. </summary>
|
/// and occupies a full block. </summary>
|
||||||
public bool IsFullAndOpaque( byte id ) {
|
public abstract bool IsFullAndOpaque( byte id );
|
||||||
return isOpaque[id] && heights[id] == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the given block id is transparent/fully see through. </summary>
|
/// <summary> Gets whether the given block id is transparent/fully see through. </summary>
|
||||||
/// <remarks> Note that these blocks's alpha values are treated as either 'fully see through'
|
/// <remarks> Note that these blocks's alpha values are treated as either 'fully see through'
|
||||||
/// or 'fully solid'. </remarks>
|
/// or 'fully solid'. </remarks>
|
||||||
public bool IsTransparent( byte id ) {
|
public abstract bool IsTransparent( byte id );
|
||||||
return isTransparent[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets the tile height of the given block id. </summary>
|
/// <summary> Gets the tile height of the given block id. </summary>
|
||||||
public float BlockHeight( byte id ) {
|
public abstract float BlockHeight( byte id );
|
||||||
return heights[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the given block id is translucent/partially see through. </summary>
|
/// <summary> Gets whether the given block id is translucent/partially see through. </summary>
|
||||||
/// <remarks> Note that these blocks's colour values are blended into both
|
/// <remarks> Note that these blocks's colour values are blended into both
|
||||||
/// the transparent and opaque blocks behind them. </remarks>
|
/// the transparent and opaque blocks behind them. </remarks>
|
||||||
public bool IsTranslucent( byte id ) {
|
public abstract bool IsTranslucent( byte id );
|
||||||
return isTranslucent[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the given block blocks sunlight. </summary>
|
/// <summary> Gets whether the given block blocks sunlight. </summary>
|
||||||
public bool BlocksLight( byte id ) {
|
public abstract bool BlocksLight( byte id );
|
||||||
return blocksLight[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the given block id is a sprite. <br/>
|
/// <summary> Gets whether the given block id is a sprite. <br/>
|
||||||
/// (flowers, saplings, fire, etc) </summary>
|
/// (flowers, saplings, fire, etc) </summary>
|
||||||
public bool IsSprite( byte id ) {
|
public abstract bool IsSprite( byte id );
|
||||||
return isSprite[id];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> Gets whether the given block id is a liquid. <br/>
|
/// <summary> Gets whether the given block id is a liquid. <br/>
|
||||||
/// (water or lava) </summary>
|
/// (water or lava) </summary>
|
||||||
public bool IsLiquid( byte id ) {
|
public abstract bool IsLiquid( byte id );
|
||||||
return isLiquid[id];
|
|
||||||
}
|
public abstract bool IsFaceHidden( byte tile, byte block, int tileSide );
|
||||||
|
|
||||||
|
/// <summary> Gets the index in the ***optimised*** 2D terrain atlas for the
|
||||||
|
/// texture of the face of the given block. </summary>
|
||||||
|
/// <param name="block"> Block ID. </param>
|
||||||
|
/// <param name="face">Face of the given block, see TileSide constants. </param>
|
||||||
|
/// <returns>The index of the texture within the terrain atlas.</returns>
|
||||||
|
public abstract int GetOptimTextureLoc( byte block, int face );
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -107,8 +107,6 @@
|
||||||
<Compile Include="2D\Widgets\Widget.cs" />
|
<Compile Include="2D\Widgets\Widget.cs" />
|
||||||
<Compile Include="Blocks\Block.cs" />
|
<Compile Include="Blocks\Block.cs" />
|
||||||
<Compile Include="Blocks\BlockInfo.cs" />
|
<Compile Include="Blocks\BlockInfo.cs" />
|
||||||
<Compile Include="Blocks\BlockInfo.Culling.cs" />
|
|
||||||
<Compile Include="Blocks\BlockInfo.Optimised.cs" />
|
|
||||||
<Compile Include="Entities\Entity.cs" />
|
<Compile Include="Entities\Entity.cs" />
|
||||||
<Compile Include="Entities\LocalPlayer.cs" />
|
<Compile Include="Entities\LocalPlayer.cs" />
|
||||||
<Compile Include="Entities\NetPlayer.cs" />
|
<Compile Include="Entities\NetPlayer.cs" />
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
|
using ClassicalSharp;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace DefaultPlugin {
|
||||||
|
|
||||||
public partial class BlockInfo {
|
public partial class ClassicBlockInfo : BlockInfo {
|
||||||
|
|
||||||
bool[] hidden = new bool[BlocksCount * BlocksCount * 6];
|
bool[] hidden = new bool[blocksCount * blocksCount * 6];
|
||||||
|
|
||||||
void SetupCullingCache() {
|
void SetupCullingCache() {
|
||||||
for( byte tile = 1; tile < BlocksCount; tile++ ) {
|
for( byte tile = 1; tile < blocksCount; tile++ ) {
|
||||||
for( byte neighbour = 1; neighbour < BlocksCount; neighbour++ ) {
|
for( byte neighbour = 1; neighbour < blocksCount; neighbour++ ) {
|
||||||
bool hidden = IsHidden( tile, neighbour );
|
bool hidden = IsHidden( tile, neighbour );
|
||||||
if( hidden ) {
|
if( hidden ) {
|
||||||
SetHidden( tile, neighbour, TileSide.Left, true );
|
SetHidden( tile, neighbour, TileSide.Left, true );
|
||||||
|
@ -29,11 +30,11 @@ namespace ClassicalSharp {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetHidden( byte tile, byte block, int tileSide, bool value ) {
|
void SetHidden( byte tile, byte block, int tileSide, bool value ) {
|
||||||
hidden[( tile * BlocksCount + block ) * 6 + tileSide] = value;
|
hidden[( tile * blocksCount + block ) * 6 + tileSide] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFaceHidden( byte tile, byte block, int tileSide ) {
|
public override bool IsFaceHidden( byte tile, byte block, int tileSide ) {
|
||||||
return hidden[( tile * BlocksCount + block ) * 6 + tileSide];
|
return hidden[( tile * blocksCount + block ) * 6 + tileSide];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,13 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
|
using ClassicalSharp;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace DefaultPlugin {
|
||||||
|
|
||||||
public partial class BlockInfo {
|
public partial class ClassicBlockInfo : BlockInfo {
|
||||||
|
|
||||||
// The designation used is as follows:
|
// The designation used is as follows:
|
||||||
// 0 - left 1 - right 2 - front
|
// 0 - left 1 - right 2 - front
|
||||||
// 3 - back 4 - bottom 5 - top
|
// 3 - back 4 - bottom 5 - top
|
||||||
int[] optimTextures = new int[BlocksCount * 6];
|
int[] optimTextures = new int[blocksCount * 6];
|
||||||
const int Row1 = 0, Row2 = 16, Row3 = 32, Row4 = 48,
|
const int Row1 = 0, Row2 = 16, Row3 = 32, Row4 = 48,
|
||||||
Row5 = 64, Row6 = 80, Row7 = 96, Row8 = 112, Row9 = 128;
|
Row5 = 64, Row6 = 80, Row7 = 96, Row8 = 112, Row9 = 128;
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ namespace ClassicalSharp {
|
||||||
/// <param name="block"> Block ID. </param>
|
/// <param name="block"> Block ID. </param>
|
||||||
/// <param name="face">Face of the given block, see TileSide constants. </param>
|
/// <param name="face">Face of the given block, see TileSide constants. </param>
|
||||||
/// <returns>The index of the texture within the terrain atlas.</returns>
|
/// <returns>The index of the texture within the terrain atlas.</returns>
|
||||||
public int GetOptimTextureLoc( byte block, int face ) {
|
public override int GetOptimTextureLoc( byte block, int face ) {
|
||||||
return optimTextures[block * 6 + face];
|
return optimTextures[block * 6 + face];
|
||||||
}
|
}
|
||||||
}
|
}
|
157
DefaultPlugin/Blocks/BlockInfo.cs
Normal file
157
DefaultPlugin/Blocks/BlockInfo.cs
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
using System;
|
||||||
|
using ClassicalSharp;
|
||||||
|
|
||||||
|
namespace DefaultPlugin {
|
||||||
|
|
||||||
|
public partial class ClassicBlockInfo : BlockInfo {
|
||||||
|
|
||||||
|
public ClassicBlockInfo( Game window ) : base( window ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
bool[] isTransparent = new bool[blocksCount];
|
||||||
|
bool[] isTranslucent = new bool[blocksCount];
|
||||||
|
bool[] isOpaque = new bool[blocksCount];
|
||||||
|
bool[] isSprite = new bool[blocksCount];
|
||||||
|
bool[] isLiquid = new bool[blocksCount];
|
||||||
|
float[] heights = new float[blocksCount];
|
||||||
|
bool[] blocksLight = new bool[blocksCount];
|
||||||
|
const byte blocksCount = (byte)Block.StoneBrick + 1;
|
||||||
|
|
||||||
|
public override byte BlocksCount {
|
||||||
|
get { return blocksCount; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Init() {
|
||||||
|
for( int tile = 1; tile < blocksCount; tile++ ) {
|
||||||
|
heights[tile] = 1f;
|
||||||
|
blocksLight[tile] = true;
|
||||||
|
isOpaque[tile] = true;
|
||||||
|
}
|
||||||
|
SetupOptimTextures();
|
||||||
|
|
||||||
|
SetIsTranslucent( Block.StillWater, Block.Water );
|
||||||
|
SetIsTransparent( Block.Glass, Block.Leaves, Block.Sapling,
|
||||||
|
Block.RedMushroom, Block.BrownMushroom, Block.Rose,
|
||||||
|
Block.Dandelion, Block.Slab );
|
||||||
|
SetIsSprite( Block.Rose, Block.Sapling, Block.Dandelion,
|
||||||
|
Block.BrownMushroom, Block.RedMushroom );
|
||||||
|
SetBlockHeight( 8 / 16f, Block.Slab );
|
||||||
|
SetBlocksLight( false, Block.Glass, Block.Leaves, Block.Sapling,
|
||||||
|
Block.RedMushroom, Block.BrownMushroom, Block.Rose,
|
||||||
|
Block.Dandelion );
|
||||||
|
SetIsLiquid( Block.StillWater, Block.Water, Block.StillLava, Block.Lava );
|
||||||
|
|
||||||
|
SetIsTransparent( Block.Snow, Block.Fire, Block.Rope, Block.CobblestoneSlab );
|
||||||
|
SetBlocksLight( false, Block.Fire, Block.Rope );
|
||||||
|
SetIsTranslucent( Block.Ice );
|
||||||
|
SetIsSprite( Block.Rope, Block.Fire );
|
||||||
|
SetBlockHeight( 8 / 16f, Block.CobblestoneSlab );
|
||||||
|
SetBlockHeight( 2 / 16f, Block.Snow );
|
||||||
|
SetupCullingCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetDefaultBlockPermissions( bool[] canPlace, bool[] canDelete ) {
|
||||||
|
for( int tile = (int)Block.Stone; tile <= (int)Block.Obsidian; tile++ ) {
|
||||||
|
canPlace[tile] = true;
|
||||||
|
canDelete[tile] = true;
|
||||||
|
}
|
||||||
|
canPlace[(int)Block.Grass] = false;
|
||||||
|
canPlace[(int)Block.Lava] = false;
|
||||||
|
canPlace[(int)Block.Water] = false;
|
||||||
|
canPlace[(int)Block.StillLava] = false;
|
||||||
|
canPlace[(int)Block.StillWater] = false;
|
||||||
|
canPlace[(int)Block.Bedrock] = false;
|
||||||
|
|
||||||
|
canDelete[(int)Block.Bedrock] = false;
|
||||||
|
canDelete[(int)Block.Lava] = false;
|
||||||
|
canDelete[(int)Block.Water] = false;
|
||||||
|
canDelete[(int)Block.StillWater] = false;
|
||||||
|
canDelete[(int)Block.StillLava] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetIsTransparent( params Block[] ids ) {
|
||||||
|
for( int i = 0; i < ids.Length; i++ ) {
|
||||||
|
isTransparent[(int)ids[i]] = true;
|
||||||
|
isOpaque[(int)ids[i]] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetIsSprite( params Block[] ids ) {
|
||||||
|
for( int i = 0; i < ids.Length; i++ ) {
|
||||||
|
isSprite[(int)ids[i]] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetIsTranslucent( params Block[] ids ) {
|
||||||
|
for( int i = 0; i < ids.Length; i++ ) {
|
||||||
|
isTranslucent[(int)ids[i]] = true;
|
||||||
|
isOpaque[(int)ids[i]] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetIsLiquid( params Block[] ids ) {
|
||||||
|
for( int i = 0; i < ids.Length; i++ ) {
|
||||||
|
isLiquid[(int)ids[i]] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetBlockHeight( float height, params Block[] ids ) {
|
||||||
|
for( int i = 0; i < ids.Length; i++ ) {
|
||||||
|
heights[(int)ids[i]] = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetBlocksLight( bool blocks, params Block[] ids ) {
|
||||||
|
for( int i = 0; i < ids.Length; i++ ) {
|
||||||
|
blocksLight[(int)ids[i]] = blocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets whether the given block id is opaque/not see through. </summary>
|
||||||
|
public override bool IsOpaque( byte id ) {
|
||||||
|
return isOpaque[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets whether the given block id is opaque/not see through,
|
||||||
|
/// and occupies a full block. </summary>
|
||||||
|
public override bool IsFullAndOpaque( byte id ) {
|
||||||
|
return isOpaque[id] && heights[id] == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets whether the given block id is transparent/fully see through. </summary>
|
||||||
|
/// <remarks> Note that these blocks's alpha values are treated as either 'fully see through'
|
||||||
|
/// or 'fully solid'. </remarks>
|
||||||
|
public override bool IsTransparent( byte id ) {
|
||||||
|
return isTransparent[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets the tile height of the given block id. </summary>
|
||||||
|
public override float BlockHeight( byte id ) {
|
||||||
|
return heights[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets whether the given block id is translucent/partially see through. </summary>
|
||||||
|
/// <remarks> Note that these blocks's colour values are blended into both
|
||||||
|
/// the transparent and opaque blocks behind them. </remarks>
|
||||||
|
public override bool IsTranslucent( byte id ) {
|
||||||
|
return isTranslucent[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets whether the given block blocks sunlight. </summary>
|
||||||
|
public override bool BlocksLight( byte id ) {
|
||||||
|
return blocksLight[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets whether the given block id is a sprite. <br/>
|
||||||
|
/// (flowers, saplings, fire, etc) </summary>
|
||||||
|
public override bool IsSprite( byte id ) {
|
||||||
|
return isSprite[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Gets whether the given block id is a liquid. <br/>
|
||||||
|
/// (water or lava) </summary>
|
||||||
|
public override bool IsLiquid( byte id ) {
|
||||||
|
return isLiquid[id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,7 @@ namespace DefaultPlugin {
|
||||||
new PluginModule( PluginModuleType.PostProcessingShader, typeof( GrayscaleFilter ) ),
|
new PluginModule( PluginModuleType.PostProcessingShader, typeof( GrayscaleFilter ) ),
|
||||||
|
|
||||||
new PluginModule( PluginModuleType.NetworkProcessor, typeof( ClassicNetworkProcessor ) ),
|
new PluginModule( PluginModuleType.NetworkProcessor, typeof( ClassicNetworkProcessor ) ),
|
||||||
|
new PluginModule( PluginModuleType.BlockInfo, typeof( ClassicBlockInfo ) ),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,9 @@
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Blocks\BlockInfo.cs" />
|
||||||
|
<Compile Include="Blocks\BlockInfo.Culling.cs" />
|
||||||
|
<Compile Include="Blocks\BlockInfo.Optimised.cs" />
|
||||||
<Compile Include="Network\ClassicNetwork.Writing.cs" />
|
<Compile Include="Network\ClassicNetwork.Writing.cs" />
|
||||||
<Compile Include="Network\ClassicNetwork.Reading.cs" />
|
<Compile Include="Network\ClassicNetwork.Reading.cs" />
|
||||||
<Compile Include="Network\Enums.cs" />
|
<Compile Include="Network\Enums.cs" />
|
||||||
|
@ -78,6 +81,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Models" />
|
<Folder Include="Models" />
|
||||||
<Folder Include="Network" />
|
<Folder Include="Network" />
|
||||||
|
<Folder Include="Blocks" />
|
||||||
<Folder Include="Shaders" />
|
<Folder Include="Shaders" />
|
||||||
<Folder Include="Renderers" />
|
<Folder Include="Renderers" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace DefaultPlugin.Network {
|
||||||
|
|
||||||
public enum PacketId {
|
public enum PacketId {
|
||||||
ServerIdentification = 0,
|
ServerIdentification = 0,
|
||||||
|
@ -39,15 +39,4 @@ namespace ClassicalSharp {
|
||||||
CpeHackControl = 32,
|
CpeHackControl = 32,
|
||||||
CpeExtAddEntity2 = 33,
|
CpeExtAddEntity2 = 33,
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum CpeMessageType {
|
|
||||||
Normal = 0,
|
|
||||||
Status1 = 1,
|
|
||||||
Status2 = 2,
|
|
||||||
Status3 = 3,
|
|
||||||
BottomRight1 = 11,
|
|
||||||
BottomRight2 = 12,
|
|
||||||
BottomRight3 = 13,
|
|
||||||
Announcement = 100,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace DefaultPlugin.Network {
|
||||||
|
|
||||||
// Basically a much faster version of List<byte>( capacity )
|
// Basically a much faster version of List<byte>( capacity )
|
||||||
internal class FastNetReader {
|
internal class FastNetReader {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace DefaultPlugin.Network {
|
||||||
|
|
||||||
internal class FixedBufferStream : Stream {
|
internal class FixedBufferStream : Stream {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace DefaultPlugin.Network {
|
||||||
|
|
||||||
internal class GZipHeaderReader {
|
internal class GZipHeaderReader {
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
|
using ClassicalSharp;
|
||||||
using ClassicalSharp.GraphicsAPI;
|
using ClassicalSharp.GraphicsAPI;
|
||||||
|
|
||||||
namespace ClassicalSharp {
|
namespace DefaultPlugin {
|
||||||
|
|
||||||
public class StandardChunkMeshBuilder : ChunkMeshBuilder {
|
public class StandardChunkMeshBuilder : ChunkMeshBuilder {
|
||||||
|
|
||||||
|
|
36
Game/Game.cs
36
Game/Game.cs
|
@ -29,6 +29,7 @@ namespace ClassicalSharp {
|
||||||
public Camera Camera;
|
public Camera Camera;
|
||||||
Camera firstPersonCam, thirdPersonCam;
|
Camera firstPersonCam, thirdPersonCam;
|
||||||
public BlockInfo BlockInfo;
|
public BlockInfo BlockInfo;
|
||||||
|
public List<Type> BlockInfoTypes = new List<Type>();
|
||||||
public double accumulator;
|
public double accumulator;
|
||||||
public TerrainAtlas2D TerrainAtlas;
|
public TerrainAtlas2D TerrainAtlas;
|
||||||
public SkinType DefaultPlayerSkinType;
|
public SkinType DefaultPlayerSkinType;
|
||||||
|
@ -127,23 +128,6 @@ namespace ClassicalSharp {
|
||||||
Bitmap terrainBmp = new Bitmap( "terrain.png" );
|
Bitmap terrainBmp = new Bitmap( "terrain.png" );
|
||||||
TerrainAtlas = new TerrainAtlas2D( Graphics );
|
TerrainAtlas = new TerrainAtlas2D( Graphics );
|
||||||
LoadAtlas( terrainBmp );
|
LoadAtlas( terrainBmp );
|
||||||
BlockInfo = new BlockInfo();
|
|
||||||
BlockInfo.Init();
|
|
||||||
BlockInfo.SetDefaultBlockPermissions( CanPlace, CanDelete );
|
|
||||||
Map = new Map( this );
|
|
||||||
LocalPlayer = new LocalPlayer( 255, this );
|
|
||||||
width = Width;
|
|
||||||
height = Height;
|
|
||||||
firstPersonCam = new FirstPersonCamera( this );
|
|
||||||
thirdPersonCam = new ThirdPersonCamera( this );
|
|
||||||
Camera = firstPersonCam;
|
|
||||||
CommandManager = new CommandManager();
|
|
||||||
CommandManager.Init( this );
|
|
||||||
SelectionManager = new SelectionManager( this );
|
|
||||||
SelectionManager.Init();
|
|
||||||
ParticleManager = new ParticleManager( this );
|
|
||||||
ParticleManager.Init();
|
|
||||||
Picking = new PickingRenderer( this );
|
|
||||||
|
|
||||||
VSync = VSyncMode.On;
|
VSync = VSyncMode.On;
|
||||||
Graphics.DepthTest = true;
|
Graphics.DepthTest = true;
|
||||||
|
@ -155,6 +139,13 @@ namespace ClassicalSharp {
|
||||||
fpsScreen = new FpsScreen( this );
|
fpsScreen = new FpsScreen( this );
|
||||||
fpsScreen.Init();
|
fpsScreen.Init();
|
||||||
Culling = new FrustumCulling();
|
Culling = new FrustumCulling();
|
||||||
|
width = Width;
|
||||||
|
height = Height;
|
||||||
|
firstPersonCam = new FirstPersonCamera( this );
|
||||||
|
thirdPersonCam = new ThirdPersonCamera( this );
|
||||||
|
Camera = firstPersonCam;
|
||||||
|
CommandManager = new CommandManager();
|
||||||
|
CommandManager.Init( this );
|
||||||
|
|
||||||
string defaultPlugin = Path.Combine( "plugins", "defaultplugin.dll" );
|
string defaultPlugin = Path.Combine( "plugins", "defaultplugin.dll" );
|
||||||
if( !Directory.Exists( "plugins" ) || !File.Exists( defaultPlugin ) ) {
|
if( !Directory.Exists( "plugins" ) || !File.Exists( defaultPlugin ) ) {
|
||||||
|
@ -171,6 +162,17 @@ namespace ClassicalSharp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BlockInfo = Utils.New<BlockInfo>( BlockInfoTypes[0], this );
|
||||||
|
BlockInfo.Init();
|
||||||
|
BlockInfo.SetDefaultBlockPermissions( CanPlace, CanDelete );
|
||||||
|
Map = new Map( this );
|
||||||
|
LocalPlayer = new LocalPlayer( 255, this );
|
||||||
|
SelectionManager = new SelectionManager( this );
|
||||||
|
SelectionManager.Init();
|
||||||
|
ParticleManager = new ParticleManager( this );
|
||||||
|
ParticleManager.Init();
|
||||||
|
Picking = new PickingRenderer( this );
|
||||||
|
|
||||||
MapBordersRenderer = Utils.New<MapBordersRenderer>( MapBordersRendererTypes[0], this );
|
MapBordersRenderer = Utils.New<MapBordersRenderer>( MapBordersRendererTypes[0], this );
|
||||||
MapBordersRenderer.Init();
|
MapBordersRenderer.Init();
|
||||||
EnvRenderer = Utils.New<EnvRenderer>( EnvRendererTypes[0], this );
|
EnvRenderer = Utils.New<EnvRenderer>( EnvRendererTypes[0], this );
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace ClassicalSharp.Model {
|
||||||
byte blockId;
|
byte blockId;
|
||||||
if( Byte.TryParse( modelName, out blockId ) ) {
|
if( Byte.TryParse( modelName, out blockId ) ) {
|
||||||
modelName = "block";
|
modelName = "block";
|
||||||
if( blockId == 0 || blockId > BlockInfo.MaxDefinedBlock )
|
if( blockId == 0 || blockId >= window.BlockInfo.BlocksCount )
|
||||||
return cache["humanoid"];
|
return cache["humanoid"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,6 +69,10 @@ namespace ClassicalSharp.Plugins {
|
||||||
case PluginModuleType.NetworkProcessor:
|
case PluginModuleType.NetworkProcessor:
|
||||||
game.NetworkProcessorTypes.Add( module.Type );
|
game.NetworkProcessorTypes.Add( module.Type );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PluginModuleType.BlockInfo:
|
||||||
|
game.BlockInfoTypes.Add( module.Type );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,6 +86,7 @@ namespace ClassicalSharp.Plugins {
|
||||||
MapRenderer,
|
MapRenderer,
|
||||||
PostProcessingShader,
|
PostProcessingShader,
|
||||||
NetworkProcessor,
|
NetworkProcessor,
|
||||||
|
BlockInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PluginModule {
|
public class PluginModule {
|
||||||
|
|
|
@ -29,12 +29,10 @@ namespace ClassicalSharp {
|
||||||
|
|
||||||
public abstract class PerspectiveCamera : Camera {
|
public abstract class PerspectiveCamera : Camera {
|
||||||
|
|
||||||
protected Player player;
|
|
||||||
IInputDriver driver;
|
IInputDriver driver;
|
||||||
public PerspectiveCamera( Game window ) {
|
public PerspectiveCamera( Game window ) {
|
||||||
Window = window;
|
Window = window;
|
||||||
driver = window.InputDriver;
|
driver = window.InputDriver;
|
||||||
player = Window.LocalPlayer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Matrix4 GetProjection() {
|
public override Matrix4 GetProjection() {
|
||||||
|
@ -44,6 +42,7 @@ namespace ClassicalSharp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void GetPickedBlock( PickedPos pos ) {
|
public override void GetPickedBlock( PickedPos pos ) {
|
||||||
|
Player player = Window.LocalPlayer;
|
||||||
Vector3 dir = Utils.GetDirectionVector( player.YawRadians, player.PitchRadians + Math.PI );
|
Vector3 dir = Utils.GetDirectionVector( player.YawRadians, player.PitchRadians + Math.PI );
|
||||||
Vector3 eyePos = player.EyePosition;
|
Vector3 eyePos = player.EyePosition;
|
||||||
float reach = Window.LocalPlayer.ReachDistance;
|
float reach = Window.LocalPlayer.ReachDistance;
|
||||||
|
@ -107,6 +106,7 @@ namespace ClassicalSharp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Matrix4 GetView() {
|
public override Matrix4 GetView() {
|
||||||
|
Player player = Window.LocalPlayer;
|
||||||
Vector3 eyePos = player.EyePosition;
|
Vector3 eyePos = player.EyePosition;
|
||||||
Vector3 cameraPos = eyePos - Utils.GetDirectionVector( player.YawRadians, player.PitchRadians + Math.PI ) * distance;
|
Vector3 cameraPos = eyePos - Utils.GetDirectionVector( player.YawRadians, player.PitchRadians + Math.PI ) * distance;
|
||||||
return Matrix4.LookAt( cameraPos, eyePos, Vector3.UnitY );
|
return Matrix4.LookAt( cameraPos, eyePos, Vector3.UnitY );
|
||||||
|
@ -123,6 +123,7 @@ namespace ClassicalSharp {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Matrix4 GetView() {
|
public override Matrix4 GetView() {
|
||||||
|
Player player = Window.LocalPlayer;
|
||||||
Vector3 eyePos = player.EyePosition;
|
Vector3 eyePos = player.EyePosition;
|
||||||
Vector3 cameraDir = Utils.GetDirectionVector( player.YawRadians, player.PitchRadians + Math.PI );
|
Vector3 cameraDir = Utils.GetDirectionVector( player.YawRadians, player.PitchRadians + Math.PI );
|
||||||
return Matrix4.LookAt( eyePos, eyePos + cameraDir, Vector3.UnitY );
|
return Matrix4.LookAt( eyePos, eyePos + cameraDir, Vector3.UnitY );
|
||||||
|
|
Loading…
Reference in a new issue