Commit Graph
463 Commits
Author SHA1 Message Date
Jonathan Coates 31370387fe Merge branch 'mc-1.21.x' into mc-26.3 2026-10-26 23:12:32 +00:00
Jonathan Coates 2f6229f253 Merge branch 'mc-1.20.x' into mc-1.21.x 2026-10-25 15:08:19 +00:00
Jonathan Coates d5da2f7d16 Enable Nullaway in main common classes
Bump to Nullaway 0.14.3, which fixes the issues we were seeing. This
requires a couple of annotation changes in the code.

Now that we've finally conquered null checking, it's clearly time to add
another static analysis tool. Maybe I'll write my own, who knows.
2026-10-23 00:18:51 +01:00
Jonathan Coates 8acc600e42 Merge branch 'mc-1.20.x' into mc-1.21.x 2026-10-22 12:10:07 +01:00
Jonathan Coates 4cd6cdb69c Enable JSpecify support in NullAway
Except in the common main classes: there's a couple of bugs in the
current version which crash the type checker.
2026-10-19 20:15:53 +01:00
Jonathan Coates be75b7357f Ensure we have @NullMarked package-info files
- Add a new task to check/generate package-info files.
 - Add missing ones, and write some basic package summaries where
   appropriate.
2026-10-19 20:06:09 +01:00
Jonathan Coates 34631dd410 Centralise HTTP URL parsing
- Moves us a bit closer to a parse-don't-validate model which is
   always nice.

 - Fixes some nullability issues: URI.getHost and URI.getScheme are
   *technically* nullable. We reject this case within our parser, but
   that's obviously not propagated to other functions.
2026-10-19 16:32:53 +01:00
Jonathan Coates 2ec32a5775 Fix all connections trying to use HTTPS/TLS
Accidentally introduced in f0cfd0929b:
we're using the global SSL context, not the one from the connection
info.
2026-10-16 17:50:26 +01:00
Jonathan Coates 2eec02fd64 Try to make HTTP tests a bit more robust
These unfortunately rely on the limiting/measuring real time, so can be
a little flakey if the CPU is overloaded.

 - Increase timeout of tests. We add a new runWithServer helper to make
   this a bit easier to do.
 - Reduce parallelism of junit tests. Not sure how much this helps —
   Gradle will still try to do other things — but hopefully a bit.
2026-10-16 17:21:01 +01:00
Jonathan Coates 832800babe Change Resource to explicitly encode a state machine
- Add a new LockedReference class that models Rusts' Mutex class,
   making the @GuardedBy and a ReentrantLock pattern a little less
   verbose.

   Of course, we don't get any of the lifetime checking here. Gosh, I
   miss Rust's ownership model so much when writing concurrent code.

 - Rewrite Resource to work with explicit (immutable) states, and
   transitions between them. Each transition runs within the mutex
   (rather than using atomics), so it's slightly easier to reason about
   possible behaviours.

 - Update our various resources (HTTPRequest, Websocket, CheckURL) to
   use this new state machine system.

 - Merge ResourceQueue and ResourceGroup into one class.
2026-10-09 18:35:17 +01:00
Jonathan Coates 8730963ea8 Detect cycles in locks
- Add a new ThreadUtils.newReentrantLock/newReentrantReadWriteLock
   functions. These use Guava's CycleDetectingLockFactory to create a
   cycle-detecting lock in a development environment.

 - Rename ForbiddenImports to ForbiddenAPIs, and forbid constructing
   these instances directly, requiring you to go through ThreadUtils.
2026-10-09 14:39:02 +01:00
Jonathan Coates a95dbe739f Merge branch 'mc-1.21.x' into mc-26.3 2026-10-05 15:14:14 +01:00
Jonathan Coates 4c669e755f Merge branch 'mc-1.20.x' into mc-1.21.x 2026-10-05 14:07:13 +01:00
Jonathan Coates cc00854821 Support generic targets in GenericMethod
When we have a function with a type-variable target defined in an
abstract class, if we can resolve that to a concrete type in the
registered instance, then it's safe to use as a generic target.

For example:

  abstract class Foo<T> { @LuaFunction public final void foo(T) { } }
  class Bar<Qux> { } // Register foo(Qux)
2026-10-02 17:49:55 +01:00
Jonathan Coates 071ca050be Write some tests for bandwidth/traffic limits
Just to prove to myself that it works! Specifically, I have some
concerns with HTTP streaming about how that will interact with bandwidth
limits, so having this in place should make it easier to write further
tests.

7c60ed109f already proving useful. As we
no longer have any global state we can run these tests in parallel.
2026-10-01 18:04:44 +01:00
Jonathan Coates 11d5f1a0b7 Property testing for GPS logic
I wrote this ages ago when looking at alternative GPS arrays for #1681.
None of the designs I've tried seem any more reliable, and still have
some positions where they fail, hence this test being marked "pending".
2026-10-01 13:18:40 +01:00
Jonathan Coates 27f3e82d8e Make SNBT parsing more conformant
- Split JSON and SNBT parsers up, and move them into their own
   modules. While there is a lot of overlap, there's sufficient
   difference it's not worth trying to keep them the same.

 - Update SNBT parser to support most of 26.3's features.

Fixes #2277.
2026-09-30 12:54:55 +01:00
Jonathan Coates 5f69f7acd6 Fix several bugs with websocket closing
- Correctly send a close websocket frame when a websocket is manually
   closed (status code 1000) or is garbage collected (1001). Computer
   shutdowns still just close the socket, as we don't/can't wait for the
   socket to cleanly shutdown.

 - After a user calls close(), don't mark the websocket as closed until
   we receive the server's close response. This means we now have a
   slightly awkward interstitial state where we can receive messages but
   not send them, but I don't think there's much we can do about that.

Fixes #2096
2026-09-29 20:52:10 +01:00
Jonathan Coates f0cfd0929b Move some common Netty code into NetworkUtils 2026-09-29 16:59:54 +01:00
Jonathan Coates 5dcbdced10 Replace ResourceQueue with a Cleaner
A bit simpler, means we don't have to poll it every tick.

I had one test failure in the websocket code where the websocket was
GCed and closed too early, so adding some reference fences in here. I've
not been able to reproduce this, so fingers crossed it works.
2026-09-29 16:59:14 +01:00
Jonathan Coates 91a60b372d Bump CC:T to 1.120.3
Update NeoForge to adjust to their breaking changes.
2026-09-28 13:51:40 +01:00
Jonathan Coates d4a8d270f2 Small perfomance improvements to vector
- Localise setmetatable
 - Provide a fast-path for vector.new which skips number coercion when
   we know the input will be a number.
2026-09-28 11:24:16 +01:00
Jonathan Coates 7c60ed109f Abstract our HTTP implementation away
Add a new HttpHandler interface, which handles checkUrl, request and
websocket calls for a computer. The default implementation is provided
by a NettyHttp class, which also stores any related HTTP config and
state.

This is a little over-engineered, but has two advantages:
 - Our Javascript/TeaVM implementation can now just implement this
   interface, rather than patching/overwriting classes.
 - This removes the final (large) bits of global state/config from
   CC:T's core. Our tests no longer need to temporarily override global
   address rules, and the traffic shaping handler no longer requires
   resetting.

It might be a bit nicer to move all the netty-specific code into a
dan200.computercraft.apis.http.netty package, so there's some cleaner
separation from the common code, but I'm trying to avoid moving code
about any more than I have to.
2026-09-24 15:31:57 +01:00
Jonathan Coates 14e8dc93f0 Make ComputerContext ctor's public
Within our TeaVM code we currently do some class rewriting magic to
replace individual classes, such as ComputerThread. However, all our
code is written to allow changing these implementations already, it's
just TeaVM isn't smart enough to look through our builder and realise
it's dead code!

We now make the ComputerContext's constructor public (though
deprecated), which allows our TeaVM code to call it directly.
2026-09-24 12:51:19 +01:00
Jonathan Coates 16ede90191 Restrict GlobalEnvironment for the actual files we use
These technically supported any mod ID and file, but in practice only
ever were used for the Lua ROM and bios.
2026-09-24 10:32:05 +01:00
devvie 670c2092be Check argument types to shell.run (#2507) 2026-09-21 12:00:44 +00:00
Jonathan Coates 704ed90395 Merge branch 'mc-1.21.x' into mc-26.3 2026-09-15 22:18:25 +01:00
Jonathan Coates cf6a12a140 Merge branch 'mc-1.20.x' into mc-1.21.x 2026-09-11 20:58:46 +01:00
Jonathan Coates a4d172bcbe Gradle cleanup/overhaul.
- Fix a whole bunch of ErrorProne warnings. It's still quite noisy, but
   most of the remaining ones now come from Java.

 - Move some config from java-conventions to a new base-conventions,
   which can be used for non-Java projects. As part of this, we now kill
   the CCTweaked plugin, and just install the cct extension in
   base-conventions instead.

 - Kill inlineProject/externalSources. We now:
    - Add an embeddedProject configuration which is used to define
      projects that are embedded within the final jar. We do some fun
      variant resolution in ExternalProjectArtifacts to extract the
      class/resource/source directories from the configuration.
    - Add a new verifyClassesMatch task which recompiles the game and
      ensures compiling everything against the loader's version of
      Minecraft gives us the same result.
2026-09-11 20:10:58 +01:00
Jonathan Coates d449cbc3e7 Some basic datapack documentation 2026-09-09 10:07:36 +01:00
Jonathan Coates 358a6e6263 Relax supported HTTP verbs
There's some really awkward duplication in the HTTP API right now, where
the Lua code reimplements the validation the Java implementation
provides, in order to throw errors at the right level.

In this particular case, our Lua validation was stricter than the Java,
only permitting a known set of verbs. This commit:

 - Makes the Java-side validation a little stricter, to only allow verbs
   matching [A-Z_-]{1,32}. This is strictly much stricter than what the
   HTTP spec allows, but I think makes sense as a restriction.

 - Update the Lua wrapper to match this logic, rather than being
   stricter.

Fixes #2501.
2026-08-28 20:36:19 +01:00
Jonathan Coates 3469060b6b Update Gradle and dependencies
- Fix *some* cross-project isolation issues. This appears to be the
   bare minimum to make the configuration cache happy. There is
   obviously a lot more work to do here.

 - Enable Configuration cache.

 - Fix some new checkstyle/errorprone/nullaway warnings.
2026-08-27 16:33:36 +01:00
Jonathan Coates 99e9c72686 Fix a whole bunch of spelling mistakes
Using typos[^1]. I wrote a config for this years ago, but never checked
it in. All things considered, there's fewer than I expected.

Fun fact: the CCPL contains the text "if added to to the main
repository", and I can't/shouldn't fix it, because it's an external
license!

[^1]: https://github.com/crate-ci/typos/
2026-08-26 14:40:04 +01:00
Jonathan Coates 3829165629 Merge branch 'mc-1.21.x' into mc-26.2 2026-08-25 15:16:49 +01:00
Jonathan Coates 48ac79bc80 Merge branch 'mc-1.20.x' into mc-1.21.x 2026-08-25 15:09:15 +01:00
Jonathan Coates 8bdea64474 Fix multishell not culling after changing focus
When we resume a process, the code looks like:

  resumeProcess(nCurrentProcess, ...)
  if cullProcess(nCurrentProcess, ...) then ... end

However, if the focused tab changes while resuming (via
multishell.setFocus), then we don't cull the correct process!

To fix this, we just add a helper function which resumes+culls, meaning
we only read the mutable global once.
2026-08-14 16:45:46 +01:00
ItsVingtdeux 9c1a9a6319 Fix random indentation of two lines in bios.lua (#2495)
The "type" field definitions for the "edit.autocomplete" and
"lua.autocomplete" settings were both randomly indented, compared to the
rest of the setting definitions.
2026-08-14 09:54:16 +01:00
Jonathan Coates f32252fc8f Merge branch 'mc-1.21.x' into mc-26.2 2026-08-08 11:03:54 +01:00
Jonathan Coates 0c233ec52b Merge branch 'mc-1.20.x' into mc-1.21.x 2026-08-08 10:29:34 +01:00
Jonathan Coates c3cfb206de Bump CC:T to 1.120.2 2026-08-08 10:13:48 +01:00
Tomodachi94 2b0adaea5c Document sleep()'s optional parameter (#2488) 2026-07-26 07:40:00 +00:00
Jonathan Coates 665353589e Merge branch 'mc-1.21.x' into mc-26.2 2026-07-22 16:45:15 +01:00
Jonathan Coates 9ac450db91 Merge branch 'mc-1.20.x' into mc-1.21.x 2026-07-22 16:24:43 +01:00
Jonathan Coates 1cf0ff299e Fix shell crashing if read() doesn't yield
This never happens normally, but can happen if read() is overridden.
2026-07-07 14:03:27 +01:00
Jonathan Coates 64b00edd81 Bump version to 1.120.1 2026-07-05 12:07:14 +01:00
Jonathan Coates 7ba8d20f55 Rename "bottom" pocket upgrade slot to "top"
With the introduction of lecterns exposing modem peripherals, the
bottom peripheral slot can be set by both upgrades and modems. Instead,
we replace the "bottom" upgrade slot with a "top" one.

This is a little more messy than I'd like. I'd originally gone for
"bottom" as it means we keep the recipe the same as before (the upgrade
above goes to the back, the upgrade below goes to the bottom). With this
change, the upgrade above now goes to the top slot, while the one below
goes to the back.

This introduces several breaking changes:
 - pocket.(un)equipBottom -> pocket.(un)equipTop.
 - There is no datafixer for this change. I'm not sure we can viably do
   it, given we're making this change inside an MC version. We can
   always write one for 26.1 -> 26.2 if needed.

Given all the versions this has been available for are in alpha, and on
relatively unpopular versions (1.21.11/26.1/26.2) I don't think it's the
end of the world. Fingers crossed.

Closes #2459.
2026-07-05 12:03:22 +01:00
Jonathan Coates eac8c13d31 Merge branch 'mc-1.21.x' into mc-26.2 2026-07-05 11:25:12 +01:00
Jonathan Coates 3404dcbbd8 Lower size/time-taken in base64 test
This sometimes fails in CI, as the GHA machines are slower than my own.
2026-07-05 11:23:20 +01:00
Jonathan Coates 1fa227d573 Link to write/print in term.write docs 2026-07-03 09:03:53 +01:00
Jonathan Coates cc147c36e4 Merge branch 'mc-1.20.x' into mc-1.21.x 2026-07-02 15:21:04 +01:00