Rewrite Textures.java

This commit is contained in:
PeytonPlayz595 2023-10-11 15:08:02 +00:00
parent ef073a4358
commit 508e2aea20
9 changed files with 56 additions and 39 deletions

View File

@ -1,66 +1,83 @@
package com.mojang.minecraft.renderer; package com.mojang.minecraft.renderer;
import com.mojang.minecraft.renderer.texture.TextureFX; import com.mojang.minecraft.renderer.texture.TextureFX;
import java.awt.image.BufferedImage;
import net.PeytonPlayz585.opengl.LWJGLMain;
import net.PeytonPlayz585.opengl.MinecraftImageData;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.imageio.ImageIO;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import org.lwjgl.GLAllocation;
public class Textures { public class Textures {
private HashMap idMap = new HashMap(); public static HashMap<String, Integer> textureMap = new HashMap<String, Integer>();
public IntBuffer idBuffer = BufferUtils.createIntBuffer(1); private IntBuffer singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
public ByteBuffer textureBuffer = BufferUtils.createByteBuffer(262144); public ByteBuffer textureBuffer = BufferUtils.createByteBuffer(262144);
public List textureList = new ArrayList(); public List textureList = new ArrayList();
public final int getTextureId(String var1) { public final int getTextureId(String var1) {
try { Integer integer = (Integer) textureMap.get(var1);
if(this.idMap.containsKey(var1)) { if (integer != null) {
return ((Integer)this.idMap.get(var1)).intValue(); return integer.intValue();
} else {
int var2 = this.addTexture(ImageIO.read(Textures.class.getResourceAsStream(var1)));
this.idMap.put(var1, Integer.valueOf(var2));
return var2;
} }
} catch (IOException var3) { try {
singleIntBuffer.clear();
GLAllocation.generateTextureNames(singleIntBuffer);
int i = singleIntBuffer.get(0);
addTexture(readTextureImage(LWJGLMain.loadResourceBytes(var1)), i);
textureMap.put(var1, Integer.valueOf(i));
return i;
} catch (IOException ioexception) {
throw new RuntimeException("!!"); throw new RuntimeException("!!");
} }
} }
public final int addTexture(BufferedImage var1) { public final void addTexture(MinecraftImageData bufferedimage, int i) {
this.idBuffer.clear(); // if(alpha) {
GL11.glGenTextures(); // GL11.glAlphaFunc(516, 0.1F);
int var2 = this.idBuffer.get(0); // }
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var2); bindTexture(i);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9728 /* GL_NEAREST */);
int var3 = var1.getWidth(); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10242 /* GL_TEXTURE_WRAP_S */, 10497 /* GL_REPEAT */);
int var4 = var1.getHeight(); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10243 /* GL_TEXTURE_WRAP_T */, 10497 /* GL_REPEAT */);
int[] var5 = new int[var3 * var4]; int j = bufferedimage.w;
byte[] var6 = new byte[var3 * var4 << 2]; int k = bufferedimage.h;
var1.getRGB(0, 0, var3, var4, var5, 0, var3); int ai[] = bufferedimage.data;
byte abyte0[] = new byte[j * k * 4];
for(int var11 = 0; var11 < var5.length; ++var11) { for (int l = 0; l < ai.length; l++) {
int var7 = var5[var11] >>> 24; int j1 = ai[l] >> 24 & 0xff;
int var8 = var5[var11] >> 16 & 255; int l1 = ai[l] >> 16 & 0xff;
int var9 = var5[var11] >> 8 & 255; int j2 = ai[l] >> 8 & 0xff;
int var10 = var5[var11] & 255; int l2 = ai[l] >> 0 & 0xff;
var6[var11 << 2] = (byte)var8; abyte0[l * 4 + 0] = (byte) l1;
var6[(var11 << 2) + 1] = (byte)var9; abyte0[l * 4 + 1] = (byte) j2;
var6[(var11 << 2) + 2] = (byte)var10; abyte0[l * 4 + 2] = (byte) l2;
var6[(var11 << 2) + 3] = (byte)var7; abyte0[l * 4 + 3] = (byte) j1;
}
textureBuffer.clear();
textureBuffer.put(abyte0);
textureBuffer.position(0).limit(abyte0.length);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, GL11.GL_RGBA /* GL_RGBA */, j, k, 0, GL11.GL_RGBA /* GL_RGBA */, 5121 /* GL_UNSIGNED_BYTE */, textureBuffer);
} }
this.textureBuffer.clear(); public void bindTexture(int i) {
this.textureBuffer.put(var6); if (i < 0) {
this.textureBuffer.position(0).limit(var6.length); return;
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, var3, var4, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.textureBuffer); } else {
return var2; GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, i);
return;
}
}
private MinecraftImageData readTextureImage(byte[] inputstream) throws IOException {
return LWJGLMain.loadPNG(inputstream);
} }
public final void registerTextureFX(TextureFX var1) { public final void registerTextureFX(TextureFX var1) {