Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GUI support for Controlify? #506

Open
kyle23u opened this issue Dec 20, 2024 · 0 comments
Open

Add GUI support for Controlify? #506

kyle23u opened this issue Dec 20, 2024 · 0 comments

Comments

@kyle23u
Copy link

kyle23u commented Dec 20, 2024

Hello, I am new to java, learning coding and such. but I am also looking into adding support for Controlify to this or that mod or atleast want to see it happen possibly. The problem i am having is your GUI for CraftingTerminalScreen.class does not support in Controlify's virtual mouse snapping that is configured to my xbox controllers DPAD, it works for everything else but GUI that are in this mod.

I have been working with chatgpt also trying to learn while also doing codeacademy for java. Analyzing what is what and such.
but here is what i got it to give me if this means anything to you or helps you out if you would help add this to it?

import dev.isxander.controlify.api.vmousesnapping.SnapPoint;
import dev.isxander.controlify.api.vmousesnapping.ISnapBehaviour;
import org.joml.Vector2i;
import java.util.Set;
import java.util.HashSet;

public class CraftingTerminalScreen extends AbstractStorageTerminalScreen<CraftingTerminalMenu> implements ISnapBehaviour {
    // Constructor and other methods...

    @Override
    public Set<SnapPoint> getSnapPoints() {
        Set<SnapPoint> snapPoints = new HashSet<>();
        // Example: add a snap point at the center of a button
        snapPoints.add(new SnapPoint(new Vector2i(buttonXCenter, buttonYCenter), 10));  // 10 is the radius
        return snapPoints;

//buttonXCenter and buttonYCenter should be the coordinates of the center of the buttons or other interactive elements within your GUI.
    }
}

Edit: here is link to chatgpt convo if intersted (it has some of the controlify shit in there if need). https://chatgpt.com/share/6765e9b2-b5a4-800e-9a41-ed3dcecfa936

warno: I just learned the very basics of java literally this week off codeacademy so i did try seeing what all ai can do lol and partially lazy, but I'm interested in learning lol. The funny part is i have been spending too dam long on this to try add a feature to a mod that mods controls for a game that dont have stock controller support like bedrock but also first time playing java edition this much and spent more time researching this than playing lmao....

Response ChatGPT The code you've provided offers valuable insights into how Controlify handles virtual mouse snapping and interacts with different GUI elements in Minecraft. To make your CraftingTerminalScreen work with the Controlify mod, you'll need to focus on implementing interfaces and potentially using utilities that Controlify expects other screens or GUI elements to use.

Steps to Implement Controlify's Snapping Functionality
Implement ISnapBehaviour in CraftingTerminalScreen:
The ISnapBehaviour interface defines a method getSnapPoints() that you should implement in your CraftingTerminalScreen. This method should return a set of SnapPoint objects, each representing a point on the screen where the virtual mouse should snap to.
java

import dev.isxander.controlify.api.vmousesnapping.SnapPoint;
import dev.isxander.controlify.api.vmousesnapping.ISnapBehaviour;
import org.joml.Vector2i;
import java.util.Set;
import java.util.HashSet;

public class CraftingTerminalScreen extends AbstractStorageTerminalScreen<CraftingTerminalMenu> implements ISnapBehaviour {
    // Constructor and other methods...

    @Override
    public Set<SnapPoint> getSnapPoints() {
        Set<SnapPoint> snapPoints = new HashSet<>();
        // Example: add a snap point at the center of a button
        snapPoints.add(new SnapPoint(new Vector2i(buttonXCenter, buttonYCenter), 10));  // 10 is the radius
        return snapPoints;
    }
}

buttonXCenter and buttonYCenter should be the coordinates of the center of the buttons or other interactive elements within your GUI.
Use SnapUtils as a reference:

The provided SnapUtils class shows how snap points are added for different components like buttons within a recipe book. You can use this logic as a model for adding snap points to the components of your CraftingTerminalScreen.
Specifically, look at how it calculates the center and adds a snap point. You would do something similar for each interactive element in your custom GUI.
Examine the Mixin Configuration:

The JSON configuration suggests that Controlify uses a comprehensive set of mixins to modify and extend the behavior of many classes in Minecraft. While you don't need to modify this directly, understanding that it is adjusting a wide range of classes can help you ensure that your screen behaves consistently with others that are modified by Controlify.
Implementing Snapping Functionality Directly
If your CraftingTerminalScreen has buttons or interactive elements, determine their x and y coordinates, preferably in the center of these elements. Use these coordinates to create SnapPoint instances as shown in the ISnapBehaviour implementation. This way, when Controlify's virtual mouse functionality is active, it will be able to snap to these elements on your custom screen.

Testing and Debugging
After implementing the changes:

Test Thoroughly: Make sure that when Controlify is active, and the CraftingTerminalScreen is displayed, the virtual mouse snaps to the defined points correctly.
Debug as Needed: If snapping doesn't work as expected, check the coordinates and radii used for the snap points. Also, ensure that CraftingTerminalScreen is correctly recognized by the mod as implementing ISnapBehaviour.
This approach ensures that your custom GUI integrates smoothly with Controlify’s system, leveraging its built-in functionality for enhanced controller support.

Controlify api.vmousesnapping

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package dev.isxander.controlify.api.vmousesnapping;

import java.util.Set;

public interface ISnapBehaviour {
Set getSnapPoints();
}

{
"package": "dev.isxander.controlify.mixins",
"required": true,
"minVersion": "0.8",
"minMixinExtrasVersion": "0.5.0-beta.1",
"injectors": {
"defaultRequire": 1
},
"compatibilityLevel": "JAVA_17",
"client": [
"core.ClientPacketListenerMixin",
"core.GLXMixin",
"core.GuiMixin",
"core.KeyboardHandlerMixin",
"core.MinecraftMixin",
"core.MouseHandlerMixin",
"feature.accessibility.LocalPlayerMixin",
"feature.autoswitch.SystemToastAccessor",
"feature.autoswitch.ToastManagerAccessor",
"feature.bind.ClientPacketListenerMixin",
"feature.bind.GuiMixin",
"feature.bind.KeyMappingMixin",
"feature.bind.MinecraftMixin",
"feature.bind.ToggleKeyMappingMixin",
"feature.font.FontAccessor",
"feature.font.KeybindContentsMixin",
"feature.guide.ingame.ClientPacketListenerMixin",
"feature.guide.ingame.GuiMixin",
"feature.guide.screen.AbstractContainerScreenAccessor",
"feature.guide.screen.AbstractWidgetMixin",
"feature.guide.screen.TabNavigationBarMixin",
"feature.hdhaptics.JOrbisAudioStreamMixin",
"feature.input.DebugScreenOverlayAccessor",
"feature.input.MinecraftMixin",
"feature.nomousetutorial.MovementTutorialStepInstanceMixin",
"feature.oofinput.GameRendererMixin",
"feature.patches.boatfix.BoatMixin",
"feature.patches.boatfix.LocalPlayerMixin",
"feature.reacharound.GameRendererMixin",
"feature.rumble.MinecraftMixin",
"feature.rumble.blockbreak.MultiPlayerGameModeMixin",
"feature.rumble.damage.LivingEntityMixin",
"feature.rumble.damage.LocalPlayerMixin",
"feature.rumble.damage.PlayerMixin",
"feature.rumble.explosion.ClientPacketListenerMixin",
"feature.rumble.explosion.LightningBoltMixin",
"feature.rumble.fishing.FishingHookMixin",
"feature.rumble.itembreak.LivingEntityMixin",
"feature.rumble.itembreak.LocalPlayerMixin",
"feature.rumble.levelevents.LevelRendererMixin",
"feature.rumble.slowblock.LocalPlayerMixin",
"feature.rumble.useitem.ClientPacketListenerMixin",
"feature.rumble.useitem.LivingEntityMixin",
"feature.rumble.useitem.LocalPlayerMixin",
"feature.rumble.waterland.LocalPlayerMixin",
"feature.rumble.waterland.PlayerMixin",
"feature.screenkeyboard.ChatComponentMixin",
"feature.screenkeyboard.ChatScreenMixin",
"feature.screenkeyboard.CommandSuggestionsMixin",
"feature.screenop.ContainerEventHandlerMixin",
"feature.screenop.MinecraftMixin",
"feature.screenop.ScreenAccessor",
"feature.screenop.ScreenMixin",
"feature.screenop.vanilla.AbstractButtonMixin",
"feature.screenop.vanilla.AbstractContainerEventHandlerMixin",
"feature.screenop.vanilla.AbstractContainerScreenMixin",
"feature.screenop.vanilla.AbstractRecipeBookScreenMixin",
"feature.screenop.vanilla.AbstractSelectionListMixin",
"feature.screenop.vanilla.AbstractSignEditScreenMixin",
"feature.screenop.vanilla.AbstractSliderButtonMixin",
"feature.screenop.vanilla.bundle.BundleMouseActionsMixin",
"feature.screenop.vanilla.ContainerObjectSelectionListEntryMixin",
"feature.screenop.vanilla.CreateWorldScreenMixin",
"feature.screenop.vanilla.CreativeModeInventoryScreenMixin",
"feature.screenop.vanilla.EditBoxMixin",
"feature.screenop.vanilla.JoinMultiplayerScreenAccessor",
"feature.screenop.vanilla.JoinMultiplayerScreenMixin",
"feature.screenop.vanilla.LanguageSelectionListEntryMixin",
"feature.screenop.vanilla.OptionsSubScreenAccessor",
"feature.screenop.vanilla.PauseScreenAccessor",
"feature.screenop.vanilla.PauseScreenMixin",
"feature.screenop.vanilla.SelectWorldScreenAccessor",
"feature.screenop.vanilla.SelectWorldScreenMixin",
"feature.screenop.vanilla.ServerSelectionListEntryMixin",
"feature.screenop.vanilla.TabNavigationBarAccessor",
"feature.screenop.vanilla.TitleScreenMixin",
"feature.screenop.vanilla.WorldSelectionListEntryMixin",
"feature.settingsbutton.ControlsScreenMixin",
"feature.steamdeck.ScreenshotAccessor",
"feature.util.ConnectScreenMixin",
"feature.virtualmouse.InputConstantsMixin",
"feature.virtualmouse.KeyboardHandlerAccessor",
"feature.virtualmouse.MinecraftMixin",
"feature.virtualmouse.MouseHandlerAccessor",
"feature.virtualmouse.MouseHandlerMixin",
"feature.virtualmouse.snapping.AbstractContainerScreenMixin",
"feature.virtualmouse.snapping.AbstractRecipeBookScreenMixin",
"feature.virtualmouse.snapping.CreativeModeInventoryScreenMixin",
"feature.virtualmouse.snapping.RecipeBookComponentAccessor",
"feature.virtualmouse.snapping.RecipeBookPageAccessor",
"feature.virtualmouse.snapping.ScreenMixin"
],
"mixins": [
"feature.font.TranslatableContentsMixin",
"feature.guide.ingame.PlayerAccessor"
],
"refmap": "Controlify-1.21.4-fabric-refmap.json"
}

controlify.virtualmouse

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package dev.isxander.controlify.virtualmouse;

import dev.isxander.controlify.api.vmousesnapping.SnapPoint;
import dev.isxander.controlify.mixins.feature.virtualmouse.snapping.RecipeBookComponentAccessor;
import dev.isxander.controlify.mixins.feature.virtualmouse.snapping.RecipeBookPageAccessor;
import java.util.Collection;
import net.minecraft.class_361;
import net.minecraft.class_507;
import org.joml.Vector2i;

public final class SnapUtils {
private SnapUtils() {
}

public static void addRecipeSnapPoints(class_507 recipeBookComponent, Collection<SnapPoint> points) {
    if (recipeBookComponent.method_2605()) {
        RecipeBookComponentAccessor componentAccessor = (RecipeBookComponentAccessor)recipeBookComponent;
        componentAccessor.getTabButtons().forEach((button) -> {
            int x = button.method_46426() + button.method_25368() / 2;
            int y = button.method_46427() + button.method_25364() / 2;
            points.add(new SnapPoint(new Vector2i(x, y), 20));
        });
        class_361 filterButton = componentAccessor.getFilterButton();
        if (filterButton.field_22764) {
            int x = filterButton.method_46426() + filterButton.method_25368() / 2;
            int y = filterButton.method_46427() + filterButton.method_25364() / 2;
            points.add(new SnapPoint(new Vector2i(x, y), 14));
        }

        RecipeBookPageAccessor pageAccessor = (RecipeBookPageAccessor)componentAccessor.getRecipeBookPage();
        pageAccessor.getButtons().forEach((button) -> {
            int x = button.method_46426() + button.method_25368() / 2;
            int y = button.method_46427() + button.method_25364() / 2;
            points.add(new SnapPoint(new Vector2i(x, y), 21));
        });
        class_361 forwardButton = pageAccessor.getForwardButton();
        if (forwardButton.field_22764) {
            int x = forwardButton.method_46426() + forwardButton.method_25368() / 2 - 2;
            int y = forwardButton.method_46427() + forwardButton.method_25364() / 2;
            points.add(new SnapPoint(new Vector2i(x, y), 10));
        }

        class_361 backButton = pageAccessor.getBackButton();
        if (backButton.field_22764) {
            int x = backButton.method_46426() + backButton.method_25368() / 2 + 2;
            int y = backButton.method_46427() + backButton.method_25364() / 2;
            points.add(new SnapPoint(new Vector2i(x, y), 10));
        }
    }

}

}

Thank you in advanced!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant