Skip to content

Squad info update for devs - #87

Closed
shvaich wants to merge 6 commits into
Alexdoru:masterfrom
shvaich:squad-info-update-for-devs
Closed

shvaich wants to merge 6 commits into
Alexdoru:masterfrom
shvaich:squad-info-update-for-devs

Conversation

@shvaich

@shvaich shvaich commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Changes I encourage

  • Added ISquadInfoRenderer#getWidth(int listIndex, @NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer)
    to replace: ISquadInfoRenderer#getWidth(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer)

  • Added ISquadInfoRenderer#render(int listIndex, @NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer, int x, int y, int reservedWidth, int reservedHeight)
    to replace: ISquadInfoRenderer#render(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer, int x, int y, int reservedWidth)

  • Added ISquadInfoRenderer#processData(int listSize, @Unmodifiable List<NetworkPlayerInfo> netInfoList, @Unmodifiable List<EntityPlayer> entityPlayerList) and ISquadInfoRenderer#clearData()

The idea behind these changes is to give developers the option to create their own data with processData and clearData
and access their data in getWidth and render with the listIndex parameter

(I added reservedHeight to render because I believe developers could use it. for example, to center something)

Note:
to make the new getWidth and render methods work nicely I had to make them default and by default execute the old getWidth and render methods, this is for backwards compatibility.

I made the old getWidth and render methods default aswell so developers who use the updated version dont have to implement them and can directly only implement the new getWidth and render methods.

Optional Additions

  • Added Priority logic to ISquadInfoRenders (same as forge's EventPriority logic).
    this can be useful for some developers
    (HIGHEST is drawn first, LOWEST is drawn last)

  • Added MWEApi.Hud.isSquadHUDEnabled() method just incase some developers could use it

Comment thread src/main/java/fr/alexdoru/mwe/api/ISquadInfoRenderer.java Outdated

/** @deprecated Use {@link #getWidth(int, NetworkPlayerInfo, EntityPlayer)} */
@Deprecated
default int getWidth(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer) { return 0; }

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't see the point of passing i you can make a map and cache things in your handler and have a on tick method too

@shvaich

shvaich commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

1. with old ISquadInfoRenderer version:

public class SquadPositionInfo implements ISquadInfoRenderer {


    @Override
    public int getWidth(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer) {
        if (entityPlayer == null) return 0;
        final Minecraft mc = Minecraft.getMinecraft();
        final EntityPlayerSP thePlayer = mc.thePlayer;
        if (thePlayer == null || thePlayer == entityPlayer) return 0;
        final int distance = (int) entityPlayer.getDistanceToEntity(thePlayer);
        final int yDistance = (int) (entityPlayer.posY - thePlayer.posY);
        
        return N; // calculate string width with the newly calculated `distance` and `yDistance` values
    }

    @Override
    public void render(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer, int x, int y, int reservedWidth) {
        if (entityPlayer == null) return;
        final Minecraft mc = Minecraft.getMinecraft();
        if (mc.thePlayer == null || mc.thePlayer == entityPlayer) return;

        final double distX = entityPlayer.posX - mc.thePlayer.posX;
        final double distY = entityPlayer.posY - mc.thePlayer.posY;
        final double distZ = entityPlayer.posZ - mc.thePlayer.posZ;
        
        final int distance = (int) Math.sqrt(distX * distX + distY * distY + distZ * distZ);
        final int yDistance = (int) distY;
        
        // draw distance string with newly created distance value
        // draw y-distance string with newly created yDistance value

        final float rotation = R; // calculate rotation
        // draw arrow with newly created rotation value
    }
}

2. with my ISquadInfoRenderer version:

public class SquadPositionInfo implements ISquadInfoRenderer {
    private final List<PosData> posDataList = new ArrayList<>();

    public void clearData() { posDataList.clear(); }

    public void processData(int listSize, List<NetworkPlayerInfo> netInfoList, List<EntityPlayer> playerList) {
        final EntityPlayerSP thePlayer = Minecraft.getMinecraft().thePlayer;
        if (thePlayer == null) {
            posDataList.addAll(Collections.nCopies(listSize, null));
            return;
        }
        for (int i = 0; i < listSize; i++) {
            final EntityPlayer player = playerList.get(i);
            posDataList.add(player == null ? null : new PosData(thePlayer, player));
        }
    }

    public int getWidth(int listIndex, @NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer) {
        final PosData posData = posDataList.get(listIndex);
        if (posData == null) return 0;
        final Minecraft mc = Minecraft.getMinecraft();
        return N; // calculate string width with the stored values of posData
    }

    public void render(int listIndex, @NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer, int x, int y, int reservedWidth, int reservedHeight) {
        final PosData posData = posDataList.get(listIndex);
        if (posData == null) return;
        final Minecraft mc = Minecraft.getMinecraft();
        
        // draw distance string with the stored posData.distance value
        // draw y-distance string with the stored posData.yDistance value
        // draw arrow with stored posData.rotation value 
    }

    private static final class PosData {
        public final int distance;
        public final int yDistance;
        public final float rotation;
        public PosData(EntityPlayerSP thePlayer, EntityPlayer player) {
            this.distance = D; // calculate distance
            this.yDistance = DY; // calculate y-distance
            this.rotation = R; // calculate rotation
        }
    }
}

In this example, you can see how in my version a developer has the option to create the data he needs when its available to create and then simply use the data he created in the getWidth and render methods.
(This is one example of how a developer can use these features)

Note: with my ISquadInfoRenderer version, developers have a choice, they can, if they choose to, not use any of my additions and write their code exactly as it is written in version 1.

…devs

# Conflicts:
#	src/main/java/fr/alexdoru/mwe/api/ISquadInfoRenderer.java
/**
* @return {@code true} if the squad HUD is currently rendered
*/
public static boolean isSquadHUDEnabled() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont need it. thought it might be useful for other developers.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it then

@Alexdoru

Alexdoru commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

Your first version is much faster, computing distances costs nothing compared to creating objects and iterating collections

@Alexdoru Alexdoru closed this Sep 19, 2026
@Alexdoru Alexdoru reopened this Sep 19, 2026
@shvaich shvaich closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants