Stronz Posted February 4, 2013 Posted February 4, 2013 I am having trouble when trying to spawn an Entity when my world is loading. The problem is that i need to spawn it when the world is loaded (No EntityRegistry.addSpawn(...)). I need this mod to make an Adventure map, which means that every entity should only be spawned once. To get my hands on a point where to world is loaded i used: Hidden TickRegistry.registerTickHandler(new WorldLoadTicker(), Side.CLIENT); An in my WorldLoadTicker: @Override public EnumSet<TickType> ticks() { // TODO Auto-generated method stub if(worldLoadet) { return null; } World theWorld = ModLoader.getMinecraftInstance().theWorld; if(theWorld != null) { System.out.println("world init"); if(theWorld.isRemote) { System.out.println("Remote"); }else{ System.out.println("Local"); } //onWorlLoad(theWorld); } return null; } The problem is that i can't spawn entitys in a remote world. but when i run the code i only receive an STDOUT msg which tells me that my world is remote. (entity spawning does work, but the entity does not move and i read, that i should never use "ModLoader.getMinecraftInstance().theWorld.spawnEntityInWorld()" if theWorld.isRemote()) I hope that I did make my problem clear. A quick respone will be appreciated. (pls forgive my possible bad spelling i am not a native english speaker) Quote
Mazetar Posted February 4, 2013 Posted February 4, 2013 well if the world IS remote, that means you are on the client side of things. And the client side shouldn't spawn entity's, the server should spawn them and then update the client about them. If the client somehow spawns and entity, the server wouldn't know about it, neither would any other clients(players) and the effects of the spawned entity would not do anything since the server doesn't know about it So Side.Client and isRemote means it's on the client side, which in turns means you should not be spawning entity's. Quote If you guys dont get it.. then well ya.. try harder...
gcewing Posted February 5, 2013 Posted February 5, 2013 To get notified on the server side when a world is loaded, you can do this in the main class of your mod: @ForgeSubscribe void onWorldLoad(WorldEvent.Load e) { ... } Quote
Stronz Posted February 5, 2013 Author Posted February 5, 2013 I added the fallowing in my main class, but i don't get any std out msg. Neither on if a run the mod via Starting the server and joning it, and also just starting the client. @ForgeSubscribe public void onWorldLoad(WorldEvent.Load e) { System.out.println("World loading main mod"); if (e.world.isRemote) { System.out.println("World is remote"); } else { System.out.println("World is local"); } } also i changed : @Mod(modid = "MadMod_modID", name = "MadMod", version = "1.0") @NetworkMod(clientSideRequired = true, serverSideRequired = false) to @Mod(modid = "MadMod_modID", name = "MadMod", version = "1.0") @NetworkMod(clientSideRequired = true, serverSideRequired = true) hopeing that it will allow me to use the onWorldLoad on the server. Did not work. Quote
Stronz Posted February 6, 2013 Author Posted February 6, 2013 Ok, I made a bit of progress. I registerd an EventHook to the MinecraftForge.EVENT_BUS.register(new MyEventHook()); inside the eventhook: @ForgeSubscribe public void onWorldLoad(WorldEvent.Load e) { //System.out.println("World loading main mod"); if (e.world.isRemote) { System.out.println("World is remote"); } else { System.out.println("World is local"); loadEntitys(e.world); } } in the loadEntitys function i am building the new Entitys from a xml file: protected void loadEntitys(World world) { ControllerUnitSaveLoad loader = new ControllerUnitSaveLoad(); ArrayList<EntityCreationSheet> entitySheetList = new ArrayList<EntityCreationSheet>(); try { entitySheetList = loader.importFromXml(new File(Config.modFile)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XMLStreamException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (entitySheetList == null) { System.out.println("Import failed"); return; } if (world.isRemote) { System.out.println("Never spawn entitys on a remote world"); return; } else { System.out.println("World is local --> spawning entitys"); } System.out.println("Placing " + entitySheetList.size() + " entitys in the world"); for (int i = 0; i < entitySheetList.size(); i++) { System.out.println("Placing entity"); EntitymadVillager npc = new EntitymadVillager(world); npc.buildVillager(entitySheetList.get(i)); world.spawnEntityInWorld(npc); npc.setPosition(60, 60, 60); } } but still i cant see the entity when i port to 60 60 60. Even tryed to sysout() the position of my entity in the update function : @Override public void onLivingUpdate() { // TODO Auto-generated method stub super.onLivingUpdate(); System.out.println("Posx: "+ posX+ " Posy: "+ posY+ "PosZ: "+posZ); } I dont' get why i dont get any sysout msg even though i registered and spawned the entity. Again help would be a appreciated Quote
Recommended Posts
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.