Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import dev.ftb.mods.ftbchunks.client.map.MapMode;
import dev.ftb.mods.ftbchunks.client.minimap.MinimapComponentConfig;
import dev.ftb.mods.ftbchunks.client.minimap.components.*;
import dev.ftb.mods.ftblibrary.config.Tristate;
import dev.ftb.mods.ftblibrary.config.manager.ConfigManager;
import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
import dev.ftb.mods.ftblibrary.snbt.config.*;
import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.ChunkPos;
import org.jetbrains.annotations.Nullable;

import java.util.Collections;
import java.util.*;
import java.util.stream.Stream;

public interface FTBChunksClientConfig {
Expand Down Expand Up @@ -41,8 +44,6 @@ public interface FTBChunksClientConfig {
IntValue WATER_VISIBILITY = APPEARANCE.addInt("water_visibility", 220, 0, 255).excluded().comment("Advanced option. Water visibility");
IntValue GRASS_DARKNESS = APPEARANCE.addInt("grass_darkness", 50, 0, 255).excluded().comment("Advanced option. Grass darkness");
IntValue FOLIAGE_DARKNESS = APPEARANCE.addInt("foliage_darkness", 50, 0, 255).excluded().comment("Advanced option. Foliage darkness");
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");
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");

SNBTConfig WAYPOINTS = CONFIG.addGroup("waypoints", 1);
BooleanValue IN_WORLD_WAYPOINTS = WAYPOINTS.addBoolean("in_world_waypoints", true).comment("Show waypoints in world");
Expand Down Expand Up @@ -96,6 +97,13 @@ public interface FTBChunksClientConfig {
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)");
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");

SNBTConfig CUSTOM_BEHAVIOUR = CONFIG.addGroup("custom_behaviour").excluded();

BooleanValue OVERRIDE_MIN_Y_LEVEL = CUSTOM_BEHAVIOUR.addBoolean("use_custom_min_y_level", false).excluded().comment("Override minimum Y level used when rendering map");
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");

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");

static boolean hasOtherMinimapMod() {
return Platform.isModLoaded("journeymap") || Platform.isModLoaded("voxelmap") || Platform.isModLoaded("antiqueatlas") || Platform.isModLoaded("xaerominimap");
}
Expand All @@ -104,4 +112,58 @@ static void saveConfig() {
ConfigManager.getInstance().save(KEY);
}

class ChunkPosCustomYSetValue extends BaseValue<Set<ChunkPosWithMinY>> {
private final HashMap<Long, Integer> lookup = new HashMap<>();

protected ChunkPosCustomYSetValue(@Nullable SNBTConfig c, String n, Set<ChunkPosWithMinY> def) {
super(c, n, def);
super.set(new HashSet<>());
}

@Override
public void write(SNBTCompoundTag tag) {
var listTag = new ListTag();

for (ChunkPosWithMinY pos : get()) {
var posTag = new SNBTCompoundTag();
posTag.putInt("x", pos.chunkX());
posTag.putInt("z", pos.chunkZ());
posTag.putInt("min_y", pos.minY());
listTag.add(posTag);
}

tag.put(key, listTag);
}

@Override
public void read(SNBTCompoundTag tag) {
var list = tag.getList(key, SNBTCompoundTag.class);
Set<ChunkPosWithMinY> set = new HashSet<>();

for (SNBTCompoundTag posTag : list) {
int x = posTag.getInt("x");
int z = posTag.getInt("z");
int minY = posTag.getInt("min_y");
set.add(new ChunkPosWithMinY(x, z, minY));
}

set(set);
}

@Override
public void set(Set<ChunkPosWithMinY> value) {
super.set(value);

lookup.clear();
for (ChunkPosWithMinY pos : value) {
lookup.put(ChunkPos.asLong(pos.chunkX(), pos.chunkZ()), pos.minY());
}
}

public Map<Long, Integer> lookup() {
return Collections.unmodifiableMap(lookup);
}
}

record ChunkPosWithMinY(int chunkX, int chunkZ, int minY) {}
}
22 changes: 19 additions & 3 deletions common/src/main/java/dev/ftb/mods/ftbchunks/util/HeightUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig;
import dev.ftb.mods.ftbchunks.core.BlockStateFTBC;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -40,9 +42,15 @@ public static int getHeight(Level level, @Nullable ChunkAccess chunkAccess, Bloc
return UNKNOWN;
}

int bottomY = FTBChunksClientConfig.USE_CUSTOM_MIN_Y_LEVEL.get()
? FTBChunksClientConfig.CUSTOM_MIN_Y_LEVEL.get()
: chunkAccess.getMinBuildHeight();
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;

// Clamped within the dimensions build height limits
int startY = FTBChunksClientConfig.OVERRIDE_MIN_Y_LEVEL.get()
? getMinYFromChunkOrConfig(chunkX, chunkZ)
: chunkAccess.getMinBuildHeight();

int bottomY = Mth.clamp(startY, chunkAccess.getMinBuildHeight(), chunkAccess.getMaxBuildHeight());

int topY = pos.getY();
boolean hasCeiling = level.dimensionType().hasCeiling();
Expand Down Expand Up @@ -78,4 +86,12 @@ public static int getHeight(Level level, @Nullable ChunkAccess chunkAccess, Bloc
pos.setY(UNKNOWN);
return UNKNOWN;
}

private static int getMinYFromChunkOrConfig(int x, int z) {
long chunkPos = ChunkPos.asLong(x, z);

return FTBChunksClientConfig.CHUNKS_WITH_CUSTOM_Y.lookup()
.getOrDefault(chunkPos, FTBChunksClientConfig.OVERRIDE_MIN_Y_LEVEL_VALUE.get());
}

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readable_name=FTB Chunks
maven_group=dev.ftb.mods
mod_author=FTB Team

mod_version=2101.1.12
mod_version=2101.1.13
minecraft_version=1.21.1

# Deps
Expand Down