improve ProbabilityCollection#map impl

This commit is contained in:
dfsek
2021-06-14 19:13:16 -07:00
parent 733b9fab4b
commit 7473119238
4 changed files with 5 additions and 9 deletions

View File

@@ -49,12 +49,7 @@ public class ProbabilityCollection<E> implements Collection<E> {
public <T> ProbabilityCollection<T> map(Function<E, T> mapper, boolean carryNull) {
ProbabilityCollection<T> newCollection = new ProbabilityCollection<>();
newCollection.array = new Object[array.length];
for(int i = 0; i < array.length; i++) {
if(carryNull && array[i] == null) continue;
newCollection.array[i] = mapper.apply((E) array[i]);
}
cont.forEach((o, count) -> newCollection.add(mapper.apply(o), count.get()));
return newCollection;
}

View File

@@ -2,6 +2,7 @@ package com.dfsek.terra.config.loaders.config.biome.templates.stage;
import com.dfsek.tectonic.annotations.Value;
import com.dfsek.tectonic.loading.object.ObjectTemplate;
import com.dfsek.terra.api.config.meta.MetaValue;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.api.util.seeded.SeededBuilder;
import com.dfsek.terra.api.util.seeded.StageSeeded;
@@ -9,7 +10,7 @@ import com.dfsek.terra.api.world.biome.pipeline.stages.Stage;
public abstract class StageTemplate implements ObjectTemplate<SeededBuilder<Stage>>, StageSeeded {
@Value("noise")
protected NoiseSeeded noise;
protected MetaValue<NoiseSeeded> noise;
@Override
public StageSeeded get() {

View File

@@ -8,6 +8,6 @@ import com.dfsek.terra.config.loaders.config.biome.templates.stage.StageTemplate
public class ExpanderStageTemplate extends StageTemplate {
@Override
public Stage apply(Long seed) {
return new ExpanderStage(new FractalExpander(noise.apply(seed)));
return new ExpanderStage(new FractalExpander(noise.get().apply(seed)));
}
}

View File

@@ -31,6 +31,6 @@ public class BorderListMutatorTemplate extends MutatorStageTemplate {
replace.forEach((keyBuilder, replacements) -> replaceMap.put(keyBuilder.apply(seed), replacements.map(replacement -> replacement.apply(seed), true)));
return new BorderListMutator(replaceMap, from, defaultReplace, noise.apply(seed), defaultTo.map(biomeBuilder -> biomeBuilder.apply(seed), true));
return new BorderListMutator(replaceMap, from, defaultReplace, noise.get().apply(seed), defaultTo.map(biomeBuilder -> biomeBuilder.apply(seed), true));
}
}