diff --git a/src/main/java/codechicken/nei/MobSpawnMarkedFace.java b/src/main/java/codechicken/nei/MobSpawnMarkedFace.java new file mode 100644 index 00000000..13259184 --- /dev/null +++ b/src/main/java/codechicken/nei/MobSpawnMarkedFace.java @@ -0,0 +1,101 @@ +package codechicken.nei; + +import net.minecraft.client.renderer.Tessellator; + +/** + * The top face of one block where mobs can spawn, in the coordinates of the overlay draw, with the spawn modes of the 8 + * blocks around the block at the same height. One instance is moved from block to block, so the draw allocates nothing. + * An offset of -1 is west or north, and 1 is east or south. + */ +public final class MobSpawnMarkedFace { + + /** The spawn mode of a neighbour outside {@link MobSpawnScan}. */ + public static final byte OUTSIDE_SCAN = -2; + + private static final int NEIGHBOURHOOD_SIZE = 3; + + private final byte[] neighbourModes = new byte[NEIGHBOURHOOD_SIZE * NEIGHBOURHOOD_SIZE]; + private double x; + private double y; + private double z; + + /** Move to the block whose north-west top corner is at {@code (x, y, z)}. */ + public void moveTo(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** The mode at offset {@code (0, 0)} is the spawn mode of this face. */ + public void setNeighbourMode(int offsetX, int offsetZ, byte spawnMode) { + neighbourModes[indexNeighbour(offsetX, offsetZ)] = spawnMode; + } + + /** Set the colour of the next vertices, for the spawn mode of this face. */ + public void applyColor(MobSpawnOverlayStyle.Colouring colouring, float alpha) { + final boolean isNightOnly = neighbourModes[indexNeighbour(0, 0)] == MobSpawnScan.NIGHT_ONLY; + final int rgb = switch (colouring) { + case OVERLAY -> isNightOnly ? 0xFFFF00 : 0xFF0000; + case STICKER -> isNightOnly ? 0xFFFFFF : 0xFF7373; + }; + Tessellator.instance.setColorRGBA_I(rgb, Math.round(alpha * 255)); + } + + /** + * Whether the neighbour has the spawn mode of this face. A neighbour outside {@link MobSpawnScan} counts as joined: + * the edge of the scan is no edge between spawn modes. + */ + public boolean isJoined(int offsetX, int offsetZ) { + final byte neighbourMode = neighbourModes[indexNeighbour(offsetX, offsetZ)]; + return neighbourMode == neighbourModes[indexNeighbour(0, 0)] || neighbourMode == OUTSIDE_SCAN; + } + + public void addFullFace() { + addVertex(0, 0); + addVertex(0, 1); + addVertex(1, 1); + addVertex(1, 0); + } + + /** + * Add a quad on one cell of a 3 x 3 grid over the face. The cells along the edges are {@code width} wide, and the + * cell at offset {@code (0, 0)} fills the rest. + */ + public void addCell(int offsetX, int offsetZ, double width) { + final double west = computeCellStart(offsetX, width); + final double east = 1 - computeCellStart(-offsetX, width); + final double north = computeCellStart(offsetZ, width); + final double south = 1 - computeCellStart(-offsetZ, width); + addVertex(west, north); + addVertex(west, south); + addVertex(east, south); + addVertex(east, north); + } + + /** Add the face as one quad with the whole texture, upright to a player facing south (+z). */ + public void addTexturedFace() { + addTexturedVertex(0, 0); + addTexturedVertex(0, 1); + addTexturedVertex(1, 1); + addTexturedVertex(1, 0); + } + + /** @param offsetX from 0 at the west edge to 1 at the east edge */ + public void addVertex(double offsetX, double offsetZ) { + Tessellator.instance.addVertex(x + offsetX, y, z + offsetZ); + } + + private void addTexturedVertex(double offsetX, double offsetZ) { + Tessellator.instance.setTextureUV(1 - offsetX, 1 - offsetZ); + addVertex(offsetX, offsetZ); + } + + private static int indexNeighbour(int offsetX, int offsetZ) { + return (offsetX + 1) * NEIGHBOURHOOD_SIZE + offsetZ + 1; + } + + private static double computeCellStart(int offset, double width) { + if (offset < 0) return 0; + return offset == 0 ? width : 1 - width; + } +} diff --git a/src/main/java/codechicken/nei/MobSpawnOverlayStyle.java b/src/main/java/codechicken/nei/MobSpawnOverlayStyle.java new file mode 100644 index 00000000..1b031c30 --- /dev/null +++ b/src/main/java/codechicken/nei/MobSpawnOverlayStyle.java @@ -0,0 +1,156 @@ +package codechicken.nei; + +import java.util.Locale; + +import javax.annotation.Nullable; + +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +/** + * The shape drawn on the top face of each block where mobs can spawn, by the mob spawn overlay. The setting + * {@code world.overlays.mobSpawnStyle} has the lower-case name of the style. + */ +public enum MobSpawnOverlayStyle { + + /** A cross from corner to corner. */ + X(GL11.GL_LINES) { + + @Override + public void addVertices(MobSpawnMarkedFace face) { + face.addVertex(0, 0); + face.addVertex(1, 1); + face.addVertex(1, 0); + face.addVertex(0, 1); + } + }, + + /** + * A translucent tint over the face, and a stronger band inside each edge to a block of another spawn mode. The band + * follows the outline of each region of one spawn mode, like the border of a connected texture. + */ + CONNECTED(GL11.GL_QUADS) { + + @Override + public void addVertices(MobSpawnMarkedFace face) { + final double BAND_WIDTH = 1.0 / 16; + face.addFullFace(); + face.applyColor(Colouring.OVERLAY, MARK_ALPHA); + for (int offsetX = -1; offsetX <= 1; offsetX++) { + for (int offsetZ = -1; offsetZ <= 1; offsetZ++) { + // a corner cell of the band is drawn when either side of the corner has a band, and on the inside + // corner of an L-shaped region + final boolean isBand = !(face.isJoined(offsetX, offsetZ) && face.isJoined(offsetX, 0) + && face.isJoined(0, offsetZ)); + if (isBand) face.addCell(offsetX, offsetZ, BAND_WIDTH); + } + } + } + }, + + /** A small translucent square in the middle of the face, with no tint. */ + SQUARE(GL11.GL_QUADS) { + + @Override + public void addVertices(MobSpawnMarkedFace face) { + final double CENTRE = 0.5; + final double HALF_SIDE = 7.0 / 64; + face.addVertex(CENTRE - HALF_SIDE, CENTRE - HALF_SIDE); + face.addVertex(CENTRE - HALF_SIDE, CENTRE + HALF_SIDE); + face.addVertex(CENTRE + HALF_SIDE, CENTRE + HALF_SIDE); + face.addVertex(CENTRE + HALF_SIDE, CENTRE - HALF_SIDE); + } + }, + + /** The gear and the letters of the GTNH logo, as a mask in the overlay colour. */ + GTNH_LOGO("gtnh_logo", Colouring.OVERLAY) { + + @Override + public void addVertices(MobSpawnMarkedFace face) { + face.addTexturedFace(); + } + }, + + /** A sticker of a yellow pufferfish, in the sticker's colours. */ + PUFFERFISH("pufferfish", Colouring.STICKER) { + + @Override + public void addVertices(MobSpawnMarkedFace face) { + face.addTexturedFace(); + } + }; + + public static final MobSpawnOverlayStyle DEFAULT = CONNECTED; + + private static final float TINT_ALPHA = 0.15F; + // the band of `CONNECTED` and the mark of `SQUARE` cover a small part of the face. At `TINT_ALPHA`, the band and + // the mark are too faint to see + private static final float MARK_ALPHA = 0.45F; + + /** The draw mode for {@code Tessellator.startDrawing}. */ + public final int glMode; + @Nullable + public final ResourceLocation texture; + public final Colouring colouring; + + MobSpawnOverlayStyle(int glMode) { + this.glMode = glMode; + this.texture = null; + this.colouring = Colouring.OVERLAY; + } + + /** A style of one textured quad over the face, from {@code textures/overlay/.png} of NEI. */ + MobSpawnOverlayStyle(String textureName, Colouring colouring) { + this.glMode = GL11.GL_QUADS; + this.texture = new ResourceLocation("nei", "textures/overlay/" + textureName + ".png"); + this.colouring = colouring; + } + + /** @return the style named {@code rawStyle} in any case, or {@link #DEFAULT} for an unknown name */ + public static MobSpawnOverlayStyle parseStyle(String rawStyle) { + for (MobSpawnOverlayStyle candidate : values()) { + if (candidate.formatName().equalsIgnoreCase(rawStyle)) return candidate; + } + return DEFAULT; + } + + public String formatName() { + return name().toLowerCase(Locale.ROOT); + } + + public String getLangKey() { + return switch (this) { + case X -> "nei.options.world.overlays.mobSpawnStyle.x"; + case CONNECTED -> "nei.options.world.overlays.mobSpawnStyle.connected"; + case SQUARE -> "nei.options.world.overlays.mobSpawnStyle.square"; + case GTNH_LOGO -> "nei.options.world.overlays.mobSpawnStyle.gtnh_logo"; + case PUFFERFISH -> "nei.options.world.overlays.mobSpawnStyle.pufferfish"; + }; + } + + public boolean isFilled() { + return glMode == GL11.GL_QUADS; + } + + public float computeAlpha() { + return switch (this) { + case CONNECTED -> TINT_ALPHA; + case SQUARE -> MARK_ALPHA; + // the lines of `X` are opaque. The textures have the opacity + case X, GTNH_LOGO, PUFFERFISH -> 1.0F; + }; + } + + public abstract void addVertices(MobSpawnMarkedFace face); + + /** The colours of a style. */ + public enum Colouring { + /** + * Yellow where mobs spawn only at night, red where mobs spawn at any time, through the alpha of any texture. + */ + OVERLAY, + /** The colours of the texture, tinted red where mobs spawn at any time. */ + STICKER + } +} diff --git a/src/main/java/codechicken/nei/MobSpawnScan.java b/src/main/java/codechicken/nei/MobSpawnScan.java new file mode 100644 index 00000000..5bf5f2d2 --- /dev/null +++ b/src/main/java/codechicken/nei/MobSpawnScan.java @@ -0,0 +1,181 @@ +package codechicken.nei; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraft.world.chunk.Chunk; + +import codechicken.lib.math.MathHelper; + +/** + * The spawn modes of the blocks around the render view entity, in a square that reaches the radius of {@link #update} + * on each side of the entity, and {@link #VERTICAL_RADIUS} blocks above and below. Once per tick, {@link #update} + * rescans {@code 1 / REFRESH_TICKS} of the columns into a second buffer, and after a full pass the second buffer + * becomes the drawn buffer. A block's mode is 0 where mobs can't spawn, {@link #NIGHT_ONLY} where mobs spawn only at + * night and 2 where mobs spawn at any time. + */ +public final class MobSpawnScan { + + public static final byte NIGHT_ONLY = 1; + public static final int MIN_RADIUS = 8; + public static final int MAX_RADIUS = 64; + public static final int DEFAULT_RADIUS = 32; + public static final int VERTICAL_RADIUS = 16; + public static final int HEIGHT = 2 * VERTICAL_RADIUS + 1; + private static final int REFRESH_TICKS = 10; + + private int radius; + private int span; + // the drawn buffer: `modes[column * HEIGHT + k]`, valid for `k < columnEnds[column]` + private byte[] modes = new byte[0]; + private int[] columnEnds = new int[0]; + private int minX; + private int minY; + private int minZ; + // the buffer of the pass in progress + private byte[] nextModes = new byte[0]; + private int[] nextColumnEnds = new int[0]; + private int nextMinX; + private int nextMinY; + private int nextMinZ; + private int nextColumn; + private boolean hasModes; + private long scannedTick; + // the world of the drawn modes + private World scannedWorld; + + /** Drop the scanned modes and free the buffers, so that the next call of {@link #update} is a full scan. */ + public void clear() { + radius = 0; + span = 0; + modes = new byte[0]; + columnEnds = new int[0]; + nextModes = new byte[0]; + nextColumnEnds = new int[0]; + hasModes = false; + scannedWorld = null; + } + + /** + * Scan the next slice of columns once per tick. On the first call after {@link #clear}, a change of + * {@code newRadius} or a change of world, scan every column at once and log the time of the scan. {@code newRadius} + * is clamped to {@link #MIN_RADIUS} and {@link #MAX_RADIUS}. + */ + public void update(Entity entity, int newRadius) { + final World world = entity.worldObj; + final int clampedRadius = Math.max(MIN_RADIUS, Math.min(MAX_RADIUS, newRadius)); + if (radius != clampedRadius) resize(clampedRadius); + if (!(hasModes && world == scannedWorld)) { + scanFullPass(entity); + return; + } + + final long worldTicks = world.getTotalWorldTime(); + if (worldTicks == scannedTick) return; + + scannedTick = worldTicks; + final int columnCount = span * span; + final int sliceEnd = Math.min(columnCount, nextColumn + (columnCount + REFRESH_TICKS - 1) / REFRESH_TICKS); + for (; nextColumn < sliceEnd; nextColumn++) { + scanColumn(world, nextColumn); + } + if (nextColumn == columnCount) { + swapBuffers(); + startPass(entity); + } + } + + public int getSpan() { + return span; + } + + public int getMinX() { + return minX; + } + + public int getMinY() { + return minY; + } + + public int getMinZ() { + return minZ; + } + + public int getColumnEnd(int column) { + return columnEnds[column]; + } + + /** @return the spawn mode of the block at height index {@code k} of {@code column}, 0 above the column's end */ + public byte readSpawnMode(int column, int k) { + return k < columnEnds[column] ? modes[column * HEIGHT + k] : 0; + } + + private void resize(int newRadius) { + radius = newRadius; + span = 2 * newRadius + 1; + modes = new byte[span * span * HEIGHT]; + columnEnds = new int[span * span]; + nextModes = new byte[span * span * HEIGHT]; + nextColumnEnds = new int[span * span]; + hasModes = false; + } + + private void scanFullPass(Entity entity) { + final long startNanos = System.nanoTime(); + startPass(entity); + for (; nextColumn < span * span; nextColumn++) { + scanColumn(entity.worldObj, nextColumn); + } + swapBuffers(); + hasModes = true; + scannedWorld = entity.worldObj; + scannedTick = entity.worldObj.getTotalWorldTime(); + NEIClientConfig.logger.info( + "moboverlay.scan.full radius={} columns={} micros={}", + radius, + span * span, + (System.nanoTime() - startNanos) / 1000); + startPass(entity); + } + + private void startPass(Entity entity) { + final int centreY = (int) MathHelper + .clip(entity.posY, VERTICAL_RADIUS, entity.worldObj.getHeight() - VERTICAL_RADIUS); + nextMinX = (int) entity.posX - radius; + nextMinY = centreY - VERTICAL_RADIUS; + nextMinZ = (int) entity.posZ - radius; + nextColumn = 0; + } + + private void scanColumn(World world, int column) { + final int x = nextMinX + column / span; + final int z = nextMinZ + column % span; + final BiomeGenBase biome = world.getBiomeGenForCoords(x, z); + if (biome.getSpawnableList(EnumCreatureType.monster).isEmpty() || biome.getSpawningChance() <= 0) { + nextColumnEnds[column] = 0; + return; + } + + final Chunk chunk = world.getChunkFromBlockCoords(x, z); + final int topY = Math.min(world.getHeight() - 1, world.getHeightValue(x, z)); + int end = 0; + while (end < HEIGHT && nextMinY + end <= topY) { + nextModes[column * HEIGHT + end] = WorldOverlayRenderer.getSpawnMode(chunk, x, nextMinY + end, z); + end++; + } + nextColumnEnds[column] = end; + } + + private void swapBuffers() { + final byte[] scannedModes = nextModes; + nextModes = modes; + modes = scannedModes; + final int[] scannedEnds = nextColumnEnds; + nextColumnEnds = columnEnds; + columnEnds = scannedEnds; + minX = nextMinX; + minY = nextMinY; + minZ = nextMinZ; + } +} diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index 1a532500..262c8993 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.StatCollector; import net.minecraft.world.storage.SaveFormatComparator; import net.minecraftforge.common.MinecraftForge; @@ -442,6 +443,37 @@ public class NEIClientConfig { tag.getTag("world.overlays.lock").getBooleanValue(true); 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") + .getValue(MobSpawnOverlayStyle.DEFAULT.formatName()); + API.addOption(new OptionCycled("world.overlays.mobSpawnStyle", MobSpawnOverlayStyle.values().length, true) { + + @Override + public int value() { + return MobSpawnOverlayStyle.parseStyle(getTag().getValue()).ordinal(); + } + + @Override + public void setValue(int value) { + getTag().setValue(MobSpawnOverlayStyle.values()[value].formatName()); + } + + @Override + public String getButtonText() { + final MobSpawnOverlayStyle style = MobSpawnOverlayStyle.parseStyle(getTag().getValue()); + return StatCollector.translateToLocal(style.getLangKey()); + } + }); + + tag.getTag("world.overlays.mobSpawnRadius") + .setComment("Blocks scanned on each side of the player by the mob spawn overlay") + .getIntValue(MobSpawnScan.DEFAULT_RADIUS); + API.addOption( + new OptionIntegerField( + "world.overlays.mobSpawnRadius", + MobSpawnScan.MIN_RADIUS, + MobSpawnScan.MAX_RADIUS)); + tag.getTag("inventory.itempanelScale").getIntValue(100); ItemsPanelGrid.updateScale(); API.addOption(new OptionIntegerField("inventory.itempanelScale", 1, 1000) { diff --git a/src/main/java/codechicken/nei/WorldOverlayRenderer.java b/src/main/java/codechicken/nei/WorldOverlayRenderer.java index 56a3af37..cfa0556c 100644 --- a/src/main/java/codechicken/nei/WorldOverlayRenderer.java +++ b/src/main/java/codechicken/nei/WorldOverlayRenderer.java @@ -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; } diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index 2b7ce60f..20d2eccf 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -566,6 +566,14 @@ nei.options.world.overlays=Overlays Settings nei.options.world.overlays.lock=Lock overlays between dimensions nei.options.world.overlays.lock.true=Enabled nei.options.world.overlays.lock.false=Disabled +nei.options.world.overlays.mobSpawnStyle=Mob Spawn Overlay Style +nei.options.world.overlays.mobSpawnStyle.x=X +nei.options.world.overlays.mobSpawnStyle.connected=Connected +nei.options.world.overlays.mobSpawnStyle.square=Square +nei.options.world.overlays.mobSpawnStyle.gtnh_logo=GTNH Logo +nei.options.world.overlays.mobSpawnStyle.pufferfish=Pufferfish +nei.options.world.overlays.mobSpawnRadius=Mob Spawn Overlay Radius +nei.options.world.overlays.mobSpawnRadius.tip=Block radius scanned around you. Range 8-64 blocks nei.options.tools=Tools nei.options.tools.export_configs=Default Config Files diff --git a/src/main/resources/assets/nei/textures/overlay/gtnh_logo.png b/src/main/resources/assets/nei/textures/overlay/gtnh_logo.png new file mode 100644 index 00000000..afd428e6 Binary files /dev/null and b/src/main/resources/assets/nei/textures/overlay/gtnh_logo.png differ diff --git a/src/main/resources/assets/nei/textures/overlay/gtnh_logo.png.mcmeta b/src/main/resources/assets/nei/textures/overlay/gtnh_logo.png.mcmeta new file mode 100644 index 00000000..70fbb13c --- /dev/null +++ b/src/main/resources/assets/nei/textures/overlay/gtnh_logo.png.mcmeta @@ -0,0 +1,6 @@ +{ + "texture": { + "blur": true, + "clamp": true + } +} diff --git a/src/main/resources/assets/nei/textures/overlay/pufferfish.png b/src/main/resources/assets/nei/textures/overlay/pufferfish.png new file mode 100644 index 00000000..451e4bb2 Binary files /dev/null and b/src/main/resources/assets/nei/textures/overlay/pufferfish.png differ diff --git a/src/main/resources/assets/nei/textures/overlay/pufferfish.png.mcmeta b/src/main/resources/assets/nei/textures/overlay/pufferfish.png.mcmeta new file mode 100644 index 00000000..96fb0a20 --- /dev/null +++ b/src/main/resources/assets/nei/textures/overlay/pufferfish.png.mcmeta @@ -0,0 +1,6 @@ +{ + "texture": { + "blur": false, + "clamp": true + } +}