diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7a8512048..bbc223a56 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -68,7 +68,7 @@ illuaminate = "0.1.0-71-g378d86e" librarian = "1.+" lwjgl = "3.3.3" minotaur = "2.+" -nullAway = "0.9.9" +nullAway = "0.10.25" spotless = "6.23.3" taskTree = "2.1.1" teavm = "0.10.0-SQUID.3" diff --git a/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java b/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java index 50f12c15e..c25c0d059 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java +++ b/projects/common/src/client/java/dan200/computercraft/client/gui/AbstractComputerScreen.java @@ -9,6 +9,7 @@ import dan200.computercraft.client.gui.widgets.DynamicImageButton; import dan200.computercraft.client.gui.widgets.TerminalWidget; import dan200.computercraft.client.network.ClientNetworking; import dan200.computercraft.core.terminal.Terminal; +import dan200.computercraft.core.util.Nullability; import dan200.computercraft.shared.computer.core.ComputerFamily; import dan200.computercraft.shared.computer.core.InputHandler; import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; @@ -18,6 +19,7 @@ import dan200.computercraft.shared.config.Config; import dan200.computercraft.shared.network.server.UploadFileMessage; import net.minecraft.ChatFormatting; import net.minecraft.Util; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; @@ -96,8 +98,8 @@ public abstract class AbstractComputerScreen ext getTerminal().update(); if (uploadNagDeadline != Long.MAX_VALUE && Util.getNanos() >= uploadNagDeadline) { - new ItemToast(minecraft, displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN) - .showOrReplace(minecraft.getToasts()); + new ItemToast(minecraft(), displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN) + .showOrReplace(minecraft().getToasts()); uploadNagDeadline = Long.MAX_VALUE; } } @@ -207,7 +209,7 @@ public abstract class AbstractComputerScreen ext return; } - if (toUpload.size() > 0) UploadFileMessage.send(menu, toUpload, ClientNetworking::sendToServer); + if (!toUpload.isEmpty()) UploadFileMessage.send(menu, toUpload, ClientNetworking::sendToServer); } public void uploadResult(UploadResult result, @Nullable Component message) { @@ -223,9 +225,13 @@ public abstract class AbstractComputerScreen ext } private void alert(Component title, Component message) { - OptionScreen.show(minecraft, title, message, - List.of(OptionScreen.newButton(OK, b -> minecraft.setScreen(this))), - () -> minecraft.setScreen(this) + OptionScreen.show(minecraft(), title, message, + List.of(OptionScreen.newButton(OK, b -> minecraft().setScreen(this))), + () -> minecraft().setScreen(this) ); } + + private Minecraft minecraft() { + return Nullability.assertNonNull(minecraft); + } } diff --git a/projects/common/src/client/java/dan200/computercraft/client/gui/NoTermComputerScreen.java b/projects/common/src/client/java/dan200/computercraft/client/gui/NoTermComputerScreen.java index 67ad95ba5..71a3609ad 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/gui/NoTermComputerScreen.java +++ b/projects/common/src/client/java/dan200/computercraft/client/gui/NoTermComputerScreen.java @@ -6,8 +6,10 @@ package dan200.computercraft.client.gui; import dan200.computercraft.client.gui.widgets.TerminalWidget; import dan200.computercraft.core.terminal.Terminal; +import dan200.computercraft.core.util.Nullability; import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.MenuAccess; @@ -16,6 +18,7 @@ import net.minecraft.world.entity.player.Inventory; import org.lwjgl.glfw.GLFW; import javax.annotation.Nullable; +import java.util.Objects; import static dan200.computercraft.core.util.Nullability.assertNonNull; @@ -44,8 +47,8 @@ public class NoTermComputerScreen extends Screen protected void init() { // First ensure we're still grabbing the mouse, so the user can look around. Then reset bits of state that // grabbing unsets. - minecraft.mouseHandler.grabMouse(); - minecraft.screen = this; + minecraft().mouseHandler.grabMouse(); + minecraft().screen = this; KeyMapping.releaseAll(); super.init(); @@ -64,13 +67,13 @@ public class NoTermComputerScreen extends Screen @Override public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) { - minecraft.player.getInventory().swapPaint(pDelta); + Objects.requireNonNull(minecraft().player).getInventory().swapPaint(pDelta); return super.mouseScrolled(pMouseX, pMouseY, pDelta); } @Override public void onClose() { - minecraft.player.closeContainer(); + Objects.requireNonNull(minecraft().player).closeContainer(); super.onClose(); } @@ -93,12 +96,16 @@ public class NoTermComputerScreen extends Screen public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { super.render(graphics, mouseX, mouseY, partialTicks); - var font = minecraft.font; + var font = minecraft().font; var lines = font.split(Component.translatable("gui.computercraft.pocket_computer_overlay"), (int) (width * 0.8)); var y = 10; for (var line : lines) { - graphics.drawString(font, line, (width / 2) - (minecraft.font.width(line) / 2), y, 0xFFFFFF, true); + graphics.drawString(font, line, (width / 2) - (font.width(line) / 2), y, 0xFFFFFF, true); y += 9; } } + + private Minecraft minecraft() { + return Nullability.assertNonNull(minecraft); + } } diff --git a/projects/common/src/client/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java b/projects/common/src/client/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java index 07a2f8c97..9fecf2bd7 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java +++ b/projects/common/src/client/java/dan200/computercraft/client/render/ItemMapLikeRenderer.java @@ -17,6 +17,8 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; +import java.util.Objects; + /** * A base class for items which have map-like rendering when held in the hand. * @@ -35,7 +37,7 @@ public abstract class ItemMapLikeRenderer { protected abstract void renderItem(PoseStack transform, MultiBufferSource render, ItemStack stack, int light); public void renderItemFirstPerson(PoseStack transform, MultiBufferSource render, int lightTexture, InteractionHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack) { - Player player = Minecraft.getInstance().player; + Player player = Objects.requireNonNull(Minecraft.getInstance().player); transform.pushPose(); if (hand == InteractionHand.MAIN_HAND && player.getOffhandItem().isEmpty()) { diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlockEntity.java index 462945cbe..aaf4efe90 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/blocks/AbstractComputerBlockEntity.java @@ -223,7 +223,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements var offsetSide = dir.getOpposite(); var localDir = remapToLocalSide(dir); - computer.setRedstoneInput(localDir, RedstoneUtil.getRedstoneInput(level, targetPos, dir)); + computer.setRedstoneInput(localDir, RedstoneUtil.getRedstoneInput(getLevel(), targetPos, dir)); computer.setBundledRedstoneInput(localDir, BundledRedstone.getOutput(getLevel(), targetPos, offsetSide)); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveBlockEntity.java index 1cf33ac44..337ef87fa 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDriveBlockEntity.java @@ -303,7 +303,7 @@ public final class DiskDriveBlockEntity extends AbstractContainerBlockEntity { // Set the id (if needed) and write it back to the media stack. var stack = media.stack().copy(); - mount = media.media().createDataMount(stack, (ServerLevel) level); + mount = media.media().createDataMount(stack, (ServerLevel) getLevel()); updateMediaStack(stack, immediate); return mount; diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java index e52f1b299..5e619d361 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/CableBlockEntity.java @@ -108,7 +108,7 @@ public class CableBlockEntity extends BlockEntity { void neighborChanged(BlockPos neighbour) { var dir = getModemDirection(); - if (!level.isClientSide && dir != null && getBlockPos().relative(dir).equals(neighbour) && isPeripheralOn()) { + if (!getLevel().isClientSide && dir != null && getBlockPos().relative(dir).equals(neighbour) && isPeripheralOn()) { queueRefreshPeripheral(); } } @@ -164,7 +164,7 @@ public class CableBlockEntity extends BlockEntity { .from(oldVariant.getFacing(), modem.getModemState().isOpen(), peripheral.hasPeripheral()); if (oldVariant != newVariant) { - level.setBlockAndUpdate(getBlockPos(), state.setValue(CableBlock.MODEM, newVariant)); + getLevel().setBlockAndUpdate(getBlockPos(), state.setValue(CableBlock.MODEM, newVariant)); } } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorBlockEntity.java index bc377a519..4442ba324 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/monitor/MonitorBlockEntity.java @@ -175,7 +175,7 @@ public class MonitorBlockEntity extends BlockEntity { } else { // Otherwise fetch the origin and attempt to get its monitor // Note this may load chunks, but we don't really have a choice here. - var te = level.getBlockEntity(toWorldPos(0, 0)); + var te = getLevel().getBlockEntity(toWorldPos(0, 0)); if (!(te instanceof MonitorBlockEntity monitor)) return null; return serverMonitor = monitor.createServerMonitor(); @@ -417,7 +417,7 @@ public class MonitorBlockEntity extends BlockEntity { @Nullable private MonitorBlockEntity tryResizeAt(BlockPos pos, int width, int height) { - var tile = level.getBlockEntity(pos); + var tile = getLevel().getBlockEntity(pos); if (tile instanceof MonitorBlockEntity monitor && isCompatible(monitor)) { monitor.resize(width, height); return monitor; diff --git a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java index af3136129..3160aac02 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/turtle/blocks/TurtleBlockEntity.java @@ -165,7 +165,7 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba public void setDirection(Direction dir) { if (dir.getAxis() == Direction.Axis.Y) dir = Direction.NORTH; - level.setBlockAndUpdate(worldPosition, getBlockState().setValue(TurtleBlock.FACING, dir)); + getLevel().setBlockAndUpdate(worldPosition, getBlockState().setValue(TurtleBlock.FACING, dir)); updateRedstone(); updateInputsImmediately(); diff --git a/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java b/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java index 266b6c669..ebec60496 100644 --- a/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java +++ b/projects/common/src/testMod/java/dan200/computercraft/export/Exporter.java @@ -33,6 +33,7 @@ import java.io.Writer; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashSet; +import java.util.Objects; import java.util.Set; /** @@ -79,7 +80,7 @@ public class Exporter { } // Now find all CC recipes. - var level = Minecraft.getInstance().level; + var level = Objects.requireNonNull(Minecraft.getInstance().level); for (var recipe : level.getRecipeManager().getAllRecipesFor(RecipeType.CRAFTING)) { var result = recipe.getResultItem(level.registryAccess()); if (!RegistryWrappers.ITEMS.getKey(result.getItem()).getNamespace().equals(ComputerCraftAPI.MOD_ID)) { diff --git a/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java b/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java index 4a4f89f73..51e99242b 100644 --- a/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java +++ b/projects/fabric/src/client/java/dan200/computercraft/client/ComputerCraftClient.java @@ -32,6 +32,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; +import java.util.Objects; + import static dan200.computercraft.core.util.Nullability.assertNonNull; public class ComputerCraftClient { @@ -77,7 +79,7 @@ public class ComputerCraftClient { if (hit.getType() != HitResult.Type.BLOCK) return ItemStack.EMPTY; var pos = ((BlockHitResult) hit).getBlockPos(); - var level = Minecraft.getInstance().level; + var level = Objects.requireNonNull(Minecraft.getInstance().level); var state = level.getBlockState(pos); if (!(state.getBlock() instanceof CableBlock cable)) return ItemStack.EMPTY;