|
1 | 1 | package me.m56738.smoothcoasters; |
2 | 2 |
|
| 3 | +import com.mojang.blaze3d.platform.InputConstants; |
3 | 4 | import me.m56738.smoothcoasters.implementation.Implementation; |
4 | 5 | import me.m56738.smoothcoasters.network.EntityPropertiesPayload; |
5 | 6 | import me.m56738.smoothcoasters.network.EntityRotationPayload; |
|
18 | 19 | import net.minecraft.client.Minecraft; |
19 | 20 | import net.minecraft.client.gui.components.debug.DebugScreenEntries; |
20 | 21 | import net.minecraft.network.chat.Component; |
21 | | -import net.minecraft.resources.ResourceLocation; |
| 22 | +import net.minecraft.resources.Identifier; |
22 | 23 | import org.joml.Quaternionf; |
23 | 24 | import org.joml.Quaternionfc; |
| 25 | +import org.jspecify.annotations.Nullable; |
24 | 26 | import org.lwjgl.glfw.GLFW; |
25 | | -import com.mojang.blaze3d.platform.InputConstants; |
| 27 | + |
26 | 28 | import java.util.NoSuchElementException; |
| 29 | +import java.util.Objects; |
27 | 30 |
|
28 | 31 | public class SmoothCoasters implements ClientModInitializer { |
29 | | - private static final ResourceLocation HANDSHAKE = ResourceLocation.fromNamespaceAndPath("smoothcoasters", "hs"); |
30 | | - private static final KeyMapping.Category CAMERA = KeyMapping.Category.register(ResourceLocation.fromNamespaceAndPath("smoothcoasters", "camera")); |
| 32 | + private static final Identifier HANDSHAKE = Identifier.fromNamespaceAndPath("smoothcoasters", "hs"); |
| 33 | + private static final KeyMapping.Category CAMERA = KeyMapping.Category.register(Identifier.fromNamespaceAndPath("smoothcoasters", "camera")); |
31 | 34 | private static final Quaternionf IDENTITY = new Quaternionf(); |
32 | | - private static SmoothCoasters instance; |
33 | | - private Implementation currentImplementation; |
34 | | - private String version; |
35 | | - private KeyMapping toggleBinding; |
| 35 | + private static @Nullable SmoothCoasters instance; |
| 36 | + private @Nullable Implementation currentImplementation; |
| 37 | + private @Nullable String version; |
| 38 | + private @Nullable KeyMapping toggleBinding; |
36 | 39 |
|
37 | 40 | public static SmoothCoasters getInstance() { |
38 | | - return instance; |
| 41 | + return Objects.requireNonNull(instance); |
39 | 42 | } |
40 | 43 |
|
41 | | - public String getVersion() { |
| 44 | + public @Nullable String getVersion() { |
42 | 45 | return version; |
43 | 46 | } |
44 | 47 |
|
@@ -88,27 +91,27 @@ public void onInitializeClient() { |
88 | 91 | } |
89 | 92 | }); |
90 | 93 |
|
91 | | - DebugScreenEntries.register(ResourceLocation.fromNamespaceAndPath("smoothcoasters", "version"), new SmoothCoastersDebugHudEntry()); |
| 94 | + DebugScreenEntries.register(Identifier.fromNamespaceAndPath("smoothcoasters", "version"), new SmoothCoastersDebugHudEntry()); |
92 | 95 | } |
93 | 96 |
|
94 | 97 | private void handleHandshake(HandshakePayload payload, ClientPlayNetworking.Context context) { |
95 | 98 | context.client().execute(() -> performHandshake(payload.versions())); |
96 | 99 | } |
97 | 100 |
|
98 | | - private void setCurrentImplementation(Implementation implementation) { |
| 101 | + private void setCurrentImplementation(@Nullable Implementation implementation) { |
99 | 102 | if (currentImplementation != null) { |
100 | 103 | currentImplementation.unregister(); |
101 | 104 | } |
102 | 105 |
|
103 | 106 | currentImplementation = implementation; |
104 | 107 |
|
105 | | - if (currentImplementation != null) { |
| 108 | + if (currentImplementation != null && version != null) { |
106 | 109 | ClientPlayNetworking.send(new HandshakeResponsePayload(currentImplementation.getVersion(), version)); |
107 | 110 | currentImplementation.register(); |
108 | 111 | } |
109 | 112 | } |
110 | 113 |
|
111 | | - private Implementation findImplementation(byte[] offeredVersions) { |
| 114 | + private @Nullable Implementation findImplementation(byte[] offeredVersions) { |
112 | 115 | for (Implementation implementation : Implementation.IMPLEMENTATIONS) { |
113 | 116 | byte version = implementation.getVersion(); |
114 | 117 | for (byte offeredVersion : offeredVersions) { |
|
0 commit comments