Commit Graph
3220 Commits
Author SHA1 Message Date
Jonathan Coates 9e288d3ccb Remove UpgradeData from the public API
I want to decouple the storage of upgrades (e.g. in data components) from
what people consume in the public API. This removes UpgradeData from
the API, pushing all interactions to go through UpgradeHandle.

 - Split UpgradeHandle into a read-only UpgradeHandle and read/write
   MutableUpgradeHandle. {IPocketAccess,ITurtleAccess}.getUpgrade return
   a mutable version, and turtle modellers consume a read-only version.

 - Remove setUpgrade from the public API. This now lives in the internal
   TurtleAccessInternal (much like PocketComputerInternal did already).
   Finding/looking-up an upgrade has never been exposed to the API, so
   I don't think this is a big loss.

 - Remove all other upgrade getters (either returning the upgrade or
   UpgradeData) from the turtle/pocket access.
2026-10-27 23:18:03 +00:00
Jonathan Coates 646251ffd0 Remove deprecated upgrade methods
I'm not aware of any addon mods targetting 26.3, and the whole ecosystem
is pretty unstable. I think this is safe to do.
2026-10-27 18:10:51 +00:00
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 c748278331 Export tests reports via OTR
- Configure JUnit tests to write OTR files.
 - Add a custom OTR reporter to the gametest framework.
 - Update parse-reports to ingest OTR files.
 - Gather all report files and publish them as an artifact.
2026-10-25 12:11:46 +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 41ad9cb71f Update web emulator to use fetch for HTTP requests
This will allow us to support streaming in the future.

TeaVM doesn't have bindings for this right now, we should upstream this.
2026-10-22 20:44:45 +01:00
Jonathan Coates d5d8fc291d Replace ItemStack.isSameItemSameTags with matches
How have I never noticed this existed before :/.
2026-10-22 20:12:54 +01:00
Jonathan Coates 4f07d2d024 Handle upgrade items in data fixers
This is not perfect, but I think as good as we're going to get it.
Because ItemStack's data is not typed in older versions, we don't apply
data fixers to upgrade items (aside from the componentisation fix). This
means that any migration between 3564 and 3818.5 will be skipped.
2026-10-22 20:11:29 +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 5c6e8e434b Rethink turtle/pocket upgrade API (#2513)
- `UpgradeData` now (optionally) stores the upgrade's item in addition
   to the upgrade's data. If the item is not explicitly specified, the
   item is created via `UpgradeBase.getUpgradeItem` as before.

 - Add `UpdateBase.getCraftingIngredient`, allowing upgrades to work with
   multiple items.

 - Add `Abstract{Turtle,Pocket}Upgrade.StackAware` class, for upgrades
   which support this new API.

 - Add `UpgradeHandle` (and matching `I{Turtle,Pocket}.getUpgradeHandle`
   getters), for reading/writing upgrade data.

 - Allow TransformedModel to also hold a list of tints for the model.

 - Update our turtle item colour provider to fetch tints from the
   upgrade's TransformedModel.

   This requires rewriting the quads in the upgrade model, mapping the
   existing tint indices to (2 * tintIndex) + (left ? 1 : 2). We already
   have to rewrite quads to apply transformations, so fortunately this
   isn't too bad.

   I have no clue how this is going to work on 26.3 though 😬.

 - Add a custom turtle upgrade modeller for the storage upgrade that
   applies the shulker tint colour.
2026-10-21 21:49:50 +00:00
Jonathan Coates c6d72adb61 Disable NullAway in verifyClassesMatch for now 2026-10-20 10:03:30 +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 b8e57de63f Require mixin classes to be package-private 2026-10-19 12:42:03 +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 794f78ae43 Replace Mth.clamp with Math.clamp
This has existed since Java 21. MC 26.4 does this, but might as well get
in early.
2026-10-06 15:38:10 +01:00
Jonathan Coates c8b3f6af27 Sort upgrades in creative tab
It's not a *sensible* order, but it is now consistent.
2026-10-05 15:17:59 +01:00
Jonathan Coates b0942c9faf Fix off-by-one error in getCapacity
Also use Ints.saturatedCast. I looked for this function in the Java
stdlib, but not guava.
2026-10-05 15:15:29 +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 8b64fc4cee Update mod dependencies
We need new JEI in order to run with latest NeoForge, so might as well
bump everything else too.
2026-10-03 12:40:16 +01:00
Jonathan Coates 71864b43ea Update NeoForge for more breaking changes 2026-10-03 11:58:27 +01:00
Jonathan Coates 038f49fa9a Shulker turtle upgrades
- Add support for extracting a ContainerTransfer from a container-like
   item (shulkers, and in the future, bundles). For Forge we can just
   use capabilities, but Fabric doesn't support this in 1.20, so we roll
   our own there.

 - Adds a new TurtleStorage peripheral, which allows transferring items
   to/from these container-like items.

 - Register a turtle storage upgrade for every shulker. This is
   currently gated behind a datapack, as I want some time to mull on the
   API, and don't want to ship this as a stable feature quite yet.

Closes #2213.
2026-10-03 00:39:37 +01:00
Jonathan Coates 9b3f3f2619 Add cross-platform abstraction for inventories
- Replace our existing ContainerTransfer class with a more general
   ItemContainer. This supports all the functionality we need for our
   inventory peripheral.

 - Change AbstractInventoryMethod to use ContainerTransfer. This reduces
   the duplicated code between the two InventoryMethod implementations
   (well, somewhat) — they only now have to handle extracting
   ContainerTransfers.
2026-10-02 21:56:37 +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 9d66edee59 Use Fabric mixin in common classes
This is what both Fabric and NeoForge uses. This fixes the compilation
mismatch in DataFixersMixin — ModifyArg.at is now an array, so the
annotation data is slightly different. Annoyingly `javap -v` doesn't
show this, but asm's textifier does.
2026-09-28 14:10:01 +01:00
Jonathan Coates 91a60b372d Bump CC:T to 1.120.3
Update NeoForge to adjust to their breaking changes.
v26.3-1.120.3
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
Jonathan Coates e458382fed Support NeoForge's config GUI
See #1727. This is not sufficient to fix the issue, as it's NeoForge
only, and doesn't support our address rules.
2026-09-21 15:41:42 +01:00
Jonathan Coates 9f27bcff64 Support non-slotted Fabric inventories
Unlike (Neo)Forge, Fabric's transfer API distinguishes between slotted
containers (such as chests) and non-slotted ones (such as bundles). Our
current code (and interface) currently assumes everything to have slots,
but for #2213, we need a way to support non-slotted containers.

We can't really change the interface here, so instead we go the other
route: treat the Iterable<StorageView<...>> as a list of slots. This is
pretty gross (which is why I've put it off for so long), but easy enough
to implement.
2026-09-21 15:02:30 +01:00
devvie 670c2092be Check argument types to shell.run (#2507) 2026-09-21 12:00:44 +00:00
Jonathan Coates 93e4ecd350 Refresh redstone output when first creating a computer
This is an identical fix to 013f2e500f,
but for computers rather than redstone integrators.

I don't love the duplication — it might make more sense to move this
into RedstoneState.updateOutput and have an "initial tick" flag there
instead.

Fixes #2392.
2026-09-18 11:06:26 +01:00
Jonathan Coates 1a7f9ce995 Update computer position in transferStateTo instead
No change in behaviour, just feels a little cleaner. And one fewer
places where we call createServerComputer()...
2026-09-18 10:47:35 +01:00
Jonathan Coates 51a52153f5 Fix NeoForge version bound
I guess I didn't have issues because 26.0.0.0-beta technically fitted
within that range already?
2026-09-17 16:10:33 +01:00
Jonathan Coates 12a8b185ee Update Iris compat
Giving up on waiting for the NeoForge version, so we reshuffle this to
avoid calling getUnderlyingVertexFormat — the RenderType's vertex format
reports this fine.

I did consider dropping all this code and just falling back to the slow
fixed width font renderer when the vertex format doesn't match our
direct one — the overhead is much lower than what it used to be — but
does still touching some internals of BufferBuilder, so probably best
avoided right now.
v26.3-1.120.2
2026-09-17 15:35:20 +01:00
Jonathan Coates fbbee65c84 Update MinecraftExec to work with config cache
- Switch withFileContents/withFileSource to be normal inputs.
 - Download complementary shaders from Maven instead.
2026-09-17 14:52:57 +01:00