resolved merge conflicts with dev

This commit is contained in:
bigguy345 committed 2026-01-13 18:14:38 +02:00
1 parent 83e11a05da
commit 95e7b3255e
8 files changed
+82 -21

No files matched your search

@@ -2,9 +2,12 @@ package noppes.npcs.client.gui.script;
import kamkeel.npcs.network.packets.request.script.BlockScriptPacket;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.blocks.tiles.TileScripted;
import noppes.npcs.constants.ScriptContext;
import noppes.npcs.controllers.ScriptHookController;
import java.util.ArrayList;
public class GuiScriptBlock extends GuiScriptInterface {
private final TileScripted tileScripted;
@@ -2,12 +2,16 @@ package noppes.npcs.client.gui.script;
import kamkeel.npcs.network.packets.request.script.EffectScriptPacket;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.client.gui.global.GuiNPCManageEffects;
import noppes.npcs.constants.ScriptContext;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptHookController;
import noppes.npcs.controllers.data.CustomEffect;
import noppes.npcs.controllers.data.EffectScript;
import java.util.ArrayList;
public class GuiScriptEffect extends GuiScriptInterface {
public final CustomEffect effect;
@@ -217,7 +217,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
}
// Set the scripting language for proper syntax highlighting
activeArea.setLanguage(this.handler.getLanguage());
// Use the container's language if available, otherwise fall back to handler's language
String language = (container != null) ? container.getLanguage() : this.handler.getLanguage();
activeArea.setLanguage(language);
// Set the script context for context-aware hook autocomplete
activeArea.setScriptContext(getScriptContext());
@@ -243,6 +245,13 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste"));
this.addButton(new GuiNpcButton(100, left1, this.guiTop + 21 + yoffset, 60, 20, "gui.copy"));
this.addButton(new GuiNpcButton(105, left1 + 61, this.guiTop + 21 + yoffset, 60, 20, "gui.remove"));
// Language toggle button (only if handler supports Janino)
if (handler.supportsJanino() && container != null) {
String langLabel = container.isJanino() ? "Java" : "ECMAScript";
this.addButton(new GuiNpcButton(113, left1, this.guiTop + 42 + yoffset, 121, 20, langLabel));
}
this.addButton(new GuiNpcButton(107, left1, this.guiTop + 66 + yoffset, 80, 20, "script.loadscript"));
GuiCustomScroll scroll = (new GuiCustomScroll(this, 0)).setUnselectable();
@@ -538,6 +547,40 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
this.setSubGui(new EventGuiScriptList((List) this.languages.get(this.handler.getLanguage()), container));
}
// Language toggle button - switch between ECMAScript and Java
if (guibutton.id == 113) {
int idx = getActiveScriptIndex();
if (idx >= 0 && idx < handler.getScripts().size()) {
IScriptUnit currentUnit = handler.getScripts().get(idx);
IScriptUnit newUnit;
if (currentUnit.isJanino()) {
// Switch from Java to ECMAScript
newUnit = new ScriptContainer(handler);
newUnit.setScript(currentUnit.getScript());
newUnit.setExternalScripts(new ArrayList<>(currentUnit.getExternalScripts()));
} else {
// Switch from ECMAScript to Java
newUnit = handler.createJaninoScriptUnit();
if (newUnit != null) {
newUnit.setScript(currentUnit.getScript());
newUnit.setExternalScripts(new ArrayList<>(currentUnit.getExternalScripts()));
} else {
return; // Handler doesn't support Janino
}
}
// Replace the script unit in the list
handler.getScripts().set(idx, newUnit);
// Clear the cached text area so it recreates with new language
textAreas.remove(idx);
// Reinitialize the GUI
initGui();
}
}
}
protected void setScript() {
@@ -6,13 +6,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.CustomItems;
import noppes.npcs.NBTTags;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.constants.ScriptContext;
import noppes.npcs.controllers.ScriptHookController;
import noppes.npcs.scripted.item.ScriptCustomItem;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
public class GuiScriptItem extends GuiScriptInterface {
private ScriptCustomItem item;
@@ -6,13 +6,17 @@ import net.minecraft.client.gui.GuiConfirmOpenLink;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
import noppes.npcs.constants.EnumScriptType;
import noppes.npcs.constants.ScriptContext;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptHookController;
import noppes.npcs.controllers.data.LinkedItem;
import noppes.npcs.controllers.data.LinkedItemScript;
import java.util.ArrayList;
public class GuiScriptLinkedItem extends GuiScriptInterface {
public final LinkedItem linkedItem;
@@ -6,13 +6,17 @@ import net.minecraft.client.gui.GuiConfirmOpenLink;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.client.gui.global.GuiNpcManageRecipes;
import noppes.npcs.constants.ScriptContext;
import noppes.npcs.controllers.ScriptContainer;
import noppes.npcs.controllers.ScriptHookController;
import noppes.npcs.controllers.data.RecipeAnvil;
import noppes.npcs.controllers.data.RecipeCarpentry;
import noppes.npcs.controllers.data.RecipeScript;
import java.util.ArrayList;
public class GuiScriptRecipe extends GuiScriptInterface {
public final int recipeId;
@@ -27,4 +27,23 @@ public interface IScriptHandler {
Map<Long, String> getConsoleText();
void clearConsole();
/**
* Create a new Janino (Java) script unit for this handler.
* Handlers that don't support Janino scripts should return null.
*
* @return A new JaninoScript instance, or null if not supported
*/
default IScriptUnit createJaninoScriptUnit() {
return null; // Default: Janino not supported
}
/**
* Check if this handler supports Janino (Java) scripts.
*
* @return true if createJaninoScriptUnit() can create valid Janino scripts
*/
default boolean supportsJanino() {
return createJaninoScriptUnit() != null;
}
}
+1 -16
View File
@@ -59,22 +59,7 @@ import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.gui.ICustomGui;
import noppes.npcs.api.handler.IActionManager;
import noppes.npcs.api.handler.IAbilityHandler;
import noppes.npcs.api.handler.IAnimationHandler;
import noppes.npcs.api.handler.IAttributeHandler;
import noppes.npcs.api.handler.ICloneHandler;
import noppes.npcs.api.handler.ICustomEffectHandler;
import noppes.npcs.api.handler.IDialogHandler;
import noppes.npcs.api.handler.IFactionHandler;
import noppes.npcs.api.handler.IMagicHandler;
import noppes.npcs.api.handler.INaturalSpawnsHandler;
import noppes.npcs.api.handler.IPartyHandler;
import noppes.npcs.api.handler.IProfileHandler;
import noppes.npcs.api.handler.IQuestHandler;
import noppes.npcs.api.handler.IRecipeHandler;
import noppes.npcs.api.handler.IScriptHookHandler;
import noppes.npcs.api.handler.ITransportHandler;
import noppes.npcs.api.handler.*;
import noppes.npcs.api.handler.data.IAnimation;
import noppes.npcs.api.handler.data.IFrame;
import noppes.npcs.api.handler.data.IFramePart;