1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-09 00:40:29 +00:00
Modernized/improved/actually updated version of ComputerCraft: https://tweaked.cc
Go to file
Jonathan Coates e9aceca1de
Add a helper class for working with attached computers
One of the easiest things to mess up with writing a custom peripheral is
handling attached peripherals. IPeripheral.{attach,detach} are called
from multiple threads, so naive implementations that just store
computers in a set/list will at some point throw a CME.

Historically I've suggested using a concurrent collection (i.e.
ConcurrentHashMap). While this solves the problems of CMEs, it still has
some flaws. If a computer is detached while iterating over the
collection, the iterator will still yield the now-detached peripheral,
causing usages of that computer (e.g. queueEvent) to throw an exception.

The only fix here is to use a lock when updating and iterating over the
collection. This does come with some risks, but I think they are not too
serious:

 - Lock contention: Contention is relatively rare in general (as
   peripheral attach/detach is not especially frequent). If we do see
   contention, both iteration and update actions are cheap, so I would
   not expect the other thread to be blocked for a significant time.

 - Deadlocks: One could imagine an implementation if IComputerAccess
   that holds a lock both when detaching a peripheral and inside
   queueEvent.

   If we queue an event on one thread, and try to detach on the other,
   we could see a deadlock:

     Thread 1                         | Thread 2
    ----------------------------------------------------------
     AttachedComputerSet.queueEvent   | MyModem.detach
      (take lock #1)                  |  (take lock #2)

     -> MyModem.queueEvent            | AttachedComputerSet.remove
      (wait on lock #2)               |  (wait on lock #1)

   Such code would have been broken already (some peripherals already
   use locks), so I'm fairly sure we've fixed this in CC. But definitely
   something to watch out for.

Anyway, the long and short of it:
 - Add a new AttachedComputerSet that can be used to track the computers
   attached to a peripheral. We also mention this in the attach/detach
   docs, to hopefully make it a little more obvoius.

 - Update speakers and monitors to use this new class.
2024-09-22 13:51:11 +01:00
.github Small bits of cleanup 2024-06-26 18:07:57 +01:00
buildSrc Fix getNextVersion 2024-08-04 14:57:09 +02:00
config/checkstyle Various Gradle tweaks 2024-04-19 18:14:51 +01:00
doc Update Cobalt to add math.atan(y, x) support 2024-09-22 13:13:07 +01:00
gradle Update Cobalt to add math.atan(y, x) support 2024-09-22 13:13:07 +01:00
LICENSES License CC:T according to the REUSE specification (#1351) 2023-03-15 21:52:13 +00:00
projects Add a helper class for working with attached computers 2024-09-22 13:51:11 +01:00
tools Fix/update language checker script 2024-07-24 19:40:09 +01:00
.editorconfig License CC:T according to the REUSE specification (#1351) 2023-03-15 21:52:13 +00:00
.git-blame-ignore-revs License CC:T according to the REUSE specification (#1351) 2023-03-15 21:52:13 +00:00
.gitattributes Force LF for .kts files too 2023-05-17 13:28:03 +01:00
.gitignore Clean up the wired network tests 2024-02-24 14:52:44 +00:00
.pre-commit-config.yaml Update to Reuse 4.0 2024-07-26 18:28:00 +01:00
build.gradle.kts Various Gradle tweaks 2024-04-19 18:14:51 +01:00
CODE_OF_CONDUCT.md License CC:T according to the REUSE specification (#1351) 2023-03-15 21:52:13 +00:00
CONTRIBUTING.md Mention Crowdin in our documentation 2024-08-24 22:55:14 +01:00
crowdin.yml Mention Crowdin in our documentation 2024-08-24 22:55:14 +01:00
gradle.properties Bump CC:T to 1.113.1 2024-09-11 18:27:13 +01:00
gradlew Update to Gradle 8.10 2024-08-15 08:49:46 +01:00
gradlew.bat Update to Gradle 8.10 2024-08-15 08:49:46 +01:00
illuaminate.sexp Update our parse errors to match latest illuaminate 2024-02-08 19:22:14 +00:00
package-lock.json Update Gradle to 8.5 2024-01-27 09:28:13 +00:00
package.json Update Gradle to 8.5 2024-01-27 09:28:13 +00:00
README.md Update links to IRC 2024-07-24 21:38:14 +01:00
REUSE.toml Update to Gradle 8.10 2024-08-15 08:49:46 +01:00
settings.gradle.kts Small bits of cleanup 2024-06-26 18:07:57 +01:00

CC: Tweaked

Current build status Download CC: Tweaked on CurseForge Download CC: Tweaked on Modrinth

CC: Tweaked is a mod for Minecraft which adds programmable computers, turtles and more to the game. A fork of the much-beloved ComputerCraft, it continues its legacy with improved performance and stability, along with a wealth of new features.

CC: Tweaked can be installed from CurseForge or Modrinth. It runs on both Minecraft Forge and Fabric.

Contributing

Any contribution is welcome, be that using the mod, reporting bugs or contributing code. If you want to get started developing the mod, check out the instructions here.

Community

If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about ComputerCraft, do check out our GitHub discussions page! There's also a fairly populated, albeit quiet IRC channel on EsperNet, if that's more your cup of tea. You can join #computercraft through your desktop client, or online using KiwiIRC.

We also host fairly comprehensive documentation at tweaked.cc.

Using

CC: Tweaked is hosted on my maven repo, and so is relatively simple to depend on. You may wish to add a soft (or hard) dependency in your mods.toml file, with the appropriate version bounds, to ensure that API functionality you depend on is present.

repositories {
  maven {
    url "https://maven.squiddev.cc"
    content {
      includeGroup("cc.tweaked")
    }
  }
}

dependencies {
  // Vanilla (i.e. for multi-loader systems)
  compileOnly("cc.tweaked:cc-tweaked-$mcVersion-common-api:$cctVersion")

  // Forge Gradle
  compileOnly("cc.tweaked:cc-tweaked-$mcVersion-core-api:$cctVersion")
  compileOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge-api:$cctVersion"))
  runtimeOnly(fg.deobf("cc.tweaked:cc-tweaked-$mcVersion-forge:$cctVersion"))

  // Fabric Loom
  modCompileOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric-api:$cctVersion")
  modRuntimeOnly("cc.tweaked:cc-tweaked-$mcVersion-fabric:$cctVersion")
}

When using ForgeGradle, you may also need to add the following:

minecraft {
    runs {
        configureEach {
            property 'mixin.env.remapRefMap', 'true'
            property 'mixin.env.refMapRemappingFile', "${buildDir}/createSrgToMcp/output.srg"
        }
    }
}

You should also be careful to only use classes within the dan200.computercraft.api package. Non-API classes are subject to change at any point. If you depend on functionality outside the API (or need to mixin to CC:T), please file an issue to let me know!

We bundle the API sources with the jar, so documentation should be easily viewable within your editor. Alternatively, the generated documentation can be browsed online.