Skip to content
This repository has been archived by the owner on Nov 24, 2024. It is now read-only.

Commit

Permalink
The final couple updates... The end is nigh...
Browse files Browse the repository at this point in the history
  • Loading branch information
Underplayer97 committed Nov 22, 2024
1 parent bdcd473 commit 24e0be9
Show file tree
Hide file tree
Showing 6 changed files with 423 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package net.underplayer97.ResonantEnemies.entity.ai;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.Goal;
import net.underplayer97.ResonantEnemies.entity.boss.AmalgamateEntity;
import net.underplayer97.ResonantEnemies.entity.boss.GrimsleyEntity;

import java.util.EnumSet;

public class AmalgamateAttackGoal extends Goal {
private final AmalgamateEntity entity;
private LivingEntity target;
private final double maxSearchDistance;

public AmalgamateAttackGoal(AmalgamateEntity entity, double maxSearchDistance) {
this.entity = entity;
this.maxSearchDistance = maxSearchDistance;
setControls(EnumSet.of(Control.MOVE, Control.LOOK));
}

@Override
public void start() {
entity.setPrimaryAttackCooldown(Math.max(entity.getPrimaryAttackCooldown(), 20));
target = entity.getTarget();
}

@Override
public boolean canStart() {
if (!entity.canTarget(entity.getTarget())){
entity.setTarget(null);
return false;
}

target = entity.getTarget();
return target != null && (entity.squaredDistanceTo(target) < maxSearchDistance);
}

@Override
public boolean shouldContinue() {
if (target == null) return false;
if (!target.isAlive()) return false;
return !entity.getNavigation().isIdle() || canStart();
}

@Override
public void stop() {
target = null;
entity.setTarget(null);
entity.getNavigation().stop();
}

@Override
public boolean shouldRunEveryTick() {
return false;
}

@Override
public void tick() {
if (target.isRemoved()) {
stop();
return;
}

entity.setSprinting(true);
entity.getLookControl().lookAt(target);
double attackDistance = entity.getWidth() * 2.0f * (entity.getWidth() * 2.0f);
double distance = entity.squaredDistanceTo(target);
entity.getNavigation().startMovingTo(target, 1);
boolean doesCollide = entity.doesCollide(entity.getBoundingBox(), target.getBoundingBox());

//if(entity.getSpecialAttackCooldown() == 0 && (distance > attackDistance * 4 || distance < attackDistance)) {
// entity.getLookControl().lookAt(target);
// //entity.shoot();
//}

if (doesCollide) entity.meleeAttack(target);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void stop() {

@Override
public boolean shouldRunEveryTick() {
return true;
return false;
}

@Override
Expand All @@ -65,13 +65,14 @@ public void tick() {
double attackDistance = entity.getWidth() * 2.0f * (entity.getWidth() * 2.0f);
double distance = entity.squaredDistanceTo(target);
entity.getNavigation().startMovingTo(target, 1);
boolean doesCollide = entity.doesCollide(entity.getBoundingBox(), target.getBoundingBox());

//if(entity.getSpecialAttackCooldown() == 0 && (distance > attackDistance * 4 || distance < attackDistance)) {
// entity.getLookControl().lookAt(target);
// //entity.shoot();
//}

if (entity.collides()) entity.meleeAttack(target);
if (doesCollide) entity.meleeAttack(target);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package net.underplayer97.ResonantEnemies.entity.ai;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.Goal;
import net.underplayer97.ResonantEnemies.entity.boss.ErebusEntity;
import net.underplayer97.ResonantEnemies.entity.boss.GrimsleyEntity;

import java.util.EnumSet;

public class GrimsleyAttackGoal extends Goal {
private final GrimsleyEntity entity;
private LivingEntity target;
private final double maxSearchDistance;

public GrimsleyAttackGoal(GrimsleyEntity entity, double maxSearchDistance) {
this.entity = entity;
this.maxSearchDistance = maxSearchDistance;
setControls(EnumSet.of(Control.MOVE, Control.LOOK));
}

@Override
public void start() {
entity.setPrimaryAttackCooldown(Math.max(entity.getPrimaryAttackCooldown(), 20));
target = entity.getTarget();
}

@Override
public boolean canStart() {
if (!entity.canTarget(entity.getTarget())){
entity.setTarget(null);
return false;
}

target = entity.getTarget();
return target != null && (entity.squaredDistanceTo(target) < maxSearchDistance);
}

@Override
public boolean shouldContinue() {
if (target == null) return false;
if (!target.isAlive()) return false;
return !entity.getNavigation().isIdle() || canStart();
}

@Override
public void stop() {
target = null;
entity.setTarget(null);
entity.getNavigation().stop();
}

@Override
public boolean shouldRunEveryTick() {
return false;
}

@Override
public void tick() {
if (target.isRemoved()) {
stop();
return;
}

entity.setSprinting(true);
entity.getLookControl().lookAt(target);
double attackDistance = entity.getWidth() * 2.0f * (entity.getWidth() * 2.0f);
double distance = entity.squaredDistanceTo(target);
entity.getNavigation().startMovingTo(target, 1);
boolean doesCollide = entity.doesCollide(entity.getBoundingBox(), target.getBoundingBox());

//if(entity.getSpecialAttackCooldown() == 0 && (distance > attackDistance * 4 || distance < attackDistance)) {
// entity.getLookControl().lookAt(target);
// //entity.shoot();
//}

if (doesCollide) entity.meleeAttack(target);

}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
package net.underplayer97.ResonantEnemies.entity.boss;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.ActiveTargetGoal;
import net.minecraft.entity.ai.goal.AttackGoal;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.math.Box;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.World;
import net.underplayer97.ResonantEnemies.entity.ai.AmalgamateAttackGoal;
import net.underplayer97.ResonantEnemies.entity.ai.ErebusAttackGoal;
import net.underplayer97.ResonantEnemies.entity.util.ModAttributes;
import software.bernie.geckolib3.core.IAnimatable;
import software.bernie.geckolib3.core.PlayState;
import software.bernie.geckolib3.core.builder.AnimationBuilder;
Expand All @@ -20,16 +31,34 @@
import software.bernie.geckolib3.core.manager.AnimationFactory;
import software.bernie.geckolib3.util.GeckoLibUtil;

import javax.annotation.Nullable;
import java.awt.*;

public class AmalgamateEntity extends AbstractBossEntity implements IAnimatable {

private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
public int ticksSinceDeath;
boolean isDead = false;
public int ticksSinceDeath;
private final AnimationFactory factory = GeckoLibUtil.createFactory(this);
private static final TrackedData<Integer> PRIMARY_ATTACK_COOLDOWN = DataTracker.registerData(AmalgamateEntity.class, TrackedDataHandlerRegistry.INTEGER);
private static final TrackedData<Integer> SPECIAL_ATTACK_COOLDOWN = DataTracker.registerData(AmalgamateEntity.class, TrackedDataHandlerRegistry.INTEGER);
public static final TrackedData<Integer> ATTACK_TYPE = DataTracker.registerData(AmalgamateEntity.class, TrackedDataHandlerRegistry.INTEGER);
public int primaryAttackDuration;
public int specialAttackDuration = 20;
boolean shoot;
boolean summoned;

public AmalgamateEntity(EntityType<? extends AbstractBossEntity> entityType, World world) {
super(entityType, world);
primaryAttackDuration = 10;

}

@Override
protected void initGoals() {
this.goalSelector.add(1, new AmalgamateAttackGoal(this, 250));

this.targetSelector.add(1, new ActiveTargetGoal<>(this, PlayerEntity.class, true));

}

public static DefaultAttributeContainer.Builder setAttributes() {
Expand All @@ -40,8 +69,89 @@ public static DefaultAttributeContainer.Builder setAttributes() {
.add(EntityAttributes.GENERIC_ATTACK_SPEED, 2.0f)
.add(EntityAttributes.GENERIC_FOLLOW_RANGE, 50.0f)
.add(EntityAttributes.GENERIC_ATTACK_KNOCKBACK, 4.0f)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.25f)
.add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 1.0f);
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.15f)
.add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 1.0f)
.add(ModAttributes.EREBUS_SPECIAL_ATTACK_COOLDOWN, 6.0f)
.add(ModAttributes.EREBUS_PRIMARY_ATTACK_COOLDOWN, 2.0f);
}


public void meleeAttack(LivingEntity target) {
setPrimaryAttackCooldown(getMaxPrimaryAttackCooldown());
setAttackType(random.nextInt(3)+1);
if (target != null) {
Box targetBox = target.getBoundingBox();
if (doesCollide(targetBox, getBoundingBox())) tryAttack(target);
}
}

public boolean doesCollide(Box box1, Box box2) {
VoxelShape voxelShape = VoxelShapes.cuboid(box1);
VoxelShape voxelShape2 = VoxelShapes.cuboid(box2);
return VoxelShapes.matchesAnywhere(voxelShape2, voxelShape, BooleanBiFunction.AND);
}


@Override
public boolean canTarget(@Nullable LivingEntity target) {
if (target == null) return false;
return super.canTarget(target);
}

@Override
protected void initDataTracker() {
super.initDataTracker();
dataTracker.startTracking(PRIMARY_ATTACK_COOLDOWN, 0);
dataTracker.startTracking(SPECIAL_ATTACK_COOLDOWN, 0);
dataTracker.startTracking(ATTACK_TYPE, 1);
}

public int getAttackType() {
return dataTracker.get(ATTACK_TYPE);
}

public void setAttackType(int state) {
dataTracker.set(ATTACK_TYPE,state);
}

public boolean isPrimaryAttack() {
return getPrimaryAttackCooldown() > getMaxPrimaryAttackCooldown() - primaryAttackDuration;
}

public int getPrimaryAttackCooldown() {
return dataTracker.get(PRIMARY_ATTACK_COOLDOWN);
}

public void setPrimaryAttackCooldown(int state) {
dataTracker.set(PRIMARY_ATTACK_COOLDOWN, state);
}

public int getMaxPrimaryAttackCooldown() {
return (int) (getAttributeValue(ModAttributes.EREBUS_PRIMARY_ATTACK_COOLDOWN));
}

public boolean isSpecialAttack() {
return getSpecialAttackCooldown() > getMaxSpecialAtackCooldown() - specialAttackDuration;
}

public int getSpecialAttackCooldown() {
return dataTracker.get(SPECIAL_ATTACK_COOLDOWN);
}

public void setSpecialAttackCooldown(int state) {
dataTracker.set(PRIMARY_ATTACK_COOLDOWN, state);
}

public int getMaxSpecialAtackCooldown() {
return (int) (getAttributeValue(ModAttributes.EREBUS_SPECIAL_ATTACK_COOLDOWN));
}

@Override
public void tick() {
super.tick();

if (getPrimaryAttackCooldown() > 0) setPrimaryAttackCooldown(getPrimaryAttackCooldown() - 1);
if (getSpecialAttackCooldown() > 0) setSpecialAttackCooldown(getSpecialAttackCooldown() - 1);
}

@Override
Expand Down Expand Up @@ -83,14 +193,6 @@ private <T extends IAnimatable> PlayState attackPredicate(AnimationEvent<T> even
return PlayState.STOP;
}

@Override
protected void initGoals() {
this.goalSelector.add(1, new AttackGoal(this));

this.targetSelector.add(1, new ActiveTargetGoal<>(this, PlayerEntity.class, true));

}

@Override
public void registerControllers(AnimationData animationData) {
animationData.addAnimationController(new AnimationController(this, "controller",
Expand Down
Loading

0 comments on commit 24e0be9

Please sign in to comment.