DebugQueueEvent.JAVA
Sonickat |
PRO |
02/01/25 10:50:47 PM UTC |
0 ⭐ |
12450 👁️ |
Never ⏰ |
[Minecraft 1.20.1, Forge 47.3]
package net.sonickat.sklib.common;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
public class DebugQueueEvent {
private final String message;
private final String timestamp;
private final CRef affectedBlock;
private final List<CRef> callStack; // Tracks full chain of triggers
public DebugQueueEvent(String message, CRef affectedBlock, List<CRef> callStack) {
this.timestamp = Instant.now().toString();
this.message = message;
this.affectedBlock = affectedBlock;
// Copy call stack + add this block
this.callStack = new ArrayList<>(callStack);
this.callStack.add(affectedBlock);
}
public String getMessage() {
return message;
}
public String getTimestamp() {
return timestamp;
}
public CRef getAffectedBlock() {
return affectedBlock;
}
public List<CRef> getCallStack() {
return callStack;
}
/**
* Formats the call stack for console output, limiting excessive length.
*/
private String formatCallStack() {
int size = callStack.size();
int maxLength = DebugQueue.MAX_CONSOLE_CHAIN_LENGTH; // Controlled by DebugQueue
if (size <= maxLength) {
return callStack.toString(); // Show full list if small
}
// Show first, '...', last few elements (e.g., [..., B, C, D])
List<CRef> reducedStack = new ArrayList<>();
reducedStack.add(callStack.get(0)); // Always include the origin
reducedStack.add(new CRef(0, 0, 0)); // Placeholder for "..."
reducedStack.addAll(callStack.subList(size - (maxLength - 1), size));
return reducedStack.toString().replace(new CRef(0, 0, 0).toString(), "...");
}
@Override
public String toString() {
return "[" + timestamp + "] (" + affectedBlock + ") <- " + formatCallStack() + " " + message;
}
}
Comments
0 B
|0 👍
/0 👎
0 B
|👍
/👎