Developer’s Cafe Come in for a cup of Java
NEW EDITION EVERY TUESDAY
Featuring: @DotDash, @LordLambda, @gabizou, and @mumfrey
Table of Contents
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!
Featured
To Learn
@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 this post!