Repository navigation
Recover scrap gems with configurable per-material chances #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
64 changes: 64 additions & 0 deletions
64
src/test/java/net/tfminecraft/recycler/ScrapRecoveryTest.java
This file contains hidden or 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,64 @@ | ||
| package net.tfminecraft.recycler; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import static org.mockito.Mockito.*; | ||
| import java.util.*; | ||
| import net.tfminecraft.advancedcrafting.loaders.IngredientLoader; | ||
| import net.tfminecraft.advancedcrafting.objects.data.ScrapProvenance; | ||
| import net.tfminecraft.advancedcrafting.objects.ingredients.Ingredient; | ||
| import net.tfminecraft.recycler.loader.ConfigLoader; | ||
| import net.tfminecraft.recycler.model.RecycleOutput; | ||
| import net.tfminecraft.recycler.provider.*; | ||
| import org.bukkit.Material; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class ScrapRecoveryTest extends TestSupport { | ||
| @Test | ||
| void ratesAreConfigurableClampedAndResetOnReload() throws Exception { | ||
| var loader = new ConfigLoader(); | ||
| loader.load(yaml("rates", "scrap_gem_return_rates:\n default: 0.12\n tiers:\n '1': 0\n '2': 2\n '3': .NaN\n '5': 0.9\n").toFile()); | ||
| assertEquals(Map.of("1", 0., "2", 1., "3", .5, "4", .75, "5", .9), Cache.scrapGemRates); | ||
| assertEquals(.12, Cache.scrapGemDefaultRate); | ||
| loader.load(yaml("rates", "{}").toFile()); | ||
| assertEquals(Map.of("1", .01, "2", .25, "3", .5, "4", .75), Cache.scrapGemRates); | ||
| assertEquals(.01, Cache.scrapGemDefaultRate); | ||
| } | ||
|
|
||
| @Test | ||
| void allRecordedGemsUseTheirTierIncludingMetalTypedGemsAndFutureTiers() { | ||
| var scrap = item(Material.IRON_NUGGET); | ||
| try (var provenance = mockStatic(ScrapProvenance.class); | ||
| var ingredients = mockStatic(IngredientLoader.class)) { | ||
| for (int tier : List.of(1, 2, 3, 4, 5)) { | ||
| var gem = mock(Ingredient.class, RETURNS_DEEP_STUBS); | ||
| when(gem.getPath()).thenReturn("m.gemstones.gem" + tier); | ||
| when(gem.getIngredientData().getTier()).thenReturn(tier); | ||
| ingredients.when(() -> IngredientLoader.getByString("gem")).thenReturn(gem); | ||
| provenance.when(() -> ScrapProvenance.readInputs(scrap)).thenReturn(Map.of("gem", 3)); | ||
| double rate = Cache.scrapGemRates.getOrDefault(Integer.toString(tier), Cache.scrapGemDefaultRate); | ||
| assertEquals(List.of(new RecycleOutput("m.gemstones.gem" + tier, 3, rate)), | ||
| new AlloyScrapProvider().resolveBaseOutputs(scrap)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void rollsEachMaterialUnitAcrossAmountsAndStacksWithoutFlooringOrRerollingPreview() { | ||
| var lines = List.of(new RecycleOutput("iron", 1, .5), new RecycleOutput("ruby", 2, .75), | ||
| new RecycleOutput("disabled", 1, 0), new RecycleOutput("guaranteed", 1, 1)); | ||
| var ctx = new RecycleContext(.5, 1, 2); | ||
| var preview = RecycleResult.of("scrap", lines, ctx); | ||
| assertEquals(List.of(new RecycleOutput("iron", 2, .5), new RecycleOutput("ruby", 4, .75), | ||
| new RecycleOutput("guaranteed", 2, 1)), preview.getOutputs()); | ||
| var rolls = new ArrayDeque<>(List.of(.49, .5, .74, .75, .1, .9, .99, .99)); | ||
| var result = RecycleResult.of("scrap", lines, ctx, true, rolls::remove); | ||
| assertEquals(List.of(new RecycleOutput("iron", 1), new RecycleOutput("ruby", 2), | ||
| new RecycleOutput("guaranteed", 2)), result.getOutputs()); | ||
| assertTrue(rolls.isEmpty()); | ||
| assertTrue(RecycleResult.of("scrap", List.of(new RecycleOutput("iron", 1, .5)), | ||
| new RecycleContext(1, 1, 1), true, () -> .9).getOutputs().isEmpty()); | ||
| assertEquals(List.of(new RecycleOutput("guaranteed", 2)), | ||
| RecycleResult.of("scrap", List.of(new RecycleOutput("guaranteed", 2, 1)), | ||
| new RecycleContext(1, 1, 1)).roll().getOutputs()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.