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) {
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>() {

View File

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

View File

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

View File

@ -1,5 +1,8 @@
package net.minecraft.src;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
@ -91,7 +94,7 @@ public class Minecraft implements Runnable {
this.playerController.init();
}
private void loadScreen() throws LWJGLException {
private void loadScreen() {
ScaledResolution var1 = new ScaledResolution(this.displayWidth, this.displayHeight);
int var2 = var1.getScaledWidth();
int var3 = var1.getScaledHeight();
@ -779,4 +782,32 @@ 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);
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);
clampTexture = false;
} else {
//if(s.equals("/terrain.png")) {
//useMipmaps = true;
//}
useMipmaps = true;
setupTexture(readTextureImage(LWJGLMain.loadResourceBytes(s)), i);
useMipmaps = false;
}
@ -99,7 +97,7 @@ public class RenderEngine {
}
int j = bufferedimage.w;
int k = bufferedimage.h;
int ai[] = bufferedimage.data;
int ai[] = bufferedimage.data();
byte abyte0[] = new byte[j * k * 4];
for (int l = 0; l < ai.length; l++) {
int j1 = ai[l] >> 24 & 0xff;
@ -177,10 +175,13 @@ public class RenderEngine {
}
public void bindTexture(int i) {
Minecraft.getMinecraft().setLighting(true);
if (i < 0) {
Minecraft.getMinecraft().setLighting(false);
return;
} else {
GL11.glBindTexture(3553 /* GL_TEXTURE_2D */, i);
Minecraft.getMinecraft().setLighting(false);
return;
}
}

View File

@ -11,7 +11,7 @@ public class TerrainTextureManager {
field_1184_e = new int[5120];
field_1183_f = new int[34];
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++) {
int k = 0;
int l = 0;

View File

@ -26,7 +26,7 @@ public class Vec3D {
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) {
var1 = 0.0D;
}