Hello. I'm working with SimpleNetworkWrapper and my mod should spawn entity when it receives message. Message receiving works great, but when i'm trying to spawn enitity, it doesn't do it.
Here's my Message.java:
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
public class Message implements IMessage{
private String text;
public Message() { }
public Message(String text) {
this.text = text;
}
@Override
public void fromBytes(ByteBuf buf) {
text = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ByteBufUtils.writeUTF8String(buf, text);
}
public static class Handler implements IMessageHandler<Message, IMessage> {
@Override
public IMessage onMessage(Message message, MessageContext ctx) {
String[] action = message.text.split(" ");
System.out.println(String.format("Recieved message %s.", message.text));
if (action[0].equals("spawn")) {
WorldServer world = null;
double x, y, z;
for(WorldServer _world : DimensionManager.getWorlds()) {
if (_world.getWorldInfo().getWorldName().equals(action[1])) {
world = _world;
}
CrystallEntity crystall = new CrystallEntity(world);
x = Double.valueOf(action[2]);
y = Double.valueOf(action[3]);
z = Double.valueOf(action[4]);
crystall.setLocationAndAngles(x, y, z, 0.0F, 0.0F);
System.out.println(String.format("Trying to spawn a Crystall at %d %d %d", x, y, z));
world.spawnEntityInWorld(crystall);
}
}
return null; // no response in this case
}
}
}