Skip to content

Commit 8c829a7

Browse files
XxFran10xXclaude
andcommitted
fix: ignore plate display slots when deciding whether food remains
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent eacaec1 commit 8c829a7

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎src/main/java/net/tfminecraft/cooking/manager/PlateManager.java‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,17 @@ public boolean hasSauce(Furniture f) {
112112
*/
113113
boolean hasLeftoverSauce(Furniture f, String leavingSlot) {
114114
if(!f.hasActiveSlot("sauce")) return false;
115+
return !hasFood(f, leavingSlot);
116+
}
117+
118+
// An active food slot counts even without a loaded item: restore can leave the item unset
119+
// while the display still shows the food.
120+
private boolean hasFood(Furniture f, String ignoredSlot) {
115121
for(String id : f.getActiveSlots().keySet()) {
116-
if(id.equals("sauce") || id.equals(leavingSlot)) continue;
117-
return false;
122+
if(id.equals("sauce") || id.contains("display") || id.equals(ignoredSlot)) continue;
123+
return true;
118124
}
119-
return true;
125+
return false;
120126
}
121127

122128
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -134,7 +140,7 @@ public void takeItem(FurnitureSlotItemTakeEvent e) {
134140
public void addSauce(Player p, Furniture f, FoodItem sauce, ItemStack base) {
135141
if (hasSauce(f)) return;
136142
// Sauce on an empty plate would never reach food added later, so keep the ladle full.
137-
if (f.getActiveSlots().isEmpty()) return;
143+
if (!hasFood(f, null)) return;
138144

139145
// Replace player ladle with empty ladle
140146
p.getInventory().setItemInMainHand(

‎src/test/java/net/tfminecraft/cooking/manager/PlateManagerTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,21 @@ void sauceOnAnEmptyPlateReturnsBeforeTouchingThePlayerOrLadle() {
157157
assertDoesNotThrow(() -> new PlateManager().addSauce(null, plate, null, null));
158158
assertTrue(plate.getActiveSlots().isEmpty());
159159
}
160+
161+
@Test
162+
void displaySlotsDoNotCountAsFood() {
163+
Furniture plate = plateWithSauceVisual();
164+
plate.getActiveSlots().put("display_1", new PlacedSlot(plate, "display_1"));
165+
166+
assertTrue(new PlateManager().hasLeftoverSauce(plate, null));
167+
}
168+
169+
@Test
170+
void sauceOnADisplayOnlyPlateReturnsBeforeTouchingThePlayerOrLadle() {
171+
Furniture plate = new Furniture("plate", null, UUID.randomUUID());
172+
plate.getActiveSlots().put("display_1", new PlacedSlot(plate, "display_1"));
173+
174+
assertDoesNotThrow(() -> new PlateManager().addSauce(null, plate, null, null));
175+
assertFalse(plate.hasActiveSlot("sauce"));
176+
}
160177
}

0 commit comments

Comments
 (0)