forked from Clones/Controlify
separate API from impl
This commit is contained in:
@ -2,7 +2,7 @@ package dev.isxander.controlify.ingame;
|
||||
|
||||
import dev.isxander.controlify.InputMode;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.event.ControlifyClientEvents;
|
||||
import dev.isxander.controlify.api.event.ControlifyEvents;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.KeyboardInput;
|
||||
|
||||
@ -16,7 +16,7 @@ public class InGameInputHandler {
|
||||
this.controller = controller;
|
||||
this.minecraft = Minecraft.getInstance();
|
||||
|
||||
ControlifyClientEvents.INPUT_MODE_CHANGED.register(mode -> {
|
||||
ControlifyEvents.INPUT_MODE_CHANGED.register(mode -> {
|
||||
if (minecraft.player != null) {
|
||||
minecraft.player.input = mode == InputMode.CONTROLLER
|
||||
? new ControllerPlayerMovement(controller, minecraft.player)
|
||||
|
@ -1,5 +0,0 @@
|
||||
package dev.isxander.controlify.ingame.guide;
|
||||
|
||||
public enum ActionLocation {
|
||||
LEFT, RIGHT
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package dev.isxander.controlify.ingame.guide;
|
||||
|
||||
public enum ActionPriority {
|
||||
LOWEST,
|
||||
LOW,
|
||||
NORMAL,
|
||||
HIGH,
|
||||
HIGHEST
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package dev.isxander.controlify.ingame.guide;
|
||||
|
||||
import dev.isxander.controlify.bindings.ControllerBinding;
|
||||
|
||||
public interface ButtonGuideRegistry {
|
||||
void registerGuideAction(ControllerBinding<?> binding, ActionLocation location, GuideActionNameSupplier supplier);
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package dev.isxander.controlify.ingame.guide;
|
||||
|
||||
import dev.isxander.controlify.api.buttonguide.ActionLocation;
|
||||
import dev.isxander.controlify.api.buttonguide.ActionPriority;
|
||||
import dev.isxander.controlify.bindings.ControllerBinding;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -1,15 +0,0 @@
|
||||
package dev.isxander.controlify.ingame.guide;
|
||||
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface GuideActionNameSupplier {
|
||||
Optional<Component> supply(Minecraft client, LocalPlayer player, ClientLevel level, HitResult hitResult, Controller<?, ?> controller);
|
||||
}
|
@ -1,9 +1,13 @@
|
||||
package dev.isxander.controlify.ingame.guide;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.isxander.controlify.api.buttonguide.ActionLocation;
|
||||
import dev.isxander.controlify.api.buttonguide.ActionPriority;
|
||||
import dev.isxander.controlify.api.buttonguide.ButtonGuideRegistry;
|
||||
import dev.isxander.controlify.api.buttonguide.GuideActionNameSupplier;
|
||||
import dev.isxander.controlify.bindings.ControllerBinding;
|
||||
import dev.isxander.controlify.controller.Controller;
|
||||
import dev.isxander.controlify.event.ControlifyClientEvents;
|
||||
import dev.isxander.controlify.api.event.ControlifyEvents;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@ -33,7 +37,7 @@ public class InGameButtonGuide implements ButtonGuideRegistry {
|
||||
this.player = localPlayer;
|
||||
|
||||
registerDefaultActions();
|
||||
ControlifyClientEvents.BUTTON_GUIDE_REGISTRY.invoker().onRegisterButtonGuide(controller.bindings(), this);
|
||||
ControlifyEvents.BUTTON_GUIDE_REGISTRY.invoker().onRegisterButtonGuide(controller.bindings(), this);
|
||||
}
|
||||
|
||||
public void renderHud(PoseStack poseStack, float tickDelta, int width, int height) {
|
||||
@ -112,7 +116,12 @@ public class InGameButtonGuide implements ButtonGuideRegistry {
|
||||
|
||||
@Override
|
||||
public void registerGuideAction(ControllerBinding<?> binding, ActionLocation location, GuideActionNameSupplier supplier) {
|
||||
guidePredicates.add(new GuideActionSupplier(binding, location, supplier));
|
||||
this.registerGuideAction(binding, location, ActionPriority.NORMAL, supplier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGuideAction(ControllerBinding<?> binding, ActionLocation location, ActionPriority priority, GuideActionNameSupplier supplier) {
|
||||
guidePredicates.add(new GuideActionSupplier(binding, location, priority, supplier));
|
||||
}
|
||||
|
||||
private void registerDefaultActions() {
|
||||
@ -232,10 +241,10 @@ public class InGameButtonGuide implements ButtonGuideRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
private record GuideActionSupplier(ControllerBinding<?> binding, ActionLocation location, GuideActionNameSupplier nameSupplier) {
|
||||
private record GuideActionSupplier(ControllerBinding<?> binding, ActionLocation location, ActionPriority priority, GuideActionNameSupplier nameSupplier) {
|
||||
public Optional<GuideAction> supply(Minecraft client, LocalPlayer player, ClientLevel level, HitResult hitResult, Controller<?, ?> controller) {
|
||||
return nameSupplier.supply(client, player, level, hitResult, controller)
|
||||
.map(name -> new GuideAction(binding, name, location));
|
||||
.map(name -> new GuideAction(binding, name, location, priority));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user