mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 15:25:08 +01:00
- Added #40 (Modded keybind support) - Added #20 (Touchscreen support) - Improved #13 (Sodium screen controller support) - Attempt to fix #31 & #38 (Jittery input on low FPS) - Fixed #35 (Front placing being broken) - Fixed #32 (Option to disable double tap to sprint) - Fixed #27 (Auto-adapt controller icons) - Fixed #19 (HUD-scaling on big scales) - Fixed #36 (Crash on game load) - Fixed reset option - Fixed scrolling in trading screens - Disable features that might be considered as cheats (install MidnightControlsExtra to enable)
159 lines
4.7 KiB
Java
159 lines
4.7 KiB
Java
/*
|
|
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
|
|
*
|
|
* This file is part of midnightcontrols.
|
|
*
|
|
* Licensed under the MIT license. For more information,
|
|
* see the LICENSE file.
|
|
*/
|
|
|
|
package eu.midnightdust.midnightcontrols;
|
|
|
|
import dev.lambdaurora.spruceui.util.Nameable;
|
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* Represents a feature.
|
|
*
|
|
* @author LambdAurora
|
|
* @version 1.5.0
|
|
* @since 1.1.0
|
|
*/
|
|
public class MidnightControlsFeature implements Nameable {
|
|
private static final List<MidnightControlsFeature> FEATURES = new ArrayList<>();
|
|
public static final MidnightControlsFeature FAST_BLOCK_PLACING = new MidnightControlsFeature("fast_block_placing", true, MidnightControlsConfig.fastBlockPlacing);
|
|
public static final MidnightControlsFeature HORIZONTAL_REACHAROUND = new MidnightControlsFeature("horizontal_reacharound", true, MidnightControlsConfig.horizontalReacharound);
|
|
public static final MidnightControlsFeature VERTICAL_REACHAROUND = new MidnightControlsFeature("vertical_reacharound", true, MidnightControlsConfig.verticalReacharound);
|
|
|
|
private final String key;
|
|
private final boolean defaultAllowed;
|
|
private boolean allowed;
|
|
private final boolean defaultEnabled;
|
|
private boolean enabled;
|
|
|
|
public MidnightControlsFeature(@NotNull String key, boolean allowed, boolean enabled) {
|
|
Objects.requireNonNull(key, "Feature key cannot be null.");
|
|
this.key = key;
|
|
this.setAllowed(this.defaultAllowed = allowed);
|
|
this.setEnabled(this.defaultEnabled = enabled);
|
|
}
|
|
|
|
public MidnightControlsFeature(@NotNull String key) {
|
|
this(key, false, false);
|
|
}
|
|
|
|
/**
|
|
* Allows the feature.
|
|
*/
|
|
public void allow() {
|
|
this.setAllowed(true);
|
|
}
|
|
|
|
/**
|
|
* Returns whether this feature is allowed.
|
|
*
|
|
* @return {@code true} if this feature is allowed, else {@code false}
|
|
*/
|
|
public boolean isAllowed() {
|
|
return MidnightControls.isExtrasLoaded && this.allowed;
|
|
}
|
|
|
|
/**
|
|
* Sets whether this feature is allowed.
|
|
*
|
|
* @param allowed {@code true} if this feature is allowed, else {@code false}
|
|
*/
|
|
public void setAllowed(boolean allowed) {
|
|
this.allowed = allowed;
|
|
}
|
|
|
|
/**
|
|
* Resets allowed state to default.
|
|
*/
|
|
public void resetAllowed() {
|
|
this.setAllowed(this.defaultAllowed);
|
|
}
|
|
|
|
/**
|
|
* Returns whether this feature is enabled.
|
|
*
|
|
* @return {@code true} if this feature is enabled, else {@code false}
|
|
*/
|
|
public boolean isEnabled() {
|
|
return this.enabled;
|
|
}
|
|
|
|
/**
|
|
* Returns whether this feature is enabled.
|
|
*
|
|
* @param enabled {@code true} if this feature is enabled, else {@code false}
|
|
*/
|
|
public void setEnabled(boolean enabled) {
|
|
this.enabled = enabled;
|
|
}
|
|
|
|
/**
|
|
* Refreshes the enabled values from the config.
|
|
*/
|
|
public static void refreshEnabled() {
|
|
MidnightControlsFeature.VERTICAL_REACHAROUND.setEnabled(MidnightControlsConfig.verticalReacharound);
|
|
MidnightControlsFeature.FAST_BLOCK_PLACING.setEnabled(MidnightControlsConfig.fastBlockPlacing);
|
|
MidnightControlsFeature.HORIZONTAL_REACHAROUND.setEnabled(MidnightControlsConfig.horizontalReacharound);
|
|
}
|
|
|
|
/**
|
|
* Returns whether this feature is available or not.
|
|
*
|
|
* @return {@code true} if this feature is available, else {@code false}
|
|
* @see #isAllowed()
|
|
* @see #isEnabled()
|
|
*/
|
|
public boolean isAvailable() {
|
|
return this.isAllowed() && this.isEnabled();
|
|
}
|
|
|
|
/**
|
|
* Resets the feature to its default values.
|
|
*/
|
|
public void reset() {
|
|
this.resetAllowed();
|
|
this.setEnabled(this.defaultEnabled);
|
|
}
|
|
|
|
@Override
|
|
public @NotNull String getName() {
|
|
return this.key;
|
|
}
|
|
|
|
public static @NotNull Optional<MidnightControlsFeature> fromName(@NotNull String key) {
|
|
Objects.requireNonNull(key, "Cannot find features with a null name.");
|
|
return FEATURES.parallelStream().filter(feature -> feature.getName().equals(key)).findFirst();
|
|
}
|
|
|
|
/**
|
|
* Resets all features to their default values.
|
|
*/
|
|
public static void resetAll() {
|
|
FEATURES.parallelStream().forEach(MidnightControlsFeature::reset);
|
|
}
|
|
|
|
/**
|
|
* Resets all features to allow state.
|
|
*/
|
|
public static void resetAllAllowed() {
|
|
FEATURES.parallelStream().forEach(MidnightControlsFeature::resetAllowed);
|
|
}
|
|
|
|
static {
|
|
FEATURES.add(FAST_BLOCK_PLACING);
|
|
FEATURES.add(HORIZONTAL_REACHAROUND);
|
|
FEATURES.add(VERTICAL_REACHAROUND);
|
|
}
|
|
}
|