Fix graphical bugs, water, music, and mob spawning

This commit is contained in:
PeytonPlayz595 2023-07-21 23:00:53 -04:00
parent 6711508638
commit 475ced969c
10 changed files with 90 additions and 23 deletions

View File

@ -52,6 +52,7 @@ public abstract class Entity implements Serializable {
public boolean noPhysics = false; public boolean noPhysics = false;
public float pushthrough = 0.0F; public float pushthrough = 0.0F;
public boolean hovered = false; public boolean hovered = false;
private int aliveTime;
public Entity(Level var1) { public Entity(Level var1) {
@ -131,6 +132,14 @@ public abstract class Entity implements Serializable {
} }
public void tick() { public void tick() {
if(!Minecraft.settings.mobSpawns) {
this.remove();
}
this.aliveTime++;
if(this.aliveTime >= 1200) {
this.aliveTime = 0;
this.remove();
}
this.walkDistO = this.walkDist; this.walkDistO = this.walkDist;
this.xo = this.x; this.xo = this.x;
this.yo = this.y; this.yo = this.y;

View File

@ -13,7 +13,7 @@ public final class GameSettings
{ {
bindings = new KeyBinding[] {forwardKey, leftKey, backKey, rightKey, jumpKey, buildKey, chatKey, toggleFogKey, saveLocationKey, loadLocationKey}; bindings = new KeyBinding[] {forwardKey, leftKey, backKey, rightKey, jumpKey, buildKey, chatKey, toggleFogKey, saveLocationKey, loadLocationKey};
settingCount = 10; settingCount = 11;
this.minecraft = minecraft; this.minecraft = minecraft;
@ -33,6 +33,7 @@ public final class GameSettings
public boolean limitFramerate = false; public boolean limitFramerate = false;
public boolean gamemode = false; public boolean gamemode = false;
public boolean fullscreen = false; public boolean fullscreen = false;
public boolean mobSpawns = false;
public KeyBinding forwardKey = new KeyBinding("Forward", 17); public KeyBinding forwardKey = new KeyBinding("Forward", 17);
public KeyBinding leftKey = new KeyBinding("Left", 30); public KeyBinding leftKey = new KeyBinding("Left", 30);
public KeyBinding backKey = new KeyBinding("Back", 31); public KeyBinding backKey = new KeyBinding("Back", 31);
@ -124,6 +125,11 @@ public final class GameSettings
GL11.setFullscreen(fullscreen); GL11.setFullscreen(fullscreen);
} }
if(setting == 10) {
mobSpawns = !mobSpawns;
minecraft.gamemode.spawnMob();
}
save(); save();
} }
@ -139,7 +145,8 @@ public final class GameSettings
: (id == 7 ? "Limit framerate: " + (limitFramerate ? "ON" : "OFF") : (id == 7 ? "Limit framerate: " + (limitFramerate ? "ON" : "OFF")
: (id == 8 ? "Game Mode: " + (gamemode ? "Creative" : "Survival") : (id == 8 ? "Game Mode: " + (gamemode ? "Creative" : "Survival")
: (id == 9 ? "Fullscreen: " + (fullscreen ? "ON" : "OFF") : (id == 9 ? "Fullscreen: " + (fullscreen ? "ON" : "OFF")
: ""))))))))); : (id == 10 ? "Mob Spawning: " + (mobSpawns ? "ON" : "OFF")
: ""))))))))));
} }
private void load() private void load()
@ -179,6 +186,10 @@ public final class GameSettings
limitFramerate = settingsFile.getBoolean("limitFramerate"); limitFramerate = settingsFile.getBoolean("limitFramerate");
} }
if(settingsFile.hasKey("mobSpawns")) {
mobSpawns = settingsFile.getBoolean("mobSpawns");
}
for(int i = 0; i < bindings.length; ++i) { for(int i = 0; i < bindings.length; ++i) {
String k = "key_" + bindings[i].name; String k = "key_" + bindings[i].name;
if(settingsFile.hasKey(k)) bindings[i].key = (int)settingsFile.getShort(k) & 0xFFFF; if(settingsFile.hasKey(k)) bindings[i].key = (int)settingsFile.getShort(k) & 0xFFFF;
@ -197,6 +208,7 @@ public final class GameSettings
settingsFile.setBoolean("bobView", viewBobbing); settingsFile.setBoolean("bobView", viewBobbing);
settingsFile.setBoolean("anaglyph3d", anaglyph); settingsFile.setBoolean("anaglyph3d", anaglyph);
settingsFile.setBoolean("limitFramerate", limitFramerate); settingsFile.setBoolean("limitFramerate", limitFramerate);
settingsFile.setBoolean("mobSpawns", mobSpawns);
for(int i = 0; i < bindings.length; ++i) { for(int i = 0; i < bindings.length; ++i) {
String k = "key_" + bindings[i].name; String k = "key_" + bindings[i].name;

View File

@ -25,7 +25,7 @@ import com.mojang.minecraft.player.Player;
import com.mojang.minecraft.render.*; import com.mojang.minecraft.render.*;
import com.mojang.minecraft.render.Renderer; import com.mojang.minecraft.render.Renderer;
import net.PeytonPlayz585.math.MathHelper; import net.PeytonPlayz585.math.MathHelper;
import net.PeytonPlayz585.music.MusicThread;
import net.lax1dude.eaglercraft.GLAllocation; import net.lax1dude.eaglercraft.GLAllocation;
import net.lax1dude.eaglercraft.adapter.Tessellator; import net.lax1dude.eaglercraft.adapter.Tessellator;
@ -38,6 +38,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random;
import java.util.Map.Entry; import java.util.Map.Entry;
public final class Minecraft implements Runnable { public final class Minecraft implements Runnable {
@ -984,10 +985,17 @@ public final class Minecraft implements Runnable {
} }
} }
private void tick() { public static boolean hasBeenInitialized = false;
// if(!settings.gamemode) {
// this.gamemode.spawnMob(); public void tick() {
// } if(!settings.gamemode && settings.mobSpawns) {
this.gamemode.spawnMob();
}
if(hasBeenInitialized) {
MusicThread.musicTick();
}
HUDScreen var17 = this.hud; HUDScreen var17 = this.hud;
++this.hud.ticks; ++this.hud.ticks;
@ -1092,7 +1100,7 @@ public final class Minecraft implements Runnable {
} }
GL11.getEventKey(); GL11.getEventKey();
if(GL11.getEventKey() == 63) { if(GL11.getEventKey() == 28) {
this.raining = !this.raining; this.raining = !this.raining;
} }

View File

@ -1,5 +1,7 @@
package com.mojang.minecraft.gamemode; package com.mojang.minecraft.gamemode;
import java.util.Random;
import com.mojang.minecraft.Minecraft; import com.mojang.minecraft.Minecraft;
import com.mojang.minecraft.level.Level; import com.mojang.minecraft.level.Level;
import com.mojang.minecraft.level.MobSpawner; import com.mojang.minecraft.level.MobSpawner;
@ -152,7 +154,6 @@ public final class SurvivalGameMode extends GameMode
{ {
spawner.spawn(area, spawner.level.player, null); spawner.spawn(area, spawner.level.player, null);
} }
} }
@Override @Override

View File

@ -23,7 +23,7 @@ public final class OptionsScreen extends GuiScreen {
this.buttons.add(new OptionButton(var1, this.width / 2 - 155 + var1 % 2 * 160, this.height / 6 + 24 * (var1 >> 1), this.settings.getSetting(var1))); this.buttons.add(new OptionButton(var1, this.width / 2 - 155 + var1 % 2 * 160, this.height / 6 + 24 * (var1 >> 1), this.settings.getSetting(var1)));
} }
this.buttons.add(new Button(100, this.width / 2 - 100, this.height / 6 + 120 + 12, "Controls...")); this.buttons.add(new Button(100, this.width / 2 - 100, this.height / 6 + 130 + 12, "Controls..."));
this.buttons.add(new Button(200, this.width / 2 - 100, this.height / 6 + 168, "Done")); this.buttons.add(new Button(200, this.width / 2 - 100, this.height / 6 + 168, "Done"));
} }

View File

@ -7,6 +7,8 @@ import com.mojang.minecraft.gui.GenerateLevelScreen;
import com.mojang.minecraft.gui.GuiScreen; import com.mojang.minecraft.gui.GuiScreen;
import com.mojang.minecraft.gui.OptionsScreen; import com.mojang.minecraft.gui.OptionsScreen;
import net.PeytonPlayz585.music.MusicThread;
public final class PauseScreen extends GuiScreen { public final class PauseScreen extends GuiScreen {
public final void onOpen() { public final void onOpen() {
@ -40,6 +42,9 @@ public final class PauseScreen extends GuiScreen {
} }
if(var1.id == 4) { if(var1.id == 4) {
if(!minecraft.hasBeenInitialized) {
minecraft.hasBeenInitialized = true;
}
this.minecraft.setCurrentScreen((GuiScreen)null); this.minecraft.setCurrentScreen((GuiScreen)null);
this.minecraft.grabMouse(); this.minecraft.grabMouse();
} }

View File

@ -156,7 +156,7 @@ public class LiquidBlock extends Block {
} }
public final int getRenderPass() { public final int getRenderPass() {
return this.type == LiquidType.WATER?1:0; return 0;
} }
@Override @Override

View File

@ -16,11 +16,9 @@ import net.lax1dude.eaglercraft.GLAllocation;
public class RenderEngine { public class RenderEngine {
public RenderEngine() { public RenderEngine() {
// textureNameToImageMap = new HashMap<Integer, EaglerImage>();
singleIntBuffer = GLAllocation.createDirectIntBuffer(1); singleIntBuffer = GLAllocation.createDirectIntBuffer(1);
imageDataB1 = GLAllocation.createDirectByteBuffer(0x100000); imageDataB1 = GLAllocation.createDirectByteBuffer(0x100000);
// imageDataB2 = GLAllocation.createDirectByteBuffer(0x100000); alpha = false;
textureBlending = false;
options = Minecraft.settings; options = Minecraft.settings;
} }
@ -34,10 +32,10 @@ public class RenderEngine {
GLAllocation.generateTextureNames(singleIntBuffer); GLAllocation.generateTextureNames(singleIntBuffer);
int i = singleIntBuffer.get(0); int i = singleIntBuffer.get(0);
if(s.equals("/terrain.png") || s.contains("arrow") || s.contains("default")) { if(s.equals("/terrain.png") || s.contains("arrow") || s.contains("default")) {
textureBlending = true; alpha = true;
} }
setupTexture(readTextureImage(GL11.loadResourceBytes(s)), i); setupTexture(readTextureImage(GL11.loadResourceBytes(s)), i);
textureBlending = false; alpha = false;
textureMap.put(s, Integer.valueOf(i)); textureMap.put(s, Integer.valueOf(i));
return i; return i;
} catch (IOException ioexception) { } catch (IOException ioexception) {
@ -46,11 +44,8 @@ public class RenderEngine {
} }
public void setupTexture(EaglerImage bufferedimage, int i) { public void setupTexture(EaglerImage bufferedimage, int i) {
if(textureBlending) { if(alpha) {
GL11.glEnable(GL11.GL_BLEND); GL11.glAlphaFunc(516, 0.1F);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//GL11.glDepthMask(false);
GL11.glAlphaFunc(GL11._wGL_LESS, 1.0F);
} }
bindTexture(i); bindTexture(i);
GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */);
@ -82,7 +77,7 @@ public class RenderEngine {
imageDataB1.clear(); imageDataB1.clear();
imageDataB1.put(abyte0); imageDataB1.put(abyte0);
imageDataB1.position(0).limit(abyte0.length); imageDataB1.position(0).limit(abyte0.length);
GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, GL11._wGL_RGBA8 /* GL_RGBA */, j, k, 0, GL11.GL_RGBA /* GL_RGBA */, GL11.glTexImage2D(3553 /* GL_TEXTURE_2D */, 0, GL11.GL_RGBA /* GL_RGBA */, j, k, 0, GL11.GL_RGBA /* GL_RGBA */,
5121 /* GL_UNSIGNED_BYTE */, imageDataB1); 5121 /* GL_UNSIGNED_BYTE */, imageDataB1);
} }
@ -107,5 +102,5 @@ public class RenderEngine {
private IntBuffer singleIntBuffer; private IntBuffer singleIntBuffer;
private ByteBuffer imageDataB1; private ByteBuffer imageDataB1;
private GameSettings options; private GameSettings options;
private boolean textureBlending; private boolean alpha;
} }

View File

@ -0,0 +1,34 @@
package net.PeytonPlayz585.music;
import java.util.Random;
import org.lwjgl.opengl.GL11;
public class MusicThread {
static int currentSong = 0;
static int lastSongPlayed = 0;
static boolean justfinishedPlayingSong = false;
public static void musicTick() {
if(!GL11.isPlaying(currentSong)) {
Random rand = new Random();
int randomNum = rand.nextInt((3 - 1) + 1) + 1;
if(randomNum == lastSongPlayed) {
randomNum = rand.nextInt((3 - 1) + 1) + 1;
}
lastSongPlayed = randomNum;
if(randomNum == 1) {
currentSong = GL11.beginPlayback("/music/calm1.mp3", 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
} else if(randomNum == 2) {
currentSong = GL11.beginPlayback("/music/calm2.mp3", 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
} else if(randomNum == 3) {
currentSong = GL11.beginPlayback("/music/calm3.mp3", 1.0f, 1.0f, 1.0f, 1.0f, 1.0f);
} else {
throw new IndexOutOfBoundsException("Tried to play a sound that does not exist! :(");
}
justfinishedPlayingSong = true;
}
}
}

View File

@ -336,6 +336,8 @@ public class EaglerAdapterImpl2 {
e.printStackTrace(); e.printStackTrace();
} }
audioctx = AudioContext.create();
mouseEvents.clear(); mouseEvents.clear();
keyEvents.clear(); keyEvents.clear();
} }
@ -1464,6 +1466,7 @@ public class EaglerAdapterImpl2 {
} }
return ret.buffer; return ret.buffer;
} }
public static final int beginPlayback(String fileName, float x, float y, float z, float volume, float pitch) { public static final int beginPlayback(String fileName, float x, float y, float z, float volume, float pitch) {
AudioBuffer b = getBufferFor(fileName); AudioBuffer b = getBufferFor(fileName);
if(b == null) return -1; if(b == null) return -1;