コード例 #1
0
ファイル: AbstractRenderState.java プロジェクト: kvverti/enim
  private <T extends Comparable<T>> T cycle(IProperty<T> property, T current) {

    boolean flag = false;
    for (T value : property.getAllowedValues()) {

      if (flag) return value;
      else if (value.equals(current)) flag = true;
    }
    // current was the last element, return the first
    return property.getAllowedValues().iterator().next();
  }
コード例 #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  private static boolean putMatchingProperty(
      final Map<IProperty, Comparable> map,
      final IBlockState blockState,
      final String name,
      final String value,
      final boolean strict)
      throws LocalizedException {
    for (final IProperty property : blockState.getPropertyNames()) {
      if (property.getName().equalsIgnoreCase(name)) {
        final Collection<Comparable> allowedValues = property.getAllowedValues();
        for (final Comparable allowedValue : allowedValues) {
          if (String.valueOf(allowedValue).equalsIgnoreCase(value)) {
            map.put(property, allowedValue);
            return true;
          }
        }
      }
    }

    if (strict) {
      throw new LocalizedException(
          Names.Messages.INVALID_PROPERTY_FOR_BLOCK,
          name + "=" + value,
          BLOCK_REGISTRY.getNameForObject(blockState.getBlock()));
    }

    return false;
  }
コード例 #3
0
ファイル: FlipHelper.java プロジェクト: Conraad/Schematica
  private IBlockState flipBlock(final IBlockState blockState, final EnumFacing axis, boolean forced)
      throws FlipException {
    final IProperty propertyFacing = getProperty(blockState, "facing");
    if (propertyFacing instanceof PropertyDirection) {
      final Comparable value = blockState.getValue(propertyFacing);
      if (value instanceof EnumFacing) {
        final EnumFacing facing = getFlippedFacing(axis, (EnumFacing) value);
        if (propertyFacing.getAllowedValues().contains(facing)) {
          return blockState.withProperty(propertyFacing, facing);
        }
      }
    } else if (propertyFacing instanceof PropertyEnum) {
      if (BlockLever.EnumOrientation.class.isAssignableFrom(propertyFacing.getValueClass())) {
        final BlockLever.EnumOrientation orientation =
            (BlockLever.EnumOrientation) blockState.getValue(propertyFacing);
        final BlockLever.EnumOrientation orientationRotated =
            getFlippedLeverFacing(axis, orientation);
        if (propertyFacing.getAllowedValues().contains(orientationRotated)) {
          return blockState.withProperty(propertyFacing, orientationRotated);
        }
      }
    } else if (propertyFacing != null) {
      Reference.logger.error(
          "'{}': found 'facing' property with unknown type {}",
          BLOCK_REGISTRY.getNameForObject(blockState.getBlock()),
          propertyFacing.getClass().getSimpleName());
    }

    if (!forced && propertyFacing != null) {
      throw new FlipException(
          "'%s' cannot be flipped across '%s'",
          BLOCK_REGISTRY.getNameForObject(blockState.getBlock()), axis);
    }

    return blockState;
  }
コード例 #4
0
 @Override
 public Set<T> getValidValues() {
   return new HashSet<>(property.getAllowedValues());
 }