Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ItemsAdder/tfmc_cooking/contents/categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ categories:
- tfmc_cooking:carrot_rotten
- tfmc_cooking:wheat_rotten
- tfmc_cooking:apple_rotten
- tfmc_cooking:brown_mushroom_rotten
- tfmc_cooking:red_mushroom_rotten
- tfmc_cooking:egg_rotten
- tfmc_cooking:beetroot_rotten
- tfmc_cooking:potato_rotten
Expand Down Expand Up @@ -307,12 +309,16 @@ categories:
- tfmc_cooking:fried_egg_burnt
- tfmc_cooking:fried_egg_rotten
- tfmc_cooking:grilled_mushroom
- tfmc_cooking:grilled_mushroom_burnt
- tfmc_cooking:grilled_mushroom_rotten
- tfmc_cooking:maple_syrup
- tfmc_cooking:mashed_potatoes
- tfmc_cooking:mustard
- tfmc_cooking:mustard_seeds
- tfmc_cooking:olive_oil
- tfmc_cooking:popcorn
- tfmc_cooking:popcorn_burnt
- tfmc_cooking:popcorn_rotten
- tfmc_cooking:rice
- tfmc_cooking:stock
- tfmc_cooking:sunflower_seeds
Expand Down
28 changes: 28 additions & 0 deletions ItemsAdder/tfmc_cooking/contents/intermediates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,31 @@ items:
material: PAPER
generate: false
model_path: item/intermediate/tomato_sauce

grilled_mushroom_burnt:
display_name: "Grilled Mushroom Burnt"
resource:
material: PAPER
generate: false
model_path: item/intermediate/grilled_mushroom_burnt

grilled_mushroom_rotten:
display_name: "Grilled Mushroom Rotten"
resource:
material: PAPER
generate: false
model_path: item/intermediate/grilled_mushroom_rotten

popcorn_burnt:
display_name: "Popcorn Burnt"
resource:
material: PAPER
generate: false
model_path: item/intermediate/popcorn_burnt

popcorn_rotten:
display_name: "Popcorn Rotten"
resource:
material: PAPER
generate: false
model_path: item/intermediate/popcorn_rotten
14 changes: 14 additions & 0 deletions ItemsAdder/tfmc_cooking/contents/items.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1626,3 +1626,17 @@ items:
material: TROPICAL_FISH
generate: false
model_path: item/ingredients/poultry/poultry_roast_filet_rotten

brown_mushroom_rotten:
display_name: "Brown Mushroom Rotten"
resource:
material: PAPER
generate: false
model_path: item/vanilla/brown_mushroom_rotten

red_mushroom_rotten:
display_name: "Red Mushroom Rotten"
resource:
material: PAPER
generate: false
model_path: item/vanilla/red_mushroom_rotten
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "tfmc_cooking:item/intermediate/grilled_mushroom_burnt" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "tfmc_cooking:item/intermediate/grilled_mushroom_rotten" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "tfmc_cooking:item/intermediate/popcorn_burnt" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "tfmc_cooking:item/intermediate/popcorn_rotten" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "tfmc_cooking:item/vanilla/brown_mushroom_rotten" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"parent": "minecraft:item/generated",
"textures": { "layer0": "tfmc_cooking:item/vanilla/red_mushroom_rotten" }
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Cooking makes food an interactive part of everyday life. Players grow and gather

## Features

- **Working kitchens** — fry, boil, prepare sauces and soups, and bake with cookware, heat sources, and fuelled ovens. Leaving food cooking too long can burn it.
- **Working kitchens** — fry, boil, prepare sauces and soups, and bake with cookware, heat sources, and fuelled ovens. Leaving food cooking too long can burn it. The frying pan fries eggs, grills mushrooms and pops chopped corn into popcorn: a cooking option can name the food a piece turns into once it is done (`output` in `types.yml`).
- **Food preparation** — milling stones, mixing bowls, butter churns, sausage makers, and baking trays provide different ways to transform ingredients.
- **Sandwiches** — lay a slice of bread on a cutting board, add spreads, cheese and vegetables, close it with another slice and pick it up. Its fillings name it, and its food, quality and freshness come from its layers (`sandwiches.yml`). Its layers also earn it bonuses such as Hearty, Buttered or Well-Rounded (`bonuses` in `sandwiches.yml`).
- **Pizzas** — place a pizza peel, put dough on it, spread a paste and add cheese, vegetables, fruit, sausage and spices, then carry the peel into a lit oven to bake. A baked pizza is taken off a slice at a time. Its toppings name it, and its food, quality and freshness come from its layers (`pizzas.yml`). Its toppings also earn it bonuses such as Saucy, Extra Cheesy or Well Seasoned (`bonuses` in `pizzas.yml`).
Expand Down
96 changes: 96 additions & 0 deletions src/main/java/net/tfminecraft/cooking/cooking/CookingOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package net.tfminecraft.cooking.cooking;

import java.util.ArrayList;
import java.util.List;

import net.tfminecraft.cooking.enums.Method;
import net.tfminecraft.cooking.enums.Tag;
import net.tfminecraft.cooking.item.FoodItem;
import net.tfminecraft.cooking.item.data.CookData;
import net.tfminecraft.cooking.item.data.CookParameter;
import net.tfminecraft.cooking.item.tag.TagQuality;
import net.tfminecraft.cooking.item.tag.TagTrack;
import net.tfminecraft.cooking.utils.FoodParser;

/**
* A cooking option that names an output (types.yml cooking-options.<method>.output) turns the piece into that
* food once it's done: chopped corn in the frying pan pops into popcorn. The piece cooks raw, then becomes the output,
* cooked (or burnt, if it burnt first), and keeps cooking by the same clock, so popcorn left too long burns as popcorn.
*/
public final class CookingOutput {
private static final String COOKED_TRACK = "cooked";

private CookingOutput() {}

/**
* A piece whose type has no doneness of its own (cooking-options with only outputs) starts raw once it's in the
* cookware, so the usual raw, cooked, burnt steps can follow.
*/
static void startRaw(FoodItem piece, Method method) {
if (output(piece, method) == null || piece.getCookData().cooksInPlace() || piece.hasTagTrack(COOKED_TRACK)) {
return;
}
piece.addTagTrack(COOKED_TRACK);
}

/**
* A piece taken off before it turned is still what went in: drops the raw track {@link #startRaw} gave it.
* True when the piece is such an unturned input.
*/
static boolean restoreInput(FoodItem piece, Method method) {
if (output(piece, method) == null || piece.getCookData().cooksInPlace()) {
return false;
}
if (piece.hasTagTrack(COOKED_TRACK) && !piece.hasTag(Tag.RAW)) {
return false;
}
piece.removeTrack(COOKED_TRACK);
return true;
}

/**
* The food the piece has become, once it is no longer raw, or the piece itself. The output keeps the piece's
* stars, its ageing tracks (freshness, warmth), lineage and ingredients, and takes its origin when the output string
* names none. Its own tags come from the output string; preparation tags such as Chopped stay behind.
*/
static FoodItem turn(FoodItem piece, Method method) {
String output = output(piece, method);
if (output == null || !piece.hasTagTrack(COOKED_TRACK) || piece.hasTag(Tag.RAW)) {
return piece;
}
FoodParser.Result parsed = FoodParser.parse(output);
if (parsed == null || parsed.template == null) {
return piece;
}
FoodItem turned = parsed.template;
if (turned.getOrigin() == null || turned.getOrigin().isBlank()) {
turned.setOrigin(piece.getOrigin());
}
List<TagTrack> kept = new ArrayList<>();
for (TagTrack track : piece.getTagTracks()) {
if (track.isAgeable() || COOKED_TRACK.equals(track.getId())) {
kept.add(track);
}
}
for (TagTrack track : kept) {
turned.addOrModifyTrack(track);
turned.setAgeRemainder(track.getId(), piece.getAgeRemainder(track.getId()));
}
int stars = piece.getEffectiveQuality() - TagQuality.stars(kept);
turned.setQualityRange(stars, stars);
turned.setLineage(piece.getLineage());
for (String ingredient : piece.getIngredients()) {
turned.addIngredient(ingredient);
}
CookData clock = new CookData(turned, piece.getCookData());
clock.getParameters().replaceAll((m, parameter) -> parameter.withoutOutput());
turned.cookData = clock;
turned.setLastUpdate(piece.getLastUpdate());
return turned;
}

private static String output(FoodItem piece, Method method) {
CookParameter parameter = piece.getCookData().getParameters().get(method);
return parameter == null ? null : parameter.getOutput();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.bukkit.Sound;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import net.tfminecraft.cooking.cache.ItemCache;
import net.tfminecraft.cooking.enums.Method;
Expand Down Expand Up @@ -90,8 +91,20 @@ public void tick() {
}

protected void applySlotUpdate(String slot, FoodItem item) {
applySlotUpdate(slot, item, null);
}

/** Redraws a slot's piece for its food; a non-null name renames it, for a piece that has become another food. */
// Keep the existing legacy text representation of item names.
@SuppressWarnings("deprecation")
protected void applySlotUpdate(String slot, FoodItem item, String displayName) {
if (!f.hasActiveSlot(slot)) return;
ItemStack stack = f.getActiveSlot(slot).get().getCurrentItem();
if (displayName != null && stack != null && stack.hasItemMeta()) {
ItemMeta meta = stack.getItemMeta();
meta.setDisplayName(displayName);
stack.setItemMeta(meta);
}
stack = ItemUpdater.applyItemUpdate(stack, item, f.getId());
if (stack == null) return;
f.getActiveSlot(slot).get().forceModel(stack);
Expand Down Expand Up @@ -196,6 +209,7 @@ public void slotAdd(FurnitureSlotItemAddEvent e) {
e.setCancelled(true);
return;
}
CookingOutput.startRaw(fi, method);
if(!fi.hasTag(Tag.RAW)) {
e.setCancelled(true);
return;
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/net/tfminecraft/cooking/cooking/FryingReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import net.tfminecraft.cooking.quality.CompositionQualityResolver;
import net.tfminecraft.cooking.quality.CompositionResult;
import net.tfminecraft.cooking.utils.IngredientConverter;
import net.tfminecraft.cooking.utils.ItemBuilder;
import net.tfminecraft.cooking.utils.ItemUpdater;
import net.tfminecraft.cooking.utils.WarmthUtils;
import net.tfminecraft.interactiblefurniture.events.FurnitureInteractEvent;
Expand Down Expand Up @@ -67,24 +68,37 @@ private void handleParticlesAndDanger() {

private void handleCookingSlots() {
for (Map.Entry<String, FoodItem> entry : slots.entrySet()) {
String slot = entry.getKey();
FoodItem item = entry.getValue();
if (!item.canBeCooked()) continue;
if (!item.getCookData().tick()) continue;
applySlotUpdate(slot, item);
showCookStep(entry);
}
}

private void burnAllSlots() {
for (Map.Entry<String, FoodItem> entry : slots.entrySet()) {
String slot = entry.getKey();
FoodItem item = entry.getValue();
if (!item.canBeCooked()) continue;
item.getCookData().setCurrentTime(item.getCookData().getParameters().get(method).getBurnTime());
super.applySlotUpdate(slot, item);
showCookStep(entry);
}
}

/**
* Shows a piece's new cook step. A piece whose pan option names an output becomes that food here (chopped corn
* pops into Popcorn), taking the output's name.
*/
private void showCookStep(Map.Entry<String, FoodItem> entry) {
FoodItem item = entry.getValue();
FoodItem turned = CookingOutput.turn(item, method);
if (turned == item) {
applySlotUpdate(entry.getKey(), item);
return;
}
entry.setValue(turned);
applySlotUpdate(entry.getKey(), turned, ItemBuilder.displayName(turned));
}

@Override
public void interact(FurnitureInteractEvent e) {
Player p = e.getPlayer();
Expand Down Expand Up @@ -207,7 +221,8 @@ public void slotRemove(FurnitureSlotItemTakeEvent e) {
e.setCancelled(true);
return;
}
if (data.getCurrentTime() < 5) {
// A piece that hasn't turned into its output yet comes back as it went in, and leaves the butter.
if (CookingOutput.restoreInput(fi, method) || data.getCurrentTime() < 5) {
ItemStack returned = ItemUpdater.applyItemUpdate(item, fi, null);
if (returned != null) {
e.setItem(returned);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/tfminecraft/cooking/item/FoodItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public FoodItem(FoodItem other) {

for (TagTrack t : other.tags.values())
this.tags.put(t.getId(), new TagTrack(t));
if(this.canBeCooked() && !hasTagTrack("cooked")) addOrModifyTrack(TrackLoader.getByString("cooked"));
if(cookData.cooksInPlace() && !hasTagTrack("cooked")) addOrModifyTrack(TrackLoader.getByString("cooked"));
}


Expand Down
16 changes: 15 additions & 1 deletion src/main/java/net/tfminecraft/cooking/item/data/CookData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public CookData(String id, ConfigurationSection config) {
for(String key : config.getKeys(false)) {
ConfigurationSection param = config.getConfigurationSection(key);
try {
parameters.put(Method.valueOf(key.toUpperCase(java.util.Locale.ROOT)), new CookParameter(param.getInt("tag", 1), param.getInt("time", 15), param.getInt("burn", 30)));
parameters.put(Method.valueOf(key.toUpperCase(java.util.Locale.ROOT)), new CookParameter(param.getInt("tag", 1), param.getInt("time", 15), param.getInt("burn", 30),
param.getString("output", null)));
} catch (Exception e) {
Bukkit.getLogger().info("Failed to create cooking data for "+id);
}
Expand Down Expand Up @@ -52,6 +53,19 @@ public FoodItem getFoodItem() {
public boolean hasMethod(Method m) {
return parameters.containsKey(m);
}

/**
* True when some method cooks this food as itself, so it carries a cooked track (Raw) from the start. A food whose
* only options name an output (chopped corn, which pops into popcorn) is not raw until it's in the cookware.
*/
public boolean cooksInPlace() {
for (CookParameter parameter : parameters.values()) {
if (parameter.getOutput() == null) {
return true;
}
}
return false;
}
public Method getCurrentMethod() {
return currentMethod;
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/tfminecraft/cooking/item/data/CookParameter.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package net.tfminecraft.cooking.item.data;

/**
* One cooking option of a food type (types.yml cooking-options.&lt;method&gt;): the cooked tag it reaches, when, when
* it burns, and optionally the food it turns into once it's done (output), such as chopped corn popping into popcorn.
*/
public class CookParameter {
private int tag;
private int time;
private int burntime;
private final String output;

public CookParameter(int tag, int time, int burntime) {
this(tag, time, burntime, null);
}

public CookParameter(int tag, int time, int burntime, String output) {
this.tag = tag;
this.time = time;
this.burntime = burntime;
this.output = output == null || output.isBlank() ? null : output.trim();
}

public int getTag() {
Expand All @@ -20,4 +30,14 @@ public int getTime() {
public int getBurnTime() {
return burntime;
}

/** The food string this option turns the piece into once it's no longer raw, or null if it stays itself. */
public String getOutput() {
return output;
}

/** The same timings without an output: what the piece keeps cooking by once it has turned into its output. */
public CookParameter withoutOutput() {
return output == null ? this : new CookParameter(tag, time, burntime);
}
}
Loading
Loading