Jump to content

[1.12.2] getTileEntityMap() cascading worldgen


MSpace-Dev

Recommended Posts

Hey all,

 

This code of mine is causing cascading worldgen. I'm lead to believe that the getTileEntityMap() call is what's causing the cascading worldgen.

 

Can anyone suggest optimisations to reduce the amount of calls to getTileEntityMap()? OR even if there is any other way of finding tile entities in a large area

 

Here is the function:

private static void findTileEntity(LivingSpawnEvent.CheckSpawn event, int radius)
{
  BlockPos pos = event.getEntity().getPosition();

  int chunkPosX = pos.getX() >> 4;
  int chunkPosZ = pos.getZ() >> 4;

  if (!event.getWorld().isRemote)
  {
    for (int x = chunkPosX - radius; x < chunkPosX + radius; x++)
    {
      for (int z = chunkPosZ - radius; z < chunkPosZ + radius; z++)
      {
        Map<BlockPos, TileEntity> currentChunkTE = event.getWorld().getChunkFromChunkCoords(x, z).getTileEntityMap();
        for (TileEntity te : currentChunkTE.values())
        {
          if (te != null)
          {
            if (te instanceof TileEntityBlockBase && radius == 8)
            {
              doSomething();
            }
          }
        }
      }
    }
  }
}

 

Thanks in advance.

Edited by MSpace-Dev
title and post changes to compliment solution
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
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.

×
×
  • Create New...

Important Information

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