@SubscribeEvent public void onEntitySpawnEvent(LivingSpawnEvent.CheckSpawn event) { int i = 0; for (SpawnRule rule : RulesManager.rules) { if (rule.match(event)) { Event.Result result = rule.getResult(); if (debug) { InControl.logger.log(Level.INFO, "Rule " + i + ": "+ result + " entity: " + event.getEntity().getName() + " y: " + event.getY() + " biome: " + event.getWorld().getBiome(new BlockPos(event.getX(), event.getY(), event.getZ())).getBiomeName()); } event.setResult(result); if (result != Event.Result.DENY) { rule.action(event); } return; } i++; } }
@SubscribeEvent public void medicSpawn(LivingSpawnEvent.SpecialSpawn event) { float chance = 0; if (event.getEntity() instanceof EntityHeavy) { chance = 0.16f; } else if (event.getEntity() instanceof EntitySoldier) { chance = 0.08f; } else if (event.getEntity() instanceof EntityDemoman) { chance = 0.07f; } else if (event.getEntity() instanceof EntityPyro) { chance = 0.06f; } else return; chance *= TF2ConfigVars.medicChance; if (event.getWorld().rand.nextFloat() < event.getWorld().getDifficulty().getDifficultyId() * chance) { EntityMedic medic = new EntityMedic(event.getWorld()); medic.setLocationAndAngles(event.getEntity().posX + event.getWorld().rand.nextDouble() * 0.5 - 0.25, event.getEntity().posY, event.getEntity().posZ + event.getWorld().rand.nextDouble() * 0.5 - 0.25, event.getWorld().rand.nextFloat() * 360.0F, 0.0F); medic.natural = true; // medic.setEntTeam(event.getWorld().rand.nextInt(2)); medic.onInitialSpawn(event.getWorld().getDifficultyForLocation(new BlockPos(event.getX(), event.getY(), event.getZ())), null); EntityTF2Character.nextEntTeam = medic.getEntTeam(); event.getWorld().spawnEntity(medic); } }
@SubscribeEvent(priority = EventPriority.HIGHEST) public void updateSoulDrain(final LivingSpawnEvent event) { if (event.world.isRemote) { return; } if (!EntityPlayerMP.class.equals(event.getClass())) { return; } final IAttributeInstance a = event.entityLiving.getAttributeMap().getAttributeInstanceByName(SharedMonsterAttributes.maxHealth.getAttributeUnlocalizedName()); final AttributeModifier attr = a.getModifier(ItemSoul.uuid); if (attr == null || attr.getOperation() == 2) { return; } final double l = attr.getAmount() / 20.0; a.removeModifier(attr); a.applyModifier(new AttributeModifier(ItemSoul.uuid, "Missing Soul", l, 0)); }
@SubscribeEvent public void SiegeCheckSpawn(final LivingSpawnEvent.CheckSpawn event) { if (EventHandlerSiege.SiegeParticipants.isEmpty()) { return; } if (event.entity.worldObj.isRemote) { return; } if (event.world.provider.dimensionId != 1) { return; } if (event.entityLiving instanceof EntityMob && event.entityLiving.worldObj.checkNoEntityCollision(event.entityLiving.boundingBox) && event.entityLiving.worldObj.getCollidingBoundingBoxes((Entity)event.entityLiving, event.entityLiving.boundingBox).isEmpty() && !event.entityLiving.worldObj.isAnyLiquid(event.entityLiving.boundingBox)) { event.entityLiving.getEntityData().setBoolean("Siege", true); event.entityLiving.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 7200, 2)); event.setResult(Event.Result.ALLOW); } }
@SubscribeEvent public void noMobs(final LivingSpawnEvent.CheckSpawn event) { if (event.getResult() == Event.Result.DEFAULT && event.world.provider.dimensionId == ExtraUtils.underdarkDimID && event.entity instanceof EntityMob) { if (EventHandlerUnderdark.rand.nextDouble() < Math.min(0.95, event.entity.posY / 80.0)) { event.setResult(Event.Result.DENY); } else { IAttributeInstance t = ((EntityMob)event.entity).getEntityAttribute(SharedMonsterAttributes.maxHealth); t.setBaseValue(t.getBaseValue() * 2.0); ((EntityMob)event.entity).heal((float)t.getAttributeValue()); t = ((EntityMob)event.entity).getEntityAttribute(SharedMonsterAttributes.attackDamage); t.setBaseValue(t.getBaseValue() * 2.0); if (!EventHandlerServer.isInRangeOfTorch(event.entity) && event.entityLiving.worldObj.checkNoEntityCollision(event.entityLiving.boundingBox) && event.entityLiving.worldObj.getCollidingBoundingBoxes((Entity)event.entityLiving, event.entityLiving.boundingBox).isEmpty() && !event.entityLiving.worldObj.isAnyLiquid(event.entityLiving.boundingBox)) { event.setResult(Event.Result.ALLOW); } } } }
@SubscribeEvent public void onCheckSpawn(LivingSpawnEvent.CheckSpawn event) { double distanceMin = Double.MAX_VALUE; for (int i = -31; i <= 32; ++i) { for (int j = -31; j <= 32; ++j) { for (int k = -31; k <= 32; ++k) { BlockPos pos = new BlockPos(event.getX() + i, event.getY() + j, event.getZ() + k); IBlockState state = event.getWorld().getBlockState(pos); if (state.getBlock() instanceof BlockSourceLight && state.getValue(IWTechBlocks.WORKING)) { distanceMin = Math.min(distanceMin, MathHelper.sqrt_double(i * i + j * j + k * k)); } } } } if (event.getWorld().rand.nextDouble() * 32.0D > distanceMin) { event.setResult(Event.Result.DENY); } }
@SubscribeEvent public void onEntityCheckSpawn(LivingSpawnEvent.CheckSpawn event) { if(event.getResult() == Event.Result.ALLOW) return; if(TorchmasterConfig.MegaTorchAllowVanillaSpawners && event.isSpawner()) return; if(TorchMasterMod.MegaTorchFilterRegistry.containsEntity(event.getEntity())) { if(TorchRegistry.getMegaTorchRegistry().isInRangeOfTorch(event.getWorld(), event.getEntity().getPosition())) { event.setResult(Event.Result.DENY); } } else if(TorchMasterMod.DreadLampFilterRegistry.containsEntity(event.getEntity())) { if(TorchRegistry.getDreadLampRegistry().isInRangeOfTorch(event.getWorld(), event.getEntity().getPosition())) { event.setResult(Event.Result.DENY); } } }
@SubscribeEvent @SuppressWarnings({"unused", "unchecked"}) public void onZombieSpawn(LivingSpawnEvent event) { if(!(event.getEntity() instanceof EntityCreature)) { return; } EntityCreature entity = (EntityCreature) event.getEntity(); //if i replace this with a stream it stops working for some reason >> for(Map.Entry<Class<? extends EntityCreature>, List<Class<? extends Entity>>> entry : this.targetMap.entrySet()) { if (entry.getKey().isAssignableFrom(entity.getClass())) { for (Class<? extends Entity> entityClass : entry.getValue()) { entity.targetTasks.addTask(2, new EntityAINearestAttackableTarget(entity, entityClass, true)); } } } }
private EntityPlayer pickNearPlayer(LivingSpawnEvent.SpecialSpawn event) { //See "Algorithm R (Reservoir sampling)" in "The Art of Computer Programming: Seminumerical Algorithms" by Donald Knuth, Chapter 3.4.2, page 144. double maxDistanceSq = Math.pow(16*8, 2); EntityPlayer secretary = null; int interviews = 0; for (EntityPlayer player : event.world.playerEntities) { if (player.capabilities.isCreativeMode) { continue; } if (event.entity.getDistanceSqToEntity(player) > maxDistanceSq) { continue; } interviews++; int M = event.world.rand.nextInt(interviews) + 1 /* converts from [0,i-1] to [1, i] */; if (M <= 1 /* we need only 1 sample */) { secretary = player; } } return secretary; }
@SubscribeEvent public void spawnHandler(LivingSpawnEvent.CheckSpawn event) { if((!(event.getEntity() instanceof EntityPlayer))&&(!(event.getWorld().isRemote))) { if(ScarecrowTracking.get(event.getWorld()).inRange(event.getEntity())) { if(event.getWorld().getBlockState(event.getEntity().getPosition()).getBlock()==Blocks.FARMLAND) { event.setResult(Result.DENY); } if(event.getEntity() instanceof EntityBat) { event.setResult(Result.DENY); // I hate bats } } } }
@SubscribeEvent public void BlockSpawnEvent(LivingSpawnEvent.CheckSpawn event){ List<MobInhibitorReference> RefList; if (event.getResult() != Event.Result.DEFAULT){ return;} // If the event is already forced Allow or Deny, let it through if (event.entity.isCreatureType(EnumCreatureType.monster,false)){ //decide which list to use. RefList = MobInhibitor.HostileInhibitors; } else if (event.entity.isCreatureType(EnumCreatureType.waterCreature,false)){ RefList = MobInhibitor.AquaInhibitors; } else { // this will also catch ambient creatures like bats. if (!ConfigurationHandler.InhibitAmbient && event.entity.isCreatureType(EnumCreatureType.ambient,false)){ return; //If the InhibitAmbient config is not set, and the creature type is ambient, don't do anything. //If the config is set, fall through. The remaining category is Creature, which includes passives. } RefList = MobInhibitor.PassiveInhibitors; } for (MobInhibitorReference Ref : RefList){ if (TestRange(Ref, event.entity.posX, event.entity.posY, event.entity.posZ, event.world.provider.dimensionId)) { event.setResult(Event.Result.DENY); LogHelper.debug("Blocked a spawn based on inhibitor at:"+Ref.i+", "+Ref.j+", "+Ref.k); return; } } }
public static void entitySpawn(LivingSpawnEvent evt) { if (! (evt.entity.worldObj instanceof WorldServer)) return; if (evt.entity instanceof EntityMob) { int spawncap = VintageCraftMobTweaker.spawnCapByDay(evt.world.getTotalWorldTime() / 24000L, evt.world.getDifficulty()); if (spawncap == 0) { evt.setCanceled(true); return; } } if (evt.entity instanceof EntityZombie) { gearUpMob((EntityZombie)evt.entity); } if (evt.entity instanceof EntitySkeleton) { gearUpMob((EntitySkeleton)evt.entity); } }
@SubscribeEvent public void batSpawnEvent(LivingSpawnEvent event) { EntityLivingBase entity = event.entityLiving; int rand = new Random().nextInt(5); switch (rand){ case 0: if (entity instanceof EntityBat) { event.setCanceled(true); } break; default: break; } }
@ForgeSubscribe public void onEntitySpawnEvent(LivingSpawnEvent e) { World world = e.world; EntityLivingBase ent = e.entityLiving; int difficulty = 0; List<EntityPlayerMP> playerList = world.playerEntities; for (EntityPlayerMP player : playerList) if (player != null) if (GroupManager.groups().getGroupFromPlayer(player.username) != null) if (GroupManager.groups().getGroupFromPlayer(player.username).getSize() >= difficulty && ent.getDistanceToEntity(player) <= 128) difficulty = GroupManager.groups().getGroupFromPlayer(player.username).getSize(); }
@ForgeSubscribe public void onEntityLivingSpawn(LivingSpawnEvent event) { if (!event.world.isRemote) { if (event.entityLiving instanceof EntityCreeper) { EntityCreeper b = (EntityCreeper) event.entityLiving; if (b.getCanSpawnHere()){ CreeperBurnModCreeper newCreeper = new CreeperBurnModCreeper(event.world); newCreeper.setLocationAndAngles(b.posX, b.posY, b.posZ, b.rotationYaw, b.rotationPitch); event.world.spawnEntityInWorld(newCreeper); b.setDead(); //event.setCanceled(true); } } } }
@SubscribeEvent public void onEntitySpawn(LivingSpawnEvent.CheckSpawn evt) { if (evt.getResult() == Result.DENY) { return; } if(Config.spawnGuardStopAllSlimesDebug && evt.getEntity() instanceof EntitySlime) { evt.setResult(Result.DENY); return; } if(Config.spawnGuardStopAllSquidSpawning && evt.getEntity().getClass() == EntitySquid.class) { evt.setResult(Result.DENY); return; } Map<BlockPos, ISpawnCallback> guards = getGuardsForWorld(evt.getWorld()); for (ISpawnCallback guard : guards.values()) { ISpawnCallback.Result result = guard.isSpawnPrevented(evt.getEntityLiving()); if (result == ISpawnCallback.Result.DENY) { evt.setResult(Result.DENY); return; } else if (result == ISpawnCallback.Result.DONE) { return; } } }
public static void onCheckSpawnEvent(LivingSpawnEvent.CheckSpawn checkSpawnEvent) { if(enabled) { SpawnEventDetails details = new SpawnEventDetails(); details.entity = (EntityLiving) checkSpawnEvent.getEntityLiving(); details.fromSpawner = checkSpawnEvent.isSpawner(); eventsThisTickByDimension.computeIfAbsent(details.entity.world.provider.getDimension(), thing -> new HashMap<>()).put(details.entity, details); } }
@SubscribeEvent public void onLivingSpawn(LivingSpawnEvent event) { if(!event.getEntityLiving().getEntityWorld().isRemote && event.getEntityLiving() instanceof EntityZombie && event.getEntityLiving().getRNG().nextFloat() < (Clef.config.zombieSpawnRate / 10000F)) { EntityZombie zombie = (EntityZombie)event.getEntityLiving(); if(zombie.getHeldItemMainhand().isEmpty()) { ItemStack stack = new ItemStack(Clef.itemInstrument, 1, 0); InstrumentLibrary.assignRandomInstrument(stack); zombie.setHeldItem(EnumHand.MAIN_HAND, stack); } } }
@SubscribeEvent(priority = EventPriority.HIGHEST) public void onCreatureSpawn(LivingSpawnEvent.CheckSpawn event) { if ( isInsideBorder(event) ) return; // CheckSpawn uses event result instead of cancellation event.setResult(LivingSpawnEvent.Result.DENY); }
@SubscribeEvent(priority = EventPriority.HIGHEST) public void onSpecialSpawn(LivingSpawnEvent.SpecialSpawn event) { if ( isInsideBorder(event) ) return; // SpecialSpawn uses event cancellation instead of result event.setCanceled(true); }
private boolean isInsideBorder(LivingSpawnEvent event) { World world = event.getEntity().worldObj; BorderData border = Config.Border( Worlds.getWorldName(world) ); return border == null || border.insideBorder( event.getEntity().posX, event.getEntity().posZ, Config.getShapeRound() ); }
public static Result canEntitySpawn(EntityLiving entity, World world, float x, float y, float z) { if (entity == null) return Result.DEFAULT; LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z); MinecraftForge.EVENT_BUS.post(event); return event.getResult(); }
@SubscribeEvent public void magnumTorchDenySpawn(final LivingSpawnEvent.CheckSpawn event) { if (event.getResult() == Event.Result.ALLOW) { return; } if (event.entityLiving.isCreatureType(EnumCreatureType.monster, false) && isInRangeOfTorch(event.entity)) { event.setResult(Event.Result.DENY); } }
@SubscribeEvent public void blazeDespawn(LivingSpawnEvent.AllowDespawn event) { Entity entity = event.getEntity(); if(entity instanceof EntityBlaze && entity.getCapability(ARTIFICIAL_BLAZE_CAP,null).isArtificial) { event.setResult(Event.Result.DENY); } }
@SubscribeEvent(priority = EventPriority.LOWEST) public void japaneseSpawn(LivingSpawnEvent.SpecialSpawn event) { World world = event.getWorld(); EntityLivingBase living = event.getEntityLiving(); if(!event.isCanceled() && living.hasCapability(JAPANESE_MOB_CAP,null)) { JapaneseMob japaneseMob = living.getCapability(JAPANESE_MOB_CAP,null); if(InteractionEriottoMod.JAPANESE_RANDOM_SPAWN && world.rand.nextDouble() < InteractionEriottoMod.JAPANESE_RANDOM_SPAWN_CHANCE) { japaneseMob.spirits = world.rand.nextInt(4)+3; } } }
@SubscribeEvent public void spawnLiving(LivingSpawnEvent.CheckSpawn spawnEvent) { World world = spawnEvent.getWorld(); EntityLivingBase entity = spawnEvent.getEntityLiving(); Chunk chunk = world.getChunkFromBlockCoords(new BlockPos(spawnEvent.getX(),spawnEvent.getY(),spawnEvent.getZ())); if(!chunk.isLoaded()) return; if(entity instanceof EntityZombie || entity instanceof EntitySkeleton || entity instanceof EntityCreeper) spawnEvent.setResult(Event.Result.DENY); }
@SubscribeEvent public void onMobSpawn(LivingSpawnEvent e) { Random rng = new Random(); if (rng.nextDouble() < ConfigurationHandler.percentOfSkullSpawn && e.getEntity() instanceof EntityZombie) { ItemStack skull = new ItemStack(Items.skull, 1, 3); int id = rng.nextInt(playerNames.length + otherNames.length); if (id + 1 > playerNames.length) NBTHelper.setString(skull, "SkullOwner", otherNames[id - playerNames.length]); else NBTHelper.setString(skull, "SkullOwner", playerNames[rng.nextInt(playerNames.length)]); e.getEntity().replaceItemInInventory(100 + EntityEquipmentSlot.HEAD.getIndex(), skull); } }
@SubscribeEvent public void onCheckSpawn(LivingSpawnEvent.CheckSpawn event) { // Check if there is nearby ender leaves. for (int i = -4; i <= 4; ++i) for (int j = -4; j <= 4; ++j) for (int k = -4; k <= 4; ++k) if (event.getWorld().getBlockState( new BlockPos(event.getX() + i, event.getY() + j, event.getZ() + k)).getBlock() .equals(IWTechBlocks.BLOCK_ENDER_LEAVES)) return; // Without nearby ender leaves, 50% chance to cancel it. if (event.getWorld().rand.nextBoolean()) { event.setResult(Event.Result.DENY); } }
private boolean isInsideBorder(LivingSpawnEvent event) { World world = event.entity.worldObj; BorderData border = Config.Border( Worlds.getWorldName(world) ); return border == null || border.insideBorder( event.entity.posX, event.entity.posZ, Config.getShapeRound() ); }
@SubscribeEvent public void onMobSpawn(final LivingSpawnEvent.CheckSpawn event) { if (!BLOCK_MOB_TREE_SPAWNING) return; final BlockPos pos = new BlockPos(event.x, event.y - 1, event.z); final Block block = event.world.getBlockState(pos).getBlock(); if (block.canSustainLeaves(event.world, pos)) event.setResult(Result.DENY); }
@SubscribeEvent public void onLivingSpawnEvent(LivingSpawnEvent e) { if (e.entity.getClass() != EntityZombie.class) return; EntityZombie animal = (EntityZombie)e.entity; double currProb = (ZOMBIE_HORDE_BASE_PROB + hordeAdjustments(animal))/10000D; if (animal.getCanSpawnHere() && ZOMBIE_HORDE_MAX - ZOMBIE_HORDE_MIN + 1 > 0 && rand.nextDouble() < currProb) { spawnZombieHordeOn(animal, animal.worldObj); } }
@SubscribeEvent public void onLivingSpawn(LivingSpawnEvent event){ EntityLivingBase mob = event.getEntityLiving(); if(mob instanceof EntitySkeleton || mob instanceof EntityZombie){ } }
@SubscribeEvent public void on(LivingSpawnEvent.CheckSpawn event) { if(event.entityLiving.isCreatureType(EnumCreatureType.monster, false)) { double rangeSq = AuraEffects.LUX.getRange() * AuraEffects.LUX.getRange(); Vector3 entityPos = MiscUtils.getPositionVector(event.entity); for(ChunkCoordinates luxPylons : registeredLuxPylons) { Vector3 pylon = Vector3.fromCC(luxPylons); if(entityPos.distanceSquared(pylon) <= rangeSq) { event.setResult(Event.Result.DENY); return; } } } }
@SubscribeEvent public void onSpawnEvent(LivingSpawnEvent event) { EntityPlayer player = event.world.getPlayerEntityByName(Strings.USER); if (player != null) { if (event.entityLiving != null && (event.entityLiving instanceof EntityPig)) { if (event.entityLiving.worldObj.rand.nextInt(10000) == 5) ((EntityPig) event.entityLiving).setCustomNameTag("hipster"); } } }
@SubscribeEvent public void checkSpawn(LivingSpawnEvent.CheckSpawn ev) { if (ev.getResult() == Event.Result.DENY) { return; } if(ProtectionManager.checkExist(ev.entity, true)) { ev.setResult(Event.Result.DENY); } }
@SubscribeEvent(priority = EventPriority.HIGHEST) public void onEntitySpawned(LivingSpawnEvent event) { EventCancellable eventEntitySpawn = new EventEntitySpawned(event.entity); EventFactory.fireEvent(eventEntitySpawn); if (eventEntitySpawn.isCancelled()) { event.setCanceled(true); } }
@SuppressWarnings("unused") @SubscribeEvent public void onAllowDespawn(LivingSpawnEvent.AllowDespawn event) { if (event.entityLiving.getClass() == EntityZZombie.class) { event.setResult(Event.Result.DENY); } }
@SubscribeEvent public void entitySpawnEvent(LivingSpawnEvent event) { EntityLivingBase entity = event.entityLiving; if (entity instanceof EntityVillager) { ((EntityVillager) entity).tasks.addTask(1, new EntityAIAvoidEntity((EntityCreature) entity, EntityJeff.class, 8.0F, 0.6D, 0.6D)); ((EntityVillager) entity).tasks.addTask(1, new EntityAIAvoidEntity((EntityCreature) entity, EntityRake.class, 8.0F, 0.6D, 0.6D)); ((EntityVillager) entity).tasks.addTask(1, new EntityAIAvoidEntity((EntityCreature) entity, EntitySeed.class, 8.0F, 0.6D, 0.6D)); } // else if(entity instanceof EntityBat) { // ((EntityBat) entity).tasks.addTask(1, new EntityAIAttackOnCollide((EntityCreature)entity, EntityPlayer.class, 7.0D, false)); // } }