blob: 70d6a401a5689197c985bb7a399bf6d3552c501b (
plain)
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
|
package de.hysky.skyblocker.skyblock.crimson.dojo;
import de.hysky.skyblocker.utils.render.RenderHelper;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.entity.Entity;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Vec3d;
import java.awt.*;
import java.text.DecimalFormat;
import java.util.Map;
public class ForceTestHelper {
private static final DecimalFormat FORMATTER = new DecimalFormat("0.0");
private static final int ZOMBIE_LIFE_TIME = 10100;
private static final Object2LongOpenHashMap<ZombieEntity> zombies = new Object2LongOpenHashMap<>();
protected static void reset() {
zombies.clear();
}
/**
* If a zombie value is negative make it glow
*
* @param name zombies value
* @return if the zombie should glow
*/
protected static boolean shouldGlow(String name) {
return name.contains("-");
}
protected static int getColor() {
return Color.RED.getRGB();
}
protected static void onEntitySpawn(Entity entity) {
if (entity instanceof ZombieEntity zombie) {
zombies.put(zombie, System.currentTimeMillis() + ZOMBIE_LIFE_TIME);
}
}
protected static void onEntityAttacked(Entity entity) {
if (entity instanceof ZombieEntity zombie) {
if (zombies.containsKey(zombie)) {
zombies.put(zombie, System.currentTimeMillis() + ZOMBIE_LIFE_TIME); //timer is reset when they are hit
}
}
}
protected static void onEntityDespawn(Entity entity) {
if (entity instanceof ZombieEntity zombie) {
zombies.removeLong(zombie);
}
}
protected static void render(WorldRenderContext context) {
//render times
long currentTime = System.currentTimeMillis();
for (Map.Entry<ZombieEntity, Long> zombie : zombies.object2LongEntrySet()) {
float secondsTime = Math.max((zombie.getValue() - currentTime) / 1000f, 0);
MutableText text = Text.literal(FORMATTER.format(secondsTime));
if (secondsTime > 1) {
text = text.formatted(Formatting.GREEN);
} else if (secondsTime > 0) {
text = text.formatted(Formatting.YELLOW);
} else {
text = text.formatted(Formatting.RED);
}
Vec3d labelPos = zombie.getKey().getCameraPosVec(context.tickCounter().getTickDelta(false));
RenderHelper.renderText(context, text, labelPos, 1.5f, true);
}
}
}
|