Jump to content

MrPlantPots

Members
  • Posts

    31
  • Joined

  • Last visited

Everything posted by MrPlantPots

  1. I believe this is the correct way to create a custom book without creating a new GUI, however the line bookPages.appendTag(new NBTTagString("hello hi")); will only add the string "hello" to the book and not the second half of the string. This is the same with the second page. Is there anyway to fix this? Also I'm guessing this is a terrible way of creating a custom book especially one with dynamic content, so if there are any better ways could somebody please explain! Thank you! Code: ItemStack book = new ItemStack(Items.written_book); NBTTagList bookPages = new NBTTagList(); bookPages.appendTag(new NBTTagString("hello hi")); bookPages.appendTag(new NBTTagString("page 2")); book.setTagInfo("pages", bookPages); book.setTagInfo("author", new NBTTagString("author")); book.setTagInfo("title", new NBTTagString("title")); playerIn.inventory.addItemStackToInventory(book);
  2. SPNWorldSavedData: package com.mrplantpots.spn.init; import java.util.ArrayList; import net.minecraft.client.Minecraft; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraft.world.WorldSavedData; import net.minecraft.world.storage.MapStorage; import com.mrplantpots.spn.Reference; public class SPNWorldSavedData extends WorldSavedData { private static final String DATA_NAME = "QUESTBOOK"; public static ArrayList<Quest> questBook; public static String[] questName = {"First Quest", "Second Quest", "Last Quest"}; public static String[] questDescription = {"Complete all objective to complete the quest.", "Try your hardest.", "You can do it!"}; public static String[] objName = {"Kill Herobrine", "Jump", "FLY", "FINAL"}; public static String[] objDescription = {"You have to slay Herobrine.", "You have to jump off a wall 3 blocks high.", "Fly higher than ever before.", "Kill yourself."}; public static Integer[] objQID = {0, 0, 1, 2}; private static NBTTagCompound data = new NBTTagCompound(); // Required constructors public SPNWorldSavedData() { super(DATA_NAME); } public SPNWorldSavedData(String s) { super(s); } @Override public void readFromNBT(NBTTagCompound compound) { data = compound.getCompoundTag(DATA_NAME); } @Override public void writeToNBT(NBTTagCompound compound) { compound.setTag(DATA_NAME, data); } public static SPNWorldSavedData get(World world) { // The IS_GLOBAL constant is there for clarity, and should be simplified into the right branch. MapStorage storage = world.getMapStorage(); SPNWorldSavedData instance = (SPNWorldSavedData) storage.loadData(SPNWorldSavedData.class, DATA_NAME); if (instance == null) { System.out.println("NULL"); instance = new SPNWorldSavedData(); storage.setData(DATA_NAME, instance); instance.getData().setInteger("qNum", questName.length); for(int i=0;i<questName.length;i++) { instance.getData().setString("q"+i+"name", questName[i]); instance.getData().setString("q"+i+"description", questDescription[i]); instance.getData().setBoolean("q"+i+"state", false); } instance.getData().setInteger("objNum", objName.length); for(int i=0;i<objName.length;i++){ instance.getData().setString("obj"+i+"name", objName[i]); instance.getData().setString("obj"+i+"description", objDescription[i]); instance.getData().setBoolean("obj"+i+"state", false); instance.getData().setInteger("obj"+i+"QID", objQID[i]); } instance.markDirty(); } else{ System.out.println("NOT NULL"); } return instance; } public static NBTTagCompound getData() { return data; } public void displayResults() { gatherData(); Minecraft.getMinecraft().thePlayer.sendChatMessage("PROCESS"); for(int i=0;i<questBook.size();i++) { Quest q = questBook.get(i); Minecraft.getMinecraft().thePlayer.sendChatMessage("-QUEST: "+q.get_name()+" | "+q.get_description()+" | Completed = "+q.get_state()); for(int x=0;x<questBook.get(i).get_objectiveArray().size();x++){ Objective obj = questBook.get(i).get_objectiveArray().get(x); System.out.println(obj.get_state()); Minecraft.getMinecraft().thePlayer.sendChatMessage("--Objective: "+obj.get_name()+" | "+obj.get_name()+" | Completed = "+obj.get_state());; } if(!q.get_state()) { int x=0; for(int j=0; j<q._objectiveArray.size(); j++){ if(q._objectiveArray.get(j).get_state()){ x+=1; } } System.out.println("X: "+x+" | Size: "+q._objectiveArray.size()); if(x==q._objectiveArray.size()) { q.set_state(true); Minecraft.getMinecraft().thePlayer.sendChatMessage("COMPLETED QUEST: "+q._name); q.set_state(true); getData().setBoolean("q"+q.get_QID()+"state", true); markDirty(); } } } } public void gatherData() { questBook = new ArrayList<Quest>(); int questNum = data.getInteger("qNum"); for(int i=0;i<questNum;i++) { questBook.add(new Quest(i, data.getString("q"+i+"name"), data.getString("q"+i+"description"), data.getBoolean("q"+i+"state"), new ArrayList<Objective>())); } int objNum = data.getInteger("objNum"); for(int i=0;i<objNum;i++) { questBook.get(data.getInteger("obj"+i+"QID")).addObjective(new Objective(questBook.get(data.getInteger("obj"+i+"QID")), data.getString("obj"+i+"name"), data.getString("obj"+i+"description"), data.getBoolean("obj"+i+"state"))); } } }
  3. Can I make it not a client only class?
  4. I have made a fully working mod for the client side, however I want the mod to work on the server. Everything works on the server side if I just use the same .jar mod files except for my custom commands, and also my WorldSavedData. The errors I am getting are supposedly from using a client side mod on a server but I can't find anywhere what to do to make it work? I can post a GitLab link to the project if you want but I'd rather send the log or PM you the link! Does anybody know a good tutorial for how to make my mod work on a server? I just have no clue what stuff needs to be done to make it work on a server! ServerLog: [15:56:36] [server thread/FATAL] [net.minecraft.server.MinecraftServer]: Error executing task java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: net/minecraft/client/Minecraft at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_91] at net.minecraft.util.Util.func_181617_a(SourceFile:46) [g.class:?] at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:664) [MinecraftServer.class:?] at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:386) [la.class:?] at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:609) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:467) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_91] Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/Minecraft at com.mrplantpots.spn.init.SPNWorldSavedData.displayResults(SPNWorldSavedData.java:80) ~[sPNWorldSavedData.class:?] at com.mrplantpots.spn.init.SupernaturalItemsEvents.func_77659_a(SupernaturalItemsEvents.java:30) ~[supernaturalItemsEvents.class:?] at net.minecraft.item.ItemStack.func_77957_a(ItemStack.java:159) ~[adq.class:?] at net.minecraft.server.management.PlayerInteractionManager.func_187250_a(PlayerInteractionManager.java:361) ~[ls.class:?] at net.minecraft.network.NetHandlerPlayServer.func_147346_a(NetHandlerPlayServer.java:712) ~[mb.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:32) ~[jh.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:9) ~[jh.class:?] at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[fh$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_91] at net.minecraft.util.Util.func_181617_a(SourceFile:45) ~[g.class:?] ... 5 more Caused by: java.lang.ClassNotFoundException: net.minecraft.client.Minecraft at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191) ~[launchwrapper-1.12.jar:?] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91] at com.mrplantpots.spn.init.SPNWorldSavedData.displayResults(SPNWorldSavedData.java:80) ~[sPNWorldSavedData.class:?] at com.mrplantpots.spn.init.SupernaturalItemsEvents.func_77659_a(SupernaturalItemsEvents.java:30) ~[supernaturalItemsEvents.class:?] at net.minecraft.item.ItemStack.func_77957_a(ItemStack.java:159) ~[adq.class:?] at net.minecraft.server.management.PlayerInteractionManager.func_187250_a(PlayerInteractionManager.java:361) ~[ls.class:?] at net.minecraft.network.NetHandlerPlayServer.func_147346_a(NetHandlerPlayServer.java:712) ~[mb.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:32) ~[jh.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:9) ~[jh.class:?] at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[fh$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_91] at net.minecraft.util.Util.func_181617_a(SourceFile:45) ~[g.class:?] ... 5 more Caused by: net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerException: Exception in class transformer net.minecraftforge.fml.common.asm.transformers.SideTransformer@7ac0e420 from coremod FMLCorePlugin at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:234) ~[forge-1.9-12.16.1.1887-universal.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.12.jar:?] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91] at com.mrplantpots.spn.init.SPNWorldSavedData.displayResults(SPNWorldSavedData.java:80) ~[sPNWorldSavedData.class:?] at com.mrplantpots.spn.init.SupernaturalItemsEvents.func_77659_a(SupernaturalItemsEvents.java:30) ~[supernaturalItemsEvents.class:?] at net.minecraft.item.ItemStack.func_77957_a(ItemStack.java:159) ~[adq.class:?] at net.minecraft.server.management.PlayerInteractionManager.func_187250_a(PlayerInteractionManager.java:361) ~[ls.class:?] at net.minecraft.network.NetHandlerPlayServer.func_147346_a(NetHandlerPlayServer.java:712) ~[mb.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:32) ~[jh.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:9) ~[jh.class:?] at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[fh$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_91] at net.minecraft.util.Util.func_181617_a(SourceFile:45) ~[g.class:?] ... 5 more Caused by: java.lang.RuntimeException: Attempted to load class bcf for invalid side SERVER at net.minecraftforge.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:49) ~[forge-1.9-12.16.1.1887-universal.jar:?] at net.minecraftforge.fml.common.asm.ASMTransformerWrapper$TransformerWrapper.transform(ASMTransformerWrapper.java:230) ~[forge-1.9-12.16.1.1887-universal.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.12.jar:?] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91] at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91] at com.mrplantpots.spn.init.SPNWorldSavedData.displayResults(SPNWorldSavedData.java:80) ~[sPNWorldSavedData.class:?] at com.mrplantpots.spn.init.SupernaturalItemsEvents.func_77659_a(SupernaturalItemsEvents.java:30) ~[supernaturalItemsEvents.class:?] at net.minecraft.item.ItemStack.func_77957_a(ItemStack.java:159) ~[adq.class:?] at net.minecraft.server.management.PlayerInteractionManager.func_187250_a(PlayerInteractionManager.java:361) ~[ls.class:?] at net.minecraft.network.NetHandlerPlayServer.func_147346_a(NetHandlerPlayServer.java:712) ~[mb.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:32) ~[jh.class:?] at net.minecraft.network.play.client.CPacketPlayerBlockPlacement.func_148833_a(SourceFile:9) ~[jh.class:?] at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[fh$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_91] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_91] at net.minecraft.util.Util.func_181617_a(SourceFile:45) ~[g.class:?] ... 5 more
  5. Is there anything wrong with this code: public class SPNWorldSavedData extends WorldSavedData { private static final String DATA_NAME = "QUESTBOOK"; private NBTTagCompound data = new NBTTagCompound(); // Required constructors public SPNWorldSavedData() { super(DATA_NAME); } public SPNWorldSavedData(String s) { super(s); } @Override public void readFromNBT(NBTTagCompound nbt) { // TODO Auto-generated method stub } @Override public void writeToNBT(NBTTagCompound nbt) { // TODO Auto-generated method stub } public static SPNWorldSavedData get(World world) { // The IS_GLOBAL constant is there for clarity, and should be simplified into the right branch. MapStorage storage = world.getMapStorage(); SPNWorldSavedData instance = (SPNWorldSavedData) storage.loadData(SPNWorldSavedData.class, DATA_NAME); if (instance == null) { instance = new SPNWorldSavedData(); storage.setData(DATA_NAME, instance); instance.getData().setString("obj0description", "DESCRIPTION"); instance.markDirty(); } return instance; } public NBTTagCompound getData() { return data; } } And how would I read and write to this data? Would this work: SPNWorldSavedData data = SPNWorldSavedData.get(world); data.getData().setString("obj0description", "value"); data.markDirty();
  6. I have completely followed this site : http://mcforge.readthedocs.io/en/latest/datastorage/worldsaveddata/ But the WorldSavedData simply wont stay if the world is closed and reopened. I have no clue what I am doing wrong?
  7. By initialise the WorldSaveData I meant add the NBT tags I created in the other class which I am now going to move into the worldSaveData class. The event it is in is currently an EntityJump event, however it will eventually be with the right click of the book. And the Reference class was unnecessary I'm not sure why I made it. I just need some help with writing the initial Quest Data to the WorldSaveData and then how I can read and write to it!
  8. The party option sounds appealing however, this is only intended for small servers where everybody plays together. I think I'm going to stick with global progress!!! Here was my attempt: WorldSaveData class: public class SPNWorldSavedData extends WorldSavedData { private static final String DATA_NAME = "QUESTBOOK"; private NBTTagCompound data = new NBTTagCompound(); // Required constructors public SPNWorldSavedData() { super(DATA_NAME); } public SPNWorldSavedData(String s) { super(s); } @Override public void readFromNBT(NBTTagCompound nbt) { // TODO Auto-generated method stub data = nbt; } @Override public void writeToNBT(NBTTagCompound nbt) { // TODO Auto-generated method stub nbt = data; } public static SPNWorldSavedData get(World world) { // The IS_GLOBAL constant is there for clarity, and should be simplified into the right branch. MapStorage storage = world.getMapStorage(); SPNWorldSavedData instance = (SPNWorldSavedData) storage.loadData(SPNWorldSavedData.class, DATA_NAME); if (instance == null) { instance = new SPNWorldSavedData(); storage.setData(DATA_NAME, instance); } return instance; } public NBTTagCompound getData() { return data; } } Code in world gen to initialise the WorldSaveData: SPNWorldSavedData data = SPNWorldSavedData.get(world); data.readFromNBT(NBTHandler.getNBTTag()); data.setDirty(true); Code in event handler to read data: SPNWorldSavedData data = SPNWorldSavedData.get(event.getEntityLiving().getEntityWorld()); NBTTagCompound nbt = new NBTTagCompound(); nbt = data.getData(); System.out.println(nbt.getString("obj0name")); Minecraft.getMinecraft().thePlayer.sendChatMessage("HIYA: "+nbt.getString("obj0description")); Reference Class (NBTHandler, purely used for organising code): public class NBTHandler { static NBTTagCompound nbt; static ItemStack book; public static void init() { nbt = new NBTTagCompound(); nbt.setString("obj0name", "NAME0"); nbt.setString("obj0description", "DESCRIPTION0"); nbt.setBoolean("obj0state", false); nbt.setInteger("obj0QID", 0); Block block = SupernaturalBlocks.angel_block; book = new ItemStack(SupernaturalItems.blood_bottle, 1, 15); System.out.println(book.getItem().getUnlocalizedName()); book.setTagCompound(nbt); } public static NBTTagCompound getNBTTag() { return nbt; } public static ItemStack getBook() { return book; } }
  9. I tried using WorldSaveData but I was told capabilities were a more suitable choice ! When I used WorldSaveData I had a few issues as it wasn't saving the data after the game closed? And I needed a way to only initialise the NBT in the WorldSaveData once!
  10. I've read both of those pages I am trying to create a quest book and if one player completes the quest it will be completed for every player. I'm just really confused about how the capability system that is attached to the player stores data server side? I just cant wrap my head around it!
  11. I am wanting to store data throughout the game which can be synchronised with every player, so everyone has the same data. I have been told that using a capability would be the best way to do this. I am just unsure of the procedure involved. Would I attach the capability to the EntityPlayer? If so, how am I meant to store that data on the server side, and how am I meant to synchronise it?
  12. This article mentions manual synchronisation between server side World Save Data and client side, how would I manage this? Would I just regularly have to update them all?
  13. Thank you, sorry I never saw the World Saved Data section! Thank you!
  14. I am working on creating a Quest Book. I have all the core functionality down, but I can't find a good way to store the data. I've decided NBT is the best idea, but I have no clue what things I can attach NBT data to, and what would be the best thing to attach it to? The data can't really be added to the quest book itself because what if they loose it? Also I want to data to be the same for each player, so preferably something that the data could be saved to on the Server Side? Can somebody suggest what would be the best thing to do?
  15. I have searched for hours finding a way to gather the right click when a certain item is in hand. I cant find any Events that work for me. I eventually want to open a GUI upon right clicking my item, however for now I just need to print to console once clicked
  16. I have had a quick look around and I cannot find anyway of storing custom data types as NBT. I want to be able to store my custom data type in game however it should exist only once and on server side
  17. I haven't researched NBT much, however I was wondering whether it would be possible to store a custom Java object(not minecraft object, like an instance of a java class) as NBT to an item? How would I go about doing this, can anyone help, or provide any pages that may cover this?
  18. Thank you, this seems like it should work for what I want to do. Would you mind explaining how I could create a dynamic book, that would change as different events are fired. I am not too sure how I could apply the capabilities to the Item and make it do this! Thank you
  19. I am wanting to create a book which will provide a task. on a single page. Once the task is completed I want the book to contain the next task. It could either just show one task at a time or show them all and tick them once completed, but they must be completed in order. I have absolutely no clue as to how I could get started. Does anybody have any tips, links, suggestions or code that could help with this?
  20. I am wanting to create a book which will provide a task. on a single page. Once the task is completed I want the book to contain the next task. It could either just show one task at a time or show them all and tick them once completed, but they must be completed in order. I have absolutely no clue as to how I could get started. Does anybody have any tips, links, suggestions or code that could help with this?
  21. I am new to modding, and I can't find anywhere how to use this, could you possible explain how I would go about doing this? Or what I should I search for?
  22. I am new to modding, and I can't find anywhere how to use this, could you possible explain how I would go about doing this? Or what I should I search for?
  23. I am trying to add a potion effect to an entity when I hit it. No methods I could find return an Entity every click besides "hitEntity", however that isn't working for me. If anybody knows how to fix this, or a different solution, any help would be great ! Code:[embed=425,349] @Override public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) { System.out.println("Testing"); return true; }[/embed]
  24. I am trying to add a potion effect to an entity when I hit it. No methods I could find return an Entity every click besides "hitEntity", however that isn't working for me. If anybody knows how to fix this, or a different solution, any help would be great ! Code:[embed=425,349] @Override public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) { System.out.println("Testing"); return true; }[/embed]
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.