Compare commits

..

No commits in common. "b51e0ec2e07b169d5feebcbfd7ffd5c64db8eb5a" and "fb83b1089471fa0f6bf1dda9f10b21b9a58b4835" have entirely different histories.

11 changed files with 35 additions and 41 deletions

View File

@ -211,7 +211,7 @@ allprojects {
"-Xjvm-default=all", "-Xlambdas=indy", "-Xtype-enhancement-improvements-strict-mode", "-Xjvm-default=all", "-Xlambdas=indy", "-Xtype-enhancement-improvements-strict-mode",
"-Xmultifile-parts-inherit", "-Xmultifile-parts-inherit",
"-Xbackend-threads=0", "-Xno-param-assertions", "-Xno-call-assertions", "-Xbackend-threads=0", "-Xno-param-assertions", "-Xno-call-assertions",
"-opt-in=kotlin.RequiresOptIn", "-Xassertions=jvm", "-progressive" "-opt-in=kotlin.RequiresOptIn", "-Xextended-compiler-checks", "-Xassertions=jvm", "-progressive"
) )
//languageVersion = (kotlinSplitVersion[0] + '.' + (kotlinSplitVersion[1].toShort() + 1).toString()) //languageVersion = (kotlinSplitVersion[0] + '.' + (kotlinSplitVersion[1].toShort() + 1).toString())
//apiVersion = "${kotlinSplitVersion[0]}.${kotlinSplitVersion[1]}" //apiVersion = "${kotlinSplitVersion[0]}.${kotlinSplitVersion[1]}"

View File

@ -4,7 +4,6 @@ import fr.username404.snowygui.gui.ColoredElement
import fr.username404.snowygui.gui.Element import fr.username404.snowygui.gui.Element
import fr.username404.snowygui.gui.SnowyScreen import fr.username404.snowygui.gui.SnowyScreen
import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.elements.ClickBox
import net.minecraft.client.input.MouseButtonEvent
import org.lwjgl.glfw.GLFW import org.lwjgl.glfw.GLFW
object ClickGui: SnowyScreen() { object ClickGui: SnowyScreen() {
@ -20,26 +19,26 @@ object ClickGui: SnowyScreen() {
private inline fun currentBoxContext(args: ClickBox.() -> Unit): Unit? = draggingBox?.run { boxContext { if (name.string == draggingBox) args() } } private inline fun currentBoxContext(args: ClickBox.() -> Unit): Unit? = draggingBox?.run { boxContext { if (name.string == draggingBox) args() } }
private var offsetX: Double = 0.0; private var offsetX: Double = 0.0;
private var offsetY: Double = 0.0; private var offsetY: Double = 0.0;
override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean { override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) { if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
clickBoxes.find { it.isWithinBounds(event.x, event.y) }?.let { draggingBox = it.name.string } clickBoxes.find { it.isWithinBounds(d, e) }?.let { draggingBox = it.name.string }
currentBoxContext { currentBoxContext {
offsetX = event.x - (x + width) offsetX = d - (x + width)
offsetY = event.y - (y + height) offsetY = e - (y + height)
} }
} }
buttonsContext { this.mouseClicked(event, isDoubleClick) }; return super.mouseClicked(event, isDoubleClick); buttonsContext { this.mouseClicked(d, e, i) }; return super.mouseClicked(d, e, i);
} }
override fun mouseReleased(event: MouseButtonEvent): Boolean { draggingBox = null; buttonsContext { this.mouseReleased(event) }; return false } override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { draggingBox = null; buttonsContext { this.mouseReleased(d, e, i) }; return false }
override fun mouseScrolled(d: Double, e: Double, f: Double, scrollY: Double): Boolean { boxContext { scroll(d, e, scrollY) }; return false } override fun mouseScrolled(d: Double, e: Double, f: Double, scrollY: Double): Boolean { boxContext { scroll(d, e, scrollY) }; return false }
override fun mouseDragged(event: MouseButtonEvent, mouseX: Double, mouseY: Double): Boolean { override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) { if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
currentBoxContext { currentBoxContext {
x = (event.x + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble()) x = (d + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble())
y = (event.y + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble()) y = (e + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble())
} }
} }
return super.mouseDragged(event, mouseX, mouseY) return super.mouseDragged(d, e, i, f, g)
} }
} }

View File

@ -96,7 +96,7 @@ class ClickBox(
addVertex(x, y + height, 0.0F).colorEnd() addVertex(x, y + height, 0.0F).colorEnd()
} }
renderBufferWithPipeline(renderPipeline = RenderPipelines.LINES_TRANSLUCENT) { renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_LINE_STRIP) {
colorShader() colorShader()
addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)

View File

@ -10,7 +10,6 @@ import fr.username404.snowygui.utils.RenderingUtil.colorShader
import fr.username404.snowygui.utils.RenderingUtil.endDraw import fr.username404.snowygui.utils.RenderingUtil.endDraw
import fr.username404.snowygui.utils.RenderingUtil.prepareDraw import fr.username404.snowygui.utils.RenderingUtil.prepareDraw
import net.minecraft.client.gui.GuiGraphics import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.input.MouseButtonEvent
import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.findAnnotation
sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
@ -69,8 +68,8 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
} }
private fun lightUp() { opacity += ButtonInfo.lightningFactor } private fun lightUp() { opacity += ButtonInfo.lightningFactor }
private fun lightDown() { opacity -= ButtonInfo.lightningFactor } private fun lightDown() { opacity -= ButtonInfo.lightningFactor }
final override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean { final override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
wasWithinBounds = isWithinBounds(event.x, event.y).also { wasWithinBounds = isWithinBounds(d, e).also {
if (it) { if (it) {
if (info.kind == Type.TOGGLE) { if (info.kind == Type.TOGGLE) {
toggled = !toggled toggled = !toggled
@ -80,7 +79,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
return false return false
} }
final override fun mouseReleased(event: MouseButtonEvent): Boolean { final override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
if (wasWithinBounds && (info.kind == Type.CLICK)) { if (wasWithinBounds && (info.kind == Type.CLICK)) {
execAction() execAction()
lightDown() lightDown()

View File

@ -3,7 +3,6 @@ package fr.username404.snowygui.gui.feature
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import net.minecraft.client.Minecraft import net.minecraft.client.Minecraft
import net.minecraft.server.permissions.Permissions
/** /**
* @property command The command to execute * @property command The command to execute
@ -18,7 +17,7 @@ data class Macro(
override fun execAction(): Unit = with(Minecraft.getInstance().player!!) { override fun execAction(): Unit = with(Minecraft.getInstance().player!!) {
connection.run { connection.run {
command.let { command.let {
if (it.startsWith("say") && !this@with.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER)) { if (it.startsWith("say") && !hasPermissions(2)) {
sendChat(it.drop(4)) sendChat(it.drop(4))
} else sendCommand(it) } else sendCommand(it)
} }

View File

@ -12,7 +12,6 @@ import org.lwjgl.glfw.GLFW.GLFW_KEY_Y
private typealias privateLambda = (() -> Unit)? private typealias privateLambda = (() -> Unit)?
object AddKeyMaps { object AddKeyMaps {
private const val prefix = "snowy" private const val prefix = "snowy"
var category: KeyMapping.Category? = null; private set
@JvmOverloads @JvmOverloads
internal fun mkMap( internal fun mkMap(
translationSuffix: String, translationSuffix: String,
@ -20,9 +19,7 @@ object AddKeyMaps {
lambda: privateLambda = null lambda: privateLambda = null
): Pair<KeyMapping, privateLambda> = KeyMapping( ): Pair<KeyMapping, privateLambda> = KeyMapping(
"key.$prefix.$translationSuffix", InputConstants.Type.KEYSYM, "key.$prefix.$translationSuffix", InputConstants.Type.KEYSYM,
key, this.category ?: run { key, "category.$prefix.$category"
this.category = KeyMapping.Category.register("category.$prefix.$category"); this.category
}!!
) to lambda ) to lambda
val list: MutableMap<KeyMapping, privateLambda> = with(Minecraft.getInstance()) { val list: MutableMap<KeyMapping, privateLambda> = with(Minecraft.getInstance()) {
mutableMapOf( mutableMapOf(

View File

@ -13,8 +13,6 @@ import fr.username404.snowygui.gui.feature.Colors
import fr.username404.snowygui.gui.hextoRGB import fr.username404.snowygui.gui.hextoRGB
import net.minecraft.client.Minecraft import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.RenderPipelines import net.minecraft.client.renderer.RenderPipelines
import org.joml.Matrix4f
import org.joml.Vector3f
import org.joml.Vector4f import org.joml.Vector4f
import java.util.OptionalDouble import java.util.OptionalDouble
import java.util.OptionalInt import java.util.OptionalInt
@ -47,11 +45,12 @@ object RenderingUtil {
val gpuSlice = RenderSystem.getDynamicUniforms().writeTransform( val gpuSlice = RenderSystem.getDynamicUniforms().writeTransform(
RenderSystem.getModelViewMatrix(), RenderSystem.getModelViewMatrix(),
Vector4f(1F, 1F, 1F, 1F), // Alternative to old setShaderColor Vector4f(1F, 1F, 1F, 1F), // Alternative to old setShaderColor
Vector3f(), RenderSystem.getModelOffset(),
Matrix4f() RenderSystem.getTextureMatrix(),
RenderSystem.getShaderLineWidth()
) )
fun renderBufferWithPipeline( fun renderBufferWithPipeline(
name: String = "Dynamic vertex buffer", name: String? = "Dynamic vertex buffer",
renderPipeline: RenderPipeline, renderPipeline: RenderPipeline,
renderTarget: RenderTarget = Minecraft.getInstance().mainRenderTarget, renderTarget: RenderTarget = Minecraft.getInstance().mainRenderTarget,
uniformAndSamplerConsumer: ((RenderPass) -> Unit)? = null, uniformAndSamplerConsumer: ((RenderPass) -> Unit)? = null,

View File

@ -4,6 +4,4 @@ accessible field net/minecraft/client/OptionInstance value Ljava/lang/Object;
mutable field net/minecraft/client/OptionInstance value Ljava/lang/Object; mutable field net/minecraft/client/OptionInstance value Ljava/lang/Object;
accessible field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z accessible field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z
mutable field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z mutable field com/mojang/blaze3d/opengl/GlCommandEncoder inRenderPass Z
accessible method net/minecraft/client/KeyMapping$Category register (Ljava/lang/String;)Lnet/minecraft/client/KeyMapping$Category;

View File

@ -25,11 +25,14 @@ abstract class KeyMappings {
@Inject(method = "<init>*", at = @At("RETURN")) @Inject(method = "<init>*", at = @At("RETURN"))
private void onSettingsConstructed(Minecraft minecraft, File file, CallbackInfo ci) { private void onSettingsConstructed(Minecraft minecraft, File file, CallbackInfo ci) {
final var categoryList = KeysAccessor.getSortedCategoryList(); final var categoryMap = KeysAccessor.getSortedCategoryMap();
var newKeys = Lists.newArrayList(keyMappings); var newKeys = Lists.newArrayList(keyMappings);
for (KeyMapping key : keysToAdd) { for (KeyMapping key : keysToAdd) {
if (!categoryList.contains(key.getCategory())) if (!categoryMap.containsKey(key.getCategory())) {
categoryList.add(key.getCategory()); Optional<Integer> biggest = categoryMap.values().stream().max(Integer::compareTo);
int biggestInt = biggest.orElse(0);
categoryMap.put(key.getCategory(), biggestInt + 1);
}
newKeys.remove(key); newKeys.remove(key);
newKeys.add(key); newKeys.add(key);
} }

View File

@ -4,10 +4,10 @@ import net.minecraft.client.KeyMapping;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.List; import java.util.Map;
@Mixin(KeyMapping.Category.class) @Mixin(KeyMapping.class)
public interface KeysAccessor { public interface KeysAccessor {
@Accessor("SORT_ORDER") @Accessor("CATEGORY_SORT_ORDER")
static List<KeyMapping.Category> getSortedCategoryList() { throw new AssertionError(); } static Map<String, Integer> getSortedCategoryMap() { throw new AssertionError(); }
} }

View File

@ -21,7 +21,7 @@ class FabricInit: Snowy(), ClientModInitializer {
EVENT.register( EVENT.register(
object: HudRenderCallback, EventSnowy { object: HudRenderCallback, EventSnowy {
override val type: String = "HudRender" override val type: String = "HudRender"
override fun onHudRender(guiGraphics: GuiGraphics, tickCounter: DeltaTracker) = fire(guiGraphics) override fun onHudRender(guiGraphics: GuiGraphics?, tickCounter: DeltaTracker?) = fire(guiGraphics)
} }
) )
} }