Jump to content

Recommended Posts

Posted

Hey,

 

Im trying create capabilities dynamically using the new capability system, though I came accros a litle problem.

For the system to work properly I need an instance of the capability which is created after calling:

CapabilityManager.INSTANCE.register();

The thing is that I provide a base structure for the actual Capability itself. meaning the registered Class is always an subInstance of my base structure.

And because of that there is no way to get the instance, since the @CapabilityInject annotation does not support the use of superclasses.

 

So for example if I have an interface called "ICapBase" which people should implement in order to use my system.

If someone implements this interface and register it, there is no way for me to get the capability unless I hardcode that into my system.

because the following doesn't work!

@CapabilityInject(ICapBase.class)
Public static void onInject(Capability<? extends ICapBase> cap)
{}

 

Before I go to Forge's github and make a possible fix, I want to make sure I dont forget something which would solve this problem.

If there isn't any there are 2 fixes:

1. modify the current system so the above code would work.

2. simply return the capability from the #register method (from which I dont understand why that hasn't been done in the first place).

 

anyway, Im looking foreward to your opinion about this.

N247S

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Posted

I defenitly dont wanna make my own Capability instances. thats whats forge should do for me. though you can use them to get new default instances,

get the IStorage singelton etc. and first and foremost, they are used as identifier in the ICapabilityProvider (getCapability & hasCapbility). So it would help a lot if you can get them without hardcoding an annotation, like I described, via a annotated method or as a return value from the register method.

 

I could go for my own identification/defaultInstance/storage system, though why should I if those mechanics are already there... only unreachable atm..

 

(just to make sure, I register capabilities dynamically, I dont use a general or a hardcoded one!)

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Posted

Erhm.. Im pretty sure Forge is creating an Capability instance in the CapabilityManager#register method, and populating/calling every @CapabilitInject annotated field/method. although its pretty much checking if the 3 passed arguments are not null, and passing those through to the Capability constructor.

 

besides I know how the Capability CLASS(:P) works, the problem is that I need the instance for the ICapabilityProvider/ICapabilitySerializable for nbt writing/reading (and preferably for the 2 checking methods).

 

It all works fine, though the flaw is, that there is no way to get those singleton Capability instances without FailProne reflection or hardcoding a @CapabilityInject a field/method(which I cannot use because of the problem described in the first post).

 

SO just to make it simple. I need an the singelton instance of the Capability stored within the CapabilityManager preferably without reflection.

Is there a way to do so? if not, Ill use reflection for now.

 

thanks for the replies!

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Posted

Alright, so I assume that there is no 'normal' way to get the Capability object instance wihtout hardcoding stuff, too bad. Anyway Im going to rely on reflection. And just like the Capability injection does, I'll try to work around doing that during performance sensitive operations.

 

Thanks for your help!

Hope they add a simple getter for this in the future

 

Btw, just to make sure, the net.minecraftforge.* part of the Forge library doesn't use deobfuscated names right?

 

N247S

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Posted

You're doing it wrong this is designed for the API provider to expose an interface. Simple as that.

Sub-interfaces are separate capabilities. Deal with it. If the provider wants to support both your capability and some sub-cap of it they can simply do:

if (CAP == PARENT_CAP || CAP == CHILD_CAP) return (T)MyCap;

Whatever the hell you're doing {you still haven't explained why your consumers are creating sub-caps} is wrong, you should stop doing it. The flaw is not in the cap system it's in your understanding.

And you need to stop just "fuck it i'll hack the system because i dont know what im doing and cant explain/understand why the system was designed as it is"

 

Ya, looking at your 'MCIndicators' mod on github your concept is completely wrong, you're trying to wrap the capability system into something it isn't for.

What you WANT is to make a IIndicatorList that gathers all the 'indecators' instead of having people go through the capability system.

 

 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

@LexManos , I am suprised you looked the MCIndicators up. and yea, its a total mess wich I already have redesigned but not pushed yet.

The main problem is that generics involvement is giving problems when registering a universal capability object.(because of the Class<T> parameter)

I tried to solve it by dynamically registering a capability per indicator, wich should give less problems (especially with the getDefaultInstance() thingy).

But I have tried to work that out a litle bit more, and technically it should work although it doesnt feel right to me. (pretty messy, and fail prone)

So I propably will go for a central wrapper object, and take the extra synchronizing of non changed values instead.

I hoped that I could exploit the @CapabilityInject Annotation mechanism which is a pretty cool feature in my opinion.

 

Anyway thanks for your comment!

N247S

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • If you’ve lost crypto to a scam, don’t let shame or fear keep you silent. There are real experts out there who know how to fight back. Dexdert Net Recovery did the impossible for me, and they can do it for others too. Contact Dexdet Net Recovery For Help Visa Information Below:    
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
    • Does it still crash if you remove holdmyitems? Looks like that mod doesn't work on a server as far as I can tell from the error.  
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.