Skip to content

Commit 80a21fa

Browse files
committed
Updated to v1.5
and with a release which is only on github
1 parent 549118a commit 80a21fa

26 files changed

+1123
-124
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ A data dumper and typing generator for the KubeJS functions, constants and class
44

55
Great thanks to @DAmNRelentless, @LatvianModder and @yesterday17 for invaluable suggestions during the development!
66

7+
With the release of v1.5.0, applying static documents to the game is possible! However, this change disabled the
8+
automatic dump of documents, so ProbeJS is currently needing a large amount of support, and please don't hesitate if you have a PR!
9+
10+
For the detailed information, please refer to the wiki page.
11+
712
## 1. Showcase
813

914
Auto-completion snippets for Items, Blocks, Fluids, Entities and Tags:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ apply from: 'https://files.latmod.com/public/markdown-git-changelog.gradle'
99
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
1010

1111
def ENV = System.getenv()
12-
version = "${mod_version}-build.22"
12+
version = "${mod_version}-build.27"
1313
archivesBaseName = project.archives_base_name
1414
group = project.maven_group
1515

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.daemon=false
33
loom.platform=forge
44
mod_id=probejs
55
archives_base_name=probejs
6-
mod_version=1.4.0
6+
mod_version=1.5.0
77
maven_group=com.prunoideae
88
mod_author=Prunoideae
99
minecraft_version=1.18.1

src/main/java/com/prunoideae/probejs/ProbeCommands.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import com.google.gson.JsonObject;
55
import com.mojang.brigadier.Command;
66
import com.mojang.brigadier.CommandDispatcher;
7+
import com.prunoideae.probejs.resolver.document.DocumentManager;
8+
import com.prunoideae.probejs.resolver.document.DocumentResolver;
9+
import com.prunoideae.probejs.resolver.document.info.ClassDocument;
10+
import com.prunoideae.probejs.toucher.ClassInfo;
711
import com.prunoideae.probejs.typings.KubeCompiler;
812
import com.prunoideae.probejs.typings.ProbeCompiler;
913
import com.prunoideae.probejs.typings.SpecialFormatters;
@@ -17,6 +21,8 @@
1721
import net.minecraft.server.packs.repository.PackRepository;
1822
import net.minecraft.world.level.storage.WorldData;
1923

24+
import java.io.BufferedReader;
25+
import java.io.IOException;
2026
import java.nio.file.Files;
2127
import java.nio.file.Path;
2228
import java.util.Collection;
@@ -29,6 +35,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
2935
.requires(source -> source.getServer().isSingleplayer() || source.hasPermission(2))
3036
.executes(context -> {
3137
try {
38+
DocumentManager.init();
3239
export(context.getSource());
3340
KubeCompiler.fromKubeDump();
3441
context.getSource().sendSuccess(new TextComponent("KubeJS registry snippets generated."), false);
@@ -41,21 +48,26 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
4148
context.getSource().sendSuccess(new TextComponent("ProbeJS typing generation finished."), false);
4249
return Command.SINGLE_SUCCESS;
4350
}))
44-
.then(Commands.literal("clear_cache"))
45-
.requires(source -> source.getServer().isSingleplayer() || source.hasPermission(2))
46-
.executes(context -> {
47-
Path path = KubeJSPaths.EXPORTED.resolve("cachedEvents.json");
48-
if (Files.exists(path)) {
49-
if (path.toFile().delete()) {
50-
context.getSource().sendSuccess(new TextComponent("Cache files removed."), false);
51-
} else {
52-
context.getSource().sendSuccess(new TextComponent("Failed to remove cache files."), false);
53-
}
54-
} else {
55-
context.getSource().sendSuccess(new TextComponent("No cached files to be cleared."), false);
56-
}
57-
return Command.SINGLE_SUCCESS;
58-
})
51+
.then(Commands.literal("clear_cache")
52+
.requires(source -> source.getServer().isSingleplayer() || source.hasPermission(2))
53+
.executes(context -> {
54+
Path path = KubeJSPaths.EXPORTED.resolve("cachedEvents.json");
55+
if (Files.exists(path)) {
56+
if (path.toFile().delete()) {
57+
context.getSource().sendSuccess(new TextComponent("Cache files removed."), false);
58+
} else {
59+
context.getSource().sendSuccess(new TextComponent("Failed to remove cache files."), false);
60+
}
61+
} else {
62+
context.getSource().sendSuccess(new TextComponent("No cached files to be cleared."), false);
63+
}
64+
return Command.SINGLE_SUCCESS;
65+
}))
66+
.then(Commands.literal("test")
67+
.executes(context -> {
68+
DocumentManager.init();
69+
return Command.SINGLE_SUCCESS;
70+
}))
5971
);
6072
}
6173

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.prunoideae.probejs.resolver;
2+
3+
import com.prunoideae.probejs.ProbeJS;
4+
import com.prunoideae.probejs.resolver.handler.AbstractStackedMachine;
5+
import com.prunoideae.probejs.resolver.handler.ICallback;
6+
import com.prunoideae.probejs.resolver.handler.IStateHandler;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
import java.util.stream.Stream;
12+
13+
public class Util {
14+
private static class Extractor implements IStateHandler<String> {
15+
private final String push;
16+
private final String pop;
17+
public List<Object> extracted = new ArrayList<>();
18+
private StringBuilder current = new StringBuilder();
19+
20+
public Extractor(String push, String pop) {
21+
this.push = push;
22+
this.pop = pop;
23+
}
24+
25+
@Override
26+
public void trial(String element, List<IStateHandler<String>> stack) {
27+
if (element.equals(push)) {
28+
Extractor e = new Extractor(this.push, this.pop);
29+
extracted.add(current.toString());
30+
current = new StringBuilder();
31+
extracted.add(e);
32+
stack.add(e);
33+
} else if (element.equals(pop)) {
34+
extracted.add(current.toString());
35+
stack.remove(this);
36+
} else {
37+
current.append(element);
38+
}
39+
}
40+
41+
public void finalizeString() {
42+
extracted.add(current.toString());
43+
current = new StringBuilder();
44+
}
45+
46+
public String join() {
47+
StringBuilder stringBuilder = new StringBuilder();
48+
for (Object o : extracted) {
49+
if (o instanceof String) {
50+
stringBuilder.append((String) o);
51+
} else if (o instanceof Extractor) {
52+
stringBuilder.append(this.push);
53+
stringBuilder.append(((Extractor) o).join());
54+
stringBuilder.append(this.pop);
55+
}
56+
}
57+
return stringBuilder.toString();
58+
}
59+
60+
@Override
61+
public String toString() {
62+
return "Extractor{" +
63+
"extracted=" + extracted +
64+
'}';
65+
}
66+
}
67+
68+
private static class SplitExtractor implements IStateHandler<String>, ICallback<String> {
69+
private final String push;
70+
private final String pop;
71+
private final String delimiter;
72+
private final List<String> result = new ArrayList<>();
73+
private StringBuilder current = new StringBuilder();
74+
75+
private SplitExtractor(String push, String pop, String delimiter) {
76+
this.push = push;
77+
this.pop = pop;
78+
this.delimiter = delimiter;
79+
}
80+
81+
@Override
82+
public void trial(String element, List<IStateHandler<String>> stack) {
83+
if (delimiter.equals(element)) {
84+
result.add(current.toString());
85+
current = new StringBuilder();
86+
} else {
87+
if (push.equals(element))
88+
stack.add(new SplitMask(this, push, pop));
89+
current.append(element);
90+
}
91+
}
92+
93+
public void finalizeString() {
94+
result.add(current.toString());
95+
current = new StringBuilder();
96+
}
97+
98+
@Override
99+
public void call(String value) {
100+
current.append(value);
101+
}
102+
103+
public List<String> getResult() {
104+
return result;
105+
}
106+
}
107+
108+
private static class SplitMask implements IStateHandler<String>, ICallback<String> {
109+
private final ICallback<String> parent;
110+
private final String push;
111+
private final String pop;
112+
private final StringBuilder result = new StringBuilder();
113+
114+
private SplitMask(ICallback<String> parent, String push, String pop) {
115+
this.parent = parent;
116+
this.push = push;
117+
this.pop = pop;
118+
}
119+
120+
@Override
121+
public void trial(String element, List<IStateHandler<String>> stack) {
122+
result.append(element);
123+
if (push.equals(element))
124+
stack.add(new SplitMask(this, push, pop));
125+
if (pop.equals(element)) {
126+
stack.remove(this);
127+
parent.call(this.result.toString());
128+
}
129+
}
130+
131+
@Override
132+
public void call(String value) {
133+
result.append(value);
134+
}
135+
}
136+
137+
138+
private static class ExtractorState extends AbstractStackedMachine<String> {
139+
}
140+
141+
public static Extractor extractString(String s, String push, String pop) {
142+
Stream<String> ss = s.chars().mapToObj(Character::toString);
143+
ExtractorState state = new ExtractorState();
144+
Extractor result = new Extractor(push, pop);
145+
state.getStack().add(result);
146+
ss.forEach(state::step);
147+
result.finalizeString();
148+
return result;
149+
}
150+
151+
public static List<String> unwrapString(String s, String push, String pop) {
152+
Extractor recursive = extractString(s, push, pop);
153+
return recursive.extracted.stream().map(o -> {
154+
if (o instanceof String)
155+
return (String) o;
156+
if (o instanceof Extractor)
157+
return ((Extractor) o).join();
158+
return "";
159+
}).collect(Collectors.toList());
160+
}
161+
162+
public static List<String> splitString(String s, String delimiter, String push, String pop) {
163+
Stream<String> ss = s.chars().mapToObj(Character::toString);
164+
SplitExtractor extractor = new SplitExtractor(push, pop, delimiter);
165+
ExtractorState state = new ExtractorState();
166+
state.getStack().add(extractor);
167+
ss.forEach(state::step);
168+
extractor.finalizeString();
169+
return extractor.getResult();
170+
}
171+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package com.prunoideae.probejs.resolver.document;
2+
3+
import com.prunoideae.probejs.ProbeJS;
4+
import com.prunoideae.probejs.resolver.Util;
5+
import com.prunoideae.probejs.resolver.document.info.ClassDocument;
6+
import com.prunoideae.probejs.resolver.document.info.CommentDocument;
7+
import com.prunoideae.probejs.resolver.document.part.ComponentComment;
8+
import com.prunoideae.probejs.resolver.document.part.PartClass;
9+
import com.prunoideae.probejs.resolver.document.part.PartModRequirement;
10+
import com.prunoideae.probejs.resolver.document.part.PartTarget;
11+
import com.prunoideae.probejs.resolver.handler.IStateHandler;
12+
import com.prunoideae.probejs.typings.TSGlobalClassFormatter;
13+
import dev.architectury.platform.Platform;
14+
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
import java.util.stream.Collectors;
18+
19+
/**
20+
* Represents the entire .d.ts declaration file.
21+
*/
22+
public class Document implements IStateHandler<String> {
23+
private final List<Object> documentParts = new ArrayList<>();
24+
25+
public static String removeBlank(String s) {
26+
while (s.startsWith(" ") || s.startsWith("\t"))
27+
s = s.substring(1);
28+
return s;
29+
}
30+
31+
public static int getBlank(String s) {
32+
int length = 0;
33+
if (s.charAt(length) == ' ')
34+
length++;
35+
return length;
36+
}
37+
38+
public static String formatType(String s) {
39+
int arrayDepth = 0;
40+
while (s.endsWith("[]")) {
41+
s = s.substring(0, s.length() - 2);
42+
arrayDepth++;
43+
}
44+
45+
if (s.startsWith("\"") || s.startsWith("'"))
46+
return s;
47+
48+
List<String> paramString = Util.splitString(s, ",", "<", ">");
49+
return paramString.stream().map(p -> {
50+
p = removeBlank(p);
51+
List<String> testParam = Util.unwrapString(p, "<", ">");
52+
String baseTypeName = testParam.get(0);
53+
baseTypeName = TSGlobalClassFormatter.resolvedClassName.getOrDefault(baseTypeName, baseTypeName);
54+
if (testParam.size() == 1) {
55+
return baseTypeName;
56+
} else {
57+
return "%s<%s>".formatted(baseTypeName, formatType(testParam.get(1)));
58+
}
59+
}).collect(Collectors.joining(", ")) + "[]".repeat(arrayDepth);
60+
}
61+
62+
@Override
63+
public void trial(String element, List<IStateHandler<String>> stack) {
64+
// If null is passed in, then it means EOF is reached.
65+
if (element == null) {
66+
stack.remove(this);
67+
return;
68+
}
69+
70+
if (element.contains("/**")) {
71+
ComponentComment comment = new ComponentComment(element);
72+
this.documentParts.add(comment);
73+
stack.add(comment);
74+
return;
75+
}
76+
77+
element = removeBlank(element);
78+
79+
if (element.startsWith("@Target")) {
80+
this.documentParts.add(new PartTarget(element));
81+
} else if (element.startsWith("@Mod")) {
82+
this.documentParts.add(new PartModRequirement(element));
83+
} else if (element.startsWith("class") || element.startsWith("interface")) {
84+
PartClass clazz = new PartClass(element);
85+
this.documentParts.add(clazz);
86+
stack.add(clazz);
87+
}
88+
}
89+
90+
public List<ClassDocument> resolveClasses() {
91+
List<ClassDocument> classDocuments = new ArrayList<>();
92+
List<PartModRequirement> mods = new ArrayList<>();
93+
PartTarget target = null;
94+
ComponentComment comment = null;
95+
for (Object o : this.documentParts) {
96+
if (o instanceof PartTarget)
97+
target = (PartTarget) o;
98+
else if (o instanceof PartModRequirement)
99+
mods.add((PartModRequirement) o);
100+
else if (o instanceof ComponentComment) {
101+
comment = (ComponentComment) o;
102+
} else if (o instanceof PartClass) {
103+
ClassDocument document = new ClassDocument((PartClass) o);
104+
if (target != null)
105+
document.setTarget(target.targetName);
106+
if (comment != null)
107+
document.setComment(new CommentDocument(comment));
108+
if (mods.stream().allMatch(part -> Platform.isModLoaded(part.targetName)))
109+
classDocuments.add(document);
110+
comment = null;
111+
target = null;
112+
mods.clear();
113+
}
114+
}
115+
return classDocuments;
116+
}
117+
}

0 commit comments

Comments
 (0)