Jump to content

Recommended Posts

Posted

I will use Forge 47.1.0 for Minecraft 1.20.1 as the example (offical mappings channel).

In MinecraftServer$createLevels, vanilla use the following code to add spawners for overworld:

List<CustomSpawner> list = ImmutableList.of(new PhantomSpawner(), new PatrolSpawner(), new CatSpawner(), new VillageSiege(), new WanderingTraderSpawner(serverleveldata));

I think it useful to post an event here to add spawners for overworld, and other dimensions. For example:

List<CustomSpawner> list = ImmutableList.of(new PhantomSpawner(), new PatrolSpawner(), new CatSpawner(), new VillageSiege(), new WanderingTraderSpawner(serverleveldata));
//change begin
AddCustomSpawnersEvent event = new AddCustomSpawnersEvent(ImmutableList.<CustomSpawner>builder().addAll(list), LevelStem.OVERWORLD);
MinecraftForge.EVENT_BUS.post(event);
LevelStem levelstem = registry.get(LevelStem.OVERWORLD);
ServerLevel serverlevel = new ServerLevel(this, this.executor, this.storageSource, serverleveldata, Level.OVERWORLD, levelstem, p_129816_, flag, j, event.getCustomSpawnerBuilder().build(), true, (RandomSequences)null);
//change end

//...

for(Map.Entry<ResourceKey<LevelStem>, LevelStem> entry : registry.entrySet()) {
   ResourceKey<LevelStem> resourcekey = entry.getKey();
   if (resourcekey != LevelStem.OVERWORLD) {
      ResourceKey<Level> resourcekey1 = ResourceKey.create(Registries.DIMENSION, resourcekey.location());
      DerivedLevelData derivedleveldata = new DerivedLevelData(this.worldData, serverleveldata);
//change begin
      AddCustomSpawnersEvent event = new AddCustomSpawnersEvent(ImmutableList.<CustomSpawner>builder(), resourcekey);
      MinecraftForge.EVENT_BUS.post(event);
      ServerLevel serverlevel1 = new ServerLevel(this, this.executor, this.storageSource, derivedleveldata, resourcekey1, entry.getValue(), p_129816_, flag, j, event.getCustomSpawnerBuilder().build(), false, randomsequences);
//change end
      worldborder.addListener(new BorderChangeListener.DelegateBorderChangeListener(serverlevel1.getWorldBorder()));
      this.levels.put(resourcekey1, serverlevel1);
      net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.level.LevelEvent.Load(levels.get(resourcekey)));
   }
}

Now the only way I can add custom spawners is to inject constructor of ServerLevel and modify final member customSpawners.

Posted

This isn't a bad idea, we typically have these things go through the GitHub PR system. However couple questions. All spawners get is a tick method. Why not use our level tick event?

The only information that spawners get is (this.spawnEnemies, this.spawnFriendlies), which are private fields, so we could add getters. 

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.