Compare commits

..
Author SHA1 Message Date
Kam 1d210dbd39 Update api 2023-05-16 18:05:48 -04:00
Kam 6d8d57db5a 1.9-sync 2023-05-16 18:00:41 -04:00
Kam 31981c99c7 Update api 2023-05-16 17:57:57 -04:00
Kam 9dae37f128 Merge branch 'dev' into sync 2023-05-16 17:57:34 -04:00
Kam 8a7c4330aa Fix Unrefactored Save() 2023-05-16 17:02:23 -04:00
Kam 3e67bf0336 Experimental SyncController with UpdateClient 2023-05-16 17:00:36 -04:00
Kam 92cf6bcad6 Merge branch 'patch' into dev 2023-05-16 16:15:15 -04:00
Kam 27842e68ea Merge branch 'master' into dev 2023-05-16 13:05:50 -04:00
Kam 2791b3aae5 Merge branch 'master' into dev 2023-05-16 11:36:40 -04:00
64 changed files with 858 additions and 775 deletions

No files matched your search

+6 -6
View File
@@ -34,7 +34,7 @@ configurations {
apply plugin: 'forge'
version = "1.8.4"
version = "1.9-sync"
group= "com.kamkeel.customnpc-plus" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "CustomNPC-Plus"
@@ -195,13 +195,13 @@ afterEvaluate {
}
}
task deobfJar(type: Jar) {
classifier = 'dev'
from sourceSets.main.output
}
sourceSets {
main {
ext.refMap = refMapForYourConfig
}
}
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'dev'
}
+1 -1
Submodule src/api updated: 8c61d07b10...e1afcb4e90.
+2 -2
View File
@@ -50,7 +50,7 @@ public class CmdDialog extends ChMcLogger {
}
for(PlayerData playerdata : data){
playerdata.dialogData.dialogsRead.add(diagid);
playerdata.save();
playerdata.save(true);
}
return true;
}
@@ -76,7 +76,7 @@ public class CmdDialog extends ChMcLogger {
}
for(PlayerData playerdata : data){
playerdata.dialogData.dialogsRead.remove(diagid);
playerdata.save();
playerdata.save(true);
}
return true;
}
+1 -1
View File
@@ -100,7 +100,7 @@ public class CmdNoppes extends ChMcLogger {
cmdfaction.processCommand(this.pcParam, args);
for (PlayerData playerdata : cmdfaction.data) {
playerdata.save();
playerdata.save(true);
}
return true;
}
+4 -4
View File
@@ -56,7 +56,7 @@ public class CmdQuest extends ChMcLogger{
continue;
QuestData questdata = new QuestData(quest);
playerdata.questData.activeQuests.put(questid, questdata);
playerdata.save();
playerdata.save(true);
if(playerdata.player != null){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
@@ -93,7 +93,7 @@ public class CmdQuest extends ChMcLogger{
}
for(PlayerData playerdata : data){
playerdata.questData.finishedQuests.put(questid, System.currentTimeMillis());
playerdata.save();
playerdata.save(true);
}
return true;
}
@@ -124,7 +124,7 @@ public class CmdQuest extends ChMcLogger{
}
for(PlayerData playerdata : data){
playerdata.questData.activeQuests.remove(questid);
playerdata.save();
playerdata.save(true);
}
return true;
}
@@ -156,7 +156,7 @@ public class CmdQuest extends ChMcLogger{
for(PlayerData playerdata : data){
playerdata.questData.activeQuests.remove(questid);
playerdata.questData.finishedQuests.remove(questid);
playerdata.save();
playerdata.save(true);
}
return true;
}
@@ -46,7 +46,7 @@ public class AnimationCommand extends CommandKamkeelBase {
processSubCommand(sender, args[1], Arrays.copyOfRange(args, 2, args.length));
data.get(0).animationData.updateClient();
data.get(0).save();
data.get(0).save(true);
}
@SubCommand(desc = "enable animation")
@@ -11,6 +11,7 @@ import noppes.npcs.client.EntityUtil;
import noppes.npcs.controllers.DialogController;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogOption;
import noppes.npcs.controllers.data.PlayerData;
@@ -48,7 +49,7 @@ public class DialogCommand extends CommandKamkeelBase {
}
for(PlayerData playerdata : data){
playerdata.dialogData.dialogsRead.add(diagid);
playerdata.save();
playerdata.save(true);
sendResult(sender, String.format("Forced Read for Dialog \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", diagid, playerdata.playername));
}
}
@@ -73,7 +74,7 @@ public class DialogCommand extends CommandKamkeelBase {
}
for(PlayerData playerdata : data){
playerdata.dialogData.dialogsRead.remove(diagid);
playerdata.save();
playerdata.save(true);
sendResult(sender, String.format("Forced Unread for Dialog \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", diagid, playerdata.playername));
}
}
@@ -83,6 +84,7 @@ public class DialogCommand extends CommandKamkeelBase {
)
public void reload(ICommandSender sender, String args[]){
new DialogController();
SyncController.syncAllDialogs();
sendResult(sender, "Dialogs Reloaded");
}
@@ -64,7 +64,7 @@ public class FactionCommand extends CommandKamkeelBase {
processSubCommand(sender, args[2], Arrays.copyOfRange(args, 3, args.length));
for(PlayerData playerdata : data){
playerdata.save();
playerdata.save(true);
}
}
@@ -10,6 +10,7 @@ import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestRepeat;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.QuestController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.controllers.data.Quest;
import noppes.npcs.controllers.data.QuestData;
@@ -56,7 +57,7 @@ public class QuestCommand extends CommandKamkeelBase {
for(PlayerData playerdata : data){
QuestData questdata = new QuestData(quest);
playerdata.questData.activeQuests.put(questid, questdata);
playerdata.save();
playerdata.save(true);
if(playerdata.player != null && questdata.sendAlerts){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.newquest", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.newquest", ": ", quest.title);
@@ -101,7 +102,7 @@ public class QuestCommand extends CommandKamkeelBase {
else
playerdata.questData.finishedQuests.put(quest.id, sender.getEntityWorld().getTotalWorldTime());
playerdata.save();
playerdata.save(true);
if(playerdata.player != null){
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.MESSAGE, "quest.completed", quest.title);
Server.sendData((EntityPlayerMP)playerdata.player, EnumPacketClient.CHAT, "quest.completed", ": ", quest.title);
@@ -135,7 +136,7 @@ public class QuestCommand extends CommandKamkeelBase {
}
for(PlayerData playerdata : data){
playerdata.questData.activeQuests.remove(questid);
playerdata.save();
playerdata.save(true);
sendResult(sender, String.format("Stopped Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
}
}
@@ -169,7 +170,7 @@ public class QuestCommand extends CommandKamkeelBase {
for(PlayerData playerdata : data){
playerdata.questData.activeQuests.remove(questid);
playerdata.questData.finishedQuests.remove(questid);
playerdata.save();
playerdata.save(true);
sendResult(sender, String.format("Removed Quest \u00A7e%d\u00A77 for Player '\u00A7b%s\u00A77'", questid, playerdata.playername));
}
}
@@ -181,6 +182,7 @@ public class QuestCommand extends CommandKamkeelBase {
public void reload(ICommandSender sender, String args[]){
new QuestController();
QuestController.instance.load();
SyncController.syncAllQuests();
sendResult(sender, "Quests Reloaded");
}
}
+5 -2
View File
@@ -94,8 +94,11 @@ public class CommonProxy implements IGuiHandler {
if(gui == EnumGuiType.MerchantAdd)
return new ContainerMerchantAdd(player, ServerEventsHandler.Merchant, player.worldObj);
if(gui == EnumGuiType.Crate)
return new ContainerCrate(player.inventory, (TileNpcContainer)player.worldObj.getTileEntity(x, y, z));
if(gui == EnumGuiType.Crate){
if(player.inventory != null && (TileNpcContainer)player.worldObj.getTileEntity(x, y, z) != null){
return new ContainerCrate(player.inventory, (TileNpcContainer)player.worldObj.getTileEntity(x, y, z));
}
}
if(gui == EnumGuiType.PlayerMailman)
return new ContainerMail(player, x == 1, y == 1);
+1 -1
View File
@@ -36,7 +36,7 @@ import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.8.4")
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.9-sync")
public class CustomNpcs {
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
@@ -441,8 +441,6 @@ public class NoppesUtilPlayer {
questData.trackQuest(nextQuest.quest);
}
playerData.save();
return true;
}
+17 -14
View File
@@ -25,10 +25,7 @@ import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumPlayerData;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.constants.*;
import noppes.npcs.containers.ContainerManageBanks;
import noppes.npcs.containers.ContainerManageRecipes;
import noppes.npcs.controllers.*;
@@ -162,6 +159,7 @@ public class NoppesUtilServer {
public static void openDialog(EntityPlayer player, EntityNPCInterface npc, Dialog dia, int optionId){
Dialog dialog = dia.copy(player);
PlayerData playerdata = PlayerDataController.instance.getPlayerData(player);
if (!npc.isRemote()) {
if (EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog)) {
@@ -174,7 +172,7 @@ public class NoppesUtilServer {
if(npc instanceof EntityDialogNpc || dia.id < 0){
dialog.hideNPC = true;
Server.sendData((EntityPlayerMP)player, EnumPacketClient.DIALOG_DUMMY, npc.getCommandSenderName(), dialog.writeToNBT(new NBTTagCompound()));
Server.sendDataDelayed((EntityPlayerMP)player, EnumPacketClient.DIALOG_DUMMY, 100, npc.getCommandSenderName(), dialog.writeToNBT(new NBTTagCompound()));
}
else
Server.sendData((EntityPlayerMP)player, EnumPacketClient.DIALOG, npc.getEntityId(), dialog.writeToNBT(new NBTTagCompound()));
@@ -187,8 +185,10 @@ public class NoppesUtilServer {
if(dialog.mail.isValid())
PlayerDataController.instance.addPlayerMessage(player.getCommandSenderName(), dialog.mail);
PlayerDialogData data = PlayerDataController.instance.getPlayerData(player).dialogData;
if(!data.dialogsRead.contains(dialog.id))
data.dialogsRead.add(dialog.id);
if(!data.dialogsRead.contains(dialog.id)){
data.dialogsRead.add(dialog.id);
playerdata.updateClient = true;
}
setEditingNpc(player, npc);
}
public static void runCommand(EntityPlayer player, String name, String command){
@@ -485,7 +485,7 @@ public class NoppesUtilServer {
return;
String name = Server.readString(buffer);
EnumPlayerData type = EnumPlayerData.values()[id];
EntityPlayer pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(name);
EntityPlayerMP pl = MinecraftServer.getServer().getConfigurationManager().func_152612_a(name);
PlayerData playerdata = null;
if(pl == null)
playerdata = PlayerDataController.instance.getDataFromUsername(name);
@@ -499,7 +499,7 @@ public class NoppesUtilServer {
if(pl != null){
playerdata.setNBT(new NBTTagCompound());
sendPlayerData(type, player, name);
playerdata.save();
playerdata.save(true);
return;
}
else {
@@ -512,28 +512,31 @@ public class NoppesUtilServer {
int questId = buffer.readInt();
data.activeQuests.remove(questId);
data.finishedQuests.remove(questId);
playerdata.save();
playerdata.save(true);
}
if(type == EnumPlayerData.Dialog){
PlayerDialogData data = playerdata.dialogData;
data.dialogsRead.remove(buffer.readInt());
playerdata.save();
playerdata.save(true);
}
if(type == EnumPlayerData.Transport){
PlayerTransportData data = playerdata.transportData;
data.transports.remove(buffer.readInt());
playerdata.save();
playerdata.save(true);
}
if(type == EnumPlayerData.Bank){
PlayerBankData data = playerdata.bankData;
data.banks.remove(buffer.readInt());
playerdata.save();
playerdata.save(true);
}
if(type == EnumPlayerData.Factions){
PlayerFactionData data = playerdata.factionData;
data.factionData.remove(buffer.readInt());
playerdata.save();
playerdata.save(true);
}
if(pl != null) {
SyncController.syncPlayer(pl);
}
sendPlayerData(type, player, name);
}
@@ -227,9 +227,7 @@ public class PacketHandlerServer{
data.getScripts().add(new ScriptContainer(data));
}
NBTTagCompound tabCompound = Server.readNBT(buffer);
ScriptContainer script = new ScriptContainer(data);
script.readFromNBT(tabCompound);
data.getScripts().set(tab,script);
data.getScripts().get(tab).readFromNBT(tabCompound);
} else {
NBTTagCompound compound = Server.readNBT(buffer);
data.setLanguage(compound.getString("ScriptLanguage"));
@@ -241,9 +239,6 @@ public class PacketHandlerServer{
}
}
data.setEnabled(compound.getBoolean("ScriptEnabled"));
for (ScriptContainer container : data.getScripts()) {
container.setEngine(data.getLanguage());
}
}
}
@@ -294,7 +289,6 @@ public class PacketHandlerServer{
private void itemScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
if (type == EnumPacketServer.ScriptItemDataGet) {
ScriptCustomItem iw = (ScriptCustomItem) NpcAPI.Instance().getIItemStack(player.getHeldItem());
iw.loadScriptData();
NBTTagCompound compound = iw.getMCNbt();
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
Server.sendData(player, EnumPacketClient.GUI_DATA, new Object[]{compound});
@@ -306,8 +300,7 @@ public class PacketHandlerServer{
NBTTagCompound compound = Server.readNBT(buffer);
ScriptCustomItem wrapper = (ScriptCustomItem) NpcAPI.Instance().getIItemStack(player.getHeldItem());
wrapper.setMCNbt(compound);
wrapper.loadScriptData();
wrapper.loaded = false;
wrapper.lastInited = -1L;
wrapper.saveScriptData();
player.sendContainerToPlayer(player.inventoryContainer);
}
@@ -58,7 +58,7 @@ public class ScriptItemEventHandler {
try {
if (event.entityItem.getEntityItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) {
IItemCustom isw = ItemScripted.GetWrapper(event.entityItem.getEntityItem());
event.setCanceled(EventHooks.onScriptItemTossed(isw, event.player, event.entityItem));
EventHooks.onScriptItemTossed(isw, event.player, event.entityItem);
}
} catch (Exception e) {}
}
@@ -27,6 +27,7 @@ import net.minecraftforge.event.world.BlockEvent;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.EnumQuestType;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.PlayerDataController;
import noppes.npcs.controllers.ScriptController;
import noppes.npcs.controllers.data.PlayerData;
@@ -67,6 +68,11 @@ public class ScriptPlayerEventHandler {
if (PlayerDataController.instance != null) {
PlayerData playerData = PlayerDataController.instance.getPlayerData(player);
if(playerData.updateClient) {
Server.sendData((EntityPlayerMP)player, EnumPacketClient.SYNC_END, SyncType.PLAYER_DATA, playerData.getSyncNBT());
playerData.updateClient = false;
}
if (playerData.timers.size() > 0) {
playerData.timers.update();
}
@@ -329,7 +335,7 @@ public class ScriptPlayerEventHandler {
if(event.player.worldObj instanceof WorldServer) {
PlayerDataScript handler = ScriptController.Instance.playerScripts;
IPlayer scriptPlayer = (IPlayer) NpcAPI.Instance().getIEntity(event.player);
event.setCanceled(EventHooks.onPlayerToss(handler, scriptPlayer, event.entityItem));
EventHooks.onPlayerToss(handler, scriptPlayer, event.entityItem);
}
}
+26 -11
View File
@@ -13,7 +13,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.village.MerchantRecipeList;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.util.CustomNPCsThreader;
import noppes.npcs.util.CustomNPCsScheduler;
import java.io.IOException;
import java.util.List;
@@ -22,7 +22,20 @@ import java.util.Map;
public class Server {
public static void sendData(final EntityPlayerMP player, final EnumPacketClient enu, final Object... obs) {
sendDataChecked(player, enu, obs);
sendDataDelayed(player, enu, 0, obs);
}
public static void sendDataDelayed(final EntityPlayerMP player, final EnumPacketClient type, int delay, final Object... obs) {
CustomNPCsScheduler.runTack(() -> {
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
try {
if (!fillBuffer(buffer, type, obs))
return;
CustomNpcs.Channel.sendTo(new FMLProxyPacket(buffer, "CustomNPCs"), player);
} catch (IOException e) {
LogWriter.error(type + " Errored", e);
}
}, delay);
}
public static boolean sendDataChecked(EntityPlayerMP player, EnumPacketClient type, Object... obs) {
@@ -38,15 +51,17 @@ public class Server {
}
public static void sendAssociatedData(final Entity entity, final EnumPacketClient enu, final Object... obs) {
ByteBuf buffer = Unpooled.buffer();
try {
if(!fillBuffer(buffer, enu, obs))
return;
TargetPoint point = new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 60);
CustomNpcs.Channel.sendToAllAround(new FMLProxyPacket(buffer,"CustomNPCs"), point);
} catch (IOException e) {
e.printStackTrace();
}
CustomNPCsScheduler.runTack(() -> {
ByteBuf buffer = Unpooled.buffer();
try {
if(!fillBuffer(buffer, enu, obs))
return;
TargetPoint point = new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 60);
CustomNpcs.Channel.sendToAllAround(new FMLProxyPacket(buffer,"CustomNPCs"), point);
} catch (IOException e) {
e.printStackTrace();
}
});
}
public static void sendToAll(EnumPacketClient enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
@@ -1,7 +1,6 @@
package noppes.npcs;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.block.Block;
@@ -21,7 +20,6 @@ import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.MathHelper;
import net.minecraft.util.StatCollector;
import net.minecraft.village.MerchantRecipeList;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
@@ -255,7 +253,7 @@ public class ServerEventsHandler {
doExcalibur((EntityPlayer) event.source.getEntity(),event.entityLiving);
}
if(event.source.getEntity() instanceof EntityNPCInterface){
if(event.source.getEntity() instanceof EntityNPCInterface && event.entityLiving != null){
EntityNPCInterface npc = (EntityNPCInterface) event.source.getEntity();
Line line = npc.advanced.getKillLine();
if(line != null)
@@ -278,7 +276,7 @@ public class ServerEventsHandler {
}
if(event.entityLiving instanceof EntityPlayer){
PlayerData data = PlayerDataController.instance.getPlayerData((EntityPlayer)event.entityLiving);
data.save();
data.save(false);
}
}
@@ -343,6 +341,7 @@ public class ServerEventsHandler {
killed.put(name, amount + 1);
}
quest.setKilled(data, killed);
playerData.updateClient = true;
}
if(!checkCompletion)
return;
@@ -360,12 +359,6 @@ public class ServerEventsHandler {
questData.checkQuestCompletion(playerData, EnumQuestType.Item);
}
@SubscribeEvent
public void world(PlayerEvent.SaveToFile event){
PlayerData data = PlayerDataController.instance.getPlayerData((EntityPlayer) event.entity);
data.save();
}
@SubscribeEvent
public void world(EntityJoinWorldEvent event){
if(event.world.isRemote || !(event.entity instanceof EntityPlayer))
@@ -374,6 +367,12 @@ public class ServerEventsHandler {
data.updateCompanion(event.world);
}
@SubscribeEvent
public void world(PlayerEvent.SaveToFile event){
PlayerData data = PlayerDataController.instance.getPlayerData((EntityPlayer) event.entity);
data.save(false);
}
@SubscribeEvent
public void populateChunk(PopulateChunkEvent.Post event){
NPCSpawning.performWorldGenSpawning(event.world, event.chunkX, event.chunkZ, event.rand);
@@ -4,9 +4,11 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import noppes.npcs.client.AnalyticsTracking;
import noppes.npcs.controllers.SyncController;
import java.net.InetAddress;
import java.net.UnknownHostException;
@@ -40,5 +42,9 @@ public class ServerTickHandler {
serverName = e;
}
AnalyticsTracking.sendData(event.player, "join", serverName);
if(event.player instanceof EntityPlayerMP){
EntityPlayerMP player = (EntityPlayerMP) event.player;
SyncController.syncPlayer(player);
}
}
}
@@ -56,6 +56,7 @@ public class TileWaypoint extends TileEntity {
player.addChatMessage(new ChatComponentTranslation(name + " " + StatCollector.translateToLocal("quest.found")));
questData.checkQuestCompletion(playerData, EnumQuestType.Location);
playerData.updateClient = true;
}
}
}
@@ -3,6 +3,7 @@ package noppes.npcs.client;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.minecraft.network.PacketBuffer;
import noppes.npcs.AnimationData;
import noppes.npcs.CustomNpcs;
import noppes.npcs.Server;
@@ -219,12 +219,13 @@ public class ClientProxy extends CommonProxy {
private GuiScreen getGui(EntityNPCInterface npc, EnumGuiType gui, Container container, int x, int y, int z) {
if (gui == EnumGuiType.MainMenuDisplay) {
if (npc != null)
if (gui == EnumGuiType.MainMenuDisplay){
if(npc != null)
return new GuiNpcDisplay(npc);
else
Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("Unable to find npc"));
} else if (gui == EnumGuiType.MainMenuStats)
}
else if (gui == EnumGuiType.MainMenuStats)
return new GuiNpcStats(npc);
else if (gui == EnumGuiType.MainMenuInv)
@@ -233,10 +234,10 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.MainMenuAdvanced)
return new GuiNpcAdvanced(npc);
else if (gui == EnumGuiType.QuestReward)
else if(gui == EnumGuiType.QuestReward)
return new GuiNpcQuestReward(npc, (ContainerNpcQuestReward) container);
else if (gui == EnumGuiType.QuestItem)
else if(gui == EnumGuiType.QuestItem)
return new GuiNpcQuestTypeItem(npc, (ContainerNpcQuestTypeItem) container);
else if (gui == EnumGuiType.MovingPath)
@@ -260,14 +261,16 @@ public class ClientProxy extends CommonProxy {
animNpc.display.texture = "customnpcs:textures/entity/humanmale/AnimationBody.png";
}
return new GuiNPCManageAnimations(animNpc);
} else if (gui == EnumGuiType.ManageLinked)
}
else if (gui == EnumGuiType.ManageLinked)
return new GuiNPCManageLinkedNpc(npc);
else if (gui == EnumGuiType.ManageTransport)
return new GuiNPCManageTransporters(npc);
else if (gui == EnumGuiType.ManageRecipes)
return new GuiNpcManageRecipes(npc, (ContainerManageRecipes) container);
return new GuiNpcManageRecipes(npc,(ContainerManageRecipes) container);
else if (gui == EnumGuiType.ManageDialogs)
return new GuiNPCManageDialogs(npc);
@@ -275,8 +278,8 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.ManageQuests)
return new GuiNPCManageQuest(npc);
else if (gui == EnumGuiType.ManageBanks)
return new GuiNPCManageBanks(npc, (ContainerManageBanks) container);
else if(gui == EnumGuiType.ManageBanks)
return new GuiNPCManageBanks(npc,(ContainerManageBanks) container);
else if (gui == EnumGuiType.MainMenuGlobal)
return new GuiNPCGlobalMainMenu(npc);
@@ -290,56 +293,56 @@ public class ClientProxy extends CommonProxy {
else if (gui == EnumGuiType.PlayerFollower)
return new GuiNpcFollower(npc, (ContainerNPCFollower) container);
else if (gui == EnumGuiType.PlayerTrader)
else if(gui == EnumGuiType.PlayerTrader)
return new GuiNPCTrader(npc, (ContainerNPCTrader) container);
else if (gui == EnumGuiType.PlayerBankSmall || gui == EnumGuiType.PlayerBankUnlock || gui == EnumGuiType.PlayerBankUprade || gui == EnumGuiType.PlayerBankLarge)
else if(gui == EnumGuiType.PlayerBankSmall || gui == EnumGuiType.PlayerBankUnlock || gui == EnumGuiType.PlayerBankUprade || gui == EnumGuiType.PlayerBankLarge)
return new GuiNPCBankChest(npc, (ContainerNPCBankInterface) container);
else if (gui == EnumGuiType.PlayerTransporter)
else if(gui == EnumGuiType.PlayerTransporter)
return new GuiTransportSelection(npc);
else if (gui == EnumGuiType.Script && ConfigScript.ScriptingEnabled)
else if(gui == EnumGuiType.Script && ConfigScript.ScriptingEnabled)
return new GuiScript(npc);
else if (gui == EnumGuiType.ScriptItem)
return new GuiScriptItem();
else if (gui == EnumGuiType.PlayerAnvil)
else if(gui == EnumGuiType.PlayerAnvil)
return new GuiNpcCarpentryBench((ContainerCarpentryBench) container);
else if (gui == EnumGuiType.SetupFollower)
return new GuiNpcFollowerSetup(npc, (ContainerNPCFollowerSetup) container);
return new GuiNpcFollowerSetup(npc, (ContainerNPCFollowerSetup) container);
else if (gui == EnumGuiType.SetupItemGiver)
return new GuiNpcItemGiver(npc, (ContainerNpcItemGiver) container);
else if (gui == EnumGuiType.SetupTrader)
else if(gui == EnumGuiType.SetupTrader)
return new GuiNpcTraderSetup(npc, (ContainerNPCTraderSetup) container);
else if (gui == EnumGuiType.SetupTransporter)
else if(gui == EnumGuiType.SetupTransporter)
return new GuiNpcTransporter(npc);
else if (gui == EnumGuiType.SetupBank)
else if(gui == EnumGuiType.SetupBank)
return new GuiNpcBankSetup(npc);
else if (gui == EnumGuiType.NpcRemote && Minecraft.getMinecraft().currentScreen == null)
else if(gui == EnumGuiType.NpcRemote && Minecraft.getMinecraft().currentScreen == null)
return new GuiNpcRemoteEditor();
else if (gui == EnumGuiType.ScriptEvent && Minecraft.getMinecraft().currentScreen == null)
else if(gui == EnumGuiType.ScriptEvent && Minecraft.getMinecraft().currentScreen == null)
return new GuiScriptGlobal();
else if (gui == EnumGuiType.PlayerMailman)
else if(gui == EnumGuiType.PlayerMailman)
return new GuiMailmanWrite((ContainerMail) container, x == 1, y == 1);
else if (gui == EnumGuiType.PlayerMailbox)
else if(gui == EnumGuiType.PlayerMailbox)
return new GuiMailbox();
else if (gui == EnumGuiType.MerchantAdd)
else if(gui == EnumGuiType.MerchantAdd)
return new GuiMerchantAdd();
else if (gui == EnumGuiType.Crate)
return new GuiCrate((ContainerCrate) container);
else if(gui == EnumGuiType.Crate)
return new GuiCrate((ContainerCrate)container);
else if(gui == EnumGuiType.NpcDimensions)
return new GuiNpcDimension();
@@ -30,14 +30,18 @@ import noppes.npcs.client.gui.util.*;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.constants.EnumGuiType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.RecipeController;
import noppes.npcs.controllers.SyncController;
import noppes.npcs.controllers.data.Animation;
import noppes.npcs.controllers.data.RecipeCarpentry;
import noppes.npcs.entity.EntityDialogNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.items.ItemScripted;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
public class PacketHandlerClient extends PacketHandlerServer{
@@ -100,6 +104,27 @@ public class PacketHandlerClient extends PacketHandlerServer{
RecipeController.instance.anvilRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
}
else if(type == EnumPacketClient.SYNC_ADD || type == EnumPacketClient.SYNC_END){
int synctype = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
SyncController.clientSync(synctype, compound, type == EnumPacketClient.SYNC_END);
if(synctype == SyncType.PLAYER_DATA){
ClientProxy.playerData.setNBT(compound);
}
}
else if(type == EnumPacketClient.SYNC_UPDATE){
int synctype = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
SyncController.clientSyncUpdate(synctype, compound, buffer);
}
else if(type == EnumPacketClient.SYNC_REMOVE){
int synctype = buffer.readInt();
int id = buffer.readInt();
SyncController.clientSyncRemove(synctype, id);
}
else if(type == EnumPacketClient.DIALOG){
Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
@@ -42,7 +42,6 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
private int posX,posY,posZ;
private List<String> list;
private List<String> rawList;
private List<String> tagList;
private static int showingClones = 0;
@@ -182,7 +181,6 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
}
}
this.list = list;
this.rawList = new ArrayList<String>(this.list);
scroll.setList(getSearchList(), ascending == 0, sortType == 0);
}
private void showClones() {
@@ -200,26 +198,6 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
}
this.tagMap = ClientTagMapController.Instance.getTagMap(activeTab);
this.rawList = new ArrayList<String>(this.list);
if(this.tagMap != null){
if(GuiNpcMobSpawner.displayTags == 0 || GuiNpcMobSpawner.displayTags == 1){
for(int i = 0; i < this.list.size(); i++){
StringBuilder npcName = new StringBuilder(list.get(i));
if (this.tagMap.hasClone(list.get(i))) {
for (UUID tagUUID : this.tagMap.getUUIDsList(list.get(i))){
Tag tag = tags.get(tagUUID);
if(tag != null){
if(GuiNpcMobSpawner.displayTags == 1 || !tag.getIsHidden()){
npcName.append(" [" + tag.name + "]");
}
}
}
}
this.rawList.set(i, npcName.toString());
}
}
}
scroll.setList(getSearchList(), ascending == 0, sortType == 0);
}
public void keyTyped(char c, int i)
@@ -244,9 +222,6 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
if(this.list == null){
this.list = new ArrayList<String>();
}
if(this.rawList == null){
this.rawList = new ArrayList<String>();
}
// No Filters - or - Entities
if(tagFilters.size() == 0 || showingClones == 1){
@@ -256,10 +231,9 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
// Yes Search
else {
List<String> list = new ArrayList<String>();
for(int i = 0; i < this.list.size(); i++){
if(this.rawList.get(i).toLowerCase().contains(search)){
list.add(this.list.get(i));
}
for(String name : this.list){
if(name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
@@ -283,16 +257,14 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
// Yes Search
List<String> list = new ArrayList<String>();
for(int i = 0; i < this.list.size(); i++){
if(this.rawList.get(i).toLowerCase().contains(search)){
String npcName = this.list.get(i);
if(tagMap.hasClone(npcName)){
if(meetsCondition(npcName)){
list.add(npcName);
for(String name : this.list){
if(name.toLowerCase().contains(search)) {
if(tagMap.hasClone(name)){
if(meetsCondition(name)){
list.add(name);
}
}
}
}
return list;
}
@@ -509,27 +481,6 @@ public class GuiNpcMobSpawner extends GuiNPCInterface implements IGuiData {
}
this.list = list;
this.rawList = new ArrayList<String>(this.list);
if(this.tagMap != null){
if(GuiNpcMobSpawner.displayTags == 0 || GuiNpcMobSpawner.displayTags == 1){
for(int i = 0; i < this.list.size(); i++){
StringBuilder npcName = new StringBuilder(list.get(i));
if (this.tagMap.hasClone(list.get(i))) {
for (UUID tagUUID : this.tagMap.getUUIDsList(list.get(i))){
Tag tag = tags.get(tagUUID);
if(tag != null){
if(GuiNpcMobSpawner.displayTags == 1 || !tag.getIsHidden()){
npcName.append(" [" + tag.name + "]");
}
}
}
}
this.rawList.set(i, npcName.toString());
}
}
}
scroll.setList(getSearchList(), ascending == 0, sortType == 0);
}
}
@@ -172,10 +172,6 @@ public class GuiNpcMobSpawnerAdd extends GuiNPCInterface implements GuiYesNoCall
@Override
public void subGuiClosed(SubGuiInterface subgui) {
if(subgui instanceof SubGuiClonerNPCTags){
close();
return;
}
initGui();
}
@@ -30,8 +30,8 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc
setBackground("menubg.png");
xSize = 305;
ySize = 220;
this.npc = npc;
closeOnEsc = false;
this.npc = npc;
}
public void initGui()
@@ -86,7 +86,6 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc
tagNames.clear();
}
if (guibutton.id == 66) {
save();
close();
}
initGui();
@@ -155,4 +154,11 @@ public class SubGuiClonerNPCTags extends SubGuiInterface implements IGuiData,ISc
}
return list;
}
@Override
public void close() {
save();
super.close();
}
}
@@ -1,9 +1,14 @@
package noppes.npcs.client.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.StatCollector;
import noppes.npcs.client.Client;
import noppes.npcs.client.gui.util.*;
import org.lwjgl.Sys;
import noppes.npcs.constants.EnumPacketServer;
import noppes.npcs.controllers.data.Tag;
import noppes.npcs.controllers.data.TagMap;
import java.util.*;
@@ -11,7 +16,6 @@ public class SubGuiClonerQuickTags extends SubGuiInterface implements IScrollDat
{
public GuiNpcMobSpawnerAdd parent;
public GuiCustomScroll quickScroll = new GuiCustomScroll(this,0);
public GuiCustomScroll selectedScroll = new GuiCustomScroll(this,5);
private static String quickSearch = "";
public SubGuiClonerQuickTags(GuiNpcMobSpawnerAdd par){
@@ -32,60 +36,35 @@ public class SubGuiClonerQuickTags extends SubGuiInterface implements IScrollDat
quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags);
this.addScroll(quickScroll);
addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("cloner.wandTags"), guiLeft + 7, guiTop + 7));
addLabel(new GuiNpcLabel(1, StatCollector.translateToLocal("cloner.wandtags"), guiLeft + 7, guiTop + 7));
addScroll(quickScroll);
addTextField(new GuiNpcTextField(2, this, fontRendererObj, guiLeft + 4, guiTop + 190, 140, 20, quickSearch));
addButton(new GuiNpcButton(10, guiLeft + 150, guiTop + 20, 120, 20, "gui.selectAll"));
addButton(new GuiNpcButton(11, guiLeft + 150, guiTop + 43, 120, 20, "gui.deselectAll"));
selectedScroll.clear();
selectedScroll.setSize(145, 103);
selectedScroll.guiLeft = guiLeft + 150;
selectedScroll.guiTop = guiTop + 82;
selectedScroll.setUnselectable();
this.addScroll(selectedScroll);
addButton(new GuiNpcButton(66, guiLeft + 240, guiTop + 175, 60, 20, "gui.done"));
addLabel(new GuiNpcLabel(3, StatCollector.translateToLocal("tags.selectedTags"), guiLeft + 153, guiTop + 68));
addScroll(selectedScroll);
addButton(new GuiNpcButton(66, guiLeft + 240, guiTop + 190, 60, 20, "gui.done"));
setSelected();
refreshSelected();
getSelected();
}
protected void actionPerformed(GuiButton guibutton){
if (guibutton.id == 10) {
GuiNpcMobSpawnerAdd.addTags = new HashSet<>(parent.allTags);
quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags);
refreshSelected();
}
if (guibutton.id == 11) {
GuiNpcMobSpawnerAdd.addTags = new HashSet<>();
quickScroll.setSelectedList(GuiNpcMobSpawnerAdd.addTags);
refreshSelected();
}
if (guibutton.id == 66) {
close();
}
}
@Override
public void mouseClicked(int i, int j, int k)
{
super.mouseClicked(i, j, k);
refreshSelected();
}
public void setSelected(){
public void getSelected(){
quickScroll.setList(getQuickTags());
}
public void refreshSelected(){
List<String> sortedList = new ArrayList<>(new TreeSet<>(GuiNpcMobSpawnerAdd.addTags));
selectedScroll.setList(sortedList);
}
@Override
public void keyTyped(char c, int i)
{
@@ -9,19 +9,26 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.api.gui.ICustomGuiComponent;
import noppes.npcs.client.Client;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IClickListener;
import noppes.npcs.client.renderer.customitem.ImageData;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import noppes.npcs.scripted.gui.ScriptGuiButton;
import org.lwjgl.opengl.GL11;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
public class CustomGuiButton extends GuiButton implements IClickListener {
GuiCustom parent;
ImageData imageData = null;
String texture;
ResourceLocation location = null;
public int textureX;
public int textureY;
boolean field_146123_n;
@@ -32,6 +39,11 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
float alpha;
float scale = 1.0F;
private int totalWidth, totalHeight;
private ImageDownloadAlt imageDownloadAlt = null;
private boolean isUrl = false;
private boolean gotWidthHeight = false;
public CustomGuiButton(int id, String buttonText, int x, int y) {
super(id, x, y, buttonText);
}
@@ -46,12 +58,24 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
public CustomGuiButton(int buttonId, String buttonText, int x, int y, int width, int height, String texture, int textureX, int textureY) {
this(buttonId, buttonText, x, y, width, height);
this.texture = texture;
this.textureX = textureX;
this.textureY = textureY;
this.label = buttonText;
if (texture != null && !texture.isEmpty()) {
this.imageData = Client.getImageData(texture);
this.location = new ResourceLocation(texture);
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);
} else {
try {
this.getWidthHeight();
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
this.location = null;
}
}
@@ -91,36 +115,42 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
this.field_146123_n = mouseX >= this.xPosition + GuiCustom.guiLeft && mouseY >= this.yPosition + GuiCustom.guiTop && mouseX < this.xPosition + GuiCustom.guiLeft + this.width * this.scale && mouseY < this.yPosition + GuiCustom.guiTop + this.height * this.scale;
FontRenderer fontRenderer = mc.fontRenderer;
if (this.imageData != null && this.imageData.imageLoaded()) {
int totalWidth = this.imageData.getTotalWidth();
int totalHeight = this.imageData.getTotalHeight();
if (this.location == null) {
totalWidth = totalHeight = 256;
textureX = textureY = 0;
}
float u1 = (float)textureX/(float)totalWidth;
float u2 = u1 + (float)width/(float)totalWidth;
float v1 = (float)textureY/(float)totalHeight;
float v2 = v1 + (float)height/(float)totalHeight;
float u1 = (float)textureX/(float)totalWidth;
float u2 = u1 + (float)width/(float)totalWidth;
float v1 = (float)textureY/(float)totalHeight;
float v2 = v1 + (float)height/(float)totalHeight;
if (this.enabled) {
if (this.field_146123_n) {
v1 = (float)(textureY + 2 * this.height)/(float)totalHeight;
} else {
v1 = (float)(textureY + this.height)/(float)totalHeight;
}
v2 = v1 + (float)height/(float)totalHeight;
if (this.location != null && this.enabled) {
if (this.field_146123_n) {
v1 = (float)(textureY + 2 * this.height)/(float)totalHeight;
} else {
v1 = (float)(textureY + this.height)/(float)totalHeight;
}
v2 = v1 + (float)height/(float)totalHeight;
}
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);
if(imageDownloadAlt != null && isUrl && !gotWidthHeight){
getURLWidthHeight();
}
GL11.glTranslatef(GuiCustom.guiLeft + this.xPosition - u1 * totalWidth * this.scale, GuiCustom.guiTop + this.yPosition - v1 * totalHeight * this.scale,(float)this.id);
GL11.glScalef(this.scale,this.scale,1.0F);
FontRenderer fontRenderer = mc.fontRenderer;
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);
this.imageData.bindTexture();
GL11.glTranslatef(GuiCustom.guiLeft + this.xPosition - u1 * totalWidth * this.scale, GuiCustom.guiTop + this.yPosition - v1 * totalHeight * this.scale,(float)this.id);
GL11.glScalef(this.scale,this.scale,1.0F);
if (this.location != null) {
mc.getTextureManager().bindTexture(this.location);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
@@ -133,9 +163,7 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
tessellator.draw();
GL11.glTranslated(0.0D, 0.0D, 0.1D);
this.drawCenteredString(fontRenderer, this.label, this.width / 2, (this.height - 8) / 2, this.color);
GL11.glPopMatrix();
} else {
GL11.glPushMatrix();
} else {
mc.getTextureManager().bindTexture(buttonTextures);
int i = this.getHoverState(this.field_146123_n);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
@@ -151,9 +179,9 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
j = 16777120;
}
GL11.glTranslated(0.0D, 0.0D, 0.1D);
this.drawCenteredString(fontRenderer, this.displayString, this.width / 2, (this.height - 8) / 2, j);
GL11.glPopMatrix();
}
this.drawCenteredString(fontRenderer, this.displayString, this.width / 2, (this.height-8)/2, j);
}
GL11.glPopMatrix();
if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
@@ -161,7 +189,7 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
}
public ICustomGuiComponent toComponent() {
ScriptGuiButton component = new ScriptGuiButton(this.id, this.label, this.xPosition, this.yPosition, this.width, this.height, this.texture, this.textureX, this.textureY);
ScriptGuiButton component = new ScriptGuiButton(this.id, this.label, this.xPosition, this.yPosition, this.width, this.height, this.location.toString(), this.textureX, this.textureY);
component.setHoverText(this.hoverText);
component.setColor(this.color);
component.setAlpha(this.alpha);
@@ -176,4 +204,40 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
return false;
}
}
public void getWidthHeight() throws IOException {
InputStream inputstream = null;
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(this.location);
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
gotWidthHeight = true;
this.totalWidth = bufferedimage.getWidth();
this.totalHeight = bufferedimage.getHeight();
correctWidthHeight();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputstream != null) {
inputstream.close();
}
}
}
public void getURLWidthHeight(){
if(imageDownloadAlt.getBufferedImage() != null) {
gotWidthHeight = true;
this.totalWidth = imageDownloadAlt.getBufferedImage().getWidth();
this.totalHeight = imageDownloadAlt.getBufferedImage().getHeight();
correctWidthHeight();
}
}
public void correctWidthHeight(){
totalWidth = Math.max(totalWidth, 1);
totalHeight = Math.max(totalHeight, 1);
this.width = width < 0 ? totalWidth : width;
this.height = height < 0 ? totalHeight : height;
}
}
@@ -8,19 +8,25 @@ package noppes.npcs.client.gui.custom.components;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResource;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.api.gui.ICustomGuiComponent;
import noppes.npcs.client.Client;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.gui.custom.GuiCustom;
import noppes.npcs.client.gui.custom.interfaces.IGuiComponent;
import noppes.npcs.client.renderer.customitem.ImageData;
import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
import org.lwjgl.opengl.GL11;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
GuiCustom parent;
ImageData imageData = null;
String texture;
ResourceLocation location;
int id;
int x;
int y;
@@ -35,6 +41,11 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
float alpha;
float rotation;
private int totalWidth, totalHeight;
private ImageDownloadAlt imageDownloadAlt = null;
private boolean isUrl = false;
private boolean gotWidthHeight = false;
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0);
}
@@ -42,15 +53,25 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
public CustomGuiTexturedRect(int id, String directory, int x, int y, int width, int height, int textureX, int textureY) {
this.scale = 1.0F;
this.id = id;
this.texture = directory;
this.location = new ResourceLocation(directory);
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.textureX = textureX;
this.textureY = textureY;
if (texture != null && !texture.isEmpty()) {
this.imageData = Client.getImageData(texture);
if(directory.startsWith("https://")){
this.isUrl = true;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
this.imageDownloadAlt = new ImageDownloadAlt(null, directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true,false));
texturemanager.loadTexture(this.location, this.imageDownloadAlt);
} else {
try {
this.getWidthHeight();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -64,38 +85,37 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
boolean hovered = mouseX >= this.x + GuiCustom.guiLeft && mouseY >= this.y + GuiCustom.guiTop && mouseX < this.x + GuiCustom.guiLeft + this.width && mouseY < this.y + GuiCustom.guiTop + this.height;
mc.getTextureManager().bindTexture(this.location);
if (this.imageData != null && this.imageData.imageLoaded()) {
int totalWidth = this.imageData.getTotalWidth();
int totalHeight = this.imageData.getTotalHeight();
float u1 = (float)textureX/(float)totalWidth;
float u2 = u1 + (float)width/(float)totalWidth;
float v1 = (float)textureY/(float)totalHeight;
float v2 = v1 + (float)height/(float)totalHeight;
float u1 = (float) textureX / (float) totalWidth;
float u2 = u1 + (float) width / (float) totalWidth;
float v1 = (float) textureY / (float) totalHeight;
float v2 = v1 + (float) height / (float) totalHeight;
if(imageDownloadAlt != null && isUrl && !gotWidthHeight){
getURLWidthHeight();
}
GL11.glPushMatrix();
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red, green, blue, this.alpha);
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslatef(GuiCustom.guiLeft + this.x - u1 * totalWidth, GuiCustom.guiTop + this.y - v1 * totalHeight, (float) this.id);
GL11.glRotatef(this.rotation, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(GuiCustom.guiLeft + this.x - u1 * totalWidth, GuiCustom.guiTop + this.y - v1 * totalHeight,(float)this.id);
GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F);
GL11.glScalef(this.scale, this.scale, this.scale);
this.imageData.bindTexture();
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorOpaque_F(1, 1, 1);
tessellator.setColorRGBA_F(red, green, blue, alpha);
tessellator.addVertexWithUV(u2 * totalWidth, v2 * totalHeight, 0, u2, v2);
tessellator.addVertexWithUV(u2 * totalWidth, v1 * totalHeight, 0, u2, v1);
tessellator.addVertexWithUV(u1 * totalWidth, v1 * totalHeight, 0, u1, v1);
tessellator.addVertexWithUV(u1 * totalWidth, v2 * totalHeight, 0, u1, v2);
tessellator.addVertexWithUV( u2 * totalWidth, v2 * totalHeight, 0, u2, v2);
tessellator.addVertexWithUV( u2 * totalWidth, v1 * totalHeight, 0, u2, v1);
tessellator.addVertexWithUV( u1 * totalWidth, v1 * totalHeight, 0, u1, v1);
tessellator.addVertexWithUV( u1 * totalWidth, v2 * totalHeight, 0, u1, v2);
tessellator.draw();
GL11.glPopMatrix();
}
GL11.glPopMatrix();
if (hovered && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
@@ -103,7 +123,7 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
}
public ICustomGuiComponent toComponent() {
ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.texture, this.x, this.y, this.width, this.height, this.textureX, this.textureY);
ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.location.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY);
component.setHoverText(this.hoverText);
component.setScale(this.scale);
component.setColor(color);
@@ -131,4 +151,40 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
return rect;
}
public void getWidthHeight() throws IOException {
InputStream inputstream = null;
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(this.location);
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
gotWidthHeight = true;
this.totalWidth = bufferedimage.getWidth();
this.totalHeight = bufferedimage.getHeight();
correctWidthHeight();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputstream != null) {
inputstream.close();
}
}
}
public void getURLWidthHeight(){
if(imageDownloadAlt.getBufferedImage() != null) {
gotWidthHeight = true;
this.totalWidth = imageDownloadAlt.getBufferedImage().getWidth();
this.totalHeight = imageDownloadAlt.getBufferedImage().getHeight();
correctWidthHeight();
}
}
public void correctWidthHeight(){
totalWidth = Math.max(totalWidth, 1);
totalHeight = Math.max(totalHeight, 1);
this.width = width < 0 ? totalWidth : width;
this.height = height < 0 ? totalHeight : height;
}
}
@@ -10,9 +10,7 @@ import noppes.npcs.containers.ContainerManageBanks;
import noppes.npcs.controllers.data.Bank;
import noppes.npcs.entity.EntityNPCInterface;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Vector;
public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScrollData,ICustomScrollListener,ITextfieldListener, IGuiData
@@ -22,7 +20,6 @@ public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScr
private ContainerManageBanks container;
private Bank bank = new Bank();
private String selected = null;
private String search = "";
public GuiNPCManageBanks(EntityNPCInterface npc,ContainerManageBanks container)
{
@@ -64,8 +61,6 @@ public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScr
addTextField(new GuiNpcTextField(2,this, this.fontRendererObj, guiLeft+10, guiTop + 110, 16, 16, ""));
getTextField(2).integersOnly = true;
getTextField(2).setMaxStringLength(1);
addTextField(new GuiNpcTextField(33, this, fontRendererObj, guiLeft + 174, guiTop + 8 + 3 + 180, 160, 20, search));
}
public void drawScreen(int x, int y, float f)
@@ -142,37 +137,12 @@ public class GuiNPCManageBanks extends GuiContainerNPCInterface2 implements IScr
}
setSelected(bank.name);
}
public void keyTyped(char c, int i)
{
super.keyTyped(c, i);
if(getTextField(33) != null){
if(getTextField(33).isFocused()){
if(search.equals(getTextField(33).getText()))
return;
search = getTextField(33).getText().toLowerCase();
scroll.setList(getSearchList());
}
}
}
private List<String> getSearchList(){
if(search.isEmpty()){
return new ArrayList<String>(this.data.keySet());
}
List<String> list = new ArrayList<String>();
for(String name : this.data.keySet()){
if(name.toLowerCase().contains(search))
list.add(name);
}
return list;
}
@Override
public void setData(Vector<String> list, HashMap<String, Integer> data) {
String name = scroll.getSelected();
this.data = data;
scroll.setList(getSearchList());
scroll.setList(list);
if(name != null)
scroll.setSelected(name);
@@ -29,7 +29,6 @@ public class GuiScriptItem extends GuiScriptInterface {
public void setGuiData(NBTTagCompound compound) {
this.item.setMCNbt(compound);
this.item.loadScriptData();
super.setGuiData(compound);
}
@@ -56,7 +56,7 @@ public class GuiCustomScrollCloner extends GuiCustomScroll {
}
if((this.parent.getShowingClones() == 0 || this.parent.getShowingClones() == 2) && this.parent.tagMap != null){
int tagStartX = j + fontRendererObj.getStringWidth(displayString) + 3;
int tagStartX = j + fontRendererObj.getStringWidth(displayString) + 5;
if(GuiNpcMobSpawner.displayTags == 0 || GuiNpcMobSpawner.displayTags == 1){
if (this.parent.tagMap.hasClone(list.get(i))) {
for (UUID tagUUID : this.parent.tagMap.getUUIDsList(list.get(i))){
@@ -64,7 +64,7 @@ public class GuiCustomScrollCloner extends GuiCustomScroll {
if(tag != null){
if(GuiNpcMobSpawner.displayTags == 1 || !tag.getIsHidden()){
fontRendererObj.drawString("[" + tag.name + "]", tagStartX, k, tag.color);
tagStartX += fontRendererObj.getStringWidth("[" + tag.name + "]") + 3;
tagStartX += fontRendererObj.getStringWidth("[" + tag.name + "]") + 2;
}
}
}
@@ -49,11 +49,16 @@ public class CustomItemRenderer implements IItemRenderer {
public void renderItem(ItemRenderType type, ItemStack itemStack, Object... data) {
ScriptCustomItem scriptCustomItem = ItemScripted.GetWrapper(itemStack);
ImageData imageData = Client.getImageData(scriptCustomItem.texture);
if (!imageData.imageLoaded()) {
return;
BufferedImage bufferedImage = Client.getImageData(scriptCustomItem.texture).getBufferedImage();
if (bufferedImage != null && (scriptCustomItem.width != bufferedImage.getWidth() || scriptCustomItem.height != bufferedImage.getHeight())) {
scriptCustomItem.width = bufferedImage.getWidth();
scriptCustomItem.height = bufferedImage.getHeight();
scriptCustomItem.saveItemData();
}
if(scriptCustomItem.width < 1 || scriptCustomItem.height < 1)
return;
if (type == ItemRenderType.INVENTORY) {
GL11.glPushMatrix();
renderInventoryCustomItem(scriptCustomItem);
@@ -75,6 +80,7 @@ public class CustomItemRenderer implements IItemRenderer {
GL11.glRotatef(scriptCustomItem.rotationYRate * entityRenderTicks%360, 0, 1, 0);
GL11.glRotatef(scriptCustomItem.rotationZRate * entityRenderTicks%360, 0, 0, 1);
GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ);
GL11.glTranslatef(0.0F, bobbingY, 0.0F);
int color = scriptCustomItem.getColor();
@@ -178,7 +184,6 @@ public class CustomItemRenderer implements IItemRenderer {
b0 = 4;
}
GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ);
GL11.glTranslatef(-f7, -f8, -((f9 + f10) * (float)b0 / 2.0F));
for (int k = 0; k < b0; ++k)
@@ -248,7 +253,6 @@ public class CustomItemRenderer implements IItemRenderer {
for (int l = 0; l < b0; ++l)
{
GL11.glPushMatrix();
GL11.glScalef(scriptCustomItem.scaleX, scriptCustomItem.scaleY, scriptCustomItem.scaleZ);
if (l > 0)
{
@@ -13,13 +13,12 @@ import java.io.IOException;
import java.io.InputStream;
public class ImageData {
private final ResourceLocation location;
private ResourceLocation location;
private final boolean isUrl;
private ImageDownloadAlt imageDownloadAlt = null;
private BufferedImage bufferedImage = null;
private int totalWidth, totalHeight;
private boolean gotWidthHeight;
private boolean invalid;
@@ -29,23 +28,14 @@ public class ImageData {
this.isUrl = true;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
this.imageDownloadAlt = new ImageDownloadAlt(null, directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true, false));
texturemanager.loadTexture(this.location, this.imageDownloadAlt);
texturemanager.loadTexture(location, this.imageDownloadAlt);
} else {
this.isUrl = false;
}
}
public boolean imageLoaded() {
if (!this.gotWidthHeight) {
try {
if (!this.isUrl) {
this.getWidthHeight();
} else {
this.getURLWidthHeight();
}
} catch (Exception ignored) {}
}
return !this.invalid && this.location != null && this.gotWidthHeight;
public boolean invalidTexture() {
return this.invalid;
}
public void bindTexture() {
@@ -59,7 +49,7 @@ public class ImageData {
}
}
private ResourceLocation getLocation() {
public ResourceLocation getLocation() {
return this.isUrl && this.imageDownloadAlt.getBufferedImage() == null ? null : this.location;
}
@@ -79,10 +69,6 @@ public class ImageData {
}
private void getWidthHeight() throws IOException {
if (this.invalid) {
return;
}
InputStream inputstream = null;
try {
@@ -94,7 +80,7 @@ public class ImageData {
this.totalHeight = bufferedimage.getHeight();
correctWidthHeight();
} catch (Exception e) {
this.invalid = true;
e.printStackTrace();
} finally {
if (inputstream != null) {
inputstream.close();
@@ -103,7 +89,7 @@ public class ImageData {
}
private void getURLWidthHeight(){
if(this.imageDownloadAlt.getBufferedImage() != null && !this.invalid) {
if(this.imageDownloadAlt.getBufferedImage() != null) {
this.gotWidthHeight = true;
this.totalWidth = this.imageDownloadAlt.getBufferedImage().getWidth();
this.totalHeight = this.imageDownloadAlt.getBufferedImage().getHeight();
@@ -117,10 +103,34 @@ public class ImageData {
}
public int getTotalWidth() {
return this.gotWidthHeight ? this.totalWidth : -1;
if (!this.gotWidthHeight) {
try {
if (!this.isUrl) {
this.getWidthHeight();
} else {
this.getURLWidthHeight();
}
} catch (Exception ignored) {}
if (!this.gotWidthHeight) {
return -1;
}
}
return this.totalWidth;
}
public int getTotalHeight() {
return this.gotWidthHeight ? this.totalHeight : -1;
if (!this.gotWidthHeight) {
try {
if (!this.isUrl) {
this.getWidthHeight();
} else {
this.getURLWidthHeight();
}
} catch (Exception ignored) {}
if (!this.gotWidthHeight) {
return -1;
}
}
return this.totalHeight;
}
}
@@ -47,5 +47,6 @@ public enum EnumPacketClient {
STOP_SOUND_FOR,
PAUSE_SOUNDS,
CONTINUE_SOUNDS,
STOP_SOUNDS
STOP_SOUNDS,
SYNC_ADD, SYNC_END, SYNC_UPDATE, SYNC_REMOVE,
}
@@ -0,0 +1,11 @@
package noppes.npcs.constants;
public class SyncType {
public static final int FACTION = 1;
public static final int QUEST = 2;
public static final int QUEST_CATEGORY = 3;
public static final int DIALOG = 4;
public static final int DIALOG_CATEGORY = 5;
public static final int PLAYER_DATA = 8;
}
@@ -7,9 +7,11 @@ package noppes.npcs.containers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import noppes.npcs.EventHooks;
import noppes.npcs.api.entity.IPlayer;
@@ -17,6 +19,7 @@ import noppes.npcs.api.gui.IItemSlot;
import noppes.npcs.client.gui.custom.components.CustomGuiSlot;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.gui.ScriptGui;
import noppes.npcs.util.CustomNPCsScheduler;
import java.util.Iterator;
@@ -108,11 +111,6 @@ public class ContainerCustomGui extends Container {
public ItemStack slotClick(int slotId, int dragType, int clickTypeIn, EntityPlayer player) {
if(slotId < 0)
return super.slotClick(slotId, dragType, clickTypeIn, player);
if (slotId >= this.inventorySlots.size()) {
return null;
}
Slot mcSlot = (Slot)this.inventorySlots.get(slotId);
if(!player.worldObj.isRemote && mcSlot != null) {
IItemSlot slot = null;
@@ -137,7 +135,7 @@ public class ContainerCustomGui extends Container {
}
EntityPlayerMP p = (EntityPlayerMP) player;
p.sendContainerToPlayer(this);
CustomNPCsScheduler.runTack(() -> {p.sendContainerToPlayer(this);}, 10);
return item;
}
}
@@ -6,10 +6,13 @@ import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IDialogHandler;
import noppes.npcs.api.handler.data.IDialog;
import noppes.npcs.api.handler.data.IDialogCategory;
import noppes.npcs.constants.EnumOptionType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogCategory;
import noppes.npcs.controllers.data.DialogOption;
@@ -21,6 +24,7 @@ import java.util.*;
public class DialogController implements IDialogHandler {
public HashMap<Integer,DialogCategory> categories = new HashMap<Integer, DialogCategory>();
public HashMap<Integer,DialogCategory> categoriesSync = new HashMap<Integer, DialogCategory>();
public HashMap<Integer,Dialog> dialogs = new HashMap<Integer, Dialog>();
public static DialogController instance;
@@ -227,6 +231,7 @@ public class DialogController implements IDialogHandler {
dir.mkdirs();
}
categories.put(category.id, category);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound()));
}
public void removeCategory(int category){
@@ -239,6 +244,7 @@ public class DialogController implements IDialogHandler {
for(int dia : cat.dialogs.keySet())
dialogs.remove(dia);
categories.remove(category);
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG_CATEGORY, category);
}
private boolean containsCategoryName(String name) {
@@ -281,10 +287,12 @@ public class DialogController implements IDialogHandler {
File file2 = new File(dir, dialog.id + ".json");
try {
NBTJsonUtil.SaveFile(file, dialog.writeToNBTPartial(new NBTTagCompound()));
NBTTagCompound compound = dialog.writeToNBT(new NBTTagCompound());
NBTJsonUtil.SaveFile(file, compound);
if(file2.exists())
file2.delete();
file.renameTo(file2);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG, compound, category.id);
} catch (Exception e) {
LogWriter.except(e);
}
@@ -298,7 +306,7 @@ public class DialogController implements IDialogHandler {
return;
category.dialogs.remove(dialog.id);
dialogs.remove(dialog.id);
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG, dialog.id);
}
private File getDir(){
@@ -5,8 +5,11 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IFactionHandler;
import noppes.npcs.api.handler.data.IFaction;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.Faction;
import java.io.*;
@@ -18,7 +21,7 @@ import java.util.zip.GZIPInputStream;
public class FactionController implements IFactionHandler {
public HashMap<Integer,Faction> factions;
public HashMap<Integer,Faction> factionsSync = new HashMap<Integer,Faction>();
private static FactionController instance;
private int lastUsedID = 0;
@@ -151,6 +154,9 @@ public class FactionController implements IFactionHandler {
}
factions.remove(faction.id);
factions.put(faction.id, faction);
NBTTagCompound nbtTagCompound = new NBTTagCompound();
faction.writeNBT(nbtTagCompound);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.FACTION, nbtTagCompound);
saveFactions();
}
@@ -185,6 +191,7 @@ public class FactionController implements IFactionHandler {
} else {
this.saveFactions();
faction.id = -1;
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.FACTION, id);
return faction;
}
} else {
@@ -9,19 +9,21 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.controllers.data.*;
import noppes.npcs.util.CustomNPCsScheduler;
import noppes.npcs.util.NBTJsonUtil;
import org.lwjgl.Sys;
import java.io.*;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.zip.GZIPInputStream;
import static noppes.npcs.util.CustomNPCsThreader.playerDataThread;
public class PlayerDataController {
public static PlayerDataController instance;
public HashMap<String, String> nameUUIDs;
@@ -167,7 +169,7 @@ public class PlayerDataController {
}
public synchronized void savePlayerDataMap(){
playerDataThread.execute(() -> {
CustomNPCsScheduler.runTack(() -> {
try {
File saveDir = getSaveDir();
File file = new File(saveDir, "___playermap.dat_new");
@@ -271,7 +273,7 @@ public class PlayerDataController {
if(data == null){
player.registerExtendedProperties("CustomNpcsData", data = new PlayerData());
data.player = player;
data.load();
data.loadPlayerDataFromFile();
}
data.player = player;
return data;
@@ -309,7 +311,7 @@ public class PlayerDataController {
EntityPlayer player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(username);
PlayerData data = getDataFromUsername(username);
data.mailData.playermail.add(mail.copy());
data.save();
data.save(false);
}
public List<PlayerData> getPlayersData(ICommandSender sender, String username){
@@ -6,9 +6,12 @@ import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IQuestHandler;
import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.api.handler.data.IQuestCategory;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.Quest;
import noppes.npcs.controllers.data.QuestCategory;
import noppes.npcs.util.NBTJsonUtil;
@@ -19,6 +22,7 @@ import java.util.*;
public class QuestController implements IQuestHandler {
public HashMap<Integer,QuestCategory> categories = new HashMap<Integer, QuestCategory>();
public HashMap<Integer,QuestCategory> categoriesSync = new HashMap<Integer, QuestCategory>();
public HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
public static QuestController instance;
@@ -142,6 +146,7 @@ public class QuestController implements IQuestHandler {
for(int dia : cat.quests.keySet())
quests.remove(dia);
categories.remove(category);
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.QUEST_CATEGORY, category);
}
public void saveCategory(QuestCategory category){
@@ -172,6 +177,7 @@ public class QuestController implements IQuestHandler {
dir.mkdirs();
}
categories.put(category.id, category);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound()));
}
private boolean containsCategoryName(String name) {
name = name.toLowerCase();
@@ -219,6 +225,7 @@ public class QuestController implements IQuestHandler {
if(file2.exists())
file2.delete();
file.renameTo(file2);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST, quest.writeToNBT(new NBTTagCompound()), category.id);
} catch (Exception e) {
e.printStackTrace();
}
@@ -230,6 +237,7 @@ public class QuestController implements IQuestHandler {
return;
quests.remove(quest.id);
quest.category.quests.remove(quest.id);
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.QUEST, quest.id);
}
private File getDir(){
@@ -33,7 +33,7 @@ public class ScriptContainer {
private String currentScriptLanguage = null;
public ScriptEngine engine = null;
private IScriptHandler handler = null;
private boolean evaluated = false;
private boolean init = false;
private static Method luaCoerce;
private static Method luaCall;
private CompiledScript compScript = null;
@@ -43,7 +43,6 @@ public class ScriptContainer {
}
public void readFromNBT(NBTTagCompound compound) {
String prevScript = this.script;
this.script = compound.getString("Script");
for (int i = 0; i < ConfigScript.ExpandedScriptLimit; i++) {
if (compound.hasKey("ExpandedScript"+i)) {
@@ -52,11 +51,7 @@ public class ScriptContainer {
break;
}
}
if (!this.script.equals(prevScript)) {
this.evaluated = false;
}
//this.type = compound.getString("Type");
this.console = NBTTags.GetLongStringMap(compound.getTagList("Console", 10));
this.scripts = NBTTags.getStringList(compound.getTagList("ScriptList", 10));
this.lastCreated = 0L;
@@ -93,7 +88,7 @@ public class ScriptContainer {
}
private String getFullCode() {
if(!this.evaluated) {
if(!this.init) {
this.fullscript = this.script;
if(!this.fullscript.isEmpty()) {
this.fullscript = this.fullscript + "\n";
@@ -150,11 +145,12 @@ public class ScriptContainer {
if(errored || !hasCode() || unknownFunctions.contains(type) || !ConfigScript.ScriptingEnabled)
return;
this.setEngine(handler.getLanguage());
if(engine == null)
return;
if(ScriptController.Instance.lastLoaded > this.lastCreated){
this.lastCreated = ScriptController.Instance.lastLoaded;
evaluated = false;
init = false;
}
synchronized (lock) {
@@ -174,9 +170,9 @@ public class ScriptContainer {
}
try {
if(!evaluated){
if(!init){
engine.eval(getFullCode());
evaluated = true;
init = true;
}
if(engine.getFactory().getLanguageName().equals("lua")){
Object ob = engine.get(type);
@@ -224,7 +220,7 @@ public class ScriptContainer {
}
public boolean isValid() {
return evaluated && !errored;
return init && !errored;
}
public boolean hasCode() {
@@ -237,9 +233,9 @@ public class ScriptContainer {
if (ConfigScript.ScriptingECMA6 && scriptLanguage.equals("ECMAScript")) {
System.setProperty("nashorn.args", "--language=es6");
}
this.engine = ScriptController.Instance.getEngineByName(scriptLanguage.toLowerCase());
this.engine = new ScriptEngineManager().getEngineByName(scriptLanguage.toLowerCase());
currentScriptLanguage = scriptLanguage;
evaluated = false;
init = false;
}
}
@@ -33,7 +33,7 @@ public class ScriptController {
public static ScriptController Instance;
public static boolean HasStart = false;
private final ScriptEngineManager manager;
private ScriptEngineManager manager;
public Map<String, String> languages = new HashMap<String, String>();
public Map<String, String> scripts = new HashMap<String, String>();
public long lastLoaded = 0;
@@ -0,0 +1,184 @@
package noppes.npcs.controllers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.NBTTags;
import noppes.npcs.Server;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.*;
import io.netty.buffer.ByteBuf;
import java.util.HashMap;
import java.util.List;
public class SyncController {
public static void syncPlayer(EntityPlayerMP player){
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
for(Faction faction : FactionController.getInstance().factions.values()){
NBTTagCompound nbtTagCompound = new NBTTagCompound();
faction.writeNBT(nbtTagCompound);
list.appendTag(nbtTagCompound);
if(list.tagCount() > 20){
compound = new NBTTagCompound();
compound.setTag("Data", list);
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.FACTION, compound);
list = new NBTTagList();
}
}
compound = new NBTTagCompound();
compound.setTag("Data", list);
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.FACTION, compound);
for(QuestCategory category : QuestController.instance.categories.values()){
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound()));
}
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
for(DialogCategory category : DialogController.instance.categories.values()){
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound()));
}
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
PlayerData data = PlayerDataController.instance.getPlayerData(player);
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.PLAYER_DATA, data.getNBT());
}
public static void syncAllDialogs() {
for(DialogCategory category : DialogController.instance.categories.values()){
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, category.writeNBT(new NBTTagCompound()));
}
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
}
public static void syncAllQuests() {
for(QuestCategory category : QuestController.instance.categories.values()){
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, category.writeNBT(new NBTTagCompound()));
}
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
}
public static void clientSync(int synctype, NBTTagCompound compound, boolean syncEnd) {
if(synctype == SyncType.FACTION){
NBTTagList list = compound.getTagList("Data", 10);
for(int i = 0; i < list.tagCount(); i++)
{
Faction faction = new Faction();
faction.readNBT(list.getCompoundTagAt(i));
FactionController.getInstance().factionsSync.put(faction.id, faction);
}
if(syncEnd){
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
}
}
else if(synctype == SyncType.QUEST_CATEGORY){
if(!compound.hasNoTags()){
QuestCategory category = new QuestCategory();
category.readNBT(compound);
QuestController.instance.categoriesSync.put(category.id, category);
}
if(syncEnd){
HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
for(QuestCategory category : QuestController.instance.categoriesSync.values()){
for(Quest quest : category.quests.values()){
quests.put(quest.id, quest);
}
}
QuestController.instance.categories = QuestController.instance.categoriesSync;
QuestController.instance.quests = quests;
QuestController.instance.categoriesSync = new HashMap<Integer, QuestCategory>();
}
}
else if(synctype == SyncType.DIALOG_CATEGORY){
if(!compound.hasNoTags()){
DialogCategory category = new DialogCategory();
category.readNBT(compound);
DialogController.instance.categoriesSync.put(category.id, category);
}
if(syncEnd){
HashMap<Integer,Dialog> dialogs = new HashMap<Integer, Dialog>();
for(DialogCategory category : DialogController.instance.categoriesSync.values()){
for(Dialog dialog : category.dialogs.values()){
dialogs.put(dialog.id, dialog);
}
}
DialogController.instance.categories = DialogController.instance.categoriesSync;
DialogController.instance.dialogs = dialogs;
DialogController.instance.categoriesSync = new HashMap<Integer, DialogCategory>();
}
}
}
public static void clientSyncUpdate(int synctype, NBTTagCompound compound, ByteBuf buffer) {
if(synctype == SyncType.FACTION){
Faction faction = new Faction();
faction.readNBT(compound);
FactionController.getInstance().factions.put(faction.id, faction);
}
else if(synctype == SyncType.DIALOG){
DialogCategory category = DialogController.instance.categories.get(buffer.readInt());
Dialog dialog = new Dialog();
dialog.category = category;
dialog.readNBT(compound);
DialogController.instance.dialogs.put(dialog.id, dialog);
category.dialogs.put(dialog.id, dialog);
}
else if(synctype == SyncType.DIALOG_CATEGORY){
DialogCategory category = new DialogCategory();
category.readNBT(compound);
DialogController.instance.categories.put(category.id, category);
}
else if(synctype == SyncType.QUEST){
QuestCategory category = QuestController.instance.categories.get(buffer.readInt());
Quest quest = new Quest();
quest.category = category;
quest.readNBT(compound);
QuestController.instance.quests.put(quest.id, quest);
category.quests.put(quest.id, quest);
}
else if(synctype == SyncType.QUEST_CATEGORY){
QuestCategory category = new QuestCategory();
category.readNBT(compound);
QuestController.instance.categories.put(category.id, category);
}
}
public static void clientSyncRemove(int synctype, int id) {
if(synctype == SyncType.FACTION){
FactionController.getInstance().factions.remove(id);
}
else if(synctype == SyncType.DIALOG){
Dialog dialog = DialogController.instance.dialogs.remove(id);
if(dialog != null) {
dialog.category.dialogs.remove(id);
}
}
else if(synctype == SyncType.DIALOG_CATEGORY){
DialogCategory category = DialogController.instance.categories.remove(id);
if(category != null) {
DialogController.instance.dialogs.keySet().removeAll(category.dialogs.keySet());
}
}
else if(synctype == SyncType.QUEST){
Quest quest = QuestController.instance.quests.remove(id);
if(quest != null) {
quest.category.quests.remove(id);
}
}
else if(synctype == SyncType.QUEST_CATEGORY){
QuestCategory category = QuestController.instance.categories.remove(id);
if(category != null) {
QuestController.instance.quests.keySet().removeAll(category.quests.keySet());
}
}
}
}
@@ -15,7 +15,7 @@ import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.containers.ContainerNPCBankInterface;
import noppes.npcs.controllers.BankController;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.util.CustomNPCsThreader;
import noppes.npcs.util.CustomNPCsScheduler;
import java.util.HashMap;
@@ -100,16 +100,18 @@ public class BankData {
NoppesUtilServer.sendOpenGui(player, EnumGuiType.PlayerBankSmall, npc, slot, bank.id, 0);
}
final ItemStack item = currency;
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("MaxSlots", bank.getMaxSlots());
compound.setInteger("UnlockedSlots", unlockedSlots);
if (item != null) {
compound.setTag("Currency", NoppesUtilServer.writeItem(item, new NBTTagCompound()));
ContainerNPCBankInterface container = getContainer(player);
if (container != null)
container.setCurrency(item);
}
Server.sendDataChecked((EntityPlayerMP) player, EnumPacketClient.GUI_DATA, compound);
CustomNPCsScheduler.runTack(() -> {
NBTTagCompound compound = new NBTTagCompound();
compound.setInteger("MaxSlots", bank.getMaxSlots());
compound.setInteger("UnlockedSlots", unlockedSlots);
if (item != null) {
compound.setTag("Currency", NoppesUtilServer.writeItem(item, new NBTTagCompound()));
ContainerNPCBankInterface container = getContainer(player);
if (container != null)
container.setCurrency(item);
}
Server.sendDataChecked((EntityPlayerMP) player, EnumPacketClient.GUI_DATA, compound);
}, 300);
}
private ContainerNPCBankInterface getContainer(EntityPlayer player){
Container con = player.openContainer;
@@ -72,19 +72,11 @@ public class DataScript implements IScriptHandler {
this.scriptLanguage = "ECMAScript";
}
}
for (ScriptContainer container : this.scripts.values()) {
container.setEngine(this.getLanguage());
}
enabled = compound.getBoolean("ScriptEnabled");
}
public void readEventsFromNBT(NBTTagCompound compound) {
eventScripts = NBTTags.GetScript(compound,this);
for (ScriptContainer container : this.eventScripts) {
container.setEngine(this.getLanguage());
}
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
@@ -157,6 +149,7 @@ public class DataScript implements IScriptHandler {
ScriptContainer script = scripts.get(type);
if(script == null || script.errored || !script.hasCode())
return false;
script.setEngine(scriptLanguage);
if(script.engine == null)
return false;
for(int i = 0; i + 1 < obs.length; i += 2){
@@ -180,7 +173,7 @@ public class DataScript implements IScriptHandler {
engine.put("npc", dummyNpc);
engine.put("world", dummyWorld);
engine.put("event", event);
engine.put("API", NpcAPI.Instance());
engine.put("API", new NpcAPI());
engine.put("EntityType", entities);
engine.put("RoleType", roles);
engine.put("JobType", jobs);
@@ -5,7 +5,6 @@ import net.minecraft.nbt.NBTTagCompound;
import noppes.npcs.NBTTags;
import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.handler.IPlayerFactionData;
import noppes.npcs.api.handler.data.IFaction;
import noppes.npcs.controllers.FactionController;
import noppes.npcs.controllers.PlayerDataController;
@@ -134,8 +133,8 @@ public class Faction implements IFaction {
}
public int playerStatus(IPlayer player) {
IPlayerFactionData data = player.getData().getFactionData();
int points = data.getPoints(this.id);
PlayerFactionData data = PlayerDataController.instance.getPlayerData((EntityPlayer) player.getMCEntity()).factionData;
int points = data.getFactionPoints(this.id);
if (points >= this.friendlyPoints) {
return 1;
} else {
@@ -46,10 +46,6 @@ public class ForgeDataScript implements IScriptHandler {
}
}
this.enabled = compound.getBoolean("ScriptEnabled");
for (ScriptContainer container : this.scripts) {
container.setEngine(this.getLanguage());
}
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
@@ -49,10 +49,6 @@ public class GlobalNPCDataScript implements IScriptHandler {
}
}
this.enabled = compound.getBoolean("ScriptEnabled");
for (ScriptContainer container : this.scripts) {
container.setEngine(this.getLanguage());
}
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setInteger("TotalScripts",this.scripts.size());
@@ -2,6 +2,7 @@ package noppes.npcs.controllers.data;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
@@ -18,10 +19,11 @@ 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.util.CustomNPCsThreader;
import noppes.npcs.util.CustomNPCsScheduler;
import noppes.npcs.util.NBTJsonUtil;
import java.io.File;
import java.io.FileInputStream;
public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public PlayerDialogData dialogData = new PlayerDialogData(this);
@@ -48,13 +50,33 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
public int companionID = 0;
public boolean isGUIOpen = false;
public boolean updateClient = false;
@Override
public void saveNBTData(NBTTagCompound nbtTagCompound) {
//Do Nothing
}
@Override
public void loadNBTData(NBTTagCompound compound) {
//Do Nothing
}
public void loadPlayerDataFromFile() {
NBTTagCompound data = PlayerDataController.instance.loadPlayerData(player.getPersistentID().toString());
if(data.hasNoTags()){
data = PlayerDataController.instance.loadPlayerDataOld(player.getCommandSenderName());
}
setNBT(data);
}
public NBTTagCompound getSyncNBT(){
NBTTagCompound compound = new NBTTagCompound();
dialogData.saveNBTData(compound);
questData.saveNBTData(compound);
factionData.saveNBTData(compound);
return compound;
}
public void setNBT(NBTTagCompound data){
@@ -126,11 +148,13 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
}
public void setGUIOpen(boolean bool) {
this.isGUIOpen = bool;
isGUIOpen = bool;
save(false);
}
public boolean getGUIOpen() {
return this.isGUIOpen;
loadPlayerDataFromFile();
return isGUIOpen;
}
public boolean hasCompanion(){
@@ -144,7 +168,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
activeCompanion = npc;
if(npc != null)
((RoleCompanion)npc.roleInterface).companionID = companionID;
save();
save(false);
}
public void updateCompanion(World world) {
@@ -166,6 +190,44 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
world.spawnEntityInWorld(npc);
}
public static NBTTagCompound loadPlayerDataOld(String player) {
File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata");
String filename = player;
if (player.isEmpty()) {
filename = "noplayername";
}
filename = filename + ".dat";
File file;
try {
file = new File(saveDir, filename);
if (file.exists()) {
NBTTagCompound comp = CompressedStreamTools.readCompressed(new FileInputStream(file));
file.delete();
file = new File(saveDir, filename + "_old");
if (file.exists()) {
file.delete();
}
return comp;
}
} catch (Exception var6) {
LogWriter.except(var6);
}
try {
file = new File(saveDir, filename + "_old");
if (file.exists()) {
return CompressedStreamTools.readCompressed(new FileInputStream(file));
}
} catch (Exception var5) {
LogWriter.except(var5);
}
return new NBTTagCompound();
}
public static NBTTagCompound loadPlayerData(String player) {
File saveDir = CustomNpcs.getWorldSaveDirectory("playerdata");
String filename = player;
@@ -188,6 +250,25 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
return new NBTTagCompound();
}
public static PlayerData get(EntityPlayer player) {
if(player.worldObj.isRemote) {
return CustomNpcs.proxy.getPlayerData(player);
} else {
PlayerData data = new PlayerData();
if (data.player == null) {
data.player = player;
NBTTagCompound compound = loadPlayerData(player.getPersistentID().toString());
if (compound.hasNoTags()) {
compound = loadPlayerDataOld(player.getCommandSenderName());
}
data.setNBT(compound);
}
return data;
}
}
public void setCompanion(ICustomNpc npc) {
this.setCompanion((EntityNPCInterface) npc.getMCEntity());
}
@@ -228,10 +309,11 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
return mailData;
}
public synchronized void save() {
public synchronized void save(boolean update) {
final NBTTagCompound compound = getNBT();
final String filename = uuid + ".json";
CustomNPCsThreader.playerDataThread.execute(() -> {
CustomNPCsScheduler.runTack(() -> {
try {
File saveDir = PlayerDataController.instance.getSaveDir();
File file = new File(saveDir, filename + "_new");
@@ -244,15 +326,11 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
} catch (Exception e) {
LogWriter.except(e);
}
});
PlayerDataController.instance.putPlayerMap(playername, uuid);
}
public void load() {
NBTTagCompound data = PlayerDataController.instance.loadPlayerData(player.getPersistentID().toString());
if(data.hasNoTags()){
data = PlayerDataController.instance.loadPlayerDataOld(player.getCommandSenderName());
}
setNBT(data);
PlayerDataController.instance.putPlayerMap(playername, uuid);
});
if(update)
updateClient = true;
}
}
@@ -55,10 +55,6 @@ public class PlayerDataScript implements IScriptHandler {
}
}
this.enabled = compound.getBoolean("ScriptEnabled");
for (ScriptContainer container : this.scripts) {
container.setEngine(this.getLanguage());
}
}
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
compound.setInteger("TotalScripts",this.scripts.size());
@@ -48,9 +48,11 @@ public class PlayerDialogData implements IPlayerDialogData {
public void readDialog(int id) {
dialogsRead.add(id);
parent.updateClient = true;
}
public void unreadDialog(int id) {
dialogsRead.remove(id);
parent.updateClient = true;
}
}
@@ -124,6 +124,10 @@ public class PlayerQuestData implements IPlayerQuestData {
QuestInterface inter = data.quest.questInterface;
if(inter.isCompleted(playerData)){
if((!data.isCompleted && data.quest.completion == EnumQuestCompletion.Npc) || data.quest.instantComplete(player,data)){
if (data.quest.completeText.isEmpty() && data.sendAlerts) {
Server.sendData((EntityPlayerMP)player, EnumPacketClient.MESSAGE, "quest.completed", data.quest.title);
Server.sendData((EntityPlayerMP)player, EnumPacketClient.CHAT, "quest.completed",": ",data.quest.title);
}
data.isCompleted = true;
if (data.quest.completion == EnumQuestCompletion.Npc) {
EventHooks.onQuestFinished(player, data.quest);
@@ -171,6 +175,7 @@ public class PlayerQuestData implements IPlayerQuestData {
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);
parent.updateClient = true;
}
public void finishQuest(int id) {
@@ -182,6 +187,8 @@ public class PlayerQuestData implements IPlayerQuestData {
finishedQuests.put(quest.id, System.currentTimeMillis());
else
finishedQuests.put(quest.id, parent.player.worldObj.getTotalWorldTime());
parent.updateClient = true;
}
public void stopQuest(int id) {
@@ -189,6 +196,7 @@ public class PlayerQuestData implements IPlayerQuestData {
if (quest == null)
return;
activeQuests.remove(id);
parent.updateClient = true;
}
public void removeQuest(int id) {
@@ -197,6 +205,7 @@ public class PlayerQuestData implements IPlayerQuestData {
return;
activeQuests.remove(id);
finishedQuests.remove(id);
parent.updateClient = true;
}
public boolean hasFinishedQuest(int id){
@@ -112,7 +112,7 @@ public abstract class MixinModelRenderer {
}
if (ClientEventHandler.renderingPlayer != null && Client.playerAnimations.containsKey(ClientEventHandler.renderingPlayer.getUniqueID())) {
animData = Client.playerAnimations.get(ClientEventHandler.renderingPlayer.getUniqueID());
EnumAnimationPart mainPartType = this.getPlayerPartType((ModelRenderer) (Object) this);
EnumAnimationPart mainPartType = null;
EnumAnimationPart pivotEqualPart = null;
if (mainPartType == null) {
pivotEqualPart = this.pivotEqualPart((ModelRenderer) (Object) this);
@@ -99,13 +99,15 @@ public class QuestDialog extends QuestInterface implements IQuestDialog {
if (progress == 0 && completed) {
data.dialogData.dialogsRead.remove(this.dialog.id);
data.questData.checkQuestCompletion(data, EnumQuestType.values()[1]);
data.save();
data.updateClient = true;
data.save(true);
}
if (progress == 1 && !completed) {
data.dialogData.dialogsRead.add(this.dialog.id);
data.questData.checkQuestCompletion(data, EnumQuestType.values()[1]);
data.save();
data.updateClient = true;
data.save(true);
}
} else {
@@ -146,11 +146,8 @@ public class QuestKill extends QuestInterface implements IQuestKill {
PlayerData data = PlayerDataController.instance.getPlayerData(player);
PlayerQuestData playerdata = data.questData;
QuestData questdata = (QuestData)playerdata.activeQuests.get(this.parent.questId);
if(questdata != null){
HashMap<String, Integer> killed = this.parent.getKilled(questdata);
return !killed.containsKey(this.entity) ? 0 : (Integer)killed.get(this.entity);
}
return 0;
HashMap<String, Integer> killed = this.parent.getKilled(questdata);
return !killed.containsKey(this.entity) ? 0 : (Integer)killed.get(this.entity);
}
public void setProgress(int progress) {
@@ -158,15 +155,13 @@ public class QuestKill extends QuestInterface implements IQuestKill {
PlayerData data = PlayerDataController.instance.getPlayerData(player);
PlayerQuestData playerdata = data.questData;
QuestData questdata = (QuestData)playerdata.activeQuests.get(this.parent.questId);
if(questdata != null){
HashMap<String, Integer> killed = this.parent.getKilled(questdata);
if (!killed.containsKey(this.entity) || (Integer)killed.get(this.entity) != progress) {
killed.put(this.entity, progress);
this.parent.setKilled(questdata, killed);
data.questData.checkQuestCompletion(data, EnumQuestType.values()[2]);
data.questData.checkQuestCompletion(data, EnumQuestType.values()[4]);
data.save();
}
HashMap<String, Integer> killed = this.parent.getKilled(questdata);
if (!killed.containsKey(this.entity) || (Integer)killed.get(this.entity) != progress) {
killed.put(this.entity, progress);
this.parent.setKilled(questdata, killed);
data.questData.checkQuestCompletion(data, EnumQuestType.values()[2]);
data.questData.checkQuestCompletion(data, EnumQuestType.values()[4]);
data.save(true);
}
} else {
throw new CustomNPCsException("Progress has to be between 0 and " + this.amount, new Object[0]);
@@ -166,7 +166,7 @@ public class QuestLocation extends QuestInterface implements IQuestLocation {
if ((!completed || progress != 1) && (completed || progress != 0)) {
questData.extraData.setBoolean(this.nbtName, progress == 1);
data.questData.checkQuestCompletion(data, EnumQuestType.values()[3]);
data.save();
data.save(true);
}
} else {
throw new CustomNPCsException("Progress has to be 0 or 1", new Object[0]);
+6 -15
View File
@@ -74,7 +74,7 @@ public class NpcAPI extends AbstractNpcAPI {
public static final EventBus EVENT_BUS = new EventBus();
private static AbstractNpcAPI instance = null;
private NpcAPI() {
public NpcAPI() {
}
public static void clearCache() {
@@ -248,14 +248,10 @@ public class NpcAPI extends AbstractNpcAPI {
}
public IBlock getIBlock(IWorld world, IPos pos) {
return pos == null ? null : this.getIBlock(world, pos.getX(),pos.getY(),pos.getZ());
return this.getIBlock(world, pos.getX(),pos.getY(),pos.getZ());
}
public ITileEntity getITileEntity(IWorld world, IPos pos) {
if (pos == null) {
return null;
}
TileEntity tileEntity = world.getMCWorld().getTileEntity(pos.getX(), pos.getY(),pos.getZ());
return this.getITileEntity(tileEntity);
}
@@ -286,13 +282,11 @@ public class NpcAPI extends AbstractNpcAPI {
}
public IPos[] getAllInBox(IPos from, IPos to, boolean sortByDistance) {
Iterator<BlockPos> posIterable = BlockPos.getAllInBox(from.getMCPos(),to.getMCPos()).iterator();
ArrayList<IPos> list = new ArrayList<>();
if (from != null && to != null) {
Iterator<BlockPos> posIterable = BlockPos.getAllInBox(from.getMCPos(),to.getMCPos()).iterator();
posIterable.forEachRemaining(BlockPos -> list.add(this.getIPos(BlockPos)));
if (sortByDistance) {
list.sort(Comparator.comparingDouble(pos -> pos.distanceTo(from)));
}
posIterable.forEachRemaining(BlockPos -> list.add(this.getIPos(BlockPos)));
if (sortByDistance) {
list.sort(Comparator.comparingDouble(pos -> pos.distanceTo(from)));
}
return list.toArray(new IPos[0]);
}
@@ -339,9 +333,6 @@ public class NpcAPI extends AbstractNpcAPI {
}
public ICustomNpc<?> spawnNPC(IWorld world, IPos pos) {
if (pos == null) {
return null;
}
return this.spawnNPC(world, pos.getX(), pos.getY(), pos.getZ());
}
@@ -1,9 +1,7 @@
package noppes.npcs.scripted;
import net.minecraft.block.Block;
import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.entity.player.EntityPlayer;
@@ -17,8 +15,6 @@ import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntitySign;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
@@ -524,229 +520,36 @@ public class ScriptWorld implements IWorld {
return this.isBreakCancelled(pos.getX(),pos.getY(),pos.getZ());
}
public MovingObjectPosition func_147447_a(Vec3 startVec, Vec3 endVec, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision)
{
if (!Double.isNaN(startVec.xCoord) && !Double.isNaN(startVec.yCoord) && !Double.isNaN(startVec.zCoord))
{
if (!Double.isNaN(endVec.xCoord) && !Double.isNaN(endVec.yCoord) && !Double.isNaN(endVec.zCoord))
{
int endX = MathHelper.floor_double(endVec.xCoord);
int endY = MathHelper.floor_double(endVec.yCoord);
int endZ = MathHelper.floor_double(endVec.zCoord);
int l = MathHelper.floor_double(startVec.xCoord);
int i1 = MathHelper.floor_double(startVec.yCoord);
int j1 = MathHelper.floor_double(startVec.zCoord);
Block block = this.world.getBlock(l, i1, j1);
int k1 = this.world.getBlockMetadata(l, i1, j1);
if (block.canCollideCheck(k1, false))
{
MovingObjectPosition movingobjectposition = block.collisionRayTrace(this.world, l, i1, j1, startVec, endVec);
if (movingobjectposition != null)
{
return movingobjectposition;
}
}
k1 = 200;
while (k1-- >= 0)
{
if (Double.isNaN(startVec.xCoord) || Double.isNaN(startVec.yCoord) || Double.isNaN(startVec.zCoord))
{
return null;
}
if (l == endX && i1 == endY && j1 == endZ)
{
return null;
}
boolean flag6 = true;
boolean flag3 = true;
boolean flag4 = true;
double d0 = 999.0D;
double d1 = 999.0D;
double d2 = 999.0D;
if (endX > l)
{
d0 = (double)l + 1.0D;
}
else if (endX < l)
{
d0 = (double)l + 0.0D;
}
else
{
flag6 = false;
}
if (endY > i1)
{
d1 = (double)i1 + 1.0D;
}
else if (endY < i1)
{
d1 = (double)i1 + 0.0D;
}
else
{
flag3 = false;
}
if (endZ > j1)
{
d2 = (double)j1 + 1.0D;
}
else if (endZ < j1)
{
d2 = (double)j1 + 0.0D;
}
else
{
flag4 = false;
}
double d3 = 999.0D;
double d4 = 999.0D;
double d5 = 999.0D;
double d6 = endVec.xCoord - startVec.xCoord;
double d7 = endVec.yCoord - startVec.yCoord;
double d8 = endVec.zCoord - startVec.zCoord;
if (flag6)
{
d3 = (d0 - startVec.xCoord) / d6;
}
if (flag3)
{
d4 = (d1 - startVec.yCoord) / d7;
}
if (flag4)
{
d5 = (d2 - startVec.zCoord) / d8;
}
byte b0;
if (d3 < d4 && d3 < d5)
{
if (endX > l)
{
b0 = 4;
}
else
{
b0 = 5;
}
startVec.xCoord = d0;
startVec.yCoord += d7 * d3;
startVec.zCoord += d8 * d3;
}
else if (d4 < d5)
{
if (endY > i1)
{
b0 = 0;
}
else
{
b0 = 1;
}
startVec.xCoord += d6 * d4;
startVec.yCoord = d1;
startVec.zCoord += d8 * d4;
}
else
{
if (endZ > j1)
{
b0 = 2;
}
else
{
b0 = 3;
}
startVec.xCoord += d6 * d5;
startVec.yCoord += d7 * d5;
startVec.zCoord = d2;
}
Vec3 vec32 = Vec3.createVectorHelper(startVec.xCoord, startVec.yCoord, startVec.zCoord);
l = (int)(vec32.xCoord = (double)MathHelper.floor_double(startVec.xCoord));
if (b0 == 5)
{
--l;
++vec32.xCoord;
}
i1 = (int)(vec32.yCoord = (double)MathHelper.floor_double(startVec.yCoord));
if (b0 == 1)
{
--i1;
++vec32.yCoord;
}
j1 = (int)(vec32.zCoord = (double)MathHelper.floor_double(startVec.zCoord));
if (b0 == 3)
{
--j1;
++vec32.zCoord;
}
Block block1 = this.world.getBlock(l, i1, j1);
int l1 = this.world.getBlockMetadata(l, i1, j1);
MovingObjectPosition movingobjectposition1 = block1.collisionRayTrace(this.world, l, i1, j1, startVec, endVec);
if (movingobjectposition1 != null)
{
if (block1.canCollideCheck(l1, false) && stopOnBlock ||
block1.getMaterial().isLiquid() && stopOnLiquid ||
!(block1 instanceof BlockAir) && block1.getCollisionBoundingBoxFromPool(this.world,l,i1,j1) == null && !stopOnCollision)
{
return movingobjectposition1;
}
}
}
return null;
}
else
{
return null;
}
}
else
{
return null;
}
}
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
if (startPos.length != 3 || lookVector.length != 3) {
return null;
}
Vec3 startVec = Vec3.createVectorHelper(startPos[0], startPos[1], startPos[2]);
Vec3 endVec = startVec.addVector(lookVector[0]*maxDistance,lookVector[1]*maxDistance,lookVector[2]*maxDistance);
IPos pos;
Vec3 currentPos = Vec3.createVectorHelper(startPos[0], startPos[1], startPos[2]); int rep = 0;
IPos endPos = NpcAPI.Instance().getIPos(endVec.xCoord,endVec.yCoord,endVec.zCoord);
if (!stopOnBlock && !stopOnLiquid && !stopOnCollision) {
return endPos;
while (rep++ < maxDistance + 10) {
currentPos = currentPos.addVector(lookVector[0], lookVector[1], lookVector[2]);
pos = NpcAPI.Instance().getIPos(currentPos.xCoord, currentPos.yCoord, currentPos.zCoord);
IBlock block = getBlock((int)currentPos.xCoord, (int)currentPos.yCoord, (int)currentPos.zCoord);
if (block != null && stopOnBlock) {
if ((!stopOnLiquid || block.getMCBlock() instanceof BlockLiquid)
&& (!stopOnCollision || block.canCollide()))
return pos;
}
double distance = Math.pow(
Math.pow(currentPos.xCoord-startPos[0],2)
+Math.pow(currentPos.yCoord-startPos[1],2)
+Math.pow(currentPos.zCoord-startPos[2],2)
, 0.5);
if (distance > maxDistance) {
return pos;
}
}
MovingObjectPosition mob = this.func_147447_a(startVec,endVec,stopOnBlock,stopOnLiquid,stopOnCollision);
return mob != null ? NpcAPI.Instance().getIPos(mob.blockX,mob.blockY,mob.blockZ) : endPos;
return null;
}
public IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance) {
@@ -1,5 +1,8 @@
package noppes.npcs.scripted.entity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -9,6 +12,9 @@ import noppes.npcs.api.item.IItemStack;
import noppes.npcs.scripted.CustomNPCsException;
import noppes.npcs.scripted.NpcAPI;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> implements IDBCPlayer {
public T player;
@@ -516,9 +522,8 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
return player.getEntityData().getCompoundTag("PlayerPersisted").getByte("jrmcState2");
}
public double getRacialFormMastery(byte form) {
public double getFormMastery(String formTree, byte form) {
try {
String formTree = this.getRacialTreeName();
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMastery" + formTree)) {
String[] formMasteries = player.getEntityData().getCompoundTag("PlayerPersisted").
getString("jrmcFormMastery" + formTree).split(";");
@@ -529,9 +534,8 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
return 0.0D;
}
public void setRacialFormMastery(byte form, double value) {
public void setFormMastery(String formTree, byte form, double value) {
try {
String formTree = this.getRacialTreeName();
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMastery" + formTree)) {
String[] formMasteries = player.getEntityData().getCompoundTag("PlayerPersisted").
getString("jrmcFormMastery" + formTree).split(";");
@@ -554,9 +558,8 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
} catch (Exception ignored) {}
}
public void addRacialFormMastery(byte form, double value) {
public void addFormMastery(String formTree, byte form, double value) {
try {
String formTree = this.getRacialTreeName();
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMastery" + formTree)) {
String[] formMasteries = player.getEntityData().getCompoundTag("PlayerPersisted").
getString("jrmcFormMastery" + formTree).split(";");
@@ -580,107 +583,6 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
} catch (Exception ignored) {}
}
private String getRacialTreeName() {
switch (this.getRace()) {
case 0:
return "Racial_Human";
case 1:
return "Racial_Saiyan";
case 2:
return "Racial_Half-Saiyan";
case 3:
return "Racial_Namekian";
case 4:
return "Racial_Arcosian";
case 5:
return "Racial_Majin";
}
return "Racial_Human";
}
public double getOtherFormMastery(String formName) {
try {
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMasteryNonRacial")) {
String masteryData = player.getEntityData().getCompoundTag("PlayerPersisted").
getString("jrmcFormMasteryNonRacial");
if (!masteryData.contains(formName)) {
return 0.0D;
}
String[] formMasteries = masteryData.split(";");
for (String masteryString : formMasteries) {
if (masteryString.split(",")[0].equals(formName)) {
return Double.parseDouble(masteryString.split(",")[1]);
}
}
}
} catch (Exception ignored) {}
return 0.0D;
}
public void setOtherFormMastery(String formName, double value) {
try {
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMasteryNonRacial")) {
String masteryData = player.getEntityData().getCompoundTag("PlayerPersisted").
getString("jrmcFormMasteryNonRacial");
if (!masteryData.contains(formName)) {
return;
}
String[] formMasteries = masteryData.split(";");
for (int i = 0; i < formMasteries.length; i++) {
String name = formMasteries[i].split(",")[0];
if (name.equals(formName)) {
formMasteries[i] = name + "," + value;
}
}
StringBuilder masteryString = new StringBuilder();
for (int i = 0; i < formMasteries.length; i++) {
masteryString.append(formMasteries[i]);
if (i < formMasteries.length - 1) {
masteryString.append(';');
}
}
player.getEntityData().getCompoundTag("PlayerPersisted").
setString("jrmcFormMasteryNonRacial", String.valueOf(masteryString));
}
} catch (Exception ignored) {}
}
public void addOtherFormMastery(String formName, double value) {
try {
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMasteryNonRacial")) {
String masteryData = player.getEntityData().getCompoundTag("PlayerPersisted").
getString("jrmcFormMasteryNonRacial");
if (!masteryData.contains(formName)) {
return;
}
String[] formMasteries = masteryData.split(";");
for (int i = 0; i < formMasteries.length; i++) {
String name = formMasteries[i].split(",")[0];
if (name.equals(formName)) {
double newMastery = Double.parseDouble(formMasteries[i].split(",")[1]) + value;
formMasteries[i] = name + "," + newMastery;
}
}
StringBuilder masteryString = new StringBuilder();
for (int i = 0; i < formMasteries.length; i++) {
masteryString.append(formMasteries[i]);
if (i < formMasteries.length - 1) {
masteryString.append(';');
}
}
player.getEntityData().getCompoundTag("PlayerPersisted").
setString("jrmcFormMasteryNonRacial", String.valueOf(masteryString));
}
} catch (Exception ignored) {}
}
public void setPowerPoints(int points){
player.getEntityData().getCompoundTag("PlayerPersisted").setInteger("jrmcArcRsrv",points);
}
@@ -162,7 +162,11 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
}
public IBlock getLookingAtBlock(int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
return NpcAPI.Instance().getIBlock(getWorld(),getLookingAtPos(maxDistance, stopOnBlock, stopOnLiquid, stopOnCollision));
Vec3 lookVec = entity.getLookVec();
return getWorld().rayCastBlock(
new double[] {entity.posX, entity.posY+entity.getEyeHeight(), entity.posZ},
new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord},
maxDistance, stopOnBlock, stopOnLiquid, stopOnCollision);
}
public IBlock getLookingAtBlock(int maxDistance) {
@@ -172,7 +176,7 @@ public class ScriptLivingBase<T extends EntityLivingBase> extends ScriptEntity<T
public IPos getLookingAtPos(int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision) {
Vec3 lookVec = entity.getLookVec();
return getWorld().rayCastPos(
new double[] {entity.posX, entity.posY + entity.getEyeHeight(), entity.posZ},
new double[] {entity.posX, entity.posY+entity.getEyeHeight(), entity.posZ},
new double[] {lookVec.xCoord, lookVec.yCoord, lookVec.zCoord},
maxDistance, stopOnBlock, stopOnLiquid, stopOnCollision);
}
@@ -19,6 +19,7 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
public List<Integer> errored = new ArrayList();
public String scriptLanguage = "ECMAScript";
public boolean enabled = false;
public long lastInited = -1L;
public boolean loaded = false;
public boolean durabilityShow = false;
@@ -42,8 +43,11 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
public float rotationX, rotationY, rotationZ;
public float rotationXRate, rotationYRate, rotationZRate;
public int width = -1, height = -1;
public ScriptCustomItem(ItemStack item) {
super(item);
loadScriptData();
loadItemData();
}
@@ -70,12 +74,16 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
if (!this.loaded) {
this.loadScriptData();
this.loaded = true;
if (type != EnumScriptType.INIT) {
EventHooks.onScriptItemInit(this);
}
}
if (this.isEnabled()) {
if (ScriptController.Instance.lastLoaded > this.lastInited) {
this.lastInited = ScriptController.Instance.lastLoaded;
if (type != EnumScriptType.INIT) {
EventHooks.onScriptItemInit(this);
}
}
for (int i = 0; i < this.scripts.size(); i++) {
ScriptContainer script = this.scripts.get(i);
if (!this.errored.contains(i)) {
@@ -413,18 +421,12 @@ public class ScriptCustomItem extends ScriptItemStack implements IItemCustom, IS
}
c.setTag("ScriptedData", this.getScriptNBT(new NBTTagCompound()));
for (ScriptContainer container : this.scripts) {
container.setEngine(this.getLanguage());
}
}
public void loadScriptData() {
NBTTagCompound c = this.item.getTagCompound();
if (c != null) {
this.setScriptNBT(c.getCompoundTag("ScriptedData"));
for (ScriptContainer container : this.scripts) {
container.setEngine(this.getLanguage());
}
}
}
@@ -1,11 +1,17 @@
package noppes.npcs.util;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class CustomNPCsThreader {
public class CustomNPCsScheduler {
private final static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
public static final Executor playerDataThread = Executors.newSingleThreadExecutor();
public static void runTack(Runnable task, int delay){
executor.schedule(task, delay, TimeUnit.MILLISECONDS);
}
public static void runTack(Runnable task){
executor.schedule(task, 0, TimeUnit.MILLISECONDS);
}
}
@@ -410,13 +410,13 @@ cloner.tagFilters=Tag Filters
cloner.tagVisibility=Tag Visibility
cloner.wandTags=Wand Tags
cloner.npcTags=NPC Tags
cloner.selectedTags=Selected Tags
cloner.order=Sort Order
cloner.ascending=Ascending
cloner.descending=Descending
cloner.type=Sort Type
cloner.name=Name
cloner.date=Date
cloner.wandtags=Wand Tags
cloner.wandtagsapplied=Wand Tags will be applied
tags.allTags=All Tags