Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply gui update into 1.19.2-create #19

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"devDependencies": {
"@types/node": "^22.9.3",
"esbuild": "^0.24.0",
"execa": "^5.5.1",
"execa": "^5.1.1",
"glob": "^11.0.0",
"tsx": "^4.19.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.unknown",
"texture_width": 16,
"texture_height": 16,
"visible_bounds_width": 2,
"visible_bounds_height": 2.5,
"visible_bounds_offset": [0, 0.75, 0]
},
"bones": [
{
"name": "bone",
"pivot": [0, 1.5, 0],
"cubes": [
{
"origin": [-0.5, 0, -0.5],
"size": [1, 11, 1],
"uv": {
"north": {"uv": [1, 1], "uv_size": [1, 11]},
"east": {"uv": [0, 1], "uv_size": [1, 11]},
"south": {"uv": [3, 1], "uv_size": [1, 11]},
"west": {"uv": [2, 1], "uv_size": [1, 11]},
"up": {"uv": [1, 0], "uv_size": [1, 1]},
"down": {"uv": [2, 1], "uv_size": [1, -1]}
}
},
{
"origin": [-0.75, 12, -0.75],
"size": [1.5, 1, 1.5],
"uv": {
"north": {"uv": [5, 4], "uv_size": [1, 1]},
"east": {"uv": [4, 4], "uv_size": [1, 1]},
"south": {"uv": [7, 4], "uv_size": [1, 1]},
"west": {"uv": [6, 4], "uv_size": [1, 1]},
"up": {"uv": [5, 3], "uv_size": [1, 1]},
"down": {"uv": [6, 4], "uv_size": [1, -1]}
}
},
{
"origin": [-1, 11, -1],
"size": [2, 1, 2],
"uv": {
"north": {"uv": [6, 2], "uv_size": [2, 1]},
"east": {"uv": [4, 2], "uv_size": [2, 1]},
"south": {"uv": [10, 2], "uv_size": [2, 1]},
"west": {"uv": [8, 2], "uv_size": [2, 1]},
"up": {"uv": [6, 0], "uv_size": [2, 2]},
"down": {"uv": [8, 2], "uv_size": [2, -2]}
}
},
{
"origin": [-0.5, 13, -0.5],
"size": [1, 1, 1],
"uv": {
"north": {"uv": [5, 6], "uv_size": [1, 1]},
"east": {"uv": [4, 6], "uv_size": [1, 1]},
"south": {"uv": [7, 6], "uv_size": [1, 1]},
"west": {"uv": [6, 6], "uv_size": [1, 1]},
"up": {"uv": [5, 5], "uv_size": [1, 1]},
"down": {"uv": [6, 6], "uv_size": [1, -1]}
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"loader": "kasuga_lib:bedrock_model",
"model": "kasuga_lib:panel/arrow",
"texture": "kasuga_lib:panel/arrow_texture",
"render_type": "translucent"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"format_version": "1.12.0",
"minecraft:geometry": [
{
"description": {
"identifier": "geometry.unknown",
"texture_width": 128,
"texture_height": 128,
"visible_bounds_width": 3,
"visible_bounds_height": 1.5,
"visible_bounds_offset": [0, 0.25, 0]
},
"bones": [
{
"name": "bb_main",
"pivot": [0, 0, 0],
"cubes": [
{
"origin": [-11, 0, -14],
"size": [22, 0, 28],
"uv": {
"north": {"uv": [28, 28], "uv_size": [22, 0]},
"east": {"uv": [0, 28], "uv_size": [28, 0]},
"south": {"uv": [78, 28], "uv_size": [22, 0]},
"west": {"uv": [50, 28], "uv_size": [28, 0]},
"up": {"uv": [28, 0], "uv_size": [22, 28]},
"down": {"uv": [28, 28], "uv_size": [22, -28]}
}
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"loader": "kasuga_lib:bedrock_model",
"model": "kasuga_lib:panel/panel",
"texture": "kasuga_lib:panel/panel_texture",
"render_type": "translucent"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/generated/resources/kasuga.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"client.MixinBlockModel$Deserializer",
"client.MixinBlockModelBinding",
"client.MixinBlockModelShaper",
"client.MixinLevelRenderer",
"client.MixinModelBakery",
"client.MixinTextureManager"
],
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/kasuga/lib/core/KasugaLibClient.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package kasuga.lib.core;

import kasuga.lib.core.client.model.BedrockModelLoader;
import kasuga.lib.core.client.model.model_json.UnbakedBedrockModel;
import kasuga.lib.core.client.render.texture.ImageMask;
import kasuga.lib.core.client.render.texture.StaticImage;
import kasuga.lib.core.client.render.texture.StaticImageHolder;
import kasuga.lib.core.util.LazyRecomputable;
import kasuga.lib.core.util.data_type.Pair;
import kasuga.lib.core.util.projectile.PanelRenderer;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.io.IOException;
import java.util.HashSet;

import static kasuga.lib.KasugaLib.MOD_ID;

Expand All @@ -19,5 +23,13 @@ public class KasugaLibClient {
public static final StaticImageHolder NO_IMG =
new StaticImageHolder(new ResourceLocation(MOD_ID, "textures/gui/no_img.png"));

public static final LazyRecomputable<UnbakedBedrockModel> panel =
BedrockModelLoader.fromFile(new ResourceLocation(MOD_ID, "panel/panel"));

public static final LazyRecomputable<UnbakedBedrockModel> arrow =
BedrockModelLoader.fromFile(new ResourceLocation(MOD_ID, "panel/arrow"));

public static final HashSet<PanelRenderer> PANEL_RENDERERS = new HashSet<>();

public static void invoke() {}
}
14 changes: 13 additions & 1 deletion src/main/java/kasuga/lib/core/addons/node/AssetReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ public class AssetReader implements BiFunction<String, String, String> {
private final HashMap<UUID, Object> assets;
private final JavascriptContext context;
private final String dirname;
private final String assetRoot;

ResourceProvider provider;

public AssetReader(String dirname, JavascriptContext context, ResourceProvider provider, HashMap<UUID, Object> assets) {
public AssetReader(String dirname, JavascriptContext context, ResourceProvider provider, HashMap<UUID, Object> assets, String assetRoot) {
this.provider = provider;
this.context = context;
this.assets = assets;
this.dirname = dirname;
this.assetRoot = assetRoot == null ? "/" : assetRoot;
}

@HostAccess.Export
Expand All @@ -45,6 +47,16 @@ public String apply(String path, String resourceType){
)
);
}
path = PackageScanner.joinPath(
PackageScanner.resolve(
PackageScanner.splitPath(
assetRoot
),
PackageScanner.splitPath(
path
)
)
);
UUID uuid;
do{
uuid = UUID.randomUUID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.network.chat.TextColor;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.DistExecutor;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

Expand Down Expand Up @@ -82,9 +83,7 @@ public void run() {
return;
}
ResourceLocation id = getParameter("id", ResourceLocation.class);
RenderSystem.recordRenderCall(()->{
Minecraft.getInstance().setScreen(KasugaLib.STACKS.GUI.get().create(id).createScreen());
});
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, ()->()->GuiScreenHelper.createAndAttach(id));
}
}).submit(REGISTRY);

Expand Down Expand Up @@ -126,18 +125,16 @@ public void run() {
.addLiteral("gui", false)
.addLiteral("instances", false)
.addLiteral("inspect", false)
.addResourceLocation("id", false)
.addString("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());
});
UUID id = UUID.fromString(getParameter("id", String.class));
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, ()->()->GuiScreenHelper.attach(id));
}
}).submit(REGISTRY);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kasuga.lib.core.client.frontend.commands;

import com.mojang.blaze3d.systems.RenderSystem;
import kasuga.lib.KasugaLib;
import kasuga.lib.core.client.frontend.gui.GuiInstance;
import kasuga.lib.core.client.frontend.gui.GuiScreen;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;

import java.util.UUID;

public class GuiScreenHelper {
public static void attach(UUID instanceId){
GuiInstance instance = KasugaLib.STACKS.GUI.orElseThrow().getInstanceById(instanceId).get();
if(instance == null)
return;
RenderSystem.recordRenderCall(()->{
Minecraft.getInstance().setScreen(new GuiScreen(instance));
});
}

public static void createAndAttach(ResourceLocation location){
RenderSystem.recordRenderCall(()->{
Minecraft.getInstance().setScreen(KasugaLib.STACKS.GUI.get().create(location).createScreen());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ protected JavascriptEngineModule load(
module.getDirectoryName(),
javascriptContext,
moduleInfo.getProvider(),
KasugaLib.STACKS.JAVASCRIPT.ASSETS.get()
));
KasugaLib.STACKS.JAVASCRIPT.ASSETS.get(),
"/"));
return module;

}catch (IOException e){
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/kasuga/lib/core/client/frontend/gui/GuiContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import kasuga.lib.core.javascript.Tickable;
import net.minecraft.resources.ResourceLocation;

import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.locks.ReentrantLock;

@V8Convert()
Expand All @@ -30,7 +32,7 @@ public class GuiContext extends DomContext<GuiDomNode,GuiDomRoot> implements Tic

public GuiContext(GuiInstance guiInstance, DOMPriorityRegistry registry, ResourceLocation location) {
super(registry, location);
layoutEngine = LayoutEngines.YOGA;
layoutEngine = LayoutEngines.YOGA.get();
this.guiInstance = guiInstance;
}

Expand Down Expand Up @@ -77,6 +79,11 @@ public void removeSourceInfo(Object source) {

@Override
public void tick() {
if(!isRendering){
this.renderLock.lock();
beforeRenderTick();
this.renderLock.unlock();
}
super.tick();
this.getRootNode().getLayoutManager().tick();
}
Expand All @@ -93,6 +100,19 @@ public void render(Object source, RenderContext context){
}


Queue<Runnable> afterRenderTickTasks = new ArrayDeque<>(32);

public void beforeRenderTick(){
Runnable task;
while((task = afterRenderTickTasks.poll()) != null){
task.run();
}
}

public void enqueueAfterRenderTask(Runnable runnable) {
this.afterRenderTickTasks.add(runnable);
}

public void queueDuringRender(Runnable task) {
Optional<JavascriptContext> threadContext = this.getRenderer().getContext();
if(threadContext.isEmpty()){
Expand All @@ -102,17 +122,16 @@ public void queueDuringRender(Runnable task) {
JavascriptContext context = threadContext.get();
if(!this.isRendering){
this.renderLock.lock();
context.beforeRenderTick();
beforeRenderTick();
RuntimeException _e = null;
try{
task.run();
}catch (RuntimeException e){
_e = e;
e.printStackTrace();
}
this.renderLock.unlock();
if(_e!=null) throw _e;
}else{
context.enqueueAfterRenderTask(task);
enqueueAfterRenderTask(task);
}
}

Expand All @@ -124,11 +143,11 @@ public void queueDuringRenderUnsafe(Runnable task){
}
JavascriptContext context = threadContext.get();
if(!this.isRendering){
context.beforeRenderTick();
beforeRenderTick();
task.run();
this.renderLock.unlock();
}else{
context.enqueueAfterRenderTask(task);
enqueueAfterRenderTask(task);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package kasuga.lib.core.client.frontend.gui.layout;

import kasuga.lib.core.client.frontend.common.layouting.LayoutEngine;
import kasuga.lib.core.client.frontend.gui.layout.yoga.YogaLayoutEngine;
import net.minecraftforge.common.util.Lazy;

public class LayoutEngines {
public static YogaLayoutEngine YOGA = new YogaLayoutEngine();
public static Lazy<LayoutEngine> YOGA = Lazy.of(YogaLayoutEngine::new);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public boolean removeChild(DomNode<GuiContext> child) {
@Override
public boolean addChild(DomNode<GuiContext> child) {
this.domContext.queueDuringRender(()-> {
super.addChild(child);
addChildInstant(children.size(), child);
});
return true;
}
Expand Down
Loading
Loading