-
Notifications
You must be signed in to change notification settings - Fork 2
/
EntityRenderer.java
2506 lines (2164 loc) · 101 KB
/
EntityRenderer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package net.minecraft.client.renderer;
import com.google.common.base.Predicates;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.FloatBuffer;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Callable;
import me.iyoshimc.iowa.event.events.Event3D;
import net.minecraft.block.Block;
import net.minecraft.block.BlockBed;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.gui.GuiDownloadTerrain;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.MapItemRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.culling.ClippingHelperImpl;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.client.shader.ShaderGroup;
import net.minecraft.client.shader.ShaderLinkHelper;
import net.minecraft.crash.CrashReport;
import net.minecraft.crash.CrashReportCategory;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EntitySelectors;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.EnumWorldBlockLayer;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MouseFilter;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.ReportedException;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.biome.BiomeGenBase;
import optfine.Config;
import optfine.CustomColorizer;
import optfine.Lagometer;
import optfine.RandomMobs;
import optfine.Reflector;
import optfine.RenderPlayerOF;
import optfine.TextureUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.util.glu.GLU;
import org.lwjgl.util.glu.Project;
public class EntityRenderer implements IResourceManagerReloadListener
{
private static final Logger logger = LogManager.getLogger();
private static final ResourceLocation locationRainPng = new ResourceLocation("textures/environment/rain.png");
private static final ResourceLocation locationSnowPng = new ResourceLocation("textures/environment/snow.png");
public static boolean anaglyphEnable;
/** Anaglyph field (0=R, 1=GB) */
public static int anaglyphField;
/** A reference to the Minecraft object. */
private Minecraft mc;
private final IResourceManager resourceManager;
private Random random = new Random();
private float farPlaneDistance;
public ItemRenderer itemRenderer;
private final MapItemRenderer theMapItemRenderer;
/** Entity renderer update count */
private int rendererUpdateCount;
/** Pointed entity */
private Entity pointedEntity;
private MouseFilter mouseFilterXAxis = new MouseFilter();
private MouseFilter mouseFilterYAxis = new MouseFilter();
private float thirdPersonDistance = 4.0F;
/** Third person distance temp */
private float thirdPersonDistanceTemp = 4.0F;
/** Smooth cam yaw */
private float smoothCamYaw;
/** Smooth cam pitch */
private float smoothCamPitch;
/** Smooth cam filter X */
private float smoothCamFilterX;
/** Smooth cam filter Y */
private float smoothCamFilterY;
/** Smooth cam partial ticks */
private float smoothCamPartialTicks;
/** FOV modifier hand */
private float fovModifierHand;
/** FOV modifier hand prev */
private float fovModifierHandPrev;
private float bossColorModifier;
private float bossColorModifierPrev;
/** Cloud fog mode */
private boolean cloudFog;
private boolean renderHand = true;
private boolean drawBlockOutline = true;
/** Previous frame time in milliseconds */
private long prevFrameTime = Minecraft.getSystemTime();
/** End time of last render (ns) */
private long renderEndNanoTime;
/**
* The texture id of the blocklight/skylight texture used for lighting effects
*/
private final DynamicTexture lightmapTexture;
/**
* Colors computed in updateLightmap() and loaded into the lightmap emptyTexture
*/
private final int[] lightmapColors;
private final ResourceLocation locationLightMap;
/**
* Is set, updateCameraAndRender() calls updateLightmap(); set by updateTorchFlicker()
*/
private boolean lightmapUpdateNeeded;
/** Torch flicker X */
private float torchFlickerX;
private float torchFlickerDX;
/** Rain sound counter */
private int rainSoundCounter;
private float[] rainXCoords = new float[1024];
private float[] rainYCoords = new float[1024];
/** Fog color buffer */
private FloatBuffer fogColorBuffer = GLAllocation.createDirectFloatBuffer(16);
public float fogColorRed;
public float fogColorGreen;
public float fogColorBlue;
/** Fog color 2 */
private float fogColor2;
/** Fog color 1 */
private float fogColor1;
private int debugViewDirection = 0;
private boolean debugView = false;
private double cameraZoom = 1.0D;
private double cameraYaw;
private double cameraPitch;
private ShaderGroup theShaderGroup;
private static final ResourceLocation[] shaderResourceLocations = new ResourceLocation[] {new ResourceLocation("shaders/post/notch.json"), new ResourceLocation("shaders/post/fxaa.json"), new ResourceLocation("shaders/post/art.json"), new ResourceLocation("shaders/post/bumpy.json"), new ResourceLocation("shaders/post/blobs2.json"), new ResourceLocation("shaders/post/pencil.json"), new ResourceLocation("shaders/post/color_convolve.json"), new ResourceLocation("shaders/post/deconverge.json"), new ResourceLocation("shaders/post/flip.json"), new ResourceLocation("shaders/post/invert.json"), new ResourceLocation("shaders/post/ntsc.json"), new ResourceLocation("shaders/post/outline.json"), new ResourceLocation("shaders/post/phosphor.json"), new ResourceLocation("shaders/post/scan_pincushion.json"), new ResourceLocation("shaders/post/sobel.json"), new ResourceLocation("shaders/post/bits.json"), new ResourceLocation("shaders/post/desaturate.json"), new ResourceLocation("shaders/post/green.json"), new ResourceLocation("shaders/post/blur.json"), new ResourceLocation("shaders/post/wobble.json"), new ResourceLocation("shaders/post/blobs.json"), new ResourceLocation("shaders/post/antialias.json"), new ResourceLocation("shaders/post/creeper.json"), new ResourceLocation("shaders/post/spider.json")};
public static final int shaderCount = shaderResourceLocations.length;
private int shaderIndex;
private boolean useShader;
private int frameCount;
private static final String __OBFID = "CL_00000947";
private boolean initialized = false;
private World updatedWorld = null;
private boolean showDebugInfo = false;
public boolean fogStandard = false;
private float clipDistance = 128.0F;
private long lastServerTime = 0L;
private int lastServerTicks = 0;
private int serverWaitTime = 0;
private int serverWaitTimeCurrent = 0;
private float avgServerTimeDiff = 0.0F;
private float avgServerTickDiff = 0.0F;
private long lastErrorCheckTimeMs = 0L;
public EntityRenderer(Minecraft mcIn, IResourceManager resourceManagerIn)
{
this.shaderIndex = shaderCount;
this.useShader = false;
this.frameCount = 0;
this.mc = mcIn;
this.resourceManager = resourceManagerIn;
this.itemRenderer = mcIn.getItemRenderer();
this.theMapItemRenderer = new MapItemRenderer(mcIn.getTextureManager());
this.lightmapTexture = new DynamicTexture(16, 16);
this.locationLightMap = mcIn.getTextureManager().getDynamicTextureLocation("lightMap", this.lightmapTexture);
this.lightmapColors = this.lightmapTexture.getTextureData();
this.theShaderGroup = null;
for (int i = 0; i < 32; ++i)
{
for (int j = 0; j < 32; ++j)
{
float f = (float)(j - 16);
float f1 = (float)(i - 16);
float f2 = MathHelper.sqrt_float(f * f + f1 * f1);
this.rainXCoords[i << 5 | j] = -f1 / f2;
this.rainYCoords[i << 5 | j] = f / f2;
}
}
}
public boolean isShaderActive()
{
return OpenGlHelper.shadersSupported && this.theShaderGroup != null;
}
public void func_181022_b()
{
if (this.theShaderGroup != null)
{
this.theShaderGroup.deleteShaderGroup();
}
this.theShaderGroup = null;
this.shaderIndex = shaderCount;
}
public void switchUseShader()
{
this.useShader = !this.useShader;
}
/**
* What shader to use when spectating this entity
*/
public void loadEntityShader(Entity entityIn)
{
if (OpenGlHelper.shadersSupported)
{
if (this.theShaderGroup != null)
{
this.theShaderGroup.deleteShaderGroup();
}
this.theShaderGroup = null;
if (entityIn instanceof EntityCreeper)
{
this.loadShader(new ResourceLocation("shaders/post/creeper.json"));
}
else if (entityIn instanceof EntitySpider)
{
this.loadShader(new ResourceLocation("shaders/post/spider.json"));
}
else if (entityIn instanceof EntityEnderman)
{
this.loadShader(new ResourceLocation("shaders/post/invert.json"));
}
}
}
public void activateNextShader()
{
if (OpenGlHelper.shadersSupported && this.mc.getRenderViewEntity() instanceof EntityPlayer)
{
if (this.theShaderGroup != null)
{
this.theShaderGroup.deleteShaderGroup();
}
this.shaderIndex = (this.shaderIndex + 1) % (shaderResourceLocations.length + 1);
if (this.shaderIndex != shaderCount)
{
this.loadShader(shaderResourceLocations[this.shaderIndex]);
}
else
{
this.theShaderGroup = null;
}
}
}
private void loadShader(ResourceLocation resourceLocationIn)
{
try
{
this.theShaderGroup = new ShaderGroup(this.mc.getTextureManager(), this.resourceManager, this.mc.getFramebuffer(), resourceLocationIn);
this.theShaderGroup.createBindFramebuffers(this.mc.displayWidth, this.mc.displayHeight);
this.useShader = true;
}
catch (IOException ioexception)
{
logger.warn((String)("Failed to load shader: " + resourceLocationIn), (Throwable)ioexception);
this.shaderIndex = shaderCount;
this.useShader = false;
}
catch (JsonSyntaxException jsonsyntaxexception)
{
logger.warn((String)("Failed to load shader: " + resourceLocationIn), (Throwable)jsonsyntaxexception);
this.shaderIndex = shaderCount;
this.useShader = false;
}
}
public void onResourceManagerReload(IResourceManager resourceManager)
{
if (this.theShaderGroup != null)
{
this.theShaderGroup.deleteShaderGroup();
}
this.theShaderGroup = null;
if (this.shaderIndex != shaderCount)
{
this.loadShader(shaderResourceLocations[this.shaderIndex]);
}
else
{
this.loadEntityShader(this.mc.getRenderViewEntity());
}
}
/**
* Updates the entity renderer
*/
public void updateRenderer()
{
if (OpenGlHelper.shadersSupported && ShaderLinkHelper.getStaticShaderLinkHelper() == null)
{
ShaderLinkHelper.setNewStaticShaderLinkHelper();
}
this.updateFovModifierHand();
this.updateTorchFlicker();
this.fogColor2 = this.fogColor1;
this.thirdPersonDistanceTemp = this.thirdPersonDistance;
if (this.mc.gameSettings.smoothCamera)
{
float f = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
float f1 = f * f * f * 8.0F;
this.smoothCamFilterX = this.mouseFilterXAxis.smooth(this.smoothCamYaw, 0.05F * f1);
this.smoothCamFilterY = this.mouseFilterYAxis.smooth(this.smoothCamPitch, 0.05F * f1);
this.smoothCamPartialTicks = 0.0F;
this.smoothCamYaw = 0.0F;
this.smoothCamPitch = 0.0F;
}
else
{
this.smoothCamFilterX = 0.0F;
this.smoothCamFilterY = 0.0F;
this.mouseFilterXAxis.reset();
this.mouseFilterYAxis.reset();
}
if (this.mc.getRenderViewEntity() == null)
{
this.mc.setRenderViewEntity(this.mc.thePlayer);
}
float f3 = this.mc.theWorld.getLightBrightness(new BlockPos(this.mc.getRenderViewEntity()));
float f4 = (float)this.mc.gameSettings.renderDistanceChunks / 32.0F;
float f2 = f3 * (1.0F - f4) + f4;
this.fogColor1 += (f2 - this.fogColor1) * 0.1F;
++this.rendererUpdateCount;
this.itemRenderer.updateEquippedItem();
this.addRainParticles();
this.bossColorModifierPrev = this.bossColorModifier;
if (BossStatus.hasColorModifier)
{
this.bossColorModifier += 0.05F;
if (this.bossColorModifier > 1.0F)
{
this.bossColorModifier = 1.0F;
}
BossStatus.hasColorModifier = false;
}
else if (this.bossColorModifier > 0.0F)
{
this.bossColorModifier -= 0.0125F;
}
}
public ShaderGroup getShaderGroup()
{
return this.theShaderGroup;
}
public void updateShaderGroupSize(int width, int height)
{
if (OpenGlHelper.shadersSupported)
{
if (this.theShaderGroup != null)
{
this.theShaderGroup.createBindFramebuffers(width, height);
}
this.mc.renderGlobal.createBindEntityOutlineFbs(width, height);
}
}
/**
* Finds what block or object the mouse is over at the specified partial tick time. Args: partialTickTime
*/
public void getMouseOver(float partialTicks)
{
Entity entity = this.mc.getRenderViewEntity();
if (entity != null && this.mc.theWorld != null)
{
this.mc.mcProfiler.startSection("pick");
this.mc.pointedEntity = null;
double d0 = (double)this.mc.playerController.getBlockReachDistance();
this.mc.objectMouseOver = entity.rayTrace(d0, partialTicks);
double d1 = d0;
Vec3 vec3 = entity.getPositionEyes(partialTicks);
boolean flag = false;
boolean flag1 = true;
if (this.mc.playerController.extendedReach())
{
d0 = 6.0D;
d1 = 6.0D;
}
else
{
if (d0 > 3.0D)
{
flag = true;
}
d0 = d0;
}
if (this.mc.objectMouseOver != null)
{
d1 = this.mc.objectMouseOver.hitVec.distanceTo(vec3);
}
Vec3 vec31 = entity.getLook(partialTicks);
Vec3 vec32 = vec3.addVector(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0);
this.pointedEntity = null;
Vec3 vec33 = null;
float f = 1.0F;
List list = this.mc.theWorld.getEntitiesInAABBexcluding(entity, entity.getEntityBoundingBox().addCoord(vec31.xCoord * d0, vec31.yCoord * d0, vec31.zCoord * d0).expand((double)f, (double)f, (double)f), Predicates.and(EntitySelectors.NOT_SPECTATING, new EntityRenderer1(this)));
double d2 = d1;
for (int i = 0; i < list.size(); ++i)
{
Entity entity1 = (Entity)list.get(i);
float f1 = entity1.getCollisionBorderSize();
AxisAlignedBB axisalignedbb = entity1.getEntityBoundingBox().expand((double)f1, (double)f1, (double)f1);
MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);
if (axisalignedbb.isVecInside(vec3))
{
if (d2 >= 0.0D)
{
this.pointedEntity = entity1;
vec33 = movingobjectposition == null ? vec3 : movingobjectposition.hitVec;
d2 = 0.0D;
}
}
else if (movingobjectposition != null)
{
double d3 = vec3.distanceTo(movingobjectposition.hitVec);
if (d3 < d2 || d2 == 0.0D)
{
boolean flag2 = false;
if (Reflector.ForgeEntity_canRiderInteract.exists())
{
flag2 = Reflector.callBoolean(entity1, Reflector.ForgeEntity_canRiderInteract, new Object[0]);
}
if (entity1 == entity.ridingEntity && !flag2)
{
if (d2 == 0.0D)
{
this.pointedEntity = entity1;
vec33 = movingobjectposition.hitVec;
}
}
else
{
this.pointedEntity = entity1;
vec33 = movingobjectposition.hitVec;
d2 = d3;
}
}
}
}
if (this.pointedEntity != null && flag && vec3.distanceTo(vec33) > 3.0D)
{
this.pointedEntity = null;
this.mc.objectMouseOver = new MovingObjectPosition(MovingObjectPosition.MovingObjectType.MISS, vec33, (EnumFacing)null, new BlockPos(vec33));
}
if (this.pointedEntity != null && (d2 < d1 || this.mc.objectMouseOver == null))
{
this.mc.objectMouseOver = new MovingObjectPosition(this.pointedEntity, vec33);
if (this.pointedEntity instanceof EntityLivingBase || this.pointedEntity instanceof EntityItemFrame)
{
this.mc.pointedEntity = this.pointedEntity;
}
}
this.mc.mcProfiler.endSection();
}
}
/**
* Update FOV modifier hand
*/
private void updateFovModifierHand()
{
float f = 1.0F;
if (this.mc.getRenderViewEntity() instanceof AbstractClientPlayer)
{
AbstractClientPlayer abstractclientplayer = (AbstractClientPlayer)this.mc.getRenderViewEntity();
f = abstractclientplayer.getFovModifier();
}
this.fovModifierHandPrev = this.fovModifierHand;
this.fovModifierHand += (f - this.fovModifierHand) * 0.5F;
if (this.fovModifierHand > 1.5F)
{
this.fovModifierHand = 1.5F;
}
if (this.fovModifierHand < 0.1F)
{
this.fovModifierHand = 0.1F;
}
}
/**
* Changes the field of view of the player depending on if they are underwater or not
*/
private float getFOVModifier(float partialTicks, boolean p_78481_2_)
{
if (this.debugView)
{
return 90.0F;
}
else
{
Entity entity = this.mc.getRenderViewEntity();
float f = 70.0F;
if (p_78481_2_)
{
f = this.mc.gameSettings.fovSetting;
f = f * (this.fovModifierHandPrev + (this.fovModifierHand - this.fovModifierHandPrev) * partialTicks);
}
boolean flag = false;
if (this.mc.currentScreen == null)
{
GameSettings gamesettings = this.mc.gameSettings;
flag = GameSettings.isKeyDown(this.mc.gameSettings.ofKeyBindZoom);
}
if (flag)
{
if (!Config.zoomMode)
{
Config.zoomMode = true;
this.mc.gameSettings.smoothCamera = true;
}
if (Config.zoomMode)
{
f /= 4.0F;
}
}
else if (Config.zoomMode)
{
Config.zoomMode = false;
this.mc.gameSettings.smoothCamera = false;
this.mouseFilterXAxis = new MouseFilter();
this.mouseFilterYAxis = new MouseFilter();
this.mc.renderGlobal.displayListEntitiesDirty = true;
}
if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).getHealth() <= 0.0F)
{
float f1 = (float)((EntityLivingBase)entity).deathTime + partialTicks;
f /= (1.0F - 500.0F / (f1 + 500.0F)) * 2.0F + 1.0F;
}
Block block = ActiveRenderInfo.getBlockAtEntityViewpoint(this.mc.theWorld, entity, partialTicks);
if (block.getMaterial() == Material.water)
{
f = f * 60.0F / 70.0F;
}
return f;
}
}
private void hurtCameraEffect(float partialTicks)
{
if (this.mc.getRenderViewEntity() instanceof EntityLivingBase)
{
EntityLivingBase entitylivingbase = (EntityLivingBase)this.mc.getRenderViewEntity();
float f = (float)entitylivingbase.hurtTime - partialTicks;
if (entitylivingbase.getHealth() <= 0.0F)
{
float f1 = (float)entitylivingbase.deathTime + partialTicks;
GlStateManager.rotate(40.0F - 8000.0F / (f1 + 200.0F), 0.0F, 0.0F, 1.0F);
}
if (f < 0.0F)
{
return;
}
f = f / (float)entitylivingbase.maxHurtTime;
f = MathHelper.sin(f * f * f * f * (float)Math.PI);
float f2 = entitylivingbase.attackedAtYaw;
GlStateManager.rotate(-f2, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(-f * 14.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(f2, 0.0F, 1.0F, 0.0F);
}
}
/**
* Setups all the GL settings for view bobbing. Args: partialTickTime
*/
private void setupViewBobbing(float partialTicks)
{
if (this.mc.getRenderViewEntity() instanceof EntityPlayer)
{
EntityPlayer entityplayer = (EntityPlayer)this.mc.getRenderViewEntity();
float f = entityplayer.distanceWalkedModified - entityplayer.prevDistanceWalkedModified;
float f1 = -(entityplayer.distanceWalkedModified + f * partialTicks);
float f2 = entityplayer.prevCameraYaw + (entityplayer.cameraYaw - entityplayer.prevCameraYaw) * partialTicks;
float f3 = entityplayer.prevCameraPitch + (entityplayer.cameraPitch - entityplayer.prevCameraPitch) * partialTicks;
GlStateManager.translate(MathHelper.sin(f1 * (float)Math.PI) * f2 * 0.5F, -Math.abs(MathHelper.cos(f1 * (float)Math.PI) * f2), 0.0F);
GlStateManager.rotate(MathHelper.sin(f1 * (float)Math.PI) * f2 * 3.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(Math.abs(MathHelper.cos(f1 * (float)Math.PI - 0.2F) * f2) * 5.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(f3, 1.0F, 0.0F, 0.0F);
}
}
/**
* sets up player's eye (or camera in third person mode)
*/
private void orientCamera(float partialTicks)
{
Entity entity = this.mc.getRenderViewEntity();
float f = entity.getEyeHeight();
double d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double)partialTicks;
double d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double)partialTicks + (double)f;
double d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)partialTicks;
if (entity instanceof EntityLivingBase && ((EntityLivingBase)entity).isPlayerSleeping())
{
f = (float)((double)f + 1.0D);
GlStateManager.translate(0.0F, 0.3F, 0.0F);
if (!this.mc.gameSettings.debugCamEnable)
{
BlockPos blockpos = new BlockPos(entity);
IBlockState iblockstate = this.mc.theWorld.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (Reflector.ForgeHooksClient_orientBedCamera.exists())
{
Reflector.callVoid(Reflector.ForgeHooksClient_orientBedCamera, new Object[] {this.mc.theWorld, blockpos, iblockstate, entity});
}
else if (block == Blocks.bed)
{
int j = ((EnumFacing)iblockstate.getValue(BlockBed.FACING)).getHorizontalIndex();
GlStateManager.rotate((float)(j * 90), 0.0F, 1.0F, 0.0F);
}
GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, -1.0F, 0.0F);
GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, -1.0F, 0.0F, 0.0F);
}
}
else if (this.mc.gameSettings.thirdPersonView > 0)
{
double d3 = (double)(this.thirdPersonDistanceTemp + (this.thirdPersonDistance - this.thirdPersonDistanceTemp) * partialTicks);
if (this.mc.gameSettings.debugCamEnable)
{
GlStateManager.translate(0.0F, 0.0F, (float)(-d3));
}
else
{
float f1 = entity.rotationYaw;
float f2 = entity.rotationPitch;
if (this.mc.gameSettings.thirdPersonView == 2)
{
f2 += 180.0F;
}
double d4 = (double)(-MathHelper.sin(f1 / 180.0F * (float)Math.PI) * MathHelper.cos(f2 / 180.0F * (float)Math.PI)) * d3;
double d5 = (double)(MathHelper.cos(f1 / 180.0F * (float)Math.PI) * MathHelper.cos(f2 / 180.0F * (float)Math.PI)) * d3;
double d6 = (double)(-MathHelper.sin(f2 / 180.0F * (float)Math.PI)) * d3;
for (int i = 0; i < 8; ++i)
{
float f3 = (float)((i & 1) * 2 - 1);
float f4 = (float)((i >> 1 & 1) * 2 - 1);
float f5 = (float)((i >> 2 & 1) * 2 - 1);
f3 = f3 * 0.1F;
f4 = f4 * 0.1F;
f5 = f5 * 0.1F;
MovingObjectPosition movingobjectposition = this.mc.theWorld.rayTraceBlocks(new Vec3(d0 + (double)f3, d1 + (double)f4, d2 + (double)f5), new Vec3(d0 - d4 + (double)f3 + (double)f5, d1 - d6 + (double)f4, d2 - d5 + (double)f5));
if (movingobjectposition != null)
{
double d7 = movingobjectposition.hitVec.distanceTo(new Vec3(d0, d1, d2));
if (d7 < d3)
{
d3 = d7;
}
}
}
if (this.mc.gameSettings.thirdPersonView == 2)
{
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
}
GlStateManager.rotate(entity.rotationPitch - f2, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(entity.rotationYaw - f1, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(0.0F, 0.0F, (float)(-d3));
GlStateManager.rotate(f1 - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f2 - entity.rotationPitch, 1.0F, 0.0F, 0.0F);
}
}
else
{
GlStateManager.translate(0.0F, 0.0F, -0.1F);
}
if (!this.mc.gameSettings.debugCamEnable)
{
GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 1.0F, 0.0F, 0.0F);
if (entity instanceof EntityAnimal)
{
EntityAnimal entityanimal = (EntityAnimal)entity;
GlStateManager.rotate(entityanimal.prevRotationYawHead + (entityanimal.rotationYawHead - entityanimal.prevRotationYawHead) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F);
}
else
{
GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks + 180.0F, 0.0F, 1.0F, 0.0F);
}
}
GlStateManager.translate(0.0F, -f, 0.0F);
d0 = entity.prevPosX + (entity.posX - entity.prevPosX) * (double)partialTicks;
d1 = entity.prevPosY + (entity.posY - entity.prevPosY) * (double)partialTicks + (double)f;
d2 = entity.prevPosZ + (entity.posZ - entity.prevPosZ) * (double)partialTicks;
this.cloudFog = this.mc.renderGlobal.hasCloudFog(d0, d1, d2, partialTicks);
}
/**
* sets up projection, view effects, camera position/rotation
*/
private void setupCameraTransform(float partialTicks, int pass)
{
this.farPlaneDistance = (float)(this.mc.gameSettings.renderDistanceChunks * 16);
if (Config.isFogFancy())
{
this.farPlaneDistance *= 0.95F;
}
if (Config.isFogFast())
{
this.farPlaneDistance *= 0.83F;
}
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
float f = 0.07F;
if (this.mc.gameSettings.anaglyph)
{
GlStateManager.translate((float)(-(pass * 2 - 1)) * f, 0.0F, 0.0F);
}
this.clipDistance = this.farPlaneDistance * 2.0F;
if (this.clipDistance < 173.0F)
{
this.clipDistance = 173.0F;
}
if (this.mc.theWorld.provider.getDimensionId() == 1)
{
this.clipDistance = 256.0F;
}
if (this.cameraZoom != 1.0D)
{
GlStateManager.translate((float)this.cameraYaw, (float)(-this.cameraPitch), 0.0F);
GlStateManager.scale(this.cameraZoom, this.cameraZoom, 1.0D);
}
Project.gluPerspective(this.getFOVModifier(partialTicks, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.clipDistance);
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
if (this.mc.gameSettings.anaglyph)
{
GlStateManager.translate((float)(pass * 2 - 1) * 0.1F, 0.0F, 0.0F);
}
this.hurtCameraEffect(partialTicks);
if (this.mc.gameSettings.viewBobbing)
{
this.setupViewBobbing(partialTicks);
}
float f1 = this.mc.thePlayer.prevTimeInPortal + (this.mc.thePlayer.timeInPortal - this.mc.thePlayer.prevTimeInPortal) * partialTicks;
if (f1 > 0.0F)
{
byte b0 = 20;
if (this.mc.thePlayer.isPotionActive(Potion.confusion))
{
b0 = 7;
}
float f2 = 5.0F / (f1 * f1 + 5.0F) - f1 * 0.04F;
f2 = f2 * f2;
GlStateManager.rotate(((float)this.rendererUpdateCount + partialTicks) * (float)b0, 0.0F, 1.0F, 1.0F);
GlStateManager.scale(1.0F / f2, 1.0F, 1.0F);
GlStateManager.rotate(-((float)this.rendererUpdateCount + partialTicks) * (float)b0, 0.0F, 1.0F, 1.0F);
}
this.orientCamera(partialTicks);
if (this.debugView)
{
switch (this.debugViewDirection)
{
case 0:
GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F);
break;
case 1:
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
break;
case 2:
GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
break;
case 3:
GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
break;
case 4:
GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
}
}
}
/**
* Render player hand
*/
private void renderHand(float partialTicks, int xOffset)
{
if (!this.debugView)
{
GlStateManager.matrixMode(5889);
GlStateManager.loadIdentity();
float f = 0.07F;
if (this.mc.gameSettings.anaglyph)
{
GlStateManager.translate((float)(-(xOffset * 2 - 1)) * f, 0.0F, 0.0F);
}
Project.gluPerspective(this.getFOVModifier(partialTicks, false), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * 2.0F);
GlStateManager.matrixMode(5888);
GlStateManager.loadIdentity();
if (this.mc.gameSettings.anaglyph)
{
GlStateManager.translate((float)(xOffset * 2 - 1) * 0.1F, 0.0F, 0.0F);
}
GlStateManager.pushMatrix();
this.hurtCameraEffect(partialTicks);
if (this.mc.gameSettings.viewBobbing)
{
this.setupViewBobbing(partialTicks);
}
boolean flag = this.mc.getRenderViewEntity() instanceof EntityLivingBase && ((EntityLivingBase)this.mc.getRenderViewEntity()).isPlayerSleeping();
if (this.mc.gameSettings.thirdPersonView == 0 && !flag && !this.mc.gameSettings.hideGUI && !this.mc.playerController.isSpectator())
{
this.enableLightmap();
this.itemRenderer.renderItemInFirstPerson(partialTicks);
this.disableLightmap();
}
GlStateManager.popMatrix();
if (this.mc.gameSettings.thirdPersonView == 0 && !flag)
{
this.itemRenderer.renderOverlays(partialTicks);
this.hurtCameraEffect(partialTicks);
}
if (this.mc.gameSettings.viewBobbing)
{
this.setupViewBobbing(partialTicks);
}
}
}
public void disableLightmap()
{
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GlStateManager.disableTexture2D();
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
public void enableLightmap()
{
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
GlStateManager.matrixMode(5890);
GlStateManager.loadIdentity();
float f = 0.00390625F;
GlStateManager.scale(f, f, f);
GlStateManager.translate(8.0F, 8.0F, 8.0F);
GlStateManager.matrixMode(5888);
this.mc.getTextureManager().bindTexture(this.locationLightMap);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.enableTexture2D();
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
}
/**
* Recompute a random value that is applied to block color in updateLightmap()
*/
private void updateTorchFlicker()
{
this.torchFlickerDX = (float)((double)this.torchFlickerDX + (Math.random() - Math.random()) * Math.random() * Math.random());