1
0
forked from Clones/Controlify

lots of API docs and fix sources jar

This commit is contained in:
isXander
2023-04-15 13:12:45 +01:00
parent 2c08d5f15c
commit 8eb8510590
16 changed files with 233 additions and 59 deletions

View File

@ -2,10 +2,11 @@ package dev.isxander.controlify.api;
import dev.isxander.controlify.Controlify;
import dev.isxander.controlify.InputMode;
import dev.isxander.controlify.api.bind.ControlifyBindingsApi;
import dev.isxander.controlify.controller.Controller;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
/**
* Interface with Controlify in a manner where you don't need to worry about updates
* breaking! This is the recommended way to interact with Controlify.
@ -17,10 +18,14 @@ import org.jetbrains.annotations.NotNull;
*/
public interface ControlifyApi {
/**
* @deprecated Use {@link #getCurrentController()} instead.
* @return the controller currently in use. If disabled, this will return {@link Controller#DUMMY}
*/
@Deprecated
@NotNull Controller<?, ?> currentController();
@NotNull Optional<Controller<?, ?>> getCurrentController();
/**
* Get the current input mode for the game.
*/

View File

@ -5,17 +5,39 @@ import dev.isxander.yacl.api.Option;
import net.minecraft.client.KeyMapping;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
import java.util.function.BooleanSupplier;
public interface ControllerBinding {
/**
* @return the current analogue state of the binding.
*/
float state();
/**
* @return the analogue state of the binding last tick.
*/
float prevState();
/**
* @return if the binding is currently held.
*/
boolean held();
/**
* @return if the binding was held last tick.
*/
boolean prevHeld();
/**
* @return if the binding is held this tick but not the previous tick
*/
boolean justPressed();
/**
* @return if the binding is not held this tick but was held last tick
*/
boolean justReleased();
Component name();
@ -24,7 +46,10 @@ public interface ControllerBinding {
ResourceLocation id();
KeyMappingOverride override();
/**
* The vanilla override of the binding. Null if there is no override.
*/
@Nullable KeyMappingOverride override();
void resetBind();
boolean isUnbound();

View File

@ -8,6 +8,8 @@ import net.minecraft.client.gui.screens.Screen;
public interface ButtonGuidePredicate<T extends AbstractButton> {
boolean shouldDisplay(T button);
/** Only display the button guide when the button is focused. */
ButtonGuidePredicate<AbstractButton> FOCUS_ONLY = AbstractWidget::isFocused;
/** Always display the button guide. */
ButtonGuidePredicate<AbstractButton> ALWAYS = btn -> true;
}

View File

@ -21,7 +21,22 @@ public final class ControlifyEvents {
/**
* Triggers every tick when the current controller state has been updated.
*/
public static final Event<ControllerStateUpdate> CONTROLLER_STATE_UPDATED = EventFactory.createArrayBacked(ControllerStateUpdate.class, callbacks -> controller -> {
public static final Event<ControllerStateUpdate> ACTIVE_CONTROLLER_TICKED = EventFactory.createArrayBacked(ControllerStateUpdate.class, callbacks -> controller -> {
for (ControllerStateUpdate callback : callbacks) {
callback.onControllerStateUpdate(controller);
}
});
/**
* @deprecated Use {@link #ACTIVE_CONTROLLER_TICKED} instead.
*/
@Deprecated
public static final Event<ControllerStateUpdate> CONTROLLER_STATE_UPDATED = ACTIVE_CONTROLLER_TICKED;
/**
* Triggers every tick when any connected controller's state has been updated before the active controller is ticked.
*/
public static final Event<ControllerStateUpdate> CONTROLLER_STATE_UPDATE = EventFactory.createArrayBacked(ControllerStateUpdate.class, callbacks -> controller -> {
for (ControllerStateUpdate callback : callbacks) {
callback.onControllerStateUpdate(controller);
}
@ -45,6 +60,10 @@ public final class ControlifyEvents {
}
});
/**
* Allows you to modify the look input before it is applied to the player.
* These modifiers are called before the look input is multiplied by the sensitivity.
*/
public static final Event<LookInputModifier> LOOK_INPUT_MODIFIER = EventFactory.createArrayBacked(LookInputModifier.class, callbacks -> new LookInputModifier() {
@Override
public float modifyX(float x, Controller<?, ?> controller) {

View File

@ -6,6 +6,15 @@ import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.world.phys.HitResult;
/**
* All information available to a guide entry.
* This may be added over time.
* @param client the minecraft client
* @param player local player
* @param level the current world
* @param hitResult where the player is currently looking
* @param controller the controller for this guide renderer
*/
public record IngameGuideContext(Minecraft client,
LocalPlayer player,
ClientLevel level,

View File

@ -6,15 +6,49 @@ import dev.isxander.controlify.ingame.InGameInputHandler;
import java.util.function.BiFunction;
import java.util.function.BooleanSupplier;
/**
* Allows dependants to modify controller look input.
*
* Implementing classes must provide methods for modifying the x
* and y axis values of the controller's look input.
*/
public interface LookInputModifier {
/**
* Modifies the x axis value of the controller's look input.
*
* @param x the current value of the x axis, typically in the range 0-1 but can be higher from gyro input
* @param controller the current active controller
* @return the modified value of the x axis
*/
float modifyX(float x, Controller<?, ?> controller);
/**
* Modifies the y axis value of the controller's look input.
*
* @param y the current value of the y axis, typically in the range 0-1 but can be higher from gyro input
* @param controller the current active controller
* @return the modified value of the y axis
*/
float modifyY(float y, Controller<?, ?> controller);
/**
* Creates a new LookInputModifier using the given x and y axis modifying functions.
*
* @param x the function for modifying the x axis
* @param y the function for modifying the y axis
* @return the new LookInputModifier object
*/
static LookInputModifier functional(BiFunction<Float, Controller<?, ?>, Float> x, BiFunction<Float, Controller<?, ?>, Float> y) {
return new InGameInputHandler.FunctionalLookInputModifier(x, y);
}
/**
* Creates a new LookInputModifier that sets the x and y axis to zero if the given condition is true.
*
* @param condition the condition that determines whether to set the axis values to zero
* @return the new LookInputModifier object
*/
static LookInputModifier zeroIf(BooleanSupplier condition) {
return functional((x, controller) -> condition.getAsBoolean() ? 0 : x, (y, controller) -> condition.getAsBoolean() ? 0 : y);
}