Files
MagicBees/magicbees_src/magicbees/bees/AlleleEffectSpawnWisp.java
T

76 lines
2.5 KiB
Java
Raw Normal View History

2013-05-23 21:07:28 -07:00
package magicbees.bees;
2013-01-19 03:29:47 -08:00
import java.lang.reflect.Field;
2013-01-26 13:42:39 -08:00
import cpw.mods.fml.common.FMLLog;
2013-01-19 03:29:47 -08:00
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
2013-05-23 21:07:28 -07:00
import magicbees.item.ItemArmorApiarist;
import magicbees.main.utils.compat.ThaumcraftHelper;
2013-01-19 03:29:47 -08:00
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
2013-01-26 13:42:39 -08:00
import net.minecraft.util.AxisAlignedBB;
2013-01-19 03:29:47 -08:00
import net.minecraft.world.World;
public class AlleleEffectSpawnWisp extends AlleleEffectSpawnMob
{
private byte[] wispTypes = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 };
public AlleleEffectSpawnWisp(String id, boolean isDominant, String mobToSpawn, String soundToPlay)
2013-01-19 03:29:47 -08:00
{
super(id, isDominant, mobToSpawn, soundToPlay);
2013-01-19 03:29:47 -08:00
}
@Override
protected boolean spawnMob(IBeeGenome bee, EntityPlayer player, World world, IBeeHousing housing, boolean spawnAlternate)
{
boolean spawnedFlag = false;
EntityLiving mob;
if (spawnAlternate && this.alternateMob != null)
{
mob = (EntityLiving) EntityList.createEntityByName(this.alternateMob, world);
}
else
{
mob = (EntityLiving) EntityList.createEntityByName(this.mobName, world);
}
if (mob != null)
{
2013-01-26 13:42:39 -08:00
double pos[] = this.randomMobSpawnCoords(world, bee, housing);
2013-01-19 03:29:47 -08:00
2013-01-26 13:42:39 -08:00
int entitiesCount = world.getEntitiesWithinAABB(mob.getClass(),
AxisAlignedBB.getBoundingBox((int)pos[0], (int)pos[1], (int)pos[2], (int)pos[0] + 1, (int)pos[1] + 1, (int)pos[2] + 1)
.expand(8.0D, 4.0D, 8.0D)).size();
2013-01-19 03:29:47 -08:00
mob.setPositionAndRotation(pos[0], pos[1], pos[2], world.rand.nextFloat() * 360f, 0f);
2013-01-19 03:29:47 -08:00
2013-01-26 13:42:39 -08:00
if (entitiesCount < this.maxMobsInArea && mob.getCanSpawnHere())
2013-01-19 03:29:47 -08:00
{
2013-01-26 13:42:39 -08:00
// Try some Reflection on TC code. This could be dangerous.
try
{
Class wispEntity = Class.forName(ThaumcraftHelper.Entity.WISP.getClassName());
2013-01-26 13:42:39 -08:00
Field type = wispEntity.getDeclaredField("type");
type.setByte(mob, wispTypes[world.rand.nextInt(wispTypes.length)]);
}
catch (Exception e) { /*Last time I had a request to post error messages, I regretted it.*/ }
2013-01-26 13:42:39 -08:00
spawnedFlag = world.spawnEntityInWorld(mob);
if (this.aggosOnPlayer && player != null)
{
if (ItemArmorApiarist.getNumberPiecesWorn(player) < 4)
{
// Protect fully suited player from initial murder intent.
mob.setAttackTarget(player);
}
}
2013-01-19 03:29:47 -08:00
}
}
return spawnedFlag;
}
}