Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion common/src/main/java/dev/ryanhcode/sable/SableConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public final class SableConfig {
public static final ModConfigSpec.IntValue SUB_LEVEL_PUNCH_COOLDOWN_TICKS;
public static final ModConfigSpec.BooleanValue DISABLE_UDP_PIPELINE;
public static final ModConfigSpec.BooleanValue ATTEMPT_UDP_NETWORKING;
public static final ModConfigSpec.BooleanValue VERBOSE_SERIALIZATION_LOGGING;
public static final ModConfigSpec.BooleanValue SUB_LEVEL_SAVING_LOG_MESSAGE;
public static final ModConfigSpec.BooleanValue VERBOSE_SERIALIZATION_LOGGING;

static {
final ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
Expand Down
20 changes: 20 additions & 0 deletions common/src/main/java/dev/ryanhcode/sable/SableServerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package dev.ryanhcode.sable;

import net.neoforged.neoforge.common.ModConfigSpec;

public final class SableServerConfig {

public static final ModConfigSpec SPEC;

public static final ModConfigSpec.IntValue SUB_LEVEL_SUBSTEPS_PER_TICK;

static {
final ModConfigSpec.Builder builder = new ModConfigSpec.Builder();

SUB_LEVEL_SUBSTEPS_PER_TICK = builder
.comment("How many times the physics simulation is stepped in every second. Higher values will be significantly more performance intensive, but will have higher accuracy.")
.defineInRange("sub_level_substeps_per_tick", 2, 1, 10);

SPEC = builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ryanhcode.sable.config;

import dev.ryanhcode.sable.SableServerConfig;
import dev.ryanhcode.sable.api.sublevel.SubLevelContainer;
import dev.ryanhcode.sable.physics.config.PhysicsConfigData;
import dev.ryanhcode.sable.sublevel.system.SubLevelPhysicsSystem;
Expand All @@ -10,6 +11,7 @@
import net.minecraft.client.server.IntegratedServer;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.neoforged.neoforge.common.ModConfigSpec;

public class SubLevelSettingsScreen extends OptionsSubScreen {
public static final Component TITLE = Component.translatable("options.sable_menu");
Expand All @@ -22,18 +24,20 @@ public SubLevelSettingsScreen(final Screen optionsScreen, final Options options,
protected void addOptions() {
final IntegratedServer singleplayerServer = this.minecraft.getSingleplayerServer();


final ModConfigSpec.Range<?> range = SableServerConfig.SUB_LEVEL_SUBSTEPS_PER_TICK.getSpec().getRange();
this.list.addBig(new OptionInstance<>(
"options.physics_steps",
OptionInstance.cachedConstantTooltip(Component.translatable("options.physics_steps.tooltip")),
(component, substeps) -> Options.genericValueLabel(component, Component.translatable("options.physics_steps_template", substeps * 20)),
new OptionInstance.IntRange(1, 10, false),
new OptionInstance.IntRange((Integer) range.getMin(), (Integer) range.getMax(), false),
SubLevelContainer.getContainer(singleplayerServer.overworld()).physicsSystem().getConfig().substepsPerTick,
steps -> {
SableServerConfig.SUB_LEVEL_SUBSTEPS_PER_TICK.set(steps);
SableServerConfig.SPEC.save();
for (final ServerLevel level : singleplayerServer.getAllLevels()) {
final SubLevelPhysicsSystem physicsSystem = SubLevelContainer.getContainer(level).physicsSystem();
final PhysicsConfigData config = physicsSystem.getConfig();
config.substepsPerTick = steps;
config.updateFromConfig();
physicsSystem.getPipeline().updateConfigFrom(config);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.ryanhcode.sable.physics.config;

import dev.ryanhcode.sable.SableConfig;
import dev.ryanhcode.sable.SableServerConfig;

public class PhysicsConfigData {
/**
* The number of solver iterations run by the constraints solver for calculating forces.
Expand Down Expand Up @@ -28,4 +31,8 @@ public class PhysicsConfigData {
* Physics ticks done per game tick in the physics pipeline.
*/
public int substepsPerTick = 2;

public void updateFromConfig() {
this.substepsPerTick = SableServerConfig.SUB_LEVEL_SUBSTEPS_PER_TICK.getAsInt();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void initialize() {
final Vector3d gravity = new Vector3d(DimensionPhysicsData.getGravity(this.level));
final double universalDrag = DimensionPhysicsData.getUniversalDrag(this.level);

this.config.updateFromConfig();
this.pipeline.init(gravity, universalDrag);
this.pipeline.updateConfigFrom(this.config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.ryanhcode.sable.Sable;
import dev.ryanhcode.sable.SableCommonEvents;
import dev.ryanhcode.sable.SableConfig;
import dev.ryanhcode.sable.SableServerConfig;
import dev.ryanhcode.sable.command.SableCommand;
import dev.ryanhcode.sable.command.argument.SubLevelSelectorModifiers;
import dev.ryanhcode.sable.index.SableAttributes;
Expand Down Expand Up @@ -43,5 +44,6 @@ public void onInitialize() {
ServerLifecycleEvents.SYNC_DATA_PACK_CONTENTS.register((player, joined) -> SableCommonEvents.syncDataPacket(packet -> player.connection.send(packet)));

NeoForgeConfigRegistry.INSTANCE.register(Sable.MOD_ID, ModConfig.Type.COMMON, SableConfig.SPEC);
NeoForgeConfigRegistry.INSTANCE.register(Sable.MOD_ID, ModConfig.Type.SERVER, SableServerConfig.SPEC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import dev.ryanhcode.sable.Sable;
import dev.ryanhcode.sable.SableCommonEvents;
import dev.ryanhcode.sable.SableConfig;
import dev.ryanhcode.sable.SableServerConfig;
import dev.ryanhcode.sable.command.SableCommand;
import dev.ryanhcode.sable.command.argument.SubLevelSelectorModifiers;
import dev.ryanhcode.sable.index.SableAttributes;
Expand Down Expand Up @@ -42,6 +43,7 @@ public SableNeoForge(final ModContainer modContainer, final IEventBus modBus) {
attributes.register(modBus);

modContainer.registerConfig(ModConfig.Type.COMMON, SableConfig.SPEC);
modContainer.registerConfig(ModConfig.Type.SERVER, SableServerConfig.SPEC);

CrashReportCallables.registerHeader(Sable::getCrashHeader);
}
Expand Down