@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; }
private IProperty getProperty(final IBlockState blockState, final String name) { for (final IProperty prop : (Set<IProperty>) blockState.getProperties().keySet()) { if (prop.getName().equals(name)) { return prop; } } return null; }
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(); }
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; }
private <T extends Comparable<T>> String getNameHelper(IProperty<T> property) { return property.getName(getValue(property)); }
@Override public Set<T> getValidValues() { return new HashSet<>(property.getAllowedValues()); }
@Override public Class<T> getValueClass() { return property.getValueClass(); }
@Override public String getValueName(T value) { return property.getName(value); }
@Override public String getAttributeName() { return property.getName(); }
private <T extends Comparable<T>> void defaultStateHelper( RenderState state, IProperty<T> property, Comparable<?> value) { state.withProperty(property, property.getValueClass().cast(value)); }