Skip to content

Commit ea251d4

Browse files
authored
Configurable sub-level assembly height
Adds 2 config values, implementing suggestions 2 & 3 from #938: - SUB_LEVEL_START_POS: Determines the approach to use for determining the height (Y value) of the first block in a newly assembled sub-level (FIXED, DYNAMIC, MIDPOINT) - FIXED: Uses the height specified by SUB_LEVEL_FIXED_START_HEIGHT (Essentially the current approach) - DYNAMIC: Uses the world height of the position the block is in (Spawn a sub-level at Y=73, the block is placed at Y=73 in the sub-level) - MIDPOINT: Calculates the midpoint between the min and max build limits, then uses that as the height - SUB_LEVEL_FIXED_START_HEIGHT - If SUB_LEVEL_START_POS is set to FIXED, then this is the height (Default value of 128 matches the current approach)
1 parent 3594364 commit ea251d4

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

common/src/main/java/dev/ryanhcode/sable/SableConfig.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.neoforged.neoforge.common.ModConfigSpec;
44

55
public final class SableConfig {
6+
public enum SubLevelStartPos { FIXED, DYNAMIC, MIDPOINT }
67

78
public static final ModConfigSpec SPEC;
89

@@ -19,6 +20,8 @@ public final class SableConfig {
1920
public static final ModConfigSpec.BooleanValue ATTEMPT_UDP_NETWORKING;
2021
public static final ModConfigSpec.BooleanValue VERBOSE_SERIALIZATION_LOGGING;
2122
public static final ModConfigSpec.BooleanValue SUB_LEVEL_SAVING_LOG_MESSAGE;
23+
public static final ModConfigSpec.EnumValue<SubLevelStartPos> SUB_LEVEL_START_POS;
24+
public static final ModConfigSpec.IntValue SUB_LEVEL_FIXED_START_HEIGHT;
2225

2326
static {
2427
final ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
@@ -64,6 +67,12 @@ public final class SableConfig {
6467
VERBOSE_SERIALIZATION_LOGGING = builder
6568
.comment("If Sable should use verbose logging for its serialization system and the holding chunk-map. Not recommended- for debugging purposes only.")
6669
.define("verbose_serialization_logging", false);
70+
SUB_LEVEL_START_POS = builder
71+
.comment("When a sub-level is created, how to determine the height within the sub-level that the first block should be placed at.")
72+
.defineEnum("sub_level_start_pos", SubLevelStartPos.FIXED);
73+
SUB_LEVEL_FIXED_START_HEIGHT = builder
74+
.comment("If 'sub_level_start_pos' is set to 'FIXED', the fixed height to use.")
75+
.defineInRange("sub_level_fixed_start_height", 128, Integer.MIN_VALUE, Integer.MAX_VALUE);
6776

6877
SPEC = builder.build();
6978
}

common/src/main/java/dev/ryanhcode/sable/api/SubLevelAssemblyHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.ryanhcode.sable.api;
22

33
import dev.ryanhcode.sable.Sable;
4+
import dev.ryanhcode.sable.SableConfig;
45
import dev.ryanhcode.sable.api.block.BlockSubLevelAssemblyListener;
56
import dev.ryanhcode.sable.api.physics.PhysicsPipeline;
67
import dev.ryanhcode.sable.api.physics.handle.RigidBodyHandle;
@@ -84,7 +85,14 @@ public static ServerSubLevel assembleBlocks(final ServerLevel level, final Block
8485
final LevelPlot plot = subLevel.getPlot();
8586
plot.newEmptyChunk(plot.getCenterChunk());
8687

87-
final BlockPos plotAnchor = plot.getCenterBlock();
88+
Integer yPos = 128;
89+
switch (SableConfig.SUB_LEVEL_START_POS.get()) {
90+
case FIXED -> yPos = SableConfig.SUB_LEVEL_FIXED_START_HEIGHT.getAsInt();
91+
case DYNAMIC -> yPos = anchor.getY();
92+
case MIDPOINT -> yPos = (level.getMinBuildHeight() + level.getMaxBuildHeight()) >> 1;
93+
}
94+
95+
final BlockPos plotAnchor = plot.getCenterBlock().atY(yPos);
8896
final SubLevelAssemblyHelper.AssemblyTransform transform = new SubLevelAssemblyHelper.AssemblyTransform(anchor, plotAnchor, 0, Rotation.NONE, level);
8997
SubLevelAssemblyHelper.moveOtherStuff(level, transform, blocks, bounds);
9098
SubLevelAssemblyHelper.moveBlocks(level, transform, blocks);

0 commit comments

Comments
 (0)