Jump to content

[1.8.9+][Capabilities] So yeah... updating.


Ernio

Recommended Posts

Hey guys,

 

While reading all those example codes:

https://github.com/MinecraftForge/MinecraftForge/blob/1.9/src/test/java/net/minecraftforge/test/TestCapabilityMod.java

https://github.com/MinecraftForge/MinecraftForge/blob/1.9/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java

And other sources (docs and google)...

... I can't help to wonder - What the hell am I supposed to do (with my particular implementation).

Note: We are only talking about LivingEntities!

 

With IEEP things were pretty straightforward: You bind data on Entity's Construction. It doesn't matter what kind of data it is, you can even bind 1000 different Objects (IEEPs) to different entities, and still keep them all with same registration name (e.g: "MyIEEP").

 

Well, my big-ass piece of code strongly depends on this fact. I am (was) treating all EntityLivingBase similar to player, with one fact - player had special extension on IEEP registered onto him.

Structure: (I = interface obviously)

IExtendedEntityProperties

--->IExtendedBase (API mod)

------>ExtendedBase (abstract implementation of API)

--------->ExtendedEntity (implementation of base)

--------->ExtendedPlayer (implementation of base)

 

Now, I was registering stuff like this:

@SubscribeEvent
public void onEntityConstructing(EntityConstructing event)
{
	if (event.entity instanceof EntityPlayer) ExtendedPlayer.register((EntityPlayer) event.entity);
	else if (event.entity instanceof EntityLivingBase) ExtendedEntity.register((EntityLivingBase) event.entity);
}

 

Now, because of this I was able to use common abstract class (ExtendedBase) to reference either Player or other LivingEntities using:

ExtendedBase.get(EntityLivingBase);

 

This was very nice solution since in my mod, all livingEntities have on "profile" (stats), but players can have multiple (ExtendedBase returned singular for Entities and "current" for Player, but using ExtendedPlayer.get(EntityPlayer) you could also skim over "other" profiles (stats)).

 

So now - how can one implement such system when Capabilities REQUIRE you to have default non-abstract implementation class. How can I register different Capability class for LivingEntity and Player, but keep them under same "title/name".

 

Additional question: Can @CapabilityInject be placed anywhere in code? In most examples I see it in Mod's main class but e.g: docs say it can be anywhere?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

The annotation can go anywhere as long as it's static.

And you need to have a default implementation of your capability.

You don't need to USE that default implementation.

You can do whatever you want. Caps can do everything that IEEPs can. If you design them correctly.

The problem with your old design is it's the exact opposite of IEEP/Caps. You're having a central storage {atleast thats what it looks like from your snippits} of entity -> data. Instead of having the data IN the entity itself which is what caps/IEEP is supposed to do.

 

Give more code, and explain what you've tried.

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

Link to comment
Share on other sites

In fact I just really needed 2h nap to refresh brain, it's always best to just read code, yet still - Thanks for help! :D

 

Extra: I really like flexibility of this system.

 

Only thing that I don't get is why would anyone want to actually use IStorage? I mean - saving and loading happens directly from e.g: capability#serializeNBT() which is part of ICapabilitySerializable - and that one can be easily reimplemented by user of some API.

 

E.g: API gives you come interface for capability and you replace it (implement not-default class) with your own modification, but then - you can also edit its saving/loding processes (serializeNBT()), so why have IStorage? Is it just to give modders way to "only edit saving/loading" or is there some other goal here? Docs say "This allows for a central implementation of saving the data."

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Capability and Capability PROVIDERS are different things.

ICapabilitySerializeable is a Serializable Capability Provider. I just knocked off the Provider part of it because thats a long fkin name.

 

Take a look at this: https://github.com/MinecraftForge/MinecraftForge/blob/1.9/src/test/java/net/minecraftforge/test/NoBedSleepingTest.java

The Default implementation and the storage provider are DEFAULT serializers.

As a normal modder {Not the one writing the API} my implementation of saving/loading is just this:

                public NBTPrimitive serializeNBT() {
                    return (NBTPrimitive)SLEEP_CAP.getStorage().writeNBT(SLEEP_CAP, inst, null);
                }

                @Override
                public void deserializeNBT(NBTPrimitive nbt) {
                    SLEEP_CAP.getStorage().readNBT(SLEEP_CAP, inst, null, nbt);
                }

I can do that for ANY capability. I dont need to care that IFuelHandler stores 100,000 NBT elements. Or Sleep stores one.

I will get one NBT object from the storage handler and I know that it will load and save the state completely fine.

 

Now here is a important part: The storage handler is ONLY garenteed to work for the DEFAULT implementation.

SLEEP_CAP.getDefaultInstance()

If I have a some custom handler that relies on 15 different things and needs to store them all in the NBT. Then I will have to write my own serializer.

 

 

So ya remember ICapabilityProvider and INBTSerializeable are two different things. I made ICapabilitySerializeable PURELY as a convenience interface so that my patch files can be smaller. See My comment

 

Get it now?

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

Link to comment
Share on other sites

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

    • I was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
  • Topics

×
×
  • Create New...

Important Information

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