Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Respect minecraft nullability in more places #2847

Merged
merged 11 commits into from
Nov 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ import net.minecraft.util.ChatComponentText
* chat component, but rather makes a new one just before rendering.
*/
class ChatHoverEvent(val component: ChatComponentText) : LorenzEvent() {
fun getHoverEvent(): HoverEvent = component.chatStyle.chatHoverEvent
fun getHoverEvent(): HoverEvent = component.chatStyle.chatHoverEvent!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,12 @@ object DamageIndicatorManager {
hitPhaseText = NumberUtil.percentageColor(hits.toLong(), maxHits.toLong()).getChatColor() + "$hits Hits"
}

val ridingEntity = entity.ridingEntity
// Laser phase
if (config.enderSlayer.laserPhaseTimer && entity.ridingEntity != null) {
if (config.enderSlayer.laserPhaseTimer && ridingEntity != null) {
val totalTimeAlive = 8.2.seconds

val ticksAlive = entity.ridingEntity.ticksExisted.ticks
val ticksAlive = ridingEntity.ticksExisted.ticks
val remainingTime = totalTimeAlive - ticksAlive
val formatDelay = formatDelay(remainingTime)
if (config.enderSlayer.showHealthDuringLaser || hitPhaseText != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ object HarpFeatures {
val minecraft = Minecraft.getMinecraft()
val width = GuiScreenUtils.scaledWindowWidth
val height = GuiScreenUtils.scaledWindowHeight
minecraft.currentScreen.setWorldAndResolution(minecraft, width, height)
minecraft.currentScreen?.setWorldAndResolution(minecraft, width, height)
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object PrecisionMiningHighlight {
!Minecraft.getMinecraft().gameSettings.keyBindAttack.isKeyDown
) return

val mouseOverObject = Minecraft.getMinecraft().objectMouseOver
val mouseOverObject = Minecraft.getMinecraft().objectMouseOver ?: return
if (mouseOverObject.typeOfHit != MovingObjectPosition.MovingObjectType.BLOCK) return

val particleBoundingBox = event.location.add(-0.12, -0.12, -0.12)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ object QuickModMenuSwitch {
return config.javaClass.name
}
if (openGui == "cc.polyfrost.oneconfig.gui.OneConfigGui") {
val actualGui = Minecraft.getMinecraft().currentScreen
val actualGui = Minecraft.getMinecraft().currentScreen ?: return openGui
val currentPage = actualGui.javaClass.getDeclaredField("currentPage")
.makeAccessible()
.get(actualGui)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object ReplaceRomanNumerals {
lore.replaceAll { it.transformLine() }

val chatComponentText = ChatComponentText(lore.joinToString("\n"))
val hoverEvent = HoverEvent(event.component.chatStyle.chatHoverEvent.action, chatComponentText)
val hoverEvent = HoverEvent(event.component.chatStyle.chatHoverEvent?.action, chatComponentText)

GuiChatHook.replaceOnlyHoverEvent(hoverEvent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TabLine(val text: String, val type: TabStringType, val customName: String
fun getInfo(): NetworkPlayerInfo? {
val minecraft = Minecraft.getMinecraft()
val usernameFromLine = TabStringType.usernameFromLine(text)
return minecraft.netHandler.getPlayerInfo(usernameFromLine)
return minecraft.netHandler?.getPlayerInfo(usernameFromLine)
}

private var entity: EntityPlayer? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ object EnchantParser {

// Just set the component text to the entire lore list instead of reconstructing the entire siblings tree
val chatComponentText = ChatComponentText(text)
val hoverEvent = HoverEvent(chatComponent.chatStyle.chatHoverEvent.action, chatComponentText)
val hoverEvent = HoverEvent(chatComponent.chatStyle.chatHoverEvent?.action, chatComponentText)

GuiChatHook.replaceOnlyHoverEvent(hoverEvent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,11 @@ object TrevorFeatures {

clickOptionPattern.findMatcher(event.message) {
for (sibling in event.chatComponent.siblings) {
if (sibling.chatStyle.chatClickEvent != null && sibling.chatStyle.chatClickEvent.value.contains("YES")) {
val clickEvent = sibling.chatStyle.chatClickEvent ?: continue

if (clickEvent.value.contains("YES")) {
lastChatPromptTime = SimpleTimeMark.now()
lastChatPrompt = sibling.chatStyle.chatClickEvent.value.substringAfter(" ")
lastChatPrompt = clickEvent.value.substringAfter(" ")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
class RenderGlobalHook {

fun renderEntitiesOutlines(camera: ICamera?, partialTicks: Float): Boolean {
val vec = RenderUtils.exactLocation(Minecraft.getMinecraft().renderViewEntity, partialTicks)
val vec = Minecraft.getMinecraft().renderViewEntity?.let { RenderUtils.exactLocation(it, partialTicks) } ?: return false
return EntityOutlineRenderer.renderEntityOutlines(camera!!, partialTicks, vec)
}

Expand Down
24 changes: 13 additions & 11 deletions src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ object RenderUtils {
Triple(xTranslate, yTranslate, zTranslate)
}

fun getViewerPos(partialTicks: Float) = exactLocation(Minecraft.getMinecraft().renderViewEntity, partialTicks)
fun getViewerPos(partialTicks: Float) =
Minecraft.getMinecraft().renderViewEntity?.let { exactLocation(it, partialTicks) } ?: LorenzVec()

fun AxisAlignedBB.expandBlock(n: Int = 1) = expand(LorenzVec.expandVector * n)
fun AxisAlignedBB.inflateBlock(n: Int = 1) = expand(LorenzVec.expandVector * -n)
Expand Down Expand Up @@ -352,9 +353,9 @@ object RenderUtils {
seeThroughBlocks: Boolean = false,
color: Color? = null,
) {
val viewer = Minecraft.getMinecraft().renderViewEntity ?: return
GlStateManager.alphaFunc(516, 0.1f)
GlStateManager.pushMatrix()
val viewer = Minecraft.getMinecraft().renderViewEntity
val renderManager = Minecraft.getMinecraft().renderManager
var x = location.x - renderManager.viewerPosX
var y = location.y - renderManager.viewerPosY - viewer.eyeHeight
Expand Down Expand Up @@ -993,15 +994,16 @@ object RenderUtils {
ignoreY: Boolean = false,
maxDistance: Int? = null,
) {
val thePlayer = Minecraft.getMinecraft().thePlayer
val viewer = Minecraft.getMinecraft().renderViewEntity ?: return
val thePlayer = Minecraft.getMinecraft().thePlayer ?: return

val x = location.x
val y = location.y
val z = location.z

val render = Minecraft.getMinecraft().renderViewEntity
val renderOffsetX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks
val renderOffsetY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks
val renderOffsetZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks
val renderOffsetX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks
val renderOffsetY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks
val renderOffsetZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks
val eyeHeight = thePlayer.eyeHeight

val dX = (x - renderOffsetX) * (x - renderOffsetX)
Expand Down Expand Up @@ -1617,13 +1619,13 @@ object RenderUtils {
lineWidth: Int,
depth: Boolean,
) {
val viewer = Minecraft.getMinecraft().renderViewEntity ?: return
GlStateManager.disableCull()

val render = Minecraft.getMinecraft().renderViewEntity
val worldRenderer = Tessellator.getInstance().worldRenderer
val realX = render.lastTickPosX + (render.posX - render.lastTickPosX) * partialTicks
val realY = render.lastTickPosY + (render.posY - render.lastTickPosY) * partialTicks
val realZ = render.lastTickPosZ + (render.posZ - render.lastTickPosZ) * partialTicks
val realX = viewer.lastTickPosX + (viewer.posX - viewer.lastTickPosX) * partialTicks
val realY = viewer.lastTickPosY + (viewer.posY - viewer.lastTickPosY) * partialTicks
val realZ = viewer.lastTickPosZ + (viewer.posZ - viewer.lastTickPosZ) * partialTicks
GlStateManager.pushMatrix()
GlStateManager.translate(-realX, -realY, -realZ)
GlStateManager.disableTexture2D()
Expand Down
1 change: 1 addition & 0 deletions versions/1.8.9/detekt/baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<ID>TooManyFunctions:SkyBlockItemModifierUtils.kt$SkyBlockItemModifierUtils</ID>
<ID>TooManyFunctions:StringUtils.kt$StringUtils</ID>
<ID>UnsafeCallOnNullableType:BucketedItemTrackerData.kt$BucketedItemTrackerData$it.value[internalName]?.hidden!!</ID>
<ID>UnsafeCallOnNullableType:ChatHoverEvent.kt$ChatHoverEvent$component.chatStyle.chatHoverEvent!!</ID>
<ID>UnsafeCallOnNullableType:ChocolateFactoryDataLoader.kt$ChocolateFactoryDataLoader$upgradeCost!!</ID>
<ID>UnsafeCallOnNullableType:CollectionUtils.kt$CollectionUtils$this.merge(key, number, Double::plus)!!</ID>
<ID>UnsafeCallOnNullableType:CollectionUtils.kt$CollectionUtils$this.merge(key, number, Float::plus)!!</ID>
Expand Down
30 changes: 18 additions & 12 deletions versions/1.8.9/shots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@ net.minecraft.client.Minecraft:
annotate org.jetbrains.annotations.NotNull
displayGuiScreen(net.minecraft.client.gui.GuiScreen):
annotateParameter 0 org.jetbrains.annotations.Nullable
getNetHandler():
annotate org.jetbrains.annotations.Nullable
getRenderViewEntity():
annotate org.jetbrains.annotations.Nullable
pointedEntity:
annotate org.jetbrains.annotations.Nullable
objectMouseOver:
annotate org.jetbrains.annotations.Nullable
currentScreen:
annotate org.jetbrains.annotations.Nullable
# thePlayer:
# annotate org.jetbrains.annotations.Nullable
# pointedEntity:
# annotate org.jetbrains.annotations.Nullable
# currentScreen:
# annotate org.jetbrains.annotations.Nullable
# objectMouseOver:
# annotate org.jetbrains.annotations.Nullable
# theWorld:
# annotate org.jetbrains.annotations.Nullable
#net.minecraft.util.ChatStyle:
# getChatClickEvent():
# annotate org.jetbrains.annotations.Nullable
# getChatHoverEvent():
# annotate org.jetbrains.annotations.Nullable
#
net.minecraft.util.ChatStyle:
getChatClickEvent():
annotate org.jetbrains.annotations.Nullable
getChatHoverEvent():
annotate org.jetbrains.annotations.Nullable
net.minecraft.item.ItemStack:
<init>(net.minecraft.block.Block):
annotateParameter 0 org.jetbrains.annotations.NotNull
Expand All @@ -76,3 +79,6 @@ net.minecraft.item.ItemStack:
<init>(net.minecraft.item.Item, int, int, net.minecraft.nbt.NBTTagCompound):
annotateParameter 0 org.jetbrains.annotations.NotNull
annotateParameter 3 org.jetbrains.annotations.Nullable
net.minecraft.entity.Entity:
ridingEntity:
annotate org.jetbrains.annotations.Nullable
Loading