Skip to content

Commit

Permalink
Improved interpolation performance in dungeons/slayer hit-box drawing…
Browse files Browse the repository at this point in the history
… context (#387)
  • Loading branch information
inglettronald authored Aug 29, 2023
1 parent 226633c commit e86f5d2
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Skytils - Hypixel Skyblock Quality of Life Mod
* Copyright (C) 2020-2023 Skytils
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package gg.skytils.skytilsmod.mixins.transformers.accessors;

import net.minecraft.client.renderer.entity.RenderManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(RenderManager.class)
public interface AccessorRenderManager {

@Accessor("renderPosX")
double getRenderX();

@Accessor("renderPosY")
double getRenderY();

@Accessor("renderPosZ")
double getRenderZ();
}
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,8 @@ object DungeonFeatures {
) {
GlStateManager.disableCull()
GlStateManager.disableDepth()
val (viewerX, viewerY, viewerZ) = RenderUtil.getViewerPos(1f)
val x = event.entity.posX - viewerX
val y = event.entity.posY - viewerY
val z = event.entity.posZ - viewerZ
val (vx, vy, vz) = RenderUtil.getViewerPos(RenderUtil.getPartialTicks())
val (x, y, z) = RenderUtil.fixRenderPos(event.x - vx, event.y - vy, event.z - vz)
RenderUtil.drawFilledBoundingBox(
matrixStack,
AxisAlignedBB(x, y, z, x + 0.75, y + 1.975, z + 0.75),
Expand Down Expand Up @@ -536,8 +534,17 @@ object DungeonFeatures {
RenderUtil.getPartialTicks()
)
} else if (hasBossSpawned && Skytils.config.boxSpiritBears && event.entity.name == "Spirit Bear" && event.entity is EntityOtherPlayerMP) {
val (x, y, z) = RenderUtil.fixRenderPos(event.x, event.y, event.z)
val aabb = AxisAlignedBB(
x - 0.5,
y,
z - 0.5,
x + 0.5,
y + 2,
z + 0.5
)
RenderUtil.drawOutlinedBoundingBox(
event.entity.entityBoundingBox,
aabb,
Color(121, 11, 255, 255),
3f,
RenderUtil.getPartialTicks()
Expand All @@ -547,24 +554,7 @@ object DungeonFeatures {
if (!hasBossSpawned && Skytils.config.boxStarredMobs && event.entity is EntityArmorStand && event.entity.hasCustomName() && event.entity.alwaysRenderNameTag) {
val name = event.entity.name
if (name.startsWith("§6✯ ") && name.endsWith("§c❤")) {
val x =
RenderUtil.interpolate(
event.entity.lastTickPosX,
event.entity.posX,
RenderUtil.getPartialTicks()
)
val y =
RenderUtil.interpolate(
event.entity.lastTickPosY,
event.entity.posY,
RenderUtil.getPartialTicks()
)
val z =
RenderUtil.interpolate(
event.entity.lastTickPosZ,
event.entity.posZ,
RenderUtil.getPartialTicks()
)
val (x, y, z) = RenderUtil.fixRenderPos(event.x, event.y, event.z)
val color = Color(0, 255, 255, 255)
if ("Spider" in name) {
RenderUtil.drawOutlinedBoundingBox(
Expand Down Expand Up @@ -600,13 +590,14 @@ object DungeonFeatures {
}
}
if (event.entity == lividTag) {
val (x, y, z) = RenderUtil.fixRenderPos(event.x, event.y, event.z)
val aabb = AxisAlignedBB(
event.entity.posX - 0.5,
event.entity.posY - 2,
event.entity.posZ - 0.5,
event.entity.posX + 0.5,
event.entity.posY,
event.entity.posZ + 0.5
x - 0.5,
y - 2,
z - 0.5,
x + 0.5,
y,
z + 0.5
)
RenderUtil.drawOutlinedBoundingBox(
aabb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,7 @@ object SlayerFeatures : CoroutineScope {
if (!entity.hasCustomName()) return
val name = entity.displayName.unformattedText
if (Skytils.config.slayerBossHitbox && name.endsWith("§c❤") && !name.endsWith("§e0§c❤") && !mc.renderManager.isDebugBoundingBox) {
val x =
RenderUtil.interpolate(event.entity.lastTickPosX, event.entity.posX, RenderUtil.getPartialTicks())
val y =
RenderUtil.interpolate(event.entity.lastTickPosY, event.entity.posY, RenderUtil.getPartialTicks())
val z =
RenderUtil.interpolate(event.entity.lastTickPosZ, event.entity.posZ, RenderUtil.getPartialTicks())
val (x, y, z) = RenderUtil.fixRenderPos(event.x, event.y, event.z)
if (ZOMBIE_MINIBOSSES.any { name.contains(it) } || BLAZE_MINIBOSSES.any { name.contains(it) }) {
drawOutlinedBoundingBox(
AxisAlignedBB(x - 0.5, y - 2, z - 0.5, x + 0.5, y, z + 0.5),
Expand Down
31 changes: 31 additions & 0 deletions src/main/kotlin/gg/skytils/skytilsmod/utils/RenderUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.core.structure.GuiElement
import gg.skytils.skytilsmod.mixins.hooks.renderer.skipGlint
import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorMinecraft
import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorRenderManager
import gg.skytils.skytilsmod.utils.graphics.ScreenRenderer
import gg.skytils.skytilsmod.utils.graphics.SmartFontRenderer
import gg.skytils.skytilsmod.utils.graphics.colors.CommonColors
Expand Down Expand Up @@ -710,6 +711,36 @@ object RenderUtil {
fun getPartialTicks() =
(mc as AccessorMinecraft).timer.renderPartialTicks

/**
* Helper method for fixRenderPos
*/
fun getRenderX() : Double {
return (mc.renderManager as AccessorRenderManager).renderX
}

/**
* Helper method for fixRenderPos
*/
fun getRenderY() : Double {
return (mc.renderManager as AccessorRenderManager).renderY
}

/**
* Helper method for fixRenderPos
*/
fun getRenderZ() : Double {
return (mc.renderManager as AccessorRenderManager).renderZ
}

/**
* Method used to Gather event location parameters and return their interpolated counterparts.
*
* Working particularly well in RenderLivingEvent.Pre/Post<*>
*/
fun fixRenderPos(x: Double, y: Double, z: Double, invert: Boolean = false) : Triple<Double, Double, Double> {
return Triple(x + getRenderX(), y + getRenderY(), z + getRenderZ())
}

infix fun Slot.highlight(color: Color) {
Gui.drawRect(
this.xDisplayPosition,
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/mixins.skytils.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"accessors.AccessorMinecraft",
"accessors.AccessorModelDragon",
"accessors.AccessorRenderItem",
"accessors.AccessorRenderManager",
"accessors.AccessorS3BPacketScoreboardObjective",
"accessors.AccessorServerListEntryNormal",
"accessors.AccessorSettingsGui",
Expand Down

0 comments on commit e86f5d2

Please sign in to comment.