Developer's Cafe [#1] | A Deeper Look into the Inventory Api

Developer’s Cafe Come in for a cup of Java
:free: NEW EDITION EVERY TUESDAY :free:


Featuring: @DotDash, @LordLambda, @gabizou, and @mumfrey


Table of Contents

  • Code of the week
  • To Learn
  • Links
  • ___ :arrow_forward: Code of the week :arrow_backward:

    Taken from @gabizou’s pull request, https://github.com/SpongePowered/SpongeAPI/pull/495

    @Subscribe
    public void onBreak(PlayerBreakBlockEvent event) {
       Optional<ItemStack> option = event.getPlayer().getItemInHand();
       if (!option.isPresent() {
         return;
       }
       ItemStack myItemStack = option.get();
       Optional<HarvestingProperty> harvestOptional = myItemStack.get(HarvestingProperty.class);
       if (harvestOptional.isPresent()) {
         // Now we can actually use the itemproperty 
         // since the item stack does have it
         HarvestingProperty harvest = harvestOptional.get();
         // And the code goes on doing whatever it was you wanted to 
         // do with that information...
         if (harvest.getValue().contains(event.getBlock().getType()) {
           // We want to just make the player exhausted. Because we're mean >:]
           event.getPlayer().setExhaustion(event.getPlayer().getExhaustion() + 10);
         }
    

    Want YOUR “interesting” code here? Be sure to private message me and/or leave a reply!


    :arrow_forward: Featured :arrow_backward:

  • @LordLamba's Warden the Plan AntiCheat Plugin - https://forums.spongepowered.org/t/warden-the-plan/6339/
  • @DotDash's Soaked Up Newsletter, https://forums.spongepowered.org/t/soaked-up-8-an-interview-with-bitbyte-and-more/6309

  • :arrow_forward:To Learn :arrow_backward:
    @mumfrey has created a major pull request on Github. It adds significant features to the weak Inventory api and adds “queries”. Be sure to check it out at https://github.com/SpongePowered/SpongeAPI/pull/443.


    And I guess that is all. Be sure to check out the links provided, give me suggestions by private messaging me or emailing me at [email protected]. Stay tuned for upcoming editions, and go eat a turkey!


    We are not afflicted with Soaked Up in any way. This newsletter serves a different purpose than Soaked Up, but we urge you to read it also. [Soaked Up] HEADQUARTERS
    .
    Be sure to :heart: this post!

    3 Likes

    The Developer’s Ramblings would be a better name :wink:

    5 Likes

    @DotDash, first of all, I don’t want to combat your newletter. Second of all, I think the Developer’s Cafe is a good idea. Please come in for a hot cup of Java!

    Moved to Sponge Discussion. Doesn’t really fit into Sponge Development, and it certainly doesn’t fit in Plugins.

    3 Likes

    Not sure how you came to that conclusion from what I’d said?

    This PR was created more than a month ago (10 Feb). I also don’t understand why it is something “To Learn”.

    Am I the only one who dislikes the overuse of text effects and emoticons/symbols?

    I want to say that we are not combating over each other for popularity. Notice how I stated I was not afflicted with your newsletter in any way. My posts touch on different topics than your, so that shouldn’t be a problem.

    Developer’s Cafe Come in for a cup of java
    :free:NEW EDITION EVERY TUESDAY :free:


    Dear readers,

    Please note that the “To Learn” section features parts of the SpongeApi that are worth learning. Although @mumfrey created his/her pull request about a month ago, his/her post contains useful instructions of programmers to see, if you haven’t seen it already.

    - The Developer’s Cafe administration


    We are not afflicted with Soaked Up in any way. This newsletter servers a different purpose then Soaked Up, but we urge you to read it also. [Soaked Up] HEADQUARTERS

    I think the word you are looking for is affiliated

    Stupid Google Chrome spellcheck :wink:

    1 Like