1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
chylex 2b15c5836c
Release 1.2.4 for Minecraft 1.19.4+ 2023-03-16 20:34:29 +01:00
chylex 5ce4f2a975
Fix or suppress some IDEA inspections 2023-03-16 19:25:51 +01:00
9 changed files with 38 additions and 18 deletions

View File

@ -1,15 +1,15 @@
modLoader = "javafml"
loaderVersion = "[0,)"
authors = "${author}"
license = "${license}"
issueTrackerURL = "${issuesURL}"
[[mods]]
modId = "${id}"
version = "${version}"
displayName = "${name}"
description = "${description}"
authors = "${author}"
version = "${version}"
logoFile = "icon.png"
[[dependencies.${id}]]

View File

@ -9,15 +9,15 @@ modSourcesURL=https://github.com/chylex/Better-Controls
modIssuesURL=https://github.com/chylex/Better-Controls/issues
# Dependencies
minecraftVersion=1.19.3
forgeVersion=44.0.11
fabricVersion=0.14.11
minecraftVersion=1.19.4
forgeVersion=45.0.6
fabricVersion=0.14.17
loomVersion=0.12
mixinVersion=0.8.5
# Constraints
minimumMinecraftVersion=1.19.3
minimumForgeVersion=44.0.0
minimumMinecraftVersion=1.19.4
minimumForgeVersion=45.0.0
minimumFabricVersion=0.7.4
# Gradle

View File

@ -24,10 +24,12 @@ final class Json {
return obj.has(key) ? obj.get(key).getAsBoolean() : defaultValue;
}
@SuppressWarnings("SameParameterValue")
static <T extends Enum<T>> void setEnum(final JsonObject obj, final String key, final T value) {
obj.addProperty(key, value.name());
}
@SuppressWarnings("SameParameterValue")
static <T extends Enum<T>> T getEnum(final JsonObject obj, final String key, final T defaultValue, final Class<T> enumClass) {
if (!obj.has(key)) {
return defaultValue;

View File

@ -8,6 +8,7 @@ import chylex.bettercontrols.gui.elements.TextWidget;
import chylex.bettercontrols.input.KeyBindingWithModifier;
import chylex.bettercontrols.input.ModifierKey;
import chylex.bettercontrols.input.SprintMode;
import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
@ -88,7 +89,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
private int generateFlightOptions(int y, final List<GuiEventListener> elements) {
final BetterControlsConfig cfg = BetterControlsCommon.getConfig();
final List<Option<Float>> flightSpeedOptions = Arrays.asList(
final ImmutableList<Option<Float>> flightSpeedOptions = ImmutableList.of(
new Option<>(Float.valueOf(0.25F), text("0.25x")),
new Option<>(Float.valueOf(0.50F), text("0.5x")),
new Option<>(Float.valueOf(0.75F), text("0.75x")),
@ -103,7 +104,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
new Option<>(Float.valueOf(8.00F), text("8x"))
);
final List<Option<Float>> flightVerticalBoostOptions = Arrays.asList(
final ImmutableList<Option<Float>> flightVerticalBoostOptions = ImmutableList.of(
new Option<>(Float.valueOf(0.00F), text("None")),
new Option<>(Float.valueOf(0.25F), text("+25%")),
new Option<>(Float.valueOf(0.50F), text("+50%")),
@ -219,6 +220,7 @@ public class BetterControlsScreen extends OptionsSubScreen {
private KeyBindingWidget editingKeyBinding;
private final List<KeyBindingWidget> allKeyBindings = new ArrayList<>();
@SuppressWarnings("DataFlowIssue")
public BetterControlsScreen(@Nullable final Screen parentScreen) {
super(parentScreen, Minecraft.getInstance().options, TITLE);
}
@ -242,7 +244,9 @@ public class BetterControlsScreen extends OptionsSubScreen {
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, text("Miscellaneous"), CENTER));
y = generateMiscellaneousOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
//noinspection DataFlowIssue
addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, btn -> minecraft.setScreen(lastScreen)).pos(width / 2 - 99, height - 29).size(200, 20).build());
addWidget(optionsWidget = new OptionListWidget(21, height - 32, width, height, elements, y - TITLE_MARGIN_TOP + BOTTOM_PADDING));
}

View File

@ -1,19 +1,19 @@
package chylex.bettercontrols.gui.elements;
import com.google.common.collect.ImmutableList;
import net.minecraft.client.gui.components.AbstractSliderButton;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.util.Mth;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.function.Consumer;
public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
private final Component narration;
private final List<Option<T>> options;
private final ImmutableList<Option<T>> options;
private final Consumer<T> onChanged;
private T selectedValue;
public DiscreteValueSliderWidget(final int x, final int y, final int width, final int height, final Component narration, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) {
public DiscreteValueSliderWidget(final int x, final int y, final int width, final int height, final Component narration, final ImmutableList<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) {
super(x, y, width, height, Option.find(options, selectedValue).text(), options.indexOf(Option.find(options, selectedValue)) / (options.size() - 1.0));
this.narration = narration;
this.options = options;
@ -21,7 +21,7 @@ public final class DiscreteValueSliderWidget<T> extends AbstractSliderButton {
this.onChanged = onChanged;
}
public DiscreteValueSliderWidget(final int x, final int y, final int width, final Component narration, final List<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) {
public DiscreteValueSliderWidget(final int x, final int y, final int width, final Component narration, final ImmutableList<Option<T>> options, final T selectedValue, final Consumer<T> onChanged) {
this(x, y, width, 20, narration, options, selectedValue, onChanged);
}

View File

@ -57,6 +57,14 @@ public final class TextWidget extends GuiComponent implements OptionWidget {
this.y = y;
}
@Override
public void setFocused(final boolean focused) {}
@Override
public boolean isFocused() {
return false;
}
@Override
public void render(final @NotNull PoseStack matrices, final int mouseX, final int mouseY, final float delta) {
final Font textRenderer = Minecraft.getInstance().font;

View File

@ -16,9 +16,12 @@ public abstract class HookPlayerFlightSpeed extends LivingEntity {
}
@Redirect(
method = "travel",
method = "getFlyingSpeed",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isSprinting()Z"),
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getFlyingSpeed()F"))
slice = @Slice(
from = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/player/Abilities;flying:Z"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Abilities;getFlyingSpeed()F")
)
)
private boolean disableVanillaSprintBoost(final Player player) {
return false;

View File

@ -7,16 +7,17 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.function.Consumer;
@Mixin(OptionInstance.class)
public abstract class HookToggleOptionButtons {
@Inject(method = "createButton", at = @At("RETURN"))
private void disableToggleOptions(final Options options, final int x, final int y, final int width, final CallbackInfoReturnable<AbstractWidget> ci) {
@Inject(method = "createButton(Lnet/minecraft/client/Options;IIILjava/util/function/Consumer;)Lnet/minecraft/client/gui/components/AbstractWidget;", at = @At("RETURN"))
private <T> void disableToggleOptions(final Options options, final int x, final int y, final int width, final Consumer<T> callback, final CallbackInfoReturnable<AbstractWidget> cir) {
@SuppressWarnings("ConstantConditions")
final OptionInstance<?> me = (OptionInstance<?>)(Object)this;
if (me == options.toggleCrouch() || me == options.toggleSprint()) {
ci.getReturnValue().active = false;
cir.getReturnValue().active = false;
}
}
}

View File

@ -149,6 +149,7 @@ public final class PlayerTicker {
public void afterInputAssignsPressingForward(final Input input) {
if (MINECRAFT.screen == null) {
//noinspection NonShortCircuitBooleanExpression
input.up |= toggleWalkForward.tick();
}
}
@ -157,6 +158,7 @@ public final class PlayerTicker {
final Input input = player.input;
if (MINECRAFT.screen == null && !player.getAbilities().flying) {
//noinspection NonShortCircuitBooleanExpression
input.jumping |= toggleJump.tick();
}