Skip to content

Instantly share code, notes, and snippets.

@Densamisten
Last active April 28, 2024 20:30
Show Gist options
  • Save Densamisten/5d7826213e77ba024dbb5cb73c4e9972 to your computer and use it in GitHub Desktop.
Save Densamisten/5d7826213e77ba024dbb5cb73c4e9972 to your computer and use it in GitHub Desktop.

Double

Add slider option for some double value - Vertical Acceleration

       SimpleOption<Double> verticalAcceleration = new SimpleOption<>("options.doubleValue",
               SimpleOption.constantTooltip(Text.literal("Set the vertical acceleration speed rate")),
               (prefix, value) -> Text.of(String.valueOf(value)),
               SimpleOption.DoubleSliderCallbacks.INSTANCE,
               0.1-10.0,  // Default value
               System.out.println(value);
       );
       this.list.addSingleOptionEntry(verticalAcceleration);

Integer

              // Add slider option for vertical speed
      SimpleOption<Integer> verticalSpeedOption = new SimpleOption<>("options.verticalSpeed",
              SimpleOption.emptyTooltip(),
              (prefix, value) -> Text.of(String.valueOf(value)),
              new SimpleOption.ValidatingIntSliderCallbacks(0, 10),
              System.out.println(value);
      );
      this.list.addSingleOptionEntry(verticalSpeedOption);

Boolean

    // Create a SimpleOption<Boolean> with a default value and change callback
      SimpleOption<Boolean> toggleBoatFly = SimpleOption.ofBoolean(
              "fabrient.option.boatfly", // Translation key for the option's text
              false, // Default value
              (value) -> {
                  BoatFly.isFlying = !BoatFly.isFlying;
              });

      // You can then create a widget for the option and add it to the game options screen
      ClickableWidget widget = toggleFly.createWidget(gameOptions, 100, 180, 50);
      addDrawableChild(widget);

CyclingButtonWidget

CyclingButtonWidget<Object> cyclingButton = CyclingButtonWidget.builder((value) -> Text.of((String) value))
                .values("CreativeFly", "Flight", "Disabled")
                .initially("Disabled")
                .tooltip((value) -> {
                    if ("CreativeFly".equals(value)) {
                        CreativeFly.isToggled = !CreativeFly.isToggled;
                        return Tooltip.of(Text.of("Enables creative mode flight"));
                    } else if ("Flight".equals(value)) {
                        Flight.isToggled = !Flight.isToggled;
                        return Tooltip.of(Text.of("Enables normal flight"));
                    } else if ("BoatFly".equals(value)) {
                        BoatFly.isFlying = !BoatFly.isFlying;
                        return Tooltip.of(Text.of("Enables normal flight"));
                    }
                    else if ("Disabled".equals(value)) {
                        return Tooltip.of(Text.of("Disables all aerials"));
                    }
                    return null;
                })
                .build(10, 10, 120, 20, Text.of("Aerial Navigation: "), (button, value) -> {
                    System.out.println("Aerial Navigation changed to: " + value);
                });
        this.addDrawableChild(cyclingButton);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment