Java 类net.minecraftforge.event.entity.living.LivingSpawnEvent.CheckSpawn 实例源码

项目:Mob-Option-Redux    文件:MobOptionsEventHandler.java   
/**
 * Checks spawning
 */
@SubscribeEvent
public void onSpawn(CheckSpawn event) {
    //If the entity is not a mob or above the forced-spawn-y-level, stop
    if (!(event.getEntity() instanceof EntityMob && event.getY() < underground))
        return;

    EntityMob mob = (EntityMob) event.getEntity();
    String name = EntityList.getEntityString(mob);

    //If whitelist and list contains mob, or blacklist and list does not contain mob
    if ((spawnWhitelist && mobsToSpawn.contains(name)) || (!(spawnWhitelist && mobsToSpawn.contains(name)))){
        //If the chance is within allowed mob-spawn-under-y-level range, and the game is not on Peaceful
        if (rand.nextFloat() < undergroundChance && event.getWorld().getDifficulty() != EnumDifficulty.PEACEFUL){
            //If there are no other entities in this area, and there are no collisions, and there is not a liquid
            if (event.getWorld().checkNoEntityCollision(mob.getEntityBoundingBox())
                    && event.getWorld().getCollisionBoxes(mob, mob.getEntityBoundingBox()).isEmpty()
                    && !event.getWorld().containsAnyLiquid(mob.getEntityBoundingBox())){
                //Allow the spawn
                event.setResult(Result.ALLOW);
            }
        }
    }

}
项目:geomastery    文件:EntityEvents.java   
/** Reduces animal spawns by half. */
@SubscribeEvent
public void checkSpawn(CheckSpawn event) {

    EntityLivingBase entity  = event.getEntityLiving();
    boolean canSpawn = true;

    if (entity instanceof EntityAnimal) {

        if (entity.world.rand.nextInt(2) == 0) {

            canSpawn = false;
        }
    }

    event.setResult(canSpawn ? Result.DEFAULT : Result.DENY);
}
项目:EnderZoo    文件:MobSpawnEventHandler.java   
@SubscribeEvent
public void onCheckSpawn(CheckSpawn evt) {
  if (evt.getEntityLiving() == null) {
    return;
  }
  String name = EntityList.getEntityString(evt.getEntityLiving());
  if (name == null) {
    return;
  }
  for (ISpawnEntry ent : MobSpawns.instance.getEntries()) {
    if (name.equals(ent.getMobName())) {
      if (!ent.canSpawnInDimension(evt.getWorld())) {
        evt.setResult(Result.DENY);
      }
    }
  }

}
项目:Proyecto-DASI    文件:ServerStateMachine.java   
/** Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world.*/
@SubscribeEvent
public void onCheckSpawn(CheckSpawn cs)
{
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null)
    {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);

        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty())
        {
            // Spawning is allowed, but restricted to our list.
            // Is this mob on our list?
            String mobName = EntityList.classToStringMapping.get(cs.entity.getClass()).toString();
            allowSpawning = false;
            for (EntityTypes mob : sic.getAllowedMobs())
            {
                if (mob.value().equals(mobName))
                {
                    allowSpawning = true;
                    break;
                }
            }
        }
    }
    if (allowSpawning)
        cs.setResult(Result.DEFAULT);
    else
        cs.setResult(Result.DENY);
}
项目:Proyecto-DASI    文件:ServerStateMachine.java   
/** Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world.*/
@SubscribeEvent
public void onCheckSpawn(CheckSpawn cs)
{
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null)
    {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);

        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty())
        {
            // Spawning is allowed, but restricted to our list.
            // Is this mob on our list?
            String mobName = EntityList.classToStringMapping.get(cs.entity.getClass()).toString();
            allowSpawning = false;
            for (EntityTypes mob : sic.getAllowedMobs())
            {
                if (mob.value().equals(mobName))
                {
                    allowSpawning = true;
                    break;
                }
            }
        }
    }
    if (allowSpawning)
        cs.setResult(Result.DEFAULT);
    else
        cs.setResult(Result.DENY);
}
项目:malmo    文件:ServerStateMachine.java   
/** Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world.*/
@SubscribeEvent
public void onCheckSpawn(CheckSpawn cs)
{
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null)
    {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);

        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty())
        {
            // Spawning is allowed, but restricted to our list.
            // Is this mob on our list?
            String mobName = EntityList.getEntityString(cs.getEntity());
            allowSpawning = false;
            for (EntityTypes mob : sic.getAllowedMobs())
            {
                if (mob.value().equals(mobName))
                {
                    allowSpawning = true;
                    break;
                }
            }
        }
    }
    if (allowSpawning)
        cs.setResult(Result.DEFAULT);
    else
        cs.setResult(Result.DENY);
}
项目:Dark-Utilities    文件:TileEntityMonolithSpawning.java   
@Override
public void onSpawnCheck (CheckSpawn event) {

    // Spawning Monolith will allways allow mobs to spawn.
    event.setResult(Result.ALLOW);

    // Start tracking the entity, so it can be modified later.
    this.trackedEntities.add(event.getEntityLiving());
}
项目:Dark-Utilities    文件:FeatureMonolith.java   
@SubscribeEvent
public void onMobSpawnCheck (CheckSpawn event) {

    if (event.getWorld() instanceof WorldServer) {

        for (final TileEntityMonolith monolith : getMonoliths((WorldServer) event.getWorld())) {

            if (monolith.isInSameChunk(new BlockPos(event.getX(), event.getY(), event.getZ()))) {

                monolith.onSpawnCheck(event);
                break;
            }
        }
    }
}
项目:ScottsTweaks    文件:SpawnGovernor.java   
@SuppressWarnings("MethodMayBeStatic")
@SubscribeEvent
public void onCheckSpawn(CheckSpawn event)
{
    if (event.entity.worldObj.isRemote) return;

    if (event.entity instanceof EntityBat || event.entity instanceof EntitySquid)
    {
        event.setResult(limitSpawn(event.entity));
    }
}
项目:Imperium    文件:EntityEvents.java   
@SubscribeEvent
public void onCheckSpawn(CheckSpawn event) {
    if(!event.entity.worldObj.isRemote) {
        if (event.entity instanceof EntityMob || event.entity instanceof IMob) {
            event.setResult(Result.DENY);
            return;
        }
        event.setResult(Result.ALLOW);
    }
}
项目:Dark-Utilities    文件:TileEntityMonolith.java   
public void onSpawnCheck (CheckSpawn event) {

    }