Skip to content

Commit e90e932

Browse files
authored
Added the Final things of 1.7.0 (#102)
## 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
1 parent e051e8b commit e90e932

File tree

12 files changed

+225
-38
lines changed

12 files changed

+225
-38
lines changed

.github/workflows/code_quality.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Qodana Code Review
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- '1.21'
7+
push:
8+
branches:
9+
- '1.21'
10+
11+
jobs:
12+
qodana:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
checks: write
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
ref: ${{ github.event.pull_request.head.sha }}
22+
fetch-depth: 0
23+
- name: 'Qodana Scan'
24+
uses: JetBrains/[email protected]
25+
env:
26+
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ neoforge/run/*
5555
build/reports/problems/problems-report.html
5656
build/tmp/spotless-register-dependencies
5757
/build
58+
/fabric/remappedSrc

common/src/main/java/software/bluelib/BlueLibConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.concurrent.Executors;
66
import java.util.concurrent.ScheduledExecutorService;
77
import java.util.logging.Logger;
8+
import net.minecraft.resources.ResourceLocation;
89

910
/**
1011
* A {@code public class} that defines common constants used across the BlueLib mod.
@@ -83,4 +84,8 @@ private BlueLibConstants() {}
8384
* @since 1.0.0
8485
*/
8586
public static boolean isLoggingEnabled = true;
87+
88+
public static ResourceLocation resourceLocation(String pPath) {
89+
return ResourceLocation.fromNamespaceAndPath(MOD_ID, pPath);
90+
}
8691
}

common/src/main/java/software/bluelib/entity/EntityStateManager.java

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Copyright (c) BlueLib. Licensed under the MIT License.
22
package software.bluelib.entity;
33

4+
import java.util.ArrayList;
45
import java.util.HashMap;
6+
import java.util.List;
57
import java.util.Map;
68
import net.minecraft.world.entity.LivingEntity;
79
import net.minecraft.world.item.Item;
10+
import org.jetbrains.annotations.Nullable;
811
import software.bluelib.interfaces.entity.ITamableEntity;
912

1013
/**
@@ -27,8 +30,10 @@
2730
* <li>{@link #setSwimmingState(LivingEntity, boolean)} - Updates the swimming state of the entity.</li>
2831
* <li>{@link #getSwimmingCooldown(LivingEntity)} - Retrieves the swimming cooldown period of the entity.</li>
2932
* <li>{@link #setSwimmingCooldown(LivingEntity, int)} - Updates the swimming cooldown period of the entity.</li>
30-
* <li>{@link #getTamingItem(LivingEntity)} - Retrieves the taming item associated with the entity.</li>
31-
* <li>{@link #setTamingItem(LivingEntity, Item)} - Updates the taming item for the entity.</li>
33+
* <li>{@link #getTamingItems(LivingEntity)} - Retrieves the taming items associated with the entity.</li>
34+
* <li>{@link #setTamingItems(LivingEntity, List)} - Sets the taming items for the entity.</li>
35+
* <li>{@link #addTamingItem(LivingEntity, Item)} - Adds a taming item to the entity.</li>
36+
* <li>{@link #getSpecificTamingItem(LivingEntity, Item)} - Retrieves the specific taming item associated with the entity.</li>
3237
* <li>{@link #getFollowingState(LivingEntity)} - Retrieves the following state of the entity.</li>
3338
* <li>{@link #setFollowingState(LivingEntity, boolean)} - Updates the following state of the entity.</li>
3439
* <li>{@link #getLoyaltyLevel(LivingEntity)} - Retrieves the loyalty level of the entity.</li>
@@ -433,7 +438,7 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) {
433438
* A map to store the taming item associated with entities.
434439
* <p>
435440
* Purpose: This map tracks the specific taming item required for each {@link LivingEntity}.<br>
436-
* When: The map is populated or accessed when {@link #getTamingItem(LivingEntity)} or {@link #setTamingItem(LivingEntity, Item)} is invoked.<br>
441+
* When: The map is populated or accessed when {@link #getTamingItem(LivingEntity)} or {@link #setTamingItem(LivingEntity, List)} is invoked.<br>
437442
* Where: Used to manage and validate taming mechanics based on specific items.<br>
438443
* Additional Info: The keys are {@link LivingEntity} instances, and the values are the taming items.
439444
* </p>
@@ -442,50 +447,116 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) {
442447
* @see String
443448
* @since 1.7.0
444449
*/
445-
private static final Map<LivingEntity, Item> tamingItemMap = new HashMap<>();
450+
private static final Map<LivingEntity, List<Item>> tamingItemMap = new HashMap<>();
446451

447452
/**
448-
* Retrieves the taming item associated with the specified entity.
453+
* Retrieves the taming items associated with the specified entity.
449454
* <p>
450-
* Purpose: Returns the {@link String} representation of the item required to tame the given {@link LivingEntity}.<br>
451-
* When: Invoked during interactions or checks that require validation of the entity's taming item.<br>
455+
* Purpose: Returns the {@link String} representation of the items required to tame the given {@link LivingEntity}.<br>
456+
* When: Invoked during interactions or checks that require validation of the entity's taming items.<br>
452457
* Where: Used in taming mechanics or gameplay systems that enforce item-based taming.<br>
453-
* Additional Info: If no taming item is set for the entity, the method returns {@code null}.
458+
* Additional Info: If no taming items are set for the entity, the method returns an empty {@link ArrayList}.
454459
* </p>
455460
*
456-
* @param pEntity The {@link LivingEntity} whose taming item is to be retrieved.
461+
* @param pEntity The {@link LivingEntity} whose taming items are to be retrieved.
457462
* @return The taming item.
458463
* @author Kyradjis
459464
* @see #tamingItemMap
460465
* @see LivingEntity
461466
* @see String
467+
* @see List
468+
* @see ArrayList
469+
* @since 1.7.0
470+
*/
471+
public static List<Item> getTamingItems(LivingEntity pEntity) {
472+
return tamingItemMap.getOrDefault(pEntity, new ArrayList<>());
473+
}
474+
475+
/**
476+
* Retrieves the specific taming item associated with the specified entity.
477+
* <p>
478+
* Purpose: Returns the specific item required to tame the given {@link LivingEntity}.<br>
479+
* When: Invoked during interactions or checks that require validation of the entity's taming items.<br>
480+
* Where: Used in taming mechanics or gameplay systems that enforce item-based taming.<br>
481+
* Additional Info: If no taming items are set for the entity, the method returns {@code null}.
482+
* </p>
483+
*
484+
* @param pEntity The {@link LivingEntity} whose taming item is to be retrieved.
485+
* @param pItem The taming item.
486+
* @return The specific taming item required to tame the entity, or {@code null} if no item is set.
487+
* @author MeAlam
488+
* @see #tamingItemMap
489+
* @see LivingEntity
490+
* @see Item
491+
* @see List
492+
* @see ArrayList
493+
* @see Nullable
462494
* @since 1.7.0
463495
*/
464-
public static Item getTamingItem(LivingEntity pEntity) {
465-
return tamingItemMap.getOrDefault(pEntity, null);
496+
@Nullable
497+
public static Item getSpecificTamingItem(LivingEntity pEntity, Item pItem) {
498+
List<Item> items = tamingItemMap.getOrDefault(pEntity, new ArrayList<>());
499+
if (items.isEmpty()) {
500+
return null;
501+
}
502+
for (Item item : items) {
503+
if (item == pItem) {
504+
return item;
505+
}
506+
}
507+
return null;
466508
}
467509

468510
/**
469-
* Sets the taming item for the specified entity.
511+
* Sets the taming items for the specified entity.
470512
* <p>
471-
* Purpose: Updates the item required to tame the given {@link LivingEntity}.<br>
513+
* Purpose: Updates the items required to tame the given {@link LivingEntity}.<br>
472514
* When: Called during interactions or events that define or modify the taming requirements for an entity.<br>
473515
* Where: Used to manage taming mechanics based on specific items.<br>
474-
* Additional Info: The taming item is stored in the {@link #tamingItemMap}.
516+
* Additional Info: The taming items are stored in the {@link #tamingItemMap}.
475517
* </p>
476518
*
477-
* @param pEntity The {@link LivingEntity} whose taming item is to be set.
478-
* @param pItem The taming item.
519+
* @param pEntity The {@link LivingEntity} whose taming items are to be set.
520+
* @param pItem The taming items.
479521
* @author Kyradjis
480522
* @see #tamingItemMap
481523
* @see LivingEntity
482524
* @see String
525+
* @see Item
526+
* @see List
527+
* @see ArrayList
483528
* @since 1.7.0
484529
*/
485-
public static void setTamingItem(LivingEntity pEntity, Item pItem) {
530+
public static void setTamingItems(LivingEntity pEntity, List<Item> pItem) {
486531
tamingItemMap.put(pEntity, pItem);
487532
}
488533

534+
/**
535+
* Adds a taming item to the specified entity.
536+
* <p>
537+
* Purpose: Adds an item to the list of taming items required to tame the given {@link LivingEntity}.<br>
538+
* When: Called during interactions or events that add new taming items to an entity's requirements.<br>
539+
* Where: Used to manage taming mechanics based on specific items.<br>
540+
* Additional Info: The taming item is stored in the {@link #tamingItemMap}.
541+
* </p>
542+
*
543+
* @param pEntity The {@link LivingEntity} to add the taming item to.
544+
* @param pItem The taming item to add to the entity's requirements.
545+
* @author MeAlam
546+
* @see #tamingItemMap
547+
* @see LivingEntity
548+
* @see String
549+
* @see Item
550+
* @see List
551+
* @see ArrayList
552+
* @since 1.7.0
553+
*/
554+
public static void addTamingItem(LivingEntity pEntity, Item pItem) {
555+
List<Item> items = tamingItemMap.getOrDefault(pEntity, new ArrayList<>());
556+
items.add(pItem);
557+
tamingItemMap.put(pEntity, items);
558+
}
559+
489560
// Owner Following
490561

491562
/**

common/src/main/java/software/bluelib/interfaces/entity/IFlyingEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* <li>{@link #getFlyingSpeedMultiplier(LivingEntity)} - Retrieves the speed multiplier for the entity while flying.</li>
2525
* <li>{@link #setFlyingSpeedMultiplier(LivingEntity, double)} - Sets the speed multiplier for the entity while flying.</li>
2626
* <li>{@link #canFly(LivingEntity)} - Checks if the entity is capable of flight.</li>
27+
* <li>{@link #canFly(LivingEntity, boolean)} - Sets whether the entity can fly.</li>
2728
* <li>{@link #getFlightCooldown(LivingEntity)} - Retrieves the cooldown period between flights.</li>
2829
* <li>{@link #setFlightCooldown(LivingEntity, int)} - Sets the cooldown period between flights.</li>
2930
* <li>{@link #getAltitude(LivingEntity)} - Retrieves the current altitude of the entity.</li>

common/src/main/java/software/bluelib/interfaces/entity/ISwimmingEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
* <li>{@link #setSwimmingState(LivingEntity, boolean)} - Updates the swimming state of the entity.</li>
2424
* <li>{@link #getSwimmingSpeedMultiplier(LivingEntity)} - Retrieves the swimming speed multiplier of the entity.</li>
2525
* <li>{@link #setSwimmingSpeedMultiplier(LivingEntity, double)} - Updates the swimming speed multiplier of the entity.</li>
26+
* <li>{@link #canSwim(LivingEntity)} - Checks if the entity is capable of swimming.</li>
27+
* <li>{@link #canSwim(LivingEntity, boolean)} - Sets whether the entity can swim.</li>
2628
* <li>{@link #getSwimmingCooldown(LivingEntity)} - Retrieves the cooldown period for the entity's swimming behavior.</li>
2729
* <li>{@link #setSwimmingCooldown(LivingEntity, int)} - Updates the cooldown period for the entity's swimming behavior.</li>
2830
* <li>{@link #getDepth(LivingEntity)} - Retrieves the current depth (Y-coordinate) of the entity.</li>

common/src/main/java/software/bluelib/interfaces/entity/ITamableEntity.java

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) BlueLib. Licensed under the MIT License.
22
package software.bluelib.interfaces.entity;
33

4+
import java.util.List;
45
import java.util.UUID;
56
import net.minecraft.world.entity.LivingEntity;
67
import net.minecraft.world.entity.OwnableEntity;
@@ -19,9 +20,11 @@
1920
* Key Methods:
2021
* <ul>
2122
* <li>{@link #isTamed(OwnableEntity)} - Checks if the provided entity is tamed.</li>
22-
* <li>{@link #ownedBy(OwnableEntity, Player)} - Checks if a specific player owns the entity.</li>
23-
* <li>{@link #getTamingItem(LivingEntity)} - Retrieves the taming item required for the entity.</li>
24-
* <li>{@link #setTamingItem(LivingEntity, String)} - Sets the taming item for the entity.</li>
23+
* <li>{@link #isOwnedBy(OwnableEntity, Player)} - Checks if a specific player owns the entity.</li>
24+
* <li>{@link #getTamingItems(LivingEntity)} - Retrieves the taming items associated with the entity.</li>
25+
* <li>{@link #getSpecificTamingItem(LivingEntity, Item)} - Retrieves the specific taming item required for the entity.</li>
26+
* <li>{@link #setTamingItems(LivingEntity, List)} - Sets the taming items for the entity.</li>
27+
* <li>{@link #addTamingItem(LivingEntity, Item)} - Adds a taming item to the entity.</li>
2528
* <li>{@link #getFollowingStatus(LivingEntity)} - Checks if the entity is following its owner.</li>
2629
* <li>{@link #setFollowingStatus(LivingEntity, boolean)} - Sets the following status of the entity.</li>
2730
* <li>{@link #getLoyaltyLevel(LivingEntity)} - Retrieves the loyalty level of the entity.</li>
@@ -79,44 +82,91 @@ default boolean isOwnedBy(OwnableEntity pEntity, Player pPlayer) {
7982
}
8083

8184
/**
82-
* Retrieves the taming item associated with the specified entity.
85+
* Retrieves the taming items associated with the specified entity.
8386
* <p>
84-
* Purpose: Returns the item required to tame the {@link LivingEntity}.<br>
87+
* Purpose: Returns the items required to tame the {@link LivingEntity}.<br>
8588
* When: Called during interactions or checks related to taming mechanics.<br>
8689
* Where: Used in gameplay systems that validate or enforce taming requirements.<br>
8790
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
8891
* </p>
8992
*
90-
* @param pEntity The {@link LivingEntity} whose taming item is to be retrieved.
91-
* @return The name of the taming item as a {@link String}.
93+
* @param pEntity The {@link LivingEntity} whose taming items are to be retrieved.
94+
* @return The name of the taming items as a {@link String}.
9295
* @author Kyradjis
9396
* @see EntityStateManager
9497
* @see LivingEntity
98+
* @see Item
99+
* @see List
95100
* @since 1.7.0
96101
*/
97-
default Item getTamingItem(LivingEntity pEntity) {
98-
return EntityStateManager.getTamingItem(pEntity);
102+
default List<Item> getTamingItems(LivingEntity pEntity) {
103+
return EntityStateManager.getTamingItems(pEntity);
99104
}
100105

101106
/**
102-
* Sets the taming item for the specified entity.
107+
* Retrieves the specific taming item required for the entity.
103108
* <p>
104-
* Purpose: Updates the item required to tame the {@link LivingEntity}.<br>
109+
* Purpose: Returns the specific item required to tame the {@link LivingEntity}.<br>
110+
* When: Called during interactions or checks related to taming mechanics.<br>
111+
* Where: Used in gameplay systems that validate or enforce taming requirements.<br>
112+
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
113+
* </p>
114+
*
115+
* @param pEntity The {@link LivingEntity} whose specific taming item is to be retrieved.
116+
* @param pItem The name of the taming item as a {@link String}.
117+
* @return The specific taming item as an {@link Item} object.
118+
* @author MeAlam
119+
* @see EntityStateManager
120+
* @see LivingEntity
121+
* @see Item
122+
* @since 1.7.0
123+
*/
124+
default Item getSpecificTamingItem(LivingEntity pEntity, Item pItem) {
125+
return EntityStateManager.getSpecificTamingItem(pEntity, pItem);
126+
}
127+
128+
/**
129+
* Sets the taming items for the specified entity.
130+
* <p>
131+
* Purpose: Updates the items required to tame the {@link LivingEntity}.<br>
105132
* When: Invoked during setup or configuration of taming mechanics.<br>
106133
* Where: Used to modify the taming requirements for an entity.<br>
107134
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
108135
* </p>
109136
*
110-
* @param pEntity The {@link LivingEntity} whose taming item is to be set.
111-
* @param pItem The name of the taming item as a {@link String}.
137+
* @param pEntity The {@link LivingEntity} whose taming items are to be set.
138+
* @param pItem The name of the taming items as a {@link String}.
112139
* @author Kyradjis
113140
* @see EntityStateManager
114141
* @see LivingEntity
115142
* @see String
143+
* @see Item
144+
* @see List
145+
* @since 1.7.0
146+
*/
147+
default void setTamingItems(LivingEntity pEntity, List<Item> pItem) {
148+
EntityStateManager.setTamingItems(pEntity, pItem);
149+
}
150+
151+
/**
152+
* Adds a taming item to the specified entity.
153+
* <p>
154+
* Purpose: Adds an item to the list of items required to tame the {@link LivingEntity}.<br>
155+
* When: Invoked during setup or configuration of taming mechanics.<br>
156+
* Where: Used to modify the taming requirements for an entity.<br>
157+
* Additional Info: The library does not enforce the Taming Items; it is up to the developer to manage the Taming Items.<br>
158+
* </p>
159+
*
160+
* @param pEntity The {@link LivingEntity} to add the taming item to.
161+
* @param pItem The item to add to the list of taming items.
162+
* @author MeAlam
163+
* @see EntityStateManager
164+
* @see LivingEntity
165+
* @see Item
116166
* @since 1.7.0
117167
*/
118-
default void setTamingItem(LivingEntity pEntity, Item pItem) {
119-
EntityStateManager.setTamingItem(pEntity, pItem);
168+
default void addTamingItem(LivingEntity pEntity, Item pItem) {
169+
EntityStateManager.addTamingItem(pEntity, pItem);
120170
}
121171

122172
/**

common/src/main/java/software/bluelib/markdown/syntax/Color.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private void appendColor(String pColorText, List<Integer> pColors, Style pOrigin
235235
}
236236

237237
if (pColors.size() == 1) {
238-
int color = pColors.get(0);
238+
int color = pColors.getFirst();
239239
pResult.append(Component.literal(pColorText).setStyle(pOriginalStyle.withColor(TextColor.fromRgb(color))));
240240
return;
241241
}

common/src/main/java/software/bluelib/test/markdown/syntax/SpoilerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static void spoilerSpoiler(GameTestHelper pHelper) {
3838
}
3939

4040
public static void spoilerGradient(GameTestHelper pHelper) {
41-
MessageUtils.sendMessageToPlayers(pHelper, "§6 This is a spoiler/gradient test: §r ||spoiler|| -#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + +MessageUtils.getRandomHex() + "-(Gradient)");
41+
MessageUtils.sendMessageToPlayers(pHelper, "§6 This is a spoiler/gradient test: §r ||spoiler|| -#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + ",#" + MessageUtils.getRandomHex() + MessageUtils.getRandomHex() + "-(Gradient)");
4242
}
4343

4444
public static void spoilerCancel(GameTestHelper pHelper) {

common/src/main/java/software/bluelib/utils/math/RandomGenUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static int generateRandomInt(int pMin, int pMax) {
7575
public static double generateRandomDouble(double pMin, double pMax) {
7676
if (pMin > pMax) {
7777
Throwable throwable = new IllegalArgumentException("Minimum value must not be greater than maximum value.");
78-
BaseLogger.log(BaseLogLevel.WARNING, "Error generating random double", true);
78+
BaseLogger.log(BaseLogLevel.WARNING, "Error generating random double", throwable, true);
7979
return 0;
8080
}
8181
return pMin + Math.random() * (pMax - pMin);

0 commit comments

Comments
 (0)