blob: 552837b3a94d55414f8a211f4ba88903a2f52489 (
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
82
83
84
85
86
|
package com.thatgravyboat.skyblockhud.tracker;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class KillTrackerHandler {
public static final Set<UUID> attackedEntities = new HashSet<>();
@SubscribeEvent
public void onAttack(AttackEntityEvent event) {
if (event.target != null) {
attackedEntities.add(event.target.getUniqueID());
}
}
@SubscribeEvent
public void onDeath(LivingDeathEvent event) {
if (false) {
//Used for testing
System.out.println(
"----------------------------------------------------------------------------------------------------------------"
);
System.out.println("Name : " + event.entity.getName());
System.out.println("UUID : " + event.entity.getUniqueID());
NBTTagCompound tag = new NBTTagCompound();
event.entity.writeToNBT(tag);
System.out.println("Tag : " + tag);
System.out.println(
"Damage : " + getDamageSourceString(event.source)
);
System.out.println(
"----------------------------------------------------------------------------------------------------------------"
);
}
attackedEntities.remove(event.entity.getUniqueID());
}
public static String getDamageSourceString(DamageSource source) {
return (
"{ " +
source.getDamageType() +
", " +
source.isDamageAbsolute() +
", " +
source.isDifficultyScaled() +
", " +
source.isFireDamage() +
", " +
source.isProjectile() +
", " +
source.isUnblockable() +
", " +
source.isExplosion() +
", " +
source.isMagicDamage() +
", " +
source.isCreativePlayer() +
", " +
source.getSourceOfDamage() +
" }"
);
}
@SubscribeEvent
public void onWorldChange(EntityJoinWorldEvent event) {
if (event.entity != null) {
if (
event.entity
.getUniqueID()
.equals(Minecraft.getMinecraft().thePlayer.getUniqueID())
) {
attackedEntities.clear();
}
}
}
}
|