Skip to content

Commit

Permalink
proper null check server data
Browse files Browse the repository at this point in the history
  • Loading branch information
BasiqueEvangelist committed Jan 25, 2023
1 parent 9e38b74 commit e26d8a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/main/java/io/wispforest/gadget/client/ServerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import io.wispforest.gadget.network.GadgetNetworking;
import net.fabricmc.fabric.api.client.networking.v1.ClientLoginConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import org.jetbrains.annotations.Nullable;

public class ServerData {
public static AnnounceS2CPacket ANNOUNCE_PACKET;
private static @Nullable AnnounceS2CPacket ANNOUNCE_PACKET;

public static void init() {
GadgetNetworking.CHANNEL.registerClientbound(AnnounceS2CPacket.class,
Expand All @@ -18,4 +19,12 @@ public static void init() {
ClientLoginConnectionEvents.DISCONNECT.register(
(handler, client) -> ANNOUNCE_PACKET = null);
}

public static boolean canReplaceStacks() {
return ANNOUNCE_PACKET != null && ANNOUNCE_PACKET.canReplaceStacks();
}

public static boolean canRequestServerData() {
return ANNOUNCE_PACKET != null && ANNOUNCE_PACKET.canRequestServerData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected void build(VerticalFlowLayout rootComponent) {

main.child(inspectResources);

if (ServerData.ANNOUNCE_PACKET != null && ServerData.ANNOUNCE_PACKET.canRequestServerData()) {
if (ServerData.canRequestServerData()) {
LabelComponent inspectServerData = Components.label(Text.translatable("text.gadget.inspect_server_data"));

inspectServerData.margins(Insets.bottom(4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public StackNbtDataScreen(HandledScreen<?> parent, Slot slot) {
var stack = slot.getStack();
Consumer<NbtCompound> reloader = null;

if (ServerData.ANNOUNCE_PACKET.canReplaceStacks()) {
if (ServerData.canReplaceStacks()) {
reloader = newNbt -> {
stack.setNbt(newNbt);

Expand Down

0 comments on commit e26d8a7

Please sign in to comment.