Fix lighting, optimize performance

This commit is contained in:
PeytonPlayz595 2024-02-04 03:12:30 +00:00
parent f9fea9dfbf
commit 011edd8647
15 changed files with 4292 additions and 4239 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle
# Ignore Gradle build output directory
build

8394
js/app.js

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -923,7 +923,8 @@ public class LWJGLMain {
for(int i = 0; i < pixels.length; ++i) { for(int i = 0; i < pixels.length; ++i) {
pixels[i] = (pxls.get(i * 4) << 16) | (pxls.get(i * 4 + 1) << 8) | pxls.get(i * 4 + 2) | (pxls.get(i * 4 + 3) << 24); pixels[i] = (pxls.get(i * 4) << 16) | (pxls.get(i * 4 + 1) << 8) | pxls.get(i * 4 + 2) | (pxls.get(i * 4 + 3) << 24);
} }
ret.complete(new MinecraftImageData(pixels, pxlsDat.getWidth(), pxlsDat.getHeight(), true)); IntBuffer buffer = IntBuffer.wrap(pixels);
ret.complete(new MinecraftImageData(buffer, pxlsDat.getWidth(), pxlsDat.getHeight(), true));
} }
}); });
toLoad.addEventListener("error", new EventListener<Event>() { toLoad.addEventListener("error", new EventListener<Event>() {

View File

@ -1,40 +1,55 @@
package net.PeytonPlayz585.opengl; package net.PeytonPlayz585.opengl;
import java.nio.IntBuffer;
public class MinecraftImageData { public class MinecraftImageData {
public final int[] data; public final IntBuffer data;
public final int w; public final int w;
public final int h; public final int h;
public final boolean alpha; public final boolean alpha;
private final int wh;
public MinecraftImageData(int pw, int ph, boolean palpha) { public MinecraftImageData(int pw, int ph, boolean palpha) {
this.w = pw; this.w = pw;
this.h = ph; this.h = ph;
this.alpha = palpha; this.alpha = palpha;
this.data = new int[pw * ph]; this.data = IntBuffer.allocate(pw * ph);
} this.wh = pw * ph;
}
public MinecraftImageData(int[] pdata, int pw, int ph, boolean palpha) { public MinecraftImageData(IntBuffer pdata, int pw, int ph, boolean palpha) {
if (pdata.length != pw * ph) { if (pdata.capacity() != pw * ph) {
throw new IllegalArgumentException("array size does not equal image size"); throw new IllegalArgumentException("buffer capacity does not equal image size");
} }
this.w = pw; w = pw;
this.h = ph; h = ph;
this.alpha = palpha; alpha = palpha;
if (!palpha) { wh = pw * ph;
for (int i = 0; i < pdata.length; ++i) { if (!alpha) {
pdata[i] = pdata[i] | 0xFF000000; for (int i = 0; i < wh; ++i) {
} pdata.put(i, pdata.get(i) | 0xFF000000);
} }
this.data = pdata; pdata.rewind();
} }
data = pdata;
}
public MinecraftImageData getSubImage(int x, int y, int pw, int ph) { public MinecraftImageData getSubImage(int x, int y, int pw, int ph) {
int[] img = new int[pw * ph]; int start = y * w + x;
for (int i = 0; i < ph; ++i) { IntBuffer subBuffer = data.slice();
System.arraycopy(data, (i + y) * this.w + x, img, i * pw, pw); subBuffer.position(start);
} subBuffer.limit(start + pw * ph);
return new MinecraftImageData(img, pw, ph, alpha); int[] temp = new int[pw * ph];
} subBuffer.get(temp);
IntBuffer newBuffer = IntBuffer.wrap(temp);
return new MinecraftImageData(newBuffer, pw, ph, alpha);
}
public int[] data() {
int[] array = new int[wh];
data.rewind();
data.get(array);
return array;
}
} }

View File

@ -18,7 +18,7 @@ public class FontRenderer {
MinecraftImageData bufferedimage = LWJGLMain.loadPNG(LWJGLMain.loadResourceBytes(s)); MinecraftImageData bufferedimage = LWJGLMain.loadPNG(LWJGLMain.loadResourceBytes(s));
int i = bufferedimage.w; int i = bufferedimage.w;
int j = bufferedimage.h; int j = bufferedimage.h;
int ai[] = bufferedimage.data; int ai[] = bufferedimage.data();
for (int k = 0; k < 256; k++) { for (int k = 0; k < 256; k++) {
int l = k % 16; int l = k % 16;
int k1 = k / 16; int k1 = k / 16;

View File

@ -10,7 +10,7 @@ public class GuiScreen extends Gui {
protected Minecraft mc; protected Minecraft mc;
public int width; public int width;
public int height; public int height;
protected List controlList<GuiButton> = new ArrayList<GuiButton>(); protected List<GuiButton> controlList = new ArrayList<GuiButton>();
public boolean allowUserInput = false; public boolean allowUserInput = false;
protected FontRenderer fontRenderer; protected FontRenderer fontRenderer;

View File

@ -1,5 +1,8 @@
package net.minecraft.src; package net.minecraft.src;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
@ -91,7 +94,7 @@ public class Minecraft implements Runnable {
this.playerController.init(); this.playerController.init();
} }
private void loadScreen() throws LWJGLException { private void loadScreen() {
ScaledResolution var1 = new ScaledResolution(this.displayWidth, this.displayHeight); ScaledResolution var1 = new ScaledResolution(this.displayWidth, this.displayHeight);
int var2 = var1.getScaledWidth(); int var2 = var1.getScaledWidth();
int var3 = var1.getScaledHeight(); int var3 = var1.getScaledHeight();
@ -779,4 +782,32 @@ public class Minecraft implements Runnable {
public static Minecraft getMinecraft() { public static Minecraft getMinecraft() {
return mc; 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);
GL11.glColorMaterial(1032, 5634);
float var4 = 0.7F;
float var2 = 0.3F;
Vec3D var3 = (new Vec3D(0.0F, -1.0F, 0.5F)).normalize();
GL11.glLight(16384, 4611, this.createBuffer((float)var3.xCoord, (float)var3.yCoord, (float)var3.zCoord, 0.0F));
GL11.glLight(16384, 4609, this.createBuffer(var2, var2, var2, 1.0F));
GL11.glLight(16384, 4608, this.createBuffer(0.0F, 0.0F, 0.0F, 1.0F));
GL11.glLightModel(2899, this.createBuffer(var4, var4, var4, 1.0F));
}
}
private FloatBuffer createBuffer(float var1, float var2, float var3, float var4) {
buffer.clear();
buffer.put(var1).put(var2).put(var3).put(var4);
buffer.flip();
return buffer;
}
private FloatBuffer buffer = GLAllocation.createFloatBuffer(16);
} }

View File

@ -39,9 +39,7 @@ public class RenderEngine {
setupTexture(readTextureImage(LWJGLMain.loadResourceBytes(s.substring(7))), i); setupTexture(readTextureImage(LWJGLMain.loadResourceBytes(s.substring(7))), i);
clampTexture = false; clampTexture = false;
} else { } else {
//if(s.equals("/terrain.png")) { useMipmaps = true;
//useMipmaps = true;
//}
setupTexture(readTextureImage(LWJGLMain.loadResourceBytes(s)), i); setupTexture(readTextureImage(LWJGLMain.loadResourceBytes(s)), i);
useMipmaps = false; useMipmaps = false;
} }
@ -99,7 +97,7 @@ public class RenderEngine {
} }
int j = bufferedimage.w; int j = bufferedimage.w;
int k = bufferedimage.h; int k = bufferedimage.h;
int ai[] = bufferedimage.data; int ai[] = bufferedimage.data();
byte abyte0[] = new byte[j * k * 4]; byte abyte0[] = new byte[j * k * 4];
for (int l = 0; l < ai.length; l++) { for (int l = 0; l < ai.length; l++) {
int j1 = ai[l] >> 24 & 0xff; int j1 = ai[l] >> 24 & 0xff;
@ -177,10 +175,13 @@ public class RenderEngine {
} }
public void bindTexture(int i) { public void bindTexture(int i) {
Minecraft.getMinecraft().setLighting(true);
if (i < 0) { if (i < 0) {
Minecraft.getMinecraft().setLighting(false);
return; return;
} else { } else {
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, i); GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, i);
Minecraft.getMinecraft().setLighting(false);
return; return;
} }
} }

View File

@ -11,7 +11,7 @@ public class TerrainTextureManager {
field_1184_e = new int[5120]; field_1184_e = new int[5120];
field_1183_f = new int[34]; field_1183_f = new int[34];
field_1182_g = new int[768]; field_1182_g = new int[768];
int ai[] = LWJGLMain.loadPNG(LWJGLMain.loadResourceBytes("/terrain.png")).data; int ai[] = LWJGLMain.loadPNG(LWJGLMain.loadResourceBytes("/terrain.png")).data();
for (int j = 0; j < 256; j++) { for (int j = 0; j < 256; j++) {
int k = 0; int k = 0;
int l = 0; int l = 0;

View File

@ -26,7 +26,7 @@ public class Vec3D {
return ((Vec3D)vectorList.get(nextVector++)).setComponents(var0, var2, var4); return ((Vec3D)vectorList.get(nextVector++)).setComponents(var0, var2, var4);
} }
private Vec3D(double var1, double var3, double var5) { public Vec3D(double var1, double var3, double var5) {
if(var1 == -0.0D) { if(var1 == -0.0D) {
var1 = 0.0D; var1 = 0.0D;
} }