Skip to content

Commit

Permalink
almoist done
Browse files Browse the repository at this point in the history
  • Loading branch information
AV306 committed Oct 27, 2023
1 parent 61d9c82 commit 1648c02
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 71 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'java'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
}

Expand Down Expand Up @@ -50,7 +50,6 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// CompleteConfig
// why is there nothing in here
modImplementation "com.github.Lortseam.completeconfig:base:${project.complete_config_version}"
modImplementation "com.github.Lortseam.completeconfig:gui-cloth:${project.complete_config_version}"
//modImplementation "com.github.shedaniel:cloth-config:v10-SNAPSHOT"
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version = 1.20.2
yarn_mappings = 1.20.2+build.1
loader_version = 0.14.23
yarn_mappings = 1.20.2+build.4
loader_version = 0.14.24

# Fabric api
fabric_version = 0.89.2+1.20.2
fabric_version = 0.90.4+1.20.2

# Mod Properties
mod_version = 4.2.2+1.20.2
mod_version = 4.3.0+1.20.2
maven_group = me.av306
archives_base_name = xenon

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 23 additions & 12 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions $var�, �${var}�, �${var:-default}�, �${var+SET},
# ${var#prefix}�, �${var%suffix}, and $( cmd );
# * compound commands having a testable exit status, especially case;
# * various built-in commands including command�, �set, and ulimit.
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand All @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m" "-Dmixin.debug.export=true"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +210,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
78 changes: 48 additions & 30 deletions src/main/java/me/av306/xenon/feature/IFeature.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package me.av306.xenon.feature;

import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import me.av306.xenon.Xenon;
import me.av306.xenon.event.KeyEvent;
import me.av306.xenon.event.MinecraftClientEvents;
import me.av306.xenon.util.text.TextFactory;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
//import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.*;

import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.util.ActionResult;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

Expand Down Expand Up @@ -70,12 +70,14 @@ public abstract class IFeature
public void setShouldHide( boolean shouldHide ) { this.hide = shouldHide; }
public boolean getShouldHide() { return this.hide; }

private final LiteralCommandNode<FabricClientCommandSource> commandNode;
protected LiteralCommandNode<FabricClientCommandSource> commandNode;
protected final LiteralArgumentBuilder<FabricClientCommandSource> commandBuilder;

/**
* Constructor that initialises a feature with the given display name, aliases and no default key
* @param name: The Feature's display name
* @param aliases: Aliases for the feature in CP. <i>Technically can</i>, but should not, contain the name in the first argument
* @see #IFeature(String, int, String...)
*/
protected IFeature( String name, String... aliases )
{
Expand All @@ -87,6 +89,7 @@ protected IFeature( String name, String... aliases )
* @param name: Display name
* @param key: GLFW keycode to bind to
* @param aliases: CommandProcessor aliases
* @see #IFeature(String, int)
*/
protected IFeature( String name, int key, String... aliases )
{
Expand All @@ -100,14 +103,24 @@ protected IFeature( String name, int key, String... aliases )
// Register aliases as Brigadier command redirects
ClientCommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess) ->
dispatcher.register( literal( alias ).redirect( this.commandNode ) )
dispatcher.register(
literal( alias )
.executes( context ->
{
if ( this instanceof IToggleableFeature iToggleableFeature )
iToggleableFeature.toggle();
else this.enable();
return 1;
} )
.redirect( this.commandNode ) )
);
}
}

/**
* Constructor that initialises a feature with a display name, no aliases and no default key
* @param name: Display name
* @see #IFeature(String, int)
*/
protected IFeature( String name )
{
Expand All @@ -124,7 +137,6 @@ protected IFeature( String name )
protected IFeature( String name, int key )
{
this.name = name;

this.key = key;

// use the name passed in because some features change their name (e.g. timer)
Expand All @@ -145,30 +157,36 @@ protected IFeature( String name, int key )

// register our display name in the registry
// in lower case (for CP)
Xenon.INSTANCE.featureRegistry.put(
name.replaceAll( " ", "" ).toLowerCase(),
this
);
String formattedName = name.replaceAll( " ", "" ).toLowerCase();
Xenon.INSTANCE.featureRegistry.put( formattedName, this );

// Register a Brigadier command (native minecraft client command)
this.commandBuilder = literal( formattedName )
.executes( context ->
{
if ( this instanceof IToggleableFeature iToggleableFeature )
iToggleableFeature.toggle();
else this.enable();
return 1;
} );

this.commandBuilder.then( literal( "enable" ).executes( context -> { this.enable(); return 1; } ) );
this.commandBuilder.then( literal( "e" ).executes( context -> { this.enable(); return 1; } ) ); // Enable alias

/*this.commandBuilder.then( literal( "set" ) )
.then( argument( "config", StringArgumentType.greedyString() ) )
.then( argument( "value", StringArgumentType.greedyString() ) )
.executes( context ->
{
this.requestConfigChange(
StringArgumentType.getString( context, "config" ),
StringArgumentType.getString( context, "value" )
);
return 1;
} );*/

// Register a Bridagier command (native minecraft client command)
ClientCommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess) ->
{
this.commandNode = dispatcher.register(
literal( name )
.executes( context ->
{
context.getSource().sendFeedback( TextFactory.createLiteral( "Executed command for " + name ) );
return 1;
} )
.then( literal( "enable" ).executes( context -> this.enable() ) ) // Enable feature
.then( literal( "e" ).redirect( "enable" ) ) // Enable alias
.then( literal( "disable" ).executes( context -> this.disable() ) // Disable feature
.then( literal( "d" ).redirect( "disable" ) // Disable alias
//.then( literal( "set" ).then( TODO: config change command

);
}
(dispatcher, registryAccess) -> this.commandNode = dispatcher.register( this.commandBuilder )
);
}

Expand Down
38 changes: 25 additions & 13 deletions src/main/java/me/av306/xenon/feature/IToggleableFeature.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

import me.av306.xenon.Xenon;
import me.av306.xenon.util.text.TextFactory;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public abstract class IToggleableFeature extends IFeature
{
Expand Down Expand Up @@ -34,22 +39,12 @@ public abstract class IToggleableFeature extends IFeature

protected IToggleableFeature( String name )
{
super( name );

this.enabledText = TextFactory.createTranslatable( "text.xenon.itoggleablefeature.enabled", name )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );
this.disabledText = TextFactory.createTranslatable( "text.xenon.itoggleablefeature.disabled", name )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );
this( name, GLFW.GLFW_KEY_UNKNOWN );
}

protected IToggleableFeature( String name, String... aliases )
{
super( name, aliases );

this.enabledText = TextFactory.createTranslatable( "text.xenon.itoggleablefeature.enabled", name )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );
this.disabledText = TextFactory.createTranslatable( "text.xenon.itoggleablefeature.disabled", name )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );
this( name, GLFW.GLFW_KEY_UNKNOWN, aliases );
}

protected IToggleableFeature( String name, int key )
Expand All @@ -60,6 +55,14 @@ protected IToggleableFeature( String name, int key )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );
this.disabledText = TextFactory.createTranslatable( "text.xenon.itoggleablefeature.disabled", name )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );

this.commandBuilder.then( literal( "disable" ).executes( context -> { this.disable(); return 1; } ) );
this.commandBuilder.then( literal( "d" ).executes( context -> { this.disable(); return 1; } ) );
this.commandBuilder.then( literal( "toggle" ).executes( context -> { this.toggle(); return 1; } ) );
this.commandBuilder.then( literal( "t" ).executes( context -> { this.toggle(); return 1; } ) );
ClientCommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess) -> dispatcher.register( this.commandBuilder )
);
}

protected IToggleableFeature( String name, int key, String... aliases )
Expand All @@ -68,8 +71,17 @@ protected IToggleableFeature( String name, int key, String... aliases )

this.enabledText = TextFactory.createTranslatable( "text.xenon.itoggleablefeature.enabled", name )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );
this.disabledText = TextFactory.createLiteral( "text.xenon.itoggleablefeature.disabled", name )
this.disabledText = TextFactory.createTranslatable( "text.xenon.itoggleablefeature.disabled", name )
.formatted( Xenon.INSTANCE.SUCCESS_FORMAT );

// We're registering the things like thrice, but it works, so I'm not complaining
this.commandBuilder.then( literal( "disable" ).executes( context -> { this.disable(); return 1; } ) );
this.commandBuilder.then( literal( "d" ).executes( context -> { this.disable(); return 1; } ) );
this.commandBuilder.then( literal( "toggle" ).executes( context -> { this.toggle(); return 1; } ) );
this.commandBuilder.then( literal( "t" ).executes( context -> { this.toggle(); return 1; } ) );
ClientCommandRegistrationCallback.EVENT.register(
(dispatcher, registryAccess) -> dispatcher.register( this.commandBuilder )
);
}

/*@Override
Expand Down
Loading

0 comments on commit 1648c02

Please sign in to comment.