-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
138 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 18 additions & 22 deletions
40
addons/SkylliaOre/src/main/java/fr/euphyllia/skylliaore/Cache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
addons/SkylliaOre/src/main/java/fr/euphyllia/skylliaore/utils/OptimizedGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fr.euphyllia.skylliaore.utils; | ||
|
||
import fr.euphyllia.skylliaore.api.Generator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class OptimizedGenerator { | ||
private final Generator generator; | ||
private final List<BlockProbability> cumulativeProbabilities; | ||
private final double totalChance; | ||
|
||
public OptimizedGenerator(Generator generator) { | ||
this.generator = generator; | ||
this.cumulativeProbabilities = new ArrayList<>(); | ||
double cumulative = 0.0; | ||
for (Map.Entry<String, Double> entry : generator.blockChances().entrySet()) { | ||
cumulative += entry.getValue(); | ||
cumulativeProbabilities.add(new BlockProbability(entry.getKey(), cumulative)); | ||
} | ||
this.cumulativeProbabilities.sort(Comparator.comparingDouble(BlockProbability::cumulativeChance)); | ||
this.totalChance = cumulative; | ||
} | ||
|
||
public Generator getGenerator() { | ||
return generator; | ||
} | ||
|
||
public List<BlockProbability> getCumulativeProbabilities() { | ||
return cumulativeProbabilities; | ||
} | ||
|
||
public double getTotalChance() { | ||
return totalChance; | ||
} | ||
|
||
public record BlockProbability(String blockKey, double cumulativeChance) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters