diff --git a/src/api b/src/api index a520cc647..c570d20fc 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit a520cc647078e32ba2659e6400d86e95e62036dd +Subproject commit c570d20fc88a4e7fad399866802be6c795d5ff23 diff --git a/src/main/java/foxz/utils/Market.java b/src/main/java/foxz/utils/Market.java index 737ab02fc..461cc9a1c 100644 --- a/src/main/java/foxz/utils/Market.java +++ b/src/main/java/foxz/utils/Market.java @@ -1,58 +1,256 @@ package foxz.utils; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChatComponentText; import noppes.npcs.CustomNpcs; +import noppes.npcs.LogWriter; +import noppes.npcs.config.ConfigMain; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.roles.RoleTrader; +import noppes.npcs.util.CacheHashMap; +import noppes.npcs.util.MarketCachedObject; import noppes.npcs.util.NBTJsonUtil; import java.io.File; +import java.io.FileOutputStream; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import static noppes.npcs.util.CustomNPCsThreader.customNPCThread; public class Market { - static public void save(RoleTrader r, String name) { - if(name.isEmpty()) - return; - File file = getFile(name + "_new"); - File file1 = getFile(name); + private static final CacheHashMap marketCache = new CacheHashMap<>(5 * 60 * 1000, 1 * 60 * 1000); - try { - NBTJsonUtil.SaveFile(file, r.writeNBT(new NBTTagCompound())); - if(file1.exists()){ - file1.delete(); - } - file.renameTo(file1); - } catch (Exception e) { + public static void save(RoleTrader r, String name) { + if(name.isEmpty()) + return; - } + NBTTagCompound roleCompound = r.writeNBT(new NBTTagCompound()); + roleCompound.setString("SaveName", name); + putMarketCache(name, roleCompound); + if(r.recordHistory) + return; + + saveFile(roleCompound); + } + + public static void saveFile(NBTTagCompound compound) { + String name = compound.getString("SaveName"); + File file = getFile(name + "_new"); + File file1 = getFile(name); + customNPCThread.execute(() -> { + try { + if(ConfigMain.MarketDatFormat){ + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(file)); + } else { + NBTJsonUtil.SaveFile(file, compound); + } + if(file1.exists()){ + file1.delete(); + } + file.renameTo(file1); + } catch (Exception e) { + + } + }); + } + + public static void getMarket(RoleTrader role, String name){ + NBTTagCompound data = getMarketCache(name); + if(data != null){ + role.readNBT(data); + return; + } + + load(role, name); + } + + public static NBTTagCompound getMarketCache(final String name) { + synchronized (marketCache) { + if (!marketCache.containsKey(name)) { + return null; + } + return marketCache.get(name).getObject(); + } + } + + public static void putMarketCache(final String name, final NBTTagCompound role) { + synchronized (marketCache) { + marketCache.put(name, new MarketCachedObject(role)); + } } static public void load(RoleTrader role, String name){ - if(role.npc.worldObj.isRemote) - return; - File file = getFile(name); - if(!file.exists()) - return; + if(role.npc.worldObj.isRemote) + return; + File file = getFile(name); + if(!file.exists()) + return; - try { - role.readNBT(NBTJsonUtil.LoadFile(file)); - } catch (Exception e) { - } + try { + if(ConfigMain.MarketDatFormat){ + NBTTagCompound compound = NBTJsonUtil.loadNBTData(file); + role.readNBT(compound); + } + else { + role.readNBT(NBTJsonUtil.LoadFile(file)); + } + } catch (Exception e) { + } } + + public static File getMarketDir(){ + try{ + File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets"); + if(!file.exists()) + file.mkdir(); + return file; + } + catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public static File getNewMarketDir(){ + try{ + File file = new File(CustomNpcs.getWorldSaveDirectory(),"markets_new"); + if(file.exists()){ + return null; + } + file.mkdir(); + return file; + } + catch (Exception e) { + e.printStackTrace(); + return null; + } + } + private static File getFile(String name){ - File dir = new File(CustomNpcs.getWorldSaveDirectory(), "markets"); - if(!dir.exists()) - dir.mkdir(); - return new File(dir, name.toLowerCase() + ".json"); + String filename = name.toLowerCase(); + if(ConfigMain.MarketDatFormat){ + filename += ".dat"; + } else { + filename += ".json"; + } + + return new File(getMarketDir(), filename); } static public void setMarket(EntityNPCInterface npc, String marketName) { - if(marketName.isEmpty()) - return; - if(!getFile(marketName).exists()) - Market.save((RoleTrader) npc.roleInterface, marketName); + if(marketName.isEmpty()) + return; + if(!getFile(marketName).exists()) + Market.save((RoleTrader) npc.roleInterface, marketName); - Market.load((RoleTrader) npc.roleInterface, marketName); + Market.getMarket((RoleTrader) npc.roleInterface, marketName); } + + + public static void convertMarketFiles(final EntityPlayerMP sender, final boolean type){ + ExecutorService executor = Executors.newSingleThreadExecutor(); + executor.execute(() -> { + String fileType; + if(type){ + fileType = ".dat"; + } + else { + fileType = ".json"; + } + + if(sender != null){ + LogWriter.info("Market Conversion queued by " + sender.getCommandSenderName()); + sender.addChatMessage(new ChatComponentText("Market Conversion to " + fileType + " format")); + } + + File dir = getMarketDir(); + LogWriter.info("Converting Market to " + fileType + " format"); + File[] files = dir.listFiles(); // Get an array of all files in the directory + if(files != null){ + int length = files.length; + if(length != 0){ + if(length > 100){ + LogWriter.info("Found " + length + " Market files... This may take a few minutes"); + } + int tenPercent = (int) ((double) length * 0.1); + int progress = 0; + File saveDir = getNewMarketDir(); + if(saveDir == null){ + if(sender != null){ + sender.addChatMessage(new ChatComponentText("markets_new folder already exists please delete it or rename it")); + } + LogWriter.error("markets_new folder already exists please delete it or rename it"); + return; + } + // Load the files in parallel using a stream + for(int i = 0; i < length; i++){ + File file = files[i]; + if(file.isDirectory() || (!file.getName().endsWith(".json") && !file.getName().endsWith(".dat"))) + continue; + try { + String filename = "error"; + boolean valid = false; + NBTTagCompound compound = new NBTTagCompound(); + if(type){ + if(file.getName().endsWith(".json")){ + compound = NBTJsonUtil.LoadFile(file); + if(compound.hasKey("PlayerName")) { + filename = file.getName().substring(0, file.getName().length() - 5); + valid = true; + } + } + } else { + if(file.getName().endsWith(".dat")){ + compound = NBTJsonUtil.loadNBTData(file); + if(compound.hasKey("PlayerName")){ + filename = file.getName().substring(0, file.getName().length() - 4); + valid = true; + } + } + } + if(valid){ + try { + File newFile = new File(saveDir, filename + "_new" + fileType); + File oldFile = new File(saveDir, filename + fileType); + if(type){ + CompressedStreamTools.writeCompressed(compound, new FileOutputStream(newFile)); + } else { + NBTJsonUtil.SaveFile(newFile, compound); + } + if(oldFile.exists()){ + oldFile.delete(); + } + newFile.renameTo(oldFile); + } catch (Exception e) { + LogWriter.except(e); + } + } + } catch (Exception e) { + LogWriter.error("Error loading: " + file.getAbsolutePath(), e); + } + if(tenPercent != 0 ){ + if(progress != 100){ + if (i % tenPercent == 0) { + progress += 10; + LogWriter.info("Converting Market: Progress: " + progress + "%"); + } + } + } + } + } + } + if(sender != null){ + sender.addChatMessage(new ChatComponentText("Market Conversion complete")); + } + LogWriter.info("Market Converted - Please rename the markets_new folder to markets and restart"); + }); + + executor.shutdown(); + } + } diff --git a/src/main/java/kamkeel/command/ConfigCommand.java b/src/main/java/kamkeel/command/ConfigCommand.java index b8d239904..4be014417 100644 --- a/src/main/java/kamkeel/command/ConfigCommand.java +++ b/src/main/java/kamkeel/command/ConfigCommand.java @@ -1,5 +1,6 @@ package kamkeel.command; +import foxz.utils.Market; import net.minecraft.block.Block; import net.minecraft.block.BlockIce; import net.minecraft.block.BlockLeavesBase; @@ -30,7 +31,7 @@ public class ConfigCommand extends CommandKamkeelBase { public String getDescription() { return "Some config things you can set"; } - + @SubCommand( desc = "Disable/Enable the natural leaves decay", usage = "[true/false]", @@ -56,7 +57,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "LeavesDecay is now \u00A7c" + ConfigMain.LeavesDecayEnabled); } } - + @SubCommand( desc = "Disable/Enable the vines growing", usage = "[true/false]", @@ -82,7 +83,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "VineGrowth is now \u00A7c" + ConfigMain.VineGrowthEnabled); } } - + @SubCommand( desc = "Disable/Enable the ice melting", usage = "[true/false]", @@ -127,7 +128,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "GunsEnabled is now \u00A7c" + ConfigMain.GunsEnabled); } } - + @SubCommand( desc = "Freezes/Unfreezes npcs", usage = "[true/false]", @@ -142,7 +143,7 @@ public class ConfigCommand extends CommandKamkeelBase { sendResult(sender, "FrozenNPCs is now \u00A7c" + CustomNpcs.FreezeNPCs); } } - + @SubCommand( desc = "Set number of active chunkloaders", usage = "", @@ -220,7 +221,54 @@ public class ConfigCommand extends CommandKamkeelBase { PlayerDataController.Instance.convertPlayerFiles(send, convertToDat); } } - + + @SubCommand( + desc = "Generate Market to JSON/DAT", + usage = "[fileType] [convert]", + permission = 4 + ) + public void market(ICommandSender sender, String[] args) throws CommandException{ + String fileType; + if(ConfigMain.MarketDatFormat){ + fileType = "DAT"; + } + else { + fileType = "JSON"; + } + if(args.length == 0){ + sendResult(sender, "Market Filetype: \u00A7c" + fileType); + } + else if(args.length == 1){ + sendResult(sender, "Please write the word 'convert' at the end to confirm. \u00A7c convert"); + } + else{ + if(args.length != 2){ + sendError(sender, "Two many arguments"); + return; + } + String formatType = args[0].toLowerCase(); + if(!formatType.equals("dat") && !formatType.equals("json")){ + sendError(sender, "Invalid Format Type - Please use dat or json"); + return; + } + + String convert = args[1].toLowerCase(); + if(!convert.equals("convert")){ + sendError(sender, "Please enter the word 'convert' at the end"); + return; + } + + boolean convertToDat = formatType.equals("dat"); + EntityPlayerMP send = null; + if(sender instanceof EntityPlayerMP){ + send = (EntityPlayerMP) sender; + } + + sendResult(sender, "Started Conversion Process for Market"); + Market.convertMarketFiles(send, convertToDat); + } + } + @SubCommand( desc = "Get/Set font", usage = "[type] [size]", @@ -236,7 +284,7 @@ public class ConfigCommand extends CommandKamkeelBase { args = Arrays.copyOfRange(args, 0, args.length - 1); } catch(Exception e){ - + } } String font = ""; @@ -245,6 +293,6 @@ public class ConfigCommand extends CommandKamkeelBase { } Server.sendData((EntityPlayerMP)sender, EnumPacketClient.CONFIG, 0, font.trim(), size); } - + } diff --git a/src/main/java/noppes/npcs/CustomNpcsPermissions.java b/src/main/java/noppes/npcs/CustomNpcsPermissions.java index 124c747eb..071e63a51 100644 --- a/src/main/java/noppes/npcs/CustomNpcsPermissions.java +++ b/src/main/java/noppes/npcs/CustomNpcsPermissions.java @@ -57,6 +57,7 @@ public class CustomNpcsPermissions{ public static final Permission TOOL_SCRIPTER = new Permission("customnpcs.tool.scripter"); public static final Permission TOOL_CLONER = new Permission("customnpcs.tool.cloner"); public static final Permission TOOL_SCRIPTED_ITEM = new Permission("customnpcs.tool.scripteditem"); + public static final Permission TOOL_TELEPORTER = new Permission("customnpcs.tool.teleporter"); // Edit Villager public static final Permission EDIT_VILLAGER = new Permission("customnpcs.edit.villager"); diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 33f9c3971..7353af13c 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -85,6 +85,11 @@ public class EventHooks { return NpcAPI.EVENT_BUS.post(event); } + public static boolean onScriptItemRightClick(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.RightClickEvent event) { + ((ScriptCustomItem) handler).callScript(EnumScriptType.RIGHT_CLICK, event); + return NpcAPI.EVENT_BUS.post(event); + } + public static boolean onScriptItemAttack(IItemCustom handler, noppes.npcs.scripted.event.ItemEvent.AttackEvent event) { ((ScriptCustomItem) handler).callScript(EnumScriptType.ATTACK, event); return NpcAPI.EVENT_BUS.post(event); diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index ab8f84363..06745b2b6 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -23,6 +23,7 @@ import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.config.ConfigMain; import noppes.npcs.constants.EnumGuiType; @@ -40,6 +41,7 @@ import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptSound; import noppes.npcs.scripted.event.DialogEvent; +import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.File; @@ -706,6 +708,12 @@ public class NoppesUtilServer { Server.sendData(player, EnumPacketClient.CLONER, x, y, z); } + public static void setTeleporterGUI(EntityPlayerMP player){ + if(player == null) + return; + Server.sendData(player, EnumPacketClient.TELEPORTER); + } + public static void setRecipeGui(EntityPlayerMP player, RecipeCarpentry recipe){ if(recipe == null) return; @@ -856,6 +864,18 @@ public class NoppesUtilServer { return null; } + public static Entity getEntityFromUUID(World world, UUID uuid) { + for (Object obj : world.loadedEntityList) { + if (obj instanceof Entity) { + Entity entity = (Entity) obj; + if (entity.getUniqueID().equals(uuid)) { + return entity; + } + } + } + return null; + } + static public EntityPlayer getPlayerByName(String playername){ return MinecraftServer.getServer().getConfigurationManager().func_152612_a(playername); } diff --git a/src/main/java/noppes/npcs/PacketHandlerPlayer.java b/src/main/java/noppes/npcs/PacketHandlerPlayer.java index 40924001f..db61d455d 100644 --- a/src/main/java/noppes/npcs/PacketHandlerPlayer.java +++ b/src/main/java/noppes/npcs/PacketHandlerPlayer.java @@ -3,6 +3,9 @@ package noppes.npcs; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; import io.netty.buffer.ByteBuf; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.ItemEditableBook; @@ -25,9 +28,10 @@ import noppes.npcs.roles.RoleCompanion; import java.io.IOException; import java.util.Iterator; +import java.util.UUID; public class PacketHandlerPlayer{ - + @SubscribeEvent public void onServerPacket(ServerCustomPacketEvent event) { EntityPlayerMP player = ((NetHandlerPlayServer)event.handler).playerEntity; @@ -40,7 +44,17 @@ public class PacketHandlerPlayer{ } private void player(ByteBuf buffer, EntityPlayerMP player, EnumPlayerPacket type) throws IOException { - if(type == EnumPlayerPacket.CompanionTalentExp){ + if(type == EnumPlayerPacket.MarkData){ + String uuid = Server.readString(buffer); + if(uuid == null) + return; + + Entity entity = NoppesUtilServer.getEntityFromUUID(player.worldObj, UUID.fromString(uuid)); + if(!(entity instanceof EntityNPCInterface)) + return; + MarkData data = MarkData.get((EntityNPCInterface) entity); + } + else if(type == EnumPlayerPacket.CompanionTalentExp){ EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player); if(npc == null || npc.advanced.role != EnumRoleType.Companion || player != npc.getOwner()) return; @@ -202,7 +216,7 @@ public class PacketHandlerPlayer{ long time = buffer.readLong(); String username = Server.readString(buffer); PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData; - + Iterator it = data.playermail.iterator(); while(it.hasNext()){ PlayerMail mail = it.next(); @@ -220,7 +234,7 @@ public class PacketHandlerPlayer{ NoppesUtilServer.sendGuiError(player, 0); return; } - + PlayerMail mail = new PlayerMail(); //String s = player.func_145748_c_().getFormattedText(); String s = player.getDisplayName(); @@ -235,7 +249,7 @@ public class PacketHandlerPlayer{ return; } PlayerDataController.Instance.addPlayerMessage(username, mail); - + NBTTagCompound comp = new NBTTagCompound(); comp.setString("username", username); NoppesUtilServer.sendGuiClose(player, 1,comp); @@ -245,7 +259,7 @@ public class PacketHandlerPlayer{ String username = Server.readString(buffer); player.closeContainer(); PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData; - + Iterator it = data.playermail.iterator(); while(it.hasNext()){ PlayerMail mail = it.next(); @@ -260,7 +274,7 @@ public class PacketHandlerPlayer{ long time = buffer.readLong(); String username = Server.readString(buffer); PlayerMailData data = PlayerDataController.Instance.getPlayerData(player).mailData; - + Iterator it = data.playermail.iterator(); while(it.hasNext()){ PlayerMail mail = it.next(); diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 7b922dee2..5df65423f 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -1000,6 +1000,11 @@ public class PacketHandlerServer{ npc.updateAI = true; npc.updateClient = true; } + else if(type == EnumPacketServer.MainmenuAdvancedMarkData){ + MarkData data = MarkData.get(npc); + data.setNBT(Server.readNBT(buffer)); + data.syncClients(); + } else if(type == EnumPacketServer.JobSave){ NBTTagCompound original = npc.jobInterface.writeToNBT(new NBTTagCompound()); NBTTagCompound compound = Server.readNBT(buffer); @@ -1094,13 +1099,14 @@ public class PacketHandlerServer{ } else if(type == EnumPacketServer.TraderMarketSave){ String market = Server.readString(buffer); + if(market == null) + return; boolean bo = buffer.readBoolean(); if(npc.roleInterface instanceof RoleTrader){ if(bo) Market.setMarket(npc, market); else Market.save((RoleTrader)npc.roleInterface, market); - //NoppesUtilServer.sendRoleData(player, npc); } } else if(type == EnumPacketServer.AnimationsGet){ diff --git a/src/main/java/noppes/npcs/ScriptItemEventHandler.java b/src/main/java/noppes/npcs/ScriptItemEventHandler.java index c2014b23a..2d7b3cafc 100644 --- a/src/main/java/noppes/npcs/ScriptItemEventHandler.java +++ b/src/main/java/noppes/npcs/ScriptItemEventHandler.java @@ -10,10 +10,15 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.player.EntityInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.entity.player.PlayerUseItemEvent; +import noppes.npcs.api.IWorld; import noppes.npcs.api.entity.IPlayer; import noppes.npcs.api.item.IItemCustom; import noppes.npcs.api.item.IItemStack; +import noppes.npcs.controllers.PlayerDataController; +import noppes.npcs.controllers.data.PlayerData; +import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.items.ItemScripted; import noppes.npcs.scripted.NpcAPI; @@ -103,6 +108,44 @@ public class ScriptItemEventHandler { IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); ItemEvent.InteractEvent eve = new ItemEvent.InteractEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIEntity(event.target)); event.setCanceled(EventHooks.onScriptItemInteract(isw, eve)); + + ItemEvent.RightClickEvent rightClickEvent = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 1, NpcAPI.Instance().getIEntity(event.target)); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, rightClickEvent)); + } + } catch(Exception e) {} + } + } + + @SubscribeEvent + public void invoke(PlayerInteractEvent event) { + if(event.entityPlayer == null || event.entityPlayer.worldObj == null || event.action == null) + return; + + if(event.entityPlayer.worldObj.isRemote && event.entityPlayer.worldObj instanceof WorldServer) + return; + + if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_AIR){ + PlayerDataScript handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer).scriptData; + if(handler.hadInteract) { + handler.hadInteract = false; + return; + } + try { + if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { + IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); + ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 0, null); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); + } + } catch(Exception e) {} + } + else if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK){ + PlayerDataScript handler = PlayerDataController.Instance.getPlayerData(event.entityPlayer).scriptData; + handler.hadInteract = true; + try { + if (event.entityPlayer.getHeldItem().getItem() == CustomItems.scripted_item && !event.isCanceled()) { + IItemCustom isw = ItemScripted.GetWrapper(event.entityPlayer.getHeldItem()); + ItemEvent.RightClickEvent eve = new ItemEvent.RightClickEvent(isw, (IPlayer) NpcAPI.Instance().getIEntity(event.entityPlayer), 2, NpcAPI.Instance().getIBlock((IWorld) NpcAPI.Instance().getIWorld(event.world), event.x, event.y, event.z)); + event.setCanceled(EventHooks.onScriptItemRightClick(isw, eve)); } } catch(Exception e) {} } diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 22f00c34a..f46d562ef 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -403,4 +403,15 @@ public class ServerEventsHandler { public void populateChunk(PopulateChunkEvent.Post event){ NPCSpawning.performWorldGenSpawning(event.world, event.chunkX, event.chunkZ, event.rand); } + + @SubscribeEvent + public void playerTracking(PlayerEvent.StartTracking event){ + if(!(event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote) + return; + + MarkData data = MarkData.get((EntityNPCInterface) event.target); + if(data.marks.isEmpty()) + return; + Server.sendData((EntityPlayerMP)event.entityPlayer, EnumPacketClient.MARK_DATA, event.target.getEntityId(), data.getNBT()); + } } diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index c30f02180..ab42f1f97 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -15,11 +15,14 @@ import net.minecraftforge.client.event.RenderLivingEvent; import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.event.entity.living.LivingEvent; import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.renderer.MarkRenderer; import noppes.npcs.client.renderer.RenderCNPCPlayer; import noppes.npcs.constants.EnumAnimationPart; +import noppes.npcs.constants.MarkType; import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; import noppes.npcs.controllers.data.FramePart; +import noppes.npcs.controllers.data.MarkData; import noppes.npcs.entity.EntityNPCInterface; import java.lang.reflect.Field; @@ -93,6 +96,16 @@ public class ClientEventHandler { AnimationData data = null; if (event.entity instanceof EntityNPCInterface) { data = ClientEventHandler.renderingNpc.display.animationData; + + MarkData markData = MarkData.get((EntityNPCInterface) event.entity); + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + for(MarkData.Mark m : markData.marks){ + if(m.getType() != MarkType.NONE && m.availability.isAvailable(player)){ + MarkRenderer.render(event.entity, event.x, event.y, event.z, m); + break; + } + } + } else if (event.entity instanceof EntityPlayer) { if (ClientCacheHandler.playerAnimations.containsKey(event.entity.getUniqueID())) { data = ClientCacheHandler.playerAnimations.get(event.entity.getUniqueID()); @@ -118,6 +131,7 @@ public class ClientEventHandler { animation.increaseTime(); } } + ClientEventHandler.renderingNpc = null; } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index caec4c6b8..609e9d7b4 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -8,6 +8,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.achievement.GuiAchievement; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -35,6 +36,7 @@ import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.controllers.RecipeController; import noppes.npcs.controllers.data.Animation; import noppes.npcs.controllers.data.AnimationData; +import noppes.npcs.controllers.data.MarkData; import noppes.npcs.controllers.data.RecipeCarpentry; import noppes.npcs.entity.EntityDialogNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -103,6 +105,13 @@ public class PacketHandlerClient extends PacketHandlerServer{ RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes; RecipeController.syncRecipes = new HashMap(); } + else if(type == EnumPacketClient.MARK_DATA){ + Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt()); + if(!(entity instanceof EntityNPCInterface)) + return; + MarkData data = MarkData.get((EntityNPCInterface) entity); + data.setNBT(Server.readNBT(buffer)); + } else if(type == EnumPacketClient.DIALOG){ Entity entity = Minecraft.getMinecraft().theWorld.getEntityByID(buffer.readInt()); if(entity == null || !(entity instanceof EntityNPCInterface)) @@ -200,6 +209,9 @@ public class PacketHandlerClient extends PacketHandlerServer{ int y = buffer.readInt(); int z = buffer.readInt(); CustomNpcs.proxy.openGui(x, y, z, EnumGuiType.MobSpawner, player); + } + else if(type == EnumPacketClient.TELEPORTER){ + CustomNpcs.proxy.openGui((EntityNPCInterface)null,EnumGuiType.NpcDimensions); } else if(type == EnumPacketClient.GUI_DATA){ GuiScreen gui = Minecraft.getMinecraft().currentScreen; diff --git a/src/main/java/noppes/npcs/client/controllers/MusicController.java b/src/main/java/noppes/npcs/client/controllers/MusicController.java index 51e80971c..c3b7f146c 100644 --- a/src/main/java/noppes/npcs/client/controllers/MusicController.java +++ b/src/main/java/noppes/npcs/client/controllers/MusicController.java @@ -1,28 +1,25 @@ package noppes.npcs.client.controllers; import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.audio.SoundCategory; import net.minecraft.client.audio.SoundHandler; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; public class MusicController { - //public TreeSet sounds = new TreeSet(); - //public TreeSet music = new TreeSet(); - + public static MusicController Instance; public PositionedSoundRecord playing; public ResourceLocation playingResource; public Entity playingEntity; - //private SoundPoolEntry musicPool; - public MusicController(){ Instance = this; } - public void stopMusic(){ SoundHandler handler = Minecraft.getMinecraft().getSoundHandler(); if(playing != null) @@ -32,9 +29,9 @@ public class MusicController { playingEntity = null; playing = null; } - + public void playStreaming(String music, Entity entity){ - if(isPlaying(music)){ + if(isPlaying(music)){ return; } stopMusic(); @@ -57,7 +54,7 @@ public class MusicController { playing = PositionedSoundRecord.func_147673_a(playingResource); handler.playSound(playing); } - + public boolean isPlaying(String music) { ResourceLocation resource = new ResourceLocation(music); @@ -66,7 +63,7 @@ public class MusicController { } return Minecraft.getMinecraft().getSoundHandler().isSoundPlaying(playing); } - + public void playSound(String music, float x, float y, float z) { Minecraft.getMinecraft().theWorld.playSound(x, y, z, music, 1, 1, false); } diff --git a/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java b/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java index 790d0b535..ad743701b 100644 --- a/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java +++ b/src/main/java/noppes/npcs/client/gui/GuiNPCDialogSelection.java @@ -26,15 +26,15 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat title = "Select Dialog Category"; this.parent = parent; this.dialog = dialog; - - + + if(dialog >= 0){ Client.sendData(EnumPacketServer.DialogsGetFromDialog, dialog); selectCategory = false; title = "Select Dialog"; }else Client.sendData(EnumPacketServer.DialogCategoriesGet, dialog); - + if(parent instanceof GuiSelectionListener){ listener = (GuiSelectionListener) parent; } @@ -48,7 +48,6 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat slot = new GuiNPCStringSlot(list,this,false,18); slot.registerScrollButtons(4, 5); - this.addButton(new GuiNpcButton(2, width / 2 -100, height - 41,98, 20, "gui.back")); this.addButton(new GuiNpcButton(4, width / 2 + 2, height - 41,98, 20, "gui.select")); } @@ -92,7 +91,7 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat close(); NoppesUtil.openGUI(player, parent); } - + } public void save() { if(dialog >= 0){ @@ -113,7 +112,7 @@ public class GuiNPCDialogSelection extends GuiNPCInterface implements IScrollDat @Override public void setSelected(String selected) { - + } diff --git a/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java new file mode 100644 index 000000000..1be2ab503 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/advanced/GuiNPCMarks.java @@ -0,0 +1,84 @@ +package noppes.npcs.client.gui.advanced; + +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.client.Client; +import noppes.npcs.client.gui.SubGuiColorSelector; +import noppes.npcs.client.gui.SubGuiNpcAvailability; +import noppes.npcs.client.gui.util.*; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.constants.MarkType; +import noppes.npcs.controllers.data.MarkData; +import noppes.npcs.entity.EntityNPCInterface; + +public class GuiNPCMarks extends GuiNPCInterface2 implements ISubGuiListener { + private final String[] marks = new String[]{"gui.none", "mark.question", "mark.exclamation", "mark.pointer", "mark.skull", "mark.cross", "mark.star"}; + private MarkData data; + private MarkData.Mark selectedMark; + + public GuiNPCMarks(EntityNPCInterface npc){ + super(npc); + this.data = MarkData.get(npc); + } + + @Override + public void initGui(){ + super.initGui(); + int y = guiTop + 14; + for(int i = 0; i < data.marks.size(); i++){ + MarkData.Mark mark = data.marks.get(i); + this.addButton(new GuiButtonBiDirectional(1 + i * 10, guiLeft + 6, y, 120, 20, marks, mark.type)); + + String color = Integer.toHexString(mark.color); + while(color.length() < 6) + color = "0" + color; + addButton(new GuiNpcButton(2 + i * 10, guiLeft + 128, y, 60, 20, color)); + getButton(2 + i * 10).setTextColor(mark.color); + + this.addButton(new GuiNpcButton(3 + i * 10, guiLeft + 190, y, 120, 20, "availability.options")); + this.addButton(new GuiNpcButton(4 + i * 10, guiLeft + 312, y, 40, 20, "X")); + y += 22; + } + + if(data.marks.size() < 9){ + this.addButton(new GuiNpcButton(101 , guiLeft + 6, y + 2, 60, 20, "gui.add")); + } + } + + @Override + public void buttonEvent(GuiButton button){ + if(button.id < 90){ + selectedMark = data.marks.get(button.id / 10); + if(button.id % 10 == 1){ + selectedMark.type = ((GuiNpcButton)button).getValue(); + } + if(button.id % 10 == 2){ + this.setSubGui(new SubGuiColorSelector(selectedMark.color)); + } + if(button.id % 10 == 3){ + setSubGui(new SubGuiNpcAvailability(selectedMark.availability)); + } + if(button.id % 10 == 4){ + data.marks.remove(selectedMark); + initGui(); + } + } + if(button.id == 101){ + data.addMark(MarkType.NONE); + initGui(); + } + } + + @Override + public void subGuiClosed(SubGuiInterface subgui) { + if(subgui instanceof SubGuiColorSelector){ + selectedMark.color = ((SubGuiColorSelector)subgui).color; + initGui(); + } + } + + @Override + public void save() { + Client.sendData(EnumPacketServer.MainmenuAdvancedMarkData, data.getNBT()); + } + +} diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java index 84ce86992..51ff99278 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNpcAdvanced.java @@ -45,7 +45,9 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData this.addButton(new GuiNpcButton(12, guiLeft + 85, y += gap, 214, 20, "advanced.night")); this.addButton(new GuiNpcButton(13, guiLeft + 85, y += gap, 214, 20, "global.linked")); this.addButton(new GuiNpcButton(14, guiLeft + 85, y += gap, 214, 20, "menu.tags")); - + + // FIX THIS KAM + this.addButton(new GuiNpcButton(15, guiLeft + 208, y, 190, 20, "advanced.marks")); } @Override @@ -68,7 +70,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData if(button.id == 5){ hasChanges = true; npc.advanced.setJob(button.getValue()); - + getButton(4).setEnabled(npc.advanced.job != EnumJobType.None && npc.advanced.job != EnumJobType.ChunkLoader); } if(button.id == 9){ @@ -99,6 +101,10 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData save(); NoppesUtil.openGUI(player, new GuiNPCTagSetup(npc)); } + if(button.id == 15){ + save(); + NoppesUtil.openGUI(player, new GuiNPCMarks(npc)); + } } @Override @@ -106,7 +112,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData if(compound.hasKey("RoleData")){ if(npc.roleInterface != null) npc.roleInterface.readFromNBT(compound); - + if(npc.advanced.role == EnumRoleType.Trader) NoppesUtil.requestOpenGUI(EnumGuiType.SetupTrader); else if(npc.advanced.role == EnumRoleType.Follower) @@ -121,7 +127,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData else if(compound.hasKey("JobData")){ if(npc.jobInterface != null) npc.jobInterface.readFromNBT(compound); - + if(npc.advanced.job == EnumJobType.Bard) NoppesUtil.openGUI(player, new GuiNpcBard(npc)); else if(npc.advanced.job == EnumJobType.Healer) @@ -142,7 +148,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData initGui(); } } - + @Override public void save() { if(hasChanges){ @@ -150,6 +156,6 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData hasChanges = false; } } - + } diff --git a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java index e2001ef10..78e8f1406 100644 --- a/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java +++ b/src/main/java/noppes/npcs/client/gui/questtypes/GuiNpcQuestTypeDialog.java @@ -20,25 +20,24 @@ import java.util.HashMap; public class GuiNpcQuestTypeDialog extends SubGuiInterface implements GuiSelectionListener, IGuiData { private GuiScreen parent; - private QuestDialog quest; - + private HashMap data = new HashMap(); public GuiNpcQuestTypeDialog(EntityNPCInterface npc, Quest q, GuiScreen parent) { this.npc = npc; this.parent = parent; title = "Quest Dialog Setup"; - + quest = (QuestDialog) q.questInterface; setBackground("menubg.png"); xSize = 256; ySize = 216; closeOnEsc = true; - Client.sendData(EnumPacketServer.QuestDialogGetTitle, - quest.dialogs.containsKey(0)?quest.dialogs.get(0):-1, - quest.dialogs.containsKey(1)?quest.dialogs.get(1):-1, + Client.sendData(EnumPacketServer.QuestDialogGetTitle, + quest.dialogs.containsKey(0)?quest.dialogs.get(0):-1, + quest.dialogs.containsKey(1)?quest.dialogs.get(1):-1, quest.dialogs.containsKey(2)?quest.dialogs.get(2):-1); } @@ -48,12 +47,12 @@ public class GuiNpcQuestTypeDialog extends SubGuiInterface implements GuiSelecti String title = "dialog.selectoption"; if(data.containsKey(i)) title = data.get(i); - this.addButton(new GuiNpcButton(i + 9, guiLeft + 10, 55 + i * 22, 20, 20, "X")); - this.addButton(new GuiNpcButton(i + 3, guiLeft + 34, 55 + i * 22, 210, 20, title)); + this.addButton(new GuiNpcButton(i + 9, guiLeft + 10, guiTop + 55 + i * 22, 20, 20, "X")); + this.addButton(new GuiNpcButton(i + 3, guiLeft + 34, guiTop + 55 + i * 22, 210, 20, title)); } this.addButton(new GuiNpcButton(0, guiLeft + 150, guiTop + 190, 98, 20, "gui.back")); - + } private int selectedSlot; @@ -67,9 +66,10 @@ public class GuiNpcQuestTypeDialog extends SubGuiInterface implements GuiSelecti int id = -1; if(quest.dialogs.containsKey(selectedSlot)) id = quest.dialogs.get(selectedSlot); - GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, parent, id); - gui.listener = this; - NoppesUtil.openGUI(player, gui); + + GuiNPCDialogSelection gui = new GuiNPCDialogSelection(npc, getParent(), id); + gui.listener = this; + NoppesUtil.openGUI(player, gui); } if (button.id >= 9 && button.id < 15) { int slot = button.id - 9; diff --git a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java index 812a7721f..067699b70 100644 --- a/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java +++ b/src/main/java/noppes/npcs/client/gui/roles/GuiNpcTraderSetup.java @@ -14,17 +14,17 @@ import noppes.npcs.roles.RoleTrader; import org.lwjgl.opengl.GL11; public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITextfieldListener{ - + private final ResourceLocation slot = new ResourceLocation("customnpcs","textures/gui/slot.png"); private RoleTrader role; - + public GuiNpcTraderSetup(EntityNPCInterface npc, ContainerNPCTraderSetup container){ super(npc, container); ySize = 220; menuYOffset = 10; role = container.role; } - + @Override public void initGui(){ super.initGui(); @@ -35,9 +35,12 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex addLabel(new GuiNpcLabel(1, "gui.ignoreDamage", guiLeft + 260, guiTop + 29)); addButton(new GuiNpcButtonYesNo(1, guiLeft + 340, guiTop + 24, role.ignoreDamage)); - + addLabel(new GuiNpcLabel(2, "gui.ignoreNBT", guiLeft + 260, guiTop + 51)); addButton(new GuiNpcButtonYesNo(2, guiLeft + 340, guiTop + 46, role.ignoreNBT)); + + addLabel(new GuiNpcLabel(3, "gui.recordHistory", guiLeft + 260, guiTop + 73)); + addButton(new GuiNpcButtonYesNo(3, guiLeft + 340, guiTop + 68, role.recordHistory)); } @Override @@ -55,6 +58,9 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex if(guibutton.id == 2){ role.ignoreNBT = ((GuiNpcButtonYesNo)guibutton).getBoolean(); } + if(guibutton.id == 3){ + role.recordHistory = ((GuiNpcButtonYesNo)guibutton).getBoolean(); + } } @Override @@ -69,20 +75,20 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex GL11.glColor4f(1, 1, 1, 1); drawTexturedModalRect(x - 1, y, 0, 0, 18, 18); drawTexturedModalRect(x + 17, y, 0, 0, 18, 18); - + fontRendererObj.drawString("=", x + 36, y + 5, CustomNpcResourceListener.DefaultTextColor); mc.renderEngine.bindTexture(this.slot); GL11.glColor4f(1, 1, 1, 1); drawTexturedModalRect(x + 42, y, 0, 0, 18, 18); } } - + @Override public void save() { Client.sendData(EnumPacketServer.TraderMarketSave, role.marketName, false); Client.sendData(EnumPacketServer.RoleSave, role.writeToNBT(new NBTTagCompound())); } - + @Override public void unFocused(GuiNpcTextField guiNpcTextField) { String name = guiNpcTextField.getText(); @@ -90,6 +96,6 @@ public class GuiNpcTraderSetup extends GuiContainerNPCInterface2 implements ITex role.marketName = name; Client.sendData(EnumPacketServer.TraderMarketSave, role.marketName, true); } - + } } diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java index ef5f41c01..395497a77 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptItem.java @@ -17,6 +17,7 @@ public class GuiScriptItem extends GuiScriptInterface { hookList.add("pickedUp"); hookList.add("spawn"); hookList.add("interact"); + hookList.add("rightClick"); hookList.add("attack"); hookList.add("startItem"); hookList.add("usingItem"); @@ -37,4 +38,4 @@ public class GuiScriptItem extends GuiScriptInterface { super.save(); Client.sendData(EnumPacketServer.ScriptItemDataSave, new Object[]{this.item.getMCNbt()}); } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java index 0cb4d163e..7dfa4b4dc 100644 --- a/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java +++ b/src/main/java/noppes/npcs/client/model/util/Model2DRenderer.java @@ -88,4 +88,81 @@ public class Model2DRenderer extends ModelRenderer { GL11.glEndList(); this.compiledModel = true; } + + public static void renderItemIn2D(float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, int p_78439_5_, int p_78439_6_, float p_78439_7_) { + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, 1.0F); + tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, p_78439_1_, p_78439_4_); + tessellator.addVertexWithUV(1.0D, 0.0D, 0.0D, p_78439_3_, p_78439_4_); + tessellator.addVertexWithUV(1.0D, 1.0D, 0.0D, p_78439_3_, p_78439_2_); + tessellator.addVertexWithUV(0.0D, 1.0D, 0.0D, p_78439_1_, p_78439_2_); + tessellator.draw(); + + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 0.0F, -1.0F); + tessellator.addVertexWithUV(0.0D, 1.0D, 0.0F - p_78439_7_, p_78439_1_, p_78439_2_); + tessellator.addVertexWithUV(1.0D, 1.0D, 0.0F - p_78439_7_, p_78439_3_, p_78439_2_); + tessellator.addVertexWithUV(1.0D, 0.0D, 0.0F - p_78439_7_, p_78439_3_, p_78439_4_); + tessellator.addVertexWithUV(0.0D, 0.0D, 0.0F - p_78439_7_, p_78439_1_, p_78439_4_); + tessellator.draw(); + + float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / (float) p_78439_5_; + float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / (float) p_78439_6_; + + tessellator.startDrawingQuads(); + tessellator.setNormal(-1.0F, 0.0F, 0.0F); + + for (int k = 0; k < p_78439_5_; ++k) { + float f7 = (float) k / (float) p_78439_5_; + float f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + tessellator.addVertexWithUV(f7, 0.0D, 0.0F - p_78439_7_, f8, p_78439_4_); + tessellator.addVertexWithUV(f7, 0.0D, 0.0D, f8, p_78439_4_); + tessellator.addVertexWithUV(f7, 1.0D, 0.0D, f8, p_78439_2_); + tessellator.addVertexWithUV(f7, 1.0D, 0.0F - p_78439_7_, f8, p_78439_2_); + } + + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(1.0F, 0.0F, 0.0F); + + for (int k = 0; k < p_78439_5_; ++k) { + float f7 = (float) k / (float) p_78439_5_; + float f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + float f9 = f7 + 1.0F / (float) p_78439_5_; + tessellator.addVertexWithUV(f9, 1.0D, 0.0F - p_78439_7_, f8, p_78439_2_); + tessellator.addVertexWithUV(f9, 1.0D, 0.0D, f8, p_78439_2_); + tessellator.addVertexWithUV(f9, 0.0D, 0.0D, f8, p_78439_4_); + tessellator.addVertexWithUV(f9, 0.0D, 0.0F - p_78439_7_, f8, p_78439_4_); + } + + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, 1.0F, 0.0F); + + for (int k = 0; k < p_78439_6_; ++k) { + float f7 = (float) k / (float) p_78439_6_; + float f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + float f9 = f7 + 1.0F / (float) p_78439_6_; + tessellator.addVertexWithUV(0.0D, f9, 0.0D, p_78439_1_, f8); + tessellator.addVertexWithUV(1.0D, f9, 0.0D, p_78439_3_, f8); + tessellator.addVertexWithUV(1.0D, f9, 0.0F - p_78439_7_, p_78439_3_, f8); + tessellator.addVertexWithUV(0.0D, f9, 0.0F - p_78439_7_, p_78439_1_, f8); + } + + tessellator.draw(); + tessellator.startDrawingQuads(); + tessellator.setNormal(0.0F, -1.0F, 0.0F); + + for (int k = 0; k < p_78439_6_; ++k) { + float f7 = (float) k / (float) p_78439_6_; + float f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + tessellator.addVertexWithUV(1.0D, f7, 0.0D, p_78439_3_, f8); + tessellator.addVertexWithUV(0.0D, f7, 0.0D, p_78439_1_, f8); + tessellator.addVertexWithUV(0.0D, f7, 0.0F - p_78439_7_, p_78439_1_, f8); + tessellator.addVertexWithUV(1.0D, f7, 0.0F - p_78439_7_, p_78439_3_, f8); + } + + tessellator.draw(); + } } diff --git a/src/main/java/noppes/npcs/client/renderer/MarkRenderer.java b/src/main/java/noppes/npcs/client/renderer/MarkRenderer.java new file mode 100644 index 000000000..50c5db0f3 --- /dev/null +++ b/src/main/java/noppes/npcs/client/renderer/MarkRenderer.java @@ -0,0 +1,59 @@ +package noppes.npcs.client.renderer; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.model.util.Model2DRenderer; +import noppes.npcs.constants.MarkType; +import noppes.npcs.controllers.data.MarkData; +import org.lwjgl.opengl.GL11; + +public class MarkRenderer { + public static ResourceLocation markExclamation = new ResourceLocation("customnpcs", "textures/marks/exclamation.png"); + public static ResourceLocation markQuestion = new ResourceLocation("customnpcs", "textures/marks/question.png"); + public static ResourceLocation markPointer = new ResourceLocation("customnpcs", "textures/marks/pointer.png"); + public static ResourceLocation markCross = new ResourceLocation("customnpcs", "textures/marks/cross.png"); + public static ResourceLocation markSkull = new ResourceLocation("customnpcs", "textures/marks/skull.png"); + public static ResourceLocation markStar = new ResourceLocation("customnpcs", "textures/marks/star.png"); + + public static int displayList = -1; + + public static void render(EntityLivingBase entity, double x, double y, double z, MarkData.Mark mark){ + GL11.glPushMatrix(); + int color = mark.color; + float red = (float)(color >> 16 & 255) / 255.0F; + float blue = (float)(color >> 8 & 255) / 255.0F; + float green = (float)(color & 255) / 255.0F; + GL11.glColor4f(red, blue, green, 1); + GL11.glTranslatef((float) x, (float) (y + entity.height + 0.6), (float) z); + GL11.glRotatef(-entity.rotationYawHead, 0, 1, 0); + + if(mark.type == MarkType.EXCLAMATION) + Minecraft.getMinecraft().getTextureManager().bindTexture(markExclamation); + else if(mark.type == MarkType.QUESTION) + Minecraft.getMinecraft().getTextureManager().bindTexture(markQuestion); + else if(mark.type == MarkType.POINTER) + Minecraft.getMinecraft().getTextureManager().bindTexture(markPointer); + else if(mark.type == MarkType.CROSS) + Minecraft.getMinecraft().getTextureManager().bindTexture(markCross); + else if(mark.type == MarkType.SKULL) + Minecraft.getMinecraft().getTextureManager().bindTexture(markSkull); + else if(mark.type == MarkType.STAR) + Minecraft.getMinecraft().getTextureManager().bindTexture(markStar); + + if(displayList >= 0){ + GL11.glCallList(displayList); + } + else{ + displayList = GLAllocation.generateDisplayLists(1); + GL11.glNewList(displayList, GL11.GL_COMPILE); + GL11.glTranslatef((float) -0.5, 0, 0); + Model2DRenderer.renderItemIn2D(0f, 0f, 1f, 1f, 32, 32, 0.0625F); + GL11.glEndList(); + } + + GL11.glPopMatrix(); + } +} diff --git a/src/main/java/noppes/npcs/config/ConfigMain.java b/src/main/java/noppes/npcs/config/ConfigMain.java index fc6efcf8d..f7e10f428 100644 --- a/src/main/java/noppes/npcs/config/ConfigMain.java +++ b/src/main/java/noppes/npcs/config/ConfigMain.java @@ -63,6 +63,10 @@ public class ConfigMain public static Property DatFormatProperty; public static boolean DatFormat = false; + public static Property MarketDatFormatProperty; + public static boolean MarketDatFormat = false; + + public static Property DefaultMaxPartySizetProperty; public static int DefaultMaxPartySize = 4; @@ -152,6 +156,9 @@ public class ConfigMain DatFormatProperty = config.get(GENERAL, "Dat Format for PlayerData", false, "You need to use '/kamkeel config playerdata' to convert existing playerdata to new format."); DatFormat = DatFormatProperty.getBoolean(false); + MarketDatFormatProperty = config.get(GENERAL, "Dat Format for Market", false, "You need to use '/kamkeel config market' to convert existing market to new format."); + MarketDatFormat = MarketDatFormatProperty.getBoolean(false); + DefaultMaxPartySizetProperty = config.get(GENERAL, "Default Max Party Size", 4, "When creating a new Quest sets the default max party size"); DefaultMaxPartySize = DefaultMaxPartySizetProperty.getInt(4); @@ -280,4 +287,4 @@ public class ConfigMain } } } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index 28abc0435..ff865baa0 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -34,6 +34,7 @@ public enum EnumPacketClient { SYNCRECIPES_CARPENTRYBENCH, CLONE, CLONER, + TELEPORTER, OPEN_BOOK, DIALOG_DUMMY, CONFIG, @@ -52,5 +53,6 @@ public enum EnumPacketClient { PAUSE_SOUNDS, CONTINUE_SOUNDS, STOP_SOUNDS, - SYNC_WEAPON + SYNC_WEAPON, + MARK_DATA } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 5714b8309..d13ee51a6 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -20,7 +20,7 @@ public enum EnumPacketServer { MainmenuDisplaySave(CustomNpcsPermissions.NPC_DISPLAY, true), MainmenuDisplayGet(true), ModelDataSave(CustomNpcsPermissions.NPC_DISPLAY, true), - MainmenuAdvancedSave(CustomNpcsPermissions.NPC_ADVANCED,true), MainmenuAdvancedGet(true), + MainmenuAdvancedSave(CustomNpcsPermissions.NPC_ADVANCED,true), MainmenuAdvancedGet(true), MainmenuAdvancedMarkData(CustomNpcsPermissions.NPC_ADVANCED,true), DialogNpcSet(CustomNpcsPermissions.NPC_ADVANCED), DialogNpcRemove(CustomNpcsPermissions.NPC_ADVANCED, true), FactionSet(CustomNpcsPermissions.NPC_ADVANCED, true), diff --git a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java index 765cb7e92..e89854166 100644 --- a/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java +++ b/src/main/java/noppes/npcs/constants/EnumPlayerPacket.java @@ -1,5 +1,9 @@ package noppes.npcs.constants; public enum EnumPlayerPacket { - FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet, MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, MouseClicked, CompanionTalentExp, ScreenSize + FollowerHire,FollowerExtend,Trader, FollowerState, Transport, BankUnlock, BankUpgrade, + Dialog, QuestLog, CheckQuestCompletion, BankSlotOpen, FactionsGet, + MailGet, MailDelete, MailSend, MailRead, MailboxOpenMail, + SignSave, SaveBook, CompanionOpenInv, RoleGet, KeyPressed, + MouseClicked, CompanionTalentExp, ScreenSize, MarkData } diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index cdaf3db88..aec0854a3 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -20,6 +20,7 @@ public enum EnumScriptType { ATTACKED("attacked"), ATTACK_MELEE("meleeAttack"), ATTACK_SWING("meleeSwing"), + RIGHT_CLICK("rightClick"), ROLE("role"), RANGED_CHARGE("rangedCharge"), RANGED_LAUNCHED("rangedLaunched"), @@ -101,4 +102,4 @@ public enum EnumScriptType { private EnumScriptType(String function) { this.function = function; } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/constants/MarkType.java b/src/main/java/noppes/npcs/constants/MarkType.java new file mode 100644 index 000000000..9beb217ec --- /dev/null +++ b/src/main/java/noppes/npcs/constants/MarkType.java @@ -0,0 +1,11 @@ +package noppes.npcs.constants; + +public class MarkType { + public static final int NONE = 0; + public static final int QUESTION = 1; + public static final int EXCLAMATION = 2; + public static final int POINTER = 3; + public static final int SKULL = 4; + public static final int CROSS = 5; + public static final int STAR = 6; +} diff --git a/src/main/java/noppes/npcs/controllers/PlayerDataController.java b/src/main/java/noppes/npcs/controllers/PlayerDataController.java index b3a0f3a7f..ecf682fbb 100644 --- a/src/main/java/noppes/npcs/controllers/PlayerDataController.java +++ b/src/main/java/noppes/npcs/controllers/PlayerDataController.java @@ -12,10 +12,7 @@ import net.minecraft.util.ChatComponentText; import noppes.npcs.CustomNpcs; import noppes.npcs.LogWriter; import noppes.npcs.config.ConfigMain; -import noppes.npcs.controllers.data.Bank; -import noppes.npcs.controllers.data.PlayerBankData; -import noppes.npcs.controllers.data.PlayerData; -import noppes.npcs.controllers.data.PlayerMail; +import noppes.npcs.controllers.data.*; import noppes.npcs.util.CacheHashMap; import noppes.npcs.util.NBTJsonUtil; @@ -28,7 +25,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.zip.GZIPInputStream; -import static noppes.npcs.util.CustomNPCsThreader.playerDataThread; +import static noppes.npcs.util.CustomNPCsThreader.customNPCThread; public class PlayerDataController { public static PlayerDataController Instance; @@ -66,7 +63,7 @@ public class PlayerDataController { } } if(file.getName().endsWith(".dat")){ - NBTTagCompound compound = loadNBTData(file); + NBTTagCompound compound = NBTJsonUtil.loadNBTData(file); if(compound.hasKey("PlayerName")){ map.put(compound.getString("PlayerName"), file.getName().substring(0, file.getName().length() - 4)); } @@ -128,7 +125,7 @@ public class PlayerDataController { } public synchronized void savePlayerDataMap(){ - playerDataThread.execute(() -> { + customNPCThread.execute(() -> { try { File saveDir = CustomNpcs.getWorldSaveDirectory(); File file = new File(saveDir, "playerdatamap.dat_new"); @@ -230,7 +227,7 @@ public class PlayerDataController { File file = new File(saveDir, filename); if(file.exists()){ if(ConfigMain.DatFormat){ - return loadNBTData(file); + return NBTJsonUtil.loadNBTData(file); } else { return NBTJsonUtil.LoadFile(file); } @@ -242,16 +239,7 @@ public class PlayerDataController { return new NBTTagCompound(); } - public NBTTagCompound loadNBTData(File file){ - try { - return CompressedStreamTools.readCompressed(new FileInputStream(file)); - } catch (Exception e) { - LogWriter.error("Error loading: " + file.getName(), e); - } - return new NBTTagCompound(); - } - - public void putPlayerDataCache(final String uuid, final PlayerData playerCompound) { + public void putPlayerDataCache(final String uuid, final PlayerData playerCompound) { synchronized (playerDataCache) { playerDataCache.put(uuid, new CacheHashMap.CachedObject<>(playerCompound)); } @@ -301,7 +289,10 @@ public class PlayerDataController { public PlayerData getPlayerData(EntityPlayer player){ PlayerData data = getPlayerDataCache(player.getUniqueID().toString()); if(data != null){ - data.player = player; + if(data.player == null){ + data.player = player; + data.scriptData = new PlayerDataScript(player); + } return data; } @@ -309,9 +300,14 @@ public class PlayerDataController { if(data == null){ player.registerExtendedProperties("CustomNpcsData", data = new PlayerData()); data.player = player; + data.scriptData = new PlayerDataScript(player); data.load(); } - data.player = player; + + if(data.player == null){ + data.player = player; + data.scriptData = new PlayerDataScript(player); + } return data; } @@ -453,7 +449,7 @@ public class PlayerDataController { } } if(file.getName().endsWith(".dat")){ - NBTTagCompound compound = loadNBTData(file); + NBTTagCompound compound = NBTJsonUtil.loadNBTData(file); if(compound.hasKey("PlayerName")){ map.put(compound.getString("PlayerName"), file.getName().substring(0, file.getName().length() - 4)); } @@ -536,7 +532,7 @@ public class PlayerDataController { } } else { if(file.getName().endsWith(".dat")){ - compound = loadNBTData(file); + compound = NBTJsonUtil.loadNBTData(file); if(compound.hasKey("PlayerName")){ filename = file.getName().substring(0, file.getName().length() - 4); valid = true; diff --git a/src/main/java/noppes/npcs/controllers/data/AnimationData.java b/src/main/java/noppes/npcs/controllers/data/AnimationData.java index f07267706..458f1d815 100644 --- a/src/main/java/noppes/npcs/controllers/data/AnimationData.java +++ b/src/main/java/noppes/npcs/controllers/data/AnimationData.java @@ -54,9 +54,6 @@ public class AnimationData implements IAnimationData { EntityLivingBase sendingEntity = parent instanceof PlayerData ? ((PlayerData) parent).player : parent instanceof DataDisplay ? ((DataDisplay) parent).npc : null; float range = parent instanceof PlayerData ? 160 : 60; if (sendingEntity != null) { - if(sendingEntity instanceof EntityNPCInterface && sendingEntity.dimension != sendingEntity.worldObj.provider.dimensionId) - sendingEntity.dimension = sendingEntity.worldObj.provider.dimensionId; - List entities = sendingEntity.worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox( sendingEntity.posX - range, sendingEntity.posY - range, sendingEntity.posZ - range, sendingEntity.posX + range, sendingEntity.posY + range, sendingEntity.posZ + range)); diff --git a/src/main/java/noppes/npcs/controllers/data/MarkData.java b/src/main/java/noppes/npcs/controllers/data/MarkData.java new file mode 100644 index 000000000..2cd4edfc6 --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/data/MarkData.java @@ -0,0 +1,147 @@ +package noppes.npcs.controllers.data; + +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.relauncher.Side; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import net.minecraftforge.common.IExtendedEntityProperties; +import noppes.npcs.Server; +import noppes.npcs.api.entity.data.IMark; +import noppes.npcs.api.handler.data.IAvailability; +import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.constants.MarkType; +import noppes.npcs.entity.EntityNPCInterface; + +import java.util.ArrayList; +import java.util.List; + +public class MarkData implements IExtendedEntityProperties { + + private static final String CNPCMARK = "cnpcmark"; + private EntityLivingBase entity; + + public List marks = new ArrayList(); + + public void setNBT(NBTTagCompound compound){ + List marks = new ArrayList(); + NBTTagList list = compound.getTagList("marks", 10); + for(int i = 0; i < list.tagCount(); i++){ + NBTTagCompound c = list.getCompoundTagAt(i); + Mark m = new Mark(); + m.type = c.getInteger("type"); + m.color = c.getInteger("color"); + m.availability.readFromNBT(c.getCompoundTag("availability")); + marks.add(m); + } + this.marks = marks; + } + + public NBTTagCompound getNBT() { + NBTTagCompound compound = new NBTTagCompound(); + NBTTagList list = new NBTTagList(); + for(Mark m : marks){ + NBTTagCompound c = new NBTTagCompound(); + c.setInteger("type", m.type); + c.setInteger("color", m.color); + c.setTag("availability", m.availability.writeToNBT(new NBTTagCompound())); + list.appendTag(c); + } + compound.setTag("marks", list); + return compound; + } + + public static boolean has(EntityLivingBase entity) { + return entity.getExtendedProperties(CNPCMARK) != null; + } + + public static MarkData get(EntityNPCInterface npc){ + if(!MarkData.has(npc)){ + npc.registerExtendedProperties(CNPCMARK, new MarkData()); + } + + MarkData data = (MarkData) npc.getExtendedProperties(CNPCMARK); + if(data.entity == null){ + data.entity = npc; + data.setNBT(npc.getEntityData().getCompoundTag(CNPCMARK)); + } + return data; + } + + public IMark addMark(int type) { + Mark m = new Mark(); + m.type = type; + marks.add(m); + if (!entity.worldObj.isRemote) + syncClients(); + return m; + } + + public IMark addMark(int type, int color) { + Mark m = new Mark(); + m.type = type; + m.color = color; + marks.add(m); + if (!entity.worldObj.isRemote) + syncClients(); + return m; + } + + @Override + public void saveNBTData(NBTTagCompound compound) { + if (!(this.entity instanceof EntityNPCInterface)) { + return; + } + this.entity.getEntityData().setTag(CNPCMARK, this.getNBT()); + } + + @Override + public void loadNBTData(NBTTagCompound compound) {} + + @Override + public void init(Entity entity, World world) {} + + public void syncClients() { + Server.sendToAll(EnumPacketClient.MARK_DATA, entity.getEntityId(), getNBT()); + } + + public class Mark implements IMark { + public int type = MarkType.NONE; + public Availability availability = new Availability(); + public int color = 0xFFED51; + + @Override + public IAvailability getAvailability() { + return availability; + } + + @Override + public int getColor() { + return color; + } + + @Override + public void setColor(int color) { + this.color = color; + } + + @Override + public int getType() { + return type; + } + + @Override + public void setType(int type) { + this.type = type; + } + + @Override + public void update() { + MarkData.this.syncClients(); + } + } +} diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerData.java b/src/main/java/noppes/npcs/controllers/data/PlayerData.java index 593bd89be..f700ed183 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerData.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerData.java @@ -41,6 +41,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { public PlayerItemGiverData itemgiverData = new PlayerItemGiverData(this); public PlayerMailData mailData = new PlayerMailData(this); public AnimationData animationData = new AnimationData(this); + public PlayerDataScript scriptData; public DataTimers timers = new DataTimers(this); public DataSkinOverlays skinOverlays = new DataSkinOverlays(this); @@ -277,7 +278,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData { } PlayerDataController.Instance.putPlayerMap(playername, uuid); PlayerDataController.Instance.putPlayerDataCache(uuid, this); - CustomNPCsThreader.playerDataThread.execute(() -> { + CustomNPCsThreader.customNPCThread.execute(() -> { try { File saveDir = PlayerDataController.Instance.getSaveDir(); File file = new File(saveDir, filename + "_new"); diff --git a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java index 3981be87a..f51b68748 100644 --- a/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java +++ b/src/main/java/noppes/npcs/controllers/data/PlayerDataScript.java @@ -1,7 +1,3 @@ -// -// Source code recreated from a .class file by IntelliJ IDEA -// (powered by Fernflower decompiler) -// package noppes.npcs.controllers.data; import com.google.common.base.Preconditions; @@ -30,6 +26,7 @@ public class PlayerDataScript implements INpcScriptHandler { private IPlayer playerAPI; private long lastPlayerUpdate = 0L; public long lastInited = -1L; + public boolean hadInteract = true; public boolean enabled = false; public PlayerDataScript(EntityPlayer player) { @@ -320,4 +317,4 @@ public class PlayerDataScript implements INpcScriptHandler { public static PlayerDataScript.ToStringHelper toStringHelper(Object self) { return new PlayerDataScript.ToStringHelper(self.getClass().getSimpleName()); } -} \ No newline at end of file +} diff --git a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java index db10cca8c..a8826ef3d 100644 --- a/src/main/java/noppes/npcs/entity/EntityNPCInterface.java +++ b/src/main/java/noppes/npcs/entity/EntityNPCInterface.java @@ -394,7 +394,6 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti updateClient = false; } - @Override public boolean interact(EntityPlayer player) { if(worldObj.isRemote) diff --git a/src/main/java/noppes/npcs/items/ItemTeleporter.java b/src/main/java/noppes/npcs/items/ItemTeleporter.java index 510a310ab..ac30fc2b2 100644 --- a/src/main/java/noppes/npcs/items/ItemTeleporter.java +++ b/src/main/java/noppes/npcs/items/ItemTeleporter.java @@ -7,6 +7,7 @@ import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; @@ -18,6 +19,8 @@ import net.minecraft.util.Vec3; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.CustomNpcs; +import noppes.npcs.CustomNpcsPermissions; +import noppes.npcs.NoppesUtilServer; import noppes.npcs.constants.EnumGuiType; import noppes.npcs.entity.EntityNPCInterface; @@ -25,7 +28,7 @@ import java.util.List; public class ItemTeleporter extends Item{ - + public ItemTeleporter(){ maxStackSize = 1; setCreativeTab(CustomItems.tab); @@ -33,9 +36,10 @@ public class ItemTeleporter extends Item{ @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){ - if(!par2World.isRemote) - return par1ItemStack; - CustomNpcs.proxy.openGui((EntityNPCInterface)null,EnumGuiType.NpcDimensions); + if(par2World.isRemote || !CustomNpcsPermissions.Instance.hasPermission(par3EntityPlayer, CustomNpcsPermissions.TOOL_TELEPORTER)) + return par1ItemStack; + + NoppesUtilServer.setTeleporterGUI((EntityPlayerMP) par3EntityPlayer); return par1ItemStack; } @@ -61,7 +65,7 @@ public class ItemTeleporter extends Item{ MovingObjectPosition movingobjectposition = par3EntityPlayer.worldObj.rayTraceBlocks(vec3, vec31, true); if (movingobjectposition == null) return false; - + Vec3 vec32 = par3EntityPlayer.getLook(f); boolean flag = false; float f9 = 1.0F; @@ -82,88 +86,32 @@ public class ItemTeleporter extends Item{ if (flag) return false; - + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK){ int i = movingobjectposition.blockX; int j = movingobjectposition.blockY; int k = movingobjectposition.blockZ; - + while(par3EntityPlayer.worldObj.getBlock(i, j, k) != Blocks.air){ j++; } par3EntityPlayer.setPositionAndUpdate(i + 0.5F, j + 1.0F, k + 0.5F); } - - + + return true; } -// protected static MovingObjectPosition rayTraceBlocks(EntityPlayer entityPlayer, int radius) { -// Vec3 vec3 = Vec3.createVectorHelper(entityPlayer.posX, entityPlayer.height * 0.8 + entityPlayer.boundingBox.minY, entityPlayer.posZ); -// Vec3 vec3a = entityPlayer.getLookVec(); -// Vec3 vec3b = vec3.addVector(vec3a.xCoord * radius, vec3a.yCoord * radius, vec3a.zCoord * radius); -// -// return entityPlayer.worldObj.func_147447_a(vec3, vec3b, false, false, true); -// } -// -// protected static MovingObjectPosition getPointingEntity(EntityPlayer entityPlayer, int radius) { -// MovingObjectPosition block = rayTraceBlocks(entityPlayer, radius); -// Vec3 vec3 = Vec3.createVectorHelper(entityPlayer.posX, entityPlayer.height * 0.8 + entityPlayer.boundingBox.minY, entityPlayer.posZ); -// -// Vec3 vec31 = entityPlayer.getLookVec(); -// Vec3 vec32 = vec3.addVector(vec31.xCoord * radius, vec31.yCoord * radius, vec31.zCoord * radius); -// Vec3 vec33 = null; -// List entities = entityPlayer.worldObj.getEntitiesWithinAABBExcludingEntity(entityPlayer, entityPlayer.boundingBox.addCoord(vec31.xCoord * radius, vec31.yCoord * radius, vec31.zCoord * radius).expand(1.0D, 1.0D, 1.0D)); -// Entity pointedEntity = null; -// double d = radius; -// -// for (Entity entity : entities) { -// if (entity.canBeCollidedWith()) { -// float f = entity.getCollisionBorderSize(); -// AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f, (double)f, (double)f); -// MovingObjectPosition movingObjectPosition = axisalignedbb.calculateIntercept(vec3, vec32); -// -// if (axisalignedbb.isVecInside(vec3)) { -// if (0.0D < radius || radius == 0.0D) { -// pointedEntity = entity; -// vec33 = movingObjectPosition == null ? vec3 : movingObjectPosition.hitVec; -// d = 0.0D; -// } -// } else if (movingObjectPosition != null) { -// double d2 = vec3.distanceTo(movingObjectPosition.hitVec); -// -// if (d2 < radius || radius == 0.0D) { -// if (entity == entityPlayer.ridingEntity && !entity.canRiderInteract()) { -// if (radius == 0.0D) { -// pointedEntity = entity; -// vec33 = movingObjectPosition.hitVec; -// } -// } else { -// pointedEntity = entity; -// vec33 = movingObjectPosition.hitVec; -// d = d2; -// } -// } -// } -// } -// } -// -// if (pointedEntity != null && (d < radius)) { -// return new MovingObjectPosition(pointedEntity, vec33); -// } -// -// return null; -// } - + @Override public int getColorFromItemStack(ItemStack par1ItemStack, int par2){ return 0x8B4513; } - + @Override public boolean requiresMultipleRenderPasses(){ return true; } - + @SideOnly(Side.CLIENT) @Override public void registerIcons(IIconRegister par1IconRegister){ diff --git a/src/main/java/noppes/npcs/roles/JobBard.java b/src/main/java/noppes/npcs/roles/JobBard.java index 7d2c6054c..d18aa0bf1 100644 --- a/src/main/java/noppes/npcs/roles/JobBard.java +++ b/src/main/java/noppes/npcs/roles/JobBard.java @@ -1,5 +1,6 @@ package noppes.npcs.roles; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -14,12 +15,12 @@ import java.util.List; public class JobBard extends JobInterface{ public int minRange = 2; public int maxRange = 64; - + public boolean isStreamer = true; public boolean hasOffRange = true; public String song = ""; - + private EnumBardInstrument instrument = EnumBardInstrument.Banjo; public JobBard(EntityNPCInterface npc) { @@ -38,7 +39,7 @@ public class JobBard extends JobInterface{ nbttagcompound.setInteger("BardInstrument", instrument.ordinal()); nbttagcompound.setBoolean("BardStreamer", isStreamer); nbttagcompound.setBoolean("BardHasOff", hasOffRange); - + return nbttagcompound; } @@ -51,7 +52,7 @@ public class JobBard extends JobInterface{ isStreamer = nbttagcompound.getBoolean("BardStreamer"); hasOffRange = nbttagcompound.getBoolean("BardHasOff"); } - + public void setInstrument(int i) { if(CustomItems.banjo == null) return; @@ -87,16 +88,11 @@ public class JobBard extends JobInterface{ public EnumBardInstrument getInstrument(){ return instrument; } - private long ticks = 0; public void onLivingUpdate() { - if(!npc.isRemote()) + if(!npc.isRemote() || song.isEmpty()) return; - ticks++; - if(ticks % 10 != 0 ) - return; - if(song.isEmpty()) - return; - if(!MusicController.Instance.isPlaying(song)){ + + if(!MusicController.Instance.isPlaying(song)){ List list = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(minRange, minRange/2, minRange)); if(!list.contains(CustomNpcs.proxy.getPlayer())) return; @@ -104,18 +100,23 @@ public class JobBard extends JobInterface{ MusicController.Instance.playStreaming(song, npc); else MusicController.Instance.playMusic(song, npc); - }else if(MusicController.Instance.playingEntity != npc){ + } + else if(MusicController.Instance.playingEntity != npc){ EntityPlayer player = CustomNpcs.proxy.getPlayer(); if(npc.getDistanceSqToEntity(player) < MusicController.Instance.playingEntity.getDistanceSqToEntity(player)){ MusicController.Instance.playingEntity = npc; } - - }else if(hasOffRange){ + + } + else if(hasOffRange){ List list = npc.worldObj.getEntitiesWithinAABB(EntityPlayer.class, npc.boundingBox.expand(maxRange, maxRange/2, maxRange)); if(!list.contains(CustomNpcs.proxy.getPlayer())) MusicController.Instance.stopMusic(); } - + + if(MusicController.Instance.isPlaying(song)) { + Minecraft.getMinecraft().mcMusicTicker.field_147676_d = 12000; + } } @Override diff --git a/src/main/java/noppes/npcs/roles/JobSpawner.java b/src/main/java/noppes/npcs/roles/JobSpawner.java index e5cc0ac92..e5aca69e1 100644 --- a/src/main/java/noppes/npcs/roles/JobSpawner.java +++ b/src/main/java/noppes/npcs/roles/JobSpawner.java @@ -321,9 +321,25 @@ public class JobSpawner extends JobInterface{ target = null; checkSpawns(); } - @Override + + @Override + public void delete() { + if(spawnType == 3 && npc.stats.spawnCycle == 3){ + spawnEntity(compound1); + spawnEntity(compound2); + spawnEntity(compound3); + spawnEntity(compound4); + spawnEntity(compound5); + spawnEntity(compound6); + number = 6; + } + reset(); + } + + + @Override public void killed() { - if(spawnType == 3){ + if(spawnType == 3 && npc.stats.spawnCycle != 3){ spawnEntity(compound1); spawnEntity(compound2); spawnEntity(compound3); diff --git a/src/main/java/noppes/npcs/roles/RoleTrader.java b/src/main/java/noppes/npcs/roles/RoleTrader.java index f6406a6e8..fa5ae40bc 100644 --- a/src/main/java/noppes/npcs/roles/RoleTrader.java +++ b/src/main/java/noppes/npcs/roles/RoleTrader.java @@ -15,7 +15,7 @@ import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; -public class RoleTrader extends RoleInterface{ +public class RoleTrader extends RoleInterface { public String marketName = ""; public NpcMiscInventory inventoryCurrency; @@ -23,14 +23,13 @@ public class RoleTrader extends RoleInterface{ public boolean ignoreDamage = false; public boolean ignoreNBT = false; - - public boolean toSave = false; - + public boolean recordHistory = false; + public int[] purchases; public int[] disableSlot; public HashMap playerPurchases; public HashMap playerDisableSlot; - + public RoleTrader(EntityNPCInterface npc) { super(npc); inventoryCurrency = new NpcMiscInventory(36); @@ -45,10 +44,6 @@ public class RoleTrader extends RoleInterface{ public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { nbttagcompound.setString("TraderMarket", marketName); writeNBT(nbttagcompound); - if (toSave && !npc.isRemote()) { - Market.save(this, marketName); - } - toSave = false; return nbttagcompound; } @@ -57,10 +52,13 @@ public class RoleTrader extends RoleInterface{ nbttagcompound.setTag("TraderSold", inventorySold.getToNBT()); nbttagcompound.setBoolean("TraderIgnoreDamage", ignoreDamage); nbttagcompound.setBoolean("TraderIgnoreNBT", ignoreNBT); - nbttagcompound.setIntArray("Purchases", purchases); + nbttagcompound.setBoolean("RecordHistory", recordHistory); nbttagcompound.setIntArray("DisableSlot", disableSlot); - nbttagcompound.setTag("PlayerPurchases", NBTTags.nbtStringIntegerArrayMap(playerPurchases)); nbttagcompound.setTag("PlayerDisableSlot", NBTTags.nbtStringIntegerArrayMap(playerDisableSlot)); + if(recordHistory){ + nbttagcompound.setIntArray("Purchases", purchases); + nbttagcompound.setTag("PlayerPurchases", NBTTags.nbtStringIntegerArrayMap(playerPurchases)); + } return nbttagcompound; } @@ -68,12 +66,11 @@ public class RoleTrader extends RoleInterface{ public void readFromNBT(NBTTagCompound nbttagcompound) { marketName = nbttagcompound.getString("TraderMarket"); readNBT(nbttagcompound); - + try { - Market.load(this, marketName); + Market.getMarket(this, marketName); } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); - } } @@ -82,25 +79,28 @@ public class RoleTrader extends RoleInterface{ inventorySold.setFromNBT(nbttagcompound.getCompoundTag("TraderSold")); ignoreDamage = nbttagcompound.getBoolean("TraderIgnoreDamage"); ignoreNBT = nbttagcompound.getBoolean("TraderIgnoreNBT"); - purchases = nbttagcompound.getIntArray("Purchases"); + recordHistory = nbttagcompound.getBoolean("RecordHistory"); + disableSlot = nbttagcompound.getIntArray("DisableSlot"); + playerDisableSlot = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerDisableSlot", 10), 18); + if(recordHistory){ + purchases = nbttagcompound.getIntArray("Purchases"); + playerPurchases = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerPurchases", 10), 18); + } if (purchases == null || purchases.length != 18) { purchases = new int[18]; for (int i = 0; i < purchases.length; ++i) purchases[i] = 0; } - disableSlot = nbttagcompound.getIntArray("DisableSlot"); if (disableSlot == null || disableSlot.length != 18) { disableSlot = new int[18]; for (int i = 0; i < disableSlot.length; ++i) disableSlot[i] = 0; } - playerPurchases = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerPurchases", 10), 18); - playerDisableSlot = NBTTags.getStringIntegerArrayMap(nbttagcompound.getTagList("PlayerDisableSlot", 10), 18); } - + @Override public void interact(EntityPlayer player) { npc.say(player, npc.advanced.getInteractLine()); try { - Market.load(this, marketName); + Market.getMarket(this, marketName); } catch (Exception ex) { Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex); } @@ -117,19 +117,22 @@ public class RoleTrader extends RoleInterface{ } return false; } - + public void addPurchase(int slot, String playerName) { if(slot >= 18 || slot < 0) return; ++purchases[slot]; ++getArrayByName(playerName, playerPurchases)[slot]; + + if(recordHistory) + Market.save(this, marketName); } - + public boolean isSlotEnabled(int slot, String playerName) { if(slot >= 18 || slot < 0) return false; if (disableSlot[slot] > 0) return false; return getArrayByName(playerName, playerDisableSlot)[slot] <= 0; } - + public int[] getArrayByName(String name, HashMap map) { map.computeIfAbsent(name, k -> new int[18]); return map.get(name); diff --git a/src/main/java/noppes/npcs/scripted/NpcAPI.java b/src/main/java/noppes/npcs/scripted/NpcAPI.java index 968e68543..4fe5f5150 100644 --- a/src/main/java/noppes/npcs/scripted/NpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/NpcAPI.java @@ -13,6 +13,7 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntityAnimal; import net.minecraft.entity.passive.EntityTameable; +import net.minecraft.entity.passive.EntityVillager; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.inventory.Container; @@ -200,6 +201,8 @@ public class NpcAPI extends AbstractNpcAPI { data = new ScriptEntityData(new ScriptAnimal<>((EntityAnimal) entity)); else if(entity instanceof EntityMob) data = new ScriptEntityData(new ScriptMonster<>((EntityMob) entity)); + else if(entity instanceof EntityVillager) + data = new ScriptEntityData(new ScriptVillager<>((EntityVillager) entity)); else if(entity instanceof EntityLiving) data = new ScriptEntityData(new ScriptLiving<>((EntityLiving) entity)); else if(entity instanceof EntityLivingBase) diff --git a/src/main/java/noppes/npcs/scripted/constants/EntityType.java b/src/main/java/noppes/npcs/scripted/constants/EntityType.java index 4bd9cdfd5..76c21de71 100644 --- a/src/main/java/noppes/npcs/scripted/constants/EntityType.java +++ b/src/main/java/noppes/npcs/scripted/constants/EntityType.java @@ -9,4 +9,6 @@ public class EntityType { public static final int LIVING = 5; public static final int ITEM = 6; public static final int PROJECTILE = 7; + public static final int PIXELMON = 8; + public static final int VILLAGER = 9; } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java index cb198413a..828803ed0 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLiving.java @@ -8,10 +8,8 @@ import noppes.npcs.scripted.NpcAPI; public class ScriptLiving extends ScriptLivingBase implements IEntityLiving { - private T entity; public ScriptLiving(T entity) { super(entity); - this.entity = entity; } @Override @@ -33,7 +31,7 @@ public class ScriptLiving extends ScriptLivingBase im IEntityLivingBase base = (IEntityLivingBase) NpcAPI.Instance().getIEntity(entity.getAttackTarget()); return (base != null)? base: super.getAttackTarget(); } - + /** * Start path finding toward this target * @param x Destination x position @@ -44,21 +42,21 @@ public class ScriptLiving extends ScriptLivingBase im public void navigateTo(double x, double y, double z, double speed){ entity.getNavigator().tryMoveToXYZ(x, y, z, speed); } - + /** * Stop navigating wherever this npc was walking to */ public void clearNavigation(){ entity.getNavigator().clearPathEntity(); } - + /** * @return Whether or not this entity is navigating somewhere */ public boolean isNavigating(){ return !entity.getNavigator().noPath(); } - + @Override public boolean canSeeEntity(IEntity entity){ return this.entity.getEntitySenses().canSee(entity.getMCEntity()); diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java index 2c45b58eb..33e38d308 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptLivingBase.java @@ -20,11 +20,9 @@ import java.util.ArrayList; import java.util.Collections; public class ScriptLivingBase extends ScriptEntity implements IEntityLivingBase { - protected T entity; public ScriptLivingBase(T entity){ super(entity); - this.entity = entity; } /** diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java index 7bc01d080..702b9ad45 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPixelmon.java @@ -4,6 +4,7 @@ import net.minecraft.entity.passive.EntityTameable; import net.minecraft.nbt.NBTTagCompound; import noppes.npcs.api.entity.IPixelmon; import noppes.npcs.compat.PixelmonHelper; +import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.util.ValueUtil; public class ScriptPixelmon extends ScriptAnimal implements IPixelmon { @@ -19,25 +20,25 @@ public class ScriptPixelmon extends ScriptAnimal im this(pixelmon); this.compound = compound; } - + public boolean getIsShiny(){ return compound.getBoolean("IsShiny"); } - + public void setIsShiny(boolean bo){ compound.setBoolean("IsShiny", bo); pixelmon.readEntityFromNBT(compound); } - + public int getLevel(){ return compound.getInteger("Level"); } - + public void setLevel(int level){ compound.setInteger("Level", level); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -54,11 +55,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("IVSpDef"); if(type == 5) return compound.getInteger("IVSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -77,7 +78,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("IVSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -94,11 +95,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("EVSpecialDefence"); if(type == 5) return compound.getInteger("EVSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -117,7 +118,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("EVSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -134,11 +135,11 @@ public class ScriptPixelmon extends ScriptAnimal im return compound.getInteger("StatsSpecialDefence"); if(type == 5) return compound.getInteger("StatsSpeed"); - + return -1; } - + /** * @param type 0:HP, 1:Attack, 2:Defense, 3:SpAttack, 4:SpDefense, 5:Speed */ @@ -157,14 +158,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("StatsSpeed", value); pixelmon.readEntityFromNBT(compound); } - + /** * @return type 0:Pygmy, 1:Runt, 2:Small, 3:Normal, 4:Huge, 5:Giant, 6:Enormous, 7:Ginormous, 8:Microscopic */ public int getSize(){ return compound.getShort("Growth"); } - + /** * @param type 0:Pygmy, 1:Runt, 2:Small, 3:Normal, 4:Huge, 5:Giant, 6:Enormous, 7:Ginormous, 8:Microscopic */ @@ -172,14 +173,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setShort("Growth", (short) type); pixelmon.readEntityFromNBT(compound); } - + /** * @return 0-255 */ public int getHapiness(){ return compound.getInteger("Friendship"); } - + /** * @param value 0-255 */ @@ -188,14 +189,14 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("Friendship", value); pixelmon.readEntityFromNBT(compound); } - + /** * @return 0:Hardy, 1:Serious, 2:Docile, 3:Bashful, 4:Quirky, 5:Lonely, 6:Brave, 7:Adamant, 8:Naughty, 9:Bold, 10:Relaxed, 11:Impish, 12:Lax, 13:Timid, 14:Hasty, 15:Jolly, 16:Naive, 17:Modest, 18:Mild, 19:Quiet, 20:Rash, 21:Calm, 22:Gentle, 23:Sassy, 24:Careful */ public int getNature(){ return compound.getShort("Nature"); } - + /** * @param type 0:Hardy, 1:Serious, 2:Docile, 3:Bashful, 4:Quirky, 5:Lonely, 6:Brave, 7:Adamant, 8:Naughty, 9:Bold, 10:Relaxed, 11:Impish, 12:Lax, 13:Timid, 14:Hasty, 15:Jolly, 16:Naive, 17:Modest, 18:Mild, 19:Quiet, 20:Rash, 21:Calm, 22:Gentle, 23:Sassy, 24:Careful */ @@ -203,7 +204,7 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setShort("Nature", (short) type); pixelmon.readEntityFromNBT(compound); } - + /** * @return -1:Uncaught, 0:Pokeball, 1:GreatBall, 2:UltraBall, 3:MasterBall, 4:LevelBall, 5:MoonBall, 6:FriendBall, 7:LoveBall, 8:SafariBall, 9:HeavyBall, 10:FastBall, 11:RepeatBall, 12:TimerBall, 13:NestBall, 14:NetBall, 15:DiveBall, 16:LuxuryBall, 17:HealBall, 18:DuskBall, 19:PremierBall, 20:SportBall, 21:QuickBall, 22:ParkBall, 23:LureBall, 24:CherishBall, 25:GSBall */ @@ -220,26 +221,26 @@ public class ScriptPixelmon extends ScriptAnimal im compound.setInteger("CaughtBall", type); pixelmon.readEntityFromNBT(compound); } - + public String getNickname(){ return compound.getString("Nickname"); } - + public boolean hasNickname(){ return !getNickname().isEmpty(); } - + public void setNickname(String name){ compound.setString("Nickname", name); pixelmon.readEntityFromNBT(compound); } - + public String getMove(int slot){ if(!compound.hasKey("PixelmonMoveID" + slot)) return null; return PixelmonHelper.getAttackName(compound.getInteger("PixelmonMoveID" + slot)); } - + public void setMove(int slot, String move){ slot = ValueUtil.clamp(slot, 0, 3); int id = PixelmonHelper.getAttackID(move); @@ -257,7 +258,17 @@ public class ScriptPixelmon extends ScriptAnimal im size++; } compound.setInteger("PixelmonNumberMoves", size); - + pixelmon.readEntityFromNBT(compound); } + + @Override + public int getType(){ + return EntityType.PIXELMON; + } + + @Override + public boolean typeOf(int type){ + return type == EntityType.PIXELMON || super.typeOf(type); + } } diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java b/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java new file mode 100644 index 000000000..cc3804651 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptVillager.java @@ -0,0 +1,41 @@ +package noppes.npcs.scripted.entity; + +import net.minecraft.entity.passive.EntityVillager; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.entity.IVillager; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.constants.EntityType; + +public class ScriptVillager extends ScriptLiving implements IVillager { + + public ScriptVillager(T entity) { + super(entity); + } + + @Override + public int getProfession() { + return entity.getProfession(); + } + + @Override + public boolean getIsTrading() { + return entity.isTrading(); + } + + @Override + public IEntityLivingBase getCustomer() + { + return (IEntityLivingBase) NpcAPI.Instance().getPlayer(entity.getCustomer().getCommandSenderName()); + } + + @Override + public int getType(){ + return EntityType.VILLAGER; + } + + @Override + public boolean typeOf(int type){ + return type == EntityType.VILLAGER || super.typeOf(type); + } + +} diff --git a/src/main/java/noppes/npcs/scripted/event/ItemEvent.java b/src/main/java/noppes/npcs/scripted/event/ItemEvent.java index c5196c78c..99e959814 100644 --- a/src/main/java/noppes/npcs/scripted/event/ItemEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/ItemEvent.java @@ -138,6 +138,40 @@ public class ItemEvent extends CustomNPCsEvent implements IItemEvent { } } + @Cancelable + public static class RightClickEvent extends ItemEvent implements IItemEvent.RightClickEvent { + + /** + * 0:air, 1:entity, 2:block + */ + public final int type; + public final Object target; + public final IPlayer player; + + public RightClickEvent(IItemCustom item, IPlayer player, int type, Object target) { + super(item); + this.type = type; + this.target = target; + this.player = player; + } + + public String getHookName() { + return EnumScriptType.INTERACT.function; + } + + public int getType() { + return type; + } + + public Object getTarget() { + return target; + } + + public IPlayer getPlayer() { + return player; + } + } + @Cancelable public static class AttackEvent extends ItemEvent implements IItemEvent.AttackEvent { public final int type;//1: Hit, 2: Whiff diff --git a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java index 1100a6c71..5fcc54821 100644 --- a/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java +++ b/src/main/java/noppes/npcs/scripted/roles/ScriptRoleTrader.java @@ -30,7 +30,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader role.inventoryCurrency.items.put(slot + 18, currency2.getMCItemStack()); else role.inventoryCurrency.items.remove(slot + 18); - + role.inventorySold.items.put(slot, sold.getMCItemStack()); } @@ -55,7 +55,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader } return currency; } - + public void removeSellOption(int slot){ if(slot >= 18 || slot < 0) return; @@ -66,7 +66,7 @@ public class ScriptRoleTrader extends ScriptRoleInterface implements IRoleTrader public void setMarket(String name){ role.marketName = name; - Market.load(role, name); + Market.getMarket(role, name); } public String getMarket(){ diff --git a/src/main/java/noppes/npcs/util/CacheHashMap.java b/src/main/java/noppes/npcs/util/CacheHashMap.java index 200630327..12e682b61 100644 --- a/src/main/java/noppes/npcs/util/CacheHashMap.java +++ b/src/main/java/noppes/npcs/util/CacheHashMap.java @@ -6,11 +6,17 @@ import java.util.Map; public class CacheHashMap> extends HashMap { private final long maxCacheTime; + private long saveInterval; public CacheHashMap(long maxCacheTime) { this.maxCacheTime = maxCacheTime; } + public CacheHashMap(long maxCacheTime, long saveInterval) { + this.maxCacheTime = maxCacheTime; + this.saveInterval = saveInterval; + } + @Override public V get(Object key) { V object = super.get(key); @@ -19,9 +25,16 @@ public class CacheHashMap> extends Has Iterator> iterator = this.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); - long timeDiff = entry.getValue().timeSinceAccessed(); - if (timeDiff > this.maxCacheTime) { + long lifeTimeDiff = entry.getValue().timeSinceAccessed(); + if (lifeTimeDiff > this.maxCacheTime) { + entry.getValue().save(); iterator.remove(); + } else if (this.saveInterval > 0) { + long saveTimeDiff = entry.getValue().timeSinceSaved(); + if (saveTimeDiff > this.saveInterval) { + entry.getValue().save(); + entry.getValue().updateSaveTime(); + } } } @@ -29,22 +42,34 @@ public class CacheHashMap> extends Has } public static class CachedObject { + private long timeSaved; private long lastTimeAccessed; private final T object; public CachedObject(T object) { this.object = object; this.lastTimeAccessed = System.currentTimeMillis(); + this.timeSaved = System.currentTimeMillis(); } public long timeSinceAccessed() { return System.currentTimeMillis() - this.lastTimeAccessed; } + public long timeSinceSaved() { + return System.currentTimeMillis() - this.timeSaved; + } + public void updateTimeAccessed() { this.lastTimeAccessed = System.currentTimeMillis(); } + public void updateSaveTime() { + this.timeSaved = System.currentTimeMillis(); + } + + public void save(){} + public T getObject() { return this.object; } diff --git a/src/main/java/noppes/npcs/util/CustomNPCsThreader.java b/src/main/java/noppes/npcs/util/CustomNPCsThreader.java index 8522fdf55..cdc040112 100644 --- a/src/main/java/noppes/npcs/util/CustomNPCsThreader.java +++ b/src/main/java/noppes/npcs/util/CustomNPCsThreader.java @@ -2,7 +2,8 @@ package noppes.npcs.util; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; public class CustomNPCsThreader { - public static final Executor playerDataThread = Executors.newSingleThreadExecutor(); + public static final Executor customNPCThread = Executors.newSingleThreadExecutor(); } diff --git a/src/main/java/noppes/npcs/util/MarketCachedObject.java b/src/main/java/noppes/npcs/util/MarketCachedObject.java new file mode 100644 index 000000000..1a6aebfbe --- /dev/null +++ b/src/main/java/noppes/npcs/util/MarketCachedObject.java @@ -0,0 +1,15 @@ +package noppes.npcs.util; + +import foxz.utils.Market; +import net.minecraft.nbt.NBTTagCompound; + +public class MarketCachedObject extends CacheHashMap.CachedObject { + public MarketCachedObject(NBTTagCompound object) { + super(object); + } + + @Override + public void save() { + Market.saveFile(getObject()); + } +} diff --git a/src/main/java/noppes/npcs/util/NBTJsonUtil.java b/src/main/java/noppes/npcs/util/NBTJsonUtil.java index 21104a103..ae8cbc7c2 100644 --- a/src/main/java/noppes/npcs/util/NBTJsonUtil.java +++ b/src/main/java/noppes/npcs/util/NBTJsonUtil.java @@ -3,12 +3,10 @@ package noppes.npcs.util; import com.google.common.io.Files; import cpw.mods.fml.common.ObfuscationReflectionHelper; import net.minecraft.nbt.*; +import noppes.npcs.LogWriter; import org.apache.commons.io.Charsets; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; +import java.io.*; import java.util.ArrayList; import java.util.List; @@ -211,7 +209,17 @@ public class NBTJsonUtil { } return json; } - static class JsonLine{ + + public static NBTTagCompound loadNBTData(File file){ + try { + return CompressedStreamTools.readCompressed(new FileInputStream(file)); + } catch (Exception e) { + LogWriter.error("Error loading: " + file.getName(), e); + } + return new NBTTagCompound(); + } + + static class JsonLine{ private String line; public JsonLine(String line){ this.line = line; diff --git a/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java b/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java index d5c52e8c5..8378c936c 100644 --- a/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java +++ b/src/main/java/tconstruct/client/tabs/InventoryTabVanilla.java @@ -10,22 +10,11 @@ public class InventoryTabVanilla extends AbstractTab { @Override public void onTabClicked() { - Thread t = new Thread(){ - @Override - public void run(){ - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - TabRegistry.openInventoryGui(); - } - }; - t.start(); + TabRegistry.openInventoryGui(); } @Override public boolean shouldAddToList() { return true; } -} \ No newline at end of file +} diff --git a/src/main/resources/META-INF/customnpcs_at.cfg b/src/main/resources/META-INF/customnpcs_at.cfg index 56f161026..990efc151 100644 --- a/src/main/resources/META-INF/customnpcs_at.cfg +++ b/src/main/resources/META-INF/customnpcs_at.cfg @@ -17,3 +17,7 @@ public net.minecraft.client.renderer.ItemRenderer field_78453_b # itemToRender public net.minecraft.client.renderer.entity.RenderPlayer func_77043_a(Lnet/minecraft/entity/EntityLivingBase;FFF)V # rotateCorpse #EntityLivingBase public net.minecraft.entity.EntityLivingBase func_82166_i()I # getArmSwingAnimationEnd +# Minecraft +public net.minecraft.client.Minecraft field_147126_aw # mcMusicTicker +# MusicTicker +public net.minecraft.client.audio.MusicTicker field_147676_d # timeUntilNextMusic diff --git a/src/main/resources/assets/customnpcs/lang/en_US.lang b/src/main/resources/assets/customnpcs/lang/en_US.lang index 4338c92f1..f929b3bdb 100644 --- a/src/main/resources/assets/customnpcs/lang/en_US.lang +++ b/src/main/resources/assets/customnpcs/lang/en_US.lang @@ -87,6 +87,7 @@ gui.untilclose=UntilClose gui.whenavailable=OnTheMove gui.ignoreDamage=Ignore damage gui.ignoreNBT=Ignore NBT +gui.recordHistory=Record History gui.minrange=MinimumRange gui.engagedistance=EngageDistance gui.orbitdistance=OrbitDistance diff --git a/src/main/resources/assets/customnpcs/textures/marks/cross.png b/src/main/resources/assets/customnpcs/textures/marks/cross.png new file mode 100644 index 000000000..1aac9f6cf Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/marks/cross.png differ diff --git a/src/main/resources/assets/customnpcs/textures/marks/exclamation.png b/src/main/resources/assets/customnpcs/textures/marks/exclamation.png new file mode 100644 index 000000000..7e39d5383 Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/marks/exclamation.png differ diff --git a/src/main/resources/assets/customnpcs/textures/marks/pointer.png b/src/main/resources/assets/customnpcs/textures/marks/pointer.png new file mode 100644 index 000000000..9436f49c7 Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/marks/pointer.png differ diff --git a/src/main/resources/assets/customnpcs/textures/marks/question.png b/src/main/resources/assets/customnpcs/textures/marks/question.png new file mode 100644 index 000000000..e22b8787e Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/marks/question.png differ diff --git a/src/main/resources/assets/customnpcs/textures/marks/skull.png b/src/main/resources/assets/customnpcs/textures/marks/skull.png new file mode 100644 index 000000000..e9d0df491 Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/marks/skull.png differ diff --git a/src/main/resources/assets/customnpcs/textures/marks/star.png b/src/main/resources/assets/customnpcs/textures/marks/star.png new file mode 100644 index 000000000..872806630 Binary files /dev/null and b/src/main/resources/assets/customnpcs/textures/marks/star.png differ