mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 14:35:12 +00:00
Scripted Items Display Errors & Fix Console Scroll Wheel and Scroll Bar
This commit is contained in:
1 parent
4202cb7271
commit
eeb6b2ea8b
8 files changed
+198
-40
No files matched your search
@@ -58,6 +58,8 @@ import kamkeel.npcs.network.packets.request.role.RoleCompanionUpdatePacket;
|
||||
import kamkeel.npcs.network.packets.request.role.RoleGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.role.RoleSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.script.*;
|
||||
import kamkeel.npcs.network.packets.request.script.item.ItemScriptErrorPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.item.ItemScriptPacket;
|
||||
import kamkeel.npcs.network.packets.request.tags.*;
|
||||
import kamkeel.npcs.network.packets.request.transform.TransformGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.transform.TransformLoadPacket;
|
||||
@@ -115,6 +117,7 @@ public class PacketHandler {
|
||||
REQUEST_PACKET.registerPacket(new ForgeScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new GlobalNPCScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ItemScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ItemScriptErrorPacket());
|
||||
REQUEST_PACKET.registerPacket(new NPCScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new PlayerScriptPacket());
|
||||
REQUEST_PACKET.registerPacket(new ScriptInfoPacket());
|
||||
|
||||
@@ -159,5 +159,15 @@ public enum EnumRequestPacket {
|
||||
CloneAllTagsShort,
|
||||
ClonePreSave,
|
||||
|
||||
EventScript, PlayerScript, ForgeScript, GlobalNPCScript, ItemScript, BlockScript, NPCScript, ScriptInfo, DimensionTeleport
|
||||
EventScript,
|
||||
PlayerScript,
|
||||
ForgeScript,
|
||||
GlobalNPCScript,
|
||||
ItemScript,
|
||||
ItemScriptError,
|
||||
BlockScript,
|
||||
NPCScript,
|
||||
ScriptInfo,
|
||||
|
||||
DimensionTeleport
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package kamkeel.npcs.network.packets.request.script.item;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.AbstractPacket;
|
||||
import kamkeel.npcs.network.PacketChannel;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.client.gui.script.GuiScriptItem;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public final class ItemScriptErrorPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|ItemScriptError";
|
||||
|
||||
private Action action;
|
||||
|
||||
public ItemScriptErrorPacket() {}
|
||||
|
||||
public ItemScriptErrorPacket(Action action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.ItemScriptError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission(){
|
||||
return CustomNpcsPermissions.SCRIPT_ITEM;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(action.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
|
||||
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT))
|
||||
return;
|
||||
|
||||
|
||||
Action requestedAction = Action.values()[in.readInt()];
|
||||
IItemStack iw = NpcAPI.Instance().getIItemStack(player.getHeldItem());
|
||||
if(iw instanceof ScriptCustomItem){
|
||||
if(requestedAction == Action.GET){
|
||||
TreeMap<Long, String> map = new TreeMap<>();
|
||||
int tab = 0;
|
||||
for (ScriptContainer script : ((ScriptCustomItem) iw).scripts) {
|
||||
++tab;
|
||||
|
||||
for (Map.Entry<Long, String> longStringEntry : script.console.entrySet()) {
|
||||
map.put(longStringEntry.getKey(), " tab " + tab + ":\n" + longStringEntry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setTag("ItemScriptConsole", NBTTags.NBTLongStringMap(map));
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
} else {
|
||||
for (ScriptContainer script : ((ScriptCustomItem) iw).scripts) {
|
||||
script.console.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear() {
|
||||
PacketClient.sendClient(new ItemScriptErrorPacket(Action.CLEAR));
|
||||
}
|
||||
|
||||
public static void Get() {
|
||||
PacketClient.sendClient(new ItemScriptErrorPacket(Action.GET));
|
||||
}
|
||||
|
||||
private enum Action {
|
||||
GET,
|
||||
CLEAR
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -1,10 +1,9 @@
|
||||
package kamkeel.npcs.network.packets.request.script;
|
||||
package kamkeel.npcs.network.packets.request.script.item;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.network.*;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
@@ -14,8 +13,6 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.PlayerDataScript;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener, ITextfieldListener {
|
||||
private int activeTab = 0;
|
||||
protected int activeTab = 0;
|
||||
public IScriptHandler handler;
|
||||
public Map<String, List<String>> languages = new HashMap();
|
||||
private int scriptLimit = 1;
|
||||
@@ -113,7 +113,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
this.addScroll(scroll);
|
||||
} else {
|
||||
GuiNpcTextArea var8 = new GuiNpcTextArea(2, this, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText());
|
||||
var8.enabled = false;
|
||||
var8.canEdit = false;
|
||||
var8.setFocused(true);
|
||||
this.addTextField(var8);
|
||||
int var9 = this.guiLeft + this.xSize - 150;
|
||||
this.addButton(new GuiNpcButton(100, var9, this.guiTop + 125, 60, 20, "gui.copy"));
|
||||
@@ -159,7 +160,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
|
||||
}
|
||||
|
||||
private String getConsoleText() {
|
||||
protected String getConsoleText() {
|
||||
Map<Long, String> map = this.handler.getConsoleText();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Iterator var3 = map.entrySet().iterator();
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
package noppes.npcs.client.gui.script;
|
||||
|
||||
import kamkeel.npcs.network.packets.request.script.ItemScriptPacket;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.script.item.ItemScriptErrorPacket;
|
||||
import kamkeel.npcs.network.packets.request.script.item.ItemScriptPacket;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.CustomItems;
|
||||
|
||||
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class GuiScriptItem extends GuiScriptInterface {
|
||||
private ScriptCustomItem item;
|
||||
public static Map<Long, String> consoleText = new HashMap<>();
|
||||
|
||||
public GuiScriptItem() {
|
||||
hookList.add("init");
|
||||
@@ -26,17 +37,47 @@ public class GuiScriptItem extends GuiScriptInterface {
|
||||
hookList.add("finishItem");
|
||||
|
||||
this.handler = this.item = new ScriptCustomItem(new ItemStack(CustomItems.scripted_item));
|
||||
ItemScriptErrorPacket.Get();
|
||||
ItemScriptPacket.Get();
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
this.item.setMCNbt(compound);
|
||||
this.item.loadScriptData();
|
||||
super.setGuiData(compound);
|
||||
if(compound.hasKey("ItemScriptConsole")){
|
||||
consoleText = NBTTags.GetLongStringMap(compound.getTagList("ItemScriptConsole", 10));
|
||||
initGui();
|
||||
}
|
||||
else {
|
||||
this.item.setMCNbt(compound);
|
||||
this.item.loadScriptData();
|
||||
super.setGuiData(compound);
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
ItemScriptPacket.Save(this.item.getMCNbt());
|
||||
}
|
||||
|
||||
protected String getConsoleText() {
|
||||
Map<Long, String> map = consoleText;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Iterator var3 = map.entrySet().iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
Map.Entry<Long, String> entry = (Map.Entry)var3.next();
|
||||
builder.insert(0, new Date((Long)entry.getKey()) + (String)entry.getValue() + "\n");
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public void confirmClicked(boolean flag, int i) {
|
||||
if(i == 102) {
|
||||
if (activeTab <= 0){
|
||||
consoleText = new HashMap<>();
|
||||
ItemScriptErrorPacket.Clear();
|
||||
}
|
||||
}
|
||||
super.confirmClicked(flag, i);
|
||||
}
|
||||
}
|
||||
@@ -90,20 +90,18 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int i, int j, int k){
|
||||
boolean wasFocused = isFocused();
|
||||
super.mouseClicked(i, j, k);
|
||||
|
||||
|
||||
if(hoverVerticalScrollBar(i, j)){
|
||||
clickVerticalBar = true;
|
||||
startClick = -1;
|
||||
return;
|
||||
}
|
||||
if(k != 0 || !canEdit)
|
||||
return;
|
||||
|
||||
|
||||
int x = i - posX;
|
||||
int y = (j - posY - 4) / font.height() + getStartLineY();
|
||||
cursorPosition = 0;
|
||||
@@ -126,22 +124,22 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
return;
|
||||
charCount++;
|
||||
line += c;
|
||||
|
||||
|
||||
}
|
||||
cursorPosition = charCount;
|
||||
|
||||
|
||||
|
||||
|
||||
lineCount++;
|
||||
charCount++;
|
||||
if(y < lineCount){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(y >= lineCount)
|
||||
cursorPosition = getText().length();
|
||||
}
|
||||
|
||||
|
||||
private List<String> getLines(){
|
||||
List<String> list = new ArrayList<String>();
|
||||
String line = "";
|
||||
@@ -156,7 +154,7 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
list.add(line);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private int getStartLineY(){
|
||||
if(!isScrolling())
|
||||
scrolledY = 0;
|
||||
@@ -171,9 +169,9 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
//int color = isEnabled?0xe0e0e0:0x707070;
|
||||
int color = 0xe0e0e0;
|
||||
boolean flag = isFocused() && (cursorCounter / 6) % 2 == 0;
|
||||
|
||||
|
||||
int startLine = getStartLineY();
|
||||
|
||||
|
||||
int maxLine = height / font.height() + startLine;
|
||||
|
||||
int charCount = 0;
|
||||
@@ -193,7 +191,7 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
int xx = posX + font.width(line) + 4;
|
||||
int yy = posY + ((lineCount - startLine) * font.height()) + 4;
|
||||
if(getText().length() == cursorPosition){
|
||||
font.drawString("_", xx, yy, color);
|
||||
font.drawString("_", xx, yy, color);
|
||||
}
|
||||
else{
|
||||
drawCursorVertical(xx, yy, xx + 1, yy + font.height());
|
||||
@@ -208,7 +206,7 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
int xx = posX + font.width(line) + 4;
|
||||
int yy = posY + ((lineCount - startLine) * font.height()) + 4;
|
||||
if(getText().length() == cursorPosition){
|
||||
font.drawString("_", xx, yy, color);
|
||||
font.drawString("_", xx, yy, color);
|
||||
}
|
||||
else{
|
||||
drawCursorVertical(xx, yy, xx + 1, yy + font.height());
|
||||
@@ -218,8 +216,8 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
lineCount++;
|
||||
charCount++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int k2 = Mouse.getDWheel();
|
||||
if(k2 != 0 && isFocused()){
|
||||
addScrollY(k2 < 0?-10:10);
|
||||
@@ -229,10 +227,10 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
if(clickVerticalBar){
|
||||
if(startClick >= 0)
|
||||
addScrollY(startClick - (mouseY - posY));
|
||||
|
||||
|
||||
if(hoverVerticalScrollBar(mouseX, mouseY))
|
||||
startClick = mouseY - posY;
|
||||
|
||||
|
||||
startClick = mouseY - posY;
|
||||
}
|
||||
}
|
||||
@@ -242,20 +240,20 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
listHeight = lineCount * font.height();
|
||||
drawVerticalScrollBar();
|
||||
}
|
||||
|
||||
|
||||
public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color){
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
font.drawString(text, x, y, color);
|
||||
//super.drawString(fontRendererIn, text, x, y, color);
|
||||
}
|
||||
|
||||
|
||||
private boolean isScrolling() {
|
||||
return listHeight > height - 4;
|
||||
}
|
||||
|
||||
private void addScrollY(int scrolled){
|
||||
scrolledY -= 1f * scrolled / height;
|
||||
|
||||
|
||||
if(scrolledY < 0)
|
||||
scrolledY = 0;
|
||||
|
||||
@@ -263,17 +261,17 @@ public class GuiNpcTextArea extends GuiNpcTextField {
|
||||
if(scrolledY > max )
|
||||
scrolledY = max;
|
||||
}
|
||||
|
||||
|
||||
private boolean hoverVerticalScrollBar(int x, int y){
|
||||
if(listHeight <= height - 4)
|
||||
return false;
|
||||
|
||||
|
||||
if(posY < y && posY + height > y && x < posX + width && x > posX + (width - 8))
|
||||
return true;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private void drawCursorVertical(int p_146188_1_, int p_146188_2_, int p_146188_3_, int p_146188_4_){
|
||||
int i1;
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ public class ScriptContainer {
|
||||
var14.printStackTrace(pw);
|
||||
} finally {
|
||||
String errorString = sw.getBuffer().toString().trim();
|
||||
this.appandConsole(errorString);
|
||||
this.appendConsole(errorString);
|
||||
pw.close();
|
||||
}
|
||||
}
|
||||
@@ -201,14 +201,14 @@ public class ScriptContainer {
|
||||
e.printStackTrace(pw);
|
||||
}
|
||||
finally {
|
||||
appandConsole(sw.getBuffer().toString().trim());
|
||||
appendConsole(sw.getBuffer().toString().trim());
|
||||
pw.close();
|
||||
Current = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void appandConsole(String message) {
|
||||
public void appendConsole(String message) {
|
||||
if (message != null && !message.isEmpty()) {
|
||||
long time = System.currentTimeMillis();
|
||||
if (this.console.containsKey(time)) {
|
||||
|
||||
Reference in new issue
Block a user