Initial fixes for PR comments

This commit is contained in:
OrderedSet committed 2026-11-14 21:07:11 -08:00
1 parent 0fc657c9d9
commit c6acb196f8
9 files changed
+97 -109

No files matched your search

@@ -444,6 +444,7 @@ public class ClientHandler {
if (event.world == mc.theWorld) {
NEIClientConfig.unloadWorld();
ItemMobSpawner.clearEntityReferences();
WorldOverlayRenderer.onWorldUnload();
}
}
@@ -17,7 +17,6 @@ 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;
@@ -462,8 +461,9 @@ public class NEIClientConfig {
@Override
public String getButtonText() {
final MobOverlayStyle style = MobOverlayStyle.parseStyle(getTag().getValue());
return StatCollector.translateToLocal(style.getLangKey());
return translateN(
"world.overlays.mobOverlayStyle."
+ MobOverlayStyle.parseStyle(getTag().getValue()).formatName());
}
});
@@ -4,20 +4,12 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
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.Tessellator;
import net.minecraft.entity.Entity;
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.chunk.Chunk;
import org.lwjgl.opengl.GL11;
@@ -44,6 +36,11 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
chunkOverlay = 0;
}
public static void onWorldUnload() {
MOB_OVERLAY_SCAN.clear();
MOB_OVERLAY_LIST.delete();
}
@Override
public void tickKeyStates() {
if (Minecraft.getMinecraft().currentScreen != null) return;
@@ -86,15 +83,6 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
GL11.glPopAttrib();
}
private static double getOverlayYOffset(World world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (block instanceof BlockSnow) {
int meta = world.getBlockMetadata(x, y, z) & 7;
return (1 + meta) / 8.0 + 0.02;
}
return 0.02;
}
/**
* The model view matrix is relative to ({@code intOffsetX}, {@code intOffsetY}, {@code intOffsetZ}), the camera
* position cast to {@code int}.
@@ -114,7 +102,7 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
.parseStyle(NEIClientConfig.getSetting("world.overlays.mobOverlayStyle").getValue());
final long worldTicks = entity.worldObj.getTotalWorldTime();
if (MOB_OVERLAY_LIST.isCompileDue(MOB_OVERLAY_SCAN.getModesVersion(), style, worldTicks)) {
compileMobOverlayList(entity.worldObj, style, worldTicks);
compileMobOverlayList(style, worldTicks);
}
beginMobOverlayDraw(style);
@@ -125,7 +113,7 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
/**
* Add a marked face to {@link #MOB_OVERLAY_LIST} for each block of {@link #MOB_OVERLAY_SCAN} where mobs can spawn.
*/
private static void compileMobOverlayList(World world, MobOverlayStyle style, long worldTicks) {
private static void compileMobOverlayList(MobOverlayStyle style, long worldTicks) {
MOB_OVERLAY_LIST.beginCompile(MOB_OVERLAY_SCAN, style, worldTicks);
final float alpha = style.computeAlpha();
final Tessellator tess = Tessellator.instance;
@@ -136,12 +124,7 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
for (int k = 0; k < MOB_OVERLAY_SCAN.getHeight(); k++) {
if (MOB_OVERLAY_SCAN.readSpawnMode(i, k, j) == 0) continue;
final double yOffset = getOverlayYOffset(
world,
MOB_OVERLAY_SCAN.getMinX() + i,
MOB_OVERLAY_SCAN.getMinY() + k,
MOB_OVERLAY_SCAN.getMinZ() + j);
MARKED_FACE.moveTo(i, k + yOffset, j);
MARKED_FACE.moveTo(i, k + MOB_OVERLAY_SCAN.readOverlayYOffset(i, k, j), j);
loadNeighbourModes(i, k, j);
MARKED_FACE.applyColor(style.colouring, alpha);
style.addVertices(MARKED_FACE);
@@ -191,33 +174,6 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
GL11.glDisable(GL11.GL_BLEND);
}
private static final Entity dummyEntity = new EntityPig(null);
private static final AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
public static byte getSpawnMode(Chunk chunk, int x, int y, int z) {
if (y >= chunk.worldObj.getHeight()) {
return 0;
}
if (chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15) >= 8
|| !SpawnerAnimals.canCreatureTypeSpawnAtLocation(EnumCreatureType.monster, chunk.worldObj, x, y, z)) {
return 0;
}
aabb.minX = x + 0.2;
aabb.maxX = x + 0.8;
aabb.minY = y + 0.01;
aabb.maxY = y + 1.8;
aabb.minZ = z + 0.2;
aabb.maxZ = z + 0.8;
if (!chunk.worldObj.getCollidingBoundingBoxes(dummyEntity, aabb).isEmpty()
|| chunk.worldObj.isAnyLiquid(aabb)) {
return 0;
}
return (byte) (chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15) >= 8 ? 1 : 2);
}
private static void renderChunkBounds(Entity entity, int intOffsetX, int intOffsetY, int intOffsetZ) {
if (chunkOverlay == 0) return;
@@ -17,7 +17,7 @@ public final class MobOverlayDisplayList {
/**
* Compiles after a {@link MobOverlayScan#getModesVersion} change are debounced to one per {@code MIN_COMPILE_TICKS}
* ticks, because the version changes several times per second while the player moves fast, and a compile takes a
* ticks, because the version changes several times per second while the player moves fast, and a compile runs for a
* millisecond or more.
*/
public boolean isCompileDue(int currentModesVersion, MobOverlayStyle currentStyle, long worldTicks) {
@@ -1,23 +1,27 @@
package codechicken.nei.moboverlay;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSnow;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.IWorldAccess;
import net.minecraft.world.SpawnerAnimals;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import codechicken.lib.math.MathHelper;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.WorldOverlayRenderer;
/**
* Spawn modes in a box around the player, from {@link WorldOverlayRenderer#getSpawnMode}: 0 for no spawns, 1 for night
* only and 2 for any time. The box moves with the player once the player is a few blocks from the box's centre, and
* {@link #update} scans only the blocks that enter the box. {@link #update} rescans the column of a block or light
* change on the next tick. On each tick, {@link #update} also rescans a slice of the columns, for changes with no block
* update, such as a boat that moves into the box.
* Spawn modes and snow layers in a box around the player. The spawn modes are from {@link Column#getSpawnMode}: 0 for
* no spawns, 1 for night only and 2 for any time. The box moves with the player once the player is a few blocks from
* the box's centre, and {@link #update} scans only the blocks that enter the box. {@link #update} rescans the column of
* a block or light change on the next tick. On each tick, {@link #update} also rescans a slice of the columns, for
* changes with no block update, such as a boat that moves into the box.
*/
public final class MobOverlayScan {
@@ -31,6 +35,8 @@ public final class MobOverlayScan {
private static final int RECENTRE_DISTANCE = 4;
private static final int VERTICAL_RECENTRE_DISTANCE = 2;
private static final int RESCAN_TICKS = 40;
private static final int SPAWN_MODE_MASK = 3;
private static final int SNOW_LAYERS_SHIFT = 2;
private final IWorldAccess changeListener = new ChangeListener();
private final Column column = new Column();
@@ -38,7 +44,8 @@ public final class MobOverlayScan {
private int verticalRadius;
private int span;
private int height;
// a ring buffer over the box, indexed by `findCell()`
// a ring buffer over the box, indexed by `findCell()`. A cell has the spawn mode in the bits of `SPAWN_MODE_MASK`,
// and the block's snow layers shifted left by `SNOW_LAYERS_SHIFT`
private byte[] modes = new byte[0];
// indexed by `findColumn(x, z)`
private boolean[] dirty = new boolean[0];
@@ -55,6 +62,8 @@ public final class MobOverlayScan {
private World scannedWorld;
public void clear() {
if (scannedWorld == null && span == 0) return;
if (scannedWorld != null) scannedWorld.removeWorldAccess(changeListener);
radius = 0;
verticalRadius = 0;
@@ -64,6 +73,8 @@ public final class MobOverlayScan {
dirty = new boolean[0];
hasModes = false;
scannedWorld = null;
// `Chunk.worldObj` references the world
column.chunk = null;
}
/**
@@ -101,7 +112,7 @@ public final class MobOverlayScan {
if (isChanged) modesVersion++;
}
/** The version changes when a spawn mode changes or the box moves. */
/** The version changes when a spawn mode or a snow layer changes, or the box moves. */
public int getModesVersion() {
return modesVersion;
}
@@ -128,7 +139,18 @@ public final class MobOverlayScan {
/** {@code i} and {@code j} are from 0 to {@link #getSpan}, and {@code k} is from 0 to {@link #getHeight}. */
public byte readSpawnMode(int i, int k, int j) {
return modes[findCell(minX + i, minY + k, minZ + j)];
return (byte) (modes[findCell(minX + i, minY + k, minZ + j)] & SPAWN_MODE_MASK);
}
/**
* Height of the overlay above the bottom of the block, so that a snow layer does not cover the overlay. The indices
* are those of {@link #readSpawnMode}.
*/
public double readOverlayYOffset(int i, int k, int j) {
final int SNOW_LAYERS_PER_BLOCK = 8;
final double OVERLAY_GAP = 0.02;
final int snowLayers = modes[findCell(minX + i, minY + k, minZ + j)] >> SNOW_LAYERS_SHIFT;
return (double) snowLayers / SNOW_LAYERS_PER_BLOCK + OVERLAY_GAP;
}
private void resize(int newRadius, int newVerticalRadius) {
@@ -139,10 +161,10 @@ public final class MobOverlayScan {
modes = new byte[span * span * height];
dirty = new boolean[span * span];
hasModes = false;
nextRescanColumn = 0;
}
private void scanFullBox(int centreX, int centreY, int centreZ) {
final long startNanos = System.nanoTime();
minX = centreX - radius;
minY = centreY - verticalRadius;
minZ = centreZ - radius;
@@ -154,12 +176,6 @@ public final class MobOverlayScan {
hasModes = true;
modesVersion++;
scannedTick = scannedWorld.getTotalWorldTime();
NEIClientConfig.logger.info(
"moboverlay.scan.full radius={} verticalRadius={} columns={} micros={}",
radius,
verticalRadius,
span * span,
(System.nanoTime() - startNanos) / 1000);
}
private void watchWorld(World world) {
@@ -230,11 +246,11 @@ public final class MobOverlayScan {
final int z = minZ + nextRescanColumn % span;
isChanged |= scanColumn(x, z);
}
if (nextRescanColumn == columnCount) nextRescanColumn = 0;
if (nextRescanColumn >= columnCount) nextRescanColumn = 0;
return isChanged;
}
/** @return whether a spawn mode changed */
/** @return whether a spawn mode or a snow layer changed */
private boolean scanColumn(int x, int z) {
column.moveTo(x, z);
dirty[findColumn(x, z)] = false;
@@ -255,6 +271,8 @@ public final class MobOverlayScan {
*/
private final class Column {
private final Entity dummyEntity = new EntityPig(null);
private final AxisAlignedBB spawnBox = AxisAlignedBB.getBoundingBox(0, 0, 0, 0, 0, 0);
private int x;
private int z;
private Chunk chunk;
@@ -268,21 +286,60 @@ public final class MobOverlayScan {
canBiomeSpawn = !biome.getSpawnableList(EnumCreatureType.monster).isEmpty()
&& biome.getSpawningChance() > 0;
chunk = scannedWorld.getChunkFromBlockCoords(x, z);
topY = Math.min(scannedWorld.getHeight() - 1, scannedWorld.getHeightValue(x, z));
// on the client, `Chunk.generateHeightMap()` never tests the top layer of the highest non-empty section.
// `getHeightValue()` can then be below a block on that layer, so test that layer here
final int topLayerY = chunk.getTopFilledSegment() + 15;
final boolean isTopLayerFilled = !chunk.isEmpty() && chunk.func_150808_b(x & 15, topLayerY, z & 15) != 0;
final int heightValue = isTopLayerFilled ? topLayerY + 1 : scannedWorld.getHeightValue(x, z);
topY = Math.min(scannedWorld.getHeight() - 1, heightValue);
}
/** @return whether a spawn mode changed */
/** @return whether a spawn mode or a snow layer changed */
private boolean scan(int fromY, int toY) {
boolean isChanged = false;
for (int y = fromY; y < toY; y++) {
final byte spawnMode = canBiomeSpawn && y <= topY ? WorldOverlayRenderer.getSpawnMode(chunk, x, y, z)
: 0;
final int spawnMode = canBiomeSpawn && y <= topY ? getSpawnMode(y) : 0;
final byte cellValue = (byte) (spawnMode == 0 ? 0
: spawnMode | (readSnowLayers(y) << SNOW_LAYERS_SHIFT));
final int cell = findCell(x, y, z);
isChanged |= modes[cell] != spawnMode;
modes[cell] = spawnMode;
isChanged |= modes[cell] != cellValue;
modes[cell] = cellValue;
}
return isChanged;
}
/** The spawn mode of the block at height {@code y} in this column. */
private byte getSpawnMode(int y) {
if (y >= chunk.worldObj.getHeight()) {
return 0;
}
if (chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15) >= 8 || !SpawnerAnimals
.canCreatureTypeSpawnAtLocation(EnumCreatureType.monster, chunk.worldObj, x, y, z)) {
return 0;
}
spawnBox.minX = x + 0.2;
spawnBox.maxX = x + 0.8;
spawnBox.minY = y + 0.01;
spawnBox.maxY = y + 1.8;
spawnBox.minZ = z + 0.2;
spawnBox.maxZ = z + 0.8;
if (!chunk.worldObj.getCollidingBoundingBoxes(dummyEntity, spawnBox).isEmpty()
|| chunk.worldObj.isAnyLiquid(spawnBox)) {
return 0;
}
return (byte) (chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15) >= 8 ? 1 : 2);
}
private int readSnowLayers(int y) {
final Block block = chunk.getBlock(x & 15, y, z & 15);
if (!(block instanceof BlockSnow)) return 0;
// snow metadata 0 is one layer
return (chunk.getBlockMetadata(x & 15, y, z & 15) & 7) + 1;
}
}
/** Marks the columns of the block and light changes in {@link #scannedWorld}. */
@@ -62,15 +62,6 @@ public enum MobOverlayStyle {
}
},
/** The GTNH logo without the globe. */
GTNH_LOGO("gtnh_logo", Colouring.OVERLAY) {
@Override
public void addVertices(MobOverlayFace face) {
face.addTexturedFace();
}
},
/** The pufferfish sticker. */
PUFFERFISH("pufferfish", Colouring.STICKER) {
@@ -124,22 +115,12 @@ public enum MobOverlayStyle {
return name().toLowerCase(Locale.ROOT);
}
public String getLangKey() {
return switch (this) {
case X -> "nei.options.world.overlays.mobOverlayStyle.x";
case CONNECTED -> "nei.options.world.overlays.mobOverlayStyle.connected";
case SQUARE -> "nei.options.world.overlays.mobOverlayStyle.square";
case GTNH_LOGO -> "nei.options.world.overlays.mobOverlayStyle.gtnh_logo";
case PUFFERFISH -> "nei.options.world.overlays.mobOverlayStyle.pufferfish";
};
}
public float computeAlpha() {
return switch (this) {
case CONNECTED -> TINT_ALPHA;
case SQUARE -> MARK_ALPHA;
// the alpha is in the PNGs
case X, GTNH_LOGO, PUFFERFISH -> 1.0F;
// opaque lines for X, and the alpha of the PNG for PUFFERFISH
case X, PUFFERFISH -> 1.0F;
};
}
@@ -570,7 +570,6 @@ nei.options.world.overlays.mobOverlayStyle=Mob Spawn Overlay Style
nei.options.world.overlays.mobOverlayStyle.x=X
nei.options.world.overlays.mobOverlayStyle.connected=Connected
nei.options.world.overlays.mobOverlayStyle.square=Square
nei.options.world.overlays.mobOverlayStyle.gtnh_logo=GTNH Logo
nei.options.world.overlays.mobOverlayStyle.pufferfish=Pufferfish
nei.options.world.overlays.mobOverlayRadius=Mob Spawn Overlay Horizontal Radius
nei.options.world.overlays.mobOverlayRadius.tip=Horizontal block radius scanned around you. Range 8-64 blocks
Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

@@ -1,6 +0,0 @@
{
"texture": {
"blur": true,
"clamp": true
}
}