Skip to content

Commit 7b0799b

Browse files
feat: overridable min_y levels for dimensions with ceilings
1 parent a31b343 commit 7b0799b

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

common/src/main/java/dev/ftb/mods/ftbchunks/client/FTBChunksClientConfig.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
import dev.ftb.mods.ftbchunks.client.map.MapMode;
88
import dev.ftb.mods.ftbchunks.client.minimap.MinimapComponentConfig;
99
import dev.ftb.mods.ftbchunks.client.minimap.components.*;
10-
import dev.ftb.mods.ftblibrary.config.Tristate;
10+
import dev.ftb.mods.ftbchunks.util.HeightUtils;
1111
import dev.ftb.mods.ftblibrary.config.manager.ConfigManager;
12+
import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
1213
import dev.ftb.mods.ftblibrary.snbt.config.*;
14+
import net.minecraft.nbt.ListTag;
1315
import net.minecraft.resources.ResourceLocation;
16+
import net.minecraft.world.level.ChunkPos;
17+
import org.jetbrains.annotations.Nullable;
1418

15-
import java.util.Collections;
19+
import java.util.*;
1620
import java.util.stream.Stream;
1721

1822
public interface FTBChunksClientConfig {
@@ -41,8 +45,6 @@ public interface FTBChunksClientConfig {
4145
IntValue WATER_VISIBILITY = APPEARANCE.addInt("water_visibility", 220, 0, 255).excluded().comment("Advanced option. Water visibility");
4246
IntValue GRASS_DARKNESS = APPEARANCE.addInt("grass_darkness", 50, 0, 255).excluded().comment("Advanced option. Grass darkness");
4347
IntValue FOLIAGE_DARKNESS = APPEARANCE.addInt("foliage_darkness", 50, 0, 255).excluded().comment("Advanced option. Foliage darkness");
44-
BooleanValue USE_CUSTOM_MIN_Y_LEVEL = APPEARANCE.addBoolean("use_custom_min_y_level", false).excluded().comment("Advanced option. Use custom minimum Y level to scan when rendering map");
45-
IntValue CUSTOM_MIN_Y_LEVEL = APPEARANCE.addInt("custom_min_y_level", 0, Short.MIN_VALUE, Short.MAX_VALUE).excluded().comment("Advanced option. Custom minimum Y level to scan when rendering map, used if use_custom_min_y_level is true");
4648

4749
SNBTConfig WAYPOINTS = CONFIG.addGroup("waypoints", 1);
4850
BooleanValue IN_WORLD_WAYPOINTS = WAYPOINTS.addBoolean("in_world_waypoints", true).comment("Show waypoints in world");
@@ -96,6 +98,13 @@ public interface FTBChunksClientConfig {
9698
IntValue AUTORELEASE_ON_MAP_CLOSE = MEMORY.addInt("autorelease_on_map_close", 32, 0, Integer.MAX_VALUE).comment("When the large map is closed, auto-release least recently accessed regions down to this number (0 disables releasing)");
9799
BooleanValue MAX_ZOOM_CONSTRAINT = MEMORY.addBoolean("max_zoom_constraint", true).comment("Constrain maximum map zoom-out based on number of explored regions and available memory");
98100

101+
SNBTConfig CUSTOM_BEHAVIOUR = CONFIG.addGroup("custom_behaviour").excluded();
102+
103+
BooleanValue OVERRIDE_MIN_Y_LEVEL = CUSTOM_BEHAVIOUR.addBoolean("use_custom_min_y_level", false).excluded().comment("Override minimum Y level used when rendering map");
104+
IntValue OVERRIDE_MIN_Y_LEVEL_VALUE = CUSTOM_BEHAVIOUR.addInt("custom_min_y_level", Short.MIN_VALUE, Short.MIN_VALUE, Short.MAX_VALUE).excluded().comment("Custom minimum Y level to scan when rendering map, used if use_custom_min_y_level is true\"");
105+
106+
ChunkPosCustomYSetValue CHUNKS_WITH_CUSTOM_Y = CUSTOM_BEHAVIOUR.add(new ChunkPosCustomYSetValue(CUSTOM_BEHAVIOUR, "chunks_with_custom_y", Collections.emptySet())).excluded().comment("Set of chunks with custom minimum Y levels, used if use_custom_min_y_level is true");
107+
99108
static boolean hasOtherMinimapMod() {
100109
return Platform.isModLoaded("journeymap") || Platform.isModLoaded("voxelmap") || Platform.isModLoaded("antiqueatlas") || Platform.isModLoaded("xaerominimap");
101110
}
@@ -104,4 +113,40 @@ static void saveConfig() {
104113
ConfigManager.getInstance().save(KEY);
105114
}
106115

116+
class ChunkPosCustomYSetValue extends BaseValue<Set<HeightUtils.ChunkPosWithMinY>> {
117+
protected ChunkPosCustomYSetValue(@Nullable SNBTConfig c, String n, Set<HeightUtils.ChunkPosWithMinY> def) {
118+
super(c, n, def);
119+
super.set(new HashSet<>());
120+
}
121+
122+
@Override
123+
public void write(SNBTCompoundTag tag) {
124+
var listTag = new ListTag();
125+
126+
for (HeightUtils.ChunkPosWithMinY pos : get()) {
127+
var posTag = new SNBTCompoundTag();
128+
posTag.putInt("x", pos.chunkX());
129+
posTag.putInt("z", pos.chunkZ());
130+
posTag.putInt("min_y", pos.minY());
131+
listTag.add(posTag);
132+
}
133+
134+
tag.put(key, listTag);
135+
}
136+
137+
@Override
138+
public void read(SNBTCompoundTag tag) {
139+
var list = tag.getList(key, SNBTCompoundTag.class);
140+
Set<HeightUtils.ChunkPosWithMinY> set = new HashSet<>();
141+
142+
for (SNBTCompoundTag posTag : list) {
143+
int x = posTag.getInt("x");
144+
int z = posTag.getInt("z");
145+
int minY = posTag.getInt("min_y");
146+
set.add(new HeightUtils.ChunkPosWithMinY(x, z, minY));
147+
}
148+
149+
set(set);
150+
}
151+
}
107152
}

common/src/main/java/dev/ftb/mods/ftbchunks/util/HeightUtils.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig;
55
import dev.ftb.mods.ftbchunks.core.BlockStateFTBC;
66
import net.minecraft.core.BlockPos;
7+
import net.minecraft.util.Mth;
78
import net.minecraft.world.level.Level;
89
import net.minecraft.world.level.block.Blocks;
910
import net.minecraft.world.level.block.state.BlockState;
1011
import net.minecraft.world.level.chunk.ChunkAccess;
1112
import net.minecraft.world.level.material.Fluids;
1213
import org.jetbrains.annotations.Nullable;
1314

15+
import java.util.Set;
16+
1417
public class HeightUtils {
1518
public static final int UNKNOWN = Short.MIN_VALUE + 1;
1619

@@ -40,9 +43,15 @@ public static int getHeight(Level level, @Nullable ChunkAccess chunkAccess, Bloc
4043
return UNKNOWN;
4144
}
4245

43-
int bottomY = FTBChunksClientConfig.USE_CUSTOM_MIN_Y_LEVEL.get()
44-
? FTBChunksClientConfig.CUSTOM_MIN_Y_LEVEL.get()
45-
: chunkAccess.getMinBuildHeight();
46+
int chunkX = pos.getX() >> 4;
47+
int chunkZ = pos.getZ() >> 4;
48+
49+
// Clamped within the dimensions build height limits
50+
int startY = FTBChunksClientConfig.OVERRIDE_MIN_Y_LEVEL.get()
51+
? getMinYFromChunkOrConfig(chunkX, chunkZ)
52+
: chunkAccess.getMinBuildHeight();
53+
54+
int bottomY = Mth.clamp(startY, chunkAccess.getMinBuildHeight(), chunkAccess.getMaxBuildHeight());
4655

4756
int topY = pos.getY();
4857
boolean hasCeiling = level.dimensionType().hasCeiling();
@@ -78,4 +87,17 @@ public static int getHeight(Level level, @Nullable ChunkAccess chunkAccess, Bloc
7887
pos.setY(UNKNOWN);
7988
return UNKNOWN;
8089
}
90+
91+
private static int getMinYFromChunkOrConfig(int x, int z) {
92+
Set<ChunkPosWithMinY> chunkPosWithMinY = FTBChunksClientConfig.CHUNKS_WITH_CUSTOM_Y.get();
93+
for (ChunkPosWithMinY c : chunkPosWithMinY) {
94+
if (c.chunkX == x && c.chunkZ == z) {
95+
return c.minY;
96+
}
97+
}
98+
99+
return FTBChunksClientConfig.OVERRIDE_MIN_Y_LEVEL_VALUE.get();
100+
}
101+
102+
public record ChunkPosWithMinY(int chunkX, int chunkZ, int minY) {}
81103
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readable_name=FTB Chunks
88
maven_group=dev.ftb.mods
99
mod_author=FTB Team
1010

11-
mod_version=2101.1.12
11+
mod_version=2101.1.13
1212
minecraft_version=1.21.1
1313

1414
# Deps

0 commit comments

Comments
 (0)