package io.github.moulberry.notenoughupdates.miscfeatures; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.commands.SimpleCommand; import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; import io.github.moulberry.notenoughupdates.util.Constants; import io.github.moulberry.notenoughupdates.util.SBInfo; import io.github.moulberry.notenoughupdates.util.SpecialColour; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.command.ICommandSender; import net.minecraft.util.*; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.*; public class FairySouls { private static HashMap> foundSouls = new HashMap<>(); private static List currentSoulList = null; private static List currentSoulListClose = null; private static boolean enabled = false; @SubscribeEvent public void onWorldUnload(WorldEvent.Unload event) { currentSoulList = null; } public static void load(File file, Gson gson) { if(file.exists()) { try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) { HashMap> foundSoulsList = gson.fromJson(reader, HashMap.class); foundSouls = new HashMap<>(); for(Map.Entry> entry : foundSoulsList.entrySet()) { HashSet set = new HashSet<>(); for(Number n : entry.getValue()) { set.add(n.intValue()); } foundSouls.put(entry.getKey(), set); } return; } catch(Exception e) {} } foundSouls = new HashMap<>(); } public static void save(File file, Gson gson) { try { file.createNewFile(); try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) { writer.write(gson.toJson(foundSouls)); } } catch(IOException ignored) {} } @SubscribeEvent public void onChatReceived(ClientChatReceivedEvent event) { if(currentSoulList == null) return; if(event.message.getFormattedText().equals("\u00A7r\u00A7dYou have already found that Fairy Soul!\u00A7r") || event.message.getFormattedText().equals("\u00A7d\u00A7lSOUL! \u00A7fYou found a \u00A7r\u00A7dFairy Soul\u00A7r\u00A7f!\u00A7r")) { String location = SBInfo.getInstance().getLocation(); if(location == null) return; int closestIndex = -1; double closestDistSq = 10*10; for(int i=0; i found = foundSouls.computeIfAbsent(location, k -> new HashSet<>()); found.add(closestIndex); } } } public static void tick() { if(!enabled) return; if(Minecraft.getMinecraft().theWorld == null) { currentSoulList = null; return; } JsonObject fairySouls = Constants.FAIRYSOULS; if(fairySouls == null) return; String location = SBInfo.getInstance().getLocation(); if(location == null) { currentSoulList = null; return; } if(currentSoulList == null) { if(fairySouls.has(location) && fairySouls.get(location).isJsonArray()) { JsonArray locations = fairySouls.get(location).getAsJsonArray(); currentSoulList = new ArrayList<>(); for(int i=0; i distanceSqMap = new TreeMap<>(); Set found = foundSouls.computeIfAbsent(location, k -> new HashSet<>()); for(int i=0; i(); for(BlockPos pos : distanceSqMap.values()) { currentSoulListClose.add(pos); if(++souls >= maxSouls) break; } } } @SubscribeEvent public void onRenderLast(RenderWorldLastEvent event) { if(!enabled) return; String location = SBInfo.getInstance().getLocation(); if(location == null) return; if(currentSoulList == null || currentSoulList.isEmpty()) return; Set found = foundSouls.computeIfAbsent(location, k -> new HashSet<>()); int rgb = 0xa839ce; for(int i=0; i found = foundSouls.computeIfAbsent(location, k -> new HashSet<>()); for(int i=0; i