Skip to content

Commit

Permalink
some issues still
Browse files Browse the repository at this point in the history
  • Loading branch information
U5B committed Apr 26, 2023
1 parent 848b380 commit b2a39dc
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 67 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ tasks {
kotlinOptions.freeCompilerArgs +=
listOf(
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-Xno-param-assertions",
"-Xjvm-default=all-compatibility"
)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/usbwire/base/mixins/ChatHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

import gg.essential.universal.wrappers.message.UTextComponent;
import net.usbwire.base.util.MixinHelper;

@Environment(EnvType.CLIENT)
@Mixin(value = ChatHud.class, priority = 400)
public abstract class ChatHudMixin extends DrawableHelper {
Expand All @@ -25,5 +28,6 @@ public abstract class ChatHudMixin extends DrawableHelper {
private void onMessage (Text message, int id, int ticks, boolean refresh, CallbackInfo ci) {
// Pass this to UniversalCraft's text compoment parser and then process it later at some point!
// System.out.println(message.toString());
MixinHelper.INSTANCE.onMessage(message, id, ticks, refresh);
}
}
6 changes: 4 additions & 2 deletions src/main/java/net/usbwire/base/mixins/HitboxMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
import net.minecraft.client.gl.VertexBuffer;
import net.minecraft.client.gui.DrawableHelper;
import java.awt.*;
import net.usbwire.base.util.Hitbox;
import net.usbwire.base.util.MixinHelper;
import net.usbwire.base.config.VigilanceConfig;

import net.minecraft.client.render.WorldRenderer;

@Mixin(EntityRenderDispatcher.class)
public abstract class HitboxMixin {
@Shadow
private boolean renderHitboxes;

@Inject(method = "renderHitbox", at = @At("HEAD"), cancellable = true)
private static void renderHitbox(MatrixStack matrices, VertexConsumer vertices, Entity entity, float tickDelta, CallbackInfo ci) {
Boolean cancel = Hitbox.INSTANCE.renderHitbox(matrices, vertices, entity);
Boolean cancel = MixinHelper.INSTANCE.renderHitbox(matrices, vertices, entity);
if (cancel == true) ci.cancel();
}

Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/net/usbwire/base/BaseMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import net.minecraft.network.MessageType
import net.minecraft.text.Text
import net.usbwire.base.access.InGameHudAccess
import net.usbwire.base.commands.BaseCommand
import net.usbwire.base.util.Hitbox
import net.usbwire.base.features.Poi
import org.slf4j.LoggerFactory
import gg.essential.universal.UMatrixStack
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/net/usbwire/base/config/VigilanceConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import kotlin.math.PI
val configFile = "${BaseMod.configPath}/config.toml"

object VigilanceConfig : Vigilant(File(configFile)) {
@Property(type = PropertyType.CHECKBOX, name = "enabled", description = "Toggles POI Module", category = "POI")
@Property(type = PropertyType.CHECKBOX, name = "Toggle POI Module", description = "", category = "POI")
var poiEnabled = false

@Property(type = PropertyType.BUTTON, name = "Update to latest pois.json", description = "Fetches from https://raw.githubusercontent.com/U5B/Monumenta/main/out/pois.json for the latest data.", category = "POI")
fun poiButton() = Poi.fetchPoiData()
@Property(type = PropertyType.CHECKBOX, name = "Toggle GlowHealth Module", description = "", category = "GlowHealth")
var healthEnabled = false
@Property(type = PropertyType.CHECKBOX, name = "Force Hitboxes On", description = "This will cause F3+B to be forced on.", category = "GlowHealth")
Expand Down
34 changes: 34 additions & 0 deletions src/main/kotlin/net/usbwire/base/features/Compass.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package net.usbwire.base.features

import gg.essential.universal.UMouse
import gg.essential.universal.wrappers.UPlayer

import net.usbwire.base.util.chat.Coordinates
import net.usbwire.base.BaseMod

object Compass {
fun getCompass (): Coordinates.Coordinates {
val spawnPos = BaseMod.mc.world!!.spawnPos
return Coordinates.Coordinates(spawnPos.x, spawnPos.y, spawnPos.z)
}

fun createCompass (compass : Coordinates.Coordinates) {
val dimension = BaseMod.mc.world!!.registryKey.value.toString()
val name = "Compass"
val x = compass.x
val y = compass.y
val z = compass.z
val message = Coordinates.coordinateBuilder(name, x, y, z, dimension)
message.chat()
}

var clicked = false;

fun onTick () {
val click = BaseMod.mc.mouse.wasLeftButtonClicked()
if (click && clicked == false) {
BaseMod.logger.info(UPlayer.getPlayer()!!.mainHandStack.name.toString())
}
clicked = click
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.usbwire.base.util
package net.usbwire.base.features

import java.awt.*
import net.minecraft.client.render.*
Expand All @@ -11,11 +11,12 @@ import com.mojang.blaze3d.systems.RenderSystem
import net.usbwire.base.config.VigilanceConfig
import net.usbwire.base.BaseMod
import gg.essential.universal.UMatrixStack
import gg.essential.universal.vertex.UVertexConsumer

object Hitbox {
object Health {
fun renderHitbox(
matrices: MatrixStack,
vertices: VertexConsumer,
matrix: MatrixStack,
vertex: VertexConsumer,
entity: Entity
) : Boolean {
if (VigilanceConfig.healthEnabled == false) return false
Expand All @@ -27,7 +28,8 @@ object Hitbox {
val green = color.green / 255.0F
val blue = color.blue / 255.0F
val alpha = color.alpha / 255.0F
WorldRenderer.drawBox(matrices, vertices, box, red, green, blue, alpha)
val test = UMatrixStack()
WorldRenderer.drawBox(matrix, vertex, box, red, green, blue, alpha)
return true
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/kotlin/net/usbwire/base/features/Poi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@ object Poi {
val shard: String,
val region: String?,
val subregion: String?,
val coordinates: JsonPoiCoordinates?
val coordinates: Coordinates.Coordinates?
)

@Serializable data class JsonPoiCoordinates(val x: Int, val y: Int, val z: Int)

val poiPath = Path.of("${BaseMod.configPath}/pois.json")
var poiMap: Map<String, JsonPoi> = emptyMap()
var poiSuggestions: List<String> = emptyList()
var firstRun: Boolean = true
var firstRun = true

@kotlinx.serialization.ExperimentalSerializationApi
fun fetchPoiData() {
URL("https://raw.githubusercontent.com/U5B/Monumenta/main/out/pois.json").openStream().use {
val project = Json.decodeFromStream<Map<String, JsonPoi>>(it) // read JSON from a URL
poiMap = project
updatePoiData(project)
savePoiData()
}
}

@kotlinx.serialization.ExperimentalSerializationApi
fun loadPoiData() {
if (Files.notExists(poiPath)) return fetchPoiData() // don't use file if it doesn't exist
Files.newInputStream(poiPath).use {
val project = Json.decodeFromStream<Map<String, JsonPoi>>(it) // read JSON from file
poiMap = project
updatePoiData(project)
}
}

@kotlinx.serialization.ExperimentalSerializationApi
private fun updatePoiData (project: Map<String, JsonPoi>) {
poiMap = project
makeCommandSuggestions()
}

private fun savePoiData() {
if (poiMap.isEmpty()) return
Util.createPath(poiPath)
Expand Down
42 changes: 0 additions & 42 deletions src/main/kotlin/net/usbwire/base/util/ColorUtil.kt

This file was deleted.

32 changes: 32 additions & 0 deletions src/main/kotlin/net/usbwire/base/util/MixinHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.usbwire.base.util

import java.awt.*
import net.minecraft.client.render.VertexConsumer
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.entity.Entity

import net.usbwire.base.config.VigilanceConfig
import net.usbwire.base.features.Health
import gg.essential.universal.UMatrixStack
import gg.essential.universal.wrappers.message.UTextComponent
import net.minecraft.text.Text

object MixinHelper {
fun renderHitbox(
matrix: MatrixStack,
vertex: VertexConsumer,
entity: Entity
) : Boolean {
return Health.renderHitbox(matrix, vertex, entity)
}

fun onMessage(
mcText: Text,
id: Int,
ticks: Int,
refresh: Boolean
) : Boolean {
val message = UTextComponent(mcText)
return false
}
}
41 changes: 41 additions & 0 deletions src/main/kotlin/net/usbwire/base/util/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,45 @@ object Util {
val prefix = UTextComponent(UChat.addColor("§7[§a${BaseMod.name}§7]§r "))
message.addTextComponent(0, prefix).chat()
}

object Color {
val xaero =
mapOf(
"black" to "0",
"dark_blue" to "1",
"dark_green" to "2",
"dark_aqua" to "3",
"dark_red" to "4",
"dark_purple" to "5",
"gold" to "6",
"gray" to "7",
"dark_gray" to "8",
"blue" to "9",
"green" to "10",
"aqua" to "11",
"red" to "12",
"light_purple" to "13",
"yellow" to "14",
"white" to "15"
)
val minecraft =
mapOf(
"black" to "§0",
"dark_blue" to "§1",
"dark_green" to "§2",
"dark_aqua" to "§3",
"dark_red" to "§4",
"dark_purple" to "§5",
"gold" to "§6",
"gray" to "§7",
"dark_gray" to "§8",
"blue" to "§9",
"green" to "§a",
"aqua" to "§b",
"red" to "§c",
"light_purple" to "§d",
"yellow" to "§e",
"white" to "§f"
)
}
}
12 changes: 6 additions & 6 deletions src/main/kotlin/net/usbwire/base/util/chat/Coordinates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import kotlinx.serialization.*
import kotlinx.serialization.json.*
import net.minecraft.text.ClickEvent
import net.usbwire.base.BaseMod
import net.usbwire.base.util.ColorUtil
import net.usbwire.base.util.Util

object Coordinates {
var supportsXaero = true
var supportsJourneymap = true
fun coordinateBuilder(name: String, x: Int, y: Int, z: Int, dimension: String): UMessage {
val message = UMessage().mutable()
fun coordinateBuilder(name: String, x: Int, y: Int, z: Int, dimension: String, message: UMessage = UMessage()): UMessage {
val coordinates = "${x}, ${y}, ${z}"

// prefix
Expand Down Expand Up @@ -59,8 +58,8 @@ object Coordinates {
// technically dimension but who cares
// TODO: map poi.region to dimension and set waypoint in correct dimension
val currentDimension = dimension.replace(":", "$")
val xaeroColor = ColorUtil.xaeroColorMap["dark_red"]
val minecraftColor = ColorUtil.minecraftColorMap["dark_red"]
val xaeroColor = Util.Color.xaero["dark_red"]
val minecraftColor = Util.Color.minecraft["dark_red"]
val xaeroCompoment = UTextComponent(" ${minecraftColor}[XAERO]§r")
val waypoint =
"xaero_waypoint_add:${name}:${name[0].uppercase()}:${x}:${y}:${z}:${xaeroColor}:false:0:Internal_dim%${currentDimension}_waypoints"
Expand All @@ -84,7 +83,7 @@ object Coordinates {
): UTextComponent? {
try {
Class.forName("journeymap.client.JourneymapClient")
val minecraftColor = ColorUtil.minecraftColorMap["aqua"]
val minecraftColor = Util.Color.minecraft["aqua"]
val journeymapCompoment = UTextComponent(" ${minecraftColor}[JM]§r")
val waypoint = "/jm wpedit [name:\"${name}\", x:${x}, y:${y}, z:${z}, dim:${dimension}]"
journeymapCompoment.clickAction = ClickEvent.Action.RUN_COMMAND
Expand All @@ -94,4 +93,5 @@ object Coordinates {
return null
}
}
@Serializable data class Coordinates(val x: Int, val y: Int, val z: Int)
}

0 comments on commit b2a39dc

Please sign in to comment.