2025-07-09 15:40:31 -04:00
|
|
|
package noppes.npcs.controllers.data;
|
|
|
|
|
|
2026-01-18 17:57:10 +02:00
|
|
|
import kamkeel.npcs.network.packets.request.script.RecipeScriptPacket;
|
2025-07-09 15:40:31 -04:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2026-01-22 14:27:48 -05:00
|
|
|
import noppes.npcs.constants.ScriptContext;
|
2025-07-09 15:40:31 -04:00
|
|
|
|
2026-01-18 17:57:10 +02:00
|
|
|
/**
|
|
|
|
|
* Script handler for Recipe scripts (both carpentry and anvil).
|
|
|
|
|
* Manages a single script container for recipe hooks (pre, post).
|
|
|
|
|
*/
|
|
|
|
|
public class RecipeScript extends SingleScriptHandler implements IScriptHandlerPacket {
|
2026-01-22 23:07:38 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The recipe ID for packet communication. -1 if not bound.
|
|
|
|
|
*/
|
2026-01-18 17:57:10 +02:00
|
|
|
private int recipeId = -1;
|
2026-01-22 23:07:38 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether this is an anvil recipe (vs carpentry).
|
|
|
|
|
*/
|
2026-01-18 17:57:10 +02:00
|
|
|
private boolean anvil = false;
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-18 17:57:10 +02:00
|
|
|
/**
|
|
|
|
|
* Create an unbound RecipeScript (for server-side use).
|
|
|
|
|
*/
|
|
|
|
|
public RecipeScript() {
|
2025-07-09 15:40:31 -04:00
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-18 17:57:10 +02:00
|
|
|
/**
|
|
|
|
|
* Create a RecipeScript bound to a specific recipe (for GUI use).
|
2026-01-22 23:07:38 -05:00
|
|
|
*
|
2026-01-18 17:57:10 +02:00
|
|
|
* @param recipeId The ID of the recipe
|
2026-01-22 23:07:38 -05:00
|
|
|
* @param anvil true for anvil recipe, false for carpentry recipe
|
2026-01-18 17:57:10 +02:00
|
|
|
*/
|
|
|
|
|
public RecipeScript(int recipeId, boolean anvil) {
|
|
|
|
|
this.recipeId = recipeId;
|
|
|
|
|
this.anvil = anvil;
|
2025-07-09 15:40:31 -04:00
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-18 17:57:10 +02:00
|
|
|
@Override
|
2026-01-22 14:27:48 -05:00
|
|
|
public ScriptContext getContext() {
|
|
|
|
|
return ScriptContext.RECIPE;
|
2026-01-18 17:57:10 +02:00
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2025-07-09 15:40:31 -04:00
|
|
|
@Override
|
|
|
|
|
public String noticeString() {
|
|
|
|
|
return "RecipeScript";
|
|
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-18 17:57:10 +02:00
|
|
|
@Override
|
|
|
|
|
public void requestData() {
|
2026-01-22 23:07:38 -05:00
|
|
|
if (recipeId >= 0)
|
2026-01-18 17:57:10 +02:00
|
|
|
RecipeScriptPacket.Get(anvil, recipeId);
|
|
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-18 17:57:10 +02:00
|
|
|
@Override
|
|
|
|
|
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
|
2026-01-22 23:07:38 -05:00
|
|
|
if (recipeId >= 0)
|
2026-01-18 17:57:10 +02:00
|
|
|
RecipeScriptPacket.Save(anvil, recipeId, index, totalCount, nbt);
|
2025-07-09 15:40:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ScriptType {
|
|
|
|
|
PRE("pre"),
|
|
|
|
|
POST("post");
|
|
|
|
|
public final String function;
|
2025-07-23 14:22:52 -04:00
|
|
|
|
2025-07-09 15:40:31 -04:00
|
|
|
ScriptType(String functionName) {
|
|
|
|
|
this.function = functionName;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
}
|