1
1
// Copyright (c) BlueLib. Licensed under the MIT License.
2
2
package software .bluelib .entity ;
3
3
4
+ import java .util .ArrayList ;
4
5
import java .util .HashMap ;
6
+ import java .util .List ;
5
7
import java .util .Map ;
6
8
import net .minecraft .world .entity .LivingEntity ;
7
9
import net .minecraft .world .item .Item ;
10
+ import org .jetbrains .annotations .Nullable ;
8
11
import software .bluelib .interfaces .entity .ITamableEntity ;
9
12
10
13
/**
27
30
* <li>{@link #setSwimmingState(LivingEntity, boolean)} - Updates the swimming state of the entity.</li>
28
31
* <li>{@link #getSwimmingCooldown(LivingEntity)} - Retrieves the swimming cooldown period of the entity.</li>
29
32
* <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>
32
37
* <li>{@link #getFollowingState(LivingEntity)} - Retrieves the following state of the entity.</li>
33
38
* <li>{@link #setFollowingState(LivingEntity, boolean)} - Updates the following state of the entity.</li>
34
39
* <li>{@link #getLoyaltyLevel(LivingEntity)} - Retrieves the loyalty level of the entity.</li>
@@ -433,7 +438,7 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) {
433
438
* A map to store the taming item associated with entities.
434
439
* <p>
435
440
* 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>
437
442
* Where: Used to manage and validate taming mechanics based on specific items.<br>
438
443
* Additional Info: The keys are {@link LivingEntity} instances, and the values are the taming items.
439
444
* </p>
@@ -442,50 +447,116 @@ public static void setSwimmingCooldown(LivingEntity pEntity, int pCooldown) {
442
447
* @see String
443
448
* @since 1.7.0
444
449
*/
445
- private static final Map <LivingEntity , Item > tamingItemMap = new HashMap <>();
450
+ private static final Map <LivingEntity , List < Item > > tamingItemMap = new HashMap <>();
446
451
447
452
/**
448
- * Retrieves the taming item associated with the specified entity.
453
+ * Retrieves the taming items associated with the specified entity.
449
454
* <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>
452
457
* 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 }.
454
459
* </p>
455
460
*
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.
457
462
* @return The taming item.
458
463
* @author Kyradjis
459
464
* @see #tamingItemMap
460
465
* @see LivingEntity
461
466
* @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
462
494
* @since 1.7.0
463
495
*/
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 ;
466
508
}
467
509
468
510
/**
469
- * Sets the taming item for the specified entity.
511
+ * Sets the taming items for the specified entity.
470
512
* <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>
472
514
* When: Called during interactions or events that define or modify the taming requirements for an entity.<br>
473
515
* 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}.
475
517
* </p>
476
518
*
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 .
479
521
* @author Kyradjis
480
522
* @see #tamingItemMap
481
523
* @see LivingEntity
482
524
* @see String
525
+ * @see Item
526
+ * @see List
527
+ * @see ArrayList
483
528
* @since 1.7.0
484
529
*/
485
- public static void setTamingItem (LivingEntity pEntity , Item pItem ) {
530
+ public static void setTamingItems (LivingEntity pEntity , List < Item > pItem ) {
486
531
tamingItemMap .put (pEntity , pItem );
487
532
}
488
533
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
+
489
560
// Owner Following
490
561
491
562
/**
0 commit comments