Files
SteamWar/HiderCore/src/de/steamwar/hullhider/HullRegion.java
T
YoyoNow d1fb4ca67e Allow removing hulls and resend their chunks
HullHider#removeHull stops hiding a hull: it shows the entities and REntities
the hull hid and resends its chunks to everybody who could not view it. A hull
is enabled again by adding and initialising it.

Hull#resendChunks only resends chunks the player has loaded. HullHider now
resends the chunks to non-viewers after initialising a hull itself, so
FightHullHider no longer does it.
2026-10-31 15:09:04 +01:00

114 lines
3.5 KiB
Java

/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.hullhider;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.bukkit.Location;
/**
* Immutable block box a {@link Hull} covers. The minimum is inclusive, the maximum exclusive.
*/
@Getter
@AllArgsConstructor
public final class HullRegion {
public static HullRegion fromSize(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) {
return new HullRegion(minX, minY, minZ, minX + sizeX, minY + sizeY, minZ + sizeZ);
}
public static HullRegion fromInclusive(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) {
return new HullRegion(minX, minY, minZ, maxX + 1, maxY + 1, maxZ + 1);
}
private final int minX;
private final int minY;
private final int minZ;
private final int maxX;
private final int maxY;
private final int maxZ;
public int getSizeX() {
return maxX - minX;
}
public int getSizeY() {
return maxY - minY;
}
public int getSizeZ() {
return maxZ - minZ;
}
public int volume() {
return getSizeX() * getSizeY() * getSizeZ();
}
public boolean contains(int x, int y, int z) {
return minX <= x && x < maxX && minY <= y && y < maxY && minZ <= z && z < maxZ;
}
public boolean contains(Location location) {
return contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
public boolean chunkOutside(int chunkX, int chunkZ) {
return chunkX < (minX >> 4) || chunkX > ((maxX - 1) >> 4) || chunkZ < (minZ >> 4) || chunkZ > ((maxZ - 1) >> 4);
}
/**
* @return the index of the block within a bitset of {@link #volume()} bits, only valid for contained blocks
*/
public int toIndex(int x, int y, int z) {
return ((y - minY) * getSizeZ() + (z - minZ)) * getSizeX() + (x - minX);
}
public void forEach(BlockConsumer executor) {
for (int x = minX; x < maxX; x++) {
for (int y = minY; y < maxY; y++) {
for (int z = minZ; z < maxZ; z++) {
executor.accept(x, y, z);
}
}
}
}
public void forEachChunk(ChunkConsumer executor) {
for (int chunkX = minX >> 4; chunkX <= (maxX - 1) >> 4; chunkX++) {
for (int chunkZ = minZ >> 4; chunkZ <= (maxZ - 1) >> 4; chunkZ++) {
executor.accept(chunkX, chunkZ);
}
}
}
public interface BlockConsumer {
void accept(int x, int y, int z);
}
public interface ChunkConsumer {
void accept(int chunkX, int chunkZ);
}
@Override
public String toString() {
return minX + "," + minY + "," + minZ + "->" + maxX + "," + maxY + "," + maxZ;
}
}