| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import java.nio.FloatBuffer;
|
| 4 | import java.nio.IntBuffer;
|
| 5 | import net.minecraft.block.Block;
|
| 6 | import net.minecraft.block.BlockLiquid;
|
| 7 | import net.minecraft.block.state.IBlockState;
|
| 8 | import net.minecraft.entity.Entity;
|
| 9 | import net.minecraft.entity.player.EntityPlayer;
|
| 10 | import net.minecraft.util.BlockPos;
|
| 11 | import net.minecraft.util.MathHelper;
|
| 12 | import net.minecraft.util.Vec3;
|
| 13 | import net.minecraft.world.World;
|
| 14 | import org.lwjgl.opengl.GL11;
|
| 15 | import org.lwjgl.util.glu.GLU;
|
| 16 |
|
| 17 | public class ActiveRenderInfo
|
| 18 | {
|
| 19 | /** The current GL viewport */
|
| 20 | private static final IntBuffer VIEWPORT = GLAllocation.createDirectIntBuffer(16);
|
| 21 |
|
| 22 | /** The current GL modelview matrix */
|
| 23 | private static final FloatBuffer MODELVIEW = GLAllocation.createDirectFloatBuffer(16);
|
| 24 |
|
| 25 | /** The current GL projection matrix */
|
| 26 | private static final FloatBuffer PROJECTION = GLAllocation.createDirectFloatBuffer(16);
|
| 27 |
|
| 28 | /** The computed view object coordinates */
|
| 29 | private static final FloatBuffer OBJECTCOORDS = GLAllocation.createDirectFloatBuffer(3);
|
| 30 | private static Vec3 position = new Vec3(0.0D, 0.0D, 0.0D);
|
| 31 |
|
| 32 | /** The X component of the entity's yaw rotation */
|
| 33 | private static float rotationX;
|
| 34 |
|
| 35 | /** The combined X and Z components of the entity's pitch rotation */
|
| 36 | private static float rotationXZ;
|
| 37 |
|
| 38 | /** The Z component of the entity's yaw rotation */
|
| 39 | private static float rotationZ;
|
| 40 |
|
| 41 | /**
|
| 42 | * The Y component (scaled along the Z axis) of the entity's pitch rotation
|
| 43 | */
|
| 44 | private static float rotationYZ;
|
| 45 |
|
| 46 | /**
|
| 47 | * The Y component (scaled along the X axis) of the entity's pitch rotation
|
| 48 | */
|
| 49 | private static float rotationXY;
|
| 50 |
|
| 51 | /**
|
| 52 | * Updates the current render info and camera location based on entity look angles and 1st/3rd person view mode
|
| 53 | */
|
| 54 | public static void updateRenderInfo(EntityPlayer entityplayerIn, boolean p_74583_1_)
|
| 55 | {
|
| 56 | GlStateManager.getFloat(2982, MODELVIEW);
|
| 57 | GlStateManager.getFloat(2983, PROJECTION);
|
| 58 | GL11.glGetInteger(GL11.GL_VIEWPORT, VIEWPORT);
|
| 59 | float f = (float)((VIEWPORT.get(0) + VIEWPORT.get(2)) / 2);
|
| 60 | float f1 = (float)((VIEWPORT.get(1) + VIEWPORT.get(3)) / 2);
|
| 61 | GLU.gluUnProject(f, f1, 0.0F, MODELVIEW, PROJECTION, VIEWPORT, OBJECTCOORDS);
|
| 62 | position = new Vec3((double)OBJECTCOORDS.get(0), (double)OBJECTCOORDS.get(1), (double)OBJECTCOORDS.get(2));
|
| 63 | int i = p_74583_1_ ? 1 : 0;
|
| 64 | float f2 = entityplayerIn.rotationPitch;
|
| 65 | float f3 = entityplayerIn.rotationYaw;
|
| 66 | rotationX = MathHelper.cos(f3 * (float)Math.PI / 180.0F) * (float)(1 - i * 2);
|
| 67 | rotationZ = MathHelper.sin(f3 * (float)Math.PI / 180.0F) * (float)(1 - i * 2);
|
| 68 | rotationYZ = -rotationZ * MathHelper.sin(f2 * (float)Math.PI / 180.0F) * (float)(1 - i * 2);
|
| 69 | rotationXY = rotationX * MathHelper.sin(f2 * (float)Math.PI / 180.0F) * (float)(1 - i * 2);
|
| 70 | rotationXZ = MathHelper.cos(f2 * (float)Math.PI / 180.0F);
|
| 71 | }
|
| 72 |
|
| 73 | public static Vec3 projectViewFromEntity(Entity p_178806_0_, double p_178806_1_)
|
| 74 | {
|
| 75 | double d0 = p_178806_0_.prevPosX + (p_178806_0_.posX - p_178806_0_.prevPosX) * p_178806_1_;
|
| 76 | double d1 = p_178806_0_.prevPosY + (p_178806_0_.posY - p_178806_0_.prevPosY) * p_178806_1_;
|
| 77 | double d2 = p_178806_0_.prevPosZ + (p_178806_0_.posZ - p_178806_0_.prevPosZ) * p_178806_1_;
|
| 78 | double d3 = d0 + position.xCoord;
|
| 79 | double d4 = d1 + position.yCoord;
|
| 80 | double d5 = d2 + position.zCoord;
|
| 81 | return new Vec3(d3, d4, d5);
|
| 82 | }
|
| 83 |
|
| 84 | public static Block getBlockAtEntityViewpoint(World worldIn, Entity p_180786_1_, float p_180786_2_)
|
| 85 | {
|
| 86 | Vec3 vec3 = projectViewFromEntity(p_180786_1_, (double)p_180786_2_);
|
| 87 | BlockPos blockpos = new BlockPos(vec3);
|
| 88 | IBlockState iblockstate = worldIn.getBlockState(blockpos);
|
| 89 | Block block = iblockstate.getBlock();
|
| 90 |
|
| 91 | if (block.getMaterial().isLiquid())
|
| 92 | {
|
| 93 | float f = 0.0F;
|
| 94 |
|
| 95 | if (iblockstate.getBlock() instanceof BlockLiquid)
|
| 96 | {
|
| 97 | f = BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()) - 0.11111111F;
|
| 98 | }
|
| 99 |
|
| 100 | float f1 = (float)(blockpos.getY() + 1) - f;
|
| 101 |
|
| 102 | if (vec3.yCoord >= (double)f1)
|
| 103 | {
|
| 104 | block = worldIn.getBlockState(blockpos.up()).getBlock();
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 | return block;
|
| 109 | }
|
| 110 |
|
| 111 | public static Vec3 getPosition()
|
| 112 | {
|
| 113 | return position;
|
| 114 | }
|
| 115 |
|
| 116 | public static float getRotationX()
|
| 117 | {
|
| 118 | return rotationX;
|
| 119 | }
|
| 120 |
|
| 121 | public static float getRotationXZ()
|
| 122 | {
|
| 123 | return rotationXZ;
|
| 124 | }
|
| 125 |
|
| 126 | public static float getRotationZ()
|
| 127 | {
|
| 128 | return rotationZ;
|
| 129 | }
|
| 130 |
|
| 131 | public static float getRotationYZ()
|
| 132 | {
|
| 133 | return rotationYZ;
|
| 134 | }
|
| 135 |
|
| 136 | public static float getRotationXY()
|
| 137 | {
|
| 138 | return rotationXY;
|
| 139 | }
|
| 140 | }
|
| 141 |
|