Compare commits
4 Commits
fb83b10894
...
b51e0ec2e0
| Author | SHA1 | Date | |
|---|---|---|---|
| b51e0ec2e0 | |||
| 019e62f33b | |||
| 90d4e7b8b4 | |||
| 4dd188d721 |
@ -211,7 +211,7 @@ allprojects {
|
||||
"-Xjvm-default=all", "-Xlambdas=indy", "-Xtype-enhancement-improvements-strict-mode",
|
||||
"-Xmultifile-parts-inherit",
|
||||
"-Xbackend-threads=0", "-Xno-param-assertions", "-Xno-call-assertions",
|
||||
"-opt-in=kotlin.RequiresOptIn", "-Xextended-compiler-checks", "-Xassertions=jvm", "-progressive"
|
||||
"-opt-in=kotlin.RequiresOptIn", "-Xassertions=jvm", "-progressive"
|
||||
)
|
||||
//languageVersion = (kotlinSplitVersion[0] + '.' + (kotlinSplitVersion[1].toShort() + 1).toString())
|
||||
//apiVersion = "${kotlinSplitVersion[0]}.${kotlinSplitVersion[1]}"
|
||||
|
||||
@ -4,6 +4,7 @@ import fr.username404.snowygui.gui.ColoredElement
|
||||
import fr.username404.snowygui.gui.Element
|
||||
import fr.username404.snowygui.gui.SnowyScreen
|
||||
import fr.username404.snowygui.gui.elements.ClickBox
|
||||
import net.minecraft.client.input.MouseButtonEvent
|
||||
import org.lwjgl.glfw.GLFW
|
||||
|
||||
object ClickGui: SnowyScreen() {
|
||||
@ -19,26 +20,26 @@ object ClickGui: SnowyScreen() {
|
||||
private inline fun currentBoxContext(args: ClickBox.() -> Unit): Unit? = draggingBox?.run { boxContext { if (name.string == draggingBox) args() } }
|
||||
private var offsetX: Double = 0.0;
|
||||
private var offsetY: Double = 0.0;
|
||||
override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
||||
if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||
clickBoxes.find { it.isWithinBounds(d, e) }?.let { draggingBox = it.name.string }
|
||||
override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean {
|
||||
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||
clickBoxes.find { it.isWithinBounds(event.x, event.y) }?.let { draggingBox = it.name.string }
|
||||
currentBoxContext {
|
||||
offsetX = d - (x + width)
|
||||
offsetY = e - (y + height)
|
||||
offsetX = event.x - (x + width)
|
||||
offsetY = event.y - (y + height)
|
||||
}
|
||||
}
|
||||
buttonsContext { this.mouseClicked(d, e, i) }; return super.mouseClicked(d, e, i);
|
||||
buttonsContext { this.mouseClicked(event, isDoubleClick) }; return super.mouseClicked(event, isDoubleClick);
|
||||
}
|
||||
override fun mouseReleased(d: Double, e: Double, i: Int): Boolean { draggingBox = null; buttonsContext { this.mouseReleased(d, e, i) }; return false }
|
||||
override fun mouseReleased(event: MouseButtonEvent): Boolean { draggingBox = null; buttonsContext { this.mouseReleased(event) }; return false }
|
||||
override fun mouseScrolled(d: Double, e: Double, f: Double, scrollY: Double): Boolean { boxContext { scroll(d, e, scrollY) }; return false }
|
||||
|
||||
override fun mouseDragged(d: Double, e: Double, i: Int, f: Double, g: Double): Boolean {
|
||||
if (i == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||
override fun mouseDragged(event: MouseButtonEvent, mouseX: Double, mouseY: Double): Boolean {
|
||||
if (event.input() == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
|
||||
currentBoxContext {
|
||||
x = (d + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble())
|
||||
y = (e + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble())
|
||||
x = (event.x + offsetX).coerceIn(0.0..this@ClickGui.width - width.toDouble())
|
||||
y = (event.y + offsetY).coerceIn(0.0..this@ClickGui.height - height.toDouble())
|
||||
}
|
||||
}
|
||||
return super.mouseDragged(d, e, i, f, g)
|
||||
return super.mouseDragged(event, mouseX, mouseY)
|
||||
}
|
||||
}
|
||||
@ -96,7 +96,7 @@ class ClickBox(
|
||||
addVertex(x, y + height, 0.0F).colorEnd()
|
||||
}
|
||||
|
||||
renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_LINE_STRIP) {
|
||||
renderBufferWithPipeline(renderPipeline = RenderPipelines.LINES_TRANSLUCENT) {
|
||||
colorShader()
|
||||
addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
|
||||
addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue)
|
||||
|
||||
@ -10,6 +10,7 @@ import fr.username404.snowygui.utils.RenderingUtil.colorShader
|
||||
import fr.username404.snowygui.utils.RenderingUtil.endDraw
|
||||
import fr.username404.snowygui.utils.RenderingUtil.prepareDraw
|
||||
import net.minecraft.client.gui.GuiGraphics
|
||||
import net.minecraft.client.input.MouseButtonEvent
|
||||
import kotlin.reflect.full.findAnnotation
|
||||
|
||||
sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||
@ -68,8 +69,8 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||
}
|
||||
private fun lightUp() { opacity += ButtonInfo.lightningFactor }
|
||||
private fun lightDown() { opacity -= ButtonInfo.lightningFactor }
|
||||
final override fun mouseClicked(d: Double, e: Double, i: Int): Boolean {
|
||||
wasWithinBounds = isWithinBounds(d, e).also {
|
||||
final override fun mouseClicked(event: MouseButtonEvent, isDoubleClick: Boolean): Boolean {
|
||||
wasWithinBounds = isWithinBounds(event.x, event.y).also {
|
||||
if (it) {
|
||||
if (info.kind == Type.TOGGLE) {
|
||||
toggled = !toggled
|
||||
@ -79,7 +80,7 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||
return false
|
||||
}
|
||||
|
||||
final override fun mouseReleased(d: Double, e: Double, i: Int): Boolean {
|
||||
final override fun mouseReleased(event: MouseButtonEvent): Boolean {
|
||||
if (wasWithinBounds && (info.kind == Type.CLICK)) {
|
||||
execAction()
|
||||
lightDown()
|
||||
|
||||
@ -3,6 +3,7 @@ package fr.username404.snowygui.gui.feature
|
||||
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
|
||||
import kotlinx.serialization.Serializable
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.server.permissions.Permissions
|
||||
|
||||
/**
|
||||
* @property command The command to execute
|
||||
@ -17,7 +18,7 @@ data class Macro(
|
||||
override fun execAction(): Unit = with(Minecraft.getInstance().player!!) {
|
||||
connection.run {
|
||||
command.let {
|
||||
if (it.startsWith("say") && !hasPermissions(2)) {
|
||||
if (it.startsWith("say") && !this@with.permissions().hasPermission(Permissions.COMMANDS_GAMEMASTER)) {
|
||||
sendChat(it.drop(4))
|
||||
} else sendCommand(it)
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import org.lwjgl.glfw.GLFW.GLFW_KEY_Y
|
||||
private typealias privateLambda = (() -> Unit)?
|
||||
object AddKeyMaps {
|
||||
private const val prefix = "snowy"
|
||||
var category: KeyMapping.Category? = null; private set
|
||||
@JvmOverloads
|
||||
internal fun mkMap(
|
||||
translationSuffix: String,
|
||||
@ -19,7 +20,9 @@ object AddKeyMaps {
|
||||
lambda: privateLambda = null
|
||||
): Pair<KeyMapping, privateLambda> = KeyMapping(
|
||||
"key.$prefix.$translationSuffix", InputConstants.Type.KEYSYM,
|
||||
key, "category.$prefix.$category"
|
||||
key, this.category ?: run {
|
||||
this.category = KeyMapping.Category.register("category.$prefix.$category"); this.category
|
||||
}!!
|
||||
) to lambda
|
||||
val list: MutableMap<KeyMapping, privateLambda> = with(Minecraft.getInstance()) {
|
||||
mutableMapOf(
|
||||
|
||||
@ -13,6 +13,8 @@ import fr.username404.snowygui.gui.feature.Colors
|
||||
import fr.username404.snowygui.gui.hextoRGB
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.RenderPipelines
|
||||
import org.joml.Matrix4f
|
||||
import org.joml.Vector3f
|
||||
import org.joml.Vector4f
|
||||
import java.util.OptionalDouble
|
||||
import java.util.OptionalInt
|
||||
@ -45,12 +47,11 @@ object RenderingUtil {
|
||||
val gpuSlice = RenderSystem.getDynamicUniforms().writeTransform(
|
||||
RenderSystem.getModelViewMatrix(),
|
||||
Vector4f(1F, 1F, 1F, 1F), // Alternative to old setShaderColor
|
||||
RenderSystem.getModelOffset(),
|
||||
RenderSystem.getTextureMatrix(),
|
||||
RenderSystem.getShaderLineWidth()
|
||||
Vector3f(),
|
||||
Matrix4f()
|
||||
)
|
||||
fun renderBufferWithPipeline(
|
||||
name: String? = "Dynamic vertex buffer",
|
||||
name: String = "Dynamic vertex buffer",
|
||||
renderPipeline: RenderPipeline,
|
||||
renderTarget: RenderTarget = Minecraft.getInstance().mainRenderTarget,
|
||||
uniformAndSamplerConsumer: ((RenderPass) -> Unit)? = null,
|
||||
|
||||
@ -4,4 +4,6 @@ accessible 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
|
||||
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;
|
||||
@ -25,14 +25,11 @@ abstract class KeyMappings {
|
||||
|
||||
@Inject(method = "<init>*", at = @At("RETURN"))
|
||||
private void onSettingsConstructed(Minecraft minecraft, File file, CallbackInfo ci) {
|
||||
final var categoryMap = KeysAccessor.getSortedCategoryMap();
|
||||
final var categoryList = KeysAccessor.getSortedCategoryList();
|
||||
var newKeys = Lists.newArrayList(keyMappings);
|
||||
for (KeyMapping key : keysToAdd) {
|
||||
if (!categoryMap.containsKey(key.getCategory())) {
|
||||
Optional<Integer> biggest = categoryMap.values().stream().max(Integer::compareTo);
|
||||
int biggestInt = biggest.orElse(0);
|
||||
categoryMap.put(key.getCategory(), biggestInt + 1);
|
||||
}
|
||||
if (!categoryList.contains(key.getCategory()))
|
||||
categoryList.add(key.getCategory());
|
||||
newKeys.remove(key);
|
||||
newKeys.add(key);
|
||||
}
|
||||
|
||||
@ -4,10 +4,10 @@ import net.minecraft.client.KeyMapping;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(KeyMapping.class)
|
||||
@Mixin(KeyMapping.Category.class)
|
||||
public interface KeysAccessor {
|
||||
@Accessor("CATEGORY_SORT_ORDER")
|
||||
static Map<String, Integer> getSortedCategoryMap() { throw new AssertionError(); }
|
||||
@Accessor("SORT_ORDER")
|
||||
static List<KeyMapping.Category> getSortedCategoryList() { throw new AssertionError(); }
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ class FabricInit: Snowy(), ClientModInitializer {
|
||||
EVENT.register(
|
||||
object: HudRenderCallback, EventSnowy {
|
||||
override val type: String = "HudRender"
|
||||
override fun onHudRender(guiGraphics: GuiGraphics?, tickCounter: DeltaTracker?) = fire(guiGraphics)
|
||||
override fun onHudRender(guiGraphics: GuiGraphics, tickCounter: DeltaTracker) = fire(guiGraphics)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user