@Override public WeightedRandomModel retexture(ImmutableMap<String, String> textures) { if (textures.isEmpty()) return this; // Rebuild the texture list taking into account new textures Set<ResourceLocation> modelTextures = Sets.newHashSet(); // Recreate the MultiModelState so that the IModelState data is properly applied to the retextured model ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder(); List<IModel> retexturedModels = Lists.newArrayList(); for (int i = 0; i < variants.size(); i++) { IModel retextured = models.get(i).retexture(textures); modelTextures.addAll(retextured.getTextures()); retexturedModels.add(retextured); builder.add(Pair.of(retextured, variants.get(i).getState())); } return new WeightedRandomModel(variants, locations, modelTextures, retexturedModels, new MultiModelState(builder.build())); } }
public WeightedRandomModel(VariantList variants) throws Exception { this.variants = variants.getVariantList(); locations = new ArrayList<>(); textures = Sets.newHashSet(); models = new ArrayList<>(); ImmutableList.Builder<Pair<IModel, IModelState>> builder = ImmutableList.builder(); for (Variant variant : this.variants) { ResourceLocation location = variant.getModelLocation(); locations.add(location); IModel model = variant.process(ModelLoaderRegistry.getModel(location)); textures.addAll(model.getTextures()); models.add(model); IModelState modelDefaultState = model.getDefaultState(); Preconditions.checkNotNull(modelDefaultState, "Model %s returned null as default state", location); builder.add(Pair.of(model, new ModelStateComposition(variant.getState(), modelDefaultState))); } // If all variants are missing, add one with the missing model and default rotation if (models.size() == 0) { IModel missing = ModelLoaderRegistry.getMissingModel(); models.add(missing); builder.add(Pair.of(missing, TRSRTransformation.identity())); } defaultState = new MultiModelState(builder.build()); }
builder.add(Pair.of(model, variant.getState()));
builder.add(Pair.of(model, variant.getState()));