Search in sources :

Example 6 with IPowerNode

use of am2.api.power.IPowerNode in project ArsMagica2 by Mithion.

the class ClientTickHandler method spawnPowerPathVisuals.

private void spawnPowerPathVisuals() {
    if (Minecraft.getMinecraft().thePlayer.getCurrentArmor(3) != null && (Minecraft.getMinecraft().thePlayer.getCurrentArmor(3).getItem() == ItemsCommonProxy.magitechGoggles || ArmorHelper.isInfusionPreset(Minecraft.getMinecraft().thePlayer.getCurrentArmor(3), GenericImbuement.magitechGoggleIntegration))) {
        if (arcSpawnCounter++ >= arcSpawnFrequency) {
            arcSpawnCounter = 0;
            AMVector3 playerPos = new AMVector3(Minecraft.getMinecraft().thePlayer);
            HashMap<PowerTypes, ArrayList<LinkedList<AMVector3>>> paths = AMCore.proxy.getPowerPathVisuals();
            if (paths != null) {
                for (PowerTypes type : paths.keySet()) {
                    String texture = type == PowerTypes.LIGHT ? "textures/blocks/oreblockbluetopaz.png" : type == PowerTypes.NEUTRAL ? "textures/blocks/oreblockvinteum.png" : type == PowerTypes.DARK ? "textures/blocks/oreblocksunstone.png" : "textures/blocks/oreblocksunstone.png";
                    ArrayList<LinkedList<AMVector3>> pathList = paths.get(type);
                    for (LinkedList<AMVector3> individualPath : pathList) {
                        for (int i = 0; i < individualPath.size() - 1; ++i) {
                            AMVector3 start = individualPath.get(i + 1);
                            AMVector3 end = individualPath.get(i);
                            if (start.distanceSqTo(playerPos) > 2500 || end.distanceSqTo(playerPos) > 2500) {
                                continue;
                            }
                            TileEntity teStart = Minecraft.getMinecraft().theWorld.getTileEntity((int) start.x, (int) start.y, (int) start.z);
                            TileEntity teEnd = Minecraft.getMinecraft().theWorld.getTileEntity((int) end.x, (int) end.y, (int) end.z);
                            if (teEnd == null || !(teEnd instanceof IPowerNode))
                                break;
                            double startX = start.x + ((teStart != null && teStart instanceof IPowerNode) ? ((IPowerNode) teStart).particleOffset(0) : 0.5f);
                            double startY = start.y + ((teStart != null && teStart instanceof IPowerNode) ? ((IPowerNode) teStart).particleOffset(1) : 0.5f);
                            double startZ = start.z + ((teStart != null && teStart instanceof IPowerNode) ? ((IPowerNode) teStart).particleOffset(2) : 0.5f);
                            double endX = end.x + ((IPowerNode) teEnd).particleOffset(0);
                            double endY = end.y + ((IPowerNode) teEnd).particleOffset(1);
                            double endZ = end.z + ((IPowerNode) teEnd).particleOffset(2);
                            AMLineArc arc = (AMLineArc) AMCore.proxy.particleManager.spawn(Minecraft.getMinecraft().theWorld, texture, startX, startY, startZ, endX, endY, endZ);
                            if (arc != null) {
                                arcs.add(arc);
                            }
                        }
                    }
                }
            }
        }
    } else {
        Iterator<AMLineArc> it = arcs.iterator();
        while (it.hasNext()) {
            AMLineArc arc = it.next();
            if (arc == null || arc.isDead)
                it.remove();
            else
                arc.setDead();
        }
        arcSpawnCounter = arcSpawnFrequency;
    }
}
Also used : ArrayList(java.util.ArrayList) AMLineArc(am2.particles.AMLineArc) LinkedList(java.util.LinkedList) TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) PowerTypes(am2.api.power.PowerTypes) IPowerNode(am2.api.power.IPowerNode)

Example 7 with IPowerNode

use of am2.api.power.IPowerNode in project ArsMagica2 by Mithion.

the class ClientProxy method drawPowerOnBlockHighlight.

@Override
public void drawPowerOnBlockHighlight(EntityPlayer player, MovingObjectPosition target, float partialTicks) {
    if (AMCore.proxy.getLocalPlayer().getCurrentArmor(3) != null && (AMCore.proxy.getLocalPlayer().getCurrentArmor(3).getItem() == ItemsCommonProxy.magitechGoggles || ArmorHelper.isInfusionPreset(AMCore.proxy.getLocalPlayer().getCurrentArmor(3), GenericImbuement.magitechGoggleIntegration))) {
        TileEntity te = player.worldObj.getTileEntity(target.blockX, target.blockY, target.blockZ);
        if (te != null && te instanceof IPowerNode) {
            AMCore.proxy.setTrackedLocation(new AMVector3(target.blockX, target.blockY, target.blockZ));
        } else {
            AMCore.proxy.setTrackedLocation(AMVector3.zero());
        }
        if (AMCore.proxy.hasTrackedLocationSynced()) {
            PowerNodeEntry data = AMCore.proxy.getTrackedData();
            Block block = player.worldObj.getBlock(target.blockX, target.blockY, target.blockZ);
            float yOff = 0.5f;
            if (data != null) {
                GL11.glPushAttrib(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_LIGHTING_BIT);
                for (PowerTypes type : ((IPowerNode) te).getValidPowerTypes()) {
                    float pwr = data.getPower(type);
                    float pct = pwr / ((IPowerNode) te).getCapacity() * 100;
                    RenderUtilities.drawTextInWorldAtOffset(String.format("%s%.2f (%.2f%%)", type.chatColor(), pwr, pct), target.blockX - (player.prevPosX - (player.prevPosX - player.posX) * partialTicks) + 0.5f, target.blockY + yOff - (player.prevPosY - (player.prevPosY - player.posY) * partialTicks) + block.getBlockBoundsMaxY() * 0.8f, target.blockZ - (player.prevPosZ - (player.prevPosZ - player.posZ) * partialTicks) + 0.5f, 0xFFFFFF);
                    yOff += 0.12f;
                }
                GL11.glPopAttrib();
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AMVector3(am2.api.math.AMVector3) PowerTypes(am2.api.power.PowerTypes) Block(net.minecraft.block.Block) PowerNodeEntry(am2.power.PowerNodeEntry) IPowerNode(am2.api.power.IPowerNode)

Example 8 with IPowerNode

use of am2.api.power.IPowerNode 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 9 with IPowerNode

use of am2.api.power.IPowerNode in project ArsMagica2 by Mithion.

the class ItemCrystalWrench method onItemUseFirst.

@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
    TileEntity te = world.getTileEntity(x, y, z);
    if (!stack.hasTagCompound())
        stack.setTagCompound(new NBTTagCompound());
    int cMode = getMode(stack);
    if (te != null && !(te instanceof IPowerNode || te instanceof TileEntityParticleEmitter) && cMode == MODE_DISCONNECT) {
        player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("am2.tooltip.wrongWrenchMode")));
        return false;
    }
    if (te != null && te instanceof IPowerNode) {
        if (cMode == MODE_DISCONNECT) {
            doDisconnect((IPowerNode) te, world, x + hitX, y + hitY, z + hitZ, player);
            return false;
        }
        if (stack.stackTagCompound.hasKey(KEY_PAIRLOC)) {
            doPairNodes(world, x, y, z, stack, player, hitX, hitY, hitZ, te);
        } else {
            storePairLocation(world, te, stack, player, x + hitX, y + hitY, z + hitZ);
        }
    } else if (te != null && te instanceof TileEntityCrystalMarker && stack.stackTagCompound != null && stack.stackTagCompound.hasKey(HAB_PAIRLOC)) {
        handleCMPair(stack, world, player, te, x + hitX, y + hitY, z + hitZ);
    } else if (player.isSneaking()) {
        handleModeChanges(stack);
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityCrystalMarker(am2.blocks.tileentities.TileEntityCrystalMarker) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileEntityParticleEmitter(am2.blocks.tileentities.TileEntityParticleEmitter) ChatComponentText(net.minecraft.util.ChatComponentText) IPowerNode(am2.api.power.IPowerNode)

Example 10 with IPowerNode

use of am2.api.power.IPowerNode 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

IPowerNode (am2.api.power.IPowerNode)14 TileEntity (net.minecraft.tileentity.TileEntity)14 AMVector3 (am2.api.math.AMVector3)13 PowerTypes (am2.api.power.PowerTypes)5 PowerNodeEntry (am2.power.PowerNodeEntry)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ChatComponentText (net.minecraft.util.ChatComponentText)3 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)3 ArrayList (java.util.ArrayList)2 Block (net.minecraft.block.Block)2 Chunk (net.minecraft.world.chunk.Chunk)2 TileEntityCrystalMarker (am2.blocks.tileentities.TileEntityCrystalMarker)1 TileEntityParticleEmitter (am2.blocks.tileentities.TileEntityParticleEmitter)1 AMDataWriter (am2.network.AMDataWriter)1 AMLineArc (am2.particles.AMLineArc)1 KeyValuePair (am2.utility.KeyValuePair)1 LinkedList (java.util.LinkedList)1 ItemBlock (net.minecraft.item.ItemBlock)1 World (net.minecraft.world.World)1