1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-11-05 01:26:20 +00:00
Commit Graph

2110 Commits

Author SHA1 Message Date
Jonathan Coates
0908acbe9b
Move all event handlers to a common class
While this does now involve a little more indirection, by having a
single location for all hooks it's much easier to keep event listeners
consistent between loaders.

The diff is pretty noisy (I've inlined some classes, and ClientRegistry
got a big restructure), but functionality should be the same.
2022-11-08 10:48:22 +00:00
Jonathan Coates
e8f9cdd221
Attach capabilities to our BlockEntities externally
Previously we overrode getCapability on our BlockEntity implementations.
While this is the Proper way to do things, it's obviously impossible to
do in a multi-loader environment.

We now subscribe to the AttachCapabilitiesEvent and add our caps that
way. This does require[^1] some nasty invalidation of caps in a couple
of places, which I'm not wild about.

[^1]: I'm not actually sure it does: we invalidate peripherals and wired
elements when neighbours change, so the explicit invalidation probably
isn't useful.
2022-11-06 22:26:07 +00:00
Jonathan Coates
53abe5e56e
Make net code more multi-loader friendly
NetworkMessage follows vanilla's Packet much more closely now: the
handler takes a context argument, which varies between the client and
server.

 - The server handler just returns the ServerPlayer who sent the
   message.
 - The client context provides handleXyz(...) methods for each
   clientbound packet. Our packet subclasses call the appropriate
   method - the implementation of which contains the actual
   implementation.

Doing this allows us to move a whole bunch of client-specific code into
the main client package, dropping several @OnlyIn annotations and
generally reducing the risk of accidentally loading client classes on
the server.

We also abstract out some packet sending and general networking code to
make it easier to use in a multi-loader context.
2022-11-06 20:13:04 +00:00
Jonathan Coates
564752c8dd
Flesh out our registry abstraction layer
- Replace our usages of DeferredRegistry with a custom
   RegistrationHelper. This effectively behaves the same, just without
   any references to Forge code!

 - Replace any references to ForgeRegistries with a home-grown
   Registries class. This just fetches the underlying registry and
   proxies the method calls.

 - Change recipe serialisers and loot item conditions to be registered
   the same way as other entries.

 - Move any Forge specific registration code off to the main
   ComputerCraft class.
2022-11-06 18:37:00 +00:00
Jonathan Coates
6d665ad841
Rename Registry to ModRegistry
Avoids the conflict with Minecraft's built-in registry class
2022-11-06 18:37:00 +00:00
Jonathan Coates
9cd728fea9
Update parse-reports to handle new paths 2022-11-06 18:37:00 +00:00
Oliver Caha
1c890e5a5c
Fix typo in speaker documentation (#1209) 2022-11-06 18:33:46 +00:00
Jonathan Coates
955b9c7d28
Default Forge/Common API to non-null 2022-11-06 15:50:24 +00:00
Jonathan Coates
76710eec9d
Move our public API into separate modules
This adds two new modules: common-api and forge-api, which contain the
common and Forge-specific interfaces for CC's Minecraft-specific API.

We add a new PlatformHelper interface, which abstracts over some of the
loader-specific functionality, such as reading registries[^1] or calling
Forge-specific methods. This interface is then implemented in the main
mod, and loaded via ServiceLoaders.

Some other notes on this:

 - We now split shared and client-specific source code into separate
   modules. This is to make it harder to reference client code on the
   server, thus crashing the game.

   Eventually we'll split the main mod up too into separate source sets
   - this is, of course, a much bigger problem!

 - There's currently some nastiness here due to wanting to preserve
   binary compatibility of the API. We'll hopefully be able to remove
   this when 1.19.3 releases.

 - In order to build a separate Forge-specific API jar, we compile the
   common sources twice: once for the common jar and once for the Forge
   jar.

   Getting this to play nicely with IDEs is a little tricky and so we
   provide a cct.inlineProject(...) helper to handle everything.

[^1]: We /can/ do this with vanilla's APIs, but it gives a lot of
deprecation warnings. It just ends up being nicer to abstract over it.
2022-11-06 15:07:13 +00:00
Jonathan Coates
d8e2161f15
Move website source/build logic to projects/web
Mostly useful as it moves some of our build logic out of the main
project, as that's already pretty noisy!
2022-11-06 13:37:07 +00:00
Jonathan Coates
c82f37d3bf
Switch the core library to be non-null by default
See comments in c8c128d335 for further
details. This requires /relatively/ few changes - mostly cases we were
missing @Nullable annotations.
2022-11-06 11:55:26 +00:00
Jonathan Coates
c8c128d335
Switch the core-api to be non-null by default
We'll do this everywhere eventually, but much easier to do it
incrementally:

 - Use checker framework to default all field/methods/parameters to
   @Nonnull.

 - Start using ErrorProne[1] and NullAway[2] to check for possible null
   pointer issues. I did look into using CheckerFramework, but it's much
   stricter (i.e. it's actually Correct). This is technically good, but
   is a much steeper migration path, which I'm not sure we're prepared
   for yet!

[1]: https://github.com/google/error-prone
[2]: https://github.com/uber/NullAway
2022-11-06 10:28:49 +00:00
Jonathan Coates
acc254a1ef
Move dan200.computercraft.core into a separate module
This is a very big diff in changed files, but very small in actual
changes.
2022-11-06 10:02:14 +00:00
Jonathan Coates
a17b001950
Move the core API into a separate module
It should be possible to consume the ComputerCraft's core (i.e.
non-Minecraft code) in other projects, such as emulators.  While this
has been possible for years, it's somewhat tricky from a maintenance
perspective - it's very easy to accidentally add an MC dependency
somewhere!

By publishing a separate "core" jar, we can better distinguish the
boundaries between our Lua runtime and the Minecraft-specific code.

Ideally we could have one core project (rather than separate core and
core-api modules), and publish a separate "api" jar, like we do for the
main mod. However, this isn't really possible to express using Maven
dependencies, and so we must resort to this system.

Of course, this is kinda what the Java module system is meant to solve,
but unfortunately getting that working with Minecraft is infeasible.
2022-11-04 21:41:59 +00:00
Jonathan Coates
e4e528e5bf
Prepare dan200.computercraft.core for splitting off
- Move core-specific config options to a separate CoreConfig class.
 - Use class-specific loggers, instead of a global one.
 - Use log markers instead of a logComputerErrors option.
2022-11-04 19:58:57 +00:00
Jonathan Coates
6cc86b0ae5
Exclude the previous commit from git blame
This can be added by running the following command:

    git config --global blame.ignoreRevsFile .git-blame-ignore-revs
2022-11-04 13:42:00 +00:00
Jonathan Coates
f478c4ffc4
Reformat everything
- Switch to a fairly standard code format. This is largely based on
   IntelliJ defaults, with some minor tweaks applied via editor config.
   Should mean people don't need to import a config!

 - Use "var" everywhere instead of explicit types. Type inference is a
   joy, and I intend to use it to its fullest.

 - Start using switch expressions: we couldn't use them before because
   IntelliJ does silly things with our previous brace style, but now we
   have the luxury of them!
2022-11-04 13:41:38 +00:00
Jonathan Coates
7df0412c2d
Bump CC:T to 1.101.1
Our last palendrome for a while!
2022-11-03 20:41:47 +00:00
Jonathan Coates
998efcc950
Move our test thread scheduler into the main jar
While useless in-game, both CCEmuX and eval.tweaked.cc ended up
reimplementing it, so might as well expose it!
2022-11-03 20:41:47 +00:00
Jonathan Coates
45c5de73bb
Correctly register turtle refuel handlers
And actually test them! Along with a whole load of other turtle tests.

Fixes #1202
2022-11-03 20:41:46 +00:00
Alessandro Proto
c919011a7e
Check for valid nSender field on RedNet message receive (#1200) 2022-11-03 08:40:37 +00:00
Jonathan Coates
0f1f5247ca
Merge branch 'mc-1.18.x' into mc-1.19.x 2022-11-02 09:55:10 +00:00
Jonathan Coates
0db32bd0fe
Merge branch 'mc-1.16.x' into mc-1.18.x 2022-11-02 09:55:10 +00:00
Jonathan Coates
1d3ecb551d
Improvee changelog 2022-11-02 07:58:31 +00:00
Jonathan Coates
aefda6a381
Fix a couple of issues with the release process
Only way to test these is in prod, alas :D:
2022-11-01 21:53:05 +00:00
Jonathan Coates
c1bf9f0b24
Prepare the public API for multi-loader support
Well, sort of. For now, we just mark a whole bunch of stuff as
@Deprecated.
2022-11-01 21:05:24 +00:00
Jonathan Coates
629abb65e3
Merge branch 'mc-1.18.x' into mc-1.19.x 2022-11-01 20:11:36 +00:00
Jonathan Coates
11ac865877
Merge branch 'mc-1.16.x' into mc-1.18.x 2022-11-01 20:07:15 +00:00
Jonathan Coates
6b93fafc46
Bump CC:T to 1.101.0
These version numbers are very hard to type correctly.
2022-11-01 20:01:21 +00:00
Jonathan Coates
1acb8441ec
Add a couple of tests for file autocompletion 2022-11-01 19:22:07 +00:00
Ivo Leal
4b0988768d
Add include_hidden option to fs.complete (#1194) 2022-11-01 14:50:15 +00:00
Jonathan Coates
f528046535
Add a whole bunch of missing @since annotations 2022-10-31 20:09:47 +00:00
Jonathan Coates
93f747fb54
Fix incorrect reboot tooltip
This tooltip was a) using the wrong text and b) incorrect anyway!
Rebooting an off computer does nothing, rather than turning it on.
2022-10-31 20:08:50 +00:00
Jonathan Coates
5d4c34fbac
Merge branch 'mc-1.16.x' into mc-1.18.x 2022-10-31 18:03:39 +00:00
Jonathan Coates
4c5b3a6ee5
Clear Origin header on websockets
Technically this removes Sec-Websocket-Origin, as that's what the
current version of Netty uses. We'll need to change this on 1.18+.

Closes ##1197.
2022-10-31 17:46:02 +00:00
Jonathan Coates
7701b343fb
Make PartialOptions immutable
- Switch to using OptionalInt/OptionalLong instead of @Nullable
   Long/Integers. I know IntelliJ complains, but it avoids the risk of
   implicit unboxing.

 - Instead of mutating PartialOptions, we now define a merge() function
   which returns the new options. This simplifies the logic in
   AddressRule a whole bunch.
2022-10-31 09:13:40 +00:00
Jonathan Coates
14cb97cba1
Sort NBT when writing
This should fix the worst cases of #1196.
2022-10-30 16:47:26 +00:00
Jonathan Coates
1490ca8624
Bump Cobalt version
Adds debug.getregistry() support
2022-10-30 16:39:25 +00:00
Jonathan Coates
f5b89982de
Don't unnecessarily scroll in edit run wrapper (#1195) 2022-10-30 15:17:33 +00:00
Jonathan Coates
1a87175ae7
Be a little more rigorous in KotlinLuaMachine's threading 2022-10-30 11:44:01 +00:00
Jonathan Coates
c4184a33bc
Rewrite our gametest system
This is a noisier diff than I'd like as this is just a direct copy from
the multi-loader branch.

 - Rename "ingame" package to "gametest"

 - Don't chain GameTestSequence methods - it's actually much cleaner if
   we just use Kotlin's implicit this syntax.

 - Use our work in 71f81e1201 to write
   computer tests using Kotlin instead of Lua. This means all the logic
   is in one place, which is nice!

 - Add a couple more tests for some of the more error-prone bits of
   functionality.
2022-10-30 10:50:16 +00:00
Jonathan Coates
b3702fed78
Remove all Minecraft references from the core package
This is an initial step before refactoring this into a separate module.
It's definitely not complete - there's a lot of work needed to remove
referneces to the main ComputerCraft class for instance - but is a
useful first step.
2022-10-30 09:20:26 +00:00
Jonathan Coates
b5056fc3b8
Merge branch 'mc-1.18.x' into mc-1.19.x 2022-10-30 09:06:40 +00:00
Jonathan Coates
38b2c944f3
Merge branch 'mc-1.16.x' into mc-1.18.x 2022-10-30 08:49:52 +00:00
Jonathan Coates
5ee5b11995
Fix month and day names under Java 17
I still don't really understand why the ROOT locale is wrong here, but
there we go. We'll need to remember to uncomment the tests on the 1.18
branch!

Also add some code to map tests back to their definition side. Alas,
this only links to the file right now, not the correct line :/.
2022-10-29 23:54:35 +01:00
Jonathan Coates
b2d2153258
Add several missing version annotations
I probably need to add this to the pre-release checklist. Don't think
there's a good way to automate this :(
2022-10-29 22:49:45 +01:00
Jonathan Coates
3d6ef0cf96
Fix peripheral API using the wrong methods 2022-10-29 22:47:57 +01:00
Jonathan Coates
71f81e1201
Move some test support code into testFixtues
This offers very few advantages now, but helps support the following in
the future:

 - Reuse test support code across multiple projects (useful for
   multi-loader).
 - Allow using test fixture code in testMod. We've got a version of our
   gametest which use Kotlin instead of Lua for asserting computer
   behaviour.

We can't use java-test-fixtures here for Forge reasons, so have to roll
our own version. Alas.

 - Add an ILuaMachine implementation which runs Kotlin coroutines
   instead. We can use this for testing asynchronous APIs. This also
   replaces the FakeComputerManager.

 - Move most things in the .support module to .test.core. We need to use
   a separate package in order to cope with Java 9 modules (again,
   thanks Forge).
2022-10-29 18:17:02 +01:00
Jonathan Coates
1e88d37004
Add peripheral_hub type for wired-modem-like peripherals (#1193)
This allows other mods to create wired-modem alike blocks, which expose
peripherals on the wired network, without having to reimplement the main
modem interface.

This is not currently documented, but a peripheral_hub should provide
the following methods:

 - isPresentRemote
 - getTypeRemote
 - hasTypeRemote
 - getMethodsRemote
 - callRemote
2022-10-29 16:03:05 +01:00
Jonathan Coates
97387556fe
Handle file transfers inside CraftOS (#1190)
- Add a new file_transfer event. This has the signature
   "file_transfer", TransferredFiles.

   TransferredFiles has a single method getFiles(), which returns a list
   of all transferred files.

 - Add a new "import" program which waits for a file_transfer event and
   writes files to the current directory.

 - If a file_transfer event is not handled (i.e. its getFiles() method
   is not called) within 5 seconds on the client, we display a toast
   informing the user on how to upload a file.
2022-10-29 12:01:23 +01:00