mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 05:33:00 +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:
		| @@ -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" | ||||
|   | ||||
| @@ -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<T extends AbstractComputerMenu> 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<T extends AbstractComputerMenu> 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<T extends AbstractComputerMenu> 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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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<T extends AbstractComputerMenu> 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<T extends AbstractComputerMenu> 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<T extends AbstractComputerMenu> 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); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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()) { | ||||
|   | ||||
| @@ -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)); | ||||
|     } | ||||
| 
 | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -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)) { | ||||
|   | ||||
| @@ -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; | ||||
| 
 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates