Jump to content

[1.12.2] Stopping mob spawns


Merthew

Recommended Posts

You can use LivingSpawnEvent.CheckSpawn to detect the spawning itself, then either iterate all TEs in neighbouring chunks to check for your special TE that prevents the spawning(may be slow and won't work if the chunk is unloaded, the TE in this case doesn't need to be a ticking one) or you can attach a capability to the world that would store an array of positions of your blocks that prevent spawning that you update every time one of your blocks is placed/broken and then you can check against that array. In any case setting the resulf of the event to DENY will prevent spawning. You will still need to check that the mob that spawns is hostile.

Link to comment
Share on other sites

This is what i came up with, any thoughts?

@SubscribeEvent
	public void bloodTotem(LivingSpawnEvent event) {
		World world = event.getWorld();
		double range = 32.0;
		for(int i = 0; i < world.loadedTileEntityList.size(); i ++) {
			if(world.loadedTileEntityList.get(i) instanceof TileEntityBloodTotem) {
				BlockPos pos = world.loadedTileEntityList.get(i).getPos();
				if(pos.getDistance((int)event.getX(), (int)event.getY(), (int)event.getZ()) <= range) {
					event.setResult(Result.DENY);
				}
				
			}
		}
	}

 

The seven became one and the one became two.

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.

Announcements



×
×
  • Create New...

Important Information

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