Swap to cleaner GTNH logo + pufferfish. And cleanup

This commit is contained in:
OrderedSet committed 2026-11-08 00:18:12 -08:00
1 parent d6789c44d4
commit b29494935d
8 files changed
+120 -91

No files matched your search

@@ -0,0 +1,41 @@
package codechicken.nei;
import net.minecraft.client.renderer.GLAllocation;
import org.lwjgl.opengl.GL11;
/**
* The display list of the mob spawn overlay quads, and the scan version and the style that the list was compiled from.
*/
public final class MobSpawnDisplayList {
private int listId = -1;
private int modesVersion;
private MobSpawnOverlayStyle style;
public boolean isCompiled(int currentModesVersion, MobSpawnOverlayStyle currentStyle) {
return listId >= 0 && modesVersion == currentModesVersion && style == currentStyle;
}
public void beginCompile(int newModesVersion, MobSpawnOverlayStyle newStyle) {
if (listId < 0) listId = GLAllocation.generateDisplayLists(1);
modesVersion = newModesVersion;
style = newStyle;
GL11.glNewList(listId, GL11.GL_COMPILE);
}
public void endCompile() {
GL11.glEndList();
}
public void draw() {
GL11.glCallList(listId);
}
public void delete() {
if (listId < 0) return;
GLAllocation.deleteDisplayLists(listId);
listId = -1;
}
}
@@ -36,7 +36,8 @@ public final class MobSpawnMarkedFace {
}
/**
* True when the neighbour has this block's spawn mode, or is outside the scan. The edge of the scan gets no band.
* True when the neighbour has this block's spawn mode. A neighbour outside the scan counts as joined, so no band is
* drawn along the edge of the scan.
*/
public boolean isJoined(int offsetX, int offsetZ) {
final byte neighbourMode = neighbourModes[indexNeighbour(offsetX, offsetZ)];
@@ -50,10 +51,7 @@ public final class MobSpawnMarkedFace {
addVertex(1, 0);
}
/**
* Add one cell of a 3 x 3 grid over the face. Edge cells are {@code width} wide, and the middle cell fills the
* rest.
*/
/** Add one cell of a 3 x 3 grid over the face. The outer rows and columns of the grid are {@code width} wide. */
public void addCell(int offsetX, int offsetZ, double width) {
final double west = computeCellStart(offsetX, width);
final double east = 1 - computeCellStart(-offsetX, width);
@@ -1,6 +1,7 @@
package codechicken.nei;
import java.util.Locale;
import java.util.StringJoiner;
import javax.annotation.Nullable;
@@ -107,6 +108,15 @@ public enum MobSpawnOverlayStyle {
return DEFAULT;
}
/** @return the {@link #formatName} of every style, separated by commas */
public static String formatAllNames() {
final StringJoiner names = new StringJoiner(", ");
for (MobSpawnOverlayStyle style : values()) {
names.add(style.formatName());
}
return names.toString();
}
public String formatName() {
return name().toLowerCase(Locale.ROOT);
}
+35 -39
View File
@@ -35,7 +35,7 @@ public final class MobSpawnScan {
// columns of `back` below this index are scanned in the pass in progress
private int nextColumn;
private boolean hasDirtyColumns;
private int changeCount;
private int modesVersion;
private boolean hasModes;
private long scannedTick;
// world of `front`, with `changeListener` added
@@ -54,7 +54,7 @@ public final class MobSpawnScan {
/**
* Rescan the columns of changed blocks, and scan the next slice of columns, at most once per tick. After
* {@link #clear}, a radius change or a world change, scan every column at once. {@code newRadius} is clamped
* {@link #clear}, a radius change or a world change, scan every column in this call. {@code newRadius} is clamped
* between {@link #MIN_RADIUS} and {@link #MAX_RADIUS}.
*/
public void update(Entity entity, int newRadius) {
@@ -82,9 +82,8 @@ public final class MobSpawnScan {
}
}
/** Changes each time the modes of {@link #readSpawnMode} change. */
public int getChangeCount() {
return changeCount;
public int getModesVersion() {
return modesVersion;
}
public int getSpan() {
@@ -123,12 +122,7 @@ public final class MobSpawnScan {
private void scanFullPass(Entity entity) {
final long startNanos = System.nanoTime();
final World world = entity.worldObj;
if (world != scannedWorld) {
if (scannedWorld != null) scannedWorld.removeWorldAccess(changeListener);
world.addWorldAccess(changeListener);
scannedWorld = world;
}
if (world != scannedWorld) watchWorld(world);
startPass(entity);
for (; nextColumn < span * span; nextColumn++) {
back.scanColumn(world, nextColumn, span);
@@ -144,6 +138,12 @@ public final class MobSpawnScan {
startPass(entity);
}
private void watchWorld(World world) {
if (scannedWorld != null) scannedWorld.removeWorldAccess(changeListener);
world.addWorldAccess(changeListener);
scannedWorld = world;
}
private void startPass(Entity entity) {
final int centreY = (int) MathHelper
.clip(entity.posY, VERTICAL_RADIUS, entity.worldObj.getHeight() - VERTICAL_RADIUS);
@@ -160,7 +160,7 @@ public final class MobSpawnScan {
if (front.dirty[column]) {
front.scanColumn(world, column, span);
front.dirty[column] = false;
changeCount++;
modesVersion++;
}
if (back.dirty[column]) {
back.scanColumn(world, column, span);
@@ -173,31 +173,7 @@ public final class MobSpawnScan {
final Buffer scanned = back;
back = front;
front = scanned;
changeCount++;
}
/**
* Mark the column of a changed block. A block's spawn mode depends on the block below and the block above, so a
* change 1 block below or above the scanned height counts too.
*/
private void markChanged(int x, int y, int z) {
final int lowestY = Math.min(front.minY, back.minY) - 1;
final int highestY = Math.max(front.minY, back.minY) + HEIGHT;
if (y >= lowestY && y <= highestY) markColumn(x, z);
}
private void markColumn(int x, int z) {
final int frontColumn = front.findColumn(x, z, span);
if (frontColumn >= 0) {
front.dirty[frontColumn] = true;
hasDirtyColumns = true;
}
// a column at or above `nextColumn` is scanned later in this pass
final int backColumn = back.findColumn(x, z, span);
if (backColumn >= 0 && backColumn < nextColumn) {
back.dirty[backColumn] = true;
hasDirtyColumns = true;
}
modesVersion++;
}
/** The spawn modes of one square of columns. */
@@ -278,8 +254,8 @@ public final class MobSpawnScan {
float volume, float pitch) {}
@Override
public void spawnParticle(String particleName, double x, double y, double z, double velocityX,
double velocityY, double velocityZ) {}
public void spawnParticle(String particleName, double x, double y, double z, double velocityX, double velocityY,
double velocityZ) {}
@Override
public void onEntityCreate(Entity entity) {}
@@ -301,5 +277,25 @@ public final class MobSpawnScan {
@Override
public void onStaticEntitiesChanged() {}
private void markChanged(int x, int y, int z) {
// spawn modes depend on the block below and the block above
final int lowestY = Math.min(front.minY, back.minY) - 1;
final int highestY = Math.max(front.minY, back.minY) + HEIGHT;
if (y >= lowestY && y <= highestY) markColumn(x, z);
}
private void markColumn(int x, int z) {
final int frontColumn = front.findColumn(x, z, span);
if (frontColumn >= 0) {
front.dirty[frontColumn] = true;
hasDirtyColumns = true;
}
final int backColumn = back.findColumn(x, z, span);
if (backColumn >= 0 && backColumn < nextColumn) {
back.dirty[backColumn] = true;
hasDirtyColumns = true;
}
}
}
}
@@ -444,8 +444,7 @@ public class NEIClientConfig {
API.addOption(new OptionToggleButton("world.overlays.lock", true));
tag.getTag("world.overlays.mobSpawnStyle")
.setComment(
"Mark on each block of the mob spawn overlay: x, connected, square, gtnh_logo or pufferfish")
.setComment("Mark on each block of the mob spawn overlay: " + MobSpawnOverlayStyle.formatAllNames())
.getValue(MobSpawnOverlayStyle.DEFAULT.formatName());
API.addOption(new OptionCycled("world.overlays.mobSpawnStyle", MobSpawnOverlayStyle.values().length, true) {
@@ -7,7 +7,6 @@ import java.util.concurrent.Callable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSnow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
@@ -32,12 +31,9 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
public static int chunkOverlay = 0;
public static int mobOverlay = 0;
private static final MobSpawnScan mobSpawnScan = new MobSpawnScan();
private static final MobSpawnMarkedFace markedFace = new MobSpawnMarkedFace();
// display list of the overlay quads, compiled when the scan or the style changes
private static int mobSpawnList = -1;
private static int mobSpawnListChange;
private static MobSpawnOverlayStyle mobSpawnListStyle;
private static final MobSpawnScan MOB_SPAWN_SCAN = new MobSpawnScan();
private static final MobSpawnMarkedFace MARKED_FACE = new MobSpawnMarkedFace();
private static final MobSpawnDisplayList MOB_SPAWN_LIST = new MobSpawnDisplayList();
public static void reset() {
mobOverlay = 0;
@@ -95,27 +91,31 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
return 0.02;
}
/**
* The model view matrix is relative to ({@code intOffsetX}, {@code intOffsetY}, {@code intOffsetZ}), the camera
* position cast to {@code int}.
*/
private static void renderMobSpawnOverlay(Entity entity, int intOffsetX, int intOffsetY, int intOffsetZ) {
if (mobOverlay == 0) {
mobSpawnScan.clear();
deleteMobSpawnList();
MOB_SPAWN_SCAN.clear();
MOB_SPAWN_LIST.delete();
return;
}
mobSpawnScan.update(entity, NEIClientConfig.getIntSetting("world.overlays.mobSpawnRadius"));
MOB_SPAWN_SCAN.update(entity, NEIClientConfig.getIntSetting("world.overlays.mobSpawnRadius"));
final MobSpawnOverlayStyle style = MobSpawnOverlayStyle
.parseStyle(NEIClientConfig.getSetting("world.overlays.mobSpawnStyle").getValue());
if (!(mobSpawnList >= 0 && mobSpawnListChange == mobSpawnScan.getChangeCount() && mobSpawnListStyle == style)) {
if (!MOB_SPAWN_LIST.isCompiled(MOB_SPAWN_SCAN.getModesVersion(), style)) {
compileMobSpawnList(entity.worldObj, style);
}
beginMobSpawnDraw(style);
GL11.glPushMatrix();
GL11.glTranslated(
mobSpawnScan.getMinX() - intOffsetX,
mobSpawnScan.getMinY() - intOffsetY,
mobSpawnScan.getMinZ() - intOffsetZ);
GL11.glCallList(mobSpawnList);
MOB_SPAWN_SCAN.getMinX() - intOffsetX,
MOB_SPAWN_SCAN.getMinY() - intOffsetY,
MOB_SPAWN_SCAN.getMinZ() - intOffsetZ);
MOB_SPAWN_LIST.draw();
GL11.glPopMatrix();
endMobSpawnDraw(style);
}
@@ -125,43 +125,32 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
* {@link MobSpawnScan#getMinZ}).
*/
private static void compileMobSpawnList(World world, MobSpawnOverlayStyle style) {
if (mobSpawnList < 0) mobSpawnList = GLAllocation.generateDisplayLists(1);
mobSpawnListChange = mobSpawnScan.getChangeCount();
mobSpawnListStyle = style;
GL11.glNewList(mobSpawnList, GL11.GL_COMPILE);
MOB_SPAWN_LIST.beginCompile(MOB_SPAWN_SCAN.getModesVersion(), style);
final float alpha = style.computeAlpha();
final Tessellator tess = Tessellator.instance;
tess.startDrawing(style.glMode);
final int span = mobSpawnScan.getSpan();
final int span = MOB_SPAWN_SCAN.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 < mobSpawnScan.getColumnEnd(column); k++) {
if (mobSpawnScan.readSpawnMode(column, k) == 0) continue;
for (int k = 0; k < MOB_SPAWN_SCAN.getColumnEnd(column); k++) {
if (MOB_SPAWN_SCAN.readSpawnMode(column, k) == 0) continue;
final double yOffset = getOverlayYOffset(
world,
mobSpawnScan.getMinX() + i,
mobSpawnScan.getMinY() + k,
mobSpawnScan.getMinZ() + j);
markedFace.moveTo(i, k + yOffset, j);
MOB_SPAWN_SCAN.getMinX() + i,
MOB_SPAWN_SCAN.getMinY() + k,
MOB_SPAWN_SCAN.getMinZ() + j);
MARKED_FACE.moveTo(i, k + yOffset, j);
loadNeighbourModes(column, k);
markedFace.applyColor(style.colouring, alpha);
style.addVertices(markedFace);
MARKED_FACE.applyColor(style.colouring, alpha);
style.addVertices(MARKED_FACE);
}
}
}
tess.draw();
GL11.glEndList();
}
private static void deleteMobSpawnList() {
if (mobSpawnList < 0) return;
GLAllocation.deleteDisplayLists(mobSpawnList);
mobSpawnList = -1;
MOB_SPAWN_LIST.endCompile();
}
/** {@link #endMobSpawnDraw} undoes every change here except the texture binding. */
@@ -181,14 +170,11 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
// a translucent quad that writes depth hides the overlay behind the quad. Turn depth writes off
GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_CULL_FACE);
// `EntityRenderer` leaves the alpha test on at GL_GREATER 0.1. Turn the test off, or a faint tint is
// discarded
GL11.glDisable(GL11.GL_ALPHA_TEST);
}
}
private static void loadNeighbourModes(int column, int k) {
final int span = mobSpawnScan.getSpan();
final int span = MOB_SPAWN_SCAN.getSpan();
final int i = column / span;
final int j = column % span;
for (int offsetX = -1; offsetX <= 1; offsetX++) {
@@ -196,16 +182,15 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
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)
final byte spawnMode = isInScan ? MOB_SPAWN_SCAN.readSpawnMode(neighbourI * span + neighbourJ, k)
: MobSpawnMarkedFace.OUTSIDE_SCAN;
markedFace.setNeighbourMode(offsetX, offsetZ, spawnMode);
MARKED_FACE.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);
}
@@ -217,7 +202,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);
static byte getSpawnMode(Chunk chunk, int x, int y, int z) {
public static byte getSpawnMode(Chunk chunk, int x, int y, int z) {
if (y >= chunk.worldObj.getHeight()) {
return 0;
}