Jump to content

[1.16] Attach Capability to Chunks?


kiou.23

Recommended Posts

Say I simply want to hold a single random Integer in each chunk, I know I can attach Capabilities to Chunks through the  AttachcapabilitiesEvent, but then I would need to create my own class that extends Capability<Integer>? Would I need to serialize the data to nbt for it to be saved? any tips on how I should go about doing this?

Link to comment
Share on other sites

No, you would create your own class that implements MySavedIntegerStorage<MySavedIntegerInterface>

 

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/farming/entities/capabilities/MilkStorage.java

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

30 minutes ago, Draco18s said:

No, you would create your own class that implements MySavedIntegerStorage<MySavedIntegerInterface>

 

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/farming/entities/capabilities/MilkStorage.java

Okay, like this?

public interface IChunkValue {

    int getValue();
    void setValue(int value);

}

 

public class ChunkValue implements IChunkValue {

    private int value;

    public ChunkValue(int value) {
        this.value = value;
    }

    @Override
    public int getValue() {
        return value;
    }

    @Override
    public void setValue(int value) {
        this.value = value;
    }
}

 

public class ChunkValueStorage implements Capability.IStorage<IChunkValue> {

    @Override
    public INBT writeNBT(Capability<IChunkValue> capability, IChunkValue instance, Direction side) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putInt("value", instance.getValue());
        return nbt;
    }

    @Override
    public void readNBT(Capability<IChunkValue> capability, IChunkValue instance, Direction side, INBT nbt) {
        instance.setValue(((CompoundNBT)nbt).getInt("value"));
    }

    public class Factory implements Callable<IChunkValue> {
        @Override
        public IChunkValue call() throws Exception {
            return new ChunkValue(0);
        }
    }
}

 

Now what?... I don't really get where to go after this

Link to comment
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

13 minutes ago, Draco18s said:

yeah, I did that, but I'm getting a bunch of NullPointerExceptions at this line:

    @Override
    public INBT serializeNBT() {
        return TutorialMod.CHUNK_VALUE_CAPABILITY.writeNBT(getCachedChunkValue(), null);
    }

 

I'm guessing that it's because I'm defining TutorialMod.CHUNK_VALUE_CAPABILITY as null, but I don't know what to do then

 

    @CapabilityInject(IChunkValue.class)
    public static final Capability<IChunkValue> CHUNK_VALUE_CAPABILITY = null;

 

should I initialise it as something else?

Link to comment
Share on other sites

1 minute ago, kiou.23 said:

should I initialise it as something else?

No, that's how its supposed to work. Forge injects the value to non-null at runtime.

You still need to register the capability.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/farming/FarmingBase.java#L189

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

22 minutes ago, Draco18s said:

No, that's how its supposed to work. Forge injects the value to non-null at runtime.

You still need to register the capability.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/farming/FarmingBase.java#L189

OHH that is what I was missing, thanks!

just a final question tho, why do I need an interface? if it's only going to be implemented once, why can't I just reference the class (in this case, ChunkValue)?

Edited by kiou.23
Link to comment
Share on other sites

Because of how Capabilities work.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

1 hour ago, kiou.23 said:

just a final question tho, why do I need an interface? if it's only going to be implemented once, why can't I just reference the class (in this case, ChunkValue)?

You don't need an interface, you could use the ChunkValue class only, without an interface.

  • Thanks 1
Link to comment
Share on other sites

Expanding on this:

  • If you intend for your capability to ever be used by other mods (i.e. you're making it part of your mod's API) then using an interface is very strongly advised, simply as good programming practice (expose the interface, not the implementation).
  • If you only ever intend for your capability to be used for storing data for your own purposes, an interface is very much optional.  You might decide it's useful to have one, just for tidiness in your own code, but then again you're free just to use a class.

 

  • Like 1
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

    • KLIK DISINI >>> LINK LOGIN & DAFTAR KLIK DISINI >>>   DAFTAR AKUN GACOR KLIK DISINI >>> DAFTAR AKUN VVIP KLIK DISINI >>> DAFTAR AKUN SLOT ANTI RUNGKAD KLIK DISINI >>>  LINK ALTERNATIF KLIK DISINI >>> AKUN GACOR SCATTER HITAM ULTRA88 adalah slot gacor winrate 100% dengan server thailand dan akun pro. Dapatkan akses menuju kemenangan ke puluhan sampai ratusan juta rupiah hanya dalam hitungan menit. 3 web yang kami hadirkan ini adalah yang terbaik dengan histori kemenangan tertinggi di satu Asia Tenggara. Member-member dari web ini selalu kembali karena tim admin dan CS yang profesional serta kemenangan berapapun pasti akan dibayar. RTP slot gacor juga sudah disiapkan agar kalian tidak bingung lagi mau main apa dan di jam berapa. Semua fasilitas seperti deposit dana dan pulsa sudah disiapkan juga untuk kemudahan para slotters. Jadi tunggu apalagi? Raih kemenangan kalian disini sekarang juga!
    • >> DAFTAR KLIK DISINI << >> DAFTAR KLIK DISINI << PROMO SLOT GRATIS kami sangat cocok bagi mereka yang ingin mencoba keberuntungan tanpa mengeluarkan banyak uang. Dengan pilihan IP tanpa batas, slot ini menjamin gameplay yang adil dan tidak memihak. Jangan lewatkan kesempatan untuk menang besar tanpa mengeluarkan uang sepeser pun! Dapatkan slot promo gratis tanpa perlu deposit! Nikmati taruhan gratis dan akses tak terbatas ke IP pilihan Anda. Manfaatkan kesempatan ini untuk mencoba peruntungan dan menang besar. Jangan lewatkan penawaran eksklusif ini. Hanya tersedia untuk waktu terbatas.
    • KLIK DISINI >>> LINK LOGIN & DAFTAR KLIK DISINI >>>   DAFTAR AKUN GACOR KLIK DISINI >>> DAFTAR AKUN VVIP KLIK DISINI >>> DAFTAR AKUN SLOT ANTI RUNGKAD KLIK DISINI >>>  LINK ALTERNATIF KLIK DISINI >>> AKUN GACOR SCATTER HITAM SLOT888 adalah slot gacor winrate 100% dengan server thailand dan akun pro. Dapatkan akses menuju kemenangan ke puluhan sampai ratusan juta rupiah hanya dalam hitungan menit. 3 web yang kami hadirkan ini adalah yang terbaik dengan histori kemenangan tertinggi di satu Asia Tenggara. Member-member dari web ini selalu kembali karena tim admin dan CS yang profesional serta kemenangan berapapun pasti akan dibayar. RTP slot gacor juga sudah disiapkan agar kalian tidak bingung lagi mau main apa dan di jam berapa. Semua fasilitas seperti deposit dana dan pulsa sudah disiapkan juga untuk kemudahan para slotters. Jadi tunggu apalagi? Raih kemenangan kalian disini sekarang juga!
    • Winning303 menyediakan berbagai jenis permainan dengan kemenangan yang tinggi , slot gacor dengan winrate 100% , hanya dengan modal receh sudah bisa meraih jutaan  Nikmati berbagai permainan judi online yang menarik dengan jaminan keamanan dan kenyamanan di WINNING303 LINK ALTERNATIF => https://w303.pink/ref1x    
    • RELATED: Horror Games Inspired By Movies Still, there are some options for a Wizard if it comes to melee combat, and there also are some alternatives on the subject of the catalyst they use to solid Spells. For each, those alternatives are first-class: Spellbook: All three spellcasting options, the Staff, Spellbook, and Crystal Ball can all have a whole lot of extra advantages of Dark And Darker Gold on them depending on rarity. But, at a base degree, the Spellbook is the catalyst option gamers appeared to gravitate to. This spell-casting catalyst will increase a Wizard's movement velocity by using the maximum overall, which clearly makes a large distinction. Crystal Ball: The distinction among the three Spell catalysts is quite easy. The Staff is the default option and has melee assaults of its own, the Spellbook is faster all around however offers no melee alternatives, and the Crystal Ball is the center ground between the 2 in regard to motion velocity, however gamers may also equip a Dagger or something in their other hand at the identical time. Crossbow: That's right, Wizards can really run Crossbows, but it is without a doubt simplest well worth the usage of once or at maximum twice at some stage in a suit, and best as soon as a Wizard is out of Spell casts. Still, tricking an enemy into thinking a Wizard is out of Spells, simplest to tug out a Crossbow and launch a bolt into them is a surprisingly effective strategy. Rondel Dagger: Again, if it ever does come right down to melee combat, a Wizard loses ninety percent of the time. But, having a Rondel Dagger as a secondary or geared up alongside the Crystal Ball improves the ones odds at least a bit bit. The Wizard's Expansive Repertoire Of Spells. Moving on to the category all and sundry became in all likelihood anticipating when studying approximately the Wizard magnificence, the Spells. Which Spells are the quality to use on the Wizard and why? Or, not less than, which of them are the maximum 'meta'? Are those professional kind Wizards, together with ones that use White, Green, Red, or even Blue magic, or are they a piece extra stereotypical? Well, after doing a little research, those appear to be the consequences, listed from least to most used: Slow: Slows an opponent for a duration, maximum of the time is changed by means of Haste, but a few gamers choose to slow others in preference to velocity themselves up. Haste: Speeds the Wizard up by way of a quite noticeable amount for a brief duration. This is the important thing device Wizards use to usually maintain their combatants at variety, and the use of this they can outrun just about everybody in the game (outside of projectile guns or different Spells). Invisibility: One of the fine Spells to apply on Wizard, but only veteran players appear to be utilizing it to the maximum. Basically permits the Wizard to use the identical strategies as a Rogue does with their Hide capability. Fireball: The Spell everyone makes use of before everything, tends to reveal up in each game, and is nearly usually extraordinarily suitable. But, in Dark and Darker, gamers will fast realizes that it is straightforward to hit allies with and there are better options for normal damage. Chain Lightning: Likely the pleasant alternative damage-sensible, and the friendly-fireplace element of it's far a chunk misleading (would not clearly chain to allies find it irresistible says it does). When aimed well, can decimate an unaware foe. Magic Missile: The most iconic 'Wizard Spell', Magic Missile, is tremendously right in Dark and Darker as properly. It's extraordinary for NPC enemies, excellent for region denial in a PvP fight, and it is the pleasant Spell to apply if the enemy manages to shut the space as it may speedy soften via their HP earlier than their swing connects. Last-Second General Wizard Tips. And it is pretty a great deal the whole thing gamers want to realize about constructing Wizards in Dark and Darker. This class, out of all of the instructions the sport currently gives Darker Gold, might be one of the maximum challenging ones to play for a newcomer.
  • Topics

×
×
  • Create New...

Important Information

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