diff options
author | nea <nea@nea.moe> | 2023-05-26 23:23:03 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-26 23:23:03 +0200 |
commit | 59ea00dabceeddf01fec7bf87ec548d7beedd7cc (patch) | |
tree | 9711c61022f2bac793c423de97901d2370b7c316 | |
parent | 484a4b1a61493eb1401ac9c8ac063db3f847cf98 (diff) | |
download | firmament-59ea00dabceeddf01fec7bf87ec548d7beedd7cc.tar.gz firmament-59ea00dabceeddf01fec7bf87ec548d7beedd7cc.tar.bz2 firmament-59ea00dabceeddf01fec7bf87ec548d7beedd7cc.zip |
Fix bug in WFixedPanel and use WScrollPanel + WBox for config
8 files changed, 61 insertions, 13 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/MixinWorldRenderer.java b/src/main/java/moe/nea/firmament/mixins/MixinWorldRenderer.java index 722cdb8..3d9d408 100644 --- a/src/main/java/moe/nea/firmament/mixins/MixinWorldRenderer.java +++ b/src/main/java/moe/nea/firmament/mixins/MixinWorldRenderer.java @@ -32,7 +32,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(WorldRenderer.class) public class MixinWorldRenderer { - @Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/WorldRenderer;renderChunkDebugInfo(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/Camera;)V", shift = At.Shift.AFTER)) + @Inject(method = "render", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;applyModelViewMatrix()V", shift = At.Shift.AFTER)) public void onWorldRenderLast(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci) { var event = new WorldRenderLastEvent( matrices, tickDelta, renderBlockOutline, diff --git a/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt b/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt index 30fc0d8..d7cf467 100644 --- a/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt +++ b/src/main/kotlin/moe/nea/firmament/events/IsSlotProtectedEvent.kt @@ -28,7 +28,8 @@ data class IsSlotProtectedEvent( ) : FirmamentEvent() { companion object : FirmamentEventBus<IsSlotProtectedEvent>() { @JvmStatic - fun shouldBlockInteraction(slot: Slot): Boolean { + fun shouldBlockInteraction(slot: Slot?): Boolean { + if (slot == null) return false return publish(IsSlotProtectedEvent(slot)).isProtected.also { if (it) { MC.player?.sendMessage(Text.translatable("firmament.protectitem").append(slot.stack.name)) diff --git a/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt index de24faa..24e31ea 100644 --- a/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt +++ b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt @@ -25,6 +25,8 @@ import kotlin.math.asin import kotlin.math.atan2 import kotlin.math.sqrt import kotlin.time.Duration.Companion.seconds +import net.minecraft.client.render.VertexConsumerProvider +import net.minecraft.client.render.VertexConsumers import net.minecraft.entity.projectile.FishingBobberEntity import net.minecraft.particle.ParticleTypes import net.minecraft.util.math.Vec3d @@ -32,9 +34,9 @@ import moe.nea.firmament.events.ParticleSpawnEvent import moe.nea.firmament.events.WorldReadyEvent import moe.nea.firmament.events.WorldRenderLastEvent import moe.nea.firmament.features.FirmamentFeature +import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.TimeMark -import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.render.RenderBlockContext.Companion.renderBlocks object FishingWarning : FirmamentFeature { @@ -89,6 +91,7 @@ object FishingWarning : FirmamentFeature { } private fun toDegrees(d: Double) = d * 180 / Math.PI + private fun toRadians(d: Double) = d / 180 * Math.PI fun isHookPossible(hook: FishingBobberEntity, particlePos: Vec3d, angle1: Double, angle2: Double): Boolean { val dx = particlePos.x - hook.pos.x @@ -104,6 +107,16 @@ object FishingWarning : FirmamentFeature { val recentParticles = mutableListOf<Pair<Vec3d, TimeMark>>() + data class Candidate( + val angle1: Double, + val angle2: Double, + val hookOrigin: Vec3d, + val position: Vec3d, + val timeMark: TimeMark = TimeMark.now() + ) + + val recentCandidates = mutableListOf<Candidate>() + private fun onParticleSpawn(event: ParticleSpawnEvent) { if (event.particleEffect.type != ParticleTypes.FISHING) return if (!(abs(event.offset.y - 0.01f) < 0.001f)) return @@ -111,6 +124,7 @@ object FishingWarning : FirmamentFeature { val actualOffset = event.offset val candidate1 = calculateAngleFromOffsets(actualOffset.x, -actualOffset.z) val candidate2 = calculateAngleFromOffsets(-actualOffset.x, actualOffset.z) + recentCandidates.add(Candidate(candidate1, candidate2, hook.pos, event.position)) if (isHookPossible(hook, event.position, candidate1, candidate2)) { recentParticles.add(Pair(event.position, TimeMark.now())) @@ -124,11 +138,22 @@ object FishingWarning : FirmamentFeature { } WorldRenderLastEvent.subscribe { recentParticles.removeIf { it.second.passedTime() > 5.seconds } + recentCandidates.removeIf { it.timeMark.passedTime() > 5.seconds } renderBlocks(it.matrices, it.camera) { color(0f, 0f, 1f, 1f) recentParticles.forEach { tinyBlock(it.first, 0.1F) } + + recentCandidates.forEach { + println(it) + color(1f, 1f, 0f, 1f) + line(it.hookOrigin, it.position) + color(1f, 0f, 0f, 1f) + line(it.position, Vec3d.fromPolar(0F, it.angle1.toFloat()).add(it.position)) + color(0f, 1f, 0f, 1f) + line(it.position, Vec3d.fromPolar(0F, it.angle2.toFloat()).add(it.position)) + } } } } diff --git a/src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt b/src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt index 4ada681..0c5eb05 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/WFixedPanel.kt @@ -8,6 +8,7 @@ class WFixedPanel() : WPanel() { set(value) { children.clear() setSize(0, 0) + value.parent = this children.add(value) } get() = children.single() diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt b/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt index dd8108f..e547e3b 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/config/AllConfigsGui.kt @@ -21,10 +21,12 @@ package moe.nea.firmament.gui.config import io.github.cottonmc.cotton.gui.client.BackgroundPainter import io.github.cottonmc.cotton.gui.client.CottonClientScreen import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription +import io.github.cottonmc.cotton.gui.widget.WBox import io.github.cottonmc.cotton.gui.widget.WButton import io.github.cottonmc.cotton.gui.widget.WGridPanel import io.github.cottonmc.cotton.gui.widget.WLabel -import io.github.cottonmc.cotton.gui.widget.WListPanel +import io.github.cottonmc.cotton.gui.widget.WScrollPanel +import io.github.cottonmc.cotton.gui.widget.data.Axis import io.github.cottonmc.cotton.gui.widget.data.Insets import io.ktor.http.* import net.minecraft.client.gui.screen.Screen @@ -40,11 +42,11 @@ object AllConfigsGui { fun makeScreen(parent: Screen? = null): CottonClientScreen { val lwgd = LightweightGuiDescription() var screen: CottonClientScreen? = null - lwgd.setRootPanel(WListPanel( - listOf( - RepoManager.Config - ) + FeatureManager.allFeatures.mapNotNull { it.config }, ::WFixedPanel - ) { config, fixedPanel -> + val configs = listOf( + RepoManager.Config + ) + FeatureManager.allFeatures.mapNotNull { it.config } + val box = WBox(Axis.VERTICAL) + configs.forEach { config -> val panel = WGridPanel() panel.insets = Insets.ROOT_PANEL panel.backgroundPainter = BackgroundPainter.VANILLA @@ -54,9 +56,12 @@ object AllConfigsGui { config.showConfigEditor(screen) } }, 0, 1, 10, 1) - fixedPanel.child = panel - }.also { - it.setSize(10 * 18 + 14 + 16, 300) + box.add(WFixedPanel(panel)) + } + box.insets = Insets.ROOT_PANEL + lwgd.setRootPanel(WScrollPanel((box)).also { + box.layout() + it.setSize(box.width + 8, MC.window.scaledHeight / 2) }) screen = object : CottonClientScreen(lwgd) { override fun close() { diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt index 2f3d029..53bad8b 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MC.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt @@ -31,7 +31,9 @@ object MC { get() = MinecraftClient.getInstance().currentScreen set(value) = MinecraftClient.getInstance().setScreen(value) inline val handledScreen: HandledScreen<*>? get() = MinecraftClient.getInstance().currentScreen as? HandledScreen<*> + inline val window get() = MinecraftClient.getInstance().window } + val Coordinate.blockPos: BlockPos get() = BlockPos(x, y, z) diff --git a/src/main/kotlin/moe/nea/firmament/util/TimeMark.kt b/src/main/kotlin/moe/nea/firmament/util/TimeMark.kt index e9826f1..3331a76 100644 --- a/src/main/kotlin/moe/nea/firmament/util/TimeMark.kt +++ b/src/main/kotlin/moe/nea/firmament/util/TimeMark.kt @@ -23,11 +23,18 @@ import kotlin.time.ExperimentalTime import kotlin.time.TimeSource @OptIn(ExperimentalTime::class) -class TimeMark private constructor(private val timeMark: TimeSource.Monotonic.ValueTimeMark?) { +class TimeMark private constructor(private val timeMark: TimeSource.Monotonic.ValueTimeMark?) : Comparable<TimeMark> { fun passedTime() = timeMark?.elapsedNow() ?: Duration.INFINITE companion object { fun now() = TimeMark(TimeSource.Monotonic.markNow()) fun farPast() = TimeMark(null) } + + override fun compareTo(other: TimeMark): Int { + if (this.timeMark == other.timeMark) return 0 + if (this.timeMark == null) return -1 + if (other.timeMark == null) return -1 + return this.timeMark.compareTo(other.timeMark) + } } diff --git a/src/main/kotlin/moe/nea/firmament/util/render/block.kt b/src/main/kotlin/moe/nea/firmament/util/render/block.kt index bc5a889..7df610b 100644 --- a/src/main/kotlin/moe/nea/firmament/util/render/block.kt +++ b/src/main/kotlin/moe/nea/firmament/util/render/block.kt @@ -24,7 +24,9 @@ import net.minecraft.client.gl.VertexBuffer import net.minecraft.client.render.BufferBuilder import net.minecraft.client.render.Camera import net.minecraft.client.render.GameRenderer +import net.minecraft.client.render.RenderLayer import net.minecraft.client.render.Tessellator +import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.VertexFormat import net.minecraft.client.render.VertexFormats import net.minecraft.client.util.math.MatrixStack @@ -33,6 +35,7 @@ import net.minecraft.util.math.Vec3d class RenderBlockContext private constructor(private val tesselator: Tessellator, private val matrixStack: MatrixStack) { private val buffer = tesselator.buffer + fun color(red: Float, green: Float, blue: Float, alpha: Float) { RenderSystem.setShaderColor(red, green, blue, alpha) } @@ -55,6 +58,10 @@ class RenderBlockContext private constructor(private val tesselator: Tessellator matrixStack.pop() } + fun line(vararg points: Vec3d, size: Double = 2.0) { + + } + companion object { private fun buildCube(matrix: Matrix4f, buf: BufferBuilder) { buf.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR) |