Jump to content

Side-Only classes


sorash67

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

hmm... maybe it helps if you read the topic i posted here:

http://www.minecraftforum.net/topic/1907147-forge-server-side-custom-gui-with-buttons/

 

that's the reason why im trying to get a button function on the server side!

 

-sorash67 || Skorpio

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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