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.

Featured Replies

Posted

Hey guys,

 

I have a problem with some strings after I send them from the Client to the server.

I need to split the string and after I split it the formatting is different then it is server side.

argh... long text short Question printf outputs me the following Strings:

@Potato

@Potato@

 

The first one is the output after I receive it with the server and Split it.

The Problem is I need it to get a value out of a HashMap can anybody help me?

And maybe explain me for what kind of formatting "@" stands for?

 

Thanks in advance - JTK222

Show some code?

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.

  • Author

private int recipeID;
private Block craftingStation;
private int stationID;
private String category;
public PacketCraft(){}

public PacketCraft(Block craftingStation,String Category, int recipeID){
	this.recipeID = recipeID;
	this.stationID = Block.getIdFromBlock(craftingStation);
	this.category = Category;
}

@Override
public void fromBytes(ByteBuf buf) {
	String[] temp = new String(Arrays.copyOfRange(buf.array(),1,buf.array().length)).split(";");
	recipeID = Integer.parseInt(temp[0]);
	stationID = Integer.parseInt(temp[1]);
	category = temp[2];

}

@Override
public void toBytes(ByteBuf buf) {
	String temp = String.valueOf(recipeID) + ";" + String.valueOf(stationID) + ";" + category;
	buf.writeBytes(temp.getBytes());
}

@Override
public void handleClientSide(PacketCraft message, EntityPlayer player) {}

@Override
public void handleServerSide(PacketCraft message, EntityPlayer player) {
CraftingManager.craftItem(message.stationID,message.category,message.recipeID,player);
}

 

Here it is. Haven't though that it might be important as I though its something more related to String in general

Ok, why the duck are you encoding the values into a string?  Just write them all to the bytebuffer.

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.

  • Author

Ok, why the duck are you encoding the values into a string?  Just write them all to the bytebuffer.

To say the truth I am not really understanding how the bytebuffer stuff is working my English isn't very good

and that creates the problem that googling explanations isn't the easiest thing when you don't know which words to use.

I have managed to write this Code after a few hours of google and maybe a few more hours of trial and error.

 

How could I read the Inserted Variables separately?

A Link to a good explaining tutorial would be a big help.

In toByes you write the two ints and the String you're sending to the ByteBuf and in fromBytes you read the two ints and the String from the ByteBuffer.

 

@Override
public void fromBytes(ByteBuf buf) {
    recipeID = buf.readInt();
    stationID = buf.readInt();
    category = ByteBufUtils.readUTF8String(buf);
}

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(recipeID);
    buf.writeInt(stationID);
    ByteBufUtils.writeUTF8String(buf, category);
}

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

  • Author

Oh man its so easy and I had so much Trouble with it *facepalm*

Big thx haven't known that this is existing:

ByteBufUtils.writeUTF8String(buf, category);

Makes a lot easier ^^

Big thanks - JTK222

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...

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.