diff --git a/common/src/main/java/org/vivecraft/MixinConfig.java b/common/src/main/java/org/vivecraft/MixinConfig.java index 8b10441dd..f21ad9437 100644 --- a/common/src/main/java/org/vivecraft/MixinConfig.java +++ b/common/src/main/java/org/vivecraft/MixinConfig.java @@ -1,12 +1,11 @@ package org.vivecraft; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; import org.objectweb.asm.tree.ClassNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import org.spongepowered.asm.service.MixinService; import org.vivecraft.client.Xplat; +import org.vivecraft.common.utils.Utils; import org.vivecraft.mod_compat_vr.iris.mixin.IrisChunkProgramOverridesMixinSodium_0_4_11; import org.vivecraft.mod_compat_vr.iris.mixin.IrisChunkProgramOverridesMixinSodium_0_4_9; import org.vivecraft.mod_compat_vr.sodium.mixin.RenderSectionManagerVRMixin; @@ -50,7 +49,7 @@ public void onLoad(String mixinPackage) { @Override public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { if (!Xplat.isModLoadedSuccess()) { - LogManager.getLogger().log(Level.WARN, "not loading '" + mixinClassName + "' because mod failed to load completely"); + Utils.logger.warn("not loading '{}' because mod failed to load completely", mixinClassName); return false; } @@ -76,7 +75,7 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { MixinService.getService().getBytecodeProvider().getClassNode(neededClass); return true; } catch (ClassNotFoundException | IOException e) { - LogManager.getLogger().log(Level.INFO, "Vivecraft: skipping mixin '" + mixinClassName + "'"); + Utils.logger.info("skipping mixin '{}'", mixinClassName); return false; } } diff --git a/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java b/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java index 459fc1273..788d74543 100644 --- a/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java +++ b/common/src/main/java/org/vivecraft/client/network/ClientNetworking.java @@ -19,6 +19,7 @@ import net.minecraft.world.phys.Vec3; import org.vivecraft.client.VRPlayersClient; import org.vivecraft.client.Xplat; +import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; import org.vivecraft.client_vr.gameplay.VRPlayer; @@ -226,10 +227,10 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI && (dataholder.vrSettings.showServerPluginMessage == VRSettings.ChatServerPluginMessage.ALWAYS || (dataholder.vrSettings.showServerPluginMessage == VRSettings.ChatServerPluginMessage.SERVER_ONLY && !Minecraft.getInstance().isLocalServer()))) { ClientNetworking.displayedChatMessage = true; - mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.serverplugin", s11)); + Utils.printChatMessage(Component.translatable("vivecraft.messages.serverplugin", s11)); } if (VRState.vrEnabled && dataholder.vrSettings.manualCalibration == -1.0F && !dataholder.vrSettings.seated) { - mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.calibrateheight")); + Utils.printChatMessage(Component.translatable("vivecraft.messages.calibrateheight")); } } case IS_VR_ACTIVE -> { @@ -299,7 +300,7 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI } } - System.out.println("Server setting override: " + s13 + " = " + s14); + org.vivecraft.common.utils.Utils.logger.info("Server setting override: {} = {}", s13, s14); } catch (Exception exception) { exception.printStackTrace(); } @@ -313,7 +314,7 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI ClientNetworking.serverAllowsVrSwitching = buffer.readBoolean(); if (VRState.vrInitialized) { if (!ClientNetworking.serverAllowsVrSwitching) { - Minecraft.getInstance().gui.getChat().addMessage(Component.translatable("vivecraft.messages.novrhotswitching")); + Utils.printChatMessage(Component.translatable("vivecraft.messages.novrhotswitching")); } dataholder.vrPlayer.vrSwitchWarning = false; } diff --git a/common/src/main/java/org/vivecraft/client/network/PatreonReceiver.java b/common/src/main/java/org/vivecraft/client/network/PatreonReceiver.java index fdb4dc384..e2075802b 100644 --- a/common/src/main/java/org/vivecraft/client/network/PatreonReceiver.java +++ b/common/src/main/java/org/vivecraft/client/network/PatreonReceiver.java @@ -38,13 +38,13 @@ private static void fileDownloadFinished(String url, String data) { } } } catch (Exception exception1) { - System.out.println("error with donors txt " + exception1.getMessage()); + org.vivecraft.common.utils.Utils.logger.error("error with donors txt {}", exception1.getMessage()); } } cache = hashmap; } catch (Exception exception1) { - System.out.println("Error parsing data: " + url + ", " + exception1.getClass().getName() + ": " + exception1.getMessage()); + org.vivecraft.common.utils.Utils.logger.error("Error parsing data: {}, {}: {}", url, exception1.getClass().getName(), exception1.getMessage()); downloadFailed = true; } } else { diff --git a/common/src/main/java/org/vivecraft/client/utils/UpdateChecker.java b/common/src/main/java/org/vivecraft/client/utils/UpdateChecker.java index cbd5eb441..1b5e57009 100644 --- a/common/src/main/java/org/vivecraft/client/utils/UpdateChecker.java +++ b/common/src/main/java/org/vivecraft/client/utils/UpdateChecker.java @@ -3,10 +3,10 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.mojang.logging.LogUtils; import net.minecraft.SharedConstants; import org.vivecraft.client.Xplat; import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.common.utils.Utils; import org.vivecraft.server.config.ServerConfig; import java.io.BufferedReader; @@ -29,7 +29,7 @@ public class UpdateChecker { public static String newestVersion = ""; public static boolean checkForUpdates() { - System.out.println("Checking for Vivecraft Updates"); + Utils.logger.info("Checking for Updates..."); char updateType; if (Xplat.isDedicatedServer()) { @@ -54,7 +54,7 @@ public static boolean checkForUpdates() { conn.connect(); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { - LogUtils.getLogger().error("Error " + conn.getResponseCode() + " fetching Vivecraft updates"); + Utils.logger.error("Error {} fetching updates!", conn.getResponseCode()); return false; } @@ -91,7 +91,7 @@ public static boolean checkForUpdates() { // no carriage returns please changelog = changelog.replaceAll("\\r", ""); if (hasUpdate) { - LogUtils.getLogger().info("Vivecraft update found: " + newestVersion); + Utils.logger.info("Update found!: {}", newestVersion); } } catch (IOException e) { e.printStackTrace(); diff --git a/common/src/main/java/org/vivecraft/client/utils/Utils.java b/common/src/main/java/org/vivecraft/client/utils/Utils.java index d8baba3f4..f7b49dbc7 100644 --- a/common/src/main/java/org/vivecraft/client/utils/Utils.java +++ b/common/src/main/java/org/vivecraft/client/utils/Utils.java @@ -12,6 +12,7 @@ import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; import net.minecraft.network.chat.Style; import net.minecraft.resources.ResourceLocation; @@ -19,7 +20,6 @@ import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.phys.Vec3; import org.apache.commons.io.IOUtils; -import org.apache.logging.log4j.LogManager; import org.lwjgl.openvr.HmdMatrix44; import org.vivecraft.client.Xplat; import org.vivecraft.client_vr.render.VRShaders; @@ -50,6 +50,13 @@ public class Utils { private static final int READ_TIMEOUT = 20000; private static final Random avRandomizer = new Random(); + public static void printChatMessage(final Component literal) { + Minecraft mc = Minecraft.getInstance(); + if (mc.level != null) { + mc.gui.getChat().addMessage(literal); + } + } + public static String sanitizeFileName(String fileName) { StringBuilder stringbuilder = new StringBuilder(); @@ -334,7 +341,7 @@ private static void handleAssetException(Throwable e, String name, boolean requi if (required) { throw new RuntimeException("Failed to load asset: " + name, e); } else { - System.out.println("Failed to load asset: " + name); + org.vivecraft.common.utils.Utils.logger.error("Failed to load asset: {}", name); e.printStackTrace(); } } @@ -352,10 +359,10 @@ public static void unpackNatives(String directory) { } if (path1.toFile().exists()) { - System.out.println("Copying " + directory + " natives..."); + org.vivecraft.common.utils.Utils.logger.info("Copying {} natives...", directory); for (File file1 : path1.toFile().listFiles()) { - System.out.println(file1.getName()); + org.vivecraft.common.utils.Utils.logger.info(file1.getName()); Files.copy(file1, new File("openvr/" + directory + "/" + file1.getName())); } @@ -364,18 +371,18 @@ public static void unpackNatives(String directory) { } catch (Exception exception) { } - System.out.println("Unpacking " + directory + " natives..."); + org.vivecraft.common.utils.Utils.logger.info("Unpacking {} natives...", directory); Path jarPath = Xplat.getJarPath(); boolean didExtractSomething = false; try (Stream natives = java.nio.file.Files.list(jarPath.resolve("natives/" + directory))) { for (Path file : natives.collect(Collectors.toCollection(ArrayList::new))) { didExtractSomething = true; - System.out.println(file); + org.vivecraft.common.utils.Utils.logger.info(file.toString()); java.nio.file.Files.copy(file, new File("openvr/" + directory + "/" + file.getFileName()).toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING); } } catch (IOException e) { - System.out.println("Failed to unpack natives from jar"); + org.vivecraft.common.utils.Utils.logger.error("Failed to unpack natives from jar"); } if (!didExtractSomething) { ZipFile zipfile = LoaderUtils.getVivecraftZip(); @@ -386,7 +393,7 @@ public static void unpackNatives(String directory) { if (zipentry.getName().startsWith("natives/" + directory)) { String s = Paths.get(zipentry.getName()).getFileName().toString(); - System.out.println(s); + org.vivecraft.common.utils.Utils.logger.info(s); writeStreamToFile(zipfile.getInputStream(zipentry), new File("openvr/" + directory + "/" + s)); } } @@ -394,7 +401,7 @@ public static void unpackNatives(String directory) { zipfile.close(); } } catch (Exception exception1) { - System.out.println("Failed to unpack natives"); + org.vivecraft.common.utils.Utils.logger.error("Failed to unpack natives"); exception1.printStackTrace(); } } @@ -627,7 +634,7 @@ public static void spawnParticles(ParticleOptions type, int count, Vec3 position try { minecraft.level.addParticle(type, position.x + d0, position.y + d1, position.z + d2, d3, d4, d5); } catch (Throwable throwable) { - LogManager.getLogger().warn("Could not spawn particle effect {}", type); + org.vivecraft.common.utils.Utils.logger.warn("Could not spawn particle effect {}", type); return; } } @@ -646,13 +653,8 @@ public static int getCombinedLightWithMin(BlockAndTintGetter lightReader, BlockP } public static void takeScreenshot(RenderTarget fb) { - Minecraft minecraft = Minecraft.getInstance(); - Screenshot.grab(minecraft.gameDirectory, fb, (text) -> - { - minecraft.execute(() -> { - minecraft.gui.getChat().addMessage(text); - }); - }); + Minecraft mc = Minecraft.getInstance(); + Screenshot.grab(mc.gameDirectory, fb, (text) -> mc.execute(() -> printChatMessage(text))); } public static List wrapText(FormattedText text, int width, Font fontRenderer, @Nullable FormattedText linePrefix) { @@ -718,30 +720,6 @@ public static String styleToFormatString(Style style) { return formatsToString(styleToFormats(style)); } - public static long microTime() { - return System.nanoTime() / 1000L; - } - - public static long milliTime() { - return System.nanoTime() / 1000000L; - } - - public static void printStackIfContainsClass(String className) { - StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace(); - boolean flag = false; - - for (StackTraceElement stacktraceelement : astacktraceelement) { - if (stacktraceelement.getClassName().equals(className)) { - flag = true; - break; - } - } - - if (flag) { - Thread.dumpStack(); - } - } - public static org.joml.Matrix4f Matrix4fFromOpenVR(HmdMatrix44 in) { return new org.joml.Matrix4f(in.m(0), in.m(4), in.m(8), in.m(12), in.m(1), in.m(5), in.m(9), in.m(13), diff --git a/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java b/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java index 0f69f1e8a..e02aa462c 100644 --- a/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/ClientDataHolderVR.java @@ -69,14 +69,4 @@ public static ClientDataHolderVR getInstance() { } return INSTANCE; } - - public void printChatMessage(String string) { - // TODO Auto-generated method stub - - } - - public void print(String string) { - string = string.replace("\n", "\n[Minecrift] "); - System.out.println("[Minecrift] " + string); - } } diff --git a/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java b/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java index b29b88b88..32f614532 100644 --- a/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java +++ b/common/src/main/java/org/vivecraft/client_vr/VRTextureTarget.java @@ -25,14 +25,19 @@ public VRTextureTarget(String name, int width, int height, boolean usedepth, boo @Override public String toString() { - StringBuilder stringbuilder = new StringBuilder(); - stringbuilder.append("\n"); - if (this.name != null) { - stringbuilder.append("Name: " + this.name).append("\n"); - } - stringbuilder.append("Size: " + this.viewWidth + " x " + this.viewHeight).append("\n"); - stringbuilder.append("FB ID: " + this.frameBufferId).append("\n"); - stringbuilder.append("Tex ID: " + this.colorTextureId).append("\n"); - return stringbuilder.toString(); + return + """ + Texture Target: + Name: %s + Size: %d x %d + FB ID: %d + Tex ID: %d + """.formatted( + this.name, + this.viewWidth, + this.viewHeight, + this.frameBufferId, + this.colorTextureId + ); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRMovementStyle.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRMovementStyle.java index fbac4463e..cccd5d870 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRMovementStyle.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRMovementStyle.java @@ -1,7 +1,8 @@ package org.vivecraft.client_vr.gameplay; -import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; public class VRMovementStyle { @@ -38,108 +39,115 @@ public VRMovementStyle(ClientDataHolderVR dataholder) { public void setStyle(String requestedStyle) { boolean flag = true; - if (requestedStyle == "Minimal") { - this.name = requestedStyle; - this.cameraSlide = false; - this.airSparkles = true; - this.destinationSparkles = true; - this.showBeam = false; - this.startTeleportingSound = null; - this.endTeleportingSoundVolume = 0.8F; - this.endTeleportingSound = "mob.endermen.portal"; - this.teleportOnRelease = false; - this.arcAiming = false; - } else if (requestedStyle == "Beam") { - this.name = requestedStyle; - this.cameraSlide = false; - this.airSparkles = true; - this.destinationSparkles = true; - this.showBeam = true; - this.beamWave = false; - this.beamArc = false; - this.beamSpiral = false; - this.beamGrow = true; - this.beamHalfWidth = 0.1F; - this.beamSegmentLength = 0.1F; - this.beamVStrips = 16; - this.renderVerticalStrip = true; - this.textureScrollSpeed = 3.0F; - this.texture = beamPng; - this.startTeleportingSound = null; - this.endTeleportingSoundVolume = 0.8F; - this.endTeleportingSound = "mob.endermen.portal"; - this.teleportOnRelease = false; - this.arcAiming = false; - } else if (requestedStyle == "Tunnel") { - this.name = requestedStyle; - this.cameraSlide = false; - this.airSparkles = true; - this.destinationSparkles = true; - this.showBeam = true; - this.beamWave = false; - this.beamArc = false; - this.beamSpiral = true; - this.beamGrow = true; - this.beamHalfWidth = 0.1F; - this.beamSpiralRadius = 1.6F; - this.renderVerticalStrip = true; - this.beamVStrips = 16; - this.textureScrollSpeed = 3.0F; - this.texture = beamPng; - this.startTeleportingSound = null; - this.endTeleportingSoundVolume = 0.8F; - this.endTeleportingSound = "mob.endermen.portal"; - this.teleportOnRelease = false; - this.arcAiming = false; - } else if (requestedStyle == "Grapple") { - this.name = requestedStyle; - this.cameraSlide = true; - this.airSparkles = false; - this.destinationSparkles = true; - this.showBeam = true; - this.beamWave = true; - this.beamArc = false; - this.beamSpiral = false; - this.beamGrow = true; - this.beamHalfWidth = 0.05F; - this.beamSegmentLength = 0.05F; - this.renderVerticalStrip = false; - this.beamVStrips = 2; - this.textureScrollSpeed = 7.0F; - this.texture = beamPng; - this.startTeleportingSoundVolume = 0.5F; - this.endTeleportingSoundVolume = 0.5F; - this.startTeleportingSound = null; - this.endTeleportingSound = "mob.endermen.portal"; - this.teleportOnRelease = false; - this.arcAiming = false; - } else if (requestedStyle == "Arc") { - this.name = requestedStyle; - this.cameraSlide = false; - this.airSparkles = false; - this.destinationSparkles = false; - this.showBeam = true; - this.beamWave = false; - this.beamArc = false; - this.beamSpiral = false; - this.beamGrow = false; - this.beamHalfWidth = 0.1F; - this.beamVStrips = 1; - this.renderVerticalStrip = true; - this.textureScrollSpeed = 3.0F; - this.texture = beamPng; - this.startTeleportingSound = null; - this.endTeleportingSoundVolume = 0.7F; - this.endTeleportingSound = null; - this.teleportOnRelease = true; - this.arcAiming = true; - } else { - flag = false; - ClientDataHolderVR.getInstance().printChatMessage("Unknown teleport style requested: " + requestedStyle); + switch (requestedStyle) { + case "Minimal" -> { + this.name = requestedStyle; + this.cameraSlide = false; + this.airSparkles = true; + this.destinationSparkles = true; + this.showBeam = false; + this.startTeleportingSound = null; + this.endTeleportingSoundVolume = 0.8F; + this.endTeleportingSound = "mob.endermen.portal"; + this.teleportOnRelease = false; + this.arcAiming = false; + } + case "Beam" -> { + this.name = requestedStyle; + this.cameraSlide = false; + this.airSparkles = true; + this.destinationSparkles = true; + this.showBeam = true; + this.beamWave = false; + this.beamArc = false; + this.beamSpiral = false; + this.beamGrow = true; + this.beamHalfWidth = 0.1F; + this.beamSegmentLength = 0.1F; + this.beamVStrips = 16; + this.renderVerticalStrip = true; + this.textureScrollSpeed = 3.0F; + this.texture = beamPng; + this.startTeleportingSound = null; + this.endTeleportingSoundVolume = 0.8F; + this.endTeleportingSound = "mob.endermen.portal"; + this.teleportOnRelease = false; + this.arcAiming = false; + } + case "Tunnel" -> { + this.name = requestedStyle; + this.cameraSlide = false; + this.airSparkles = true; + this.destinationSparkles = true; + this.showBeam = true; + this.beamWave = false; + this.beamArc = false; + this.beamSpiral = true; + this.beamGrow = true; + this.beamHalfWidth = 0.1F; + this.beamSpiralRadius = 1.6F; + this.renderVerticalStrip = true; + this.beamVStrips = 16; + this.textureScrollSpeed = 3.0F; + this.texture = beamPng; + this.startTeleportingSound = null; + this.endTeleportingSoundVolume = 0.8F; + this.endTeleportingSound = "mob.endermen.portal"; + this.teleportOnRelease = false; + this.arcAiming = false; + } + case "Grapple" -> { + this.name = requestedStyle; + this.cameraSlide = true; + this.airSparkles = false; + this.destinationSparkles = true; + this.showBeam = true; + this.beamWave = true; + this.beamArc = false; + this.beamSpiral = false; + this.beamGrow = true; + this.beamHalfWidth = 0.05F; + this.beamSegmentLength = 0.05F; + this.renderVerticalStrip = false; + this.beamVStrips = 2; + this.textureScrollSpeed = 7.0F; + this.texture = beamPng; + this.startTeleportingSoundVolume = 0.5F; + this.endTeleportingSoundVolume = 0.5F; + this.startTeleportingSound = null; + this.endTeleportingSound = "mob.endermen.portal"; + this.teleportOnRelease = false; + this.arcAiming = false; + } + case "Arc" -> { + this.name = requestedStyle; + this.cameraSlide = false; + this.airSparkles = false; + this.destinationSparkles = false; + this.showBeam = true; + this.beamWave = false; + this.beamArc = false; + this.beamSpiral = false; + this.beamGrow = false; + this.beamHalfWidth = 0.1F; + this.beamVStrips = 1; + this.renderVerticalStrip = true; + this.textureScrollSpeed = 3.0F; + this.texture = beamPng; + this.startTeleportingSound = null; + this.endTeleportingSoundVolume = 0.7F; + this.endTeleportingSound = null; + this.teleportOnRelease = true; + this.arcAiming = true; + } + default -> { + flag = false; + Utils.printChatMessage(Component.translatableWithFallback("vivecraft.options.teleport.style", "Unknown teleport style requested: " + requestedStyle, requestedStyle)); + } } - if (flag && Minecraft.getInstance() != null && dataholder != null) { - dataholder.printChatMessage("Teleport style (RCTRL-M): " + this.name); + if (flag && this.dataholder != null) { + Utils.printChatMessage(Component.translatableWithFallback("vivecraft.options.teleport.style", "Teleport style (RCTRL-M): " + this.name, this.name)); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java index e1dd20112..7b748d670 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/VRPlayer.java @@ -256,14 +256,18 @@ public void rotateOriginAround(float degrees, Vec3 o) { public void tick(LocalPlayer player, Minecraft mc, RandomSource rand) { if (((PlayerExtension) player).vivecraft$getInitFromServer()) { if (!this.initdone) { - System.out.println(""); - System.out.println("Room object: " + this); - System.out.println("Room origin: " + this.vrdata_world_pre.origin); - System.out.println("Hmd position room: " + this.vrdata_room_pre.hmd.getPosition()); - System.out.println("Hmd position world: " + this.vrdata_world_pre.hmd.getPosition()); - System.out.println("Hmd Projection Left: " + dh.vrRenderer.eyeproj[0]); - System.out.println("Hmd Projection Right: " + dh.vrRenderer.eyeproj[1]); - System.out.println(""); + org.vivecraft.common.utils.Utils.logger.info( + """ + {} + Hmd Projection Left: + {} + Hmd Projection Right: + {} + """, + this, + dh.vrRenderer.eyeproj[0], + dh.vrRenderer.eyeproj[1] + ); this.initdone = true; } diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java index 14eaaa344..b8501621a 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/screenhandlers/GuiHandler.java @@ -491,7 +491,7 @@ public static Vec3 applyGUIModelView(RenderPass currentPass, PoseStack pMatrixSt //GL11.glMultMatrixf(dh.vrPlayer.vrdata_world_render.getEye(currentPass).getMatrix().toFloatBuffer()); if (guipos == null) { - VRSettings.logger.error("guipos was null, how did that happen. vrRunning: {}", VRState.vrRunning); + org.vivecraft.common.utils.Utils.logger.error("guipos was null, how did that happen. vrRunning: {}", VRState.vrRunning); new RuntimeException().printStackTrace(); guiPos_room = new Vec3(0, 0, 0); guipos = VRPlayer.room_to_world_pos(guiPos_room, dh.vrPlayer.vrdata_world_render); diff --git a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java index 1a17d162e..f646ae59b 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java +++ b/common/src/main/java/org/vivecraft/client_vr/gameplay/trackers/HorseTracker.java @@ -111,7 +111,7 @@ boolean doBreak() { } else if (System.currentTimeMillis() < this.lastBoostMillis + (long) this.coolDownMillis) { return false; } else { - System.out.println("Breaking"); + org.vivecraft.common.utils.Utils.logger.info("Breaking"); --this.speedLevel; this.lastBoostMillis = System.currentTimeMillis(); return true; diff --git a/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java b/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java index f9deb9e4d..8d1b10435 100644 --- a/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java +++ b/common/src/main/java/org/vivecraft/client_vr/gui/PhysicalKeyboard.java @@ -140,13 +140,13 @@ public void onPressed() { this.addKey(new KeyButton(1000 + l, "Shift", l == 1 ? this.keyWidthSpecial + this.spacing + (float) this.columns * (this.keyWidth + this.spacing) : 0.0F, 3.0F * (this.keyHeight + this.spacing), this.keyWidthSpecial, this.keyHeight) { @Override public void onPressed() { - if (PhysicalKeyboard.this.shift && !PhysicalKeyboard.this.shiftSticky && Utils.milliTime() - PhysicalKeyboard.this.shiftPressTime < 400L) { + if (PhysicalKeyboard.this.shift && !PhysicalKeyboard.this.shiftSticky && org.vivecraft.common.utils.Utils.milliTime() - PhysicalKeyboard.this.shiftPressTime < 400L) { PhysicalKeyboard.this.setShift(true, true); } else { PhysicalKeyboard.this.setShift(!PhysicalKeyboard.this.shift, false); } - PhysicalKeyboard.this.shiftPressTime = Utils.milliTime(); + PhysicalKeyboard.this.shiftPressTime = org.vivecraft.common.utils.Utils.milliTime(); } @Override @@ -307,7 +307,7 @@ public void onPressed() { RGBAColor color = new RGBAColor(Integer.parseInt(colorSplit[0]), Integer.parseInt(colorSplit[1]), Integer.parseInt(colorSplit[2]), 255); customTheme.put(id, color); } catch (Exception ex) { - System.out.println("Bad theme line: " + line); + org.vivecraft.common.utils.Utils.logger.error("Bad theme line: {}", line); ex.printStackTrace(); } }); @@ -330,7 +330,7 @@ public void process() { KeyButton physicalkeyboard$keybutton = this.findTouchedKey(controllertype); if (physicalkeyboard$keybutton != null) { - if (physicalkeyboard$keybutton != this.pressedKey[i] && Utils.milliTime() - this.pressTime[i] >= 150L) { + if (physicalkeyboard$keybutton != this.pressedKey[i] && org.vivecraft.common.utils.Utils.milliTime() - this.pressTime[i] >= 150L) { if (this.pressedKey[i] != null) { this.pressedKey[i].unpress(controllertype); this.pressedKey[i] = null; @@ -338,16 +338,16 @@ public void process() { physicalkeyboard$keybutton.press(controllertype, false); this.pressedKey[i] = physicalkeyboard$keybutton; - this.pressTime[i] = Utils.milliTime(); - this.pressRepeatTime[i] = Utils.milliTime(); - } else if (physicalkeyboard$keybutton == this.pressedKey[i] && Utils.milliTime() - this.pressTime[i] >= 500L && Utils.milliTime() - this.pressRepeatTime[i] >= 100L) { + this.pressTime[i] = org.vivecraft.common.utils.Utils.milliTime(); + this.pressRepeatTime[i] = org.vivecraft.common.utils.Utils.milliTime(); + } else if (physicalkeyboard$keybutton == this.pressedKey[i] && org.vivecraft.common.utils.Utils.milliTime() - this.pressTime[i] >= 500L && org.vivecraft.common.utils.Utils.milliTime() - this.pressRepeatTime[i] >= 100L) { physicalkeyboard$keybutton.press(controllertype, true); - this.pressRepeatTime[i] = Utils.milliTime(); + this.pressRepeatTime[i] = org.vivecraft.common.utils.Utils.milliTime(); } } else if (this.pressedKey[i] != null) { this.pressedKey[i].unpress(controllertype); this.pressedKey[i] = null; - this.pressTime[i] = Utils.milliTime(); + this.pressTime[i] = org.vivecraft.common.utils.Utils.milliTime(); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java index 215c781be..ceda3d8e7 100644 --- a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java +++ b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldDownloader.java @@ -38,11 +38,11 @@ public static void downloadWorld(String path) throws IOException, NoSuchAlgorith String localSha1 = Utils.getFileChecksum(file, "SHA-1"); String remoteSha1 = Utils.httpReadLine(baseUrl + "checksum.php?file=" + path); if (localSha1.equals(remoteSha1)) { - VRSettings.logger.info("MenuWorlds: SHA-1 matches for " + path); + org.vivecraft.common.utils.Utils.logger.info("MenuWorlds: SHA-1 matches for {}", path); return; } } - VRSettings.logger.info("MenuWorlds: Downloading world " + path); + org.vivecraft.common.utils.Utils.logger.info("MenuWorlds: Downloading world {}", path); Utils.httpReadToFile(baseUrl + path, file, true); } @@ -81,11 +81,11 @@ public static InputStream getRandomWorld() throws IOException, NoSuchAlgorithmEx private static InputStream getStreamForWorld(MenuWorldItem world) throws IOException, NoSuchAlgorithmException { if (world.file != null) { - VRSettings.logger.info("MenuWorlds: Using world " + world.file.getName()); + org.vivecraft.common.utils.Utils.logger.info("MenuWorlds: Using world {}", world.file.getName()); return new FileInputStream(world.file); } else if (world.path != null) { downloadWorld(world.path); - VRSettings.logger.info("MenuWorlds: Using official world " + world.path); + org.vivecraft.common.utils.Utils.logger.info("MenuWorlds: Using official world {}", world.path); return new FileInputStream(world.path); } else { throw new IllegalArgumentException("File or path must be assigned"); @@ -110,7 +110,7 @@ private static List getOfficialWorlds() throws IOException { } private static InputStream getRandomWorldFallback() throws IOException, NoSuchAlgorithmException { - VRSettings.logger.info("MenuWorlds: Couldn't find a world, trying random file from directory"); + org.vivecraft.common.utils.Utils.logger.info("MenuWorlds: Couldn't find a world, trying random file from directory"); File dir = new File("menuworlds"); if (dir.exists()) { MenuWorldItem world = getRandomWorldFromList(getWorldsInDirectory(dir)); diff --git a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java index 169ae881e..50263863a 100644 --- a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java +++ b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldExporter.java @@ -31,7 +31,7 @@ import net.minecraft.world.level.dimension.BuiltinDimensionTypes; import net.minecraft.world.level.dimension.DimensionType; import org.vivecraft.client.Xplat; -import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import java.io.*; import java.util.*; @@ -223,7 +223,7 @@ public static FakeBlockAccess loadWorld(byte[] data) throws IOException, DataFor } if (dataVersion > SharedConstants.getCurrentVersion().getDataVersion().getVersion()) { - VRSettings.logger.warn("Data version is newer than current, this menu world may not load correctly."); + Utils.logger.warn("Data version is newer than current, this menu world may not load correctly."); } OptionalLong dimFixedTime = OptionalLong.empty(); diff --git a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java index 7e53be130..88f70161b 100644 --- a/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/menuworlds/MenuWorldRenderer.java @@ -43,6 +43,7 @@ import org.vivecraft.client.Xplat; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import org.vivecraft.mod_compat_vr.optifine.OptifineHelper; import org.vivecraft.mod_compat_vr.sodium.SodiumHelper; @@ -124,20 +125,20 @@ public void init() { try { InputStream inputStream = MenuWorldDownloader.getRandomWorld(); if (inputStream != null) { - VRSettings.logger.info("MenuWorlds: Initializing main menu world renderer..."); + Utils.logger.info("MenuWorlds: Initializing main menu world renderer..."); loadRenderers(); - VRSettings.logger.info("MenuWorlds: Loading world data..."); + Utils.logger.info("MenuWorlds: Loading world data..."); setWorld(MenuWorldExporter.loadWorld(inputStream)); prepare(); fastTime = new Random().nextInt(10) == 0; } else { - VRSettings.logger.warn("Failed to load any main menu world, falling back to old menu room"); + Utils.logger.warn("Failed to load any main menu world, falling back to old menu room"); } } catch (Throwable e) { // Only effective way of preventing crash on poop computers with low heap size if (e instanceof OutOfMemoryError || e.getCause() instanceof OutOfMemoryError) { - VRSettings.logger.error("OutOfMemoryError while loading main menu world. Low heap size or 32-bit Java?"); + Utils.logger.error("OutOfMemoryError while loading main menu world. Low heap size or 32-bit Java?"); } else { - VRSettings.logger.error("Exception thrown when loading main menu world, falling back to old menu room. \n {}", e.getMessage()); + Utils.logger.error("Exception thrown when loading main menu world, falling back to old menu room. \n {}", e.getMessage()); } e.printStackTrace(); destroy(); @@ -226,7 +227,7 @@ private void renderChunkLayer(RenderType layer, Matrix4f modelView, Matrix4f Pro public void prepare() { if (vertexBuffers == null) { - VRSettings.logger.info("MenuWorlds: Building geometry..."); + Utils.logger.info("MenuWorlds: Building geometry..."); boolean ao = mc.options.ambientOcclusion().get(); mc.options.ambientOcclusion().set(true); @@ -337,7 +338,7 @@ private Pair buildGeometryLayer(Render } } } - VRSettings.logger.info("Built " + c + " blocks."); + Utils.logger.info("Built {} blocks.", c); if (layer == RenderType.translucent()) { vertBuffer.setQuadSorting(VertexSorting.byDistance(0, Mth.frac(blockAccess.getGround()), 0)); } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java index fd60ff11a..beddc180e 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/MCVR.java @@ -454,7 +454,7 @@ protected void hmdSampling() { if (Math.abs(Utils.angleNormalize(this.hmdYawTotal) - this.hmdYawLast) > 1.0F || this.hmdYawTotal > 100000.0F) { this.hmdYawTotal = this.hmdYawLast; - System.out.println("HMD yaw desync/overflow corrected"); + org.vivecraft.common.utils.Utils.logger.warn("HMD yaw desync/overflow corrected"); } this.hmdPosSamples.add(this.dh.vrPlayer.vrdata_room_pre.hmd.getPosition()); @@ -741,16 +741,16 @@ public void processBindings() { } else if (++this.moveModeSwitchCount == 80 || flag2) { if (this.dh.vrSettings.seated) { this.dh.vrSettings.seatedFreeMove = !this.dh.vrSettings.seatedFreeMove; - this.mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.movementmodeswitch", this.dh.vrSettings.seatedFreeMove ? Component.translatable("vivecraft.options.freemove") : Component.translatable("vivecraft.options.teleport"))); + Utils.printChatMessage(Component.translatable("vivecraft.messages.movementmodeswitch", this.dh.vrSettings.seatedFreeMove ? Component.translatable("vivecraft.options.freemove") : Component.translatable("vivecraft.options.teleport"))); } else if (this.dh.vrPlayer.isTeleportSupported()) { this.dh.vrSettings.forceStandingFreeMove = !this.dh.vrSettings.forceStandingFreeMove; - this.mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.movementmodeswitch", this.dh.vrSettings.seatedFreeMove ? Component.translatable("vivecraft.options.freemove") : Component.translatable("vivecraft.options.teleport"))); + Utils.printChatMessage(Component.translatable("vivecraft.messages.movementmodeswitch", this.dh.vrSettings.seatedFreeMove ? Component.translatable("vivecraft.options.freemove") : Component.translatable("vivecraft.options.teleport"))); } else if (this.dh.vrPlayer.isTeleportOverridden()) { this.dh.vrPlayer.setTeleportOverride(false); - this.mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.teleportdisabled")); + Utils.printChatMessage(Component.translatable("vivecraft.messages.teleportdisabled")); } else { this.dh.vrPlayer.setTeleportOverride(true); - this.mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.teleportenabled")); + Utils.printChatMessage(Component.translatable("vivecraft.messages.teleportenabled")); } } @@ -1073,7 +1073,7 @@ public Map getSpecialActionParams() { File file1 = new File("customactionsets.txt"); if (file1.exists()) { - System.out.println("Loading custom action set definitions..."); + org.vivecraft.common.utils.Utils.logger.info("Loading custom action set definitions..."); String s; try (BufferedReader bufferedreader = new BufferedReader(new FileReader(file1))) { @@ -1081,14 +1081,14 @@ public Map getSpecialActionParams() { String[] astring = s.split(":", 2); if (astring.length < 2) { - System.out.println("Invalid tokens: " + s); + org.vivecraft.common.utils.Utils.logger.warn("Invalid tokens: " + s); } else { KeyMapping keymapping = this.findKeyBinding(astring[0]); if (keymapping == null) { - System.out.println("Unknown key binding: " + astring[0]); + org.vivecraft.common.utils.Utils.logger.warn("Unknown key binding: " + astring[0]); } else if (mod.getAllKeyBindings().contains(keymapping)) { - System.out.println("NO! Don't touch Vivecraft bindings!"); + org.vivecraft.common.utils.Utils.logger.warn("NO! Don't touch Vivecraft bindings!"); } else { VRInputActionSet vrinputactionset = null; String s1 = astring[1].toLowerCase(); @@ -1107,7 +1107,7 @@ public Map getSpecialActionParams() { } if (vrinputactionset == null) { - System.out.println("Unknown action set: " + astring[1]); + org.vivecraft.common.utils.Utils.logger.warn("Unknown action set: {}", astring[1]); } else { this.addActionParams(map, keymapping, "optional", "boolean", vrinputactionset); } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java index cccda865f..194c03ce6 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/VRRenderer.java @@ -31,8 +31,10 @@ import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_vr.render.ShaderHelper; import org.vivecraft.client_vr.render.VRShaders; +import org.vivecraft.client_vr.render.helpers.VRPassHelper; import org.vivecraft.client_vr.settings.VRSettings; import org.vivecraft.client_xr.render_pass.WorldRenderPass; +import org.vivecraft.common.utils.Utils; import org.vivecraft.mod_compat_vr.ShadersHelper; import org.vivecraft.mod_compat_vr.resolutioncontrol.ResolutionControlHelper; @@ -86,13 +88,6 @@ public VRRenderer(MCVR vr) { this.vr = vr; } - protected void checkGLError(String message) { - //Config.checkGlError(message); TODO - if (GlStateManager._getError() != 0) { - System.err.println(message); - } - } - public abstract void createRenderTexture(int var1, int var2); public abstract Matrix4f getProjectionMatrix(int var1, float var2, float var3); @@ -414,7 +409,7 @@ public void reinitFrameBuffers(String cause) { if (acceptReinits) { if (!reinitFramebuffers) { // only print the first cause - System.out.println("Reinit Render: " + cause); + Utils.logger.info("Reinit Render: {}", cause); } this.reinitFramebuffers = true; } @@ -422,7 +417,7 @@ public void reinitFrameBuffers(String cause) { public void resizeFrameBuffers(String cause) { if (!cause.isEmpty() && !this.resizeFrameBuffers) { - System.out.println("Resizing Buffers: " + cause); + Utils.logger.info("Resizing Buffers: {}", cause); } this.resizeFrameBuffers = true; } @@ -509,7 +504,7 @@ public void setupRenderConfiguration() throws Exception { if (this.reinitFramebuffers) { this.reinitShadersFlag = true; - this.checkGLError("Start Init"); + VRPassHelper.checkGLError("Start Init"); if (GlUtil.getRenderer().toLowerCase().contains("intel")) //Optifine { @@ -533,22 +528,22 @@ public void setupRenderConfiguration() throws Exception { throw new RenderConfigException("Failed to initialise stereo rendering plugin: " + this.getName(), Component.literal(this.getLastError())); } - dataholder.print("Provider supplied render texture IDs: " + this.LeftEyeTextureId + " " + this.RightEyeTextureId); - dataholder.print("Provider supplied texture resolution: " + eyew + " x " + eyeh); + Utils.logger.info("Provider supplied render texture IDs: {} {}", this.LeftEyeTextureId, this.RightEyeTextureId); + Utils.logger.info("Provider supplied texture resolution: {} x {}", eyew, eyeh); } - this.checkGLError("Render Texture setup"); + VRPassHelper.checkGLError("Render Texture setup"); if (this.framebufferEye0 == null) { this.framebufferEye0 = new VRTextureTarget("L Eye", eyew, eyeh, false, false, this.LeftEyeTextureId, false, true, false); - dataholder.print(this.framebufferEye0.toString()); - this.checkGLError("Left Eye framebuffer setup"); + Utils.logger.info(this.framebufferEye0.toString()); + VRPassHelper.checkGLError("Left Eye framebuffer setup"); } if (this.framebufferEye1 == null) { this.framebufferEye1 = new VRTextureTarget("R Eye", eyew, eyeh, false, false, this.RightEyeTextureId, false, true, false); - dataholder.print(this.framebufferEye1.toString()); - this.checkGLError("Right Eye framebuffer setup"); + Utils.logger.info(this.framebufferEye1.toString()); + VRPassHelper.checkGLError("Right Eye framebuffer setup"); } float resolutionScale = ResolutionControlHelper.isLoaded() ? ResolutionControlHelper.getCurrentScaleFactor() : 1.0F; @@ -559,15 +554,15 @@ public void setupRenderConfiguration() throws Exception { this.framebufferVrRender = new VRTextureTarget("3D Render", eyeFBWidth, eyeFBHeight, true, false, -1, true, true, dataholder.vrSettings.vrUseStencil); WorldRenderPass.stereoXR = new WorldRenderPass((VRTextureTarget) this.framebufferVrRender); - dataholder.print(this.framebufferVrRender.toString()); - this.checkGLError("3D framebuffer setup"); + Utils.logger.info(this.framebufferVrRender.toString()); + VRPassHelper.checkGLError("3D framebuffer setup"); getMirrorTextureSize(eyeFBWidth, eyeFBHeight, resolutionScale); List list = this.getRenderPasses(); for (RenderPass renderpass : list) { - System.out.println("Passes: " + renderpass.toString()); + Utils.logger.info("Passes: {}", renderpass.toString()); } // only do these, if the window is not minimized @@ -575,43 +570,43 @@ public void setupRenderConfiguration() throws Exception { if (list.contains(RenderPass.THIRD) || ShadersHelper.isShaderActive()) { this.framebufferMR = new VRTextureTarget("Mixed Reality Render", this.mirrorFBWidth, this.mirrorFBHeight, true, false, -1, true, false, false); WorldRenderPass.mixedReality = new WorldRenderPass((VRTextureTarget) this.framebufferMR); - dataholder.print(this.framebufferMR.toString()); - this.checkGLError("Mixed reality framebuffer setup"); + Utils.logger.info(this.framebufferMR.toString()); + VRPassHelper.checkGLError("Mixed reality framebuffer setup"); } if (list.contains(RenderPass.CENTER) || ShadersHelper.isShaderActive()) { this.framebufferUndistorted = new VRTextureTarget("Undistorted View Render", this.mirrorFBWidth, this.mirrorFBHeight, true, false, -1, false, false, false); WorldRenderPass.center = new WorldRenderPass((VRTextureTarget) this.framebufferUndistorted); - dataholder.print(this.framebufferUndistorted.toString()); - this.checkGLError("Undistorted view framebuffer setup"); + Utils.logger.info(this.framebufferUndistorted.toString()); + VRPassHelper.checkGLError("Undistorted view framebuffer setup"); } } GuiHandler.guiFramebuffer = new VRTextureTarget("GUI", GuiHandler.guiWidth, GuiHandler.guiHeight, true, false, -1, false, true, false); - dataholder.print(GuiHandler.guiFramebuffer.toString()); - this.checkGLError("GUI framebuffer setup"); + Utils.logger.info(GuiHandler.guiFramebuffer.toString()); + VRPassHelper.checkGLError("GUI framebuffer setup"); KeyboardHandler.Framebuffer = new VRTextureTarget("Keyboard", GuiHandler.guiWidth, GuiHandler.guiHeight, true, false, -1, false, true, false); - dataholder.print(KeyboardHandler.Framebuffer.toString()); - this.checkGLError("Keyboard framebuffer setup"); + Utils.logger.info(KeyboardHandler.Framebuffer.toString()); + VRPassHelper.checkGLError("Keyboard framebuffer setup"); RadialHandler.Framebuffer = new VRTextureTarget("Radial Menu", GuiHandler.guiWidth, GuiHandler.guiHeight, true, false, -1, false, true, false); - dataholder.print(RadialHandler.Framebuffer.toString()); - this.checkGLError("Radial framebuffer setup"); + Utils.logger.info(RadialHandler.Framebuffer.toString()); + VRPassHelper.checkGLError("Radial framebuffer setup"); Tuple telescopeSize = getTelescopeTextureSize(eyeFBWidth, eyeFBHeight); this.telescopeFramebufferR = new VRTextureTarget("TelescopeR", telescopeSize.getA(), telescopeSize.getB(), true, false, -1, true, false, false); WorldRenderPass.rightTelescope = new WorldRenderPass((VRTextureTarget) this.telescopeFramebufferR); - dataholder.print(this.telescopeFramebufferR.toString()); + Utils.logger.info(this.telescopeFramebufferR.toString()); this.telescopeFramebufferR.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); this.telescopeFramebufferR.clear(Minecraft.ON_OSX); - this.checkGLError("TelescopeR framebuffer setup"); + VRPassHelper.checkGLError("TelescopeR framebuffer setup"); this.telescopeFramebufferL = new VRTextureTarget("TelescopeL", telescopeSize.getA(), telescopeSize.getB(), true, false, -1, true, false, false); WorldRenderPass.leftTelescope = new WorldRenderPass((VRTextureTarget) this.telescopeFramebufferL); - dataholder.print(this.telescopeFramebufferL.toString()); + Utils.logger.info(this.telescopeFramebufferL.toString()); this.telescopeFramebufferL.setClearColor(0.0f, 0.0f, 0.0f, 1.0f); this.telescopeFramebufferL.clear(Minecraft.ON_OSX); - this.checkGLError("TelescopeL framebuffer setup"); + VRPassHelper.checkGLError("TelescopeL framebuffer setup"); Tuple cameraSize = getCameraTextureSize(eyeFBWidth, eyeFBHeight); @@ -624,32 +619,32 @@ public void setupRenderConfiguration() throws Exception { } this.cameraFramebuffer = new VRTextureTarget("Handheld Camera", cameraSize.getA(), cameraSize.getB(), true, false, -1, true, false, false); - dataholder.print(this.cameraFramebuffer.toString()); + Utils.logger.info(this.cameraFramebuffer.toString()); - this.checkGLError("Camera framebuffer setup"); + VRPassHelper.checkGLError("Camera framebuffer setup"); this.cameraRenderFramebuffer = new VRTextureTarget("Handheld Camera Render", cameraRenderFBwidth, cameraRenderFBheight, true, false, -1, true, true, false); WorldRenderPass.camera = new WorldRenderPass((VRTextureTarget) this.cameraRenderFramebuffer); - dataholder.print(this.cameraRenderFramebuffer.toString()); + Utils.logger.info(this.cameraRenderFramebuffer.toString()); - this.checkGLError("Camera render framebuffer setup"); + VRPassHelper.checkGLError("Camera render framebuffer setup"); ((GameRendererExtension) minecraft.gameRenderer).vivecraft$setupClipPlanes(); this.eyeproj[0] = this.getProjectionMatrix(0, ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getMinClipDistance(), ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getClipDistance()); this.eyeproj[1] = this.getProjectionMatrix(1, ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getMinClipDistance(), ((GameRendererExtension) minecraft.gameRenderer).vivecraft$getClipDistance()); if (dataholder.vrSettings.useFsaa) { try { - this.checkGLError("pre FSAA FBO creation"); + VRPassHelper.checkGLError("pre FSAA FBO creation"); this.fsaaFirstPassResultFBO = new VRTextureTarget("FSAA Pass1 FBO", eyew, eyeFBHeight, true, false, -1, false, false, false); this.fsaaLastPassResultFBO = new VRTextureTarget("FSAA Pass2 FBO", eyew, eyeh, true, false, -1, false, false, false); - dataholder.print(this.fsaaFirstPassResultFBO.toString()); - dataholder.print(this.fsaaLastPassResultFBO.toString()); - this.checkGLError("FSAA FBO creation"); + Utils.logger.info(this.fsaaFirstPassResultFBO.toString()); + Utils.logger.info(this.fsaaLastPassResultFBO.toString()); + VRPassHelper.checkGLError("FSAA FBO creation"); VRShaders.setupFSAA(); ShaderHelper.checkGLError("FBO init fsaa shader"); } catch (Exception exception) { dataholder.vrSettings.useFsaa = false; dataholder.vrSettings.saveOptions(); - System.out.println(exception.getMessage()); + org.vivecraft.common.utils.Utils.logger.info(exception.getMessage()); this.reinitFramebuffers = true; return; } @@ -665,7 +660,7 @@ public void setupRenderConfiguration() throws Exception { ShaderHelper.checkGLError("init portal shader"); minecraft.gameRenderer.checkEntityPostEffect(minecraft.getCameraEntity()); } catch (Exception exception1) { - System.out.println(exception1.getMessage()); + Utils.logger.error(exception1.getMessage()); System.exit(-1); } @@ -686,11 +681,21 @@ public void setupRenderConfiguration() throws Exception { vrPixels += windowPixels; } - System.out.println("[Minecrift] New render config:" + - "\nOpenVR target width: " + eyew + ", height: " + eyeh + " [" + String.format("%.1f", (float) (eyew * eyeh) / 1000000.0F) + " MP]" + - "\nRender target width: " + eyeFBWidth + ", height: " + eyeFBHeight + " [Render scale: " + Math.round(dataholder.vrSettings.renderScaleFactor * 100.0F) + "%, " + String.format("%.1f", (float) (eyeFBWidth * eyeFBHeight) / 1000000.0F) + " MP]" + - "\nMain window width: " + minecraft.getWindow().getScreenWidth() + ", height: " + minecraft.getWindow().getScreenHeight() + " [" + String.format("%.1f", (float) windowPixels / 1000000.0F) + " MP]" + - "\nTotal shaded pixels per frame: " + String.format("%.1f", (float) vrPixels / 1000000.0F) + " MP (eye stencil not accounted for)"); + Utils.logger.info( + """ + New render config: + OpenVR target width: {}, height: {} [{} MP] + Render target width: {}, height: {} [Render scale: {}%, {} MP] + Main window width: {}, height: {} [{} MP] + Total shaded pixels per frame: {} MP (eye stencil not accounted for) + """, + eyew, eyeh, String.format("%.1f", (float) (eyew * eyeh) / 1000000.0F), + eyeFBWidth, eyeFBHeight, Math.round(dataholder.vrSettings.renderScaleFactor * 100.0F), + String.format("%.1f", (float) (eyeFBWidth * eyeFBHeight) / 1000000.0F), + minecraft.getWindow().getScreenWidth(), minecraft.getWindow().getScreenHeight(), + String.format("%.1f", (float) windowPixels / 1000000.0F), + String.format("%.1f", (float) vrPixels / 1000000.0F) + ); this.lastDisplayFBWidth = eyeFBWidth; this.lastDisplayFBHeight = eyeFBHeight; this.reinitFramebuffers = false; diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java index 1bd65a126..0e065ee5f 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVR.java @@ -60,7 +60,7 @@ public boolean init() { this.mc = Minecraft.getInstance(); // only supports seated mode - System.out.println("NullDriver. Forcing seated mode."); + org.vivecraft.common.utils.Utils.logger.info("NullDriver. Forcing seated mode."); this.dh.vrSettings.seated = true; this.headIsTracking = false; diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java index b8d020266..7a191d60a 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/nullvr/NullVRStereoRenderer.java @@ -21,9 +21,9 @@ public Tuple getRenderTextureSizes() { return this.resolution; } else { this.resolution = new Tuple<>(2048, 2048); - System.out.println("NullVR Render Res " + this.resolution.getA() + " x " + this.resolution.getB()); + org.vivecraft.common.utils.Utils.logger.info("NullVR Render Res {} x {}", this.resolution.getA(), this.resolution.getB()); this.ss = -1.0F; - System.out.println("NullVR Supersampling: " + this.ss); + org.vivecraft.common.utils.Utils.logger.info("NullVR Supersampling: {}", this.ss); return this.resolution; } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java index a23282d07..427ee3fe4 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/MCOpenVR.java @@ -236,11 +236,11 @@ public boolean init() { } if (OpenVR.VRInput == null) { - System.out.println("Controller input not available. Forcing seated mode."); + org.vivecraft.common.utils.Utils.logger.info("Controller input not available. Forcing seated mode."); this.dh.vrSettings.seated = true; } - System.out.println("OpenVR initialized & VR connected."); + org.vivecraft.common.utils.Utils.logger.info("OpenVR initialized & VR connected."); this.deviceVelocity = new Vec3[64]; for (int i = 0; i < this.poseMatrices.length; ++i) { @@ -252,36 +252,36 @@ public boolean init() { if (ClientDataHolderVR.katvr) { try { - System.out.println("Waiting for KATVR...."); + org.vivecraft.common.utils.Utils.logger.info("Waiting for KATVR...."); Utils.unpackNatives("katvr"); NativeLibrary.addSearchPath("WalkerBase.dll", (new File("openvr/katvr")).getAbsolutePath()); jkatvr.Init(1); jkatvr.Launch(); if (jkatvr.CheckForLaunch()) { - System.out.println("KATVR Loaded"); + org.vivecraft.common.utils.Utils.logger.info("KATVR Loaded"); } else { - System.out.println("KATVR Failed to load"); + org.vivecraft.common.utils.Utils.logger.warn("KATVR Failed to load"); } } catch (Exception exception1) { - System.out.println("KATVR crashed: " + exception1.getMessage()); + org.vivecraft.common.utils.Utils.logger.error("KATVR crashed: {}", exception1.getMessage()); } } if (ClientDataHolderVR.infinadeck) { try { - System.out.println("Waiting for Infinadeck...."); + org.vivecraft.common.utils.Utils.logger.info("Waiting for Infinadeck...."); Utils.unpackNatives("infinadeck"); NativeLibrary.addSearchPath("InfinadeckAPI.dll", (new File("openvr/infinadeck")).getAbsolutePath()); if (jinfinadeck.InitConnection()) { jinfinadeck.CheckConnection(); - System.out.println("Infinadeck Loaded"); + org.vivecraft.common.utils.Utils.logger.info("Infinadeck Loaded"); } else { - System.out.println("Infinadeck Failed to load"); + org.vivecraft.common.utils.Utils.logger.warn("Infinadeck Failed to load"); } } catch (Exception exception) { - System.out.println("Infinadeck crashed: " + exception.getMessage()); + org.vivecraft.common.utils.Utils.logger.error("Infinadeck crashed: {}", exception.getMessage()); } } @@ -694,7 +694,7 @@ private void initializeOpenVR() { } if (OpenVR.VRSystem != null && !this.isError()) { - System.out.println("OpenVR System Initialized OK."); + org.vivecraft.common.utils.Utils.logger.info("OpenVR System Initialized OK."); this.hmdTrackedDevicePoses = TrackedDevicePose.calloc(64); this.poseMatrices = new Matrix4f[64]; @@ -743,10 +743,10 @@ private void initOpenVRCompositor() { VRCompositor_SetTrackingSpace(1); try (MemoryStack stack = MemoryStack.stackPush()) { var pointer = stack.calloc(20); - System.out.println("TrackingSpace: " + VRCompositor_GetTrackingSpace()); + org.vivecraft.common.utils.Utils.logger.info("TrackingSpace: {}", VRCompositor_GetTrackingSpace()); VRSystem_GetStringTrackedDeviceProperty(0, 1005, pointer, this.hmdErrorStore); String s = memUTF8NullTerminated(pointer); - System.out.println("Device manufacturer is: " + s); + org.vivecraft.common.utils.Utils.logger.info("Device manufacturer is: {}", s); this.detectedHardware = HardwareType.fromManufacturer(s); } this.dh.vrSettings.loadOptions(); @@ -754,7 +754,7 @@ private void initOpenVRCompositor() { } if (OpenVR.VRCompositor == null) { - System.out.println("Skipping VR Compositor..."); + org.vivecraft.common.utils.Utils.logger.info("Skipping VR Compositor..."); } this.texBounds.uMax(1.0F); @@ -767,7 +767,7 @@ private void initOpenVRCompositor() { this.texType1.eColorSpace(VR.EColorSpace_ColorSpace_Gamma); this.texType1.eType(VR.ETextureType_TextureType_OpenGL); this.texType1.handle(-1); - System.out.println("OpenVR Compositor initialized OK."); + org.vivecraft.common.utils.Utils.logger.info("OpenVR Compositor initialized OK."); } private void installApplicationManifest(boolean force) throws RenderConfigException { @@ -786,15 +786,15 @@ private void installApplicationManifest(boolean force) throws RenderConfigExcept Map map = (new Gson()).fromJson(new FileReader(file1), Map.class); s = ((Map) ((List) map.get("applications")).get(0)).get("app_key").toString(); } catch (Exception exception1) { - System.out.println("Error reading appkey from manifest"); + org.vivecraft.common.utils.Utils.logger.error("Error reading appkey from manifest"); exception1.printStackTrace(); return; } - System.out.println("Appkey: " + s); + org.vivecraft.common.utils.Utils.logger.info("Appkey: {}", s); if (!force && VRApplications_IsApplicationInstalled(s)) { - System.out.println("Application manifest already installed"); + org.vivecraft.common.utils.Utils.logger.info("Application manifest already installed"); } else { int i = VRApplications_AddApplicationManifest(file1.getAbsolutePath(), true); @@ -812,12 +812,12 @@ private void installApplicationManifest(boolean force) throws RenderConfigExcept } String error = VRApplications_GetApplicationsErrorNameFromEnum(i) + (hasInvalidChars ? "\nInvalid characters in path: \n" : "\n"); - System.out.println("Failed to install application manifest: " + error + file1.getAbsolutePath()); + org.vivecraft.common.utils.Utils.logger.error("Failed to install application manifest: {}{}", error, file1.getAbsolutePath()); throw new RenderConfigException("Failed to install application manifest", Component.empty().append(error).append(pathFormatted)); } - System.out.println("Application manifest installed successfully"); + org.vivecraft.common.utils.Utils.logger.info("Application manifest installed successfully"); } int j; @@ -826,7 +826,7 @@ private void installApplicationManifest(boolean force) throws RenderConfigExcept String s1 = ManagementFactory.getRuntimeMXBean().getName(); j = Integer.parseInt(s1.split("@")[0]); } catch (Exception exception) { - System.out.println("Error getting process id"); + org.vivecraft.common.utils.Utils.logger.error("Error getting process id"); exception.printStackTrace(); return; } @@ -834,9 +834,9 @@ private void installApplicationManifest(boolean force) throws RenderConfigExcept int k = VRApplications_IdentifyApplication(j, s); if (k != 0) { - System.out.println("Failed to identify application: " + VRApplications_GetApplicationsErrorNameFromEnum(k)); + org.vivecraft.common.utils.Utils.logger.warn("Failed to identify application: {}", VRApplications_GetApplicationsErrorNameFromEnum(k)); } else { - System.out.println("Application identified successfully"); + org.vivecraft.common.utils.Utils.logger.info("Application identified successfully"); } } } @@ -1043,7 +1043,7 @@ private void updatePose() { int i = VRCompositor_WaitGetPoses(this.hmdTrackedDevicePoses, null); if (i > 0) { - System.out.println("Compositor Error: GetPoseError " + OpenVRStereoRenderer.getCompostiorError(i)); + org.vivecraft.common.utils.Utils.logger.error("Compositor Error: GetPoseError {}", OpenVRStereoRenderer.getCompostiorError(i)); } if (i == 101) { diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRHapticScheduler.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRHapticScheduler.java index 00b1348a9..853125a67 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRHapticScheduler.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRHapticScheduler.java @@ -11,7 +11,7 @@ private void triggerHapticPulse(ControllerType controller, float durationSeconds int i = VRInput.VRInput_TriggerHapticVibrationAction(MCOpenVR.get().getHapticHandle(controller), 0.0F, durationSeconds, frequency, amplitude, 0L); if (i != 0) { - System.out.println("Error triggering haptic: " + MCOpenVR.getInputErrorName(i)); + org.vivecraft.common.utils.Utils.logger.error("Error triggering haptic: {}", MCOpenVR.getInputErrorName(i)); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java index 1d386114e..98b895e95 100644 --- a/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java +++ b/common/src/main/java/org/vivecraft/client_vr/provider/openvr_lwjgl/OpenVRStereoRenderer.java @@ -43,9 +43,9 @@ public Tuple getRenderTextureSizes() { var intbyreference1 = stack.callocInt(1); VRSystem_GetRecommendedRenderTargetSize(intbyreference, intbyreference1); this.resolution = new Tuple<>(intbyreference.get(0), intbyreference1.get(0)); - System.out.println("OpenVR Render Res " + this.resolution.getA() + " x " + this.resolution.getB()); + org.vivecraft.common.utils.Utils.logger.info("OpenVR Render Res {} x {}", this.resolution.getA(), this.resolution.getB()); this.ss = this.openvr.getSuperSampling(); - System.out.println("OpenVR Supersampling: " + this.ss); + org.vivecraft.common.utils.Utils.logger.info("OpenVR Supersampling: {}", this.ss); } for (int i = 0; i < 2; ++i) { @@ -53,7 +53,7 @@ public Tuple getRenderTextureSizes() { int j = this.hiddenMeshes[i].unTriangleCount(); if (j <= 0) { - System.out.println("No stencil mesh found for eye " + i); + org.vivecraft.common.utils.Utils.logger.info("No stencil mesh found for eye {}", i); } else { this.hiddenMesheVertecies[i] = new float[this.hiddenMeshes[i].unTriangleCount() * 3 * 2]; MemoryUtil.memFloatBuffer(MemoryUtil.memAddress(this.hiddenMeshes[i].pVertexData()), this.hiddenMesheVertecies[i].length).get(this.hiddenMesheVertecies[i]); @@ -63,7 +63,7 @@ public Tuple getRenderTextureSizes() { this.hiddenMesheVertecies[i][k + 1] *= (float) this.resolution.getB(); } - System.out.println("Stencil mesh loaded for eye " + i); + org.vivecraft.common.utils.Utils.logger.info("Stencil mesh loaded for eye {}", i); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java index eb16439fa..941d60140 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/ShaderHelper.java @@ -4,6 +4,7 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20C; import org.lwjgl.opengl.GL43C; +import org.vivecraft.common.utils.Utils; import java.util.List; @@ -37,10 +38,14 @@ public static int checkGLError(String par1Str) { int i = GL11.glGetError(); if (i != 0) { - String s = ""; - System.out.println("########## GL ERROR ##########"); - System.out.println("@ " + par1Str); - System.out.println(i + ": " + s); + Utils.logger.error( + """ + ########## GL ERROR ########## + "@ %s" + "%d" + """ + .formatted(par1Str, i) + ); } return i; @@ -91,12 +96,12 @@ public static int initShaders(String vertexShaderGLSL, String fragmentShaderGLSL String log = GL20C.glGetShaderInfoLog(i); if (!log.isEmpty()) { - System.out.println("Shader compilation log: " + log); + Utils.logger.info("Shader compilation log: {}", log); return 0; } String log2 = GL20C.glGetShaderInfoLog(j); if (!log2.isEmpty()) { - System.out.println("Shader compilation log: " + log2); + Utils.logger.info("Shader compilation log: {}", log2); return 0; } else { return k; diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java index e321987f0..a7757ed9c 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VREffectsHelper.java @@ -123,7 +123,7 @@ public static void drawEyeStencil(boolean flag1) { if (wasStencilOn && !showedStencilMessage && dataHolder.vrSettings.vrUseStencil && dataHolder.vrSettings.showChatMessageStencil) { showedStencilMessage = true; - mc.gui.getChat().addMessage(Component.translatable("vivecraft.messages.stencil", + Utils.printChatMessage(Component.translatable("vivecraft.messages.stencil", Component.translatable("vivecraft.messages.3options", Component.translatable("options.title"), Component.translatable("vivecraft.options.screen.main"), @@ -699,7 +699,7 @@ public static void renderGuiLayer(float partialTicks, boolean depthAlways, PoseS try { renderTechjarsAwesomeMainMenuRoom(poseStack); } catch (Exception exception) { - System.out.println("Error rendering main menu world, unloading to prevent more errors"); + org.vivecraft.common.utils.Utils.logger.error("Error rendering main menu world, unloading to prevent more errors"); exception.printStackTrace(); dataHolder.menuWorldRenderer.destroy(); } diff --git a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java index b8adb4bc2..1467909b4 100644 --- a/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java +++ b/common/src/main/java/org/vivecraft/client_vr/render/helpers/VRPassHelper.java @@ -17,6 +17,7 @@ import org.vivecraft.client_vr.render.RenderPass; import org.vivecraft.client_vr.render.VRShaders; import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import org.vivecraft.mod_compat_vr.iris.IrisHelper; import org.vivecraft.mod_compat_vr.optifine.OptifineHelper; @@ -219,10 +220,10 @@ public static void renderSingleView(RenderPass eye, float partialTicks, long nan } } - private static void checkGLError(String string) { + public static void checkGLError(String string) { int i = GlStateManager._getError(); if (i != 0) { - System.err.println(string + ": " + i); + Utils.logger.error("{}: {}", string, i); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/AutoCalibration.java b/common/src/main/java/org/vivecraft/client_vr/settings/AutoCalibration.java index e002f2df6..53a81364b 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/AutoCalibration.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/AutoCalibration.java @@ -3,6 +3,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import org.vivecraft.client.utils.LangHelper; +import org.vivecraft.client.utils.Utils; import org.vivecraft.client_vr.ClientDataHolderVR; public class AutoCalibration { @@ -13,7 +14,7 @@ public static void calibrateManual() { ClientDataHolderVR dataholder = ClientDataHolderVR.getInstance(); dataholder.vrSettings.manualCalibration = (float) dataholder.vr.hmdPivotHistory.averagePosition(0.5D).y; int i = (int) ((float) ((double) Math.round(100.0D * (double) getPlayerHeight() / (double) 1.52F))); - minecraft.gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.heightset", i))); + Utils.printChatMessage(Component.literal(LangHelper.get("vivecraft.messages.heightset", i))); dataholder.vrSettings.saveOptions(); } diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java b/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java index 422d74e4d..bfa032025 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/VRHotkeys.java @@ -41,19 +41,19 @@ public static boolean handleKeyboardInputs(int key, int scanCode, int action, in if (action == 1 && key == 344 && MethodHolder.isKeyDown(345)) { dataholder.vrSettings.storeDebugAim = true; - minecraft.gui.getChat().addMessage(Component.translatable("vivecraft.messages.showaim")); + Utils.printChatMessage(Component.translatable("vivecraft.messages.showaim")); flag = true; } if (action == 1 && key == 66 && MethodHolder.isKeyDown(345)) { dataholder.vrSettings.walkUpBlocks = !dataholder.vrSettings.walkUpBlocks; - minecraft.gui.getChat().addMessage(Component.translatable("vivecraft.messages.walkupblocks", dataholder.vrSettings.walkUpBlocks ? LangHelper.getYes() : LangHelper.getNo())); + Utils.printChatMessage(Component.translatable("vivecraft.messages.walkupblocks", dataholder.vrSettings.walkUpBlocks ? LangHelper.getYes() : LangHelper.getNo())); flag = true; } if (action == 1 && key == 73 && MethodHolder.isKeyDown(345)) { dataholder.vrSettings.inertiaFactor = dataholder.vrSettings.inertiaFactor.getNext(); - minecraft.gui.getChat().addMessage(Component.translatable("vivecraft.messages.playerinertia", Component.translatable(dataholder.vrSettings.inertiaFactor.getLangKey()))); + Utils.printChatMessage(Component.translatable("vivecraft.messages.playerinertia", Component.translatable(dataholder.vrSettings.inertiaFactor.getLangKey()))); flag = true; } @@ -61,10 +61,10 @@ public static boolean handleKeyboardInputs(int key, int scanCode, int action, in if (action == 1 && key == 82 && MethodHolder.isKeyDown(345)) { if (dataholder.vrPlayer.isTeleportOverridden()) { dataholder.vrPlayer.setTeleportOverride(false); - minecraft.gui.getChat().addMessage(Component.translatable("vivecraft.messages.teleportdisabled")); + Utils.printChatMessage(Component.translatable("vivecraft.messages.teleportdisabled")); } else { dataholder.vrPlayer.setTeleportOverride(true); - minecraft.gui.getChat().addMessage(Component.translatable("vivecraft.messages.teleportenabled")); + Utils.printChatMessage(Component.translatable("vivecraft.messages.teleportenabled")); } flag = true; @@ -182,13 +182,13 @@ public static void handleMRKeys() { dataholder.vrSettings.saveOptions(); if (dataholder.vr.mrMovingCamActive) { - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.coords", dataholder.vrSettings.mrMovingCamOffsetX, dataholder.vrSettings.mrMovingCamOffsetY, dataholder.vrSettings.mrMovingCamOffsetZ))); + Utils.printChatMessage(Component.literal(LangHelper.get("vivecraft.messages.coords", dataholder.vrSettings.mrMovingCamOffsetX, dataholder.vrSettings.mrMovingCamOffsetY, dataholder.vrSettings.mrMovingCamOffsetZ))); Angle angle = dataholder.vrSettings.mrMovingCamOffsetRotQuat.toEuler(); - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.angles", angle.getPitch(), angle.getYaw(), angle.getRoll()))); + Utils.printChatMessage(Component.literal(LangHelper.get("vivecraft.messages.angles", angle.getPitch(), angle.getYaw(), angle.getRoll()))); } else { - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.coords", dataholder.vrSettings.vrFixedCamposX, dataholder.vrSettings.vrFixedCamposY, dataholder.vrSettings.vrFixedCamposZ))); + Utils.printChatMessage(Component.literal(LangHelper.get("vivecraft.messages.coords", dataholder.vrSettings.vrFixedCamposX, dataholder.vrSettings.vrFixedCamposY, dataholder.vrSettings.vrFixedCamposZ))); Angle angle1 = dataholder.vrSettings.vrFixedCamrotQuat.toEuler(); - Minecraft.getInstance().gui.getChat().addMessage(Component.literal(LangHelper.get("vivecraft.messages.angles", angle1.getPitch(), angle1.getYaw(), angle1.getRoll()))); + Utils.printChatMessage(Component.literal(LangHelper.get("vivecraft.messages.angles", angle1.getPitch(), angle1.getYaw(), angle1.getRoll()))); } } } diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java index a3fb1d52c..35f5aaf13 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/VRSettings.java @@ -14,8 +14,6 @@ import net.minecraft.util.Mth; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Triple; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.vivecraft.client.utils.LangHelper; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; @@ -25,6 +23,7 @@ import org.vivecraft.client_vr.settings.profile.ProfileManager; import org.vivecraft.client_vr.settings.profile.ProfileReader; import org.vivecraft.client_vr.settings.profile.ProfileWriter; +import org.vivecraft.common.utils.Utils; import org.vivecraft.common.utils.math.Angle; import org.vivecraft.common.utils.math.Quaternion; import org.vivecraft.common.utils.math.Vector3; @@ -43,7 +42,6 @@ public class VRSettings { public static final int VERSION = 2; - public static final Logger logger = LogManager.getLogger(); public static VRSettings inst; public JsonObject defaults = new JsonObject(); public static final int UNKNOWN_VERSION = 0; @@ -577,7 +575,7 @@ private Object loadOption(String name, String value, Object currentValue, VrOpti } // If we get here, the value wasn't interpreted - logger.warn("Don't know how to load VR option " + name + " with type " + type.getSimpleName()); + Utils.logger.warn("Don't know how to load VR option {} with type {}", name, type.getSimpleName()); return null; } @@ -623,7 +621,7 @@ private String saveOption(String name, Object obj, VrOptions option, Class ty } // If we get here, the object wasn't interpreted - logger.warn("Don't know how to save VR option " + name + " with type " + type.getSimpleName()); + Utils.logger.warn("Don't know how to save VR option {} with type {}", name, type.getSimpleName()); return null; } @@ -697,7 +695,7 @@ private Object loadDefault(String name, String value, VrOptions option, Class } // If we get here, the value wasn't interpreted - logger.warn("Don't know how to load default VR option " + name + " with type " + type.getSimpleName()); + Utils.logger.warn("Don't know how to load default VR option {} with type {}", name, type.getSimpleName()); return null; } @@ -738,7 +736,7 @@ public void loadDefault(VrOptions option) { field.set(this, obj); } } catch (Exception ex) { - logger.warn("Failed to load default VR option: " + option); + Utils.logger.warn("Failed to load default VR option: {}", option); ex.printStackTrace(); } } @@ -790,7 +788,7 @@ public void loadOptions(JsonObject theProfiles) { field.set(this, obj); } } catch (Exception var7) { - logger.warn("Skipping bad VR option: " + var2); + Utils.logger.warn("Skipping bad VR option: {}", var2); var7.printStackTrace(); } } @@ -798,7 +796,7 @@ public void loadOptions(JsonObject theProfiles) { preservedSettingMap = optionsVRReader.getData(); optionsVRReader.close(); } catch (Exception var8) { - logger.warn("Failed to load VR options!"); + Utils.logger.warn("Failed to load VR options!"); var8.printStackTrace(); } } @@ -846,14 +844,14 @@ private void saveOptions(JsonObject theProfiles) { var5.println(name + ":" + value); } } catch (Exception ex) { - logger.warn("Failed to save VR option: " + name); + Utils.logger.warn("Failed to save VR option: {}", name); ex.printStackTrace(); } } var5.close(); } catch (Exception var3) { - logger.warn("Failed to save VR options: " + var3.getMessage()); + Utils.logger.warn("Failed to save VR options: {}", var3.getMessage()); var3.printStackTrace(); } } @@ -901,7 +899,7 @@ public String getButtonDisplayString(VrOptions par1EnumOptions) { return var4 + obj.toString(); } } catch (Exception ex) { - System.out.println("Failed to get VR option display string: " + par1EnumOptions); + Utils.logger.info("Failed to get VR option display string: {}", par1EnumOptions); ex.printStackTrace(); } @@ -923,7 +921,7 @@ public float getOptionFloatValue(VrOptions par1EnumOptions) { return Objects.requireNonNullElse(par1EnumOptions.getOptionFloatValue(value), value); } catch (Exception ex) { - System.out.println("Failed to get VR option float value: " + par1EnumOptions); + Utils.logger.info("Failed to get VR option float value: {}", par1EnumOptions); ex.printStackTrace(); } @@ -950,14 +948,14 @@ public void setOptionValue(VrOptions par1EnumOptions) { } else if (OptionEnum.class.isAssignableFrom(type)) { field.set(this, ((OptionEnum) field.get(this)).getNext()); } else { - logger.warn("Don't know how to set VR option " + mapping.getMiddle() + " with type " + type.getSimpleName()); + Utils.logger.warn("Don't know how to set VR option {} with type {}", mapping.getMiddle(), type.getSimpleName()); return; } par1EnumOptions.onOptionChange(); this.saveOptions(); } catch (Exception ex) { - System.out.println("Failed to set VR option: " + par1EnumOptions); + Utils.logger.info("Failed to set VR option: {}", par1EnumOptions); ex.printStackTrace(); } } @@ -987,7 +985,7 @@ public void setOptionFloatValue(VrOptions par1EnumOptions, float par2) { par1EnumOptions.onOptionChange(); this.saveOptions(); } catch (Exception ex) { - System.out.println("Failed to set VR option float value: " + par1EnumOptions); + Utils.logger.error("Failed to set VR option float value: {}", par1EnumOptions); ex.printStackTrace(); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/settings/profile/ProfileManager.java b/common/src/main/java/org/vivecraft/client_vr/settings/profile/ProfileManager.java index 0f62eb2e0..1420572fc 100644 --- a/common/src/main/java/org/vivecraft/client_vr/settings/profile/ProfileManager.java +++ b/common/src/main/java/org/vivecraft/client_vr/settings/profile/ProfileManager.java @@ -1,6 +1,7 @@ package org.vivecraft.client_vr.settings.profile; import com.google.gson.*; +import org.vivecraft.common.utils.Utils; import java.io.*; import java.nio.charset.StandardCharsets; @@ -65,7 +66,7 @@ public static synchronized void load() { validateProfiles(); loaded = true; } catch (Exception exception1) { - System.out.println("FAILED to read VR profile settings!"); + Utils.logger.error("FAILED to read VR profile settings!"); exception1.printStackTrace(); loaded = false; } diff --git a/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java b/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java index 62d996189..3861f5fd8 100644 --- a/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java +++ b/common/src/main/java/org/vivecraft/client_vr/utils/LoaderUtils.java @@ -1,5 +1,7 @@ package org.vivecraft.client_vr.utils; +import org.vivecraft.common.utils.Utils; + import java.io.File; import java.io.IOException; import java.net.URI; @@ -20,7 +22,7 @@ public static void init() { vivecraftFile = toFile(ZipFileUrl.toURI()); ZipFile = new java.util.zip.ZipFile(vivecraftFile); } catch (Exception e) { - System.out.print("Error getting Vivecraft library: " + e.getLocalizedMessage()); + Utils.logger.error("Error getting Vivecraft library: {}", e.getLocalizedMessage()); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/utils/external/jinfinadeck.java b/common/src/main/java/org/vivecraft/client_vr/utils/external/jinfinadeck.java index e4c15988b..9e471314a 100644 --- a/common/src/main/java/org/vivecraft/client_vr/utils/external/jinfinadeck.java +++ b/common/src/main/java/org/vivecraft/client_vr/utils/external/jinfinadeck.java @@ -6,6 +6,7 @@ import com.sun.jna.ptr.DoubleByReference; import com.sun.jna.ptr.FloatByReference; import com.sun.jna.ptr.IntByReference; +import org.vivecraft.common.utils.Utils; public class jinfinadeck implements Library { public static final String INFINADECK_LIBRARY_NAME = "InfinadeckAPI.dll"; @@ -62,7 +63,7 @@ public static void query() { ismoving = GetTreadmillRunState(); yaw *= 57.296F; } catch (Exception exception) { - System.out.println("Infinadeck Error: " + exception.getMessage()); + Utils.logger.error("Infinadeck Error: {}", exception.getMessage()); } } diff --git a/common/src/main/java/org/vivecraft/client_vr/utils/external/jkatvr.java b/common/src/main/java/org/vivecraft/client_vr/utils/external/jkatvr.java index e0d5d3a9f..785056120 100644 --- a/common/src/main/java/org/vivecraft/client_vr/utils/external/jkatvr.java +++ b/common/src/main/java/org/vivecraft/client_vr/utils/external/jkatvr.java @@ -6,6 +6,7 @@ import com.sun.jna.ptr.DoubleByReference; import com.sun.jna.ptr.FloatByReference; import com.sun.jna.ptr.IntByReference; +import org.vivecraft.common.utils.Utils; public class jkatvr implements Library { public static final String KATVR_LIBRARY_NAME = "WalkerBase.dll"; @@ -43,7 +44,7 @@ public static void query() { ismoving = is.getValue(); yaw = yaw / 1024.0F * 360.0F; } catch (Exception exception) { - System.out.println("KATVR Error: " + exception.getMessage()); + Utils.logger.error("KATVR Error: {}", exception.getMessage()); } } diff --git a/common/src/main/java/org/vivecraft/common/utils/Utils.java b/common/src/main/java/org/vivecraft/common/utils/Utils.java index 781d9b962..0b3e7d9ec 100644 --- a/common/src/main/java/org/vivecraft/common/utils/Utils.java +++ b/common/src/main/java/org/vivecraft/common/utils/Utils.java @@ -11,7 +11,12 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.ParametersAreNonnullByDefault; + +@ParametersAreNonnullByDefault public class Utils { public static AABB getEntityHeadHitbox(Entity entity, double inflate) { @@ -54,4 +59,33 @@ public static AABB getEntityHeadHitbox(Entity entity, double inflate) { } return null; } + + /** + * Vivecraft's logger for printing to console. + */ + public static final Logger logger = LoggerFactory.getLogger("Vivecraft"); + + public static void printStackIfContainsClass(String className) { + StackTraceElement[] astacktraceelement = Thread.currentThread().getStackTrace(); + boolean flag = false; + + for (StackTraceElement stacktraceelement : astacktraceelement) { + if (stacktraceelement.getClassName().equals(className)) { + flag = true; + break; + } + } + + if (flag) { + Thread.dumpStack(); + } + } + + public static long microTime() { + return System.nanoTime() / 1000L; + } + + public static long milliTime() { + return System.nanoTime() / 1000000L; + } } diff --git a/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java b/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java index e50eb371a..27ab0537a 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/main/MainMixin.java @@ -11,6 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.vivecraft.client_vr.ClientDataHolderVR; +import org.vivecraft.common.utils.Utils; @Mixin(Main.class) public class MainMixin { @@ -29,14 +30,14 @@ public class MainMixin { ClientDataHolderVR.kiosk = optionset.has("kiosk"); if (ClientDataHolderVR.kiosk) { - System.out.println("Setting kiosk"); + Utils.logger.info("Setting kiosk"); } if (ClientDataHolderVR.kiosk) { ClientDataHolderVR.viewonly = optionset.has("viewonly"); if (ClientDataHolderVR.viewonly) { - System.out.println("Setting viewonly"); + Utils.logger.info("Setting viewonly"); } } diff --git a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java index f991369f9..0c2f996a6 100644 --- a/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client/renderer/entity/PlayerRendererMixin.java @@ -18,7 +18,7 @@ import org.vivecraft.client.extensions.EntityRenderDispatcherExtension; import org.vivecraft.client.extensions.RenderLayerExtension; import org.vivecraft.client.utils.RenderLayerTypes; -import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -100,7 +100,7 @@ public boolean addLayer(RenderLayer renderLayer) { @Unique private void addLayerClone(RenderLayer renderLayer, LivingEntityRenderer target) { try { - VRSettings.logger.warn("Copying layer: {} with Object.copy, this could cause issues", renderLayer.getClass()); + Utils.logger.warn("Copying layer: {} with Object.copy, this could cause issues", renderLayer.getClass()); RenderLayer newLayer = (RenderLayer) ((RenderLayerExtension) renderLayer).clone(); newLayer.renderer = target; target.addLayer(newLayer); diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java index 66d09fbb8..017a4b7d2 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/MinecraftVRMixin.java @@ -2,7 +2,6 @@ import com.mojang.blaze3d.pipeline.MainTarget; import com.mojang.blaze3d.pipeline.RenderTarget; -import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.shaders.ProgramManager; @@ -347,9 +346,9 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { this.profiler.push("setupRenderConfiguration"); try { - this.vivecraft$checkGLError("pre render setup "); + VRPassHelper.checkGLError("pre render setup"); ClientDataHolderVR.getInstance().vrRenderer.setupRenderConfiguration(); - this.vivecraft$checkGLError("post render setup "); + VRPassHelper.checkGLError("post render setup"); } catch (RenderConfigException renderConfigException) { vivecraft$switchVRState(false); VRState.destroyVR(true); @@ -430,7 +429,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { guiGraphics.flush(); } this.profiler.pop(); - this.vivecraft$checkGLError("post 2d "); + VRPassHelper.checkGLError("post 2d"); // render the different vr passes List list = ClientDataHolderVR.getInstance().vrRenderer.getRenderPasses(); @@ -489,10 +488,10 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { try { ClientDataHolderVR.getInstance().vrRenderer.endFrame(); } catch (RenderConfigException exception) { - VRSettings.logger.error(exception.toString()); + org.vivecraft.common.utils.Utils.logger.error(exception.toString()); } this.profiler.pop(); - this.vivecraft$checkGLError("post submit "); + VRPassHelper.checkGLError("post submit"); } } @@ -504,7 +503,7 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { this.profiler.push("mirror"); this.vivecraft$copyToMirror(); this.vivecraft$drawNotifyMirror(); - this.vivecraft$checkGLError("post-mirror "); + VRPassHelper.checkGLError("post-mirror"); } } @@ -685,8 +684,8 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { final File file2 = new File(file1, "world" + i + ".mmw"); if (!file2.exists()) { - VRSettings.logger.info("Exporting world... area size: " + size); - VRSettings.logger.info("Saving to " + file2.getAbsolutePath()); + org.vivecraft.common.utils.Utils.logger.info("Exporting world... area size: " + size); + org.vivecraft.common.utils.Utils.logger.info("Saving to " + file2.getAbsolutePath()); if (isLocalServer()) { final Level level = getSingleplayerServer().getLevel(player.level().dimension()); @@ -912,14 +911,6 @@ public abstract class MinecraftVRMixin implements MinecraftExtension { } } - @Unique - private void vivecraft$checkGLError(String string) { - // TODO optifine - if (GlStateManager._getError() != 0) { - System.err.println(string); - } - } - @Unique private void vivecraft$copyToMirror() { if (ClientDataHolderVR.getInstance().vrSettings.displayMirrorMode == VRSettings.MirrorMode.OFF diff --git a/common/src/main/java/org/vivecraft/mixin/client_vr/blaze3d/audio/LibraryVRMixin.java b/common/src/main/java/org/vivecraft/mixin/client_vr/blaze3d/audio/LibraryVRMixin.java index affd5ca0e..e04b85fff 100644 --- a/common/src/main/java/org/vivecraft/mixin/client_vr/blaze3d/audio/LibraryVRMixin.java +++ b/common/src/main/java/org/vivecraft/mixin/client_vr/blaze3d/audio/LibraryVRMixin.java @@ -1,26 +1,19 @@ package org.vivecraft.mixin.client_vr.blaze3d.audio; -import com.mojang.blaze3d.audio.Library; -import org.slf4j.Logger; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.vivecraft.client_vr.ClientDataHolderVR; import org.vivecraft.client_vr.VRState; +import org.vivecraft.common.utils.Utils; -@Mixin(Library.class) +@Mixin(com.mojang.blaze3d.audio.Library.class) public class LibraryVRMixin { - @Shadow - @Final - static Logger LOGGER; - @ModifyVariable(method = "init", at = @At("HEAD"), argsOnly = true) private boolean vivecraft$shouldDoHRTF(boolean vanillaHRTF) { if (VRState.vrRunning) { // don't force HRTF in nonvr - LOGGER.info("enabling HRTF: {}", ClientDataHolderVR.getInstance().vrSettings.hrtfSelection >= 0); + Utils.logger.info("enabling HRTF: {}", ClientDataHolderVR.getInstance().vrSettings.hrtfSelection >= 0); return ClientDataHolderVR.getInstance().vrSettings.hrtfSelection >= 0; } return vanillaHRTF; diff --git a/common/src/main/java/org/vivecraft/mod_compat_vr/iris/IrisHelper.java b/common/src/main/java/org/vivecraft/mod_compat_vr/iris/IrisHelper.java index 4f09c3801..e1bcc4abd 100644 --- a/common/src/main/java/org/vivecraft/mod_compat_vr/iris/IrisHelper.java +++ b/common/src/main/java/org/vivecraft/mod_compat_vr/iris/IrisHelper.java @@ -4,6 +4,7 @@ import net.coderbot.iris.pipeline.WorldRenderingPipeline; import net.irisshaders.iris.api.v0.IrisApi; import org.vivecraft.client_xr.render_pass.RenderPassManager; +import org.vivecraft.common.utils.Utils; import java.io.IOException; @@ -19,7 +20,7 @@ public static void reload() { RenderPassManager.setVanillaRenderPass(); Iris.reload(); } catch (IOException e) { - System.err.println("Error reloading shaders on Frame Buffer reinit"); + Utils.logger.error("Error reloading shaders on Frame Buffer reinit"); e.printStackTrace(); } } diff --git a/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java b/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java index 614c1858d..a7fd06029 100644 --- a/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java +++ b/common/src/main/java/org/vivecraft/mod_compat_vr/optifine/OptifineHelper.java @@ -6,7 +6,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.phys.Vec3; -import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -60,10 +60,10 @@ public static boolean isOptifineLoaded() { // check for optifine with a class search try { Class.forName("net.optifine.Config"); - VRSettings.logger.info("Vivecraft: Optifine detected"); + Utils.logger.info("Optifine detected"); optifineLoaded = true; } catch (ClassNotFoundException ignore) { - VRSettings.logger.info("Vivecraft: Optifine not detected"); + Utils.logger.info("Optifine not detected"); optifineLoaded = false; } if (optifineLoaded) { @@ -337,13 +337,13 @@ private static void init() { vertexRenderPositions = null; } } catch (ClassNotFoundException e) { - VRSettings.logger.error("Optifine detected, but couldn't load class: {}", e.getMessage()); + Utils.logger.error("Optifine detected, but couldn't load class: {}", e.getMessage()); optifineLoaded = false; } catch (NoSuchMethodException e) { - VRSettings.logger.error("Optifine detected, but couldn't load Method: {}", e.getMessage()); + Utils.logger.error("Optifine detected, but couldn't load Method: {}", e.getMessage()); optifineLoaded = false; } catch (NoSuchFieldException e) { - VRSettings.logger.error("Optifine detected, but couldn't load Field: {}", e.getMessage()); + Utils.logger.error("Optifine detected, but couldn't load Field: {}", e.getMessage()); } } } diff --git a/common/src/main/java/org/vivecraft/mod_compat_vr/sodium/SodiumHelper.java b/common/src/main/java/org/vivecraft/mod_compat_vr/sodium/SodiumHelper.java index 0fc305528..dccfe9f90 100644 --- a/common/src/main/java/org/vivecraft/mod_compat_vr/sodium/SodiumHelper.java +++ b/common/src/main/java/org/vivecraft/mod_compat_vr/sodium/SodiumHelper.java @@ -5,7 +5,7 @@ import net.minecraft.client.model.geom.ModelPart; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import org.vivecraft.client.Xplat; -import org.vivecraft.client_vr.settings.VRSettings; +import org.vivecraft.common.utils.Utils; import java.lang.reflect.Field; @@ -49,7 +49,7 @@ public static void copyModelCuboidUV(ModelPart source, ModelPart dest, int sourc } catch (ClassNotFoundException ignored) { return; } catch (NoSuchFieldException e) { - VRSettings.logger.error("sodium version has ModelCuboids, but field was not found. VR hands will probably look wrong"); + Utils.logger.error("sodium version has ModelCuboids, but field was not found. VR hands will probably look wrong"); return; } } @@ -63,7 +63,7 @@ public static void copyModelCuboidUV(ModelPart source, ModelPart dest, int sourc destQuad.textures[i].y = sourceQuad.textures[i].y; } } catch (IllegalAccessException | ClassCastException ignored) { - VRSettings.logger.error("sodium version has ModelCuboids, but field has wrong type. VR hands will probably look wrong"); + Utils.logger.error("sodium version has ModelCuboids, but field has wrong type. VR hands will probably look wrong"); hasModelCuboid = false; } } diff --git a/common/src/main/java/org/vivecraft/server/AimFixHandler.java b/common/src/main/java/org/vivecraft/server/AimFixHandler.java index 4b470ec9f..4381dca5e 100644 --- a/common/src/main/java/org/vivecraft/server/AimFixHandler.java +++ b/common/src/main/java/org/vivecraft/server/AimFixHandler.java @@ -12,6 +12,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.world.phys.Vec3; +import org.vivecraft.common.utils.Utils; import org.vivecraft.server.config.ServerConfig; public class AimFixHandler extends ChannelInboundHandlerAdapter { @@ -60,7 +61,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { serverplayer.eyeHeight = 0.0001F; serverviveplayer.offset = position.subtract(aimPos); if (ServerConfig.debug.get()) { - System.out.println("AimFix " + aimPos.x + " " + aimPos.y + " " + aimPos.z + " " + (float) Math.toDegrees(Math.asin(-dir.y)) + " " + (float) Math.toDegrees(Math.atan2(-dir.x, dir.z))); + Utils.logger.info("AimFix {} {} {}", aimPos, (float) Math.toDegrees(Math.asin(-dir.y)), (float) Math.toDegrees(Math.atan2(-dir.x, dir.z))); } } @@ -79,7 +80,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { if ((aimPos != null && !serverplayer.position().equals(aimPos)) || (aimPos == null && !serverplayer.position().equals(position))) { position = serverplayer.position(); if (ServerConfig.debug.get()) { - System.out.println("AimFix moved Player to " + position.x + " " + position.y + " " + position.z); + Utils.logger.info("AimFix moved Player to {}", position); } } diff --git a/common/src/main/java/org/vivecraft/server/ServerNetworking.java b/common/src/main/java/org/vivecraft/server/ServerNetworking.java index 94273ac7d..9a2e54a71 100644 --- a/common/src/main/java/org/vivecraft/server/ServerNetworking.java +++ b/common/src/main/java/org/vivecraft/server/ServerNetworking.java @@ -1,6 +1,5 @@ package org.vivecraft.server; -import com.mojang.logging.LogUtils; import io.netty.buffer.Unpooled; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; @@ -12,11 +11,11 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.player.Player; -import org.slf4j.Logger; import org.vivecraft.common.CommonDataHolder; import org.vivecraft.common.network.CommonNetworkHelper; import org.vivecraft.common.network.VrPlayerState; import org.vivecraft.common.network.packets.VivecraftDataPacket; +import org.vivecraft.common.utils.Utils; import org.vivecraft.mixin.server.ChunkMapAccessor; import org.vivecraft.server.config.ServerConfig; @@ -27,8 +26,6 @@ public class ServerNetworking { // temporarily stores the packets from legacy clients to assemble a complete VrPlayerState private final static Map> legacyDataMap = new HashMap<>(); - private static final Logger LOGGER = LogUtils.getLogger(); - public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetID, FriendlyByteBuf buffer, ServerGamePacketListenerImpl listener) { var playerEntity = listener.player; ServerVivePlayer vivePlayer = ServerVRPlayers.getVivePlayer(playerEntity); @@ -50,7 +47,7 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI String clientVivecraftVersion = parts[0]; if (ServerConfig.debug.get()) { - LOGGER.info("Vivecraft: player '{}' joined with {}", listener.player.getName().getString(), clientVivecraftVersion); + Utils.logger.info("player '{}' joined with {}", listener.player.getName().getString(), clientVivecraftVersion); } if (parts.length >= 3) { @@ -62,13 +59,13 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI && clientMinVersion <= CommonNetworkHelper.MAX_SUPPORTED_NETWORK_VERSION) { vivePlayer.networkVersion = Math.min(clientMaxVersion, CommonNetworkHelper.MAX_SUPPORTED_NETWORK_VERSION); if (ServerConfig.debug.get()) { - LOGGER.info("{} networking supported, using version {}", listener.player.getName().getString(), vivePlayer.networkVersion); + Utils.logger.info("{} networking supported, using version {}", listener.player.getName().getString(), vivePlayer.networkVersion); } } else { // unsupported version, send notification, and disregard listener.player.sendSystemMessage(Component.literal("Unsupported vivecraft version, VR features will not work")); if (ServerConfig.debug.get()) { - LOGGER.info("{} networking not supported. client range [{},{}], server range [{},{}]", + Utils.logger.info("{} networking not supported. client range [{},{}], server range [{},{}]", listener.player.getName().getString(), clientMinVersion, clientMaxVersion, @@ -81,7 +78,7 @@ public static void handlePacket(CommonNetworkHelper.PacketDiscriminators packetI // client didn't send a version, so it's a legacy client vivePlayer.networkVersion = -1; if (ServerConfig.debug.get()) { - LOGGER.info("{} using legacy networking", listener.player.getName().getString()); + Utils.logger.info("{} using legacy networking", listener.player.getName().getString()); } } diff --git a/common/src/main/java/org/vivecraft/server/config/ServerConfig.java b/common/src/main/java/org/vivecraft/server/config/ServerConfig.java index 8d4656599..2ba4669c6 100644 --- a/common/src/main/java/org/vivecraft/server/config/ServerConfig.java +++ b/common/src/main/java/org/vivecraft/server/config/ServerConfig.java @@ -85,7 +85,7 @@ public static void init(ConfigSpec.CorrectionListener listener) { if (listener == null) { listener = (action, path, incorrectValue, correctedValue) -> { if (incorrectValue != null) { - System.out.println("Corrected " + String.join(".", path) + ": was " + incorrectValue + ", is now " + correctedValue); + org.vivecraft.common.utils.Utils.logger.info("Corrected {}: was {}, is now {}", String.join(".", path), incorrectValue, correctedValue); } }; } diff --git a/common/src/main/resources/assets/vivecraft/lang/en_us.json b/common/src/main/resources/assets/vivecraft/lang/en_us.json index 8530533b3..61e96f817 100644 --- a/common/src/main/resources/assets/vivecraft/lang/en_us.json +++ b/common/src/main/resources/assets/vivecraft/lang/en_us.json @@ -314,6 +314,8 @@ "vivecraft.options.bowmode.vanilla": "Vanilla", "vivecraft.options.teleportlimit": "%d Blocks", "vivecraft.options.teleport": "Teleport", + "vivecraft.options.teleport.style": "Teleport style (RCTRL-M): %s", + "vivecraft.options.teleport.style.unknown": "Unknown teleport style requested: %s", "vivecraft.options.freemove": "Free Move", "vivecraft.options.menuworld.both": "Official & Custom", "vivecraft.options.menuworld.custom": "Custom Only",