Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* */ package com.ikingssgc.mdc.utils;
- /* */
- /* */ import com.ikingssgc.mdc.block.ModelBlock;
- /* */ import java.awt.image.BufferedImage;
- /* */ import java.io.File;
- /* */ import java.io.FileInputStream;
- /* */ import java.io.FileNotFoundException;
- /* */ import java.io.InputStream;
- /* */ import java.nio.ByteBuffer;
- /* */ import java.util.HashMap;
- /* */ import java.util.Random;
- /* */ import net.minecraft.client.Minecraft;
- /* */ import net.minecraft.client.model.ModelBase;
- /* */ import org.lwjgl.BufferUtils;
- /* */ import org.lwjgl.opengl.GL11;
- /* */
- /* */
- /* */
- /* */ //DWCM Code - Sub
- /* */ public class CustomModels
- /* */ {
- /* */ private static TCNLoader defaultModel;
- /* */ public static int defaultTexture;
- /* */ static Random rand;
- /* */ static boolean defTex;
- /* */
- /* */ public static void initModels()
- /* */ {
- /* 29 */ if (!defTex) {
- /* 30 */ rand = new Random();
- /* 31 */ BufferedImage im = new BufferedImage(64, 64, 1);
- /* 32 */ for (int i = 0; i < 64; i++) {
- /* 33 */ for (int j = 0; j < 64; j++) {
- /* 34 */ im.setRGB(i, j, rand.nextInt(16777215));
- /* */ }
- /* */ }
- /* 37 */ defaultTexture = loadTexture(im);
- /* 38 */ defTex = true;
- /* */ }
- /* 40 */ if (defaultModel == null) {
- /* 41 */ defaultModel = new ModelBlock();
- /* */ }
- /* 43 */ File folder = new File(Minecraft.func_71410_x().field_71412_D + "/mods/Dalek Mod/Models");
- /* 44 */ if (!folder.exists()) {
- /* 45 */ folder.mkdirs();
- /* */ }
- /* 47 */ File[] listOfFiles = folder.listFiles();
- /* 48 */ for (int i = 0; i < listOfFiles.length; i++) {
- /* 49 */ if ((listOfFiles[i].isFile()) && (listOfFiles[i].getName().endsWith(".tcn")))
- /* */ {
- /* 51 */ InputStream is = null;
- /* */ try {
- /* 53 */ is = new FileInputStream(listOfFiles[i].getAbsolutePath());
- /* */ } catch (FileNotFoundException e) {
- /* 55 */ e.printStackTrace();
- /* */ }
- /* 57 */ if ((is != null) && (!models.containsKey(listOfFiles[i].getName())))
- /* */ {
- /* 59 */ addModel(listOfFiles[i].getName(), new TCNLoader(is));
- /* */ }
- /* */ }
- /* */ }
- /* */ }
- /* */
- /* 65 */ private static HashMap<String, TCNLoader> models = new HashMap();
- /* */
- /* */ public static HashMap<String, TCNLoader> getModels() {
- /* 68 */ return models;
- /* */ }
- /* */
- /* */ public static void addModel(String name, TCNLoader b) {
- /* 72 */ if (!models.containsKey(name)) {
- /* 73 */ models.put(name, b);
- /* */ }
- /* */ }
- /* */
- /* */ public static ModelBase getModel(String name) {
- /* 78 */ if (models.containsKey(name)) {
- /* 79 */ return (ModelBase)models.get(name);
- /* */ }
- /* 81 */ return defaultModel;
- /* */ }
- /* */
- /* */ public static int loadTexture(BufferedImage image) {
- /* 85 */ int[] pixels = new int[image.getWidth() * image.getHeight()];
- /* 86 */ image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
- /* */
- /* 88 */ ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);
- /* 89 */ for (int y = 0; y < image.getHeight(); y++) {
- /* 90 */ for (int x = 0; x < image.getWidth(); x++) {
- /* 91 */ int pixel = pixels[(y * image.getWidth() + x)];
- /* 92 */ buffer.put((byte)(pixel >> 16 & 0xFF));
- /* 93 */ buffer.put((byte)(pixel >> 8 & 0xFF));
- /* 94 */ buffer.put((byte)(pixel & 0xFF));
- /* 95 */ buffer.put((byte)(pixel >> 24 & 0xFF));
- /* */ }
- /* */ }
- /* 98 */ buffer.flip();
- /* 99 */ int textureID = GL11.glGenTextures();
- /* 100 */ GL11.glBindTexture(3553, textureID);
- /* 101 */ GL11.glTexParameteri(3553, 10242, 33071);
- /* 102 */ GL11.glTexParameteri(3553, 10243, 33071);
- /* 103 */ GL11.glTexParameteri(3553, 10241, 9729);
- /* 104 */ GL11.glTexParameteri(3553, 10240, 9729);
- /* 105 */ GL11.glTexImage2D(3553, 0, 32856, image.getWidth(), image.getHeight(), 0, 6408, 5121, buffer);
- /* */
- /* 107 */ return textureID;
- /* */ }
- /* */ }
- /* Location: C:\Users\NAMEREMOVED\Desktop\dwcm-dwcm-open-alpha.jar!\com\ikingssgc\mdc\utils\CustomModels.class
- * Java compiler version: 6 (50.0)
- * JD-Core Version: 0.7.1
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement