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

ok, can somebody PLEASE EXPLAIN TO ME why the HELL are these classes "@SideOnly(Side.CLIENT)" now? -_-

 

1)EntityFX

 

2)GUI related classes, server can't open GUI since "net.minecraft.client.gui" is involved!

 

anyone know what the hell im supposed to do then?

 

-sorash67 || Skorpio

SideOnly means that the thing is only used on a specific side. And When you then say Side.Client, you say, that it is only used on the client side.

its not a question of moving class to the right side, its a question of NOT using them on the wrong side

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

my apologies, i didnt state my question right. what can i do to be able to use the functions of them on the server side? for example, i have a gui with buttons, and my item class uses these buttons to function, but im not allowed to do this on the server side! so how do i implement buttons and their uses in the server?

 

-sorash67 || Skorpio

this seems weird to me but i think what you want to do is let the client do his things and use packets to communicate information between client-server

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

how to use packets ? yes, will i explain this in a forge forum post? no, please use the wiki somebody already spent time making a tutorial on how to use them :)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

well i dont mind helping but what do you need, if you know how to use packets then there shouldnt be any problem ??? ???

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

ahhh, ok, basicly you need to make a PacketHandler server side (register it in your main mod file)

 

 

mine looks like this

 


public class ForgeRevServerPacketHandler implements IPacketHandler {

@Override
public void onPacketData(INetworkManager manager,
		Packet250CustomPayload packet, Player player) {
                //here i do the stuff i need
}
}

btw im using a custom class for reading and writing packets  but basicly its the same as what the wiki says, and reading is the inverse of writing (OutputStream become InputStream etc)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

actually ... here, my packing helping class

 

good guy hydro giving away his tools

 

 

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;

import net.minecraft.network.packet.Packet250CustomPayload;

/**
* 
* @author hydroflame
* 
*/
public class PacketReadStream {
// not sure what this does, but it works with 8
// according to oracle javadoc on bytearrayinputstream the number is the
// number of byte for the stream... 
//edit: according to im high as fuck this variable isnt used anywhere
private static final int bytesForStream = 8;
private final DataInputStream inputStream;

/**
 * Creates a wrapper for a DataInputStream for easier reading.
 * 
 * @param packet
 *            : the packet to read from
 */
public PacketReadStream(Packet250CustomPayload packet) {
	inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
}

/**
 * Will return "" if there is an error reading
 * 
 * @return the next string stored in the packet.
 */
public String getText() {
	try {
		return inputStream.readUTF();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return "";
}

/**
 * Will return 0 if there is an error reading
 * 
 * @return the next int stored in the packet
 */
public int readInt() {
	try {
		return inputStream.readInt();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return 0;
}

/**
 * Will return 0 if there is an error reading
 * 
 * @return the next double stored in the packet
 */
public double readDouble() {
	try {
		return inputStream.readDouble();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return 0;
}

/**
 * Will return 0 if there is an error reading
 * 
 * @return the next float stored in the packet
 */
public float readFloat() {
	try {
		return inputStream.readFloat();
	} catch (IOException e) {
		e.printStackTrace();
	}
	return 0;
}

public boolean readBoolean() {
	try{
		return inputStream.readBoolean();
	}catch(Exception e){
		e.printStackTrace();
	}
	return false;
}

public long readLong() {
	try{
		return inputStream.readLong();
	}catch(Exception e){
		e.printStackTrace();
	}
	return 0;
}
}

 

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import net.minecraft.network.packet.Packet250CustomPayload;

public class PacketWriteStream {
private static final int bytesForStream =8;
private final ByteArrayOutputStream byteArrayOutputStream;
private final DataOutputStream dataOutputStream;

public PacketWriteStream() {
	byteArrayOutputStream = new ByteArrayOutputStream(bytesForStream);
	dataOutputStream = new DataOutputStream(byteArrayOutputStream);
}

/**
 * 
 * @param string to write into the packet
 * @return the object itself
 */
public PacketWriteStream put(String text) {
	try {
		dataOutputStream.writeUTF(text);
	} catch (IOException e) {

	}
	return this;
}

/**
 * 
 * @param float to write into the packet
 * @return the object itself
 */
public PacketWriteStream put(float x) {
	try {
		dataOutputStream.writeFloat(x);
	} catch (IOException e) {

	}
	return this;
}

/**
 * 
 * @param double to write into the packet
 * @return the object itself
 */
public PacketWriteStream put(double x) {
	try {
		dataOutputStream.writeDouble(x);
	} catch (IOException e) {

	}
	return this;
}

/**
 * 
 * @param int to write into the packet
 * @return the object itself
 */
public PacketWriteStream put(int x) {
	try {
		dataOutputStream.writeInt(x);
	} catch (IOException e) {

	}
	return this;
}

public PacketWriteStream put(boolean b){
	try{
		dataOutputStream.writeBoolean(b);
	}catch(Exception e){

	}
	return this;
}

public PacketWriteStream put(long l){
	try{
		dataOutputStream.writeLong(l);
	}catch(Exception e){

	}
	return this;
}

/**
 * 
 * @param channel: the name of the channel of the packet
 * @return a packet with the information of the PacketStream ready to be sent
 */
public Packet250CustomPayload makePacket(String channel) {
	Packet250CustomPayload packet = new Packet250CustomPayload();
	packet.channel = channel;
	packet.data = byteArrayOutputStream.toByteArray();
	packet.length = byteArrayOutputStream.size();
	try {
		dataOutputStream.close();
		byteArrayOutputStream.close();
	} catch (IOException e) {

	}
	return packet;
}
}

 

 

baiscly when you want to send a packet

 

PacketWriteStream stream = new PacketWriteStream();

stream.put(any primitive type)

PacketDispatcher.send*to whoever you want*(stream.makePacket("channel");

 

to read

PacketReadStream stream = new PacketReadStream(Packet);

int i = stream.readInt();

double b = stream.readDouble();

etc

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

why do you want to use a button on server side ?

technicly you could send a packet to the client saying "hey btw do thsi"

 

check Minecraft.getMinecraft().thePlayer.currentScreen to see if this GuiScreen is of type of the gui you want to interract with and if yes cast it and call the method to simulate this button press, but thsi seems very weird to want to press a button from server side

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

holy shit that is overcomplicate

 

just check that you are client side ...

 

if(world.isRemote){

player.openGui();

}

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

no actually thats not right ... can you jsut

 

 

spoiler your error trace ?

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

but the problem isnt opening the gui, its using the functions of its buttons! the error that i get when i use a button on the server is this:

Encountered an unexpected exception NoClassDefFoundError
java.lang.NoClassDefFoundError: moreores/tools/rainbow/GuiRainbowStaff
at moreores.tools.rainbow.ItemRainbowStaff.onItemRightClick(ItemRainbowStaff.java:57)

 

line 57 is this:

if(gui.mode == "lightning"){

 

look through the link i gave you to understand better what im trying to say!

 

-sorash67 || Skorpio

if(container.mode == "lightning"){

 

is what is in your code in the other thread, and theres no "container" anywhere

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

but if i understand correctly you want your item do shoot lightning if its in a certain mdoe and maybe other stuff in another, you should change this "mode" using the itemStack nbtTagCompound instead of tying this to a gui ...

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

You can send this "mode" (better, the guibutton id) of yours in a packet, alongside player username. The server can then change a variable in the item the given player has.

Guest
This topic is now closed to further replies.

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.