aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/bscv/modules/defense/Aura.java
blob: 0ffe45c3e779e6793cb2a4e6ec8dce7750ae36a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package ftbsc.bscv.modules.defense;

import com.google.auto.service.AutoService;

import ftbsc.bscv.Boscovicino;
import ftbsc.bscv.ICommons;
import ftbsc.bscv.api.ILoadable;
import ftbsc.bscv.modules.QuickModule;
import ftbsc.bscv.tools.Setting;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.eventbus.api.SubscribeEvent;

@AutoService(ILoadable.class)
public class Aura extends QuickModule implements ICommons {

   @Override
   protected int getDefaultKey() {
      return UNBOUND;
   }

   public final ForgeConfigSpec.ConfigValue<Double> reach;
   public final ForgeConfigSpec.ConfigValue<Double> strenght;
   public final ForgeConfigSpec.ConfigValue<Boolean> neutral;
   public final ForgeConfigSpec.ConfigValue<Boolean> friends;

   public Aura() {
      super();

      this.reach = Setting.Decimal.builder()
         .min(0.)
         .fallback(5.)
         .name("reach")
         .comment("aura attack reach")
         .build(this);

      this.strenght = Setting.Decimal.builder()
         .min(0.)
         .max(1.)
         .name("strenght")
         .comment("minimum strenght required for attack")
         .fallback(1.)
         .build(this);

      this.neutral = Setting.Bool.builder()
         .fallback(false)
         .name("neutral")
         .comment("attack neutral mobs")
         .build(this);

      this.friends = Setting.Bool.builder()
         .fallback(false)
         .name("friends")
         .comment("attack players tagged as friends")
         .build(this);
   }

   @SubscribeEvent
   public void onTick(TickEvent.ClientTickEvent event) {
      if (event.phase == Phase.END) return;
      if (MC.level == null) return;
      if (MC.player == null) return;

      if (MC.player.getAttackStrengthScale(0.f) < this.strenght.get()) return;

      for (Entity e : MC.level.entitiesForRendering()) {
         if (e.equals(MC.player)) continue;
         if (!(e instanceof LivingEntity)) continue;
         if (!e.isAlive()) continue;
         if (e.distanceTo(MC.player) > this.reach.get()) continue;
         if (!this.neutral.get() && e.getClassification(false).isFriendly()) continue;
         if (e instanceof PlayerEntity) {
            PlayerEntity player = (PlayerEntity) e;
            if (Boscovicino.friends().isFriend(player.getGameProfile().getId())) {
               continue;
            }
         }
         if (!this.friends.get() && Boscovicino.friends().isFriend(e.getDisplayName().getString())) continue;
         MC.gameMode.attack(MC.player, e);
         break;
      }
   }
}