diff --git a/build.gradle b/build.gradle index 339c839..63a7545 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.5-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' } @@ -34,9 +34,9 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" //Cardinal Components API - include(modApi("dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cca_version}")) - include(modApi("dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cca_version}")) - include(modApi("dev.onyxstudios.cardinal-components-api:cardinal-components-scoreboard:${project.cca_version}")) + include(modApi("org.ladysnake.cardinal-components-api:cardinal-components-base:${project.cca_version}")) + include(modApi("org.ladysnake.cardinal-components-api:cardinal-components-entity:${project.cca_version}")) + include(modApi("org.ladysnake.cardinal-components-api:cardinal-components-scoreboard:${project.cca_version}")) //Permissions modCompileOnly "me.lucko:fabric-permissions-api:${project.fabricperms_version}" diff --git a/gradle.properties b/gradle.properties index 31d2650..8c75ca8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,21 +4,21 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.1 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 #minecraft_version=1.20.1 #yarn_mappings=1.20.1+build.10 -loader_version=0.15.1 +loader_version=0.15.11 # Mod Properties - mod_version = 3.0.1+fabric_1.20.4 + mod_version = 3.1.0+fabric_1.20.6 maven_group = me.emafire003.dev archives_base_name = coloredglowlib # Dependencies -fabric_version=0.91.1+1.20.4 -cca_version = 5.4.0 +fabric_version=0.98.0+1.20.6 +cca_version = 6.0.0-rc1 #Soft Dependencies fabricperms_version=0.2-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..d64cd49 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a595206..a80b22c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -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/. @@ -80,13 +80,11 @@ 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"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. 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=SC2039,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=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# 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 -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# 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, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,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. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -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 @@ -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% @@ -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. @@ -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 diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibAPI.java b/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibAPI.java index f8048ae..242c87c 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibAPI.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibAPI.java @@ -10,6 +10,7 @@ import static me.emafire003.dev.coloredglowlib.component.ColorComponent.COLOR_COMPONENT; +@SuppressWarnings("unused") public class ColoredGlowLibAPI { @@ -28,7 +29,7 @@ public ColoredGlowLibAPI(Scoreboard scoreboard){ /**Set this to true to override the default minecraft team colors * even of the entity is in a team. - * + *

* By default this option is set to false * * @param b The value to assing to overrideTeamColors*/ @@ -45,7 +46,7 @@ public boolean getOverrideTeamColors(){ } /** Makes the Default color override a potential Entity-specific or EntityType-specific color. - * + *

* By default this option is false * * @param b Set to true to enable overriding, set false to disable it. @@ -66,7 +67,7 @@ public boolean getDefaultOverridesAll(){ /** * Makes the EntityType-specific color override a potential * Entity-specific color. - * + *

* By default this option is false * * @param b Set to true to enable overriding, set false to disable it. @@ -91,7 +92,7 @@ public boolean getEntityTypeColorOverridesEntityColor(){ /** Sets a default global color. The one used by default is "#ffffff, same as vanilla Minecraft. - * + *

* If an entity has another color assigned to its EntityType, or itself it will glow that color * instead of this one, unless {@link #setDefaultOverridesAll(boolean)} method is used. * @@ -105,7 +106,7 @@ public void setGlobalColor(String color){ /** Makes the default color to be "rainbow", so every entity will by default * glow in rainbow colors, kinda like a _jeb sheep. - * + *

* If an entity has another color assigned to its EntityType, or itself it will glow that color * instead of this one, unless {@link #setDefaultOverridesAll(boolean)} method is used. */ @@ -115,7 +116,7 @@ public void setGlobalRainbow(){ /** Makes the default color to be "random", so every entity will by default * glow in a random color each tick. - * + *

* If an entity has another color assigned to its EntityType, or itself it will glow that color * instead of this one, unless {@link #setDefaultOverridesAll(boolean)} method is used. */ @@ -137,7 +138,7 @@ public void clearGlobalColor(){ /** * Sets a custom glow color for an Entity. * The entity will now glow the specified color instead of vanilla minecraft's one. - * + *

* This glow color can be overridden by other methods, such as: * {@link #setDefaultOverridesAll(boolean)} and {@link #setEntityTypeColorOverridesEntityColor(boolean)} * @@ -156,13 +157,13 @@ public void setColor(Entity target, String color){ /** * Sets a custom glow color for an EntityType. * All entities of the specified EntityType will now glow the specified color instead of vanilla minecraft's one. - * + *

* This glow color can be overridden by other methods, such as: * {@link #setDefaultOverridesAll(boolean)} * * If an Entity has a color which is different from its EntityType's one it will glow that color unless * {@link #setEntityTypeColorOverridesEntityColor(boolean)} is enabled - * + *

* If no color is specified, but a default color is, the entities will glow that color. * * @param target The EntityType that will glow the specified color @@ -177,7 +178,7 @@ public void setColor(EntityType target, String color){ /** * Sets the custom glow color of an Entity to rainbow. * This will make the entity glow every color periodically like a _jeb sheep - * + *

* See {@link #setColor(Entity, String)} for more information * * @param target The Entity that will glow the specified color @@ -188,7 +189,7 @@ public void setRainbowColor(Entity target){ /** * Sets the custom glow color of an Entity to a random, the entity will glow a different color each tick. - * + *

* See {@link #setColor(Entity, String)} for more information * * @param target The Entity that will glow the specified color @@ -200,7 +201,7 @@ public void setRandomColor(Entity target){ /** * Sets the custom glow color of an EntityType to rainbow. * This will make the entities of that type glow every color periodically like a _jeb sheep - * + *

* See {@link #setColor(EntityType, String)} for more information * * @param target The EntityType that will glow the specified color @@ -211,7 +212,7 @@ public void setRainbowColor(EntityType target){ /** * Sets the custom glow color of an Entity to a random, the entity will glow a different color each tick. - * + *

* See {@link #setColor(EntityType, String)} for more information * * @param target The EntityType that will glow the specified color @@ -242,7 +243,7 @@ public void clearColor(Entity entity, boolean useDefaultColorInstead){ * unless useDefaultColorInstead is true, in which case the default color * you specified will be used. The default color is the same one that would be applied globally * if {@link #setDefaultOverridesAll(boolean)} is used. - * + *

* This will also clear the rainbow/random/custom color! * * @param entityType The EntityType that will be cleared from the color @@ -259,14 +260,14 @@ public void clearColor(EntityType entityType, boolean useDefaultColorInstead) /** * Gets the custom glow color of an Entity. - * + *

* The result could be "#ffffff" meaning it does not have a custom color and is using * the vanilla one, or "rainbow" meaning its glowing rainbow, * or "random" meaning its glowing a random color each tick, * or another hexadecimal string color. - * + *

* It can also return a custom animation name if they are added by a datapack - * + *

* If you need a color value instead you can use {@link me.emafire003.dev.coloredglowlib.util.ColorUtils} to manipulate it * * @param target The Entity to check the color for @@ -279,14 +280,14 @@ public String getColor(Entity target){ /** * Gets the custom glow color of an EntityType. - * + *

* The result could be "#ffffff" meaning it does not have a custom color and is using * the vanilla one, or "rainbow" meaning its glowing rainbow, * or "random" meaning its glowing a random color each tick, * or another hexadecimal string color. - * + *

* It can also return a custom animation name if they are added by a datapack - * + *

* If you need a color value instead you can use {@link me.emafire003.dev.coloredglowlib.util.ColorUtils} to manipulate it * * @param target The EntityType to check the color for @@ -300,14 +301,14 @@ public String getColor(EntityType target){ /** * Gets the global/default custom glow color - * + *

* The result could be "#ffffff" meaning it does not have a custom color and is using * the vanilla one, or "rainbow" meaning its glowing rainbow, * or "random" meaning its glowing a random color each tick, * or another hexadecimal string color. - * + *

* It can also return a custom animation name if they are added by a datapack - * + *

* If you need a color value instead you can use {@link me.emafire003.dev.coloredglowlib.util.ColorUtils} to manipulate it * * @return The color string associated to the global color @@ -327,11 +328,11 @@ public String getDefaultColor(){ /** * Checks if an EntityType has a custom glow color or not. - * This is done by checking if its color is "#ffffff" or not. - * + * This is done by checking if its color (stored in the global component) is "#ffffff" or not. + *

* WARNING! This doesn't mean necessarily mean it has a custom color added by a datapack * but that it has a color that is different from the default value of white! - * + *

* Warning! If you used {@link #clearColor(EntityType, boolean)} with useDefaultColorInstead to true, * you may want to use: {@link #hasCustomOrDefaultColor(EntityType)} * @@ -361,20 +362,21 @@ public boolean hasCustomOrDefaultColor(EntityType target){ /** * Checks if an Entity has a custom glow color or not. - * This is done by checking if its color is "#ffffff" or not. - * + * This is done by checking if its color (stored in the component) is "#ffffff" or not. + *

* WARNING! This doesn't mean necessarily mean it has a custom color added by a datapack * but that it has a color that is different from the default value of white! - * + *

* Warning! If you used {@link #clearColor(Entity, boolean)} with useDefaultColorInstead to true, * you may want to use: {@link #hasCustomOrDefaultColor(Entity)} - * + *

* @param target The Entity to check the color for * * @return Returns true if the Entity has a custom glow color associated to it. */ + //TODO make configurable? Like using the default color instead. The has custom color i mean public boolean hasCustomColor(Entity target){ - return ColorUtils.checkDefault(COLOR_COMPONENT.get(target).getColor()); + return !ColorUtils.checkDefault(COLOR_COMPONENT.get(target).getColor()); } /** @@ -463,8 +465,12 @@ public boolean hasCustomColorAnimation(EntityType target){ * @return Returns true if the color associated to that Entity is added by a datapack * */ public boolean hasCustomColorAnimation(Entity target){ - String target_color = COLOR_COMPONENT.get(target).getColor(); - + String color = COLOR_COMPONENT.get(target).getColor(); + for(CustomColorAnimation customColorAnimation : ColoredGlowLibMod.getCustomColorAnimations()){ + if(color.equalsIgnoreCase(customColorAnimation.getName())){ + return true; + } + } return false; } diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibMod.java b/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibMod.java index 2451c45..b88a1ee 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibMod.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/ColoredGlowLibMod.java @@ -1,12 +1,11 @@ package me.emafire003.dev.coloredglowlib; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; -import dev.onyxstudios.cca.api.v3.component.ComponentRegistry; -import dev.onyxstudios.cca.api.v3.entity.EntityComponentFactoryRegistry; -import dev.onyxstudios.cca.api.v3.entity.EntityComponentInitializer; -import dev.onyxstudios.cca.api.v3.entity.RespawnCopyStrategy; -import dev.onyxstudios.cca.api.v3.scoreboard.ScoreboardComponentFactoryRegistry; -import dev.onyxstudios.cca.api.v3.scoreboard.ScoreboardComponentInitializer; +import net.minecraft.entity.Entity; +import org.ladysnake.cca.api.v3.entity.EntityComponentFactoryRegistry; +import org.ladysnake.cca.api.v3.entity.EntityComponentInitializer; +import org.ladysnake.cca.api.v3.entity.RespawnCopyStrategy; +import org.ladysnake.cca.api.v3.scoreboard.ScoreboardComponentFactoryRegistry; +import org.ladysnake.cca.api.v3.scoreboard.ScoreboardComponentInitializer; import me.emafire003.dev.coloredglowlib.command.CGLCommands; import me.emafire003.dev.coloredglowlib.component.ColorComponent; import me.emafire003.dev.coloredglowlib.component.GlobalColorComponent; @@ -16,8 +15,6 @@ import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.minecraft.entity.LivingEntity; -import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,9 +66,9 @@ public void onInitialize() { /** * Use this to get the ColoredGlowLib API instance and * use the methods to set colors and such - * + *

* It will return null if the server hasn't started yet. - * + *

* Aliases: {@link #getColoredGlowLib()} , {@link #getLib()} * */ @Nullable @@ -82,9 +79,9 @@ public static ColoredGlowLibAPI getAPI(){ /** * Use this to get the ColoredGlowLib API instance and * use the methods to set colors and such - * + *

* It will return null if the server hasn't started yet. - * + *

* Aliases: {@link #getAPI()} , {@link #getLib()} * */ @Nullable @@ -95,9 +92,9 @@ public static ColoredGlowLibAPI getColoredGlowLib(){ /** * Use this to get the ColoredGlowLib API instance and * use the methods to set colors and such - * + *

* It will return null if the server hasn't started yet. - * + *

* Aliases: {@link #getAPI()} , {@link #getAPI()} * */ @Nullable @@ -117,7 +114,7 @@ public static ColoredGlowLibAPI getLib(){ @Override public void registerEntityComponentFactories(EntityComponentFactoryRegistry registry) { registry.registerForPlayers(COLOR_COMPONENT, ColorComponent::new, RespawnCopyStrategy.ALWAYS_COPY); - registry.registerFor(LivingEntity.class, COLOR_COMPONENT, ColorComponent::new); + registry.registerFor(Entity.class, COLOR_COMPONENT, ColorComponent::new); } /** @@ -139,7 +136,7 @@ public void registerScoreboardComponentFactories(ScoreboardComponentFactoryRegis /** * Returns false if there were issues reading colors - * + *

* */ public static boolean loadCustomColorAnimation(CustomColorAnimation animation){ for(CustomColorAnimation customColorAnimation : custom_color_animations){ @@ -160,6 +157,7 @@ public static boolean loadCustomColorAnimation(CustomColorAnimation animation){ } } custom_color_animations.add(animation); + //TODO move to .debug? LOGGER.info("The custom color animation '" + animation.getName() + "' was loaded successfully!"); return true; } @@ -179,6 +177,7 @@ public static void checkMaybeWrongAnimations(){ } if(should_add){ custom_color_animations.add(animation); + //TODO move to .debug? LOGGER.info("The custom color animation '" + animation.getName() + "' was loaded successfully!"); } } diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/command/ClearGlowColorCommand.java b/src/main/java/me/emafire003/dev/coloredglowlib/command/ClearGlowColorCommand.java index deb460e..d318b76 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/command/ClearGlowColorCommand.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/command/ClearGlowColorCommand.java @@ -9,7 +9,7 @@ import me.emafire003.dev.coloredglowlib.component.GlobalColorComponent; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.command.argument.RegistryEntryArgumentType; +import net.minecraft.command.argument.RegistryEntryReferenceArgumentType; import net.minecraft.command.suggestion.SuggestionProviders; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -62,7 +62,7 @@ private int clearEntityColor(CommandContext context) throws } private int clearEntityTypeColor(CommandContext context) throws CommandSyntaxException { - EntityType type = RegistryEntryArgumentType.getSummonableEntityType(context, "entity").value(); + EntityType type = RegistryEntryReferenceArgumentType.getSummonableEntityType(context, "entity").value(); ServerCommandSource source = context.getSource(); boolean useDefault; @@ -123,7 +123,7 @@ public LiteralCommandNode getNode(CommandRegistryAccess reg ) ) .then( - CommandManager.argument("entity", RegistryEntryArgumentType.registryEntry(registryAccess, RegistryKeys.ENTITY_TYPE)).suggests(SuggestionProviders.SUMMONABLE_ENTITIES) + CommandManager.argument("entity", RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryKeys.ENTITY_TYPE)).suggests(SuggestionProviders.SUMMONABLE_ENTITIES) .executes(this::clearEntityTypeColor) .then( CommandManager.argument("useDefaultColor", BoolArgumentType.bool()) diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/command/SetGlowColorCommand.java b/src/main/java/me/emafire003/dev/coloredglowlib/command/SetGlowColorCommand.java index c8acd21..4fe9f2b 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/command/SetGlowColorCommand.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/command/SetGlowColorCommand.java @@ -9,7 +9,7 @@ import me.emafire003.dev.coloredglowlib.compat.permissions.PermissionsChecker; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.command.argument.EntityArgumentType; -import net.minecraft.command.argument.RegistryEntryArgumentType; +import net.minecraft.command.argument.RegistryEntryReferenceArgumentType; import net.minecraft.command.suggestion.SuggestionProviders; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -72,7 +72,7 @@ private int setTypeGlowColor(CommandContext context) throws ServerCommandSource source = context.getSource(); if(isValidColorOrCustom(color)){ - EntityType type = RegistryEntryArgumentType.getSummonableEntityType(context, "entity").value(); + EntityType type = RegistryEntryReferenceArgumentType.getSummonableEntityType(context, "entity").value(); if(color.equalsIgnoreCase("#rainbow")){ if (ColoredGlowLibMod.getAPI() != null) { ColoredGlowLibMod.getAPI().setRainbowColor(type); @@ -171,7 +171,7 @@ private int clearEntityColor(CommandContext context) throws private int clearEntityTypeColor(CommandContext context) throws CommandSyntaxException { boolean useDefault = BoolArgumentType.getBool(context, "useDefaultColor"); - EntityType type = RegistryEntryArgumentType.getSummonableEntityType(context, "entity").value(); + EntityType type = RegistryEntryReferenceArgumentType.getSummonableEntityType(context, "entity").value(); ServerCommandSource source = context.getSource(); @@ -198,7 +198,7 @@ public LiteralCommandNode getNode(CommandRegistryAccess reg ) ) .then( - CommandManager.argument("entity", RegistryEntryArgumentType.registryEntry(registryAccess, RegistryKeys.ENTITY_TYPE)).suggests(SuggestionProviders.SUMMONABLE_ENTITIES) + CommandManager.argument("entity", RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryKeys.ENTITY_TYPE)).suggests(SuggestionProviders.SUMMONABLE_ENTITIES) .then( CommandManager.argument("color", StringArgumentType.string()) .executes(this::setTypeGlowColor) diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/component/CGLComponent.java b/src/main/java/me/emafire003/dev/coloredglowlib/component/CGLComponent.java deleted file mode 100644 index a9f756f..0000000 --- a/src/main/java/me/emafire003/dev/coloredglowlib/component/CGLComponent.java +++ /dev/null @@ -1,8 +0,0 @@ -package me.emafire003.dev.coloredglowlib.component; - -import net.minecraft.nbt.NbtCompound; - -public interface CGLComponent { - void readFromNbt(NbtCompound tag); - void writeToNbt(NbtCompound tag); -} diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/component/ColorComponent.java b/src/main/java/me/emafire003/dev/coloredglowlib/component/ColorComponent.java index 41fd784..c7b623c 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/component/ColorComponent.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/component/ColorComponent.java @@ -1,44 +1,28 @@ package me.emafire003.dev.coloredglowlib.component; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; -import dev.onyxstudios.cca.api.v3.component.ComponentRegistry; -import dev.onyxstudios.cca.api.v3.component.ComponentV3; -import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; -import me.emafire003.dev.coloredglowlib.ColoredGlowLibMod; +import net.minecraft.entity.Entity; +import net.minecraft.registry.RegistryWrapper; +import org.ladysnake.cca.api.v3.component.ComponentKey; +import org.ladysnake.cca.api.v3.component.ComponentRegistry; +import org.ladysnake.cca.api.v3.component.ComponentV3; +import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent; import me.emafire003.dev.coloredglowlib.util.ColorUtils; -import net.minecraft.entity.LivingEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.util.Identifier; import static me.emafire003.dev.coloredglowlib.ColoredGlowLibMod.MOD_ID; -public class ColorComponent implements ComponentV3, AutoSyncedComponent, CGLComponent { +public class ColorComponent implements ComponentV3, AutoSyncedComponent{ public static final ComponentKey COLOR_COMPONENT = ComponentRegistry.getOrCreate(new Identifier(MOD_ID, "color_component"), ColorComponent.class); - private final LivingEntity self; + private final Entity self; - //TODO the rainbow thing doesn't work, it's black protected String color = ColorUtils.WHITE; - public ColorComponent(LivingEntity livingEntity) { - this.self = livingEntity; - } - - @Override - public void readFromNbt(NbtCompound tag) { - - if(tag.contains("color")){ - this.color = tag.getString("color"); - }else{ - this.color = ColorUtils.WHITE; - } - } - - @Override - public void writeToNbt(NbtCompound tag) { - tag.putString("color", this.color); + public ColorComponent(Entity entity) { + this.self = entity; } /** @@ -50,16 +34,26 @@ public String getColor(){ /** * @param color A hex color or "rainbow"*/ public void setColor(String color) { - ColoredGlowLibMod.LOGGER.info("Setting color to entity ( "+ this.self + ") : " + color); this.color = color; COLOR_COMPONENT.sync(self); } public void clear(){ this.color = ColorUtils.WHITE; - ColoredGlowLibMod.LOGGER.info("Clearing the color of ( "+ this.self + ") : " + color); - ColoredGlowLibMod.LOGGER.info("The entity color: " + getColor()); COLOR_COMPONENT.sync(self); } + @Override + public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { + if(tag.contains("color")){ + this.color = tag.getString("color"); + }else{ + this.color = ColorUtils.WHITE; + } + } + + @Override + public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { + tag.putString("color", this.color); + } } diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/component/GlobalColorComponent.java b/src/main/java/me/emafire003/dev/coloredglowlib/component/GlobalColorComponent.java index 8eb1e9f..dbad6a2 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/component/GlobalColorComponent.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/component/GlobalColorComponent.java @@ -1,9 +1,10 @@ package me.emafire003.dev.coloredglowlib.component; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; -import dev.onyxstudios.cca.api.v3.component.ComponentRegistry; -import dev.onyxstudios.cca.api.v3.component.ComponentV3; -import dev.onyxstudios.cca.api.v3.component.sync.AutoSyncedComponent; +import net.minecraft.registry.RegistryWrapper; +import org.ladysnake.cca.api.v3.component.ComponentKey; +import org.ladysnake.cca.api.v3.component.ComponentRegistry; +import org.ladysnake.cca.api.v3.component.ComponentV3; +import org.ladysnake.cca.api.v3.component.sync.AutoSyncedComponent; import me.emafire003.dev.coloredglowlib.util.ColorUtils; import net.minecraft.entity.EntityType; import net.minecraft.nbt.NbtCompound; @@ -19,7 +20,7 @@ import static me.emafire003.dev.coloredglowlib.ColoredGlowLibMod.MOD_ID; -public class GlobalColorComponent implements ComponentV3, AutoSyncedComponent, CGLComponent { +public class GlobalColorComponent implements ComponentV3, AutoSyncedComponent{ public static final ComponentKey GLOBAL_COLOR_COMPONENT = ComponentRegistry.getOrCreate(new Identifier(MOD_ID, "global_color_component"), GlobalColorComponent.class); @@ -39,7 +40,7 @@ public GlobalColorComponent(Scoreboard scoreboard, @Nullable MinecraftServer ser } @Override - public void readFromNbt(NbtCompound tag) { + public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { if(tag.contains("defaultColor")){ this.default_color = tag.getString("defaultColor"); @@ -73,7 +74,7 @@ public void readFromNbt(NbtCompound tag) { } @Override - public void writeToNbt(NbtCompound tag) { + public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { tag.putString("defaultColor", this.default_color); tag.putBoolean("typeOverridesEntityColor", this.typeOverridesEntityColor); tag.putBoolean("defaultOverridesAll", this.defaultOverridesAll); @@ -172,5 +173,4 @@ public void clear(){ this.entityTypeColorMap = new NbtCompound(); GLOBAL_COLOR_COMPONENT.sync(scoreboard); } - } diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/CGLResourceManager.java b/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/CGLResourceManager.java index 38d5ff7..f3fb245 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/CGLResourceManager.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/CGLResourceManager.java @@ -46,7 +46,7 @@ public void reload(ResourceManager manager) { ColoredGlowLibMod.LOGGER.debug("Processing file: " + id); - CustomColorAnimation groupOutput = result.getOrThrow(false, System.out::println); + CustomColorAnimation groupOutput = result.getOrThrow(); ColoredGlowLibMod.loadCustomColorAnimation(groupOutput); diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/ColorAnimationItem.java b/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/ColorAnimationItem.java index f861fc1..7275823 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/ColorAnimationItem.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/custom_data_animations/ColorAnimationItem.java @@ -14,8 +14,8 @@ public class ColorAnimationItem { ) .apply(instance, ColorAnimationItem::new)); - private String color; - private int active_for; + private final String color; + private final int active_for; public ColorAnimationItem(String color, int active_for){ diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/mixin/EntityColorMixin.java b/src/main/java/me/emafire003/dev/coloredglowlib/mixin/EntityColorMixin.java index 81505f3..db06772 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/mixin/EntityColorMixin.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/mixin/EntityColorMixin.java @@ -9,6 +9,7 @@ import net.minecraft.entity.Entity; import net.minecraft.util.math.random.Random; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -18,12 +19,14 @@ @Environment(EnvType.CLIENT) @Mixin(Entity.class) public abstract class EntityColorMixin { + @Unique private final Entity entity = ((Entity)(Object)this); /*public int nameSpecificColor(Entity entity){ Maybe i'll add it maybe not }*/ + @Unique public int handleCustomColor(String color){ if(color.startsWith("#")){ color = color.replaceAll("#", ""); @@ -65,17 +68,22 @@ public int handleCustomColor(String color){ return -1; } + @Unique private final ColorUtils.RainbowChanger rainbowColor = new ColorUtils.RainbowChanger(255, 0, 0); /**Returns the rainbow color*/ + @Unique private int getRainbowColor(){ rainbowColor.setRainbowColor(10); return rainbowColor.getColorValue(); } + @Unique int random_delay_counter = 0; + @Unique int prev_random_color = ColorUtils.toColorValue(ColorUtils.WHITE); + @Unique private int randomColor(){ Random r = entity.getWorld().getRandom(); if(random_delay_counter == 10){ @@ -92,7 +100,7 @@ public void injectChangeColorValue(CallbackInfoReturnable cir){ ColoredGlowLibAPI cgl = ColoredGlowLibMod.getAPI(); if(cgl == null){ - LOGGER.warn("The coloredglowlib api instance is null!"); + LOGGER.warn("The ColoredGlowLib API instance is null!"); return; } @@ -133,7 +141,7 @@ public void injectChangeColorValue(CallbackInfoReturnable cir){ } /**Checks if there is the EntityType color overrides the Entity's one - * + *

* If ( EntityType >> Entity-specific ) do stuff * */ if(cgl.getEntityTypeColorOverridesEntityColor()){ @@ -159,10 +167,11 @@ public void injectChangeColorValue(CallbackInfoReturnable cir){ * If it's the default one, it will check its entitytype, then the default color*/ String entity_col = cgl.getColor(entity); - //TODO make configurable? Like using the default color instead. The has custom color i mean - if(ColoredGlowLibMod.getAPI() != null && ColoredGlowLibMod.getAPI().hasCustomColor(entity)){ + //If the entity does not have a custom color, it will check for other things, like default color and entitytype color + if(ColoredGlowLibMod.getAPI() != null && !ColoredGlowLibMod.getAPI().hasCustomColor(entity)){ //If the entity type's color is the default one as well, returns the default color String type_col = cgl.getColor(entity.getType()); + //Checking if the enttiy has a custom color if(ColoredGlowLibMod.getAPI().hasCustomColor(entity.getType())){ if(type_col.equalsIgnoreCase("rainbow")){ //Checks if the entitytype is rainbow or random colored @@ -200,6 +209,7 @@ public void injectChangeColorValue(CallbackInfoReturnable cir){ } } + //It should be ending up here if the entity actually has a custom color, which entity_col /**Checks if the entity color is rainbow*/ if(entity_col.equalsIgnoreCase("rainbow")){ cir.setReturnValue(getRainbowColor()); @@ -217,7 +227,7 @@ public void injectChangeColorValue(CallbackInfoReturnable cir){ //TODO maybe set back to white if the color animation gets removed? - + /**If it hasn't returned yet, it means that the entity has a specific color, so it returns it*/ cir.setReturnValue(ColorUtils.toColorValue(entity_col)); } diff --git a/src/main/java/me/emafire003/dev/coloredglowlib/util/ColorUtils.java b/src/main/java/me/emafire003/dev/coloredglowlib/util/ColorUtils.java index 55c8cfe..a0dd20d 100644 --- a/src/main/java/me/emafire003/dev/coloredglowlib/util/ColorUtils.java +++ b/src/main/java/me/emafire003/dev/coloredglowlib/util/ColorUtils.java @@ -6,6 +6,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +@SuppressWarnings("unused") public class ColorUtils { public static final String WHITE = "#ffffff"; @@ -64,13 +65,11 @@ public static int toColorValue(String hex){ return Integer.decode(hex); } - //TODO needs testing /** Converts a given integer Color value to an */ public static String toHex(int colorValue){ return "#"+Integer.toHexString(colorValue).substring(2); } - //TODO needs testing public static String toHex(int r, int g, int b){ return "#"+Integer.toHexString(toColorValue(r,g,b)).substring(2); } @@ -176,7 +175,7 @@ public void setRainbowColor(int factor){ } /**Checks is a given string is actually a valid color - * + *

* It's here instead of in the API because it is sometimes needed before the server loads * */ public static boolean isValidColor(String color){ @@ -187,7 +186,7 @@ public static boolean isValidColor(String color){ } /**Checks is a given string is actually a valid color - * + *

* It's here instead of in the API because it is sometimes needed before the server loads * */ public static boolean isValidColorOrCustom(String color){ diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index b553e22..9e56019 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -41,12 +41,12 @@ ] }, "depends": { - "fabricloader": ">=0.15.1", - "minecraft": ">=1.20-", + "fabricloader": ">=0.15.11", + "minecraft": ">=1.20.5", "java": ">=16", - "cardinal-components-base": ">=3.0.0-0", - "cardinal-components-entity": ">=3.0.0-0", - "cardinal-components-scoreboard": ">=3.0.0-0" + "cardinal-components-base": ">=6.0.0-0", + "cardinal-components-entity": ">=6.0.0-0", + "cardinal-components-scoreboard": ">=6.0.0-0" }, "suggests": { "another-mod": "*"