Search in sources :

Example 81 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class NotifyProxyClient method renderMessage.

private void renderMessage(ClientMessage m, float partial, float opacity, Vec3d c) {
    int width = 0;
    String[] lines = m.msgRendered.split("\n");
    FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    for (String line : lines) {
        width = Math.max(width, fr.getStringWidth(line));
    }
    width += 2;
    int halfWidth = width / 2;
    float scaling = 1.6F / 60F;
    scaling *= 2F / 3F;
    GlStateManager.pushMatrix();
    int lineCount = lines.length;
    float centeringOffset = 0;
    if (m.show_item) {
        if (lineCount == 1) {
            centeringOffset = 5F;
        }
        lineCount = Math.max(2, lineCount);
    }
    Vec3d vec = m.getPosition(partial);
    float x = (float) vec.x;
    float y = (float) vec.y;
    float z = (float) vec.z;
    if (m.style.contains(NoticeStyle.SCALE_SIZE)) {
        double dx = x - c.x;
        double dy = y - c.y;
        double dz = z - c.z;
        double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
        scaling *= Math.sqrt(dist);
    }
    NotificationCoord co = m.asCoord();
    if (co != null && !m.position_important) {
        BlockPos pos = co.getPos();
        IBlockState bs = co.getWorld().getBlockState(pos);
        AxisAlignedBB bb = bs.getCollisionBoundingBox(co.getWorld(), pos);
        if (bb != null) {
            y = (float) Math.max(y, pos.getY() + bb.maxY);
        } else {
            y = (float) Math.max(y, pos.getY() + 0.5f);
        }
    }
    GlStateManager.translate(x + 0.5F, y, z + 0.5F);
    Minecraft mc = Minecraft.getMinecraft();
    float pvx = mc.getRenderManager().playerViewX;
    float pvy = -mc.getRenderManager().playerViewY;
    if (mc.gameSettings.thirdPersonView == 2) {
        pvx = -pvx;
    }
    GlStateManager.rotate(pvy, 0.0F, 1.0F, 0.0F);
    GlStateManager.rotate(pvx, 1.0F, 0.0F, 0.0F);
    GlStateManager.scale(-scaling, -scaling, scaling);
    GlStateManager.translate(0, -10 * lineCount, 0);
    {
        int lineHeight = (lineCount - 1) * 10;
        double item_add = 0;
        if (m.show_item) {
            item_add += 24;
        }
        float col = 0.0F;
        GlStateManager.disableTexture2D();
        GlStateManager.color(col, col, col, Math.min(opacity, 0.2F));
        double Z = 0.001D;
        // TODO: Use 2 tessellator + 2 draw calls to do all notice rendering
        worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
        worldrenderer.pos(-halfWidth - 1, -1, Z).endVertex();
        worldrenderer.pos(-halfWidth - 1, 8 + lineHeight, Z).endVertex();
        worldrenderer.pos(halfWidth + 1 + item_add, 8 + lineHeight, Z).endVertex();
        worldrenderer.pos(halfWidth + 1 + item_add, -1, Z).endVertex();
        tessellator.draw();
        GlStateManager.enableTexture2D();
    }
    {
        int i = 0;
        int B = (int) (0xFF * Math.min(1, 0.5F + opacity));
        int color = (B << 16) + (B << 8) + B + ((int) (0xFF * opacity) << 24);
        GlStateManager.translate(0, centeringOffset, 0);
        for (String line : lines) {
            fr.drawString(line, -fr.getStringWidth(line) / 2, 10 * i, color);
            i++;
        }
    }
    {
        if (m.show_item) {
            // TODO: Add transparency support
            GlStateManager.translate(0, -centeringOffset, 0);
            GlStateManager.translate((float) (halfWidth + 4), -lineCount / 2, 0);
            // Undoes the effects of setupGuiTransform
            renderItem.zLevel -= 100;
            renderItem.renderItemIntoGUI(m.item, 0, 0);
            renderItem.zLevel += 100;
        }
    }
    GlStateManager.popMatrix();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Tessellator(net.minecraft.client.renderer.Tessellator) IBlockState(net.minecraft.block.state.IBlockState) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Minecraft(net.minecraft.client.Minecraft) Vec3d(net.minecraft.util.math.Vec3d) BlockPos(net.minecraft.util.math.BlockPos) FontRenderer(net.minecraft.client.gui.FontRenderer)

Example 82 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class PacketNotification method readData.

@Override
public void readData(INetHandler handler, PacketBuffer input) {
    me = getPlayer(handler);
    type = Type.VALUES[input.readByte()];
    switch(type) {
        case COORD:
            pos = new BlockPos(input.readInt(), input.readInt(), input.readInt());
            target = new NotificationCoord(me.world, pos);
            break;
        case ENTITY:
            int id = input.readInt();
            if (id == me.getEntityId()) {
                // bebna
                target = me;
            } else {
                target = me.world.getEntityByID(id);
            }
            break;
        case TILEENTITY:
            pos = new BlockPos(input.readInt(), input.readInt(), input.readInt());
            target = me.world.getTileEntity(pos);
            if (target == null) {
                target = new NotificationCoord(me.world, pos);
            }
            break;
        case VEC3:
            target = new Vec3d(input.readDouble(), input.readDouble(), input.readDouble());
            break;
        case ONSCREEN:
            readStyles(input);
            readMsg(input);
            return;
        default:
            return;
    }
    if (target == null) {
        return;
    }
    item = ByteBufUtils.readItemStack(input);
    readStyles(input);
    readMsg(input);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d)

Example 83 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class RayTraceUtils method getCollision.

public static Result getCollision(World world, BlockPos pos, EntityLivingBase player, List<AxisAlignedBB> list) {
    Vec3d origin = getStart(player);
    Vec3d direction = getEnd(player);
    return getCollision(world, pos, origin, direction, list);
}
Also used : Vec3d(net.minecraft.util.math.Vec3d)

Example 84 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class RayTraceUtils method getCollision.

public static RayTraceResult getCollision(World world, BlockPos pos, EntityLivingBase player, AxisAlignedBB aabb) {
    Vec3d origin = getStart(player);
    Vec3d direction = getEnd(player);
    return getCollision(pos, origin, direction, aabb);
}
Also used : Vec3d(net.minecraft.util.math.Vec3d)

Example 85 with Vec3d

use of net.minecraft.util.math.Vec3d in project Charset by CharsetMC.

the class ArrowHighlightHandler method drawArrowHighlight.

private void drawArrowHighlight(EntityPlayer player, RayTraceResult trace, Vec3d cameraPos) {
    Orientation orientation = SpaceUtils.getOrientation(trace.getBlockPos(), player, trace.sideHit, trace.hitVec.subtract(new Vec3d(trace.getBlockPos())));
    if (orientation.top.getAxis() == trace.sideHit.getAxis() || trace.sideHit == EnumFacing.UP) {
        return;
    }
    GlStateManager.pushMatrix();
    GlStateManager.translate(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    EnumFacing fd = trace.sideHit;
    BlockPos v = trace.getBlockPos().add(fd.getDirectionVec());
    GlStateManager.translate(v.getX(), v.getY(), v.getZ());
    GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
    GlStateManager.disableAlpha();
    GlStateManager.disableTexture2D();
    GlStateManager.disableDepth();
    GlStateManager.glLineWidth(2.0F);
    {
        EnumFacing face = orientation.facing;
        if (SpaceUtils.sign(face) == 1) {
            GlStateManager.translate(face.getDirectionVec().getX(), face.getDirectionVec().getY(), face.getDirectionVec().getZ());
        }
        float d = -2F;
        GlStateManager.translate(d * fd.getDirectionVec().getX(), d * fd.getDirectionVec().getY(), d * fd.getDirectionVec().getZ());
        GlStateManager.translate(0.5 * (1 - Math.abs(face.getDirectionVec().getX())), 0.5 * (1 - Math.abs(face.getDirectionVec().getY())), 0.5 * (1 - Math.abs(face.getDirectionVec().getZ())));
        GlStateManager.glBegin(GL11.GL_LINE_LOOP);
        float mid_x = orientation.facing.getDirectionVec().getX();
        float mid_y = orientation.facing.getDirectionVec().getY();
        float mid_z = orientation.facing.getDirectionVec().getZ();
        float top_x = mid_x + orientation.top.getDirectionVec().getX() / 2F;
        float top_y = mid_y + orientation.top.getDirectionVec().getY() / 2F;
        float top_z = mid_z + orientation.top.getDirectionVec().getZ() / 2F;
        float bot_x = mid_x - orientation.top.getDirectionVec().getX() / 2F;
        float bot_y = mid_y - orientation.top.getDirectionVec().getY() / 2F;
        float bot_z = mid_z - orientation.top.getDirectionVec().getZ() / 2F;
        EnumFacing r = SpaceUtils.rotateCounterclockwise(orientation.facing, orientation.top);
        float right_x = r.getDirectionVec().getX() / 2F;
        float right_y = r.getDirectionVec().getY() / 2F;
        float right_z = r.getDirectionVec().getZ() / 2F;
        // GL11.glVertex3f(mid_x, mid_y, mid_z);
        GlStateManager.glVertex3f(top_x, top_y, top_z);
        GlStateManager.glVertex3f(mid_x + right_x, mid_y + right_y, mid_z + right_z);
        d = 0.25F;
        GlStateManager.glVertex3f(mid_x + right_x * d, mid_y + right_y * d, mid_z + right_z * d);
        GlStateManager.glVertex3f(bot_x + right_x * d, bot_y + right_y * d, bot_z + right_z * d);
        d = -0.25F;
        GlStateManager.glVertex3f(bot_x + right_x * d, bot_y + right_y * d, bot_z + right_z * d);
        GlStateManager.glVertex3f(mid_x + right_x * d, mid_y + right_y * d, mid_z + right_z * d);
        GlStateManager.glVertex3f(mid_x - right_x, mid_y - right_y, mid_z - right_z);
        GlStateManager.glEnd();
    }
    GlStateManager.popMatrix();
    GlStateManager.enableTexture2D();
    GlStateManager.enableDepth();
    GlStateManager.enableAlpha();
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Orientation(pl.asie.charset.lib.utils.Orientation) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

Vec3d (net.minecraft.util.math.Vec3d)789 BlockPos (net.minecraft.util.math.BlockPos)204 Entity (net.minecraft.entity.Entity)118 EnumFacing (net.minecraft.util.EnumFacing)108 ItemStack (net.minecraft.item.ItemStack)100 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)97 RayTraceResult (net.minecraft.util.math.RayTraceResult)90 World (net.minecraft.world.World)90 EntityPlayer (net.minecraft.entity.player.EntityPlayer)88 IBlockState (net.minecraft.block.state.IBlockState)76 EntityLivingBase (net.minecraft.entity.EntityLivingBase)74 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)72 ResourceLocation (net.minecraft.util.ResourceLocation)68 ParticleBuilder (com.teamwizardry.librarianlib.features.particle.ParticleBuilder)59 InterpFadeInOut (com.teamwizardry.librarianlib.features.particle.functions.InterpFadeInOut)59 TileEntity (net.minecraft.tileentity.TileEntity)42 Block (net.minecraft.block.Block)41 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)30 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)27 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)27