Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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)

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 :P

 

So Side.Client and isRemote means it's on the client side, which in turns means you should not be spawning entity's.

 

 

If you guys dont get it.. then well ya.. try harder...

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) {
        ...
    }

  • Author

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.  :(

 

 

  • Author

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.