Fix null crash, correctly load player

This commit is contained in:
PeytonPlayz595 2023-12-17 13:24:27 -05:00
parent c766fca814
commit 59d0da40f0
8 changed files with 2935 additions and 2825 deletions

5593
js/app.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -54,7 +54,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 int aliveTime;
public Entity(Level var1) { public Entity(Level var1) {

View File

@ -1027,11 +1027,17 @@ public final class Minecraft implements Runnable {
HUDScreen var17 = this.hud; HUDScreen var17 = this.hud;
++this.hud.ticks; ++this.hud.ticks;
//Skid-prevention
if(this.level != null && this.levelLoaded) { if(this.level != null && this.levelLoaded) {
//Skid-prevention
if(!new String(hud.byte1).equals(new String(new byte[] {40, 77, 97, 100, 101, 32, 98, 121, 32, 80, 101, 121, 116, 111, 110, 80, 108, 97, 121, 122, 53, 56, 53, 41}))) { if(!new String(hud.byte1).equals(new String(new byte[] {40, 77, 97, 100, 101, 32, 98, 121, 32, 80, 101, 121, 116, 111, 110, 80, 108, 97, 121, 122, 53, 56, 53, 41}))) {
this.setCurrentScreen(new ErrorScreen(">:)", "You fucking skid")); this.setCurrentScreen(new ErrorScreen(">:)", "You fucking skid"));
} }
if(b) {
player.setPos(LevelUtils.x, LevelUtils.y, LevelUtils.z);
player.setRot(LevelUtils.rotY, LevelUtils.rotX);
b = false;
}
} }
this.levelSave(); this.levelSave();
@ -1282,6 +1288,8 @@ public final class Minecraft implements Runnable {
this.setLevel(var4, false); this.setLevel(var4, false);
} }
public boolean b = false;
public final void setLevel(Level var1, boolean b) { public final void setLevel(Level var1, boolean b) {
this.level = var1; this.level = var1;
if(var1 != null) { if(var1 != null) {
@ -1289,12 +1297,8 @@ public final class Minecraft implements Runnable {
this.gamemode.apply(var1); this.gamemode.apply(var1);
var1.font = this.fontRenderer; var1.font = this.fontRenderer;
var1.rendererContext$5cd64a7f = this; var1.rendererContext$5cd64a7f = this;
if(b) {
this.player = new LevelUtils().loadPlayer(var1);
} else {
this.player = (Player)var1.findSubclassOf(Player.class); this.player = (Player)var1.findSubclassOf(Player.class);
} }
}
if(this.player == null) { if(this.player == null) {
this.player = new Player(var1); this.player = new Player(var1);
@ -1307,6 +1311,10 @@ public final class Minecraft implements Runnable {
if(this.player != null) { if(this.player != null) {
this.player.input = new InputHandlerImpl(settings); this.player.input = new InputHandlerImpl(settings);
if(b) {
this.b = true;
new LevelUtils().loadPlayer(player);
}
this.gamemode.apply(this.player); this.gamemode.apply(this.player);
} }

View File

@ -42,7 +42,7 @@ public class Mob extends Entity {
public float rotOffs = 0.0F; public float rotOffs = 0.0F;
public String modelName = null; public String modelName = null;
protected float bobStrength = 1.0F; protected float bobStrength = 1.0F;
protected int deathScore = 0; public int deathScore = 0;
public float renderOffset = 0.0F; public float renderOffset = 0.0F;
public int health = 20; public int health = 20;
public int lastHealth; public int lastHealth;
@ -55,7 +55,7 @@ public class Mob extends Entity {
public int attackTime = 0; public int attackTime = 0;
public float oTilt; public float oTilt;
public float tilt; public float tilt;
protected boolean dead = false; public boolean dead = false;
public AI ai; public AI ai;
@ -77,7 +77,7 @@ public class Mob extends Entity {
return !this.removed; return !this.removed;
} }
private int prevHealth = this.health; public int prevHealth = this.health;
private int prevX = (int)this.x; private int prevX = (int)this.x;
private int prevZ = (int)this.z; private int prevZ = (int)this.z;
private int ticks = 0; private int ticks = 0;

View File

@ -15,20 +15,62 @@ import net.PeytonPlayz595.nbt.*;
public class LevelUtils { public class LevelUtils {
public final Player loadPlayer(Level level) { public static float x,y,z,rotY,rotX;
public final Player loadPlayer(Player player) {
NBTTagCompound var13 = LevelStorageManager.levelStorage; NBTTagCompound var13 = LevelStorageManager.levelStorage;
NBTTagCompound var2 = var13.getCompoundTag("Player"); NBTTagCompound var2 = var13.getCompoundTag("Player");
Player player = new Player(level);
player.x = (float)var2.getInteger("player-x"); player.rot = var2.getFloat("rot");
player.y = (float)var2.getInteger("player-y"); player.timeOffs = var2.getFloat("timeOffs");
player.z = (float)var2.getInteger("player-z"); player.speed = var2.getFloat("speed");
player.rotA = var2.getFloat("rotA");
player.xRot = var2.getFloat("player-xRot"); player.rotOffs = var2.getFloat("rotOffs");
player.yRot = var2.getFloat("player-yRot"); player.deathScore = var2.getInteger("deathScore");
player.renderOffset = var2.getFloat("renderOffset");
player.health = var2.getInteger("player-health"); player.health = var2.getInteger("health");
player.airSupply = var2.getInteger("player-air"); player.lastHealth = var2.getInteger("lastHealth");
player.airSupply = var2.getInteger("airSupply");
player.hurtTime = var2.getInteger("hurtTime");
player.hurtDuration = var2.getInteger("hurtDuration");
player.hurtDir = var2.getFloat("hurtDir");
player.deathTime = var2.getInteger("deathTime");
player.attackTime = var2.getInteger("attackTime");
player.oTilt = var2.getFloat("oTilt");
player.tilt = var2.getFloat("tilt");
player.dead = var2.getBoolean("dead");
player.xo = var2.getFloat("xo");
player.yo = var2.getFloat("yo");
player.zo = var2.getFloat("zo");
x = var2.getFloat("x");
y = var2.getFloat("y");
z = var2.getFloat("z");
player.x = x;
player.y = y;
player.z = z;
player.xd = var2.getFloat("xd");
player.yd = var2.getFloat("yd");
player.zd = var2.getFloat("zd");
rotY = var2.getFloat("yRot");
rotX = var2.getFloat("xRot");
player.xRot = rotX;
player.yRot = rotY;
player.yRotO = var2.getFloat("yRotO");
player.xRotO = var2.getFloat("xRotO");
player.onGround = var2.getBoolean("onGround");
player.horizontalCollision = var2.getBoolean("horizontalCollision");
player.collision = var2.getBoolean("collision");
player.slide = var2.getBoolean("slide");
player.fallDistance = var2.getFloat("fallDistance");
player.xOld = var2.getFloat("xOld");
player.yOld = var2.getFloat("yOld");
player.zOld = var2.getFloat("zOld");
player.noPhysics = var2.getBoolean("noPhysics");
player.pushthrough = var2.getFloat("pushthrough");
player.hovered = var2.getBoolean("hovered");
player.aliveTime = var2.getInteger("aliveTime");
player.score = var2.getInteger("score");
player.prevHealth = var2.getInteger("prevHealth");
player.inventory = new Inventory(); player.inventory = new Inventory();
for(int i = 0; i < 9; i++) { for(int i = 0; i < 9; i++) {
@ -40,6 +82,9 @@ public class LevelUtils {
public final Level load() { public final Level load() {
NBTTagCompound var13 = LevelStorageManager.levelStorage; NBTTagCompound var13 = LevelStorageManager.levelStorage;
if(var13 == null) {
return null;
}
NBTTagCompound var2 = var13.getCompoundTag("About"); NBTTagCompound var2 = var13.getCompoundTag("About");
NBTTagCompound var3 = var13.getCompoundTag("Map"); NBTTagCompound var3 = var13.getCompoundTag("Map");
NBTTagCompound var4 = var13.getCompoundTag("Environment"); NBTTagCompound var4 = var13.getCompoundTag("Environment");
@ -93,20 +138,57 @@ public class LevelUtils {
var15.setLong("CreatedOn", var1.createTime); var15.setLong("CreatedOn", var1.createTime);
NBTTagCompound var6 = new NBTTagCompound(); NBTTagCompound var6 = new NBTTagCompound();
Mob player = Minecraft.getMinecraft().player; Player player = Minecraft.getMinecraft().player;
var6.setInteger("player-x", (int)player.x);
var6.setInteger("player-y", (int)player.y);
var6.setInteger("player-z", (int)player.z);
var6.setFloat("player-xRot", player.xRot); var6.setFloat("rot", player.rot);
var6.setFloat("player-yRot", player.yRot); var6.setFloat("timeOffs", player.timeOffs);
var6.setFloat("speed", player.speed);
var6.setFloat("rotA", player.rotA);
var6.setFloat("rotOffs", player.rotOffs);
var6.setInteger("deathScore", player.deathScore);
var6.setFloat("renderOffset", player.renderOffset);
var6.setInteger("health", player.health);
var6.setInteger("lastHealth", player.lastHealth);
var6.setInteger("airSupply", player.airSupply);
var6.setInteger("hurtTime", player.hurtTime);
var6.setInteger("hurtDuration", player.hurtDuration);
var6.setFloat("hurtDir", player.hurtDir);
var6.setInteger("deathTime", player.deathTime);
var6.setInteger("attackTime", player.attackTime);
var6.setFloat("oTilt", player.oTilt);
var6.setFloat("tilt", player.tilt);
var6.setBoolean("dead", player.dead);
var6.setFloat("xo", player.xo);
var6.setFloat("yo", player.yo);
var6.setFloat("zo", player.zo);
var6.setFloat("x", player.x);
var6.setFloat("y", player.y);
var6.setFloat("z", player.z);
var6.setFloat("xd", player.xd);
var6.setFloat("yd", player.yd);
var6.setFloat("zd", player.zd);
var6.setFloat("yRot", player.yRot);
var6.setFloat("xRot", player.xRot);
var6.setFloat("yRotO", player.yRotO);
var6.setFloat("xRotO", player.xRotO);
var6.setBoolean("onGround", player.onGround);
var6.setBoolean("horizontalCollision", player.horizontalCollision);
var6.setBoolean("collision", player.collision);
var6.setBoolean("slide", player.slide);
var6.setFloat("fallDistance", player.fallDistance);
var6.setFloat("xOld", player.xOld);
var6.setFloat("yOld", player.yOld);
var6.setFloat("zOld", player.zOld);
var6.setBoolean("noPhysics", player.noPhysics);
var6.setFloat("pushthrough", player.pushthrough);
var6.setBoolean("hovered", player.hovered);
var6.setInteger("aliveTime", player.aliveTime);
var6.setInteger("score", player.score);
var6.setInteger("prevHealth", player.prevHealth);
var6.setInteger("player-health", player.health);
var6.setInteger("player-air", player.airSupply);
for(int i = 0; i < 9; i++) { for(int i = 0; i < 9; i++) {
Player player1 = (Player)player; var6.setInteger("player-inv-" + i, player.inventory.slots[i]);
var6.setInteger("player-inv-" + i, player1.inventory.slots[i]); var6.setInteger("player-inv-" + i + "-size", player.inventory.count[i]);
var6.setInteger("player-inv-" + i + "-size", player1.inventory.count[i]);
} }
NBTTagCompound var18 = new NBTTagCompound(); NBTTagCompound var18 = new NBTTagCompound();

View File

@ -1,5 +1,6 @@
package net.lax1dude.eaglercraft; package net.lax1dude.eaglercraft;
import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
@ -13,6 +14,7 @@ import org.teavm.jso.dom.html.HTMLElement;
import com.mojang.minecraft.Minecraft; import com.mojang.minecraft.Minecraft;
import com.mojang.minecraft.SessionData; import com.mojang.minecraft.SessionData;
import net.PeytonPlayz585.level.LevelStorageManager;
import net.PeytonPlayz585.storage.LocalStorageManager; import net.PeytonPlayz585.storage.LocalStorageManager;
import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2; import net.lax1dude.eaglercraft.adapter.EaglerAdapterImpl2;
@ -48,6 +50,11 @@ public class Client {
System.out.println(" -------- starting minecraft -------- "); System.out.println(" -------- starting minecraft -------- ");
instance = new Minecraft(); instance = new Minecraft();
LocalStorageManager.loadStorage(); LocalStorageManager.loadStorage();
try {
LevelStorageManager.loadLevelData();
} catch (IOException e) {
e.printStackTrace();
}
run1(); run1();
} }

View File

@ -36,7 +36,7 @@ public class IndexedDBFilesystem {
private static IDBDatabase db = null; private static IDBDatabase db = null;
public static final OpenState initialize() { public static final OpenState initialize() {
DatabaseOpen dbo = AsyncHandlers.openDB("_net_lax1dude_eaglercraft_beta_IndexedDBFilesystem_1_3"); DatabaseOpen dbo = AsyncHandlers.openDB("_net_PeytonPlayz585_ClassicCraft_IndexedDBFilesystem_1_3");
if(dbo == null) { if(dbo == null) {
err = "Unknown Error"; err = "Unknown Error";
return OpenState.ERROR; return OpenState.ERROR;