public IPropertyAdapter(IProperty<T> property) { this.property = property; this.values = ImmutableList.copyOf(property.getAllowedValues()); }
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; }
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 static IBlockState cyclePropertyBackwards(IBlockState state, IProperty<?> property) { IBlockState result = state; for (int i = 0; i < property.getAllowedValues().size() - 1; i++) { result = result.cycleProperty(property); } return result; }
public static <T extends Comparable<T>> IBlockState[] getAllPropertyValues(IBlockState blockState, IProperty<T> property) { Collection<T> allowedValues = property.getAllowedValues(); IBlockState[] resultArray = new IBlockState[allowedValues.size()]; int index = 0; for(T propertyValue : allowedValues) { resultArray[index++] = blockState.withProperty(property, propertyValue); } return resultArray; }
void updateNeighbours(Map<Map<IProperty<?>, Comparable<?>>, State> valuesToStateMap) { Preconditions.checkState(neighbours == null); final Table<IProperty<?>, Comparable<?>, State> neighbours = HashBasedTable.create(); for (Map.Entry<IProperty<?>, Comparable<?>> e : values.entrySet()) { final IProperty<?> property = e.getKey(); final Comparable<?> currentValue = e.getValue(); for (Comparable<?> value : property.getAllowedValues()) { if (value != currentValue) { neighbours.put(property, value, valuesToStateMap.get(updateSingleValue(property, value))); } } } this.neighbours = ImmutableTable.copyOf(neighbours); }
private static void addStatesToList(IBlockState state, List<IBlockState> list, Stack<IProperty> stack) { if (stack.empty()) { list.add(state); return; } else { IProperty prop = stack.pop(); for (Object value : prop.getAllowedValues()) { addStatesToList(state.withProperty(prop, (Comparable)value), list, stack); } stack.push(prop); } }
private static void addStatesToList(IBlockState state, List<IBlockState> list, Stack<IProperty> stack) { if (stack.empty()) { list.add(state); return; } else { IProperty prop = stack.pop(); for (Object value : prop.getAllowedValues()) { addStatesToList(state.withProperty(prop, (Comparable)value), list, stack); } stack.push(prop); } }
public static <T extends Comparable<T>> void makePropertyInfo(IProperty<T> property) { if (propertyWidths.containsKey(property)) { return; } Collection<T> allowedValues = property.getAllowedValues(); // Calculate width of the property's number in the bit field propertyWidths.put(property, MathHelper.log2(allowedValues.size()) + 1); // Fill the 'number -> value' and 'value -> number' maps int i = 0; for (T value : allowedValues) { numberToValue.put(new Pair<>(property, i), value); valueToNumber.put(new Pair<>(property, value), i); i++; } }
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; } }
public StateContainer(List<IProperty<?>> properties) { List<IProperty<?>> sortedProperties = Lists.newArrayList(properties); Collections.sort(sortedProperties, PROPERTY_NAME_COMPARATOR); List<Collection<? extends Comparable<?>>> allAlowedValues = Lists.newArrayList(); for (IProperty<?> property : sortedProperties) allAlowedValues.add(property.getAllowedValues()); final Map<Map<IProperty<?>, Comparable<?>>, State> valuesToStateMap = Maps.newHashMap(); final List<State> allStates = Lists.newArrayList(); for (List<Comparable<?>> values : Cartesian.cartesianProduct(allAlowedValues)) { final Map<IProperty<?>, Comparable<?>> propertyValueMap = joinLists(sortedProperties, values); final State itemState = new State(propertyValueMap); allStates.add(itemState); valuesToStateMap.put(propertyValueMap, itemState); } for (State state : allStates) state.updateNeighbours(valuesToStateMap); this.allStates = ImmutableList.copyOf(allStates); this.baseState = allStates.get(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.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; }
allValues = new ArrayList<>(property.getAllowedValues()); allValues.removeAll(blacklistValues);
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; } }
NumericalBlockState.makePropertyInfo(property); propertyOffsets.put(property, offset); offset += MathHelper.log2(property.getAllowedValues().size()) + 1;
@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; }
private void registerFarmable(Block plantBlock, Item plantItem, ItemStack product, String identifier) { IProperty<Integer> growthProperty = BlockUtil.getProperty(plantBlock, "growth", Integer.class); if (growthProperty == null) { Log.error("Could not find the growth property of {}.", plantBlock.getLocalizedName()); } else { IFarmRegistry registry = FarmRegistry.getInstance(); int harvestAge = Collections.max(growthProperty.getAllowedValues()); int replantAge = plantBlock.getDefaultState().getValue(growthProperty); registry.registerFarmables(identifier, new FarmableAgingCrop(new ItemStack(plantItem), plantBlock, product, growthProperty, harvestAge, replantAge)); } } }
if (value instanceof EnumFacing) { final EnumFacing facing = getRotatedFacing(axisRotation, (EnumFacing) value); if (propertyFacing.getAllowedValues().contains(facing)) { return blockState.withProperty(propertyFacing, facing); 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);