Skip to content

Commit b4a0c46

Browse files
committed
Fix some stuff
1 parent cd042e7 commit b4a0c46

File tree

3 files changed

+17
-106
lines changed

3 files changed

+17
-106
lines changed

src/main/java/me/twoleggedcat/bettercats/Main.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package me.twoleggedcat.bettercats;
22

33
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
4-
import me.twoleggedcat.bettercats.ai.PlayWithItemGoal;
4+
import me.twoleggedcat.bettercats.ai.CatPlayWithItemGoal;
55
import org.bukkit.Bukkit;
66
import org.bukkit.Material;
77
import org.bukkit.Sound;
@@ -42,8 +42,8 @@ public void onDisable() {
4242
public void onEntityLoad(EntityAddToWorldEvent e) {
4343
if (e.getEntityType() == EntityType.CAT) {
4444
Cat cat = (Cat) e.getEntity();
45-
Bukkit.getMobGoals().addGoal(cat, 8, new PlayWithItemGoal(this, cat, Material.SALMON));
46-
Bukkit.getMobGoals().addGoal(cat, 8, new PlayWithItemGoal(this, cat, Material.STRING));
45+
Bukkit.getMobGoals().addGoal(cat, 8, new CatPlayWithItemGoal(this, cat, Material.SALMON));
46+
Bukkit.getMobGoals().addGoal(cat, 8, new CatPlayWithItemGoal(this, cat, Material.STRING));
4747
}
4848
}
4949

src/main/java/me/twoleggedcat/bettercats/ai/PlayWithItemGoal.java renamed to src/main/java/me/twoleggedcat/bettercats/ai/CatPlayWithItemGoal.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.destroystokyo.paper.entity.ai.GoalType;
66
import org.bukkit.Material;
77
import org.bukkit.NamespacedKey;
8+
import org.bukkit.Sound;
89
import org.bukkit.entity.Cat;
910
import org.bukkit.entity.Item;
1011
import org.bukkit.plugin.Plugin;
@@ -15,21 +16,22 @@
1516
import java.util.EnumSet;
1617
import java.util.concurrent.ThreadLocalRandom;
1718

18-
public class PlayWithItemGoal implements Goal<Cat> {
19+
public class CatPlayWithItemGoal implements Goal<Cat> {
1920
private final GoalKey<Cat> key;
2021
private final Cat cat;
2122
private final Material targetType;
2223
private Item targetItem;
24+
private int ticksPlayed;
2325

24-
public PlayWithItemGoal(Plugin plugin, Cat cat, Material targetType) {
26+
public CatPlayWithItemGoal(Plugin plugin, Cat cat, Material targetType) {
2527
this.key = GoalKey.of(Cat.class, new NamespacedKey(plugin, "play_with_item"));
2628
this.cat = cat;
2729
this.targetType = targetType;
2830
}
2931

3032
@Override
3133
public boolean shouldActivate() {
32-
return (findItem() && Math.random() < 0.7);
34+
return findItem();
3335
}
3436

3537
@Override
@@ -54,7 +56,13 @@ public void tick() {
5456
return;
5557
cat.getPathfinder().moveTo(targetItem.getLocation(), 1.2);
5658
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+
}
5866
}
5967
}
6068

@@ -87,7 +95,8 @@ private boolean findItem() {
8795
if (targetItem == null || !targetItem.isValid()) {
8896
targetItem = getNearbyTargetItem();
8997
return targetItem != null;
90-
} else return true;
98+
} else
99+
return true;
91100
}
92101

93102
private int randomInt(int min, int max) {

src/main/java/me/twoleggedcat/bettercats/ai/PlayWithStringGoal.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)