1
+ package com .solegendary .reignofnether .unit ;
2
+
3
+ import com .solegendary .reignofnether .orthoview .OrthoviewClientEvents ;
4
+ import com .solegendary .reignofnether .research .ResearchClient ;
5
+ import com .solegendary .reignofnether .sandbox .SandboxClientEvents ;
6
+ import com .solegendary .reignofnether .unit .interfaces .Unit ;
7
+ import com .solegendary .reignofnether .util .MyRenderer ;
8
+ import net .minecraft .client .Minecraft ;
9
+ import net .minecraft .core .BlockPos ;
10
+ import net .minecraft .core .Direction ;
11
+ import net .minecraft .resources .ResourceLocation ;
12
+ import net .minecraft .server .level .ServerLevel ;
13
+ import net .minecraft .world .entity .LivingEntity ;
14
+ import net .minecraft .world .entity .PathfinderMob ;
15
+ import net .minecraft .world .entity .ai .attributes .Attributes ;
16
+ import net .minecraft .world .entity .ai .goal .WrappedGoal ;
17
+ import net .minecraft .world .entity .ai .goal .target .NearestAttackableTargetGoal ;
18
+ import net .minecraft .world .level .Level ;
19
+ import net .minecraft .world .level .block .SnowLayerBlock ;
20
+ import net .minecraft .world .phys .AABB ;
21
+ import net .minecraft .world .phys .Vec3 ;
22
+ import net .minecraftforge .client .event .RenderLevelStageEvent ;
23
+ import net .minecraftforge .event .TickEvent ;
24
+ import net .minecraftforge .eventbus .api .SubscribeEvent ;
25
+
26
+ import static com .solegendary .reignofnether .unit .UnitClientEvents .getSelectedUnits ;
27
+ import static net .minecraftforge .client .event .RenderLevelStageEvent .Stage .AFTER_CUTOUT_BLOCKS ;
28
+
29
+ public class NonUnitClientEvents {
30
+
31
+ private static final Minecraft MC = Minecraft .getInstance ();
32
+
33
+ public static boolean canControlNonUnits () {
34
+ return MC .player != null &&
35
+ !getSelectedUnits ().isEmpty () &&
36
+ (ResearchClient .hasCheat ("wouldyoukindly" ) ||
37
+ SandboxClientEvents .isSandboxPlayer (MC .player .getName ().getString ()));
38
+ }
39
+
40
+ public static boolean canAttack (LivingEntity le ) {
41
+ if (le instanceof PathfinderMob mob ) {
42
+ if (mob .getAttributes ().hasAttribute (Attributes .ATTACK_DAMAGE ) ||
43
+ mob .getAttributes ().hasAttribute (Attributes .ATTACK_SPEED ))
44
+ return true ;
45
+
46
+ for (WrappedGoal wrappedGoal : mob .goalSelector .getAvailableGoals ())
47
+ if (wrappedGoal .getGoal () instanceof NearestAttackableTargetGoal )
48
+ return true ;
49
+ }
50
+ return false ;
51
+ }
52
+
53
+ // override attack and random move goals while we have an active command
54
+ @ SubscribeEvent
55
+ public static void onRenderLevel (RenderLevelStageEvent evt ) {
56
+ if (MC .level == null )
57
+ return ;
58
+
59
+ // AFTER_CUTOUT_BLOCKS lets us see checkpoints through leaves
60
+ if (OrthoviewClientEvents .isEnabled () && evt .getStage () == AFTER_CUTOUT_BLOCKS ) {
61
+
62
+ for (LivingEntity le : UnitClientEvents .getSelectedUnits ()) {
63
+ if (le instanceof PathfinderMob mob && !(le instanceof Unit ) && le .isAlive () && !le .isRemoved ()) {
64
+ float entityYOffset = 1.74f - le .getEyeHeight () - 1 ;
65
+ Vec3 firstPos = le .getEyePosition ().add (0 , entityYOffset ,0 );
66
+
67
+ if (mob .getTarget () != null && !mob .getTarget ().isDeadOrDying ()) {
68
+ MyRenderer .drawLine (evt .getPoseStack (), firstPos , mob .getTarget ().getEyePosition (), 1 , 0 , 0 , 0.5f );
69
+ }
70
+ else if (!mob .getNavigation ().isDone () && mob .getNavigation ().getTargetPos () != null ) {
71
+
72
+ double dist = Math .sqrt (mob .distanceToSqr (Vec3 .atCenterOf (mob .getNavigation ().getTargetPos ())));
73
+ float a = (float ) Math .min (1 , dist / 4 ) - 0.2f ;
74
+
75
+ if (a > 0 ) {
76
+ BlockPos bp = mob .getNavigation ().getTargetPos ().below ();
77
+ Vec3 pos = new Vec3 (bp .getX () + 0.5f , bp .getY () + 1.0f , bp .getZ () + 0.5f );
78
+ MyRenderer .drawLine (evt .getPoseStack (), firstPos , pos , 0 , 1 , 0 , a );
79
+
80
+ if (MC .level .getBlockState (bp .offset (0 , 1 , 0 )).getBlock () instanceof SnowLayerBlock ) {
81
+ AABB aabb = new AABB (bp );
82
+ aabb = aabb .setMaxY (aabb .maxY + 0.13f );
83
+ MyRenderer .drawSolidBox (evt .getPoseStack (), aabb , Direction .UP , 0 , 1 , 0 , a * 0.5f ,
84
+ new ResourceLocation ("forge:textures/white.png" ));
85
+ } else {
86
+ MyRenderer .drawBlockFace (evt .getPoseStack (), Direction .UP , bp , 0 , 1 , 0 , a * 0.5f );
87
+ }
88
+ }
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
0 commit comments