1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-26 07:03:22 +00:00
Commit Graph

85 Commits

Author SHA1 Message Date
Jonathan Coates
4d3d8e6a8e
Add support for libmultipart to wireless modems 2023-07-02 17:25:58 +01:00
Jonathan Coates
d138d9c4a5
Preserve item NBT for turtle tools
This is a pre-requisite for #1501, and some other refactorings I want to do.

Also fix items in the turtle upgrade slots vanishing. We now explicitly
invalidate the cache when setting the item.
2023-07-02 11:02:10 +01:00
Edvin
f54cb8a432
Allow upgrades to read/write upgrade data from ItemStacks (#1465) 2023-07-02 10:55:55 +01:00
Jonathan Coates
94f5ede75a
Remove superflous Nonnull/Notnull annotations 2023-07-01 19:32:28 +01:00
Jonathan Coates
1977556da4
Deprecate IPocketAccess.getUpgrades
I think this left over from CCTweaks or Peripheral++. It doesn't really
make sense as an API - if/when we add multiple upgrades, we'll want a
different API for this.
2023-07-01 18:34:17 +01:00
Jonathan Coates
ecf880ed82
Document HTTP rules a little better
It turns out we don't document the "port" option anywhere, so probably
worth doing a bit of an overhaul here.

 - Expand the top-level HTTP rules comment, clarifying how things are
   matched and describing each field.

 - Improve the comments on the default HTTP rule. We now also describe
   the $private rule and its motivation.

 - Don't drop/ignore invalid rules. This gets written back to the
   original config file, so is very annoying! Instead we now log an
   error and convert the rule into a "deny all" rule, which should make
   it obvious something is wrong.
2023-07-01 16:16:06 +01:00
Jonathan Coates
910a63214e
Make Generic methods per-ComputerContext
- Move the class cache out of Generator into MethodSupplierImpl. This
   means we cache class generation globally (that's really expensive!),
   but the class -> method list lookup is local.

 - Move the global GenericSource/GenericMethod registry out of core,
   passing in the list of generic methods to the ComputerContext.

I'm not entirely thrilled by the slight overlap of MethodSupplierImpl and
Generator here, something to clean up in the future.
2023-06-26 21:46:55 +01:00
Jonathan Coates
591a7eca23
Clean up how we enumerate Lua/peripheral methods
- Move several interfaces out of `d00.computercraft.core.asm` into a
   new `aethods` package. It may make sense to expose this to the
   public API in a future commit (possibly part of #1462).

 - Add a new MethodSupplier<T> interface, which provides methods to
   iterate over all methods exported by an object (either directly, or
   including those from ObjectSources).

   This interface's concrete implementation (asm.MethodSupplierImpl),
   uses Generators and IntCaches as before - we can now make that all
   package-private though, which is nice!

 - Make the LuaMethod and PeripheralMethod MethodSupplier local to the
   ComputerContext. This currently has no effect (the underlying
   Generator is still global), but eventually we'll make GenericMethods
   non-global, which unlocks the door for #1382.

 - Update everything to use this new interface. This is mostly pretty
   sensible, but is a little uglier on the MC side (especially in
   generic peripherals), as we need to access the global ServerContext.
2023-06-26 19:42:42 +01:00
Jonathan Coates
a29a516a3f
Small refactoring to generic peripherals
- Remove SidedGenericPeripheral (we never used this!), adding the
   functionality to GenericPeripheral directly. This is just used on the
   Fabric side for now, but might make sense with Forge too.

 - Move GenericPeripheralBuilder into the common project - this is
   identical between the two projects!

 - GenericPeripheralBuilder now generates a list of methods internally,
   rather than being passed the methods.

 - Add a tiny bit of documentation.
2023-06-26 19:11:59 +01:00
Jonathan Coates
4a5e03c11a
Convert NamedMethod into a record 2023-06-26 18:51:14 +01:00
Jonathan Coates
50d460624f
Make the list of API factories per-ComputerContext
The registry is still a singleton inside the Minecraft code, but this
makes the core a little cleaner.
2023-06-26 18:48:26 +01:00
Jonathan Coates
bc500df921
Use a builder for constructing ComputerContexts
We've got a few optional fields here, and more on their way, so this
ends up being a little nicer.
2023-06-26 18:42:19 +01:00
Jonathan Coates
672c2cf029
Limit turtle's reach distance in Item.use
When a turtle attempts to place a block, it does so by searching for
nearby blocks and attempting to place the item against that block.

This has slightly strange behaviour when working with "placable"
non-block items though (such as buckets or boats). In this case, we call
Item.use, which doesn't take in the position of the block we're placing
against. Instead these items do their own ray trace, using the default
reach distance.

If the block we're trying to place against is non-solid, the ray trace
will go straight through it and continue (up to the maximum of 5
blocks), allowing placing the item much further away.

Our fix here is to override the default reach distance of our fake
players, limiting it to 2. This is easy on Forge (it has built-in
support), and requires a mixin on Fabric.

Closes #1497.
2023-06-24 17:09:34 +01:00
Jonathan Coates
36b9f4ec55
Merge pull request #1485 from cc-tweaked/feature/turtle-upgrade-ui
Allow changing turtle upgrades from the GUI
2023-06-18 08:09:47 +01:00
Jonathan Coates
ccfed0059b
Render the computer cursor as emissive
- Split the front face of the computer model into two layers - one for
   the main texture, and one for the cursor. This is actually a
   simplification of what we had before, which is nice.

 - Make the cursor layer render as an emissive quad, meaning it glows in
   the dark. This is very easy on Forge (just some model JSON) and very
   hard on Fabric (requires a custom model loader).
2023-06-17 18:02:05 +01:00
Jonathan Coates
7b4ba11fb4
Allow changing turtle upgrades from the GUI
This adds two slots to the right of the turtle interface which contain
the left and right upgrades of a turtle.

 - Add turtle_upgrade_{left,right} indicators, which used as the
   background texture for the two upgrade slots. In order to use
   Slot.getNoItemIcon, we need to bake these into the block texture
   atlas.

   This is done with the new atlas JSON and a data generator - it's
   mostly pretty simple, but we do now need a client-side data
   generator, which is a little ugly to do.

 - Add a new UpgradeContainer/UpgradeSlot, which exposes a turtle's
   upgrades in an inventory-like way.

 - Update the turtle menu and screen to handle these new slots.
2023-06-17 10:48:44 +01:00
Jonathan Coates
8ccd5a560c
Add support for codecs to our data generator system
This already exists in both upstream loaders, we just need to abstract
over it.
2023-06-17 10:37:19 +01:00
Marcus
5722e51735
Fix missing curly brace in instrument list 2023-06-13 06:04:35 -04:00
Jonathan Coates
96847bb8c2
Make turtle placing consistent at all positions
Turtles used to place stairs upside-down when at y<0. Now we know why!
2023-06-08 20:52:32 +01:00
Jonathan Coates
68ef9f717b
Deprecate itemGroups field
Since 1.19.3, this was only populated when the player opened the
creative menu, and so was useless in survival or multi-player
worlds.

Rather than removing the field entirely (🦑 backwards compatibility), we
replace it with the empty list. We also remove it from the docs, and add
a note explaining what the field used to do.

Closes #1285, albeit in the least satisfactory way possible.
2023-06-08 20:33:31 +01:00
Jonathan Coates
ef19988c37
Add translations for HTTP proxy config 2023-06-07 18:33:26 +01:00
Drew Edwards
c91bb5ac33
Add support for proxying HTTP requests (#1461) 2023-06-06 18:58:24 +00:00
Jonathan Coates
6e7cbf25e8
Clean up turtle/pocket computer item creation
- Remove ITurtleItem (and ITurtleBlockEntity): this was, AFAIK, mostly
   a relic of the pre-1.13 code where we had multiple turtle items.

   I do like the theory of abstracting everything out behind an
   interface, but given there's only one concrete implementation, I'm
   not convinced it's worth it right now.

 - Remove TurtleItemFactory/PocketComputerItemFactory: we now prefer
   calling the instance .create(...) method where we have the item
   available (for instance upgrade recipes).

   In the cases we don't (creating an item the first time round), we now
   move the static .create(...) method to the actual item class.
2023-06-04 11:25:30 +01:00
Jonathan Coates
f0abb83f6e
Eagerly create upgrade registries for Fabric
Instead of creating the upgrade serialiser registries in mod
initialisation, we now do it when the API is created. This ensures the
registries are available for other mods, irrespective of mod load order.

This feels a little sad (we're doing side effects in the static
initialiser), but is /fine/ - it's pretty much what other mods do.
2023-06-03 19:04:02 +01:00
Jonathan Coates
4d064d1552
Document some of our client classes
This is mostly aiming to give an overview rather than be anything
comprehensive (there's another 230+ undocumented classes to go :p), but
it's a start.

Mostly just an excuse for me to procrastinate working on the nasty bugs
though!
2023-06-02 21:59:45 +01:00
Jonathan Coates
5082b1677c
Move MainThread config to its own class
This means the config is no longer stored as static fields, which is a
little cleaner. Would like to move everything else in the future, but
this is a good first step.
2023-05-31 22:21:17 +01:00
Jonathan Coates
b09200a270
Fix breaking computers having no particle or sound 2023-05-31 19:18:19 +01:00
Jonathan Coates
2ae14b4c08
Add support for HTTP timeouts (#1453)
- Add a `timeout` parameter to http request and websocket methods.
    - For requests, this sets the connection and read timeout.
    - For websockets, this sets the connection and handshake timeout.
 - Remove the timeout config option, as this is now specified by user
   code.
 - Use netty for handling websocket handshakes, meaning we no longer
   need to deal with pongs.
2023-05-23 22:32:16 +00:00
Jonathan Coates
3112f455ae
Support arguments being coerced from strings
In this case, we use Lua's tostring(x) semantics (well, modulo
metamethods), instead of Java's Object.toString(x) call. This ensures
that values are formatted (mostly) consistently between Lua and Java
methods.

 - Add IArguments.getStringCoerced, which uses Lua's tostring semantics.

 - Add a Coerced<T> wrapper type, which says to use the .getXCoerced
   methods. I'm not thrilled about this interface - there's definitely
   an argument for using annotations - but this is probably more
   consistent for now.

 - Convert existing methods to use this call.

Closes #1445
2023-05-20 18:54:22 +01:00
Jonathan Coates
e0216f8792
Some core cleanup
- Move some ArgumentHelpers methods to the core project.
 - Remove static imports in CobaltLuaMachine, avoiding confusing calls
   to valueOf.
2023-05-18 19:20:27 +01:00
Jonathan Coates
03c794cd53
Remove packet distance restriction for wired modems
Given that the network (and peripheral access within the network) no
longer have distance limits, packets being limited makes less sense.

Closes #1434.
2023-05-18 19:01:09 +01:00
khankul
e24b5f0888
Make maximum upload file size configurable (#1417) 2023-05-17 13:07:16 +00:00
Jonathan Coates
3bf29695fb
Fix a couple of wee bugs
- Fix monitor renderer debug text showing up even when debug overlay
   was not visible. This was a Forge-specific bug, which is why I'd not
   noticed it I guess??

 - Don't crash on alternative implementations of LoggerContext. Fixes
   #1431. I'm not 100% sure what is causing this - it doesn't happen
   with just CC:T at least - but at least we can bodge around it.
2023-05-07 10:15:03 +01:00
Jonathan Coates
232c051526
Update to latest Fabric
- Use Fabric FakePlayer class
 - Remove redundant explosion accessor
2023-05-04 18:50:00 +01:00
Kevin Z
d6751b8e3d
Update TurtleAPI.java
Fixed `turtle.detectUp` & `turtle.detectDown` doc
2023-04-23 09:58:29 -06:00
Jonathan Coates
8fe509ecb1
Properly scope IArguments to the current function call
This is a horrible commit: It's a breaking change in a pretty subtle
way, which means it won't be visible while updating. Fortunately I think
the only mod on 1.19.4 is Plethora, but other mods (Mek, Advanced
Peripherals) may be impacted when they update. Sorry!

For some motivation behind the original issue:

The default IArguments implementation (VarargArguments) lazily converts
Lua arguments to Java ones. This is mostly important when passing tables
to Java functions, as we can avoid the conversion entirely if the
function uses IArguments.getTableUnsafe.

However, this lazy conversion breaks down if IArguments is accessed on a
separate thread, as Lua values are not thread-safe. Thus we need to
perform this conversion before the cross-thread sharing occurs.

Now, ideally this would be an implementation detail and entirely
invisible to the user. One approach here would be to only perform this
lazy conversion for methods annotated with @LuaFunction(unsafe=true),
and have it be eager otherwise.

However, the peripheral API gets in the way here, as it means we can no
longer inspect the "actual" method being invoked. And so, alas, this
must leak into the public API.

TLDR: If you're getting weird errors about scope, add an
IArguments.escapes() call before sharing the arguments between threads.

Closes #1384
2023-04-01 11:09:03 +01:00
Jonathan Coates
cbb3e88d76
Relicense a couple more files
Again, not wild about .license files, but it's kinda the only option :/.

See #1339 for further details. <3 everyone!
2023-03-31 18:22:57 +01:00
Jonathan Coates
081953655c
Turtle flags
- Add a new recipe type for turtle overlays, and recipe generator
   support for this recipe.
 - Add trans and rainbow flags.
 - Exclude .license files from the generated jar. I'm not thrilled on
   the whole .license file system, but it's kinda the easiest way.
 - Regenerate data. Yes, this is 90% of the commit :D.
2023-03-31 18:14:44 +01:00
Jonathan Coates
a9547d1d6f
Further licensing work
- Fix several inaccuracies with several files not marking Dan's
   authorship. Most of these are new files, where the code was moved from
   somewhere else:
   - In the public API:  IDynamicLuaObject, ILuaAPI, TaskCallbakc,
     IDynamicPeripheral, UpgradeBase
   - In the ROM: fs, http, require

 - Do not mark Dan as an author for entirely new code. This affects
   DetailHelpers, DropConsumer, FluidData, InventoryMethods, ItemDetails,
   MonitorRenderState, NoTermComputerScreen, Palette, PlatformHelperImpl,
   UploadFileMessage, the Terminal tests, and any speaker-related files.

 - Relicence many files under the MPL where we have permission to do
   so. See #1339 for further details.

Thank you to everyone who has contributed so far! Cannot overstate how
appreciated it is <3.
2023-03-29 23:00:18 +01:00
Jonathan Coates
5bb2e8e8cd
Update Cobalt to 0.7
- Timeouts are now driven by an interrupt system, rather than polling.
   While we do not impose memory limits, this should close #1333.

 - Update the table library to largely match Lua 5.4:
    - Add table.move
    - Table methods (with the exception of foreach/foreachi) now use
      metamethods (closes #1088).
   There's still some remaining quirks (for instance, table.insert
   accepts values out-of-bounds), but I think that's fine.

 - Cobalt's threaded-coroutine system is gone (load now supports
   yielding), so we no longer track coroutine metrics.

 - Type errors now use __name. See #1355, though this does not apply to
   CC methods (either on the Java or CraftOS side), so is not enough to
   resolve it.

See https://github.com/SquidDev/Cobalt/compare/v0.6.0...v0.7.0 for the
full delta.
2023-03-26 19:42:55 +01:00
Drew Edwards
0046b095b1
Sort compounds in NBT lists for hashing (#1391) 2023-03-26 16:49:52 +00:00
Jonathan Coates
895bc7721a
License CC:T according to the REUSE specification (#1351)
This adds SPDX license headers to all source code files, following the
REUSE[1] specification. This does not include any asset files (such as
generated JSON files, or textures). While REUSE does support doing so
with ".license" files, for now we define these licences using the
.reuse/dep5 file.

[1]: https://reuse.software/
2023-03-15 21:52:13 +00:00
Jonathan Coates
3e6e3e70e5
Update to 1.19.4 (#1376) 2023-03-15 21:04:11 +00:00
Jonathan Coates
e96ac35d67
Replace Forge Config port with a NYI version
While it is a really nice library, it ends up being a bit overkill for
our needs - we don't need config syncing or anything. By NIHing our own,
we can drop one dependency and ease the updating burden a little.

Closes #1296
2023-03-14 22:47:34 +00:00
Jonathan Coates
a74089d8ae
Bump dependency versions
Mostly in prep for 1.19.4.

 - Update to Loom 1.1.

   - Simplifies our handling of remapped configurations a little.
   - Removes the need for a fake fabric.mod.json in the API jar.

   For reasons I don't quite understand, this required us to bump the
   Fabric API version. Otherwise interfaces are not injected.

 - Update to Rollup 3.0.

 - Do NOT update NullAway: It now correctly checks @Nullable fields in
   inherited classes. This is good, but also a pain as Minecraft is a
   little over-eager in where it puts @Nullable.
2023-03-14 18:43:42 +00:00
Jonathan Coates
04fed62dad
Fix NBT key name from the previous commit
I'd got it right originally, and then did a find-and-replace to fix the
gametests, forgetting that it'd touch here too. Woops.
2023-03-14 09:42:53 +00:00
Jonathan Coates
06322feb69
Fix typo in modem NBT key 2023-03-14 09:21:13 +00:00
Jonathan Coates
118d04f018
Allow placing items against some blocks
We define a tag which allows specifying which blocks can be used. Right
now this is is just cauldrons and hives, as they have "placing into"
semantics.

Closes #1305. Many thanks to Lindsay-Needs-Sleep for their initial work
on this!

Fixes #1008. I believe also fixes #854.
2023-03-04 18:17:43 +00:00
Jonathan Coates
566315947b
Try to ensure atomic writes to our ID file
- We now write to a "ids.json.new" file, then move that on top of the
   original ids.json file instead.

 - Use FileChannel.force to ensure the new file is properly flushed to
   disk. I can't really guarantee this'll work with the later
   Files.move, but it's better than not doing it!

Closes #1346.
2023-03-04 16:02:21 +00:00
Jonathan Coates
8ac42566ec
Be a little more robust in turtle item rendering
See #1328. Also some holiday cleanup, because my commit discipline is
terrible.
2023-02-09 20:07:55 +00:00