forked from Prunoideae/ProbeJS-Forge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
special support for RegistryEvents and TagEvents might have to be Kes…
…sJS exclusive, I dont know
- Loading branch information
Showing
6 changed files
with
207 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 117 additions & 84 deletions
201
src/main/java/zzzank/probejs/docs/events/TagEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,130 @@ | ||
package zzzank.probejs.docs.events; | ||
|
||
import dev.latvian.kubejs.script.ScriptType; | ||
import dev.latvian.kubejs.server.TagEventJS; | ||
import lombok.val; | ||
import net.minecraftforge.fml.server.ServerLifecycleHooks; | ||
import zzzank.probejs.features.kubejs.SpecialData; | ||
import zzzank.probejs.lang.java.clazz.ClassPath; | ||
import zzzank.probejs.lang.typescript.ScriptDump; | ||
import zzzank.probejs.lang.typescript.TypeScriptFile; | ||
import zzzank.probejs.lang.typescript.code.Code; | ||
import zzzank.probejs.lang.typescript.code.ts.Statements; | ||
import zzzank.probejs.lang.typescript.code.ts.Wrapped; | ||
import zzzank.probejs.lang.typescript.code.type.Types; | ||
import zzzank.probejs.plugin.ProbeJSPlugin; | ||
import zzzank.probejs.utils.NameUtils; | ||
|
||
import java.util.*; | ||
|
||
public class TagEvents extends ProbeJSPlugin { | ||
public static final Set<String> POSTED = new HashSet<>(); | ||
|
||
public static final ClassPath TAG_EVENT = new ClassPath("zzzank.probejs.generated.TagEventProbe"); | ||
public static final ClassPath TAG_WRAPPER = new ClassPath("zzzank.probejs.generated.TagWrapperProbe"); | ||
|
||
// Create TagEventProbe<T, I> and TagWrapperProbe<T, I> | ||
// Generate string overrides for all registry types | ||
// tags(extra: "item", handler: (event: TagEventProbe<Special.ItemTag, Special.Item>) => void) | ||
// | ||
// @Override | ||
// public void addGlobals(ScriptDump scriptDump) { | ||
// if (scriptDump.scriptType != ScriptType.SERVER) { | ||
// return; | ||
// } | ||
// | ||
// BaseType eventType = Types.type(TAG_EVENT); | ||
// MinecraftServer currentServer = ServerLifecycleHooks.getCurrentServer(); | ||
// if (currentServer == null) { | ||
// return; | ||
// } | ||
// RegistryAccess registryAccess = currentServer.registryAccess(); | ||
// | ||
// Wrapped.Namespace groupNamespace = new Wrapped.Namespace("ServerEvents"); | ||
// for (ResourceKey<? extends Registry<?>> key : RegistryUtils.getRegistries(registryAccess)) { | ||
// Registry<?> registry = registryAccess.registry(key).orElse(null); | ||
// if (registry == null) { | ||
// continue; | ||
// } | ||
// | ||
// String typeName = "Special." + NameUtils.rlToTitle(key.location().getPath()); | ||
// String tagName = typeName + "Tag"; | ||
// String extraName = key.location().getNamespace().equals("minecraft") ? | ||
// key.location().getPath() : | ||
// key.location().toString(); | ||
// MethodDeclaration declaration = Statements.method("tags") | ||
// .param("extra", Types.literal(extraName)) | ||
// .param("handler", Types.lambda() | ||
// .param("event", Types.parameterized( | ||
// eventType, | ||
// Types.primitive(tagName), Types.primitive(typeName) | ||
// )) | ||
// .build() | ||
// ) | ||
// .build(); | ||
// groupNamespace.addCode(declaration); | ||
// } | ||
// | ||
// scriptDump.addGlobal("tag_events", groupNamespace); | ||
// } | ||
// | ||
// @Override | ||
// public void modifyClasses(ScriptDump scriptDump, Map<ClassPath, TypeScriptFile> globalClasses) { | ||
// if (scriptDump.scriptType != ScriptType.SERVER) { | ||
// return; | ||
// } | ||
// | ||
// BaseType wrapperType = Types.type(TAG_WRAPPER); | ||
// | ||
// ClassDecl tagEventProbe = Statements.clazz(TAG_EVENT.getName()) | ||
// .superClass(Types.type(TagKubeEvent.class)) | ||
// .typeVariables("T", "I") | ||
// .method("add", builder -> builder | ||
// .returnType(Types.parameterized(wrapperType, Types.generic("T"), Types.generic("I"))) | ||
// .param("tag", Types.generic("T")) | ||
// .param("filters", Types.generic("I").asArray(), false, true) | ||
// ) | ||
// .method("remove", builder -> builder | ||
// .returnType(Types.parameterized(wrapperType, Types.generic("T"), Types.generic("I"))) | ||
// .param("tag", Types.generic("T")) | ||
// .param("filters", Types.generic("I").asArray(), false, true) | ||
// ) | ||
// .build(); | ||
// TypeScriptFile eventFile = new TypeScriptFile(TAG_EVENT); | ||
// eventFile.addCode(tagEventProbe); | ||
// globalClasses.put(TAG_EVENT, eventFile); | ||
// | ||
// ClassDecl tagWrapperProbe = Statements.clazz(TAG_WRAPPER.getName()) | ||
// .superClass(Types.type(TagEventJS.TagWrapper.class)) | ||
// .typeVariables("T", "I") | ||
// .method("add", builder -> builder | ||
// .returnType(Types.THIS) | ||
// .param("filters", Types.generic("I").asArray(), false, true) | ||
// ) | ||
// .method("remove", builder -> builder | ||
// .returnType(Types.THIS) | ||
// .param("filters", Types.generic("I").asArray(), false, true) | ||
// ) | ||
// .build(); | ||
// TypeScriptFile wrapperFile = new TypeScriptFile(TAG_WRAPPER); | ||
// wrapperFile.addCode(tagWrapperProbe); | ||
// globalClasses.put(TAG_WRAPPER, wrapperFile); | ||
// } | ||
|
||
@Override | ||
public void addGlobals(ScriptDump scriptDump) { | ||
if (scriptDump.scriptType != ScriptType.SERVER) { | ||
return; | ||
} | ||
|
||
val eventType = Types.type(TAG_EVENT); | ||
val server = ServerLifecycleHooks.getCurrentServer(); | ||
if (server == null) { | ||
return; | ||
} | ||
|
||
val events = new ArrayList<Code>(); | ||
for (val info : SpecialData.instance().registries()) { | ||
val forgeRegistry = info.forgeRaw(); | ||
val tagFolder = forgeRegistry.getTagFolder(); | ||
if (tagFolder == null) { | ||
continue; | ||
} | ||
|
||
} | ||
|
||
val groupNamespace = new Wrapped.Namespace("ServerEvents"); | ||
for (val info : SpecialData.instance().registries()) { | ||
val key = info.resKey(); | ||
val registry = info.raw(); | ||
if (registry == null) { | ||
continue; | ||
} | ||
val typeName = "Special." + NameUtils.rlToTitle(key.location().getPath()); | ||
val tagName = typeName + "Tag"; | ||
val extraName = key.location().getNamespace().equals("minecraft") | ||
? key.location().getPath() | ||
: key.location().toString(); | ||
val declaration = Statements.func("tags") | ||
.param("extra", Types.literal(extraName)) | ||
.param("handler", Types.lambda() | ||
.param("event", Types.parameterized( | ||
eventType, | ||
Types.primitive(tagName), Types.primitive(typeName) | ||
)) | ||
.build() | ||
) | ||
.build(); | ||
groupNamespace.addCode(declaration); | ||
} | ||
|
||
scriptDump.addGlobal("tag_events", groupNamespace); | ||
} | ||
|
||
@Override | ||
public void modifyClasses(ScriptDump scriptDump, Map<ClassPath, TypeScriptFile> globalClasses) { | ||
if (scriptDump.scriptType != ScriptType.SERVER) { | ||
return; | ||
} | ||
|
||
val wrapperType = Types.type(TAG_WRAPPER); | ||
|
||
val genericT = Types.generic("T"); | ||
val genericI = Types.generic("I"); | ||
|
||
val tagEventProbe = Statements.clazz(TAG_EVENT.getName()) | ||
.superClass(Types.type(TagEventJS.class)) | ||
.typeVariables("T", "I") | ||
.method("add", builder -> builder | ||
.returnType(Types.parameterized(wrapperType, genericT, genericI)) | ||
.param("tag", genericT) | ||
.param("filters", genericI.asArray(), false, true) | ||
) | ||
.method("remove", builder -> builder | ||
.returnType(Types.parameterized(wrapperType, genericT, genericI)) | ||
.param("tag", genericT) | ||
.param("filters", genericI.asArray(), false, true) | ||
) | ||
.build(); | ||
val eventFile = new TypeScriptFile(TAG_EVENT); | ||
eventFile.addCode(tagEventProbe); | ||
globalClasses.put(TAG_EVENT, eventFile); | ||
|
||
val tagWrapperProbe = Statements.clazz(TAG_WRAPPER.getName()) | ||
.superClass(Types.type(TagEventJS.TagWrapper.class)) | ||
.typeVariables("T", "I") | ||
.method("add", builder -> builder | ||
.returnType(Types.THIS) | ||
.param("filters", genericI.asArray(), false, true) | ||
) | ||
.method("remove", builder -> builder | ||
.returnType(Types.THIS) | ||
.param("filters", genericI.asArray(), false, true) | ||
) | ||
.build(); | ||
val wrapperFile = new TypeScriptFile(TAG_WRAPPER); | ||
wrapperFile.addCode(tagWrapperProbe); | ||
globalClasses.put(TAG_WRAPPER, wrapperFile); | ||
} | ||
|
||
@Override | ||
public Set<String> disableEventDumps(ScriptDump dump) { | ||
return POSTED; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.