mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 20:16:36 -04:00
minor code cleanup
This commit is contained in:
parent
59582dd187
commit
d9b2679608
@ -45,7 +45,7 @@ namespace MCGalaxy.Commands.World {
|
||||
Help(p); return;
|
||||
}
|
||||
|
||||
Player.Message(p, "Fixed " + totalFixed + " blocks.");
|
||||
Player.Message(p, "Fixed " + totalFixed + " blocks");
|
||||
}
|
||||
|
||||
static void Fix(Player p, Level lvl, ref int totalFixed, bool fixGrass, bool fixDirt) {
|
||||
@ -57,29 +57,19 @@ namespace MCGalaxy.Commands.World {
|
||||
for (ushort z = 0; z < lvl.Length; z++)
|
||||
for (ushort x = 0; x < lvl.Width; x++)
|
||||
{
|
||||
block = lvl.blocks[index];
|
||||
if (block == Block.custom_block) {
|
||||
block = (ushort)(Block.Extended | lvl.GetExtTileNoCheck(x, y, z));
|
||||
}
|
||||
|
||||
block = lvl.FastGetBlock(index);
|
||||
if (fixGrass && lvl.Props[block].GrassBlock != Block.Invalid) {
|
||||
above = y == maxY ? Block.Air : lvl.blocks[index + oneY];
|
||||
if (above == Block.custom_block) {
|
||||
above = (ushort)(Block.Extended | lvl.GetExtTileNoCheck(x, (ushort)(y + 1), z));
|
||||
}
|
||||
|
||||
above = y == maxY ? Block.Air : lvl.FastGetBlock(index + oneY);
|
||||
BlockID grass = lvl.Props[block].GrassBlock;
|
||||
|
||||
if (lvl.LightPasses(above) && p.level.DoBlockchange(p, x, y, z, grass) == 2) {
|
||||
buffer.Add(index, grass);
|
||||
totalFixed++;
|
||||
}
|
||||
} else if (fixDirt && lvl.Props[block].DirtBlock != Block.Invalid) {
|
||||
above = y == maxY ? Block.Air : lvl.blocks[index + oneY];
|
||||
if (above == Block.custom_block) {
|
||||
above= (ushort)(Block.Extended | lvl.GetExtTileNoCheck(x, (ushort)(y + 1), z));
|
||||
}
|
||||
|
||||
above = y == maxY ? Block.Air : lvl.FastGetBlock(index + oneY);
|
||||
BlockID dirt = lvl.Props[block].DirtBlock;
|
||||
|
||||
if (!lvl.LightPasses(above) && p.level.DoBlockchange(p, x, y, z, dirt) == 2) {
|
||||
buffer.Add(index, dirt);
|
||||
totalFixed++;
|
||||
@ -91,7 +81,7 @@ namespace MCGalaxy.Commands.World {
|
||||
}
|
||||
|
||||
static void FixLight(Player p, Level lvl, ref int totalFixed) {
|
||||
int index = 0;
|
||||
int index = 0, oneY = lvl.Width * lvl.Length;
|
||||
BufferedBlockSender buffer = new BufferedBlockSender(lvl);
|
||||
BlockID above, block;
|
||||
|
||||
@ -99,40 +89,29 @@ namespace MCGalaxy.Commands.World {
|
||||
for (ushort z = 0; z < lvl.Length; z++)
|
||||
for (ushort x = 0; x < lvl.Width; x++)
|
||||
{
|
||||
block = lvl.blocks[index];
|
||||
block = lvl.FastGetBlock(index);
|
||||
bool inShadow = false;
|
||||
if (block == Block.custom_block) {
|
||||
block = (ushort)(Block.Extended | lvl.GetExtTileNoCheck(x, y, z));
|
||||
}
|
||||
|
||||
if (lvl.Props[block].GrassBlock != Block.Invalid) {
|
||||
for (int i = 1; i < (lvl.Height - y); i++) {
|
||||
above = lvl.blocks[index + (lvl.Width * lvl.Length) * i];
|
||||
if (above == Block.custom_block) {
|
||||
above = (ushort)(Block.Extended | lvl.GetExtTileNoCheck(x, (ushort)(y + i), z));
|
||||
}
|
||||
|
||||
above = lvl.FastGetBlock(index + oneY * i);
|
||||
if (!lvl.LightPasses(above)) { inShadow = true; break; }
|
||||
}
|
||||
|
||||
BlockID grass = lvl.Props[block].GrassBlock;
|
||||
if (!inShadow && p.level.DoBlockchange(p, x, y, z, grass) == 2) {
|
||||
buffer.Add(index, grass);
|
||||
buffer.Add(lvl.PosToInt(x, y, z), grass);
|
||||
totalFixed++;
|
||||
}
|
||||
} else if (lvl.Props[block].DirtBlock != Block.Invalid) {
|
||||
for (int i = 1; i < (lvl.Height - y); i++) {
|
||||
above = lvl.blocks[index + (lvl.Width * lvl.Length) * i];
|
||||
if (above == Block.custom_block) {
|
||||
above = (ushort)(Block.Extended | lvl.GetExtTileNoCheck(x, (ushort)(y + i), z));
|
||||
}
|
||||
|
||||
above = lvl.FastGetBlock(index + oneY * i);
|
||||
if (!lvl.LightPasses(above)) { inShadow = true; break; }
|
||||
}
|
||||
|
||||
BlockID dirt = lvl.Props[block].DirtBlock;
|
||||
if (inShadow && p.level.DoBlockchange(p, x, y, z, dirt) == 2) {
|
||||
buffer.Add(index, dirt);
|
||||
buffer.Add(lvl.PosToInt(x, y, z), dirt);
|
||||
totalFixed++;
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ namespace MCGalaxy.Commands.World {
|
||||
temp.blocks[x + width * (z + y * length)] = block;
|
||||
if (block != Block.custom_block) continue;
|
||||
|
||||
byte extBlock = lvl.GetExtTileNoCheck(x, y, z);
|
||||
temp.SetExtTileNoCheck(x, y, z, extBlock);
|
||||
byte extBlock = lvl.FastGetExtTile(x, y, z);
|
||||
temp.FastSetExtTile(x, y, z, extBlock);
|
||||
}
|
||||
|
||||
temp.spawnx = lvl.spawnx; temp.spawny = lvl.spawny; temp.spawnz = lvl.spawnz;
|
||||
|
@ -169,7 +169,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
|
||||
int index = b.X + lvl.Width * (b.Z + b.Y * lvl.Length);
|
||||
BlockID old = lvl.blocks[index];
|
||||
if (old == Block.custom_block) old = (BlockID)(Block.Extended | lvl.GetExtTileNoCheck(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;
|
||||
|
||||
// Check to make sure the block is actually different and that we can change it
|
||||
@ -179,7 +179,7 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
lvl.Changed = true;
|
||||
if (b.Block >= Block.Extended) {
|
||||
lvl.blocks[index] = Block.custom_block;
|
||||
lvl.SetExtTileNoCheck(b.X, b.Y, b.Z, (BlockRaw)b.Block);
|
||||
lvl.FastSetExtTile(b.X, b.Y, b.Z, (BlockRaw)b.Block);
|
||||
} else {
|
||||
lvl.blocks[index] = (BlockRaw)b.Block;
|
||||
if (old >= Block.Extended) {
|
||||
|
@ -38,23 +38,16 @@ namespace MCGalaxy.Drawing.Ops {
|
||||
public Level Source;
|
||||
|
||||
public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
|
||||
Max.X = Math.Min(Max.X, Source.Width - 1);
|
||||
Max.X = Math.Min(Max.X, Source.Width - 1);
|
||||
Max.Y = Math.Min(Max.Y, Source.Height - 1);
|
||||
Max.Z = Math.Min(Max.Z, Source.Length - 1);
|
||||
|
||||
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||
int width = Source.Width, length = Source.Length;
|
||||
byte[] blocks = Source.blocks;
|
||||
|
||||
Vec3U16 p1 = Clamp(Min), p2 = Clamp(Max);
|
||||
for (ushort y = p1.Y; y <= p2.Y; y++)
|
||||
for (ushort z = p1.Z; z <= p2.Z; z++)
|
||||
for (ushort x = p1.X; x <= p2.X; x++)
|
||||
{
|
||||
BlockID block = blocks[x + width * (z + y * length)];
|
||||
if (block == Block.custom_block) {
|
||||
block = (BlockID)(Block.Extended | Source.GetExtTileNoCheck(x, y, z));
|
||||
}
|
||||
output(Place(x, y, z, block));
|
||||
output(Place(x, y, z, Source.FastGetBlock(x, y, z)));
|
||||
}
|
||||
|
||||
Source.Dispose();
|
||||
|
@ -62,7 +62,7 @@ namespace MCGalaxy.Levels.IO {
|
||||
|
||||
blocks[i] = Block.custom_block;
|
||||
lvl.IntToPos(i, out x, out y, out z);
|
||||
lvl.SetExtTileNoCheck(x, y, z, raw);
|
||||
lvl.FastSetExtTile(x, y, z, raw);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,12 +42,26 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Gets the block at the given coordinates. </summary>
|
||||
/// <returns> Undefined behaviour if coordinates are invalid. </returns>
|
||||
public BlockID FastGetBlock(int index) {
|
||||
byte raw = blocks[index];
|
||||
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | GetExtTile(index));
|
||||
}
|
||||
|
||||
/// <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)];
|
||||
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
|
||||
}
|
||||
|
||||
/// <summary> Gets the block at the given coordinates. </summary>
|
||||
/// <returns> Block.Invalid if coordinates outside map. </returns>
|
||||
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)];
|
||||
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | GetExtTileNoCheck(x, y, z));
|
||||
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
|
||||
}
|
||||
|
||||
/// <summary> Gets the block at the given coordinates. </summary>
|
||||
@ -56,7 +70,7 @@ 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];
|
||||
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | GetExtTileNoCheck(x, y, z));
|
||||
return raw != Block.custom_block ? raw : (BlockID)(Block.Extended | FastGetExtTile(x, y, z));
|
||||
}
|
||||
|
||||
/// <summary> Gets whether the block at the given coordinates is air. </summary>
|
||||
@ -81,7 +95,7 @@ namespace MCGalaxy {
|
||||
return chunk == null ? Block.Air : chunk[(y & 0x0F) << 8 | (z & 0x0F) << 4 | (x & 0x0F)];
|
||||
}
|
||||
|
||||
public byte GetExtTileNoCheck(ushort x, ushort y, ushort z) {
|
||||
public byte FastGetExtTile(ushort x, ushort y, ushort z) {
|
||||
int cx = x >> 4, cy = y >> 4, cz = z >> 4;
|
||||
byte[] chunk = CustomBlocks[(cy * ChunksZ + cz) * ChunksX + cx];
|
||||
return chunk == null ? Block.Air : chunk[(y & 0x0F) << 8 | (z & 0x0F) << 4 | (x & 0x0F)];
|
||||
@ -115,10 +129,10 @@ namespace MCGalaxy {
|
||||
public void SetExtTile(ushort x, ushort y, ushort z, byte extBlock) {
|
||||
int index = PosToInt(x, y, z);
|
||||
if (index < 0 || blocks == null) return;
|
||||
SetExtTileNoCheck(x, y, z, extBlock);
|
||||
FastSetExtTile(x, y, z, extBlock);
|
||||
}
|
||||
|
||||
public void SetExtTileNoCheck(ushort x, ushort y, ushort z, byte extBlock) {
|
||||
public void FastSetExtTile(ushort x, ushort y, ushort z, byte extBlock) {
|
||||
int cx = x >> 4, cy = y >> 4, cz = z >> 4;
|
||||
int cIndex = (cy * ChunksZ + cz) * ChunksX + cx;
|
||||
byte[] chunk = CustomBlocks[cIndex];
|
||||
@ -249,7 +263,7 @@ namespace MCGalaxy {
|
||||
errorLocation = "Setting tile";
|
||||
if (block >= Block.Extended) {
|
||||
SetTile(x, y, z, Block.custom_block);
|
||||
SetExtTileNoCheck(x, y, z, (BlockRaw)block);
|
||||
FastSetExtTile(x, y, z, (BlockRaw)block);
|
||||
} else {
|
||||
SetTile(x, y, z, (BlockRaw)block);
|
||||
if (old >= Block.Extended) {
|
||||
@ -337,7 +351,7 @@ namespace MCGalaxy {
|
||||
blocks[b] = Block.custom_block;
|
||||
ushort x, y, z;
|
||||
IntToPos(b, out x, out y, out z);
|
||||
SetExtTileNoCheck(x, y, z, (BlockRaw)block);
|
||||
FastSetExtTile(x, y, z, (BlockRaw)block);
|
||||
} else {
|
||||
blocks[b] = (BlockRaw)block;
|
||||
if (old >= Block.Extended) {
|
||||
|
@ -153,7 +153,7 @@ namespace MCGalaxy {
|
||||
|
||||
C.Block = blocks[chk.Index];
|
||||
if (C.Block == Block.custom_block) {
|
||||
C.Block = (BlockID)(Block.Extended | GetExtTileNoCheck(C.X, C.Y, C.Z));
|
||||
C.Block = (BlockID)(Block.Extended | FastGetExtTile(C.X, C.Y, C.Z));
|
||||
}
|
||||
|
||||
if ((C.Data.Raw & mask) == 0 || C.Data.Type1 == PhysicsArgs.Custom || extraHandler(this, ref C)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user