Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.64 KB | None | 0 0
  1. import net.minecraft.block.material.Material;
  2. import net.minecraft.client.Minecraft;
  3. import net.minecraft.client.renderer.GlStateManager;
  4. import net.minecraft.client.renderer.entity.RenderItem;
  5. import net.minecraft.client.renderer.texture.TextureMap;
  6. import net.minecraft.client.resources.model.IBakedModel;
  7. import net.minecraft.entity.Entity;
  8. import net.minecraft.entity.item.EntityItem;
  9. import net.minecraft.item.Item;
  10. import net.minecraft.item.ItemBlock;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.BlockPos;
  13. import net.minecraft.util.ResourceLocation;
  14. import org.lwjgl.opengl.GL11;
  15.  
  16. import de.blockmod.BlockMod;
  17.  
  18. import java.util.Random;
  19.  
  20. public class ItemPhysics {
  21.  
  22. public static Random random = new Random();
  23. public static Minecraft mc = Minecraft.getMinecraft();
  24. public static RenderItem renderItem = mc.getRenderItem();
  25. public static long tick;
  26. public static double rotation;
  27. public static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
  28.  
  29. /**
  30. * doRender is called in RenderEntityItem
  31. */
  32. public static void doRender(Entity par1Entity, double x, double y, double z, float par8, float par9) {
  33. rotation = (System.nanoTime() - tick) / BlockMod.itemphysicrotation * 1.0F;
  34. if (!mc.inGameHasFocus) {
  35. rotation = 0.0D;
  36. }
  37. EntityItem item = (EntityItem) par1Entity;
  38. ItemStack itemstack = item.getEntityItem();
  39. if (itemstack.getItem() != null) {
  40. random.setSeed(187L);
  41. boolean flag = false;
  42. if (TextureMap.locationBlocksTexture != null) {
  43. mc.getRenderManager().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
  44. mc.getRenderManager().renderEngine.getTexture(TextureMap.locationBlocksTexture).setBlurMipmap(false,
  45. false);
  46.  
  47. flag = true;
  48. }
  49. GlStateManager.enableRescaleNormal();
  50. GlStateManager.alphaFunc(516, 0.1F);
  51. GlStateManager.enableBlend();
  52. GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
  53. GlStateManager.pushMatrix();
  54.  
  55. IBakedModel ibakedmodel = renderItem.getItemModelMesher().getItemModel(itemstack);
  56. int i = func_177077_a(item, x, y, z, par9, ibakedmodel);
  57.  
  58. BlockPos pos = new BlockPos(item);
  59. if (item.rotationPitch > 360.0F) {
  60. item.rotationPitch = 0.0F;
  61. }
  62. if ((item != null) && (!Double.isNaN(item.getAge())) && (!Double.isNaN(item.getAir()))
  63. && (!Double.isNaN(item.getEntityId())) && (item.getPosition() != null)) {
  64. if (item.onGround) {
  65. if ((item.rotationPitch != 0.0F) && (item.rotationPitch != 90.0F) && (item.rotationPitch != 180.0F)
  66. && (item.rotationPitch != 270.0F)) {
  67. double Abstand0 = formPositiv(item.rotationPitch);
  68. double Abstand90 = formPositiv(item.rotationPitch - 90.0F);
  69. double Abstand180 = formPositiv(item.rotationPitch - 180.0F);
  70. double Abstand270 = formPositiv(item.rotationPitch - 270.0F);
  71. if ((Abstand0 <= Abstand90) && (Abstand0 <= Abstand180) && (Abstand0 <= Abstand270)) {
  72. if (item.rotationPitch < 0.0F) {
  73. EntityItem tmp389_387 = item;
  74. tmp389_387.rotationPitch = ((float) (tmp389_387.rotationPitch + rotation));
  75. } else {
  76. EntityItem tmp407_405 = item;
  77. tmp407_405.rotationPitch = ((float) (tmp407_405.rotationPitch - rotation));
  78. }
  79. }
  80. if ((Abstand90 < Abstand0) && (Abstand90 <= Abstand180) && (Abstand90 <= Abstand270)) {
  81. if (item.rotationPitch - 90.0F < 0.0F) {
  82. EntityItem tmp459_457 = item;
  83. tmp459_457.rotationPitch = ((float) (tmp459_457.rotationPitch + rotation));
  84. } else {
  85. EntityItem tmp477_475 = item;
  86. tmp477_475.rotationPitch = ((float) (tmp477_475.rotationPitch - rotation));
  87. }
  88. }
  89. if ((Abstand180 < Abstand90) && (Abstand180 < Abstand0) && (Abstand180 <= Abstand270)) {
  90. if (item.rotationPitch - 180.0F < 0.0F) {
  91. EntityItem tmp529_527 = item;
  92. tmp529_527.rotationPitch = ((float) (tmp529_527.rotationPitch + rotation));
  93. } else {
  94. EntityItem tmp547_545 = item;
  95. tmp547_545.rotationPitch = ((float) (tmp547_545.rotationPitch - rotation));
  96. }
  97. }
  98. if ((Abstand270 < Abstand90) && (Abstand270 < Abstand180) && (Abstand270 < Abstand0)) {
  99. if (item.rotationPitch - 270.0F < 0.0F) {
  100. EntityItem tmp599_597 = item;
  101. tmp599_597.rotationPitch = ((float) (tmp599_597.rotationPitch + rotation));
  102. } else {
  103. EntityItem tmp617_615 = item;
  104. tmp617_615.rotationPitch = ((float) (tmp617_615.rotationPitch - rotation));
  105. }
  106. }
  107. }
  108. } else {
  109. BlockPos posUp = new BlockPos(item);
  110. posUp.add(0, 1, 0);
  111.  
  112. Material m1 = item.worldObj.getBlockState(posUp).getBlock().getMaterial();
  113.  
  114. Material m2 = item.worldObj.getBlockState(pos).getBlock().getMaterial();
  115.  
  116. boolean m3 = item.isInsideOfMaterial(Material.water);
  117. boolean m4 = item.inWater;
  118. if ((m3 | m1 == Material.water | m2 == Material.water | m4)) {
  119. EntityItem tmp748_746 = item;
  120. tmp748_746.rotationPitch = ((float) (tmp748_746.rotationPitch + rotation / 4.0D));
  121. } else {
  122. EntityItem tmp770_768 = item;
  123. tmp770_768.rotationPitch = ((float) (tmp770_768.rotationPitch + rotation * 2.0D));
  124. }
  125. }
  126. }
  127. GL11.glRotatef(item.rotationYaw, 0.0F, 1.0F, 0.0F);
  128. GL11.glRotatef(item.rotationPitch + 90.0F, 1.0F, 0.0F, 0.0F);
  129. for (int j = 0; j < i; j++) {
  130. if (ibakedmodel.isAmbientOcclusion()) {
  131. GlStateManager.pushMatrix();
  132. GlStateManager.scale(0.5F, 0.5F, 0.5F);
  133. renderItem.renderItem(itemstack, ibakedmodel);
  134. GlStateManager.popMatrix();
  135. } else {
  136. GlStateManager.pushMatrix();
  137. if ((j > 0) && (shouldSpreadItems())) {
  138. GlStateManager.translate(0.0F, 0.0F, 0.046875F * j);
  139. }
  140. renderItem.renderItem(itemstack, ibakedmodel);
  141. if (!shouldSpreadItems()) {
  142. GlStateManager.translate(0.0F, 0.0F, 0.046875F);
  143. }
  144. GlStateManager.popMatrix();
  145. }
  146. }
  147. GlStateManager.popMatrix();
  148. GlStateManager.disableRescaleNormal();
  149. GlStateManager.disableBlend();
  150. mc.getRenderManager().renderEngine.bindTexture(TextureMap.locationBlocksTexture);
  151. if (flag) {
  152. mc.getRenderManager().renderEngine.getTexture(TextureMap.locationBlocksTexture).restoreLastBlurMipmap();
  153. }
  154. }
  155. }
  156.  
  157. public static int func_177077_a(EntityItem item, double x, double y, double z, float p_177077_8_, IBakedModel p_177077_9_) {
  158. ItemStack itemstack = item.getEntityItem();
  159. Item item2 = itemstack.getItem();
  160. if (item2 == null) {
  161. return 0;
  162. }
  163. boolean flag = p_177077_9_.isAmbientOcclusion();
  164. int i = func_177078_a(itemstack);
  165. float f1 = 0.25F;
  166. float f2 = 0.0F;
  167. GlStateManager.translate((float) x, (float) y + f2 + 0.25F, (float) z);
  168. float f3 = 0.0F;
  169. if ((flag) || ((mc.getRenderManager().renderEngine != null) && (mc.gameSettings.fancyGraphics))) {
  170. GlStateManager.rotate(f3, 0.0F, 1.0F, 0.0F);
  171. }
  172. if (!flag) {
  173. f3 = -0.0F * (i - 1) * 0.5F;
  174. float f4 = -0.0F * (i - 1) * 0.5F;
  175. float f5 = -0.046875F * (i - 1) * 0.5F;
  176. GlStateManager.translate(f3, f4, f5);
  177. }
  178. GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  179. return i;
  180. }
  181.  
  182. public static boolean shouldSpreadItems() {
  183. return true;
  184. }
  185.  
  186. public static double formPositiv(float rotationPitch) {
  187. if (rotationPitch > 0.0F) {
  188. return rotationPitch;
  189. }
  190. return -rotationPitch;
  191. }
  192.  
  193. public static int func_177078_a(ItemStack stack) {
  194. byte b0 = 1;
  195. if (stack.animationsToGo > 48) {
  196. b0 = 5;
  197. } else if (stack.animationsToGo > 32) {
  198. b0 = 4;
  199. } else if (stack.animationsToGo > 16) {
  200. b0 = 3;
  201. } else if (stack.animationsToGo > 1) {
  202. b0 = 2;
  203. }
  204. return b0;
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement