Initial 10 bit block support

This commit is contained in:
UnknownShadow200 2018-03-05 21:24:44 +11:00
parent 0e555f00cd
commit 3ce5bb2e4e
9 changed files with 87 additions and 11 deletions

View File

@ -20,7 +20,7 @@ using BlockID = System.UInt16;
using BlockRaw = System.Byte;
namespace MCGalaxy {
public sealed partial class Block {
public static partial class Block {
internal static string[] coreNames = new string[Block.Count];
public static bool Undefined(BlockID block) { return IsPhysicsType(block) && coreNames[block].CaselessEq("unknown"); }

View File

@ -21,8 +21,7 @@ using MCGalaxy.Blocks;
using BlockID = System.UInt16;
namespace MCGalaxy {
public sealed partial class Block {
public static partial class Block {
public static BlockProps[] Props = new BlockProps[Block.ExtendedCount];
public static readonly object PropsLock = new object();

View File

@ -18,14 +18,33 @@
using System;
namespace MCGalaxy {
public sealed partial class Block {
public static partial class Block {
public const byte OriginalMaxBlock = Obsidian;
public const byte OriginalCount = OriginalMaxBlock + 1;
public const byte CpeMaxBlock = StoneBrick;
public const byte CpeCount = CpeMaxBlock + 1;
public const int Count = 256;
#if TEN_BIT_BLOCKS
public const ushort MaxRaw = 767;
public const int ExtendedCount = 256 * 4;
public static ushort[] ExtendedBase = new ushort[Block.Count];
public static byte[] ExtendedClass = new byte[4];
static Block() {
ExtendedBase[custom_block] = Extended;
ExtendedBase[custom_block_2] = Extended * 2;
ExtendedBase[custom_block_3] = Extended * 3;
ExtendedClass[0] = Air;
ExtendedClass[1] = custom_block;
ExtendedClass[2] = custom_block_2;
ExtendedClass[3] = custom_block_3;
}
#else
public const ushort MaxRaw = 255;
public const int ExtendedCount = 256 * 2;
#endif
// Original blocks
public const byte Air = 0;
@ -261,7 +280,10 @@ namespace MCGalaxy {
public const byte Geyser = 196;
public const byte Checkpoint = 197;
// 198, 199 free
#if TEN_BIT_BLOCKS
public const byte custom_block_2 = 198;
public const byte custom_block_3 = 199;
#endif
// Air type blocks
public const byte Air_Flood = 200;

View File

@ -22,7 +22,7 @@ using MCGalaxy.Maths;
using BlockID = System.UInt16;
namespace MCGalaxy {
public sealed partial class Block {
public static partial class Block {
public static bool Walkthrough(BlockID block) {
return block == Air || block == Sapling || block == Block.Snow

View File

@ -69,7 +69,11 @@ namespace MCGalaxy.Commands.World {
{
byte block = lvl.blocks[x + lvl.Width * (z + y * lvl.Length)];
temp.blocks[x + width * (z + y * length)] = block;
#if TEN_BIT_BLOCKS
if (Block.ExtendedBase[block] == 0) continue;
#else
if (block != Block.custom_block) continue;
#endif
byte extBlock = lvl.FastGetExtTile(x, y, z);
temp.FastSetExtTile(x, y, z, extBlock);

View File

@ -169,16 +169,25 @@ namespace MCGalaxy.Drawing.Ops {
int index = b.X + lvl.Width * (b.Z + b.Y * lvl.Length);
BlockID old = lvl.blocks[index];
#if TEN_BIT_BLOCKS
BlockID extended = Block.ExtendedBase[old];
if (extended > 0) old = (BlockID)(extended | lvl.FastGetExtTile(b.X, b.Y, b.Z));
#else
if (old == Block.custom_block) old = (BlockID)(Block.Extended | lvl.FastGetExtTile(b.X, b.Y, b.Z));
if (old == Block.Invalid) return;
#endif
if (old == Block.Invalid) return;
// Check to make sure the block is actually different and that we can change it
if (old == b.Block || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block)) return;
// Set the block (inlined)
lvl.Changed = true;
if (b.Block >= Block.Extended) {
#if TEN_BIT_BLOCKS
lvl.blocks[index] = Block.ExtendedClass[b.Block >> Block.ExtendedShift];
#else
lvl.blocks[index] = Block.custom_block;
#endif
lvl.FastSetExtTile(b.X, b.Y, b.Z, (BlockRaw)b.Block);
} else {
lvl.blocks[index] = (BlockRaw)b.Block;

View File

@ -36,8 +36,8 @@ namespace MCGalaxy.Generator.Foliage {
public override void SetData(Random rnd, int value) {
this.rnd = rnd;
height = (byte)value;
size = (byte)(maxExtent + maxCluster);
height = value;
size = maxExtent + maxCluster;
branchBaseHeight = height / 4;
branchAmount = rnd.Next(10, 25);

View File

@ -46,14 +46,24 @@ namespace MCGalaxy {
/// <returns> Undefined behaviour if coordinates are invalid. </returns>
public BlockID FastGetBlock(int index) {
byte raw = blocks[index];
#if TEN_BIT_BLOCKS
BlockID extended = Block.ExtendedBase[raw];
return extended == 0 ? raw : (BlockID)(extended | GetExtTile(index));
#else
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | GetExtTile(index));
#endif
}
/// <summary> Gets the block at the given coordinates. </summary>
/// <returns> Undefined behaviour if coordinates are invalid. </returns>
public BlockID FastGetBlock(ushort x, ushort y, ushort z) {
byte raw = blocks[x + Width * (z + y * Length)];
#if TEN_BIT_BLOCKS
BlockID extended = Block.ExtendedBase[raw];
return extended == 0 ? raw : (BlockID)(extended | FastGetExtTile(x, y, z));
#else
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
#endif
}
/// <summary> Gets the block at the given coordinates. </summary>
@ -61,7 +71,13 @@ namespace MCGalaxy {
public BlockID GetBlock(ushort x, ushort y, ushort z) {
if (x >= Width || y >= Height || z >= Length || blocks == null) return Block.Invalid;
byte raw = blocks[x + Width * (z + y * Length)];
#if TEN_BIT_BLOCKS
BlockID extended = Block.ExtendedBase[raw];
return extended == 0 ? raw : (BlockID)(extended | FastGetExtTile(x, y, z));
#else
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
#endif
}
/// <summary> Gets the block at the given coordinates. </summary>
@ -70,7 +86,13 @@ namespace MCGalaxy {
if (x >= Width || y >= Height || z >= Length || blocks == null) { index = -1; return Block.Invalid; }
index = x + Width * (z + y * Length);
byte raw = blocks[index];
#if TEN_BIT_BLOCKS
BlockID extended = Block.ExtendedBase[raw];
return extended == 0 ? raw : (BlockID)(extended | FastGetExtTile(x, y, z));
#else
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
#endif
}
/// <summary> Gets whether the block at the given coordinates is air. </summary>
@ -256,7 +278,11 @@ namespace MCGalaxy {
errorLocation = "Setting tile";
if (block >= Block.Extended) {
#if TEN_BIT_BLOCKS
SetTile(x, y, z, Block.ExtendedClass[block >> Block.ExtendedShift]);
#else
SetTile(x, y, z, Block.custom_block);
#endif
FastSetExtTile(x, y, z, (BlockRaw)block);
} else {
SetTile(x, y, z, (BlockRaw)block);
@ -310,7 +336,12 @@ namespace MCGalaxy {
PhysicsArgs data = default(PhysicsArgs), bool addUndo = true) {
if (blocks == null || b < 0 || b >= blocks.Length) return false;
BlockID old = blocks[b];
old = old != Block.custom_block ? old : (BlockID)(Block.Extended | GetExtTile(b));
#if TEN_BIT_BLOCKS
BlockID extended = Block.ExtendedBase[old];
if (extended > 0) old = (BlockID)(extended | GetExtTile(b));
#else
if (old == Block.custom_block) old = (BlockID)(Block.Extended | GetExtTile(b));
#endif
try
{
@ -342,7 +373,11 @@ namespace MCGalaxy {
Changed = true;
if (block >= Block.Extended) {
#if TEN_BIT_BLOCKS
blocks[b] = Block.ExtendedClass[block >> Block.ExtendedShift];
#else
blocks[b] = Block.custom_block;
#endif
ushort x, y, z;
IntToPos(b, out x, out y, out z);
FastSetExtTile(x, y, z, (BlockRaw)block);

View File

@ -152,9 +152,16 @@ namespace MCGalaxy {
OnPhysicsUpdateEvent.Call(C.X, C.Y, C.Z, C.Data, this);
C.Block = blocks[chk.Index];
#if TEN_BIT_BLOCKS
BlockID extended = Block.ExtendedBase[C.Block];
if (extended > 0) {
C.Block = (BlockID)(extended | FastGetExtTile(C.X, C.Y, C.Z));
}
#else
if (C.Block == Block.custom_block) {
C.Block = (BlockID)(Block.Extended | FastGetExtTile(C.X, C.Y, C.Z));
}
#endif
if ((C.Data.Raw & mask) == 0 || C.Data.Type1 == PhysicsArgs.Custom || extraHandler(this, ref C)) {
HandlePhysics handler = handlers[C.Block];