diff --git a/Client/src/main/java/de/com/baseband/client/Setup.java b/Client/src/main/java/de/com/baseband/client/Setup.java index ef2505d..4c478f1 100644 --- a/Client/src/main/java/de/com/baseband/client/Setup.java +++ b/Client/src/main/java/de/com/baseband/client/Setup.java @@ -1,6 +1,7 @@ package de.com.baseband.client; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.background.PlayerListHandler; import de.com.baseband.client.feature.background.ServerSafeguard; import de.com.baseband.client.feature.commands.*; import de.com.baseband.client.feature.modules.chat.*; @@ -91,6 +92,7 @@ public class Setup { new Velocity(), new ServerSafeguard(), + new PlayerListHandler(), }; diff --git a/Client/src/main/java/de/com/baseband/client/event/events/PlayerEnteredViewEvent.java b/Client/src/main/java/de/com/baseband/client/event/events/PlayerEnteredViewEvent.java new file mode 100644 index 0000000..1af5028 --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/event/events/PlayerEnteredViewEvent.java @@ -0,0 +1,15 @@ +package de.com.baseband.client.event.events; + +import de.com.baseband.client.event.Event; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.player.EntityPlayer; + +public class PlayerEnteredViewEvent extends Event { + public final NetworkPlayerInfo playerInfo; + public final EntityPlayer entity; + + public PlayerEnteredViewEvent(NetworkPlayerInfo playerInfo, EntityPlayer entity) { + this.playerInfo = playerInfo; + this.entity = entity; + } +} diff --git a/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftViewEvent.java b/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftViewEvent.java new file mode 100644 index 0000000..792f83c --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftViewEvent.java @@ -0,0 +1,14 @@ +package de.com.baseband.client.event.events; + +import de.com.baseband.client.event.Event; +import net.minecraft.client.network.NetworkPlayerInfo; + +public class PlayerLeftViewEvent extends Event { + public final NetworkPlayerInfo playerInfo; + public final int index; + + public PlayerLeftViewEvent(NetworkPlayerInfo playerInfo, int index) { + this.playerInfo = playerInfo; + this.index = index; + } +} diff --git a/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEvent.java b/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEvent.java index 3b3c17d..7b95c84 100644 --- a/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEvent.java +++ b/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEvent.java @@ -1,7 +1,11 @@ package de.com.baseband.client.event.remote; +import de.com.baseband.client.BaseBand; import de.com.baseband.client.event.Event; +import de.tudbut.obj.Save; // any event which might be useful to others and can be serialized (@Save) should extend RemoteEvent public class RemoteEvent extends Event { + @Save + public final int source = BaseBand.REMOTE_EVENT_BUS.getID(); } diff --git a/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEventBus.java b/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEventBus.java index ae5b5e4..7db15f7 100644 --- a/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEventBus.java +++ b/Client/src/main/java/de/com/baseband/client/event/remote/RemoteEventBus.java @@ -191,6 +191,10 @@ public class RemoteEventBus { } public void publish(RemoteEvent event) { + if(!isConnected()) { + BaseBand.EVENT_BUS.publish(event); + return; + } toSend.offer(event); if(id == 0) toProcess.offer(event); diff --git a/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java b/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java new file mode 100644 index 0000000..d482d91 --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java @@ -0,0 +1,45 @@ +package de.com.baseband.client.feature.background; + +import de.com.baseband.client.BaseBand; +import de.com.baseband.client.event.events.PlayerEnteredViewEvent; +import de.com.baseband.client.event.events.PlayerLeftViewEvent; +import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.category.Background; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.player.EntityPlayer; + +import java.util.ArrayList; +import java.util.Optional; + +@Background +public class PlayerListHandler extends Feature { + + public static ArrayList playersInRenderDistance = new ArrayList<>(); + + @Override + public void onTick() { + ArrayList players = new ArrayList<>(); + for (NetworkPlayerInfo playerInfo : mc.player.connection.getPlayerInfoMap()) { + Optional player = mc.world.playerEntities.stream().filter(x -> x.getGameProfile().getId().equals(playerInfo.getGameProfile().getId())).findAny(); + if(player.isPresent()) { + players.add(playerInfo); + if(!playersInRenderDistance.contains(playerInfo)) { + playersInRenderDistance.add(playerInfo); + BaseBand.publish(new PlayerEnteredViewEvent(playerInfo, player.get())); + } + } + } + for (int i = 0; i < playersInRenderDistance.size(); i++) { + NetworkPlayerInfo playerInfo = playersInRenderDistance.get(i); + if (!players.contains(playerInfo)) { + BaseBand.publish(new PlayerLeftViewEvent(playerInfo, i)); + playersInRenderDistance.remove(i--); + } + } + } + + @Override + public String toString() { + return "INTERNAL:PlayerListHandler"; + } +} diff --git a/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java b/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java index de27660..579629a 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java +++ b/Client/src/main/java/de/com/baseband/client/feature/background/ServerSafeguard.java @@ -45,6 +45,6 @@ public class ServerSafeguard extends Feature { @Override public String toString() { - return "ServerSafeguard"; + return "INTERNAL:ServerSafeguard"; } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java index f566797..ef7db3d 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java @@ -5,6 +5,7 @@ import de.com.baseband.client.event.events.PacketEvent; import de.com.baseband.client.event.events.PlayerDestroyEvent; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.category.ClientCategory; +import de.com.baseband.client.feature.modules.experimental.PlayerSelector; import de.com.baseband.client.gui.GuiTheme; import de.com.baseband.client.registry.Configuration; import de.com.baseband.client.registry.annotation.*; @@ -113,6 +114,10 @@ public class Client extends Feature { @Override protected void setup() { this.setEnabled(true); + new PlayerSelector.PlayerSelectOption(this, "Target now", (x, p) -> { + playerTarget = p; + BaseBand.notify("Now targeting " + x.getGameProfile().getName() + "."); + }); } static boolean disableLock = false; @@ -155,6 +160,11 @@ public class Client extends Feature { } } + @Override + public boolean displayOnHUD() { + return false; + } + public enum NotificationDest { HUD, Chat, diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/experimental/PlayerSelector.java b/Client/src/main/java/de/com/baseband/client/feature/modules/experimental/PlayerSelector.java index e24e85e..35270c9 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/experimental/PlayerSelector.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/experimental/PlayerSelector.java @@ -1,20 +1,149 @@ package de.com.baseband.client.feature.modules.experimental; +import de.com.baseband.client.event.KeyManager; +import de.com.baseband.client.event.events.PlayerLeftViewEvent; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.background.PlayerListHandler; import de.com.baseband.client.feature.category.Experimental; +import de.com.baseband.client.registry.AnyGate; +import de.com.baseband.client.registry.annotation.Gate; +import de.com.baseband.client.registry.annotation.Requires; +import de.com.baseband.client.util.adapt.FieldFinder; +import de.com.baseband.client.util.adapt.Marker; +import de.com.baseband.client.util.type.KeyBind; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.network.NetworkPlayerInfo; +import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import org.lwjgl.input.Keyboard; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.BiConsumer; @Experimental +@Requires(PlayerListHandler.class) public class PlayerSelector extends Feature { + private static final ArrayList options = new ArrayList<>(); + + public enum Mode { + LIST, + OPTIONS, + } + + private Mode mode = Mode.LIST; + + List display = new ArrayList<>(); + + int cursor = 0; + int optionCursor = 0; + + @Marker(1) + @Gate(M_ENABLED) + KeyBind downBind = new KeyBind(Keyboard.KEY_DOWN, () -> { + if(mode == Mode.LIST) + if(cursor < display.size() - 1) cursor++; + if(mode == Mode.OPTIONS) + if(optionCursor < options.size() - 1) optionCursor++; + }, AnyGate.get(FieldFinder.findMarked(getClass(), 1), this)); + + @Marker(2) + @Gate(M_ENABLED) + KeyBind upBind = new KeyBind(Keyboard.KEY_UP, () -> { + if(mode == Mode.LIST) + if(cursor > 0) cursor--; + if(mode == Mode.OPTIONS) + if(optionCursor > 0) optionCursor--; + }, AnyGate.get(FieldFinder.findMarked(getClass(), 2), this)); + + @Override + protected void setup() { + KeyManager.registerKeyBind(downBind); + KeyManager.registerKeyBind(upBind); + } + + @Override + public void onEnable() { + cursor = 0; + } + @SubscribeEvent public void text(RenderGameOverlayEvent.Text e) { + ScaledResolution sr = new ScaledResolution(mc); + int x = sr.getScaledWidth() / 5; + int y = sr.getScaledHeight() / 2; + if(display.isEmpty()) + return; + + if(mode == Mode.LIST) { + renderList(x, y); + } + if(mode == Mode.OPTIONS) { + renderOptions(x, y); + } + } + + private void renderList(int x, int y) { + for (int i = Math.max(0, cursor - 5); i < Math.min(display.size(), cursor + 6); i++) { + NetworkPlayerInfo playerInfo = display.get(i); + boolean selected = cursor == i; + if (selected && Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { + mode = Mode.OPTIONS; + optionCursor = 0; + } + mc.fontRenderer.drawStringWithShadow((selected ? "§c§m| §r§a " : "§c| §r ") + playerInfo.getGameProfile().getName() + (selected ? " §c>" : ""), x, y, 0xffffffff); + y += mc.fontRenderer.FONT_HEIGHT; + } + } + private void renderOptions(int x, int y) { + if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)) + mode = Mode.LIST; + mc.fontRenderer.drawStringWithShadow(" Select with enter", x, y, 0xffffffff); + y += mc.fontRenderer.FONT_HEIGHT; + + for (int i = Math.max(0, optionCursor - 5); i < Math.min(options.size(), optionCursor + 6); i++) { + PlayerSelectOption option = options.get(i); + boolean selected = optionCursor == i; + if (selected && Keyboard.isKeyDown(Keyboard.KEY_RETURN)) { + NetworkPlayerInfo playerInfo = display.get(cursor); + option.callback.accept(playerInfo, mc.world.playerEntities.stream().filter(p -> p.getGameProfile().getId().equals(playerInfo.getGameProfile().getId())).findFirst().get()); + mode = Mode.LIST; + } + mc.fontRenderer.drawStringWithShadow((selected ? "§c< §m| §r§a " : "§c | §r ") + option.name, x, y, 0xffffffff); + y += mc.fontRenderer.FONT_HEIGHT; + } + } + + public void onPlayerLeftView(PlayerLeftViewEvent event) { + if(event.index == cursor) + mode = Mode.LIST; + if(event.index >= cursor && cursor > 0) + cursor--; + } + + @Override + public void onTick() { + display = PlayerListHandler.playersInRenderDistance; } @Override public String toString() { return "PlayerSelector"; } + + public static class PlayerSelectOption { + public final Feature registrar; + public final String name; + public final BiConsumer callback; + + public PlayerSelectOption(Feature registrar, String name, BiConsumer callback) { + this.registrar = registrar; + this.name = name; + this.callback = callback; + PlayerSelector.options.add(this); + } + } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java b/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java index 57723c5..79d135d 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java @@ -1,7 +1,6 @@ package de.com.baseband.client.feature.modules.render; import de.com.baseband.client.BaseBand; -import de.com.baseband.client.feature.Category; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.Features; import de.com.baseband.client.feature.category.Render; @@ -249,7 +248,7 @@ public class HUD extends Feature { } int maxWidth = TextSplitter.getStringWidth(initString); - Feature[] renderFeatures = Arrays.stream(Features.features).filter(m -> m.enabled && m.category != Category.COMMAND && m.getClass() != Client.class && m != this && m.displayOnHUD()).sorted(Comparator.comparingDouble(value -> -Minecraft.getMinecraft().fontRenderer.getStringWidth(includeStatus ? value.text : value.toString()))).toArray(Feature[]::new); + Feature[] renderFeatures = Arrays.stream(Features.features).filter(m -> m.enabled && m.category.mayDisplay && m.displayOnHUD()).sorted(Comparator.comparingDouble(value -> -Minecraft.getMinecraft().fontRenderer.getStringWidth(includeStatus ? value.text : value.toString()))).toArray(Feature[]::new); for (Feature f : renderFeatures) { maxWidth = Math.max(mc.fontRenderer.getStringWidth(f.getHUDText()), maxWidth); }