Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. package hi.guard.mods;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.renderer.GlStateManager;
  5. import net.minecraft.client.renderer.chunk.RenderChunk;
  6. import net.minecraft.util.BlockPos;
  7. import net.minecraft.util.EnumFacing;
  8. import net.minecraft.util.Vec3i;
  9. import java.util.WeakHashMap;
  10.  
  11. public class ChunkAnimator {
  12.  
  13. public static boolean enabled = true;
  14. private final ChunkAnimator animationHandler = new ChunkAnimator();
  15. public static boolean disableAroundPlayer;
  16. public static int animDuration = 1000;
  17.  
  18. private WeakHashMap<RenderChunk, AnimationData> timeStamps = new WeakHashMap<RenderChunk, AnimationData>();
  19.  
  20. public void setPosition(RenderChunk rc, BlockPos bp) {
  21. if (!ChunkAnimator.enabled) return;
  22. if (Minecraft.getMinecraft().thePlayer != null) {
  23. boolean flag = true;
  24. BlockPos zeroedPlayerPosition = Minecraft.getMinecraft().thePlayer.getPosition();
  25. zeroedPlayerPosition = zeroedPlayerPosition.add(0, -zeroedPlayerPosition.getY(), 0);
  26. BlockPos zeroedCenteredChunkPos = bp.add(8, -bp.getY(), 8);
  27.  
  28. if (ChunkAnimator.disableAroundPlayer) {
  29. flag = zeroedPlayerPosition.distanceSq(zeroedCenteredChunkPos) > (64 * 64);
  30. }
  31.  
  32. if (flag) {
  33. EnumFacing chunkFacing = null;
  34.  
  35. Vec3i dif = zeroedPlayerPosition.subtract(zeroedCenteredChunkPos);
  36. int difX = Math.abs(dif.getX());
  37. int difZ = Math.abs(dif.getZ());
  38. chunkFacing = getFacing(dif, difX, difZ);
  39.  
  40.  
  41. AnimationData animationData = new AnimationData(-1L, chunkFacing);
  42. timeStamps.put(rc, animationData);
  43. }
  44. }
  45. }
  46.  
  47. public void preRenderChunk(RenderChunk renderChunk) {
  48. if (!ChunkAnimator.enabled) return;
  49. if (timeStamps.containsKey(renderChunk)) {
  50. AnimationData animationData = timeStamps.get(renderChunk);
  51. long time = animationData.timeStamp;
  52. if (time == -1L) {
  53. time = System.currentTimeMillis();
  54. animationData.timeStamp = time;
  55.  
  56. BlockPos zeroedPlayerPosition = Minecraft.getMinecraft().thePlayer.getPosition();
  57. zeroedPlayerPosition = zeroedPlayerPosition.add(0, -zeroedPlayerPosition.getY(), 0);
  58. BlockPos zeroedCenteredChunkPos = renderChunk.getPosition().add(8, -renderChunk.getPosition().getY(), 8);
  59. Vec3i dif = zeroedPlayerPosition.subtract(zeroedCenteredChunkPos);
  60. int difX = Math.abs(dif.getX());
  61. int difZ = Math.abs(dif.getZ());
  62. animationData.chunkFacing = getFacing(dif, difX, difZ);
  63.  
  64. }
  65. long timeDif = System.currentTimeMillis() - time;
  66. int animationDuration = ChunkAnimator.animDuration;
  67. if (timeDif < animationDuration) {
  68. double chunkY = renderChunk.getPosition().getY();
  69.  
  70.  
  71. } else {
  72. timeStamps.remove(renderChunk);
  73. }
  74. }
  75. }
  76.  
  77. private EnumFacing getFacing(Vec3i dif, int difX, int difZ) {
  78. return difX > difZ ? dif.getX() > 0 ? EnumFacing.EAST : EnumFacing.WEST : dif.getZ() > 0 ? EnumFacing.SOUTH : EnumFacing.NORTH;
  79. }
  80.  
  81. private static class AnimationData {
  82. long timeStamp;
  83. EnumFacing chunkFacing;
  84.  
  85. AnimationData(long timeStamp, EnumFacing chunkFacing) {
  86. this.timeStamp = timeStamp;
  87. this.chunkFacing = chunkFacing;
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement