mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-27 15:30:58 -04:00
Initial 10 bit block support
This commit is contained in:
parent
0e555f00cd
commit
3ce5bb2e4e
@ -20,7 +20,7 @@ using BlockID = System.UInt16;
|
|||||||
using BlockRaw = System.Byte;
|
using BlockRaw = System.Byte;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
public sealed partial class Block {
|
public static partial class Block {
|
||||||
|
|
||||||
internal static string[] coreNames = new string[Block.Count];
|
internal static string[] coreNames = new string[Block.Count];
|
||||||
public static bool Undefined(BlockID block) { return IsPhysicsType(block) && coreNames[block].CaselessEq("unknown"); }
|
public static bool Undefined(BlockID block) { return IsPhysicsType(block) && coreNames[block].CaselessEq("unknown"); }
|
||||||
|
@ -21,8 +21,7 @@ using MCGalaxy.Blocks;
|
|||||||
using BlockID = System.UInt16;
|
using BlockID = System.UInt16;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
|
public static partial class Block {
|
||||||
public sealed partial class Block {
|
|
||||||
|
|
||||||
public static BlockProps[] Props = new BlockProps[Block.ExtendedCount];
|
public static BlockProps[] Props = new BlockProps[Block.ExtendedCount];
|
||||||
public static readonly object PropsLock = new object();
|
public static readonly object PropsLock = new object();
|
||||||
|
@ -18,14 +18,33 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
public sealed partial class Block {
|
public static partial class Block {
|
||||||
public const byte OriginalMaxBlock = Obsidian;
|
public const byte OriginalMaxBlock = Obsidian;
|
||||||
public const byte OriginalCount = OriginalMaxBlock + 1;
|
public const byte OriginalCount = OriginalMaxBlock + 1;
|
||||||
public const byte CpeMaxBlock = StoneBrick;
|
public const byte CpeMaxBlock = StoneBrick;
|
||||||
public const byte CpeCount = CpeMaxBlock + 1;
|
public const byte CpeCount = CpeMaxBlock + 1;
|
||||||
public const int Count = 256;
|
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 ushort MaxRaw = 255;
|
||||||
public const int ExtendedCount = 256 * 2;
|
public const int ExtendedCount = 256 * 2;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Original blocks
|
// Original blocks
|
||||||
public const byte Air = 0;
|
public const byte Air = 0;
|
||||||
@ -261,7 +280,10 @@ namespace MCGalaxy {
|
|||||||
public const byte Geyser = 196;
|
public const byte Geyser = 196;
|
||||||
|
|
||||||
public const byte Checkpoint = 197;
|
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
|
// Air type blocks
|
||||||
public const byte Air_Flood = 200;
|
public const byte Air_Flood = 200;
|
||||||
|
@ -22,7 +22,7 @@ using MCGalaxy.Maths;
|
|||||||
using BlockID = System.UInt16;
|
using BlockID = System.UInt16;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
public sealed partial class Block {
|
public static partial class Block {
|
||||||
|
|
||||||
public static bool Walkthrough(BlockID block) {
|
public static bool Walkthrough(BlockID block) {
|
||||||
return block == Air || block == Sapling || block == Block.Snow
|
return block == Air || block == Sapling || block == Block.Snow
|
||||||
|
@ -69,7 +69,11 @@ namespace MCGalaxy.Commands.World {
|
|||||||
{
|
{
|
||||||
byte block = lvl.blocks[x + lvl.Width * (z + y * lvl.Length)];
|
byte block = lvl.blocks[x + lvl.Width * (z + y * lvl.Length)];
|
||||||
temp.blocks[x + width * (z + y * length)] = block;
|
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;
|
if (block != Block.custom_block) continue;
|
||||||
|
#endif
|
||||||
|
|
||||||
byte extBlock = lvl.FastGetExtTile(x, y, z);
|
byte extBlock = lvl.FastGetExtTile(x, y, z);
|
||||||
temp.FastSetExtTile(x, y, z, extBlock);
|
temp.FastSetExtTile(x, y, z, extBlock);
|
||||||
|
@ -169,16 +169,25 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
|
|
||||||
int index = b.X + lvl.Width * (b.Z + b.Y * lvl.Length);
|
int index = b.X + lvl.Width * (b.Z + b.Y * lvl.Length);
|
||||||
BlockID old = lvl.blocks[index];
|
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.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
|
// 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;
|
if (old == b.Block || !lvl.CheckAffectPermissions(p, b.X, b.Y, b.Z, old, b.Block)) return;
|
||||||
|
|
||||||
// Set the block (inlined)
|
// Set the block (inlined)
|
||||||
lvl.Changed = true;
|
lvl.Changed = true;
|
||||||
if (b.Block >= Block.Extended) {
|
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;
|
lvl.blocks[index] = Block.custom_block;
|
||||||
|
#endif
|
||||||
lvl.FastSetExtTile(b.X, b.Y, b.Z, (BlockRaw)b.Block);
|
lvl.FastSetExtTile(b.X, b.Y, b.Z, (BlockRaw)b.Block);
|
||||||
} else {
|
} else {
|
||||||
lvl.blocks[index] = (BlockRaw)b.Block;
|
lvl.blocks[index] = (BlockRaw)b.Block;
|
||||||
|
@ -36,8 +36,8 @@ namespace MCGalaxy.Generator.Foliage {
|
|||||||
|
|
||||||
public override void SetData(Random rnd, int value) {
|
public override void SetData(Random rnd, int value) {
|
||||||
this.rnd = rnd;
|
this.rnd = rnd;
|
||||||
height = (byte)value;
|
height = value;
|
||||||
size = (byte)(maxExtent + maxCluster);
|
size = maxExtent + maxCluster;
|
||||||
|
|
||||||
branchBaseHeight = height / 4;
|
branchBaseHeight = height / 4;
|
||||||
branchAmount = rnd.Next(10, 25);
|
branchAmount = rnd.Next(10, 25);
|
||||||
|
@ -46,14 +46,24 @@ namespace MCGalaxy {
|
|||||||
/// <returns> Undefined behaviour if coordinates are invalid. </returns>
|
/// <returns> Undefined behaviour if coordinates are invalid. </returns>
|
||||||
public BlockID FastGetBlock(int index) {
|
public BlockID FastGetBlock(int index) {
|
||||||
byte raw = blocks[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));
|
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | GetExtTile(index));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets the block at the given coordinates. </summary>
|
/// <summary> Gets the block at the given coordinates. </summary>
|
||||||
/// <returns> Undefined behaviour if coordinates are invalid. </returns>
|
/// <returns> Undefined behaviour if coordinates are invalid. </returns>
|
||||||
public BlockID FastGetBlock(ushort x, ushort y, ushort z) {
|
public BlockID FastGetBlock(ushort x, ushort y, ushort z) {
|
||||||
byte raw = blocks[x + Width * (z + y * Length)];
|
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));
|
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets the block at the given coordinates. </summary>
|
/// <summary> Gets the block at the given coordinates. </summary>
|
||||||
@ -61,7 +71,13 @@ namespace MCGalaxy {
|
|||||||
public BlockID GetBlock(ushort x, ushort y, ushort z) {
|
public BlockID GetBlock(ushort x, ushort y, ushort z) {
|
||||||
if (x >= Width || y >= Height || z >= Length || blocks == null) return Block.Invalid;
|
if (x >= Width || y >= Height || z >= Length || blocks == null) return Block.Invalid;
|
||||||
byte raw = blocks[x + Width * (z + y * Length)];
|
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));
|
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets the block at the given coordinates. </summary>
|
/// <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; }
|
if (x >= Width || y >= Height || z >= Length || blocks == null) { index = -1; return Block.Invalid; }
|
||||||
index = x + Width * (z + y * Length);
|
index = x + Width * (z + y * Length);
|
||||||
byte raw = blocks[index];
|
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));
|
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>
|
/// <summary> Gets whether the block at the given coordinates is air. </summary>
|
||||||
@ -256,7 +278,11 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
errorLocation = "Setting tile";
|
errorLocation = "Setting tile";
|
||||||
if (block >= Block.Extended) {
|
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);
|
SetTile(x, y, z, Block.custom_block);
|
||||||
|
#endif
|
||||||
FastSetExtTile(x, y, z, (BlockRaw)block);
|
FastSetExtTile(x, y, z, (BlockRaw)block);
|
||||||
} else {
|
} else {
|
||||||
SetTile(x, y, z, (BlockRaw)block);
|
SetTile(x, y, z, (BlockRaw)block);
|
||||||
@ -310,7 +336,12 @@ namespace MCGalaxy {
|
|||||||
PhysicsArgs data = default(PhysicsArgs), bool addUndo = true) {
|
PhysicsArgs data = default(PhysicsArgs), bool addUndo = true) {
|
||||||
if (blocks == null || b < 0 || b >= blocks.Length) return false;
|
if (blocks == null || b < 0 || b >= blocks.Length) return false;
|
||||||
BlockID old = blocks[b];
|
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
|
try
|
||||||
{
|
{
|
||||||
@ -342,7 +373,11 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
Changed = true;
|
Changed = true;
|
||||||
if (block >= Block.Extended) {
|
if (block >= Block.Extended) {
|
||||||
|
#if TEN_BIT_BLOCKS
|
||||||
|
blocks[b] = Block.ExtendedClass[block >> Block.ExtendedShift];
|
||||||
|
#else
|
||||||
blocks[b] = Block.custom_block;
|
blocks[b] = Block.custom_block;
|
||||||
|
#endif
|
||||||
ushort x, y, z;
|
ushort x, y, z;
|
||||||
IntToPos(b, out x, out y, out z);
|
IntToPos(b, out x, out y, out z);
|
||||||
FastSetExtTile(x, y, z, (BlockRaw)block);
|
FastSetExtTile(x, y, z, (BlockRaw)block);
|
||||||
|
@ -152,9 +152,16 @@ namespace MCGalaxy {
|
|||||||
OnPhysicsUpdateEvent.Call(C.X, C.Y, C.Z, C.Data, this);
|
OnPhysicsUpdateEvent.Call(C.X, C.Y, C.Z, C.Data, this);
|
||||||
|
|
||||||
C.Block = blocks[chk.Index];
|
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) {
|
if (C.Block == Block.custom_block) {
|
||||||
C.Block = (BlockID)(Block.Extended | FastGetExtTile(C.X, C.Y, C.Z));
|
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)) {
|
if ((C.Data.Raw & mask) == 0 || C.Data.Type1 == PhysicsArgs.Custom || extraHandler(this, ref C)) {
|
||||||
HandlePhysics handler = handlers[C.Block];
|
HandlePhysics handler = handlers[C.Block];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user