need help with changing monster spawns

Discussion in 'Plugin Development' started by sluvine, Mar 11, 2011.

Thread Status:
Not open for further replies.
  1. Offline


    So I just finished getting myself set up with a github acct and got my IDE ready to go. Before I dive headfirst into the bukkit code though, I figured I should ask where I should start with this plugin.

    Here's the idea:
    The players on my server want monster spawning to change, and I agree. My opinion is that the idea behind light-level based spawning came from the desire to keep monsters out of civilized areas. This forces the player to create some semblance of "civilization" in the game that the monsters aren't able to spawn in. I'd like to take it one step further though, mostly because my players don't want to cover the above-ground area of our cities with a grid of torches every 7 spaces, but we want to have a sense of danger when venturing outside the town walls or going deep into unexplored caves.

    Basically, my plan is to hook into the monster spawning events and add an additional condition for an acceptable spawn point. My current idea is to keep monsters from spawning within 30 blocks or so of any "man-made" block, that being any block that doesn't occur naturally in the environment (cobblestone, iron/gold/diamond blocks, glass, wood planks, etc).

    What I'm hoping to find here is some help with some useful methods and classes that I should be looking into to do this as simply and as cleanly as possible. I want to avoid hooking into another bukkit plugin as possible to keep this dependent only on craftbukkit.

    I'd really appreciate any advice that anyone can give me!
  2. Offline


    I like the idea but it wont work too well, could get exploited though... walk 30 blocks from my home place cobble then do the same each side.. now my house in the wild is safe from monster spawns.

    And then, what about mob dungeons? mobs wont spawn in em no more.

    So what i'd suggest is using worldGuard regions to make no spawn areas... all you need to do is check if mobdamage is set to off for the regions then disallow spawning...

    even better would be to code it and put in a pull request in github so that they add it into WG
  3. Offline


    I ended up making the radius much smaller. Now it checks 16 blocks around and 4 blocks up and down for the specified materials. Eventually I'm going to make it all configurable (the radius and the materials). I also solved spawning on trees (another feature that I know some people like, but the players on my server don't) by adding an additional loop that looks in a 10x10 area on the level the spawn is being attempted at as well as the one directly below it. It doesn't look above the spawn, so mobs still spawn under trees when they should.

    I'm going to try and fix the mob dungeon issue though. I'm thinking of first checking to see if there is a mob spawner within a certain range. If there is, we return from my function without cancelling the event. All the other checks would be skipped.

    As for WG... do the no-spawn areas include animals/peaceful mobs? I'd still like them to spawn normally (and they do currently with my plugin). I guess I should have looked into existing plugins a little more, but on the surface it looked like there wasn't anything that did what I was trying to do.

    What do you think about the mob spawner idea? I think that would solve the issue with dungeons.

    Can you think of some other way to fix the exploit you were talking about? I was thinking maybe nesting the if(the material near the spawn == cobble || == woodplanks || etc) statement within itself so that it has to find at least two of those things within the radius. Could even do it several times over.

    At any rate, thanks for the feedback.
    Actually, for exploit control, it might actually be better for me to hold off on calling event.setCancelled(true) inside the loop. Instead, in the loop, I increment a counter that checks for a configurable number of conditions. After the loop runs, if it meets the threshold for constructed blocks, it cancels the event, if not, we go on as normal.
    by the way, the plugin is released here now, I plan on continuing to work on it though as often as I can.
Thread Status:
Not open for further replies.

Share This Page