From 7de33468b2fe1730c61dc821025b6ac4e0cda912 Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Wed, 9 Mar 2022 00:16:10 +0000 Subject: [PATCH] Freecam, Xray tweaks --- build.gradle.kts | 2 +- .../som/hibiscus/mixins/MixinDebugHud.java | 22 ++++++++++++ .../som/hibiscus/mixins/xray/MixinBlock.java | 2 +- .../som/hibiscus/features/visual/Freecam.kt | 6 +++- .../som/hibiscus/features/visual/Xray.kt | 36 +++++++++++++++++++ .../subsystems/tps/TPSDetectionSubsystem.kt | 7 ++-- .../hibiscus/subsystems/xray/XraySystem.kt | 21 +++++++---- .../MinecraftRenderPipelineProgress.kt | 1 + src/main/resources/hibiscus.mixins.json | 1 + 9 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 src/main/java/codes/som/hibiscus/mixins/MixinDebugHud.java diff --git a/build.gradle.kts b/build.gradle.kts index 3cd7a71..009091d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -62,7 +62,7 @@ dependencies { runtimeOnly("org.joml:joml:1.10.4") runtimeOnly("org.anarres:jcpp:1.4.14") - modImplementation(files("vendor/mods/baritone-unoptimized-fabric-1.8.2.jar")) + // modRuntimeOnly(files("vendor/mods/baritone-unoptimized-fabric-1.8.2.jar")) modImplementation(files("vendor/mods/iris-mc1.18.2-1.2.1-rc2-0cc372f0.jar")) modImplementation(files("vendor/mods/sodium-fabric-mc1.18.2-0.4.1+build.15.jar")) modRuntimeOnly(files("vendor/mods/lazydfu-0.1.2.jar")) diff --git a/src/main/java/codes/som/hibiscus/mixins/MixinDebugHud.java b/src/main/java/codes/som/hibiscus/mixins/MixinDebugHud.java new file mode 100644 index 0000000..da2f482 --- /dev/null +++ b/src/main/java/codes/som/hibiscus/mixins/MixinDebugHud.java @@ -0,0 +1,22 @@ +package codes.som.hibiscus.mixins; + +import codes.som.hibiscus.util.graphics.MinecraftRenderPipelineProgress; +import net.minecraft.client.gui.hud.DebugHud; +import net.minecraft.client.util.math.MatrixStack; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(DebugHud.class) +public abstract class MixinDebugHud { + @Inject(method = "render", at = @At("HEAD")) + private void onStartRender(MatrixStack matrices, CallbackInfo ci) { + MinecraftRenderPipelineProgress.INSTANCE.setDrawingDebugHud(true); + } + + @Inject(method = "render", at = @At("RETURN")) + private void onFinishRender(MatrixStack matrices, CallbackInfo ci) { + MinecraftRenderPipelineProgress.INSTANCE.setDrawingDebugHud(false); + } +} diff --git a/src/main/java/codes/som/hibiscus/mixins/xray/MixinBlock.java b/src/main/java/codes/som/hibiscus/mixins/xray/MixinBlock.java index 031bf4a..14c70ee 100644 --- a/src/main/java/codes/som/hibiscus/mixins/xray/MixinBlock.java +++ b/src/main/java/codes/som/hibiscus/mixins/xray/MixinBlock.java @@ -16,7 +16,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; public abstract class MixinBlock { private static boolean ignoreShouldDrawSide = false; - @Inject(method = "shouldDrawSide", at = @At("RETURN"), cancellable = true) + @Inject(method = "shouldDrawSide", at = @At("HEAD"), cancellable = true) private static void onShouldRenderFace(BlockState state, BlockView world, BlockPos pos, Direction side, BlockPos blockPos, CallbackInfoReturnable cir) { if (ignoreShouldDrawSide) return; diff --git a/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt b/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt index b38ec70..cc788cf 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/visual/Freecam.kt @@ -47,9 +47,13 @@ class Freecam : Feature("Freecam", FeatureCategory.VISUAL) { if (isPlayerTicking) return@on - if (MinecraftRenderPipelineProgress.isRenderingEntities || MinecraftRenderPipelineProgress.isDrawingUI) + if (MinecraftRenderPipelineProgress.isRenderingEntities) return@on + if (MinecraftRenderPipelineProgress.isDrawingUI) + if (!MinecraftRenderPipelineProgress.isDrawingDebugHud || isControllingPlayer) + return@on + if (isControllingPlayer && MinecraftRenderPipelineProgress.isProcessingInput) return@on diff --git a/src/main/kotlin/codes/som/hibiscus/features/visual/Xray.kt b/src/main/kotlin/codes/som/hibiscus/features/visual/Xray.kt index 072a914..997e256 100644 --- a/src/main/kotlin/codes/som/hibiscus/features/visual/Xray.kt +++ b/src/main/kotlin/codes/som/hibiscus/features/visual/Xray.kt @@ -1,11 +1,27 @@ package codes.som.hibiscus.features.visual +import codes.som.hibiscus.HibiscusLog import codes.som.hibiscus.api.feature.Feature import codes.som.hibiscus.api.feature.FeatureCategory import codes.som.hibiscus.events.WorldCullingEvent import codes.som.hibiscus.mc class Xray : Feature("X-ray", FeatureCategory.VISUAL) { + val xrayBlocks = mutableSetOf( + "#minecraft:diamond_ores", + "#minecraft:iron_ores", + "#minecraft:portals", + "minecraft:obsidian", + "minecraft:furnace", + "minecraft:blast_furnace", + "minecraft:smoker", + "minecraft:dropper", + "minecraft:hopper", + "minecraft:barrel", + "minecraft:dispenser", + "minecraft:brewing_stand", + ) + init { on { event: WorldCullingEvent -> event.cancel() } } @@ -20,5 +36,25 @@ class Xray : Feature("X-ray", FeatureCategory.VISUAL) { override fun createFeatureCommand() = super.createFeatureCommand().apply { alias("xray") + + // TODO: Database stuff + + branch("add") { blockOrTag: String -> + xrayBlocks.add(blockOrTag) + } + + branch("del") { blockOrTag: String -> + xrayBlocks.remove(blockOrTag) + } + + branch("list") { + HibiscusLog.info(buildString { + append("X-Ray Blocks: ${xrayBlocks.size}") + for (block in xrayBlocks) { + append("\n - ") + append(block) + } + }) + } } } diff --git a/src/main/kotlin/codes/som/hibiscus/subsystems/tps/TPSDetectionSubsystem.kt b/src/main/kotlin/codes/som/hibiscus/subsystems/tps/TPSDetectionSubsystem.kt index 1c8a7ba..f16fce2 100644 --- a/src/main/kotlin/codes/som/hibiscus/subsystems/tps/TPSDetectionSubsystem.kt +++ b/src/main/kotlin/codes/som/hibiscus/subsystems/tps/TPSDetectionSubsystem.kt @@ -26,11 +26,12 @@ object TPSDetectionSubsystem { if (event.packet is WorldTimeUpdateS2CPacket) { val currTime = System.currentTimeMillis() if (lastSecond != -1L) { - tpsMultipliers.add((currTime - lastSecond) / 1000.0) - if (tpsMultipliers.size > 2) + val multiplier = (currTime - lastSecond) / 1000.0 + tpsMultipliers.add(multiplier) + if (tpsMultipliers.size > 8) tpsMultipliers.removeAt(0) + lastSecond = currTime } - lastSecond = currTime } } } diff --git a/src/main/kotlin/codes/som/hibiscus/subsystems/xray/XraySystem.kt b/src/main/kotlin/codes/som/hibiscus/subsystems/xray/XraySystem.kt index 0bbbab4..b79fff4 100644 --- a/src/main/kotlin/codes/som/hibiscus/subsystems/xray/XraySystem.kt +++ b/src/main/kotlin/codes/som/hibiscus/subsystems/xray/XraySystem.kt @@ -3,9 +3,8 @@ package codes.som.hibiscus.subsystems.xray import codes.som.hibiscus.Hibiscus import codes.som.hibiscus.features.visual.Xray import net.minecraft.block.BlockState -import net.minecraft.block.FluidBlock -import net.minecraft.block.IceBlock -import net.minecraft.block.OreBlock +import net.minecraft.util.registry.Registry +import kotlin.streams.asSequence object XraySystem { @JvmStatic @@ -20,9 +19,19 @@ object XraySystem { @JvmStatic fun isXrayBlock(blockState: BlockState): Boolean { - return when (blockState.block) { - is OreBlock, is FluidBlock, is IceBlock -> true - else -> false + try { + val blockId = Registry.BLOCK.getId(blockState.block).toString() + val tags = blockState.streamTags().asSequence().map { "#" + it.id.toString() } + + val checkedStrings = (sequenceOf(blockId) + tags).toSet() + + return Hibiscus.features + .getFeature() + .xrayBlocks + .any(checkedStrings::contains) + } catch (_: Exception) { } + + return false } } diff --git a/src/main/kotlin/codes/som/hibiscus/util/graphics/MinecraftRenderPipelineProgress.kt b/src/main/kotlin/codes/som/hibiscus/util/graphics/MinecraftRenderPipelineProgress.kt index 487d563..ed49513 100644 --- a/src/main/kotlin/codes/som/hibiscus/util/graphics/MinecraftRenderPipelineProgress.kt +++ b/src/main/kotlin/codes/som/hibiscus/util/graphics/MinecraftRenderPipelineProgress.kt @@ -4,4 +4,5 @@ object MinecraftRenderPipelineProgress { var isRenderingEntities: Boolean = false var isDrawingUI: Boolean = false var isProcessingInput: Boolean = false + var isDrawingDebugHud: Boolean = false } diff --git a/src/main/resources/hibiscus.mixins.json b/src/main/resources/hibiscus.mixins.json index 14f1ef8..406efac 100644 --- a/src/main/resources/hibiscus.mixins.json +++ b/src/main/resources/hibiscus.mixins.json @@ -10,6 +10,7 @@ "MixinClientConnection", "MixinClientPlayerEntity", "MixinClientPlayNetworkHandler", + "MixinDebugHud", "MixinExtClientPlayerEntity", "MixinExtEntity", "MixinExtMinecraftClient",