Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and Freecam's versioning is based on [Semantic Versioning](https://semver.org/sp
### Changed

- Movement speed options now use sliders instead of text fields ([#190](https://github.com/MinecraftFreecam/Freecam/pull/190)).
- Redundant collision options are now dynamically hidden ([#121](https://github.com/MinecraftFreecam/Freecam/pull/121)).

### Removed

Expand Down
47 changes: 25 additions & 22 deletions common/src/main/java/net/xolt/freecam/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public static class MovementConfig {
public CollisionConfig collision = new CollisionConfig();
public static class CollisionConfig {
@ConfigEntry.Gui.Tooltip
public boolean ignoreTransparent = true;
public boolean ignoreTransparent = false;

@ConfigEntry.Gui.Tooltip
public boolean ignoreOpenable = true;
public boolean ignoreOpenable = false;

@VariantTooltip(variant = "normal", count = 2)
@VariantTooltip(variant = "modrinth", count = 3)
Expand Down Expand Up @@ -121,49 +121,52 @@ public static class NotificationConfig {
}

public enum FlightMode implements SelectionListEntry.Translatable {
CREATIVE("text.autoconfig.freecam.option.movement.flightMode.creative"),
DEFAULT("text.autoconfig.freecam.option.movement.flightMode.default");
CREATIVE("creative"),
DEFAULT("default");

private final String name;
private final String key;

FlightMode(String name) {
this.name = name;
this.key = "text.autoconfig.freecam.option.movement.flightMode." + name;
}

public String getKey() {
return name;
@Override
public @NotNull String getKey() {
return key;
}
}

public enum InteractionMode implements SelectionListEntry.Translatable {
CAMERA("text.autoconfig.freecam.option.utility.interactionMode.camera"),
PLAYER("text.autoconfig.freecam.option.utility.interactionMode.player");
CAMERA("camera"),
PLAYER("player");

private final String name;
private final String key;

InteractionMode(String name) {
this.name = name;
this.key = "text.autoconfig.freecam.option.utility.interactionMode." + name;
}

public String getKey() {
return name;
@Override
public @NotNull String getKey() {
return key;
}
}

public enum Perspective implements SelectionListEntry.Translatable {
FIRST_PERSON("text.autoconfig.freecam.option.visual.perspective.firstPerson"),
THIRD_PERSON("text.autoconfig.freecam.option.visual.perspective.thirdPerson"),
THIRD_PERSON_MIRROR("text.autoconfig.freecam.option.visual.perspective.thirdPersonMirror"),
INSIDE("text.autoconfig.freecam.option.visual.perspective.inside");
FIRST_PERSON("firstPerson"),
THIRD_PERSON("thirdPerson"),
THIRD_PERSON_MIRROR("thirdPersonMirror"),
INSIDE("inside");

private final String name;
private final String key;

Perspective(String name) {
this.name = name;
this.key = "text.autoconfig.freecam.option.visual.perspective." + name;
}

public String getKey() {
return name;
@Override
public @NotNull String getKey() {
return key;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private AutoConfigExtensions() {}

public static void apply(Class<? extends ConfigData> configClass) {
GuiRegistry registry = AutoConfig.getGuiRegistry(configClass);
Requirements.apply(registry);
ModBindingsConfigImpl.apply(registry);
VariantTooltipImpl.apply(registry);
BoundedContinuousImpl.apply(registry);
Expand Down
67 changes: 67 additions & 0 deletions common/src/main/java/net/xolt/freecam/config/gui/Requirements.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package net.xolt.freecam.config.gui;

import me.shedaniel.autoconfig.gui.registry.GuiRegistry;
import me.shedaniel.clothconfig2.api.ValueHolder;
import me.shedaniel.clothconfig2.gui.entries.BooleanListEntry;
import net.xolt.freecam.variant.api.BuildVariant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.List;

import static java.lang.Boolean.FALSE;

@SuppressWarnings("UnstableApiUsage")
class Requirements {

private static final Logger LOGGER = LogManager.getLogger();
private static ValueHolder<Boolean> ignoreAllWidget;

private Requirements() {}

static void apply(GuiRegistry guiRegistry) {
// FIXME These transformers assume that no subsequent GUI transformers will replace
// the widgets. That's fine, so long as nothing changes, however a dedicated
// AutoConfig requirements API would be better.
//
// NOTE The Cloth Config Requirements API is currently marked "unstable", although
// significant changes seem unlikely.

// Register a transformer to capture the ignoreAll GUI
guiRegistry.registerPredicateTransformer((guis, i18n, field, config, defaults, registry) -> {
// Filter out unrelated widgets, such as PrefixText.
// Also allows us to safely cast.
List<BooleanListEntry> widgets = guis.stream()
.filter(BooleanListEntry.class::isInstance)
.map(BooleanListEntry.class::cast)
.toList();
if (widgets.isEmpty()) {
LOGGER.error("Unable to find ignoreAll widget.");
return guis;
}
if (widgets.size() > 1) {
LOGGER.warn("Multiple ignoreAll widgets, choosing first.");
}
ignoreAllWidget = widgets.get(0);
return guis;
}, field -> field.getName().equals("ignoreAll"));

// Register a transformer to set requirements for ignoreTransparent & ignoreOpenable
guiRegistry.registerPredicateTransformer((guis, i18n, field, config, defaults, registry) -> {
if (BuildVariant.getInstance().name().equals("modrinth")) {
// Disabling doesn't make sense on the modrinth build
return guis;
}
guis.stream()
.filter(BooleanListEntry.class::isInstance)
.map(BooleanListEntry.class::cast)
.forEach(gui -> gui.setRequirement(Requirements::notIgnoreAll));
return guis;
}, field -> List.of("ignoreTransparent", "ignoreOpenable").contains(field.getName()));
}

// Requirement handler: require ignoreAll is set to "No"
private static boolean notIgnoreAll() {
return ignoreAllWidget == null || FALSE.equals(ignoreAllWidget.getValue());
}
}