Ignore special spawn conditions for mobs from mob spawners, fixes #260

This commit is contained in:
Electroblob77
2019-10-05 14:34:29 +01:00
parent 4677d9ff30
commit 378e02eb6c
3 changed files with 48 additions and 21 deletions
@@ -35,11 +35,17 @@ import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.IEntityAdditionalSpawnData;
import org.apache.commons.lang3.ArrayUtils;
import javax.annotation.Nullable;
import java.util.*;
@Mod.EventBusSubscriber
public class EntityEvilWizard extends EntityMob implements ISpellCaster, IEntityAdditionalSpawnData {
private EntityAIAttackSpell<EntityEvilWizard> spellCastingAI = new EntityAIAttackSpell<>(this, 0.5D, 14.0F, 30, 50);
@@ -283,16 +289,6 @@ public class EntityEvilWizard extends EntityMob implements ISpellCaster, IEntity
public int getMaxSpawnedInChunk(){
return 1;
}
@Override
public boolean getCanSpawnHere(){
// Evil wizards can only spawn in the specified dimensions
for(int id : Wizardry.settings.mobSpawnDimensions){
if(this.dimension == id) return super.getCanSpawnHere();
}
return false;
}
@Override
protected boolean canDespawn(){
@@ -393,4 +389,13 @@ public class EntityEvilWizard extends EntityMob implements ISpellCaster, IEntity
textureIndex = data.readInt();
}
@SubscribeEvent
public static void onCheckSpawnEvent(LivingSpawnEvent.CheckSpawn event){
// We have no way of checking if it's a spawner in getCanSpawnHere() so this has to be done here instead
if(!event.isSpawner()){
if(!ArrayUtils.contains(Wizardry.settings.mobSpawnDimensions, event.getWorld().provider.getDimension()))
event.setResult(Event.Result.DENY);
}
}
}
@@ -16,7 +16,13 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.lang3.ArrayUtils;
@Mod.EventBusSubscriber
public class EntityIceWraith extends EntityBlazeMinion {
/** The version from EntityLivingBase is only used in onLivingUpdate, so it can safely be copied. */
@@ -185,12 +191,16 @@ public class EntityIceWraith extends EntityBlazeMinion {
@Override
public boolean getCanSpawnHere(){
// Only spawns in the specified dimensions
for(int id : Wizardry.settings.mobSpawnDimensions){
if(this.dimension == id) return super.getCanSpawnHere() && this.isValidLightLevel();
}
return super.getCanSpawnHere() && this.isValidLightLevel();
}
return false;
@SubscribeEvent
public static void onCheckSpawnEvent(LivingSpawnEvent.CheckSpawn event){
// We have no way of checking if it's a spawner in getCanSpawnHere() so this has to be done here instead
if(!event.isSpawner()){
if(!ArrayUtils.contains(Wizardry.settings.mobSpawnDimensions, event.getWorld().provider.getDimension()))
event.setResult(Event.Result.DENY);
}
}
/**
@@ -13,7 +13,16 @@ import net.minecraft.init.MobEffects;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.commons.lang3.ArrayUtils;
import java.util.Arrays;
import java.util.function.IntPredicate;
@Mod.EventBusSubscriber
public class EntityLightningWraith extends EntityBlazeMinion {
public EntityLightningWraith(World world){
@@ -74,14 +83,17 @@ public class EntityLightningWraith extends EntityBlazeMinion {
@Override
public boolean getCanSpawnHere(){
// Only spawns in the specified dimensions, during thunderstorms
if(!world.isThundering()) return false;
return super.getCanSpawnHere() && this.isValidLightLevel();
}
for(int id : Wizardry.settings.mobSpawnDimensions){
if(this.dimension == id) return super.getCanSpawnHere() && this.isValidLightLevel();
@SubscribeEvent
public static void onCheckSpawnEvent(LivingSpawnEvent.CheckSpawn event){
// We have no way of checking if it's a spawner in getCanSpawnHere() so this has to be done here instead
if(!event.isSpawner()){
if(!event.getWorld().isThundering()) event.setResult(Event.Result.DENY);
if(!ArrayUtils.contains(Wizardry.settings.mobSpawnDimensions, event.getWorld().provider.getDimension()))
event.setResult(Event.Result.DENY);
}
return false;
}
/**