Skip to content

Commit 8824b53

Browse files
authored
Misc: Cleanup warnings
GitHub: #77
1 parent 6eafe0f commit 8824b53

File tree

10 files changed

+32
-11
lines changed

10 files changed

+32
-11
lines changed

src/main/java/gg/essential/universal/UGraphics.java

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import net.minecraft.client.renderer.texture.ITextureObject;
8686
//#endif
8787

88+
@SuppressWarnings("deprecation") // lots of MC methods are deprecated on some versions but only replaced on the next one
8889
public class UGraphics {
8990
private static final Pattern formattingCodePattern = Pattern.compile("(?i)\u00a7[0-9A-FK-OR]");
9091

src/main/kotlin/gg/essential/universal/UImage.kt

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class UImage(val nativeImage: BufferedImage) {
6767
//#if MC>=11600
6868
//$$ return UImage(NativeImage(width, height, clear))
6969
//#else
70+
@Suppress("UNUSED_EXPRESSION") clear // not yet using native memory, so it'll be cleared by the jvm
7071
return UImage(BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB))
7172
//#endif
7273
}

src/main/kotlin/gg/essential/universal/UKeyboard.kt

+3
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ object UKeyboard {
250250
fun allowRepeatEvents(enabled: Boolean) {
251251
//#if MC>=11903
252252
//$$ // Minecraft removed this function in 1.19.3, repeat events are now always enabled.
253+
//$$ @Suppress("UNUSED_EXPRESSION") enabled
253254
//#elseif MC>=11502
254255
//$$ UMinecraft.getMinecraft().keyboardListener.enableRepeatEvents(enabled)
255256
//#else
@@ -348,10 +349,12 @@ object UKeyboard {
348349
//$$ if (it.length == 1) it.uppercase() else it
349350
//$$ }
350351
//#else
352+
@Suppress("UNUSED_EXPRESSION") scanCode
351353
return Keyboard.getKeyName(keyCode)
352354
//#endif
353355
}
354356

357+
@Suppress("DEPRECATION")
355358
@Deprecated("Does not work for mouse or scanCode-type bindings", replaceWith = ReplaceWith("getKeyName(keyCode, -1)"))
356359
@JvmStatic
357360
fun getKeyName(keyCode: Int): String? = getKeyName(keyCode, -1)

src/main/kotlin/gg/essential/universal/UMatrixStack.kt

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class UMatrixStack private constructor(
165165
//$$ model.mul(quaternion)
166166
//$$ normal.mul(quaternion)
167167
//#else
168+
@Suppress("UNUSED_EXPRESSION") quaternion
168169
TODO("lwjgl quaternion multiply") // there seems to be no existing methods to do this
169170
//#endif
170171
}

src/main/kotlin/gg/essential/universal/UMinecraft.kt

+3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ object UMinecraft {
7676
}
7777

7878
@JvmStatic
79+
//#if FORGE
80+
@Suppress("UNNECESSARY_SAFE_CALL") // Forge adds inappropriate NonNullByDefault
81+
//#endif
7982
fun getChatGUI(): GuiNewChat? = getMinecraft().ingameGUI?.chatGUI
8083

8184
@JvmStatic

src/main/kotlin/gg/essential/universal/shader/UShader.kt

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface UShader {
4545
//#if MC>=11700
4646
//$$ return MCShader.fromLegacyShader(vertSource, fragSource, blendState, vertexFormat)
4747
//#else
48+
@Suppress("UNUSED_EXPRESSION") vertexFormat // only relevant to MCShader
4849
return GlShader(vertSource, fragSource, blendState)
4950
//#endif
5051
}

src/main/kotlin/gg/essential/universal/wrappers/UPlayer.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ object UPlayer {
1919
//#if MC>=11900
2020
//$$ getPlayer()!!.sendMessage(message)
2121
//#elseif MC>=11602
22+
//#if FORGE
23+
//$$ @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") // Forge adds inappropriate NonNullByDefault
24+
//#endif
2225
//$$ getPlayer()!!.sendMessage(message, null)
2326
//#elseif MC>=11202
2427
//$$ getPlayer()!!.sendMessage(message)
@@ -30,7 +33,7 @@ object UPlayer {
3033
@JvmStatic
3134
fun getUUID(): UUID {
3235
//#if MC>=12002
33-
//$$ return UMinecraft.getMinecraft().session.uuidOrNull!!
36+
//$$ return UMinecraft.getMinecraft().session.uuidOrNull // misnamed, should not actually ever be null
3437
//#else
3538
return UMinecraft.getMinecraft().session.profile.id
3639
//#endif

src/main/kotlin/gg/essential/universal/wrappers/message/UTextComponent.kt

+11-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class UTextComponent : IChatComponent {
4545
lateinit var component: IChatComponent
4646
//#endif
4747
private set
48-
var text: String
48+
var text: String = ""
4949
set(value) {
5050
field = value
5151
reInstance()
@@ -156,10 +156,12 @@ class UTextComponent : IChatComponent {
156156
}
157157

158158
private fun reInstanceClick() {
159+
val clickAction = clickAction
160+
val clickValue = clickValue
159161
if (clickAction == null || clickValue == null)
160162
return
161163

162-
val event = ClickEvent(clickAction, clickValue!!.formatIf(formatted))
164+
val event = ClickEvent(clickAction, clickValue.formatIf(formatted))
163165

164166
//#if MC>=11600
165167
//$$ component.style = component.style.setClickEvent(event)
@@ -171,17 +173,20 @@ class UTextComponent : IChatComponent {
171173
}
172174

173175
private fun reInstanceHover() {
176+
val hoverAction = hoverAction
177+
val hoverValue = hoverValue
174178
if (hoverAction == null || hoverValue == null)
175179
return
176180

177181
//#if MC>=11602
178-
//$$ val event = HoverEvent<Any>(hoverAction as HoverEvent.Action<Any>, hoverValue!!)
182+
//$$ @Suppress("UNCHECKED_CAST")
183+
//$$ val event = HoverEvent(hoverAction as HoverEvent.Action<Any>, hoverValue)
179184
//$$ setHoverEventHelper(event)
180185
//#else
181186
val value: IChatComponent = when (hoverValue) {
182-
is String -> ChatComponentText(hoverValue as String)
183-
is UTextComponent -> (hoverValue as UTextComponent).component
184-
is IChatComponent -> hoverValue as IChatComponent
187+
is String -> ChatComponentText(hoverValue)
188+
is UTextComponent -> hoverValue.component
189+
is IChatComponent -> hoverValue
185190
else -> ChatComponentText(hoverValue.toString())
186191
}
187192
setHoverEventHelper(HoverEvent(

versions/1.17.1-fabric/src/main/kotlin/gg/essential/universal/shader/MCShader.kt

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ internal class MCShader(
137137

138138

139139
val name = DigestUtils.sha1Hex(json).lowercase()
140+
//#if FORGE
141+
//$$ @Suppress("DEPRECATION") // Forge wants us to use its overload, but we don't care
142+
//#endif
140143
return MCShader(Shader(factory, name, shaderVertexFormat), blendState)
141144
}
142145
}

versions/1.19.3-fabric/src/main/kotlin/gg/essential/universal/DummyPack.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ internal object DummyPack : ResourcePack {
2424
throw UnsupportedOperationException()
2525
}
2626

27-
override fun open(type: ResourceType?, id: Identifier?): InputSupplier<InputStream>? {
27+
override fun open(type: ResourceType, id: Identifier): InputSupplier<InputStream>? {
2828
throw UnsupportedOperationException()
2929
}
3030

31-
override fun findResources(type: ResourceType?, namespace: String?, prefix: String?, consumer: ResourcePack.ResultConsumer?) {
31+
override fun findResources(type: ResourceType, namespace: String, prefix: String, consumer: ResourcePack.ResultConsumer) {
3232
throw UnsupportedOperationException()
3333
}
3434

35-
override fun getNamespaces(type: ResourceType?): MutableSet<String> {
35+
override fun getNamespaces(type: ResourceType): MutableSet<String> {
3636
throw UnsupportedOperationException()
3737
}
3838

39-
override fun <T : Any?> parseMetadata(metaReader: ResourceMetadataReader<T>?): T? {
39+
override fun <T : Any?> parseMetadata(metaReader: ResourceMetadataReader<T>): T? {
4040
throw UnsupportedOperationException()
4141
}
4242

0 commit comments

Comments
 (0)