mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-12 00:17:51 +00:00
Comment cleanup
This commit is contained in:
1 parent
d04718c5c6
commit
b7dcd0fb3d
4 files changed
+33
-62
No files matched your search
@@ -2,14 +2,9 @@ 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.
|
||||
*/
|
||||
/** The vertices of the mob spawn overlay on the top face of one block. */
|
||||
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;
|
||||
@@ -19,19 +14,18 @@ public final class MobSpawnMarkedFace {
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
/** Move to the block whose north-west top corner is at {@code (x, y, z)}. */
|
||||
/** {@code (x, y, z)} is the north-west corner of the block's top face. */
|
||||
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. */
|
||||
/** An offset of -1 is west or north, and 1 is east or south. Offset {@code (0, 0)} is this block. */
|
||||
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) {
|
||||
@@ -42,8 +36,7 @@ public final class MobSpawnMarkedFace {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* True when the neighbour has this block's spawn mode, or is outside the scan. The edge of the scan gets no band.
|
||||
*/
|
||||
public boolean isJoined(int offsetX, int offsetZ) {
|
||||
final byte neighbourMode = neighbourModes[indexNeighbour(offsetX, offsetZ)];
|
||||
@@ -57,10 +50,7 @@ public final class MobSpawnMarkedFace {
|
||||
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.
|
||||
*/
|
||||
/** 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. */
|
||||
public void addCell(int offsetX, int offsetZ, double width) {
|
||||
final double west = computeCellStart(offsetX, width);
|
||||
final double east = 1 - computeCellStart(-offsetX, width);
|
||||
@@ -72,7 +62,7 @@ public final class MobSpawnMarkedFace {
|
||||
addVertex(east, north);
|
||||
}
|
||||
|
||||
/** Add the face as one quad with the whole texture, upright to a player facing south (+z). */
|
||||
/** The texture is upright to a player facing south (+z). */
|
||||
public void addTexturedFace() {
|
||||
addTexturedVertex(0, 0);
|
||||
addTexturedVertex(0, 1);
|
||||
@@ -80,7 +70,7 @@ public final class MobSpawnMarkedFace {
|
||||
addTexturedVertex(1, 0);
|
||||
}
|
||||
|
||||
/** @param offsetX from 0 at the west edge to 1 at the east edge */
|
||||
/** @param offsetX 0 at the west edge, 1 at the east edge */
|
||||
public void addVertex(double offsetX, double offsetZ) {
|
||||
Tessellator.instance.addVertex(x + offsetX, y, z + offsetZ);
|
||||
}
|
||||
|
||||
@@ -8,13 +8,10 @@ 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.
|
||||
*/
|
||||
/** A mark of the mob spawn overlay. {@code world.overlays.mobSpawnStyle} is saved as {@link #formatName()}. */
|
||||
public enum MobSpawnOverlayStyle {
|
||||
|
||||
/** A cross from corner to corner. */
|
||||
/** NEI's original cross from corner to corner. */
|
||||
X(GL11.GL_LINES) {
|
||||
|
||||
@Override
|
||||
@@ -26,10 +23,7 @@ public enum MobSpawnOverlayStyle {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/** A light tint, with a stronger band along the outline of each area of one spawn mode, like a connected texture. */
|
||||
CONNECTED(GL11.GL_QUADS) {
|
||||
|
||||
@Override
|
||||
@@ -39,8 +33,7 @@ public enum MobSpawnOverlayStyle {
|
||||
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
|
||||
// a corner cell is drawn when either edge next to the corner has a band, and on an inside corner
|
||||
final boolean isBand = !(face.isJoined(offsetX, offsetZ) && face.isJoined(offsetX, 0)
|
||||
&& face.isJoined(0, offsetZ));
|
||||
if (isBand) face.addCell(offsetX, offsetZ, BAND_WIDTH);
|
||||
@@ -49,7 +42,7 @@ public enum MobSpawnOverlayStyle {
|
||||
}
|
||||
},
|
||||
|
||||
/** A small translucent square in the middle of the face, with no tint. */
|
||||
/** A small square in the middle of the block, with no tint. */
|
||||
SQUARE(GL11.GL_QUADS) {
|
||||
|
||||
@Override
|
||||
@@ -63,7 +56,7 @@ public enum MobSpawnOverlayStyle {
|
||||
}
|
||||
},
|
||||
|
||||
/** The gear and the letters of the GTNH logo, as a mask in the overlay colour. */
|
||||
/** The GTNH logo without the globe. */
|
||||
GTNH_LOGO("gtnh_logo", Colouring.OVERLAY) {
|
||||
|
||||
@Override
|
||||
@@ -72,7 +65,7 @@ public enum MobSpawnOverlayStyle {
|
||||
}
|
||||
},
|
||||
|
||||
/** A sticker of a yellow pufferfish, in the sticker's colours. */
|
||||
/** The pufferfish sticker. */
|
||||
PUFFERFISH("pufferfish", Colouring.STICKER) {
|
||||
|
||||
@Override
|
||||
@@ -84,11 +77,9 @@ public enum MobSpawnOverlayStyle {
|
||||
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
|
||||
// at the tint's opacity, a small mark is 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;
|
||||
@@ -100,14 +91,13 @@ public enum MobSpawnOverlayStyle {
|
||||
this.colouring = Colouring.OVERLAY;
|
||||
}
|
||||
|
||||
/** A style of one textured quad over the face, from {@code textures/overlay/<textureName>.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 */
|
||||
/** Case-insensitive. Returns {@link #DEFAULT} for an unknown name. */
|
||||
public static MobSpawnOverlayStyle parseStyle(String rawStyle) {
|
||||
for (MobSpawnOverlayStyle candidate : values()) {
|
||||
if (candidate.formatName().equalsIgnoreCase(rawStyle)) return candidate;
|
||||
@@ -137,20 +127,17 @@ public enum MobSpawnOverlayStyle {
|
||||
return switch (this) {
|
||||
case CONNECTED -> TINT_ALPHA;
|
||||
case SQUARE -> MARK_ALPHA;
|
||||
// the lines of `X` are opaque. The textures have the opacity
|
||||
// the alpha is in the PNGs
|
||||
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.
|
||||
*/
|
||||
/** Yellow where mobs spawn only at night, red where mobs spawn at any time. */
|
||||
OVERLAY,
|
||||
/** The colours of the texture, tinted red where mobs spawn at any time. */
|
||||
/** The texture's colours, tinted red where mobs spawn at any time. */
|
||||
STICKER
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,9 @@ 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.
|
||||
* The mob spawn modes of the blocks around the player, scanned a slice per tick into a back buffer. The buffers swap
|
||||
* when a pass is done. The modes come from {@link WorldOverlayRenderer#getSpawnMode}: 0 for no spawns, 1 for night only
|
||||
* and 2 for any time.
|
||||
*/
|
||||
public final class MobSpawnScan {
|
||||
|
||||
@@ -27,13 +25,13 @@ public final class MobSpawnScan {
|
||||
|
||||
private int radius;
|
||||
private int span;
|
||||
// the drawn buffer: `modes[column * HEIGHT + k]`, valid for `k < columnEnds[column]`
|
||||
// front 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
|
||||
// back buffer
|
||||
private byte[] nextModes = new byte[0];
|
||||
private int[] nextColumnEnds = new int[0];
|
||||
private int nextMinX;
|
||||
@@ -42,10 +40,10 @@ public final class MobSpawnScan {
|
||||
private int nextColumn;
|
||||
private boolean hasModes;
|
||||
private long scannedTick;
|
||||
// the world of the drawn modes
|
||||
// world of the front buffer
|
||||
private World scannedWorld;
|
||||
|
||||
/** Drop the scanned modes and free the buffers, so that the next call of {@link #update} is a full scan. */
|
||||
/** Free the buffers. The next {@link #update} does a full scan. */
|
||||
public void clear() {
|
||||
radius = 0;
|
||||
span = 0;
|
||||
@@ -58,9 +56,8 @@ public final class MobSpawnScan {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
* 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 between {@link #MIN_RADIUS} and {@link #MAX_RADIUS}.
|
||||
*/
|
||||
public void update(Entity entity, int newRadius) {
|
||||
final World world = entity.worldObj;
|
||||
@@ -106,7 +103,7 @@ public final class MobSpawnScan {
|
||||
return columnEnds[column];
|
||||
}
|
||||
|
||||
/** @return the spawn mode of the block at height index {@code k} of {@code column}, 0 above the column's end */
|
||||
/** @return 0 at or above {@link #getColumnEnd} */
|
||||
public byte readSpawnMode(int column, int k) {
|
||||
return k < columnEnds[column] ? modes[column * HEIGHT + k] : 0;
|
||||
}
|
||||
|
||||
@@ -129,10 +129,7 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
|
||||
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.
|
||||
*/
|
||||
/** {@link #endMobSpawnDraw} undoes every change here except the texture binding. */
|
||||
private static void beginMobSpawnDraw(MobSpawnOverlayStyle style) {
|
||||
final ResourceLocation texture = style.texture;
|
||||
if (texture == null) {
|
||||
@@ -146,11 +143,11 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
|
||||
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
|
||||
// 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. The test discards a tint of opacity 0.1 or
|
||||
// less
|
||||
// `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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user