CerbonXD

Untitled

Nov 21st, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.15 KB | Source Code | 0 0
  1. package com.cerbon.bosses_of_mass_destruction.entity.custom.lich;
  2.  
  3. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.general.data.HistoricalData;
  4. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.general.event.TimedEvent;
  5. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.static_utilities.MathUtils;
  6. import com.cerbon.bosses_of_mass_destruction.api.maelstrom.static_utilities.MobUtils;
  7. import com.cerbon.bosses_of_mass_destruction.config.mob.LichConfig;
  8. import com.cerbon.bosses_of_mass_destruction.entity.ai.action.IActionWithCooldown;
  9. import com.cerbon.bosses_of_mass_destruction.entity.ai.goals.CompositeGoal;
  10. import com.cerbon.bosses_of_mass_destruction.entity.ai.goals.FindTargetGoal;
  11. import com.cerbon.bosses_of_mass_destruction.entity.custom.gauntlet.AnimationHolder;
  12. import com.cerbon.bosses_of_mass_destruction.entity.custom.void_blossom.CappedHeal;
  13. import com.cerbon.bosses_of_mass_destruction.entity.damage.CompositeDamageHandler;
  14. import com.cerbon.bosses_of_mass_destruction.entity.damage.DamageMemory;
  15. import com.cerbon.bosses_of_mass_destruction.entity.damage.DamagedAttackerNotSeen;
  16. import com.cerbon.bosses_of_mass_destruction.entity.damage.StagedDamageHandler;
  17. import com.cerbon.bosses_of_mass_destruction.entity.util.BaseEntity;
  18. import com.cerbon.bosses_of_mass_destruction.entity.util.CompositeEntityEventHandler;
  19. import com.cerbon.bosses_of_mass_destruction.entity.util.CompositeEntityTick;
  20. import com.cerbon.bosses_of_mass_destruction.sound.BMDSounds;
  21. import com.cerbon.bosses_of_mass_destruction.util.AnimationUtils;
  22. import com.cerbon.bosses_of_mass_destruction.util.BMDUtils;
  23. import com.cerbon.bosses_of_mass_destruction.util.VanillaCopies;
  24. import net.minecraft.core.BlockPos;
  25. import net.minecraft.server.level.ServerBossEvent;
  26. import net.minecraft.server.level.ServerLevel;
  27. import net.minecraft.server.level.ServerPlayer;
  28. import net.minecraft.sounds.SoundEvent;
  29. import net.minecraft.world.BossEvent;
  30. import net.minecraft.world.damagesource.DamageSource;
  31. import net.minecraft.world.entity.Entity;
  32. import net.minecraft.world.entity.EntityType;
  33. import net.minecraft.world.entity.MobType;
  34. import net.minecraft.world.entity.ai.goal.FloatGoal;
  35. import net.minecraft.world.entity.monster.Phantom;
  36. import net.minecraft.world.entity.player.Player;
  37. import net.minecraft.world.level.Level;
  38. import net.minecraft.world.level.block.state.BlockState;
  39. import net.minecraft.world.phys.AABB;
  40. import net.minecraft.world.phys.Vec3;
  41. import org.jetbrains.annotations.NotNull;
  42. import org.jetbrains.annotations.Nullable;
  43. import software.bernie.geckolib.core.animation.AnimatableManager;
  44. import software.bernie.geckolib.core.animation.AnimationController;
  45.  
  46. import java.util.Map;
  47.  
  48. public class LichEntity extends BaseEntity {
  49.     private final LichConfig mobConfig;
  50.     private final AnimationHolder animationHolder;
  51.     private final TeleportAction teleportAction;
  52.     public HistoricalData<Vec3> velocityHistory;
  53.     public boolean shouldSetToNighttime;
  54.     public boolean collides;
  55.  
  56.     public LichEntity(EntityType<? extends LichEntity> entityType, Level level, LichConfig mobConfig) {
  57.         super(entityType, level);
  58.         this.mobConfig = mobConfig;
  59.  
  60.         noCulling = true;
  61.  
  62.         this.animationHolder = new AnimationHolder(this, Map.of(
  63.                 LichActions.endTeleport, new AnimationHolder.Animation("unteleport", "idle"),
  64.                 LichActions.cometRageAttack, new AnimationHolder.Animation("rage_mode", "idle"),
  65.                 LichActions.volleyRageAttack, new AnimationHolder.Animation("rage_mode", "idle"),
  66.                 LichActions.cometAttack, new AnimationHolder.Animation("summon_fireball", "idle"),
  67.                 LichActions.minionAttack, new AnimationHolder.Animation("summon_minions", "idle"),
  68.                 LichActions.minionRageAttack, new AnimationHolder.Animation("rage_mode", "idle"),
  69.                 LichActions.teleportAction, new AnimationHolder.Animation("teleport", "teleporting"),
  70.                 LichActions.volleyAttack, new AnimationHolder.Animation("summon_missiles", "idle"),
  71.                 (byte) 3, new AnimationHolder.Animation("idle", "idle")),
  72.                 LichActions.stopAttackAnimation, 0
  73.         );
  74.  
  75.         MinionAction minionAction = new MinionAction(this, preTickEvents, this::cancelAttackAction);
  76.         this.teleportAction = new TeleportAction(this, preTickEvents, this::cancelAttackAction);
  77.         Map<Byte, IActionWithCooldown> statusRegistry = Map.of(
  78.                 LichActions.cometAttack, new CometAction(this, preTickEvents, this::cancelAttackAction, mobConfig),
  79.                 LichActions.volleyAttack, new VolleyAction(this, mobConfig, preTickEvents, this::cancelAttackAction),
  80.                 LichActions.minionAttack, minionAction,
  81.                 LichActions.minionRageAttack, new MinionRageAction(this, preTickEvents, this::cancelAttackAction, minionAction),
  82.                 LichActions.teleportAction, teleportAction,
  83.                 LichActions.cometRageAttack, new CometRageAction(this, preTickEvents, this::cancelAttackAction, mobConfig),
  84.                 LichActions.volleyRageAttack, new VolleyRageAction(this, mobConfig, preTickEvents, this::cancelAttackAction));
  85.         DamageMemory damageMemory = new DamageMemory(5, this);
  86.         LichMoveLogic moveLogic = new LichMoveLogic(statusRegistry, this, damageMemory);
  87.         LichParticleHandler lichParticles = new LichParticleHandler(this, preTickEvents);
  88.  
  89.         this.shouldSetToNighttime = mobConfig.eternalNighttime;
  90.         this.velocityHistory = new HistoricalData<>(Vec3.ZERO, 2);
  91.         this.collides = true;
  92.  
  93.         CappedHeal cappedHeal = new CappedHeal(this, LichUtils.hpPercentRageModes, mobConfig.idleHealingPerTick);
  94.         entityEventHandler = new CompositeEntityEventHandler(animationHolder, lichParticles);
  95.         damageHandler = new CompositeDamageHandler(
  96.                 new StagedDamageHandler(LichUtils.hpPercentRageModes, () -> level.broadcastEntityEvent(this, LichActions.hpBelowThresholdStatus)),
  97.                 new DamagedAttackerNotSeen(this, livingEntity -> {if (livingEntity instanceof ServerPlayer) teleportAction.performTeleport((ServerPlayer) livingEntity);}),
  98.                 moveLogic, damageMemory
  99.         );
  100.  
  101.         bossBar = new ServerBossEvent(this.getDisplayName(), BossEvent.BossBarColor.BLUE, BossEvent.BossBarOverlay.PROGRESS);
  102.         serverTick = new CompositeEntityTick<>(cappedHeal, moveLogic);
  103.         clientTick = lichParticles;
  104.  
  105.         if (!level.isClientSide){
  106.             LichActions attackHelper = new LichActions(this, moveLogic);
  107.             LichMovement moveHelper = new LichMovement(this);
  108.  
  109.             goalSelector.addGoal(1, new FloatGoal(this));
  110.             goalSelector.addGoal(3, new CompositeGoal(moveHelper.buildAttackMovement(), attackHelper.buildAttackGoal()));
  111.             goalSelector.addGoal(4, moveHelper.buildWanderGoal());
  112.  
  113.             targetSelector.addGoal(2, new FindTargetGoal<>(this, Player.class, d -> this.getBoundingBox().inflate(d), 10, true, false, null));
  114.         }
  115.     }
  116.  
  117.     @Override
  118.     public void registerControllers(AnimatableManager.ControllerRegistrar data) {
  119.         animationHolder.registerControllers(data);
  120.         data.add(new AnimationController<>(this, "skull_float", 0, AnimationUtils.createIdlePredicate("skull_float")));
  121.         data.add(new AnimationController<>(this, "float", 0, AnimationUtils.createIdlePredicate("float")));
  122.         data.add(new AnimationController<>(this, "book_idle", 0, AnimationUtils.createIdlePredicate("book_idle")));
  123.     }
  124.  
  125.     public boolean inLineOfSight(Entity target){
  126.         boolean hasDirectLineOfSight = VanillaCopies.hasDirectLineOfSight(getEyePosition(), MobUtils.eyePos(target), level(), this);
  127.         Vec3 directionToLich = MathUtils.unNormedDirection(MobUtils.eyePos(target), getEyePosition());
  128.         boolean facingSameDirection = MathUtils.facingSameDirection(target.getLookAngle(), directionToLich);
  129.         return hasDirectLineOfSight && facingSameDirection;
  130.     }
  131.  
  132.     @Override
  133.     public void clientTick() {
  134.         velocityHistory.set(getDeltaMovement());
  135.     }
  136.  
  137.     @Override
  138.     public void serverTick(ServerLevel serverLevel) {
  139.         if (shouldSetToNighttime)
  140.             serverLevel.setDayTime(LichUtils.timeToNighttime(serverLevel.dayTime()));
  141.     }
  142.  
  143.     @Override
  144.     public boolean canCollideWith(@NotNull Entity entity) {
  145.         return collides;
  146.     }
  147.  
  148.     @Override
  149.     public boolean causeFallDamage(float fallDistance, float multiplier, @NotNull DamageSource source) {
  150.         return false;
  151.     }
  152.  
  153.     @Override
  154.     public @NotNull MobType getMobType() {
  155.         return MobType.UNDEAD;
  156.     }
  157.  
  158.     @Override
  159.     public void checkDespawn() {
  160.         BMDUtils.preventDespawnExceptPeaceful(this, level());
  161.     }
  162.  
  163.     @Nullable
  164.     @Override
  165.     protected SoundEvent getHurtSound(@NotNull DamageSource damageSource) {
  166.         return BMDSounds.LICH_HURT.get();
  167.     }
  168.  
  169.     @Nullable
  170.     @Override
  171.     protected SoundEvent getDeathSound() {
  172.         return BMDSounds.LICH_DEATH.get();
  173.     }
  174.  
  175.     @Override
  176.     protected float getSoundVolume() {
  177.         return 5.0f;
  178.     }
  179.  
  180.     @Override
  181.     public boolean onClimbable() {
  182.         return false;
  183.     }
  184.  
  185.     private boolean cancelAttackAction(){
  186.         return isDeadOrDying() || getTarget() == null;
  187.     }
  188.  
  189.     @Override
  190.     public void die(@NotNull DamageSource damageSource) {
  191.         int expTicks = 18;
  192.         int expPerTick = (int) (mobConfig.experienceDrop / (float) expTicks);
  193.         preTickEvents.addEvent(
  194.                 new TimedEvent(
  195.                         () -> VanillaCopies.awardExperience(expPerTick, MobUtils.eyePos(this), level()), 0,
  196.                         expTicks,
  197.                         () -> false
  198.                 )
  199.         );
  200.  
  201.          level().getEntitiesOfClass(Phantom.class, new AABB(blockPosition()).inflate(100.0, 100.0, 100.0)).forEach(Phantom::kill);
  202.  
  203.          super.die(damageSource);
  204.     }
  205.  
  206.     @Override
  207.     protected void checkFallDamage(double y, boolean onGround, @NotNull BlockState state, @NotNull BlockPos pos) {}
  208.  
  209.     @Override
  210.     public void travel(@NotNull Vec3 movementInput) {
  211.         VanillaCopies.travel(movementInput, this, 0.91f);
  212.     }
  213. }
Add Comment
Please, Sign In to add comment