diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml new file mode 100644 index 0000000..6636a94 --- /dev/null +++ b/.github/workflows/code_quality.yml @@ -0,0 +1,26 @@ +name: Qodana Code Review +on: + workflow_dispatch: + pull_request: + branches: + - '1.21' + push: + branches: + - '1.21' + +jobs: + qodana: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + checks: write + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + - name: 'Qodana Scan' + uses: JetBrains/qodana-action@v2024.3 + env: + QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 059d38c..7cb2567 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,4 @@ neoforge/run/* build/reports/problems/problems-report.html build/tmp/spotless-register-dependencies /build +/fabric/remappedSrc diff --git a/common/src/main/java/software/bluelib/BlueLibConstants.java b/common/src/main/java/software/bluelib/BlueLibConstants.java index 57afe68..cbc1c84 100644 --- a/common/src/main/java/software/bluelib/BlueLibConstants.java +++ b/common/src/main/java/software/bluelib/BlueLibConstants.java @@ -5,6 +5,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.logging.Logger; +import net.minecraft.resources.ResourceLocation; /** * A {@code public class} that defines common constants used across the BlueLib mod. @@ -83,4 +84,8 @@ private BlueLibConstants() {} * @since 1.0.0 */ public static boolean isLoggingEnabled = true; + + public static ResourceLocation resourceLocation(String pPath) { + return ResourceLocation.fromNamespaceAndPath(MOD_ID, pPath); + } } diff --git a/common/src/main/java/software/bluelib/entity/EntityStateManager.java b/common/src/main/java/software/bluelib/entity/EntityStateManager.java index 7d84627..330c464 100644 --- a/common/src/main/java/software/bluelib/entity/EntityStateManager.java +++ b/common/src/main/java/software/bluelib/entity/EntityStateManager.java @@ -1,10 +1,13 @@ // Copyright (c) BlueLib. Licensed under the MIT License. package software.bluelib.entity; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.Item; +import org.jetbrains.annotations.Nullable; import software.bluelib.interfaces.entity.ITamableEntity; /** @@ -27,8 +30,10 @@ *
  • {@link #setSwimmingState(LivingEntity, boolean)} - Updates the swimming state of the entity.
  • *
  • {@link #getSwimmingCooldown(LivingEntity)} - Retrieves the swimming cooldown period of the entity.
  • *
  • {@link #setSwimmingCooldown(LivingEntity, int)} - Updates the swimming cooldown period of the entity.
  • - *
  • {@link #getTamingItem(LivingEntity)} - Retrieves the taming item associated with the entity.
  • - *
  • {@link #setTamingItem(LivingEntity, Item)} - Updates the taming item for the entity.
  • + *
  • {@link #getTamingItems(LivingEntity)} - Retrieves the taming items associated with the entity.
  • + *
  • {@link #setTamingItems(LivingEntity, List)} - Sets the taming items for the entity.
  • + *
  • {@link #addTamingItem(LivingEntity, Item)} - Adds a taming item to the entity.
  • + *
  • {@link #getSpecificTamingItem(LivingEntity, Item)} - Retrieves the specific taming item associated with the entity.
  • *
  • {@link #getFollowingState(LivingEntity)} - Retrieves the following state of the entity.
  • *
  • {@link #setFollowingState(LivingEntity, boolean)} - Updates the following state of the entity.
  • *
  • {@link #getLoyaltyLevel(LivingEntity)} - Retrieves the loyalty level of the entity.
  • @@ -433,7 +438,7 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) { * A map to store the taming item associated with entities. *

    * Purpose: This map tracks the specific taming item required for each {@link LivingEntity}.
    - * When: The map is populated or accessed when {@link #getTamingItem(LivingEntity)} or {@link #setTamingItem(LivingEntity, Item)} is invoked.
    + * When: The map is populated or accessed when {@link #getTamingItem(LivingEntity)} or {@link #setTamingItem(LivingEntity, List)} is invoked.
    * Where: Used to manage and validate taming mechanics based on specific items.
    * Additional Info: The keys are {@link LivingEntity} instances, and the values are the taming items. *

    @@ -442,50 +447,116 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) { * @see String * @since 1.7.0 */ - private static final Map tamingItemMap = new HashMap<>(); + private static final Map> tamingItemMap = new HashMap<>(); /** - * Retrieves the taming item associated with the specified entity. + * Retrieves the taming items associated with the specified entity. *

    - * Purpose: Returns the {@link String} representation of the item required to tame the given {@link LivingEntity}.
    - * When: Invoked during interactions or checks that require validation of the entity's taming item.
    + * Purpose: Returns the {@link String} representation of the items required to tame the given {@link LivingEntity}.
    + * When: Invoked during interactions or checks that require validation of the entity's taming items.
    * Where: Used in taming mechanics or gameplay systems that enforce item-based taming.
    - * Additional Info: If no taming item is set for the entity, the method returns {@code null}. + * Additional Info: If no taming items are set for the entity, the method returns an empty {@link ArrayList}. *

    * - * @param pEntity The {@link LivingEntity} whose taming item is to be retrieved. + * @param pEntity The {@link LivingEntity} whose taming items are to be retrieved. * @return The taming item. * @author Kyradjis * @see #tamingItemMap * @see LivingEntity * @see String + * @see List + * @see ArrayList + * @since 1.7.0 + */ + public static List getTamingItems(LivingEntity pEntity) { + return tamingItemMap.getOrDefault(pEntity, new ArrayList<>()); + } + + /** + * Retrieves the specific taming item associated with the specified entity. + *

    + * Purpose: Returns the specific item required to tame the given {@link LivingEntity}.
    + * When: Invoked during interactions or checks that require validation of the entity's taming items.
    + * Where: Used in taming mechanics or gameplay systems that enforce item-based taming.
    + * Additional Info: If no taming items are set for the entity, the method returns {@code null}. + *

    + * + * @param pEntity The {@link LivingEntity} whose taming item is to be retrieved. + * @param pItem The taming item. + * @return The specific taming item required to tame the entity, or {@code null} if no item is set. + * @author MeAlam + * @see #tamingItemMap + * @see LivingEntity + * @see Item + * @see List + * @see ArrayList + * @see Nullable * @since 1.7.0 */ - public static Item getTamingItem(LivingEntity pEntity) { - return tamingItemMap.getOrDefault(pEntity, null); + @Nullable + public static Item getSpecificTamingItem(LivingEntity pEntity, Item pItem) { + List items = tamingItemMap.getOrDefault(pEntity, new ArrayList<>()); + if (items.isEmpty()) { + return null; + } + for (Item item : items) { + if (item == pItem) { + return item; + } + } + return null; } /** - * Sets the taming item for the specified entity. + * Sets the taming items for the specified entity. *

    - * Purpose: Updates the item required to tame the given {@link LivingEntity}.
    + * Purpose: Updates the items required to tame the given {@link LivingEntity}.
    * When: Called during interactions or events that define or modify the taming requirements for an entity.
    * Where: Used to manage taming mechanics based on specific items.
    - * Additional Info: The taming item is stored in the {@link #tamingItemMap}. + * Additional Info: The taming items are stored in the {@link #tamingItemMap}. *

    * - * @param pEntity The {@link LivingEntity} whose taming item is to be set. - * @param pItem The taming item. + * @param pEntity The {@link LivingEntity} whose taming items are to be set. + * @param pItem The taming items. * @author Kyradjis * @see #tamingItemMap * @see LivingEntity * @see String + * @see Item + * @see List + * @see ArrayList * @since 1.7.0 */ - public static void setTamingItem(LivingEntity pEntity, Item pItem) { + public static void setTamingItems(LivingEntity pEntity, List pItem) { tamingItemMap.put(pEntity, pItem); } + /** + * Adds a taming item to the specified entity. + *

    + * Purpose: Adds an item to the list of taming items required to tame the given {@link LivingEntity}.
    + * When: Called during interactions or events that add new taming items to an entity's requirements.
    + * Where: Used to manage taming mechanics based on specific items.
    + * Additional Info: The taming item is stored in the {@link #tamingItemMap}. + *

    + * + * @param pEntity The {@link LivingEntity} to add the taming item to. + * @param pItem The taming item to add to the entity's requirements. + * @author MeAlam + * @see #tamingItemMap + * @see LivingEntity + * @see String + * @see Item + * @see List + * @see ArrayList + * @since 1.7.0 + */ + public static void addTamingItem(LivingEntity pEntity, Item pItem) { + List items = tamingItemMap.getOrDefault(pEntity, new ArrayList<>()); + items.add(pItem); + tamingItemMap.put(pEntity, items); + } + // Owner Following /** diff --git a/common/src/main/java/software/bluelib/interfaces/entity/IFlyingEntity.java b/common/src/main/java/software/bluelib/interfaces/entity/IFlyingEntity.java index 8bd88c3..15a14e9 100644 --- a/common/src/main/java/software/bluelib/interfaces/entity/IFlyingEntity.java +++ b/common/src/main/java/software/bluelib/interfaces/entity/IFlyingEntity.java @@ -24,6 +24,7 @@ *
  • {@link #getFlyingSpeedMultiplier(LivingEntity)} - Retrieves the speed multiplier for the entity while flying.
  • *
  • {@link #setFlyingSpeedMultiplier(LivingEntity, double)} - Sets the speed multiplier for the entity while flying.
  • *
  • {@link #canFly(LivingEntity)} - Checks if the entity is capable of flight.
  • + *
  • {@link #canFly(LivingEntity, boolean)} - Sets whether the entity can fly.
  • *
  • {@link #getFlightCooldown(LivingEntity)} - Retrieves the cooldown period between flights.
  • *
  • {@link #setFlightCooldown(LivingEntity, int)} - Sets the cooldown period between flights.
  • *
  • {@link #getAltitude(LivingEntity)} - Retrieves the current altitude of the entity.
  • diff --git a/common/src/main/java/software/bluelib/interfaces/entity/ISwimmingEntity.java b/common/src/main/java/software/bluelib/interfaces/entity/ISwimmingEntity.java index eb0b34d..29bd9c9 100644 --- a/common/src/main/java/software/bluelib/interfaces/entity/ISwimmingEntity.java +++ b/common/src/main/java/software/bluelib/interfaces/entity/ISwimmingEntity.java @@ -23,6 +23,8 @@ *
  • {@link #setSwimmingState(LivingEntity, boolean)} - Updates the swimming state of the entity.
  • *
  • {@link #getSwimmingSpeedMultiplier(LivingEntity)} - Retrieves the swimming speed multiplier of the entity.
  • *
  • {@link #setSwimmingSpeedMultiplier(LivingEntity, double)} - Updates the swimming speed multiplier of the entity.
  • + *
  • {@link #canSwim(LivingEntity)} - Checks if the entity is capable of swimming.
  • + *
  • {@link #canSwim(LivingEntity, boolean)} - Sets whether the entity can swim.
  • *
  • {@link #getSwimmingCooldown(LivingEntity)} - Retrieves the cooldown period for the entity's swimming behavior.
  • *
  • {@link #setSwimmingCooldown(LivingEntity, int)} - Updates the cooldown period for the entity's swimming behavior.
  • *
  • {@link #getDepth(LivingEntity)} - Retrieves the current depth (Y-coordinate) of the entity.
  • diff --git a/common/src/main/java/software/bluelib/interfaces/entity/ITamableEntity.java b/common/src/main/java/software/bluelib/interfaces/entity/ITamableEntity.java index be509ff..2baaf21 100644 --- a/common/src/main/java/software/bluelib/interfaces/entity/ITamableEntity.java +++ b/common/src/main/java/software/bluelib/interfaces/entity/ITamableEntity.java @@ -1,6 +1,7 @@ // Copyright (c) BlueLib. Licensed under the MIT License. package software.bluelib.interfaces.entity; +import java.util.List; import java.util.UUID; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.OwnableEntity; @@ -19,9 +20,11 @@ * Key Methods: *
      *
    • {@link #isTamed(OwnableEntity)} - Checks if the provided entity is tamed.
    • - *
    • {@link #ownedBy(OwnableEntity, Player)} - Checks if a specific player owns the entity.
    • - *
    • {@link #getTamingItem(LivingEntity)} - Retrieves the taming item required for the entity.
    • - *
    • {@link #setTamingItem(LivingEntity, String)} - Sets the taming item for the entity.
    • + *
    • {@link #isOwnedBy(OwnableEntity, Player)} - Checks if a specific player owns the entity.
    • + *
    • {@link #getTamingItems(LivingEntity)} - Retrieves the taming items associated with the entity.
    • + *
    • {@link #getSpecificTamingItem(LivingEntity, Item)} - Retrieves the specific taming item required for the entity.
    • + *
    • {@link #setTamingItems(LivingEntity, List)} - Sets the taming items for the entity.
    • + *
    • {@link #addTamingItem(LivingEntity, Item)} - Adds a taming item to the entity.
    • *
    • {@link #getFollowingStatus(LivingEntity)} - Checks if the entity is following its owner.
    • *
    • {@link #setFollowingStatus(LivingEntity, boolean)} - Sets the following status of the entity.
    • *
    • {@link #getLoyaltyLevel(LivingEntity)} - Retrieves the loyalty level of the entity.
    • @@ -79,44 +82,91 @@ default boolean isOwnedBy(OwnableEntity pEntity, Player pPlayer) { } /** - * Retrieves the taming item associated with the specified entity. + * Retrieves the taming items associated with the specified entity. *

      - * Purpose: Returns the item required to tame the {@link LivingEntity}.
      + * Purpose: Returns the items required to tame the {@link LivingEntity}.
      * When: Called during interactions or checks related to taming mechanics.
      * Where: Used in gameplay systems that validate or enforce taming requirements.
      * Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.
      *

      * - * @param pEntity The {@link LivingEntity} whose taming item is to be retrieved. - * @return The name of the taming item as a {@link String}. + * @param pEntity The {@link LivingEntity} whose taming items are to be retrieved. + * @return The name of the taming items as a {@link String}. * @author Kyradjis * @see EntityStateManager * @see LivingEntity + * @see Item + * @see List * @since 1.7.0 */ - default Item getTamingItem(LivingEntity pEntity) { - return EntityStateManager.getTamingItem(pEntity); + default List getTamingItems(LivingEntity pEntity) { + return EntityStateManager.getTamingItems(pEntity); } /** - * Sets the taming item for the specified entity. + * Retrieves the specific taming item required for the entity. *

      - * Purpose: Updates the item required to tame the {@link LivingEntity}.
      + * Purpose: Returns the specific item required to tame the {@link LivingEntity}.
      + * When: Called during interactions or checks related to taming mechanics.
      + * Where: Used in gameplay systems that validate or enforce taming requirements.
      + * Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.
      + *

      + * + * @param pEntity The {@link LivingEntity} whose specific taming item is to be retrieved. + * @param pItem The name of the taming item as a {@link String}. + * @return The specific taming item as an {@link Item} object. + * @author MeAlam + * @see EntityStateManager + * @see LivingEntity + * @see Item + * @since 1.7.0 + */ + default Item getSpecificTamingItem(LivingEntity pEntity, Item pItem) { + return EntityStateManager.getSpecificTamingItem(pEntity, pItem); + } + + /** + * Sets the taming items for the specified entity. + *

      + * Purpose: Updates the items required to tame the {@link LivingEntity}.
      * When: Invoked during setup or configuration of taming mechanics.
      * Where: Used to modify the taming requirements for an entity.
      * Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.
      *

      * - * @param pEntity The {@link LivingEntity} whose taming item is to be set. - * @param pItem The name of the taming item as a {@link String}. + * @param pEntity The {@link LivingEntity} whose taming items are to be set. + * @param pItem The name of the taming items as a {@link String}. * @author Kyradjis * @see EntityStateManager * @see LivingEntity * @see String + * @see Item + * @see List + * @since 1.7.0 + */ + default void setTamingItems(LivingEntity pEntity, List pItem) { + EntityStateManager.setTamingItems(pEntity, pItem); + } + + /** + * Adds a taming item to the specified entity. + *

      + * Purpose: Adds an item to the list of items required to tame the {@link LivingEntity}.
      + * When: Invoked during setup or configuration of taming mechanics.
      + * Where: Used to modify the taming requirements for an entity.
      + * Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.
      + *

      + * + * @param pEntity The {@link LivingEntity} to add the taming item to. + * @param pItem The item to add to the list of taming items. + * @author MeAlam + * @see EntityStateManager + * @see LivingEntity + * @see Item * @since 1.7.0 */ - default void setTamingItem(LivingEntity pEntity, Item pItem) { - EntityStateManager.setTamingItem(pEntity, pItem); + default void addTamingItem(LivingEntity pEntity, Item pItem) { + EntityStateManager.addTamingItem(pEntity, pItem); } /** diff --git a/common/src/main/java/software/bluelib/markdown/syntax/Color.java b/common/src/main/java/software/bluelib/markdown/syntax/Color.java index b7bd737..c565750 100644 --- a/common/src/main/java/software/bluelib/markdown/syntax/Color.java +++ b/common/src/main/java/software/bluelib/markdown/syntax/Color.java @@ -235,7 +235,7 @@ private void appendColor(String pColorText, List pColors, Style pOrigin } if (pColors.size() == 1) { - int color = pColors.get(0); + int color = pColors.getFirst(); pResult.append(Component.literal(pColorText).setStyle(pOriginalStyle.withColor(TextColor.fromRgb(color)))); return; } diff --git a/common/src/main/java/software/bluelib/test/markdown/syntax/SpoilerTest.java b/common/src/main/java/software/bluelib/test/markdown/syntax/SpoilerTest.java index b919772..562053c 100644 --- a/common/src/main/java/software/bluelib/test/markdown/syntax/SpoilerTest.java +++ b/common/src/main/java/software/bluelib/test/markdown/syntax/SpoilerTest.java @@ -38,7 +38,7 @@ public static void spoilerSpoiler(GameTestHelper pHelper) { } public static void spoilerGradient(GameTestHelper pHelper) { - MessageUtils.sendMessageToPlayers(pHelper, "§6 This is a spoiler/gradient test: §r ||spoiler|| -#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + +MessageUtils.getRandomHex() + "-(Gradient)"); + MessageUtils.sendMessageToPlayers(pHelper, "§6 This is a spoiler/gradient test: §r ||spoiler|| -#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + MessageUtils.getRandomHex() + "-(Gradient)"); } public static void spoilerCancel(GameTestHelper pHelper) { diff --git a/common/src/main/java/software/bluelib/utils/math/RandomGenUtils.java b/common/src/main/java/software/bluelib/utils/math/RandomGenUtils.java index 1b71b96..c902793 100644 --- a/common/src/main/java/software/bluelib/utils/math/RandomGenUtils.java +++ b/common/src/main/java/software/bluelib/utils/math/RandomGenUtils.java @@ -75,7 +75,7 @@ public static int generateRandomInt(int pMin, int pMax) { public static double generateRandomDouble(double pMin, double pMax) { if (pMin > pMax) { Throwable throwable = new IllegalArgumentException("Minimum value must not be greater than maximum value."); - BaseLogger.log(BaseLogLevel.WARNING, "Error generating random double", true); + BaseLogger.log(BaseLogLevel.WARNING, "Error generating random double", throwable, true); return 0; } return pMin + Math.random() * (pMax - pMin); diff --git a/gradle.properties b/gradle.properties index cde34da..3deb6d1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,11 +26,11 @@ parchment_minecraft=1.21.4 parchment_version=2024.12.22 # Fabric -fabric_version=0.114.0+1.21.4 -fabric_loader_version=0.16.9 +fabric_version=0.114.2+1.21.4 +fabric_loader_version=0.16.10 # NeoForge -neoforge_version=21.4.47-beta +neoforge_version=21.4.50-beta neoforge_loader_version_range=[4,) neoforge_version_range=[21.0.0-beta,) diff --git a/qodana.yaml b/qodana.yaml new file mode 100644 index 0000000..44a1abe --- /dev/null +++ b/qodana.yaml @@ -0,0 +1,31 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# +version: "1.0" + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +projectJDK: "21" #(Applied in CI/CD pipeline) + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-jvm:latest