aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud_2/api
diff options
context:
space:
mode:
authorLorenz <ESs95s3P5z8Pheb>2022-07-08 16:12:55 +0200
committerLorenz <ESs95s3P5z8Pheb>2022-07-08 16:12:55 +0200
commit4463c7fa78f886a8abc09e867dd17cde2a685ad4 (patch)
tree9245b4eed7f410f1c168688a77eeda6bfd55c994 /src/main/java/com/thatgravyboat/skyblockhud_2/api
parent9e08dbf2baa9819abd281ad285df7462c99491e2 (diff)
downloadskyhanni-4463c7fa78f886a8abc09e867dd17cde2a685ad4.tar.gz
skyhanni-4463c7fa78f886a8abc09e867dd17cde2a685ad4.tar.bz2
skyhanni-4463c7fa78f886a8abc09e867dd17cde2a685ad4.zip
code cleanup
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud_2/api')
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/KillTracking.java61
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/LeaderboardGetter.java65
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/events/LocationChangeEvent.java15
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileJoinedEvent.java12
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileSwitchedEvent.java12
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarLineUpdateEvent.java22
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPostEvent.java21
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPreGetEvent.java18
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SkyBlockEntityKilled.java18
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/item/IAbility.java7
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeHelper.java36
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeRegistry.java27
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/SkyBlockEntity.java27
13 files changed, 341 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/KillTracking.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/KillTracking.java
new file mode 100644
index 000000000..84882e1f4
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/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();
+// }
+// }
+//}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/LeaderboardGetter.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/LeaderboardGetter.java
new file mode 100644
index 000000000..de485ef5e
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/LeaderboardGetter.java
@@ -0,0 +1,65 @@
+//package com.thatgravyboat.skyblockhud.api;
+//
+//import static com.thatgravyboat.skyblockhud.ComponentHandler.SCOREBOARD_CHARACTERS;
+//
+//import at.lorenz.mod.LorenzMod;
+//import com.thatgravyboat.skyblockhud.api.events.SidebarLineUpdateEvent;
+//import com.thatgravyboat.skyblockhud.api.events.SidebarPostEvent;
+//import com.thatgravyboat.skyblockhud.api.events.SidebarPreGetEvent;
+//import com.thatgravyboat.skyblockhud.utils.Utils;
+//import java.util.*;
+//import java.util.stream.Collectors;
+//import net.minecraft.client.Minecraft;
+//import net.minecraft.scoreboard.Score;
+//import net.minecraft.scoreboard.ScoreObjective;
+//import net.minecraft.scoreboard.ScorePlayerTeam;
+//import net.minecraft.scoreboard.Scoreboard;
+//import net.minecraftforge.common.MinecraftForge;
+//import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+//import net.minecraftforge.fml.common.gameevent.TickEvent;
+//
+//public class LeaderboardGetter {
+//
+// private static Map<Integer, String> cachedScores = new HashMap<>();
+// private static List<String> cachedScoresList = new ArrayList<>();
+//
+// private static int ticks = 0;
+//
+// public static List<String> getCachedScores() {
+// return cachedScoresList;
+// }
+//
+// @SubscribeEvent
+// public void onClientUpdate(TickEvent.ClientTickEvent event) {
+// if (event.phase.equals(TickEvent.Phase.START)) return;
+// ticks++;
+// if (ticks % 5 != 0) return;
+//
+// Minecraft mc = Minecraft.getMinecraft();
+// if (mc.theWorld != null && LorenzMod.hasSkyblockScoreboard()) {
+// Scoreboard scoreboard = mc.theWorld.getScoreboard();
+// ScoreObjective sidebarObjective = scoreboard.getObjectiveInDisplaySlot(1);
+//
+// if (sidebarObjective != null && !MinecraftForge.EVENT_BUS.post(new SidebarPreGetEvent(scoreboard, sidebarObjective))) {
+// Collection<Score> scoreList = sidebarObjective.getScoreboard().getSortedScores(sidebarObjective);
+// Map<Integer, String> scores = scoreList.stream().collect(Collectors.toMap(Score::getScorePoints, this::getLine, (s1, s2) -> s1));
+//
+// if (!cachedScores.equals(scores)) {
+// scores.forEach((score, name) -> {
+// if (cachedScores.get(score) == null || !cachedScores.get(score).equals(name)) {
+// MinecraftForge.EVENT_BUS.post(new SidebarLineUpdateEvent(name, SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim(), score, scores.size(), scoreboard, sidebarObjective));
+// }
+// });
+// cachedScores = scores;
+// cachedScoresList = scores.values().stream().map(name -> SCOREBOARD_CHARACTERS.matcher(name).replaceAll("").trim()).collect(Collectors.toList());
+// }
+// MinecraftForge.EVENT_BUS.post(new SidebarPostEvent(scoreboard, sidebarObjective, cachedScoresList));
+// }
+// }
+// }
+//
+// public String getLine(Score score) {
+// ScorePlayerTeam scorePlayerTeam = score.getScoreScoreboard().getPlayersTeam(score.getPlayerName());
+// return Utils.removeColor(ScorePlayerTeam.formatPlayerName(scorePlayerTeam, score.getPlayerName()));
+// }
+//}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/LocationChangeEvent.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/LocationChangeEvent.java
new file mode 100644
index 000000000..560ad32e4
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/LocationChangeEvent.java
@@ -0,0 +1,15 @@
+//package com.thatgravyboat.skyblockhud.api.events;
+//
+//import com.thatgravyboat.skyblockhud.location.Locations;
+//import net.minecraftforge.fml.common.eventhandler.Event;
+//
+//public class LocationChangeEvent extends Event {
+//
+// public Locations oldLocation;
+// public Locations newLocation;
+//
+// public LocationChangeEvent(Locations oldLocation, Locations newLocation) {
+// this.oldLocation = oldLocation;
+// this.newLocation = newLocation;
+// }
+//}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileJoinedEvent.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileJoinedEvent.java
new file mode 100644
index 000000000..c1d51baf6
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileJoinedEvent.java
@@ -0,0 +1,12 @@
+package com.thatgravyboat.skyblockhud_2.api.events;
+
+import net.minecraftforge.fml.common.eventhandler.Event;
+
+public class ProfileJoinedEvent extends Event {
+
+ public String profile;
+
+ public ProfileJoinedEvent(String profile) {
+ this.profile = profile;
+ }
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileSwitchedEvent.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileSwitchedEvent.java
new file mode 100644
index 000000000..577821349
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/ProfileSwitchedEvent.java
@@ -0,0 +1,12 @@
+package com.thatgravyboat.skyblockhud_2.api.events;
+
+import net.minecraftforge.fml.common.eventhandler.Event;
+
+public class ProfileSwitchedEvent extends Event {
+
+ public String profile;
+
+ public ProfileSwitchedEvent(String profile) {
+ this.profile = profile;
+ }
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarLineUpdateEvent.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarLineUpdateEvent.java
new file mode 100644
index 000000000..c99684a79
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarLineUpdateEvent.java
@@ -0,0 +1,22 @@
+package com.thatgravyboat.skyblockhud_2.api.events;
+
+import net.minecraft.scoreboard.ScoreObjective;
+import net.minecraft.scoreboard.Scoreboard;
+import net.minecraftforge.fml.common.eventhandler.Event;
+
+public class SidebarLineUpdateEvent extends Event {
+
+ public String rawLine;
+ public String formattedLine;
+ public int position;
+ public Scoreboard scoreboard;
+ public ScoreObjective objective;
+
+ public SidebarLineUpdateEvent(String rawLine, String formattedLine, int score, int max, Scoreboard scoreboard, ScoreObjective objective) {
+ this.rawLine = rawLine;
+ this.formattedLine = formattedLine;
+ this.position = max - score;
+ this.scoreboard = scoreboard;
+ this.objective = objective;
+ }
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPostEvent.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPostEvent.java
new file mode 100644
index 000000000..13bf5c1e8
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPostEvent.java
@@ -0,0 +1,21 @@
+package com.thatgravyboat.skyblockhud_2.api.events;
+
+import java.util.List;
+import net.minecraft.scoreboard.ScoreObjective;
+import net.minecraft.scoreboard.Scoreboard;
+import net.minecraftforge.fml.common.eventhandler.Event;
+
+public class SidebarPostEvent extends Event {
+
+ public Scoreboard scoreboard;
+ public ScoreObjective objective;
+ public List<String> scores;
+ public String[] arrayScores;
+
+ public SidebarPostEvent(Scoreboard scoreboard, ScoreObjective objective, List<String> scores) {
+ this.scoreboard = scoreboard;
+ this.objective = objective;
+ this.scores = scores;
+ this.arrayScores = scores.toArray(new String[] {});
+ }
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPreGetEvent.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPreGetEvent.java
new file mode 100644
index 000000000..b94780acc
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SidebarPreGetEvent.java
@@ -0,0 +1,18 @@
+package com.thatgravyboat.skyblockhud_2.api.events;
+
+import net.minecraft.scoreboard.ScoreObjective;
+import net.minecraft.scoreboard.Scoreboard;
+import net.minecraftforge.fml.common.eventhandler.Cancelable;
+import net.minecraftforge.fml.common.eventhandler.Event;
+
+@Cancelable
+public class SidebarPreGetEvent extends Event {
+
+ public Scoreboard scoreboard;
+ public ScoreObjective objective;
+
+ public SidebarPreGetEvent(Scoreboard scoreboard, ScoreObjective objective) {
+ this.scoreboard = scoreboard;
+ this.objective = objective;
+ }
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SkyBlockEntityKilled.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SkyBlockEntityKilled.java
new file mode 100644
index 000000000..7553c171d
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/events/SkyBlockEntityKilled.java
@@ -0,0 +1,18 @@
+package com.thatgravyboat.skyblockhud_2.api.events;
+
+import javax.annotation.Nullable;
+import net.minecraft.entity.Entity;
+import net.minecraftforge.fml.common.eventhandler.Event;
+
+public class SkyBlockEntityKilled extends Event {
+
+ public String id;
+
+ @Nullable
+ public Entity entity;
+
+ public SkyBlockEntityKilled(String id, @Nullable Entity entity) {
+ this.id = id;
+ this.entity = entity;
+ }
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/item/IAbility.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/item/IAbility.java
new file mode 100644
index 000000000..ab3954048
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/item/IAbility.java
@@ -0,0 +1,7 @@
+package com.thatgravyboat.skyblockhud_2.api.item;
+
+public interface IAbility {
+ String getAbility();
+
+ int getAbilityTime();
+}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeHelper.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeHelper.java
new file mode 100644
index 000000000..2d8a17e4b
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeHelper.java
@@ -0,0 +1,36 @@
+//package com.thatgravyboat.skyblockhud.api.sbentities;
+//
+//import com.thatgravyboat.skyblockhud.location.LocationHandler;
+//import com.thatgravyboat.skyblockhud.location.Locations;
+//import net.minecraft.entity.Entity;
+//import net.minecraft.entity.monster.EntityEnderman;
+//import net.minecraft.entity.monster.EntityZombie;
+//import net.minecraft.init.Blocks;
+//import net.minecraft.init.Items;
+//
+//public class EntityTypeHelper {
+//
+// public static boolean isZealot(Entity entity) {
+// if (entity instanceof EntityEnderman) {
+// EntityEnderman enderman = ((EntityEnderman) entity);
+// double maxHealthBase = enderman.getAttributeMap().getAttributeInstanceByName("generic.maxHealth").getBaseValue();
+// if (maxHealthBase == 13000 || (maxHealthBase == 2000d && enderman.getHeldBlockState().getBlock().equals(Blocks.end_portal_frame))) {
+// return LocationHandler.getCurrentLocation().equals(Locations.DRAGONSNEST);
+// }
+// }
+// return false;
+// }
+//
+// public static boolean isCrypt(Entity entity) {
+// if (entity instanceof EntityZombie) {
+// EntityZombie zombie = ((EntityZombie) entity);
+// double maxHealthBase = zombie.getAttributeMap().getAttributeInstanceByName("generic.maxHealth").getBaseValue();
+// if (maxHealthBase != 2000d) return false;
+// if (zombie.getEquipmentInSlot(0) == null || !zombie.getEquipmentInSlot(0).getItem().equals(Items.iron_sword)) return false;
+// if (zombie.getEquipmentInSlot(1) == null || !zombie.getEquipmentInSlot(1).getItem().equals(Items.chainmail_boots)) return false;
+// if (zombie.getEquipmentInSlot(2) == null || !zombie.getEquipmentInSlot(2).getItem().equals(Items.chainmail_leggings)) return false;
+// return zombie.getEquipmentInSlot(3) != null && zombie.getEquipmentInSlot(3).getItem().equals(Items.chainmail_chestplate);
+// }
+// return false;
+// }
+//}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeRegistry.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeRegistry.java
new file mode 100644
index 000000000..d507eecfd
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/EntityTypeRegistry.java
@@ -0,0 +1,27 @@
+//package com.thatgravyboat.skyblockhud.api.sbentities;
+//
+//import com.google.common.collect.ImmutableList;
+//import com.google.common.collect.Maps;
+//import java.util.List;
+//import java.util.Map;
+//import net.minecraft.entity.Entity;
+//import net.minecraft.entity.monster.EntityEnderman;
+//import net.minecraft.entity.monster.EntityZombie;
+//
+//public class EntityTypeRegistry {
+//
+// private static final Map<Class<? extends Entity>, List<SkyBlockEntity>> entities = Maps.newHashMap();
+//
+// static {
+// entities.put(EntityEnderman.class, ImmutableList.of(SkyBlockEntity.of("ZEALOT", EntityTypeHelper::isZealot)));
+// entities.put(EntityZombie.class, ImmutableList.of(SkyBlockEntity.of("CRYPT_GHOUL", EntityTypeHelper::isCrypt)));
+// }
+//
+// public static String getEntityId(Entity entity) {
+// if (!entities.containsKey(entity.getClass())) return null;
+// for (SkyBlockEntity skyBlockEntity : entities.get(entity.getClass())) {
+// if (skyBlockEntity.isEntity(entity)) return skyBlockEntity.getName();
+// }
+// return null;
+// }
+//}
diff --git a/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/SkyBlockEntity.java b/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/SkyBlockEntity.java
new file mode 100644
index 000000000..24b30e712
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud_2/api/sbentities/SkyBlockEntity.java
@@ -0,0 +1,27 @@
+package com.thatgravyboat.skyblockhud_2.api.sbentities;
+
+import java.util.function.Predicate;
+import net.minecraft.entity.Entity;
+
+public class SkyBlockEntity {
+
+ private final String name;
+ private final Predicate<Entity> predicate;
+
+ public static SkyBlockEntity of(String name, Predicate<Entity> predicate) {
+ return new SkyBlockEntity(name, predicate);
+ }
+
+ private SkyBlockEntity(String name, Predicate<Entity> predicate) {
+ this.name = name;
+ this.predicate = predicate;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isEntity(Entity entity) {
+ return predicate.test(entity);
+ }
+}