Fix lighting and chunk loading

This commit is contained in:
PeytonPlayz595 2024-02-11 00:44:15 -05:00
parent 4c2def847a
commit 7ad874b27a
12 changed files with 2064 additions and 2264 deletions

View File

@ -284,6 +284,27 @@ public class Matrix4f extends Matrix implements Serializable {
buf[15] = m33;
return this;
}
public float[] get() {
float[] buf = new float[15];
buf[0] = m00;
buf[1] = m01;
buf[2] = m02;
buf[3] = m03;
buf[4] = m10;
buf[5] = m11;
buf[6] = m12;
buf[7] = m13;
buf[8] = m20;
buf[9] = m21;
buf[10] = m22;
buf[11] = m23;
buf[12] = m30;
buf[13] = m31;
buf[14] = m32;
buf[15] = m33;
return buf;
}
/**
* Store this matrix in a float buffer. The matrix is stored in row major

View File

@ -117,7 +117,6 @@ public class Minecraft implements Runnable {
this.checkGLError("Pre startup");
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glClearDepth(1.0F);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
@ -922,15 +921,4 @@ public class Minecraft implements Runnable {
public static Minecraft getMinecraft() {
return mc;
}
public final void setLighting(boolean var1) {
if(!var1) {
GL11.glDisable(2896);
GL11.glDisable(16384);
} else {
GL11.glEnable(2896);
GL11.glEnable(16384);
GL11.glEnable(2903);
}
}
}

View File

@ -13,13 +13,54 @@ public class ChunkLoader implements IChunkLoader {
this.saveDir = var1;
this.createIfNecessary = var2;
}
private String chunkFileForXZ(int var1, int var2) {
String var3 = "c." + Integer.toString(var1, 36) + "." + Integer.toString(var2, 36) + ".dat";
String var4 = Integer.toString(var1 & 63, 36);
String var5 = Integer.toString(var2 & 63, 36);
String var6 = this.saveDir + "/" + var4 + "/" + var3;
return var6;
String var6;
if(saveDir.endsWith("/")) {
var6 = saveDir + var4;
} else {
var6 = saveDir + "/" + var4;
}
byte[] data = GL11.readFile(var6);
if(data == null) {
if(!this.createIfNecessary) {
return null;
}
GL11.writeFile(var6, new byte[0]);
}
if(var6.endsWith("/")) {
var6 = var6 + var5;
} else {
var6 = var6 + "/" + var5;
}
data = null;
data = GL11.readFile(var6);
if(data == null) {
if(!this.createIfNecessary) {
return null;
}
GL11.writeFile(var6, new byte[0]);
}
if(var6.endsWith("/")) {
var6 = var6 + var3;
} else {
var6 = var6 + "/" + var3;
}
data = null;
data = GL11.readFile(var6);
return data == null && !this.createIfNecessary ? null : var6;
}
public Chunk loadChunk(World var1, int var2, int var3) throws IOException {

View File

@ -10,8 +10,8 @@ public class ColorizerFoliage {
field_6529_a = GL11.loadPNG(GL11.loadResourceBytes("/misc/foliagecolor.png")).data;
}
var2 *= var0;
int i = (int) ((1.0D - var0) * 255D);
int j = (int) ((1.0D - var2) * 255D);
return field_6529_a[j << 8 | i];
}
int var4 = (int)((1.0D - var0) * 255.0D);
int var5 = (int)((1.0D - var2) * 255.0D);
return field_6529_a[var5 << 8 | var4];
}
}

View File

@ -38,7 +38,6 @@ public class Gui {
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glShadeModel(GL11.GL_SMOOTH);
Tessellator var15 = Tessellator.instance;
var15.startDrawingQuads();
var15.setColorRGBA_F(var8, var9, var10, var7);
@ -48,7 +47,6 @@ public class Gui {
var15.addVertex((double)var1, (double)var4, 0.0D);
var15.addVertex((double)var3, (double)var4, 0.0D);
var15.draw();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_TEXTURE_2D);

View File

@ -45,11 +45,7 @@ public class RenderEngine {
setupTexture(readTextureImage(GL11.loadResourceBytes(s1[1])), i);
blurTexture = false;
} else {
if(s.contains("terrain")) {
useMipmaps = true;
}
setupTexture(readTextureImage(GL11.loadResourceBytes(s)), i);
useMipmaps = false;
}
textureMap.put(s, Integer.valueOf(i));
return i;
@ -84,14 +80,8 @@ public class RenderEngine {
public void setupTexture(EaglerImage bufferedimage, int i) {
bindTexture(i);
if (useMipmaps) {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, GL11.GL_NEAREST_MIPMAP_LINEAR);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, GL11.GL_NEAREST /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, GL11.GL_TEXTURE_MAX_LEVEL, 4);
} else {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9728 /* GL_NEAREST */);
}
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9728 /* GL_NEAREST */);
if (blurTexture) {
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9729 /* GL_LINEAR */);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10240 /* GL_TEXTURE_MAG_FILTER */, 9729 /* GL_LINEAR */);
@ -130,32 +120,6 @@ public class RenderEngine {
imageDataB1.position(0).limit(abyte0.length);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, 6408 /* GL_RGBA */, j, k, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB1);
if (useMipmaps) {
for (int i1 = 1; i1 <= 4; i1++) {
int k1 = j >> i1 - 1;
int i2 = j >> i1;
int k2 = k >> i1;
imageDataB2.clear();
for (int i3 = 0; i3 < i2; i3++) {
for (int k3 = 0; k3 < k2; k3++) {
int i4 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 0) * k1) * 4);
int k4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 0) * k1) * 4);
int l4 = imageDataB1.getInt((i3 * 2 + 1 + (k3 * 2 + 1) * k1) * 4);
int i5 = imageDataB1.getInt((i3 * 2 + 0 + (k3 * 2 + 1) * k1) * 4);
int j5 = averageColor(averageColor(i4, k4), averageColor(l4, i5));
imageDataB2.putInt((i3 + k3 * i2) * 4, j5);
}
}
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, i1, 6408 /* GL_RGBA */, i2, k2, 0, 6408 /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB2);
ByteBuffer tmp = imageDataB1;
imageDataB1 = imageDataB2;
imageDataB2 = tmp;
}
}
}
public void deleteTexture(int i) {
@ -167,24 +131,14 @@ public class RenderEngine {
texturefx.func_783_a();
}
private int averageColor(int i, int j) {
int k = (i & 0xff000000) >> 24 & 0xff;
int l = (j & 0xff000000) >> 24 & 0xff;
return ((k + l >> 1) << 24) + ((i & 0xfefefe) + (j & 0xfefefe) >> 1);
}
private EaglerImage readTextureImage(byte[] inputstream) throws IOException {
return GL11.loadPNG(inputstream);
}
public void bindTexture(int i) {
Minecraft.getMinecraft().setLighting(true);
if (i < 0) {
Minecraft.getMinecraft().setLighting(false);
return;
} else {
Minecraft.getMinecraft().setLighting(false);
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, i);
return;
}
@ -199,14 +153,6 @@ public class RenderEngine {
TextureFX var2;
int var3;
int var4;
int var5;
int var6;
int var7;
int var8;
int var9;
int var10;
int var11;
int var12;
for(var1 = 0; var1 < this.textureList.size(); ++var1) {
var2 = (TextureFX)this.textureList.get(var1);
var2.field_1131_c = this.options.anaglyph;
@ -220,28 +166,6 @@ public class RenderEngine {
for(var3 = 0; var3 < var2.field_1129_e; ++var3) {
for(var4 = 0; var4 < var2.field_1129_e; ++var4) {
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, var2.field_1126_b % 16 * 16 + var3 * 16, var2.field_1126_b / 16 * 16 + var4 * 16, 16, 16, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageDataB1);
if(useMipmaps) {
for(var5 = 1; var5 <= 4; ++var5) {
var6 = 16 >> var5 - 1;
var7 = 16 >> var5;
for(var8 = 0; var8 < var7; ++var8) {
for(var9 = 0; var9 < var7; ++var9) {
var10 = this.imageDataB1.getInt((var8 * 2 + 0 + (var9 * 2 + 0) * var6) * 4);
var11 = this.imageDataB1.getInt((var8 * 2 + 1 + (var9 * 2 + 0) * var6) * 4);
var12 = this.imageDataB1.getInt((var8 * 2 + 1 + (var9 * 2 + 1) * var6) * 4);
int var13 = this.imageDataB1.getInt((var8 * 2 + 0 + (var9 * 2 + 1) * var6) * 4);
int var14 = this.averageColor(this.averageColor(var10, var11), this.averageColor(var12, var13));
this.imageDataB2.putInt((var8 + var9 * var7) * 4, var14);
}
}
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, var5, var2.field_1126_b % 16 * var7, var2.field_1126_b / 16 * var7, var7, var7, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, this.imageDataB2);
ByteBuffer tmp = imageDataB1;
imageDataB1 = imageDataB2;
imageDataB2 = tmp;
}
}
}
}
}
@ -255,34 +179,11 @@ public class RenderEngine {
imageDataB2.clear();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, var2.field_1130_d);
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, 16, 16, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageDataB1);
if(useMipmaps) {
for(var3 = 1; var3 <= 4; ++var3) {
var4 = 16 >> var3 - 1;
var5 = 16 >> var3;
for(var6 = 0; var6 < var5; ++var6) {
for(var7 = 0; var7 < var5; ++var7) {
var8 = this.imageDataB1.getInt((var6 * 2 + 0 + (var7 * 2 + 0) * var4) * 4);
var9 = this.imageDataB1.getInt((var6 * 2 + 1 + (var7 * 2 + 0) * var4) * 4);
var10 = this.imageDataB1.getInt((var6 * 2 + 1 + (var7 * 2 + 1) * var4) * 4);
var11 = this.imageDataB1.getInt((var6 * 2 + 0 + (var7 * 2 + 1) * var4) * 4);
var12 = this.averageColor(this.averageColor(var8, var9), this.averageColor(var10, var11));
this.imageDataB2.putInt((var6 + var7 * var5) * 4, var12);
}
}
GL11.glTexSubImage2D(GL11.GL_TEXTURE_2D, var3, 0, 0, var5, var5, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer)this.imageDataB2);
ByteBuffer tmp = imageDataB1;
imageDataB1 = imageDataB2;
imageDataB2 = tmp;
}
}
}
}
}
public static boolean useMipmaps = false;
private static HashMap<String, Integer> textureMap;
private HashMap<Integer, EaglerImage> textureNameToImageMap;
private IntBuffer singleIntBuffer;

View File

@ -477,7 +477,6 @@ public class RenderGlobal implements IWorldAccess {
float var11;
if(var15 != null) {
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glPushMatrix();
GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
var8 = this.worldObj.getCelestialAngle(var1);
@ -497,7 +496,6 @@ public class RenderGlobal implements IWorldAccess {
var14.draw();
GL11.glPopMatrix();
GL11.glShadeModel(GL11.GL_FLAT);
}
GL11.glEnable(GL11.GL_TEXTURE_2D);

View File

@ -1,49 +1,20 @@
package net.minecraft.src;
import java.nio.FloatBuffer;
import org.lwjgl.opengl.GL11;
public class RenderHelper {
private static FloatBuffer field_1695_a = GLAllocation.createDirectFloatBuffer(16);
public static void disableStandardItemLighting() {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_LIGHT0);
GL11.glDisable(GL11.GL_LIGHT1);
GL11.glDisable(GL11.GL_COLOR_MATERIAL);
GL11.glDisable(2896);
GL11.glDisable(16384);
}
public static void enableStandardItemLighting() {
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glEnable(GL11.GL_LIGHT1);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
float var0 = 0.4F;
float var1 = 0.6F;
float var2 = 0.0F;
Vec3D var3 = Vec3D.createVector((double)0.2F, 1.0D, (double)-0.7F).normalize();
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, func_1157_a(var3.xCoord, var3.yCoord, var3.zCoord, 0.0D));
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, func_1156_a(var1, var1, var1, 1.0F));
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, func_1156_a(0.0F, 0.0F, 0.0F, 1.0F));
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, func_1156_a(var2, var2, var2, 1.0F));
var3 = Vec3D.createVector((double)-0.2F, 1.0D, (double)0.7F).normalize();
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION, func_1157_a(var3.xCoord, var3.yCoord, var3.zCoord, 0.0D));
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, func_1156_a(var1, var1, var1, 1.0F));
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, func_1156_a(0.0F, 0.0F, 0.0F, 1.0F));
GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR, func_1156_a(var2, var2, var2, 1.0F));
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glLightModel(GL11.GL_LIGHT_MODEL_AMBIENT, func_1156_a(var0, var0, var0, 1.0F));
GL11.glEnable(2896);
GL11.glEnable(16384);
GL11.glEnable(2903);
GL11.glColorMaterial(1032, 5634);
GL11.copyModelToLightMatrix();
GL11.flipLightMatrix();
}
private static FloatBuffer func_1157_a(double var0, double var2, double var4, double var6) {
return func_1156_a((float)var0, (float)var2, (float)var4, (float)var6);
}
private static FloatBuffer func_1156_a(float var0, float var1, float var2, float var3) {
field_1695_a.clear();
field_1695_a.put(var0).put(var1).put(var2).put(var3);
field_1695_a.flip();
return field_1695_a;
}
}
}

View File

@ -15,6 +15,7 @@ public class Tessellator {
private int color;
private boolean hasColor = false;
private boolean hasTexture = false;
private boolean hasNormals = false;
private int rawBufferIndex = 0;
private int addedVertices = 0;
private boolean isColorDisabled = false;
@ -24,6 +25,7 @@ public class Tessellator {
private double zOffset;
public static final Tessellator instance = new Tessellator(524288);
private boolean isDrawing = false;
private int normal;
private Tessellator(int par1) {
ArrayBuffer a = ArrayBuffer.create(par1 * 4);
@ -51,8 +53,16 @@ public class Tessellator {
GL11.glEnableVertexAttrib(GL11.GL_COLOR_ARRAY);
}
if (this.hasNormals) {
GL11.glEnableVertexAttrib(GL11.GL_NORMAL_ARRAY);
}
GL11.glDrawArrays(this.drawMode, 0, this.vertexCount, Int32Array.create(intBuffer.getBuffer(), 0, this.vertexCount * 7));
if (this.hasNormals) {
GL11.glDisableVertexAttrib(GL11.GL_NORMAL_ARRAY);
}
if (this.hasTexture) {
GL11.glDisableVertexAttrib(GL11.GL_TEXTURE_COORD_ARRAY);
}
@ -96,6 +106,7 @@ public class Tessellator {
this.isDrawing = true;
this.reset();
this.drawMode = par1;
this.hasNormals = false;
this.hasColor = false;
this.hasTexture = false;
this.isColorDisabled = false;
@ -209,6 +220,10 @@ public class Tessellator {
intBuffer0.set(bufferIndex + 5, this.color);
}
if (this.hasNormals) {
intBuffer0.set(bufferIndex + 6, this.normal);
}
this.rawBufferIndex += 7;
}
@ -245,7 +260,12 @@ public class Tessellator {
* Sets the normal for the current draw call.
*/
public void setNormal(float par1, float par2, float par3) {
GL11.glNormal3f(par1, par2, par3);
this.hasNormals = true;
float len = (float) Math.sqrt(par1 * par1 + par2 * par2 + par3 * par3);
int var4 = (int)((par1 / len) * 127.0F) + 127;
int var5 = (int)((par2 / len) * 127.0F) + 127;
int var6 = (int)((par3 / len) * 127.0F) + 127;
this.normal = var4 & 255 | (var5 & 255) << 8 | (var6 & 255) << 16;
}
/**

View File

@ -10,6 +10,9 @@ import net.PeytonPlayz585.glemu.FixedFunctionShader;
import net.PeytonPlayz585.glemu.GLObjectMap;
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
import net.minecraft.client.Minecraft;
import net.minecraft.src.GLAllocation;
import net.minecraft.src.Vec3D;
import net.PeytonPlayz585.glemu.vector.*;
public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
@ -245,10 +248,6 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
}
}
public static final void glShadeModel(int p1) {
}
public static final void glClearDepth(float p1) {
_wglClearDepth(-p1);
}
@ -422,19 +421,11 @@ public class EaglerAdapterGL30 extends EaglerAdapterImpl2 {
_wglTexImage2D(_wGL_TEXTURE_2D, p2, _wGL_RGBA8, p4, p5, p6, _wGL_RGBA, _wGL_UNSIGNED_BYTE, p9);
}
public static final void glLight(int p1, int p2, FloatBuffer p3) {
}
public static final void glLightModel(int p1, FloatBuffer p2) {
}
private static Vector4f lightPos0vec0 = new Vector4f();
private static Vector4f lightPos1vec0 = new Vector4f();
private static Vector4f lightPos0vec = new Vector4f();
private static Vector4f lightPos1vec = new Vector4f();
public static final void copyModelToLightMatrix() {
lightPos0vec0.set(lightPos0vec);
lightPos1vec0.set(lightPos1vec);

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long