Add light level overlay variants, set default to connected

This commit is contained in:
OrderedSet committed 2026-11-07 22:59:28 -08:00
1 parent 514af5669c
commit d04718c5c6
10 files changed
+567 -102

No files matched your search

@@ -13,17 +13,16 @@ import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.SpawnerAnimals;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import org.lwjgl.opengl.GL11;
import com.cardinalstar.cubicchunks.world.api.IMinMaxHeight;
import codechicken.lib.math.MathHelper;
import codechicken.nei.KeyManager.IKeyStateTracker;
import cpw.mods.fml.relauncher.ReflectionHelper;
@@ -32,8 +31,8 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
public static int chunkOverlay = 0;
public static int mobOverlay = 0;
private static byte[] mobSpawnCache;
private static long mobOverlayUpdateTime;
private static final MobSpawnScan mobSpawnScan = new MobSpawnScan();
private static final MobSpawnMarkedFace markedFace = new MobSpawnMarkedFace();
public static void reset() {
mobOverlay = 0;
@@ -82,51 +81,6 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
GL11.glPopAttrib();
}
private static void buildMobSpawnOverlay(Entity entity) {
if (mobSpawnCache == null) {
mobSpawnCache = new byte[33 * 33 * 33]; // 35kB
}
World world = entity.worldObj;
int worldHeight = world.getHeight();
int x1 = (int) entity.posX;
int z1 = (int) entity.posZ;
int y1 = (int) MathHelper.clip(entity.posY, 16, worldHeight - 16);
for (int i = 0; i <= 32; i++) {
int x = x1 - 16 + i;
for (int j = 0; j <= 32; j++) {
int z = z1 - 16 + j;
int bufIndex = (i * 33 + j) * 33;
Chunk chunk = world.getChunkFromBlockCoords(x, z);
BiomeGenBase biome = world.getBiomeGenForCoords(x, z);
if (biome.getSpawnableList(EnumCreatureType.monster).isEmpty() || biome.getSpawningChance() <= 0) {
mobSpawnCache[bufIndex] = -1;
continue;
}
int maxHeight = chunk.worldObj.getHeightValue(x, z);
for (int k = 0; k <= 32; k++) {
int y = y1 - 16 + k;
if (y >= worldHeight) {
mobSpawnCache[bufIndex + k] = -1;
continue;
}
if (y > maxHeight) {
mobSpawnCache[bufIndex + k] = -1;
break;
}
mobSpawnCache[bufIndex + k] = getSpawnMode(chunk, x, y, z);
}
}
}
}
private static double getOverlayYOffset(World world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (block instanceof BlockSnow) {
@@ -138,70 +92,91 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
private static void renderMobSpawnOverlay(Entity entity, int intOffsetX, int intOffsetY, int intOffsetZ) {
if (mobOverlay == 0) {
if (mobSpawnCache != null) {
mobSpawnCache = null;
}
mobSpawnScan.clear();
return;
}
long worldTime = entity.worldObj.getTotalWorldTime();
if (mobSpawnCache == null || mobOverlayUpdateTime != worldTime) {
mobOverlayUpdateTime = worldTime;
buildMobSpawnOverlay(entity);
}
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glLineWidth(1.5F);
int curSpawnMode = 2;
World world = entity.worldObj;
int x1 = (int) entity.posX - intOffsetX;
int z1 = (int) entity.posZ - intOffsetZ;
int y1 = (int) MathHelper.clip(entity.posY, 16, world.getHeight() - 16) - intOffsetY;
mobSpawnScan.update(entity, NEIClientConfig.getIntSetting("world.overlays.mobSpawnRadius"));
final MobSpawnOverlayStyle style = MobSpawnOverlayStyle
.parseStyle(NEIClientConfig.getSetting("world.overlays.mobSpawnStyle").getValue());
beginMobSpawnDraw(style);
final float alpha = style.computeAlpha();
final World world = entity.worldObj;
final Tessellator tess = Tessellator.instance;
tess.startDrawing(GL11.GL_LINES);
tess.setColorOpaque(255, 0, 0);
tess.startDrawing(style.glMode);
for (int i = 0; i <= 32; i++) {
int x = x1 - 16 + i;
for (int j = 0; j <= 32; j++) {
int z = z1 - 16 + j;
int cacheIndex = (i * 33 + j) * 33;
final int span = mobSpawnScan.getSpan();
for (int i = 0; i < span; i++) {
for (int j = 0; j < span; j++) {
final int column = i * span + j;
for (int k = 0; k <= 32; k++) {
int y = y1 - 16 + k;
int spawnMode = mobSpawnCache[cacheIndex + k];
if (spawnMode == 0) {
continue;
} else if (spawnMode == -1) {
break;
}
for (int k = 0; k < mobSpawnScan.getColumnEnd(column); k++) {
if (mobSpawnScan.readSpawnMode(column, k) == 0) continue;
if (spawnMode != curSpawnMode) {
if (spawnMode == 1) {
tess.setColorOpaque(255, 255, 0);
} else {
tess.setColorOpaque(255, 0, 0);
}
curSpawnMode = spawnMode;
}
double yOff = getOverlayYOffset(world, x + intOffsetX, y + intOffsetY, z + intOffsetZ);
tess.addVertex(x, y + yOff, z);
tess.addVertex(x + 1, y + yOff, z + 1);
tess.addVertex(x + 1, y + yOff, z);
tess.addVertex(x, y + yOff, z + 1);
final int x = mobSpawnScan.getMinX() + i;
final int y = mobSpawnScan.getMinY() + k;
final int z = mobSpawnScan.getMinZ() + j;
final double yOffset = getOverlayYOffset(world, x, y, z);
markedFace.moveTo(x - intOffsetX, y - intOffsetY + yOffset, z - intOffsetZ);
loadNeighbourModes(column, k);
markedFace.applyColor(style.colouring, alpha);
style.addVertices(markedFace);
}
}
}
tess.draw();
endMobSpawnDraw(style);
}
/**
* Set the GL state for the draw of {@code style}. For a style with a texture, the texture is bound, and stays bound
* after {@link #endMobSpawnDraw}. {@link #endMobSpawnDraw} resets each other setting.
*/
private static void beginMobSpawnDraw(MobSpawnOverlayStyle style) {
final ResourceLocation texture = style.texture;
if (texture == null) {
GL11.glDisable(GL11.GL_TEXTURE_2D);
} else {
GL11.glEnable(GL11.GL_TEXTURE_2D);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
}
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glLineWidth(1.5F);
if (style.isFilled()) {
// a translucent quad that writes depth hides the overlay quads behind the quad
GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_CULL_FACE);
// `EntityRenderer` leaves the alpha test on at GL_GREATER 0.1. The test discards a tint of opacity 0.1 or
// less
GL11.glDisable(GL11.GL_ALPHA_TEST);
}
}
private static void loadNeighbourModes(int column, int k) {
final int span = mobSpawnScan.getSpan();
final int i = column / span;
final int j = column % span;
for (int offsetX = -1; offsetX <= 1; offsetX++) {
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
final int neighbourI = i + offsetX;
final int neighbourJ = j + offsetZ;
final boolean isInScan = neighbourI >= 0 && neighbourI < span && neighbourJ >= 0 && neighbourJ < span;
final byte spawnMode = isInScan ? mobSpawnScan.readSpawnMode(neighbourI * span + neighbourJ, k)
: MobSpawnMarkedFace.OUTSIDE_SCAN;
markedFace.setNeighbourMode(offsetX, offsetZ, spawnMode);
}
}
}
private static void endMobSpawnDraw(MobSpawnOverlayStyle style) {
if (style.isFilled()) {
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDepthMask(true);
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_BLEND);
@@ -210,7 +185,7 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
private static final Entity dummyEntity = new EntityPig(null);
private static final AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
private static byte getSpawnMode(Chunk chunk, int x, int y, int z) {
static byte getSpawnMode(Chunk chunk, int x, int y, int z) {
if (y >= chunk.worldObj.getHeight()) {
return 0;
}