diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index ad4842791..05d439dd8 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -60,11 +60,8 @@ public class CustomNpcs { @ConfigProp(info = "Set to true if you want the dialog command option to be able to use op commands like tp etc") public static boolean NpcUseOpCommands = false; - @ConfigProp(info = "The amount of time that passes before a player's quests are checked for completion in seconds.") - public static int PlayerQuestCheck = 300; - - @ConfigProp(info = "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8.") - public static int TrackingInfoAlignment = 5; + @ConfigProp(info = "Client sided! Determines where tracking quest info shows up on the screen based on a number from 0 to 8. Default: 3") + public static int TrackingInfoAlignment = 3; @ConfigProp(info = "Client sided! Offsets the tracking info GUI by this amount in the X direction.") public static int TrackingInfoX = 0; @@ -171,9 +168,6 @@ public class CustomNpcs { if(NpcSizeLimit < 1) NpcSizeLimit = 1; - if(PlayerQuestCheck < 1) - PlayerQuestCheck = 1; - if (TrackingInfoAlignment < 0) TrackingInfoAlignment = 0; if (TrackingInfoAlignment > 8) @@ -302,6 +296,7 @@ public class CustomNpcs { @EventHandler public void stopped(FMLServerStoppedEvent event){ ServerCloneController.Instance = null; + GlobalDataController.instance.saveData(); } @EventHandler diff --git a/src/main/java/noppes/npcs/DataAdvanced.java b/src/main/java/noppes/npcs/DataAdvanced.java index 67200a374..c8864dee1 100644 --- a/src/main/java/noppes/npcs/DataAdvanced.java +++ b/src/main/java/noppes/npcs/DataAdvanced.java @@ -6,6 +6,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.constants.EnumJobType; import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.controllers.GlobalDataController; import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.controllers.data.FactionOptions; import noppes.npcs.controllers.data.Line; @@ -195,8 +196,25 @@ public class DataAdvanced { npc.jobInterface = new JobHealer(npc); else if (job == EnumJobType.Guard && !(npc.jobInterface instanceof JobGuard)) npc.jobInterface = new JobGuard(npc); - else if (job == EnumJobType.ItemGiver && !(npc.jobInterface instanceof JobItemGiver)) - npc.jobInterface = new JobItemGiver(npc); + else if (job == EnumJobType.ItemGiver && !(npc.jobInterface instanceof JobItemGiver)) { + if (!npc.isRemote()) { + if (npc.itemGiverId > 0 && GlobalDataController.instance.itemGivers.containsKey(npc.itemGiverId)) { + GlobalDataController.instance.itemGivers.get(npc.itemGiverId).npc = npc; + npc.jobInterface = GlobalDataController.instance.itemGivers.get(npc.itemGiverId); + } else { + npc.jobInterface = new JobItemGiver(npc); + if (npc.itemGiverId == -1) { + ((JobItemGiver) npc.jobInterface).itemGiverId = GlobalDataController.instance.incrementItemGiverId(); + } else { + ((JobItemGiver) npc.jobInterface).itemGiverId = npc.itemGiverId; + } + GlobalDataController.instance.itemGivers.put(((JobItemGiver) npc.jobInterface).itemGiverId, (JobItemGiver) npc.jobInterface); + npc.itemGiverId = ((JobItemGiver) npc.jobInterface).itemGiverId; + } + } else { + npc.jobInterface = new JobItemGiver(npc); + } + } else if (job == EnumJobType.Follower && !(npc.jobInterface instanceof JobFollower)) npc.jobInterface = new JobFollower(npc); else if (job == EnumJobType.Spawner && !(npc.jobInterface instanceof JobSpawner)) diff --git a/src/main/java/noppes/npcs/DataInventory.java b/src/main/java/noppes/npcs/DataInventory.java index 924ebd969..9d2ff9c8e 100644 --- a/src/main/java/noppes/npcs/DataInventory.java +++ b/src/main/java/noppes/npcs/DataInventory.java @@ -93,7 +93,9 @@ public class DataInventory implements IInventory{ weapons.put(2, item); } - public void dropStuff(Entity entity, DamageSource damagesource) { + public ArrayList getDroppedItems(DamageSource damagesource) { + ArrayList drops = new ArrayList<>(); + ArrayList list = new ArrayList(); for (int i : items.keySet()) { ItemStack item = items.get(i); @@ -109,53 +111,76 @@ public class DataInventory implements IInventory{ list.add(e); } } - + for (EntityItem e : list) { + drops.add(e.getEntityItem()); + } + int enchant = 0; - if (damagesource.getEntity() instanceof EntityPlayer){ - enchant = EnchantmentHelper.getLootingModifier((EntityLivingBase)damagesource.getEntity()); - } - - if (!net.minecraftforge.common.ForgeHooks.onLivingDrops(npc, damagesource, list, enchant, true, 0)){ - for (EntityItem item : list){ - if(lootMode == 1 && entity instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)entity; - item.delayBeforeCanPickup = 2; - npc.worldObj.spawnEntityInWorld(item); - ItemStack stack = item.getEntityItem(); - int i = stack.stackSize; + if (damagesource.getEntity() instanceof EntityPlayer){ + enchant = EnchantmentHelper.getLootingModifier((EntityLivingBase)damagesource.getEntity()); + } - if (player.inventory.addItemStackToInventory(stack)) { - npc.worldObj.playSoundAtEntity(item, - "random.pop", - 0.2F, - ((npc.getRNG().nextFloat() - npc.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F); - player.onItemPickup(item, i); + if (!net.minecraftforge.common.ForgeHooks.onLivingDrops(npc, damagesource, list, enchant, true, 0)){ + return drops; + } else { + return new ArrayList<>(); + } + } - if (stack.stackSize <= 0) { - item.setDead(); - } - } - } - else - npc.worldObj.spawnEntityInWorld(item); - } - } - - int var1 = minExp; + public int getDroppedXp() { + int droppedXp = minExp; if (maxExp - minExp > 0) - var1 += npc.worldObj.rand.nextInt(maxExp - minExp); + droppedXp += npc.worldObj.rand.nextInt(maxExp - minExp); - while (var1 > 0){ - int var2 = EntityXPOrb.getXPSplit(var1); - var1 -= var2; - if(lootMode == 1 && entity instanceof EntityPlayer){ - npc.worldObj.spawnEntityInWorld(new EntityXPOrb(entity.worldObj, entity.posX, entity.posY, entity.posZ, var2)); - } - else{ - npc.worldObj.spawnEntityInWorld(new EntityXPOrb(npc.worldObj, npc.posX, npc.posY, npc.posZ, var2)); - } - } - + return droppedXp; + } + + public void dropXp(Entity entity, int droppedXp) { + while (droppedXp > 0){ + int var2 = EntityXPOrb.getXPSplit(droppedXp); + droppedXp -= var2; + if(lootMode == 1 && entity instanceof EntityPlayer){ + npc.worldObj.spawnEntityInWorld(new EntityXPOrb(entity.worldObj, entity.posX, entity.posY, entity.posZ, var2)); + } + else{ + npc.worldObj.spawnEntityInWorld(new EntityXPOrb(npc.worldObj, npc.posX, npc.posY, npc.posZ, var2)); + } + } + } + + public void dropItems(Entity entity, ArrayList itemList) { + ArrayList list = new ArrayList(); + for (ItemStack item : itemList) { + if(item == null) + continue; + EntityItem e = getEntityItem(item.copy()); + if(e != null) + list.add(e); + } + + for (EntityItem item : list){ + if(lootMode == 1 && entity instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)entity; + item.delayBeforeCanPickup = 2; + npc.worldObj.spawnEntityInWorld(item); + ItemStack stack = item.getEntityItem(); + int i = stack.stackSize; + + if (player.inventory.addItemStackToInventory(stack)) { + npc.worldObj.playSoundAtEntity(item, + "random.pop", + 0.2F, + ((npc.getRNG().nextFloat() - npc.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F); + player.onItemPickup(item, i); + + if (stack.stackSize <= 0) { + item.setDead(); + } + } + } + else + npc.worldObj.spawnEntityInWorld(item); + } } public EntityItem getEntityItem(ItemStack itemstack) { diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 4da9356f7..3a2b2d5dc 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -121,7 +121,7 @@ public class EventHooks { noppes.npcs.scripted.event.NpcEvent.InitEvent event = new noppes.npcs.scripted.event.NpcEvent.InitEvent(npc.wrappedNPC); ScriptController.Instance.npcScripts.callScript(EnumScriptType.INIT, event); - npc.script.callScript(EnumScriptType.INIT); + npc.script.callScript(EnumScriptType.INIT, event); NpcAPI.EVENT_BUS.post(event); } @@ -131,7 +131,7 @@ public class EventHooks { noppes.npcs.scripted.event.NpcEvent.UpdateEvent event = new noppes.npcs.scripted.event.NpcEvent.UpdateEvent(npc.wrappedNPC); ScriptController.Instance.npcScripts.callScript(EnumScriptType.TICK, event); - npc.script.callScript(EnumScriptType.TICK); + npc.script.callScript(EnumScriptType.TICK, event); NpcAPI.EVENT_BUS.post(event); } @@ -141,9 +141,7 @@ public class EventHooks { NpcEvent.DialogEvent event = new NpcEvent.DialogEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG, event); - - ScriptEventDialog npcEvent = new ScriptEventDialog(player,dialogId,optionId,dialog); - npc.script.callScript(EnumScriptType.DIALOG, "event", npcEvent, "player", npcEvent.getPlayer(), "dialog", npcEvent.getDialogId(), "option", npcEvent.getOptionId(), "dialogObj", npcEvent.getDialog()); + npc.script.callScript(EnumScriptType.DIALOG, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); NpcAPI.EVENT_BUS.post(event); } @@ -154,9 +152,7 @@ public class EventHooks { NpcEvent.DialogClosedEvent event = new NpcEvent.DialogClosedEvent(npc.wrappedNPC, player, dialogId, optionId, dialog); ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG_CLOSE, event); - - ScriptEventDialog npcEvent = new ScriptEventDialog(player,dialogId,optionId,dialog); - npc.script.callScript(EnumScriptType.DIALOG_CLOSE, "event", npcEvent, "player", npcEvent.getPlayer(), "dialog", npcEvent.getDialogId(), "option", npcEvent.getOptionId(), "dialogObj", npcEvent.getDialog()); + npc.script.callScript(EnumScriptType.DIALOG_CLOSE, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog()); NpcAPI.EVENT_BUS.post(event); } @@ -167,31 +163,27 @@ public class EventHooks { NpcEvent.InteractEvent event = new NpcEvent.InteractEvent(npc.wrappedNPC,player); ScriptController.Instance.npcScripts.callScript(EnumScriptType.INTERACT, event); - boolean result = npc.script.callScript(EnumScriptType.INTERACT, "player", player); + boolean result = npc.script.callScript(EnumScriptType.INTERACT, event, "player", player); NpcAPI.EVENT_BUS.post(event); return result; } - public static boolean onNPCMeleeAttack(EntityNPCInterface npc, float damage, EntityLivingBase target){ + public static boolean onNPCMeleeAttack(EntityNPCInterface npc, NpcEvent.MeleeAttackEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.MeleeAttackEvent event = new NpcEvent.MeleeAttackEvent(npc.wrappedNPC,damage,target); ScriptController.Instance.npcScripts.callScript(EnumScriptType.ATTACK_MELEE, event); - boolean result = npc.script.callScript(EnumScriptType.ATTACK, "event", new ScriptEventAttack(damage,target,false), "target", target); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); + return NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCRangedAttack(EntityNPCInterface npc, float damage, EntityLivingBase target){ + public static boolean onNPCRangedAttack(EntityNPCInterface npc, NpcEvent.RangedLaunchedEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.RangedLaunchedEvent event = new NpcEvent.RangedLaunchedEvent(npc.wrappedNPC,damage,target); ScriptController.Instance.npcScripts.callScript(EnumScriptType.RANGED_LAUNCHED, event); - boolean result = npc.script.callScript(EnumScriptType.ATTACK, "event", new ScriptEventAttack(damage,target,true), "target", target); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.ATTACK, event, "target", event.target); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCKilledEntity(EntityNPCInterface npc, EntityLivingBase entity){ @@ -200,19 +192,17 @@ public class EventHooks { NpcEvent.KilledEntityEvent event = new NpcEvent.KilledEntityEvent(npc.wrappedNPC,entity); ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLS, event); - npc.script.callScript(EnumScriptType.KILLS, "target", entity); + npc.script.callScript(EnumScriptType.KILLS, event, "target", entity); NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCTarget(EntityNPCInterface npc, EntityLivingBase target){ + public static boolean onNPCTarget(EntityNPCInterface npc, NpcEvent.TargetEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.TargetEvent event = new NpcEvent.TargetEvent(npc.wrappedNPC,target); ScriptController.Instance.npcScripts.callScript(EnumScriptType.TARGET, event); - boolean result = npc.script.callScript(EnumScriptType.TARGET, "event", new ScriptEventTarget(target)); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.TARGET, event); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCCollide(EntityNPCInterface npc, Entity entity){ @@ -221,30 +211,26 @@ public class EventHooks { NpcEvent.CollideEvent event = new NpcEvent.CollideEvent(npc.wrappedNPC,entity); ScriptController.Instance.npcScripts.callScript(EnumScriptType.COLLIDE, event); - npc.script.callScript(EnumScriptType.COLLIDE, "entity", entity); + npc.script.callScript(EnumScriptType.COLLIDE, event, "entity", entity); NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCDamaged(EntityNPCInterface npc, Entity source, float damage, DamageSource damagesource, ScriptEventDamaged damagedEvent){ + public static boolean onNPCDamaged(EntityNPCInterface npc, NpcEvent.DamagedEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.DamagedEvent event = new NpcEvent.DamagedEvent(npc.wrappedNPC,source,damage,damagesource); ScriptController.Instance.npcScripts.callScript(EnumScriptType.DAMAGED, event); - boolean result = npc.script.callScript(EnumScriptType.DAMAGED, "event", damagedEvent); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.DAMAGED, event); + return NpcAPI.EVENT_BUS.post(event); } - public static boolean onNPCKilled(EntityNPCInterface npc, DamageSource damagesource, Entity entity, ScriptEventKilled killedEvent){ + public static boolean onNPCKilled(EntityNPCInterface npc, NpcEvent.DiedEvent event){ if(npc == null || npc.wrappedNPC == null) return false; - NpcEvent.DiedEvent event = new NpcEvent.DiedEvent(npc.wrappedNPC,damagesource,entity); ScriptController.Instance.npcScripts.callScript(EnumScriptType.KILLED, event); - boolean result = npc.script.callScript(EnumScriptType.KILLED, "event", killedEvent); - NpcAPI.EVENT_BUS.post(event); - return result; + npc.script.callScript(EnumScriptType.KILLED, event); + return NpcAPI.EVENT_BUS.post(event); } public static void onNPCTimer(EntityNPCInterface npc, int id) { @@ -252,8 +238,7 @@ public class EventHooks { return; NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); - ScriptEventTimer scriptEvent = new ScriptEventTimer(id); - npc.script.callScript(EnumScriptType.TIMER, "event", scriptEvent); + npc.script.callScript(EnumScriptType.TIMER, event); ScriptController.Instance.npcScripts.callScript(EnumScriptType.TIMER, event); NpcAPI.EVENT_BUS.post(event); } diff --git a/src/main/java/noppes/npcs/NoppesUtilPlayer.java b/src/main/java/noppes/npcs/NoppesUtilPlayer.java index df129a397..200240b78 100644 --- a/src/main/java/noppes/npcs/NoppesUtilPlayer.java +++ b/src/main/java/noppes/npcs/NoppesUtilPlayer.java @@ -14,6 +14,9 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; import net.minecraft.server.MinecraftServer; import net.minecraft.util.ChatComponentText; import net.minecraft.world.WorldServer; @@ -33,6 +36,7 @@ import cpw.mods.fml.common.network.internal.FMLProxyPacket; import noppes.npcs.scripted.event.DialogEvent; import noppes.npcs.scripted.event.QuestEvent; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.IQuestObjective; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.NpcAPI; @@ -255,18 +259,19 @@ public class NoppesUtilPlayer { Dialog dialog = DialogController.instance.dialogs.get(dialogId); if(dialog == null) return; - - EventHooks.onDialogOption(new DialogEvent.DialogOption((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); - EventHooks.onNPCDialogClosed(npc,player,dialogId,optionId+1,dialog); - - if(!dialog.hasDialogs(player) && !dialog.hasOtherOptions()) { - EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); - return; - } DialogOption option = dialog.options.get(optionId); - if(option == null || option.optionType == EnumOptionType.DialogOption && (!option.isAvailable(player) || !option.hasDialog()) || option.optionType == EnumOptionType.Disabled || option.optionType == EnumOptionType.QuitOption) { - EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); - return; + if (!npc.isRemote()) { + EventHooks.onDialogOption(new DialogEvent.DialogOption((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + EventHooks.onNPCDialogClosed(npc, player, dialogId, optionId + 1, dialog); + + if (!dialog.hasDialogs(player) && !dialog.hasOtherOptions()) { + EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + return; + } + if (option == null || option.optionType == EnumOptionType.DialogOption && (!option.isAvailable(player) || !option.hasDialog()) || option.optionType == EnumOptionType.Disabled || option.optionType == EnumOptionType.QuitOption) { + EventHooks.onDialogClosed(new DialogEvent.DialogClosed((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + return; + } } if(option.optionType == EnumOptionType.RoleOption){ if(npc.roleInterface != null) @@ -284,6 +289,24 @@ public class NoppesUtilPlayer { else Server.sendData(player, EnumPacketClient.GUI_CLOSE); } + public static void sendTrackedQuestData(EntityPlayerMP player, Quest trackedQuest) { + Quest quest = (Quest) PlayerDataController.instance.getPlayerData(player).questData.trackedQuest; + if (quest == null || trackedQuest == null || quest.id != trackedQuest.id) { + return; + } + + NBTTagCompound compound = new NBTTagCompound(); + compound.setTag("Quest",trackedQuest.writeToNBT(new NBTTagCompound())); + compound.setString("CategoryName", trackedQuest.getCategory().getName()); + compound.setString("TurnInNPC", trackedQuest.getNpcName()); + NBTTagList nbtTagList = new NBTTagList(); + for (IQuestObjective objective : trackedQuest.questInterface.getObjectives(player)) { + nbtTagList.appendTag(new NBTTagString(objective.getText())); + } + compound.setTag("ObjectiveList",nbtTagList); + Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound); + } + public static void sendQuestLogData(EntityPlayerMP player) { if(!PlayerQuestController.hasActiveQuests(player)){ return; diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index c56bff429..363d31516 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -181,7 +181,9 @@ public class NoppesUtilServer { public static void openDialog(EntityPlayer player, EntityNPCInterface npc, Dialog dia, int optionId){ Dialog dialog = dia.copy(player); - EventHooks.onDialogOpen(new DialogEvent.DialogOpen((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + if (!npc.isRemote()) { + EventHooks.onDialogOpen(new DialogEvent.DialogOpen((IPlayer) NpcAPI.Instance().getIEntity(player), dialog)); + } if(npc instanceof EntityDialogNpc){ dialog.hideNPC = true; @@ -201,7 +203,10 @@ public class NoppesUtilServer { if(!data.dialogsRead.contains(dialog.id)) data.dialogsRead.add(dialog.id); setEditingNpc(player, npc); - EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog); + + if (!npc.isRemote()) { + EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog); + } } public static void runCommand(EntityPlayer player, String name, String command){ runCommand(player, name, command, player); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 0a030410c..5d776b7f4 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -154,10 +154,7 @@ public class PacketHandlerServer{ for (Quest quest : category.quests.values()) { if (quest.title.equals(questName)) { PlayerDataController.instance.getPlayerData(player).questData.trackedQuest = quest; - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("Quest",quest.writeToNBT(new NBTTagCompound())); - compound.setString("CategoryName", quest.getCategory().getName()); - Server.sendData(player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound); + NoppesUtilPlayer.sendTrackedQuestData(player, quest); return; } } @@ -632,7 +629,7 @@ public class PacketHandlerServer{ } else if(type == EnumPacketServer.TransportSave){ int cat = buffer.readInt(); - TransportLocation location = TransportController.getInstance().saveLocation(cat,Server.readNBT(buffer),player, npc); + TransportLocation location = TransportController.getInstance().saveLocation(cat,Server.readNBT(buffer), npc); if(location != null){ if(npc.advanced.role != EnumRoleType.Transporter) return; diff --git a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java index 3bfed30b9..1c5aa2272 100644 --- a/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptPlayerEventHandler.java @@ -14,7 +14,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.ContainerPlayer; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; @@ -28,7 +27,6 @@ import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.*; import net.minecraftforge.event.world.*; -import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumQuestType; import noppes.npcs.controllers.*; import noppes.npcs.controllers.data.PlayerData; @@ -61,12 +59,6 @@ public class ScriptPlayerEventHandler { if(playerData.timers.size() > 0) playerData.timers.update(); } - - if(player.ticksExisted%(20*CustomNpcs.PlayerQuestCheck) == 0){ - PlayerQuestData questData = playerData.questData; - for(EnumQuestType e : EnumQuestType.values()) - questData.checkQuestCompletion(playerData, e); - } } } @@ -435,10 +427,7 @@ public class ScriptPlayerEventHandler { Quest quest = (Quest) PlayerDataController.instance.getPlayerData(event.player).questData.trackedQuest; if (quest != null) { - NBTTagCompound compound = new NBTTagCompound(); - compound.setTag("Quest",quest.writeToNBT(new NBTTagCompound())); - compound.setString("CategoryName", quest.getCategory().getName()); - Server.sendData((EntityPlayerMP) event.player, EnumPacketClient.OVERLAY_QUEST_TRACKING, compound); + NoppesUtilPlayer.sendTrackedQuestData((EntityPlayerMP) event.player, quest); } } } diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index a25950633..520598787 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -3,6 +3,7 @@ package noppes.npcs.client; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemArmor; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderHandEvent; import net.minecraftforge.client.event.RenderPlayerEvent; @@ -36,11 +37,17 @@ public class ClientEventHandler { } @SubscribeEvent - public void cancelSpecials(RenderPlayerEvent.Specials.Pre event) { + public void cancelSpecials(RenderPlayerEvent.Specials event) { if (event.renderer instanceof RenderCNPCPlayer) event.setCanceled(true); } + @SubscribeEvent + public void cancelSpecials(RenderPlayerEvent.SetArmorModel event) { + if (event.renderer instanceof RenderCNPCPlayer && event.stack != null && event.stack.getItem() instanceof ItemArmor) + event.setCanceled(true); + } + @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { Minecraft mc = Minecraft.getMinecraft(); diff --git a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java index 88338c744..470a13647 100644 --- a/src/main/java/noppes/npcs/client/ImageDownloadAlt.java +++ b/src/main/java/noppes/npcs/client/ImageDownloadAlt.java @@ -4,6 +4,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; +import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.atomic.AtomicInteger; @@ -160,6 +161,8 @@ public class ImageDownloadAlt extends SimpleTexture ImageDownloadAlt.this.setBufferedImage(bufferedimage); } + catch (MalformedURLException ignored) { + } catch (Exception exception) { ImageDownloadAlt.logger.error("Couldn\'t download http texture", exception); diff --git a/src/main/java/noppes/npcs/client/TextBlockClient.java b/src/main/java/noppes/npcs/client/TextBlockClient.java index b5f476bcc..0ff3a81e9 100644 --- a/src/main/java/noppes/npcs/client/TextBlockClient.java +++ b/src/main/java/noppes/npcs/client/TextBlockClient.java @@ -8,19 +8,25 @@ import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatStyle; import noppes.npcs.NoppesStringUtils; import noppes.npcs.TextBlock; +import noppes.npcs.controllers.data.Dialog; import noppes.npcs.entity.EntityNPCInterface; public class TextBlockClient extends TextBlock{ private ChatStyle style; public int color = 0xe0e0e0; + public int titleColor = 0xe0e0e0; + public int titlePos = 0; private String name; private ICommandSender sender; - public TextBlockClient(ICommandSender sender, String text, int lineWidth, int color, Object... obs) { - this(text, lineWidth, false, obs); - this.color = color; + public TextBlockClient(ICommandSender sender, Dialog dialog, Object... obs) { + this(dialog.text, dialog.textWidth, false, obs); + this.color = dialog.color; + this.titleColor = dialog.titleColor; + this.titlePos = dialog.titlePos; this.sender = sender; } + public TextBlockClient(String name, String text, int lineWidth, int color, Object... obs) { this(text, lineWidth, false, obs); this.color = color; diff --git a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java index d0152dcd6..98ffa8dc6 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNpcTextureOverlays.java @@ -11,8 +11,7 @@ import org.lwjgl.opengl.GL11; public class GuiNpcTextureOverlays extends GuiNpcSelectionInterface{ public GuiNpcTextureOverlays(EntityNPCInterface npc,GuiScreen parent){ - //super(npc, parent, npc.display.glowTexture.isEmpty()?"customnpcs:textures/overlays/":npc.display.glowTexture); - super(npc, parent, npc.display.skinOverlayData.overlayList.containsKey(0) ? npc.display.skinOverlayData.overlayList.get(0).getTexture() : ""); + super(npc, parent, npc.display.skinOverlayData.overlayList.containsKey(0) ? !npc.display.skinOverlayData.overlayList.get(0).getTexture().isEmpty() ? npc.display.skinOverlayData.overlayList.get(0).getTexture() : "customnpcs:textures/overlays/" : "customnpcs:textures/overlays/"); title = "Select Overlay"; this.parent = parent; } @@ -79,10 +78,7 @@ public class GuiNpcTextureOverlays extends GuiNpcSelectionInterface{ //npc.display.glowTexture = assets.getAsset(slot.selected); //npc.textureGlowLocation = null; - npc.display.skinOverlayData.overlayList.put(0,new SkinOverlay( - assets.getAsset(slot.selected), true, 1.0F, 1.0F, 0.0F, 0.0F, - 1.0F, 1.0F, 0.0F, 0.0F, 0.0F - )); + npc.display.skinOverlayData.overlayList.put(0,new SkinOverlay(assets.getAsset(slot.selected))); } } diff --git a/src/main/java/noppes/npcs/client/gui/GuiScript.java b/src/main/java/noppes/npcs/client/gui/GuiScript.java index 44ecae3ec..ea7e4f3a9 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiScript.java +++ b/src/main/java/noppes/npcs/client/gui/GuiScript.java @@ -8,8 +8,7 @@ import net.minecraft.client.gui.GuiYesNoCallback; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.server.MinecraftServer; -import noppes.npcs.CustomNpcs; -import noppes.npcs.DataScript; +import noppes.npcs.controllers.data.DataScript; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; diff --git a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java index ef3f2cd25..dc7cbdbc7 100644 --- a/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java +++ b/src/main/java/noppes/npcs/client/gui/OverlayQuestTracking.java @@ -10,6 +10,7 @@ import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.ResourceLocation; import noppes.npcs.CustomNpcs; import noppes.npcs.controllers.data.Quest; @@ -54,9 +55,12 @@ public class OverlayQuestTracking extends Gui { private float posY; private float renderOffsetY; + private final int overlayWidth = 120; - public static Quest trackedQuest = new Quest(); - public static String categoryName = ""; + public ArrayList trackedQuestLines = new ArrayList<>(); + public ArrayList categoryNameLines = new ArrayList<>(); + public ArrayList objectiveLines = new ArrayList<>(); + public ArrayList turnInText = new ArrayList<>(); public OverlayQuestTracking(Minecraft mc) { this.mc = mc; @@ -102,64 +106,52 @@ public class OverlayQuestTracking extends Gui { } public void setOverlayData(NBTTagCompound compound) { + Quest trackedQuest = new Quest(); trackedQuest.readNBT(compound.getCompoundTag("Quest")); - categoryName = compound.getString("CategoryName"); + + trackedQuestLines = getLineList(trackedQuest.getName()); + categoryNameLines = getLineList(compound.getString("CategoryName")); + + NBTTagList nbtTagList = compound.getTagList("ObjectiveList",8); + for (int i = 0; i < nbtTagList.tagCount(); i++) { + String objective = nbtTagList.getStringTagAt(i); + + String[] split = objective.split(":"); + split = split[split.length-1].split("/"); + + boolean completed = false; + + try { + int killed = Integer.parseInt(split[0].trim()); + int total = Integer.parseInt(split[1].trim()); + + if (killed/total == 1) { + completed = true; + } + } catch (NumberFormatException e) { + if (objective.endsWith("(read)") || (objective.endsWith("Found") && !objective.endsWith("Not Found"))) { + completed = true; + } + } + + if (completed) { + objective = "&a&o&m" + objective; + } else { + objective = "&o" + objective; + } + + objectiveLines.add(objective); + } + + String npcName = compound.getString("TurnInNPC"); + if (!npcName.isEmpty()) { + turnInText.add("Complete with " + npcName); + } + this.initOverlay(); } - public void renderGameOverlay(float partialTicks){ - res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - scaledWidth = res.getScaledWidth(); - scaledHeight = res.getScaledHeight(); - - GL11.glEnable(GL11.GL_BLEND); - OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); - GL11.glDisable(GL11.GL_ALPHA_TEST); - - GL11.glPushMatrix(); - GL11.glTranslatef(CustomNpcs.TrackingInfoAlignment%3*((float)(scaledWidth)/2), (float) (Math.floor((float)(CustomNpcs.TrackingInfoAlignment/3))*((float)(scaledHeight)/2)),0.0F); - GL11.glTranslatef(CustomNpcs.TrackingInfoX - 10, CustomNpcs.TrackingInfoY, 0.0F); - - red = (color >> 16 & 255) / 255f; - green = (color >> 8 & 255) / 255f; - blue = (color & 255) / 255f; - - float centerX = -60; - float questTitleTop; - this.renderOffsetY = -40; - GL11.glPushMatrix(); - GL11.glTranslatef(centerX, 0.0F, 0.0F); - this.renderStringLines(trackedQuest.getName(),1.2F, false, true); - GL11.glPopMatrix(); - questTitleTop = this.renderOffsetY; - this.renderOffsetY -= 5; - GL11.glPushMatrix(); - GL11.glTranslatef(centerX, 0.0F, 0.0F); - this.renderStringLines(categoryName,0.85F, false, false); - GL11.glPopMatrix(); - - //TODO: Add objectives list, with green strikethrough text for completed objectives. Then, add who the player should turn the quest in to. - - this.renderOffsetY = -25; - GL11.glPushMatrix(); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY+2), 0xFF777777); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY+1), 0xFFA8A8A8); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); - GL11.glPopMatrix(); - this.renderOffsetY = questTitleTop + 5; - GL11.glPushMatrix(); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY-1), 0xFFA8A8A8); - this.drawHorizontalLine((int)(-60 + centerX), (int)(60 + centerX), (int) (this.renderOffsetY-2), 0xFF777777); - GL11.glPopMatrix(); - GL11.glPopMatrix(); - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glEnable(GL11.GL_ALPHA_TEST); - } - - public void renderStringLines(String string, float scale, boolean upwards, boolean bold) { + public ArrayList getLineList(String string) { String[] split = string.split(" "); ArrayList lines = new ArrayList<>(); @@ -174,21 +166,105 @@ public class OverlayQuestTracking extends Gui { } } + return lines; + } + + public void renderGameOverlay(float partialTicks){ + res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + scaledWidth = res.getScaledWidth(); + scaledHeight = res.getScaledHeight(); + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glPushMatrix(); + GL11.glTranslatef(CustomNpcs.TrackingInfoAlignment%3*((float)(scaledWidth)/2), (float) (Math.floor((float)(CustomNpcs.TrackingInfoAlignment/3))*((float)(scaledHeight)/2)),0.0F); + + float offsetX = CustomNpcs.TrackingInfoAlignment%3 == 0 ? 5 : -5; + GL11.glTranslatef(CustomNpcs.TrackingInfoX + offsetX, CustomNpcs.TrackingInfoY, 0.0F); + + red = (color >> 16 & 255) / 255f; + green = (color >> 8 & 255) / 255f; + blue = (color & 255) / 255f; + + float centerX = -60; + centerX *= CustomNpcs.TrackingInfoAlignment%3 == 0 ? -1 : 1; + + float questTitleTop; + this.renderOffsetY = -40; + GL11.glPushMatrix(); + GL11.glTranslatef(centerX, 0.0F, 0.0F); + this.renderStringLines(trackedQuestLines,1.2F, false, true, 0); + GL11.glPopMatrix(); + questTitleTop = this.renderOffsetY; + this.renderOffsetY -= 10; + GL11.glPushMatrix(); + GL11.glTranslatef(centerX, 0.0F, 0.0F); + this.renderStringLines(categoryNameLines,0.85F, false, false, 0); + GL11.glPopMatrix(); + + this.renderOffsetY = -10; + GL11.glPushMatrix(); + this.renderStringLines(objectiveLines,1F, true, false, CustomNpcs.TrackingInfoAlignment%3 == 0 ? 1 : 2); + GL11.glPopMatrix(); + + this.renderOffsetY += 10; + GL11.glPushMatrix(); + this.renderStringLines(turnInText,1F, false, false, CustomNpcs.TrackingInfoAlignment%3 == 0 ? 1 : 2); + GL11.glPopMatrix(); + + this.renderOffsetY = -20; + GL11.glPushMatrix(); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY+2), 0xFF777777); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY+1), 0xFFA8A8A8); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); + GL11.glPopMatrix(); + this.renderOffsetY = questTitleTop + 2; + GL11.glPushMatrix(); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY), 0xFFFFFFFF); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY-1), 0xFFA8A8A8); + this.drawHorizontalLine((int)(-overlayWidth/2 + centerX), (int)(overlayWidth/2 + centerX), (int) (this.renderOffsetY-2), 0xFF777777); + GL11.glPopMatrix(); + GL11.glPopMatrix(); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + } + + public void renderStringLines(ArrayList lines, float scale, boolean downwards, boolean bold, int facing) { for (int i = 0; i < lines.size(); i++) { String s = lines.get(i); - if (!upwards) { + if (!downwards) { s = lines.get(lines.size()-1 - i); } + int stringWidth = this.fontRenderer.getStringWidth(s.replace("&o","")); + if (s.startsWith("&a&o&m")) { + stringWidth = this.fontRenderer.getStringWidth(s.replace("&a&o&m","")); + } + GL11.glPushMatrix(); - GL11.glTranslatef(scale*(-this.fontRenderer.getStringWidth(s)/2.0F), this.renderOffsetY, 0.0F); + switch (facing) { + case 0://center + GL11.glTranslatef(scale * (-stringWidth / 2.0F), this.renderOffsetY, 0.0F); + break; + case 1://left + GL11.glTranslatef(0, this.renderOffsetY, 0.0F); + break; + case 2://right + GL11.glTranslatef(scale * (-stringWidth), this.renderOffsetY, 0.0F); + break; + } + GL11.glScalef(scale, scale, scale); this.drawString(s, 0, 0, this.color, true); if (bold) { GL11.glTranslatef(0.2F, 0.2F, 0.0F); this.drawString(s, 0, 0, this.color, false); } - this.renderOffsetY += upwards ? 10 : -10; + this.renderOffsetY += downwards ? 10 : -10; GL11.glPopMatrix(); } } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java index 5fc09c88c..39e55df76 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java @@ -39,19 +39,10 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList addButton(new GuiNpcButton(10, guiLeft + 120, y += 22, 50, 20, "selectServer.edit")); addLabel(new GuiNpcLabel(10, "advMode.command", guiLeft + 4, y + 5)); - - addButton(new GuiNpcButtonYesNo(11, guiLeft + 120, y += 22, dialog.hideNPC)); - addLabel(new GuiNpcLabel(11, "dialog.hideNPC", guiLeft + 4, y + 5)); - - addButton(new GuiNpcButtonYesNo(12, guiLeft + 120, y += 22, dialog.showWheel)); - addLabel(new GuiNpcLabel(12, "dialog.showWheel", guiLeft + 4, y + 5)); addButton(new GuiNpcButtonYesNo(15, guiLeft + 120, y += 22, dialog.disableEsc)); addLabel(new GuiNpcLabel(15, "dialog.disableEsc", guiLeft + 4, y + 5)); - addButton(new GuiNpcButtonYesNo(16, guiLeft + 120, y += 22, dialog.darkenScreen)); - addLabel(new GuiNpcLabel(16, "Darken Screen", guiLeft + 4, y + 5)); - this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 192,98, 20, "gui.done")); } @@ -63,18 +54,9 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList if(button.id == 10){ setSubGui(new SubGuiNpcCommand(dialog.command)); } - if(button.id == 11){ - dialog.hideNPC = button.getValue() == 1; - } - if(button.id == 12){ - dialog.showWheel = button.getValue() == 1; - } if(button.id == 15){ dialog.disableEsc = button.getValue() == 1; } - if(button.id == 16){ - dialog.darkenScreen = button.getValue() == 1; - } if(button.id == 13){ setSubGui(new SubGuiMailmanSendSetup(dialog.mail, getParent())); } diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java new file mode 100644 index 000000000..c44832313 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogVisual.java @@ -0,0 +1,546 @@ +package noppes.npcs.client.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.client.Client; +import noppes.npcs.client.NoppesUtil; +import noppes.npcs.client.gui.global.GuiNPCManageDialogs; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.controllers.data.Dialog; +import noppes.npcs.controllers.data.DialogImage; + +import java.util.ArrayList; +import java.util.Collections; + +public class SubGuiNpcDialogVisual extends SubGuiInterface implements ISubGuiListener, ITextfieldListener, ICustomScrollListener { + private final Dialog dialog; + public GuiScreen parent2; + + private GuiMenuTopButton[] topButtons; + private int activeMenu = 1; + + private GuiCustomScroll imageScroll; + private int selected = -1; + private int lastColorClicked = -1; + private int changedId = -1; + + public SubGuiNpcDialogVisual(Dialog dialog, GuiScreen parent) { + this.parent2 = parent; + this.dialog = dialog; + setBackground("menubg.png"); + xSize = 256; + ySize = 216; + closeOnEsc = true; + } + + public void initGui() + { + super.initGui(); + int y = guiTop - 10; + + GuiMenuTopButton close = new GuiMenuTopButton(0,guiLeft + xSize - 22, guiTop - 17, "X"); + GuiMenuTopButton general = new GuiMenuTopButton(1, guiLeft + 4, guiTop - 17, "General"); + GuiMenuTopButton spacing = new GuiMenuTopButton(2, general.xPosition + general.getWidth(), guiTop - 17, "Spacing"); + GuiMenuTopButton images = new GuiMenuTopButton(3, spacing.xPosition + spacing.getWidth(), guiTop - 17, "Images"); + topButtons = new GuiMenuTopButton[]{general,images,spacing,close}; + for(GuiMenuTopButton button : topButtons) { + button.active = button.id == activeMenu; + addButton(button); + } + + if (activeMenu == 1) { + addButton(new GuiNpcButtonYesNo(10, guiLeft + 120, y += 22, dialog.hideNPC)); + addLabel(new GuiNpcLabel(10, "dialog.hideNPC", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(11, guiLeft + 120, y += 22, dialog.showWheel)); + addLabel(new GuiNpcLabel(11, "dialog.showWheel", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(12, guiLeft + 120, y += 22, dialog.darkenScreen)); + addLabel(new GuiNpcLabel(12, "dialog.darkenScreen", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(13, guiLeft + 120, y += 22, 50, 20, new String[]{"dialog.instant", "dialog.gradual"}, dialog.renderGradual ? 1 : 0)); + addLabel(new GuiNpcLabel(13, "dialog.renderType", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(14, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showPreviousBlocks ? 1 : 0)); + addLabel(new GuiNpcLabel(14, "dialog.previousBlocks", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(15, guiLeft + 120, y += 22, 50, 20, new String[]{"display.hide", "display.show"}, dialog.showOptionLine ? 1 : 0)); + addLabel(new GuiNpcLabel(15, "dialog.optionLine", guiLeft + 4, y + 5)); + + String color = Integer.toHexString(dialog.color); + while (color.length() < 6) { + color = 0 + color; + } + addButton(new GuiNpcButton(16, guiLeft + 35, y += 25, 60, 20, color)); + addLabel(new GuiNpcLabel(16, "gui.color", guiLeft + 4, y + 5)); + getButton(16).setTextColor(dialog.color); + + color = Integer.toHexString(dialog.titleColor); + while (color.length() < 6) { + color = 0 + color; + } + addButton(new GuiNpcButton(17, guiLeft + 157, y, 60, 20, color)); + addLabel(new GuiNpcLabel(17, "dialog.titleColor", guiLeft + 100, y + 5)); + getButton(17).setTextColor(dialog.titleColor); + + addTextField(new GuiNpcTextField(18, this, guiLeft + 80, y += 22, 165, 20, dialog.textSound)); + addLabel(new GuiNpcLabel(18, "dialog.textSound", guiLeft + 4, y + 5)); + getTextField(18).setVisible(dialog.renderGradual); + getLabel(18).enabled = dialog.renderGradual; + + addTextField(new GuiNpcTextField(19, this, guiLeft + 125, y += 22, 40, 20, String.valueOf(dialog.textPitch))); + addLabel(new GuiNpcLabel(19, "dialog.textPitch", guiLeft + 4, y + 5)); + getTextField(19).floatsOnly = true; + getTextField(19).setVisible(dialog.renderGradual); + getLabel(19).enabled = dialog.renderGradual; + } else if (activeMenu == 2) { + addButton(new GuiNpcButton(10, guiLeft + 70, y += 22, 50, 20, new String[]{"gui.text", "gui.option", "display.fixed"}, dialog.titlePos)); + addLabel(new GuiNpcLabel(10, "dialog.titlePos", guiLeft + 4, y + 5)); + + addTextField(new GuiNpcTextField(11, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textWidth))); + addTextField(new GuiNpcTextField(12, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textHeight))); + addLabel(new GuiNpcLabel(12, "gui.widthHeight", guiLeft + 4, y + 5)); + getTextField(11).integersOnly = true; + getTextField(11).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(12).integersOnly = true; + getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(13, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.textOffsetX))); + addTextField(new GuiNpcTextField(14, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.textOffsetY))); + addLabel(new GuiNpcLabel(15, "dialog.textOffset", guiLeft + 4, y + 5)); + getTextField(13).integersOnly = true; + getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(14).integersOnly = true; + getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(15, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.titleOffsetX))); + addTextField(new GuiNpcTextField(16, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.titleOffsetY))); + addLabel(new GuiNpcLabel(18, "dialog.titleOffset", guiLeft + 4, y + 5)); + getTextField(15).integersOnly = true; + getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(16).integersOnly = true; + getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(17, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionOffsetX))); + addTextField(new GuiNpcTextField(18, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionOffsetY))); + addLabel(new GuiNpcLabel(21, "dialog.optionOffset", guiLeft + 4, y + 5)); + getTextField(17).integersOnly = true; + getTextField(17).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(18).integersOnly = true; + getTextField(18).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(19, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.optionSpaceX))); + addTextField(new GuiNpcTextField(20, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.optionSpaceY))); + addLabel(new GuiNpcLabel(24, "dialog.optionSpacing", guiLeft + 4, y + 5)); + getTextField(19).integersOnly = true; + getTextField(19).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(20).integersOnly = true; + getTextField(20).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(21, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcOffsetX))); + addTextField(new GuiNpcTextField(22, this, guiLeft + 165, y, 40, 20, String.valueOf(dialog.npcOffsetY))); + addLabel(new GuiNpcLabel(25, "dialog.npcOffset", guiLeft + 4, y + 5)); + getTextField(21).integersOnly = true; + getTextField(21).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(21).setVisible(!dialog.hideNPC); + getTextField(22).integersOnly = true; + getTextField(22).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(22).setVisible(!dialog.hideNPC); + getLabel(25).enabled = !dialog.hideNPC; + + addTextField(new GuiNpcTextField(23, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialog.npcScale))); + addLabel(new GuiNpcLabel(26, "dialog.npcScale", guiLeft + 4, y + 5)); + getTextField(23).floatsOnly = true; + getTextField(23).setMinMaxDefaultFloat(-Float.MAX_VALUE, Float.MAX_VALUE, 0); + getTextField(23).setVisible(!dialog.hideNPC); + getLabel(26).enabled = !dialog.hideNPC; + } else if (activeMenu == 3) { + if (imageScroll == null) { + imageScroll = new GuiCustomScroll(this, 0, false); + } + imageScroll.guiLeft = guiLeft + xSize; + imageScroll.guiTop = guiTop + 25; + imageScroll.setSize(50, this.ySize - 25); + + updateScrollData(); + + addButton(new GuiNpcButton(1, guiLeft + xSize + 2, guiTop + 5, 20, 20, "+")); + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + addButton(new GuiNpcButton(2, guiLeft + xSize + 24, guiTop + 5, 20, 20, "-")); + + addTextField(new GuiNpcTextField(10, this, guiLeft + 17, y += 25, 30, 20, String.valueOf(dialogImage.id))); + addTextField(new GuiNpcTextField(11, this, guiLeft + 92, y, 150, 20, dialogImage.texture)); + addLabel(new GuiNpcLabel(10, "gui.id", guiLeft + 4, y + 5)); + addLabel(new GuiNpcLabel(11, "display.texture", guiLeft + 50, y + 5)); + getTextField(10).integersOnly = true; + + addTextField(new GuiNpcTextField(12, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.x))); + addTextField(new GuiNpcTextField(13, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.y))); + addLabel(new GuiNpcLabel(12, "gui.position", guiLeft + 4, y + 5)); + getTextField(12).integersOnly = true; + getTextField(12).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(13).integersOnly = true; + getTextField(13).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(14, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.width))); + addTextField(new GuiNpcTextField(15, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.height))); + addLabel(new GuiNpcLabel(13, "gui.widthHeight", guiLeft + 4, y + 5)); + getTextField(14).integersOnly = true; + getTextField(14).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(15).integersOnly = true; + getTextField(15).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + addTextField(new GuiNpcTextField(16, this, guiLeft + 120, y += 25, 40, 20, String.valueOf(dialogImage.textureX))); + addTextField(new GuiNpcTextField(17, this, guiLeft + 165, y, 40, 20, String.valueOf(dialogImage.textureY))); + addLabel(new GuiNpcLabel(14, "dialog.textureOffset", guiLeft + 4, y + 5)); + getTextField(16).integersOnly = true; + getTextField(16).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + getTextField(17).integersOnly = true; + getTextField(17).setMinMaxDefault(-Integer.MAX_VALUE, Integer.MAX_VALUE, 0); + + String color = Integer.toHexString(dialogImage.color); + while(color.length() < 6) + color = 0 + color; + addButton(new GuiNpcButton(18, guiLeft + 35, y += 25, 60, 20, color)); + addLabel(new GuiNpcLabel(15, "gui.color", guiLeft + 4, y + 5)); + getButton(18).setTextColor(dialogImage.color); + + String selectedColor = Integer.toHexString(dialogImage.selectedColor); + while (selectedColor.length() < 6) + selectedColor = 0 + selectedColor; + addButton(new GuiNpcButton(19, guiLeft + 180, y, 60, 20, selectedColor)); + addLabel(new GuiNpcLabel(16, "dialog.selectedColor", guiLeft + 100, y + 5)); + getButton(19).setTextColor(dialogImage.selectedColor); + getButton(19).setEnabled(dialogImage.imageType == 2); + getButton(19).setVisible(dialogImage.imageType == 2); + getLabel(16).enabled = dialogImage.imageType == 2; + + addTextField(new GuiNpcTextField(20, this, guiLeft + 33, y += 25, 30, 20, String.valueOf(dialogImage.scale))); + addTextField(new GuiNpcTextField(21, this, guiLeft + 102, y, 30, 20, String.valueOf(dialogImage.alpha))); + addTextField(new GuiNpcTextField(22, this, guiLeft + 183, y, 45, 20, String.valueOf(dialogImage.rotation))); + addLabel(new GuiNpcLabel(17, "model.scale", guiLeft + 4, y + 5)); + addLabel(new GuiNpcLabel(18, "display.alpha", guiLeft + 72, y + 5)); + addLabel(new GuiNpcLabel(19, "movement.rotation", guiLeft + 140, y + 5)); + getTextField(20).floatsOnly = true; + getTextField(21).floatsOnly = true; + getTextField(22).floatsOnly = true; + + addButton(new GuiNpcButton(23, guiLeft + 35, y += 25, 60, 20, new String[]{"gui.screen", "gui.text", "gui.option"}, dialogImage.imageType)); + addLabel(new GuiNpcLabel(20, "gui.type", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButton(24, guiLeft + 160, y, 60, 20, + new String[]{"display.topLeft", "display.topCenter", "display.topRight", + "display.left", "display.center", "display.right", + "display.botLeft", "display.botCenter", "display.botRight"}, + dialogImage.alignment)); + addLabel(new GuiNpcLabel(21, "display.alignment", guiLeft + 110, y + 5)); + getButton(24).setEnabled(dialogImage.imageType == 0); + getButton(24).setVisible(dialogImage.imageType == 0); + getLabel(21).enabled = dialogImage.imageType == 0; + } + } + } + + public void updateScrollData() { + ArrayList ids = new ArrayList<>(dialog.dialogImages.keySet()); + Collections.sort(ids); + ArrayList strings = new ArrayList<>(); + for (int i : ids) { + strings.add(String.valueOf(i)); + } + imageScroll.setUnsortedList(strings); + + if (changedId != -1) { + selected = imageScroll.getList().indexOf(String.valueOf(changedId)); + imageScroll.setSelected(String.valueOf(changedId)); + changedId = -1; + } + + addScroll(imageScroll); + } + + private void topButtonPressed(GuiMenuTopButton button) { + NoppesUtil.clickSound(); + + int id = button.id; + if(id == 0){ + close(); + if(parent2 != null) + NoppesUtil.openGUI(player, parent2); + return; + } + save(); + + activeMenu = id; + initGui(); + } + + @Override + protected void actionPerformed(GuiButton guibutton){ + GuiNpcButton button = (GuiNpcButton) guibutton; + + if (guibutton instanceof GuiMenuTopButton) { + topButtonPressed((GuiMenuTopButton) guibutton); + } + + if (activeMenu == 1) { + if (button.id == 10) { + dialog.hideNPC = button.getValue() == 1; + } + if (button.id == 11) { + dialog.showWheel = button.getValue() == 1; + } + if (button.id == 12) { + dialog.darkenScreen = button.getValue() == 1; + } + if (button.id == 13) { + dialog.renderGradual = button.getValue() == 1; + } + if (button.id == 14) { + dialog.showPreviousBlocks = button.getValue() == 1; + } + if (button.id == 15) { + dialog.showOptionLine = button.getValue() == 1; + } + if (button.id == 16) { + setSubGui(new SubGuiColorSelector(dialog.color)); + lastColorClicked = 0; + } + if (button.id == 17) { + setSubGui(new SubGuiColorSelector(dialog.titleColor)); + lastColorClicked = 1; + } + } + + if (activeMenu == 2) { + if (button.id == 10) { + dialog.titlePos = button.getValue(); + } + } + + if (activeMenu == 3) { + if (button.id == 1) { + int addId = 0; + if (selected != -1 && imageScroll.getSelected() != null) { + DialogImage selectedImage = (DialogImage) dialog.dialogImages.get(Integer.valueOf(imageScroll.getSelected())); + ArrayList keys = new ArrayList<>(dialog.dialogImages.keySet()); + int keyIndex = keys.indexOf(selectedImage.id); + do { + addId = keys.get(keyIndex) + 1; + keyIndex++; + } while (dialog.dialogImages.containsKey(addId)); + } else if (dialog.dialogImages.size() > 0) { + addId = (Integer) dialog.dialogImages.keySet().toArray()[dialog.dialogImages.size() - 1] + 1; + } + + dialog.dialogImages.put(addId, new DialogImage(addId)); + updateScrollData(); + selected = imageScroll.getList().indexOf(String.valueOf(addId)); + } + if (button.id == 2) { + if (imageScroll.getSelected() != null) { + dialog.dialogImages.remove(Integer.valueOf(imageScroll.getSelected())); + selected--; + } + } + if (button.id == 18) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + setSubGui(new SubGuiColorSelector(dialogImage.color)); + lastColorClicked = 0; + } + } + if (button.id == 19) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + setSubGui(new SubGuiColorSelector(dialogImage.selectedColor)); + lastColorClicked = 1; + } + } + if (button.id == 23) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + dialogImage.imageType = button.getValue(); + } + } + if (button.id == 24) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + dialogImage.alignment = button.getValue(); + } + } + } + + initGui(); + } + + @Override + public void drawScreen(int i, int j, float f){ + super.drawScreen(i,j,f); + for(GuiMenuTopButton button: topButtons) + button.drawButton(mc, i, j); + } + + + @Override + public void subGuiClosed(SubGuiInterface subgui){ + if (activeMenu == 1) { + if (lastColorClicked == 0) { + dialog.color = ((SubGuiColorSelector) subgui).color; + } else if (lastColorClicked == 1) { + dialog.titleColor = ((SubGuiColorSelector) subgui).color; + } + initGui(); + } + if (activeMenu == 3) { + if (getSelectedImage() != null) { + DialogImage dialogImage = getSelectedImage(); + if (lastColorClicked == 0) { + dialogImage.color = ((SubGuiColorSelector) subgui).color; + } else if (lastColorClicked == 1) { + dialogImage.selectedColor = ((SubGuiColorSelector) subgui).color; + } + initGui(); + } + } + save(); + } + + public void save() { + GuiNpcTextField.unfocus(); + if(dialog.id >= 0) + Client.sendData(EnumPacketServer.DialogSave, ((GuiNPCManageDialogs)parent2).category.id, dialog.writeToNBT(new NBTTagCompound())); + } + + private DialogImage getSelectedImage() { + if (selected > -1) { + return (DialogImage) dialog.dialogImages.get((dialog.dialogImages.keySet().toArray(new Integer[0]))[selected]); + } else { + return null; + } + } + + @Override + public void unFocused(GuiNpcTextField textfield) { + if (activeMenu == 1) { + if (textfield.id == 18) { + dialog.textSound = textfield.getText(); + } + if (textfield.id == 19) { + dialog.textPitch = textfield.getFloat(); + } + } + + if (activeMenu == 2) { + if (textfield.id == 11) { + dialog.textWidth = textfield.getInteger(); + } + if (textfield.id == 12) { + dialog.textHeight = textfield.getInteger(); + } + + if (textfield.id == 13) { + dialog.textOffsetX = textfield.getInteger(); + } + if (textfield.id == 14) { + dialog.textOffsetY = textfield.getInteger(); + } + + if (textfield.id == 15) { + dialog.titleOffsetX = textfield.getInteger(); + } + if (textfield.id == 16) { + dialog.titleOffsetY = textfield.getInteger(); + } + + if (textfield.id == 17) { + dialog.optionOffsetX = textfield.getInteger(); + } + if (textfield.id == 18) { + dialog.optionOffsetY = textfield.getInteger(); + } + + if (textfield.id == 19) { + dialog.optionSpaceX = textfield.getInteger(); + } + if (textfield.id == 20) { + dialog.optionSpaceY = textfield.getInteger(); + } + + if (textfield.id == 21) { + dialog.npcOffsetX = textfield.getInteger(); + } + if (textfield.id == 22) { + dialog.npcOffsetY = textfield.getInteger(); + } + if (textfield.id == 23) { + dialog.npcScale = textfield.getFloat(); + } + } + + if (activeMenu == 3) { + DialogImage dialogImage = getSelectedImage(); + if (dialogImage == null) { + return; + } + + if (textfield.id == 10) { + if (imageScroll.getList().contains(String.valueOf(textfield.getInteger()))) { + textfield.setText(String.valueOf(dialogImage.id)); + return; + } + + dialog.dialogImages.remove(dialogImage.id); + dialogImage.id = textfield.getInteger(); + dialog.dialogImages.put(dialogImage.id, dialogImage); + + changedId = dialogImage.id; + updateScrollData(); + initGui(); + } + if (textfield.id == 11) { + dialogImage.texture = textfield.getText(); + } + if (textfield.id == 12) { + dialogImage.x = textfield.getInteger(); + } + if (textfield.id == 13) { + dialogImage.y = textfield.getInteger(); + } + if (textfield.id == 14) { + dialogImage.width = textfield.getInteger(); + } + if (textfield.id == 15) { + dialogImage.height = textfield.getInteger(); + } + if (textfield.id == 16) { + dialogImage.textureX = textfield.getInteger(); + } + if (textfield.id == 17) { + dialogImage.textureY = textfield.getInteger(); + } + if (textfield.id == 20) { + dialogImage.scale = textfield.getFloat(); + } + if (textfield.id == 21) { + dialogImage.alpha = textfield.getFloat(); + } + if (textfield.id == 22) { + dialogImage.rotation = textfield.getFloat(); + } + } + + save(); + } + + @Override + public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { + if(guiCustomScroll.id == 0 && imageScroll != null) { + selected = guiCustomScroll.selected; + initGui(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java index b1402308f..2525b1d42 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java @@ -71,7 +71,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent float green = (color >> 8 & 255) / 255f; float blue = (color & 255) / 255f; - GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F); GL11.glScalef(this.scale, this.scale, this.scale); diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java index 77d9025b8..5252bc50a 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageDialogs.java @@ -7,12 +7,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.client.Client; import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.GuiNpcSoundSelection; -import noppes.npcs.client.gui.SubGuiNpcAvailability; -import noppes.npcs.client.gui.SubGuiNpcDialogExtra; -import noppes.npcs.client.gui.SubGuiNpcDialogOptions; -import noppes.npcs.client.gui.SubGuiNpcFactionOptions; -import noppes.npcs.client.gui.SubGuiNpcTextArea; +import noppes.npcs.client.gui.*; import noppes.npcs.client.gui.util.GuiCustomScroll; import noppes.npcs.client.gui.util.ICustomScrollListener; import noppes.npcs.client.gui.util.GuiNPCInterface2; @@ -35,7 +30,7 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData private GuiCustomScroll scroll; private HashMap data = new HashMap(); private Dialog dialog = new Dialog(); - private DialogCategory category = new DialogCategory(); + public DialogCategory category = new DialogCategory(); private boolean categorySelection = true; private GuiNpcSoundSelection gui; @@ -88,14 +83,17 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData addLabel(new GuiNpcLabel(6, "dialog.options", guiLeft + 4, guiTop + 93)); addButton(new GuiNpcButton(6, guiLeft + 120, guiTop + 89, 50, 20, "selectServer.edit")); - addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 114, 144, 20, "availability.selectquest")); - addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 114, 20, 20, "X")); + addLabel(new GuiNpcLabel(11, "dialog.visualOption", guiLeft + 4, guiTop + 115)); + addButton(new GuiNpcButton(11, guiLeft + 120, guiTop + 110, 50, 20, "selectServer.edit")); - addLabel(new GuiNpcLabel(9, "gui.selectSound", guiLeft + 4, guiTop + 138)); - addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 148, 144, 20, dialog.sound)); - addButton(new GuiNpcButton(9, guiLeft + 150, guiTop + 148, 60, 20, "mco.template.button.select")); + addButton(new GuiNpcButton(7, guiLeft + 4, guiTop + 134, 144, 20, "availability.selectquest")); + addButton(new GuiNpcButton(8, guiLeft + 150, guiTop + 134, 20, 20, "X")); - addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 172, 120, 20, "gui.showmore")); + addLabel(new GuiNpcLabel(9, "gui.selectSound", guiLeft + 4, guiTop + 158)); + addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 168, 144, 20, dialog.sound)); + addButton(new GuiNpcButton(9, guiLeft + 150, guiTop + 168, 60, 20, "mco.template.button.select")); + + addButton(new GuiNpcButton(10, guiLeft + 4, guiTop + 192, 120, 20, "gui.showmore")); } private void categoryGuiInit() { @@ -183,6 +181,9 @@ public class GuiNPCManageDialogs extends GuiNPCInterface2 implements IScrollData if(id == 10){ setSubGui(new SubGuiNpcDialogExtra(dialog, this)); } + if(id == 11){ + setSubGui(new SubGuiNpcDialogVisual(dialog, this)); + } } @Override diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java index 2c1621059..e691f8342 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcDisplay.java @@ -132,10 +132,7 @@ public class GuiNpcDisplay extends GuiNPCInterface2 implements ITextfieldListene //npc.textureGlowLocation = null; //display.glowTexture = textfield.getText(); if (!textfield.getText().isEmpty()) { - npc.display.skinOverlayData.overlayList.put(0, new SkinOverlay( - textfield.getText(), true, 1.0F, 1.0F, 0.0F, 0.0F, - 1.0F, 1.0F, 0.0F, 0.0F, 0.0F - )); + npc.display.skinOverlayData.overlayList.put(0,new SkinOverlay(textfield.getText())); } } else if(textfield.id == 11){ diff --git a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java index 0e124d88e..6029fe636 100644 --- a/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java +++ b/src/main/java/noppes/npcs/client/gui/model/GuiEntitySelection.java @@ -16,7 +16,7 @@ import noppes.npcs.client.EntityUtil; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNPCStringSlot; import noppes.npcs.client.gui.util.GuiNpcButton; -import noppes.npcs.entity.EntityCustomNpc; +import noppes.npcs.entity.*; import org.lwjgl.opengl.GL11; @@ -115,13 +115,29 @@ public class GuiEntitySelection extends GuiNPCInterface super.drawScreen(i, j, f); } public void elementClicked(){ + if (playerdata.getEntityClass().equals(parent.data.get(slot.selected))) { + return; + } + try{ playerdata.setEntityClass(parent.data.get(slot.selected)); EntityLivingBase entity = playerdata.getEntity(npc); if(entity != null){ npc.display.modelType = 0; - RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); - npc.display.texture = NPCRendererHelper.getTexture(render,entity); + if (entity instanceof EntityNpcCrystal) { + npc.display.texture = "customnpcs:textures/entity/crystal/EnderCrystal.png"; + } else if (entity instanceof EntityNPCGolem) { + npc.display.texture = "customnpcs:textures/entity/golem/Iron Golem.png"; + } else if (entity instanceof EntityNpcPony) { + npc.display.texture = "customnpcs:textures/entity/ponies/MineLP Derpy Hooves.png"; + } else if (entity instanceof EntityNpcSlime) { + npc.display.texture = "customnpcs:textures/entity/slime/Slime.png"; + } else if (entity instanceof EntityNpcDragon) { + npc.display.texture = "customnpcs:textures/entity/dragon/BlackDragon.png"; + } else { + RendererLivingEntity render = (RendererLivingEntity) RenderManager.instance.getEntityRenderObject(entity); + npc.display.texture = NPCRendererHelper.getTexture(render, entity); + } } else{ npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; @@ -130,8 +146,7 @@ public class GuiEntitySelection extends GuiNPCInterface npc.display.skinOverlayData.overlayList.remove(0); npc.textureLocation = null; npc.updateHitbox(); - } - catch(Exception ex){ + } catch(Exception ex) { npc.display.texture = "customnpcs:textures/entity/humanmale/Steve.png"; } } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java new file mode 100644 index 000000000..f4de00036 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogImage.java @@ -0,0 +1,107 @@ +package noppes.npcs.client.gui.player; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; +import noppes.npcs.controllers.data.DialogImage; +import org.lwjgl.opengl.GL11; + +public class GuiDialogImage extends Gui { + GuiDialogInteract parent; + ResourceLocation location; + + public int id; + public String texture; + public int x; + public int y; + public int width; + public int height; + public int textureX; + public int textureY; + public float scale; + + public int color; + public int selectedColor; + public float alpha; + public float rotation; + + public int imageType = 0; //0 - Default, 1 - Text, 2 - Option + public int alignment = 0; + + public GuiDialogImage(DialogImage dialogImage) { + this.location = new ResourceLocation(dialogImage.texture); + + this.id = dialogImage.id; + this.texture = dialogImage.texture; + this.x = dialogImage.x; + this.y = dialogImage.y; + this.width = dialogImage.width; + this.height = dialogImage.height; + this.textureX = dialogImage.textureX; + this.textureY = dialogImage.textureY; + this.scale = dialogImage.scale; + + this.color = dialogImage.color; + this.selectedColor = dialogImage.selectedColor; + this.rotation = dialogImage.rotation; + this.alpha = dialogImage.alpha; + + this.imageType = dialogImage.imageType; + this.alignment = dialogImage.alignment; + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true,false)); + texturemanager.loadTexture(this.location, object); + } + } + + public void setParent(GuiDialogInteract parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc) { + try { + mc.getTextureManager().bindTexture(this.location); + } catch (Exception ignored) { return; } + + GL11.glPushMatrix(); + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + GL11.glColor4f(red,green,blue,this.alpha); + + GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + + int p_73729_1_ = (int) (this.x/(this.scale)); + int p_73729_2_ = (int) (this.y/(this.scale)); + int p_73729_3_ = this.textureX; + int p_73729_4_ = this.textureY; + int p_73729_5_ = (int)(this.width); + int p_73729_6_ = (int)(this.height); + + float f = 0.00390625F; + float f1 = 0.00390625F; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorOpaque_F(1, 1, 1); + tessellator.setColorRGBA_F(red, green, blue, alpha); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.draw(); + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index 142fc1127..0ac6df680 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -4,7 +4,9 @@ import java.util.ArrayList; import java.util.List; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.entity.RenderManager; @@ -22,9 +24,11 @@ import noppes.npcs.client.gui.util.IGuiClose; import noppes.npcs.constants.EnumOptionType; import noppes.npcs.constants.EnumPlayerPacket; import noppes.npcs.controllers.data.Dialog; +import noppes.npcs.controllers.data.DialogImage; import noppes.npcs.controllers.data.DialogOption; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.scripted.interfaces.handler.data.IDialogImage; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -34,21 +38,38 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose { private Dialog dialog; private int selected = 0; - private List lines = new ArrayList(); + private List lineBlocks = new ArrayList(); private List options = new ArrayList(); - private int rowStart = 0; - private int rowTotal = 0; - private int dialogHeight = 180; + private int totalRows = 0; + private ScaledResolution scaledResolution; + + private String gradualText = ""; + private int currentBlock = 0; + private int currentLine = 0; + private int gradualTextTime = 0; + private int optionStart = 0; + + private int instantBlockPos = 0; + private int instantLinePos = 0; + private int prevPausePos = -1; + + private static int textSpeed = 10; + private static boolean textSoundEnabled = true; + + private int scrollY; private ResourceLocation wheel; private ResourceLocation[] wheelparts; private ResourceLocation indicator; - + private boolean isGrabbed = false; - + private int textSoundTime = 0; + private int textPauseTime = 0; + public GuiDialogInteract(EntityNPCInterface npc, Dialog dialog){ super(npc); this.dialog = dialog; + appendDialog(dialog); ySize = 238; @@ -57,16 +78,19 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose wheelparts = new ResourceLocation[]{getResource("wheel1.png"),getResource("wheel2.png"),getResource("wheel3.png"), getResource("wheel4.png"),getResource("wheel5.png"),getResource("wheel6.png")}; } - + public void initGui(){ super.initGui(); isGrabbed = false; grabMouse(dialog.showWheel); guiTop = (height - ySize); calculateRowHeight(); + this.scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); this.drawDefaultBackground = dialog.darkenScreen; + + optionStart = scaledResolution.getScaledHeight() - (options.size()) * (ClientProxy.Font.height() + dialog.optionSpaceY) - 20; } - + public void grabMouse(boolean grab){ if(grab && !isGrabbed){ Minecraft.getMinecraft().mouseHelper.grabMouseCursor(); @@ -77,16 +101,16 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose isGrabbed = false; } } - + public void drawScreen(int i, int j, float f){ GL11.glColor4f(1, 1, 1, 1); - + if(!dialog.hideNPC){ float l = (guiLeft - 70); float i1 = (guiTop + ySize); GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glPushMatrix(); - GL11.glTranslatef(l, i1, 50F); + GL11.glTranslatef(l + dialog.npcOffsetX, i1 + dialog.npcOffsetY, 50F); float zoomed = npc.height; if(npc.width * 2 > zoomed) zoomed = npc.width * 2; @@ -111,12 +135,12 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose npc.prevRotationYawHead = npc.rotationYawHead = npc.rotationYaw; GL11.glTranslatef(0.0F, npc.yOffset, 0.0F); RenderManager.instance.playerViewY = 180F; - + try{ + GL11.glScalef(dialog.npcScale,dialog.npcScale,dialog.npcScale); RenderManager.instance.renderEntityWithPosYaw(npc, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); - } - catch(Exception e){ - } + } catch(Exception ignored){} + npc.ai.orientation = rotation; npc.renderYawOffset = f2; npc.rotationYaw = f3; @@ -134,44 +158,227 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glPushMatrix(); - GL11.glTranslatef(0.0F, 0.5f, 100.065F); - int count = 0; - for(TextBlockClient block : lines){ - int size = ClientProxy.Font.width(block.getName() + ": "); - drawString(block.getName() + ": ", -4 - size, block.color, count); - for(IChatComponent line : block.lines){ - drawString(line.getFormattedText(), 0, block.color, count); - count++; - } - count++; - } - - if(!options.isEmpty()){ - if(!dialog.showWheel) - drawLinedOptions(j); - else - drawWheel(); - } + GL11.glTranslatef(0.0F, 0.5f, 100.065F); + if (dialog.renderGradual) { + drawString(fontRendererObj, "Text Speed: " + textSpeed, 10, 10, 0xFFFFFF); + drawString(fontRendererObj, "Text Sound: " + (textSoundEnabled ? "On" : "Off"), 10, 20, 0xFFFFFF); + } + + for (IDialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage((DialogImage) dialogImage); + + if (image.imageType != 0) + continue; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glTranslatef(image.alignment%3*((float)(scaledResolution.getScaledWidth())/2), (float) (Math.floor((float)(image.alignment/3))*((float)(scaledResolution.getScaledHeight())/2)),0.0F); + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + } + + GL11.glPushMatrix(); + for (IDialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage((DialogImage) dialogImage); + + if (image.imageType != 1) + continue; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glTranslatef(guiLeft + dialog.textOffsetX, optionStart + dialog.textOffsetY - image.height * image.scale, 0.0F); + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + } + GL11.glPopMatrix(); + + if (!dialog.renderGradual) { + int count = 0; + blockLoop: + for (int b = 0; b < lineBlocks.size(); b++) { + TextBlockClient block = lineBlocks.get(b); + + int size = ClientProxy.Font.width(block.getName() + " "); + drawDialogString(block.getName() + " ", -4 - size, count, false, block); + + for (int l = 0; l < block.lines.size(); l++) { + IChatComponent line = block.lines.get(l); + String drawText = line.getFormattedText(); + + if (b >= instantBlockPos && l >= instantLinePos) { + if (drawText.matches("(.*)(\\{(\\d+)})(.*)")) { + if (textPauseTime > 0) { + drawText = drawText.substring(0, prevPausePos); + drawDialogString(drawText, 0, count, true, block); + textPauseTime--; + break blockLoop; + } + + String strInt = ""; + for (int c = 0; c < drawText.length(); c++) { + if (drawText.substring(c).matches("^(\\{(\\d+)})(.*)") && c > prevPausePos) { + prevPausePos = c; + strInt += drawText.charAt(++c); + } else if (c > prevPausePos && !strInt.isEmpty()) { + if (drawText.charAt(c) == '}') + break; + + strInt += drawText.charAt(c); + } + } + + if (!strInt.isEmpty()) { + drawText = drawText.substring(0, prevPausePos); + + drawDialogString(drawText, 0, count, true, block); + + instantBlockPos = b; + instantLinePos = l; + textPauseTime = Integer.parseInt(strInt); + break blockLoop; + } + } else { + prevPausePos = -1; + } + } + + drawDialogString(drawText, 0, count, true, block); + count++; + } + count++; + } + } else { + int count = 0; + for (int pastBlock = 0; pastBlock < currentBlock; pastBlock++) { + TextBlockClient block = lineBlocks.get(pastBlock); + int size = ClientProxy.Font.width(block.getName() + " "); + drawDialogString(block.getName() + " ", -4 - size, count, false, block); + + for (IChatComponent line : block.lines) { + drawDialogString(line.getFormattedText(), 0, count, true, block); + count++; + } + count++; + } + + if (currentBlock < lineBlocks.size()) { + TextBlockClient block = lineBlocks.get(currentBlock); + int size = ClientProxy.Font.width(block.getName() + " "); + drawDialogString(block.getName() + " ", -4 - size, count, false, block); + + for (int pastLine = 0; pastLine < currentLine; pastLine++) { + IChatComponent line = block.lines.get(pastLine); + drawDialogString(line.getFormattedText(), 0, count, true, block); + count++; + } + + if (currentLine < block.lines.size()) { + IChatComponent line = block.lines.get(currentLine); + try { + if (textPauseTime > 0) { + textPauseTime--; + } else if (textSpeed > 10 || gradualTextTime%(11 - textSpeed) == 0) { + int addChar = textSpeed > 10 ? textSpeed - 9 : 1; + String addText = line.getFormattedText().substring(gradualText.length(), gradualText.length() + addChar); + + if (addText.matches("^(\\{(\\d+)})(.*)")) { + StringBuilder numStr = new StringBuilder(); + int numLength; + for (numLength = 1; numLength < addText.length(); numLength++) { + if (addText.charAt(numLength) == '}') + break; + + numStr.append(addText.charAt(numLength)); + } + textPauseTime = Integer.parseInt(numStr.toString()); + addText = line.getFormattedText().substring(gradualText.length(), gradualText.length() + numLength + 1); + } else if (addText.matches("(.+)\\{(\\d+)(.*)")) { + StringBuilder str = new StringBuilder(); + for (char c : addText.toCharArray()) { + if (c == '{') + break; + str.append(c); + } + + addText = str.toString(); + } else if (addText.matches("(\\{(\\d+))$") || addText.equals("{")) { + do { + if (addText.length() == gradualText.length() + addText.length() + 1) + break; + + addText += line.getFormattedText().substring(gradualText.length() + addText.length(), gradualText.length() + addText.length() + 1); + } while (addText.matches("(.*)(\\{(\\d+))$")); + + textPauseTime = Integer.parseInt(addText.replace("{","").replace("}","")); + } + + gradualText += addText; + if (textSoundTime % 5 == 0) { + Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation(dialog.textSound), dialog.textPitch)); + } + textSoundTime++; + } + } catch (IndexOutOfBoundsException exception) { + gradualText = line.getFormattedText(); + } + + drawDialogString(gradualText, 0, count, true, block); + + if (gradualText.length() == line.getFormattedText().length()) { + gradualText = ""; + currentLine++; + if (currentLine >= lineBlocks.get(currentBlock).lines.size()) { + currentBlock++; + } + } + + gradualTextTime++; + } + } + } + GL11.glPopMatrix(); + + GL11.glPushMatrix(); + if (!options.isEmpty()) { + if (!dialog.showWheel) { + GL11.glTranslatef(dialog.optionOffsetX, dialog.optionOffsetY, 0); + drawLinedOptions(j); + } else { + drawWheel(); + } + } GL11.glPopMatrix(); } private int selectedX = 0; private int selectedY = 0; private void drawWheel(){ - int yoffset = guiTop + dialogHeight + 14; + int yoffset = optionStart + dialog.optionOffsetY; + GL11.glColor4f(1, 1, 1, 1); mc.renderEngine.bindTexture(wheel); - drawTexturedModalRect((width/2) - 31, yoffset, 0, 0, 63, 40); - - selectedX += Mouse.getDX(); + drawTexturedModalRect((width/2) - 31 + dialog.optionOffsetX, yoffset, 0, 0, 63, 40); + + selectedX += Mouse.getDX(); selectedY += Mouse.getDY(); int limit = 80; if(selectedX > limit) selectedX = limit; if(selectedX < -limit) selectedX = -limit; - + if(selectedY > limit) selectedY = limit; if(selectedY < -limit) @@ -182,89 +389,167 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose selected++; if(selectedY > 54) selected--; - + if(selectedX < 0) selected += 3; mc.renderEngine.bindTexture(wheelparts[selected]); - drawTexturedModalRect((width/2) - 31,yoffset, 0, 0, 85, 55); + drawTexturedModalRect((width/2) - 31 + dialog.optionOffsetX,yoffset, 0, 0, 85, 55); for(int slot:dialog.options.keySet()){ DialogOption option = dialog.options.get(slot); if(option == null || option.optionType == EnumOptionType.Disabled) continue; - int color = option.optionColor; + int color = option.optionColor; if(slot == (selected)) color = 0x838FD8; //drawString(fontRenderer, option.title, width/2 -50 ,yoffset+ 162 + slot * 13 , color); if(slot == 0) - drawString(fontRendererObj, option.title, width/2 + 13,yoffset - 6 , color); + drawString(fontRendererObj, option.title, width/2 + 13 + dialog.optionOffsetX,yoffset - 6 , color); if(slot == 1) - drawString(fontRendererObj, option.title, width/2 + 33,yoffset + 12 , color); + drawString(fontRendererObj, option.title, width/2 + 33 + dialog.optionOffsetX,yoffset + 12 , color); if(slot == 2) - drawString(fontRendererObj, option.title, width/2 + 27,yoffset + 32 , color); + drawString(fontRendererObj, option.title, width/2 + 27 + dialog.optionOffsetX,yoffset + 32 , color); if(slot == 3) - drawString(fontRendererObj, option.title, width/2 - 13 - ClientProxy.Font.width(option.title),yoffset - 6 , color); + drawString(fontRendererObj, option.title, width/2 - 13 + dialog.optionOffsetX - ClientProxy.Font.width(option.title),yoffset - 6 , color); if(slot == 4) - drawString(fontRendererObj, option.title, width/2 - 33 - ClientProxy.Font.width(option.title),yoffset + 12 , color); + drawString(fontRendererObj, option.title, width/2 - 33 + dialog.optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 12 , color); if(slot == 5) - drawString(fontRendererObj, option.title, width/2 - 27 - ClientProxy.Font.width(option.title),yoffset + 32 , color); - + drawString(fontRendererObj, option.title, width/2 - 27 + dialog.optionOffsetX - ClientProxy.Font.width(option.title),yoffset + 32 , color); + } mc.renderEngine.bindTexture(indicator); - drawTexturedModalRect(width/2 + selectedX/4 - 2,yoffset + 16 - selectedY/6, 0, 0, 8, 8); + drawTexturedModalRect(width/2 + selectedX/4 - 2 + dialog.optionOffsetX,yoffset + 16 - selectedY/6, 0, 0, 8, 8); } private void drawLinedOptions(int j){ - drawHorizontalLine(guiLeft - 60, guiLeft + xSize + 120, guiTop + dialogHeight, 0xFFFFFFFF); - int offset = dialogHeight + 4; - if(j >= (int)((guiTop + offset))){ - int selected = (int) ((j - (guiTop + offset)) / (ClientProxy.Font.height())); + int offset = optionStart; + + if(j >= offset){ + int selected = (j - offset - ClientProxy.Font.height() - dialog.optionOffsetY) / (ClientProxy.Font.height() + dialog.optionSpaceY); if(selected < options.size()) this.selected = selected; } if(selected >= options.size()) - selected = 0; + selected = options.size() - 1; if(selected < 0) selected = 0; - int count = 0; + + if (dialog.showOptionLine) { + drawHorizontalLine(guiLeft - 60, guiLeft + xSize + 120, offset, 0xFFFFFFFF); + } + for(int k = 0; k < options.size(); k++){ + GL11.glPushMatrix(); int id = options.get(k); DialogOption option = dialog.options.get(id); - int y = (int)((guiTop + offset + (count * ClientProxy.Font.height()))); + int y = offset + (k + 1) * ClientProxy.Font.height(); + offset += dialog.optionSpaceY; + if(selected == k){ drawString(fontRendererObj, ">", guiLeft - 60, y, 0xe0e0e0); } - drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30, y, option.optionColor); - count++; - } - } - - private void drawString(String text, int left, int color, int count){ - int height = count - rowStart; - drawString(fontRendererObj, text, guiLeft + left, guiTop + (height * ClientProxy.Font.height()), color); + + GL11.glPushMatrix(); + for (IDialogImage dialogImage : dialog.dialogImages.values()) { + GuiDialogImage image = new GuiDialogImage((DialogImage) dialogImage); + + if (image.imageType != 2) + continue; + + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); + GL11.glDisable(GL11.GL_ALPHA_TEST); + + GL11.glTranslatef(guiLeft - 30 + dialog.optionSpaceX * k, y, 0.0F); + image.color = selected == k ? image.selectedColor : image.color; + image.onRender(mc); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + } + GL11.glPopMatrix(); + + drawString(fontRendererObj, NoppesStringUtils.formatText(option.title, player, npc), guiLeft - 30 + dialog.optionSpaceX * k, y, option.optionColor); + GL11.glPopMatrix(); + } } + private void drawDialogString(String text, int left, int count, boolean mainDialogText, TextBlockClient block){ + int lineOffset = dialog.renderGradual ? (currentBlock < lineBlocks.size() ? lineBlocks.get(currentBlock).lines.size() : lineBlocks.get(lineBlocks.size()-1).lines.size()) - currentLine : 0; + int height = count - totalRows + lineOffset; + int screenPos = optionStart; + int y = (height * ClientProxy.Font.height()) + screenPos + scrollY; + + if (block.titlePos == 0 || mainDialogText) { + if (y < screenPos - dialog.textHeight || y > screenPos - ClientProxy.Font.height()) { + return; + } + } + + int offsetX, offsetY, color; + if (mainDialogText) { + offsetX = dialog.textOffsetX; + offsetY = dialog.textOffsetY; + color = block.color; + } else { + offsetX = dialog.titleOffsetX; + offsetY = dialog.titleOffsetY; + color = block.titleColor; + + if (block.titlePos == 1 && block.equals(lineBlocks.get(currentBlock < lineBlocks.size() ? currentBlock : currentBlock - 1))) { + y = screenPos - ClientProxy.Font.height() - 5; + } + } + + text = text.replaceAll("\\{(\\d+)}",""); + if (!mainDialogText && block.titlePos == 2 && block.equals(lineBlocks.get(currentBlock < lineBlocks.size() ? currentBlock : currentBlock - 1))) { + drawString(fontRendererObj, text, offsetX, offsetY, color); + } else { + drawString(fontRendererObj, text, guiLeft + left + offsetX, y + offsetY, color); + } + } + public void drawString(FontRenderer fontRendererIn, String text, int x, int y, int color){ ClientProxy.Font.drawString(text, x, y, color); - //super.drawString(fontRendererIn, text, x, y, color); - } - - private int getSelected(){ - if(selected <= 0) - return 0; - - if(selected < options.size()) - return selected; - - return options.size() - 1; } @Override public void keyTyped(char c, int i){ if(i == mc.gameSettings.keyBindForward.getKeyCode() || i == Keyboard.KEY_UP){ - selected--; + if (dialog.showWheel) { + selected--; + } else { + selected++; + } } if(i == mc.gameSettings.keyBindBack.getKeyCode() || i == Keyboard.KEY_DOWN){ - selected++; + if (dialog.showWheel) { + selected++; + } else { + selected--; + } } + + if(i == mc.gameSettings.keyBindForward.getKeyCode() || i == Keyboard.KEY_LEFT){ + textSpeed--; + if (textSpeed < 1) { + textSpeed = 1; + } + } + if(i == mc.gameSettings.keyBindBack.getKeyCode() || i == Keyboard.KEY_RIGHT){ + textSpeed++; + } + + if(i == mc.gameSettings.keyBindJump.getKeyCode() || i == Keyboard.KEY_SPACE){ + textSoundEnabled = !textSoundEnabled; + } + + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 201 && scrollY < (totalRows - 2) * ClientProxy.Font.height()) {//Page up + scrollY += ClientProxy.Font.height() * 2; + } + if (i == mc.gameSettings.keyBindBack.getKeyCode() || i == 209 && scrollY > 0) {//Page down + scrollY -= ClientProxy.Font.height() * 2; + } + if(i == 28){ handleDialogSelection(); } @@ -278,8 +563,10 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose @Override public void mouseClicked(int i,int j,int k){ - if(selected == -1 && options.isEmpty() || selected >= 0) - handleDialogSelection(); + if(selected == -1 && options.isEmpty() || selected >= 0) { + scrollY = 0; + handleDialogSelection(); + } } private void handleDialogSelection(){ int optionId = -1; @@ -299,20 +586,31 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose close(); return; } - - lines.add(new TextBlockClient(player.getDisplayName(), option.title, 280, option.optionColor, player, npc)); + + if (!dialog.showPreviousBlocks) { + lineBlocks.clear(); + } + lineBlocks.add(new TextBlockClient(player.getDisplayName(), option.title, dialog.textWidth, option.optionColor, player, npc)); + gradualText = ""; + currentBlock = lineBlocks.size()-1; + currentLine = 0; + gradualTextTime = 0; + + instantBlockPos = lineBlocks.size()-1; + instantLinePos = 0; calculateRowHeight(); - + textPauseTime = 0; + NoppesUtil.clickSound(); - + } private void closed(){ grabMouse(false); NoppesUtilPlayer.sendData(EnumPlayerPacket.CheckQuestCompletion); } - + public void save() { - + } public void appendDialog(Dialog dialog) { @@ -324,38 +622,31 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose MusicController.Instance.stopMusic(); MusicController.Instance.playSound(dialog.sound, (float)npc.posX, (float)npc.posY, (float)npc.posZ); } - - lines.add(new TextBlockClient(npc, dialog.text, 280, 0xe0e0e0, player, npc)); - - for(int slot:dialog.options.keySet()){ + + if (!dialog.showPreviousBlocks) { + lineBlocks.clear(); + } + lineBlocks.add(new TextBlockClient(npc, dialog, player, npc)); + gradualText = ""; + currentBlock = lineBlocks.size()-1; + currentLine = 0; + gradualTextTime = 0; + + for(int slot:dialog.options.keySet()){ DialogOption option = dialog.options.get(slot); if(option == null || option.optionType == EnumOptionType.Disabled) continue; options.add(slot); - } - calculateRowHeight(); + } + calculateRowHeight(); - grabMouse(dialog.showWheel); + grabMouse(dialog.showWheel); } private void calculateRowHeight(){ - if(dialog.showWheel){ - dialogHeight = ySize - 58; - } - else{ - dialogHeight = ySize - 3 * ClientProxy.Font.height() - 4; - if(dialog.options.size() > 3){ - dialogHeight -= (dialog.options.size() - 3) * ClientProxy.Font.height(); - } - } - rowTotal = 0; - for(TextBlockClient block : lines){ - rowTotal += block.lines.size() + 1; + totalRows = 0; + for(TextBlockClient block : lineBlocks){ + totalRows += block.lines.size() + 1; } - int max = dialogHeight / ClientProxy.Font.height(); - - rowStart = rowTotal - max; - if(rowStart < 0) - rowStart = 0; } @Override diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java index 6060d5cea..a45c5d062 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java @@ -43,6 +43,10 @@ public class GuiNpcTextField extends GuiTextField{ private boolean charAllowed(char c, int i){ if(!integersOnly || Character.isDigit(c)) return true; + + if(integersOnly && getText().isEmpty() && c == '-') + return true; + for(int j : allowedSpecialChars) if(j == i) return true; diff --git a/src/main/java/noppes/npcs/client/model/ModelMPM.java b/src/main/java/noppes/npcs/client/model/ModelMPM.java index 01f251ac4..1968ce49e 100644 --- a/src/main/java/noppes/npcs/client/model/ModelMPM.java +++ b/src/main/java/noppes/npcs/client/model/ModelMPM.java @@ -64,6 +64,7 @@ public class ModelMPM extends ModelNPCMale{ public boolean currentlyPlayerTexture; public boolean isArmor; + public boolean isAlexArmor; public float alpha = 1; // Steve 64x64 and Alex 64x64 @@ -198,6 +199,10 @@ public class ModelMPM extends ModelNPCMale{ super(par1); isArmor = par1 > 0; + if (isArmor && alexArms == 1) { + isAlexArmor = true; + } + float par2 = 0; this.bipedCloak = new ModelRenderer(this, 0, 0); @@ -230,12 +235,18 @@ public class ModelMPM extends ModelNPCMale{ this.bipedLeftArm.setRotationPoint(5.0F, 2.0F + par2, 0.0F); } else { this.bipedRightArm = (new ModelScaleRenderer(this, 40, 16)); - this.bipedRightArm.addBox(-2.0F, -2.0F, -2.0F, 3, 12, 4, par1); - this.bipedLeftArm = new ModelScaleRenderer(this, 40, 16); this.bipedLeftArm.mirror = true; - this.bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 3, 12, 4, par1); - this.bipedLeftArm.setRotationPoint(5.0F, 2.5F + par2, 0.0F); + + if (isArmor) { + this.bipedLeftArm.setRotationPoint(5.0F, 2.5F + par2, 0.0F); + this.bipedRightArm.addBox(-4.5F, -2.0F, -2.0F, 4, 12, 4, par1); + this.bipedLeftArm.addBox(0.25F, -2.0F, -2.0F, 4, 12, 4, par1); + } else { + this.bipedLeftArm.setRotationPoint(5.0F, 2.5F + par2, 0.0F); + this.bipedRightArm.addBox(-2.0F, -2.0F, -2.0F, 3, 12, 4, par1); + this.bipedLeftArm.addBox(-1.0F, -2.0F, -2.0F, 3, 12, 4, par1); + } } this.bipedRightLeg = new ModelScaleRenderer(this, 0, 16); @@ -598,6 +609,10 @@ public class ModelMPM extends ModelNPCMale{ GL11.glPushMatrix(); + if (isAlexArmor) { + GL11.glScalef(0.75F,1.0F,1.0F); + } + if(entity.currentAnimation == EnumAnimation.DANCING){ float dancing = entity.ticksExisted / 4f; GL11.glTranslatef((float)Math.sin(dancing) * 0.025F, (float)Math.abs(Math.cos(dancing)) * 0.125F - 0.02F, 0.0F); diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java index fe913ebe1..86046afec 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCNPCPlayer.java @@ -45,7 +45,7 @@ public class RenderCNPCPlayer extends RenderPlayer { this.setRenderManager(RenderManager.instance); } - private boolean preRenderOverlay(EntityPlayer player, ResourceLocation overlayLocation, boolean glow, + private boolean preRenderOverlay(EntityPlayer player, ResourceLocation overlayLocation, boolean glow, boolean blend, float alpha, float size, float speedX, float speedY, float scaleX, float scaleY, float offsetX, float offsetY, float offsetZ) { if (overlayLocation.getResourcePath().isEmpty()) @@ -67,7 +67,11 @@ public class RenderCNPCPlayer extends RenderPlayer { // Overlay & Glow GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + if (blend) { + GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); + } else { + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + } GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F); if (glow) { @@ -127,7 +131,7 @@ public class RenderCNPCPlayer extends RenderPlayer { } } - if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.alpha, overlayData.size, + if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.blend, overlayData.alpha, overlayData.size, overlayData.speedX, overlayData.speedY, overlayData.scaleX, overlayData.scaleY, overlayData.offsetX, overlayData.offsetY, overlayData.offsetZ )) @@ -330,7 +334,7 @@ public class RenderCNPCPlayer extends RenderPlayer { } } - if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.alpha, overlayData.size, + if (!preRenderOverlay(player, overlayData.location, overlayData.glow, overlayData.blend, overlayData.alpha, overlayData.size, overlayData.speedX, overlayData.speedY, overlayData.scaleX, overlayData.scaleY, overlayData.offsetX, overlayData.offsetY, overlayData.offsetZ )) @@ -628,7 +632,7 @@ public class RenderCNPCPlayer extends RenderPlayer { int j = 5095183; h1 = 1.0F; ////renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,bodycm); - ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,"N"); + //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,"N"); ////renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,bodycm); ModelBipedDBC.getMethod("renderBody",float.class).invoke(modelMain,0.0625F); @@ -660,7 +664,7 @@ public class RenderCNPCPlayer extends RenderPlayer { short TransFrHrn = ((short[]) JRMCoreH.getField("TransFrHrn").get(null))[st]; - ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,(ts == 4 ? "n" : "") + "FR" + TransFrHrn); + //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,(ts == 4 ? "n" : "") + "FR" + TransFrHrn); //renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,bodyc1); //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,(ts == 4 ? "n" : "") + "FR" + TransFrHrn); @@ -784,7 +788,7 @@ public class RenderCNPCPlayer extends RenderPlayer { } //renderPlayerJBRA.getMethod("glColor3f",int.class).invoke(null,maxBody); - ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,ts != 0 && ts != -1 ? (ts == 1 ? "SJT2" : "") : "SJT1"); + //ModelBipedDBC.getMethod("renderHairs",float.class,String.class).invoke(modelMain,0.0625F,ts != 0 && ts != -1 ? (ts == 1 ? "SJT2" : "") : "SJT1"); } h1 = 1.0F; diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java index e0615c6c7..60d119f52 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCHumanMale.java @@ -37,7 +37,9 @@ public class RenderNPCHumanMale extends RenderNPCInterface protected final static ModelMPM steve64 = new ModelMPM(0, false); protected final static ModelMPM alex = new ModelMPM(0, true); - protected final static ModelMPM alex32mainmodel = new ModelMPM(0,1); + protected final static ModelMPM steveArmorChest = new ModelMPM(1,0); + protected final static ModelMPM steveArmor = new ModelMPM(0.5F,0); + protected final static ModelMPM alex32armorChest = new ModelMPM(1,1); protected final static ModelMPM alex32armor = new ModelMPM(0.5F,1); @@ -119,28 +121,17 @@ public class RenderNPCHumanMale extends RenderNPCInterface EntityCustomNpc test = (EntityCustomNpc) npc; if(test.modelData.entityClass == null){ int modelVal = npc.display.modelType; - if(modelVal == 1 && npc.display.x64texture){ + if(modelVal == 1){ this.mainModel = steve64; this.modelBipedMain = steve64; + this.modelArmorChestplate = steveArmorChest; + this.modelArmor = steveArmor; } else if(modelVal == 2){ - if (npc.display.x64texture) { - this.mainModel = alex; - this.modelBipedMain = alex; - } else { - ((EntityCustomNpc) npc).modelData.bodywear = 0; - ((EntityCustomNpc) npc).modelData.armwear = 0; - ((EntityCustomNpc) npc).modelData.legwear = 0; - this.mainModel = alex32mainmodel; - this.modelBipedMain = alex32mainmodel; - } - } - else if(modelVal == 3){ - ((EntityCustomNpc) npc).modelData.bodywear = 0; - ((EntityCustomNpc) npc).modelData.armwear = 0; - ((EntityCustomNpc) npc).modelData.legwear = 0; - this.mainModel = alex32mainmodel; - this.modelBipedMain = alex32mainmodel; + this.mainModel = alex; + this.modelBipedMain = alex; + this.modelArmorChestplate = alex32armorChest; + this.modelArmor = alex32armor; } else{ ((EntityCustomNpc) npc).modelData.bodywear = 0; @@ -148,6 +139,8 @@ public class RenderNPCHumanMale extends RenderNPCInterface ((EntityCustomNpc) npc).modelData.legwear = 0; this.mainModel = originalModel; this.modelBipedMain = originalBipedMain; + this.modelArmorChestplate = steveArmorChest; + this.modelArmor = steveArmor; } } } diff --git a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java index 254c3ef16..73d190929 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderNPCInterface.java @@ -243,7 +243,11 @@ public class RenderNPCInterface extends RenderLiving{ // Overlay & Glow GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + if (overlayData.getBlend()) { + GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE); + } else { + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + } GL11.glAlphaFunc(GL11.GL_GREATER, 0.003921569F); if (overlayData.getGlow()) { @@ -309,11 +313,16 @@ public class RenderNPCInterface extends RenderLiving{ EntityNPCInterface npc = (EntityNPCInterface) entity; if (npc.textureLocation == null) { if (npc.display.skinType == 0) { - if (!(npc.display.texture).equals("")) { - //npc.textureLocation = new ResourceLocation(npc.display.texture); - try { - npc.textureLocation = adjustLocalTexture(npc, new ResourceLocation(npc.display.texture)); - } catch (IOException ignored) {} + if (npc instanceof EntityCustomNpc && ((EntityCustomNpc) npc).modelData.entityClass == null) { + if (!(npc.display.texture).equals("")) { + //npc.textureLocation = new ResourceLocation(npc.display.texture); + try { + npc.textureLocation = adjustLocalTexture(npc, new ResourceLocation(npc.display.texture)); + } catch (IOException ignored) { + } + } + } else { + npc.textureLocation = new ResourceLocation(npc.display.texture); } } else if(LastTextureTick < 5) { //fixes request flood somewhat return AbstractClientPlayer.locationStevePng; diff --git a/src/main/java/noppes/npcs/controllers/GlobalDataController.java b/src/main/java/noppes/npcs/controllers/GlobalDataController.java index 3c91876c3..d02912009 100644 --- a/src/main/java/noppes/npcs/controllers/GlobalDataController.java +++ b/src/main/java/noppes/npcs/controllers/GlobalDataController.java @@ -3,15 +3,19 @@ package noppes.npcs.controllers; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.util.HashMap; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import noppes.npcs.CustomNpcs; +import noppes.npcs.roles.JobItemGiver; public class GlobalDataController { public static GlobalDataController instance; private int itemGiverId = 0; + public HashMap itemGivers = new HashMap<>(); public GlobalDataController(){ instance = this; @@ -37,9 +41,17 @@ public class GlobalDataController { } } } - private void loadData(File file) throws Exception{ + private void loadData(File file) throws Exception { NBTTagCompound nbttagcompound1 = CompressedStreamTools.readCompressed(new FileInputStream(file)); itemGiverId = nbttagcompound1.getInteger("itemGiverId"); + + NBTTagList jobList = nbttagcompound1.getTagList("ItemGivers", 10); + for (int i = 0; i < jobList.tagCount(); i++) { + NBTTagCompound compound = jobList.getCompoundTagAt(i); + JobItemGiver jobItemGiver = new JobItemGiver(); + jobItemGiver.readFromNBT(compound); + itemGivers.put(jobItemGiver.itemGiverId, jobItemGiver); + } } public void saveData(){ try { @@ -47,6 +59,14 @@ public class GlobalDataController { NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.setInteger("itemGiverId", itemGiverId); + + NBTTagList jobList = new NBTTagList(); + for (JobItemGiver jobItemGiver : itemGivers.values()) { + NBTTagCompound compound = new NBTTagCompound(); + jobItemGiver.writeToNBT(compound); + jobList.appendTag(compound); + } + nbttagcompound.setTag("ItemGivers", jobList); File file = new File(saveDir, "global.dat_new"); File file1 = new File(saveDir, "global.dat_old"); @@ -72,7 +92,6 @@ public class GlobalDataController { } public int incrementItemGiverId(){ itemGiverId++; - saveData(); return itemGiverId; } } diff --git a/src/main/java/noppes/npcs/controllers/ScriptController.java b/src/main/java/noppes/npcs/controllers/ScriptController.java index 066ef7193..dac601506 100644 --- a/src/main/java/noppes/npcs/controllers/ScriptController.java +++ b/src/main/java/noppes/npcs/controllers/ScriptController.java @@ -67,7 +67,13 @@ public class ScriptController { for(ScriptEngineFactory fac : manager.getEngineFactories()){ if(fac.getExtensions().isEmpty()) continue; - fac.getScriptEngine(); + ScriptEngine scriptEngine = fac.getScriptEngine(); + try { + scriptEngine.put("$RunTest",null); + } catch (Exception e) { + continue; + } + String ext = "." + fac.getExtensions().get(0).toLowerCase(); LogWriter.info(fac.getLanguageName() + ": " + ext); languages.put(fac.getLanguageName(), ext); diff --git a/src/main/java/noppes/npcs/controllers/TransportController.java b/src/main/java/noppes/npcs/controllers/TransportController.java index b84371c4b..2679269c3 100644 --- a/src/main/java/noppes/npcs/controllers/TransportController.java +++ b/src/main/java/noppes/npcs/controllers/TransportController.java @@ -4,7 +4,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.CompressedStreamTools; @@ -17,8 +20,11 @@ import noppes.npcs.controllers.data.TransportCategory; import noppes.npcs.controllers.data.TransportLocation; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTransporter; +import noppes.npcs.scripted.interfaces.handler.ITransportHandler; +import noppes.npcs.scripted.interfaces.handler.data.ITransportCategory; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class TransportController { +public class TransportController implements ITransportHandler { private HashMap locations = new HashMap(); public HashMap categories = new HashMap(); @@ -131,7 +137,7 @@ public class TransportController { return null; } - private int getUniqueIdLocation() { + public int getUniqueIdLocation() { if(lastUsedID == 0){ for(int catid : locations.keySet()) if(catid > lastUsedID) @@ -219,7 +225,27 @@ public class TransportController { public static TransportController getInstance(){ return instance; } - public TransportLocation saveLocation(int categoryId, NBTTagCompound compound, EntityPlayerMP player, EntityNPCInterface npc){ + + public TransportLocation saveLocation(int categoryId, TransportLocation location){ + TransportCategory category = categories.get(categoryId); + if(category == null) + return null; + location.category = category; + if(location.id < 0 || !locations.get(location.id).name.equals(location.name)){ + while(containsLocationName(location.name)) + location.name += "_"; + } + if(location.id < 0) + location.id = getUniqueIdLocation(); + + category.locations.put(location.id, location); + locations.put(location.id, location); + saveCategories(); + + return location; + } + + public TransportLocation saveLocation(int categoryId, NBTTagCompound compound, EntityNPCInterface npc){ TransportCategory category = categories.get(categoryId); if(category == null || npc.advanced.role != EnumRoleType.Transporter) return null; @@ -243,4 +269,32 @@ public class TransportController { return location; } + public ITransportCategory[] categories() { + return (new ArrayList<>(categories.values())).toArray(new ITransportCategory[0]); + } + + public void createCategory(String title) { + this.saveCategory(title, -1); + } + + public ITransportCategory getCategory(String title) { + TransportCategory category = null; + for (TransportCategory c : categories.values()) { + if (c.title.equals(title)) { + category = c; + break; + } + } + + return category; + } + + public void removeCategory(String title) { + for (Map.Entry entry : categories.entrySet()) { + if (entry.getValue().title.equals(title)) { + categories.remove(entry.getKey()); + break; + } + } + } } diff --git a/src/main/java/noppes/npcs/DataScript.java b/src/main/java/noppes/npcs/controllers/data/DataScript.java similarity index 88% rename from src/main/java/noppes/npcs/DataScript.java rename to src/main/java/noppes/npcs/controllers/data/DataScript.java index 883550e11..6e2998e67 100644 --- a/src/main/java/noppes/npcs/DataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/DataScript.java @@ -1,4 +1,4 @@ -package noppes.npcs; +package noppes.npcs.controllers.data; import java.util.*; @@ -10,13 +10,13 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.world.World; import net.minecraft.world.WorldServer; +import noppes.npcs.EventHooks; import noppes.npcs.constants.EnumScriptType; import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.IScriptHandler; import noppes.npcs.controllers.ScriptController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.entity.ScriptNpc; -import noppes.npcs.scripted.event.ScriptEvent; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.constants.JobType; @@ -58,7 +58,14 @@ public class DataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { scripts = readScript(compound.getTagList("ScriptsContainers", 10)); - scriptLanguage = compound.getString("ScriptLanguage"); + this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } enabled = compound.getBoolean("ScriptEnabled"); } @@ -97,7 +104,7 @@ public class DataScript implements IScriptHandler { return list; } - public boolean callScript(EnumScriptType type, Object... obs){ + public boolean callScript(EnumScriptType type, Event event, Object... obs){ if(aiNeedsUpdate){ npc.updateAI = true; aiNeedsUpdate = false; @@ -108,10 +115,9 @@ public class DataScript implements IScriptHandler { } if(!isEnabled()) return false; - if(!hasInited){ + if(!hasInited && !npc.isRemote() && type != EnumScriptType.INIT){ hasInited = true; EventHooks.onNPCInit(this.npc); - callScript(EnumScriptType.INIT); } ScriptContainer script = scripts.get(type.ordinal()); if(script == null || script.errored || !script.hasCode()) @@ -126,16 +132,14 @@ public class DataScript implements IScriptHandler { script.engine.put(obs[i].toString(), ob); } - return callScript(script); + return callScript(script, event); } - private boolean callScript(ScriptContainer script){ + private boolean callScript(ScriptContainer script, Event event){ ScriptEngine engine = script.engine; engine.put("npc", dummyNpc); engine.put("world", dummyWorld); - ScriptEvent result = (ScriptEvent) engine.get("event"); - if(result == null) - engine.put("event", result = new ScriptEvent()); + engine.put("event", event); engine.put("API", new NpcAPI()); engine.put("EntityType", entities); engine.put("RoleType", roles); @@ -150,17 +154,13 @@ public class DataScript implements IScriptHandler { npc.updateAI = true; aiNeedsUpdate = false; } - return result.isCancelled(); + return event.isCanceled(); } public boolean isEnabled(){ return enabled && ScriptController.HasStart && !npc.worldObj.isRemote && !scripts.isEmpty(); } - public void callScript(EnumScriptType var1, Event var2, Object... obs) { - - } - public Map getConsoleText() { Map map = new TreeMap(); int tab = 0; @@ -192,7 +192,7 @@ public class DataScript implements IScriptHandler { @Override public void callScript(EnumScriptType var1, Event var2) { - + callScript(var1, var2, "$$IGNORED$$", null); } public boolean isClient() { diff --git a/src/main/java/noppes/npcs/controllers/data/Dialog.java b/src/main/java/noppes/npcs/controllers/data/Dialog.java index 76ef188c1..01cfa4ece 100644 --- a/src/main/java/noppes/npcs/controllers/data/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/data/Dialog.java @@ -28,11 +28,36 @@ public class Dialog implements ICompatibilty, IDialog { public String sound; public String command = ""; public PlayerMail mail = new PlayerMail(); - + + public int color = 0xe0e0e0; + public int titleColor = 0xe0e0e0; + public boolean hideNPC = false; public boolean showWheel = false; public boolean disableEsc = false; public boolean darkenScreen = true; + public boolean showOptionLine = true; + + public boolean renderGradual = false; + public boolean showPreviousBlocks = true; + + public String textSound = "minecraft:random.wood_click"; + public float textPitch = 1.0F; + + public int textWidth = 300; + public int textHeight = 400; + + public int titlePos; + public int textOffsetX, textOffsetY; + public int titleOffsetX, titleOffsetY; + + public int optionSpaceX, optionSpaceY; + public int optionOffsetX, optionOffsetY; + + public float npcScale = 1.0F; + public int npcOffsetX, npcOffsetY; + + public HashMap dialogImages = new HashMap<>(); public boolean hasDialogs(EntityPlayer player) { for(DialogOption option: options.values()) @@ -82,6 +107,58 @@ public class Dialog implements ICompatibilty, IDialog { } this.options = newoptions; + NBTTagList images = compound.getTagList("Images", 10); + HashMap newImages = new HashMap<>(); + for(int i = 0; i < images.tagCount(); i++){ + NBTTagCompound imageCompound = images.getCompoundTagAt(i); + int id = imageCompound.getInteger("ID"); + DialogImage image = new DialogImage(id); + image.readNBT(imageCompound); + newImages.put(id, image); + } + this.dialogImages = newImages; + + color = compound.getInteger("Color"); + titleColor = compound.getInteger("TitleColor"); + renderGradual = compound.getBoolean("RenderGradual"); + showPreviousBlocks = compound.getBoolean("PreviousBlocks"); + showOptionLine = compound.getBoolean("ShowOptionLine"); + textSound = compound.getString("TextSound"); + textPitch = compound.getFloat("TextPitch"); + textWidth = compound.getInteger("TextWidth"); + textHeight = compound.getInteger("TextHeight"); + textOffsetX = compound.getInteger("TextOffsetX"); + textOffsetY = compound.getInteger("TextOffsetY"); + titlePos = compound.getInteger("TitlePos"); + titleOffsetX = compound.getInteger("TitleOffsetX"); + titleOffsetY = compound.getInteger("TitleOffsetY"); + optionOffsetX = compound.getInteger("OptionOffsetX"); + optionOffsetY = compound.getInteger("OptionOffsetY"); + optionSpaceX = compound.getInteger("OptionSpaceX"); + optionSpaceY = compound.getInteger("OptionSpaceY"); + npcScale = compound.getFloat("NPCScale"); + npcOffsetX = compound.getInteger("NPCOffsetX"); + npcOffsetY = compound.getInteger("NPCOffsetY"); + + if (!compound.hasKey("PreviousBlocks")) + showPreviousBlocks = true; + if (!compound.hasKey("TextSound")) + textSound = "minecraft:random.wood_click"; + if (!compound.hasKey("TextPitch")) + textPitch = 1.0F; + if (!compound.hasKey("TextWidth")) + textWidth = 300; + if (!compound.hasKey("TextHeight")) + textHeight = 400; + if (!compound.hasKey("ShowOptionLine")) + showOptionLine = true; + if (!compound.hasKey("NPCScale")) + npcScale = 1.0F; + if (!compound.hasKey("Color")) + color = 0xe0e0e0; + if (!compound.hasKey("TitleColor")) + titleColor = 0xe0e0e0; + availability.readFromNBT(compound); factionOptions.readFromNBT(compound); } @@ -119,6 +196,36 @@ public class Dialog implements ICompatibilty, IDialog { availability.writeToNBT(compound); factionOptions.writeToNBT(compound); compound.setInteger("ModRev", version); + + compound.setInteger("Color", color); + compound.setInteger("TitleColor", titleColor); + compound.setBoolean("RenderGradual", renderGradual); + compound.setBoolean("PreviousBlocks", showPreviousBlocks); + compound.setBoolean("ShowOptionLine", showOptionLine); + compound.setString("TextSound", textSound); + compound.setFloat("TextPitch", textPitch); + compound.setInteger("TextWidth", textWidth); + compound.setInteger("TextHeight", textHeight); + compound.setInteger("TextOffsetX", textOffsetX); + compound.setInteger("TextOffsetY", textOffsetY); + compound.setInteger("TitlePos", titlePos); + compound.setInteger("TitleOffsetX", titleOffsetX); + compound.setInteger("TitleOffsetY", titleOffsetY); + compound.setInteger("OptionOffsetX", optionOffsetX); + compound.setInteger("OptionOffsetY", optionOffsetY); + compound.setInteger("OptionSpaceX", optionSpaceX); + compound.setInteger("OptionSpaceY", optionSpaceY); + compound.setFloat("NPCScale", npcScale); + compound.setInteger("NPCOffsetX", npcOffsetX); + compound.setInteger("NPCOffsetY", npcOffsetY); + + NBTTagList images = new NBTTagList(); + for (IDialogImage dialogImage : dialogImages.values()) { + NBTTagCompound imageCompound = ((DialogImage) dialogImage).writeToNBT(new NBTTagCompound()); + images.appendTag(imageCompound); + } + compound.setTag("Images",images); + return compound; } @@ -143,10 +250,32 @@ public class Dialog implements ICompatibilty, IDialog { dialog.sound = sound; dialog.mail = mail; dialog.command = command; + dialog.color = color; + dialog.titleColor = titleColor; dialog.hideNPC = hideNPC; dialog.showWheel = showWheel; dialog.disableEsc = disableEsc; dialog.darkenScreen = darkenScreen; + dialog.renderGradual = renderGradual; + dialog.showPreviousBlocks = showPreviousBlocks; + dialog.showOptionLine = showOptionLine; + dialog.textSound = textSound; + dialog.textPitch = textPitch; + dialog.textWidth = textWidth; + dialog.textHeight = textHeight; + dialog.textOffsetX = textOffsetX; + dialog.textOffsetY = textOffsetY; + dialog.titlePos = titlePos; + dialog.titleOffsetX = titleOffsetX; + dialog.titleOffsetY = titleOffsetY; + dialog.optionOffsetX = optionOffsetX; + dialog.optionOffsetY = optionOffsetY; + dialog.optionSpaceX = optionSpaceX; + dialog.optionSpaceY = optionSpaceY; + dialog.npcScale = npcScale; + dialog.npcOffsetX = npcOffsetX; + dialog.npcOffsetY = npcOffsetY; + dialog.dialogImages = dialogImages; for(int slot : options.keySet()){ DialogOption option = options.get(slot); @@ -269,4 +398,156 @@ public class Dialog implements ICompatibilty, IDialog { public String getSound() { return this.sound; } + + public void setColor(int color) { + this.color = color; + } + public int getColor() { + return this.color; + } + + public void setTitleColor(int titleColor) { + this.titleColor = titleColor; + } + public int getTitleColor() { + return titleColor; + } + + public void renderGradual(boolean gradual) { + this.renderGradual = gradual; + } + public boolean renderGradual() { + return renderGradual; + } + + public void showPreviousBlocks(boolean show) { + this.showPreviousBlocks = show; + } + public boolean showPreviousBlocks() { + return showPreviousBlocks; + } + + public void showOptionLine(boolean show) { + this.showOptionLine = show; + } + public boolean showOptionLine() { + return showOptionLine; + } + + public void setTextSound(String textSound) { + this.textSound = textSound; + } + public String getTextSound() { + return textSound; + } + + public void setTextPitch(float textPitch) { + this.textPitch = textPitch; + } + public float getTextPitch() { + return textPitch; + } + + public void setTitlePos(int pos) { + this.titlePos = pos; + } + public int getTitlePos() { + return this.titlePos; + } + + public void setNPCScale(float scale) { + this.npcScale = scale; + } + public float getNpcScale() { + return npcScale; + } + + public void setNpcOffset(int offsetX, int offsetY) { + this.npcOffsetX = offsetX; + this.npcOffsetY = offsetY; + } + public int getNpcOffsetX() { + return npcOffsetX; + } + public int getNpcOffsetY() { + return npcOffsetY; + } + + public void textWidthHeight(int textWidth, int textHeight) { + this.textWidth = textWidth; + this.textHeight = textHeight; + } + public int getTextWidth() { + return textWidth; + } + public int setTextHeight() { + return textHeight; + } + + public void setTextOffset(int offsetX, int offsetY) { + this.textOffsetX = offsetX; + this.textOffsetY = offsetY; + } + public int getTextOffsetX() { + return textOffsetX; + } + public int getTextOffsetY() { + return textOffsetY; + } + + public void setTitleOffset(int offsetX, int offsetY) { + this.titleOffsetX = offsetX; + this.titleOffsetY = offsetY; + } + public int getTitleOffsetX() { + return titleOffsetX; + } + public int getTitleOffsetY() { + return titleOffsetY; + } + + public void setOptionOffset(int offsetX, int offsetY) { + this.optionOffsetX = offsetX; + this.optionOffsetY = offsetY; + } + public int getOptionOffsetX() { + return optionOffsetX; + } + public int getOptionOffsetY() { + return optionOffsetY; + } + + public void setOptionSpacing(int spaceX, int spaceY) { + this.optionSpaceX = spaceX; + this.optionSpaceY = spaceY; + } + public int getOptionSpaceX() { + return optionSpaceX; + } + public int getOptionSpaceY() { + return optionSpaceY; + } + + public void addImage(int id, IDialogImage image) { + ((DialogImage) image).id = id; + dialogImages.put(id, image); + } + public IDialogImage getImage(int id) { + return dialogImages.get(id); + } + public IDialogImage createImage() { + return new DialogImage(); + } + public IDialogImage[] getImages() { + return (new ArrayList<>(dialogImages.values())).toArray(new IDialogImage[0]); + } + public boolean hasImage(int id) { + return dialogImages.containsKey(id); + } + public void removeImage(int id) { + dialogImages.remove(id); + } + public void clearImages() { + dialogImages.clear(); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/DialogImage.java b/src/main/java/noppes/npcs/controllers/data/DialogImage.java new file mode 100644 index 000000000..068836a8c --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/DialogImage.java @@ -0,0 +1,202 @@ +package noppes.npcs.controllers.data; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.interfaces.handler.data.IDialogImage; + +public class DialogImage implements IDialogImage { + public int id; + public String texture = ""; + public int x = 0; + public int y = 0; + public int width = 0; + public int height = 0; + public int textureX = 0; + public int textureY = 0; + public float scale = 1.0F; + + public int color = 0xFFFFFF; + public int selectedColor = 0xFFFFFF; + public float alpha = 1.0F; + public float rotation = 0; + + public int imageType = 1; //0 - Default, 1 - Text, 2 - Option + public int alignment = 0; + + public DialogImage() { + } + + public DialogImage(int id) { + this.id = id; + } + + public NBTTagCompound writeToNBT(NBTTagCompound compound) { + compound.setInteger("ID", id); + compound.setString("Texture", texture); + compound.setInteger("PosX", x); + compound.setInteger("PosY", y); + compound.setInteger("Width", width); + compound.setInteger("Height", height); + compound.setInteger("TextureX", textureX); + compound.setInteger("TextureY", textureY); + compound.setFloat("Scale", scale); + compound.setInteger("Color", color); + compound.setInteger("SelectedColor", selectedColor); + compound.setFloat("Alpha", alpha); + compound.setFloat("Rotation", rotation); + compound.setInteger("ImageType", imageType); + compound.setInteger("Alignment", alignment); + + return compound; + } + + public void readNBT(NBTTagCompound compound) { + id = compound.getInteger("ID"); + texture = compound.getString("Texture"); + x = compound.getInteger("PosX"); + y = compound.getInteger("PosY"); + width = compound.getInteger("Width"); + height = compound.getInteger("Height"); + textureX = compound.getInteger("TextureX"); + textureY = compound.getInteger("TextureY"); + scale = compound.getFloat("Scale"); + color = compound.getInteger("Color"); + selectedColor = compound.getInteger("SelectedColor"); + alpha = compound.getFloat("Alpha"); + rotation = compound.getFloat("Rotation"); + imageType = compound.getInteger("ImageType"); + alignment = compound.getInteger("Alignment"); + } + + @Override + public int getId() { + return id; + } + + @Override + public void setTexture(String texture) { + this.texture = texture; + } + + @Override + public String getTexture() { + return texture; + } + + @Override + public void setPosition(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public int getX() { + return x; + } + + @Override + public int getY() { + return y; + } + + @Override + public void setWidthHeight(int width, int height) { + this.width = width; + this.height = height; + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } + + @Override + public void setTextureOffset(int offsetX, int offsetY) { + this.textureX = offsetX; + this.textureY = offsetY; + } + + @Override + public int getTextureX() { + return textureX; + } + + @Override + public int getTextureY() { + return textureY; + } + + @Override + public void setColor(int color) { + this.color = color; + } + + @Override + public int getColor() { + return color; + } + + @Override + public void setSelectedColor(int color) { + this.selectedColor = color; + } + + @Override + public int getSelectedColor() { + return selectedColor; + } + + @Override + public void setScale(float scale) { + this.scale = scale; + } + + @Override + public float getScale() { + return scale; + } + + @Override + public void setAlpha(float alpha) { + this.alpha = alpha; + } + + @Override + public float getAlpha() { + return alpha; + } + + @Override + public void setRotation(float rotation) { + this.rotation = rotation; + } + + @Override + public float getRotation() { + return rotation; + } + + @Override + public void setImageType(int imageType) { + this.imageType = imageType; + } + + @Override + public int getImageType() { + return imageType; + } + + @Override + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + @Override + public int getAlignment() { + return alignment; + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java index f4e548b1b..50c449e3c 100644 --- a/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/ForgeDataScript.java @@ -38,6 +38,13 @@ public class ForgeDataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } this.enabled = compound.getBoolean("ScriptEnabled"); } diff --git a/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java b/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java index 621a6877b..24ea16816 100644 --- a/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/NPCDataScript.java @@ -41,6 +41,13 @@ public class NPCDataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } this.enabled = compound.getBoolean("ScriptEnabled"); this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java b/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java index df1d40afd..ae9e47178 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerBankData.java @@ -5,11 +5,15 @@ import java.util.HashMap; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.controllers.BankController; +import noppes.npcs.scripted.interfaces.handler.IPlayerBankData; -public class PlayerBankData{ +public class PlayerBankData implements IPlayerBankData { + private final PlayerData parent; public HashMap banks; - public PlayerBankData(){ + + public PlayerBankData(PlayerData parent){ banks = new HashMap(); + this.parent = parent; } public void loadNBTData(NBTTagCompound compound) { diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 77f779db9..6fa62f017 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -15,19 +15,23 @@ import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.entity.data.DataSkinOverlays; import noppes.npcs.entity.data.DataTimers; import noppes.npcs.roles.RoleCompanion; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.handler.*; import noppes.npcs.util.NBTJsonUtil; import java.io.File; import java.io.FileInputStream; -public class PlayerData implements IExtendedEntityProperties{ - public PlayerDialogData dialogData = new PlayerDialogData(); - public PlayerBankData bankData = new PlayerBankData(); - public PlayerQuestData questData = new PlayerQuestData(); - public PlayerTransportData transportData = new PlayerTransportData(); - public PlayerFactionData factionData = new PlayerFactionData(); - public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(); - public PlayerMailData mailData = new PlayerMailData(); +public class PlayerData implements IExtendedEntityProperties, IPlayerData { + public PlayerDialogData dialogData = new PlayerDialogData(this); + public PlayerBankData bankData = new PlayerBankData(this); + public PlayerQuestData questData = new PlayerQuestData(this); + public PlayerTransportData transportData = new PlayerTransportData(this); + public PlayerFactionData factionData = new PlayerFactionData(this); + public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this); + public PlayerMailData mailData = new PlayerMailData(this); + public DataTimers timers = new DataTimers(this); public DataSkinOverlays skinOverlays = new DataSkinOverlays(this); @@ -245,4 +249,48 @@ public class PlayerData implements IExtendedEntityProperties{ return data; } } + + public void setCompanion(ICustomNpc npc) { + this.setCompanion((EntityNPCInterface) npc.getMCEntity()); + } + + public ICustomNpc getCompanion() { + return (ICustomNpc) NpcAPI.Instance().getIEntity(activeCompanion); + } + + public int getCompanionID() { + return companionID; + } + + public IPlayerDialogData getDialogData() { + return dialogData; + } + + public IPlayerBankData getBankData() { + return bankData; + } + + public IPlayerQuestData getQuestData() { + return questData; + } + + public IPlayerTransportData getTransportData() { + return transportData; + } + + public IPlayerFactionData getFactionData() { + return factionData; + } + + public IPlayerItemGiverData getItemGiverData() { + return itemgiverData; + } + + public IPlayerMailData getMailData() { + return mailData; + } + + public void save() { + PlayerDataController.instance.savePlayerData(this); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index 7f8ea2e60..94e464571 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -47,6 +47,13 @@ public class PlayerDataScript implements IScriptHandler { public void readFromNBT(NBTTagCompound compound) { this.scripts = NBTTags.GetScript(compound.getTagList("Scripts", 10), this); this.scriptLanguage = compound.getString("ScriptLanguage"); + if (!ScriptController.Instance.languages.containsKey(scriptLanguage)) { + if (!ScriptController.Instance.languages.isEmpty()) { + this.scriptLanguage = (String) ScriptController.Instance.languages.keySet().toArray()[0]; + } else { + this.scriptLanguage = "ECMAScript"; + } + } this.enabled = compound.getBoolean("ScriptEnabled"); this.console = NBTTags.GetLongStringMap(compound.getTagList("ScriptConsole", 10)); } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java b/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java index 93b879f46..265b036d4 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java @@ -4,9 +4,15 @@ import java.util.HashSet; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.scripted.interfaces.handler.IPlayerDialogData; -public class PlayerDialogData{ +public class PlayerDialogData implements IPlayerDialogData { + private final PlayerData parent; public HashSet dialogsRead = new HashSet(); + + public PlayerDialogData(PlayerData parent) { + this.parent = parent; + } public void loadNBTData(NBTTagCompound compound) { HashSet dialogsRead = new HashSet(); @@ -35,5 +41,16 @@ public class PlayerDialogData{ compound.setTag("DialogData", list); } - + + public boolean hasReadDialog(int id) { + return dialogsRead.contains(id); + } + + public void readDialog(int id) { + dialogsRead.add(id); + } + + public void unreadDialog(int id) { + dialogsRead.remove(id); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java b/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java index e19290fe9..365c30c58 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerFactionData.java @@ -11,10 +11,20 @@ import noppes.npcs.controllers.FactionController; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.event.FactionEvent; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.IPlayerFactionData; -public class PlayerFactionData { +public class PlayerFactionData implements IPlayerFactionData { + private final PlayerData parent; public HashMap factionData = new HashMap(); - + + public PlayerFactionData() { + parent = null; + } + + public PlayerFactionData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { HashMap factionData = new HashMap(); if(compound == null) @@ -79,4 +89,19 @@ public class PlayerFactionData { return compound; } + public int getPoints(int id) { + return this.getFactionPoints(id); + } + + public void addPoints(int id, int points) { + if (parent != null) { + this.increasePoints(id, points, parent.player); + } + } + + public void setPoints(int id, int points) { + if (parent != null) { + increasePoints(id, points-getFactionPoints(id), parent.player); + } + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java b/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java index 88bdb52f0..d54e54f20 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerItemGiverData.java @@ -1,15 +1,25 @@ package noppes.npcs.controllers.data; +import java.util.ArrayList; import java.util.HashMap; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.NBTTags; +import noppes.npcs.controllers.GlobalDataController; import noppes.npcs.roles.JobItemGiver; +import noppes.npcs.scripted.interfaces.handler.IPlayerItemGiverData; +import noppes.npcs.scripted.interfaces.jobs.IJobItemGiver; +import noppes.npcs.scripted.roles.ScriptJobItemGiver; -public class PlayerItemGiverData{ +public class PlayerItemGiverData implements IPlayerItemGiverData { + private final PlayerData parent; private HashMap itemgivers = new HashMap(); private HashMap chained = new HashMap(); - + + public PlayerItemGiverData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { chained = NBTTags.getIntegerIntegerMap(compound.getTagList("ItemGiverChained", 10)); itemgivers = NBTTags.getIntegerLongMap(compound.getTagList("ItemGiversList", 10)); @@ -37,4 +47,29 @@ public class PlayerItemGiverData{ public void setItemIndex(JobItemGiver jobItemGiver, int i) { chained.put(jobItemGiver.itemGiverId, i); } + + public long getTime(IJobItemGiver jobItemGiver){ + return itemgivers.get(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId); + } + + public void setTime(IJobItemGiver jobItemGiver, long day) { + itemgivers.put(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId, day); + } + + public boolean hasInteractedBefore(IJobItemGiver jobItemGiver) { + return itemgivers.containsKey(((JobItemGiver) jobItemGiver.getJobInterface()).itemGiverId); + } + + public IJobItemGiver[] getItemGivers() { + ArrayList list = new ArrayList<>(); + for (JobItemGiver jobItemGiver : GlobalDataController.instance.itemGivers.values()) { + if (jobItemGiver.npc != null) { + list.add(new ScriptJobItemGiver(jobItemGiver.npc)); + } else { + list.add(new ScriptJobItemGiver(jobItemGiver)); + } + } + + return list.toArray(new IJobItemGiver[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerMail.java b/src/main/java/noppes/npcs/controllers/data/PlayerMail.java index 35677adcd..01af6d63c 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerMail.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerMail.java @@ -5,10 +5,17 @@ import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; import noppes.npcs.NoppesUtilServer; import noppes.npcs.controllers.QuestController; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail; +import noppes.npcs.scripted.interfaces.handler.data.IQuest; +import noppes.npcs.scripted.interfaces.item.IItemStack; -public class PlayerMail implements IInventory{ +import java.util.ArrayList; + +public class PlayerMail implements IInventory, IPlayerMail { public String subject = ""; public String sender = ""; public NBTTagCompound message = new NBTTagCompound(); @@ -202,4 +209,99 @@ public class PlayerMail implements IInventory{ mail.readNBT(writeNBT()); return mail; } + + public void setPageText(String[] pages) { + NBTTagList bookPages = new NBTTagList(); + for (String text : pages) { + bookPages.appendTag(new NBTTagString(text)); + } + + message.setTag("pages", bookPages); + } + + public String[] getPageText() { + NBTTagList bookPages = new NBTTagList(); + + if(message.hasKey("pages")) + bookPages = message.getTagList("pages", 8); + + if (bookPages != null) + { + bookPages = (NBTTagList)bookPages.copy(); + ArrayList pageStrings = new ArrayList<>(); + + for (int i = 0; i < bookPages.tagCount(); i++) { + pageStrings.add(bookPages.getStringTagAt(i)); + } + + return pageStrings.toArray(new String[0]); + } else { + return new String[]{""}; + } + } + + public int getPageCount() { + NBTTagList bookPages = new NBTTagList(); + + if(message.hasKey("pages")) + bookPages = message.getTagList("pages", 8); + + int bookTotalPages = 0; + if (bookPages != null) + { + bookPages = (NBTTagList)bookPages.copy(); + bookTotalPages = bookPages.tagCount(); + + if (bookTotalPages < 1) + { + bookTotalPages = 1; + } + + return bookTotalPages; + } + + return 0; + } + + public void setSender(String sender) { + this.sender = sender; + } + + public String getSender() { + return sender; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public String getSubject() { + return subject; + } + + public long getTimePast() { + return timePast; + } + + public long getTimeSent() { + return time; + } + + public IItemStack[] getItems() { + ArrayList list = new ArrayList<>(); + for (ItemStack itemStack : items) { + list.add(NpcAPI.Instance().getIItemStack(itemStack)); + } + + return list.toArray(new IItemStack[0]); + } + + public void setItems(IItemStack[] items) { + ArrayList list = new ArrayList<>(); + for (IItemStack itemStack : items) { + list.add(itemStack.getMCItemStack()); + } + + this.items = list.toArray(new ItemStack[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java b/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java index e6e9dee62..58432a98b 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerMailData.java @@ -4,10 +4,21 @@ import java.util.ArrayList; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.scripted.interfaces.handler.IPlayerMailData; +import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail; -public class PlayerMailData{ +public class PlayerMailData implements IPlayerMailData { + private final PlayerData parent; public ArrayList playermail = new ArrayList(); + public PlayerMailData() { + this.parent = null; + } + + public PlayerMailData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { ArrayList newmail = new ArrayList(); NBTTagList list = compound.getTagList("MailData", 10); @@ -39,4 +50,56 @@ public class PlayerMailData{ return true; return false; } + + public void addMail(IPlayerMail mail) { + playermail.add((PlayerMail) mail); + } + + public void removeMail(IPlayerMail mail) { + playermail.remove((PlayerMail) mail); + } + + public boolean hasMail(IPlayerMail mail) { + return playermail.contains((PlayerMail) mail); + } + + public IPlayerMail[] getAllMail() { + return playermail.toArray(new IPlayerMail[0]); + } + + public IPlayerMail[] getUnreadMail() { + ArrayList mails = new ArrayList<>(); + + for (PlayerMail mail : playermail) { + if (!mail.beenRead) { + mails.add(mail); + } + } + + return mails.toArray(new IPlayerMail[0]); + } + + public IPlayerMail[] getReadMail() { + ArrayList mails = new ArrayList<>(); + + for (PlayerMail mail : playermail) { + if (mail.beenRead) { + mails.add(mail); + } + } + + return mails.toArray(new IPlayerMail[0]); + } + + public IPlayerMail[] getMailFrom(String sender) { + ArrayList mails = new ArrayList<>(); + + for (PlayerMail mail : playermail) { + if (mail.sender.equals(sender)) { + mails.add(mail); + } + } + + return mails.toArray(new IPlayerMail[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java index d02218ef4..505241f06 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerQuestData.java @@ -1,12 +1,15 @@ package noppes.npcs.controllers.data; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import noppes.npcs.EventHooks; +import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.Server; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumQuestCompletion; @@ -15,14 +18,20 @@ import noppes.npcs.controllers.PlayerDataController; import noppes.npcs.controllers.QuestController; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.quests.QuestInterface; +import noppes.npcs.scripted.interfaces.handler.IPlayerQuestData; import noppes.npcs.scripted.interfaces.handler.data.IQuest; -public class PlayerQuestData { +public class PlayerQuestData implements IPlayerQuestData { + private final PlayerData parent; public IQuest trackedQuest = null; public HashMap activeQuests = new HashMap(); public HashMap finishedQuests = new HashMap(); - + + public PlayerQuestData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound mainCompound) { if(mainCompound == null) return; @@ -107,9 +116,10 @@ public class PlayerQuestData { for(QuestData data : this.activeQuests.values()){ if(data.quest.type != type && type != null) continue; - - QuestInterface inter = data.quest.questInterface; + NoppesUtilPlayer.sendTrackedQuestData((EntityPlayerMP) player,data.quest); + + QuestInterface inter = data.quest.questInterface; if(inter.isCompleted(playerData)){ if(!data.isCompleted){ if(!data.quest.complete(player,data)){ @@ -127,5 +137,76 @@ public class PlayerQuestData { return bo; } - + + public IQuest getTrackedQuest() { + return trackedQuest; + } + + public void startQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + if(activeQuests.containsKey(id)) + return; + QuestData questdata = new QuestData(quest); + activeQuests.put(id, questdata); + Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title); + Server.sendData((EntityPlayerMP)parent.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title); + } + + public void finishQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + finishedQuests.put(id, System.currentTimeMillis()); + } + + public void stopQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + activeQuests.remove(id); + } + + public void removeQuest(int id) { + Quest quest = QuestController.instance.quests.get(id); + if (quest == null) + return; + activeQuests.remove(id); + finishedQuests.remove(id); + } + + public boolean hasFinishedQuest(int id){ + return finishedQuests.containsKey(id); + } + + public boolean hasActiveQuest(int id){ + return activeQuests.containsKey(id); + } + + public IQuest[] getActiveQuests() { + List quests = new ArrayList<>(); + + for (int id : activeQuests.keySet()) { + IQuest quest = (IQuest) QuestController.instance.quests.get(id); + if (quest != null) { + quests.add(quest); + } + } + + return (IQuest[])quests.toArray(new IQuest[0]); + } + + public IQuest[] getFinishedQuests() { + List quests = new ArrayList<>(); + + for (int id : finishedQuests.keySet()) { + IQuest quest = (IQuest) QuestController.instance.quests.get(id); + if (quest != null) { + quests.add(quest); + } + } + + return (IQuest[])quests.toArray(new IQuest[0]); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java b/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java index 945243474..50f7b8dc8 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java @@ -1,13 +1,22 @@ package noppes.npcs.controllers.data; +import java.util.ArrayList; import java.util.HashSet; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.TransportController; +import noppes.npcs.scripted.interfaces.handler.IPlayerTransportData; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class PlayerTransportData{ +public class PlayerTransportData implements IPlayerTransportData { + private final PlayerData parent; public HashSet transports = new HashSet(); + public PlayerTransportData(PlayerData parent) { + this.parent = parent; + } + public void loadNBTData(NBTTagCompound compound) { HashSet dialogsRead = new HashSet(); if(compound == null) @@ -35,5 +44,34 @@ public class PlayerTransportData{ compound.setTag("TransportData", list); } - + + public boolean hasTransport(int id) { + return transports.contains(id); + } + + public void addTransport(int id) { + transports.add(id); + } + + public void addTransport(ITransportLocation location) { + transports.add(location.getId()); + } + + public ITransportLocation getTransport(int id) { + return TransportController.getInstance().getTransport(id); + } + + public ITransportLocation[] getTransports() { + ArrayList list = new ArrayList<>(); + for (int id : transports) { + ITransportLocation location = TransportController.getInstance().getTransport(id); + list.add(location); + } + + return list.toArray(new ITransportLocation[0]); + } + + public void removeTransport(int id) { + transports.remove(id); + } } diff --git a/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java b/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java index 750a76469..217ecedd6 100644 --- a/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java +++ b/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java @@ -10,6 +10,7 @@ public class SkinOverlay implements ISkinOverlay { public ResourceLocation location = null; public String texture; public boolean glow = true; + public boolean blend = false; public float alpha = 1.0F; public float size = 1.0F; @@ -30,21 +31,6 @@ public class SkinOverlay implements ISkinOverlay { this.texture = texture; } - public SkinOverlay(String texture, boolean glow, float alpha, float size, float speedX, float speedY, - float scaleX, float scaleY, float offsetX, float offsetY, float offsetZ) { - this.texture = texture; - this.glow = glow; - this.alpha = alpha; - this.size = size; - this.speedX = speedX; - this.speedY = speedY; - this.scaleX = scaleX; - this.scaleY = scaleY; - this.offsetX = offsetX; - this.offsetY = offsetY; - this.offsetZ = offsetZ; - } - public void setTexture(String texture) { this.texture = texture; this.updateClient(); @@ -61,6 +47,14 @@ public class SkinOverlay implements ISkinOverlay { return glow; } + public void setBlend(boolean blend) { + this.blend = blend; + this.updateClient(); + } + public boolean getBlend() { + return blend; + } + public void setAlpha(float alpha) { this.alpha = alpha; this.updateClient(); @@ -128,6 +122,7 @@ public class SkinOverlay implements ISkinOverlay { public void readFromNBT(NBTTagCompound compound) { this.texture = compound.getString("SkinOverlayTexture"); this.glow = compound.getBoolean("SkinOverlayGlow"); + this.blend = compound.getBoolean("SkinOverlayBlend"); this.alpha = compound.getFloat("SkinOverlayAlpha"); this.size = compound.getFloat("SkinOverlaySize"); this.speedX = compound.getFloat("SkinOverlaySpeedX"); @@ -142,6 +137,7 @@ public class SkinOverlay implements ISkinOverlay { public NBTTagCompound writeToNBT(NBTTagCompound compound) { compound.setString("SkinOverlayTexture", this.getTexture()); compound.setBoolean("SkinOverlayGlow", this.getGlow()); + compound.setBoolean("SkinOverlayBlend", this.getBlend()); compound.setFloat("SkinOverlayAlpha", this.getAlpha()); compound.setFloat("SkinOverlaySize", this.getSize()); compound.setFloat("SkinOverlaySpeedX", this.getSpeedX()); diff --git a/src/main/java/noppes/npcs/controllers/data/TransportCategory.java b/src/main/java/noppes/npcs/controllers/data/TransportCategory.java index fdfa21f86..99b6f3acb 100644 --- a/src/main/java/noppes/npcs/controllers/data/TransportCategory.java +++ b/src/main/java/noppes/npcs/controllers/data/TransportCategory.java @@ -1,18 +1,24 @@ package noppes.npcs.controllers.data; import java.util.HashMap; +import java.util.Map; import java.util.Vector; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.TransportController; +import noppes.npcs.scripted.interfaces.handler.data.ITransportCategory; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class TransportCategory { +public class TransportCategory implements ITransportCategory { public int id = -1; public String title = ""; public HashMap locations; + public TransportCategory(){ locations = new HashMap(); } + public Vector getDefaultLocations() { Vector list = new Vector(); for(TransportLocation loc : locations.values()) @@ -47,4 +53,53 @@ public class TransportCategory { } compound.setTag("CategoryLocations", locs); } + + public int getId() { + return id; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public void addLocation(String name) { + int id = TransportController.getInstance().getUniqueIdLocation(); + TransportLocation location = new TransportLocation(); + location.id = id; + location.name = name; + location.category = this; + + TransportController.getInstance().setLocation(location); + } + + public ITransportLocation getLocation(String name) { + TransportLocation location = null; + for (TransportLocation l : locations.values()) { + if (l.getName().equals(name)) { + location = l; + break; + } + } + + return location; + } + + public void removeLocation(String name) { + int id = -1; + for (Map.Entry entry : locations.entrySet()) { + if (entry.getValue().getName().equals(name)) { + id = entry.getKey();; + locations.remove(entry.getKey()); + break; + } + } + + if (id >= 0) { + TransportController.getInstance().removeLocation(id); + } + } } diff --git a/src/main/java/noppes/npcs/controllers/data/TransportLocation.java b/src/main/java/noppes/npcs/controllers/data/TransportLocation.java index fc1dcb620..9d3256d38 100644 --- a/src/main/java/noppes/npcs/controllers/data/TransportLocation.java +++ b/src/main/java/noppes/npcs/controllers/data/TransportLocation.java @@ -1,8 +1,10 @@ package noppes.npcs.controllers.data; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.controllers.TransportController; +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; -public class TransportLocation { +public class TransportLocation implements ITransportLocation { public int id = -1; public String name = "default name"; public double posX; @@ -41,4 +43,54 @@ public class TransportLocation { public boolean isDefault() { return type == 1; } + + public int getId() { + return id; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setDimension(int dimension) { + this.dimension = dimension; + } + + public int getDimension() { + return dimension; + } + + public void setType(int type) { + this.type = type; + } + + public int getType() { + return type; + } + + public void setPosition(int x, int y, int z) { + this.posX = x; + this.posY = y; + this.posZ = z; + } + + public double getX() { + return posX; + } + + public double getY() { + return posY; + } + + public double getZ() { + return posZ; + } + + public void save() { + TransportController.getInstance().saveLocation(this.category.id, this); + } } diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index 904b11d15..4ab7d2ce5 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -62,30 +62,18 @@ import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumPotionType; import noppes.npcs.constants.EnumRoleType; import noppes.npcs.constants.EnumStandingType; -import noppes.npcs.controllers.data.Dialog; -import noppes.npcs.controllers.data.DialogOption; -import noppes.npcs.controllers.data.Faction; +import noppes.npcs.controllers.GlobalDataController; +import noppes.npcs.controllers.data.*; import noppes.npcs.controllers.FactionController; -import noppes.npcs.controllers.data.Line; import noppes.npcs.controllers.LinkedNpcController; import noppes.npcs.controllers.LinkedNpcController.LinkedData; import noppes.npcs.controllers.PlayerDataController; -import noppes.npcs.controllers.data.PlayerQuestData; -import noppes.npcs.controllers.data.QuestData; -import noppes.npcs.controllers.data.DataTransform; import noppes.npcs.entity.data.DataTimers; -import noppes.npcs.roles.JobBard; -import noppes.npcs.roles.JobFollower; -import noppes.npcs.roles.JobInterface; -import noppes.npcs.roles.RoleCompanion; -import noppes.npcs.roles.RoleFollower; -import noppes.npcs.roles.RoleInterface; +import noppes.npcs.roles.*; import noppes.npcs.scripted.entity.ScriptNpc; -import noppes.npcs.scripted.event.ScriptEventAttack; -import noppes.npcs.scripted.event.ScriptEventDamaged; -import noppes.npcs.scripted.event.ScriptEventKilled; -import noppes.npcs.scripted.event.ScriptEventTarget; +import noppes.npcs.scripted.event.*; import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.util.GameProfileAlt; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; @@ -119,6 +107,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public long totalTicksAlive = 0; private int taskCount = 1; public int lastInteract = 0; + public int itemGiverId = 0; public Faction faction; //should only be used server side @@ -217,10 +206,12 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti @Override public void onUpdate(){ super.onUpdate(); - if(this.ticksExisted % 10 == 0) { - EventHooks.onNPCUpdate(this); + if (!isRemote()) { + if (this.ticksExisted % 10 == 0) { + EventHooks.onNPCUpdate(this); + } + this.timers.update(); } - this.timers.update(); } public void setWorld(World world){ @@ -240,9 +231,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if (stats.attackSpeed < 10){ par1Entity.hurtResistantTime = 0; } - if(par1Entity instanceof EntityLivingBase){ - ScriptEventAttack event = new ScriptEventAttack(f, (EntityLivingBase)par1Entity, false); - if(EventHooks.onNPCMeleeAttack(this, f, (EntityLivingBase)par1Entity)) + if(par1Entity instanceof EntityLivingBase && !isRemote()){ + NpcEvent.MeleeAttackEvent event = new NpcEvent.MeleeAttackEvent(wrappedNPC, f, (EntityLivingBase)par1Entity); + if(EventHooks.onNPCMeleeAttack(this, event)) return false; f = event.getDamage(); } @@ -499,10 +490,10 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti } else if (attackingEntity instanceof EntityPlayer && faction.isFriendlyToPlayer((EntityPlayer) attackingEntity)) return false; - ScriptEventDamaged result = new ScriptEventDamaged(i, attackingEntity, damagesource); - if(EventHooks.onNPCDamaged(this, attackingEntity, i, damagesource, result) || isKilled()) + NpcEvent.DamagedEvent event = new NpcEvent.DamagedEvent(this.wrappedNPC, attackingEntity, i, damagesource); + if(EventHooks.onNPCDamaged(this, event) || isKilled()) return false; - i = result.getDamage(); + i = event.getDamage(); if(isKilled()) return false; @@ -532,7 +523,7 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti return super.attackEntityFrom(damagesource, i); } finally{ - if(result.getClearTarget()){ + if(event.getClearTarget()){ setAttackTarget(null); setRevengeTarget(null); } @@ -548,20 +539,22 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti public void setAttackTarget(EntityLivingBase entity){ if(entity instanceof EntityPlayer && ((EntityPlayer)entity).capabilities.disableDamage || entity != null && entity == getOwner()) return; - if(getAttackTarget() != entity && entity != null){ - ScriptEventTarget event = new ScriptEventTarget(entity); - if(EventHooks.onNPCTarget(this,entity)) - return; - - if(event.getTarget() == null) - entity = null; - else - entity = event.getTarget().getMCEntity(); - } - if (entity != null && entity != this && ai.onAttack != 3 && !isAttacking() && !isRemote()){ - Line line = advanced.getAttackLine(); - if(line != null) - saySurrounding(line.formatTarget(entity)); + if (!isRemote()) { + if (getAttackTarget() != entity && entity != null) { + NpcEvent.TargetEvent event = new NpcEvent.TargetEvent(wrappedNPC,entity); + if (EventHooks.onNPCTarget(this, event)) + return; + + if (event.getTarget() == null) + entity = null; + else + entity = event.getTarget().getMCEntity(); + } + if (entity != null && entity != this && ai.onAttack != 3 && !isAttacking()) { + Line line = advanced.getAttackLine(); + if (line != null) + saySurrounding(line.formatTarget(entity)); + } } super.setAttackTarget(entity); @@ -574,16 +567,16 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti updateTasks(); return; } - ScriptEventAttack event = new ScriptEventAttack(stats.pDamage, entity, true); - if(EventHooks.onNPCRangedAttack(this, f, (EntityLivingBase)entity)) - return; - for(int i = 0; i < this.stats.shotCount; i++) - { - EntityProjectile projectile = shoot(entity, stats.accuracy, proj, f == 1); - projectile.damage = event.getDamage(); + if (!isRemote()) { + NpcEvent.RangedLaunchedEvent event = new NpcEvent.RangedLaunchedEvent(wrappedNPC,stats.pDamage,entity); + if (EventHooks.onNPCRangedAttack(this, event)) + return; + for (int i = 0; i < this.stats.shotCount; i++) { + EntityProjectile projectile = shoot(entity, stats.accuracy, proj, f == 1); + projectile.damage = event.getDamage(); + } + this.playSound(this.stats.fireSound, 2.0F, 1.0f); } - this.playSound(this.stats.fireSound, 2.0F, 1.0f); - } public EntityProjectile shoot(EntityLivingBase entity, int accuracy, ItemStack proj, boolean indirect){ @@ -940,6 +933,11 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti ai.readToNBT(compound); script.readFromNBT(compound); timers.readFromNBT(compound); + if (compound.hasKey("ItemGiverId")) { + itemGiverId = compound.getInteger("ItemGiverId"); + } else { + itemGiverId = -1; + } advanced.readToNBT(compound); if (advanced.role != EnumRoleType.None && roleInterface != null) roleInterface.readFromNBT(compound); @@ -1058,7 +1056,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if(jobInterface != null) jobInterface.reset(); - EventHooks.onNPCInit(this); + if (!isRemote()) { + EventHooks.onNPCInit(this); + } } public void onCollide() { @@ -1078,12 +1078,14 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti if(list == null) return; - for (int i = 0; i < list.size(); ++i){ - Entity entity = (Entity)list.get(i); - if (entity.isEntityAlive()) { - EventHooks.onNPCCollide(this,entity); + if (!isRemote()) { + for (int i = 0; i < list.size(); ++i) { + Entity entity = (Entity) list.get(i); + if (entity.isEntityAlive()) { + EventHooks.onNPCCollide(this, entity); + } } - } + } } @@ -1208,12 +1210,25 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti else if ((entity instanceof EntityThrowable)) attackingEntity = ((EntityThrowable) entity).getThrower(); - ScriptEventKilled result = new ScriptEventKilled(attackingEntity, damagesource); - if(EventHooks.onNPCKilled(this,damagesource,attackingEntity,result)) - return; + + int droppedXp = inventory.getDroppedXp(); + ArrayList droppedItems = inventory.getDroppedItems(damagesource); + if(!isRemote()){ - if(this.recentlyHit > 0) - inventory.dropStuff(entity, damagesource); + NpcEvent.DiedEvent event = new NpcEvent.DiedEvent(this.wrappedNPC,damagesource,entity,droppedItems, droppedXp); + if(EventHooks.onNPCKilled(this, event)) + return; + + droppedItems.clear(); + for (IItemStack iItemStack : event.droppedItems) { + droppedItems.add(iItemStack.getMCItemStack()); + } + droppedXp = event.expDropped; + + if(this.recentlyHit > 0) { + inventory.dropItems(entity, droppedItems); + inventory.dropXp(entity, droppedXp); + } Line line = advanced.getKilledLine(); if(line != null) saySurrounding(line.formatTarget(attackingEntity)); diff --git a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java index 62c4c224c..bfc85d14d 100644 --- a/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java +++ b/src/main/java/noppes/npcs/entity/old/EntityNPCEnderman.java @@ -19,10 +19,7 @@ public class EntityNPCEnderman extends EntityNpcEnderchibi super(world); display.texture = "customnpcs:textures/entity/enderman/enderman.png"; //display.glowTexture = ; - display.skinOverlayData.overlayList.put(0,new SkinOverlay( - "customnpcs:textures/overlays/ender_eyes.png", true, 1.0F, 1.0F, 0.0F, 0.0F, - 1.0F, 1.0F, 0.0F, 0.0F, 0.0F - )); + display.skinOverlayData.overlayList.put(0,new SkinOverlay("customnpcs:textures/overlays/ender_eyes.png")); this.width = 0.6F; this.height = 2.9F; } diff --git a/src/main/java/noppes/npcs/roles/JobItemGiver.java b/src/main/java/noppes/npcs/roles/JobItemGiver.java index 80c3319fb..6a696f3ca 100644 --- a/src/main/java/noppes/npcs/roles/JobItemGiver.java +++ b/src/main/java/noppes/npcs/roles/JobItemGiver.java @@ -35,6 +35,11 @@ public class JobItemGiver extends JobInterface{ private List toCheck; public Availability availability = new Availability(); + public JobItemGiver() { + super(null); + inventory = new NpcMiscInventory(9); + } + public JobItemGiver(EntityNPCInterface npc) { super(npc); inventory = new NpcMiscInventory(9); @@ -61,10 +66,6 @@ public class JobItemGiver extends JobInterface{ cooldown = nbttagcompound.getInteger("igCooldown"); lines = NBTTags.getStringList(nbttagcompound.getTagList("igLines", 10)); inventory.setFromNBT(nbttagcompound.getCompoundTag("igJobInventory")); - - if(itemGiverId == 0 && GlobalDataController.instance != null) - itemGiverId = GlobalDataController.instance.incrementItemGiverId(); - availability.readFromNBT(nbttagcompound.getCompoundTag("igAvailability")); } @@ -92,7 +93,7 @@ public class JobItemGiver extends JobInterface{ return map; } - private boolean giveItems(EntityPlayer player){ + public boolean giveItems(EntityPlayer player){ PlayerItemGiverData data = PlayerDataController.instance.getPlayerData(player).itemgiverData; if(!canPlayerInteract(data)){ return false; @@ -162,7 +163,7 @@ public class JobItemGiver extends JobInterface{ private int getDay(){ return (int) (npc.worldObj.getTotalWorldTime() / 24000L); } - private boolean canPlayerInteract(PlayerItemGiverData data) { + public boolean canPlayerInteract(PlayerItemGiverData data) { if(inventory.items.isEmpty()) return false; if(isOnTimer()){ diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 877dd19a0..d83a615e6 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -6,6 +6,7 @@ package noppes.npcs.scripted; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -66,6 +67,10 @@ public class NpcAPI extends AbstractNpcAPI { worldCache.clear(); } + public void stopServer() { + CustomNpcs.getServer().stopServer(); + } + public IFactionHandler getFactions() { this.checkWorld(); return FactionController.getInstance(); @@ -89,6 +94,10 @@ public class NpcAPI extends AbstractNpcAPI { return ServerCloneController.Instance; } + public ITransportHandler getLocations() { + return TransportController.getInstance(); + } + public IEntity getIEntity(Entity entity) { if(entity == null) return null; @@ -117,6 +126,18 @@ public class NpcAPI extends AbstractNpcAPI { } } + public IEntity[] getLoadedEntities() { + ArrayList list = new ArrayList<>(); + + for (IWorld world : worldCache.values()) { + for (Object obj : world.getMCWorld().loadedEntityList) { + list.add(NpcAPI.Instance().getIEntity((Entity) obj)); + } + } + + return list.toArray(new IEntity[0]); + } + public IBlock getIBlock(World world, BlockPos pos) { return new ScriptBlock(world, world.getBlock(pos.getX(),pos.getY(),pos.getZ()), pos); } @@ -203,13 +224,13 @@ public class NpcAPI extends AbstractNpcAPI { return getIItemStack(new ItemStack(item, size, damage)); } - public IWorld getIWorld(WorldServer world) { - ScriptWorld w = (ScriptWorld)worldCache.get(world.provider.dimensionId); + public IWorld getIWorld(World world) { + ScriptWorld w = worldCache.get(world.provider.dimensionId); if (w != null) { - w.world = world; + w.world.provider.dimensionId = world.provider.dimensionId; return w; } else { - worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world)); + worldCache.put(world.provider.dimensionId, w = ScriptWorld.createNew(world.provider.dimensionId)); return w; } } diff --git a/src/main/java/noppes/npcs/scripted/ScriptWorld.java b/src/main/java/noppes/npcs/scripted/ScriptWorld.java index 9c01455ee..e377e486a 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptWorld.java +++ b/src/main/java/noppes/npcs/scripted/ScriptWorld.java @@ -1,9 +1,6 @@ package noppes.npcs.scripted; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -21,6 +18,7 @@ import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.Vec3; import net.minecraft.util.math.BlockPos; import net.minecraft.world.WorldServer; +import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; import noppes.npcs.blocks.tiles.TileBigSign; import noppes.npcs.controllers.ScriptController; @@ -41,7 +39,15 @@ public class ScriptWorld implements IWorld { this.world = world; } - public static ScriptWorld createNew(WorldServer world) { + public static ScriptWorld createNew(int dimensionId) { + WorldServer[] worlds = CustomNpcs.getServer().worldServers; + + WorldServer world = worlds[0]; + for (WorldServer w : worlds) { + if (w.provider.dimensionId == dimensionId) { + world = w; + } + } return new ScriptWorld(world); } @@ -172,6 +178,15 @@ public class ScriptWorld implements IWorld { return world.countEntities(entity.getMCEntity().getClass()); } + public IEntity[] getLoadedEntities() { + ArrayList list = new ArrayList<>(); + for (Object obj : world.loadedEntityList) { + list.add(NpcAPI.Instance().getIEntity((Entity) obj)); + } + + return list.toArray(new IEntity[0]); + } + public void setTileEntity(int x, int y, int z, ITileEntity tileEntity){ world.setTileEntity(x,y,z,tileEntity.getMCTileEntity()); } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java index 4bdbe7951..72e94f68c 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptEntity.java @@ -29,6 +29,7 @@ import noppes.npcs.scripted.ScriptBlockPos; import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.interfaces.IParticle; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.entity.IEntity; import noppes.npcs.scripted.interfaces.INbt; import noppes.npcs.scripted.interfaces.IPos; @@ -755,7 +756,7 @@ public class ScriptEntity implements IEntity { } } - public ScriptWorld getWorld() { - return (ScriptWorld) NpcAPI.Instance().getIWorld((WorldServer) entity.worldObj); + public IWorld getWorld() { + return NpcAPI.Instance().getIWorld(entity.worldObj); } } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index b812d8e70..d723f4bfb 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -44,6 +44,7 @@ import noppes.npcs.scripted.ScriptPixelmonPlayerData; import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.interfaces.IParticle; +import noppes.npcs.scripted.interfaces.handler.IPlayerData; import noppes.npcs.scripted.interfaces.handler.data.IQuest; import noppes.npcs.scripted.interfaces.IBlock; import noppes.npcs.scripted.interfaces.IContainer; @@ -557,7 +558,7 @@ public class ScriptPlayer extends ScriptLivingBase return player.isBlocking(); } - private PlayerData getData() { + public PlayerData getData() { if (this.data == null) { this.data = PlayerDataController.instance.getPlayerData(player); } @@ -566,7 +567,7 @@ public class ScriptPlayer extends ScriptLivingBase } public IQuest[] getActiveQuests() { - PlayerQuestData data = this.getData().questData; + PlayerQuestData data = (PlayerQuestData) this.getData().getQuestData(); List quests = new ArrayList(); Iterator var3 = data.activeQuests.keySet().iterator(); diff --git a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java index e1a5c69f0..c0320096e 100644 --- a/src/main/java/noppes/npcs/scripted/event/NpcEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/NpcEvent.java @@ -9,6 +9,7 @@ import cpw.mods.fml.common.eventhandler.Cancelable; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import noppes.npcs.controllers.data.Dialog; import noppes.npcs.scripted.interfaces.*; @@ -19,6 +20,8 @@ import noppes.npcs.scripted.interfaces.entity.IPlayer; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.NpcAPI; +import java.util.ArrayList; + public class NpcEvent extends CustomNPCsEvent { public final ICustomNpc npc; @@ -33,6 +36,10 @@ public class NpcEvent extends CustomNPCsEvent { super(npc); this.id = id; } + + public int getId(){ + return id; + } } public static class CollideEvent extends NpcEvent { @@ -49,13 +56,49 @@ public class NpcEvent extends CustomNPCsEvent { public final IDamageSource damageSource; public final IEntity source; public float damage; - public boolean clearTarget = false; + private boolean clearTarget = false; + + public boolean clear = false; + public final DamageSource damagesource; public DamagedEvent(ICustomNpc npc, Entity source, float damage, DamageSource damagesource) { super(npc); this.source = NpcAPI.Instance().getIEntity(source); this.damage = damage; this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); + + //Old CNPC Script compatibility + this.damagesource = damagesource; + } + + /** + * @return The source of the damage + */ + public IEntity getSource(){ + return source; + } + + /** + * @return Returns the damage value + */ + public float getDamage(){ + return damage; + } + + /** + * @param damage The new damage value + */ + public void setDamage(float damage){ + this.damage = damage; + } + + public void setClearTarget(boolean bo){ + this.clearTarget = bo; + this.clear = bo; + } + + public boolean getClearTarget(){ + return clearTarget && clear; } public String getType(){ @@ -73,6 +116,36 @@ public class NpcEvent extends CustomNPCsEvent { this.target = (IEntityLivingBase)NpcAPI.Instance().getIEntity(target); this.damage = damage; } + + /** + * @return The source of the damage + * @deprecated + */ + public IEntityLivingBase getTarget(){ + return target; + } + + + /** + * @return Returns the damage value + */ + public float getDamage(){ + return damage; + } + + /** + * @param damage The new damage value + */ + public void setDamage(float damage){ + this.damage = damage; + } + + /** + * @return Returns the damage type + */ + public boolean isRange(){ + return true; + } } @Cancelable @@ -85,6 +158,36 @@ public class NpcEvent extends CustomNPCsEvent { this.target = (IEntityLivingBase)NpcAPI.Instance().getIEntity(target); this.damage = damage; } + + /** + * @return The source of the damage + * @deprecated + */ + public IEntityLivingBase getTarget(){ + return target; + } + + + /** + * @return Returns the damage value + */ + public float getDamage(){ + return damage; + } + + /** + * @param damage The new damage value + */ + public void setDamage(float damage){ + this.damage = damage; + } + + /** + * @return Returns the damage type + */ + public boolean isRange(){ + return false; + } } public static class KilledEntityEvent extends NpcEvent { @@ -103,13 +206,33 @@ public class NpcEvent extends CustomNPCsEvent { public IItemStack[] droppedItems; public int expDropped; - public DiedEvent(ICustomNpc npc, DamageSource damagesource, Entity entity) { + public DiedEvent(ICustomNpc npc, DamageSource damagesource, Entity entity, ArrayList droppedItems, int expDropped) { super(npc); this.damageSource = NpcAPI.Instance().getIDamageSource(damagesource); this.type = damagesource.damageType; this.source = NpcAPI.Instance().getIEntity(entity); + + ArrayList iItemStacks = new ArrayList<>(); + for (ItemStack itemStack : droppedItems) { + IItemStack iItemStack = NpcAPI.Instance().getIItemStack(itemStack); + iItemStacks.add(iItemStack); + } + this.droppedItems = iItemStacks.toArray(new IItemStack[0]); + this.expDropped = expDropped; } + /** + * @return The source of the damage + */ + public IEntity getSource(){ + return source; + } + + public IDamageSource getDamageSource() { return damageSource; } + + /** + * @return Returns the damage type + */ public String getType(){ return damageSource.getMCDamageSource().damageType; } @@ -129,14 +252,43 @@ public class NpcEvent extends CustomNPCsEvent { public final IPlayer player; public final int id; public final int optionId; - public final Dialog dialog; + public final Dialog dialogObj; + + public final int dialog; + public final int option; public DialogEvent(ICustomNpc npc, EntityPlayer player, int id, int optionId, Dialog dialog) { super(npc); this.player = (IPlayer)NpcAPI.Instance().getIEntity(player); this.id = id; this.optionId = optionId; - this.dialog = dialog; + this.dialogObj = dialog; + + this.dialog = id; + this.option = optionId; + } + + public IPlayer getPlayer() { + return player; + } + + public Dialog getDialog() { + return dialogObj; + } + + public int getDialogId() { + return dialog; + } + + public int getOptionId() { + return option; + } + + /** + * @deprecated + */ + public boolean isClosing(){ + return true; } } @@ -144,14 +296,43 @@ public class NpcEvent extends CustomNPCsEvent { public final IPlayer player; public final int id; public final int optionId; - public final Dialog dialog; + public final Dialog dialogObj; + + public final int dialog; + public final int option; public DialogClosedEvent(ICustomNpc npc, EntityPlayer player, int id, int optionId, Dialog dialog) { super(npc); this.player = (IPlayer)NpcAPI.Instance().getIEntity(player); this.id = id; this.optionId = optionId; - this.dialog = dialog; + this.dialogObj = dialog; + + this.dialog = id; + this.option = optionId; + } + + public IPlayer getPlayer() { + return player; + } + + public Dialog getDialog() { + return dialogObj; + } + + public int getDialogId() { + return option; + } + + public int getOptionId() { + return option; + } + + /** + * @deprecated + */ + public boolean isClosing(){ + return true; } } @@ -173,6 +354,17 @@ public class NpcEvent extends CustomNPCsEvent { super(npc); this.entity = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity); } + + /** + * @return The target source + */ + public IEntityLivingBase getTarget(){ + return entity; + } + + public void setTarget(IEntityLivingBase entity){ + this.entity = entity; + } } public static class UpdateEvent extends NpcEvent { diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java b/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java deleted file mode 100644 index 12a951ca2..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEvent.java +++ /dev/null @@ -1,22 +0,0 @@ -package noppes.npcs.scripted.event; - -public -class ScriptEvent{ - private boolean isCancelled = false; - - public void setCancelled(boolean bo){ - isCancelled = bo; - } - - public boolean isCancelled(){ - return isCancelled; - } - - public void setCanceled(boolean bo){ - isCancelled = bo; - } - - public boolean isCanceled(){ - return isCancelled; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java deleted file mode 100644 index 0b8403c3f..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventAttack.java +++ /dev/null @@ -1,48 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventAttack extends ScriptEvent{ - - private float damage; - private IEntityLivingBase target; - private boolean isRanged; - - public ScriptEventAttack(float damage, EntityLivingBase target, boolean isRanged){ - this.damage = damage; - this.isRanged = isRanged; - this.target = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); - } - - /** - * @return The source of the damage - * @deprecated - */ - public IEntityLivingBase getTarget(){ - return target; - } - - - /** - * @return Returns the damage value - */ - public float getDamage(){ - return damage; - } - - /** - * @param damage The new damage value - */ - public void setDamage(float damage){ - this.damage = damage; - } - - /** - * @return Returns the damage type - */ - public boolean isRange(){ - return isRanged; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java deleted file mode 100644 index f4511a400..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventDamaged.java +++ /dev/null @@ -1,56 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventDamaged extends ScriptEvent{ - - private float damage; - private boolean clear = false; - private IEntityLivingBase source; - private DamageSource damagesource; - - public ScriptEventDamaged(float damage, EntityLivingBase attackingEntity, DamageSource damagesource){ - this.damage = damage; - this.damagesource = damagesource; - this.source = (IEntityLivingBase) NpcAPI.Instance().getIEntity(attackingEntity); - } - - /** - * @return The source of the damage - */ - public IEntityLivingBase getSource(){ - return source; - } - - public void setClearTarget(boolean bo){ - this.clear = bo; - } - - public boolean getClearTarget(){ - return clear; - } - - /** - * @return Returns the damage value - */ - public float getDamage(){ - return damage; - } - - /** - * @param damage The new damage value - */ - public void setDamage(float damage){ - this.damage = damage; - } - - /** - * @return Returns the damage type - */ - public String getType(){ - return damagesource.damageType; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java deleted file mode 100644 index f546ce429..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventDialog.java +++ /dev/null @@ -1,43 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.player.EntityPlayer; -import noppes.npcs.controllers.data.Dialog; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IPlayer; - -public class ScriptEventDialog extends ScriptEvent{ - public IPlayer player; - public int dialog; - public int option; - public Dialog dialogObj; - - public ScriptEventDialog(EntityPlayer player, int dialog, int option, Dialog dialogObj){ - this.player = (IPlayer) NpcAPI.Instance().getIEntity(player); - this.dialog = dialog; - this.option = option; - this.dialogObj = dialogObj; - } - - public IPlayer getPlayer() { - return player; - } - - public Dialog getDialog() { - return dialogObj; - } - - public int getDialogId() { - return dialog; - } - - public int getOptionId() { - return option; - } - - /** - * @deprecated - */ - public boolean isClosing(){ - return true; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java deleted file mode 100644 index 8362598a7..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventKilled.java +++ /dev/null @@ -1,33 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.IDamageSource; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventKilled extends ScriptEvent{ - private IEntityLivingBase source; - private DamageSource damagesource; - - public ScriptEventKilled(EntityLivingBase target, DamageSource damagesource){ - this.damagesource = damagesource; - this.source = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); - } - - /** - * @return The source of the damage - */ - public IEntityLivingBase getSource(){ - return source; - } - - public IDamageSource getDamageSource() { return NpcAPI.Instance().getIDamageSource(damagesource); } - - /** - * @return Returns the damage type - */ - public String getType(){ - return damagesource.damageType; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java deleted file mode 100644 index 10d2effc1..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventTarget.java +++ /dev/null @@ -1,26 +0,0 @@ -package noppes.npcs.scripted.event; - -import net.minecraft.entity.EntityLivingBase; -import noppes.npcs.scripted.NpcAPI; -import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; - -public class ScriptEventTarget extends ScriptEvent { - - private IEntityLivingBase target; - - public ScriptEventTarget(EntityLivingBase target){ - if(target != null) - this.target = (IEntityLivingBase) NpcAPI.Instance().getIEntity(target); - } - - /** - * @return The source of the damage - */ - public IEntityLivingBase getTarget(){ - return target; - } - - public void setTarget(IEntityLivingBase target){ - this.target = target; - } -} diff --git a/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java b/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java deleted file mode 100644 index 0fdc3584b..000000000 --- a/src/main/java/noppes/npcs/scripted/event/ScriptEventTimer.java +++ /dev/null @@ -1,13 +0,0 @@ -package noppes.npcs.scripted.event; - -public class ScriptEventTimer extends ScriptEvent { - private int id; - - public ScriptEventTimer(int id){ - this.id = id; - } - - public int getId(){ - return id; - } -} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java index 939341e73..b6aa3afcd 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/AbstractNpcAPI.java @@ -43,6 +43,8 @@ public abstract class AbstractNpcAPI { public AbstractNpcAPI() { } + public abstract void stopServer(); + public abstract IFactionHandler getFactions(); public abstract IRecipeHandler getRecipes(); @@ -53,6 +55,8 @@ public abstract class AbstractNpcAPI { public abstract ICloneHandler getClones(); + public abstract ITransportHandler getLocations(); + public abstract ICustomNpc createNPC(World var1); /** @@ -63,6 +67,8 @@ public abstract class AbstractNpcAPI { public abstract IEntity getIEntity(Entity var1); + public abstract IEntity[] getLoadedEntities(); + public abstract IBlock getIBlock(World var1, BlockPos var2); public abstract IBlock getIBlock(World world, Block block, BlockPos pos); @@ -75,7 +81,7 @@ public abstract class AbstractNpcAPI { public abstract IItemStack getIItemStack(ItemStack var1); - public abstract IWorld getIWorld(WorldServer var1); + public abstract IWorld getIWorld(World var1); public abstract IWorld getIWorld(int var1); @@ -83,6 +89,8 @@ public abstract class AbstractNpcAPI { public abstract IDamageSource getIDamageSource(DamageSource var1); + public abstract IDamageSource getIDamageSource(IEntity entity); + public abstract EventBus events(); public abstract File getGlobalDir(); @@ -135,6 +143,8 @@ public abstract class AbstractNpcAPI { public abstract INbt getINbt(NBTTagCompound nbtTagCompound); + public abstract INbt stringToNbt(String str); + public abstract IPlayer[] getAllServerPlayers(); public abstract IItemStack createItem(String id, int damage, int size); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java b/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java index 637c52a7b..4bf83f0d8 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ISkinOverlay.java @@ -21,6 +21,12 @@ public interface ISkinOverlay { void setGlow(boolean glow); boolean getGlow(); + /** + * Sets whether this overlay blends on top of bottom textures at any alpha value. + */ + void setBlend(boolean blend); + boolean getBlend(); + /** * Sets the transparency of the overlay, from 0 to 1. */ diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java index 78585deca..275d51e0f 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/IWorld.java @@ -98,6 +98,8 @@ public interface IWorld { */ int countEntities(IEntity entity); + IEntity[] getLoadedEntities(); + /** * Sets the block's tile entity at the given position. */ diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java index 0c266d515..2d35aaf9c 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IEntity.java @@ -10,6 +10,7 @@ import noppes.npcs.scripted.ScriptWorld; import noppes.npcs.scripted.interfaces.INbt; import noppes.npcs.scripted.interfaces.IParticle; import noppes.npcs.scripted.interfaces.IPos; +import noppes.npcs.scripted.interfaces.IWorld; import noppes.npcs.scripted.interfaces.item.IItemStack; public interface IEntity { @@ -342,5 +343,5 @@ public interface IEntity { void storeAsClone(int tab, String name); - ScriptWorld getWorld(); + IWorld getWorld(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java index 2dbd2c72b..e6cb61dd3 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/entity/IPlayer.java @@ -5,6 +5,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.util.EnumChatFormatting; import noppes.npcs.scripted.entity.ScriptDBCPlayer; import noppes.npcs.scripted.interfaces.handler.IOverlayHandler; +import noppes.npcs.scripted.interfaces.handler.IPlayerData; import noppes.npcs.scripted.interfaces.handler.data.IQuest; import noppes.npcs.scripted.interfaces.*; import noppes.npcs.scripted.interfaces.gui.ICustomGui; @@ -228,6 +229,8 @@ public interface IPlayer extends IEntityLivingBase boolean blocking(); + public IPlayerData getData(); + IQuest[] getActiveQuests(); IContainer getOpenContainer(); diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerBankData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerBankData.java new file mode 100644 index 000000000..5303af7c3 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerBankData.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.interfaces.handler; + +public interface IPlayerBankData { +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerData.java new file mode 100644 index 000000000..2a0a2b048 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerData.java @@ -0,0 +1,29 @@ +package noppes.npcs.scripted.interfaces.handler; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; + +public interface IPlayerData { + + void setCompanion(ICustomNpc npc); + + ICustomNpc getCompanion(); + + boolean hasCompanion(); + + int getCompanionID(); + + IPlayerDialogData getDialogData(); + + IPlayerBankData getBankData(); + + IPlayerQuestData getQuestData(); + + IPlayerTransportData getTransportData(); + + IPlayerFactionData getFactionData(); + + IPlayerItemGiverData getItemGiverData(); + + IPlayerMailData getMailData(); + + void save(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerDialogData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerDialogData.java new file mode 100644 index 000000000..b816dd68b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerDialogData.java @@ -0,0 +1,10 @@ +package noppes.npcs.scripted.interfaces.handler; + +public interface IPlayerDialogData { + + boolean hasReadDialog(int id); + + void readDialog(int id); + + void unreadDialog(int id); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerFactionData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerFactionData.java new file mode 100644 index 000000000..f6eba6b97 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerFactionData.java @@ -0,0 +1,10 @@ +package noppes.npcs.scripted.interfaces.handler; + +public interface IPlayerFactionData { + + int getPoints(int id); + + void addPoints(int id, int points); + + void setPoints(int id, int points); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerItemGiverData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerItemGiverData.java new file mode 100644 index 000000000..dd319ae82 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerItemGiverData.java @@ -0,0 +1,14 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.jobs.IJobItemGiver; + +public interface IPlayerItemGiverData { + + long getTime(IJobItemGiver jobItemGiver); + + void setTime(IJobItemGiver jobItemGiver, long day); + + boolean hasInteractedBefore(IJobItemGiver jobItemGiver); + + IJobItemGiver[] getItemGivers(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerMailData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerMailData.java new file mode 100644 index 000000000..aff72aa04 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerMailData.java @@ -0,0 +1,22 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.IPlayerMail; + +public interface IPlayerMailData { + + boolean hasMail(); + + void addMail(IPlayerMail mail); + + void removeMail(IPlayerMail mail); + + boolean hasMail(IPlayerMail mail); + + IPlayerMail[] getAllMail(); + + IPlayerMail[] getUnreadMail(); + + IPlayerMail[] getReadMail(); + + IPlayerMail[] getMailFrom(String sender); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerQuestData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerQuestData.java new file mode 100644 index 000000000..ce3bc3f04 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerQuestData.java @@ -0,0 +1,24 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.IQuest; + +public interface IPlayerQuestData { + + IQuest getTrackedQuest(); + + void startQuest(int id); + + void finishQuest(int id); + + void stopQuest(int id); + + void removeQuest(int id); + + boolean hasFinishedQuest(int id); + + public boolean hasActiveQuest(int id); + + IQuest[] getActiveQuests(); + + IQuest[] getFinishedQuests(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerTransportData.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerTransportData.java new file mode 100644 index 000000000..86e529758 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/IPlayerTransportData.java @@ -0,0 +1,18 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.ITransportLocation; + +public interface IPlayerTransportData { + + boolean hasTransport(int id); + + void addTransport(int id); + + void addTransport(ITransportLocation location); + + ITransportLocation getTransport(int id); + + ITransportLocation[] getTransports(); + + void removeTransport(int id); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/ITransportHandler.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/ITransportHandler.java new file mode 100644 index 000000000..cb16d0967 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/ITransportHandler.java @@ -0,0 +1,14 @@ +package noppes.npcs.scripted.interfaces.handler; + +import noppes.npcs.scripted.interfaces.handler.data.ITransportCategory; + +public interface ITransportHandler { + + ITransportCategory[] categories(); + + void createCategory(String title); + + ITransportCategory getCategory(String title); + + void removeCategory(String title); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java index e7e5bb6cc..21f8cf9e5 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialog.java @@ -4,7 +4,6 @@ // package noppes.npcs.scripted.interfaces.handler.data; - import java.util.List; public interface IDialog { @@ -50,4 +49,90 @@ public interface IDialog { String getSound(); void save(); + + void setColor(int color); + + int getColor(); + + void setTitleColor(int titleColor); + + int getTitleColor(); + + void renderGradual(boolean gradual); + + boolean renderGradual(); + + void showPreviousBlocks(boolean show); + + boolean showPreviousBlocks(); + + void showOptionLine(boolean show); + + boolean showOptionLine(); + + void setTextSound(String textSound); + + String getTextSound(); + + void setTextPitch(float textPitch); + + float getTextPitch(); + + void setTitlePos(int pos); + + int getTitlePos(); + + void setNPCScale(float scale); + + float getNpcScale(); + + void setNpcOffset(int offsetX, int offsetY); + + int getNpcOffsetX(); + + int getNpcOffsetY(); + + void textWidthHeight(int textWidth, int textHeight); + + int getTextWidth(); + + int setTextHeight(); + + void setTextOffset(int offsetX, int offsetY); + + int getTextOffsetX(); + + int getTextOffsetY(); + + void setTitleOffset(int offsetX, int offsetY); + + int getTitleOffsetX(); + + int getTitleOffsetY(); + + void setOptionOffset(int offsetX, int offsetY); + + int getOptionOffsetX(); + + int getOptionOffsetY(); + + void setOptionSpacing(int spaceX, int spaceY); + + int getOptionSpaceX(); + + int getOptionSpaceY(); + + void addImage(int id, IDialogImage image); + + IDialogImage getImage(int id); + + IDialogImage createImage(); + + IDialogImage[] getImages(); + + boolean hasImage(int id); + + void removeImage(int id); + + void clearImages(); } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialogImage.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialogImage.java new file mode 100644 index 000000000..af6bdb1bb --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IDialogImage.java @@ -0,0 +1,41 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +public interface IDialogImage { + int getId(); + + void setTexture(String texture); + String getTexture(); + + void setPosition(int x, int y); + int getX(); + int getY(); + + void setWidthHeight(int width, int height); + int getWidth(); + int getHeight(); + + void setTextureOffset(int offsetX, int offsetY); + int getTextureX(); + int getTextureY(); + + void setColor(int color); + int getColor(); + + void setSelectedColor(int color); + int getSelectedColor(); + + void setScale(float scale); + float getScale(); + + void setAlpha(float alpha); + float getAlpha(); + + void setRotation(float rotation); + float getRotation(); + + void setImageType(int imageType); + int getImageType(); + + void setAlignment(int alignment); + int getAlignment(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IPlayerMail.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IPlayerMail.java new file mode 100644 index 000000000..4ade6a2e6 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/IPlayerMail.java @@ -0,0 +1,32 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +import noppes.npcs.scripted.interfaces.item.IItemStack; + +public interface IPlayerMail { + + void setPageText(String[] pages); + + String[] getPageText(); + + int getPageCount(); + + void setSender(String sender); + + String getSender(); + + void setSubject(String subject); + + String getSubject(); + + long getTimePast(); + + long getTimeSent(); + + boolean hasQuest(); + + IQuest getQuest(); + + IItemStack[] getItems(); + + void setItems(IItemStack[] items); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportCategory.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportCategory.java new file mode 100644 index 000000000..be97d683d --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportCategory.java @@ -0,0 +1,16 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +public interface ITransportCategory { + + int getId(); + + void setTitle(String title); + + String getTitle(); + + void addLocation(String name); + + ITransportLocation getLocation(String name); + + void removeLocation(String name); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java new file mode 100644 index 000000000..6978ae0b9 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/handler/data/ITransportLocation.java @@ -0,0 +1,28 @@ +package noppes.npcs.scripted.interfaces.handler.data; + +public interface ITransportLocation { + + int getId(); + + void setName(String name); + + String getName(); + + void setDimension(int dimension); + + int getDimension(); + + void setType(int type); + + int getType(); + + void setPosition(int x, int y, int z); + + double getX(); + + double getY(); + + double getZ(); + + void save(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJob.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJob.java new file mode 100644 index 000000000..41c82e852 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJob.java @@ -0,0 +1,13 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.roles.JobInterface; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; + +public interface IJob { + + int getType(); + + JobInterface getJobInterface(); + + ICustomNpc getNpc(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java new file mode 100644 index 000000000..a9416d60e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobBard.java @@ -0,0 +1,8 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobBard extends IJob { + + String getSong(); + + void setSong(String song); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobConversation.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobConversation.java new file mode 100644 index 000000000..e302430ec --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobConversation.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobConversation extends IJob { + +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobFollower.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobFollower.java new file mode 100644 index 000000000..963d1b66a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobFollower.java @@ -0,0 +1,14 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; + +public interface IJobFollower extends IJob { + + String getFollowingName(); + + void setFollowingName(String name); + + ICustomNpc getFollowingNpc(); + + boolean isFollowing(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java new file mode 100644 index 000000000..16710a8a7 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobGuard.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobGuard extends IJob { +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java new file mode 100644 index 000000000..4cc335383 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobHealer.java @@ -0,0 +1,8 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; + +public interface IJobHealer extends IJob { + + void heal(IEntityLivingBase entity, float amount); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobItemGiver.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobItemGiver.java new file mode 100644 index 000000000..c09e2ff8a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobItemGiver.java @@ -0,0 +1,34 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.IAvailability; +import noppes.npcs.scripted.interfaces.item.IItemStack; + +public interface IJobItemGiver extends IJob { + + void setCooldown(int cooldown); + + void setCooldownType(int type); + + int getCooldownType(); + + void setGivingMethod(int method); + + int getGivingMethod(); + + void setLines(String[] lines); + + String[] getLines(); + + void setAvailability(IAvailability availability); + + IAvailability getAvailability(); + + void setItem(int slot, IItemStack item); + + IItemStack[] getItems(); + + boolean giveItems(IPlayer player); + + boolean canPlayerInteract(IPlayer player); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobPuppet.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobPuppet.java new file mode 100644 index 000000000..b96d125e2 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobPuppet.java @@ -0,0 +1,20 @@ +package noppes.npcs.scripted.interfaces.jobs; + +public interface IJobPuppet extends IJob { + + int getRotationX(int part); + + int getRotationY(int part); + + int getRotationZ(int part); + + void setRotationX(int part, int rotation); + + void setRotationY(int part, int rotation); + + void setRotationZ(int part, int rotation); + + boolean isEnabled(int part); + + void setEnabled(int part, boolean bo); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java new file mode 100644 index 000000000..b9ff96ac5 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/jobs/IJobSpawner.java @@ -0,0 +1,10 @@ +package noppes.npcs.scripted.interfaces.jobs; + +import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; + +public interface IJobSpawner extends IJob { + + IEntityLivingBase spawnEntity(int number); + + void removeAllSpawned(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java new file mode 100644 index 000000000..f309d7bd0 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRole.java @@ -0,0 +1,6 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRole { + + int getType(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleBank.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleBank.java new file mode 100644 index 000000000..1f8d209dc --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleBank.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRoleBank extends IRole { + +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleFollower.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleFollower.java new file mode 100644 index 000000000..66c125572 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleFollower.java @@ -0,0 +1,64 @@ +package noppes.npcs.scripted.interfaces.roles; + +import noppes.npcs.scripted.interfaces.entity.IPlayer; + +public interface IRoleFollower extends IRole { + + /** + * @since 1.7.10c + * @param player Player who is set as the owner. If null given everything resets + */ + void setOwner(IPlayer player); + + /** + * @since 1.7.10c + * @return Returns the followers owner. Returns null if he has no owner or the owner is offline + */ + IPlayer getOwner(); + + /** + * @since 1.7.10c + * @return Returns whether or not the follower has an owner + */ + boolean hasOwner(); + + boolean isFollowing(); + + void setIsFollowing(boolean following); + + /** + * @since 1.7.10c + * @return Returns days left + */ + int getDaysLeft(); + + /** + * @since 1.7.10c + * @param days The days you want to add to the days remaining + */ + void addDaysLeft(int days); + + /** + * @since 1.7.10c + * @return Returns whether or not the follower is set to infinite days + */ + boolean getInfiniteDays(); + + /** + * @since 1.7.10c + * @param infinite Sets whether the days hired are infinite + */ + void setInfiniteDays(boolean infinite); + + /** + * @since 1.7.10c + * @return Return whether the gui is disabled + */ + boolean getGuiDisabled(); + + /** + * @since 1.7.10c + * @param disabled Set the gui to be disabled or not + */ + void setGuiDisabled(boolean disabled); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleMailman.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleMailman.java new file mode 100644 index 000000000..3813b031e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleMailman.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRoleMailman extends IRole { + +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTrader.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTrader.java new file mode 100644 index 000000000..ed469568b --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTrader.java @@ -0,0 +1,119 @@ +package noppes.npcs.scripted.interfaces.roles; + +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.item.IItemStack; + +public interface IRoleTrader extends IRole { + + /** + * @param slot Slot number 0-17 + * @param currency Currency item + * @param currency2 Currency item number two + * @param sold Item to be sold by this npc + */ + void setSellOption(int slot, IItemStack currency, IItemStack currency2, IItemStack sold); + + /** + * @param slot Slot number 0-17 + * @param currency Currency item + * @param sold Item to be sold by this npc + */ + void setSellOption(int slot, IItemStack currency, IItemStack sold); + + /** + * @param slot + * @return The item being sold in this slot. + */ + IItemStack getSellOption(int slot); + + /** + * @param slot + * @return a ScriptItemStack array of size 2 which contains the currency of this trade + */ + IItemStack[] getCurrency(int slot); + + /** + * @param slot Slot number 0-17 + */ + void removeSellOption(int slot); + + /** + * @param name The trader Linked Market name + */ + void setMarket(String name); + + /** + * @return Get the currently set Linked Market name + */ + String getMarket(); + + /** + * @param slot + * @return the number of times an item has been sold on that slot + */ + int getPurchaseNum(int slot); + + /** + * @param slot + * @param player + * @return the number of times this player has purchased from this trader + */ + int getPurchaseNum(int slot, IPlayer player); + + /** + * Sets the purchase count of all slots to 0 + */ + void resetPurchaseNum(); + + /** + * sets the purchase num for that slot to 0 + * @param slot + */ + void resetPurchaseNum(int slot); + + /** + * sets the purchase num for that slot and player to 0 + * @param slot + * @param player + */ + void resetPurchaseNum(int slot, IPlayer player); + + /** + * @param slot + * @return if this slot is enabled + */ + boolean isSlotEnabled(int slot); + + /** + * @param slot + * @param player + * @return if this slot is enabled for this player + */ + boolean isSlotEnabled(int slot, IPlayer player); + + /** + * prevent an item from being sold on that slot + * @param slot + */ + void disableSlot(int slot); + + /** + * disables the slot for this player + * @param slot + * @param player + */ + void disableSlot(int slot, IPlayer player); + + /** + * allow an item to be sold on that slot + * @param slot + */ + void enableSlot(int slot); + + /** + * enables the slot for this player + * @param slot + * @param player + */ + void enableSlot(int slot, IPlayer player); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java new file mode 100644 index 000000000..b5c9b8f4c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/roles/IRoleTransporter.java @@ -0,0 +1,5 @@ +package noppes.npcs.scripted.interfaces.roles; + +public interface IRoleTransporter extends IRole { + +} diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java index 306a652cc..fe5811930 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobBard.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobBard; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobBard; -public class ScriptJobBard extends ScriptJobInterface{ +public class ScriptJobBard extends ScriptJobInterface implements IJobBard { private JobBard job; public ScriptJobBard(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java index 5f92c6d92..ea8071202 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobConversation.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobConversation; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobConversation; -public class ScriptJobConversation extends ScriptJobInterface{ +public class ScriptJobConversation extends ScriptJobInterface implements IJobConversation { private JobConversation job; public ScriptJobConversation(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java index ddbce4dd0..c34c18ef4 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobFollower.java @@ -4,8 +4,9 @@ import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobFollower; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.jobs.IJobFollower; -public class ScriptJobFollower extends ScriptJobInterface{ +public class ScriptJobFollower extends ScriptJobInterface implements IJobFollower { private JobFollower job; public ScriptJobFollower(EntityNPCInterface npc){ super(npc); @@ -20,7 +21,7 @@ public class ScriptJobFollower extends ScriptJobInterface{ job.name = name; } - public ICustomNpc getFollowingNpc(){ + public ICustomNpc getFollowingNpc() { if(!isFollowing()) return null; return job.following.script.dummyNpc; diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java index 1543cd0a6..e16340f30 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobGuard.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobGuard; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobGuard; -public class ScriptJobGuard extends ScriptJobInterface{ +public class ScriptJobGuard extends ScriptJobInterface implements IJobGuard { private JobGuard job; public ScriptJobGuard(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java index eec32c14c..85578453b 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobHealer.java @@ -4,8 +4,9 @@ import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobHealer; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; +import noppes.npcs.scripted.interfaces.jobs.IJobHealer; -public class ScriptJobHealer extends ScriptJobInterface{ +public class ScriptJobHealer extends ScriptJobInterface implements IJobHealer { private JobHealer job; public ScriptJobHealer(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java index d3887629c..b68789540 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobInterface.java @@ -1,13 +1,24 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.roles.JobInterface; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.entity.ICustomNpc; +import noppes.npcs.scripted.interfaces.jobs.IJob; -public class ScriptJobInterface { - protected EntityNPCInterface npc; +public class ScriptJobInterface implements IJob { + public final EntityNPCInterface npc; + public final JobInterface jobInterface; + + public ScriptJobInterface(JobInterface jobInterface) { + this.npc = null; + this.jobInterface = jobInterface; + } public ScriptJobInterface(EntityNPCInterface npc){ this.npc = npc; + this.jobInterface = npc.jobInterface; } /** * @see noppes.npcs.scripted.constants.JobType @@ -16,4 +27,13 @@ public class ScriptJobInterface { public int getType(){ return JobType.UNKNOWN; } + + public JobInterface getJobInterface() { + return jobInterface; + } + + public ICustomNpc getNpc() { + return (ICustomNpc) NpcAPI.Instance().getIEntity(npc); + } + } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java index 046f89dac..b32841b93 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobItemGiver.java @@ -1,11 +1,29 @@ package noppes.npcs.scripted.roles; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import noppes.npcs.controllers.data.Availability; +import noppes.npcs.controllers.data.PlayerItemGiverData; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobItemGiver; +import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.handler.data.IAvailability; +import noppes.npcs.scripted.interfaces.item.IItemStack; +import noppes.npcs.scripted.interfaces.jobs.IJobItemGiver; -public class ScriptJobItemGiver extends ScriptJobInterface{ +import java.util.ArrayList; +import java.util.Arrays; + +public class ScriptJobItemGiver extends ScriptJobInterface implements IJobItemGiver { private JobItemGiver job; + + public ScriptJobItemGiver(JobItemGiver job) { + super(job); + this.job = job; + } + public ScriptJobItemGiver(EntityNPCInterface npc){ super(npc); this.job = (JobItemGiver) npc.jobInterface; @@ -15,5 +33,81 @@ public class ScriptJobItemGiver extends ScriptJobInterface{ public int getType(){ return JobType.ITEMGIVER; } - + + public void setCooldown(int cooldown) { + if (cooldown < 0) + cooldown = 0; + + job.cooldown = cooldown; + } + + public void setCooldownType(int type) { + if (type < 0) { + type = 0; + } else if (type > 2) { + type = 2; + } + job.cooldownType = type; + } + + public int getCooldownType() { + return job.cooldownType; + } + + public void setGivingMethod(int method) { + if (method < 0) { + method = 0; + } else if (method > 4) { + method = 4; + } + job.givingMethod = method; + } + + public int getGivingMethod() { + return job.givingMethod; + } + + public void setLines(String[] lines) { + job.lines = new ArrayList<>(Arrays.asList(lines)); + } + + public String[] getLines() { + return job.lines.toArray(new String[0]); + } + + public void setAvailability(IAvailability availability) { + job.availability = (Availability) availability; + } + + public IAvailability getAvailability() { + return job.availability; + } + + public void setItem(int slot, IItemStack item) { + if (slot < 0) { + slot = 0; + } else if (slot > 8) { + slot = 8; + } + + job.inventory.items.put(slot, item.getMCItemStack()); + } + + public IItemStack[] getItems() { + ArrayList items = new ArrayList<>(); + + for (int i = 0; i < job.inventory.getSizeInventory(); i++) { + items.add(NpcAPI.Instance().getIItemStack(job.inventory.getStackInSlot(i))); + } + + return items.toArray(new IItemStack[0]); + } + + public boolean giveItems(IPlayer player) { + return job.giveItems((EntityPlayer) player.getMCEntity()); + } + + public boolean canPlayerInteract(IPlayer player) { + return job.canPlayerInteract((PlayerItemGiverData) player.getData().getItemGiverData()); + } } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java index 20b12965f..fa59f48da 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobPuppet.java @@ -3,8 +3,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.JobPuppet; import noppes.npcs.scripted.constants.JobType; +import noppes.npcs.scripted.interfaces.jobs.IJobPuppet; -public class ScriptJobPuppet extends ScriptJobInterface{ +public class ScriptJobPuppet extends ScriptJobInterface implements IJobPuppet { private JobPuppet job; public ScriptJobPuppet(EntityNPCInterface npc){ super(npc); @@ -100,7 +101,7 @@ public class ScriptJobPuppet extends ScriptJobInterface{ /** * @since 1.7.10c - * @param type Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg) + * @param part Body part (0:head, 1:body, 2:leftarm, 3:rightarm, 4:leftleg, 5:rightleg) * @param rotation Rotation the of the body part */ public void setRotationY(int part, int rotation){ diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java index 64bc609f4..c44f03aad 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptJobSpawner.java @@ -8,8 +8,9 @@ import noppes.npcs.roles.JobSpawner; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.JobType; import noppes.npcs.scripted.interfaces.entity.IEntityLivingBase; +import noppes.npcs.scripted.interfaces.jobs.IJobSpawner; -public class ScriptJobSpawner extends ScriptJobInterface{ +public class ScriptJobSpawner extends ScriptJobInterface implements IJobSpawner { private JobSpawner job; public ScriptJobSpawner(EntityNPCInterface npc){ super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java index 222ddcc9e..2c5d48e23 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleBank.java @@ -2,8 +2,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRoleBank; -public class ScriptRoleBank extends ScriptRoleInterface{ +public class ScriptRoleBank extends ScriptRoleInterface implements IRoleBank { public ScriptRoleBank(EntityNPCInterface npc) { super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java index 4667c0d18..f6c7850a6 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleFollower.java @@ -6,18 +6,15 @@ import noppes.npcs.roles.RoleFollower; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.constants.RoleType; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.roles.IRoleFollower; -public class ScriptRoleFollower extends ScriptRoleInterface{ +public class ScriptRoleFollower extends ScriptRoleInterface implements IRoleFollower { private RoleFollower role; public ScriptRoleFollower(EntityNPCInterface npc) { super(npc); role = (RoleFollower) npc.roleInterface; } - - /** - * @since 1.7.10c - * @param player Player who is set as the owner. If null given everything resets - */ + public void setOwner(IPlayer player){ if(player == null || player.getMCEntity() == null){ role.setOwner(null); @@ -26,22 +23,14 @@ public class ScriptRoleFollower extends ScriptRoleInterface{ EntityPlayer mcplayer = (EntityPlayer) player.getMCEntity(); role.setOwner(mcplayer); } - - /** - * @since 1.7.10c - * @return Returns the followers owner. Returns null if he has no owner or the owner is offline - */ + public IPlayer getOwner(){ if(role.owner == null) return null; return (IPlayer) NpcAPI.Instance().getIEntity(role.owner); } - - /** - * @since 1.7.10c - * @return Returns whether or not the follower has an owner - */ + public boolean hasOwner(){ return role.owner != null; } @@ -53,51 +42,27 @@ public class ScriptRoleFollower extends ScriptRoleInterface{ public void setIsFollowing(boolean following) { if (role.owner != null && role.getDaysLeft() > 0) role.isFollowing = following; } - - /** - * @since 1.7.10c - * @return Returns days left - */ + public int getDaysLeft(){ return role.getDaysLeft(); } - - /** - * @since 1.7.10c - * @param days The days you want to add to the days remaining - */ + public void addDaysLeft(int days){ role.addDays(days); } - - /** - * @since 1.7.10c - * @return Returns whether or not the follower is set to infinite days - */ + public boolean getInfiniteDays(){ return role.infiniteDays; } - - /** - * @since 1.7.10c - * @param infinite Sets whether the days hired are infinite - */ + public void setInfiniteDays(boolean infinite){ role.infiniteDays = infinite; } - - /** - * @since 1.7.10c - * @return Return whether the gui is disabled - */ + public boolean getGuiDisabled(){ return role.disableGui; } - - /** - * @since 1.7.10c - * @param disabled Set the gui to be disabled or not - */ + public void setGuiDisabled(boolean disabled){ role.disableGui = disabled; } diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java index 338306819..eef73dd82 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleInterface.java @@ -1,13 +1,17 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; +import noppes.npcs.roles.RoleInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRole; -public class ScriptRoleInterface { - protected EntityNPCInterface npc; +public class ScriptRoleInterface implements IRole { + public final EntityNPCInterface npc; + public final RoleInterface role; public ScriptRoleInterface(EntityNPCInterface npc){ this.npc = npc; + this.role = npc.roleInterface; } /** diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java index dd461bf92..907f6e3ce 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleMailman.java @@ -2,8 +2,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRoleMailman; -public class ScriptRoleMailman extends ScriptRoleInterface{ +public class ScriptRoleMailman extends ScriptRoleInterface implements IRoleMailman { public ScriptRoleMailman(EntityNPCInterface npc) { super(npc); diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 6d36f0d0d..8aa4f13dc 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -8,20 +8,15 @@ import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.interfaces.item.IItemStack; import noppes.npcs.scripted.constants.RoleType; import noppes.npcs.scripted.interfaces.entity.IPlayer; +import noppes.npcs.scripted.interfaces.roles.IRoleTrader; -public class ScriptRoleTrader extends ScriptRoleInterface{ +public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader { private RoleTrader role; public ScriptRoleTrader(EntityNPCInterface npc) { super(npc); role = (RoleTrader) npc.roleInterface; } - - /** - * @param slot Slot number 0-17 - * @param currency Currency item - * @param currency2 Currency item number two - * @param sold Item to be sold by this npc - */ + public void setSellOption(int slot, IItemStack currency, IItemStack currency2, IItemStack sold){ if(sold == null || slot >= 18 || slot < 0) return; @@ -40,29 +35,16 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ role.inventorySold.items.put(slot, sold.getMCItemStack()); } - /** - * @param slot Slot number 0-17 - * @param currency Currency item - * @param sold Item to be sold by this npc - */ public void setSellOption(int slot, IItemStack currency, IItemStack sold){ setSellOption(slot, currency, null, sold); } - - /** - * @param slot - * @return The item being sold in this slot. - */ + public IItemStack getSellOption(int slot) { if (slot >= 18 || slot < 0) return null; if (role.inventorySold.items.get(slot) == null) return null; return NpcAPI.Instance().getIItemStack(role.inventoryCurrency.items.get(slot)); } - - /** - * @param slot - * @return a ScriptItemStack array of size 2 which contains the currency of this trade - */ + public IItemStack[] getCurrency(int slot) { if (slot >= 18 || slot < 0) return null; IItemStack[] currency = new IItemStack[2]; @@ -75,127 +57,72 @@ public class ScriptRoleTrader extends ScriptRoleInterface{ return currency; } - /** - * @param slot Slot number 0-17 - */ + public void removeSellOption(int slot){ if(slot >= 18 || slot < 0) return; role.inventoryCurrency.items.remove(slot); role.inventoryCurrency.items.remove(slot + 18); role.inventorySold.items.remove(slot); } - /** - * @param name The trader Linked Market name - */ + public void setMarket(String name){ role.marketName = name; Market.load(role, name); } - - /** - * @return Get the currently set Linked Market name - */ + public String getMarket(){ return role.marketName; } - - /** - * @param slot - * @return the number of times an item has been sold on that slot - */ + public int getPurchaseNum(int slot) { if(slot >= 18 || slot < 0) return -1; return role.purchases[slot]; } - - /** - * @param slot - * @param player - * @return the number of times this player has purchased from this trader - */ + public int getPurchaseNum(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return -1; return role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot]; } - - /** - * Sets the purchase count of all slots to 0 - */ + public void resetPurchaseNum() { for (int i = 0; i < role.purchases.length; ++i) role.purchases[i] = 0; } - - /** - * sets the purchase num for that slot to 0 - * @param slot - */ + public void resetPurchaseNum(int slot) { if(slot >= 18 || slot < 0) return; role.purchases[slot] = 0; } - - /** - * sets the purchase num for that slot and player to 0 - * @param slot - * @param player - */ + public void resetPurchaseNum(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return; role.getArrayByName(player.getDisplayName(), role.playerPurchases)[slot] = 0; } - - /** - * @param slot - * @return if this slot is enabled - */ + public boolean isSlotEnabled(int slot) { if(slot >= 18 || slot < 0) return false; return role.disableSlot[slot] > 0; } - - /** - * @param slot - * @param player - * @return if this slot is enabled for this player - */ + public boolean isSlotEnabled(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return false; return role.isSlotEnabled(slot, (EntityPlayer)player.getMCEntity()); } - - /** - * prevent an item from being sold on that slot - * @param slot - */ + public void disableSlot(int slot) { if(slot >= 18 || slot < 0) return; role.disableSlot[slot] = 1; } - - /** - * disables the slot for this player - * @param slot - * @param player - */ + public void disableSlot(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return; role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 1; } - - /** - * allow an item to be sold on that slot - * @param slot - */ + public void enableSlot(int slot) { if(slot >= 18 || slot < 0) return; role.disableSlot[slot] = 0; } - - /** - * enables the slot for this player - * @param slot - * @param player - */ + public void enableSlot(int slot, IPlayer player) { if(slot >= 18 || slot < 0) return; role.getArrayByName(player.getDisplayName(), role.playerDisableSlot)[slot] = 0; diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java index 50e9b63cd..3fbe5560b 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTransporter.java @@ -2,8 +2,9 @@ package noppes.npcs.scripted.roles; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.constants.RoleType; +import noppes.npcs.scripted.interfaces.roles.IRoleTransporter; -public class ScriptRoleTransporter extends ScriptRoleInterface{ +public class ScriptRoleTransporter extends ScriptRoleInterface implements IRoleTransporter { public ScriptRoleTransporter(EntityNPCInterface npc) { super(npc); diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 2891b0adc..046dc8f76 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -116,6 +116,13 @@ gui.update=Update gui.editor=Editor gui.playernearby=Player nearby gui.forum=Forum +gui.id=ID +gui.widthHeight=Width & Height +gui.position=Position +gui.screen=Screen +gui.option=Option +gui.default=Default +gui.type=Type remote.title=Nearby NPCs remote.reset=Reset @@ -175,6 +182,18 @@ display.bossbar=BossBar display.squareTexture=Square Texture display.url=Url display.urlSix=Url64 +display.alpha=Alpha +display.alignment=Alignment +display.topLeft=Top Left +display.topCenter=Top Center +display.topRight=Top Right +display.left=Left +display.center=Center +display.right=Right +display.botLeft=Bottom Left +display.botCenter=Bottom Center +display.botRight=Bottom Right +display.fixed=Fixed inv.minExp=Min Exp inv.maxExp=Max Exp @@ -416,6 +435,25 @@ dialog.commandoptionplayer=Use "@dp" to target the player using this dialog.hideNPC=Hide NPC dialog.showWheel=Show Dialog Wheel dialog.disableEsc=Disable Esc +dialog.visualOption=Visual Options +dialog.darkenScreen=Darken Screen +dialog.renderType=Render Type +dialog.instant=Instant +dialog.gradual=Gradual +dialog.previousBlocks=Previous Text Blocks +dialog.textOffset=Text Offset +dialog.titleOffset=Title Offset +dialog.optionOffset=Option Offset +dialog.optionSpacing=Option Spacing +dialog.textSound=Text Sound +dialog.textPitch=Text Pitch +dialog.textureOffset=Texture Offset +dialog.selectedColor=Selected Color +dialog.optionLine=Option Line +dialog.npcScale=NPC Scale +dialog.npcOffset=NPC Offset +dialog.titleColor=Title Color +dialog.titlePos=Title Position quest.quest=Quest quest.quests=Quests