diff options
author | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-06 15:10:29 -0230 |
---|---|---|
committer | ThatGravyBoat <thatgravyboat@gmail.com> | 2021-07-06 15:10:29 -0230 |
commit | 6d8e1e5659f64a4f9ba86d6ab5bbc8e688faf22a (patch) | |
tree | 7451e53ceeae3c324d83a7faba83ce80005e6f23 /src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java | |
download | SkyblockHud-Death-Defied-6d8e1e5659f64a4f9ba86d6ab5bbc8e688faf22a.tar.gz SkyblockHud-Death-Defied-6d8e1e5659f64a4f9ba86d6ab5bbc8e688faf22a.tar.bz2 SkyblockHud-Death-Defied-6d8e1e5659f64a4f9ba86d6ab5bbc8e688faf22a.zip |
Initial Commit
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java')
-rw-r--r-- | src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java new file mode 100644 index 0000000..6734283 --- /dev/null +++ b/src/main/java/com/thatgravyboat/skyblockhud/tracker/KillTrackerHandler.java @@ -0,0 +1,76 @@ +package com.thatgravyboat.skyblockhud.tracker; + +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; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +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(); + } + } + } +} |