Jump to content

Recommended Posts

Posted

I have created a simple entity class to figure out how to get it to work on a server but when running solely the client I am able to use the spawn egg no problem to spawn the entity, but when I try it on a server, nothing happens (no errors or entity constructor called). The egg is there it just doesn't work on the server.

 

TestMod:

 

@Mod(name = TestMod.NAME, modid = TestMod.MODID, version = TestMod.VERSION, acceptedMinecraftVersions = TestMod.ACCEPTED_MINECRAFT_VERSIONS)
public class TestMod {

	public static final String NAME = "Test Mod";
	public static final String MODID = "testmod";
	public static final String VERSION = "1.0.0";
	public static final String ACCEPTED_MINECRAFT_VERSIONS = "[1.11.2]";
	public static final String PROXY_PATH = "com.testmod.proxy";

	@Instance
	public static TestMod instance;

	@SidedProxy(clientSide = TestMod.PROXY_PATH + ".ClientProxy", serverSide = TestMod.PROXY_PATH + ".ServerProxy")
	public static CommonProxy proxy;

	@EventHandler
	public void preInit(FMLPreInitializationEvent event) {
		proxy.preInit();
	}

	@EventHandler
	public void init(FMLInitializationEvent event) {
		proxy.init();
	}

	@EventHandler
	public void postInit(FMLPostInitializationEvent event) {
		proxy.postInit();
	}

}

 

Proxies:

 

public class CommonProxy {

	public void preInit() {
		NetworkHelper.registerMessages();
	}

	public void init() {
		
	}

	public void postInit() {
		
	}
	
	public EntityPlayer getPlayer(MessageContext ctx) {
		return ctx.getServerHandler().playerEntity;
	}

}

 

public class ServerProxy extends CommonProxy {
	
	public void preInit() {
		super.preInit();
		NetworkHelper.registerMessages();
	}

	public void init() {
		super.init();
	}

	public void postInit() {
		super.postInit();
	}
	
	public EntityPlayer getPlayer(MessageContext ctx) {
		return ctx.getServerHandler().playerEntity;
	}
	
}

 

public class ClientProxy extends CommonProxy {
	
	@Override
	public void preInit() {
		super.preInit();
	}

	@Override
	public void init() {
		super.init();
		EntityHelper.registerEntities();
		RenderingRegistry.registerEntityRenderingHandler(TestEntity.class, new RenderTestEntity(Minecraft.getMinecraft().getRenderManager()));
	}

	@Override
	public void postInit() {
		super.postInit();
	}

	@Override
	public EntityPlayer getPlayer(MessageContext ctx) {
		return ctx.side.isClient() ? Minecraft.getMinecraft().player : super.getPlayer(ctx);
	}
	
}

 

EntityHelper:

 

public class EntityHelper {

	private static int entityID = 3467;
	
	public static void registerEntities() {
		EntityHelper.register(TestEntity.class, "test_entity", 7951674, 7319108);
	}
	
	public static void renderEntities() {
		RenderingRegistry.registerEntityRenderingHandler(TestEntity.class, new RenderTestEntity(Minecraft.getMinecraft().getRenderManager()));
	}
	
	private static void register(Class<? extends Entity> entityClass, String entityName, int eggColour, int spotColour) {
		EntityRegistry.registerModEntity(new ResourceLocation("testmod:test_entity"), entityClass, entityName, entityID++, TestMod.instance, 128, 1, true, eggColour, spotColour);
	}
	
}

 

Posted

Well duh it doesn't work on the server. Look where you put EntityHelper.registerEntities();

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.

Posted
Just now, Draco18s said:

Well duh it doesn't work on the server. Look where you put EntityHelper.registerEntities();

 

If I put it in the CommonProxy or anywhere else I get this crash when starting the server:

 

Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/renderer/entity/Render for invalid side SERVER

 

public class CommonProxy {

	public void preInit() {
		NetworkHelper.registerMessages();
	}

	public void init() {
		EntityHelper.registerEntities(); // Error here
	}

	public void postInit() {
		
	}
	
	public EntityPlayer getPlayer(MessageContext ctx) {
		return ctx.getServerHandler().playerEntity;
	}

}

 

Posted

Okay, I have removed the rendering for now and moved the entity registration to the CommonProxy init and I still get this error:

 

Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/renderer/entity/Render for invalid side SERVER

 

Am I registering it wrong?

 

private static void register(Class<? extends Entity> entityClass, String entityName, int eggColour, int spotColour) {
	EntityRegistry.registerModEntity(new ResourceLocation("test_entity"), entityClass, entityName, entityID++, TestMod.instance, 128, 1, true, eggColour, spotColour);
}

 

public static void registerEntities() { // Which is called in the CommonProxy init
	EntityHelper.register(TestEntity.class, "test_entity", 0x000000, 0xffffff);
}

 

Posted
2 hours ago, harison513 said:

Oh wait, now its gone... I'm confused.

Eclipse probably got around to cleaning up your imports so that the renderer class is no longer loaded.

 

If you really need that renderer, then you should still use it, but only call it from your client proxy. Don't mix it in with actions that must execute on the server. Your problem was where you chose to make the jump to the proxy, not the need for it. Get those initialization things sorted between common and client.

 

Why do you bother with an EntityHelper class? Are any of those methods ever called from more than one place? Can't you just put their guts into the proxies from which they're called?

 

PS: Put @Override annotations on all methods that are supposed to be overrides.

 

PPS:

private static int entityID = 3467;

 

Looks like bad form. I think you should allow the system to allocate your entity ID and return it to you. Forcing any static ID for anything is just asking for trouble. How old is the tutorial you're working from?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
On 3/21/2017 at 1:10 PM, diesieben07 said:

Imports have nothing to do with when classes get loaded. In fact imports do not even appear in the compiled class files.

You've said that before, but I know from experience that a left-behind import statement alone can cause a class loading error (at least when running in Eclipse's debugger).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
7 hours ago, jeffryfisher said:

You've said that before, but I know from experience that a left-behind import statement alone can cause a class loading error (at least when running in Eclipse's debugger).

Imports are syntactic sugar. They avoid you having to use fully qualified names.

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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