@Override public String getName() { return property.getName(); }
public IPropertyAdapter(IProperty<T> property) { this.property = property; this.values = ImmutableList.copyOf(property.getAllowedValues()); }
@Override public T getValueFor(String string) throws IllegalArgumentException { Optional<T> val = property.parseValue(string); checkArgument(val.isPresent(), "%s has no value for %s", getName(), string); return val.get(); }
private void showGrowthLevel(IProbeInfo probeInfo, IBlockState blockState) { for (IProperty<?> property : blockState.getProperties().keySet()) { if(!"age".equals(property.getName())) continue; if(property.getValueClass() == Integer.class) { IProperty<Integer> integerProperty = (IProperty<Integer>)property; int age = blockState.getValue(integerProperty); int maxAge = Collections.max(integerProperty.getAllowedValues()); if (age == maxAge) { probeInfo.text(OK + "Fully grown"); } else { probeInfo.text(LABEL + "Growth: " + WARNING + (age * 100) / maxAge + "%"); } } return; } }
private <T extends Comparable<T>> IBlockState findProperty(IBlockState state, IProperty<T> prop, String key, String newValue) { if (key.equals(prop.getName())) { for (T value : prop.getAllowedValues()) { if (prop.getName(value).equals(newValue)) { return state.withProperty(prop, value); } } } return null; } }
JsonElement valueElement = object.get(property.getName()); if(valueElement.isJsonPrimitive()) { JsonElement singleValue = valueElement; isBlacklist = true; Optional<?> parsedValue = property.parseValue(elementValue); if(!parsedValue.isPresent()) { throw new IllegalArgumentException("Couldn't parse property " + property.getName() + " value " + valueElement); allValues = new ArrayList<>(property.getAllowedValues()); allValues.removeAll(blacklistValues);
public static EnumFacing getRotation(IBlockState state) { for (IProperty<?> prop : state.getProperties().keySet()) { if ((prop.getName().equals("facing") || prop.getName().equals("rotation")) && prop.getValueClass() == EnumFacing.class) { return (EnumFacing) state.getValue(prop); } } return null; }
public static IBlockState parseBlockStateDefinition(JsonObject object) { Block block = getBlockByName(object.get("block").getAsString()); IBlockState blockState = block.getDefaultState(); for(IProperty<?> property : block.getBlockState().getProperties()) { JsonElement valueElement = object.get(property.getName()); if(valueElement != null && valueElement.isJsonPrimitive()) { String stringValue = valueElement.getAsString(); Optional<?> parsedValue = property.parseValue(stringValue); if(!parsedValue.isPresent()) { throw new IllegalArgumentException("Couldn't parse property " + property.getName() + " value " + valueElement); } //fuck java @SuppressWarnings("UnnecessaryLocalVariable") IProperty areYouFuckingSerious = property; Comparable fuckJava = (Comparable) parsedValue.get(); //noinspection unchecked blockState = blockState.withProperty(areYouFuckingSerious, fuckJava); } } return blockState; }
@SuppressWarnings({ "rawtypes", "unchecked" }) private IBlockState flipBlock(final IBlockState blockState, final EnumFacing axis, final boolean forced) throws FlipException { final IProperty propertyFacing = BlockStateHelper.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; }
public <T extends Comparable<T>> T getValue(IProperty<T> property) { final Comparable<?> value = values.get(property); Preconditions.checkArgument(value != null, "Cannot get property %s", property); return property.getValueClass().cast(value); }
@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.getPropertyKeys()) { 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; }
@Nullable public static <T extends Comparable<T>> IProperty<T> getProperty(Block block, String propertyName, Class<T> valueClass) { for (IProperty<?> property : block.getDefaultState().getPropertyKeys()) { if (property.getName().equals(propertyName)) { if (property.getValueClass().isAssignableFrom(valueClass)) { //noinspection unchecked return (IProperty<T>) property; } } } return null; } }
int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed"); Stream<IProperty<?>> propertyStream = hempCrop.getBlockState().getProperties().stream(); IProperty age = propertyStream.filter(p -> p.getName().equals("type")).findAny().orElseGet(null); Optional bottom0 = age.parseValue("bottom0"); Optional bottom4 = age.parseValue("bottom4"); Optional top0 = age.parseValue("top0"); if (bottom0.isPresent() && top0.isPresent()) { IBlockState defaultState = hempCrop.getDefaultState();
if (value instanceof EnumFacing) { final EnumFacing facing = getRotatedFacing(axisRotation, (EnumFacing) value); if (propertyFacing.getAllowedValues().contains(facing)) { return blockState.withProperty(propertyFacing, facing); if (BlockLever.EnumOrientation.class.isAssignableFrom(propertyFacing.getValueClass())) { final BlockLever.EnumOrientation orientation = (BlockLever.EnumOrientation) blockState.getValue(propertyFacing); final BlockLever.EnumOrientation orientationRotated = getRotatedLeverFacing(axisRotation, orientation); if (propertyFacing.getAllowedValues().contains(orientationRotated)) { return blockState.withProperty(propertyFacing, orientationRotated); if (EnumFacing.Axis.class.isAssignableFrom(propertyAxis.getValueClass())) { final EnumFacing.Axis axis = (EnumFacing.Axis) blockState.getValue(propertyAxis); final EnumFacing.Axis axisRotated = getRotatedAxis(axisRotation, axis); if (BlockLog.EnumAxis.class.isAssignableFrom(propertyAxis.getValueClass())) { final BlockLog.EnumAxis axis = (BlockLog.EnumAxis) blockState.getValue(propertyAxis); final BlockLog.EnumAxis axisRotated = getRotatedLogAxis(axisRotation, axis); if (BlockQuartz.EnumType.class.isAssignableFrom(propertyVariant.getValueClass())) { final BlockQuartz.EnumType type = (BlockQuartz.EnumType) blockState.getValue(propertyVariant); final BlockQuartz.EnumType typeRotated = getRotatedQuartzType(axisRotation, type);
@Override public <T extends Comparable<T>> T getValue(IProperty<T> property) { int offset = ((IPatchedBlockStateContainer) container).getPropertyOffsets().getOrDefault(property, -1); if (offset == -1) { throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + container); } int width = propertyWidths.get(property); int number = data >>> offset & 0xFFFFFFFF >>> 32 - width; Comparable<?> value = numberToValue.get(new Pair<>(property, number)); return property.getValueClass().cast(value); }
private Map<Property<?>, Object> adaptProperties(BlockType block, Map<IProperty<?>, Comparable<?>> mcProps) { Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName)); for (Map.Entry<IProperty<?>, Comparable<?>> prop : mcProps.entrySet()) { Object value = prop.getValue(); if (prop.getKey() instanceof PropertyDirection) { value = ForgeAdapter.adaptEnumFacing((EnumFacing) value); } else if (prop.getKey() instanceof PropertyEnum) { value = ((IStringSerializable) value).getName(); } props.put(block.getProperty(prop.getKey().getName()), value); } return props; }
propertyMap.put(property.getName(), property); offset += MathHelper.log2(property.getAllowedValues().size()) + 1;
public static Comparable getPropertyValueByName(IBlockState blockState, IProperty property, String valueName) { for (Comparable value : (ImmutableSet<Comparable>) property.getAllowedValues()) { if (value.toString().equals(valueName)) return value; } return null; }
private <T extends Comparable<T>> IBlockState setProperty(IBlockState state, IProperty<T> prop, String valueString) { com.google.common.base.Optional<T> value = prop.parseValue(valueString); if (value.isPresent()) { state = state.withProperty(prop, value.get()); } return state; }
public static IBlockState rotateFacing(IBlockState state, int turns) { for (Map.Entry<IProperty<?>, Comparable<?>> property : state.getProperties().entrySet()) { Class<?> valueClass = property.getKey().getValueClass(); if (ROTATORS.containsKey(valueClass)) { //noinspection unchecked state = rotateY(state, property.getKey(), turns); } } return state; }