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

Hey all, I'm looking to make a simple mod that disables mobs from spawning in a square around a chunk. I'm new to Java (and therefore Minecraft Modding), so I poked around last night to come up with a simple Event Listener that intercepts new spawns and entity.remove()s the new entity before it can spawn. This seems inefficient because of game mechanics and ongoing spawns, so I was hoping that there was a way to simply disable spawns in a given Chunk. Is this possible?

 

I suppose I'm a bit overwhelmed with the vast amount of classes and methods of Forge's documentation. Anyone have a good recommendation as to where I should start? Or is my code (below) a sufficient place to start?

 

    @SubscribeEvent
    public static void spawnEntity(LivingSpawnEvent event) {
        LivingEntity entity = event.getEntityLiving();
        double deltaX = entity.getPosX() - 50;
        double deltaY = entity.getPosY() - 4;
        double deltaZ = entity.getPosZ() - 50;

        double distance = (Math.sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ)));

        if (distance < 100) {
            entity.remove();
            NoSpawn.LOGGER.info("DELETED");
        } else {
            NoSpawn.LOGGER.info(distance);
        }
    }

 

Edited by BenGBoo

Simply get the chunk

 

Chunk chunk = mc.theWorld.getChunkFromChunkCoords(entity.getPosX(), entity.getPosZ());

Edited by NOctu

  • Author
1 hour ago, NOctu said:

Simply get the chunk

 


Chunk chunk = mc.theWorld.getChunkFromChunkCoords(entity.getPosX(), entity.getPosZ());

Oh, perfect! And is there any way to disable certain mobs / hostile mobs from spawning in this specific chunk?

  • Author
5 minutes ago, diesieben07 said:

This is not correct in so many ways.

  1. mc.theWorld implies two things:
    1. mc is a Minecraft instance, meaning this is the client. Which does not do mob spawning. As such this would be reaching across logical sides.
    2. theWorld has not been the name for this field in forever.
  2. getChunkFromChunkCoords is an ancient name.
  3. getPosX and getPosZ are block coordinates, getChunkFromChunkCoords requires chunk coordinates.

The correct way would be either World#getChunk(int, int) (which requries chunk coordinates) or World#getChunk(BlockPos) (which obviously requires block coordinates.

 

LivingSpawnEvent.CheckSpawn is the best you can do to achieve this. There is nothing built-in.

Awesome, thanks a bunch for the thorough answer, I really appreciate it!

  • 5 months later...

Are you the real BenGBoo, the one that deleted all the Minecraft survival games videos on Mineplex, because if it is I really enjoyed watching them. Especially with that laugh of yours.

Edited by Glasstler

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.