Search in sources :

Example 16 with IPowerNode

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

the class AMClientEventHandler method renderPowerFloatingText.

private void renderPowerFloatingText(DrawBlockHighlightEvent event, TileEntity te) {
    PowerNodeEntry data = AMCore.proxy.getTrackedData();
    Block block = event.player.worldObj.getBlock(event.target.blockX, event.target.blockY, event.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;
            AMVector3 offset = new AMVector3(event.target.blockX + 0.5, event.target.blockY + 0.5, event.target.blockZ + 0.5).sub(new AMVector3((event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks), (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + event.player.getEyeHeight(), (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks)));
            offset = offset.normalize();
            if (event.target.blockY <= event.player.posY - 0.5) {
                RenderUtilities.drawTextInWorldAtOffset(String.format("%s%.2f (%.2f%%)", type.chatColor(), pwr, pct), event.target.blockX - (event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks) + 0.5f - offset.x, event.target.blockY + yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) + block.getBlockBoundsMaxY() * 0.8f, event.target.blockZ - (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks) + 0.5f - offset.z, 0xFFFFFF);
                yOff += 0.12f;
            } else {
                RenderUtilities.drawTextInWorldAtOffset(String.format("%s%.2f (%.2f%%)", type.chatColor(), pwr, pct), event.target.blockX - (event.player.prevPosX - (event.player.prevPosX - event.player.posX) * event.partialTicks) + 0.5f - offset.x, event.target.blockY - yOff - (event.player.prevPosY - (event.player.prevPosY - event.player.posY) * event.partialTicks) - block.getBlockBoundsMaxY() * 0.2f, event.target.blockZ - (event.player.prevPosZ - (event.player.prevPosZ - event.player.posZ) * event.partialTicks) + 0.5f - offset.z, 0xFFFFFF);
                yOff -= 0.12f;
            }
        }
        GL11.glPopAttrib();
    }
}
Also used : AMVector3(am2.api.math.AMVector3) PowerTypes(am2.api.power.PowerTypes) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) PowerNodeEntry(am2.power.PowerNodeEntry) IPowerNode(am2.api.power.IPowerNode)

Example 17 with IPowerNode

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

the class ItemSpellStaff 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) {
    if (isMagiTechStaff()) {
        if (!world.isRemote) {
            TileEntity te = world.getTileEntity(x, y, z);
            if (te != null && te instanceof IPowerNode) {
                if (player.isSneaking()) {
                    AMNetHandler.INSTANCE.syncPowerPaths((IPowerNode) te, (EntityPlayerMP) player);
                } else {
                    PowerTypes[] types = ((IPowerNode) te).getValidPowerTypes();
                    for (PowerTypes type : types) {
                        float power = PowerNodeRegistry.For(world).getPower((IPowerNode) te, type);
                        player.addChatMessage(new ChatComponentText(String.format(StatCollector.translateToLocal("am2.tooltip.det_eth"), type.chatColor(), type.name(), String.format("%.2f", power))));
                    }
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PowerTypes(am2.api.power.PowerTypes) 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