From f8ab64f88f69ec50d5aca562f0ddbbf6ff7b0a34 Mon Sep 17 00:00:00 2001 From: hackthetime Date: Thu, 14 Dec 2023 12:57:03 +0100 Subject: a lot of prob not full working things --- .../java/de/hype/bbsentials/forge/MCUtils.java | 113 ++++++++++++++++++++- .../hype/bbsentials/forge/client/MoulConfig.java | 30 ++---- .../bbsentials/forge/client/MoulConfigManager.java | 22 ++++ 3 files changed, 144 insertions(+), 21 deletions(-) create mode 100644 forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java (limited to 'forge/src/main') diff --git a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java index 251b20b..8bb02f0 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/MCUtils.java @@ -3,14 +3,18 @@ package de.hype.bbsentials.forge; import com.mojang.authlib.exceptions.AuthenticationException; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.Display; import java.io.File; -import java.math.BigInteger; -import java.util.Random; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { public boolean isWindowFocused() { @@ -58,4 +62,109 @@ public class MCUtils implements de.hype.bbsentials.common.mclibraries.MCUtils { return serverId; } + public List getAllPlayers() { + List players = new ArrayList<>(); + + // Iterate through all players on the server + for (EntityPlayer player : Minecraft.getMinecraft().thePlayer.getEntityWorld().playerEntities) { + if (!player.getDisplayNameString().startsWith("!")) { + players.add(player); + } + } + + return players; + } + + public List getPlayersInRadius(EntityPlayer referencePlayer, List players, double radius) { + List nearbyPlayers = new ArrayList<>(); + + // Iterate through all players and check their distance from the reference player + for (EntityPlayer player : players) { + if (player != referencePlayer && player.getDistanceSq(referencePlayer.posX, referencePlayer.posY, referencePlayer.posZ) <= radius * radius) { + nearbyPlayers.add(player); + } + } + + return nearbyPlayers; + } + + + public List getBingoPlayers() { + List bingoPlayers = new ArrayList<>(); + + // Iterate through all players and check their distance from the source player + for (Iterator it = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap().stream().iterator(); it.hasNext(); ) { + NetworkPlayerInfo entry = it.next(); + try { + if (entry.getGameProfile().getName().startsWith("!")) { + String customName = entry.getDisplayName().getUnformattedText(); + if (customName.contains("Ⓑ")) { + bingoPlayers.add(customName.trim().split(" ")[1]); + } + } + } catch (Exception ignored) { + } + + } + return bingoPlayers; + } + + public List getIronmanPlayers() { + List ironmanPlayers = new ArrayList<>(); + + // Iterate through all players and check their distance from the source player + for (Iterator it = Minecraft.getMinecraft().getNetHandler().getPlayerInfoMap().stream().iterator(); it.hasNext(); ) { + NetworkPlayerInfo entry = it.next(); + try { + if (entry.getGameProfile().getName().startsWith("!")) { + String customName = entry.getDisplayName().getUnformattedText(); + if (customName.contains("♻")) { + ironmanPlayers.add(customName.trim().split(" ")[1]); + } + } + } catch (Exception ignored) { + } + + } + return ironmanPlayers; + } + + public List onlyFromList(List players, List usernames) { + ArrayList filtered = new ArrayList<>(); + for (EntityPlayer player : players) { + String playerUsername = player.getGameProfile().getName(); + for (int i = 0; i < usernames.size(); i++) { + if (playerUsername.equals(usernames.get(i))) { + usernames.remove(i); + filtered.add(player); + } + } + } + return filtered; + } + + public List filterOut(List players, List usernames) { + ArrayList filtered = new ArrayList<>(); + for (EntityPlayer player : players) { + String playerUsername = player.getGameProfile().getName(); + boolean toAdd = true; + for (int i = 0; i < usernames.size(); i++) { + if (playerUsername.equals(usernames.get(i))) { + toAdd = false; + usernames.remove(i); + break; + } + } + if (toAdd) { + filtered.add(player); + } + } + return filtered; + } + + public List getSplashLeechingPlayers() { + List players = getAllPlayers(); + players.remove(Minecraft.getMinecraft().thePlayer); + return getPlayersInRadius(Minecraft.getMinecraft().thePlayer, filterOut(getAllPlayers(), getBingoPlayers()), 5).stream().map((playerEntity -> playerEntity.getDisplayName().getFormattedText())).collect(Collectors.toList()); + } } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java index 4d50a4e..e0598ff 100644 --- a/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfig.java @@ -4,43 +4,35 @@ import com.google.gson.annotations.Expose; import de.hype.bbsentials.forge.client.categories.FirstCategory; import io.github.moulberry.moulconfig.Config; import io.github.moulberry.moulconfig.annotations.Category; -import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown; -import io.github.moulberry.moulconfig.annotations.ConfigOption; -import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper; -import io.github.moulberry.moulconfig.gui.MoulConfigEditor; -import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis; -import io.github.moulberry.moulconfig.processor.ConfigProcessorDriver; -import io.github.moulberry.moulconfig.processor.MoulConfigProcessor; import net.minecraft.client.Minecraft; -import net.minecraftforge.common.config.ConfigCategory; +import net.minecraft.util.ChatComponentText; import static de.hype.bbsentials.common.client.BBsentials.config; public class MoulConfig extends Config { - MoulConfigEditor editor; - MoulConfigProcessor processor; @Expose @Category(name = "First Category", desc = "This is the first category.") public FirstCategory firstCategory = new FirstCategory(); - public MoulConfig() { - processor = new MoulConfigProcessor<>(this); - editor = new MoulConfigEditor<>(processor); - BuiltinMoulConfigGuis.addProcessors(processor); - ConfigProcessorDriver.processConfig(MoulConfig.class, this, processor); - } - @Override public String getTitle() { return "BBsentials " + de.hype.bbsentials.common.client.Config.apiVersion; } + @Override public void saveNow() { config.save(); } - public void openConfigGui() { - Minecraft.getMinecraft().displayGuiScreen(new GuiScreenElementWrapper(editor)); + @Override + public void executeRunnable(int runnableId) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Just executed runnableId " + runnableId)); + } + + @Override + public boolean shouldAutoFocusSearchbar() { + return true; } + } diff --git a/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java new file mode 100644 index 0000000..07491cd --- /dev/null +++ b/forge/src/main/java/de/hype/bbsentials/forge/client/MoulConfigManager.java @@ -0,0 +1,22 @@ +package de.hype.bbsentials.forge.client; + +import io.github.moulberry.moulconfig.gui.MoulGuiOverlayEditor; +import io.github.moulberry.moulconfig.processor.BuiltinMoulConfigGuis; +import io.github.moulberry.moulconfig.processor.ConfigProcessorDriver; +import io.github.moulberry.moulconfig.processor.MoulConfigProcessor; +import net.minecraft.client.Minecraft; + +public class MoulConfigManager { + static MoulConfig moulConfig = new MoulConfig(); + MoulConfigProcessor testConfigMoulConfigProcessor; + + public MoulConfigManager() { + testConfigMoulConfigProcessor = new MoulConfigProcessor<>(moulConfig); + BuiltinMoulConfigGuis.addProcessors(testConfigMoulConfigProcessor); + ConfigProcessorDriver.processConfig(moulConfig.getClass(), moulConfig, testConfigMoulConfigProcessor); + } + + public void openConfigGui() { + Minecraft.getMinecraft().displayGuiScreen(new MoulGuiOverlayEditor(testConfigMoulConfigProcessor)); + } +} -- cgit