diff --git a/src/main/java/io/github/hhui64/pixelmoninfoplus/gui/statspanel/StatsPanelGuiContainer.java b/src/main/java/io/github/hhui64/pixelmoninfoplus/gui/statspanel/StatsPanelGuiContainer.java index c24466c..f845fdd 100644 --- a/src/main/java/io/github/hhui64/pixelmoninfoplus/gui/statspanel/StatsPanelGuiContainer.java +++ b/src/main/java/io/github/hhui64/pixelmoninfoplus/gui/statspanel/StatsPanelGuiContainer.java @@ -139,36 +139,6 @@ public static void close() { } } - /** - * 获取宝当前宝可梦的 IVStore 实例 - * (此方法会在绘制时一直被调用,所以应该不用手动触发更新缓存) - * - * @return IVStore - */ - public IVStore getCurrentPokemonIVStore() { - if (this.pokemon != null) { - // 获取当前宝可梦自身的本地 IVStore - IVStore localIVStore = this.pokemon.getIVs(); - // 尝试根据 Pokemon UUID 从缓存处获取 IVStore - IVStore remoteIVStore = PartyCache.getPokemonIVStore(this.pokemon); - return Arrays.stream(localIVStore.getArray()).sum() == 0 ? remoteIVStore : localIVStore; - } - return new IVStore(new int[]{0, 0, 0, 0, 0, 0}); - } - - - /** - * 获取宝当前宝可梦的 EVStore 实例 - * - * @return EVStore - */ - public EVStore getCurrentPokemonEVStore() { - if (this.pokemon != null) { - return this.pokemon.getEVs(); - } - return new EVStore(new int[]{0, 0, 0, 0, 0, 0}); - } - /** * 绘制背景层 *
@@ -210,8 +180,8 @@ protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, i
public void drawProgress() {
int offsetX = this.getOffsetXY()[0], offsetY = this.getOffsetXY()[1];
- IVStore ivs = this.getCurrentPokemonIVStore();
- EVStore evs = this.getCurrentPokemonEVStore();
+ IVStore ivs = PartyApi.getCurrentPokemonIVStore(this.pokemon);
+ EVStore evs = PartyApi.getCurrentPokemonEVStore(this.pokemon);
int ivsProgressWidth = Math.toIntExact(Math.round(115 * ivs.getPercentage(0) / 100));
double evsPercentage = Arrays.stream(evs.getArray()).sum() / 510.0 * 100.0;
@@ -228,8 +198,8 @@ public void drawProgressText() {
int offsetX = this.getOffsetXY()[0], offsetY = this.getOffsetXY()[1];
if (this.pokemon != null) {
- IVStore ivs = this.getCurrentPokemonIVStore();
- EVStore evs = this.getCurrentPokemonEVStore();
+ IVStore ivs = PartyApi.getCurrentPokemonIVStore(this.pokemon);
+ EVStore evs = PartyApi.getCurrentPokemonEVStore(this.pokemon);
double evsPercentage = Arrays.stream(evs.getArray()).sum() / 510.0 * 100.0;
String strIVs = this.pokemon.isEgg() ? "???/??? (???%)" : Arrays.stream(ivs.getArray()).sum() + "/186 (" + Math.round(ivs.getPercentage(0)) + "%)";
@@ -339,8 +309,8 @@ public void drawPokemonStatsText() {
int x = offsetX + 104;
if (this.pokemon != null) {
- IVStore ivs = this.getCurrentPokemonIVStore();
- EVStore evs = this.getCurrentPokemonEVStore();
+ IVStore ivs = PartyApi.getCurrentPokemonIVStore(this.pokemon);
+ EVStore evs = PartyApi.getCurrentPokemonEVStore(this.pokemon);
String IVsHp = this.pokemon.isEgg() ? "???" : ivs.isHyperTrained(StatsType.HP) ? "31(" + ivs.getStat(StatsType.HP) + ")" : String.valueOf(ivs.getStat(StatsType.HP));
String IVsAtk = this.pokemon.isEgg() ? "???" : ivs.isHyperTrained(StatsType.Attack) ? "31(" + ivs.getStat(StatsType.Attack) + ")" : String.valueOf(ivs.getStat(StatsType.Attack));
diff --git a/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyApi.java b/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyApi.java
index 9ce3f5c..1538ebd 100644
--- a/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyApi.java
+++ b/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyApi.java
@@ -4,7 +4,11 @@
import com.pixelmonmod.pixelmon.api.pokemon.Pokemon;
import com.pixelmonmod.pixelmon.client.storage.ClientStorageManager;
import com.pixelmonmod.pixelmon.client.gui.GuiPixelmonOverlay;
+import com.pixelmonmod.pixelmon.entities.pixelmon.stats.EVStore;
+import com.pixelmonmod.pixelmon.entities.pixelmon.stats.IVStore;
+import javax.annotation.Nullable;
+import java.util.Arrays;
import java.util.List;
public class PartyApi {
@@ -51,4 +55,37 @@ public static String[] getTeamStringUUID() {
public static Pokemon getSelectedPokemon() {
return ClientStorageManager.party.get(GuiPixelmonOverlay.selectedPixelmon);
}
+
+ /**
+ * 获取宝当前宝可梦的 IVStore 实例
+ *
+ * @param pokemonIn 指定的 {@link Pokemon},如为 null 则自动获取当前队伍中选择的宝可梦
+ * @return {@link IVStore}
+ */
+ public static IVStore getCurrentPokemonIVStore(@Nullable Pokemon pokemonIn) {
+ Pokemon pokemon = pokemonIn != null ? pokemonIn : PartyApi.getSelectedPokemon();
+ if (pokemon != null) {
+ // 获取当前宝可梦自身的本地 IVStore
+ IVStore localIVStore = pokemon.getIVs();
+ // 尝试根据 Pokemon UUID 从缓存处获取 IVStore
+ IVStore remoteIVStore = PartyCache.getPokemonIVStore(pokemon);
+ return Arrays.stream(localIVStore.getArray()).sum() == 0 ? remoteIVStore : localIVStore;
+ }
+ return new IVStore(new int[]{0, 0, 0, 0, 0, 0});
+ }
+
+
+ /**
+ * 获取宝当前宝可梦的 EVStore 实例
+ *
+ * @param pokemonIn 指定的 {@link Pokemon},如为 null 则自动获取当前队伍中选择的宝可梦
+ * @return {@link EVStore}
+ */
+ public static EVStore getCurrentPokemonEVStore(@Nullable Pokemon pokemonIn) {
+ Pokemon pokemon = pokemonIn != null ? pokemonIn : PartyApi.getSelectedPokemon();
+ if (pokemon != null) {
+ return pokemon.getEVs();
+ }
+ return new EVStore(new int[]{0, 0, 0, 0, 0, 0});
+ }
}
diff --git a/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyCache.java b/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyCache.java
index 676d5b7..e979fb2 100644
--- a/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyCache.java
+++ b/src/main/java/io/github/hhui64/pixelmoninfoplus/pixelmon/PartyCache.java
@@ -172,13 +172,16 @@ public static void cleanCache() {
*/
public static void updateCache(boolean forceUpdate) {
String[] localPartyPokemonsUUID = PartyApi.getTeamStringUUID();
- List