Java源码示例:net.minecraftforge.event.entity.living.LivingSpawnEvent
示例1
public static Result canEntitySpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType) {
if (entity == null) {
return Result.DEFAULT;
}
LivingSpawnEvent.CheckSpawn event = new LivingSpawnEvent.CheckSpawn(entity, world, x, y, z, spawner, spawnType);
MinecraftForge.EVENT_BUS.post(event);
return event.getResult();
}
示例2
@SubscribeEvent
public static void onEntitySpawn(LivingSpawnEvent.SpecialSpawn event) {
EntityLivingBase entity = event.getEntityLiving();
EnumDifficulty difficulty = entity.world.getDifficulty();
if (difficulty == EnumDifficulty.HARD && entity.getRNG().nextFloat() <= 0.03f) {
if (entity instanceof EntityZombie) {
ItemStack itemStack = MetaItems.NANO_SABER.getInfiniteChargedStack();
ToggleEnergyConsumerBehavior.setItemActive(itemStack, true);
entity.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, itemStack);
((EntityZombie) entity).setDropChance(EntityEquipmentSlot.MAINHAND, 0.0f);
}
}
}
示例3
@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;
}
}
}
}
示例4
@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);
}
}
示例5
private void spawnCat(Point3i spawnLoc) {
EntityWitherCat cat = new EntityWitherCat(world);
cat.onInitialSpawn(world.getDifficultyForLocation(new BlockPos(this)), null);
cat.setOwner(this);
cat.setPositionAndRotation(spawnLoc.x + 0.5, spawnLoc.y + 0.5, spawnLoc.z + 0.5, rotationYaw, 0);
if (MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.CheckSpawn(cat, world, (float)cat.posX, (float)cat.posY, (float)cat.posZ, false))) {
return;
}
if(!cat.getCanSpawnHere()) {
return;
}
cats.add(cat);
world.spawnEntity(cat);
}
示例6
public static boolean doSpecialSpawn(MobEntity entity, IWorld world, double x, double y, double z, MobSpawnerLogic spawner, SpawnType spawnType) {
return MinecraftForge.EVENT_BUS.post(new LivingSpawnEvent.SpecialSpawn(entity, world, x, y, z, spawner, spawnType));
}
示例7
@SubscribeEvent
public void specialSpawn(LivingSpawnEvent.SpecialSpawn ev) {
if (ev.isCanceled()) return;
ProtectionManager.checkExist(ev.entity, true);
}
示例8
@SubscribeEvent
public void onMonsterSpawn(LivingSpawnEvent evt) {
if (evt.getEntityLiving() != null) { //&& !evt.entityLiving.getClass().getName().contains("enderzoo")) {
evt.setResult(Result.DENY);
}
}