Will LivingSpawnEvent.CheckSpawn also screw things up with players, or is that only a problem with entity join world event?
LivingSpawnEvent.CheckSpawn won't fire for players.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Cancelable events are annotated with @Cancelable, LivingSpawnEvent.CheckSpawn isn't so it can't be cancelled. Instead it's annotated with @HasResult, so you need to call Event#setResult to set the Result.
The doc comments of each event explain whether it can be cancelled or has a result and what each result means.
For LivingSpawnEvent.CheckSpawn, set the result to Result.DENY to prevent the spawn.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
You're using Entity#getCollisionBoundingBox, which only returns non-null for boats, minecarts and shulkers. Use Entity#getEntityBoundingBox instead.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Making progress! The block seems to work. Unfortunately, it works a bit too well. While it prevents all mob spawns, passive and hostile, in a 64 meter radius (or is it diameter in this case? not sure) it seems to prevent them even after the block is broken. The weird thing is, switching to peaceful then back to easy fixes it, so I don't think the problem is with the list. What could be causing this?
The number you call AxisAlignedBB#expandXyz with is the radius of the effect (if you treat the central block as a single point), though it's a cube rather than a sphere.
Post your current code.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
That looks mostly correct, but you're spawning particles regardless of whether the entity's spawn was cancelled.
You'll need to step through the code in the debugger to see why the spawn is cancelled even after the block is removed.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
After further testing, I think what was happening has more to do with how vanilla spawning works than my mod. Moving around seems to fix it. One thing I am slightly concerned about however is that when I added some code to print to console when a spawn is prevented, it spits out Spawn Canceled CONSTANTLY until the scarecrow is broken. Do mob-spawn events really happen that frequently?
EDIT: upon further investigation, almost every single prevented spawn is a bat spawn. WTF?
Every tick (in WorldEntitySpawner#findChunksForSpawning), the server creates a list of chunk positions within 8 chunks of each player (for a total of 225 per player, some of which may be the same as the positions picked for other players). For each EnumCreatureType, it then checks if it's reached the maximum number of entities of that type. If it hasn't, it then iterates through the unique chunk positions and tries 3-12 times to spawn a random entity in a random position within or around the chunk. If the position is valid and the entity is about to spawn, LivingSpawnEvent.CheckSpawn is fired.
If every random position was valid and every player was sufficiently spread out, the server could spawn anywhere from 2700 to 10800 entities a tick per player. It's unlikely to actually spawn this many because the random position won't always be valid for the entity being spawned.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
LivingSpawnEvent.CheckSpawn won't fire for players.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Awesome! One last question: will it also fire for spawn eggs?
My first mod =D
No, spawn eggs only fire EntityJoinWorldEvent.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Gotcha! I guess now the rigorous testing begins! I'll let you know how it goes
My first mod =D
Welp, every time I try to load my test world, the game crashes with this log:
http://pastebin.com/d3BKKk0C
I tried to fix it by preventing the event from being canceled on the client, and preventing it from being canceled if its an instanceof enityplayer.
My first mod =D
Cancelable events are annotated with @Cancelable, LivingSpawnEvent.CheckSpawn isn't so it can't be cancelled. Instead it's annotated with @HasResult, so you need to call Event#setResult to set the Result.
The doc comments of each event explain whether it can be cancelled or has a result and what each result means.
For LivingSpawnEvent.CheckSpawn, set the result to Result.DENY to prevent the spawn.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Ok, the world loads now, but this happens when I place the block
http://pastebin.com/uPTWp2nc
The problem seems to be with this line of code:
if(entity.getCollisionBoundingBox().intersectsWith(new AxisAlignedBB(pos).expandXyz(16)))
As you probably already know, that line checks if there is a mob within 16 blocks of the scarecrow.
My first mod =D
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Whoops! forgot to change that one
My first mod =D
Making progress! The block seems to work. Unfortunately, it works a bit too well. While it prevents all mob spawns, passive and hostile, in a 64 meter radius (or is it diameter in this case? not sure) it seems to prevent them even after the block is broken. The weird thing is, switching to peaceful then back to easy fixes it, so I don't think the problem is with the list. What could be causing this?
My first mod =D
The number you call AxisAlignedBB#expandXyz with is the radius of the effect (if you treat the central block as a single point), though it's a cube rather than a sphere.
Post your current code.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Gotcha!
Here's the tracking class:
http://pastebin.com/mKv0EJFC
Here's the event handler:
http://pastebin.com/cgLariB5
And here's the the block class:
http://pastebin.com/0Ngf1m7u
My first mod =D
That looks mostly correct, but you're spawning particles regardless of whether the entity's spawn was cancelled.
You'll need to step through the code in the debugger to see why the spawn is cancelled even after the block is removed.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
After further testing, I think what was happening has more to do with how vanilla spawning works than my mod. Moving around seems to fix it. One thing I am slightly concerned about however is that when I added some code to print to console when a spawn is prevented, it spits out Spawn Canceled CONSTANTLY until the scarecrow is broken. Do mob-spawn events really happen that frequently?
EDIT: upon further investigation, almost every single prevented spawn is a bat spawn. WTF?
My first mod =D
Every tick (in WorldEntitySpawner#findChunksForSpawning), the server creates a list of chunk positions within 8 chunks of each player (for a total of 225 per player, some of which may be the same as the positions picked for other players). For each EnumCreatureType, it then checks if it's reached the maximum number of entities of that type. If it hasn't, it then iterates through the unique chunk positions and tries 3-12 times to spawn a random entity in a random position within or around the chunk. If the position is valid and the entity is about to spawn, LivingSpawnEvent.CheckSpawn is fired.
If every random position was valid and every player was sufficiently spread out, the server could spawn anywhere from 2700 to 10800 entities a tick per player. It's unlikely to actually spawn this many because the random position won't always be valid for the entity being spawned.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Thank you for all your help. The scarecrow works perfectly. Unfortunately, he seems averse to wearing shirts. But that's a topic for a different thread.
My first mod =D
I'm glad you got it working.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.