Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2][SOLVED!] Capabilities and networking
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
MCrafterzz

[1.12.2][SOLVED!] Capabilities and networking

By MCrafterzz, April 18, 2018 in Modder Support

  • Reply to this topic
  • Start new topic
  • Prev
  • 1
  • 2
  • Next
  • Page 2 of 2  

Recommended Posts

MCrafterzz    10

MCrafterzz

MCrafterzz    10

  • Diamond Finder
  • MCrafterzz
  • Members
  • 10
  • 285 posts
Posted April 25, 2018

The problem with that is that it doesn't provide the player or any other information that can be used to get that. I need the players as I otherwise can't add the capability to it

  • Quote

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

[Creator of mcrafterzz mod]

Share this post


Link to post
Share on other sites

Alexiy    21

Alexiy

Alexiy    21

  • Creeper Killer
  • Alexiy
  • Forge Modder
  • 21
  • 195 posts
Posted April 25, 2018

Of course it doesn't, because this event is only fired on client, so you can get the client player "Minecraft.getMinecraft().player" as usual.

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2408

Draco18s

Draco18s    2408

  • Reality Controller
  • Draco18s
  • Members
  • 2408
  • 15946 posts
Posted April 25, 2018

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

You should not use it.

Use the ClientTickEvent

  • Thanks 1
  • Quote

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.

Share this post


Link to post
Share on other sites

Dragonisser    10

Dragonisser

Dragonisser    10

  • Creeper Killer
  • Dragonisser
  • Forge Modder
  • 10
  • 157 posts
Posted April 26, 2018 (edited)

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 April 26, 2018 by Dragonisser
  • Quote

Share this post


Link to post
Share on other sites

MCrafterzz    10

MCrafterzz

MCrafterzz    10

  • Diamond Finder
  • MCrafterzz
  • Members
  • 10
  • 285 posts
Posted April 26, 2018 (edited)

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 April 26, 2018 by MCrafterzz
  • Quote

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

[Creator of mcrafterzz mod]

Share this post


Link to post
Share on other sites

diesieben07    7622

diesieben07

diesieben07    7622

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7622
  • 55277 posts
Posted April 27, 2018
  • Your fromBytes method does nothing with the read value.
  • In the message handler you need to perform the action you want the key binding to have.
  • Quote

Share this post


Link to post
Share on other sites

MCrafterzz    10

MCrafterzz

MCrafterzz    10

  • Diamond Finder
  • MCrafterzz
  • Members
  • 10
  • 285 posts
Posted April 29, 2018 (edited)

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.

Edited April 29, 2018 by MCrafterzz
  • Quote

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

[Creator of mcrafterzz mod]

Share this post


Link to post
Share on other sites

diesieben07    7622

diesieben07

diesieben07    7622

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7622
  • 55277 posts
Posted April 29, 2018
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.

  • Quote

Share this post


Link to post
Share on other sites

MCrafterzz    10

MCrafterzz

MCrafterzz    10

  • Diamond Finder
  • MCrafterzz
  • Members
  • 10
  • 285 posts
Posted April 29, 2018

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

  • Quote

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

[Creator of mcrafterzz mod]

Share this post


Link to post
Share on other sites

diesieben07    7622

diesieben07

diesieben07    7622

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7622
  • 55277 posts
Posted April 29, 2018

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.

  • Quote

Share this post


Link to post
Share on other sites

MCrafterzz    10

MCrafterzz

MCrafterzz    10

  • Diamond Finder
  • MCrafterzz
  • Members
  • 10
  • 285 posts
Posted April 30, 2018 (edited)

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 April 30, 2018 by MCrafterzz
  • Quote

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

[Creator of mcrafterzz mod]

Share this post


Link to post
Share on other sites

NextInima    0

NextInima

NextInima    0

  • Tree Puncher
  • NextInima
  • Forge Modder
  • 0
  • 48 posts
Posted April 30, 2018 (edited)

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 April 30, 2018 by NextInima
  • Quote

May RPG MOD

 

KoRIN at minecraftforum

http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2570463-kingdom-of-rin-rpg-stuff-classes-dungeons

 

http://rin-online.de/forum/

Share this post


Link to post
Share on other sites

MCrafterzz    10

MCrafterzz

MCrafterzz    10

  • Diamond Finder
  • MCrafterzz
  • Members
  • 10
  • 285 posts
Posted April 30, 2018

I updated my previous message

  • Quote

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

[Creator of mcrafterzz mod]

Share this post


Link to post
Share on other sites

NextInima    0

NextInima

NextInima    0

  • Tree Puncher
  • NextInima
  • Forge Modder
  • 0
  • 48 posts
Posted April 30, 2018 (edited)

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 April 30, 2018 by NextInima
  • Quote

May RPG MOD

 

KoRIN at minecraftforum

http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2570463-kingdom-of-rin-rpg-stuff-classes-dungeons

 

http://rin-online.de/forum/

Share this post


Link to post
Share on other sites

diesieben07    7622

diesieben07

diesieben07    7622

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7622
  • 55277 posts
Posted April 30, 2018
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
  • Quote

Share this post


Link to post
Share on other sites

NextInima    0

NextInima

NextInima    0

  • Tree Puncher
  • NextInima
  • Forge Modder
  • 0
  • 48 posts
Posted April 30, 2018

yes you are right, i forgot that he want to work with the value and do not want to save it.. sry

  • Quote

May RPG MOD

 

KoRIN at minecraftforum

http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/2570463-kingdom-of-rin-rpg-stuff-classes-dungeons

 

http://rin-online.de/forum/

Share this post


Link to post
Share on other sites

MCrafterzz    10

MCrafterzz

MCrafterzz    10

  • Diamond Finder
  • MCrafterzz
  • Members
  • 10
  • 285 posts
Posted April 30, 2018

I think I finally got it working :D I changed the fromBytes to: keyboardDown = buf.readBoolean()

  • Quote

width=700 height=200http://i.imgur.com/J4rrGt6.png[/img]

[Creator of mcrafterzz mod]

Share this post


Link to post
Share on other sites
  • Prev
  • 1
  • 2
  • Next
  • Page 2 of 2  

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.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Maxi90909
      Forge 1.16.5 - 36.0.9 start up crash

      By Maxi90909 · Posted 8 minutes ago

      OK Thank you. I had 2 Random Patches datas in my mods folder.
    • matthyit
      my 1.16.5 modded game crashes after a while of playing

      By matthyit · Posted 8 minutes ago

      so i need to update java?
    • Luis_ST
      [1.16.5] Enchantments can Apply to all Tools

      By Luis_ST · Posted 12 minutes ago

      but eclipse say i have to set the cast
    • diesieben07
      [1.16.5] Enchantments can Apply to all Tools

      By diesieben07 · Posted 16 minutes ago

      Sure. Although you should not need that cast.   Actually. I looked again. No, that does not make sense. Why are you trying to cast the iterator.
    • Luis_ST
      [1.16.5] Enchantments can Apply to all Tools

      By Luis_ST · Posted 17 minutes ago

      than this while (enchantmentIterator.hasNext()) { Enchantment enchantment = (Enchantment) enchantmentIterator; if (!enchantment.isCompatibleWith(enchantmentIterator.next())) { enchantmentIterator.remove(); } }  
  • Topics

    • Maxi90909
      4
      Forge 1.16.5 - 36.0.9 start up crash

      By Maxi90909
      Started 1 hour ago

    • matthyit
      4
      my 1.16.5 modded game crashes after a while of playing

      By matthyit
      Started 2 hours ago

    • Luis_ST
      22
      [1.16.5] Enchantments can Apply to all Tools

      By Luis_ST
      Started Yesterday at 07:21 AM

    • Zockerbua
      1
      I need help

      By Zockerbua
      Started 47 minutes ago

    • domi0908
      6
      fix hitbox red baby mobs version forge

      By domi0908
      Started Tuesday at 03:04 PM

  • Who's Online (See full list)

    • matthyit
    • domi0908
    • Puma_MGP
    • xX_deadbush_Xx
    • Maxi90909
    • ozi
    • diesieben07
    • Ray99
    • Tavi007
    • Zemelua
    • Luis_ST
    • Stefan2007
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12.2][SOLVED!] Capabilities and networking
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community