CC: Tweaked

CC: Tweaked

42M Downloads

A grand-ol' cleanup

SquidDev opened this issue ยท 1 comments

commented

As some people may have noticed, I've committed some relatively large commits recently (such as reformatting the codebase, removing LuaJ). None have really impacted functionality, but have instead made some progress towards making the code (in my opinion at least), cleaner and more easy to maintain in the future.

Over the next few weeks, I'd like to continue these improvements (albeit on a less major scale), in an attempt to simplify the codebase as much as possible. As I've talked about elsewhere, CC is a pretty old mod, and there's many features which can be implemented in a better way - either due to improvements in Forge or Minecraft's base engine.

I've implemented some of these changes in the 1.13 and 1.14 PRs, and while not everything can be integrated into master, there's several useful improvements which can be.

A summary of the desired changes

Most changes fall into a couple of categories:

  • General reformatting: This is purely a personal preference, but there is an awful lot of code which could be made more concise and/or understandable by a little rearranging. Namely: inverting ifs to allow early-returns, using ?: instead of if/else, etc...
  • Using builtins: Replacing our home-grown solutions with ones built-in to Forge or Minecraft.

One thing to be aware of is that we must not break backwards compatibility with other mods. This has been a bit of an issue recently (#87, #76), so we must be sure to test the changes work with Computronics and Plethora.

If people do encounter issues with their add-on, do file a report, and I'll add it to the "to test" list.

List of (desired) changes

  • Reduce TileComputerBase's dependency on the actual "computer". For instance, picking or breaking a block relies on the client/server computer, where we could just use the label field on the tile.

    Most of the time this isn't an issue, but it does mean we have to sync computer data to the client separately, which gets a little annoying. We'll still need to do this for pocket computers, but not blocks too. (54acf1d, but would be nice to clean up pocket computers).

  • Make printers/disk drives thread safe. (Some work done in #183, found some more issues as a result of those changes)

  • Go through all times we request a block update, and see if we can narrow the scope. We don't actually need to mark the chunk as dirty a lot of the times.

  • Clean up destroying of blocks. I feel there's a couple of places we could get away with using invalidate. Likewise, could we rebuild the state when validated?

  • Clean up disk drive mounting/unmounting code, so #240 does not occur again. We don't want to rely on the internal stack being immutable.

Archive

Mostly so I can feel happy about the "progress" made, without filling up the issue.

  • Remove CCEdu integration (4ead319)
  • Refactor upgrades to share more code (dd6bab5)
  • Replace DirectionUtil with EnumFacing methods (a1c4a9f)
  • Replace WorldUtil with builtin alternatives (4d5c52b).
  • Replace current ComputerCraftPacket with multiple, more-specific IMessages. We'll have to be careful here that this doesn't increase the packet size when sending terminals (which is by far-and-large the biggest packet). (42d3901)
    • Make the registration model closer to that of Forge's? Namely, move the packet ID into the registration, rather than the class. (ce0685c)
  • Replace pocket computer model overrides with a custom property and JSON. (37e2513)
  • Move several methods from TileGeneric onto more specific tile entities or blocks. Off the top of my head: explosion resistance, bounding box, maybe pick block? (2c87e66)
  • Move modems, and associated code into separate wired/wireless packages. (364d314)
  • Move as much API code out of ComputerCraft as possible. We'll have to be careful to preserve the peripheral list, as Plethora and Computronics reflect into that. (41a320e)
  • Try to reduce the surface-area that the proxies cover. (26ba610, f8b328a, 41a320e).
  • Move some inventory code into a parent interface. (57fb77d)
  • Replace BlockCable's cable state with JSON, as we have on the Fabric branch. (f61f7df)
  • Define recipes in JSON rather than in code. (618c534)
  • Clean up of what items printers can accept? (46fa798)
  • Replace EntityItem spawning with the version in WorldUtil. (77666d7)
  • Make speakers (and modems) use Vec3d instead of their current wacky positioning. (77666d7)
  • Can we move some tiles away from TilePeripheralBase? Namely ones which don't depend on BlockPeripheralBase
  • Use @Mod.EventBusSubscriber a little more. We'd have to make some classes static instead of singletons, but that's fine. (5d97b9c)
    • ^ On a related note, move block/item registration into something separate from the proxies. (6369170)
  • Rethink block drops. We have to manually specify all block's drops, and it gets awfully confusing.
  • Make load/loadstring do the prefix appending on the Lua side.
  • Register an implementation of JEI's IRecipeRegistryPlugin for various dynamic recipes, instead of generating a load of them. We should perhaps think about how this works with the recipe book (if that matters). (41429bd)
  • Use the native "can use command block" checks, rather than our own. (cbfd5ae)
commented

At this point the big things have been done, and the remaining things haven't ended up being that important.