1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-10 01:10:30 +00:00

Update to latest NullAway

This fixes several issues with @Nullable fields not being checked. This
is great in principle, but a little annoying in practice as MC's
@Nullable annotations are sometimes a little overly strict -- we now
need to wrap a couple of things in assertNonNull checks.
This commit is contained in:
Jonathan Coates 2024-04-06 08:38:44 +01:00
parent bce099ef32
commit 8b2516abb5
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
11 changed files with 41 additions and 23 deletions

View File

@ -68,7 +68,7 @@ illuaminate = "0.1.0-71-g378d86e"
librarian = "1.+" librarian = "1.+"
lwjgl = "3.3.3" lwjgl = "3.3.3"
minotaur = "2.+" minotaur = "2.+"
nullAway = "0.9.9" nullAway = "0.10.25"
spotless = "6.23.3" spotless = "6.23.3"
taskTree = "2.1.1" taskTree = "2.1.1"
teavm = "0.10.0-SQUID.3" teavm = "0.10.0-SQUID.3"

View File

@ -9,6 +9,7 @@ import dan200.computercraft.client.gui.widgets.DynamicImageButton;
import dan200.computercraft.client.gui.widgets.TerminalWidget; import dan200.computercraft.client.gui.widgets.TerminalWidget;
import dan200.computercraft.client.network.ClientNetworking; import dan200.computercraft.client.network.ClientNetworking;
import dan200.computercraft.core.terminal.Terminal; 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.ComputerFamily;
import dan200.computercraft.shared.computer.core.InputHandler; import dan200.computercraft.shared.computer.core.InputHandler;
import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; 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 dan200.computercraft.shared.network.server.UploadFileMessage;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
@ -96,8 +98,8 @@ public abstract class AbstractComputerScreen<T extends AbstractComputerMenu> ext
getTerminal().update(); getTerminal().update();
if (uploadNagDeadline != Long.MAX_VALUE && Util.getNanos() >= uploadNagDeadline) { if (uploadNagDeadline != Long.MAX_VALUE && Util.getNanos() >= uploadNagDeadline) {
new ItemToast(minecraft, displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN) new ItemToast(minecraft(), displayStack, NO_RESPONSE_TITLE, NO_RESPONSE_MSG, ItemToast.TRANSFER_NO_RESPONSE_TOKEN)
.showOrReplace(minecraft.getToasts()); .showOrReplace(minecraft().getToasts());
uploadNagDeadline = Long.MAX_VALUE; uploadNagDeadline = Long.MAX_VALUE;
} }
} }
@ -207,7 +209,7 @@ public abstract class AbstractComputerScreen<T extends AbstractComputerMenu> ext
return; 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) { public void uploadResult(UploadResult result, @Nullable Component message) {
@ -223,9 +225,13 @@ public abstract class AbstractComputerScreen<T extends AbstractComputerMenu> ext
} }
private void alert(Component title, Component message) { private void alert(Component title, Component message) {
OptionScreen.show(minecraft, title, message, OptionScreen.show(minecraft(), title, message,
List.of(OptionScreen.newButton(OK, b -> minecraft.setScreen(this))), List.of(OptionScreen.newButton(OK, b -> minecraft().setScreen(this))),
() -> minecraft.setScreen(this) () -> minecraft().setScreen(this)
); );
} }
private Minecraft minecraft() {
return Nullability.assertNonNull(minecraft);
}
} }

View File

@ -6,8 +6,10 @@ package dan200.computercraft.client.gui;
import dan200.computercraft.client.gui.widgets.TerminalWidget; import dan200.computercraft.client.gui.widgets.TerminalWidget;
import dan200.computercraft.core.terminal.Terminal; import dan200.computercraft.core.terminal.Terminal;
import dan200.computercraft.core.util.Nullability;
import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu; import dan200.computercraft.shared.computer.inventory.AbstractComputerMenu;
import net.minecraft.client.KeyMapping; import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.MenuAccess; 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 org.lwjgl.glfw.GLFW;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Objects;
import static dan200.computercraft.core.util.Nullability.assertNonNull; import static dan200.computercraft.core.util.Nullability.assertNonNull;
@ -44,8 +47,8 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
protected void init() { protected void init() {
// First ensure we're still grabbing the mouse, so the user can look around. Then reset bits of state that // First ensure we're still grabbing the mouse, so the user can look around. Then reset bits of state that
// grabbing unsets. // grabbing unsets.
minecraft.mouseHandler.grabMouse(); minecraft().mouseHandler.grabMouse();
minecraft.screen = this; minecraft().screen = this;
KeyMapping.releaseAll(); KeyMapping.releaseAll();
super.init(); super.init();
@ -64,13 +67,13 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
@Override @Override
public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) { 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); return super.mouseScrolled(pMouseX, pMouseY, pDelta);
} }
@Override @Override
public void onClose() { public void onClose() {
minecraft.player.closeContainer(); Objects.requireNonNull(minecraft().player).closeContainer();
super.onClose(); super.onClose();
} }
@ -93,12 +96,16 @@ public class NoTermComputerScreen<T extends AbstractComputerMenu> extends Screen
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) { public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
super.render(graphics, mouseX, mouseY, 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 lines = font.split(Component.translatable("gui.computercraft.pocket_computer_overlay"), (int) (width * 0.8));
var y = 10; var y = 10;
for (var line : lines) { 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; y += 9;
} }
} }
private Minecraft minecraft() {
return Nullability.assertNonNull(minecraft);
}
} }

View File

@ -17,6 +17,8 @@ import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack; 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. * 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); 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) { 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(); transform.pushPose();
if (hand == InteractionHand.MAIN_HAND && player.getOffhandItem().isEmpty()) { if (hand == InteractionHand.MAIN_HAND && player.getOffhandItem().isEmpty()) {

View File

@ -223,7 +223,7 @@ public abstract class AbstractComputerBlockEntity extends BlockEntity implements
var offsetSide = dir.getOpposite(); var offsetSide = dir.getOpposite();
var localDir = remapToLocalSide(dir); 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)); computer.setBundledRedstoneInput(localDir, BundledRedstone.getOutput(getLevel(), targetPos, offsetSide));
} }

View File

@ -303,7 +303,7 @@ public final class DiskDriveBlockEntity extends AbstractContainerBlockEntity {
// Set the id (if needed) and write it back to the media stack. // Set the id (if needed) and write it back to the media stack.
var stack = media.stack().copy(); var stack = media.stack().copy();
mount = media.media().createDataMount(stack, (ServerLevel) level); mount = media.media().createDataMount(stack, (ServerLevel) getLevel());
updateMediaStack(stack, immediate); updateMediaStack(stack, immediate);
return mount; return mount;

View File

@ -108,7 +108,7 @@ public class CableBlockEntity extends BlockEntity {
void neighborChanged(BlockPos neighbour) { void neighborChanged(BlockPos neighbour) {
var dir = getModemDirection(); 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(); queueRefreshPeripheral();
} }
} }
@ -164,7 +164,7 @@ public class CableBlockEntity extends BlockEntity {
.from(oldVariant.getFacing(), modem.getModemState().isOpen(), peripheral.hasPeripheral()); .from(oldVariant.getFacing(), modem.getModemState().isOpen(), peripheral.hasPeripheral());
if (oldVariant != newVariant) { if (oldVariant != newVariant) {
level.setBlockAndUpdate(getBlockPos(), state.setValue(CableBlock.MODEM, newVariant)); getLevel().setBlockAndUpdate(getBlockPos(), state.setValue(CableBlock.MODEM, newVariant));
} }
} }

View File

@ -175,7 +175,7 @@ public class MonitorBlockEntity extends BlockEntity {
} else { } else {
// Otherwise fetch the origin and attempt to get its monitor // Otherwise fetch the origin and attempt to get its monitor
// Note this may load chunks, but we don't really have a choice here. // 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; if (!(te instanceof MonitorBlockEntity monitor)) return null;
return serverMonitor = monitor.createServerMonitor(); return serverMonitor = monitor.createServerMonitor();
@ -417,7 +417,7 @@ public class MonitorBlockEntity extends BlockEntity {
@Nullable @Nullable
private MonitorBlockEntity tryResizeAt(BlockPos pos, int width, int height) { 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)) { if (tile instanceof MonitorBlockEntity monitor && isCompatible(monitor)) {
monitor.resize(width, height); monitor.resize(width, height);
return monitor; return monitor;

View File

@ -165,7 +165,7 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba
public void setDirection(Direction dir) { public void setDirection(Direction dir) {
if (dir.getAxis() == Direction.Axis.Y) dir = Direction.NORTH; 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(); updateRedstone();
updateInputsImmediately(); updateInputsImmediately();

View File

@ -33,6 +33,7 @@ import java.io.Writer;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
/** /**
@ -79,7 +80,7 @@ public class Exporter {
} }
// Now find all CC recipes. // 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)) { for (var recipe : level.getRecipeManager().getAllRecipesFor(RecipeType.CRAFTING)) {
var result = recipe.getResultItem(level.registryAccess()); var result = recipe.getResultItem(level.registryAccess());
if (!RegistryWrappers.ITEMS.getKey(result.getItem()).getNamespace().equals(ComputerCraftAPI.MOD_ID)) { if (!RegistryWrappers.ITEMS.getKey(result.getItem()).getNamespace().equals(ComputerCraftAPI.MOD_ID)) {

View File

@ -32,6 +32,8 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult;
import java.util.Objects;
import static dan200.computercraft.core.util.Nullability.assertNonNull; import static dan200.computercraft.core.util.Nullability.assertNonNull;
public class ComputerCraftClient { public class ComputerCraftClient {
@ -77,7 +79,7 @@ public class ComputerCraftClient {
if (hit.getType() != HitResult.Type.BLOCK) return ItemStack.EMPTY; if (hit.getType() != HitResult.Type.BLOCK) return ItemStack.EMPTY;
var pos = ((BlockHitResult) hit).getBlockPos(); var pos = ((BlockHitResult) hit).getBlockPos();
var level = Minecraft.getInstance().level; var level = Objects.requireNonNull(Minecraft.getInstance().level);
var state = level.getBlockState(pos); var state = level.getBlockState(pos);
if (!(state.getBlock() instanceof CableBlock cable)) return ItemStack.EMPTY; if (!(state.getBlock() instanceof CableBlock cable)) return ItemStack.EMPTY;