Jump to content

[1.12.2] How to detect feature-gen


DoctorLOGiQ
 Share

Recommended Posts

Hey guys. So I have a query, which doesn't come without much code-digging prior to asking.

I'm looking for the best way to have my mod detect when an end gateway is spawned.

I have tried listening for the event

net.minecraftforge.event.ForgeEventFactory.onChunkPopulate(false, this, this.world, this.rand, x, z, false);

which is called right after

(new WorldGenEndGateway()).generate(this.world, this.rand, blockpos1);

in Vanilla's ChunkGeneratorEnd script... but my mod isn't detecting this event. I am using

@SubscribeEvent
public static void onChunkPopulate(PopulateChunkEvent.Post event)

to listen for the event, and I have tried annotating the class with

@Mod.EventBusSubscriber

and registering it with

MinecraftForge.EVENT_BUS.register(...)

but to no avail. Am I doing something wrong? How can I detect when the gateways are spawned, preferably with access to the generation code?

 

Many thanks.

- Logiq

Link to comment
Share on other sites

Sure. This is the function. Upon testing, nothing happens, the System.out.println() doesn't even print. I have tested this by killing the Dragon. Each time a new end gateway is spawned, but nothing shows up in the console (and yes, I know Systmem.out.println() isn't the proper way to log, it's only temporary, and works with IDEA).

 

Function:

@SubscribeEvent
public static void onChunkPopulate(PopulateChunkEvent.Post event)
{
   System.out.println("End chunk population event");
   
   if (!event.getWorld().isRemote && event.getGen() instanceof ChunkGeneratorEnd)
   {
      World world = event.getWorld();
      ChunkGeneratorEnd generator = (ChunkGeneratorEnd) event.getGen();
      int chunkX = event.getChunkX(), chunkZ = event.getChunkZ();
      
      for (int x = 0; x < 16; x++)
      {
         for (int y = 8; y < 128; y++)
         {
            for (int z = 0; z < 16; z++)
            {
               if (world.getChunkFromChunkCoords(chunkX, chunkZ).getBlockState(new BlockPos(x, y, z)).getBlock() == Blocks.END_GATEWAY)
               {
                  System.out.println("Located gateway! Chunk X: " + chunkX + ", Chunk Z: " + chunkZ + ", Block X: " + x + ", Block Y: " + y + ", Block Z: " + z);
               }
            }
         }
      }
   }
}

 

Registration (during FMLInitializationEvent?

MinecraftForge.EVENT_BUS.register(new VppChunkGeneratorEnd());

3db82551f3db69e41365c3aa65119750.png

Edited by DoctorLOGiQ
Forgot to include attachment, derp
Link to comment
Share on other sites

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

 Share



×
×
  • Create New...

Important Information

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