Skip to content

Commit

Permalink
Added the Final things of 1.7.0 (#102)
Browse files Browse the repository at this point in the history
## Description
Added various things that finalize the 1.7.0 release

## Changes
- **Change 1**: Added Qodana Code Review
- **Change 2**: Changed `Item` to `List<Item>` in ITamableEntity to
allow more then 1 Taming Item being set at the same time.
- **Change 3**: Added a Method for BlueLib ResourceLocations
- **Change 4:** Small Cleanup of Comments and Code

## Type of Change
- [ ] Bug fix
- [x] New feature
- [x] Cleanup
- [ ] Breaking change
- [ ] Documentation update

## Checklist
- [x] My code follows the style guidelines of this project.
[Contributing](https://github.com/MeAlam1/BlueLib/blob/1.21/CONTRIBUTING.md)
- [x] I have performed a self-review of my own code.
- [x] I have commented my code following the guidelines.
[Contributing](https://github.com/MeAlam1/BlueLib/blob/1.21/CONTRIBUTING.md)
- [x] My changes generate no new warnings.

## Related Issues
#63
  • Loading branch information
MeAlam1 authored Jan 9, 2025
1 parent e051e8b commit e90e932
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 38 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ neoforge/run/*
build/reports/problems/problems-report.html
build/tmp/spotless-register-dependencies
/build
/fabric/remappedSrc
5 changes: 5 additions & 0 deletions common/src/main/java/software/bluelib/BlueLibConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
105 changes: 88 additions & 17 deletions common/src/main/java/software/bluelib/entity/EntityStateManager.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -27,8 +30,10 @@
* <li>{@link #setSwimmingState(LivingEntity, boolean)} - Updates the swimming state of the entity.</li>
* <li>{@link #getSwimmingCooldown(LivingEntity)} - Retrieves the swimming cooldown period of the entity.</li>
* <li>{@link #setSwimmingCooldown(LivingEntity, int)} - Updates the swimming cooldown period of the entity.</li>
* <li>{@link #getTamingItem(LivingEntity)} - Retrieves the taming item associated with the entity.</li>
* <li>{@link #setTamingItem(LivingEntity, Item)} - Updates the taming item for the entity.</li>
* <li>{@link #getTamingItems(LivingEntity)} - Retrieves the taming items associated with the entity.</li>
* <li>{@link #setTamingItems(LivingEntity, List)} - Sets the taming items for the entity.</li>
* <li>{@link #addTamingItem(LivingEntity, Item)} - Adds a taming item to the entity.</li>
* <li>{@link #getSpecificTamingItem(LivingEntity, Item)} - Retrieves the specific taming item associated with the entity.</li>
* <li>{@link #getFollowingState(LivingEntity)} - Retrieves the following state of the entity.</li>
* <li>{@link #setFollowingState(LivingEntity, boolean)} - Updates the following state of the entity.</li>
* <li>{@link #getLoyaltyLevel(LivingEntity)} - Retrieves the loyalty level of the entity.</li>
Expand Down Expand Up @@ -433,7 +438,7 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) {
* A map to store the taming item associated with entities.
* <p>
* Purpose: This map tracks the specific taming item required for each {@link LivingEntity}.<br>
* When: The map is populated or accessed when {@link #getTamingItem(LivingEntity)} or {@link #setTamingItem(LivingEntity, Item)} is invoked.<br>
* When: The map is populated or accessed when {@link #getTamingItem(LivingEntity)} or {@link #setTamingItem(LivingEntity, List)} is invoked.<br>
* Where: Used to manage and validate taming mechanics based on specific items.<br>
* Additional Info: The keys are {@link LivingEntity} instances, and the values are the taming items.
* </p>
Expand All @@ -442,50 +447,116 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) {
* @see String
* @since 1.7.0
*/
private static final Map<LivingEntity, Item> tamingItemMap = new HashMap<>();
private static final Map<LivingEntity, List<Item>> tamingItemMap = new HashMap<>();

/**
* Retrieves the taming item associated with the specified entity.
* Retrieves the taming items associated with the specified entity.
* <p>
* Purpose: Returns the {@link String} representation of the item required to tame the given {@link LivingEntity}.<br>
* When: Invoked during interactions or checks that require validation of the entity's taming item.<br>
* Purpose: Returns the {@link String} representation of the items required to tame the given {@link LivingEntity}.<br>
* When: Invoked during interactions or checks that require validation of the entity's taming items.<br>
* Where: Used in taming mechanics or gameplay systems that enforce item-based taming.<br>
* 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}.
* </p>
*
* @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<Item> getTamingItems(LivingEntity pEntity) {
return tamingItemMap.getOrDefault(pEntity, new ArrayList<>());
}

/**
* Retrieves the specific taming item associated with the specified entity.
* <p>
* Purpose: Returns the specific item required to tame the given {@link LivingEntity}.<br>
* When: Invoked during interactions or checks that require validation of the entity's taming items.<br>
* Where: Used in taming mechanics or gameplay systems that enforce item-based taming.<br>
* Additional Info: If no taming items are set for the entity, the method returns {@code null}.
* </p>
*
* @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<Item> 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.
* <p>
* Purpose: Updates the item required to tame the given {@link LivingEntity}.<br>
* Purpose: Updates the items required to tame the given {@link LivingEntity}.<br>
* When: Called during interactions or events that define or modify the taming requirements for an entity.<br>
* Where: Used to manage taming mechanics based on specific items.<br>
* Additional Info: The taming item is stored in the {@link #tamingItemMap}.
* Additional Info: The taming items are stored in the {@link #tamingItemMap}.
* </p>
*
* @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<Item> pItem) {
tamingItemMap.put(pEntity, pItem);
}

/**
* Adds a taming item to the specified entity.
* <p>
* Purpose: Adds an item to the list of taming items required to tame the given {@link LivingEntity}.<br>
* When: Called during interactions or events that add new taming items to an entity's requirements.<br>
* Where: Used to manage taming mechanics based on specific items.<br>
* Additional Info: The taming item is stored in the {@link #tamingItemMap}.
* </p>
*
* @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<Item> items = tamingItemMap.getOrDefault(pEntity, new ArrayList<>());
items.add(pItem);
tamingItemMap.put(pEntity, items);
}

// Owner Following

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* <li>{@link #getFlyingSpeedMultiplier(LivingEntity)} - Retrieves the speed multiplier for the entity while flying.</li>
* <li>{@link #setFlyingSpeedMultiplier(LivingEntity, double)} - Sets the speed multiplier for the entity while flying.</li>
* <li>{@link #canFly(LivingEntity)} - Checks if the entity is capable of flight.</li>
* <li>{@link #canFly(LivingEntity, boolean)} - Sets whether the entity can fly.</li>
* <li>{@link #getFlightCooldown(LivingEntity)} - Retrieves the cooldown period between flights.</li>
* <li>{@link #setFlightCooldown(LivingEntity, int)} - Sets the cooldown period between flights.</li>
* <li>{@link #getAltitude(LivingEntity)} - Retrieves the current altitude of the entity.</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* <li>{@link #setSwimmingState(LivingEntity, boolean)} - Updates the swimming state of the entity.</li>
* <li>{@link #getSwimmingSpeedMultiplier(LivingEntity)} - Retrieves the swimming speed multiplier of the entity.</li>
* <li>{@link #setSwimmingSpeedMultiplier(LivingEntity, double)} - Updates the swimming speed multiplier of the entity.</li>
* <li>{@link #canSwim(LivingEntity)} - Checks if the entity is capable of swimming.</li>
* <li>{@link #canSwim(LivingEntity, boolean)} - Sets whether the entity can swim.</li>
* <li>{@link #getSwimmingCooldown(LivingEntity)} - Retrieves the cooldown period for the entity's swimming behavior.</li>
* <li>{@link #setSwimmingCooldown(LivingEntity, int)} - Updates the cooldown period for the entity's swimming behavior.</li>
* <li>{@link #getDepth(LivingEntity)} - Retrieves the current depth (Y-coordinate) of the entity.</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,9 +20,11 @@
* Key Methods:
* <ul>
* <li>{@link #isTamed(OwnableEntity)} - Checks if the provided entity is tamed.</li>
* <li>{@link #ownedBy(OwnableEntity, Player)} - Checks if a specific player owns the entity.</li>
* <li>{@link #getTamingItem(LivingEntity)} - Retrieves the taming item required for the entity.</li>
* <li>{@link #setTamingItem(LivingEntity, String)} - Sets the taming item for the entity.</li>
* <li>{@link #isOwnedBy(OwnableEntity, Player)} - Checks if a specific player owns the entity.</li>
* <li>{@link #getTamingItems(LivingEntity)} - Retrieves the taming items associated with the entity.</li>
* <li>{@link #getSpecificTamingItem(LivingEntity, Item)} - Retrieves the specific taming item required for the entity.</li>
* <li>{@link #setTamingItems(LivingEntity, List)} - Sets the taming items for the entity.</li>
* <li>{@link #addTamingItem(LivingEntity, Item)} - Adds a taming item to the entity.</li>
* <li>{@link #getFollowingStatus(LivingEntity)} - Checks if the entity is following its owner.</li>
* <li>{@link #setFollowingStatus(LivingEntity, boolean)} - Sets the following status of the entity.</li>
* <li>{@link #getLoyaltyLevel(LivingEntity)} - Retrieves the loyalty level of the entity.</li>
Expand Down Expand Up @@ -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.
* <p>
* Purpose: Returns the item required to tame the {@link LivingEntity}.<br>
* Purpose: Returns the items required to tame the {@link LivingEntity}.<br>
* When: Called during interactions or checks related to taming mechanics.<br>
* Where: Used in gameplay systems that validate or enforce taming requirements.<br>
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
* </p>
*
* @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<Item> getTamingItems(LivingEntity pEntity) {
return EntityStateManager.getTamingItems(pEntity);
}

/**
* Sets the taming item for the specified entity.
* Retrieves the specific taming item required for the entity.
* <p>
* Purpose: Updates the item required to tame the {@link LivingEntity}.<br>
* Purpose: Returns the specific item required to tame the {@link LivingEntity}.<br>
* When: Called during interactions or checks related to taming mechanics.<br>
* Where: Used in gameplay systems that validate or enforce taming requirements.<br>
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
* </p>
*
* @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.
* <p>
* Purpose: Updates the items required to tame the {@link LivingEntity}.<br>
* When: Invoked during setup or configuration of taming mechanics.<br>
* Where: Used to modify the taming requirements for an entity.<br>
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
* </p>
*
* @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<Item> pItem) {
EntityStateManager.setTamingItems(pEntity, pItem);
}

/**
* Adds a taming item to the specified entity.
* <p>
* Purpose: Adds an item to the list of items required to tame the {@link LivingEntity}.<br>
* When: Invoked during setup or configuration of taming mechanics.<br>
* Where: Used to modify the taming requirements for an entity.<br>
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
* </p>
*
* @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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private void appendColor(String pColorText, List<Integer> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit e90e932

Please sign in to comment.