Fix cuboid holes.

This commit is contained in:
UnknownShadow200 2015-12-19 16:36:03 +11:00
parent a98c35fbef
commit 002e114a6d
4 changed files with 60 additions and 52 deletions

View File

@ -91,25 +91,21 @@ namespace MCGalaxy.Commands
switch (cpos.solid) {
case SolidType.solid:
drawOp = new CuboidDrawOp();
brush = new SolidBrush(type); break;
drawOp = new CuboidDrawOp(); break;
case SolidType.hollow:
drawOp = new CuboidHollowsDrawOp();
brush = new SolidBrush(type); break;
drawOp = new CuboidHollowsDrawOp(); break;
case SolidType.walls:
drawOp = new CuboidWallsDrawOp();
brush = new SolidBrush(type); break;
drawOp = new CuboidWallsDrawOp(); break;
case SolidType.holes:
drawOp = new CuboidDrawOp();
brush = new HolesBrush(type); break;
drawOp = new CuboidHolesDrawOp(); break;
case SolidType.wire:
drawOp = new CuboidWireframeDrawOp();
brush = new SolidBrush(type); break;
drawOp = new CuboidWireframeDrawOp(); break;
case SolidType.random:
drawOp = new CuboidDrawOp();
brush = new RandomBrush(type); break;
}
if (brush == null) brush = new SolidBrush(type);
ushort x1 = Math.Min(cpos.x, x), x2 = Math.Max(cpos.x, x);
ushort y1 = Math.Min(cpos.y, y), y2 = Math.Max(cpos.y, y);
ushort z1 = Math.Min(cpos.z, z), z2 = Math.Max(cpos.z, z);

View File

@ -36,20 +36,6 @@ namespace MCGalaxy {
}
}
public sealed class HolesBrush : Brush {
readonly byte block;
public HolesBrush(byte block) {
this.block = block;
}
int i = 0;
public override byte NextBlock() {
i++;
return (i & 1) == 0 ? Block.air : block;
}
}
public sealed class RainbowBrush : Brush {
readonly Random rnd;

View File

@ -35,7 +35,34 @@ namespace MCGalaxy {
for (ushort z = z1; z <= z2; z++)
for (ushort x = x1; x <= x2; x++)
{
PlaceBlock(p, lvl, x, y, z, brush);
PlaceBlock(p, lvl, x, y, z, brush.NextBlock());
}
}
}
public class CuboidHolesDrawOp : DrawOp {
public override string Name {
get { return "Cuboid Holes"; }
}
public override int GetBlocksAffected(ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
return (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1);
}
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
for (ushort y = y1; y <= y2; y++)
for (ushort z = z1; z <= z2; z++)
{
int i = (y & 1) == 0 ? 0 : 1;
if ((z & 1) == 0) i++;
for (ushort x = x1; x <= x2; x++) {
byte block = (i & 1) == 0 ? brush.NextBlock() : Block.air;
PlaceBlock(p, lvl, x, y, z, block);
i++;
}
}
}
}
@ -47,7 +74,7 @@ namespace MCGalaxy {
}
public override int GetBlocksAffected(ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
int lenX = (x2 - x1 + 1), lenY = (y2 - y1 + 1), lenZ = (z2 - z2 + 1);
int lenX = (x2 - x1 + 1), lenY = (y2 - y1 + 1), lenZ = (z2 - z2 + 1);
int xQuadsVol = Math.Min(lenX, 2) * (lenY * lenZ);
int yQuadsVol = Math.Max(0, Math.Min(lenY, 2) * ((lenX - 2) * lenZ)); // we need to avoid double counting overlaps
int zQuadzVol = Math.Max(0, Math.Min(lenZ, 2) * ((lenX - 2) * (lenY - 2)));
@ -64,37 +91,37 @@ namespace MCGalaxy {
QuadX(x2, (ushort)(y1 + 1), z1, (ushort)(y2 - 1), z2, p, lvl, brush);
}
if (lenX > 2 && lenY > 2) {
QuadZ(z1, (ushort)(x1 + 1), (ushort)(y1 + 1),
QuadZ(z1, (ushort)(x1 + 1), (ushort)(y1 + 1),
(ushort)(x2 - 1), (ushort)(y2 - 1), p, lvl, brush);
QuadZ(z2, (ushort)(x1 + 1), (ushort)(y1 + 1),
QuadZ(z2, (ushort)(x1 + 1), (ushort)(y1 + 1),
(ushort)(x2 - 1), (ushort)(y2 - 1), p, lvl, brush);
}
}
}
protected void QuadX(ushort x, ushort y1, ushort z1, ushort y2, ushort z2,
Player p, Level lvl, Brush brush) {
Player p, Level lvl, Brush brush) {
for (ushort y = y1; y <= y2; y++)
for (ushort z = z1; z <= z2; z++)
{
PlaceBlock(p, lvl, x, y, z, brush);
PlaceBlock(p, lvl, x, y, z, brush.NextBlock());
}
}
protected void QuadY(ushort y, ushort x1, ushort z1, ushort x2, ushort z2,
Player p, Level lvl, Brush brush) {
Player p, Level lvl, Brush brush) {
for (ushort z = z1; z <= z2; z++)
for (ushort x = x1; x <= x2; x++)
{
PlaceBlock(p, lvl, x, y, z, brush);
PlaceBlock(p, lvl, x, y, z, brush.NextBlock());
}
}
}
protected void QuadZ(ushort z, ushort x1, ushort y1, ushort x2, ushort y2,
Player p, Level lvl, Brush brush) {
Player p, Level lvl, Brush brush) {
for (ushort y = y1; y <= y2; y++)
for (ushort x = x1; x <= x2; x++)
{
PlaceBlock(p, lvl, x, y, z, brush);
PlaceBlock(p, lvl, x, y, z, brush.NextBlock());
}
}
}
@ -106,7 +133,7 @@ namespace MCGalaxy {
}
public override int GetBlocksAffected(ushort x1, ushort y1, ushort z1, ushort x2, ushort y2, ushort z2) {
int lenX = (x2 - x1 + 1), lenY = (y2 - y1 + 1), lenZ = (z2 - z2 + 1);
int lenX = (x2 - x1 + 1), lenY = (y2 - y1 + 1), lenZ = (z2 - z2 + 1);
int xQuadsVol = Math.Min(lenX, 2) * (lenY * lenZ);
int zQuadsVol = Math.Max(0, Math.Min(lenZ, 2) * ((lenX - 2) * lenY)); // we need to avoid double counting overlaps
return xQuadsVol + zQuadsVol;
@ -120,7 +147,7 @@ namespace MCGalaxy {
if (lenX > 2) {
QuadZ(z1, (ushort)(x1 + 1), y1, (ushort)(x2 - 1), y2, p, lvl, brush);
QuadZ(z2, (ushort)(x1 + 1), y1, (ushort)(x2 - 1), y2, p, lvl, brush);
}
}
}
}
@ -140,24 +167,24 @@ namespace MCGalaxy {
public override void Perform(ushort x1, ushort y1, ushort z1, ushort x2,
ushort y2, ushort z2, Player p, Level lvl, Brush brush) {
for (ushort y = y1; y <= y2; y++ ) {
PlaceBlock(p, lvl, x1, y, z1, brush);
PlaceBlock(p, lvl, x2, y, z1, brush);
PlaceBlock(p, lvl, x1, y, z2, brush);
PlaceBlock(p, lvl, x2, y, z2, brush);
PlaceBlock(p, lvl, x1, y, z1, brush.NextBlock());
PlaceBlock(p, lvl, x2, y, z1, brush.NextBlock());
PlaceBlock(p, lvl, x1, y, z2, brush.NextBlock());
PlaceBlock(p, lvl, x2, y, z2, brush.NextBlock());
}
for (ushort z = z1; z <= z2; z++) {
PlaceBlock(p, lvl, x1, y1, z, brush);
PlaceBlock(p, lvl, x2, y1, z, brush);
PlaceBlock(p, lvl, x1, y2, z, brush);
PlaceBlock(p, lvl, x2, y2, z, brush);
PlaceBlock(p, lvl, x1, y1, z, brush.NextBlock());
PlaceBlock(p, lvl, x2, y1, z, brush.NextBlock());
PlaceBlock(p, lvl, x1, y2, z, brush.NextBlock());
PlaceBlock(p, lvl, x2, y2, z, brush.NextBlock());
}
for (ushort x = x1; x <= x2; x++) {
PlaceBlock(p, lvl, x, y1, z1, brush);
PlaceBlock(p, lvl, x, y1, z2, brush);
PlaceBlock(p, lvl, x, y2, z1, brush);
PlaceBlock(p, lvl, x, y2, z2, brush);
PlaceBlock(p, lvl, x, y1, z1, brush.NextBlock());
PlaceBlock(p, lvl, x, y1, z2, brush.NextBlock());
PlaceBlock(p, lvl, x, y2, z1, brush.NextBlock());
PlaceBlock(p, lvl, x, y2, z2, brush.NextBlock());
}
}
}

View File

@ -61,8 +61,7 @@ namespace MCGalaxy {
TotalModified = 0;
}
protected void PlaceBlock(Player p, Level lvl, ushort x, ushort y, ushort z, Brush brush) {
byte type = brush.NextBlock();
protected void PlaceBlock(Player p, Level lvl, ushort x, ushort y, ushort z, byte type) {
if (type == Block.Zero)
return;