mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 19:15:11 +00:00
Linked Item GUI + Packets
This commit is contained in:
1 parent
a2d4c4fd5a
commit
eb8b5387ea
19 files changed
+590
-75
No files matched your search
@@ -148,9 +148,12 @@ public class PacketHandler {
|
||||
// Linked Packets
|
||||
REQUEST_PACKET.registerPacket(new LinkedGetAllPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedGetPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedNPCRemovePacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedSetPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedAddPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedNPCAddPacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedItemSavePacket());
|
||||
REQUEST_PACKET.registerPacket(new LinkedItemRemovePacket());
|
||||
|
||||
|
||||
// Bank Packets
|
||||
REQUEST_PACKET.registerPacket(new BanksGetPacket());
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
import noppes.npcs.controllers.data.EffectScript;
|
||||
|
||||
public enum EnumRequestPacket {
|
||||
NPCDelete,
|
||||
RemoteMainMenu,
|
||||
@@ -121,8 +119,8 @@ public enum EnumRequestPacket {
|
||||
PartySetLeader,
|
||||
PartySetQuest,
|
||||
|
||||
LinkedRemove,
|
||||
LinkedAdd,
|
||||
LinkedNPCRemove,
|
||||
LinkedNPCAdd,
|
||||
LinkedGetAll,
|
||||
LinkedSet,
|
||||
LinkedGet,
|
||||
@@ -182,5 +180,5 @@ public enum EnumRequestPacket {
|
||||
EffectRemove,
|
||||
EffectSave,
|
||||
|
||||
ColorSet, ColorBrush
|
||||
ColorSet, LinkedItemSave, LinkedItemRemove, ColorBrush
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class EffectRemovePacket extends AbstractPacket {
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
effectID = in.readInt();
|
||||
int effectID = in.readInt();
|
||||
CustomEffectController.getInstance().delete(effectID);
|
||||
NoppesUtilServer.sendCustomEffectDataAll((EntityPlayerMP) player);
|
||||
NBTTagCompound compound = (new CustomEffect()).writeToNBT(false);
|
||||
|
||||
@@ -8,7 +8,6 @@ import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import kamkeel.npcs.network.packets.data.ScrollSelectedPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
|
||||
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
@@ -16,9 +15,7 @@ import noppes.npcs.controllers.LinkedNpcController;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public final class LinkedGetAllPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedGetAll";
|
||||
@@ -65,7 +62,7 @@ public final class LinkedGetAllPacket extends AbstractPacket {
|
||||
}
|
||||
} else if (action == Action.ITEM){
|
||||
HashMap<String, Integer> list = new HashMap<>();
|
||||
for (LinkedItem linkedItem : LinkedItemController.Instance().linkedItems.values()) {
|
||||
for (LinkedItem linkedItem : LinkedItemController.getInstance().linkedItems.values()) {
|
||||
list.put(linkedItem.name, linkedItem.id);
|
||||
}
|
||||
ScrollDataPacket.sendScrollData((EntityPlayerMP) player, list);
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class LinkedGetPacket extends AbstractPacket {
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
} else if (action == Action.ITEM) {
|
||||
int id = in.readInt();
|
||||
LinkedItem data = LinkedItemController.Instance().get(id);
|
||||
LinkedItem data = LinkedItemController.getInstance().get(id);
|
||||
NBTTagCompound compound = data.writeToNBT();
|
||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, compound);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package kamkeel.npcs.network.packets.request.linked;
|
||||
|
||||
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.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import noppes.npcs.CustomNpcsPermissions;
|
||||
import noppes.npcs.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LinkedItemRemovePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedItemRemove";
|
||||
|
||||
private int id;
|
||||
|
||||
public LinkedItemRemovePacket(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LinkedItemRemovePacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.LinkedItemRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_LINKED;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
out.writeInt(this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
|
||||
int linkedID = in.readInt();
|
||||
LinkedItemController.getInstance().delete(linkedID);
|
||||
NoppesUtilServer.sendLinkedItemDataAll((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package kamkeel.npcs.network.packets.request.linked;
|
||||
|
||||
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.PacketHandler;
|
||||
import kamkeel.npcs.network.PacketUtil;
|
||||
import kamkeel.npcs.network.enums.EnumItemPacketType;
|
||||
import kamkeel.npcs.network.enums.EnumRequestPacket;
|
||||
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.NoppesUtilServer;
|
||||
import noppes.npcs.controllers.LinkedItemController;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class LinkedItemSavePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedItemSave";
|
||||
|
||||
private String prevName;
|
||||
private NBTTagCompound compound;
|
||||
|
||||
public LinkedItemSavePacket(){}
|
||||
|
||||
public LinkedItemSavePacket(NBTTagCompound compound, String prev){
|
||||
this.compound = compound;
|
||||
this.prevName = prev;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.LinkedItemSave;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketChannel getChannel() {
|
||||
return PacketHandler.REQUEST_PACKET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomNpcsPermissions.Permission getPermission() {
|
||||
return CustomNpcsPermissions.GLOBAL_LINKED;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void sendData(ByteBuf out) throws IOException {
|
||||
ByteBufUtils.writeString(out, this.prevName);
|
||||
ByteBufUtils.writeNBT(out, this.compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveData(ByteBuf in, EntityPlayer player) throws IOException {
|
||||
if (!(player instanceof EntityPlayerMP))
|
||||
return;
|
||||
if (!PacketUtil.verifyItemPacket(EnumItemPacketType.WAND, player))
|
||||
return;
|
||||
|
||||
String prevName = ByteBufUtils.readString(in);
|
||||
LinkedItem linkedItem = new LinkedItem();
|
||||
linkedItem.readFromNBT(ByteBufUtils.readNBT(in), false);
|
||||
linkedItem.version++;
|
||||
|
||||
LinkedItemController.getInstance().saveLinkedItem(linkedItem);
|
||||
|
||||
if(!prevName.isEmpty() && !prevName.equals(linkedItem.name)){
|
||||
LinkedItemController.getInstance().deleteLinkedItemFile(prevName);
|
||||
}
|
||||
|
||||
NoppesUtilServer.sendLinkedItemDataAll((EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
+5
-6
@@ -21,21 +21,20 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class LinkedAddPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedAdd";
|
||||
public final class LinkedNPCAddPacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedNPCAdd";
|
||||
|
||||
private String data;
|
||||
|
||||
public LinkedAddPacket(String data) {
|
||||
public LinkedNPCAddPacket(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public LinkedAddPacket() {
|
||||
}
|
||||
public LinkedNPCAddPacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.LinkedAdd;
|
||||
return EnumRequestPacket.LinkedNPCAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
+5
-5
@@ -20,20 +20,20 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class LinkedRemovePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedRemove";
|
||||
public final class LinkedNPCRemovePacket extends AbstractPacket {
|
||||
public static String packetName = "Request|LinkedNPCRemove";
|
||||
|
||||
private String data;
|
||||
|
||||
public LinkedRemovePacket(String data) {
|
||||
public LinkedNPCRemovePacket(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public LinkedRemovePacket() {}
|
||||
public LinkedNPCRemovePacket() {}
|
||||
|
||||
@Override
|
||||
public Enum getType() {
|
||||
return EnumRequestPacket.LinkedRemove;
|
||||
return EnumRequestPacket.LinkedNPCRemove;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -5,7 +5,6 @@ import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.*;
|
||||
import cpw.mods.fml.common.network.FMLEventChannel;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -210,7 +209,7 @@ public class CustomNpcs {
|
||||
new LinkedNpcController();
|
||||
new AnimationController();
|
||||
|
||||
LinkedItemController.Instance().load();
|
||||
LinkedItemController.getInstance().load();
|
||||
|
||||
// Custom Effects
|
||||
CustomEffectController.getInstance().load();
|
||||
|
||||
@@ -53,6 +53,8 @@ public class CustomNpcsPermissions{
|
||||
public static final Permission GLOBAL_NATURALSPAWN = new Permission("customnpcs.global.naturalspawn");
|
||||
public static final Permission GLOBAL_TAG = new Permission("customnpcs.global.tag");
|
||||
public static final Permission GLOBAL_ANIMATION = new Permission("customnpcs.global.animation");
|
||||
public static final Permission GLOBAL_MAGIC = new Permission("customnpcs.global.magic");
|
||||
public static final Permission GLOBAL_EFFECT = new Permission("customnpcs.global.effect");
|
||||
|
||||
public static final Permission SPAWNER_MOB = new Permission("customnpcs.spawner.mob");
|
||||
public static final Permission SPAWNER_CREATE = new Permission("customnpcs.spawner.create");
|
||||
|
||||
@@ -664,6 +664,14 @@ public class NoppesUtilServer {
|
||||
ScrollDataPacket.sendScrollData(player, map);
|
||||
}
|
||||
|
||||
public static void sendLinkedItemDataAll(EntityPlayerMP player) {
|
||||
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||
for (LinkedItem linkedItem : LinkedItemController.getInstance().linkedItems.values()) {
|
||||
map.put(linkedItem.name, linkedItem.id);
|
||||
}
|
||||
ScrollDataPacket.sendScrollData(player, map);
|
||||
}
|
||||
|
||||
public static void sendTransportCategoryData(EntityPlayerMP player) {
|
||||
HashMap<String,Integer> map = new HashMap<String,Integer>();
|
||||
for(TransportCategory category : TransportController.getInstance().categories.values()){
|
||||
|
||||
@@ -268,8 +268,7 @@ public class ClientProxy extends CommonProxy {
|
||||
return new GuiNpcPather(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ManageFactions)
|
||||
return new GuiNPCManageMagic(npc);
|
||||
// return new GuiNPCManageFactions(npc);
|
||||
return new GuiNPCManageFactions(npc);
|
||||
|
||||
else if (gui == EnumGuiType.ManageCustomForms)
|
||||
return DBCClient.Instance.manageCustomForms(npc);
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
package noppes.npcs.client.gui.global;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedAddPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedGetAllPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedGetPacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.effects.EffectRemovePacket;
|
||||
import kamkeel.npcs.network.packets.request.effects.EffectSavePacket;
|
||||
import kamkeel.npcs.network.packets.request.linked.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.RenderManager;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.SubGuiEditText;
|
||||
import noppes.npcs.client.gui.item.SubGuiLinkedItem;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
|
||||
import noppes.npcs.controllers.data.CustomEffect;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
import noppes.npcs.entity.EntityCustomNpc;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -30,7 +34,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData, ISubGuiListener, ICustomScrollListener, IGuiData {
|
||||
public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData, ISubGuiListener, ICustomScrollListener, IGuiData, GuiYesNoCallback {
|
||||
private int tab = 0;
|
||||
private boolean loadedNPC = false;
|
||||
private GuiCustomScroll scroll;
|
||||
@@ -38,6 +42,9 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
public HashMap<String, Integer> data = new HashMap<>();
|
||||
private String selected = null;
|
||||
|
||||
private LinkedItem linkedItem = null;
|
||||
public String originalName = "";
|
||||
|
||||
private String search = "";
|
||||
|
||||
private float zoomed = 70, rotation;
|
||||
@@ -192,24 +199,59 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
if(tab == 0){
|
||||
setSubGui(new SubGuiEditText("New"));
|
||||
} else {
|
||||
|
||||
String name = "New";
|
||||
while (data.containsKey(name))
|
||||
name += "_";
|
||||
LinkedItem linkedItem = new LinkedItem(name);
|
||||
PacketClient.sendClient(new LinkedItemSavePacket(linkedItem.writeToNBT(), ""));
|
||||
}
|
||||
}
|
||||
if(button.id == 2){
|
||||
if(tab == 0){
|
||||
if(scroll.hasSelected())
|
||||
PacketClient.sendClient(new LinkedRemovePacket(scroll.getSelected()));
|
||||
if (data.containsKey(scroll.getSelected())) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, scroll.getSelected(), StatCollector.translateToLocal("gui.delete"), 0);
|
||||
displayGuiScreen(guiyesno);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (data.containsKey(scroll.getSelected())) {
|
||||
GuiYesNo guiyesno = new GuiYesNo(this, scroll.getSelected(), StatCollector.translateToLocal("gui.delete"), 1);
|
||||
displayGuiScreen(guiyesno);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(button.id == 10){
|
||||
tab = 0;
|
||||
initGui();
|
||||
LinkedGetAllPacket.GetNPCs();
|
||||
}
|
||||
if(button.id == 11){
|
||||
tab = 1;
|
||||
initGui();
|
||||
LinkedGetAllPacket.GetItems();
|
||||
}
|
||||
|
||||
if(linkedItem == null)
|
||||
return;
|
||||
|
||||
if(button.id == 3){
|
||||
setSubGui(new SubGuiLinkedItem(this, this.linkedItem));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean result, int id) {
|
||||
NoppesUtil.openGUI(player, this);
|
||||
if (!result)
|
||||
return;
|
||||
if (id == 0) {
|
||||
if (data.containsKey(scroll.getSelected())) {
|
||||
PacketClient.sendClient(new LinkedNPCRemovePacket(scroll.getSelected()));
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
if(id == 1){
|
||||
if (data.containsKey(scroll.getSelected())) {
|
||||
PacketClient.sendClient(new LinkedItemRemovePacket(data.get(scroll.getSelected())));
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,22 +313,33 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if(!((SubGuiEditText)subgui).cancelled){
|
||||
PacketClient.sendClient(new LinkedAddPacket(((SubGuiEditText)subgui).text));
|
||||
}
|
||||
if(subgui instanceof SubGuiEditText){
|
||||
if(!((SubGuiEditText)subgui).cancelled){
|
||||
PacketClient.sendClient(new LinkedNPCAddPacket(((SubGuiEditText)subgui).text));
|
||||
}
|
||||
}
|
||||
else if (subgui instanceof SubGuiLinkedItem){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data) {
|
||||
this.data = new HashMap<>(data);
|
||||
this.scroll.setList(getSearchList());
|
||||
initGui();
|
||||
}
|
||||
@Override
|
||||
public void setData(Vector<String> list, HashMap<String, Integer> data) {
|
||||
String name = scroll.getSelected();
|
||||
this.data = data;
|
||||
scroll.setList(getSearchList());
|
||||
|
||||
if (name != null)
|
||||
scroll.setSelected(name);
|
||||
|
||||
initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(String selected) {
|
||||
this.selected = selected;
|
||||
scroll.setSelected(selected);
|
||||
originalName = scroll.getSelected();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -301,6 +354,7 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
if (guiCustomScroll.id == 0) {
|
||||
loadedNPC = false;
|
||||
selected = scroll.getSelected();
|
||||
originalName = scroll.getSelected();
|
||||
if (selected != null && !selected.isEmpty()){
|
||||
if(tab == 0)
|
||||
LinkedGetPacket.GetNPC(selected);
|
||||
@@ -315,6 +369,7 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
loadedNPC = false;
|
||||
this.linkedItem = null;
|
||||
if(compound.hasKey("NPCData")){
|
||||
// Linked NPC
|
||||
this.npc.display.readToNBT(compound.getCompoundTag("NPCData"));
|
||||
@@ -322,8 +377,9 @@ public class GuiNPCManageLinked extends GuiNPCInterface2 implements IScrollData,
|
||||
this.npc.ais.readToNBT(compound.getCompoundTag("NPCData"));
|
||||
loadedNPC = true;
|
||||
} else {
|
||||
// Linked Item
|
||||
|
||||
this.linkedItem = new LinkedItem();
|
||||
this.linkedItem.readFromNBT(compound, false);
|
||||
}
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
package noppes.npcs.client.gui.item;
|
||||
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.request.linked.LinkedItemSavePacket;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import noppes.npcs.client.gui.global.GuiNPCManageLinked;
|
||||
import noppes.npcs.client.gui.util.*;
|
||||
import noppes.npcs.controllers.data.LinkedItem;
|
||||
|
||||
public class SubGuiLinkedItem extends SubGuiInterface implements ITextfieldListener {
|
||||
private final GuiNPCManageLinked parent;
|
||||
public LinkedItem linkedItem;
|
||||
private final String originalName;
|
||||
|
||||
public SubGuiLinkedItem(GuiNPCManageLinked parent, LinkedItem linkedItem) {
|
||||
this.linkedItem = linkedItem;
|
||||
this.parent = parent;
|
||||
this.originalName = linkedItem.name;
|
||||
this.closeOnEsc = true;
|
||||
|
||||
setBackground("menubg.png");
|
||||
xSize = 360;
|
||||
ySize = 216;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
GuiMenuTopButton close = new GuiMenuTopButton(-5, guiLeft + xSize - 22, guiTop - 10, "X");
|
||||
|
||||
GuiMenuTopButton general = new GuiMenuTopButton(-1, guiLeft + 4, guiTop - 10, "menu.general");
|
||||
GuiMenuTopButton scripts = new GuiMenuTopButton(-2, general.xPosition + general.getWidth(), guiTop - 10, "script.scripts");
|
||||
|
||||
close.active = false;
|
||||
general.active = true;
|
||||
scripts.active = false;
|
||||
|
||||
addTopButton(close);
|
||||
addTopButton(general);
|
||||
addTopButton(scripts);
|
||||
|
||||
guiTop += 7;
|
||||
int y = guiTop + 7;
|
||||
int x = guiLeft + 4;
|
||||
y += 5;
|
||||
|
||||
GuiScrollWindow scrollWindow = new GuiScrollWindow(this, x + 5, y, xSize - 20, ySize - 10 - (y - guiTop), 0);
|
||||
addScrollableGui(0, scrollWindow);
|
||||
|
||||
y = 5;
|
||||
x = 5;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(1, "display.name", x, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(1, this, x + 80, y, scrollWindow.clipWidth - 20 - 80, 20, linkedItem.name));
|
||||
scrollWindow.getTextField(1).setMaxStringLength(100);
|
||||
|
||||
y += 25;
|
||||
|
||||
scrollWindow.addLabel(new GuiNpcLabel(2, "display.texture", x, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(2, this, x + 80, y, scrollWindow.clipWidth - 20 - 80, 20, linkedItem.display.texture));
|
||||
scrollWindow.getTextField(2).setMaxStringLength(300);
|
||||
|
||||
y += 30;
|
||||
|
||||
String color = Integer.toHexString(linkedItem.display.itemColor);
|
||||
while(color.length() < 6)
|
||||
color = "0" + color;
|
||||
|
||||
scrollWindow.addLabel(new GuiNpcLabel(9, "display.color", x, y + 5, 0xFFFFFF));
|
||||
x += 35;
|
||||
scrollWindow.addButton(new GuiNpcButton(9, x + 80, y, 80, 20, color + ""));
|
||||
scrollWindow.getButton(9).packedFGColour = linkedItem.display.itemColor;
|
||||
|
||||
x = 5;
|
||||
|
||||
y += 30;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(10, "display.isTool", x, y + 5, 0xFFFFFF));
|
||||
x += 35;
|
||||
scrollWindow.addButton(new GuiNpcButtonYesNo(10, x + 80, y, linkedItem.isTool));
|
||||
|
||||
x = 5;
|
||||
y += 25;
|
||||
|
||||
scrollWindow.addLabel(new GuiNpcLabel(11, "display.isNormalItem", x, y + 5, 0xFFFFFF));
|
||||
x += 35;
|
||||
scrollWindow.addButton(new GuiNpcButtonYesNo(11, x + 80, y, linkedItem.isNormalItem));
|
||||
|
||||
x = 5;
|
||||
|
||||
y += 30;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(3, "display.scale", x, y + 5, 0xFFFFFF));
|
||||
|
||||
x += 30;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(31, "X", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(31, this, x + 90, y, 40, 20, linkedItem.display.scaleX + ""));
|
||||
scrollWindow.getTextField(31).setFloatsOnly();
|
||||
scrollWindow.getTextField(31).setMinMaxDefaultFloat(0, 30, 1);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(32, "Y", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(32, this, x + 90, y, 40, 20, linkedItem.display.scaleY + ""));
|
||||
scrollWindow.getTextField(32).setFloatsOnly();
|
||||
scrollWindow.getTextField(32).setMinMaxDefaultFloat(0, 30, 1);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(33, "Z", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(33, this, x + 90, y, 40, 20, linkedItem.display.scaleZ + ""));
|
||||
scrollWindow.getTextField(33).setFloatsOnly();
|
||||
scrollWindow.getTextField(33).setMinMaxDefaultFloat(0, 30, 1);
|
||||
|
||||
x = 5;
|
||||
y += 25;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(4, "display.rotation", x, y + 5, 0xFFFFFF));
|
||||
|
||||
x += 30;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(41, "X", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(41, this, x + 90, y, 40, 20, linkedItem.display.rotationX + ""));
|
||||
scrollWindow.getTextField(41).setFloatsOnly();
|
||||
scrollWindow.getTextField(41).setMinMaxDefaultFloat(-360, 360, 0);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(42, "Y", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(42, this, x + 90, y, 40, 20, linkedItem.display.rotationY + ""));
|
||||
scrollWindow.getTextField(42).setFloatsOnly();
|
||||
scrollWindow.getTextField(42).setMinMaxDefaultFloat(-360, 360, 0);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(43, "Z", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(43, this, x + 90, y, 40, 20, linkedItem.display.rotationZ + ""));
|
||||
scrollWindow.getTextField(43).setFloatsOnly();
|
||||
scrollWindow.getTextField(43).setMinMaxDefaultFloat(-360, 360, 0);
|
||||
|
||||
x = 5;
|
||||
y += 25;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(5, "display.rotationRate", x, y + 5, 0xFFFFFF));
|
||||
|
||||
x += 30;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(51, "X", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(51, this, x + 90, y, 40, 20, linkedItem.display.rotationXRate + ""));
|
||||
scrollWindow.getTextField(51).setFloatsOnly();
|
||||
scrollWindow.getTextField(51).setMinMaxDefaultFloat(0, 100, 0);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(52, "Y", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(52, this, x + 90, y, 40, 20, linkedItem.display.rotationYRate + ""));
|
||||
scrollWindow.getTextField(52).setFloatsOnly();
|
||||
scrollWindow.getTextField(52).setMinMaxDefaultFloat(0, 100, 0);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(53, "Z", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(53, this, x + 90, y, 40, 20, linkedItem.display.rotationZRate + ""));
|
||||
scrollWindow.getTextField(53).setFloatsOnly();
|
||||
scrollWindow.getTextField(53).setMinMaxDefaultFloat(0, 100, 0);
|
||||
|
||||
x = 5;
|
||||
y += 25;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(6, "display.translate", x, y + 5, 0xFFFFFF));
|
||||
|
||||
x += 30;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(61, "X", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(61, this, x + 90, y, 40, 20, linkedItem.display.translateX + ""));
|
||||
scrollWindow.getTextField(61).setFloatsOnly();
|
||||
scrollWindow.getTextField(61).setMinMaxDefaultFloat(-10, 10, 0);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(62, "Y", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(62, this, x + 90, y, 40, 20, linkedItem.display.translateY + ""));
|
||||
scrollWindow.getTextField(62).setFloatsOnly();
|
||||
scrollWindow.getTextField(62).setMinMaxDefaultFloat(-10, 10, 0);
|
||||
|
||||
x += 70;
|
||||
scrollWindow.addLabel(new GuiNpcLabel(63, "Z", x + 80, y + 5, 0xFFFFFF));
|
||||
scrollWindow.addTextField(new GuiNpcTextField(63, this, x + 90, y, 40, 20, linkedItem.display.translateZ + ""));
|
||||
scrollWindow.getTextField(63).setFloatsOnly();
|
||||
scrollWindow.getTextField(63).setMinMaxDefaultFloat(-10, 10, 0);
|
||||
|
||||
y += 30;
|
||||
|
||||
scrollWindow.scrollY = 0;
|
||||
scrollWindow.maxScrollY = y - scrollWindow.clipHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
if (id == -5) {
|
||||
close();
|
||||
return;
|
||||
} else if (id == 9) {
|
||||
// OPEN COLOR PICKER
|
||||
} else if (id == 10) {
|
||||
// IsTool
|
||||
if (guibutton instanceof GuiNpcButtonYesNo) {
|
||||
linkedItem.isTool = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
}
|
||||
} else if (id == 11) {
|
||||
// isNormalItem
|
||||
if (guibutton instanceof GuiNpcButtonYesNo) {
|
||||
linkedItem.isNormalItem = ((GuiNpcButtonYesNo) guibutton).getBoolean();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
int id = textField.id;
|
||||
if (id == 1) {
|
||||
// Name
|
||||
linkedItem.name = textField.getText();
|
||||
} else if (id == 2) {
|
||||
// Texture
|
||||
linkedItem.display.texture = textField.getText();
|
||||
} else if (id == 31) {
|
||||
// Scale X
|
||||
linkedItem.display.scaleX = textField.getFloat();
|
||||
} else if (id == 32) {
|
||||
// Scale Y
|
||||
linkedItem.display.scaleY = textField.getFloat();
|
||||
} else if (id == 33) {
|
||||
// Scale Z
|
||||
linkedItem.display.scaleZ = textField.getFloat();
|
||||
} else if (id == 41) {
|
||||
// Rotation X
|
||||
linkedItem.display.rotationX = textField.getFloat();
|
||||
} else if (id == 42) {
|
||||
// Rotation Y
|
||||
linkedItem.display.rotationY = textField.getFloat();
|
||||
} else if (id == 43) {
|
||||
// Rotation Z
|
||||
linkedItem.display.rotationZ = textField.getFloat();
|
||||
} else if (id == 51) {
|
||||
// Rotation X Rate
|
||||
linkedItem.display.rotationXRate = textField.getFloat();
|
||||
} else if (id == 52) {
|
||||
// Rotation Y Rate
|
||||
linkedItem.display.rotationYRate = textField.getFloat();
|
||||
} else if (id == 53) {
|
||||
// Rotation Z Rate
|
||||
linkedItem.display.rotationZRate = textField.getFloat();
|
||||
} else if (id == 61) {
|
||||
// Translate X
|
||||
linkedItem.display.translateX = textField.getFloat();
|
||||
} else if (id == 62) {
|
||||
// Translate Y
|
||||
linkedItem.display.translateY = textField.getFloat();
|
||||
} else if (id == 63) {
|
||||
// Translate Z
|
||||
linkedItem.display.translateZ = textField.getFloat();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
PacketClient.sendClient(new LinkedItemSavePacket(linkedItem.writeToNBT(), originalName));
|
||||
}
|
||||
|
||||
public enum LinkedItemType {
|
||||
TOOL,
|
||||
NORMAL
|
||||
}
|
||||
|
||||
public enum LinkedItemUseAction {
|
||||
NONE,
|
||||
BLOCK,
|
||||
BOW,
|
||||
EAT,
|
||||
DRINK
|
||||
}
|
||||
|
||||
public enum LinkedItemArmorType {
|
||||
NONE(-2, "none"),
|
||||
ALL(-1, "all"),
|
||||
HELM(0, "helm"),
|
||||
CHESTPLATE(1, "chestplate"),
|
||||
LEGGINGS(2, "leggings"),
|
||||
BOOTS(3, "boots");
|
||||
|
||||
public int value;
|
||||
public String name;
|
||||
|
||||
LinkedItemArmorType(int type, String display){
|
||||
this.value = type;
|
||||
this.name = display;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -26,7 +24,7 @@ public class LinkedItemController {
|
||||
|
||||
private LinkedItemController() {}
|
||||
|
||||
public static LinkedItemController Instance() {
|
||||
public static LinkedItemController getInstance() {
|
||||
if (Instance == null) {
|
||||
Instance = new LinkedItemController();
|
||||
}
|
||||
@@ -49,17 +47,15 @@ public class LinkedItemController {
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
private void addScript(int id) {
|
||||
this.linkedItemsScripts.put(id, new LinkedItemScript());
|
||||
}
|
||||
|
||||
public void remove(int id) {
|
||||
this.linkedItems.remove(id);
|
||||
public LinkedItem remove(int id) {
|
||||
this.removeScript(id);
|
||||
return this.linkedItems.remove(id);
|
||||
}
|
||||
|
||||
@SideOnly(Side.SERVER)
|
||||
private void removeScript(int id) {
|
||||
this.linkedItemsScripts.remove(id);
|
||||
}
|
||||
@@ -163,21 +159,17 @@ public class LinkedItemController {
|
||||
}
|
||||
|
||||
public ILinkedItem saveLinkedItem(ILinkedItem linkedItem){
|
||||
if(linkedItem.getId() < 0){
|
||||
if (linkedItem.getId() < 0) {
|
||||
linkedItem.setId(getUnusedId());
|
||||
while(hasName(linkedItem.getName()))
|
||||
while (hasName(linkedItem.getName()))
|
||||
linkedItem.setName(linkedItem.getName() + "_");
|
||||
}
|
||||
else{
|
||||
LinkedItem existing = linkedItems.get(linkedItem.getId());
|
||||
if(existing != null && !existing.name.equals(linkedItem.getName()))
|
||||
while(hasName(linkedItem.getName()))
|
||||
linkedItem.setName(linkedItem.getName() + "_");
|
||||
}
|
||||
|
||||
while (hasOther(linkedItem.getName(), linkedItem.getId()))
|
||||
linkedItem.setName(linkedItem.getName() + "_");
|
||||
|
||||
linkedItems.remove(linkedItem.getId());
|
||||
linkedItems.put(linkedItem.getId(), (LinkedItem) linkedItem);
|
||||
|
||||
saveLinkedItemsMap();
|
||||
|
||||
// Save Linked Item File
|
||||
@@ -199,6 +191,42 @@ public class LinkedItemController {
|
||||
return linkedItems.get(linkedItem.getId());
|
||||
}
|
||||
|
||||
private boolean hasOther(String name, int id) {
|
||||
for (LinkedItem linkedItem : linkedItems.values()) {
|
||||
if (linkedItem.getId() != id && linkedItem.getName().equalsIgnoreCase(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
LinkedItem linkedItem = get(id);
|
||||
if (linkedItem != null) {
|
||||
LinkedItem foundItem = remove(id);
|
||||
if (foundItem != null && foundItem.name != null) {
|
||||
File dir = this.getDir();
|
||||
for (File file : dir.listFiles()) {
|
||||
if (!file.isFile() || !file.getName().endsWith(".json"))
|
||||
continue;
|
||||
if (file.getName().equalsIgnoreCase(foundItem.name + ".json")) {
|
||||
file.delete();
|
||||
break;
|
||||
}
|
||||
}
|
||||
saveLinkedItemsMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteLinkedItemFile(String prevName) {
|
||||
File dir = this.getDir();
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
File file2 = new File(dir, prevName + ".json");
|
||||
if (file2.exists())
|
||||
file2.delete();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////
|
||||
|
||||
@@ -58,7 +58,6 @@ public class ItemDisplayData {
|
||||
if (compound.hasKey("ItemTexture")) {
|
||||
this.texture = compound.getString("ItemTexture");
|
||||
}
|
||||
|
||||
if (compound.hasKey("RotationX")) {
|
||||
this.rotationX = compound.getFloat("RotationX");
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ public class LinkedItem implements ILinkedItem {
|
||||
public static final String LINKED_DATA_NBT_TAG = "LinkedData";
|
||||
|
||||
public int id = -1;
|
||||
public int version = 1;
|
||||
public int version = 0;
|
||||
public String name;
|
||||
public final ItemDisplayData display = new ItemDisplayData();
|
||||
|
||||
@@ -22,7 +22,7 @@ public class LinkedItem implements ILinkedItem {
|
||||
public boolean isNormalItem = false;
|
||||
public boolean isTool = false;
|
||||
public int digSpeed = 1;
|
||||
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 4: Fits in Head -> Boots slot respectively
|
||||
public int armorType = -2; //-2: Fits in no armor slot, -1: Fits in all slots, 0 - 3: Fits in Head -> Boots slot respectively
|
||||
public int enchantability;
|
||||
|
||||
public LinkedItem() {
|
||||
@@ -34,7 +34,7 @@ public class LinkedItem implements ILinkedItem {
|
||||
}
|
||||
|
||||
public INpcScriptHandler getScriptHandler() {
|
||||
return LinkedItemController.Instance().getScriptHandler(this.getId());
|
||||
return LinkedItemController.getInstance().getScriptHandler(this.getId());
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
@@ -61,7 +61,7 @@ public class LinkedItem implements ILinkedItem {
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound, boolean checkID) {
|
||||
if(checkID)
|
||||
this.id = compound.hasKey("Id") ? compound.getInteger("Id") : LinkedItemController.Instance().getUnusedId();
|
||||
this.id = compound.hasKey("Id") ? compound.getInteger("Id") : LinkedItemController.getInstance().getUnusedId();
|
||||
else
|
||||
this.id = compound.getInteger("Id");
|
||||
|
||||
@@ -84,7 +84,7 @@ public class LinkedItem implements ILinkedItem {
|
||||
}
|
||||
|
||||
public ILinkedItem save() {
|
||||
return LinkedItemController.Instance().saveLinkedItem(this);
|
||||
return LinkedItemController.getInstance().saveLinkedItem(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ScriptLinkedItem extends ScriptCustomizableItem implements IItemLin
|
||||
}
|
||||
|
||||
public LinkedItem getLinkedItem() {
|
||||
return LinkedItemController.Instance().get(this.linkedItem.getId());
|
||||
return LinkedItemController.getInstance().get(this.linkedItem.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user