use of org.spongepowered.api.data.property.item.HarvestingProperty in project SpongeCommon by SpongePowered.
the class HarvestingPropertyStore method getFor.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected Optional<HarvestingProperty> getFor(ItemStack itemStack) {
final Item item = itemStack.getItem();
if (item instanceof ItemTool && !(item instanceof ItemPickaxe)) {
final ImmutableSet<BlockType> blocks = ImmutableSet.copyOf((Set) ((ItemTool) item).effectiveBlocks);
return Optional.of(new HarvestingProperty(blocks));
}
final Collection<BlockType> blockTypes = SpongeImpl.getRegistry().getAllOf(BlockType.class);
final ImmutableSet.Builder<BlockType> builder = ImmutableSet.builder();
blockTypes.stream().filter(blockType -> item.canHarvestBlock((IBlockState) blockType.getDefaultState())).forEach(builder::add);
final ImmutableSet<BlockType> blocks = builder.build();
if (blocks.isEmpty()) {
return Optional.empty();
}
return Optional.of(new HarvestingProperty(blocks));
}
Aggregations