Search in sources :

Example 6 with Affinity

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;
}
Also used : AffinityData(am2.playerextensions.AffinityData) Affinity(am2.api.spell.enums.Affinity)

Example 7 with Affinity

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);
}
Also used : Affinity(am2.api.spell.enums.Affinity)

Example 8 with Affinity

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Affinity(am2.api.spell.enums.Affinity)

Example 9 with Affinity

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IInventory(net.minecraft.inventory.IInventory) AMVector3(am2.api.math.AMVector3) TileEntityChest(net.minecraft.tileentity.TileEntityChest) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 10 with Affinity

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMParticle(am2.particles.AMParticle) IGrowable(net.minecraft.block.IGrowable) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) Affinity(am2.api.spell.enums.Affinity) ParticleFloatUpward(am2.particles.ParticleFloatUpward)

Aggregations

Affinity (am2.api.spell.enums.Affinity)27 AffinityData (am2.playerextensions.AffinityData)6 ItemStack (net.minecraft.item.ItemStack)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 TileEntity (net.minecraft.tileentity.TileEntity)4 ArrayList (java.util.ArrayList)3 AMVector2 (am2.api.math.AMVector2)2 AMVector3 (am2.api.math.AMVector3)2 ISpellModifier (am2.api.spell.component.interfaces.ISpellModifier)2 AMParticle (am2.particles.AMParticle)2 Colour (am2.spell.modifiers.Colour)2 HashMap (java.util.HashMap)2 Block (net.minecraft.block.Block)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 AffinityChangingEvent (am2.api.events.AffinityChangingEvent)1 ManaCostEvent (am2.api.events.ManaCostEvent)1 SpellRecipeItemsEvent (am2.api.events.SpellRecipeItemsEvent)1