Skip to content
Open
Show file tree
Hide file tree
Changes from all 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,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.EntitySelector;
Expand All @@ -12,7 +13,9 @@
import org.jetbrains.annotations.Nullable;
import twilightforest.entity.IBreathAttacker;

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 +88,7 @@ public void tick() {
// anyhoo, deal damage
Entity target = this.getHeadLookTarget();
if (target != null) {
this.entityHost.doBreathAttack(target);
this.entityHost.doBreathAttack(getServerLevel(target), 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(getServerLevel(this.charger), 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(getServerLevel(this.chargeTarget), this.chargeTarget);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import twilightforest.entity.boss.SnowQueen;
Expand Down Expand Up @@ -155,14 +157,14 @@ private void doRayAttack() {

if (collisionBB.contains(srcVec)) {
if (0.0D < hitDist || hitDist == 0.0D) {
this.attacker.doBreathAttack(possibleEntity);
this.attacker.doBreathAttack(getServerLevel(possibleEntity), 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(getServerLevel(possibleEntity), possibleEntity);
hitDist = possibleDist;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package twilightforest.entity.ai.goal;

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;
import twilightforest.entity.boss.SnowQueen;
import twilightforest.entity.boss.SnowQueen.Phase;

Expand Down Expand Up @@ -114,7 +116,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(getServerLevel(this.attacker), this.attacker.getBoundingBox().inflate(1, 0.5F, 1));
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/twilightforest/entity/ai/goal/LichMinionsGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ServerLevelAccessor;
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;
Expand Down Expand Up @@ -88,14 +89,16 @@ public void tick() {
}

if (this.lich.getAttackCooldown() == 0) {
ServerLevel serverLevel = getServerLevel(this.lich);
if (dist < 2.0F) {
// melee attack
this.lich.doHurtTarget(targetedEntity);
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.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 +132,7 @@ 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);
EventHooks.finalizeMobSpawn(minion, accessor, accessor.getCurrentDifficultyAt(BlockPos.containing(minionSpot)), 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 @@ -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,13 @@ 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 chance = Mth.clamp(healthRatio + (getServerLevel(this.naga).getCurrentDifficultyAt(this.naga.blockPosition()).getDifficulty().getId() * 0.05F), 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 +178,7 @@ private void doIntimidate() {
}

private void crumbleBelowTarget(int range) {
if (!EventHooks.canEntityGrief(this.naga.level(), this.naga) || naga.getTarget() == null) return;
if (!EventHooks.canEntityGrief(getServerLevel(this.naga), 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 +249,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(getServerLevel(this.naga), 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.getYRot(), this.boss.getXRot());

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), i * 45, this.boss.getXRot());

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(getServerLevel(target), target);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

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.entity.ai.goal.Goal;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.gameevent.GameEvent;
Expand All @@ -28,7 +30,7 @@ public RedcapLightTNTGoal(Redcap hostEntity, float speed) {

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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.entity.ai.goal.Goal;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.gameevent.GameEvent;
import net.neoforged.neoforge.event.EventHooks;
Expand All @@ -21,7 +23,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(getServerLevel(this.redcap), 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(getServerLevel(entity), 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 Down Expand Up @@ -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
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.entity.ai.goal.Goal;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.Vec3;
Expand Down Expand Up @@ -72,11 +73,11 @@ public void tick() {
this.yeti.gameEvent(GameEvent.HIT_GROUND);
}

this.yeti.destroyBlocksInAABB(this.yeti.getBoundingBox().inflate(1, 2, 1).move(0, 2, 0));
this.yeti.destroyBlocksInAABB(getServerLevel(this.yeti), this.yeti.getBoundingBox().inflate(1, 2, 1).move(0, 2, 0));

// regular falling blocks, twice a second
if (this.currentDuration % 10 == 0) {
this.yeti.makeRandomBlockFall(30, 80);
this.yeti.makeRandomBlockFall(getServerLevel(this.yeti), 30, 80);
}

// blocks target players, one every second
Expand All @@ -86,11 +87,11 @@ public void tick() {

// blocks that fall close to the yeti, twice a second near the end of the rampage
if (this.currentDuration < 40 && this.currentDuration % 10 == 0) {
this.yeti.makeRandomBlockFall(15, 40);
this.yeti.makeRandomBlockFall(getServerLevel(this.yeti), 15, 40);
}

if (this.currentDuration % 20 == 0) {
IceBomb ice = new IceBomb(TFEntities.THROWN_ICE.get(), this.yeti.level(), this.yeti);
IceBomb ice = new IceBomb(TFEntities.THROWN_ICE.get(), this.yeti.level());
Vec3 vec = new Vec3(0.5F + this.yeti.getRandom().nextFloat() * 0.5F, 0.5F + this.yeti.getRandom().nextFloat() * 0.3F, 0).yRot(this.yeti.getRandom().nextFloat() * 360F);
ice.shoot(vec.x(), vec.y(), vec.z(), 0.4F + yeti.getRandom().nextFloat() * 0.3F, 0);
this.yeti.playSound(TFSounds.ALPHA_YETI_ICE.get(), 1.0F, 1.0F / (this.yeti.getRandom().nextFloat() * 0.4F + 0.8F));
Expand Down
Loading