Jump to content

Entity doesn't spawn


Farianit

Recommended Posts

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

Link to comment
Share on other sites

You cannot interact with the main Minecraft threads from the networking thread. See the warning at mcforge.readthedocs.org for more information.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Also don't implement IMessage and IMessageHandler in the same class file, you'll invariably mess something up.

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.

Link to comment
Share on other sites

Also don't implement IMessage and IMessageHandler in the same class file, you'll invariably mess something up.

 

I don't really agree with this. Implementing them both on a single class is a bad idea and can lead to confusion (which instance is the handler and which is the message?), but implementing one in a nested class of the other (like the OP has done) isn't likely to cause much confusion. You've still got two separate classes, but they're grouped together in one file instead of two.

 

To the OP: 1.7.10 is no longer supported here. You should update to 1.10.2.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I don't really agree with this. Implementing them both on a single class is a bad idea and can lead to confusion (which instance is the handler and which is the message?), but implementing one in a nested class of the other (like the OP has done) isn't likely to cause much confusion. You've still got two separate classes, but they're grouped together in one file instead of two.

 

Personally, I still think it helps to have the classes in different files.  There was another poster about a week ago who'd used the nested class structure and was having an issue that as soon as I suggested he use separate files he found and fixed his problem.

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.

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.