Files
CustomNPC-Plus/src/main/java/noppes/npcs/controllers/data/RecipeScript.java
T

77 lines
2.0 KiB
Java
Raw Normal View History

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;
import noppes.npcs.janino.EventJaninoScript;
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 {
/**
* The recipe ID for packet communication. -1 if not bound.
*/
2026-01-18 17:57:10 +02:00
private int recipeId = -1;
/**
* Whether this is an anvil recipe (vs carpentry).
*/
2026-01-18 17:57:10 +02:00
private boolean anvil = false;
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-18 17:57:10 +02:00
/**
* Create a RecipeScript bound to a specific recipe (for GUI use).
*
2026-01-18 17:57:10 +02:00
* @param recipeId The ID of the recipe
* @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-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
}
@Override
public IScriptUnit createJaninoScriptUnit() {
return new EventJaninoScript(ScriptContext.RECIPE);
}
2025-07-09 15:40:31 -04:00
@Override
public String noticeString() {
return "RecipeScript";
}
2026-01-18 17:57:10 +02:00
@Override
public void requestData() {
if (recipeId >= 0)
2026-01-18 17:57:10 +02:00
RecipeScriptPacket.Get(anvil, recipeId);
}
2026-01-18 17:57:10 +02:00
@Override
public void sendSavePacket(int index, int totalCount, NBTTagCompound nbt) {
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;
}
}
}