Jump to content

HalestormXV

Forge Modder
  • Posts

    328
  • Joined

  • Last visited

Everything posted by HalestormXV

  1. Got it, okay. It took me a minute. The first value is the number that is "clamped" (forced) to be within the second and third values and is returned. So by assining a new "temp" int just within that add or subtract function to be the result of the calculation of this.morality + points or - points I can then pass that "temp" int into the value area of .clamp then set value 1 and value 2 to the min and max and then return that result ("the temp" int) to = this.morality value.
  2. oh I gotcha, this.morality = this.morality - points MathHelper.clamp(this.morality, this.maxSin, this.MaxVirute, and vice versa for the adding. This way the min and max are obeyed if the player uses an item that icnreases their virtue by 50 and are already at 380 or something like that. And yeah the fields for min and max should have been used since they are going to be configurable in the future but I was typing to quick and not paying attention. that is indeed a nifty little piece of code. I gotta get more familar with that one.
  3. I've never used the MathHelper functions in forge, maybe once in 1.7.10. I forgot all about them actually. So your saying that doing something like public void addSin(int points) //Subtract Morality { MathHelper.clamp(this.morality -= points, -400, 400) //this.syncToClient(); } public void addVirtue(int points) //Add Morality { MathHelper.clamp(this.morality += points, -400, 400); // this.syncToClient(); } Would rectify that situation? I wasn't thinking about it currently becasue right now morality only goes up in values of 1 or -1 but I do plan to add items that will increase and decrease it by larger amounts in which case it could exceed the min and max at least intially on the item's use. As for creating a random instance and storing it. Is that a matter of efficency? Or quality of the random number produced? What would the difference be between the two methods? I ask because I have always created random values this way, as a matter of fact I thought it was the best way to do it? As for moving the synchronisation to the scale itself I am probably going to give it another shot becasue I kind of want it there also. I was just having so many problems with it being there and errors generating server crashing, etc it was absurd. (See my spoiler post). I know i was doing something wrong but I will proably give it another shot. Hardcoded messages, yes I will eventualy move away from them probably as I proceed through the mod and then ultimatey convert all my messages to my Lang. I don't use many messages as it is, it is mostly copy pasting my same messages over, so moving them to the Lang won't be so bad.
  4. I needed to bump this topic to mark it as what appears to be solved. (I couldn't seem to edit the topic title, but I don't want the thread locked either) After stepping away from the code for a while and working on something else it hit me like some bricks. I also took a look at the botania source code and managed to understand it because I know Vazki uses packets alot and even though our code style isn't similar I can understand it better. So in looking over the code there and then looking at my code I about pissed myself. Sending my packet to the client isn't hard once I stopped thinking so hard about it. So it seems my code works now but I would like another pair of eyes to view it to maybe confirm I am correct. Here is the code: MoralityScale: https://pastebin.com/7HB7qR0x SyncMoralityPacekt: https://pastebin.com/2V42WNPc PacketHandler: https://pastebin.com/FRkWvCVy Example of sending the packet in my event handler: https://pastebin.com/4T6BbZM7 Everything loads up fine and my debug message in the SyncMorality only shows up client side when testing. The message does not appear in the serverConsole, well because the server is sending it So please if someone can do a look over and confirm with me that this is the correct way to handle this (maybe not the most efficient) but gets the job done for now at least, I'd apprecaite it. And @Choonster I CANNOT thank you enough and I apprecaite you putting up with my noobyness. But I do want you to know that I learned something from every single post and will take it with me going forward lol. Especially my naming conventions. So thanks for all that And yes on my copy of the file I changed: Minecraft mc = Minecraft.getMinecraft(); World world = mc.world; EntityPlayer player = Minecraft.getMinecraft().player; to Minecraft mc = Minecraft.getMinecraft(); EntityPlayer player = mc.getMinecraft().player;
  5. Alright. And once again I apologize for my ignorance because I know once I figure it out I'm going to feel like an idiot because I know it isn't that difficult and I know this is likely just a mental block I'm not seeing past because I've done similar things to this. I think because it's I've just started remoding after a couple of years and trying to understand the whole new capabilities system I'm making this more difficult. So let me explain what I am likely going to have to do. Store the player field in the main class where I have my morality currently initialized to 0. Then on each function add in the player field (so then make changes accordingly to current spots the code is called). Add a new void SyncClient that has the Args for the morality value and the player. Create a packet that writes the passed value to the NBT (so later on if I do a bar or something the data is stored to disk client side and can be checked) am I looking st this correctly now? Or skip NBT all together and just have the packet call my SetMoraloty function?
  6. You have a brief example of what it may look like? I am trying to work it out and I am guessing that in my moralityScale i will have a void syncDataClient(entityPlayer player) then it will fetch the moreality value of the player passed into it and send it to the client in a packet using MyPacektHandler.sentTo(new SyncMoralityToClient, (EntityMP) player. Does it then need to write that using toBytes and fromBytes to a player NBT tag? I know it should not be this hard to pass one interger in a packet to the client but I just am having hte worst trouble with it for no reason.
  7. I actually managed to fix this up and get it working as intended. The idea was to be able to press a keyBind and then you will receive a message with your Morality. That worked and is working wonderfully both on a server and on a client, so I managed to get my packets set up correctly. However I have run into a new issue with a similar situation. Now I am trying to Sync the server and the client. In the future I plan to make a GUIBar that will reflect your Morality levels, however I want to lay the foundation. I followed a tutoiral that seems to have been updated to 1.11.2 and seems to work but I am getting a strange error and perhaps it is because I misunderstood the tutoiral but maybe reading it here will help me understand it better. Here is how it works currently. You break certain blocks the morality scales tip back and forth. I want to sync the client and the server everytime that happens. So here are my two packets. (Now please do mind you this was a tutoiral that I was following so perhaps I misunderstood or did something wrong). SyncMorality - https://pastebin.com/bnNkaE9P SyncMoralityReturn - https://pastebin.com/Kj7udWmR Those are the two packets and here is where I make the call in my event handler: (attached to a blockbreak) if (chance < 15) { EntityPlayer player = event.getPlayer(); IMorality morality = player.getCapability(moralityProvider.MORALITY_CAP, null); player.sendMessage(new TextComponentString("\u00A74" + "Your scales of morality have tipped to sin.")); morality.addSin(1); eAngelusPacketHandler.sendToServer(new SyncMorality(morality.getMorality(), "halestormxv.eAngelus.main.handlers.EA_EventHandler", Reference.MODID +":morality")); } } Now all works fine. When you break the block and the chance procs your morality will increase. And as you can see I call my sentToServer which produces this error: https://pastebin.com/pNXDHaMq I mean I understand the error (i think?), it is basically saying that the eangel:morality field doesnt exist. But it does, I am looking at it in the NBT data: So like I said, maybe I am misunderstanding something which is more than possible. So any help is apprecaited. Examples are excellent as well since I am one of those stare at it and study it learners (most of my learning comes from YouTube so I can pause and learn whats going on) I know i don't need to get the Sync system working IMMEDIATLY but I like to have the foundation laid out. If you need any of the other code just let me know and I will post it. Here is the capability code: https://pastebin.com/cKt9U5Be - moralityProvider https://pastebin.com/KA47rFYJ - moralityStorage https://pastebin.com/yJadAav3 - moralityScale And my interface just has the functions in it.
  8. I See, so the static class (since I implement the handler into the packe) should look something like this instead: public static class FetchMoralityHandler implements IMessageHandler<FetchMoralityPacket, IMessage> { // Do note that the default constructor is required, but implicitly defined in this case @Override public IMessage onMessage(FetchMoralityPacket message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; player.mcServer.addScheduledTask(() -> { IMorality morality = player.getCapability(moralityProvider.MORALITY_CAP, null); int amount = message.toSend; player.sendMessage(new TextComponentString("Your current morality is: " + morality.getMorality())); }); // No response packet return null; } } }
  9. I actually have a question for you. I've followed a number of your tutorials and tehy are great. Perhaps you can give me some feedback on this. This is my packetHandler: https://pastebin.com/K5vzgq9N This is my NetworkWrapper: https://pastebin.com/wYLKay8N This is my packet andler and network wrapper. This is from I think 1.8.2 or 1.9? I honestly can't remember sicne it has been so long. Is this still valid/effcient way to take care of this in 1.11.2?
  10. And it being a single interger shouldn't pose any issue right. If anything itd make it easier right?
  11. Quick question. I set up a capability and it works great. It is hooked up to an OnBlockBreak event. Basically, when you break a certain block there is a 15% change that the ability will activate and either increase or decrease the scale by 1 point. The capability is persistent and hooked up to the onCloned so it stays. What I want to do is set up a bar (guiOverlay, like an HP bar) that can increase or decreased based on the value of the capability. The capability can go negative which is fine. Here is a pic of the bar: So the red is the "background color" and basically is what will show once you start going negative. The blue is what will start filling up as you go positive. Your value starts at 0 so essentially it will display as half blue and half red. I know to solve all that you need to math and thats fine but what I want to know is do you need to involve packets since it is a capability? Or is it possible to get the capaibility and just read it. My gut says you need a packet since it is client fetching data from server for display but I figured I'd ask anyway.
  12. Yeah i noticed it after i made the post and made the edit up top. Thanks for the response though. Honestly sometimes i think the knowing "Your going to look like an idiot when somone sees this" fear sometimes makes you see the code better lol. At least for me because I may not be a phenomenal coder and still have a lot to learn, but stupid and silly mistakes like this always make me cringe especially when I know they are stupid and silly and I just can't see it. Any tips that you might have with the layout of the code?
  13. Alright at the risk of sounding and looking stupid I make this post. I'd like to preface this with I ported this code over from 1.9.2 or 1.8.2 (I can't exactly remeber as it has been quite some time) and I know there may have obivously been some changes, because this code worked in 1.9.2 and i beleive 1.8.2 on both Client and Server. But like I said I may be totally wrong as it has been quite some time. Now for some reason it works perfectly on the client but once you try to run the server with the mod it causes the server to crash with the following: https://pastebin.com/vqHcSXMs It clearly appears to be a NullPointer in my WorldGen. Here is the: WorldGen code: https://pastebin.com/eGLwqf8C Main: https://pastebin.com/ikm5Y1fd ClientProxy: https://pastebin.com/tU18bTPe CommonProxy: https://pastebin.com/B5kpeXSJ That should be all the relevant files. Perhaps it is because I don't have any .withProperty (I didn't think I needed properties unless 1.11.2 now requires them on my gens? Or maybe BlockMatcher is no longer used? Or hell maybe I am just registering it in the wrong spot on the proxy) Either way that is why I am posting here. I need some help, it's been a while since I have done modding and despite how dumb the error might be I will learn from it as I have done in the past. But I need the extra eyes to point it out to me. So I appologize in advanced for the noobyness but it has been some time. Also most of this setup was learned from old tutorials and older videos, that may have been good for their time, but perhaps there have been a number of changes that render those old tutorials obsolete (the way the main is setup, and proxies etc.) therefore rendering my code style obsolete at least for the 1.11.2. EDIT: I'm a flipping idiot. I registered all my items and blocks in my ClientProxy and not my CommonProxy (derp the server needs to know what is being registered also) and I was registering my worldGen in the CommonProxy. Moving my items and block registration into the CommonProxy fixed the issue. I'm guessing the same golden rule of ClientProxy ONLY handles renders and client side crap ONLY still stands strong? Feedback is still aprreciated or perhaps registering them this way is only a temp fix and something else may crash.
  14. Got it all squared away. Had to do a little hackery on the cooldown display porton but it now works. By hackery I mean minor adjustments that I am sure have much better ways to accomplish. But everything seems to work as intended. onUpdate is gone completly and the item strictly uses the world timer and the cooldown converts properly to minutes and the tooltip updates effectively and when the item becomes usable the cooldown message changes entirely. Here is the working code: https://pastebin.com/WcEXYnyR I am open to some suggestions but as it stands this seems to work flawlessly, unless someone can spot an error I missed. And ty Draco for the conversion formula and diesieben07 for suggesting the world time.The 3600 timer is hard-coded atm but will eventually be configuarable with a minimum of at least a minute to avoid breaking anything.
  15. Lol I figured that much but thank you. What I should have said was would it be wiser to create a method that calulates this and then call that method in the addToolTip since it updates every render frame, or would it be better to calculate that within the addTooltip segment of the code on its own.
  16. I see. Then I could calculate if 6000 ticks have passed (5 minutes) which I can still set to be configurable and if 6000 ticks have passed set offCooldown to true or something like that so you can use the item? Thus cutting out onUpdate completly. EDIT: I am screwing something up roally and it is probably so simple becasue I have been trying to work with this stupid orb forever. Here is the new code: https://pastebin.com/CstGLimw I only have it set to 200 ticks right now for testing purposes. But the issue is that once it calulates using + or - it goes negative. The debug line reads this: [16:19:44] [Server thread/INFO]: [STDOUT]: The cooldown variable is currently: 8928 Then after you store the information and use the orb once it reads this: [16:19:46] [Server thread/INFO]: [STDOUT]: The cooldown variable is currently: -54521 All i am trying to do is check if 200 ticks have passed from intitally using it which is stored in the nbt as the TotalWorldTime, So if we are 200 ticks greater than the intital used time (since a server doesn't go backwards lol) you get to use it again. Like i said, i am overthinking and probably missing the simplest detail. EDIT 2: Scratch that whole first edit. Looks like I fixed it. Not sure what changed really but it looks like part of my issue was that I wasn't clearing out the tag when trying to append data to it. I thought it would just overwrite it on its own but perhaps I am wrong. Anyway here is the new code that works with a 200 tick buffer. https://pastebin.com/43PvUJ8A Debugger [17:19:19] [Server thread/INFO]: [STDOUT]: Current World Time: 5973 [17:19:19] [Server thread/INFO]: [STDOUT]: Current Stored Time: 5910 [17:19:19] [Client thread/INFO]: [CHAT] §4The Scrying Orb is on cooldown. Last question I have is how I can make this display in "minutes" on the actual tooltip so players know how long of a cooldown remains. Rembmer that 200 tick buffer is going to be 6000 (configurable) which is 5 minutes in real time. So I would need a way to display the 6000 ticks remaining in minutes as a tooltip without using onUpdate since i removed it. I imagining this is where what you said Draco18s comes into play right. Do you have an example of what it might look like?
  17. Okay, I can see how that would be better. But on a server it will calulcate the server time and I imagine if a player is logged off and the timer expires once they log back in the tooltip will refresh itself right? This would efectively bind the cooldown to the server's world time, which is fine (my original plan was to make it configurable but configurations arent implemented yet). Effectively the start cooldown would be something like: this.startCoolDown(stack, world); protected void startCoolDown(ItemStack stack, World world) { if (stack.getTagCompound() != null) { //stack.getTagCompound().setInteger("coolDown", 6000); stack.getTagCompound().setLong("coolDown", world.getTotalWorldTime()); } } And then when you use it you would do something along the lines of long cooldown = this.getCoolDown(stack); protected int getCoolDown(ItemStack stack) { if ( (stack.getTagCompound() != null) && (stack.getTagCompound().hasKey("coolDown")) ) { return stack.getTagCompound().getLong("coolDown"); } return 0; } Then you would calculate a 5 minute difference between the two and would it be if you reach 0 you can use the item otherwise "It's on cooldown" or if 5 minutes has passed "It's on cooldown"? But what about displaying the remaining time left on the cooldown or does the addTooltip auto-refresh itself on its own, so simply having it display the coolDown tag is enough?
  18. Hello everyone. It has been quite some time since I was in the modding field. I was in it back with 1.7.10 and then stepped out for quite some time and am back in it with 1.11.2 (for now at least, soon I will bump to 1.12). I've gone through all the changes, updated my code and familizared myself with the jump from 1.7.10 to 1.11.2. But let me not divert from my inquiry. I have an item class that can teleport a player on use (the teleporting is still being worked on). The item displays its NBT on the tooltip. Tooltip, Stored Location and Cooldown timer, etc. The cooldown timer is 5 minutes or 6000 ticks. I have a couple of questions about this item. First the method I am using the grab the cooldown and change it to say 5 Min. or 4 Min or 3 Min. etc. is working fine and on the tooltip rather than count down every tick it properly updated to Cooldown: 5 Min. , Cooldown 4 Min. etc. However I noticed that once it reachs 0 it stays at 0 for a bit. I imagine this is because I am getting a remainder in my method. Perhaps a fresh set of eyes can view it and show how I can prevent that from happening. To be quite honest it only stays on 0 Min for a second or 2 and then properly updates the Tooltip to say it is ready for use, so this isn't a major concern if it can't be helepd. My second and probably more pressing question is how do I make it so that if the player is holding the item in there hand while it is on cooldown it is not constantly "refreshing" in their hand as if they are using it. I know this likely has to do with the onUpdate and with the NBT data changing so perhaps I can cancel the animation somehow? It is quite annoying to see the item constantly changing as the item's cooldown is ticking. Third and last question. As I indicated, it has been quite some time since I picked up my coder gloves and I only just starting modding with 1.11.2 about two days ago from this post so my optimizations are probably very rusty. Perhaps a brief indication of a better way to optimize the code would be helpful. Perhaps forge has new functions that I am not yet aware of etc. etc. Regardless I like efficient code, so if there are ways to optimize this class I would greatly appreciate some tips. Now after my long winded paragraph here is the code: https://pastebin.com/H6A160FQ
  19. Well chee that sucks lol. They use a single check. Well that kinda explains why people haven't messed with it really. recreating the Elytra segment of the LivingBase code is also quite ridiculous.
  20. Alright this may be quite a dumb question. But I was looking through some code and really can't find anything about the Elytra, other than the ItemElyta class in the vanilla code. I have done a number of searches and have not turned up anything good relating to Forge and "Elytra" creation. For example if someone want to "cough" create different variants of the Elytra that have armor and stuff. How could one do this? Can one even do this, or is the reason nothing turns up with searches related to modifying the Elytra is because people aren't sure how to do it? EDIT: After searching around these boards I have seen a handful of threads that try to replicate it and none of them seem to succeed. Although I did seem to find a thread that had the Elytra code posted. Perhaps the reason it isn't really done is because it is very difficult?
  21. I see. Well that's why I said it was a noob/rookie mistake lol. Anyway, I moved everything exceptmy ModelBakerStuff and RegisterRenders since I know that is client-side to my "CommonProxy" (ServerProxy) and just have ClientProxy extend that and call the supers and it seems like everything is working just fine. Including starting up the actual server and testing it on the client.
  22. I know but isn't that why the client is extending out the common so you can do it in one and then have them registered in the main? Isn't that like the "new way" or something from whatever tutorial I was watching to get started with 1.10.2 modding. Because I know originally in my 1.7.10, client side only stuff (rendering, models, keybinds, etc.) where only in the client side proxy. However now, or maybe I understood the method I posted above by extending the common proxy and using those implementation you dont need to register things in the ServerProxy/CommonProxy, that is the point of this "new style" and the only time you need to worry is when you are registering them in your main class. Or did I misunderstand that?
  23. http://pastebin.com/8ZzQt9Ux - Client http://pastebin.com/dRYcd45R - Common
  24. Yeah it is initialized in my main blocks class: http://pastebin.com/DPMEuKtn It also has its own class: And it works without crash when you launch the client. Can be spawned in, shows in my creative tab with its model/texture, and is placeable and mine-able.
×
×
  • Create New...

Important Information

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