Posted October 9, 20205 yr 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 October 9, 20205 yr by BenGBoo
October 9, 20205 yr Simply get the chunk Chunk chunk = mc.theWorld.getChunkFromChunkCoords(entity.getPosX(), entity.getPosZ()); Edited October 9, 20205 yr by NOctu
October 9, 20205 yr 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?
October 9, 20205 yr Author 5 minutes ago, diesieben07 said: This is not correct in so many ways. mc.theWorld implies two things: 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. theWorld has not been the name for this field in forever. getChunkFromChunkCoords is an ancient name. 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!
April 3, 20214 yr 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 April 3, 20214 yr 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.