1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package com.dulkirfabric.features
import com.dulkirfabric.DulkirModFabric.mc
import com.dulkirfabric.config.DulkirConfig
import com.dulkirfabric.events.ClientTickEvent
import com.dulkirfabric.events.LongUpdateEvent
import com.dulkirfabric.events.WorldRenderLastEvent
import com.dulkirfabric.util.render.WorldRenderUtils
import meteordevelopment.orbit.EventHandler
import net.minecraft.client.MinecraftClient
import net.minecraft.client.util.InputUtil
import net.minecraft.entity.Entity
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.hit.HitResult
import net.minecraft.util.math.Vec3d
import net.minecraft.world.RaycastContext
import org.lwjgl.glfw.GLFW
import java.awt.Color
object AotvHighlight {
private var heldItemID = ""
@EventHandler
fun onTick(event: ClientTickEvent) {
heldItemID = getHeldItemID()
}
fun getHeldItemID(): String {
val stack = mc.player?.mainHandStack ?: return ""
val tag = stack.nbt ?: return ""
val id = tag.getCompound("ExtraAttributes").get("id") ?: return ""
return id.toString().trim('"')
}
@EventHandler
fun onLong(event: LongUpdateEvent) {
//println(heldItemID)
}
@EventHandler
fun onWorldRenderLast(event: WorldRenderLastEvent) {
if (!DulkirConfig.configOptions.showEtherwarpPreview) return
// check that holding aotv
if (heldItemID != "ASPECT_OF_THE_VOID") return
val handle = MinecraftClient.getInstance().window.handle
if (!InputUtil.isKeyPressed(handle, GLFW.GLFW_KEY_LEFT_SHIFT)) return
// Find the targeted block with a range of 60.9
val entity = mc.cameraEntity
if (mc.player == null) return
val blockHit = raycast(entity!!, 60.9, mc.tickDelta)
if (blockHit.type != HitResult.Type.BLOCK) return
val pos = (blockHit as BlockHitResult).blockPos
// if found display box
WorldRenderUtils.drawBox(event.context, pos.x.toDouble(), pos.y.toDouble(), pos.z.toDouble(), 1.0, 1.0, 1.0,
Color(DulkirConfig.configOptions.etherwarpPreviewColor, true), false)
}
private fun raycast(entity: Entity, maxDistance: Double, tickDelta: Float): HitResult {
// 1.7 if not crouch, 1.54 if crouch
val crouching = mc.player!!.isSneaking
var vec3d: Vec3d = mc.player!!.pos.add(0.0, if (crouching) 1.54 else 1.7, 0.0)
val vec3d2: Vec3d = entity.getRotationVec(tickDelta)
val vec3d3 = vec3d.add(vec3d2.x * maxDistance, vec3d2.y * maxDistance, vec3d2.z * maxDistance)
return mc.world!!
.raycast(
RaycastContext(
vec3d,
vec3d3,
RaycastContext.ShapeType.OUTLINE,
RaycastContext.FluidHandling.ANY,
entity
)
)
}
}
|