Commit Graph
3016 Commits
Author SHA1 Message Date
Jonathan Coates 0611e23d1b Rewrite turtle upgrade interface 2026-10-15 22:10:26 +01:00
Jonathan Coates 7b5fae17f3 Support dyed shulker box upgrades
- 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-12 16:46:40 +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 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 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 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 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 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
Jonathan Coates cc54413718 Fix reference to core-api in common javadoc task 2026-09-16 14:35:08 +01:00
Jonathan Coates c04b7599de Replace 26.2 with 26.3 in issue template 2026-09-15 21:48:57 +01:00
Jonathan Coates 019855dfb2 Some more Gradle tweaks
- Fix missing license header and some over-eager gitignore removals.
 - Fix several isolated project errors. I think all the remaining ones
   come from limitations in other projects:
    - MDG's mod configs don't support referencing source sets from other
      projects.
    - idea-ext is terrible in every way.

   There's some nastiness in MergeTrees where we can't do
   `resources.elements.map { it.single() }` as it throws a configuration
   cache error, so we now use a ConfigurableFileCollection. Somehow it
   still works.
2026-09-12 10:54:59 +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 b634ef80c8 Move buildSrc to build-logic
What Gradle recommends seems to have gone pretty back-and-forth on this,
but it seems like this is the standard these days.
2026-09-11 12:15:46 +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 7d05fa9ac2 Remove MC version from project name
This dates back from when we had multiple MC versions in a single
project (see the build-tools branch). We don't do this any more, so no
need for it.

(More importantly, something has changed in IDEA/Gradle so that the
1.20.1 now is escaped as 1_20_1, which breaks Fabric Loom).
2026-08-25 14:56:45 +01:00
Jonathan Coates 7b7039c677 Fix turtle.place() not skipping ItemStack.useOn 2026-08-21 13:53:02 +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 67732ace06 Sync translations from Crowdin 2026-08-08 17:04:50 +01:00
Jonathan Coates c3cfb206de Bump CC:T to 1.120.2 v1.20.1-1.120.2 2026-08-08 10:13:48 +01:00
Jonathan Coates d37793d29a Some small cleanup to the block placing code
Just clarify a couple of things which are a little confusing.

 - Explicitly initialise the position within deployOnEntity, rather than
   relying on getWithPosition above.
 - Rename "position" to "blockPos" in deployOnBlock to make it clearer
   whose position it is.
 - Clarify that we need to call use(...) for all directions.
2026-07-26 12:36:34 +01:00
Jonathan Coates f2161f0765 Add all turtle/pocket upgrades to the search creative tab
This means we no longer need to register additional stacks with recipe
mods, as they'll pick them up from the creative tab instead.

Closes #2463.
2026-07-26 10:41:17 +01:00
Tomodachi94 2b0adaea5c Document sleep()'s optional parameter (#2488) 2026-07-26 07:40:00 +00:00
Jonathan Coates 7ab92628d9 Some cleanup to CI workflow
- Bump versions
 - Remove some workarounds for flakiness. MDG is much more robust than FG
   used to be.
2026-07-22 13:24:34 +01:00
Jonathan Coates e0c530efe2 Add missing @GuardedBy 2026-07-22 13:21:19 +01:00
Jonathan Coates 3607165cf9 Run pre-commit with --all-files in CI
Wow, this has been broken for ages.
2026-07-22 13:17:20 +01:00
Jonathan Coates 1ec5d53a68 Add test for brewing stand item limit
See #2480.
2026-07-22 12:01:35 +01:00
Jonathan Coates db070d7737 Add missing @Nullability annotations to arg lists
The *contents* of the array is nullable, but the array itself isn't.
2026-07-22 11:48:58 +01:00
Jonathan Coates e83fdd2d5d Fix several BE render bounds
- Monitors were one block taller/wider than they should be.
 - Lecterns are higher than one block, so got cut off if just looking at
   the top.
2026-07-21 11:59:02 +01:00
Jonathan Coates 6f16cd6b0e Reset pocket computer if family changes
When we upgrade a normal pocket computer to an advanced one, we need to
create a new ServerComputer instance (and destroy the old one).

On 1.20.1 the ComputerUpgradeRecipe does not preserve the
instance/session ID on the resulting stack. When the item is next
ticked, we create a new computer, with the old computer no longer being
kept alive and eventually dying.

On 1.21.1 we copy all components, *including* the the current computer
reference. This means a new computer is never created and so we continue
to use the old one (with the wrong family). We could exclude the
computer component from the recipe (and so have the same behaviour as
1.20.1), but by adding a hook in onCraftedBy we can destroy the old
computer immediately, ensuring it no longer continues to run.

Fixes #2479.
2026-07-12 16:30:46 +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 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