5
5
import com .destroystokyo .paper .entity .ai .GoalType ;
6
6
import org .bukkit .Material ;
7
7
import org .bukkit .NamespacedKey ;
8
+ import org .bukkit .Sound ;
8
9
import org .bukkit .entity .Cat ;
9
10
import org .bukkit .entity .Item ;
10
11
import org .bukkit .plugin .Plugin ;
15
16
import java .util .EnumSet ;
16
17
import java .util .concurrent .ThreadLocalRandom ;
17
18
18
- public class PlayWithItemGoal implements Goal <Cat > {
19
+ public class CatPlayWithItemGoal implements Goal <Cat > {
19
20
private final GoalKey <Cat > key ;
20
21
private final Cat cat ;
21
22
private final Material targetType ;
22
23
private Item targetItem ;
24
+ private int ticksPlayed ;
23
25
24
- public PlayWithItemGoal (Plugin plugin , Cat cat , Material targetType ) {
26
+ public CatPlayWithItemGoal (Plugin plugin , Cat cat , Material targetType ) {
25
27
this .key = GoalKey .of (Cat .class , new NamespacedKey (plugin , "play_with_item" ));
26
28
this .cat = cat ;
27
29
this .targetType = targetType ;
28
30
}
29
31
30
32
@ Override
31
33
public boolean shouldActivate () {
32
- return ( findItem () && Math . random () < 0.7 );
34
+ return findItem ();
33
35
}
34
36
35
37
@ Override
@@ -54,7 +56,13 @@ public void tick() {
54
56
return ;
55
57
cat .getPathfinder ().moveTo (targetItem .getLocation (), 1.2 );
56
58
if (targetItem .getLocation ().distanceSquared (cat .getLocation ()) < 1 ) {
57
- targetItem .setVelocity (new Vector (randomDouble (-0.25 , 0.25 ), randomDouble (-0.25 , 0.25 ), randomDouble (-0.25 , 0.25 )));
59
+ if (ticksPlayed > 600 && targetItem .getItemStack ().getType ().isEdible ()) {
60
+ targetItem .remove ();
61
+ cat .getWorld ().playSound (cat .getLocation (), Sound .ENTITY_CAT_AMBIENT , 1 , 1 );
62
+ } else {
63
+ targetItem .setVelocity (new Vector (randomDouble (-0.25 , 0.25 ), randomDouble (-0.25 , 0.25 ), randomDouble (-0.25 , 0.25 )));
64
+ ticksPlayed ++;
65
+ }
58
66
}
59
67
}
60
68
@@ -87,7 +95,8 @@ private boolean findItem() {
87
95
if (targetItem == null || !targetItem .isValid ()) {
88
96
targetItem = getNearbyTargetItem ();
89
97
return targetItem != null ;
90
- } else return true ;
98
+ } else
99
+ return true ;
91
100
}
92
101
93
102
private int randomInt (int min , int max ) {
0 commit comments