Search in sources :

Example 76 with AMVector3

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

the class MathUtilities method bezier.

public static AMVector3 bezier(AMVector3 s, AMVector3 c1, AMVector3 c2, AMVector3 e, float t) {
    if (t < 0 || t > 1.0f) {
        throw new InvalidParameterException("t is out of range, with a value of :" + t);
    }
    float one_minus_t = 1 - t;
    AMVector3 retValue = new AMVector3(0, 0, 0);
    AMVector3[] terms = new AMVector3[4];
    terms[0] = calcNewVector(one_minus_t * one_minus_t * one_minus_t, s);
    terms[1] = calcNewVector(3 * one_minus_t * one_minus_t * t, c1);
    terms[2] = calcNewVector(3 * one_minus_t * t * t, c2);
    terms[3] = calcNewVector(t * t * t, e);
    for (int i = 0; i < 4; ++i) {
        retValue.add(terms[i]);
    }
    return retValue;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) AMVector3(am2.api.math.AMVector3)

Example 77 with AMVector3

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

the class TileEntityCrystalMarker method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound par1) {
    super.readFromNBT(par1);
    filterItems = new ItemStack[FILTER_SIZE];
    if (par1.hasKey("facing")) {
        this.facing = par1.getInteger("facing");
    }
    if (par1.hasKey("priority")) {
        this.priority = par1.getInteger("priority");
    }
    if (par1.hasKey("markerType")) {
        this.markerType = par1.getInteger("markerType");
        if (this.markerType == BlockCrystalMarker.META_FINAL_DEST)
            this.priority = TileEntityFlickerHabitat.PRIORITY_FINAL;
    }
    //Get elemental attuner location
    if (par1.hasKey("elementalAttuner")) {
        float x = 0;
        float y = 0;
        float z = 0;
        boolean success = true;
        NBTTagCompound elementalAttunerLocation = par1.getCompoundTag("elementalAttuner");
        if (elementalAttunerLocation.hasKey("x")) {
            x = elementalAttunerLocation.getFloat("x");
        } else {
            success = false;
        }
        if (success && elementalAttunerLocation.hasKey("y")) {
            y = elementalAttunerLocation.getFloat("y");
        } else {
            success = false;
        }
        if (success && elementalAttunerLocation.hasKey("z")) {
            z = elementalAttunerLocation.getFloat("z");
        } else {
            success = false;
        }
        if (success) {
            elementalAttuner = new AMVector3(x, y, z);
        }
    }
    //Load filter items
    if (par1.hasKey("filterItems")) {
        NBTTagList filterItemsList = par1.getTagList("filterItems", Constants.NBT.TAG_COMPOUND);
        filterItems = new ItemStack[getSizeInventory()];
        for (int i = 0; i < filterItemsList.tagCount(); i++) {
            String tag = String.format("ArrayIndex", i);
            NBTTagCompound nbttagcompound1 = (NBTTagCompound) filterItemsList.getCompoundTagAt(i);
            byte byte0 = nbttagcompound1.getByte(tag);
            if (byte0 >= 0 && byte0 < filterItems.length) {
                filterItems[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }
    }
    //Get connected block bounding box
    if (par1.hasKey("connectedBoundingBox")) {
        NBTTagCompound connectedBoundingBoxDimensions = par1.getCompoundTag("connectedBoundingBox");
        double minx = connectedBoundingBoxDimensions.getDouble("minx");
        double miny = connectedBoundingBoxDimensions.getDouble("miny");
        double minz = connectedBoundingBoxDimensions.getDouble("minz");
        double maxx = connectedBoundingBoxDimensions.getDouble("maxx");
        double maxy = connectedBoundingBoxDimensions.getDouble("maxy");
        double maxz = connectedBoundingBoxDimensions.getDouble("maxz");
        connectedBoundingBox = AxisAlignedBB.getBoundingBox(minx, miny, minz, maxx, maxy, maxz);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) AMVector3(am2.api.math.AMVector3) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 78 with AMVector3

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

the class TileEntityCrystalMarker method linkToHabitat.

public void linkToHabitat(AMVector3 habLocation, EntityPlayer player) {
    TileEntity te = worldObj.getTileEntity((int) habLocation.x, (int) habLocation.y, (int) habLocation.z);
    if (te instanceof TileEntityFlickerHabitat) {
        AMVector3 myLocation = new AMVector3(this.xCoord, this.yCoord, this.zCoord);
        boolean setElementalAttuner = false;
        if (myLocation.distanceSqTo(habLocation) <= SEARCH_RADIUS) {
            if (BlockCrystalMarker.isInputMarker(worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord))) {
                ((TileEntityFlickerHabitat) te).AddMarkerLocationIn(myLocation);
                setElementalAttuner = true;
            }
            if (BlockCrystalMarker.isOutputMarker(worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord))) {
                ((TileEntityFlickerHabitat) te).AddMarkerLocationOut(myLocation);
                setElementalAttuner = true;
            }
            if (setElementalAttuner)
                this.setElementalAttuner(habLocation);
        } else {
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.habitatToFar")));
        }
    }
}
Also used : S35PacketUpdateTileEntity(net.minecraft.network.play.server.S35PacketUpdateTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 79 with AMVector3

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

the class TileEntityCraftingAltar method setCrafting.

private void setCrafting(boolean crafting) {
    this.isCrafting = crafting;
    if (!worldObj.isRemote) {
        AMDataWriter writer = new AMDataWriter();
        writer.add(xCoord);
        writer.add(yCoord);
        writer.add(zCoord);
        writer.add(CRAFTING_CHANGED);
        writer.add(crafting);
        AMNetHandler.INSTANCE.sendPacketToAllClientsNear(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 32, AMPacketIDs.CRAFTING_ALTAR_DATA, writer.generate());
    }
    if (crafting) {
        allAddedItems.clear();
        currentAddedItems.clear();
        spellDef.clear();
        for (ArrayList<KeyValuePair<ISpellPart, byte[]>> groups : shapeGroups) groups.clear();
        //find otherworld auras
        IPowerNode[] nodes = PowerNodeRegistry.For(worldObj).getAllNearbyNodes(worldObj, new AMVector3(this), PowerTypes.DARK);
        for (IPowerNode node : nodes) {
            if (node instanceof TileEntityOtherworldAura) {
                ((TileEntityOtherworldAura) node).setActive(true, this);
                break;
            }
        }
    }
}
Also used : AMVector3(am2.api.math.AMVector3) KeyValuePair(am2.utility.KeyValuePair) AMDataWriter(am2.network.AMDataWriter) IPowerNode(am2.api.power.IPowerNode)

Example 80 with AMVector3

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

the class ItemCrystalWrench method doPairNodes.

private void doPairNodes(World world, int x, int y, int z, ItemStack stack, EntityPlayer player, double hitX, double hitY, double hitZ, TileEntity te) {
    AMVector3 source = AMVector3.readFromNBT(stack.stackTagCompound.getCompoundTag(KEY_PAIRLOC));
    TileEntity sourceTE = world.getTileEntity((int) source.x, (int) source.y, (int) source.z);
    if (sourceTE != null && sourceTE instanceof IPowerNode && !world.isRemote) {
        player.addChatMessage(new ChatComponentText(PowerNodeRegistry.For(world).tryPairNodes((IPowerNode) sourceTE, (IPowerNode) te)));
    } else if (world.isRemote) {
        spawnLinkParticles(world, x + hitX, y + hitY, z + hitZ);
    }
    if (!stack.stackTagCompound.hasKey(KEEP_BINDING))
        stack.stackTagCompound.removeTag(KEY_PAIRLOC);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) ChatComponentText(net.minecraft.util.ChatComponentText) IPowerNode(am2.api.power.IPowerNode)

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