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); }
@Overwrite public ImmutableList<IBlockState> getValidStates() { if (!isNumerical) { return validStates; } if (validStatesCache == null) { ImmutableList.Builder<IBlockState> states = ImmutableList.builder(); for (List<Comparable<?>> list : Cartesian.cartesianProduct(getAllowedValues())) { Map<IProperty<?>, Comparable<?>> propertyValueMap = MapPopulator.createMap(properties.values(), list); IBlockState state = createState(ImmutableMap.<IProperty<?>, Comparable<?>>builder().putAll(propertyValueMap).build(), unlistedProperties); states.add(state); } validStatesCache = states.build(); } return validStatesCache; }
List<BlockStateContainer.StateImplementation> validStates = Lists.newArrayList(); for (List<Comparable<?>> list : Cartesian.cartesianProduct(getAllowedValues())) { Map<IProperty<?>, Comparable<?>> map1 = MapPopulator.createMap(this.properties.values(), list); BlockStateContainer.StateImplementation blockstatecontainer$stateimplementation = createState(block, ImmutableMap.copyOf(map1), unlistedProperties);