Advertisement
Guest User

DWCM OPEN ALPHA TCN

a guest
Apr 2nd, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. /* */ package com.ikingssgc.mdc.utils;
  2. /* */
  3. /* */ import com.ikingssgc.mdc.block.ModelBlock;
  4. /* */ import java.awt.image.BufferedImage;
  5. /* */ import java.io.File;
  6. /* */ import java.io.FileInputStream;
  7. /* */ import java.io.FileNotFoundException;
  8. /* */ import java.io.InputStream;
  9. /* */ import java.nio.ByteBuffer;
  10. /* */ import java.util.HashMap;
  11. /* */ import java.util.Random;
  12. /* */ import net.minecraft.client.Minecraft;
  13. /* */ import net.minecraft.client.model.ModelBase;
  14. /* */ import org.lwjgl.BufferUtils;
  15. /* */ import org.lwjgl.opengl.GL11;
  16. /* */
  17. /* */
  18. /* */
  19. /* */ //DWCM Code - Sub
  20. /* */ public class CustomModels
  21. /* */ {
  22. /* */ private static TCNLoader defaultModel;
  23. /* */ public static int defaultTexture;
  24. /* */ static Random rand;
  25. /* */ static boolean defTex;
  26. /* */
  27. /* */ public static void initModels()
  28. /* */ {
  29. /* 29 */ if (!defTex) {
  30. /* 30 */ rand = new Random();
  31. /* 31 */ BufferedImage im = new BufferedImage(64, 64, 1);
  32. /* 32 */ for (int i = 0; i < 64; i++) {
  33. /* 33 */ for (int j = 0; j < 64; j++) {
  34. /* 34 */ im.setRGB(i, j, rand.nextInt(16777215));
  35. /* */ }
  36. /* */ }
  37. /* 37 */ defaultTexture = loadTexture(im);
  38. /* 38 */ defTex = true;
  39. /* */ }
  40. /* 40 */ if (defaultModel == null) {
  41. /* 41 */ defaultModel = new ModelBlock();
  42. /* */ }
  43. /* 43 */ File folder = new File(Minecraft.func_71410_x().field_71412_D + "/mods/Dalek Mod/Models");
  44. /* 44 */ if (!folder.exists()) {
  45. /* 45 */ folder.mkdirs();
  46. /* */ }
  47. /* 47 */ File[] listOfFiles = folder.listFiles();
  48. /* 48 */ for (int i = 0; i < listOfFiles.length; i++) {
  49. /* 49 */ if ((listOfFiles[i].isFile()) && (listOfFiles[i].getName().endsWith(".tcn")))
  50. /* */ {
  51. /* 51 */ InputStream is = null;
  52. /* */ try {
  53. /* 53 */ is = new FileInputStream(listOfFiles[i].getAbsolutePath());
  54. /* */ } catch (FileNotFoundException e) {
  55. /* 55 */ e.printStackTrace();
  56. /* */ }
  57. /* 57 */ if ((is != null) && (!models.containsKey(listOfFiles[i].getName())))
  58. /* */ {
  59. /* 59 */ addModel(listOfFiles[i].getName(), new TCNLoader(is));
  60. /* */ }
  61. /* */ }
  62. /* */ }
  63. /* */ }
  64. /* */
  65. /* 65 */ private static HashMap<String, TCNLoader> models = new HashMap();
  66. /* */
  67. /* */ public static HashMap<String, TCNLoader> getModels() {
  68. /* 68 */ return models;
  69. /* */ }
  70. /* */
  71. /* */ public static void addModel(String name, TCNLoader b) {
  72. /* 72 */ if (!models.containsKey(name)) {
  73. /* 73 */ models.put(name, b);
  74. /* */ }
  75. /* */ }
  76. /* */
  77. /* */ public static ModelBase getModel(String name) {
  78. /* 78 */ if (models.containsKey(name)) {
  79. /* 79 */ return (ModelBase)models.get(name);
  80. /* */ }
  81. /* 81 */ return defaultModel;
  82. /* */ }
  83. /* */
  84. /* */ public static int loadTexture(BufferedImage image) {
  85. /* 85 */ int[] pixels = new int[image.getWidth() * image.getHeight()];
  86. /* 86 */ image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
  87. /* */
  88. /* 88 */ ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);
  89. /* 89 */ for (int y = 0; y < image.getHeight(); y++) {
  90. /* 90 */ for (int x = 0; x < image.getWidth(); x++) {
  91. /* 91 */ int pixel = pixels[(y * image.getWidth() + x)];
  92. /* 92 */ buffer.put((byte)(pixel >> 16 & 0xFF));
  93. /* 93 */ buffer.put((byte)(pixel >> 8 & 0xFF));
  94. /* 94 */ buffer.put((byte)(pixel & 0xFF));
  95. /* 95 */ buffer.put((byte)(pixel >> 24 & 0xFF));
  96. /* */ }
  97. /* */ }
  98. /* 98 */ buffer.flip();
  99. /* 99 */ int textureID = GL11.glGenTextures();
  100. /* 100 */ GL11.glBindTexture(3553, textureID);
  101. /* 101 */ GL11.glTexParameteri(3553, 10242, 33071);
  102. /* 102 */ GL11.glTexParameteri(3553, 10243, 33071);
  103. /* 103 */ GL11.glTexParameteri(3553, 10241, 9729);
  104. /* 104 */ GL11.glTexParameteri(3553, 10240, 9729);
  105. /* 105 */ GL11.glTexImage2D(3553, 0, 32856, image.getWidth(), image.getHeight(), 0, 6408, 5121, buffer);
  106. /* */
  107. /* 107 */ return textureID;
  108. /* */ }
  109. /* */ }
  110.  
  111.  
  112. /* Location: C:\Users\NAMEREMOVED\Desktop\dwcm-dwcm-open-alpha.jar!\com\ikingssgc\mdc\utils\CustomModels.class
  113. * Java compiler version: 6 (50.0)
  114. * JD-Core Version: 0.7.1
  115. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement