Skip to content

Commit 78c9409

Browse files
committed
Fixed capuchin trying to hit you on creative mode, and slowed them down on throwing stuff. Aswell that added a little cooldown on Yacare attack
1 parent 37127df commit 78c9409

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

src/main/java/cybercat5555/faunus/Faunus.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public void onInitialize() {
3030
}
3131

3232
public void eventHandler() {
33-
EventManager.onAttack();
33+
EventManager.onAttackBlock();
34+
EventManager.onAttackEntity();
3435
}
3536

3637
public void configHandler() {

src/main/java/cybercat5555/faunus/common/EventManager.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cybercat5555.faunus.core.entity.livingEntity.YacareManEaterEntity;
44
import net.fabricmc.fabric.api.event.player.AttackBlockCallback;
5+
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
56
import net.minecraft.entity.player.PlayerEntity;
67
import net.minecraft.util.ActionResult;
78
import net.minecraft.util.Hand;
@@ -11,7 +12,7 @@
1112

1213
public class EventManager {
1314

14-
public static void onAttack() {
15+
public static void onAttackBlock() {
1516
AttackBlockCallback.EVENT.register((PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) -> {
1617
if (player.getVehicle() != null && player.getVehicle() instanceof YacareManEaterEntity && player.isAlive()) {
1718
player.attack(player.getVehicle());
@@ -20,4 +21,14 @@ public static void onAttack() {
2021
return ActionResult.PASS;
2122
});
2223
}
24+
25+
public static void onAttackEntity() {
26+
AttackEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> {
27+
if (player.getVehicle() != null && player.getVehicle() instanceof YacareManEaterEntity && player.isAlive()) {
28+
player.attack(player.getVehicle());
29+
}
30+
31+
return ActionResult.PASS;
32+
});
33+
}
2334
}

src/main/java/cybercat5555/faunus/core/entity/ai/goals/MeleeHungryGoal.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ public void tick() {
2525

2626
@Override
2727
protected void attack(LivingEntity target, double squaredDistance) {
28-
super.attack(target, squaredDistance);
28+
if (isCooledDown()) {
29+
super.attack(target, squaredDistance);
2930

30-
if (!target.isAlive()) {
31-
increaseHunger(-(MAX_HUNGER / 10));
31+
if (!target.isAlive()) {
32+
increaseHunger(-(MAX_HUNGER / 3));
33+
}
3234
}
3335
}
3436

@@ -42,9 +44,15 @@ public boolean canStart() {
4244
return false;
4345
}
4446

47+
4548
return super.canStart();
4649
}
4750

51+
@Override
52+
public void stop() {
53+
super.stop();
54+
}
55+
4856
@Override
4957
public boolean shouldContinue() {
5058
return doesHaveHunger() && super.shouldContinue();

src/main/java/cybercat5555/faunus/core/entity/livingEntity/CapuchinEntity.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected void initGoals() {
8080
this.goalSelector.add(0, new AnimalMateGoal(this, 1.0D));
8181
this.goalSelector.add(1, new RunAwayCapuchinGoal(this, 1.5));
8282
this.goalSelector.add(2, new LookAtEntityGoal(this, PlayerEntity.class, 8.0f));
83-
this.goalSelector.add(2, new MeleeCapuchinGoal(this, 1.5, false));
83+
this.goalSelector.add(2, new AttackCapuchinGoal(this, 1.5, false));
8484
this.goalSelector.add(3, new HangTreeGoal(this, 1.0));
8585
this.goalSelector.add(4, new FollowOwnerGoal(this, 1.0, 5.0f, 1.0f, true));
8686

@@ -138,16 +138,17 @@ protected <E extends CapuchinEntity> PlayState movementAnimController(final Anim
138138

139139
protected <E extends CapuchinEntity> PlayState attackAnimController(final AnimationState<E> event) {
140140
boolean isAlreadyPlayingAttackAnim = event.getController().getCurrentRawAnimation() == ATTACK_LEFT_ANIM || event.getController().getCurrentRawAnimation() == ATTACK_RIGHT_ANIM;
141+
boolean isAttacking = event.getLimbSwingAmount() > 0.001f;
141142

142-
if (isAttacking()) {
143+
if (isAttacking) {
143144
if (isAlreadyPlayingAttackAnim) {
144145
return PlayState.CONTINUE;
145146
}
146147

147148
event.setAnimation(Math.random() < 0.5 ? ATTACK_LEFT_ANIM : ATTACK_RIGHT_ANIM);
148149
}
149150

150-
return PlayState.CONTINUE;
151+
return PlayState.STOP;
151152
}
152153

153154
@Nullable
@@ -307,18 +308,19 @@ public PassiveEntity createChild(ServerWorld world, PassiveEntity entity) {
307308
return EntityRegistry.CAPUCHIN.create(world);
308309
}
309310

310-
static class MeleeCapuchinGoal extends MeleeAttackGoal {
311+
static class AttackCapuchinGoal extends MeleeAttackGoal {
311312

312-
public MeleeCapuchinGoal(CapuchinEntity mob, double speed, boolean pauseWhenMobIdle) {
313+
public AttackCapuchinGoal(CapuchinEntity mob, double speed, boolean pauseWhenMobIdle) {
313314
super(mob, speed, pauseWhenMobIdle);
314315
}
315316

316317
@Override
317318
protected void attack(LivingEntity target, double squaredDistance) {
318319
if (this.mob.isInAttackRange(target)) {
319320
this.mob.tryAttack(target);
320-
} else {
321+
} else if(isCooledDown()) {
321322
throwCocoaBean(target);
323+
resetCooldown();
322324
}
323325
}
324326

@@ -347,6 +349,8 @@ public boolean canStart() {
347349
if (shouldAttack && this.mob.getTarget() != null) {
348350
attack(this.mob.getTarget(), 4);
349351
this.mob.setAttacking(true);
352+
353+
return !(this.mob.getTarget() instanceof PlayerEntity player) || !player.isCreative();
350354
} else {
351355
this.mob.setAttacking(false);
352356
}
@@ -355,6 +359,12 @@ public boolean canStart() {
355359
return false;
356360
}
357361

362+
@Override
363+
public void stop() {
364+
this.mob.setAttacking(false);
365+
super.stop();
366+
}
367+
358368
@Override
359369
public boolean shouldContinue() {
360370
if(this.mob.getTarget() instanceof PlayerEntity player && !player.isCreative()) return false;

0 commit comments

Comments
 (0)