Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Roboguy99

Members
  • Joined

  • Last visited

Everything posted by Roboguy99

  1. I'm going to sound like some lazy arse programmer who just copies and pastes people's code without understanding, then makes a million excuses in reply, but here's what's happened: I've read and copied the code (I typed, didn't c+p) your tutorial with very little understanding of how the packets work. I was doing something else at the same time, so my attention was only half on programming. Failender told me I should use the constructor with arguments, so I assumed this meant send a string. He then told me to remove the string from the arguments, so I did. By this point I completely forgot that text field existed, and I was checking into this thread every now and then while doing something else. Thanks for the help, and I'll try to be less stupid in the future. It was entirely my fault, and I appreciate that. You guys are very useful, and I didn't mean to waste your time with a really noob mistake like that. EDIT: One last thing, because I'm confused myself silly with all this now. Do I get rid of all references to the string as I don't need it, and leave the fromBytes()/toBytes() blank or do I actually need the string, or something I've also somehow stupidly missed which is so blatantly obvious I need to go and punch a wall? If that sounded like it was against you, it seriously wasn't. I'm angry I didn't spot the text field sooner.
  2. The only thing I changed was this line: HotbarBag.networkWrapper.sendToAll(new InventoryUpdate()); I'll upload the rest of the packet related code so you can see that as well: Main class pre-init: Packet class:
  3. Ok I've done that and I get this:
  4. I'm not getting a crash log - NOTHING is happening. If I don't initialise with a string, I get a nep I am sending the packet using HotbarBag.networkWrapper.sendToAll(new InventoryUpdate("updateInventory")); I have also tried .sendToServer() and got the same result.
  5. Ok, but as I said with a message nothing happens.
  6. uploaded wrong class, whoops I'm changing it now. In answer to part 1 of your reply, that code was client-side. Lesson learned - make sure you paste the right thing before clicking submit.
  7. Ok I've created the packet, but I have a couple of problems. Firstly, my packet doesn't actually seem to be received. If I don't initialise InventoryUpdate (the IMessage class) with a string, it throws a nullpointerexception when encoding. If I do pass a string, nothing happens. Secondly, I have no idea how to actually use the packet to update the inventory. Here's the packet class:
  8. Ok thanks, I will create one then.
  9. Update as in change the the contents of slots.
  10. I want it so when the player clicks a button, their inventory, and another inventory, are both updated. The code to update the inventory is triggered client-side, so as soon as you try to open the updated inventory it un-updates because the server was unaware of the change. Do I need to write a load of packet-handling code or is there a much easier way of doing this?
  11. Caused a nullpointerexception updating the inventory because no item had been select to update (an item is selected on key release). I'll try jiggling around some code to see if it will work. Also, has anybody got a link to a tutorial on updating the inventory client-side (or would it be better to move the update code to a common class instead?) EDIT: If I set it to true, I get exactly the same result.
  12. Ok I have no idea when I removed that, because I remember it being there, but it's now not set to anything (just private boolean pressedLastTick; ). I still have to press the key twice for it to work.
  13. Hmm, well it's not working. I'll upload the class in which the game is unfocussed and the HUD is drawn, because it must be something in there. I hate logic.
  14. Whoops. I actually did, that just more testing before I sent the code.
  15. Using .getIsKeyPressed() I got the same result (HUD renders for 1 tick and game remains unfocussed first button press, second button press acts as expected). I then tried .isPressed() and now the HUD only renders for 1 tick and the game never re-focusses. Here's my code, just in case I've done something stupid: private boolean pressedLastTick = false; @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { if (event.phase == TickEvent.Phase.START) { if (pressedLastTick && !HotbarBag.bagHUD.isPressed()) { Minecraft.getMinecraft().setIngameFocus(); } pressedLastTick = HotbarBag.bagHUD.getIsKeyPressed(); } }
  16. I want it to be true as the key is let go of, so as it is released (not true for as long as the key is not pressed, otherwise I could have just used !keyIsPressed() couldn't I?). The problem is it is only set to true if you release it twice for some reason.
  17. For some reason keyReleased is not set to true unless I release the key, press it and release it again. Here is the entire class: public class TickEventHandler { public static boolean keyReleased = false; @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { if (event.phase == TickEvent.Phase.START) { if (keyReleased && !HotbarBag.bagHUD.getIsKeyPressed()) this.keyReleased = true; keyReleased = HotbarBag.bagHUD.getIsKeyPressed(); System.out.println(this.keyReleased); } } } This is also causing the HUD to only render for one frame. Here's the check for that: if (TickEventHandler.keyReleased && !minecraft.inGameHasFocus) minecraft.setIngameFocus(); Sorry if I'm making really stupid basic Java mistakes, but it's the first week back at school and I'm tired
  18. I'll admit I did very quickly skim through the answer in between doing something else. Thanks.
  19. I probably should have made this clear, but I need to know when the key is actually let go of, not just all the time it's not held down. Or maybe I did make this clear, and you've answered that? Sorry for the stupid questions.
  20. I need to know when a key is released, and have noticed no built in method for this. How would I make one?
  21. Ok so I can unfocus the game without a problem, but making sure it's focussed again when the button is released is quite hard: a) I don't wan't to keep the game focussed even when other HUD elements (i.e the chat or pause menu) are trying to open because this breaks them and b) I want my HUD element to appear for more than one frame. I suppose what I'm asking by hinting at my problems is how do I toggle the focus on button press without keeping it stuck in focus the whole time the button is not pressed? Would I need to write a keyUp method (this could do with being implemented into Forge, I might look into writing and pushing it when I've got time), or is there a better way? Here's the whole class (mostly) to (maybe) make life easier:
  22. This seems like it should work. I'm going to have to play with it a bit, because you have to manually re-set the focus when the key is no longer pressed. If the other method doesn't work, I will use a GUI. It sounds easy enough, although I'll need to find out how packets work.
  23. My weapon wheel is rendered straight onto the HUD because it was easier to dynamically adjust the size this way. Would opening a GUI still work, and would I just have to open it client-side?
  24. So the idea is when the player holds down a key, a HUD appears showing items stored in an inventory in a GTA V-style weapon wheel. The rendering is all done, but I'd like the user to be able to move their cursor over one of the options and click (or move the cursor and let go of the key without clicking, doesn't really matter). So I need to know the mouse co-ordinates and possibly when they click essentially.
  25. I want to make it so when the player presses a key (my keybind is already working) the cursor is unlocked from the centre like when you use a Gui, and locked again when the player lets go. How would I do this?

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.