Search in sources :

Example 1 with HardnessProperty

use of org.spongepowered.api.data.property.block.HardnessProperty in project SpongeCommon by SpongePowered.

the class HardnessPropertyStore method getFor.

@Override
public Optional<HardnessProperty> getFor(Location<World> location) {
    final IBlockState blockState = (IBlockState) location.getBlock();
    final float hardness = blockState.getBlockHardness((net.minecraft.world.World) location.getExtent(), VecHelper.toBlockPos(location));
    if (hardness > 0) {
        return Optional.of(new HardnessProperty(hardness));
    }
    return Optional.empty();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) HardnessProperty(org.spongepowered.api.data.property.block.HardnessProperty)

Example 2 with HardnessProperty

use of org.spongepowered.api.data.property.block.HardnessProperty in project LanternServer by LanternPowered.

the class LanternWorld method getBlockDigTimeWith.

public int getBlockDigTimeWith(int x, int y, int z, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
    // Check if the user has the creative game mode
    if (profile != null) {
        final Optional<User> optUser = Lantern.getGame().getUserStorageService().get(profile);
        if (optUser.isPresent()) {
            final User user = optUser.get();
            if (user.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET) == GameModes.CREATIVE) {
                return 0;
            }
        }
    }
    final Optional<UnbreakableProperty> optUnbreakableProperty = getProperty(x, y, z, UnbreakableProperty.class);
    if (optUnbreakableProperty.isPresent() && optUnbreakableProperty.get().getValue() == Boolean.TRUE) {
        return -1;
    }
    final Optional<HardnessProperty> optHardnessProperty = getProperty(x, y, z, HardnessProperty.class);
    if (optHardnessProperty.isPresent()) {
        final Double value = optHardnessProperty.get().getValue();
        double hardness = value == null ? 0 : value;
        // TODO: Calculate the duration
        return hardness <= 0 ? 0 : 1;
    }
    return 0;
}
Also used : User(org.spongepowered.api.entity.living.player.User) HardnessProperty(org.spongepowered.api.data.property.block.HardnessProperty) UnbreakableProperty(org.spongepowered.api.data.property.block.UnbreakableProperty)

Aggregations

HardnessProperty (org.spongepowered.api.data.property.block.HardnessProperty)2 IBlockState (net.minecraft.block.state.IBlockState)1 UnbreakableProperty (org.spongepowered.api.data.property.block.UnbreakableProperty)1 User (org.spongepowered.api.entity.living.player.User)1