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();
}
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;
}
Aggregations