Compare commits

...
46 Commits
Author SHA1 Message Date
Kam 1a7ac52297 REMVOEOMOWAMo Arggg LOUIS! 2023-06-22 17:13:14 -04:00
Kam 37e9d5f899 Update to Main API 2023-06-01 16:31:22 -04:00
Kam 09423427a0 Merge branch 'patch' 2023-06-01 16:30:38 -04:00
Kam f213cab261 Add Search to Manage Banks 2023-06-01 16:10:38 -04:00
Kam bf78c1be0f Display Selected Wand Tags in Cloner 2023-06-01 12:29:28 -04:00
Kam ff5e7de1be Save NPC Quick Tags properly on Close 2023-06-01 12:29:16 -04:00
Luis C.M 01339e7baf ScriptLivingBase:
-Reverted previous change, not worth the inaccuracies it would cause on servers
2023-06-01 00:49:33 -05:00
Luis C.M 62ee42a23d ScriptLivingBase:
-Slightly improved getLookingAtPos() results
2023-06-01 00:36:40 -05:00
Luis C.M a8a0528275 ScriptWorld:
-Increased the accuracy of rayCastPos().
2023-05-31 23:59:11 -05:00
Luis C.M 0e9ddd75b6 Fixed index out of bounds error on custom GUI slot clicks. 2023-05-31 20:21:00 -05:00
Luis C.M 0c25d7ec1c Reverted changes to saving/loading player data from previous commit to 2023-05-31 19:59:20 -05:00
Luis C.M b3a5854ff1 Merge remote-tracking branch 'origin/patch' into patch 2023-05-31 18:55:12 -05:00
Luis C.M 7000b525f3 Fixed entity custom item rendering, and rendering of textures for custom GUI buttons and rectangles. 2023-05-31 18:55:06 -05:00
Kam 9bcb8133bb Update api 2023-05-31 19:46:21 -04:00
Kam 9d727499df Fix Gradle Order 2023-05-31 19:45:36 -04:00
Kam 075e3fdb41 1.8.4 Version Change 2023-05-31 19:34:24 -04:00
Kam 5befe141bd Fix Searching in Clone Tab to now account for the displayed tags 2023-05-31 18:45:10 -04:00
Luis C.M 895d20335f DataScript:
-Now doesn't create a new instance of NpcAPI
2023-05-30 01:27:34 -05:00
Luis C.M 1ce5b7b302 ScriptCustomItem:
-Fixed issue where NBT data was not being sent to the client side, caused by latest commit.
2023-05-30 00:56:39 -05:00
Luis C.M 7c4965d368 ScriptCustomItem:
-Made engine for containers also set on saving
2023-05-29 23:59:57 -05:00
Luis C.M a0adf0d7bd Fixed item toss event not being cancellable. Setting a script container's engine doesn't happen on every script call now, reducing lag. 2023-05-29 23:57:45 -05:00
Luis C.M 2ec6e5b753 PacketHandlerServer:
-Fixed global scripts still running old versions of their scripts when changed.
2023-05-26 00:22:14 -05:00
Luis C.M 130ac26879 ScriptContainer:
-Fixed issue where the full code the script engine evaluates wouldn't get remade after being changed
2023-05-25 22:18:54 -05:00
Luis C.M cbf99be297 PlayerData:
-Renamed loadPlayerDataFromFile() to load(), and moved it next to the save() function for later addition to the API.
-Moved saving/loading to EP functions where they used to be.
-Removed now unused PlayerData.get() and loadPlayerDataOld() functions

ServerEventsHandler:
-Added new EntityConstructing event to add the PlayerData EP earlier.

NoppesUtilPlayer:
-questCompletion() now saves player data right before its return statement.
2023-05-21 02:48:30 -05:00
Luis C.M dc42beee15 Merge branch 'dev' into patch
# Conflicts:
#	src/api
2023-05-20 21:15:14 -05:00
Luis C.M b49402f8bd Implemented ImageData object caching for custom GUI button & rect elements 2023-05-20 19:23:54 -05:00
Luis C.M 8df94aaf67 IDBCPlayer:
-Created separate mastery functions for racial and non-racial forms.
2023-05-20 16:13:15 -05:00
Luis C.M ed5cfad00d IDBCPlayer:
-Changed mastery functions to use a boolean for racial or non-racial forms.
2023-05-20 15:00:58 -05:00
Kam a9961ed740 Update to 1.8.4-beta 2023-05-19 14:29:08 -04:00
Kam 6700030890 Fix Animation on Players not finding body parts 2023-05-19 14:28:55 -04:00
Kam 02b44953cb Remove duplicate Quest Completed Message 2023-05-17 16:18:09 -04:00
Kam b8c3e9bef2 QuestData Null check for QuestKill 2023-05-17 12:21:38 -04:00
Kam 5b361d779f Fix Crate Crash 2023-05-17 11:43:43 -04:00
Kam 6df7d3643f Remove runTack() 2023-05-16 19:16:34 -04:00
Luis C.M e7ed34a591 Merge remote-tracking branch 'origin/dev' into dev 2023-05-16 18:02:19 -05:00
Kam a6cd55fcea Merge branch 'master' into patch 2023-05-16 17:46:42 -04:00
Kam f77a2ff101 Remove more threading 2023-05-16 17:45:23 -04:00
Kam 49fab85291 Revert lots of multithreading for better threaded saving and data synchronization 2023-05-16 17:43:54 -04:00
Kam 6f1914c002 Remove ClientSide 2023-05-16 17:33:28 -04:00
Kam d1901dcf0c Spoof 1.8.3 2023-05-16 17:17:47 -04:00
Kam 204e7a9c15 Revert Some Multithreading for Synchronization 2023-05-16 17:17:11 -04:00
Kam 892d11b89b Synchronized savePlayerDataMap 2023-05-16 14:40:16 -04:00
Kam b965d2e097 1.8.3 - version change 2023-05-16 14:33:06 -04:00
Kam 9e7e3c8e5d Merge pull request #76 from Dreamfinity/better-json-to-nbt-parsing
More NBT serialising and deserialising
2023-05-11 01:28:31 -04:00
georgii.imeshkenov 112305f059 wow looks like this string was not committed 2023-02-03 00:23:22 +03:00
georgii.imeshkenov 45f006b7bf de- and serialization of NBTTagByteArray from json based on post-array "b" suffix 2023-02-02 21:24:34 +03:00
49 changed files with 806 additions and 574 deletions

No files matched your search

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