diff options
author | Äkwav <ekwav@coflnet.com> | 2023-05-17 18:08:32 +0200 |
---|---|---|
committer | Äkwav <ekwav@coflnet.com> | 2023-05-17 18:08:32 +0200 |
commit | 72ba24f1d7032343b3c88f7e63abb546a4457092 (patch) | |
tree | f0ce502f36678ffd9350c4274bf616567a43d3be /src | |
parent | afb18445b175ce54b9bae6f59ab73a2502be9e42 (diff) | |
download | COFL-72ba24f1d7032343b3c88f7e63abb546a4457092.tar.gz COFL-72ba24f1d7032343b3c88f7e63abb546a4457092.tar.bz2 COFL-72ba24f1d7032343b3c88f7e63abb546a4457092.zip |
fix description updating in trade
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/de/torui/coflsky/handlers/DescriptionHandler.java | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/main/java/de/torui/coflsky/handlers/DescriptionHandler.java b/src/main/java/de/torui/coflsky/handlers/DescriptionHandler.java index 861ab44..1c64bfd 100644 --- a/src/main/java/de/torui/coflsky/handlers/DescriptionHandler.java +++ b/src/main/java/de/torui/coflsky/handlers/DescriptionHandler.java @@ -51,12 +51,13 @@ public class DescriptionHandler { public static String ExtractStackableIdFromItemStack(ItemStack stack) { if (stack != null) { try { - String uuid = stack.serializeNBT().getCompoundTag("tag").getCompoundTag("ExtraAttributes") - .getString("id") + ":" + stack.stackSize; - if (uuid.length() == 0) { - throw new Exception(); - } - return uuid; + NBTTagCompound serialized = stack.serializeNBT(); + String itemTag = serialized.getCompoundTag("tag").getCompoundTag("ExtraAttributes") + .getString("id"); + if (itemTag != null && itemTag.length() > 1) + return itemTag + ":" + stack.stackSize; + return serialized.getCompoundTag("tag").getCompoundTag("display") + .getString("Name"); } catch (Exception e) { } } @@ -91,25 +92,33 @@ public class DescriptionHandler { return EMPTY_ARRAY; } + /** + * Called when the inventory is opened + * checks for changes every once in a while and updates the description if + * there was a change found + * + * @param event + */ public void loadDescriptionAndListenForChanges(GuiOpenEvent event) { GuiContainer gc = (GuiContainer) event.gui; loadDescriptionForInventory(event, gc, false); - int iteration = 0; + int iteration = 1; while (IsOpen) { - iteration++; try { - Thread.sleep(300 + iteration); + Thread.sleep(300 + iteration++); } catch (InterruptedException e) { throw new RuntimeException(e); } - if (shouldUpdate || iteration % 10 == 0 && hasAnyStackChanged(gc)) { + if (shouldUpdate || hasAnyStackChanged(gc)) { shouldUpdate = false; loadDescriptionForInventory(event, gc, true); + // reduce update time since its more likely that more changes occure after one + iteration = 5; } if (iteration >= 30) - iteration = 30; // cap at 9 second update interval + iteration = 29; // cap at 9 second update interval } } @@ -201,7 +210,8 @@ public class DescriptionHandler { for (DescModification datum : data) { if (event.toolTip.size() <= datum.line) { - System.out.println("Skipped line modification " + datum.line + " for " + event.itemStack.getDisplayName()); + System.out.println( + "Skipped line modification " + datum.line + " for " + event.itemStack.getDisplayName()); continue; } switch (datum.type) { |