add PlayerSelector and the infrastructure surrounding it
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m31s
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m31s
This commit is contained in:
parent
053b4e71b6
commit
3e63b7ac17
10 changed files with 225 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
package de.com.baseband.client;
|
package de.com.baseband.client;
|
||||||
|
|
||||||
import de.com.baseband.client.feature.Feature;
|
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.background.ServerSafeguard;
|
||||||
import de.com.baseband.client.feature.commands.*;
|
import de.com.baseband.client.feature.commands.*;
|
||||||
import de.com.baseband.client.feature.modules.chat.*;
|
import de.com.baseband.client.feature.modules.chat.*;
|
||||||
|
@ -91,6 +92,7 @@ public class Setup {
|
||||||
new Velocity(),
|
new Velocity(),
|
||||||
|
|
||||||
new ServerSafeguard(),
|
new ServerSafeguard(),
|
||||||
|
new PlayerListHandler(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,11 @@
|
||||||
package de.com.baseband.client.event.remote;
|
package de.com.baseband.client.event.remote;
|
||||||
|
|
||||||
|
import de.com.baseband.client.BaseBand;
|
||||||
import de.com.baseband.client.event.Event;
|
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
|
// any event which might be useful to others and can be serialized (@Save) should extend RemoteEvent
|
||||||
public class RemoteEvent extends Event {
|
public class RemoteEvent extends Event {
|
||||||
|
@Save
|
||||||
|
public final int source = BaseBand.REMOTE_EVENT_BUS.getID();
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,10 @@ public class RemoteEventBus {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void publish(RemoteEvent event) {
|
public void publish(RemoteEvent event) {
|
||||||
|
if(!isConnected()) {
|
||||||
|
BaseBand.EVENT_BUS.publish(event);
|
||||||
|
return;
|
||||||
|
}
|
||||||
toSend.offer(event);
|
toSend.offer(event);
|
||||||
if(id == 0)
|
if(id == 0)
|
||||||
toProcess.offer(event);
|
toProcess.offer(event);
|
||||||
|
|
|
@ -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<NetworkPlayerInfo> playersInRenderDistance = new ArrayList<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTick() {
|
||||||
|
ArrayList<NetworkPlayerInfo> players = new ArrayList<>();
|
||||||
|
for (NetworkPlayerInfo playerInfo : mc.player.connection.getPlayerInfoMap()) {
|
||||||
|
Optional<EntityPlayer> 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";
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,6 +45,6 @@ public class ServerSafeguard extends Feature {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ServerSafeguard";
|
return "INTERNAL:ServerSafeguard";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.event.events.PlayerDestroyEvent;
|
||||||
import de.com.baseband.client.feature.Feature;
|
import de.com.baseband.client.feature.Feature;
|
||||||
import de.com.baseband.client.feature.category.ClientCategory;
|
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.gui.GuiTheme;
|
||||||
import de.com.baseband.client.registry.Configuration;
|
import de.com.baseband.client.registry.Configuration;
|
||||||
import de.com.baseband.client.registry.annotation.*;
|
import de.com.baseband.client.registry.annotation.*;
|
||||||
|
@ -113,6 +114,10 @@ public class Client extends Feature {
|
||||||
@Override
|
@Override
|
||||||
protected void setup() {
|
protected void setup() {
|
||||||
this.setEnabled(true);
|
this.setEnabled(true);
|
||||||
|
new PlayerSelector.PlayerSelectOption(this, "Target now", (x, p) -> {
|
||||||
|
playerTarget = p;
|
||||||
|
BaseBand.notify("Now targeting " + x.getGameProfile().getName() + ".");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean disableLock = false;
|
static boolean disableLock = false;
|
||||||
|
@ -155,6 +160,11 @@ public class Client extends Feature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean displayOnHUD() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public enum NotificationDest {
|
public enum NotificationDest {
|
||||||
HUD,
|
HUD,
|
||||||
Chat,
|
Chat,
|
||||||
|
|
|
@ -1,20 +1,149 @@
|
||||||
package de.com.baseband.client.feature.modules.experimental;
|
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.Feature;
|
||||||
|
import de.com.baseband.client.feature.background.PlayerListHandler;
|
||||||
import de.com.baseband.client.feature.category.Experimental;
|
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.client.event.RenderGameOverlayEvent;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
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
|
@Experimental
|
||||||
|
@Requires(PlayerListHandler.class)
|
||||||
public class PlayerSelector extends Feature {
|
public class PlayerSelector extends Feature {
|
||||||
|
|
||||||
|
private static final ArrayList<PlayerSelectOption> options = new ArrayList<>();
|
||||||
|
|
||||||
|
public enum Mode {
|
||||||
|
LIST,
|
||||||
|
OPTIONS,
|
||||||
|
}
|
||||||
|
|
||||||
|
private Mode mode = Mode.LIST;
|
||||||
|
|
||||||
|
List<NetworkPlayerInfo> 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
|
@SubscribeEvent
|
||||||
public void text(RenderGameOverlayEvent.Text e) {
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "PlayerSelector";
|
return "PlayerSelector";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class PlayerSelectOption {
|
||||||
|
public final Feature registrar;
|
||||||
|
public final String name;
|
||||||
|
public final BiConsumer<NetworkPlayerInfo, EntityPlayer> callback;
|
||||||
|
|
||||||
|
public PlayerSelectOption(Feature registrar, String name, BiConsumer<NetworkPlayerInfo, EntityPlayer> callback) {
|
||||||
|
this.registrar = registrar;
|
||||||
|
this.name = name;
|
||||||
|
this.callback = callback;
|
||||||
|
PlayerSelector.options.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package de.com.baseband.client.feature.modules.render;
|
package de.com.baseband.client.feature.modules.render;
|
||||||
|
|
||||||
import de.com.baseband.client.BaseBand;
|
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.Feature;
|
||||||
import de.com.baseband.client.feature.Features;
|
import de.com.baseband.client.feature.Features;
|
||||||
import de.com.baseband.client.feature.category.Render;
|
import de.com.baseband.client.feature.category.Render;
|
||||||
|
@ -249,7 +248,7 @@ public class HUD extends Feature {
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxWidth = TextSplitter.getStringWidth(initString);
|
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) {
|
for (Feature f : renderFeatures) {
|
||||||
maxWidth = Math.max(mc.fontRenderer.getStringWidth(f.getHUDText()), maxWidth);
|
maxWidth = Math.max(mc.fontRenderer.getStringWidth(f.getHUDText()), maxWidth);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue