mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 17:34:26 +00:00
Compare commits
15
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be173f13ca | ||
|
|
2567bf63b0 | ||
|
|
a591fef66e | ||
|
|
160f3ae628 | ||
|
|
32839206d3 | ||
|
|
3448957d04 | ||
|
|
985e03c227 | ||
|
|
16f0022505 | ||
|
|
2dd41fb9d5 | ||
|
|
0736ac27d4 | ||
|
|
fc9b386ea7 | ||
|
|
7f7d54403c | ||
|
|
9b3c1aaa44 | ||
|
|
3216926681 | ||
|
|
1a7d9187e5 |
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ plugins {
|
||||
id "dts.typescript-generator"
|
||||
}
|
||||
|
||||
version = "1.11"
|
||||
version = "1.11.1"
|
||||
group= "kamkeel.customnpc-plus"
|
||||
archivesBaseName = "CustomNPC-Plus"
|
||||
|
||||
|
||||
+1
-1
Submodule src/api updated: f91e17ab3e...04fd348d13.
@@ -125,7 +125,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11")
|
||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.11.1")
|
||||
public class CustomNpcs {
|
||||
|
||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||
|
||||
@@ -19,7 +19,9 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import noppes.npcs.client.gui.customoverlay.OverlayCustom;
|
||||
import noppes.npcs.client.gui.hud.ClientHudManager;
|
||||
import noppes.npcs.client.gui.hud.CompassHudComponent;
|
||||
@@ -36,6 +38,7 @@ import noppes.npcs.controllers.data.FramePart;
|
||||
import noppes.npcs.controllers.data.MarkData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import somehussar.gui.guides.GuideController;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
@@ -79,6 +82,12 @@ public class ClientEventHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void worldEventLoad(WorldEvent.Load event) {
|
||||
GuideController.resetGlint();
|
||||
GuideController.handleWorldJoin();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onItemTooltip(ItemTooltipEvent event) {
|
||||
AuctionTooltipHandler.onItemTooltip(event);
|
||||
|
||||
@@ -254,14 +254,13 @@ import noppes.npcs.items.ItemNpcTool;
|
||||
import noppes.npcs.items.ItemScripted;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import tconstruct.client.tabs.InventoryTabCustomNpc;
|
||||
import tconstruct.client.tabs.InventoryTabVanilla;
|
||||
import tconstruct.client.tabs.TabRegistry;
|
||||
import tconstruct.client.tabs.*;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
@@ -386,14 +385,34 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForge.EVENT_BUS.register(new LightningHandler());
|
||||
|
||||
if (ConfigClient.InventoryGuiEnabled) {
|
||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||
if (TabRegistry.getTabList().isEmpty()) {
|
||||
TabRegistry.registerTab(new InventoryTabVanilla());
|
||||
}
|
||||
TabRegistry.registerTab(new InventoryTabCustomNpc());
|
||||
setupTabs();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupTabs() {
|
||||
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
||||
|
||||
ensureInventoryTabIsFirst();
|
||||
|
||||
TabRegistry.getTabList().add(1, new InventoryTabGuides());
|
||||
TabRegistry.registerTab(new InventoryTabCustomNpc());
|
||||
}
|
||||
|
||||
private void ensureInventoryTabIsFirst() {
|
||||
List<AbstractTab> tabList = TabRegistry.getTabList();
|
||||
|
||||
// Find the first inventory tab or create one.
|
||||
InventoryTabVanilla vanillaTab = tabList.stream()
|
||||
.filter(InventoryTabVanilla.class::isInstance)
|
||||
.map(InventoryTabVanilla.class::cast)
|
||||
.findFirst()
|
||||
.orElseGet(InventoryTabVanilla::new);
|
||||
|
||||
// Move the inventory tab to be the FIRST in the list no matter what.
|
||||
tabList.remove(vanillaTab);
|
||||
tabList.add(0, vanillaTab);
|
||||
}
|
||||
|
||||
public FakePlayer getCommandPlayer(IWorld world) {
|
||||
return (FakePlayer) (new EntityCustomNpc(world.getMCWorld())).getFakePlayer();
|
||||
}
|
||||
|
||||
@@ -288,10 +288,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
// Set the script context for context-aware hook autocomplete
|
||||
activeArea.setScriptContext(getScriptContext());
|
||||
updateScriptDocumentImports(activeArea, container);
|
||||
|
||||
activeArea.enableCodeHighlighting();
|
||||
|
||||
updateScriptDocumentImports(activeArea, container);
|
||||
|
||||
// Setup fullscreen key binding
|
||||
GuiScriptTextArea.KEYS.FULLSCREEN.setTask(e -> {
|
||||
if (e.isPress()) {
|
||||
@@ -299,6 +299,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
});
|
||||
|
||||
activeArea.enableCodeHighlighting();
|
||||
this.addTextField(activeArea);
|
||||
|
||||
// ==================== FULLSCREEN BUTTON ====================
|
||||
@@ -457,10 +458,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
this.getTextField(2).setText(this.getTextField(2).getText() + addString);
|
||||
previousHookClicked = "";
|
||||
|
||||
GuiScriptTextArea activeArea = getActiveScriptArea();
|
||||
updateScriptDocumentImports(activeArea, container);
|
||||
activeArea.enableCodeHighlighting();
|
||||
|
||||
updateScriptDocumentImports(getActiveScriptArea(), container);
|
||||
} else {
|
||||
previousHookClicked = hook;
|
||||
}
|
||||
@@ -486,6 +484,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
for (String fqn : ctx.getNamespaceFQNs())
|
||||
wildcardImports.add(fqn + ".*");
|
||||
activeArea.addImplicitImports(wildcardImports.toArray(new String[0]));
|
||||
|
||||
|
||||
// Format to update which implicit imports are actually used
|
||||
activeArea.formatCodeText();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3504,6 +3504,9 @@ public class GuiScriptTextArea extends GuiNpcTextField {
|
||||
public void setLanguage(String language) {
|
||||
if (this.container != null) {
|
||||
this.container.setLanguage(language);
|
||||
if (this.enableCodeHighlighting) {
|
||||
this.container.formatCodeText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+154
-287
@@ -159,50 +159,6 @@ public class ScriptDocument {
|
||||
// Populated in inferLambdaParameterTypes() (method calls, constructors, field assignments).
|
||||
// Consumed by resolveExpressionType() to avoid re-inferring lambda context.
|
||||
private final Map<Integer, LambdaCacheEntry> lambdaCache = new HashMap<>();
|
||||
|
||||
// Per-format-cycle cache for resolveSimpleName results.
|
||||
// Avoids repeated wildcard-package Class.forName() scans for the same simple name.
|
||||
// Key: simple name, Value: resolved TypeInfo (may be unresolved for cached misses).
|
||||
// Cleared at start of each formatCodeText() cycle.
|
||||
private final Map<String, TypeInfo> simpleNameCache = new HashMap<>();
|
||||
|
||||
// Profiler accumulators for resolve chain diagnosis (active only when ScriptProfiler.isEnabled())
|
||||
private long profResolveTypePosNs, profResolveTypeNs, profSubstituteNs, profFindEnclosingNs;
|
||||
private long profTrackUsageOverheadNs, profResolveBaseNs, profCachedSimpleNs;
|
||||
private int profResolveTypePosCalls, profResolveTypeCalls, profFindEnclosingCalls;
|
||||
private int profCacheHits, profCacheMisses;
|
||||
private int profResolveBasePrimitive, profResolveBaseString, profResolveBaseScript;
|
||||
private int profResolveBaseDotName, profResolveBaseSimple;
|
||||
|
||||
private void resetResolveProfiler() {
|
||||
profResolveTypePosNs = profResolveTypeNs = profSubstituteNs = profFindEnclosingNs = 0;
|
||||
profTrackUsageOverheadNs = profResolveBaseNs = profCachedSimpleNs = 0;
|
||||
profResolveTypePosCalls = profResolveTypeCalls = profFindEnclosingCalls = 0;
|
||||
profCacheHits = profCacheMisses = 0;
|
||||
profResolveBasePrimitive = profResolveBaseString = profResolveBaseScript = 0;
|
||||
profResolveBaseDotName = profResolveBaseSimple = 0;
|
||||
}
|
||||
|
||||
private void printResolveProfiler() {
|
||||
System.out.println(" [resolve-profiler] ---- resolve chain breakdown ----");
|
||||
emitAccumulatedNanos("resolveType(name,pos) TOTAL", profResolveTypePosNs);
|
||||
System.out.println(String.format(" [resolve-profiler] calls: %d", profResolveTypePosCalls));
|
||||
emitAccumulatedNanos(" resolveType(name) inner", profResolveTypeNs);
|
||||
System.out.println(String.format(" [resolve-profiler] calls: %d", profResolveTypeCalls));
|
||||
emitAccumulatedNanos(" substituteTypeParams", profSubstituteNs);
|
||||
emitAccumulatedNanos(" findEnclosingScriptType", profFindEnclosingNs);
|
||||
System.out.println(String.format(" [resolve-profiler] findEnclosing calls: %d", profFindEnclosingCalls));
|
||||
emitAccumulatedNanos(" trackUsage overhead", profTrackUsageOverheadNs);
|
||||
emitAccumulatedNanos(" resolveBase lambda", profResolveBaseNs);
|
||||
emitAccumulatedNanos(" cachedResolveSimpleName", profCachedSimpleNs);
|
||||
System.out.println(String.format(" [resolve-profiler] cache hits: %d, misses: %d, rate: %.1f%%",
|
||||
profCacheHits, profCacheMisses,
|
||||
(profCacheHits + profCacheMisses) > 0 ? 100.0 * profCacheHits / (profCacheHits + profCacheMisses) : 0));
|
||||
System.out.println(String.format(" [resolve-profiler] resolveBase branches: primitive=%d string=%d script=%d dotName=%d simple=%d",
|
||||
profResolveBasePrimitive, profResolveBaseString, profResolveBaseScript,
|
||||
profResolveBaseDotName, profResolveBaseSimple));
|
||||
System.out.println(" [resolve-profiler] ---- end ----");
|
||||
}
|
||||
|
||||
// Thread-local to communicate SAM conflict errors from resolveIdentifier back to parseMethodArguments
|
||||
// Set when injectSamParameterTypes detects a conflict, cleared after argument is created
|
||||
@@ -412,54 +368,45 @@ public class ScriptDocument {
|
||||
* fieldAccesses, etc.) are shared between languages.
|
||||
*/
|
||||
public void formatCodeText() {
|
||||
ScriptProfiler.begin("formatCodeText");
|
||||
try {
|
||||
errors.clear();
|
||||
imports.clear();
|
||||
methods.clear();
|
||||
globalFields.clear();
|
||||
wildcardPackages.clear();
|
||||
excludedRanges.clear();
|
||||
methodLocals.clear();
|
||||
topLevelLocals.clear();
|
||||
scriptTypes.clear();
|
||||
scriptTypesByFullName.clear();
|
||||
scriptTypesByDotName.clear();
|
||||
innerScopes.clear();
|
||||
methodCalls.clear();
|
||||
externalFieldAssignments.clear();
|
||||
declarationErrors.clear();
|
||||
scriptMethodSamContexts.clear();
|
||||
objectLiterals.clear();
|
||||
lambdaCache.clear();
|
||||
simpleNameCache.clear();
|
||||
// Clear previous state (same for both languages)
|
||||
errors.clear();
|
||||
imports.clear();
|
||||
methods.clear();
|
||||
globalFields.clear();
|
||||
wildcardPackages.clear();
|
||||
excludedRanges.clear();
|
||||
methodLocals.clear();
|
||||
topLevelLocals.clear();
|
||||
scriptTypes.clear();
|
||||
scriptTypesByFullName.clear();
|
||||
scriptTypesByDotName.clear();
|
||||
innerScopes.clear();
|
||||
methodCalls.clear();
|
||||
externalFieldAssignments.clear();
|
||||
declarationErrors.clear();
|
||||
scriptMethodSamContexts.clear();
|
||||
objectLiterals.clear();
|
||||
lambdaCache.clear();
|
||||
|
||||
// Unified pipeline for both languages
|
||||
List<ScriptLine.Mark> marks = formatUnified();
|
||||
|
||||
List<ScriptLine.Mark> marks = formatUnified();
|
||||
// Phase 5: Resolve conflicts and sort
|
||||
marks = resolveConflicts(marks);
|
||||
|
||||
ScriptProfiler.begin("resolveConflicts");
|
||||
marks = resolveConflicts(marks);
|
||||
ScriptProfiler.end("resolveConflicts");
|
||||
|
||||
ScriptProfiler.begin("buildTokensPerLine");
|
||||
for (ScriptLine line : lines) {
|
||||
line.buildTokensFromMarks(marks, text, this);
|
||||
}
|
||||
ScriptProfiler.end("buildTokensPerLine");
|
||||
|
||||
ScriptProfiler.begin("removeUnusedImplicitImports");
|
||||
removeUnusedImplicitImports();
|
||||
ScriptProfiler.end("removeUnusedImplicitImports");
|
||||
|
||||
ScriptProfiler.begin("computeIndentGuides");
|
||||
computeIndentGuides(marks);
|
||||
ScriptProfiler.end("computeIndentGuides");
|
||||
|
||||
ScriptProfiler.begin("populateErrors");
|
||||
populateErrors();
|
||||
ScriptProfiler.end("populateErrors");
|
||||
} finally {
|
||||
ScriptProfiler.end("formatCodeText");
|
||||
// Phase 6: Build tokens for each line
|
||||
for (ScriptLine line : lines) {
|
||||
line.buildTokensFromMarks(marks, text, this);
|
||||
}
|
||||
|
||||
// Phase 6.5: Now that tokens are built, remove implicit imports that aren't actually used
|
||||
removeUnusedImplicitImports();
|
||||
|
||||
// Phase 7: Compute indent guides
|
||||
computeIndentGuides(marks);
|
||||
|
||||
// Phase 8: Populate centralized error list from all error sources
|
||||
populateErrors();
|
||||
}
|
||||
|
||||
// Store the last JS analyzer for autocomplete (deprecated - use methods/globalFields/methodLocals instead)
|
||||
@@ -481,23 +428,17 @@ public class ScriptDocument {
|
||||
private List<ScriptLine.Mark> formatUnified() {
|
||||
TypeChecker.enterTypeCheckingContext(isJavaScript());
|
||||
|
||||
ScriptProfiler.begin("findExcludedRanges");
|
||||
// Phase 1: Find excluded regions (strings/comments) - same for both
|
||||
findExcludedRanges();
|
||||
ScriptProfiler.end("findExcludedRanges");
|
||||
|
||||
ScriptProfiler.begin("parseImports");
|
||||
// Phase 2: Parse imports (Java only, JS skips this)
|
||||
parseImports();
|
||||
ScriptProfiler.end("parseImports");
|
||||
|
||||
ScriptProfiler.begin("parseStructure");
|
||||
// Phase 3: Parse structure (methods, fields, locals) - language aware
|
||||
parseStructure();
|
||||
ScriptProfiler.end("parseStructure");
|
||||
|
||||
ScriptProfiler.begin("buildMarks");
|
||||
List<ScriptLine.Mark> result = buildMarks();
|
||||
ScriptProfiler.end("buildMarks");
|
||||
|
||||
return result;
|
||||
// Phase 4: Build marks - language aware
|
||||
return buildMarks();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -796,48 +737,41 @@ public class ScriptDocument {
|
||||
* Uses the SAME logic and data structures for both Java and JavaScript.
|
||||
*/
|
||||
private void parseStructure() {
|
||||
// Clear import references before re-parsing
|
||||
for (ImportData imp : imports) {
|
||||
imp.clearReferences();
|
||||
}
|
||||
|
||||
// Parse script-defined types (classes, interfaces, enums) - Java only
|
||||
if (!isJavaScript()) {
|
||||
ScriptProfiler.begin("parseScriptTypes");
|
||||
parseScriptTypes();
|
||||
ScriptProfiler.end("parseScriptTypes");
|
||||
}
|
||||
|
||||
ScriptProfiler.begin("parseMethodDeclarations");
|
||||
// Parse methods/functions - UNIFIED for both languages
|
||||
parseMethodDeclarations();
|
||||
ScriptProfiler.end("parseMethodDeclarations");
|
||||
|
||||
ScriptProfiler.begin("parseInnerCallableScopes");
|
||||
// Parse inner callable scopes (lambdas, JS function expressions)
|
||||
parseInnerCallableScopes();
|
||||
ScriptProfiler.end("parseInnerCallableScopes");
|
||||
|
||||
ScriptProfiler.begin("parseLocalVariables");
|
||||
// Parse local variables inside methods/functions - UNIFIED for both languages
|
||||
parseLocalVariables();
|
||||
ScriptProfiler.end("parseLocalVariables");
|
||||
|
||||
ScriptProfiler.begin("parseGlobalFields");
|
||||
// Parse global fields (outside methods) - UNIFIED for both languages
|
||||
parseGlobalFields();
|
||||
ScriptProfiler.end("parseGlobalFields");
|
||||
|
||||
ScriptProfiler.begin("inferLambdaParameterTypes");
|
||||
// Must run before parseAssignments: sets inferredType on lambda params so that
|
||||
// body variable resolution (e.g. "act" in "int x = act.getData()") works correctly.
|
||||
inferLambdaParameterTypes();
|
||||
ScriptProfiler.end("inferLambdaParameterTypes");
|
||||
|
||||
ScriptProfiler.begin("parseAssignments");
|
||||
// Parse and validate assignments (reassignments) - UNIFIED for both languages
|
||||
parseAssignments();
|
||||
ScriptProfiler.end("parseAssignments");
|
||||
|
||||
ScriptProfiler.begin("parseObjectLiterals");
|
||||
// Cache object literals after globals/locals are available for accurate value-type inference
|
||||
parseObjectLiterals();
|
||||
ScriptProfiler.end("parseObjectLiterals");
|
||||
|
||||
// Detect method overrides and interface implementations for script types - Java only
|
||||
if (!isJavaScript()) {
|
||||
ScriptProfiler.begin("detectMethodInheritance");
|
||||
detectMethodInheritance();
|
||||
ScriptProfiler.end("detectMethodInheritance");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4364,7 +4298,10 @@ public class ScriptDocument {
|
||||
}
|
||||
|
||||
public TypeInfo resolveType(String typeName) {
|
||||
profResolveTypeCalls++;
|
||||
/**
|
||||
* Resolve a JS type name to unified TypeInfo.
|
||||
* Handles JS primitives, .d.ts defined types, and falls back to Java types.
|
||||
*/
|
||||
if (isJavaScript())
|
||||
return typeResolver.resolveJSType(typeName);
|
||||
|
||||
@@ -4436,22 +4373,12 @@ public class ScriptDocument {
|
||||
* @return The resolved TypeInfo, or an unresolved TypeInfo if not found
|
||||
*/
|
||||
public TypeInfo resolveType(String typeName, int position) {
|
||||
boolean p = ScriptProfiler.isEnabled();
|
||||
long t0 = p ? System.nanoTime() : 0;
|
||||
profResolveTypePosCalls++;
|
||||
|
||||
long t1 = p ? System.nanoTime() : 0;
|
||||
// First: delegate to the standard (positionless) resolver
|
||||
TypeInfo resolved = resolveType(typeName);
|
||||
if (p) profResolveTypeNs += System.nanoTime() - t1;
|
||||
|
||||
// If already resolved, no need for positional fallback
|
||||
if (resolved != null && resolved.isResolved()) {
|
||||
long tSub = p ? System.nanoTime() : 0;
|
||||
TypeInfo result = substituteTypeParams(resolved, position);
|
||||
if (p) {
|
||||
profSubstituteNs += System.nanoTime() - tSub;
|
||||
profResolveTypePosNs += System.nanoTime() - t0;
|
||||
}
|
||||
return result;
|
||||
return substituteTypeParams(resolved, position);
|
||||
}
|
||||
|
||||
if (typeName != null && !typeName.contains(".")) {
|
||||
@@ -4459,30 +4386,27 @@ public class ScriptDocument {
|
||||
String baseTypeName = arraySplit.base;
|
||||
int arrayDims = arraySplit.dimensions;
|
||||
|
||||
long tEnc = p ? System.nanoTime() : 0;
|
||||
profFindEnclosingCalls++;
|
||||
ScriptTypeInfo enclosing = findEnclosingScriptType(position);
|
||||
if (p) profFindEnclosingNs += System.nanoTime() - tEnc;
|
||||
|
||||
while (enclosing != null) {
|
||||
// Check if the name is a declared type parameter on this class (e.g., E in class Box<E>)
|
||||
TypeParamInfo typeParam = enclosing.getDeclaredTypeParam(baseTypeName);
|
||||
if (typeParam != null) {
|
||||
TypeInfo result = TypeInfo.typeParameter(baseTypeName, typeParam);
|
||||
for (int i = 0; i < arrayDims; i++) result = TypeInfo.arrayOf(result);
|
||||
if (p) profResolveTypePosNs += System.nanoTime() - t0;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Check inner classes
|
||||
ScriptTypeInfo inner = enclosing.getInnerClass(typeName);
|
||||
if (inner != null) {
|
||||
if (p) profResolveTypePosNs += System.nanoTime() - t0;
|
||||
return inner;
|
||||
}
|
||||
// Move up to the parent type — inner classes of outer types are also in scope
|
||||
enclosing = enclosing.getOuterClass();
|
||||
}
|
||||
}
|
||||
|
||||
if (p) profResolveTypePosNs += System.nanoTime() - t0;
|
||||
// Return whatever resolveType() returned (possibly unresolved)
|
||||
return resolved;
|
||||
}
|
||||
|
||||
@@ -4492,50 +4416,48 @@ public class ScriptDocument {
|
||||
* Used for Java/Groovy scripts.
|
||||
*/
|
||||
private TypeInfo resolveTypeAndTrackUsage(String typeName) {
|
||||
boolean p = ScriptProfiler.isEnabled();
|
||||
long tOverhead = p ? System.nanoTime() : 0;
|
||||
|
||||
if (typeName == null || typeName.isEmpty())
|
||||
return TypeInfo.unresolved(typeName, typeName);
|
||||
|
||||
final String normalized = typeName.trim();
|
||||
final String normalizedFinal = stripLeadingModifiers(normalized);
|
||||
|
||||
// Split array suffixes first
|
||||
TypeStringNormalizer.ArraySplit arraySplit = TypeStringNormalizer.splitArraySuffixes(normalizedFinal);
|
||||
String baseExpr = arraySplit.base;
|
||||
int arrayDims = arraySplit.dimensions;
|
||||
|
||||
if (p) profTrackUsageOverheadNs += System.nanoTime() - tOverhead;
|
||||
|
||||
// Base type resolver with import tracking
|
||||
Function<String, TypeInfo> resolveBase = baseName -> {
|
||||
boolean pp = ScriptProfiler.isEnabled();
|
||||
long tBase = pp ? System.nanoTime() : 0;
|
||||
TypeInfo resolved;
|
||||
|
||||
// Primitives
|
||||
if (TypeResolver.isPrimitiveType(baseName)) {
|
||||
profResolveBasePrimitive++;
|
||||
resolved = TypeInfo.fromPrimitive(baseName);
|
||||
}
|
||||
// Common java.lang.String
|
||||
else if ("String".equals(baseName)) {
|
||||
profResolveBaseString++;
|
||||
resolved = typeResolver.resolveFullName("java.lang.String");
|
||||
}
|
||||
// Script-defined types (simple names only)
|
||||
else if (!baseName.contains(".") && scriptTypes.containsKey(baseName)) {
|
||||
profResolveBaseScript++;
|
||||
resolved = scriptTypes.get(baseName);
|
||||
}
|
||||
// Script-defined inner types (dot-separated, e.g., "Outer.Inner")
|
||||
// Checked before Java full-name resolution so script types shadow Java types
|
||||
else if (baseName.contains(".") && scriptTypesByDotName.containsKey(baseName)) {
|
||||
profResolveBaseScript++;
|
||||
resolved = scriptTypesByDotName.get(baseName);
|
||||
}
|
||||
// Fully-qualified Java types
|
||||
else if (baseName.contains(".")) {
|
||||
profResolveBaseDotName++;
|
||||
resolved = typeResolver.resolveFullName(baseName);
|
||||
// Fallback: "SimpleName.InnerClass" where SimpleName is a known import
|
||||
// e.g., "Map.Entry" when java.util.Map is imported → java.util.Map$Entry
|
||||
if (resolved == null || !resolved.isResolved()) {
|
||||
int firstDot = baseName.indexOf('.');
|
||||
String outerSimple = baseName.substring(0, firstDot);
|
||||
String innerPath = baseName.substring(firstDot + 1);
|
||||
TypeInfo outerType = cachedResolveSimpleName(outerSimple);
|
||||
TypeInfo outerType = typeResolver.resolveSimpleName(outerSimple, importsBySimpleName, wildcardPackages);
|
||||
if (outerType != null && outerType.isResolved() && outerType.getJavaClass() != null) {
|
||||
Class<?> currentClass = outerType.getJavaClass();
|
||||
for (String part : innerPath.split("\\.")) {
|
||||
@@ -4551,6 +4473,7 @@ public class ScriptDocument {
|
||||
}
|
||||
if (currentClass != null) {
|
||||
resolved = TypeInfo.fromClass(currentClass);
|
||||
// Track import usage for the outer class
|
||||
ImportData usedImport = importsBySimpleName.get(outerSimple);
|
||||
if (usedImport != null) {
|
||||
usedImport.incrementUsage();
|
||||
@@ -4567,12 +4490,11 @@ public class ScriptDocument {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Imported/simple
|
||||
else {
|
||||
profResolveBaseSimple++;
|
||||
long tSimple = pp ? System.nanoTime() : 0;
|
||||
resolved = cachedResolveSimpleName(baseName);
|
||||
if (pp) profCachedSimpleNs += System.nanoTime() - tSimple;
|
||||
resolved = typeResolver.resolveSimpleName(baseName, importsBySimpleName, wildcardPackages);
|
||||
|
||||
// Track import usage
|
||||
if (resolved != null && resolved.isResolved()) {
|
||||
ImportData usedImport = importsBySimpleName.get(baseName);
|
||||
if (usedImport != null) {
|
||||
@@ -4589,20 +4511,23 @@ public class ScriptDocument {
|
||||
}
|
||||
}
|
||||
|
||||
if (pp) profResolveBaseNs += System.nanoTime() - tBase;
|
||||
return resolved != null ? resolved : TypeInfo.unresolved(baseName, normalizedFinal);
|
||||
};
|
||||
|
||||
TypeInfo resolved;
|
||||
|
||||
// Fast path: no generics - skip expensive parsing
|
||||
if (!baseExpr.contains("<")) {
|
||||
resolved = resolveBase.apply(baseExpr);
|
||||
} else {
|
||||
// Slow path: parse and resolve generics
|
||||
GenericTypeParser.ParsedType parsed = GenericTypeParser.parse(baseExpr);
|
||||
if (parsed != null) {
|
||||
// Normalize whitespace around dots in base name
|
||||
String baseName = parsed.baseName.replaceAll("\\s*\\.\\s*", ".").trim();
|
||||
resolved = resolveBase.apply(baseName);
|
||||
|
||||
// Apply generic arguments
|
||||
if (parsed.hasTypeArgs() && resolved != null && resolved.isResolved()) {
|
||||
List<TypeInfo> resolvedArgs = new ArrayList<>();
|
||||
for (GenericTypeParser.ParsedType argParsed : parsed.typeArgs) {
|
||||
@@ -4619,9 +4544,11 @@ public class ScriptDocument {
|
||||
}
|
||||
}
|
||||
} else
|
||||
// Fallback: treat as simple type
|
||||
resolved = resolveBase.apply(baseExpr);
|
||||
}
|
||||
|
||||
// Apply array dimensions
|
||||
for (int i = 0; i < arrayDims; i++) {
|
||||
resolved = TypeInfo.arrayOf(resolved);
|
||||
}
|
||||
@@ -4629,21 +4556,6 @@ public class ScriptDocument {
|
||||
return resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached wrapper for typeResolver.resolveSimpleName() that avoids repeated
|
||||
* wildcard-package scanning for the same simple name within a format cycle.
|
||||
*/
|
||||
private TypeInfo cachedResolveSimpleName(String simpleName) {
|
||||
if (simpleNameCache.containsKey(simpleName)) {
|
||||
profCacheHits++;
|
||||
return simpleNameCache.get(simpleName);
|
||||
}
|
||||
profCacheMisses++;
|
||||
TypeInfo result = typeResolver.resolveSimpleName(simpleName, importsBySimpleName, wildcardPackages);
|
||||
simpleNameCache.put(simpleName, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip only LEADING Java modifiers from a type expression.
|
||||
* This avoids breaking generic argument lists which may contain whitespace.
|
||||
@@ -4681,91 +4593,80 @@ public class ScriptDocument {
|
||||
private List<ScriptLine.Mark> buildMarks() {
|
||||
List<ScriptLine.Mark> marks = new ArrayList<>();
|
||||
|
||||
ScriptProfiler.begin("markStrings");
|
||||
// Strings first to protect their content
|
||||
addPatternMarks(marks, STRING_PATTERN, TokenType.STRING);
|
||||
ScriptProfiler.end("markStrings");
|
||||
|
||||
ScriptProfiler.begin("markJSDocElements");
|
||||
// JSDoc comments with fragmented marking (avoids conflicts with @tags and {Type})
|
||||
markJSDocElements(marks);
|
||||
ScriptProfiler.end("markJSDocElements");
|
||||
|
||||
ScriptProfiler.begin("markComments");
|
||||
// Regular comments (non-JSDoc)
|
||||
markNonJSDocComments(marks);
|
||||
ScriptProfiler.end("markComments");
|
||||
|
||||
ScriptProfiler.begin("markKeywords");
|
||||
// Keywords - same for both languages (KEYWORD_PATTERN includes JS keywords like function, var, let, const)
|
||||
addPatternMarks(marks, KEYWORD_PATTERN, TokenType.KEYWORD);
|
||||
if(isJavaScript())
|
||||
addPatternMarks(marks, KEYWORD_JS_PATTERN, TokenType.KEYWORD);
|
||||
ScriptProfiler.end("markKeywords");
|
||||
|
||||
// Numbers - same for both languages
|
||||
addPatternMarks(marks, NUMBER_PATTERN, TokenType.LITERAL);
|
||||
|
||||
if (isJavaScript()) {
|
||||
markObjectLiteralKeys(marks);
|
||||
}
|
||||
|
||||
// Import statements - Java only
|
||||
if (!isJavaScript()) {
|
||||
markImports(marks);
|
||||
}
|
||||
|
||||
// Class/interface/enum declarations - Java only
|
||||
if (!isJavaScript()) {
|
||||
markClassDeclarations(marks);
|
||||
markEnumConstants(marks);
|
||||
}
|
||||
|
||||
// Modifiers - Java only
|
||||
if (!isJavaScript()) {
|
||||
addPatternMarks(marks, MODIFIER_PATTERN, TokenType.KEYWORD);
|
||||
}
|
||||
|
||||
// Type declarations and usages - Java only (JS doesn't have explicit types)
|
||||
if (!isJavaScript()) {
|
||||
ScriptProfiler.begin("markTypeDeclarations");
|
||||
markTypeDeclarations(marks);
|
||||
ScriptProfiler.end("markTypeDeclarations");
|
||||
}
|
||||
|
||||
ScriptProfiler.begin("markMethodDeclarations");
|
||||
// Methods/functions - UNIFIED (uses shared 'methods' list)
|
||||
markMethodDeclarations(marks);
|
||||
ScriptProfiler.end("markMethodDeclarations");
|
||||
|
||||
ScriptProfiler.begin("markMethodCalls");
|
||||
// Method calls - UNIFIED (stores in shared 'methodCalls' list)
|
||||
markMethodCalls(marks);
|
||||
ScriptProfiler.end("markMethodCalls");
|
||||
|
||||
ScriptProfiler.begin("markVariables");
|
||||
// Variables and fields - UNIFIED (uses shared globalFields, methodLocals)
|
||||
markVariables(marks);
|
||||
ScriptProfiler.end("markVariables");
|
||||
|
||||
ScriptProfiler.begin("markChainedFieldAccesses");
|
||||
// Chained field accesses - UNIFIED (uses resolveVariable which handles both)
|
||||
markChainedFieldAccesses(marks);
|
||||
ScriptProfiler.end("markChainedFieldAccesses");
|
||||
|
||||
ScriptProfiler.begin("markImportedClassUsages");
|
||||
markImportedClassUsages(marks);
|
||||
ScriptProfiler.end("markImportedClassUsages");
|
||||
|
||||
// Java-specific final passes
|
||||
if (!isJavaScript()) {
|
||||
ScriptProfiler.begin("markCastTypes");
|
||||
markCastTypes(marks);
|
||||
ScriptProfiler.end("markCastTypes");
|
||||
|
||||
markUnusedImports(marks);
|
||||
// Mark method reference expressions (target::methodName)
|
||||
markMethodReferences(marks);
|
||||
}
|
||||
|
||||
// Mark lambda and method reference operators (-> and ::)
|
||||
markLambdaOperators(marks);
|
||||
|
||||
ScriptProfiler.begin("markInnerScopeParams");
|
||||
// Mark lambda/function parameters with type info
|
||||
markInnerScopeParameters(marks);
|
||||
ScriptProfiler.end("markInnerScopeParams");
|
||||
|
||||
ScriptProfiler.begin("validateLambdaReturnTypes");
|
||||
// Validate lambda return types
|
||||
validateLambdaReturnTypes(marks);
|
||||
ScriptProfiler.end("validateLambdaReturnTypes");
|
||||
|
||||
ScriptProfiler.begin("markUndefinedIdentifiers");
|
||||
// Final pass: Mark any remaining unmarked identifiers as undefined
|
||||
markUndefinedIdentifiers(marks);
|
||||
ScriptProfiler.end("markUndefinedIdentifiers");
|
||||
|
||||
return marks;
|
||||
}
|
||||
@@ -9923,83 +9824,73 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
}
|
||||
|
||||
private void markImportedClassUsages(List<ScriptLine.Mark> marks) {
|
||||
boolean profiling = ScriptProfiler.isEnabled();
|
||||
if (profiling) resetResolveProfiler();
|
||||
|
||||
// ── Loop 1: classUsage ── identifiers followed by dot
|
||||
long loop1RegexNs = 0, loop1ExcludedNs = 0, loop1ResolveNs = 0;
|
||||
int loop1Matches = 0, loop1Resolved = 0, loop1Skipped = 0;
|
||||
|
||||
long t0 = profiling ? System.nanoTime() : 0;
|
||||
// Find uppercase identifiers followed by dot (static method calls, field access)
|
||||
Pattern classUsage = Pattern.compile("\\b([A-Za-z][a-zA-Z0-9_]*)\\s*\\.");
|
||||
Matcher m = classUsage.matcher(text);
|
||||
if (profiling) loop1RegexNs = System.nanoTime() - t0;
|
||||
|
||||
while (m.find()) {
|
||||
loop1Matches++;
|
||||
String className = m.group(1);
|
||||
int start = m.start(1);
|
||||
int end = m.end(1);
|
||||
|
||||
long tExcl = profiling ? System.nanoTime() : 0;
|
||||
boolean excluded = isExcluded(start);
|
||||
if (!excluded) excluded = isInImportOrPackage(start);
|
||||
if (profiling) loop1ExcludedNs += System.nanoTime() - tExcl;
|
||||
if (excluded) { loop1Skipped++; continue; }
|
||||
if (isExcluded(start))
|
||||
continue;
|
||||
|
||||
// Skip in import/package statements
|
||||
if (isInImportOrPackage(start))
|
||||
continue;
|
||||
|
||||
// For JavaScript, first check synthetic types (Nashorn built-ins like Java, print, etc.)
|
||||
if (isJavaScript()) {
|
||||
if (typeResolver.isSyntheticType(className)) {
|
||||
SyntheticType syntheticType = typeResolver.getSyntheticType(className);
|
||||
// Mark as IMPORTED_CLASS since it's a type reference
|
||||
// Pass the TypeInfo (which the hover system can display)
|
||||
marks.add(new ScriptLine.Mark(m.start(1), m.end(1), TokenType.IMPORTED_CLASS,
|
||||
syntheticType.getTypeInfo()));
|
||||
continue;
|
||||
}
|
||||
JSTypeRegistry jsRegistry = JSTypeRegistry.getInstance();
|
||||
if (jsRegistry.isGlobalImport(className)) {
|
||||
// Mark as IMPORTED_CLASS since it's a type reference
|
||||
TypeInfo globalType = TypeInfo.fromJSTypeInfo(jsRegistry.getGlobalImportType(className));
|
||||
marks.add(new ScriptLine.Mark(m.start(1), m.end(1), TokenType.INTERFACE_DECL, globalType));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
long tRes = profiling ? System.nanoTime() : 0;
|
||||
// Use position-aware resolution so inner class names (e.g., OrbBuilder inside Outer)
|
||||
// resolve via the positional fallback that walks enclosing.getInnerClass(name).
|
||||
TypeInfo info = resolveType(className, start);
|
||||
if (profiling) loop1ResolveNs += System.nanoTime() - tRes;
|
||||
|
||||
if (info != null && info.isResolved()) {
|
||||
loop1Resolved++;
|
||||
marks.add(new ScriptLine.Mark(start, end, info.getTokenType(), info));
|
||||
} else {
|
||||
// Unknown type - mark as undefined
|
||||
marks.add(new ScriptLine.Mark(start, end, TokenType.UNDEFINED_VAR));
|
||||
}
|
||||
}
|
||||
|
||||
// ── Loop 2: typeUsage ── identifiers in type positions (new, decl, etc.)
|
||||
long loop2RegexNs = 0, loop2ExcludedNs = 0, loop2ResolveNs = 0;
|
||||
long loop2CtorParseNs = 0, loop2CtorMatchNs = 0, loop2CtorValidateNs = 0;
|
||||
long loop2QualWalkNs = 0;
|
||||
int loop2Matches = 0, loop2Resolved = 0, loop2Skipped = 0;
|
||||
int loop2CtorCalls = 0, loop2CtorSecondPass = 0;
|
||||
|
||||
t0 = profiling ? System.nanoTime() : 0;
|
||||
// Also mark uppercase identifiers in type positions (new X(), X variable, etc.)
|
||||
Pattern typeUsage = Pattern.compile("\\b(new\\s+)?([A-Za-z][a-zA-Z0-9_]*)(?:\\s*<[^>]*>)?\\s*(?:\\(|\\[|\\b[a-z])");
|
||||
Matcher tm = typeUsage.matcher(text);
|
||||
if (profiling) loop2RegexNs = System.nanoTime() - t0;
|
||||
|
||||
while (tm.find()) {
|
||||
loop2Matches++;
|
||||
String className = tm.group(2);
|
||||
String newKeyword = tm.group(1);
|
||||
int start = tm.start(2);
|
||||
int end = tm.end(2);
|
||||
|
||||
long tExcl = profiling ? System.nanoTime() : 0;
|
||||
boolean excluded = isExcluded(start);
|
||||
if (!excluded) excluded = isInImportOrPackage(start);
|
||||
if (profiling) loop2ExcludedNs += System.nanoTime() - tExcl;
|
||||
if (excluded) { loop2Skipped++; continue; }
|
||||
if (isExcluded(start))
|
||||
continue;
|
||||
|
||||
long tQual = profiling ? System.nanoTime() : 0;
|
||||
// Skip in import/package statements
|
||||
if (isInImportOrPackage(start))
|
||||
continue;
|
||||
|
||||
// When the class name is preceded by a dot (e.g., OrbBuilder in AbilityLine.OrbBuilder),
|
||||
// walk backwards to reconstruct the full qualified name and resolve via scriptTypesByDotName.
|
||||
// resolveType(simpleNameOnly) fails outside the enclosing class body; the qualified name always works.
|
||||
// We also track outerQualStart so we can detect 'new' before the full qualified name.
|
||||
String resolveKey = className;
|
||||
int outerQualStart = start;
|
||||
if (isPrecededByDot(start)) {
|
||||
@@ -10016,21 +9907,18 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
while (pos >= 0 && Character.isWhitespace(text.charAt(pos))) pos--;
|
||||
}
|
||||
}
|
||||
if (profiling) loop2QualWalkNs += System.nanoTime() - tQual;
|
||||
|
||||
long tRes = profiling ? System.nanoTime() : 0;
|
||||
TypeInfo info = resolveType(resolveKey, start);
|
||||
if (info == null || !info.isResolved()) {
|
||||
info = resolveType(className, start);
|
||||
}
|
||||
if (profiling) loop2ResolveNs += System.nanoTime() - tRes;
|
||||
|
||||
boolean isClassTypeInfo = false;
|
||||
ClassTypeInfo classRef = null;
|
||||
FieldInfo varInfo = null;
|
||||
// If not a class name, check if it's a variable holding a ClassTypeInfo
|
||||
if ((info == null || !info.isResolved()) && isJavaScript()) {
|
||||
varInfo = resolveVariable(className, start);
|
||||
if (varInfo != null && varInfo.getTypeInfo() instanceof ClassTypeInfo) {
|
||||
// Variable holds a class reference (like var File = Java.type("java.io.File"))
|
||||
classRef = (ClassTypeInfo) varInfo.getTypeInfo();
|
||||
info = classRef.getInstanceType();
|
||||
isClassTypeInfo = true;
|
||||
@@ -10038,8 +9926,10 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
}
|
||||
|
||||
if (info != null && info.isResolved()) {
|
||||
loop2Resolved++;
|
||||
boolean isNewCreation = newKeyword != null && newKeyword.trim().equals("new");
|
||||
// For dot-qualified types like 'new AbilityLine.OrbBuilder(...)', the regex never
|
||||
// captures 'new' in group 1 because 'new' precedes 'AbilityLine', not 'OrbBuilder'.
|
||||
// Detect it by checking whether outerQualStart is preceded by the 'new' keyword.
|
||||
if (!isNewCreation && outerQualStart < start) {
|
||||
int checkPos = outerQualStart - 1;
|
||||
while (checkPos >= 0 && Character.isWhitespace(text.charAt(checkPos))) checkPos--;
|
||||
@@ -10052,11 +9942,14 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
}
|
||||
boolean isConstructorDecl = info instanceof ScriptTypeInfo && className.equals(info.getSimpleName());
|
||||
|
||||
// Check if this is a "new" expression or constructor declaration
|
||||
if (isNewCreation || isConstructorDecl) {
|
||||
// Find opening paren after the class name
|
||||
int searchPos = end;
|
||||
while (searchPos < text.length() && Character.isWhitespace(text.charAt(searchPos)))
|
||||
searchPos++;
|
||||
|
||||
// Skip generic args or diamond operator (e.g., <Integer> or <>)
|
||||
if (searchPos < text.length() && text.charAt(searchPos) == '<') {
|
||||
int closeAngle = text.indexOf('>', searchPos);
|
||||
if (closeAngle >= 0) {
|
||||
@@ -10071,28 +9964,31 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
int closeParen = findMatchingParen(openParen);
|
||||
|
||||
if (closeParen >= 0) {
|
||||
// For constructor declarations, verify it's followed by opening brace
|
||||
if (isConstructorDecl && !isNewCreation) {
|
||||
int braceSearch = closeParen + 1;
|
||||
while (braceSearch < text.length() && Character.isWhitespace(text.charAt(braceSearch)))
|
||||
braceSearch++;
|
||||
|
||||
if (braceSearch >= text.length() || text.charAt(braceSearch) != '{') {
|
||||
// Not a constructor declaration, treat as normal type usage
|
||||
marks.add(new ScriptLine.Mark(start, end, info.getTokenType(), info));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
loop2CtorCalls++;
|
||||
long tParse = profiling ? System.nanoTime() : 0;
|
||||
// Parse arguments to find matching constructor
|
||||
List<MethodCallInfo.Argument> arguments = parseMethodArguments(openParen + 1, closeParen,
|
||||
null, info);
|
||||
if (profiling) loop2CtorParseNs += System.nanoTime() - tParse;
|
||||
|
||||
int argCount = arguments.size();
|
||||
TypeInfo[] argTypes = arguments.stream().map(MethodCallInfo.Argument::getResolvedType)
|
||||
.toArray(TypeInfo[]::new);
|
||||
|
||||
long tMatch = profiling ? System.nanoTime() : 0;
|
||||
|
||||
// Try to find matching constructor (may be null if not found).
|
||||
// First try exact type-match; if that fails but constructors exist, fall back to
|
||||
// arg-count match so validate() can fire a WRONG_ARG_TYPE error instead of
|
||||
// incorrectly treating the call as "no constructor matches N arguments".
|
||||
MethodInfo constructor = null;
|
||||
if (info.hasConstructors()) {
|
||||
constructor = info.findConstructor(argTypes);
|
||||
@@ -10100,23 +9996,24 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
constructor = info.findConstructor(argCount);
|
||||
}
|
||||
}
|
||||
if (profiling) loop2CtorMatchNs += System.nanoTime() - tMatch;
|
||||
|
||||
// Second pass: re-parse arguments with expected parameter types from resolved constructor
|
||||
// This enables SAM type inference for lambda arguments (e.g., Consumer<T> parameters)
|
||||
if (constructor != null && constructor.getParameters().size() == arguments.size()) {
|
||||
loop2CtorSecondPass++;
|
||||
long tParse2 = profiling ? System.nanoTime() : 0;
|
||||
arguments = parseMethodArguments(openParen + 1, closeParen, constructor, info);
|
||||
if (profiling) loop2CtorParseNs += System.nanoTime() - tParse2;
|
||||
}
|
||||
|
||||
// Create MethodCallInfo for constructor
|
||||
// Use the actual variable name (className) for variables, not the class's simple name
|
||||
MethodCallInfo ctorCall;
|
||||
if (isClassTypeInfo) {
|
||||
// Use constructor directly with variable name
|
||||
ctorCall = new MethodCallInfo(
|
||||
className,
|
||||
className, // Use variable name, not class name
|
||||
start, end,
|
||||
openParen, closeParen,
|
||||
arguments,
|
||||
classRef,
|
||||
classRef, // The actual class type
|
||||
constructor,
|
||||
false
|
||||
).setConstructor(true);
|
||||
@@ -10127,11 +10024,9 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
);
|
||||
}
|
||||
|
||||
long tVal = profiling ? System.nanoTime() : 0;
|
||||
ctorCall.validate();
|
||||
if (profiling) loop2CtorValidateNs += System.nanoTime() - tVal;
|
||||
methodCalls.add(ctorCall); // Add to methodCalls list for error tracking
|
||||
|
||||
methodCalls.add(ctorCall);
|
||||
|
||||
TokenType type = isClassTypeInfo ? varInfo.isGlobal() ? TokenType.GLOBAL_FIELD
|
||||
: TokenType.LOCAL_FIELD : TokenType.METHOD_CALL;
|
||||
@@ -10143,38 +10038,10 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
|
||||
marks.add(new ScriptLine.Mark(start, end, info.getTokenType(), info));
|
||||
} else {
|
||||
// Unknown type - mark as undefined
|
||||
marks.add(new ScriptLine.Mark(start, end, TokenType.UNDEFINED_VAR));
|
||||
}
|
||||
}
|
||||
|
||||
// ── Emit profiler sections from accumulated timings ──
|
||||
if (profiling) {
|
||||
emitAccumulatedNanos("classUsage.regexCompile", loop1RegexNs);
|
||||
emitAccumulatedNanos("classUsage.isExcluded", loop1ExcludedNs);
|
||||
emitAccumulatedNanos("classUsage.resolveType", loop1ResolveNs);
|
||||
emitAccumulatedNanos("typeUsage.regexCompile", loop2RegexNs);
|
||||
emitAccumulatedNanos("typeUsage.isExcluded", loop2ExcludedNs);
|
||||
emitAccumulatedNanos("typeUsage.qualWalk", loop2QualWalkNs);
|
||||
emitAccumulatedNanos("typeUsage.resolveType", loop2ResolveNs);
|
||||
emitAccumulatedNanos("typeUsage.ctorParse", loop2CtorParseNs);
|
||||
emitAccumulatedNanos("typeUsage.ctorMatch", loop2CtorMatchNs);
|
||||
emitAccumulatedNanos("typeUsage.ctorValidate", loop2CtorValidateNs);
|
||||
|
||||
System.out.println("[markImportedClassUsages] Loop1: " + loop1Matches + " matches, "
|
||||
+ loop1Skipped + " skipped, " + loop1Resolved + " resolved"
|
||||
+ " | Loop2: " + loop2Matches + " matches, " + loop2Skipped + " skipped, "
|
||||
+ loop2Resolved + " resolved, " + loop2CtorCalls + " ctors ("
|
||||
+ loop2CtorSecondPass + " 2nd-pass)");
|
||||
|
||||
printResolveProfiler();
|
||||
}
|
||||
}
|
||||
|
||||
private void emitAccumulatedNanos(String name, long nanos) {
|
||||
double ms = nanos / 1_000_000.0;
|
||||
if (ms >= 0.01) {
|
||||
System.out.println(String.format(" [profiler] %-30s %8.2f ms", name, ms));
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== PHASE 5: CONFLICT RESOLUTION ====================
|
||||
@@ -11147,7 +11014,7 @@ for (ScriptTypeInfo type:scriptTypes.values()) {
|
||||
Set<TypeInfo> types = new HashSet<>();
|
||||
for (ImportData imp : imports) {
|
||||
if (!imp.isWildcard() && imp.isResolved()) {
|
||||
TypeInfo type = cachedResolveSimpleName(imp.getSimpleName());
|
||||
TypeInfo type = typeResolver.resolveSimpleName(imp.getSimpleName(), importsBySimpleName, wildcardPackages);
|
||||
if (type != null && type.isResolved()) {
|
||||
types.add(type);
|
||||
}
|
||||
|
||||
@@ -1,435 +0,0 @@
|
||||
package noppes.npcs.client.gui.util.script.interpreter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Profiler for the ScriptDocument parsing/marking pipeline.
|
||||
* <p>
|
||||
* <b>Usage:</b>
|
||||
* <pre>
|
||||
* ScriptProfiler.setEnabled(true);
|
||||
* ScriptProfiler.setReportingThresholdMs(5.0);
|
||||
* // Results auto-print to System.out when root section ends.
|
||||
* // Or: ScriptProfiler.getLastReport();
|
||||
* </pre>
|
||||
* <p>
|
||||
* When disabled, begin/end are single boolean checks with zero overhead.
|
||||
* Single-threaded only (Minecraft client thread).
|
||||
*/
|
||||
public final class ScriptProfiler {
|
||||
|
||||
private static boolean enabled = false;
|
||||
private static double reportingThresholdMs = 0.0;
|
||||
private static boolean autoPrint = true;
|
||||
private static int maxHistory = 50;
|
||||
|
||||
private static final Deque<ActiveSection> sectionStack = new ArrayDeque<>();
|
||||
private static final List<SectionResult> currentResults = new ArrayList<>();
|
||||
private static int currentDepth = 0;
|
||||
private static int beginSequence = 0;
|
||||
private static final Deque<ProfileSnapshot> history = new ArrayDeque<>();
|
||||
private static String lastReport = null;
|
||||
private static ProfileSnapshot lastSnapshot = null;
|
||||
private static final Map<String, AccumulatedStats> accumulatedStats = new LinkedHashMap<>();
|
||||
private static int invocationCount = 0;
|
||||
|
||||
public static void setEnabled(boolean enable) {
|
||||
enabled = enable;
|
||||
if (!enable) {
|
||||
reset();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public static void setReportingThresholdMs(double thresholdMs) {
|
||||
reportingThresholdMs = thresholdMs;
|
||||
}
|
||||
|
||||
public static void setAutoPrint(boolean auto) {
|
||||
autoPrint = auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin timing a named section. Sections nest: begin("A") -> begin("B") -> end("B") -> end("A").
|
||||
*/
|
||||
public static void begin(String name) {
|
||||
if (!enabled) return;
|
||||
sectionStack.push(new ActiveSection(name, System.nanoTime(), currentDepth, beginSequence++));
|
||||
currentDepth++;
|
||||
}
|
||||
|
||||
/**
|
||||
* End timing a named section. Must match the most recent begin().
|
||||
*/
|
||||
public static void end(String name) {
|
||||
if (!enabled) return;
|
||||
if (sectionStack.isEmpty()) {
|
||||
System.err.println("[ScriptProfiler] WARNING: end('" + name + "') called with no active section");
|
||||
return;
|
||||
}
|
||||
|
||||
ActiveSection active = sectionStack.pop();
|
||||
currentDepth--;
|
||||
|
||||
if (!active.name.equals(name)) {
|
||||
System.err.println("[ScriptProfiler] WARNING: end('" + name + "') doesn't match begin('" + active.name + "')");
|
||||
}
|
||||
|
||||
long elapsed = System.nanoTime() - active.startNano;
|
||||
currentResults.add(new SectionResult(active.name, active.depth, elapsed, active.beginOrder));
|
||||
|
||||
if (sectionStack.isEmpty()) {
|
||||
finalizeReport();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience: time a Runnable.
|
||||
*/
|
||||
public static void time(String name, Runnable work) {
|
||||
begin(name);
|
||||
try {
|
||||
work.run();
|
||||
} finally {
|
||||
end(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLastReport() {
|
||||
return lastReport;
|
||||
}
|
||||
|
||||
public static ProfileSnapshot getLastSnapshot() {
|
||||
return lastSnapshot;
|
||||
}
|
||||
|
||||
public static List<ProfileSnapshot> getHistory() {
|
||||
return new ArrayList<>(history);
|
||||
}
|
||||
|
||||
public static Map<String, AccumulatedStats> getAccumulatedStats() {
|
||||
return Collections.unmodifiableMap(accumulatedStats);
|
||||
}
|
||||
|
||||
public static int getInvocationCount() {
|
||||
return invocationCount;
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
sectionStack.clear();
|
||||
currentResults.clear();
|
||||
currentDepth = 0;
|
||||
beginSequence = 0;
|
||||
history.clear();
|
||||
lastReport = null;
|
||||
lastSnapshot = null;
|
||||
accumulatedStats.clear();
|
||||
invocationCount = 0;
|
||||
}
|
||||
|
||||
public static void resetStats() {
|
||||
history.clear();
|
||||
accumulatedStats.clear();
|
||||
invocationCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary of accumulated stats across all invocations -
|
||||
* identifies consistent bottlenecks vs. one-off spikes.
|
||||
*/
|
||||
public static String getAccumulatedReport() {
|
||||
if (accumulatedStats.isEmpty()) {
|
||||
return "[ScriptProfiler] No accumulated data.";
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("\n============================================================\n");
|
||||
sb.append(" SCRIPT PROFILER - ACCUMULATED STATS\n");
|
||||
sb.append(" Invocations: ").append(invocationCount).append("\n");
|
||||
sb.append("============================================================\n");
|
||||
sb.append(String.format(" %-30s | %7s | %7s | %7s\n", "Section", "Avg(ms)", "Max(ms)", "Min(ms)"));
|
||||
sb.append("------------------------------------------------------------\n");
|
||||
|
||||
for (Map.Entry<String, AccumulatedStats> entry : accumulatedStats.entrySet()) {
|
||||
AccumulatedStats stats = entry.getValue();
|
||||
String indent = getIndent(stats.depth);
|
||||
String label = indent + truncate(entry.getKey(), 30 - indent.length());
|
||||
sb.append(String.format(" %-30s | %7.2f | %7.2f | %7.2f\n",
|
||||
label, stats.getAverageMs(), stats.getMaxMs(), stats.getMinMs()));
|
||||
}
|
||||
|
||||
sb.append("============================================================\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// ======================== Internals ========================
|
||||
|
||||
private static void finalizeReport() {
|
||||
invocationCount++;
|
||||
|
||||
List<SectionResult> results = new ArrayList<>(currentResults);
|
||||
Collections.sort(results, new Comparator<SectionResult>() {
|
||||
public int compare(SectionResult a, SectionResult b) {
|
||||
return Integer.compare(a.beginOrder, b.beginOrder);
|
||||
}
|
||||
});
|
||||
ProfileSnapshot snapshot = new ProfileSnapshot(results, System.currentTimeMillis());
|
||||
lastSnapshot = snapshot;
|
||||
|
||||
history.addLast(snapshot);
|
||||
while (history.size() > maxHistory) {
|
||||
history.removeFirst();
|
||||
}
|
||||
|
||||
for (SectionResult r : results) {
|
||||
AccumulatedStats stats = accumulatedStats.get(r.name);
|
||||
if (stats == null) {
|
||||
stats = new AccumulatedStats(r.depth);
|
||||
accumulatedStats.put(r.name, stats);
|
||||
}
|
||||
stats.record(r.elapsedNanos);
|
||||
}
|
||||
|
||||
String report = buildReport(snapshot);
|
||||
lastReport = report;
|
||||
|
||||
if (autoPrint) {
|
||||
double totalMs = snapshot.getTotalMs();
|
||||
if (totalMs >= reportingThresholdMs) {
|
||||
System.out.println(report);
|
||||
}
|
||||
}
|
||||
|
||||
currentResults.clear();
|
||||
currentDepth = 0;
|
||||
beginSequence = 0;
|
||||
}
|
||||
|
||||
private static String buildReport(ProfileSnapshot snapshot) {
|
||||
List<SectionResult> results = snapshot.results;
|
||||
if (results.isEmpty()) return "[ScriptProfiler] Empty report.";
|
||||
|
||||
SectionResult root = null;
|
||||
for (SectionResult r : results) {
|
||||
if (r.depth == 0) {
|
||||
root = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (root == null) root = results.get(0);
|
||||
|
||||
double totalMs = root.elapsedNanos / 1_000_000.0;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("\n================================================================\n");
|
||||
sb.append(" SCRIPT DOCUMENT PROFILER - Pipeline Breakdown\n");
|
||||
sb.append(" Total: ").append(String.format("%.2fms", totalMs));
|
||||
sb.append(" | Lines: ").append(getLineCount());
|
||||
sb.append(" | Chars: ").append(getCharCount());
|
||||
sb.append("\n================================================================\n");
|
||||
sb.append(String.format(" %-36s | %8s | %5s | %s\n", "Stage", "Time(ms)", " % ", "Bar"));
|
||||
sb.append("----------------------------------------------------------------\n");
|
||||
|
||||
for (SectionResult r : results) {
|
||||
double ms = r.elapsedNanos / 1_000_000.0;
|
||||
double pct = (root.elapsedNanos > 0) ? (100.0 * r.elapsedNanos / root.elapsedNanos) : 0;
|
||||
String indent = getIndent(r.depth);
|
||||
String label = indent + truncate(r.name, 36 - indent.length());
|
||||
String bar = makeBar(pct, 8);
|
||||
|
||||
String flag = "";
|
||||
if (r.depth > 0 && (pct > 20.0 || ms > 5.0)) {
|
||||
flag = " << SLOW";
|
||||
}
|
||||
|
||||
sb.append(String.format(" %-36s | %8.2f | %4.1f%% | %-8s %s\n",
|
||||
label, ms, pct, bar, flag));
|
||||
}
|
||||
|
||||
long childSum = 0;
|
||||
for (SectionResult r : results) {
|
||||
if (r.depth == 1) {
|
||||
childSum += r.elapsedNanos;
|
||||
}
|
||||
}
|
||||
if (root.elapsedNanos > 0) {
|
||||
long unaccounted = root.elapsedNanos - childSum;
|
||||
if (unaccounted > 0) {
|
||||
double uMs = unaccounted / 1_000_000.0;
|
||||
double uPct = 100.0 * unaccounted / root.elapsedNanos;
|
||||
sb.append(String.format(" %-36s | %8.2f | %4.1f%% | %-8s\n",
|
||||
" (overhead/unlisted)", uMs, uPct, makeBar(uPct, 8)));
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("================================================================\n");
|
||||
sb.append(buildBottleneckSummary(results, root.elapsedNanos));
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String buildBottleneckSummary(List<SectionResult> results, long totalNanos) {
|
||||
if (results.size() <= 1) return "";
|
||||
|
||||
List<SectionResult> sorted = new ArrayList<>();
|
||||
for (SectionResult r : results) {
|
||||
if (r.depth > 0) sorted.add(r);
|
||||
}
|
||||
Collections.sort(sorted, new Comparator<SectionResult>() {
|
||||
public int compare(SectionResult a, SectionResult b) {
|
||||
return Long.compare(b.elapsedNanos, a.elapsedNanos);
|
||||
}
|
||||
});
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(" Top bottlenecks:\n");
|
||||
int count = Math.min(3, sorted.size());
|
||||
for (int i = 0; i < count; i++) {
|
||||
SectionResult r = sorted.get(i);
|
||||
double ms = r.elapsedNanos / 1_000_000.0;
|
||||
double pct = totalNanos > 0 ? (100.0 * r.elapsedNanos / totalNanos) : 0;
|
||||
sb.append(String.format(" %d. %-30s %7.2fms (%4.1f%%)\n", i + 1, r.name, ms, pct));
|
||||
}
|
||||
sb.append("\n");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String getIndent(int depth) {
|
||||
if (depth <= 0) return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < depth; i++) sb.append(" ");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String truncate(String s, int max) {
|
||||
if (max <= 0) return "";
|
||||
if (s.length() <= max) return s;
|
||||
return s.substring(0, max - 2) + "..";
|
||||
}
|
||||
|
||||
private static String makeBar(double pct, int maxLen) {
|
||||
int filled = (int) Math.round(pct / 100.0 * maxLen);
|
||||
filled = Math.min(filled, maxLen);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < filled; i++) sb.append('#');
|
||||
for (int i = filled; i < maxLen; i++) sb.append('.');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String pad(int n) {
|
||||
if (n <= 0) return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < n; i++) sb.append(' ');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static int getLineCount() {
|
||||
ScriptDocument doc = ScriptDocument.INSTANCE;
|
||||
return doc != null ? doc.getLines().size() : 0;
|
||||
}
|
||||
|
||||
private static int getCharCount() {
|
||||
ScriptDocument doc = ScriptDocument.INSTANCE;
|
||||
return doc != null ? doc.getText().length() : 0;
|
||||
}
|
||||
|
||||
// ======================== Data Classes ========================
|
||||
|
||||
private static class ActiveSection {
|
||||
final String name;
|
||||
final long startNano;
|
||||
final int depth;
|
||||
final int beginOrder;
|
||||
|
||||
ActiveSection(String name, long startNano, int depth, int beginOrder) {
|
||||
this.name = name;
|
||||
this.startNano = startNano;
|
||||
this.depth = depth;
|
||||
this.beginOrder = beginOrder;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SectionResult {
|
||||
public final String name;
|
||||
public final int depth;
|
||||
public final long elapsedNanos;
|
||||
final int beginOrder;
|
||||
|
||||
SectionResult(String name, int depth, long elapsedNanos, int beginOrder) {
|
||||
this.name = name;
|
||||
this.depth = depth;
|
||||
this.elapsedNanos = elapsedNanos;
|
||||
this.beginOrder = beginOrder;
|
||||
}
|
||||
|
||||
public double getElapsedMs() {
|
||||
return elapsedNanos / 1_000_000.0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProfileSnapshot {
|
||||
public final List<SectionResult> results;
|
||||
public final long timestampMs;
|
||||
|
||||
ProfileSnapshot(List<SectionResult> results, long timestampMs) {
|
||||
this.results = Collections.unmodifiableList(results);
|
||||
this.timestampMs = timestampMs;
|
||||
}
|
||||
|
||||
public double getTotalMs() {
|
||||
if (results.isEmpty()) return 0;
|
||||
return results.get(0).getElapsedMs();
|
||||
}
|
||||
|
||||
public double getSectionMs(String name) {
|
||||
for (SectionResult r : results) {
|
||||
if (r.name.equals(name)) return r.getElapsedMs();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AccumulatedStats {
|
||||
public final int depth;
|
||||
private long totalNanos;
|
||||
private long maxNanos;
|
||||
private long minNanos;
|
||||
private int count;
|
||||
|
||||
AccumulatedStats(int depth) {
|
||||
this.depth = depth;
|
||||
this.totalNanos = 0;
|
||||
this.maxNanos = Long.MIN_VALUE;
|
||||
this.minNanos = Long.MAX_VALUE;
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
void record(long nanos) {
|
||||
totalNanos += nanos;
|
||||
if (nanos > maxNanos) maxNanos = nanos;
|
||||
if (nanos < minNanos) minNanos = nanos;
|
||||
count++;
|
||||
}
|
||||
|
||||
public double getAverageMs() {
|
||||
return count > 0 ? (totalNanos / (double) count) / 1_000_000.0 : 0;
|
||||
}
|
||||
|
||||
public double getMaxMs() {
|
||||
return maxNanos != Long.MIN_VALUE ? maxNanos / 1_000_000.0 : 0;
|
||||
}
|
||||
|
||||
public double getMinMs() {
|
||||
return minNanos != Long.MAX_VALUE ? minNanos / 1_000_000.0 : 0;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
private ScriptProfiler() {}
|
||||
}
|
||||
@@ -190,9 +190,6 @@ public class ScriptTextContainer extends JavaTextContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. initScriptEditor.setLanguage
|
||||
* 2. initScriptEditorTab.enableCodeHighlighting
|
||||
* 3. initScriptEditor.updateScriptDocumentImports
|
||||
* Main formatting entry point - matches JavaTextContainer signature.
|
||||
*/
|
||||
@Override
|
||||
@@ -202,9 +199,7 @@ public class ScriptTextContainer extends JavaTextContainer {
|
||||
return;
|
||||
}
|
||||
|
||||
ScriptProfiler.setEnabled(true);
|
||||
document.formatCodeText();
|
||||
ScriptProfiler.setEnabled(false);
|
||||
rebuildLineData();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
package somehussar.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
import somehussar.gui.annotationHandling.GuiFieldHandler;
|
||||
import somehussar.gui.annotationHandling.field.EditableField;
|
||||
|
||||
public class AnnotatedGui<T> extends SubGuiInterface {
|
||||
private final GuiFieldHandler.ClassMetadata metadata;
|
||||
|
||||
public AnnotatedGui(T object, String[] groups, GuiScreen parent) {
|
||||
this(object, groups, parent, 256, 216);
|
||||
}
|
||||
|
||||
public AnnotatedGui(T object, String[] groups, GuiScreen parent, int xSize, int ySize) {
|
||||
if (object != null)
|
||||
metadata = GuiFieldHandler.getMetadata(object.getClass());
|
||||
else
|
||||
metadata = null;
|
||||
setBackground("menubg.png");
|
||||
this.xSize = xSize;
|
||||
this.ySize = ySize;
|
||||
closeOnEsc = true;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
if (metadata == null)
|
||||
return;
|
||||
|
||||
int i = 0;
|
||||
for (EditableField field : metadata.getParent().getDeclaredFields()) {
|
||||
addLabel(new GuiNpcLabel(i++, field.getName(), guiLeft + 8, guiTop + i * 15 + 5));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package somehussar.gui;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import somehussar.gui.annotationHandling.field.EditableField;
|
||||
|
||||
public class ImmediateTextField extends GuiNpcTextField {
|
||||
private final EditableField editableField;
|
||||
//
|
||||
// private final GuiNpcTextField encapsulatedField;
|
||||
|
||||
public ImmediateTextField(int id, EditableField field, int xPos, int yPos) {
|
||||
this(id, field, Minecraft.getMinecraft().fontRenderer, xPos, yPos);
|
||||
}
|
||||
|
||||
public ImmediateTextField(int id, EditableField field, FontRenderer fontRenderer, int xPos, int yPos) {
|
||||
super(id, null, fontRenderer, xPos, yPos, 0, 0, null);
|
||||
|
||||
this.editableField = field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTextBox(int mousX, int mousY) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xPos, int yPos, int k) {
|
||||
xPos -= this.xPosition;
|
||||
yPos -= this.yPosition;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package somehussar.gui.annotationHandling;
|
||||
|
||||
public interface FieldConstraint {
|
||||
void validate(Object value);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package somehussar.gui.annotationHandling;
|
||||
|
||||
public final class FieldConstraints {
|
||||
|
||||
private static final FieldConstraints EMPTY =
|
||||
new FieldConstraints(new FieldConstraint[0]);
|
||||
|
||||
private final FieldConstraint[] constraints;
|
||||
|
||||
public FieldConstraints(FieldConstraint[] constraints) {
|
||||
this.constraints = constraints;
|
||||
}
|
||||
|
||||
public static FieldConstraints empty() {
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
public void validate(Object value) {
|
||||
for (FieldConstraint c : constraints) {
|
||||
c.validate(value);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return constraints.length == 0;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package somehussar.gui.annotationHandling;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface GuiEditable {
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Field {
|
||||
String value();
|
||||
|
||||
/**
|
||||
* Display order
|
||||
* Higher value = higher priority.
|
||||
*/
|
||||
int order() default 0;
|
||||
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Group {
|
||||
String value();
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Size {
|
||||
int labelWidth() default 60;
|
||||
|
||||
int fieldWidth() default 50;
|
||||
|
||||
GuiEditable.Size DEFAULT_SIZE = new GuiEditable.Size() {
|
||||
@Override
|
||||
public int labelWidth() {
|
||||
return 60;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fieldWidth() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> annotationType() {
|
||||
return GuiEditable.Size.class;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
package somehussar.gui.annotationHandling;
|
||||
|
||||
import somehussar.gui.annotationHandling.constraints.ConstraintFactory;
|
||||
import somehussar.gui.annotationHandling.constraints.NumericConstraint;
|
||||
import somehussar.gui.annotationHandling.constraints.NumericConstraintFactory;
|
||||
import somehussar.gui.annotationHandling.field.EditableField;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class GuiFieldHandler {
|
||||
|
||||
private static final Map<Class<?>, ClassMetadata> CACHE = new HashMap<>();
|
||||
private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
|
||||
|
||||
public static final Map<Class<? extends Annotation>, ConstraintFactory<?>> registry = new HashMap<>();
|
||||
|
||||
static {
|
||||
registry.put(NumericConstraint.class, new NumericConstraintFactory());
|
||||
}
|
||||
|
||||
|
||||
private GuiFieldHandler() {
|
||||
}
|
||||
|
||||
public static ClassMetadata getMetadata(Class<?> type) {
|
||||
return CACHE.computeIfAbsent(type, GuiFieldHandler::scanClass);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"RawUseOfParameterized"})
|
||||
private static ClassMetadata scanClass(Class<?> type) {
|
||||
if (!type.isAnnotationPresent(GuiEditable.class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClassMetadata parent = null;
|
||||
|
||||
Class<?> superCls = type.getSuperclass();
|
||||
if (superCls != null && superCls != Object.class) {
|
||||
parent = getMetadata(superCls);
|
||||
}
|
||||
|
||||
List<EditableField> list = new ArrayList<>();
|
||||
for (Field field : type.getDeclaredFields()) {
|
||||
EditableField editableField = createEditableField(field);
|
||||
|
||||
if (editableField != null) {
|
||||
list.add(editableField);
|
||||
}
|
||||
}
|
||||
|
||||
return new ClassMetadata(
|
||||
type,
|
||||
list.toArray(list.toArray(new EditableField[0])),
|
||||
parent
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"RawUseOfParameterized", "unchecked"})
|
||||
private static EditableField createEditableField(Field field) {
|
||||
try {
|
||||
GuiEditable.Field fieldConfig = field.getAnnotation(GuiEditable.Field.class);
|
||||
if (fieldConfig == null) return null;
|
||||
if (Modifier.isFinal(field.getModifiers())) return null;
|
||||
|
||||
GuiEditable.Size size = field.getAnnotation(GuiEditable.Size.class);
|
||||
if (size == null) size = GuiEditable.Size.DEFAULT_SIZE;
|
||||
;
|
||||
|
||||
field.setAccessible(true);
|
||||
EditableField.Builder builder = new EditableField.Builder()
|
||||
.name(fieldConfig.value())
|
||||
.type(field.getType())
|
||||
.getter(LOOKUP.unreflectGetter(field))
|
||||
.setter(LOOKUP.unreflectSetter(field))
|
||||
.constraints(buildConstraints(field))
|
||||
.order(fieldConfig.order())
|
||||
.size(size);
|
||||
|
||||
|
||||
GuiEditable.Group group = field.getAnnotation(GuiEditable.Group.class);
|
||||
if (group != null)
|
||||
builder.group(group.value());
|
||||
|
||||
|
||||
return builder.build();
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(
|
||||
"Failed to bind field: " + field, e);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"RawUseOfParameterized", "unchecked"})
|
||||
private static FieldConstraints buildConstraints(Field field) {
|
||||
List<FieldConstraint> list = new ArrayList<>();
|
||||
|
||||
for (Annotation ann : field.getAnnotations()) {
|
||||
ConstraintFactory factory = registry.get(ann.annotationType());
|
||||
if (factory != null) {
|
||||
FieldConstraint c = factory.create(field, ann);
|
||||
list.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (list.isEmpty()) return FieldConstraints.empty();
|
||||
return new FieldConstraints(list.toArray(new FieldConstraint[0]));
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({"RawUseOfParameterized"})
|
||||
public static final class ClassMetadata {
|
||||
final Class<?> type;
|
||||
final EditableField[] fields; // only declared fields
|
||||
final ClassMetadata parent; // superclass metadata (nullable)
|
||||
|
||||
ClassMetadata(Class<?> type, EditableField[] fields, ClassMetadata parent) {
|
||||
this.type = type;
|
||||
this.fields = fields;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public ClassMetadata getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public EditableField[] getDeclaredFields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package somehussar.gui.annotationHandling.constraints;
|
||||
|
||||
import somehussar.gui.annotationHandling.FieldConstraint;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public interface ConstraintFactory<A extends Annotation> {
|
||||
FieldConstraint create(Field field, A annotation);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package somehussar.gui.annotationHandling.constraints;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface NumericConstraint {
|
||||
double min() default Double.NEGATIVE_INFINITY;
|
||||
|
||||
double max() default Double.POSITIVE_INFINITY;
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package somehussar.gui.annotationHandling.constraints;
|
||||
|
||||
import somehussar.gui.annotationHandling.FieldConstraint;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NumericConstraintFactory implements ConstraintFactory<NumericConstraint> {
|
||||
|
||||
@Override
|
||||
public FieldConstraint create(Field field, NumericConstraint ann) {
|
||||
return new NumericRangeConstraint(ann.min(), ann.max());
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
package somehussar.gui.annotationHandling.constraints;
|
||||
|
||||
import somehussar.gui.annotationHandling.FieldConstraint;
|
||||
|
||||
public final class NumericRangeConstraint implements FieldConstraint {
|
||||
|
||||
private final double min;
|
||||
private final double max;
|
||||
|
||||
public NumericRangeConstraint(double min, double max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(Object value) {
|
||||
if (!(value instanceof Number)) {
|
||||
throw new ConstraintViolationException("Expected number, got " + value);
|
||||
}
|
||||
|
||||
double v = ((Number) value).doubleValue();
|
||||
if (v < min || v > max) {
|
||||
throw new ConstraintViolationException(
|
||||
"Value " + v + " must be between " + min + " and " + max
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ConstraintViolationException extends RuntimeException {
|
||||
public ConstraintViolationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package somehussar.gui.annotationHandling.field;
|
||||
|
||||
import somehussar.gui.annotationHandling.FieldConstraints;
|
||||
import somehussar.gui.annotationHandling.GuiEditable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
public final class EditableField<T> {
|
||||
|
||||
private final String name;
|
||||
private final Class<T> type;
|
||||
private final MethodHandle getter;
|
||||
private final MethodHandle setter;
|
||||
private final FieldConstraints constraints;
|
||||
private final int order;
|
||||
private final String group;
|
||||
private final GuiEditable.Size size;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class<?> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
public T read(T instance) {
|
||||
try {
|
||||
return (T) getter.invoke(instance);
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException("Failed to read field " + name, t);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(T instance, T value) {
|
||||
constraints.validate(value);
|
||||
try {
|
||||
setter.invoke(instance, value);
|
||||
} catch (Throwable t) {
|
||||
throw new RuntimeException("Failed to write field " + name, t);
|
||||
}
|
||||
}
|
||||
|
||||
public FieldConstraints getConstraints() {
|
||||
return this.constraints;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
}
|
||||
|
||||
EditableField(Builder<T> b) {
|
||||
this.name = b.name;
|
||||
this.type = b.type;
|
||||
this.getter = b.getter;
|
||||
this.setter = b.setter;
|
||||
this.constraints = b.constraints;
|
||||
this.order = b.order;
|
||||
this.group = b.group;
|
||||
this.size = b.size;
|
||||
}
|
||||
|
||||
public static class Builder<T> {
|
||||
private String name;
|
||||
private Class<T> type;
|
||||
private MethodHandle getter;
|
||||
private MethodHandle setter;
|
||||
private FieldConstraints constraints;
|
||||
private int order;
|
||||
private String group = null;
|
||||
private GuiEditable.Size size;
|
||||
|
||||
public Builder<T> name(String v) {
|
||||
this.name = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> type(Class<T> v) {
|
||||
this.type = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> getter(MethodHandle v) {
|
||||
this.getter = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> setter(MethodHandle v) {
|
||||
this.setter = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> constraints(FieldConstraints v) {
|
||||
this.constraints = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> order(int order) {
|
||||
this.order = order;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> group(String value) {
|
||||
this.group = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> size(GuiEditable.Size size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EditableField<T> build() {
|
||||
return new EditableField<>(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package somehussar.gui.guides;
|
||||
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.achievement.GuiAchievement;
|
||||
import net.minecraft.stats.AchievementList;
|
||||
|
||||
// TODO: THIS IS JUST THE CLIENT SIDE CONTROLLER
|
||||
// NEED SERVER SIDE
|
||||
public class GuideController {
|
||||
private static boolean glint = true;
|
||||
private static boolean isGuideLoaded = true;
|
||||
|
||||
public static boolean isGuideLoaded() {
|
||||
return isGuideLoaded;
|
||||
}
|
||||
|
||||
public static void setGuideLoaded(boolean isGuideLoaded) {
|
||||
GuideController.isGuideLoaded = isGuideLoaded;
|
||||
}
|
||||
|
||||
public static boolean glint() {
|
||||
return glint;
|
||||
}
|
||||
|
||||
public static void handleWorldJoin() {
|
||||
if (glint()){
|
||||
GuiAchievement achievementGui = Minecraft.getMinecraft().guiAchievement;
|
||||
achievementGui.func_146255_b(AchievementList.openInventory);
|
||||
achievementGui.field_146265_j = "Check out guides in your inventory!";
|
||||
achievementGui.field_146268_i = "CNPC Guides!";
|
||||
}
|
||||
}
|
||||
|
||||
public static void disableGlint() {
|
||||
glint = false;
|
||||
final long time = Minecraft.getSystemTime();
|
||||
GuiAchievement achievementGui = Minecraft.getMinecraft().guiAchievement;
|
||||
achievementGui.field_146263_l = (achievementGui.field_146263_l <= time - 3000 && achievementGui.field_146262_n ? time : Minecraft.getSystemTime() - (long) (3000.0D * 0.5D));
|
||||
achievementGui.field_146262_n = false;
|
||||
achievementGui.field_146265_j = "Guides explored!";
|
||||
}
|
||||
|
||||
public static void resetGlint() {
|
||||
glint = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package tconstruct.client.tabs;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.achievement.GuiAchievement;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.stats.Achievement;
|
||||
import net.minecraft.stats.AchievementList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
import somehussar.gui.guides.GuideController;
|
||||
|
||||
import static tconstruct.client.tabs.TabRegistry.getPotionOffset;
|
||||
|
||||
public class InventoryTabGuides extends AbstractTab {
|
||||
|
||||
// TODO: Replace with a proper texture.
|
||||
private static final ResourceLocation HELP_TEXTURE = new ResourceLocation("customnpcs", "textures/marks/question.png");
|
||||
public InventoryTabGuides() {
|
||||
super(0, 0, 0, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabClicked() {
|
||||
int xSize = 176;
|
||||
int ySize = 166;
|
||||
GuiScreen gui = Minecraft.getMinecraft().currentScreen;
|
||||
|
||||
GuideController.disableGlint();
|
||||
if (!(gui instanceof GuiInventory))
|
||||
return;
|
||||
|
||||
int guiLeft = (gui.width - xSize) / 2;
|
||||
int guiTop = (gui.height - ySize) / 2;
|
||||
guiLeft += getPotionOffset();
|
||||
TabRegistry.updateTabValues(guiLeft, guiTop, InventoryTabGuides.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAddToList() {
|
||||
return GuideController.isGuideLoaded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (this.visible) {
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||
GL11.glDepthMask(true);
|
||||
this.zLevel = 100.0F;
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
int yTexPos = this.enabled ? 3 : 32;
|
||||
int ySize = this.enabled ? 25 : 32;
|
||||
int xOffset = this.id == 2 ? 0 : 1;
|
||||
int yPos = this.yPosition + (this.enabled ? 3 : 0);
|
||||
mc.renderEngine.bindTexture(super.texture);
|
||||
this.drawTexturedModalRect(this.xPosition, yPos, xOffset * 28,
|
||||
yTexPos, 28, ySize);
|
||||
|
||||
this.zLevel = 100.0f;
|
||||
mc.renderEngine.bindTexture(HELP_TEXTURE);
|
||||
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
this.zLevel = 100.0F;
|
||||
this.itemRenderer.zLevel = 100.0F;
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
drawTextured(this.xPosition + 6, this.yPosition + 8, 0, 0, 16, 16, 16, 16);
|
||||
|
||||
if (GuideController.glint()) {
|
||||
GL11.glDepthFunc(GL11.GL_EQUAL);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDepthMask(false);
|
||||
mc.renderEngine.bindTexture(RenderItem.RES_ITEM_GLINT);
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F);
|
||||
this.renderGlint(this.xPosition, yPos, 28, ySize);
|
||||
GL11.glDepthMask(true);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glDepthFunc(GL11.GL_LEQUAL);
|
||||
}
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
this.zLevel = 0.0F;
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void renderGlint(int x, int y, int width, int height) {
|
||||
OpenGlHelper.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE, 0, 0);
|
||||
|
||||
final float GLINT_TEX_SCALE = 0.00390625F; // 1 / 256
|
||||
long now = Minecraft.getSystemTime();
|
||||
double z = this.zLevel;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
|
||||
for (int pass = 0; pass < 2; ++pass) {
|
||||
long cycleLengthMs = 3000 + pass * 1873;
|
||||
float scrollU = (now % cycleLengthMs) / (float) cycleLengthMs * 256.0F;
|
||||
float skew = (pass == 1) ? -1.0F : 4.0F;
|
||||
|
||||
float uLeft = scrollU * GLINT_TEX_SCALE;
|
||||
float uRight = (scrollU + width) * GLINT_TEX_SCALE;
|
||||
float uBottomSkew = (scrollU + height * skew) * GLINT_TEX_SCALE;
|
||||
float uBottomRightSkew = (scrollU + width + height * skew) * GLINT_TEX_SCALE;
|
||||
float vTop = 0.0F;
|
||||
float vBottom = height * GLINT_TEX_SCALE;
|
||||
|
||||
tessellator.addVertexWithUV(x, y + height, z, uBottomSkew, vBottom);
|
||||
tessellator.addVertexWithUV(x + width, y + height, z, uBottomRightSkew, vBottom);
|
||||
tessellator.addVertexWithUV(x + width, y, z, uRight, vTop);
|
||||
tessellator.addVertexWithUV(x, y, z, uLeft, vTop);
|
||||
}
|
||||
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
private void drawTextured(int x, int y, float u, float v, int width, int height, float textureWidth, float textureHeight)
|
||||
{
|
||||
float f4 = 1.0F / textureWidth;
|
||||
float f5 = 1.0F / textureHeight;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.addVertexWithUV((double)x, (double)(y + height), this.zLevel, (double)(u * f4), (double)((v + (float)height) * f5));
|
||||
tessellator.addVertexWithUV((double)(x + width), (double)(y + height), this.zLevel, (double)((u + (float)width) * f4), (double)((v + (float)height) * f5));
|
||||
tessellator.addVertexWithUV((double)(x + width), (double)y, this.zLevel, (double)((u + (float)width) * f4), (double)(v * f5));
|
||||
tessellator.addVertexWithUV((double)x, (double)y, this.zLevel, (double)(u * f4), (double)(v * f5));
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
@@ -26,3 +26,11 @@ public net.minecraft.client.Minecraft field_147126_aw # mcMusicTicker
|
||||
public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic
|
||||
#GuiScreen
|
||||
public net.minecraft.client.gui.GuiScreen field_146290_a # selectedButton
|
||||
# ItemRenderer
|
||||
public net.minecraft.client.renderer.entity.RenderItem field_110798_h # RES_ITEM_GLINT
|
||||
|
||||
public net.minecraft.client.gui.achievement.GuiAchievement field_146268_i # popupTitle
|
||||
public net.minecraft.client.gui.achievement.GuiAchievement field_146265_j # description
|
||||
public net.minecraft.client.gui.achievement.GuiAchievement field_146263_l # startTime
|
||||
public net.minecraft.client.gui.achievement.GuiAchievement field_146266_k # achievementType
|
||||
public net.minecraft.client.gui.achievement.GuiAchievement field_146262_n # showOnlyDescription / persistUntilCompletion. It does the job of both of these ;o
|
||||
Reference in new issue
Block a user