2013-05-23 21:07:28 -07:00
|
|
|
package magicbees.bees;
|
2012-12-29 17:50:58 -08:00
|
|
|
|
2013-01-19 03:29:47 -08:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2013-03-06 19:33:09 -08:00
|
|
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
|
|
|
|
|
2013-05-29 11:15:25 -07:00
|
|
|
import magicbees.main.MagicBees;
|
2013-05-23 21:07:28 -07:00
|
|
|
import magicbees.main.utils.LocalizationManager;
|
2013-01-19 03:29:47 -08:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
|
import net.minecraft.world.World;
|
2012-12-29 17:50:58 -08:00
|
|
|
import forestry.api.apiculture.IAlleleBeeEffect;
|
|
|
|
|
import forestry.api.apiculture.IBeeGenome;
|
|
|
|
|
import forestry.api.apiculture.IBeeHousing;
|
|
|
|
|
import forestry.api.genetics.IEffectData;
|
|
|
|
|
|
|
|
|
|
public abstract class AlleleEffect extends Allele implements IAlleleBeeEffect
|
|
|
|
|
{
|
2013-06-14 13:30:00 -07:00
|
|
|
protected int throttle;
|
2012-12-29 17:50:58 -08:00
|
|
|
|
2013-06-14 13:30:00 -07:00
|
|
|
public AlleleEffect(String id, boolean isDominant, int timeout)
|
2012-12-29 17:50:58 -08:00
|
|
|
{
|
2013-05-29 11:15:25 -07:00
|
|
|
super("effect" + id, isDominant);
|
2013-06-14 13:30:00 -07:00
|
|
|
this.throttle = timeout;
|
2012-12-29 17:50:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isCombinable()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public abstract IEffectData validateStorage(IEffectData storedData);
|
|
|
|
|
|
|
|
|
|
@Override
|
2013-06-14 13:30:00 -07:00
|
|
|
public final IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing)
|
|
|
|
|
{
|
|
|
|
|
int count = storedData.getInteger(0);
|
|
|
|
|
if (count >= this.throttle)
|
|
|
|
|
{
|
|
|
|
|
storedData = this.doEffectThrottled(genome, storedData, housing);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
storedData.setInteger(0, count + 1);
|
|
|
|
|
}
|
|
|
|
|
return storedData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param genome
|
|
|
|
|
* @param storedData
|
|
|
|
|
* @param housing
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
protected abstract IEffectData doEffectThrottled(IBeeGenome genome, IEffectData storedData, IBeeHousing housing);
|
2012-12-29 17:50:58 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing)
|
|
|
|
|
{
|
2013-09-02 17:32:59 -07:00
|
|
|
return Allele.forestryBaseEffect.doFX(genome, storedData, housing);
|
2012-12-29 17:50:58 -08:00
|
|
|
}
|
2013-01-19 03:29:47 -08:00
|
|
|
|
|
|
|
|
protected List<Entity> getEntitiesWithinRange(IBeeGenome genome, IBeeHousing housing)
|
|
|
|
|
{
|
|
|
|
|
// Get the size of the affected area
|
|
|
|
|
int[] area = genome.getTerritory();
|
|
|
|
|
|
|
|
|
|
// Calculate offset
|
|
|
|
|
int[] min = new int[3];
|
|
|
|
|
int[] max = new int[3];
|
|
|
|
|
min[0] = housing.getXCoord() - area[0] / 2;
|
|
|
|
|
max[0] = housing.getXCoord() + area[0] / 2;
|
|
|
|
|
|
|
|
|
|
min[1] = housing.getYCoord() - area[1] / 2;
|
|
|
|
|
max[1] = housing.getYCoord() + area[1] / 2;
|
|
|
|
|
|
|
|
|
|
min[2] = housing.getZCoord() - area[2] / 2;
|
|
|
|
|
max[2] = housing.getZCoord() + area[2] / 2;
|
|
|
|
|
|
2013-04-15 00:17:50 -07:00
|
|
|
AxisAlignedBB bounds = AxisAlignedBB.getAABBPool().getAABB(min[0], min[1], min[2], max[0], max[1], max[2]);
|
2013-01-19 03:29:47 -08:00
|
|
|
return housing.getWorld().getEntitiesWithinAABB(EntityPlayer.class, bounds);
|
|
|
|
|
}
|
2012-12-29 17:50:58 -08:00
|
|
|
|
|
|
|
|
}
|