CottonMC / LibGui

Buttons & Co
MIT License
291 stars 47 forks source link

must not be opened with an ExtendedScreenHandlerFactory #223

Closed drkhodakarami closed 11 months ago

drkhodakarami commented 11 months ago

Followes everything from the wiki page to get started with a block entity, when I right click on the block with entity, I get this :

[Server thread/ERROR] (Minecraft) Failed to handle packet net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket@4faba209, suppressing error java.lang.IllegalArgumentException: [Fabric] Non-extended screen handler allthatmatters:gem_cleanser must not be opened with an ExtendedScreenHandlerFactory! at net.minecraft.server.network.ServerPlayerEntity.redirect$zog000$fabric-screen-handler-api-v1$fabric_replaceVanillaScreenPacket(ServerPlayerEntity.java:5439) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.network.ServerPlayerEntity.openHandledScreen(ServerPlayerEntity.java:1043) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at jiraiyah.allthatmatters.block.custom.GemCleanserBlock.onUse(GemCleanserBlock.java:51) ~[main/:?] at net.minecraft.block.AbstractBlock$AbstractBlockState.onUse(AbstractBlock.java:1133) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.network.ServerPlayerInteractionManager.interactBlock(ServerPlayerInteractionManager.java:343) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.network.ServerPlayNetworkHandler.onPlayerInteractBlock(ServerPlayNetworkHandler.java:1117) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket.apply(PlayerInteractBlockC2SPacket.java:34) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket.apply(PlayerInteractBlockC2SPacket.java:8) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.network.NetworkThreadUtils.method_11072(NetworkThreadUtils.java:23) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.ServerTask.run(ServerTask.java:18) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.util.thread.ThreadExecutor.executeTask(ThreadExecutor.java:156) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.util.thread.ReentrantThreadExecutor.executeTask(ReentrantThreadExecutor.java:23) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.MinecraftServer.executeTask(MinecraftServer.java:778) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.MinecraftServer.executeTask(MinecraftServer.java:163) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.util.thread.ThreadExecutor.runTask(ThreadExecutor.java:130) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.MinecraftServer.runOneTask(MinecraftServer.java:760) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.MinecraftServer.runTask(MinecraftServer.java:754) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.util.thread.ThreadExecutor.runTasks(ThreadExecutor.java:115) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.MinecraftServer.runTasksTillTickEnd(MinecraftServer.java:738) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:671) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:263) ~[minecraft-merged-db9dde025b-1.20.2-net.fabricmc.yarn.1_20_2.1.20.2+build.4-v2.jar:?] at java.lang.Thread.run(Thread.java:842) ~[?:?]

here is the block : https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/block/custom/GemCleanserBlock.java#L51

here is the repo for block entity : https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/block/entity/GemCleanserBE.java#L130

here is the SyncedGuiDescription : https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/screen/handler/GemCleanserScreenHandler.java

this is how I register the screen type : https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/screen/ModScreenHandlers.java#L37

and finally, this is base class for the block entity that is handling most of the heavy lifting : https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/utils/block/entity/BEWithInventory.java#L43

please help

Juuxel commented 11 months ago

https://github.com/drkhodakarami/AllThatMatters/blob/57fcd09801f944faa38ffd2fb8e104f7e8ff53ea/src/main/java/jiraiyah/allthatmatters/utils/block/entity/BEWithInventory.java#L43

The BE implements ExtendedScreenHandlerFactory, but the screen handler type is not an ExtendedScreenHandlerType. The error stems from this mismatch.

drkhodakarami commented 11 months ago

I have a progress, and fluid container, should I use ExtendedScreenHandlerType ? and I assume you are refering to the screen type registration?

Juuxel commented 11 months ago

Both of those can (and should) be synced with other tools as they're changing data.

"Screen opening data" refers to unchanging data that is sent once and not updated.

I assume you are refering to the screen type registration?

Yep, the screen handler type that is given to the registry.

drkhodakarami commented 11 months ago

another Issue and I assume this is from lacking the tutorial seciton on the wiki :

1 - why the progress bar is not updating and showing the full progress ( i am simulating the change of value for time being to increase to max and reset tick by tick) https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/screen/handler/GemCleanserScreenHandler.java#L63

https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/block/entity/GemCleanserBE.java#L321

2- how to draw a fluid container and use the texture of the fluid inside automatically?

3- how to draw a tooltip on the fluid container?

Juuxel commented 11 months ago

1:

2 and 3: There's no stock fluid widget in LibGui. A tooltip can be added to a custom widget by overriding appendTooltip.

drkhodakarami commented 11 months ago

the progress and max progress are from delegate that is correct. how ever, I don't see anything in the wiki page that show how to utilize these values to make the progress working.

the link you gave on the wiki is showing how to pass the delegate to the SyncedGuiDescription , I already done that in local repo (not pushed yet maybe), how ever, the problem of updating the progress with ticks remains untouched in the wiki completely.

is there any online repo that would briefly show how to use progress bar? and what do you suggest I should do to handle drawing fluids?

Juuxel commented 11 months ago

I don't really know of any example repo, but you can use this small example as a base:

// The PropertyDelegateHolder interface is needed so that the getBlockPropertyDelegate call discovers the properties
class MyBE extends BlockEntity implements PropertyDelegateHolder {
    private final PropertyDelegate propertyDelegate = new PropertyDelegate() {
        @Override
        public int get(int id) { return ...; }

        @Override
        public int set(int id) { return ...; }

        @Override
        public int size() { return 2; /* the number of properties */ }
    };

    @Override
    public PropertyDelegate getPropertyDelegate() {
        return propertyDelegate;
    }
}

// In the GUI description class
WBar bar = new WBar(..., /* the ID of the progress field: */ 0, /* the ID of the max progress field: */ 1);

WBar reads the values from the property delegate of the GUI description automatically if it's given the right ids.

For fluids, you'll probably need to make your own widget.

drkhodakarami commented 11 months ago

here is a question, which one of the two (screen, and description) is ticking by itself? I think i can handle fluid drawing from screen. Take a look at here :

https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/utils/fluid/FluidStackRenderer.java#L74

drkhodakarami commented 11 months ago

ok, I think now I am seeing a bug? on the screen class, no matter where I put the call for that fluidStackRenderer.Draw , it always draws on the background behind the panel, even if I put the call in render (after the super), or forground after the super, it is still being drawn behind the panel !

Also, when i put the same code in forground, the x and y coordinated behave differently than when the code is in render and renderBackground?

drkhodakarami commented 11 months ago

ignore the previous post. managed all of it. looking into your paint method, you are translating the matrix to 0.01 in z. in other words, no matter where I would call the base matrix, it would always be behind the panel. tweak the render fluid code a little and added a zorder with setter. works like charm.

can i suggest that you look into my repository and find a way to utilize these files and classes into your library? tried forking and pulling but for some reason, project can't find v1 stuff like FluidVariant

here are everything you would need :

1- the FluidStack is responsible of converting fabric fluid utins to mili buckets : https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/utils/fluid/FluidStack.java 2- the FluidStack renderer that is handling everything. By default i set the z order to 0, but if you want easier time for users, set the default to 1 https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/utils/fluid/FluidStackRenderer.java 3- the interface that is being used : https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/utils/interfaces/IIngredientRenderer.java

now you can simply render the fluid in screen with one line of code :

https://github.com/drkhodakarami/AllThatMatters/blob/master/src/main/java/jiraiyah/allthatmatters/screen/custom/GemCleanserScreen.java#L43

Juuxel commented 11 months ago

Thanks for the info. Since the original question is resolved, I'll close this issue.