Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
- dragons can break blocks in water (avoids issues where they get stuck even in caves)
- player are now again properly targeted
- even if the dragon is sleeping if a player gets too close it will attack (otherwise the dragon will stop targeting the player in some cases)
- add bandaid fix to not get stuck when riding dragon / target of shaking attack
- reduce healing
  • Loading branch information
SiverDX authored and TheBv committed Dec 26, 2023
1 parent 2e70e2e commit af22026
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.pathfinder.BlockPathTypes;
import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.LootTable;
Expand Down Expand Up @@ -311,9 +310,11 @@ protected void registerGoals() {
this.targetSelector.addGoal(3, new HurtByTargetGoal(this));
this.targetSelector.addGoal(4, new DragonAITargetItems<>(this, 60, false, false, true));
this.targetSelector.addGoal(5, new DragonAITargetNonTamed<>(this, LivingEntity.class, false, (Predicate<LivingEntity>) entity -> {
boolean skip = entity instanceof Player player ? player.isCreative() : getRandom().nextInt(100) < getHunger();
if (entity instanceof Player player) {
return !player.isCreative();
}

if (!skip) {
if (getRandom().nextInt(100) > getHunger()) {
return entity.getType() != getType() && DragonUtils.canHostilesTarget(entity) && DragonUtils.isAlive(entity) && shouldTarget(entity);
}

Expand Down Expand Up @@ -1499,7 +1500,7 @@ public void breakBlocks(boolean force) {
}

if (doBreak) {
if ((force || !this.isInWater()) && ForgeEventFactory.getMobGriefingEvent(this.level(), this)) {
if (ForgeEventFactory.getMobGriefingEvent(this.level(), this)) {
if (DragonUtils.canGrief(this)) {
// TODO :: make `force` ignore the dragon stage?
if (!isModelDead() && this.getDragonStage() >= 3 && (this.canMove() || this.getControllingPassenger() != null)) {
Expand Down Expand Up @@ -1622,35 +1623,37 @@ private float bob(float speed, float degree, boolean bounce, float f, float f1)
return bob * this.getRenderSize() / 3;
}

protected void updatePreyInMouth(Entity prey) {
protected void updatePreyInMouth(final Entity prey) {
if (this.getAnimation() != ANIMATION_SHAKEPREY) {
this.setAnimation(ANIMATION_SHAKEPREY);
}

if (this.getAnimation() == ANIMATION_SHAKEPREY && this.getAnimationTick() > 55 && prey != null) {
float baseDamage = (float) this.getAttribute(Attributes.ATTACK_DAMAGE).getValue();
float damage = baseDamage * 2;
boolean didDamage = prey.hurt(this.level().damageSources().mobAttack(this), damage);

if (didDamage && IafConfig.canDragonsHealFromBiting) {
heal(damage);
heal(damage * 0.5f);
}

if (!(prey instanceof Player)) {
setHunger(getHunger() + 1);
}

prey.stopRiding();
} else {
yBodyRot = getYRot();
final float modTick_0 = this.getAnimationTick() - 25;
final float modTick_1 = this.getAnimationTick() > 25 && this.getAnimationTick() < 55 ? 8 * Mth.clamp(Mth.sin((float) (Math.PI + modTick_0 * 0.25)), -0.8F, 0.8F) : 0;
final float modTick_2 = this.getAnimationTick() > 30 ? 10 : Math.max(0, this.getAnimationTick() - 20);
final float radius = 0.75F * (0.6F * getRenderSize() / 3) * -3;
final float angle = (0.01745329251F * this.yBodyRot) + 3.15F + (modTick_1 * 2F) * 0.015F;
final double extraX = radius * Mth.sin((float) (Math.PI + angle));
final double extraZ = radius * Mth.cos(angle);
final double extraY = modTick_2 == 0 ? 0 : 0.035F * ((getRenderSize() / 3) + (modTick_2 * 0.5 * (getRenderSize() / 3)));
prey.setPos(this.getX() + extraX, this.getY() + extraY, this.getZ() + extraZ);
}
yBodyRot = getYRot();
final float modTick_0 = this.getAnimationTick() - 25;
final float modTick_1 = this.getAnimationTick() > 25 && this.getAnimationTick() < 55 ? 8 * Mth.clamp(Mth.sin((float) (Math.PI + modTick_0 * 0.25)), -0.8F, 0.8F) : 0;
final float modTick_2 = this.getAnimationTick() > 30 ? 10 : Math.max(0, this.getAnimationTick() - 20);
final float radius = 0.75F * (0.6F * getRenderSize() / 3) * -3;
final float angle = (0.01745329251F * this.yBodyRot) + 3.15F + (modTick_1 * 2F) * 0.015F;
final double extraX = radius * Mth.sin((float) (Math.PI + angle));
final double extraZ = radius * Mth.cos(angle);
final double extraY = modTick_2 == 0 ? 0 : 0.035F * ((getRenderSize() / 3) + (modTick_2 * 0.5 * (getRenderSize() / 3)));
prey.setPos(this.getX() + extraX, this.getY() + extraY, this.getZ() + extraZ);
}

public int getDragonStage() {
Expand Down Expand Up @@ -2374,7 +2377,7 @@ public void updateRider() {
boolean didDamage = logic.attackTarget(target, rider, damage);

if (didDamage && IafConfig.canDragonsHealFromBiting) {
heal(damage);
heal(damage * 0.1f);
}
}
}
Expand Down Expand Up @@ -2704,8 +2707,12 @@ public Vec3 getRiderPosition() {
}

@Override
public @NotNull Vec3 getDismountLocationForPassenger(LivingEntity pPassenger) {
return this.getRiderPosition().add(0, pPassenger.getBbHeight(), 0);
public @NotNull Vec3 getDismountLocationForPassenger(final LivingEntity passenger) {
if (passenger.isInWall()) {
return this.position().add(0, 1, 0);
}

return this.getRiderPosition().add(0, passenger.getBbHeight(), 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;

Expand All @@ -22,10 +23,26 @@ public DragonAITargetNonTamed(EntityDragonBase entityIn, Class<T> classTarget, b

@Override
public boolean canUse() {
if (!dragon.isTame() && dragon.lookingForRoostAIFlag) {
if (dragon.isTame()) {
return false;
}
return !dragon.isTame() && !dragon.isSleeping() && super.canUse();

if (dragon.lookingForRoostAIFlag) {
return false;
}

boolean canUse = super.canUse();
boolean isSleeping = dragon.isSleeping();

if (canUse) {
if (isSleeping && target instanceof Player) {
return dragon.distanceToSqr(target) <= 16;
}

return !isSleeping;
}

return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ protected void generateRoostPile(final WorldGenLevel level, final RandomSource r
}
}

protected double getCircularArea(int radius, int height) {
double area = (radius + height + radius) * 0.333F + 0.5F;
return Mth.floor(area * area);
}

protected double getCircularArea(int radius) {
double area = (radius + radius) * 0.333F + 0.5F;
return Mth.floor(area * area);
}

protected BlockPos getSurfacePosition(final WorldGenLevel level, final BlockPos position) {
return level.getHeightmapPos(Heightmap.Types.WORLD_SURFACE_WG, position);
}

protected BlockState transform(final Block block) {
return transform(block.defaultBlockState());
}

private void generateDecoration(@NotNull final FeaturePlaceContext<NoneFeatureConfiguration> context, int radius, boolean isMale) {
int height = (radius / 5);
double circularArea = getCircularArea(radius, height);
Expand Down Expand Up @@ -225,24 +243,6 @@ private void spawnDragon(@NotNull final FeaturePlaceContext<NoneFeatureConfigura
context.level().addFreshEntity(dragon);
}

protected double getCircularArea(int radius, int height) {
double area = (radius + height + radius) * 0.333F + 0.5F;
return Mth.floor(area * area);
}

protected double getCircularArea(int radius) {
double area = (radius + radius) * 0.333F + 0.5F;
return Mth.floor(area * area);
}

protected BlockPos getSurfacePosition(final WorldGenLevel level, final BlockPos position) {
return level.getHeightmapPos(Heightmap.Types.WORLD_SURFACE_WG, position);
}

protected BlockState transform(final Block block) {
return transform(block.defaultBlockState());
}

protected abstract EntityType<? extends EntityDragonBase> getDragonType();

protected abstract ResourceLocation getRoostLootTable();
Expand Down

0 comments on commit af22026

Please sign in to comment.