mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-16 18:54:45 +00:00
Add NEI mob spawn overlay variants (#1111)
- Add multiple light level overlay modes (Connected, Square, GTNH Logo, Pufferfish, X) - Set default F7 overlay to Connected - Allow changing horizontal and vertical radius of light level overlay (before it was stuck at 16 blocks) - Set default horizontal radius to 32 blocks - Optimize performance by 10-30x compared to master - Works with shaders (tested Complementary Unbound + Euphoria patches) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
10 files changed
+851
-144
No files matched your search
@@ -0,0 +1,135 @@
|
||||
package codechicken.nei.moboverlay;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
/**
|
||||
* Each style is a mark drawn on every block where mobs can spawn. {@code world.overlays.mobOverlayStyle} is saved as
|
||||
* {@link #formatName()}.
|
||||
*/
|
||||
public enum MobOverlayStyle {
|
||||
|
||||
/** NEI's original cross from corner to corner. */
|
||||
X(GL11.GL_LINES) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace face) {
|
||||
face.addVertex(0, 0);
|
||||
face.addVertex(1, 1);
|
||||
face.addVertex(1, 0);
|
||||
face.addVertex(0, 1);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* A light tint, with a stronger outline around each area of one spawn mode, like a connected texture.
|
||||
*/
|
||||
CONNECTED(GL11.GL_QUADS) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace face) {
|
||||
final double OUTLINE_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 is drawn when either edge next to the corner is outlined, and on an inside corner
|
||||
final boolean isOutline = !(face.isJoined(offsetX, offsetZ) && face.isJoined(offsetX, 0)
|
||||
&& face.isJoined(0, offsetZ));
|
||||
if (isOutline) face.addCell(offsetX, offsetZ, OUTLINE_WIDTH);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/** A small square in the middle of the block, with no tint. */
|
||||
SQUARE(GL11.GL_QUADS) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace 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 pufferfish sticker. */
|
||||
PUFFERFISH("pufferfish", Colouring.STICKER) {
|
||||
|
||||
@Override
|
||||
public void addVertices(MobOverlayFace face) {
|
||||
face.addTexturedFace();
|
||||
}
|
||||
};
|
||||
|
||||
public static final MobOverlayStyle DEFAULT = CONNECTED;
|
||||
|
||||
private static final float TINT_ALPHA = 0.15F;
|
||||
// the square and the outline cover a small part of the block and need more opacity than the tint to stay visible
|
||||
private static final float MARK_ALPHA = 0.45F;
|
||||
|
||||
public final int glMode;
|
||||
@Nullable
|
||||
public final ResourceLocation texture;
|
||||
public final Colouring colouring;
|
||||
|
||||
MobOverlayStyle(int glMode) {
|
||||
this.glMode = glMode;
|
||||
this.texture = null;
|
||||
this.colouring = Colouring.OVERLAY;
|
||||
}
|
||||
|
||||
MobOverlayStyle(String textureName, Colouring colouring) {
|
||||
this.glMode = GL11.GL_QUADS;
|
||||
this.texture = new ResourceLocation("nei", "textures/overlay/" + textureName + ".png");
|
||||
this.colouring = colouring;
|
||||
}
|
||||
|
||||
/** Case-insensitive. Returns {@link #DEFAULT} for an unknown name. */
|
||||
public static MobOverlayStyle parseStyle(String rawStyle) {
|
||||
for (MobOverlayStyle candidate : values()) {
|
||||
if (candidate.formatName().equalsIgnoreCase(rawStyle)) return candidate;
|
||||
}
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
/** @return the {@link #formatName} of every style, separated by commas */
|
||||
public static String formatAllNames() {
|
||||
final StringJoiner names = new StringJoiner(", ");
|
||||
for (MobOverlayStyle style : values()) {
|
||||
names.add(style.formatName());
|
||||
}
|
||||
return names.toString();
|
||||
}
|
||||
|
||||
public String formatName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public float computeAlpha() {
|
||||
return switch (this) {
|
||||
case CONNECTED -> TINT_ALPHA;
|
||||
case SQUARE -> MARK_ALPHA;
|
||||
// opaque lines for X, and the alpha of the PNG for PUFFERFISH
|
||||
case X, PUFFERFISH -> 1.0F;
|
||||
};
|
||||
}
|
||||
|
||||
public abstract void addVertices(MobOverlayFace face);
|
||||
|
||||
public enum Colouring {
|
||||
/** Yellow where mobs spawn only at night, red where mobs spawn at any time. */
|
||||
OVERLAY,
|
||||
/** The texture's colours, tinted red where mobs spawn at any time. */
|
||||
STICKER
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user