use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.
the class ItemAffinityBook method onItemRightClick.
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
if (par1ItemStack.getItemDamage() == META_GENERAL) {
AffinityData data = AffinityData.For(par3EntityPlayer);
data.setLocked(false);
for (Affinity aff : Affinity.values()) {
data.setAffinityAndDepth(aff, data.getAffinityDepth(aff) - 20);
}
} else {
AffinityData.For(par3EntityPlayer).incrementAffinity(Affinity.getByID(par1ItemStack.getItemDamage()), 20);
}
if (!par2World.isRemote)
par1ItemStack.stackSize--;
return par1ItemStack;
}
use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.
the class FlickerOperatorFelledOak method TimeBetweenOperation.
@Override
public int TimeBetweenOperation(boolean powered, Affinity[] flickers) {
int base = powered ? 300 : 3600;
float augments = 1.0f;
for (Affinity aff : flickers) {
if (aff == Affinity.LIGHTNING)
augments *= 0.5f;
}
return (int) Math.ceil(base * augments);
}
use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.
the class FlickerOperatorInterdiction method DoOperation.
@Override
public boolean DoOperation(World worldObj, IFlickerController habitat, boolean powered, Affinity[] flickers) {
if (worldObj.isRemote)
return true;
boolean hasEnderAugment = false;
for (Affinity aff : flickers) {
if (aff == Affinity.ENDER) {
hasEnderAugment = true;
break;
}
}
int lastRadius = getLastRadius(habitat);
int calcRadius = calculateRadius(flickers);
if (lastRadius != calcRadius) {
RemoveOperator(worldObj, habitat, powered, flickers);
}
for (int i = 0; i < calcRadius * 2 + 1; ++i) {
if (hasEnderAugment) {
// -x
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord - calcRadius, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord - calcRadius + i, 9);
// +x
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord + calcRadius + 1, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord - calcRadius + i, 9);
// -z
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord - calcRadius + i, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord - calcRadius, 9);
// +z
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord + calcRadius + 1 - i, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord + calcRadius + 1, 9);
} else {
// -x
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord - calcRadius, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord - calcRadius + i, 9);
// +x
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord + calcRadius + 1, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord - calcRadius + i, 9);
// -z
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord - calcRadius + i, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord - calcRadius, 9);
// +z
setUtilityBlock(worldObj, ((TileEntity) habitat).xCoord + calcRadius + 1 - i, ((TileEntity) habitat).yCoord, ((TileEntity) habitat).zCoord + calcRadius + 1, 9);
}
}
setLastRadius(habitat, calcRadius);
return true;
}
use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.
the class FlickerOperatorItemTransport method DoOperation.
@Override
public boolean DoOperation(World worldObj, IFlickerController controller, boolean powered, Affinity[] flickers) {
if (worldObj.isRemote) {
return false;
}
// Gets the habitat running this operation
TileEntityFlickerHabitat habitat = null;
if (controller instanceof TileEntityFlickerHabitat) {
habitat = (TileEntityFlickerHabitat) controller;
} else {
// if the habitat couldn't be found, bail
return false;
}
int toMove = 0;
// if(powered){
for (int i = 0; i < 6; i++) {
if (flickers[i] == Affinity.ARCANE) {
toMove += 32;
}
}
// }
// ensure toMove is at least 1
toMove = Math.max(toMove, 1);
// initiate the arrays for any input crystals
ArrayList<ItemStack> itemsToTransfer = new ArrayList<ItemStack>();
ArrayList<AMVector3> removeFromInList = new ArrayList<AMVector3>();
boolean itemFound = false;
// if the in list position has exceeded the size of the list reset it
if (habitat.getInListPosition() >= habitat.getInListSize()) {
habitat.setInListPosition(0);
}
for (int inIterator = habitat.getInListPosition(); inIterator < habitat.getInListSize(); ++inIterator) {
// Gets the tile entity for the attached crystal marker at the specified location
AMVector3 vector = habitat.getInListAt(inIterator);
TileEntity te = null;
TileEntityCrystalMarker crystalMarkerTE = GetCrystalMarkerTileEntity(worldObj, (int) vector.x, (int) vector.y, (int) vector.z);
if (crystalMarkerTE == null) {
// crystal marker no longer exists, remove it from the list
removeFromInList.add(vector);
break;
}
te = GetAttachedCrystalMarkerTileEntity(worldObj, crystalMarkerTE, vector);
if (te != null && te instanceof IInventory) {
// if the crystal is attached to an inventory
itemFound = moveItem(worldObj, (IInventory) te, crystalMarkerTE, habitat, toMove);
if (itemFound) {
// if an item was found the break out of the current loop
habitat.setInListPosition(inIterator + 1);
break;
} else if (te instanceof TileEntityChest) {
// This is to handle the special case of double chests
TileEntityChest adjacent = InventoryUtilities.getAdjacentChest((TileEntityChest) te);
if (adjacent != null) {
itemFound = moveItem(worldObj, adjacent, crystalMarkerTE, habitat, toMove);
if (itemFound) {
habitat.setInListPosition(inIterator + 1);
}
}
}
}
}
if (itemFound == false) {
// if no items were found to move then reset the input list position
habitat.setInListPosition(0);
}
for (AMVector3 vector : removeFromInList) {
// remove the invalid in list positions from the maintained in list
habitat.removeInListAt(vector);
}
return itemFound;
}
use of am2.api.spell.enums.Affinity in project ArsMagica2 by Mithion.
the class FlickerOperatorNaturesBounty method DoOperation.
@Override
public boolean DoOperation(World worldObj, IFlickerController habitat, boolean powered, Affinity[] flickers) {
int radius = 6;
int diameter = radius * 2 + 1;
boolean updatedOnce = false;
if (!worldObj.isRemote) {
for (int i = 0; i < (powered ? 5 : 1); ++i) {
int effectX = ((TileEntity) habitat).xCoord - radius + (worldObj.rand.nextInt(diameter));
int effectZ = ((TileEntity) habitat).zCoord - radius + (worldObj.rand.nextInt(diameter));
int effectY = ((TileEntity) habitat).yCoord;
while (worldObj.isAirBlock(effectX, effectY, effectZ) && effectY > 0) {
effectY--;
}
while (!worldObj.isAirBlock(effectX, effectY, effectZ) && effectY > 0) {
effectY++;
}
effectY--;
Block block = worldObj.getBlock(effectX, effectY, effectZ);
if (block instanceof IPlantable || block instanceof IGrowable) {
block.updateTick(worldObj, effectX, effectY, effectZ, worldObj.rand);
updatedOnce = true;
}
}
} else {
int posY = ((TileEntity) habitat).yCoord;
while (!worldObj.isAirBlock(((TileEntity) habitat).xCoord, posY, ((TileEntity) habitat).zCoord)) {
posY++;
}
posY--;
for (int i = 0; i < AMCore.config.getGFXLevel() * 2; ++i) {
AMParticle particle = (AMParticle) AMCore.proxy.particleManager.spawn(worldObj, "plant", ((TileEntity) habitat).xCoord + 0.5, posY + 0.5f, ((TileEntity) habitat).zCoord + 0.5);
if (particle != null) {
particle.addRandomOffset(diameter, 0, diameter);
particle.AddParticleController(new ParticleFloatUpward(particle, 0.01f, 0.04f, 1, false));
particle.setMaxAge(16);
particle.setParticleScale(0.08f);
}
}
}
if (powered) {
for (Affinity aff : flickers) {
if (aff == Affinity.WATER)
FlickerOperatorRegistry.instance.getOperatorForMask(Affinity.WATER.getAffinityMask()).DoOperation(worldObj, habitat, powered);
}
}
return updatedOnce;
}
Aggregations