mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 02:39:05 +00:00
Added a configurable expansion to scripts' length, adding 65535 more characters with every additional increase.
This commit is contained in:
1 parent
b4f112ee89
commit
9fc408e598
4 files changed
+68
-12
No files matched your search
@@ -54,6 +54,11 @@ public class CustomNpcs {
|
||||
@ConfigProp(info = "Enables global NPC scripts to be used in the scripter. You can still see and write code in the scripter, but these scripts won't run. False by default, use with caution!")
|
||||
public static boolean GlobalNPCScripts = false;
|
||||
|
||||
@ConfigProp(info = "If scripts are too long (>65535 characters), they normally won't be saved in NBT data.\n" +
|
||||
"This config adds additional compound tags to scripts that need it, so you can store much larger scripts!\n" +
|
||||
"Every additional compound tag adds 65535 more characters to your script length limit. Use incrementally, with caution.")
|
||||
public static int ExpandedScriptLimit = 2;
|
||||
|
||||
@ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.")
|
||||
public static int NpcNavRange = 32;
|
||||
|
||||
@@ -216,6 +221,9 @@ public class CustomNpcs {
|
||||
if (TrackingInfoAlignment > 8)
|
||||
TrackingInfoAlignment = 8;
|
||||
|
||||
if (ExpandedScriptLimit < 0)
|
||||
ExpandedScriptLimit = 0;
|
||||
|
||||
EnchantInterface.load();
|
||||
CustomItems.load();
|
||||
|
||||
|
||||
@@ -320,11 +320,11 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
public void confirmClicked(boolean flag, int i) {
|
||||
if(flag) {
|
||||
if(i == 0) {
|
||||
this.openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting");
|
||||
this.openLink("https://www.curseforge.com/minecraft/mc-mods/customnpc-plus");
|
||||
}
|
||||
|
||||
if(i == 1) {
|
||||
this.openLink("http://www.kodevelopment.nl/customnpcs/api/");
|
||||
this.openLink("https://kamkeel.github.io/CustomNPC-Plus/");
|
||||
}
|
||||
|
||||
if(i == 2) {
|
||||
@@ -380,6 +380,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
if(guibutton.id == 101) {
|
||||
(this.getTextField(2)).setText(NoppesStringUtils.getClipboardContents());
|
||||
this.setScript();
|
||||
}
|
||||
|
||||
ScriptContainer container;
|
||||
@@ -427,7 +428,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
container = (ScriptContainer)this.handler.getScripts().get(this.activeTab - 1);
|
||||
if(container != null) {
|
||||
this.setScript();
|
||||
this.AWTWindow = new GuiJTextArea(container.script).setListener(this);
|
||||
AWTWindow = new GuiJTextArea(container.script).setListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
private int startClick = -1;
|
||||
private boolean clickVerticalBar = false;
|
||||
private boolean wrapLine = true;
|
||||
|
||||
private List<String> lines = new ArrayList<>();
|
||||
|
||||
public GuiNpcTextArea(int id,GuiScreen guiscreen, int i, int j, int k, int l, String s) {
|
||||
super(id,guiscreen, i, j, k, l, s);
|
||||
posX = i;
|
||||
@@ -39,6 +40,24 @@ public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
this.setText(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
super.setText(text);
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
StringBuilder line = new StringBuilder();
|
||||
for(char c : getText().toCharArray()){
|
||||
if(c == '\r' || c == '\n'){
|
||||
list.add(line.toString());
|
||||
line = new StringBuilder();
|
||||
}
|
||||
else
|
||||
line.append(c);
|
||||
}
|
||||
list.add(line.toString());
|
||||
lines = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCursorCounter(){
|
||||
cursorCounter++;
|
||||
@@ -52,10 +71,12 @@ public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
if(c == '\r' || c == '\n'){
|
||||
this.setText(originalText.substring(0, cursorPosition) + c + originalText.substring(cursorPosition));
|
||||
}
|
||||
this.setCursorPositionZero();
|
||||
boolean bo = super.textboxKeyTyped(c, i);
|
||||
String newText = getText();
|
||||
this.setText(newText);
|
||||
|
||||
this.setCursorPositionZero();
|
||||
this.moveCursorBy(cursorPosition);
|
||||
boolean bo = super.textboxKeyTyped(c, i);
|
||||
String newText = getText();
|
||||
if(i != Keyboard.KEY_DELETE)
|
||||
cursorPosition += newText.length() - originalText.length();
|
||||
if(i == Keyboard.KEY_LEFT && cursorPosition > 0)
|
||||
@@ -63,7 +84,6 @@ public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
if(i == Keyboard.KEY_RIGHT && cursorPosition < newText.length())
|
||||
cursorPosition++;
|
||||
return bo;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -84,7 +104,6 @@ public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
int x = i - posX;
|
||||
int y = (j - posY - 4) / font.height() + getStartLineY();
|
||||
cursorPosition = 0;
|
||||
List<String> lines = getLines();
|
||||
int charCount = 0;
|
||||
int lineCount = 0;
|
||||
int maxSize = width - (isScrolling()?14:4);
|
||||
@@ -153,8 +172,7 @@ public class GuiNpcTextArea extends GuiNpcTextField implements IGui{
|
||||
int startLine = getStartLineY();
|
||||
|
||||
int maxLine = height / font.height() + startLine;
|
||||
|
||||
List<String> lines = getLines();
|
||||
|
||||
int charCount = 0;
|
||||
int lineCount = 0;
|
||||
int maxSize = width - (isScrolling()?14:4);
|
||||
|
||||
@@ -47,6 +47,13 @@ public class ScriptContainer {
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
this.script = compound.getString("Script");
|
||||
for (int i = 0; i < CustomNpcs.ExpandedScriptLimit; i++) {
|
||||
if (compound.hasKey("ExpandedScript"+i)) {
|
||||
this.script += compound.getString("ExpandedScript"+i);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//this.type = compound.getString("Type");
|
||||
this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10));
|
||||
this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10));
|
||||
@@ -54,7 +61,29 @@ public class ScriptContainer {
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
|
||||
compound.setString("Script", this.script);
|
||||
if (this.script.length() < 65535) {
|
||||
compound.setString("Script", this.script);
|
||||
} else {
|
||||
if (CustomNpcs.ExpandedScriptLimit > 0) {
|
||||
int i = 0;
|
||||
int length = this.script.length();
|
||||
while (length > 0 && i <= CustomNpcs.ExpandedScriptLimit) {
|
||||
String str = "";
|
||||
if (i == 0) {
|
||||
compound.setString("Script", this.script.substring(0, 65535));
|
||||
str = this.script.substring(0, 65535);
|
||||
} else {
|
||||
int end = (length - 65535) >= 0 ? 65535 * (i + 1) : 65535 * i + length;
|
||||
str = this.script.substring(65535 * i, end);
|
||||
compound.setString("ExpandedScript" + (i - 1), str);
|
||||
}
|
||||
i++;
|
||||
length -= str.length();
|
||||
}
|
||||
} else {
|
||||
compound.setString("Script", this.script.substring(0, 65535));
|
||||
}
|
||||
}
|
||||
//compound.setString("Type", this.type);
|
||||
compound.setTag("Console", NBTTags.NBTLongStringMap(this.console));
|
||||
compound.setTag("ScriptList", NBTTags.nbtStringList(this.scripts));
|
||||
|
||||
Reference in new issue
Block a user