Repository navigation
fix: show each held ingredient in soup and bowls #34
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 all commits
Commits
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
35 changes: 35 additions & 0 deletions
35
src/main/java/net/tfminecraft/cooking/manager/BowlIngredientLayout.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,35 @@ | ||
| package net.tfminecraft.cooking.manager; | ||
|
|
||
| import net.tfminecraft.interactiblefurniture.furniture.data.DisplayData; | ||
|
|
||
| /** | ||
| * Bowl ingredient slots share one centered offset in the furniture definition. | ||
| * Spread input_1..input_5 around the bowl interior when the soup is poured. | ||
| */ | ||
| public final class BowlIngredientLayout { | ||
| static final float RADIUS = 0.12f; | ||
| private static final int INPUTS = 5; | ||
|
|
||
| private BowlIngredientLayout() {} | ||
|
|
||
| public static DisplayData offsetFor(String slotId) { | ||
| Integer index = inputIndex(slotId); | ||
| if (index == null) return null; | ||
| double angle = -Math.PI / 2d + index * (2d * Math.PI / INPUTS); | ||
| DisplayData data = new DisplayData(); | ||
| data.setxPos((float) (Math.cos(angle) * RADIUS)); | ||
| data.setzPos((float) (Math.sin(angle) * RADIUS)); | ||
| return data; | ||
| } | ||
|
|
||
| static Integer inputIndex(String slotId) { | ||
| if (slotId == null || !slotId.startsWith("input_")) return null; | ||
| try { | ||
| int index = Integer.parseInt(slotId.substring("input_".length())); | ||
| if (index < 1 || index > INPUTS) return null; | ||
| return index - 1; | ||
| } catch (NumberFormatException e) { | ||
| return null; | ||
| } | ||
| } | ||
| } |
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
37 changes: 37 additions & 0 deletions
37
src/test/java/net/tfminecraft/cooking/manager/BowlIngredientLayoutTest.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,37 @@ | ||
| package net.tfminecraft.cooking.manager; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import net.tfminecraft.interactiblefurniture.furniture.data.DisplayData; | ||
|
|
||
| class BowlIngredientLayoutTest { | ||
|
|
||
| @Test | ||
| void ingredientsSitAroundTheBowlInsteadOfTheCenter() { | ||
| DisplayData[] placed = new DisplayData[5]; | ||
| for (int i = 1; i <= 5; i++) { | ||
| placed[i - 1] = BowlIngredientLayout.offsetFor("input_" + i); | ||
| double radius = Math.hypot(placed[i - 1].getxPos(), placed[i - 1].getzPos()); | ||
| assertEquals(BowlIngredientLayout.RADIUS, radius, 0.001); | ||
| } | ||
| for (int i = 0; i < placed.length; i++) { | ||
| for (int j = i + 1; j < placed.length; j++) { | ||
| double apart = Math.hypot( | ||
| placed[i].getxPos() - placed[j].getxPos(), | ||
| placed[i].getzPos() - placed[j].getzPos()); | ||
| assertTrue(apart > 0.1, "input slots overlap at the center"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| void soupLiquidAndHiddenFoodStayCentered() { | ||
| assertNull(BowlIngredientLayout.offsetFor("liquid")); | ||
| assertNull(BowlIngredientLayout.offsetFor("food_item")); | ||
| assertNull(BowlIngredientLayout.offsetFor("input_6")); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/test/java/net/tfminecraft/cooking/utils/SlotSnapshotTest.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,45 @@ | ||
| package net.tfminecraft.cooking.utils; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SlotSnapshotTest { | ||
|
|
||
| @Test | ||
| void snapshotKeepsEachIngredientModel() { | ||
| String encoded = Encoder.formatSlot("input_1", "APPLE", 0, "tfmc_cooking:red_meat_steak_boiled") | ||
| + ":" | ||
| + Encoder.formatSlot("input_2", "APPLE", 0, "tfmc_cooking:pork_steak_boiled"); | ||
|
|
||
| String[] parts = encoded.split(":", -1); | ||
| assertEquals(2, parts.length); | ||
| Encoder.ParsedSlot first = Encoder.parseSlot(parts[0]); | ||
| Encoder.ParsedSlot second = Encoder.parseSlot(parts[1]); | ||
|
|
||
| assertEquals("input_1", first.slotId()); | ||
| assertEquals("tfmc_cooking:red_meat_steak_boiled", first.itemModel()); | ||
| assertEquals("input_2", second.slotId()); | ||
| assertEquals("tfmc_cooking:pork_steak_boiled", second.itemModel()); | ||
| } | ||
|
|
||
| @Test | ||
| void snapshotKeepsItemModelKeysThatContainDots() { | ||
| Encoder.ParsedSlot parsed = Encoder.parseSlot( | ||
| Encoder.formatSlot("input_3", "CARROT", 4, "tfmc_cooking:item/carrot.boiled")); | ||
|
|
||
| assertEquals("CARROT", parsed.material()); | ||
| assertEquals(4, parsed.customModelData()); | ||
| assertEquals("tfmc_cooking:item/carrot.boiled", parsed.itemModel()); | ||
| } | ||
|
|
||
| @Test | ||
| void olderSnapshotsWithoutAnItemModelStillParse() { | ||
| Encoder.ParsedSlot parsed = Encoder.parseSlot("input_1.POTATO.0"); | ||
|
|
||
| assertEquals("POTATO", parsed.material()); | ||
| assertEquals(0, parsed.customModelData()); | ||
| assertNull(parsed.itemModel()); | ||
| } | ||
| } |
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.