Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2][SOLVED!] Capabilities and networking


Recommended Posts

Which is fired for EVERY key that's pressed EVERY time its pressed.

You should not use it.

Use the ClientTickEvent

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

I did it like this last time to open my backpack item via a keybind. It shouldnt be that much different from 1.7.10 to 1.12.2

 

https://github.com/Dragonisser/CobaltMod/blob/master/src/main/java/cobaltmod/handler/event/CobaltKeyHandler.java#L53

 

https://github.com/Dragonisser/CobaltMod/blob/master/src/main/java/cobaltmod/network/packet/server/CobaltOpenGuiMessage.java

Edited by Dragonisser
Link to post
Share on other sites

I have fixed that. Now I only need to send the data over to the server which isn't currently working.

 

KeybindMessage: https://pastebin.com/neQQZggT

KeybindMessage: https://pastebin.com/aTCipDuP (Here I'm lost)

What should I add to get it working. Currently it only works on the client side.

Edited by MCrafterzz
Link to post
Share on other sites
3 hours ago, MCrafterzz said:

What I want is to move the client capability value to the server side of the itemblock methoud. How can this be achived? I can't do the action in message handler as it should be done when placing my block.

That is not the action for the keybinding then. The action for the keybinding is "hey, I am pressing the keybind now". You need to store that state in the capability.

Link to post
Share on other sites

Currently I'm detecting a key press on the client side and then storing that value as a player capability. But on the capability page on the docs it sais that the data has to be sent over to the server side with packets so that it somehow can be accessed on the SERVER side in the itemblock methoud. This is where I'm stuck. If you need any more code I can post it.

Here is the eventhandler class: https://pastebin.com/MAhwwzgM

Link to post
Share on other sites

In the setKeybindDown method you can detect if the state changed. If it has, send the packet to the server.

Then on the server when the packet is received, obtain the capability instance from the player that sent the packet and also update the state there.

Link to post
Share on other sites

I've updated my Eventhandler:

https://pastebin.com/0mYMp5Gz

 

And my KeybindMessageHandler: https://pastebin.com/SNGBFhqs

 

But it still doesn't work

 

EDIT: KeybindMessage: https://pastebin.com/pD2CdBMN

EDIT 2: Printing out Main.logger.warn(keybindDown) in the onMessage methoud always prints out false even tho the value sent is true.

Edited by MCrafterzz
Link to post
Share on other sites

better show the KeybindMessage class of yours.

 

in your capability you can create a setter method and set the value on the server. do not forget to save it in Nbt aswell.

 

Make sure that you register your packet for the SERVER side 
    

Quote

    INSTANCE.registerMessage(Packet.Handler.class, packet.class, ID of your packet, Side.SERVER);

 

onMessage you take the Entityplayer and get the CAPABILITY for that player.

Quote


player.getCapability().getyourmethodtogetthevalueyouwant();

 

 

now you use your setter to set the value you want. the server will save that if you fill serializeNBT and deserializeNBT in your CAPABILITY

 

Quote

player.getCapability().setyourmethodtosetthevalueyouwant();

 

Edited by NextInima
Link to post
Share on other sites

do you have checked what you have send to the server?

 

  1.   public KeybindMessage(boolean keybindDown) {
  2.         this.keybindDown = keybindDown;
    1. System.out.println(the key is: "+keybindDown);
  3.     }
 
            this.keybindDown = ByteBufUtils.readBoolean((buf);
Edited by NextInima
Link to post
Share on other sites
28 minutes ago, MCrafterzz said:

I've updated my Eventhandler:

https://pastebin.com/0mYMp5Gz

Why are you no longer using setKeybindDown on the client?

 

This is still the case, you need to fix this:

On 27.4.2018 at 9:00 AM, diesieben07 said:

Your fromBytes method does nothing with the read value.

 

23 minutes ago, NextInima said:

do not forget to save it in Nbt aswell.

Not applicable here at all.

  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.