aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle.kts2
-rw-r--r--src/main/java/de/torui/coflsky/handlers/DescriptionHandler.java34
2 files changed, 23 insertions, 13 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index b4ddc8e..8978cc7 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -7,7 +7,7 @@ plugins {
}
group = "de.torui.coflmod"
-version = "1.5.2-alpha"
+version = "1.5.3-alpha"
// Toolchains:
java {
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) {