Shadowducky

BTGazer.java

May 24th, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. package com.shadowducky.minestranding.common.mob.entity;
  2.  
  3. import org.apache.logging.log4j.LogManager;
  4. import org.apache.logging.log4j.Logger;
  5.  
  6. import com.shadowducky.minestranding.common.MineStranding;
  7.  
  8. import net.minecraft.world.entity.Entity;
  9. import net.minecraft.world.entity.EntityType;
  10. import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
  11. import net.minecraft.world.entity.ai.attributes.Attributes;
  12. import net.minecraft.world.entity.ai.goal.FloatGoal;
  13. import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal;
  14. import net.minecraft.world.entity.ai.goal.MeleeAttackGoal;
  15. import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal;
  16. import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal;
  17. import net.minecraft.world.entity.monster.Monster;
  18. import net.minecraft.world.entity.player.Player;
  19. import net.minecraft.world.level.Level;
  20.  
  21. public class BTGazer extends Monster {
  22.  
  23. public static final Logger LOGGER = LogManager.getLogger(MineStranding.MODID);
  24. private Entity lastTarget;
  25.  
  26. public BTGazer(EntityType<? extends BTGazer> entityType, Level level) {
  27. super(entityType, level);
  28. lastTarget = null;
  29. }
  30.  
  31. @Override
  32. protected void registerGoals() {
  33. super.registerGoals();
  34. this.goalSelector.addGoal(0, new FloatGoal(this));
  35. this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0D, false));
  36. this.goalSelector.addGoal(2, new LookAtPlayerGoal(this, Player.class, 6.0F));
  37. this.goalSelector.addGoal(3, new RandomLookAroundGoal(this));
  38. this.targetSelector.addGoal(0, new NearestAttackableTargetGoal<>(this, Player.class, true));
  39. }
  40.  
  41. public static AttributeSupplier.Builder createAttributes() {
  42. return Monster.createMonsterAttributes().add(Attributes.FOLLOW_RANGE, 5.0D).add(Attributes.MOVEMENT_SPEED, 0.1D)
  43. .add(Attributes.MAX_HEALTH, 30.0D).add(Attributes.ATTACK_DAMAGE, 1.0D);
  44. }
  45.  
  46. public boolean targetIsNear() {
  47. if (lastTarget != null) {
  48. return this.distanceTo(lastTarget) <= 7;
  49. } else {
  50. return false;
  51. }
  52. }
  53.  
  54. public void tick() {
  55. super.tick();
  56. Entity tempTarget = this.getTarget();
  57. if (tempTarget != null) {
  58. lastTarget = tempTarget;
  59. }
  60. System.out.println(lastTarget);
  61. }
  62.  
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment