Skip to content

Commit

Permalink
fixed grim reaper
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed May 16, 2024
1 parent c2d8e2f commit ce52ddc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 40 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Merged [Inworld integration](https://github.com/Luke100000/minecraft-comes-alive/wiki/GPT3-based-conversations) branch (thanks CSCMe!)
* Fixed incompatibility with Cobblemon (thanks Apion!)
* Fixed AI issues with Grim Reapers, causing him to go much higher than intended
* Fixed issues when using Arabic numerals
* Fixed crashes when using TTS
* Fixed Inn spamming adventurers
Expand Down
54 changes: 19 additions & 35 deletions common/src/main/java/net/mca/entity/GrimReaperEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.mob.PathAwareEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ArrowEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
Expand All @@ -44,7 +44,7 @@ public class GrimReaperEntity extends PathAwareEntity implements CTrackedEntity<

public static final CDataManager<GrimReaperEntity> DATA = new CDataManager.Builder<>(GrimReaperEntity.class).addAll(ATTACK_STAGE).build();

private final ServerBossBar bossInfo = (ServerBossBar)new ServerBossBar(getDisplayName(), BossBar.Color.PURPLE, BossBar.Style.PROGRESS).setDarkenSky(true);
private final ServerBossBar bossInfo = (ServerBossBar) new ServerBossBar(getDisplayName(), BossBar.Color.PURPLE, BossBar.Style.PROGRESS).setDarkenSky(true);

public GrimReaperEntity(EntityType<? extends GrimReaperEntity> type, World world) {
super(type, world);
Expand Down Expand Up @@ -89,11 +89,10 @@ public EntityGroup getGroup() {
protected void initGoals() {
this.targetSelector.add(1, new GrimReaperTargetGoal(this));

this.goalSelector.add(0, new LookAtEntityGoal(this, PlayerEntity.class, 24, 1.0f));
this.goalSelector.add(1, new GrimReaperRestGoal(this));
this.goalSelector.add(2, new GrimReaperMeleeGoal(this));
this.goalSelector.add(3, new GrimReaperIdleGoal(this, 1));
this.goalSelector.add(4, new LookAtEntityGoal(this, PlayerEntity.class, 8));
this.goalSelector.add(5, new LookAroundGoal(this));
}

@Override
Expand Down Expand Up @@ -166,46 +165,37 @@ public boolean damage(DamageSource source, float damage) {
return false;
}

Entity attacker = source.getSource();
Entity entity = source.getSource();
Entity attacker = source.getAttacker();

// Ignore damage when blocking, and teleport behind the attacker when attacked
if (!getWorld().isClient && this.getAttackState() == ReaperAttackState.BLOCK && attacker != null) {
// Ignore damage when blocking, and randomly teleport around
if (this.getAttackState() == ReaperAttackState.BLOCK && attacker != null) {
playSound(SoundsMCA.REAPER_BLOCK.get(), 1.0F, 1.0F);
return false;
}

double deltaX = this.getX() - attacker.getX();
double deltaZ = this.getZ() - attacker.getZ();
// Teleport next to the player who fired an arrow
if (entity instanceof ProjectileEntity && getAttackState() != ReaperAttackState.REST && attacker != null && random.nextBoolean()) {
double newX = attacker.getX() + (random.nextFloat() >= 0.50F ? 4 : -4);
double newZ = attacker.getZ() + (random.nextFloat() >= 0.50F ? 4 : -4);

playSound(SoundsMCA.REAPER_BLOCK.get(), 1.0F, 1.0F);
requestTeleport(attacker.getX() - (deltaX * 2), attacker.getY() + 2, this.getZ() - (deltaZ * 2));
requestTeleport(newX, attacker.getY(), newZ);
return false;
}

// Randomly portal behind the player who just attacked.
if (!getWorld().isClient && random.nextFloat() >= 0.30F && attacker != null) {
double deltaX = this.getX() - attacker.getX();
double deltaZ = this.getZ() - attacker.getZ();
double distance = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
double length = Math.max(5.0, distance) / distance * 0.95;

requestTeleport(attacker.getX() - (deltaX * 2), attacker.getY() + 2, this.getZ() - (deltaZ * 2));
}

// Teleport behind the player who fired an arrow and ignore its damage.
if (attacker instanceof ArrowEntity arrow) {
if (getAttackState() != ReaperAttackState.REST) {
Entity owner = arrow.getOwner();

if (owner != null) {
double newX = owner.getX() + (random.nextFloat() >= 0.50F ? 2 : -2);
double newZ = owner.getZ() + (random.nextFloat() >= 0.50F ? 2 : -2);

requestTeleport(newX, owner.getY(), newZ);
}
arrow.discard();
}
return false;
requestTeleport(attacker.getX() - deltaX * length, attacker.getY() + 1.5, attacker.getZ() - deltaZ * length);
}

// 25% damage when healing
if (this.getAttackState() == ReaperAttackState.REST) {
damage *= 0.25;
damage *= 0.25f;
}

return super.damage(source, damage);
Expand Down Expand Up @@ -243,12 +233,6 @@ public void tick() {
return;
}

// look at the player. Always.
PlayerEntity player = getWorld().getClosestPlayer(this, 10.D);
if (player != null) {
getLookControl().lookAt(player.getX(), player.getEyeY(), player.getZ());
}

LivingEntity entityToAttack = this.getTarget();

// See if our entity to attack has died at any point.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected Vec3d getPosition() {
return reaper.getTarget().getPos();
}

return NoWaterTargeting.find(reaper, 8, 6, -2, Vec3d.ofBottomCenter(reaper.getBlockPos()), 1);
return NoWaterTargeting.find(reaper, 8, 6, -1, Vec3d.ofBottomCenter(reaper.getBlockPos()), 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.util.math.Vec3d;

public class GrimReaperMeleeGoal extends Goal {
private final static int COOLDOWN = 150;
private static final int COOLDOWN = 150;
private final GrimReaperEntity reaper;

private int blockDuration;
Expand Down Expand Up @@ -46,7 +46,7 @@ public boolean canStop() {

@Override
public void start() {
blockDuration = 60;
blockDuration = 50;
attackDuration = 100;
retreatDuration = 20;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
import net.minecraft.util.math.Vec3d;

public class GrimReaperRestGoal extends Goal {
private final static int COOLDOWN = 1000;
private static final int COOLDOWN = 1000;
private final GrimReaperEntity reaper;
private int lastHeal = -COOLDOWN;
private int healingCount = 0;
private static final int MAX_HEALING_COUNT = 5;
private static final int MAX_HEALING_TIME = 500;
private static final int MAX_HEALING_TIME = 400;
private int healingTime;

public GrimReaperRestGoal(GrimReaperEntity reaper) {
Expand Down

0 comments on commit ce52ddc

Please sign in to comment.