Skip to content

Commit cbba06f

Browse files
Merge branch '1.21.1/dev' into 1.21.1/main
2 parents 40957f7 + 367cd60 commit cbba06f

File tree

5 files changed

+111
-10
lines changed

5 files changed

+111
-10
lines changed

common/src/main/java/dev/ftb/mods/ftbchunks/FTBChunksWorldConfig.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dev.ftb.mods.ftbchunks.api.ProtectionPolicy;
66
import dev.ftb.mods.ftbchunks.data.*;
77
import dev.ftb.mods.ftbchunks.integration.PermissionsHelper;
8+
import dev.ftb.mods.ftbchunks.util.ChunkPosCustomYSetValue;
89
import dev.ftb.mods.ftbchunks.util.DimensionFilter;
910
import dev.ftb.mods.ftblibrary.config.NameMap;
1011
import dev.ftb.mods.ftblibrary.integration.stages.StageHelper;
@@ -124,7 +125,14 @@ public interface FTBChunksWorldConfig {
124125
BooleanValue DEF_PVP = TEAM_PROP_DEFAULTS.addBoolean("def_pvp", true)
125126
.comment("Default PvP setting in claimed chunks");
126127

127-
SNBTConfig DEV = CONFIG.addGroup("dev");
128+
SNBTConfig CUSTOM_BEHAVIOUR = CONFIG.addGroup("custom_behaviour").excluded();
129+
130+
BooleanValue OVERRIDE_MIN_Y_LEVEL = CUSTOM_BEHAVIOUR.addBoolean("use_custom_min_y_level", false).excluded().comment("Override minimum Y level used when rendering map");
131+
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");
132+
133+
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");
134+
135+
SNBTConfig DEV = CONFIG.addGroup("dev");
128136
BooleanValue DEV_COMMANDS = DEV.addBoolean("commands", false)
129137
.excluded()
130138
.comment("Enable dev commands");
@@ -174,4 +182,4 @@ static void onConfigChanged(boolean isServerConfig) {
174182
ClaimedChunkManagerImpl.getInstance().getOrCreateData(team).updateLimits());
175183
}
176184
}
177-
}
185+
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
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.ChunkPosCustomYSetValue;
1111
import dev.ftb.mods.ftblibrary.config.manager.ConfigManager;
1212
import dev.ftb.mods.ftblibrary.snbt.config.*;
1313
import net.minecraft.resources.ResourceLocation;
1414

15-
import java.util.Collections;
15+
import java.util.*;
1616
import java.util.stream.Stream;
1717

1818
public interface FTBChunksClientConfig {
@@ -41,8 +41,6 @@ public interface FTBChunksClientConfig {
4141
IntValue WATER_VISIBILITY = APPEARANCE.addInt("water_visibility", 220, 0, 255).excluded().comment("Advanced option. Water visibility");
4242
IntValue GRASS_DARKNESS = APPEARANCE.addInt("grass_darkness", 50, 0, 255).excluded().comment("Advanced option. Grass darkness");
4343
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");
4644

4745
SNBTConfig WAYPOINTS = CONFIG.addGroup("waypoints", 1);
4846
BooleanValue IN_WORLD_WAYPOINTS = WAYPOINTS.addBoolean("in_world_waypoints", true).comment("Show waypoints in world");
@@ -103,5 +101,4 @@ static boolean hasOtherMinimapMod() {
103101
static void saveConfig() {
104102
ConfigManager.getInstance().save(KEY);
105103
}
106-
107104
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package dev.ftb.mods.ftbchunks.util;
2+
3+
import dev.ftb.mods.ftblibrary.snbt.SNBTCompoundTag;
4+
import dev.ftb.mods.ftblibrary.snbt.config.BaseValue;
5+
import dev.ftb.mods.ftblibrary.snbt.config.SNBTConfig;
6+
import net.minecraft.nbt.ListTag;
7+
import net.minecraft.world.level.ChunkPos;
8+
import org.jetbrains.annotations.Nullable;
9+
10+
import java.util.*;
11+
12+
public class ChunkPosCustomYSetValue extends BaseValue<Set<ChunkPosWithMinY>> {
13+
private final HashMap<Long, Integer> lookup = new HashMap<>();
14+
15+
public ChunkPosCustomYSetValue(@Nullable SNBTConfig c, String n, Set<ChunkPosWithMinY> def) {
16+
super(c, n, def);
17+
super.set(new HashSet<>());
18+
}
19+
20+
@Override
21+
public void write(SNBTCompoundTag tag) {
22+
var listTag = new ListTag();
23+
24+
for (ChunkPosWithMinY pos : get()) {
25+
var posTag = new SNBTCompoundTag();
26+
posTag.putInt("x", pos.chunkX());
27+
posTag.putInt("z", pos.chunkZ());
28+
posTag.putInt("min_y", pos.minY());
29+
listTag.add(posTag);
30+
}
31+
32+
tag.put(key, listTag);
33+
}
34+
35+
@Override
36+
public void read(SNBTCompoundTag tag) {
37+
var list = tag.getList(key, SNBTCompoundTag.class);
38+
Set<ChunkPosWithMinY> set = new HashSet<>();
39+
40+
for (SNBTCompoundTag posTag : list) {
41+
int x = posTag.getInt("x");
42+
int z = posTag.getInt("z");
43+
int minY = posTag.getInt("min_y");
44+
set.add(new ChunkPosWithMinY(x, z, minY));
45+
}
46+
47+
set(set);
48+
}
49+
50+
@Override
51+
public void set(Set<ChunkPosWithMinY> value) {
52+
super.set(value);
53+
54+
lookup.clear();
55+
for (ChunkPosWithMinY pos : value) {
56+
lookup.put(ChunkPos.asLong(pos.chunkX(), pos.chunkZ()), pos.minY());
57+
}
58+
}
59+
60+
public Map<Long, Integer> lookup() {
61+
return Collections.unmodifiableMap(lookup);
62+
}
63+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package dev.ftb.mods.ftbchunks.util;
2+
3+
import net.minecraft.world.level.ChunkPos;
4+
5+
/**
6+
* Helper record to store chunk position along with a minimum Y value.
7+
*/
8+
public record ChunkPosWithMinY(int chunkX, int chunkZ, int minY) {
9+
public ChunkPos asChunkPos() {
10+
return new ChunkPos(chunkX, chunkZ);
11+
}
12+
13+
public long chunkPosAsLong() {
14+
return asChunkPos().toLong();
15+
}
16+
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package dev.ftb.mods.ftbchunks.util;
22

3+
import dev.ftb.mods.ftbchunks.FTBChunksWorldConfig;
34
import dev.ftb.mods.ftbchunks.client.FTBChunksClient;
45
import dev.ftb.mods.ftbchunks.client.FTBChunksClientConfig;
56
import dev.ftb.mods.ftbchunks.core.BlockStateFTBC;
67
import net.minecraft.core.BlockPos;
8+
import net.minecraft.util.Mth;
9+
import net.minecraft.world.level.ChunkPos;
710
import net.minecraft.world.level.Level;
811
import net.minecraft.world.level.block.Blocks;
912
import net.minecraft.world.level.block.state.BlockState;
@@ -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 = FTBChunksWorldConfig.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,12 @@ 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+
long chunkPos = ChunkPos.asLong(x, z);
93+
94+
return FTBChunksWorldConfig.CHUNKS_WITH_CUSTOM_Y.lookup()
95+
.getOrDefault(chunkPos, FTBChunksWorldConfig.OVERRIDE_MIN_Y_LEVEL_VALUE.get());
96+
}
97+
8198
}

0 commit comments

Comments
 (0)