Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions src/main/java/fr/alexdoru/mwe/api/ISquadInfoRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.minecraft.entity.player.EntityPlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Unmodifiable;

import java.util.List;

/**
* Implementing this interface and registering it via
Expand All @@ -19,24 +22,47 @@ default int getPriority() {
return 0;
}

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

/**
* @param listIndex the index of the squad member in the list
* @param netInfo the NetworkPlayerInfo of the squad member on this line
* @param entityPlayer the corresponding EntityPlayer if loaded in the world, may be null
* @return the width in pixels needed to render this info for the given player,
* or 0 if nothing should be rendered for this player
*/
int getWidth(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer);
default int getWidth(int listIndex, @NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer) {return getWidth(netInfo, entityPlayer);}

/** @deprecated Use {@link #render(int, NetworkPlayerInfo, EntityPlayer, int, int, int, int)} */
@Deprecated
default void render(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer, int x, int y, int reservedWidth) {}

/**
* Renders the extra info. Implementations should stay within [x, x + reservedWidth].
* Renders the extra info. Implementations should stay within [x, x + reservedWidth] and [y, y + reservedHeight].
*
* @param netInfo the NetworkPlayerInfo of the squad member on this line
* @param entityPlayer the corresponding EntityPlayer if loaded in the world, may be null
* @param x left edge of the column reserved for this renderer
* @param y y position of the line
* @param reservedWidth the max width reserved for this renderer across all displayed players,
* as previously returned by {@link #getWidth}
* @param listIndex the index of the squad member in the list
* @param netInfo the NetworkPlayerInfo of the squad member on this line
* @param entityPlayer the corresponding EntityPlayer if loaded in the world, may be null
* @param x left edge of the column reserved for this renderer
* @param y y position of the line
* @param reservedWidth the max width reserved for this renderer across all displayed players,
* as previously returned by {@link #getWidth(int, NetworkPlayerInfo, EntityPlayer)}
* @param reservedHeight the max height reserved for this row
*/
default void render(int listIndex, @NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer, int x, int y, int reservedWidth, int reservedHeight) {render(netInfo, entityPlayer, x, y, reservedWidth);}

/**
* Use this to clean information created in {@link #processData(int, List, List)}
*/
default void clearData() {}

/**
* @param listSize the size of the list ({@code 0} if empty)
* @param netInfoList the NetworkPlayerInfo of each player
* @param entityPlayerList a list containing either the corresponding EntityPlayer if loaded in the world or null
*/
void render(@NotNull NetworkPlayerInfo netInfo, @Nullable EntityPlayer entityPlayer, int x, int y, int reservedWidth);
default void processData(int listSize, @Unmodifiable List<NetworkPlayerInfo> netInfoList, @Unmodifiable List<EntityPlayer> entityPlayerList) {}

}
6 changes: 6 additions & 0 deletions src/main/java/fr/alexdoru/mwe/api/MWEApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@ public static void registerSquadHUDExtraRenderer(@NotNull ISquadInfoRenderer ren
MWE.INSTANCE().getMweRenderers().squadHUD.registerExtraRenderer(renderer);
}

/**
* @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

return MWE.INSTANCE().getMweRenderers().squadHUD.isEnabled(-1); // System.currentTimeMillis()
}
}

public static final class MojangApi {
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/fr/alexdoru/mwe/gui/huds/SquadHealthHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@ public void onTick(TickEvent.ClientTickEvent event) {
netInfoList.clear();
playerList.clear();
playerNamesList.clear();
extraInfoRenderers.forEach(ISquadInfoRenderer::clearData);
final Minecraft mc = Minecraft.getMinecraft();
if (mc.theWorld != null && mc.thePlayer != null && this.isEnabled(0)) {
final Scoreboard scoreboard = mc.theWorld.getScoreboard();
final ScoreObjective scoreobjective = scoreboard.getObjectiveInDisplaySlot(0);
if (!mc.isIntegratedServerRunning() || scoreobjective != null) {
this.populateRenderList(mc, scoreboard, scoreobjective);
if (!extraInfoRenderers.isEmpty()) {
final int listSize = netInfoList.size();
final List<NetworkPlayerInfo> netInfoListView = Collections.unmodifiableList(netInfoList);
final List<EntityPlayer> playerListView = Collections.unmodifiableList(playerList);
for (final ISquadInfoRenderer infoRenderer : extraInfoRenderers) {
infoRenderer.processData(listSize, netInfoListView, playerListView);
}
}
}
}
}
Expand Down Expand Up @@ -102,7 +111,7 @@ private void render(ScaledResolution resolution, Minecraft mc, Scoreboard scoreb
}
}
for (int r = 0; r < this.extraInfoRenderers.size(); r++) {
final int width = this.extraInfoRenderers.get(r).getWidth(netInfo, entityPlayer);
final int width = this.extraInfoRenderers.get(r).getWidth(i, netInfo, entityPlayer);
maxExtraWidths[r] = Math.max(maxExtraWidths[r], width);
}
}
Expand Down Expand Up @@ -157,7 +166,7 @@ private void render(ScaledResolution resolution, Minecraft mc, Scoreboard scoreb
for (int r = 0; r < this.extraInfoRenderers.size(); r++) {
final int reservedWidth = maxExtraWidths[r];
if (reservedWidth > 0) {
this.extraInfoRenderers.get(r).render(netInfo, entityPlayer, xDrawingPos, yDrawingPos, reservedWidth);
this.extraInfoRenderers.get(r).render(i, netInfo, entityPlayer, xDrawingPos, yDrawingPos, reservedWidth, 8);
xDrawingPos += reservedWidth + PADDING;
}
}
Expand Down