TU31 feature: Nether Portals can be any rectangle from 4x5 to 23x23

This commit is contained in:
NSDeathman 2026-05-20 13:37:18 +04:00
parent c326eabbb4
commit 69dca59172
2 changed files with 167 additions and 62 deletions

View file

@ -101,97 +101,201 @@ bool PortalTile::validPortalFrame(Level* level, int x, int y, int z, int xd, int
return true; return true;
} }
bool PortalTile::trySpawnPortal(Level *level, int x, int y, int z, bool actuallySpawn) bool PortalTile::detectAndSpawnPortal(Level* level, int x, int y, int z, int axis, bool actuallySpawn) {
{ int baseX = x;
int xd = 0; int baseZ = z;
int zd = 0; int hCoord;
if (level->getTile(x - 1, y, z) == Tile::obsidian_Id || level->getTile(x + 1, y, z) == Tile::obsidian_Id) xd = 1; if (axis == 1) {
if (level->getTile(x, y, z - 1) == Tile::obsidian_Id || level->getTile(x, y, z + 1) == Tile::obsidian_Id) zd = 1; hCoord = x;
}
bool twoPosible = false; // two neth portals posible (x and z direction) else {
if (xd == zd) hCoord = z;
{
if (xd == 1) twoPosible = true;
else return false;
} }
bool changedx = false; // changed x so it can be reverted if two portals are posible int left = hCoord;
if (level->getTile(x - xd, y, z) == 0) while (true) {
{ int nextX = (axis == 1) ? left - 1 : baseX;
changedx = true; int nextZ = (axis == 0) ? left - 1 : baseZ;
x--; int tile = level->getTile(nextX, y, nextZ);
} if (tile == Tile::obsidian_Id) break;
else if (level->getTile(x, y, z - zd) == 0 && !twoPosible) if (tile != 0 && tile != Tile::fire_Id) return false;
{ left--;
z--; if (left < -30000000) return false;
} }
if (!twoPosible) int right = hCoord;
{ while (true) {
if (!validPortalFrame(level, x, y, z, xd, zd, actuallySpawn)) return false; int nextX = (axis == 1) ? right + 1 : baseX;
int nextZ = (axis == 0) ? right + 1 : baseZ;
int tile = level->getTile(nextX, y, nextZ);
if (tile == Tile::obsidian_Id) break;
if (tile != 0 && tile != Tile::fire_Id) return false;
right++;
if (right > 30000000) return false;
} }
else int interiorWidth = right - left + 1;
{
if (!validPortalFrame(level, x, y, z, xd, 0, actuallySpawn))
{
if (changedx) x++; // revert x (this check wants to check z not x and z)
if (level->getTile(x, y, z - zd) == 0) z--; int bottom = y;
while (true) {
int tileBelow = level->getTile((axis == 1) ? hCoord : baseX, bottom - 1, (axis == 0) ? hCoord : baseZ);
if (tileBelow == Tile::obsidian_Id) break;
if (tileBelow != 0 && tileBelow != Tile::fire_Id) return false;
bottom--;
if (bottom < -64) return false;
}
if (!validPortalFrame(level, x, y, z, 0, zd, actuallySpawn)) int top = y;
return false; while (true) {
int tileAbove = level->getTile((axis == 1) ? hCoord : baseX, top + 1, (axis == 0) ? hCoord : baseZ);
if (tileAbove == Tile::obsidian_Id) break;
if (tileAbove != 0 && tileAbove != Tile::fire_Id) return false;
top++;
if (top > 320) return false;
}
int interiorHeight = top - bottom + 1;
if (interiorWidth < 2 || interiorWidth > 21) return false;
if (interiorHeight < 3 || interiorHeight > 21) return false;
for (int cy = bottom; cy <= top; cy++) {
int obsX = (axis == 1) ? left - 1 : baseX;
int obsZ = (axis == 0) ? left - 1 : baseZ;
if (level->getTile(obsX, cy, obsZ) != Tile::obsidian_Id) return false;
}
for (int cy = bottom; cy <= top; cy++) {
int obsX = (axis == 1) ? right + 1 : baseX;
int obsZ = (axis == 0) ? right + 1 : baseZ;
if (level->getTile(obsX, cy, obsZ) != Tile::obsidian_Id) return false;
}
for (int cx = left; cx <= right; cx++) {
int obsX = (axis == 1) ? cx : baseX;
int obsZ = (axis == 0) ? cx : baseZ;
if (level->getTile(obsX, bottom - 1, obsZ) != Tile::obsidian_Id) return false;
}
for (int cx = left; cx <= right; cx++) {
int obsX = (axis == 1) ? cx : baseX;
int obsZ = (axis == 0) ? cx : baseZ;
if (level->getTile(obsX, top + 1, obsZ) != Tile::obsidian_Id) return false;
}
for (int cx = left; cx <= right; cx++) {
for (int cy = bottom; cy <= top; cy++) {
int tile = level->getTile(
(axis == 1) ? cx : baseX,
cy,
(axis == 0) ? cx : baseZ
);
if (tile != 0 && tile != Tile::fire_Id) return false;
}
}
if (actuallySpawn) {
for (int cx = left; cx <= right; cx++) {
for (int cy = bottom; cy <= top; cy++) {
int px = (axis == 1) ? cx : baseX;
int pz = (axis == 0) ? cx : baseZ;
level->setTileAndData(px, cy, pz, Tile::portalTile_Id, 0, Tile::UPDATE_CLIENTS);
}
} }
} }
return true; return true;
} }
void PortalTile::neighborChanged(Level *level, int x, int y, int z, int type) bool PortalTile::trySpawnPortal(Level* level, int x, int y, int z, bool actuallySpawn) {
{ int centerTile = level->getTile(x, y, z);
int xd = 0; if (centerTile != 0 && centerTile != Tile::fire_Id) return false;
int zd = 1;
if (level->getTile(x - 1, y, z) == id || level->getTile(x + 1, y, z) == id) if (detectAndSpawnPortal(level, x, y, z, 1, actuallySpawn)) return true; // X
{ if (detectAndSpawnPortal(level, x, y, z, 0, actuallySpawn)) return true; // Z
xd = 1;
zd = 0; return false;
}
void PortalTile::neighborChanged(Level* level, int x, int y, int z, int type) {
int axis = -1; // 0:Z, 1:X
if (level->getTile(x - 1, y, z) == id || level->getTile(x + 1, y, z) == id) {
axis = 1;
} }
else if (level->getTile(x, y, z - 1) == id || level->getTile(x, y, z + 1) == id) {
int yBottom = y; axis = 0;
while (level->getTile(x, yBottom - 1, z) == id) }
yBottom--; else {
if (level->getTile(x, yBottom - 1, z) != Tile::obsidian_Id)
{
level->removeTile(x, y, z); level->removeTile(x, y, z);
return; return;
} }
int height = 1; int bottomY = y;
while (height < 4 && level->getTile(x, yBottom + height, z) == id) while (level->getTile(x, bottomY - 1, z) == id) bottomY--;
height++; if (level->getTile(x, bottomY - 1, z) != Tile::obsidian_Id) {
if (height != 3 || level->getTile(x, yBottom + height, z) != Tile::obsidian_Id)
{
level->removeTile(x, y, z); level->removeTile(x, y, z);
return; return;
} }
bool we = level->getTile(x - 1, y, z) == id || level->getTile(x + 1, y, z) == id; int topY = y;
bool ns = level->getTile(x, y, z - 1) == id || level->getTile(x, y, z + 1) == id; while (level->getTile(x, topY + 1, z) == id) topY++;
if (we && ns) if (level->getTile(x, topY + 1, z) != Tile::obsidian_Id) {
{ level->removeTile(x, y, z);
return;
}
int height = topY - bottomY + 1;
if (height < 3 || height > 21) {
level->removeTile(x, y, z); level->removeTile(x, y, z);
return; return;
} }
if (!(// int baseX = x, baseZ = z;
(level->getTile(x + xd, y, z + zd) == Tile::obsidian_Id && level->getTile(x - xd, y, z - zd) == id) || // int hCoord = (axis == 1) ? x : z;
(level->getTile(x - xd, y, z - zd) == Tile::obsidian_Id && level->getTile(x + xd, y, z + zd) == id)// int left = hCoord, right = hCoord;
))
{ while (true) {
int nx = (axis == 1) ? left - 1 : baseX;
int nz = (axis == 0) ? left - 1 : baseZ;
int tile = level->getTile(nx, y, nz);
if (tile == Tile::obsidian_Id) break;
if (tile != id) {
level->removeTile(x, y, z);
return;
}
left--;
}
while (true) {
int nx = (axis == 1) ? right + 1 : baseX;
int nz = (axis == 0) ? right + 1 : baseZ;
int tile = level->getTile(nx, y, nz);
if (tile == Tile::obsidian_Id) break;
if (tile != id) {
level->removeTile(x, y, z);
return;
}
right++;
}
int width = right - left + 1;
if (width < 2 || width > 21) {
level->removeTile(x, y, z); level->removeTile(x, y, z);
return; return;
} }
for (int cy = bottomY; cy <= topY; cy++) {
if (level->getTile((axis == 1) ? left - 1 : baseX, cy, (axis == 0) ? left - 1 : baseZ) != Tile::obsidian_Id) { level->removeTile(x, y, z); return; }
if (level->getTile((axis == 1) ? right + 1 : baseX, cy, (axis == 0) ? right + 1 : baseZ) != Tile::obsidian_Id) { level->removeTile(x, y, z); return; }
}
for (int cx = left; cx <= right; cx++) {
if (level->getTile((axis == 1) ? cx : baseX, bottomY - 1, (axis == 0) ? cx : baseZ) != Tile::obsidian_Id) { level->removeTile(x, y, z); return; }
if (level->getTile((axis == 1) ? cx : baseX, topY + 1, (axis == 0) ? cx : baseZ) != Tile::obsidian_Id) { level->removeTile(x, y, z); return; }
}
for (int cx = left; cx <= right; cx++) {
for (int cy = bottomY; cy <= topY; cy++) {
int tile = level->getTile((axis == 1) ? cx : baseX, cy, (axis == 0) ? cx : baseZ);
if (tile != id && tile != 0 && tile != Tile::fire_Id) {
level->removeTile(x, y, z);
return;
}
}
}
} }
bool PortalTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face) bool PortalTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face)

View file

@ -14,6 +14,7 @@ public:
virtual bool isSolidRender(bool isServerLevel = false); virtual bool isSolidRender(bool isServerLevel = false);
virtual bool isCubeShaped(); virtual bool isCubeShaped();
virtual bool validPortalFrame(Level* level, int x, int y, int z, int xd, int zd, bool actuallySpawn); virtual bool validPortalFrame(Level* level, int x, int y, int z, int xd, int zd, bool actuallySpawn);
bool detectAndSpawnPortal(Level* level, int x, int y, int z, int axis, bool actuallySpawn);
virtual bool trySpawnPortal(Level *level, int x, int y, int z, bool actuallySpawn); virtual bool trySpawnPortal(Level *level, int x, int y, int z, bool actuallySpawn);
virtual void neighborChanged(Level *level, int x, int y, int z, int type); virtual void neighborChanged(Level *level, int x, int y, int z, int type);
virtual bool shouldRenderFace(LevelSource *level, int x, int y, int z, int face); virtual bool shouldRenderFace(LevelSource *level, int x, int y, int z, int face);