aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java
diff options
context:
space:
mode:
authorLorenz <ESs95s3P5z8Pheb>2022-07-07 00:31:50 +0200
committerLorenz <ESs95s3P5z8Pheb>2022-07-07 00:31:50 +0200
commit99773d6a593c444151503de315f127bea6f74d49 (patch)
tree9ee1ae505e5f82aba62f10c882af85a3acd6e483 /src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java
downloadskyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.gz
skyhanni-99773d6a593c444151503de315f127bea6f74d49.tar.bz2
skyhanni-99773d6a593c444151503de315f127bea6f74d49.zip
init lorenz mod
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java')
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java b/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java
new file mode 100644
index 000000000..bc98672d8
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud/api/KillTracking.java
@@ -0,0 +1,61 @@
+package com.thatgravyboat.skyblockhud.api;
+
+import com.thatgravyboat.skyblockhud.DevModeConstants;
+import com.thatgravyboat.skyblockhud.api.events.SkyBlockEntityKilled;
+import com.thatgravyboat.skyblockhud.api.sbentities.EntityTypeRegistry;
+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.common.MinecraftForge;
+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 KillTracking {
+
+ 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 (DevModeConstants.mobDeathLogging) {
+ //Used for testing
+ System.out.println("----------------------------------------------------------------------------------------------------------------");
+ System.out.println("Name : " + event.entity.getName());
+ System.out.println("UUID : " + event.entity.getUniqueID());
+ NBTTagCompound compound = new NBTTagCompound();
+ event.entity.writeToNBT(compound);
+ System.out.println("Tag : " + compound);
+ System.out.println("Damage : " + getDamageSourceString(event.source));
+ System.out.println("SBH Entity ID: " + EntityTypeRegistry.getEntityId(event.entity));
+ System.out.println("----------------------------------------------------------------------------------------------------------------");
+ }
+ if (attackedEntities.contains(event.entity.getUniqueID())) {
+ if (EntityTypeRegistry.getEntityId(event.entity) != null) {
+ MinecraftForge.EVENT_BUS.post(new SkyBlockEntityKilled(EntityTypeRegistry.getEntityId(event.entity), event.entity));
+ }
+ 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 == Minecraft.getMinecraft().thePlayer) {
+ attackedEntities.clear();
+ }
+ }
+}