From f6a45d00ccede625487050f5ae2a0cfec70b5f7a Mon Sep 17 00:00:00 2001 From: TimeBather Date: Sat, 23 Nov 2024 07:59:31 +0800 Subject: [PATCH 1/5] fix: closing content is null when closing --- .../dom/registration/DOMRegistryItemDynamicProxy.java | 7 +++++-- .../frontend/gui/layout/yoga/api/YogaFileExtractor.java | 4 +++- .../frontend/gui/layout/yoga/api/YogaFileLocator.java | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/kasuga/lib/core/client/frontend/dom/registration/DOMRegistryItemDynamicProxy.java b/src/main/java/kasuga/lib/core/client/frontend/dom/registration/DOMRegistryItemDynamicProxy.java index 76fc7816..5ab7e466 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/dom/registration/DOMRegistryItemDynamicProxy.java +++ b/src/main/java/kasuga/lib/core/client/frontend/dom/registration/DOMRegistryItemDynamicProxy.java @@ -60,10 +60,13 @@ public void unload(){ return; this.context.getRootNode().clear(); this.closed = true; - context.appendTask(()->sideEffectContext.close()); + SideEffectContext _closingContext = this.sideEffectContext; + context.appendTask(()->{ + _closingContext.close(); + }); context.setNotReady(); - this.registryContext = null; this.sideEffectContext = null; + this.registryContext = null; } public void enable() { diff --git a/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileExtractor.java b/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileExtractor.java index cd59a9a1..b110140d 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileExtractor.java +++ b/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileExtractor.java @@ -25,7 +25,9 @@ public static String extract() throws URISyntaxException, IOException { return librariesFolder.getAbsolutePath(); } URI path = YogaFileExtractor.class.getProtectionDomain().getCodeSource().getLocation().toURI(); - if (!path.getPath().contains(".jar")) return null; + if (!path.getPath().contains(".jar")) { + return YogaFileLocator.getDevelopmentLibrariesDirectory(); + } String jarPath = path.getPath().substring(0, path.getPath().indexOf(".jar") + 4); JarFile jarFile = new JarFile(jarPath); diff --git a/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileLocator.java b/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileLocator.java index 8c8e175f..83574bdc 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileLocator.java +++ b/src/main/java/kasuga/lib/core/client/frontend/gui/layout/yoga/api/YogaFileLocator.java @@ -24,7 +24,7 @@ public static String getYogaAssemblyDirectory(){ throw new IllegalStateException("Illegal environment"); } - public static String getDevYogaAssemblyDirectory(){ - return "../src/generated/resources/libraries/lwjgl-yoga-3.3.1/"; + public static String getDevelopmentLibrariesDirectory(){ + return "../src/generated/resources/libraries/"; } } From f3484769962e751bd0b5afb56115674eeab51db9 Mon Sep 17 00:00:00 2001 From: TimeBather Date: Sat, 23 Nov 2024 07:59:49 +0800 Subject: [PATCH 2/5] fix: javascript engine commonjs load error --- .../kasuga/lib/core/javascript/engine/javet/JavetContext.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetContext.java b/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetContext.java index 0e458a90..c1830b2d 100644 --- a/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetContext.java +++ b/src/main/java/kasuga/lib/core/javascript/engine/javet/JavetContext.java @@ -89,8 +89,8 @@ public JavetJavascriptModule compileModuleFromSource(NodePackage packageTarget, return new JavetJavascriptModule( module, packageTarget, - dirName, fileName, + dirName, this.context ); }catch (JavetException e){ From 0a355e07560967df2119c58a8174993627363eb0 Mon Sep 17 00:00:00 2001 From: TimeBather Date: Sat, 23 Nov 2024 08:02:17 +0800 Subject: [PATCH 3/5] fix: sub channel connection exceptions --- .../java/kasuga/lib/core/menu/locator/BlockMenuLocator.java | 2 +- src/main/java/kasuga/lib/core/menu/locator/MenuLocator.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/kasuga/lib/core/menu/locator/BlockMenuLocator.java b/src/main/java/kasuga/lib/core/menu/locator/BlockMenuLocator.java index f0aa68a8..b087d3fa 100644 --- a/src/main/java/kasuga/lib/core/menu/locator/BlockMenuLocator.java +++ b/src/main/java/kasuga/lib/core/menu/locator/BlockMenuLocator.java @@ -83,9 +83,9 @@ private void unlisten() { @Override public void disable(LocatedMenuManager manager) { + this.broadcastDisable(); super.disable(manager); this.unlisten(); - this.broadcastDisable(); } @Override diff --git a/src/main/java/kasuga/lib/core/menu/locator/MenuLocator.java b/src/main/java/kasuga/lib/core/menu/locator/MenuLocator.java index f0a4d400..d885fab3 100644 --- a/src/main/java/kasuga/lib/core/menu/locator/MenuLocator.java +++ b/src/main/java/kasuga/lib/core/menu/locator/MenuLocator.java @@ -40,6 +40,8 @@ public void disable(LocatedMenuManager manager){ public void sendUpTo(Connection connection){ + if(!connection.isConnected()) + return; AllPackets.CHANNEL_REG.sendTo( new ServerLocatorChangePacket(this, manager.asServer()), connection, @@ -50,6 +52,8 @@ public void sendUpTo(Connection connection){ public void sendDownTo(Connection connection){ + if(!connection.isConnected()) + return; AllPackets.CHANNEL_REG.sendTo( new ServerLocatorChangePacket(this, manager.asServer()), connection, From 18d07925a70f55a7c48f3709eb9f1ecee6daa495 Mon Sep 17 00:00:00 2001 From: TimeBather Date: Sat, 23 Nov 2024 08:14:41 +0800 Subject: [PATCH 4/5] fix: some crash-able exceptions --- .gitignore | 5 ++++- .../frontend/common/layouting/LayoutContext.java | 5 +++++ .../lib/core/client/frontend/gui/GuiContext.java | 2 +- .../lib/core/client/frontend/gui/GuiInstance.java | 7 ++++--- .../lib/core/javascript/JavascriptContext.java | 14 -------------- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 4de5bc68..186a9bb6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,7 @@ forge*changelog.txt node_modules yarn.lock -package-lock.json \ No newline at end of file +package-lock.json + +# Javascript Build +javascript/**/lib \ No newline at end of file diff --git a/src/main/java/kasuga/lib/core/client/frontend/common/layouting/LayoutContext.java b/src/main/java/kasuga/lib/core/client/frontend/common/layouting/LayoutContext.java index c16f5860..6f61f35b 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/common/layouting/LayoutContext.java +++ b/src/main/java/kasuga/lib/core/client/frontend/common/layouting/LayoutContext.java @@ -34,6 +34,11 @@ public T addSource(Object source){ public LayoutNode removeSource(Object source){ LayoutNode node = this.sources.remove(source); + if(node == null){ + if(Envs.isDevEnvironment()){ + KasugaLib.MAIN_LOGGER.error("Source "+source.toString()+ "has not found in layout context, it may caused by multithread problems. If this still happends, please check."); + } + } for (LayoutContext child : children) { node.removeChild(child.removeSource(source)); } diff --git a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiContext.java b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiContext.java index f1b81c5a..bc35e24e 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiContext.java +++ b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiContext.java @@ -30,7 +30,7 @@ public class GuiContext extends DomContext implements Tic public GuiContext(GuiInstance guiInstance, DOMPriorityRegistry registry, ResourceLocation location) { super(registry, location); - layoutEngine = LayoutEngines.YOGA; + layoutEngine = LayoutEngines.YOGA; this.guiInstance = guiInstance; } diff --git a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java index 33b84d26..8fdde837 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java +++ b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java @@ -115,16 +115,20 @@ public Optional getContext() { public void updateSourceInfo(Object source, SourceInfo sourceInfo){ this.sourceInfos.put(source, sourceInfo); + beforeRender(); getContext().ifPresent((c)->{ c.setSourceInfo(source, sourceInfo); }); + afterRender(); } public void removeSourceInfo(Object source){ this.sourceInfos.remove(source); + beforeRender(); getContext().ifPresent((c)->{ c.removeSourceInfo(source); }); + afterRender(); } public void beforeRender(){ @@ -139,9 +143,6 @@ public void afterRender(){ return; this.context.renderLock.unlock(); this.context.isRendering = false; - this.context.getRenderer().getContext().ifPresent((c)->{ - c.dispatchBeforeRenderTick(); - }); } public Object getModule(String contextModuleName) { diff --git a/src/main/java/kasuga/lib/core/javascript/JavascriptContext.java b/src/main/java/kasuga/lib/core/javascript/JavascriptContext.java index 55996c28..1b157436 100644 --- a/src/main/java/kasuga/lib/core/javascript/JavascriptContext.java +++ b/src/main/java/kasuga/lib/core/javascript/JavascriptContext.java @@ -38,14 +38,7 @@ public void close(){ Set tickables = new HashSet<>(); - Queue futures = new ArrayDeque<>(); - public void tick(){ - if(!this.futures.isEmpty()){ - beforeRenderTick(); - CompletableFuture future; - while((future = this.futures.poll()) != null) future.complete(null); - } tickables.forEach(Tickable::tick); } @@ -85,13 +78,6 @@ public void beforeRenderTick(){ } } - public CompletableFuture dispatchBeforeRenderTick(){ - CompletableFuture future = new CompletableFuture(); - this.futures.add(future); - return future; - } - - public void enqueueAfterRenderTask(Runnable runnable) { this.afterRenderTickTasks.add(runnable); } From 15fe24c5bba5166263adecccc794eeefeaacb338 Mon Sep 17 00:00:00 2001 From: TimeBather Date: Sat, 23 Nov 2024 17:17:11 +0800 Subject: [PATCH 5/5] feat: frontend commands (list) --- .../frontend/commands/FrontendCommands.java | 58 +++++++++++++++++++ .../core/client/frontend/gui/GuiEngine.java | 4 ++ .../core/client/frontend/gui/GuiInstance.java | 4 ++ 3 files changed, 66 insertions(+) diff --git a/src/main/java/kasuga/lib/core/client/frontend/commands/FrontendCommands.java b/src/main/java/kasuga/lib/core/client/frontend/commands/FrontendCommands.java index f9f580a5..62d08e5d 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/commands/FrontendCommands.java +++ b/src/main/java/kasuga/lib/core/client/frontend/commands/FrontendCommands.java @@ -5,11 +5,15 @@ import kasuga.lib.KasugaLib; import kasuga.lib.core.addons.node.NodePackage; import kasuga.lib.core.base.commands.CommandHandler; +import kasuga.lib.core.client.frontend.gui.GuiInstance; import kasuga.lib.core.javascript.JavascriptContext; import kasuga.lib.core.javascript.JavascriptThread; import kasuga.lib.registrations.common.CommandReg; import kasuga.lib.registrations.registry.SimpleRegistry; import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextColor; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import org.apache.http.impl.client.CloseableHttpClient; @@ -83,6 +87,60 @@ public void run() { }); } }).submit(REGISTRY); + + public static final CommandReg GUI_INSTANCES_LIST = new CommandReg("kasugalib") + .addLiteral("gui", false) + .addLiteral("instances", false) + .addLiteral("list", false) + .onlyIn(Dist.CLIENT) + .setHandler(new CommandHandler(){ + @Override + public void run() { + Minecraft.getInstance().player.sendSystemMessage(Component.literal("-------- GUI Instances --------")); + KasugaLib.STACKS.GUI.ifPresent((gui)->{ + gui.getAllInstances().forEach((id, instance)->{ + Minecraft.getInstance().player.sendSystemMessage( + Component.literal(id.toString().substring(0,8)) + .append(" ") + .append(Component.literal(instance.getLocation().toString())) + .append(" ") + .append(Component.literal("[Inspect]") + .withStyle((s)-> + s.withBold(true) + .withClickEvent( + new ClickEvent( + ClickEvent.Action.RUN_COMMAND, + "/kasugalib gui instances inspect "+id + ) + ) + ) + ).withStyle((s)->s.withColor(TextColor.parseColor("#ffff00"))) + ); + }); + }); + + } + }).submit(REGISTRY); + + public static final CommandReg GUI_INSPECT = new CommandReg("kasugalib") + .addLiteral("gui", false) + .addLiteral("instances", false) + .addLiteral("inspect", false) + .addResourceLocation("id", false) + .onlyIn(Dist.CLIENT) + .setHandler(new CommandHandler(){ + @Override + public void run() { + if(KasugaLib.STACKS.GUI.isEmpty()){ + return; + } + ResourceLocation id = getParameter("id", ResourceLocation.class); + RenderSystem.recordRenderCall(()->{ + Minecraft.getInstance().setScreen(KasugaLib.STACKS.GUI.get().create(id).createScreen()); + }); + } + }).submit(REGISTRY); + public static void invoke(){ REGISTRY.submit(); } diff --git a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiEngine.java b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiEngine.java index c8e7a121..d1680ebf 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiEngine.java +++ b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiEngine.java @@ -64,4 +64,8 @@ public GuiInstance create(UUID id, ResourceLocation location){ public Optional getInstanceById(UUID id) { return Optional.ofNullable(localInstances.get(id)); } + + public HashMap getAllInstances() { + return localInstances; + } } diff --git a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java index 8fdde837..b55e4eb5 100644 --- a/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java +++ b/src/main/java/kasuga/lib/core/client/frontend/gui/GuiInstance.java @@ -152,4 +152,8 @@ public Object getModule(String contextModuleName) { public void putContextObject(String contextModuleName, Object object){ contextObject.put(contextModuleName, object); } + + public ResourceLocation getLocation() { + return location; + } }