Search in sources :

Example 16 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class ItemCrystalWrench method storePairLocation.

private void storePairLocation(World world, TileEntity te, ItemStack stack, EntityPlayer player, double hitX, double hitY, double hitZ) {
    AMVector3 destination = new AMVector3(te);
    if (!world.isRemote) {
        if (te instanceof TileEntityFlickerHabitat) {
            NBTTagCompound habLoc = new NBTTagCompound();
            destination.writeToNBT(habLoc);
            stack.stackTagCompound.setTag(HAB_PAIRLOC, habLoc);
        } else {
            NBTTagCompound pairLoc = new NBTTagCompound();
            destination.writeToNBT(pairLoc);
            stack.stackTagCompound.setTag(KEY_PAIRLOC, pairLoc);
        }
        if (player.isSneaking()) {
            stack.stackTagCompound.setBoolean(KEEP_BINDING, true);
        }
    } else {
        spawnLinkParticles(world, hitX, hitY, hitZ);
    }
}
Also used : AMVector3(am2.api.math.AMVector3) TileEntityFlickerHabitat(am2.blocks.tileentities.TileEntityFlickerHabitat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 17 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class FlickerOperatorFelledOak method getPlantLocation.

private AMVector3 getPlantLocation(World worldObj, IFlickerController habitat, ItemStack sapling) {
    if (sapling.getItem() instanceof ItemBlock == false)
        return null;
    TileEntity te = (TileEntity) habitat;
    byte[] data = habitat.getMetadata(this);
    AMVector3 offset = null;
    if (data == null || data.length == 0) {
        offset = new AMVector3(te.xCoord - radius_horiz, te.yCoord - radius_vert, te.zCoord - radius_horiz);
    } else {
        AMDataReader reader = new AMDataReader(data, false);
        offset = new AMVector3(reader.getInt(), te.yCoord - radius_vert, reader.getInt());
    }
    Block treeBlock = ((ItemBlock) sapling.getItem()).field_150939_a;
    for (int i = (int) offset.x; i <= te.xCoord + radius_horiz; i += 2) {
        for (int k = (int) offset.z; k <= te.zCoord + radius_horiz; k += 2) {
            for (int j = (int) offset.y; j <= te.yCoord + radius_vert; ++j) {
                Block block = worldObj.getBlock(i, j, k);
                if (block.isReplaceable(worldObj, i, j, k) && treeBlock.canPlaceBlockAt(worldObj, i, j, k)) {
                    AMDataWriter writer = new AMDataWriter();
                    writer.add(i).add(k);
                    habitat.setMetadata(this, writer.generate());
                    return new AMVector3(i, j, k);
                }
            }
        }
    }
    AMDataWriter writer = new AMDataWriter();
    writer.add(te.xCoord - radius_horiz).add(te.zCoord - radius_horiz);
    habitat.setMetadata(this, writer.generate());
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) AMDataReader(am2.network.AMDataReader) ItemBlock(net.minecraft.item.ItemBlock) AMDataWriter(am2.network.AMDataWriter)

Example 18 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class FlickerOperatorFelledOak method plantTree.

private void plantTree(World worldObj, IFlickerController habitat, boolean powered) {
    if (!powered || worldObj.isRemote)
        return;
    ItemStack sapling = getSaplingFromNearbyChest(worldObj, habitat);
    if (sapling == null)
        return;
    AMVector3 plantLoc = getPlantLocation(worldObj, habitat, sapling);
    if (plantLoc == null)
        return;
    deductSaplingFromNearbyChest(worldObj, habitat);
    ItemBlock block = (ItemBlock) sapling.getItem();
    worldObj.setBlock((int) plantLoc.x, (int) plantLoc.y, (int) plantLoc.z, block.field_150939_a, block.getMetadata(sapling.getItemDamage()), 3);
}
Also used : AMVector3(am2.api.math.AMVector3) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock)

Example 19 with AMVector3

use of am2.api.math.AMVector3 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 20 with AMVector3

use of am2.api.math.AMVector3 in project ArsMagica2 by Mithion.

the class FlickerOperatorMoonstoneAttractor method RemoveOperator.

@Override
public void RemoveOperator(World worldObj, IFlickerController habitat, boolean powered) {
    AMVector3 vec = new AMVector3((TileEntity) habitat);
    attractors.remove(vec);
}
Also used : AMVector3(am2.api.math.AMVector3)

Aggregations

AMVector3 (am2.api.math.AMVector3)113 TileEntity (net.minecraft.tileentity.TileEntity)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)16 EntityLivingBase (net.minecraft.entity.EntityLivingBase)15 ArrayList (java.util.ArrayList)11 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)11 IPowerNode (am2.api.power.IPowerNode)10 Block (net.minecraft.block.Block)9 Entity (net.minecraft.entity.Entity)9 ItemStack (net.minecraft.item.ItemStack)9 NBTTagList (net.minecraft.nbt.NBTTagList)9 IInventory (net.minecraft.inventory.IInventory)8 PowerTypes (am2.api.power.PowerTypes)6 AMParticle (am2.particles.AMParticle)5 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)5 TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)4 EntityDragonPart (net.minecraft.entity.boss.EntityDragonPart)4 TileEntityFlickerHabitat (am2.blocks.tileentities.TileEntityFlickerHabitat)3 AMDataWriter (am2.network.AMDataWriter)3 ParticleFloatUpward (am2.particles.ParticleFloatUpward)3