Commit Graph

55 Commits

Author SHA1 Message Date
Jonathan Coates edf372a695
Merge branch 'mc-1.16.x' into mc-1.18.x 2023-07-07 00:02:42 +01:00
Jonathan Coates 7436447a6e
Several command permission fixes
- Attach permission checks to the first argument (so the literal
   command name) rather than the last argument. This fixes commands
   showing up when they shouldn't.

 - HelpingArgumentBuilder now inherits permissions of its leaf nodes.
   This only really impacts the "track" subcommand.

 - Don't autocomplete the computer selector for the "queue" subcommand.
   As everyone has permission for this command, it's possible to find
   all computer ids and labels in the world.

   I'm in mixed minds about this, but don't think this is an exploit -
   computer ids/labels are sent to in-range players so shouldn't be
   considered secret - but worth patching none-the-less.
2023-07-06 23:41:23 +01: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 38b2c944f3
Merge branch 'mc-1.16.x' into mc-1.18.x 2022-10-30 08:49:52 +00: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
Jonathan Coates be827a21db
Merge branch 'mc-1.16.x' into mc-1.18.x
I dare say there's going to be some bugs with this. I was as careful as
I could be, but yikes it was nasty.
2022-10-25 22:38:26 +01:00
Jonathan Coates 0b26ab366d
Rewrite the metrics system
- Remove TrackingField and replace it with a Metric abstract class.
   This has two concrete subclasses - Counter and Event. Events carry an
   additional piece of data each time it is observed, such as HTTP
   response size.

 - Computers now accept a MetricsObserver, which tracks metrics for this
   particular computer. This allows us to decouple Computer classes and
   metrics information. The concrete MetricsObserver class we use within
   Minecraft exposes the ServerComputer directly, so we no longer need to
   do the awkward mapping and lookups!

 - The /computercraft command can now do aggregates (count, avg, max)
   over all Event metrics. This removes the need for special handling of
   computer and server time.

There's also a small number of changes in removing the coupling between
Computer and some of its dependencies (ILuaMachine, MainThreadExecutor).
This makes some future refactorings easier, I promise!
2022-10-22 01:35:13 +01:00
Jonathan Coates b663028f42
Start work on curtailing our global state
The last 4 or 5 commits have simplified things. I can now have some
unnecessary complexity as a treat!

This is some initial work on better tying the lifecycle of
computers (and ComputerCraft) related state to the lifecycle of the
current Minecraft server.

 - Move server-wide methods in IComputerEnvironment (such as creating
   resource mounts) into a separate interface.
 - Add a new ServerContext class, which now holds the ID Assigner,
   server computer registry, and some other tiny bits and bobs. This can
   only be accessed by ServerContect.get(MinecraftServer), forcing
   slightly better discipline for how we use these globals.

This does allow us to nuke some of the ugliest bits in IDAssigner. Even
if it makes things much longer!
2022-10-21 21:02:24 +01:00
Jonathan Coates c49547b962
Remove ClientComputer
Historically CC has maintained two computer registries; one on the
server (which runs the actual computer) and one on the client (which
stores the terminal and some small bits of additional data).

This means when a user opens the computer UI, we send the terminal
contents and store it in the client computer registry. We then send the
instance id alongside the "open container" packet, which is used to look
up the client computer (and thus terminal) in our client-side registry.

This patch makes the computer menu syncing behaviour more consistent
with vanilla. The initial terminal contents is sent alongside the "open
container" packet, and subsequent terminal changes apply /just/ to the
open container. Computer on/off state is synced via a vanilla
ContainerData/IIntArray.

Likewise, sending user input to the server now targets the open
container, rather than an arbitrary instance id.

The one remaining usage of ClientComputer is for pocket computers. For
these, we still need to sync the current on/off/blinking state and the
pocket computer light.

We don't need the full ClientComputer interface for this case (after
all, you can't send input to a pocket computer someone else is
holding!). This means we can tear out ClientComputer and
ClientComputerRegistry, replacing it with a much simpler
ClientPocketComputers store.

This in turn allows the following changes:

 - Remove IComputer, as we no longer need to abstract over client and
   server computers.

 - Likewise, we can merge ComputerRegistry into the server
   registry. This commit also cleans up the handling of instance IDs a
   little bit: ServerComputers are now responsible for generating their
   ID and adding/removing themselves from the registry.

 - As the client-side terminal will never be null, we can remove a whole
   bunch of null checks throughout the codebase.

 - As the terminal is available immediately, we don't need to explicitly
   pass in terminal sizes to the computer GUIs. This means we're no
   longer reliant on those config values on the client side!

 - Remove the "request computer state" packet. Pocket computers now
   store which players need to know the computer state, automatically
   sending data when a new player starts tracking the computer.
2022-10-21 18:17:43 +01:00
Jonathan Coates 5052718428
Merge branch 'mc-1.16.x' into mc-1.18.x 2022-05-22 15:03:01 +01:00
Jonathan Coates 78334c4cb1
Fix counts in /computercraft {turn-on,shutdown}
We were using the size of the selectors (which is normally 1) rather
than the number of computers.
2022-05-07 20:17:44 +01:00
Jonathan Coates 413fa5bcc8
Merge branch 'mc-1.16.x' into mc-1.17.x 2022-01-01 15:41:05 +00:00
Jonathan Coates 9d50d6414c
Happy new year
Should be the last time I'll have to do this!
2022-01-01 00:09:34 +00:00
Jonathan Coates 0d6528aaf0
Merge branch 'mc-1.16.x' into mc-1.17.x 2021-09-19 11:38:25 +01:00
Jonathan Coates 2aa70b49c1
Add invisible slots to computer GUIs
This ensures inventory slots are synced while the container is open,
meaning the hotbar (which is visible underneath the GUI) correctly
updates.

Fixes #915
2021-09-19 11:18:24 +01:00
Jonathan Coates aa857c1be3
Start using Java's instanceof pattern matching
Well, not really pattern matching, but it's still an improvement!
2021-08-08 12:45:30 +01:00
Jonathan Coates bb1183d274
Update to Minecraft 1.17.1
- Remap everything to use MojMap class names too. This is what Forge
   uses, so \o/.

   This does NOT currently rename any classes to use suffix notation or
   BlockEntity. That will come in a later change. We do however rename
   references of "World" to "Level".

 - Move the test mod into a separate "cctest" source set. As Forge now
   works using Jigsaw we cannot have multiple mods defining the same
   package, which causes problems with our JUnit test classes.

 - Remove our custom test framework and replace it with vanilla's (this
   is no longer stripped from the jar). RIP kotlin coroutines.

   It's still worth using Kotlin here though, just for extension
   methods.

 - Other 1.17-related changes:
    - Use separate tile/block entity tick methods for server and client
      side, often avoiding ticking at all on the client.

    - Switch much of the monitor rendering code to use vanilla's
      built-in shader system. It's still an incredibly ugly hack, so not
      really expecting this to work with any rendering mods, but we'll
      cross that bridge when we come to it.
2021-08-06 17:18:09 +01:00
Jonathan Coates f38a6a9d43
Merge branch 'mc-1.15.x' into mc-1.16.x 2021-06-05 11:36:30 +01:00
Jonathan Coates 9f7cc00fcb
Add button to view computer's folder
Implementation is a little awkward, as we can't send OPEN_FILE links
from the server, so we ensure the client runs a
/computercraft open-computer ID command instead. We then intercept this
on the client side and use that to open the folder.
2021-05-28 22:19:04 +01:00
Jonathan Coates c5694ea966 Merge branch 'mc-1.15.x' into mc-1.16.x 2021-01-09 19:25:33 +00:00
Jonathan Coates 34b5ede326 Switch to Mojang mappings
ForgeGradle (probably sensibly) yells at me about doing this. However:
 - There's a reasonable number of mods doing this, which establishes
   some optimistic precedent.
 - The licence update in Aug 2020 now allows you to use them for
   "development purposes". I guess source code counts??
 - I'm fairly sure this is also compatible with the CCPL - there's an
   exception for Minecraft code.

The main motivation for this is to make the Fabric port a little
easier. Hopefully folks (maybe me in the future, we'll see) will no
longer have to deal with mapping hell when merging - only mod loader
hell.
2021-01-09 19:22:58 +00:00
Jonathan Coates 1edb7288b9 Merge branch 'mc-1.15.x' into mc-1.16.x 2021-01-06 22:39:54 +00:00
Jonathan Coates e4b0a5b3ce 2020 -> 2021
Oh, the most useless part of my build process.
2021-01-06 17:13:40 +00:00
SquidDev e5cf0d1c61 Update mappings 2020-07-27 18:26:42 +01:00
SquidDev 46595e73df Initial update to Minecraft 1.16.1
A lot is broken, but at least we can get in game:
 - GUIs render a whole bunch of additional "inventory" text, which we
   really don't want.
 - Computers load from the wrong location.
 - There's some issues with using Forge's tags from outside of JSON
   recipes. We need to work out why.
2020-07-11 20:36:10 +01:00
SquidDev f3a330e330 Normalise enums to use SHOUTY_CASE
PascalCase is more .NET than Java
2020-01-28 22:28:48 +00:00
SquidDev 41a1b99f7d Merge branch 'master' into mc-1.14.x 2020-01-13 15:05:50 +00:00
SquidDev 93a9ebc4f6 Happy new year 2020-01-01 00:09:18 +00:00
SquidDev ccd85eb055 Bump Forge version 2019-07-21 09:41:58 +01:00
SquidDev 8dd1c2a6cc Finish off containers, somewhat fix block drops
- Add Forge's "name" field to the loot tables. This doesn't resolve all
   our missing loot providers, but it's a start.
 - Add back GUIs for pocket computers, printouts, view computer, etc...
2019-06-12 08:40:20 +01:00
SquidDev d10b657a54 Initial work on GUIs
Needs a bit of a cleanup, but it's a start!
2019-06-11 21:03:40 +01:00
SquidDev 39a9ad0ce7 Initial update to 1.14
So very little works, but it compiles and runs.

Things to resolve over the next few days:
 - Horrible mappings (should largely be resolved by tomorrow).
 - Cannot send extra data over containers - we'll have to see what Forge
   does here.
 - Turtle models are broken
 - No block drops yet - this will largely be cherry-picking whatever I
   did on Fabric.
 - Weird inventory desyncs (items don't show up initially when
   interacting with a CC inventory).
 - Probably lots of other things.
2019-06-08 13:36:31 +01:00
SquidDev fcaa777c95 Merge branch 'master' into mc-1.13.x 2019-04-09 11:11:12 +01:00
SquidDev 63dc0daa09 Convert computer sides to an enum
Previously we just relied on magic int values, which was confusing and
potentially error-prone. We could use EnumFacing, but that's a)
dependent on MC and b) incorrect, as we're referring to local
coordinates.
2019-04-09 10:02:54 +01:00
SquidDev f9e13ca67a Update CC: Tweaked to 1.13
Look, I originally had this split into several commits, but lots of
other cleanups got mixed in. I then backported some of the cleanups to
1.12, did other tidy ups there, and eventually the web of merges was
unreadable.

Yes, this is a horrible mess, but it's still nicer than it was. Anyway,
changes:

 - Flatten everything. For instance, there are now three instances of
   BlockComputer, two BlockTurtle, ItemPocketComputer. There's also no
   more BlockPeripheral (thank heavens) - there's separate block classes
   for each peripheral type.

 - Remove pretty much all legacy code. As we're breaking world
   compatibility anyway, we can remove all the code to load worlds from
   1.4 days.
 - The command system is largely rewriten to take advantage of 1.13's
   new system. It's very fancy!

 - WidgetTerminal now uses Minecraft's "GUI listener" system.

 - BREAKING CHANGE: All the codes in keys.lua are different, due to the
   move to LWJGL 3. Hopefully this won't have too much of an impact.

   I don't want to map to the old key codes on the Java side, as there
   always ends up being small but slight inconsistencies. IMO it's
   better to make a clean break - people should be using keys rather
   than hard coding the constants anyway.

 - commands.list now allows fetching sub-commands. The ROM has already
   been updated to allow fancy usage such as commands.time.set("noon").

 - Turtles, modems and cables can be waterlogged.
2019-04-02 20:59:48 +01:00
SquidDev 173ea72001 Turn inspections up to 11
OK, so let's get this out of the way, there's some actual changes mixed
in here too. I'm really sorry:
 - Turtles can now not be renamed with unnamed item tags (previously it
   would clear the name, this seemed a little unideal).
 - commands.getBlock(s)Data will also include NBT.

Now, onto the horror story which is these inspection changes:
 - Make a lot of methods static
 - Typo fixes
 - Make utility classes final + private constructor
 - Lots of reformatting (ifs -> ternary, invert control flow, etc...)
 - ???
 - Profit!

I'm so going to regret this - can pretty much guarantee this is going to
break something.
2019-03-29 21:26:21 +00:00
SquidDev c4b371b124 Cherry pick several improvements from 1.13
- Move container opening (and gui handling) into a separate class
 - Move turtle/computer placement code onto the block
 - GUIs now use gui{Left,Top} instead of calculating it manually.
 - IPeripheralTile is now exposed in the API.
2019-03-27 19:20:59 +00:00
SquidDev d12bdf50d8 Remove most instances of non-translatable strings
Oh goodness, this is going to painful to update to 1.13.

We now translate:
 - Computer/Disk ID tooltips
 - /computercraft descriptions, synopsises and usages. The last of these
   may not always be translated when in SMP, as it is sometimes done on
   the server, but the alternative would be more complex than I'm happy
   with.
 - Tracking field names. Might be worth adding descriptions too in the
   future.

Also cleanup a couple of other translation keys, so they're more
consistent with Minecraft.

Closes #141
2019-03-16 10:26:40 +00:00
SquidDev 3e28f79ce9 Shutdown computers in /computercraft shutdown
Unloading them now means they'll never be turned on again, which is a
little unideal.
2019-02-27 13:49:07 +00:00
SquidDev d6e0f368df Handle managing computer inputs/outputs separatly
The Computer class currently has several resposiblities such as storing
id/label, managing redstone/peirpherals, handling management of the
computer (on/off/events) and updating the output.

In order to simplify this a little bit, we move our IAPIEnvironment
implementation into a separate file, and store all "world state"
(redstone + peripherals) in there. While we still need to have some
level of updating them within the main Computer instance, it's
substantially simpler.
2019-02-17 19:48:52 +00:00
SquidDev 0d6787641a Clean up our handling of configuration files
- Move configuration loading into a separate file, just so it doesn't
   clutter up ComputerCraft.java.
 - Normalise property names, so they're all snake_case.
 - Split properties into separate categories (http, turtle, peripheral),
   so the main one is less cluttered.
 - Define an explicit ordering of each category.
2019-01-05 20:12:02 +00:00
SquidDev 1c9110b927 Happy new year! 2019-01-01 01:10:18 +00:00
SquidDev 42d3901ee3 Move from FMLEventChannel to SimpleNetworkWrapper
- Split each network packet into it's own individual IMessage class.
 - Move the TextTable into separate classes for server and client based
   rendering.
2018-12-29 12:44:18 +00:00
SquidDev 7e6eb62504 Move the /computer command into the main computercraft command
I don't think anyone has actually ended up using this, so it's unlikely
to break anything (though do tell me if this is the case). On the flip
side, this allows us to queue events on multiple computers, and means
we can provide a little more documentation.
2018-11-29 11:57:52 +00:00
SquidDev f40733e9a6 Error when missing computers after executing the command
This allows you to automate running various commands and still have them
"work" if some computers are not loaded.

Closes #47
2018-08-04 10:39:44 +01:00
SquidDev 81aaead032 Improve using /computercraft as a non-player
- Fix text table only showing the first row (fixes #40)
 - Do not emit alignment characters in monospace environments
 - Reduce padding in monospace environments

Also make the output of dump consistent with that of the profiler: we
provide tp and view shortcuts for each computer.
2018-06-22 08:28:36 +01:00
SquidDev 7ec8ddcf7d Delete previous chat messages of the same type
This uses a custom ComputerCraft packet to send chat messages to the
client. When received, we delete all messages of the same category
before sending the new ones.

This avoids cluttering the chat with near-identical messages, and helps
make working with the "individual dump" command easier, as the previous
computer's dump output is deleted.

Also change the max height of the TextTable to 18, so it fits within
Minecraft's default chat limit.
2018-05-15 11:44:23 +01:00
SquidDev 911e404bfa Add support for tracking fs, turtle and peripheral operations
See #25
2018-04-17 09:22:26 +01:00
SquidDev bfeafe163f Various improvements to the tracking system
- Trackers are created per-user, meaning multiple people can run
   /computercraft track at once.
 - Allow sorting the tracking information by arbitrary fields.
 - Add support for tracking arbitrary fields (though none are currently
   implemented).
2018-04-16 21:06:16 +01:00