From 475ced969c4f7c2a20b5e913e33bf1b99a3f10d0 Mon Sep 17 00:00:00 2001 From: PeytonPlayz595 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Fri, 21 Jul 2023 23:00:53 -0400 Subject: [PATCH] Fix graphical bugs, water, music, and mob spawning --- .../java/com/mojang/minecraft/Entity.java | 9 +++++ .../com/mojang/minecraft/GameSettings.java | 16 +++++++-- .../java/com/mojang/minecraft/Minecraft.java | 20 +++++++---- .../minecraft/gamemode/SurvivalGameMode.java | 3 +- .../mojang/minecraft/gui/OptionsScreen.java | 2 +- .../com/mojang/minecraft/gui/PauseScreen.java | 5 +++ .../minecraft/level/tile/LiquidBlock.java | 2 +- .../mojang/minecraft/render/RenderEngine.java | 19 ++++------- .../net/PeytonPlayz585/music/MusicThread.java | 34 +++++++++++++++++++ .../adapter/EaglerAdapterImpl2.java | 3 ++ 10 files changed, 90 insertions(+), 23 deletions(-) create mode 100644 src/teavm/java/net/PeytonPlayz585/music/MusicThread.java diff --git a/src/teavm/java/com/mojang/minecraft/Entity.java b/src/teavm/java/com/mojang/minecraft/Entity.java index d42c5ae..80674a0 100644 --- a/src/teavm/java/com/mojang/minecraft/Entity.java +++ b/src/teavm/java/com/mojang/minecraft/Entity.java @@ -52,6 +52,7 @@ public abstract class Entity implements Serializable { public boolean noPhysics = false; public float pushthrough = 0.0F; public boolean hovered = false; + private int aliveTime; public Entity(Level var1) { @@ -131,6 +132,14 @@ public abstract class Entity implements Serializable { } 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.xo = this.x; this.yo = this.y; diff --git a/src/teavm/java/com/mojang/minecraft/GameSettings.java b/src/teavm/java/com/mojang/minecraft/GameSettings.java index 9a501e3..908b543 100644 --- a/src/teavm/java/com/mojang/minecraft/GameSettings.java +++ b/src/teavm/java/com/mojang/minecraft/GameSettings.java @@ -13,7 +13,7 @@ public final class GameSettings { bindings = new KeyBinding[] {forwardKey, leftKey, backKey, rightKey, jumpKey, buildKey, chatKey, toggleFogKey, saveLocationKey, loadLocationKey}; - settingCount = 10; + settingCount = 11; this.minecraft = minecraft; @@ -33,6 +33,7 @@ public final class GameSettings public boolean limitFramerate = false; public boolean gamemode = false; public boolean fullscreen = false; + public boolean mobSpawns = false; public KeyBinding forwardKey = new KeyBinding("Forward", 17); public KeyBinding leftKey = new KeyBinding("Left", 30); public KeyBinding backKey = new KeyBinding("Back", 31); @@ -123,6 +124,11 @@ public final class GameSettings fullscreen = !fullscreen; GL11.setFullscreen(fullscreen); } + + if(setting == 10) { + mobSpawns = !mobSpawns; + minecraft.gamemode.spawnMob(); + } save(); } @@ -139,7 +145,8 @@ public final class GameSettings : (id == 7 ? "Limit framerate: " + (limitFramerate ? "ON" : "OFF") : (id == 8 ? "Game Mode: " + (gamemode ? "Creative" : "Survival") : (id == 9 ? "Fullscreen: " + (fullscreen ? "ON" : "OFF") - : ""))))))))); + : (id == 10 ? "Mob Spawning: " + (mobSpawns ? "ON" : "OFF") + : "")))))))))); } private void load() @@ -179,6 +186,10 @@ public final class GameSettings limitFramerate = settingsFile.getBoolean("limitFramerate"); } + if(settingsFile.hasKey("mobSpawns")) { + mobSpawns = settingsFile.getBoolean("mobSpawns"); + } + for(int i = 0; i < bindings.length; ++i) { String k = "key_" + bindings[i].name; 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("anaglyph3d", anaglyph); settingsFile.setBoolean("limitFramerate", limitFramerate); + settingsFile.setBoolean("mobSpawns", mobSpawns); for(int i = 0; i < bindings.length; ++i) { String k = "key_" + bindings[i].name; diff --git a/src/teavm/java/com/mojang/minecraft/Minecraft.java b/src/teavm/java/com/mojang/minecraft/Minecraft.java index eebb5f7..fa9106a 100644 --- a/src/teavm/java/com/mojang/minecraft/Minecraft.java +++ b/src/teavm/java/com/mojang/minecraft/Minecraft.java @@ -25,7 +25,7 @@ import com.mojang.minecraft.player.Player; import com.mojang.minecraft.render.*; import com.mojang.minecraft.render.Renderer; import net.PeytonPlayz585.math.MathHelper; - +import net.PeytonPlayz585.music.MusicThread; import net.lax1dude.eaglercraft.GLAllocation; import net.lax1dude.eaglercraft.adapter.Tessellator; @@ -38,6 +38,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Random; import java.util.Map.Entry; public final class Minecraft implements Runnable { @@ -984,10 +985,17 @@ public final class Minecraft implements Runnable { } } - private void tick() { -// if(!settings.gamemode) { -// this.gamemode.spawnMob(); -// } + public static boolean hasBeenInitialized = false; + + public void tick() { + if(!settings.gamemode && settings.mobSpawns) { + this.gamemode.spawnMob(); + } + + if(hasBeenInitialized) { + MusicThread.musicTick(); + } + HUDScreen var17 = this.hud; ++this.hud.ticks; @@ -1092,7 +1100,7 @@ public final class Minecraft implements Runnable { } GL11.getEventKey(); - if(GL11.getEventKey() == 63) { + if(GL11.getEventKey() == 28) { this.raining = !this.raining; } diff --git a/src/teavm/java/com/mojang/minecraft/gamemode/SurvivalGameMode.java b/src/teavm/java/com/mojang/minecraft/gamemode/SurvivalGameMode.java index 047a059..3f40dd9 100644 --- a/src/teavm/java/com/mojang/minecraft/gamemode/SurvivalGameMode.java +++ b/src/teavm/java/com/mojang/minecraft/gamemode/SurvivalGameMode.java @@ -1,5 +1,7 @@ package com.mojang.minecraft.gamemode; +import java.util.Random; + import com.mojang.minecraft.Minecraft; import com.mojang.minecraft.level.Level; import com.mojang.minecraft.level.MobSpawner; @@ -152,7 +154,6 @@ public final class SurvivalGameMode extends GameMode { spawner.spawn(area, spawner.level.player, null); } - } @Override diff --git a/src/teavm/java/com/mojang/minecraft/gui/OptionsScreen.java b/src/teavm/java/com/mojang/minecraft/gui/OptionsScreen.java index 99cd877..bb115ff 100644 --- a/src/teavm/java/com/mojang/minecraft/gui/OptionsScreen.java +++ b/src/teavm/java/com/mojang/minecraft/gui/OptionsScreen.java @@ -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 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")); } diff --git a/src/teavm/java/com/mojang/minecraft/gui/PauseScreen.java b/src/teavm/java/com/mojang/minecraft/gui/PauseScreen.java index 2a7f0e9..c42da0a 100644 --- a/src/teavm/java/com/mojang/minecraft/gui/PauseScreen.java +++ b/src/teavm/java/com/mojang/minecraft/gui/PauseScreen.java @@ -7,6 +7,8 @@ import com.mojang.minecraft.gui.GenerateLevelScreen; import com.mojang.minecraft.gui.GuiScreen; import com.mojang.minecraft.gui.OptionsScreen; +import net.PeytonPlayz585.music.MusicThread; + public final class PauseScreen extends GuiScreen { public final void onOpen() { @@ -40,6 +42,9 @@ public final class PauseScreen extends GuiScreen { } if(var1.id == 4) { + if(!minecraft.hasBeenInitialized) { + minecraft.hasBeenInitialized = true; + } this.minecraft.setCurrentScreen((GuiScreen)null); this.minecraft.grabMouse(); } diff --git a/src/teavm/java/com/mojang/minecraft/level/tile/LiquidBlock.java b/src/teavm/java/com/mojang/minecraft/level/tile/LiquidBlock.java index 36b2f33..a6b00f1 100644 --- a/src/teavm/java/com/mojang/minecraft/level/tile/LiquidBlock.java +++ b/src/teavm/java/com/mojang/minecraft/level/tile/LiquidBlock.java @@ -156,7 +156,7 @@ public class LiquidBlock extends Block { } public final int getRenderPass() { - return this.type == LiquidType.WATER?1:0; + return 0; } @Override diff --git a/src/teavm/java/com/mojang/minecraft/render/RenderEngine.java b/src/teavm/java/com/mojang/minecraft/render/RenderEngine.java index d396443..5036762 100644 --- a/src/teavm/java/com/mojang/minecraft/render/RenderEngine.java +++ b/src/teavm/java/com/mojang/minecraft/render/RenderEngine.java @@ -16,11 +16,9 @@ import net.lax1dude.eaglercraft.GLAllocation; public class RenderEngine { public RenderEngine() { -// textureNameToImageMap = new HashMap(); singleIntBuffer = GLAllocation.createDirectIntBuffer(1); imageDataB1 = GLAllocation.createDirectByteBuffer(0x100000); -// imageDataB2 = GLAllocation.createDirectByteBuffer(0x100000); - textureBlending = false; + alpha = false; options = Minecraft.settings; } @@ -34,10 +32,10 @@ public class RenderEngine { GLAllocation.generateTextureNames(singleIntBuffer); int i = singleIntBuffer.get(0); if(s.equals("/terrain.png") || s.contains("arrow") || s.contains("default")) { - textureBlending = true; + alpha = true; } setupTexture(readTextureImage(GL11.loadResourceBytes(s)), i); - textureBlending = false; + alpha = false; textureMap.put(s, Integer.valueOf(i)); return i; } catch (IOException ioexception) { @@ -46,11 +44,8 @@ public class RenderEngine { } public void setupTexture(EaglerImage bufferedimage, int i) { - if(textureBlending) { - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - //GL11.glDepthMask(false); - GL11.glAlphaFunc(GL11._wGL_LESS, 1.0F); + if(alpha) { + GL11.glAlphaFunc(516, 0.1F); } bindTexture(i); GL11.glTexParameteri(3553 /* GL_TEXTURE_2D */, 10241 /* GL_TEXTURE_MIN_FILTER */, 9728 /* GL_NEAREST */); @@ -82,7 +77,7 @@ public class RenderEngine { imageDataB1.clear(); imageDataB1.put(abyte0); 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); } @@ -107,5 +102,5 @@ public class RenderEngine { private IntBuffer singleIntBuffer; private ByteBuffer imageDataB1; private GameSettings options; - private boolean textureBlending; + private boolean alpha; } \ No newline at end of file diff --git a/src/teavm/java/net/PeytonPlayz585/music/MusicThread.java b/src/teavm/java/net/PeytonPlayz585/music/MusicThread.java new file mode 100644 index 0000000..cddad92 --- /dev/null +++ b/src/teavm/java/net/PeytonPlayz585/music/MusicThread.java @@ -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; + } + } +} diff --git a/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java b/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java index 21b8090..1204a1d 100644 --- a/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java +++ b/src/teavm/java/net/lax1dude/eaglercraft/adapter/EaglerAdapterImpl2.java @@ -336,6 +336,8 @@ public class EaglerAdapterImpl2 { e.printStackTrace(); } + audioctx = AudioContext.create(); + mouseEvents.clear(); keyEvents.clear(); } @@ -1464,6 +1466,7 @@ public class EaglerAdapterImpl2 { } return ret.buffer; } + public static final int beginPlayback(String fileName, float x, float y, float z, float volume, float pitch) { AudioBuffer b = getBufferFor(fileName); if(b == null) return -1;