Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package twilightforest.entity.ai.goal;

import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.Nullable;
import twilightforest.entity.IBreathAttacker;
import twilightforest.world.components.chunkgenerators.AbsoluteDifferenceFunction;

import java.awt.*;
import java.util.*;
import java.util.List;

public class BreathAttackGoal<T extends Mob & IBreathAttacker> extends Goal {

Expand Down Expand Up @@ -85,7 +92,7 @@ public void tick() {
// anyhoo, deal damage
Entity target = this.getHeadLookTarget();
if (target != null) {
this.entityHost.doBreathAttack(target);
this.entityHost.doBreathAttack((ServerLevel) target.level(), target);
this.entityHost.gameEvent(GameEvent.PROJECTILE_SHOOT);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package twilightforest.entity.ai.goal;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -97,7 +98,7 @@ public void tick() {
}
}
} else if (this.canBreak) {
if (!this.charger.level().isClientSide() && EventHooks.canEntityGrief(this.charger.level(), this.charger)) {
if (!this.charger.level().isClientSide() && EventHooks.canEntityGrief((ServerLevel) this.charger.level(), this.charger)) {

AABB bb = this.charger.getBoundingBox();
int minx = Mth.floor(bb.minX - 0.75D);
Expand Down Expand Up @@ -126,7 +127,7 @@ public void tick() {
if (this.charger.distanceToSqr(this.chargeTarget.getX(), this.chargeTarget.getBoundingBox().minY, this.chargeTarget.getZ()) <= rangeSq) {
if (!this.hasAttacked) {
this.hasAttacked = true;
this.charger.doHurtTarget(this.chargeTarget);
this.charger.doHurtTarget((ServerLevel) this.chargeTarget.level(), this.chargeTarget);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.phys.Vec3;
import twilightforest.tags.TFItemTags;
import twilightforest.entity.monster.Kobold;
import twilightforest.tags.TFItemTags;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package twilightforest.entity.ai.goal;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -155,14 +156,14 @@ private void doRayAttack() {

if (collisionBB.contains(srcVec)) {
if (0.0D < hitDist || hitDist == 0.0D) {
this.attacker.doBreathAttack(possibleEntity);
this.attacker.doBreathAttack((ServerLevel) possibleEntity.level(), possibleEntity);
hitDist = 0.0D;
}
} else if (interceptPos.isPresent()) {
double possibleDist = srcVec.distanceTo(interceptPos.get());

if (possibleDist < hitDist || hitDist == 0.0D) {
this.attacker.doBreathAttack(possibleEntity);
this.attacker.doBreathAttack((ServerLevel) possibleEntity.level(), possibleEntity);
hitDist = possibleDist;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package twilightforest.entity.ai.goal;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import twilightforest.entity.boss.SnowQueen;
Expand Down Expand Up @@ -114,7 +115,7 @@ public void tick() {
// drop!
this.dropTimer++;
if (this.attacker.getY() > this.dropY) {
this.attacker.destroyBlocksInAABB(this.attacker.getBoundingBox().inflate(1, 0.5F, 1));
this.attacker.destroyBlocksInAABB((ServerLevel) this.attacker.level(), this.attacker.getBoundingBox().inflate(1, 0.5F, 1));
}
}
}
Expand Down
22 changes: 18 additions & 4 deletions src/main/java/twilightforest/entity/ai/goal/LichMinionsGoal.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package twilightforest.entity.ai.goal;

import net.minecraft.core.BlockPos;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.dimension.DimensionType;
import net.minecraft.world.phys.Vec3;
import net.minecraft.server.level.ServerLevel;
import net.neoforged.neoforge.event.EventHooks;
import twilightforest.entity.boss.Lich;
import twilightforest.entity.monster.LichMinion;
import twilightforest.entity.projectile.LichBolt;
import twilightforest.entity.projectile.LichBomb;
import twilightforest.init.TFItems;
import twilightforest.init.TFSounds;
import twilightforest.world.components.layer.vanillalegacy.traits.DimensionOffset0Transformer;
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated

import java.util.EnumSet;

Expand Down Expand Up @@ -90,12 +95,17 @@ public void tick() {
if (this.lich.getAttackCooldown() == 0) {
if (dist < 2.0F) {
// melee attack
this.lich.doHurtTarget(targetedEntity);
if (this.lich.level() instanceof ServerLevel serverLevel) {
this.lich.doHurtTarget(serverLevel, targetedEntity);
}

this.lich.swing(InteractionHand.MAIN_HAND);
this.lich.setAttackCooldown(20);
} else if (dist < ATTACK_RANGE && this.lich.getSensing().hasLineOfSight(targetedEntity)) {
if (this.lich.getNextAttackType() == 0) this.lich.launchProjectileAt(new LichBolt(this.lich.level(), this.lich));
else this.lich.launchProjectileAt(new LichBomb(this.lich.level(), this.lich));
if (this.lich.level() instanceof ServerLevel serverLevel) {
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
if (this.lich.getNextAttackType() == 0) this.lich.launchProjectileAt(new LichBolt(serverLevel, this.lich));
else this.lich.launchProjectileAt(new LichBomb(serverLevel, this.lich));
}

this.lich.swing(InteractionHand.MAIN_HAND);
this.lich.setNextAttackType(this.lich.getRandom().nextBoolean() ? 0 : 1);
Expand Down Expand Up @@ -129,7 +139,11 @@ private void spawnMinionAt() {
// put a clone there
LichMinion minion = new LichMinion(this.lich.level(), this.lich);
minion.setPos(minionSpot.x(), minionSpot.y(), minionSpot.z());
EventHooks.finalizeMobSpawn(minion, accessor, this.lich.level().getCurrentDifficultyAt(BlockPos.containing(minionSpot)), EntitySpawnReason.MOB_SUMMONED, null);
Level level = this.lich.level();
long time = level.getOverworldClockTime();
int phase = (int)(time / 24000L % 8L + 8L) % 8;
DifficultyInstance difficultyInstance = new DifficultyInstance(level.getDifficulty(), level.getGameTime(), level.getChunkAt(BlockPos.containing(minionSpot)).getInhabitedTime(), DimensionType.MOON_BRIGHTNESS_PER_PHASE[phase]);
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated
EventHooks.finalizeMobSpawn(minion, accessor, difficultyInstance, EntitySpawnReason.MOB_SUMMONED, null);
this.lich.level().addFreshEntity(minion);

minion.setTarget(targetedEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.level.gameevent.GameEvent;
import twilightforest.tags.TFEntityTypeTags;
Comment thread
albazavr-alba marked this conversation as resolved.
import twilightforest.entity.boss.Lich;
import twilightforest.init.TFSounds;
import twilightforest.item.LifedrainScepterItem;
import twilightforest.tags.TFEntityTypeTags;
import twilightforest.util.entities.EntityUtil;

import java.util.EnumSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.goal.Goal;
Expand Down Expand Up @@ -71,12 +72,21 @@ public void tick() {
//the stunless charge has a higher chance to happen the lower the naga's health gets
Comment thread
albazavr-alba marked this conversation as resolved.
//difficulty is also factored in. The higher the difficulty the greater the chance
float healthRatio = 1.0F - (this.naga.getHealth() / (this.naga.getMaxHealth())) - 0.25F;
float chance = Mth.clamp(healthRatio + (this.naga.level().getCurrentDifficultyAt(this.naga.blockPosition()).getDifficulty().getId() * 0.05F), 0.0F, 0.5F);
float difficultyBonus;

if (this.naga.level() instanceof ServerLevel serverLevel) {
difficultyBonus = serverLevel.getCurrentDifficultyAt(this.naga.blockPosition()).getDifficulty().getId() * 0.05F;
} else {
difficultyBonus = this.naga.level().getDifficulty().getId() * 0.05F;
}

float chance = Mth.clamp(healthRatio + difficultyBonus, 0.0F, 0.5F);
float randChance = this.naga.getRandom().nextFloat() * 0.75F;
boolean stunless = randChance < chance;
this.naga.setStunlessCharging(stunless);
this.stunCalculated = true;
}

}
case CRUMBLE -> {
this.naga.getNavigation().stop();
Expand Down Expand Up @@ -176,7 +186,7 @@ private void doIntimidate() {
}

private void crumbleBelowTarget(int range) {
if (!EventHooks.canEntityGrief(this.naga.level(), this.naga) || naga.getTarget() == null) return;
if (!EventHooks.canEntityGrief((ServerLevel) this.naga.level(), this.naga) || naga.getTarget() == null) return;

int floor = (int) this.naga.getBoundingBox().minY;
int targetY = (int) this.naga.getTarget().getBoundingBox().minY;
Expand Down Expand Up @@ -247,4 +257,4 @@ public enum MovementState {
CIRCLE,
DAZE
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package twilightforest.entity.ai.goal;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.ai.goal.Goal;
Expand All @@ -20,7 +21,7 @@ public NagaSmashGoal(Naga naga) {

@Override
public boolean canUse() {
return this.naga.horizontalCollision && EventHooks.canEntityGrief(this.naga.level(), this.naga);
return this.naga.horizontalCollision && EventHooks.canEntityGrief((ServerLevel) this.naga.level(), this.naga);
}

@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.goal.Goal;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.Vec3;
import twilightforest.entity.boss.KnightPhantom;
import twilightforest.entity.projectile.ThrownWep;
import twilightforest.init.TFEntities;
Expand Down Expand Up @@ -56,7 +57,7 @@ private void launchAxeAt(Entity targetedEntity) {

projectile.shoot(tx, ty, tz, speed, 1.0F);

projectile.moveTo(sx, sy, sz, this.boss.getYRot(), this.boss.getXRot());
Comment thread
albazavr-alba marked this conversation as resolved.
projectile.snapTo(new Vec3(sx, sy, sz), this.boss.getXRot(), this.boss.getYRot());

this.boss.level().addFreshEntity(projectile);
}
Expand All @@ -76,11 +77,9 @@ private void launchPicks() {
double vy = 0;
double vz = Mth.sin(throwAngle);


ThrownWep projectile = new ThrownWep(TFEntities.THROWN_WEP.get(), this.boss.level(), this.boss).setDamage(3).setVelocity(0.015F).setItem(new ItemStack(TFItems.KNIGHTMETAL_PICKAXE.get()));


projectile.moveTo(sx, sy, sz, i * 45F, this.boss.getXRot());
Comment thread
albazavr-alba marked this conversation as resolved.
projectile.snapTo(new Vec3(sx, sy, sz), this.boss.getXRot(), i * 45);
Comment thread
albazavr-alba marked this conversation as resolved.
Outdated

float speed = 0.5F;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package twilightforest.entity.ai.goal;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.goal.Goal;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void tick() {
if (this.boss.getSensing().hasLineOfSight(target)) {
if (attackTime-- <= 0 && f1 < 2.0F && target.getBoundingBox().maxY > this.boss.getBoundingBox().minY && this.boss.getTarget().getBoundingBox().minY < this.boss.getBoundingBox().maxY) {
attackTime = 20;
this.boss.doHurtTarget(target);
this.boss.doHurtTarget((ServerLevel) target.level(), target);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.level.block.Block;
Expand All @@ -28,7 +29,7 @@ public RedcapLightTNTGoal(Redcap hostEntity, float speed) {

@Override
public boolean canUse() {
if (!EventHooks.canEntityGrief(this.redcap.level(), this.redcap)) {
if (!EventHooks.canEntityGrief((ServerLevel) this.redcap.level(), this.redcap)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package twilightforest.entity.ai.goal;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.block.Blocks;
Expand All @@ -21,7 +22,7 @@ public boolean canUse() {
&& !this.redcap.heldTNT.isEmpty()
&& this.redcap.distanceToSqr(attackTarget) < 25
&& !this.isTargetLookingAtMe(attackTarget)
&& EventHooks.canEntityGrief(this.redcap.level(), this.redcap)
&& EventHooks.canEntityGrief((ServerLevel) this.redcap.level(), this.redcap)
&& !this.isLitTNTNearby(8)
&& this.findBlockTNTNearby(5) == null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package twilightforest.entity.ai.goal;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected void checkAndPerformAttack(LivingEntity entity) {
if (this.attackTick <= 0 && this.mob.isWithinMeleeAttackRange(entity) && this.mob.hasLineOfSight(entity)) {
this.attackTick = this.adjustedTickDelay(20);
this.mob.swing(InteractionHand.MAIN_HAND);
this.mob.doHurtTarget(entity);
this.mob.doHurtTarget((ServerLevel) entity.level(), entity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import net.neoforged.neoforge.common.Tags;
import net.neoforged.neoforge.network.PacketDistributor;
import twilightforest.components.entity.YetiThrowAttachment;
import twilightforest.tags.TFEntityTypeTags;
import twilightforest.events.HostileMountEvents;
import twilightforest.init.TFDataAttachments;
import twilightforest.network.MovePlayerPacket;
import twilightforest.tags.TFEntityTypeTags;

public class ThrowRiderGoal extends MeleeAttackGoal {

Expand All @@ -38,7 +38,7 @@ public boolean canUse() {
@Override
public void start() {
this.throwTimer = 10 + this.mob.getRandom().nextInt(30); // Wait 0.5 to 2 seconds before we throw the target
this.timeout = 80 + this.mob.getRandom().nextInt(40); // Lets only try to chase for around 4-6 seconds
Comment thread
albazavr-alba marked this conversation as resolved.
this.timeout = 80 + this.mob.getRandom().nextInt(40); // Let's only try to chase for around 4-6 seconds
super.start();
}

Expand All @@ -65,7 +65,7 @@ protected void checkAndPerformAttack(LivingEntity victim) {
// Pluck them from the boat, minecart, donkey, or whatever
victim.stopRiding();

victim.startRiding(this.mob, true);
victim.startRiding(this.mob, true, false);
}
}
}
Expand All @@ -74,7 +74,7 @@ protected void checkAndPerformAttack(LivingEntity victim) {
@Override
public void stop() {
if (!this.mob.getPassengers().isEmpty()) {
Entity rider = this.mob.getPassengers().get(0);
Entity rider = this.mob.getPassengers().getFirst();
HostileMountEvents.hostileDismount(rider);

Vec3 throwVec = new Vec3(this.mob.getLookAngle().x() * 2.0D, 0.9, this.mob.getLookAngle().z() * 2.0D);
Expand Down
Loading
Loading