Skip to content

Commit

Permalink
misc: make emulated entity hitbox crosshair color when hovered
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyvest committed Feb 6, 2022
1 parent c9a970f commit d0edc9b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2G

# Define project properties.
mod_name=REDACTION
mod_ver=1.1.0-beta2
mod_ver=1.1.0-pre1
28 changes: 2 additions & 26 deletions src/main/java/net/wyvest/redaction/mixin/RenderManagerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.wyvest.redaction.features.hitbox.Entity;
import net.wyvest.redaction.features.hitbox.GeneralConfig;
import net.wyvest.redaction.gui.HitboxPreviewGUI;
Expand Down Expand Up @@ -57,7 +56,7 @@ private void initHitbox(net.minecraft.entity.Entity entityIn, double x, double y
eye = entity.getEyeLineEnabled();
line = entity.getLineEnabled();
hitboxColor = entity.getColor();
crosshairColor = entity.getColor();
crosshairColor = entity.getCrosshairColor();
eyeColor = entity.getEyeColor();
lineColor = entity.getLineColor();
GL11.glLineWidth(GeneralConfig.getConfig().getHitboxWidth());
Expand Down Expand Up @@ -85,7 +84,7 @@ private void initHitbox(net.minecraft.entity.Entity entityIn, double x, double y
@Redirect(method = "renderDebugBoundingBox", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;drawOutlinedBoundingBox(Lnet/minecraft/util/AxisAlignedBB;IIII)V", ordinal = 0))
private void shouldRenderHitbox(AxisAlignedBB boundingBox, int red, int green, int blue, int alpha, net.minecraft.entity.Entity entityIn, double x, double y, double z, float entityYaw, float partialTicks) {
if (box) {
int color = isWithinCrosshair(entityIn) ? crosshairColor : hitboxColor;
int color = (Minecraft.getMinecraft().objectMouseOver != null && Minecraft.getMinecraft().objectMouseOver.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY && Minecraft.getMinecraft().objectMouseOver.entityHit.equals(entityIn)) || (HitboxPreviewGUI.Companion.getBypassHitbox() && HitboxPreviewGUI.Companion.getCursorOverEmulatedEntity()) ? crosshairColor : hitboxColor;
RenderGlobal.drawOutlinedBoundingBox((GeneralConfig.getConfig().getAccurateHitbox() ? boundingBox.expand(entityIn.getCollisionBorderSize(), entityIn.getCollisionBorderSize(), entityIn.getCollisionBorderSize()) : boundingBox), ColorUtils.getRed(color), ColorUtils.getGreen(color), ColorUtils.getBlue(color), alpha);
}
}
Expand Down Expand Up @@ -118,27 +117,4 @@ private void modifyEyeLineColor(Args args) {
private void resetEmulatedPlayerHitboxBypass(net.minecraft.entity.Entity entityIn, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci) {
GL11.glLineWidth(1);
}

/**
* Adapted from EvergreenHUD under GPLv3
* https://github.com/isXander/EvergreenHUD/blob/main/LICENSE
*
*
* Modified to be more compact.
*/
private boolean isWithinCrosshair(net.minecraft.entity.Entity entity) {
if (entity == null) return false;
Minecraft.getMinecraft().mcProfiler.startSection("Calculating Reach Dist");
double maxSize = 3.0;
AxisAlignedBB otherBB = entity.getEntityBoundingBox();
float collisionBorderSize = entity.getCollisionBorderSize();
AxisAlignedBB otherHitbox = otherBB.expand(collisionBorderSize, collisionBorderSize, collisionBorderSize);
Vec3 eyePos = Minecraft.getMinecraft().thePlayer.getPositionEyes(1.0f);
Vec3 lookPos = Minecraft.getMinecraft().thePlayer.getLook(1.0f);
Vec3 adjustedPos = eyePos.addVector(lookPos.xCoord * maxSize, lookPos.yCoord * maxSize, lookPos.zCoord * maxSize);
MovingObjectPosition movingObjectPosition = otherHitbox.calculateIntercept(eyePos, adjustedPos);
if (movingObjectPosition == null) return false;
Minecraft.getMinecraft().mcProfiler.endSection();
return true;
}
}
13 changes: 12 additions & 1 deletion src/main/kotlin/net/wyvest/redaction/gui/HitboxPreviewGUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HitboxPreviewGUI @JvmOverloads constructor(private val returnToConfigGUI:
} constrain {
x = CenterConstraint()
y = CenterConstraint()
width = 100.percent()
width = 14.percent()
height = 100.percent()
} childOf block effect ScissorEffect(block)

Expand Down Expand Up @@ -135,6 +135,13 @@ class HitboxPreviewGUI @JvmOverloads constructor(private val returnToConfigGUI:
resetSettings(it)
}
resetSettings(1)
cursorOverEmulatedEntity = false
player.onMouseEnter {
cursorOverEmulatedEntity = true
}
player.onMouseLeave {
cursorOverEmulatedEntity = false
}
}

private fun resetSettings(i: Int) {
Expand Down Expand Up @@ -314,12 +321,16 @@ class HitboxPreviewGUI @JvmOverloads constructor(private val returnToConfigGUI:
EssentialAPI.getGuiUtil().openScreen(RedactionConfig.gui())
}
Hitboxes.writeConfig()
cursorOverEmulatedEntity = false
}

companion object {
val bypassHitbox
get() = Minecraft.getMinecraft().currentScreen is HitboxPreviewGUI

var cursorOverEmulatedEntity = false
private set

var entityToEmulate: Entity = Entity.blank
private set
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RedactionMixinPlugin : IMixinConfigPlugin {
return@run it
}
}
returned = true
returned = true // this is set to true so mods like crashpatch can recover from these crashes
throw RuntimeException("REDACTION ASM Failed, please go to https://woverflow.cc/discord for support!")
})
method.instructions.insert(insn.next.next.next, fieldinsn)
Expand Down

0 comments on commit d0edc9b

Please sign in to comment.