I’m not really sure if what I’m asking makes sense. Here’s an example of something I currently have:
public class GameObject implements Serializable
{
protected static final long serialVersionUID = 1112122200L;
private int health, stamina, mana, xPos, yPos;
private String name;
public GameObject (String name, int xPos, int yPos)
{
this.name = name;
this.xPos = xPos;
this.yPos = yPos;
health = 100;
stamina = 100;
mana = 100;
}
public void setName(String name)
{
this.name = name;
}
public void setXPos(int xPos)
{
this.xPos = xPos;
}
public void setYPos(int yPos)
{
this.yPos = yPos;
}
public void setHealth(int health)
{
this.health = health;
}
// ETC. Setters and getters for all variables.
}
When I create a packet, I scoop all this up and send it in a packet. But all those getters and setters REALLY don’t need to be in there. Both the client and server know what an “Entity” is. Can I trim it down so it is just the following:
public class GameObject implements Serializable
{
protected static final long serialVersionUID = 1112122200L;
private int health, stamina, mana, xPos, yPos;
private String name;
public GameObject (String name, int xPos, int yPos)
{
this.name = name;
this.xPos = xPos;
this.yPos = yPos;
health = 100;
stamina = 100;
mana = 100;
}
}
And somehow have a second class with all the getters and setters? If I nest a second class in here, I know nested classes are not serializable… what will happen if I have a nested class, send it, then try to call that nested class?