Jump to content

Recommended Posts

Posted

I am trying to code a Mod that will add a codeLock (atm its just a block without a texture). In a GUI with buttons i want to change the password for the codeLock if no password was set. ATM it works until i unload the map. If i load it again the password is "" (so it wont save the password corretly). I read some tutorials about NBTTags but they didnt help me.

 

I would be happy about some hints.

 

Here is my code:

 

(ATM i am changing the lockCode in my GUICodeLockBlock class file and i dont know if that is right - and yes, i registered the tileentity in my basemod class file)

 

  Reveal hidden contents

 

 

 

  Reveal hidden contents

 

Posted

Nice thank you very much. I read some tutorials about packethandler, but didn't figure out how to realize this in my special case (in the tutorials were send messages in chat). The problem is nearly solved, but if you know a tutorial how to send packages between GUI and tile entity I would be happy if you could post a link.

 

greets

MagicHaze

Posted

Hi

 

Here is some more information about Packet Handling in vanilla, which might be useful for background information.

http://greyminecraftcoder.blogspot.com/2013/10/client-server-communication-using.html

 

I think your best bet is to use the custom packet as shown in the tutorial you already looked at.

On the client, send the new code to the server along with the [x,y,z] of the TileEntity using Packet250

On the server, find the TileEntity with that [x,y,z] and set the new code, then send the TileEntity information back to all the Clients using Packet132 (for example see TileEntityMobSpawner.getDescriptionPacket().  (The method name is misleading.))

 

-TGG

 

 

Posted

I copied this code to my project now. It sends packets, it writes/reads fromt the nbt but if i close minecraft and start it again he loads the right passwords from the nbt (i saw it in the console) but if i activate the block again the nbt entry for the password is null. Another problem is, that all blocks get the same password. If i change the password for any block all blocks get these password.

 

Thank you for the link. Looks complicated but ill give it a try.

 

 

  Reveal hidden contents

 

 

 

  Reveal hidden contents

 

 

 

Posted

public static String codeInput;

This is why all blocks have the same password.

You don't even use the block coordinates to set the password, how would you expect that to work  ?

Posted
  On 10/20/2013 at 8:29 AM, GotoLink said:

public static String codeInput;

This is why all blocks have the same password.

You don't even use the block coordinates to set the password, how would you expect that to work  ?

 

Yeah, that question wasnt smart. I copied the code from the tutorial i read and changed it step by step (i had to change some code to get it work without the static String). But now i figured out how it to code it and it works well. There is only one more question, i have. Is it possible to realize it without a new packet handler? ATM i am comparing attributes of the tileentity in the gui class (here its the clientcopy of the fileentity, isnt it?) file and comparing/changing them in the packet handler (here its the tileentity of the server, isnt it?). I would like to remove the packethandler and handle the packets directly in the tileentity (looks better for me). Then i would just create a packethelper, that i just need to pass the data for the packet to the packethelper which sends them in a packet (so i wont need to write tons of code for every packet i want to send in the gui class file).

 

Thank you guys, i am very happy that it works now and i think i figured out how sending packets (put the information in a packet, send it, get them on the server side, handle them and by the update method the client gets a copie of the server tileentity?) works.

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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