mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-28 00:12:16 +00:00
Merge pull request #24 from Merith-TK/1.17.1-mojmap
mojmap port + make codebase closer to CC:T codebase
This commit is contained in:
commit
19d12a4706
4
.github/workflows/main-ci.yml
vendored
4
.github/workflows/main-ci.yml
vendored
@ -9,8 +9,8 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Checkout submodules
|
||||
run: git submodule update --init --recursive
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Set up Java 16
|
||||
uses: actions/setup-java@v1
|
||||
|
166
build.gradle
166
build.gradle
@ -1,47 +1,68 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.9-SNAPSHOT'
|
||||
id 'maven-publish'
|
||||
id "checkstyle"
|
||||
id "jacoco"
|
||||
id "maven-publish"
|
||||
id "com.github.hierynomus.license" version "0.16.1"
|
||||
id "org.jetbrains.kotlin.jvm" version "1.5.21"
|
||||
id 'fabric-loom' version '0.10-SNAPSHOT'
|
||||
}
|
||||
|
||||
def javaVersion = JavaLanguageVersion.of(16)
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(16)
|
||||
vendor = JvmVendorSpec.ADOPTOPENJDK
|
||||
languageVersion = javaVersion
|
||||
}
|
||||
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
tasks.withType(JavaExec).configureEach {
|
||||
javaLauncher = javaToolchains.launcherFor {
|
||||
languageVersion = javaVersion
|
||||
}
|
||||
}
|
||||
|
||||
version = mod_version
|
||||
|
||||
group = "dan200.computercraft"
|
||||
archivesBaseName = "cc-restiched"
|
||||
archivesBaseName = "cc-restitched"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven { url 'https://api.modrinth.com/maven'}
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.terraformersmc.com/" }
|
||||
maven {
|
||||
name "SquidDev"
|
||||
url "https://squiddev.cc/maven"
|
||||
sourceSets {
|
||||
main.resources {
|
||||
srcDir 'src/generated/resources'
|
||||
}
|
||||
|
||||
testMod {}
|
||||
}
|
||||
|
||||
loom {
|
||||
accessWidenerPath = file("src/main/resources/cc.accesswidener")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name "SquidDev"
|
||||
url "https://squiddev.cc/maven"
|
||||
}
|
||||
|
||||
// TODO: Limit these to a set of groups.
|
||||
maven { url "https://maven.shedaniel.me/" }
|
||||
maven { url "https://maven.terraformersmc.com/" }
|
||||
}
|
||||
|
||||
configurations {
|
||||
shade
|
||||
implementation.extendsFrom shade
|
||||
cctJavadoc
|
||||
}
|
||||
|
||||
dependencies {
|
||||
checkstyle 'com.puppycrawl.tools:checkstyle:8.45.1'
|
||||
checkstyle "com.puppycrawl.tools:checkstyle:8.45"
|
||||
|
||||
minecraft "com.mojang:minecraft:${mc_version}"
|
||||
mappings "net.fabricmc:yarn:${mc_version}+build.${mappings_version}:v2"
|
||||
mappings loom.officialMojangMappings()
|
||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
|
||||
|
||||
@ -52,7 +73,8 @@ dependencies {
|
||||
modImplementation "me.shedaniel.cloth.api:cloth-utils-v1:${cloth_api_version}"
|
||||
|
||||
implementation 'com.electronwill.night-config:toml:3.6.3'
|
||||
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
|
||||
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
|
||||
shade 'org.squiddev:Cobalt:0.5.2-SNAPSHOT'
|
||||
|
||||
@ -61,39 +83,114 @@ dependencies {
|
||||
include 'com.electronwill.night-config:toml:3.6.3'
|
||||
include "me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}"
|
||||
|
||||
modRuntime "me.shedaniel:RoughlyEnoughItems-api-fabric:6.0.254-alpha"
|
||||
modRuntime "me.shedaniel:RoughlyEnoughItems-fabric:6.0.254-alpha"
|
||||
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:6.0.254-alpha"
|
||||
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:6.0.254-alpha"
|
||||
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||
testImplementation 'org.hamcrest:hamcrest:2.2'
|
||||
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21'
|
||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
|
||||
|
||||
cctJavadoc 'cc.tweaked:cct-javadoc:1.4.1'
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
|
||||
filesMatching("fabric.mod.json") {
|
||||
expand "version": project.version
|
||||
}
|
||||
def hash = 'none'
|
||||
Set<String> contributors = []
|
||||
try {
|
||||
hash = ["git", "-C", projectDir, "rev-parse", "HEAD"].execute().text.trim()
|
||||
|
||||
def blacklist = ['GitHub', 'dan200', 'Daniel Ratcliffe']
|
||||
["git", "-C", projectDir, "log", "--format=tformat:%an%n%cn"].execute().text.split('\n').each {
|
||||
if (!blacklist.contains(it)) contributors.add(it)
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
inputs.property "commithash", hash
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
|
||||
filesMatching(["fabric.mod.json", "data/computercraft/lua/rom/help/credits.txt"]) {
|
||||
expand(
|
||||
'version': mod_version,
|
||||
'mcversion': mc_version,
|
||||
'gitcontributors': contributors.sort(false, String.CASE_INSENSITIVE_ORDER).join('\n')
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// ensure that the encoding is set to UTF-8, no matter what the system default is
|
||||
// this fixes some edge cases with special characters not displaying correctly
|
||||
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
|
||||
tasks.withType(JavaCompile) {
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
|
||||
// if it is present.
|
||||
// If you remove this task, sources will not be generated.
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = "sources"
|
||||
from sourceSets.main.allSource
|
||||
javadoc {
|
||||
include "dan200/computercraft/api/**/*.java"
|
||||
}
|
||||
|
||||
task luaJavadoc(type: Javadoc) {
|
||||
description "Generates documentation for Java-side Lua functions."
|
||||
group "documentation"
|
||||
|
||||
source = sourceSets.main.allJava
|
||||
destinationDir = file("${project.docsDir}/luaJavadoc")
|
||||
classpath = sourceSets.main.compileClasspath
|
||||
|
||||
options.docletpath = configurations.cctJavadoc.files as List
|
||||
options.doclet = "cc.tweaked.javadoc.LuaDoclet"
|
||||
options.noTimestamp = false
|
||||
|
||||
javadocTool = javaToolchains.javadocToolFor {
|
||||
languageVersion = javaVersion
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
from "LICENSE"
|
||||
manifest {
|
||||
attributes([
|
||||
"Specification-Title" : "computercraft",
|
||||
"Specification-Version" : "1",
|
||||
"Implementation-Title" : "CC: Restitched",
|
||||
"Implementation-Version" : "${mod_version}",
|
||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
])
|
||||
}
|
||||
|
||||
from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
|
||||
[compileJava, compileTestJava].forEach {
|
||||
it.configure {
|
||||
options.compilerArgs << "-Xlint" << "-Xlint:-processing"
|
||||
}
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
||||
}
|
||||
|
||||
// Check tasks
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
events "skipped", "failed"
|
||||
}
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
dependsOn('test')
|
||||
reports {
|
||||
xml.required = true
|
||||
html.required = true
|
||||
}
|
||||
}
|
||||
|
||||
check.dependsOn jacocoTestReport
|
||||
|
||||
import com.hierynomus.gradle.license.tasks.LicenseCheck
|
||||
import com.hierynomus.gradle.license.tasks.LicenseFormat
|
||||
@ -113,7 +210,7 @@ license {
|
||||
}
|
||||
}
|
||||
|
||||
[licenseTest, licenseFormatTest].forEach {
|
||||
[licenseTest, licenseFormatTest, licenseTestMod, licenseFormatTestMod].forEach {
|
||||
it.configure {
|
||||
include("**/*.java")
|
||||
header file('config/license/main.txt')
|
||||
@ -126,9 +223,8 @@ gradle.projectsEvaluated {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task licenseAPI(type: LicenseCheck);
|
||||
task licenseFormatAPI(type: LicenseFormat);
|
||||
task licenseAPI(type: LicenseCheck)
|
||||
task licenseFormatAPI(type: LicenseFormat)
|
||||
[licenseAPI, licenseFormatAPI].forEach {
|
||||
it.configure {
|
||||
source = sourceSets.main.java
|
||||
|
@ -58,13 +58,20 @@
|
||||
<module name="SimplifyBooleanExpression" />
|
||||
<module name="SimplifyBooleanReturn" />
|
||||
<module name="StringLiteralEquality" />
|
||||
<!-- <module name="UnnecessaryParentheses" /> -->
|
||||
<module name="UnnecessaryParentheses">
|
||||
<!-- Default minus LAND. -->
|
||||
<property name="tokens" value="EXPR,IDENT,NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG,STRING_LITERAL,LITERAL_NULL,LITERAL_FALSE,LITERAL_TRUE,ASSIGN,BAND_ASSIGN,BOR_ASSIGN,BSR_ASSIGN,BXOR_ASSIGN,DIV_ASSIGN,MINUS_ASSIGN,MOD_ASSIGN,PLUS_ASSIGN,SL_ASSIGN,SR_ASSIGN,STAR_ASSIGN,LAMBDA,TEXT_BLOCK_LITERAL_BEGIN,LITERAL_INSTANCEOF,GT,LT,GE,LE,EQUAL,NOT_EQUAL,UNARY_MINUS,UNARY_PLUS,INC,DEC,LNOT,BNOT,POST_INC,POST_DEC" />
|
||||
</module>
|
||||
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
|
||||
<module name="UnnecessarySemicolonInTryWithResources" />
|
||||
<module name="UnnecessarySemicolonInEnumeration" />
|
||||
|
||||
<!-- Imports -->
|
||||
<!--<module name="CustomImportOrder" />-->
|
||||
<module name="CustomImportOrder">
|
||||
<property name="customImportOrderRules"
|
||||
value="THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###STATIC"
|
||||
/>
|
||||
</module>
|
||||
<module name="IllegalImport" />
|
||||
<module name="RedundantImport" />
|
||||
<module name="UnusedImports" />
|
||||
@ -149,8 +156,13 @@
|
||||
<property name="tokens" value="COMMA" />
|
||||
</module>
|
||||
<module name="WhitespaceAround">
|
||||
<property name="allowEmptyConstructors" value="true" />
|
||||
<property name="ignoreEnhancedForColon" value="false" />
|
||||
<!-- Allow empty functions -->
|
||||
<property name="allowEmptyLambdas" value="true" />
|
||||
<property name="allowEmptyMethods" value="true" />
|
||||
<property name="allowEmptyConstructors" value="true" />
|
||||
<property name="allowEmptyTypes" value="true" />
|
||||
|
||||
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_RETURN,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND" />
|
||||
</module>
|
||||
</module>
|
||||
|
@ -2,7 +2,7 @@
|
||||
# See https://pre-commit.com/hooks.html for more hooks
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v3.2.0
|
||||
rev: v4.0.1
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
@ -16,7 +16,7 @@ repos:
|
||||
exclude: "tsconfig\\.json$"
|
||||
|
||||
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
|
||||
rev: 2.3.5
|
||||
rev: 2.3.54
|
||||
hooks:
|
||||
- id: editorconfig-checker
|
||||
args: ['-disable-indentation']
|
||||
@ -38,6 +38,13 @@ repos:
|
||||
entry: ./gradlew licenseFormat
|
||||
pass_filenames: false
|
||||
require_serial: true
|
||||
- id: illuaminate
|
||||
name: Check Lua code
|
||||
files: ".*\\.(lua|java|md)"
|
||||
language: script
|
||||
entry: config/pre-commit/illuaminate-lint.sh
|
||||
pass_filenames: false
|
||||
require_serial: true
|
||||
|
||||
exclude: |
|
||||
(?x)^(
|
||||
|
21
doc/events/alarm.md
Normal file
21
doc/events/alarm.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
module: [kind=event] alarm
|
||||
see: os.setAlarm To start an alarm.
|
||||
---
|
||||
|
||||
The @{timer} event is fired when an alarm started with @{os.setAlarm} completes.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The ID of the alarm that finished.
|
||||
|
||||
## Example
|
||||
Starts a timer and then prints its ID:
|
||||
```lua
|
||||
local alarmID = os.setAlarm(os.time() + 0.05)
|
||||
local event, id
|
||||
repeat
|
||||
event, id = os.pullEvent("alarm")
|
||||
until id == alarmID
|
||||
print("Alarm with ID " .. id .. " was fired")
|
||||
```
|
24
doc/events/char.md
Normal file
24
doc/events/char.md
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
module: [kind=event] char
|
||||
see: key To listen to any key press.
|
||||
---
|
||||
|
||||
The @{char} event is fired when a character is _typed_ on the keyboard.
|
||||
|
||||
The @{char} event is different to a key press. Sometimes multiple key presses may result in one character being
|
||||
typed (for instance, on some European keyboards). Similarly, some keys (e.g. <kbd>Ctrl</kbd>) do not have any
|
||||
corresponding character. The @{key} should be used if you want to listen to key presses themselves.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The string representing the character that was pressed.
|
||||
|
||||
|
||||
## Example
|
||||
Prints each character the user presses:
|
||||
```lua
|
||||
while true do
|
||||
local event, character = os.pullEvent("char")
|
||||
print(character .. " was pressed.")
|
||||
end
|
||||
```
|
18
doc/events/computer_command.md
Normal file
18
doc/events/computer_command.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
module: [kind=event] computer_command
|
||||
---
|
||||
|
||||
The @{computer_command} event is fired when the `/computercraft queue` command is run for the current computer.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
... @{string}: The arguments passed to the command.
|
||||
|
||||
## Example
|
||||
Prints the contents of messages sent:
|
||||
```lua
|
||||
while true do
|
||||
local event = {os.pullEvent("computer_command")}
|
||||
print("Received message:", table.unpack(event, 2))
|
||||
end
|
||||
```
|
19
doc/events/disk.md
Normal file
19
doc/events/disk.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
module: [kind=event] disk
|
||||
see: disk_eject For the event sent when a disk is removed.
|
||||
---
|
||||
|
||||
The @{disk} event is fired when a disk is inserted into an adjacent or networked disk drive.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The side of the disk drive that had a disk inserted.
|
||||
|
||||
## Example
|
||||
Prints a message when a disk is inserted:
|
||||
```lua
|
||||
while true do
|
||||
local event, side = os.pullEvent("disk")
|
||||
print("Inserted a disk on side " .. side)
|
||||
end
|
||||
```
|
19
doc/events/disk_eject.md
Normal file
19
doc/events/disk_eject.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
module: [kind=event] disk_eject
|
||||
see: disk For the event sent when a disk is inserted.
|
||||
---
|
||||
|
||||
The @{disk_eject} event is fired when a disk is removed from an adjacent or networked disk drive.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The side of the disk drive that had a disk removed.
|
||||
|
||||
## Example
|
||||
Prints a message when a disk is removed:
|
||||
```lua
|
||||
while true do
|
||||
local event, side = os.pullEvent("disk_eject")
|
||||
print("Removed a disk on side " .. side)
|
||||
end
|
||||
```
|
14
doc/events/http_check.md
Normal file
14
doc/events/http_check.md
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
module: [kind=event] http_check
|
||||
see: http.checkURLAsync To check a URL asynchronously.
|
||||
---
|
||||
|
||||
The @{http_check} event is fired when a URL check finishes.
|
||||
|
||||
This event is normally handled inside @{http.checkURL}, but it can still be seen when using @{http.checkURLAsync}.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The URL requested to be checked.
|
||||
3. @{boolean}: Whether the check succeeded.
|
||||
4. @{string|nil}: If the check failed, a reason explaining why the check failed.
|
39
doc/events/http_failure.md
Normal file
39
doc/events/http_failure.md
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
module: [kind=event] http_failure
|
||||
see: http.request To send an HTTP request.
|
||||
---
|
||||
|
||||
The @{http_failure} event is fired when an HTTP request fails.
|
||||
|
||||
This event is normally handled inside @{http.get} and @{http.post}, but it can still be seen when using @{http.request}.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The URL of the site requested.
|
||||
3. @{string}: An error describing the failure.
|
||||
4. @{http.Response|nil}: A response handle if the connection succeeded, but the server's response indicated failure.
|
||||
|
||||
## Example
|
||||
Prints an error why the website cannot be contacted:
|
||||
```lua
|
||||
local myURL = "https://does.not.exist.tweaked.cc"
|
||||
http.request(myURL)
|
||||
local event, url, err
|
||||
repeat
|
||||
event, url, err = os.pullEvent("http_failure")
|
||||
until url == myURL
|
||||
print("The URL " .. url .. " could not be reached: " .. err)
|
||||
```
|
||||
|
||||
Prints the contents of a webpage that does not exist:
|
||||
```lua
|
||||
local myURL = "https://tweaked.cc/this/does/not/exist"
|
||||
http.request(myURL)
|
||||
local event, url, err, handle
|
||||
repeat
|
||||
event, url, err, handle = os.pullEvent("http_failure")
|
||||
until url == myURL
|
||||
print("The URL " .. url .. " could not be reached: " .. err)
|
||||
print(handle.getResponseCode())
|
||||
handle.close()
|
||||
```
|
27
doc/events/http_success.md
Normal file
27
doc/events/http_success.md
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
module: [kind=event] http_success
|
||||
see: http.request To make an HTTP request.
|
||||
---
|
||||
|
||||
The @{http_success} event is fired when an HTTP request returns successfully.
|
||||
|
||||
This event is normally handled inside @{http.get} and @{http.post}, but it can still be seen when using @{http.request}.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The URL of the site requested.
|
||||
3. @{http.Response}: The handle for the response text.
|
||||
|
||||
## Example
|
||||
Prints the content of a website (this may fail if the request fails):
|
||||
```lua
|
||||
local myURL = "https://tweaked.cc/"
|
||||
http.request(myURL)
|
||||
local event, url, handle
|
||||
repeat
|
||||
event, url, handle = os.pullEvent("http_success")
|
||||
until url == myURL
|
||||
print("Contents of " .. url .. ":")
|
||||
print(handle.readAll())
|
||||
handle.close()
|
||||
```
|
26
doc/events/key.md
Normal file
26
doc/events/key.md
Normal file
@ -0,0 +1,26 @@
|
||||
---
|
||||
module: [kind=event] key
|
||||
---
|
||||
|
||||
This event is fired when any key is pressed while the terminal is focused.
|
||||
|
||||
This event returns a numerical "key code" (for instance, <kbd>F1</kbd> is 290). This value may vary between versions and
|
||||
so it is recommended to use the constants in the @{keys} API rather than hard coding numeric values.
|
||||
|
||||
If the button pressed represented a printable character, then the @{key} event will be followed immediately by a @{char}
|
||||
event. If you are consuming text input, use a @{char} event instead!
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The numerical key value of the key pressed.
|
||||
3. @{boolean}: Whether the key event was generated while holding the key (@{true}), rather than pressing it the first time (@{false}).
|
||||
|
||||
## Example
|
||||
Prints each key when the user presses it, and if the key is being held.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, key, is_held = os.pullEvent("key")
|
||||
print(("%s held=%s"):format(keys.getName(key), is_held))
|
||||
end
|
||||
```
|
24
doc/events/key_up.md
Normal file
24
doc/events/key_up.md
Normal file
@ -0,0 +1,24 @@
|
||||
---
|
||||
module: [kind=event] key_up
|
||||
see: keys For a lookup table of the given keys.
|
||||
---
|
||||
|
||||
Fired whenever a key is released (or the terminal is closed while a key was being pressed).
|
||||
|
||||
This event returns a numerical "key code" (for instance, <kbd>F1</kbd> is 290). This value may vary between versions and
|
||||
so it is recommended to use the constants in the @{keys} API rather than hard coding numeric values.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The numerical key value of the key pressed.
|
||||
|
||||
## Example
|
||||
Prints each key released on the keyboard whenever a @{key_up} event is fired.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, key = os.pullEvent("key_up")
|
||||
local name = keys.getName(key) or "unknown key"
|
||||
print(name .. " was released.")
|
||||
end
|
||||
```
|
22
doc/events/modem_message.md
Normal file
22
doc/events/modem_message.md
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
module: [kind=event] modem_message
|
||||
---
|
||||
|
||||
The @{modem_message} event is fired when a message is received on an open channel on any modem.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The side of the modem that received the message.
|
||||
3. @{number}: The channel that the message was sent on.
|
||||
4. @{number}: The reply channel set by the sender.
|
||||
5. @{any}: The message as sent by the sender.
|
||||
6. @{number}: The distance between the sender and the receiver, in blocks (decimal).
|
||||
|
||||
## Example
|
||||
Prints a message when one is sent:
|
||||
```lua
|
||||
while true do
|
||||
local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
|
||||
print(("Message received on side %s on channel %d (reply to %d) from %f blocks away with message %s"):format(side, channel, replyChannel, distance, tostring(message)))
|
||||
end
|
||||
```
|
18
doc/events/monitor_resize.md
Normal file
18
doc/events/monitor_resize.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
module: [kind=event] monitor_resize
|
||||
---
|
||||
|
||||
The @{monitor_resize} event is fired when an adjacent or networked monitor's size is changed.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The side or network ID of the monitor that resized.
|
||||
|
||||
## Example
|
||||
Prints a message when a monitor is resized:
|
||||
```lua
|
||||
while true do
|
||||
local event, side = os.pullEvent("monitor_resize")
|
||||
print("The monitor on side " .. side .. " was resized.")
|
||||
end
|
||||
```
|
20
doc/events/monitor_touch.md
Normal file
20
doc/events/monitor_touch.md
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
module: [kind=event] monitor_touch
|
||||
---
|
||||
|
||||
The @{monitor_touch} event is fired when an adjacent or networked Advanced Monitor is right-clicked.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The side or network ID of the monitor that was touched.
|
||||
3. @{number}: The X coordinate of the touch, in characters.
|
||||
4. @{number}: The Y coordinate of the touch, in characters.
|
||||
|
||||
## Example
|
||||
Prints a message when a monitor is touched:
|
||||
```lua
|
||||
while true do
|
||||
local event, side, x, y = os.pullEvent("monitor_touch")
|
||||
print("The monitor on side " .. side .. " was touched at (" .. x .. ", " .. y .. ")")
|
||||
end
|
||||
```
|
34
doc/events/mouse_click.md
Normal file
34
doc/events/mouse_click.md
Normal file
@ -0,0 +1,34 @@
|
||||
---
|
||||
module: [kind=event] mouse_click
|
||||
---
|
||||
|
||||
This event is fired when the terminal is clicked with a mouse. This event is only fired on advanced computers (including
|
||||
advanced turtles and pocket computers).
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The mouse button that was clicked.
|
||||
3. @{number}: The X-coordinate of the click.
|
||||
4. @{number}: The Y-coordinate of the click.
|
||||
|
||||
## Mouse buttons
|
||||
Several mouse events (@{mouse_click}, @{mouse_up}, @{mouse_scroll}) contain a "mouse button" code. This takes a
|
||||
numerical value depending on which button on your mouse was last pressed when this event occurred.
|
||||
|
||||
<table class="pretty-table">
|
||||
<!-- Our markdown parser doesn't work on tables!? Guess I'll have to roll my own soonish :/. -->
|
||||
<tr><th>Button code</th><th>Mouse button</th></tr>
|
||||
<tr><td align="right">1</td><td>Left button</td></tr>
|
||||
<tr><td align="right">2</td><td>Middle button</td></tr>
|
||||
<tr><td align="right">3</td><td>Right button</td></tr>
|
||||
</table>
|
||||
|
||||
## Example
|
||||
Print the button and the coordinates whenever the mouse is clicked.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, button, x, y = os.pullEvent("mouse_click")
|
||||
print(("The mouse button %s was pressed at %d, %d"):format(button, x, y))
|
||||
end
|
||||
```
|
22
doc/events/mouse_drag.md
Normal file
22
doc/events/mouse_drag.md
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
module: [kind=event] mouse_drag
|
||||
see: mouse_click For when a mouse button is initially pressed.
|
||||
---
|
||||
|
||||
This event is fired every time the mouse is moved while a mouse button is being held.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The [mouse button](mouse_click.html#Mouse_buttons) that is being pressed.
|
||||
3. @{number}: The X-coordinate of the mouse.
|
||||
4. @{number}: The Y-coordinate of the mouse.
|
||||
|
||||
## Example
|
||||
Print the button and the coordinates whenever the mouse is dragged.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, button, x, y = os.pullEvent("mouse_drag")
|
||||
print(("The mouse button %s was dragged at %d, %d"):format(button, x, y))
|
||||
end
|
||||
```
|
21
doc/events/mouse_scroll.md
Normal file
21
doc/events/mouse_scroll.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
module: [kind=event] mouse_scroll
|
||||
---
|
||||
|
||||
This event is fired when a mouse wheel is scrolled in the terminal.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The direction of the scroll. (-1 = up, 1 = down)
|
||||
3. @{number}: The X-coordinate of the mouse when scrolling.
|
||||
4. @{number}: The Y-coordinate of the mouse when scrolling.
|
||||
|
||||
## Example
|
||||
Prints the direction of each scroll, and the position of the mouse at the time.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, dir, x, y = os.pullEvent("mouse_scroll")
|
||||
print(("The mouse was scrolled in direction %s at %d, %d"):format(dir, x, y))
|
||||
end
|
||||
```
|
21
doc/events/mouse_up.md
Normal file
21
doc/events/mouse_up.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
module: [kind=event] mouse_up
|
||||
---
|
||||
|
||||
This event is fired when a mouse button is released or a held mouse leaves the computer's terminal.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The [mouse button](mouse_click.html#Mouse_buttons) that was released.
|
||||
3. @{number}: The X-coordinate of the mouse.
|
||||
4. @{number}: The Y-coordinate of the mouse.
|
||||
|
||||
## Example
|
||||
Prints the coordinates and button number whenever the mouse is released.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, button, x, y = os.pullEvent("mouse_up")
|
||||
print(("The mouse button %s was released at %d, %d"):format(button, x, y))
|
||||
end
|
||||
```
|
18
doc/events/paste.md
Normal file
18
doc/events/paste.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
module: [kind=event] paste
|
||||
---
|
||||
|
||||
The @{paste} event is fired when text is pasted into the computer through Ctrl-V (or ⌘V on Mac).
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{string} The text that was pasted.
|
||||
|
||||
## Example
|
||||
Prints pasted text:
|
||||
```lua
|
||||
while true do
|
||||
local event, text = os.pullEvent("paste")
|
||||
print('"' .. text .. '" was pasted')
|
||||
end
|
||||
```
|
19
doc/events/peripheral.md
Normal file
19
doc/events/peripheral.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
module: [kind=event] peripheral
|
||||
see: peripheral_detach For the event fired when a peripheral is detached.
|
||||
---
|
||||
|
||||
The @{peripheral} event is fired when a peripheral is attached on a side or to a modem.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The side the peripheral was attached to.
|
||||
|
||||
## Example
|
||||
Prints a message when a peripheral is attached:
|
||||
```lua
|
||||
while true do
|
||||
local event, side = os.pullEvent("peripheral")
|
||||
print("A peripheral was attached on side " .. side)
|
||||
end
|
||||
```
|
19
doc/events/peripheral_detach.md
Normal file
19
doc/events/peripheral_detach.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
module: [kind=event] peripheral_detach
|
||||
see: peripheral For the event fired when a peripheral is attached.
|
||||
---
|
||||
|
||||
The @{peripheral_detach} event is fired when a peripheral is detached from a side or from a modem.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The side the peripheral was detached from.
|
||||
|
||||
## Example
|
||||
Prints a message when a peripheral is detached:
|
||||
```lua
|
||||
while true do
|
||||
local event, side = os.pullEvent("peripheral_detach")
|
||||
print("A peripheral was detached on side " .. side)
|
||||
end
|
||||
```
|
30
doc/events/rednet_message.md
Normal file
30
doc/events/rednet_message.md
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
module: [kind=event] rednet_message
|
||||
see: modem_message For raw modem messages sent outside of Rednet.
|
||||
see: rednet.receive To wait for a Rednet message with an optional timeout and protocol filter.
|
||||
---
|
||||
|
||||
The @{rednet_message} event is fired when a message is sent over Rednet.
|
||||
|
||||
This event is usually handled by @{rednet.receive}, but it can also be pulled manually.
|
||||
|
||||
@{rednet_message} events are sent by @{rednet.run} in the top-level coroutine in response to @{modem_message} events. A @{rednet_message} event is always preceded by a @{modem_message} event. They are generated inside CraftOS rather than being sent by the ComputerCraft machine.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The ID of the sending computer.
|
||||
3. @{any}: The message sent.
|
||||
4. @{string|nil}: The protocol of the message, if provided.
|
||||
|
||||
## Example
|
||||
Prints a message when one is sent:
|
||||
```lua
|
||||
while true do
|
||||
local event, sender, message, protocol = os.pullEvent("rednet_message")
|
||||
if protocol ~= nil then
|
||||
print("Received message from " .. sender .. " with protocol " .. protocol .. " and message " .. tostring(message))
|
||||
else
|
||||
print("Received message from " .. sender .. " with message " .. tostring(message))
|
||||
end
|
||||
end
|
||||
```
|
14
doc/events/redstone.md
Normal file
14
doc/events/redstone.md
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
module: [kind=event] redstone
|
||||
---
|
||||
|
||||
The @{redstone} event is fired whenever any redstone inputs on the computer change.
|
||||
|
||||
## Example
|
||||
Prints a message when a redstone input changes:
|
||||
```lua
|
||||
while true do
|
||||
os.pullEvent("redstone")
|
||||
print("A redstone input has changed!")
|
||||
end
|
||||
```
|
28
doc/events/task_complete.md
Normal file
28
doc/events/task_complete.md
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
module: [kind=event] task_complete
|
||||
see: commands.execAsync To run a command which fires a task_complete event.
|
||||
---
|
||||
|
||||
The @{task_complete} event is fired when an asynchronous task completes. This is usually handled inside the function call that queued the task; however, functions such as @{commands.execAsync} return immediately so the user can wait for completion.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The ID of the task that completed.
|
||||
3. @{boolean}: Whether the command succeeded.
|
||||
4. @{string}: If the command failed, an error message explaining the failure. (This is not present if the command succeeded.)
|
||||
...: Any parameters returned from the command.
|
||||
|
||||
## Example
|
||||
Prints the results of an asynchronous command:
|
||||
```lua
|
||||
local taskID = commands.execAsync("say Hello")
|
||||
local event
|
||||
repeat
|
||||
event = {os.pullEvent("task_complete")}
|
||||
until event[2] == taskID
|
||||
if event[3] == true then
|
||||
print("Task " .. event[2] .. " succeeded:", table.unpack(event, 4))
|
||||
else
|
||||
print("Task " .. event[2] .. " failed: " .. event[4])
|
||||
end
|
||||
```
|
15
doc/events/term_resize.md
Normal file
15
doc/events/term_resize.md
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
module: [kind=event] term_resize
|
||||
---
|
||||
|
||||
The @{term_resize} event is fired when the main terminal is resized, mainly when a new tab is opened or closed in @{multishell}.
|
||||
|
||||
## Example
|
||||
Prints :
|
||||
```lua
|
||||
while true do
|
||||
os.pullEvent("term_resize")
|
||||
local w, h = term.getSize()
|
||||
print("The term was resized to (" .. w .. ", " .. h .. ")")
|
||||
end
|
||||
```
|
25
doc/events/terminate.md
Normal file
25
doc/events/terminate.md
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
module: [kind=event] terminate
|
||||
---
|
||||
|
||||
The @{terminate} event is fired when <kbd>Ctrl-T</kbd> is held down.
|
||||
|
||||
This event is normally handled by @{os.pullEvent}, and will not be returned. However, @{os.pullEventRaw} will return this event when fired.
|
||||
|
||||
@{terminate} will be sent even when a filter is provided to @{os.pullEventRaw}. When using @{os.pullEventRaw} with a filter, make sure to check that the event is not @{terminate}.
|
||||
|
||||
## Example
|
||||
Prints a message when Ctrl-T is held:
|
||||
```lua
|
||||
while true do
|
||||
local event = os.pullEventRaw("terminate")
|
||||
if event == "terminate" then print("Terminate requested!") end
|
||||
end
|
||||
```
|
||||
|
||||
Exits when Ctrl-T is held:
|
||||
```lua
|
||||
while true do
|
||||
os.pullEvent()
|
||||
end
|
||||
```
|
21
doc/events/timer.md
Normal file
21
doc/events/timer.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
module: [kind=event] timer
|
||||
see: os.startTimer To start a timer.
|
||||
---
|
||||
|
||||
The @{timer} event is fired when a timer started with @{os.startTimer} completes.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The ID of the timer that finished.
|
||||
|
||||
## Example
|
||||
Starts a timer and then prints its ID:
|
||||
```lua
|
||||
local timerID = os.startTimer(2)
|
||||
local event, id
|
||||
repeat
|
||||
event, id = os.pullEvent("timer")
|
||||
until id == timerID
|
||||
print("Timer with ID " .. id .. " was fired")
|
||||
```
|
14
doc/events/turtle_inventory.md
Normal file
14
doc/events/turtle_inventory.md
Normal file
@ -0,0 +1,14 @@
|
||||
---
|
||||
module: [kind=event] turtle_inventory
|
||||
---
|
||||
|
||||
The @{turtle_inventory} event is fired when a turtle's inventory is changed.
|
||||
|
||||
## Example
|
||||
Prints a message when the inventory is changed:
|
||||
```lua
|
||||
while true do
|
||||
os.pullEvent("turtle_inventory")
|
||||
print("The inventory was changed.")
|
||||
end
|
||||
```
|
21
doc/events/websocket_closed.md
Normal file
21
doc/events/websocket_closed.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
module: [kind=event] websocket_closed
|
||||
---
|
||||
|
||||
The @{websocket_closed} event is fired when an open WebSocket connection is closed.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The URL of the WebSocket that was closed.
|
||||
|
||||
## Example
|
||||
Prints a message when a WebSocket is closed (this may take a minute):
|
||||
```lua
|
||||
local myURL = "wss://example.tweaked.cc/echo"
|
||||
local ws = http.websocket(myURL)
|
||||
local event, url
|
||||
repeat
|
||||
event, url = os.pullEvent("websocket_closed")
|
||||
until url == myURL
|
||||
print("The WebSocket at " .. url .. " was closed.")
|
||||
```
|
25
doc/events/websocket_failure.md
Normal file
25
doc/events/websocket_failure.md
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
module: [kind=event] websocket_failure
|
||||
see: http.websocketAsync To send an HTTP request.
|
||||
---
|
||||
|
||||
The @{websocket_failure} event is fired when a WebSocket connection request fails.
|
||||
|
||||
This event is normally handled inside @{http.websocket}, but it can still be seen when using @{http.websocketAsync}.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The URL of the site requested.
|
||||
3. @{string}: An error describing the failure.
|
||||
|
||||
## Example
|
||||
Prints an error why the website cannot be contacted:
|
||||
```lua
|
||||
local myURL = "wss://example.tweaked.cc/not-a-websocket"
|
||||
http.websocketAsync(myURL)
|
||||
local event, url, err
|
||||
repeat
|
||||
event, url, err = os.pullEvent("websocket_failure")
|
||||
until url == myURL
|
||||
print("The URL " .. url .. " could not be reached: " .. err)
|
||||
```
|
27
doc/events/websocket_message.md
Normal file
27
doc/events/websocket_message.md
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
module: [kind=event] websocket_message
|
||||
---
|
||||
|
||||
The @{websocket_message} event is fired when a message is received on an open WebSocket connection.
|
||||
|
||||
This event is normally handled by @{http.Websocket.receive}, but it can also be pulled manually.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The URL of the WebSocket.
|
||||
3. @{string}: The contents of the message.
|
||||
4. @{boolean}: Whether this is a binary message.
|
||||
|
||||
## Example
|
||||
Prints a message sent by a WebSocket:
|
||||
```lua
|
||||
local myURL = "wss://example.tweaked.cc/echo"
|
||||
local ws = http.websocket(myURL)
|
||||
ws.send("Hello!")
|
||||
local event, url, message
|
||||
repeat
|
||||
event, url, message = os.pullEvent("websocket_message")
|
||||
until url == myURL
|
||||
print("Received message from " .. url .. " with contents " .. message)
|
||||
ws.close()
|
||||
```
|
28
doc/events/websocket_success.md
Normal file
28
doc/events/websocket_success.md
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
module: [kind=event] websocket_success
|
||||
see: http.websocketAsync To open a WebSocket asynchronously.
|
||||
---
|
||||
|
||||
The @{websocket_success} event is fired when a WebSocket connection request returns successfully.
|
||||
|
||||
This event is normally handled inside @{http.websocket}, but it can still be seen when using @{http.websocketAsync}.
|
||||
|
||||
## Return Values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The URL of the site.
|
||||
3. @{http.Websocket}: The handle for the WebSocket.
|
||||
|
||||
## Example
|
||||
Prints the content of a website (this may fail if the request fails):
|
||||
```lua
|
||||
local myURL = "wss://example.tweaked.cc/echo"
|
||||
http.websocketAsync(myURL)
|
||||
local event, url, handle
|
||||
repeat
|
||||
event, url, handle = os.pullEvent("websocket_success")
|
||||
until url == myURL
|
||||
print("Connected to " .. url)
|
||||
handle.send("Hello!")
|
||||
print(handle.receive())
|
||||
handle.close()
|
||||
```
|
1
doc/head.html
Normal file
1
doc/head.html
Normal file
@ -0,0 +1 @@
|
||||
<meta name="theme-color" content="#c8d87c">
|
BIN
doc/images/basic-terminal.png
Normal file
BIN
doc/images/basic-terminal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 53 KiB |
BIN
doc/images/peripherals.png
Normal file
BIN
doc/images/peripherals.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 194 KiB |
BIN
doc/images/turtle.png
Normal file
BIN
doc/images/turtle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 163 KiB |
55
doc/index.md
Normal file
55
doc/index.md
Normal file
@ -0,0 +1,55 @@
|
||||
# 
|
||||
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 better performance, stability, and a wealth of new features.
|
||||
|
||||
CC: Tweaked can be installed from [CurseForge] or [Modrinth]. It requires the [Minecraft Forge][forge] mod loader, but
|
||||
[versions are available for Fabric][ccrestitched].
|
||||
|
||||
## Features
|
||||
Controlled using the [Lua programming language][lua], CC: Tweaked's computers provides all the tools you need to start
|
||||
writing code and automating your Minecraft world.
|
||||
|
||||
{.big-image}
|
||||
|
||||
While computers are incredibly powerful, they're rather limited by their inability to move about. *Turtles* are the
|
||||
solution here. They can move about the world, placing and breaking blocks, swinging a sword to protect you from zombies,
|
||||
or whatever else you program them to!
|
||||
|
||||
{.big-image}
|
||||
|
||||
Not all problems can be solved with a pickaxe though, and so CC: Tweaked also provides a bunch of additional peripherals
|
||||
for your computers. You can play a tune with speakers, display text or images on a monitor, connect all your
|
||||
computers together with modems, and much more.
|
||||
|
||||
Computers can now also interact with inventories such as chests, allowing you to build complex inventory and item
|
||||
management systems.
|
||||
|
||||
{.big-image}
|
||||
|
||||
## Getting Started
|
||||
While ComputerCraft is lovely for both experienced programmers and for people who have never coded before, it can be a
|
||||
little daunting getting started. Thankfully, there's several fantastic tutorials out there:
|
||||
|
||||
- [Direwolf20's ComputerCraft tutorials](https://www.youtube.com/watch?v=wrUHUhfCY5A "ComputerCraft Tutorial Episode 1 - HELP! and Hello World")
|
||||
- [Sethbling's ComputerCraft series](https://www.youtube.com/watch?v=DSsx4VSe-Uk "Programming Tutorial with Minecraft Turtles -- Ep. 1: Intro to Turtles and If-Then-Else_End")
|
||||
- [Lyqyd's Computer Basics 1](http://www.computercraft.info/forums2/index.php?/topic/15033-computer-basics-i/ "Computer Basics I")
|
||||
|
||||
Once you're a little more familiar with the mod, the sidebar and links below provide more detailed documentation on the
|
||||
various APIs and peripherals provided by the mod.
|
||||
|
||||
If you get stuck, do pop in to the [Minecraft Computer Mod Discord guild][discord] or ComputerCraft's
|
||||
[IRC channel][irc].
|
||||
|
||||
## Get Involved
|
||||
CC: Tweaked lives on [GitHub]. If you've got any ideas, feedback or bugs please do [create an issue][bug].
|
||||
|
||||
[github]: https://github.com/cc-tweaked/CC-Tweaked/ "CC: Tweaked on GitHub"
|
||||
[bug]: https://github.com/cc-tweaked/CC-Tweaked/issues/new/choose
|
||||
[computercraft]: https://github.com/dan200/ComputerCraft "ComputerCraft on GitHub"
|
||||
[curseforge]: https://minecraft.curseforge.com/projects/cc-tweaked "Download CC: Tweaked from CurseForge"
|
||||
[modrinth]: https://modrinth.com/mod/gu7yAYhd "Download CC: Tweaked from Modrinth"
|
||||
[forge]: https://files.minecraftforge.net/ "Download Minecraft Forge."
|
||||
[ccrestitched]: https://www.curseforge.com/minecraft/mc-mods/cc-restitched "Download CC: Restitched from CurseForge"
|
||||
[lua]: https://www.lua.org/ "Lua's main website"
|
||||
[discord]: https://discord.computercraft.cc "The Minecraft Computer Mods Discord"
|
||||
[irc]: http://webchat.esper.net/?channels=computercraft "IRC webchat on EsperNet"
|
BIN
doc/logo.png
Normal file
BIN
doc/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
36
doc/stub/fs.lua
Normal file
36
doc/stub/fs.lua
Normal file
@ -0,0 +1,36 @@
|
||||
--- The FS API allows you to manipulate files and the filesystem.
|
||||
--
|
||||
-- @module fs
|
||||
|
||||
--- Returns true if a path is mounted to the parent filesystem.
|
||||
--
|
||||
-- The root filesystem "/" is considered a mount, along with disk folders and
|
||||
-- the rom folder. Other programs (such as network shares) can exstend this to
|
||||
-- make other mount types by correctly assigning their return value for getDrive.
|
||||
--
|
||||
-- @tparam string path The path to check.
|
||||
-- @treturn boolean If the path is mounted, rather than a normal file/folder.
|
||||
-- @throws If the path does not exist.
|
||||
-- @see getDrive
|
||||
-- @since 1.87.0
|
||||
function isDriveRoot(path) end
|
||||
|
||||
--[[- Provides completion for a file or directory name, suitable for use with
|
||||
@{_G.read}.
|
||||
|
||||
When a directory is a possible candidate for completion, two entries are
|
||||
included - one with a trailing slash (indicating that entries within this
|
||||
directory exist) and one without it (meaning this entry is an immediate
|
||||
completion candidate). `include_dirs` can be set to @{false} to only include
|
||||
those with a trailing slash.
|
||||
|
||||
@tparam string path The path to complete.
|
||||
@tparam string location The location where paths are resolved from.
|
||||
@tparam[opt] boolean include_files When @{false}, only directories will be
|
||||
included in the returned list.
|
||||
@tparam[opt] boolean include_dirs When @{false}, "raw" directories will not be
|
||||
included in the returned list.
|
||||
@treturn { string... } A list of possible completion candidates.
|
||||
@since 1.74
|
||||
]]
|
||||
function complete(path, location, include_files, include_dirs) end
|
130
doc/stub/global.lua
Normal file
130
doc/stub/global.lua
Normal file
@ -0,0 +1,130 @@
|
||||
--[[-
|
||||
Functions in the global environment, defined in `bios.lua`. This does not
|
||||
include standard Lua functions.
|
||||
|
||||
@module _G
|
||||
]]
|
||||
|
||||
--[[- Pauses execution for the specified number of seconds.
|
||||
|
||||
As it waits for a fixed amount of world ticks, `time` will automatically be
|
||||
rounded up to the nearest multiple of 0.05 seconds. If you are using coroutines
|
||||
or the @{parallel|parallel API}, it will only pause execution of the current
|
||||
thread, not the whole program.
|
||||
|
||||
**Note** Because sleep internally uses timers, it is a function that yields.
|
||||
This means that you can use it to prevent "Too long without yielding" errors,
|
||||
however, as the minimum sleep time is 0.05 seconds, it will slow your program
|
||||
down.
|
||||
|
||||
**Warning** Internally, this function queues and waits for a timer event (using
|
||||
@{os.startTimer}), however it does not listen for any other events. This means
|
||||
that any event that occurs while sleeping will be entirely discarded. If you
|
||||
need to receive events while sleeping, consider using @{os.startTimer|timers},
|
||||
or the @{parallel|parallel API}.
|
||||
|
||||
@tparam number time The number of seconds to sleep for, rounded up to the
|
||||
nearest multiple of 0.05.
|
||||
|
||||
@see os.startTimer
|
||||
@usage Sleep for three seconds.
|
||||
|
||||
print("Sleeping for three seconds")
|
||||
sleep(3)
|
||||
print("Done!")
|
||||
]]
|
||||
function sleep(time) end
|
||||
|
||||
--- Writes a line of text to the screen without a newline at the end, wrapping
|
||||
-- text if necessary.
|
||||
--
|
||||
-- @tparam string text The text to write to the string
|
||||
-- @treturn number The number of lines written
|
||||
-- @see print A wrapper around write that adds a newline and accepts multiple arguments
|
||||
-- @usage write("Hello, world")
|
||||
function write(text) end
|
||||
|
||||
--- Prints the specified values to the screen separated by spaces, wrapping if
|
||||
-- necessary. After printing, the cursor is moved to the next line.
|
||||
--
|
||||
-- @param ... The values to print on the screen
|
||||
-- @treturn number The number of lines written
|
||||
-- @usage print("Hello, world!")
|
||||
function print(...) end
|
||||
|
||||
--- Prints the specified values to the screen in red, separated by spaces,
|
||||
-- wrapping if necessary. After printing, the cursor is moved to the next line.
|
||||
--
|
||||
-- @param ... The values to print on the screen
|
||||
-- @usage printError("Something went wrong!")
|
||||
function printError(...) end
|
||||
|
||||
--[[- Reads user input from the terminal, automatically handling arrow keys,
|
||||
pasting, character replacement, history scrollback, auto-completion, and
|
||||
default values.
|
||||
|
||||
@tparam[opt] string replaceChar A character to replace each typed character with.
|
||||
This can be used for hiding passwords, for example.
|
||||
@tparam[opt] table history A table holding history items that can be scrolled
|
||||
back to with the up/down arrow keys. The oldest item is at index 1, while the
|
||||
newest item is at the highest index.
|
||||
@tparam[opt] function(partial: string):({ string... }|nil) completeFn A function
|
||||
to be used for completion. This function should take the partial text typed so
|
||||
far, and returns a list of possible completion options.
|
||||
@tparam[opt] string default Default text which should already be entered into
|
||||
the prompt.
|
||||
|
||||
@treturn string The text typed in.
|
||||
|
||||
@see cc.completion For functions to help with completion.
|
||||
@usage Read a string and echo it back to the user
|
||||
|
||||
write("> ")
|
||||
local msg = read()
|
||||
print(msg)
|
||||
|
||||
@usage Prompt a user for a password.
|
||||
|
||||
while true do
|
||||
write("Password> ")
|
||||
local pwd = read("*")
|
||||
if pwd == "let me in" then break end
|
||||
print("Incorrect password, try again.")
|
||||
end
|
||||
print("Logged in!")
|
||||
|
||||
@usage A complete example with completion, history and a default value.
|
||||
|
||||
local completion = require "cc.completion"
|
||||
local history = { "potato", "orange", "apple" }
|
||||
local choices = { "apple", "orange", "banana", "strawberry" }
|
||||
write("> ")
|
||||
local msg = read(nil, history, function(text) return completion.choice(text, choices) end, "app")
|
||||
print(msg)
|
||||
|
||||
@changed 1.74 Added `completeFn` parameter.
|
||||
@changed 1.80pr1 Added `default` parameter.
|
||||
]]
|
||||
function read(replaceChar, history, completeFn, default) end
|
||||
|
||||
--- The ComputerCraft and Minecraft version of the current computer environment.
|
||||
--
|
||||
-- For example, `ComputerCraft 1.93.0 (Minecraft 1.15.2)`.
|
||||
-- @usage _HOST
|
||||
-- @since 1.76
|
||||
_HOST = _HOST
|
||||
|
||||
--[[- The default computer settings as defined in the ComputerCraft
|
||||
configuration.
|
||||
|
||||
This is a comma-separated list of settings pairs defined by the mod
|
||||
configuration or server owner. By default, it is empty.
|
||||
|
||||
An example value to disable autocompletion:
|
||||
|
||||
shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false
|
||||
|
||||
@usage _CC_DEFAULT_SETTINGS
|
||||
@since 1.77
|
||||
]]
|
||||
_CC_DEFAULT_SETTINGS = _CC_DEFAULT_SETTINGS
|
181
doc/stub/http.lua
Normal file
181
doc/stub/http.lua
Normal file
@ -0,0 +1,181 @@
|
||||
--- The http library allows communicating with web servers, sending and
|
||||
-- receiving data from them.
|
||||
--
|
||||
-- @module http
|
||||
-- @since 1.1
|
||||
|
||||
--- Asynchronously make a HTTP request to the given url.
|
||||
--
|
||||
-- This returns immediately, a [`http_success`](#http-success-event) or
|
||||
-- [`http_failure`](#http-failure-event) will be queued once the request has
|
||||
-- completed.
|
||||
--
|
||||
-- @tparam string url The url to request
|
||||
-- @tparam[opt] string body An optional string containing the body of the
|
||||
-- request. If specified, a `POST` request will be made instead.
|
||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
-- of this request.
|
||||
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
|
||||
-- the body will not be UTF-8 encoded, and the received response will not be
|
||||
-- decoded.
|
||||
--
|
||||
-- @tparam[2] {
|
||||
-- url = string, body? = string, headers? = { [string] = string },
|
||||
-- binary? = boolean, method? = string, redirect? = boolean,
|
||||
-- } request Options for the request.
|
||||
--
|
||||
-- This table form is an expanded version of the previous syntax. All arguments
|
||||
-- from above are passed in as fields instead (for instance,
|
||||
-- `http.request("https://example.com")` becomes `http.request { url =
|
||||
-- "https://example.com" }`).
|
||||
--
|
||||
-- This table also accepts several additional options:
|
||||
--
|
||||
-- - `method`: Which HTTP method to use, for instance `"PATCH"` or `"DELETE"`.
|
||||
-- - `redirect`: Whether to follow HTTP redirects. Defaults to true.
|
||||
--
|
||||
-- @see http.get For a synchronous way to make GET requests.
|
||||
-- @see http.post For a synchronous way to make POST requests.
|
||||
--
|
||||
-- @changed 1.63 Added argument for headers.
|
||||
-- @changed 1.80pr1 Added argument for binary handles.
|
||||
-- @changed 1.80pr1.6 Added support for table argument.
|
||||
-- @changed 1.86.0 Added PATCH and TRACE methods.
|
||||
function request(...) end
|
||||
|
||||
--- Make a HTTP GET request to the given url.
|
||||
--
|
||||
-- @tparam string url The url to request
|
||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
-- of this request.
|
||||
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
|
||||
-- the body will not be UTF-8 encoded, and the received response will not be
|
||||
-- decoded.
|
||||
--
|
||||
-- @tparam[2] {
|
||||
-- url = string, headers? = { [string] = string },
|
||||
-- binary? = boolean, method? = string, redirect? = boolean,
|
||||
-- } request Options for the request. See @{http.request} for details on how
|
||||
-- these options behave.
|
||||
--
|
||||
-- @treturn Response The resulting http response, which can be read from.
|
||||
-- @treturn[2] nil When the http request failed, such as in the event of a 404
|
||||
-- error or connection timeout.
|
||||
-- @treturn string A message detailing why the request failed.
|
||||
-- @treturn Response|nil The failing http response, if available.
|
||||
--
|
||||
-- @changed 1.63 Added argument for headers.
|
||||
-- @changed 1.80pr1 Response handles are now returned on error if available.
|
||||
-- @changed 1.80pr1 Added argument for binary handles.
|
||||
-- @changed 1.80pr1.6 Added support for table argument.
|
||||
-- @changed 1.86.0 Added PATCH and TRACE methods.
|
||||
--
|
||||
-- @usage Make a request to [example.tweaked.cc](https://example.tweaked.cc),
|
||||
-- and print the returned page.
|
||||
-- ```lua
|
||||
-- local request = http.get("https://example.tweaked.cc")
|
||||
-- print(request.readAll())
|
||||
-- -- => HTTP is working!
|
||||
-- request.close()
|
||||
-- ```
|
||||
function get(...) end
|
||||
|
||||
--- Make a HTTP POST request to the given url.
|
||||
--
|
||||
-- @tparam string url The url to request
|
||||
-- @tparam string body The body of the POST request.
|
||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
-- of this request.
|
||||
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
|
||||
-- the body will not be UTF-8 encoded, and the received response will not be
|
||||
-- decoded.
|
||||
--
|
||||
-- @tparam[2] {
|
||||
-- url = string, body? = string, headers? = { [string] = string },
|
||||
-- binary? = boolean, method? = string, redirect? = boolean,
|
||||
-- } request Options for the request. See @{http.request} for details on how
|
||||
-- these options behave.
|
||||
--
|
||||
-- @treturn Response The resulting http response, which can be read from.
|
||||
-- @treturn[2] nil When the http request failed, such as in the event of a 404
|
||||
-- error or connection timeout.
|
||||
-- @treturn string A message detailing why the request failed.
|
||||
-- @treturn Response|nil The failing http response, if available.
|
||||
--
|
||||
-- @since 1.31
|
||||
-- @changed 1.63 Added argument for headers.
|
||||
-- @changed 1.80pr1 Response handles are now returned on error if available.
|
||||
-- @changed 1.80pr1 Added argument for binary handles.
|
||||
-- @changed 1.80pr1.6 Added support for table argument.
|
||||
-- @changed 1.86.0 Added PATCH and TRACE methods.
|
||||
function post(...) end
|
||||
|
||||
--- Asynchronously determine whether a URL can be requested.
|
||||
--
|
||||
-- If this returns `true`, one should also listen for [`http_check`
|
||||
-- events](#http-check-event) which will container further information about
|
||||
-- whether the URL is allowed or not.
|
||||
--
|
||||
-- @tparam string url The URL to check.
|
||||
-- @treturn true When this url is not invalid. This does not imply that it is
|
||||
-- allowed - see the comment above.
|
||||
-- @treturn[2] false When this url is invalid.
|
||||
-- @treturn string A reason why this URL is not valid (for instance, if it is
|
||||
-- malformed, or blocked).
|
||||
--
|
||||
-- @see http.checkURL For a synchronous version.
|
||||
function checkURLAsync(url) end
|
||||
|
||||
--- Determine whether a URL can be requested.
|
||||
--
|
||||
-- If this returns `true`, one should also listen for [`http_check`
|
||||
-- events](#http-check-event) which will container further information about
|
||||
-- whether the URL is allowed or not.
|
||||
--
|
||||
-- @tparam string url The URL to check.
|
||||
-- @treturn true When this url is valid and can be requested via @{http.request}.
|
||||
-- @treturn[2] false When this url is invalid.
|
||||
-- @treturn string A reason why this URL is not valid (for instance, if it is
|
||||
-- malformed, or blocked).
|
||||
--
|
||||
-- @see http.checkURLAsync For an asynchronous version.
|
||||
--
|
||||
-- @usage
|
||||
-- ```lua
|
||||
-- print(http.checkURL("https://example.tweaked.cc/"))
|
||||
-- -- => true
|
||||
-- print(http.checkURL("http://localhost/"))
|
||||
-- -- => false Domain not permitted
|
||||
-- print(http.checkURL("not a url"))
|
||||
-- -- => false URL malformed
|
||||
-- ```
|
||||
function checkURL(url) end
|
||||
|
||||
--- Open a websocket.
|
||||
--
|
||||
-- @tparam string url The websocket url to connect to. This should have the
|
||||
-- `ws://` or `wss://` protocol.
|
||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
-- of the initial websocket connection.
|
||||
--
|
||||
-- @treturn Websocket The websocket connection.
|
||||
-- @treturn[2] false If the websocket connection failed.
|
||||
-- @treturn string An error message describing why the connection failed.
|
||||
-- @since 1.80pr1.1
|
||||
-- @changed 1.80pr1.3 No longer asynchronous.
|
||||
-- @changed 1.95.3 Added User-Agent to default headers.
|
||||
function websocket(url, headers) end
|
||||
|
||||
--- Asynchronously open a websocket.
|
||||
--
|
||||
-- This returns immediately, a [`websocket_success`](#websocket-success-event)
|
||||
-- or [`websocket_failure`](#websocket-failure-event) will be queued once the
|
||||
-- request has completed.
|
||||
--
|
||||
-- @tparam string url The websocket url to connect to. This should have the
|
||||
-- `ws://` or `wss://` protocol.
|
||||
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||
-- of the initial websocket connection.
|
||||
-- @since 1.80pr1.3
|
||||
-- @changed 1.95.3 Added User-Agent to default headers.
|
||||
function websocketAsync(url, headers) end
|
128
doc/stub/os.lua
Normal file
128
doc/stub/os.lua
Normal file
@ -0,0 +1,128 @@
|
||||
-- Defined in bios.lua
|
||||
|
||||
--[[- Loads the given API into the global environment.
|
||||
|
||||
This function loads and executes the file at the given path, and all global
|
||||
variables and functions exported by it will by available through the use of
|
||||
`myAPI.<function name>`, where `myAPI` is the base name of the API file.
|
||||
|
||||
@tparam string path The path of the API to load.
|
||||
@treturn boolean Whether or not the API was successfully loaded.
|
||||
@since 1.2
|
||||
|
||||
@deprecated When possible it's best to avoid using this function. It pollutes
|
||||
the global table and can mask errors.
|
||||
|
||||
@{require} should be used to load libraries instead.
|
||||
]]
|
||||
function loadAPI(path) end
|
||||
|
||||
--- Unloads an API which was loaded by @{os.loadAPI}.
|
||||
--
|
||||
-- This effectively removes the specified table from `_G`.
|
||||
--
|
||||
-- @tparam string name The name of the API to unload.
|
||||
-- @since 1.2
|
||||
-- @deprecated See @{os.loadAPI} for why.
|
||||
function unloadAPI(name) end
|
||||
|
||||
--[[- Pause execution of the current thread and waits for any events matching
|
||||
`filter`.
|
||||
|
||||
This function @{coroutine.yield|yields} the current process and waits for it
|
||||
to be resumed with a vararg list where the first element matches `filter`.
|
||||
If no `filter` is supplied, this will match all events.
|
||||
|
||||
Unlike @{os.pullEventRaw}, it will stop the application upon a "terminate"
|
||||
event, printing the error "Terminated".
|
||||
|
||||
@tparam[opt] string filter Event to filter for.
|
||||
@treturn string event The name of the event that fired.
|
||||
@treturn any param... Optional additional parameters of the event.
|
||||
@usage Listen for `mouse_click` events.
|
||||
|
||||
while true do
|
||||
local event, button, x, y = os.pullEvent("mouse_click")
|
||||
print("Button", button, "was clicked at", x, ",", y)
|
||||
end
|
||||
|
||||
@usage Listen for multiple events.
|
||||
|
||||
while true do
|
||||
local eventData = {os.pullEvent()}
|
||||
local event = eventData[1]
|
||||
|
||||
if event == "mouse_click" then
|
||||
print("Button", eventData[2], "was clicked at", eventData[3], ",", eventData[4])
|
||||
elseif event == "key" then
|
||||
print("Key code", eventData[2], "was pressed")
|
||||
end
|
||||
end
|
||||
|
||||
@see os.pullEventRaw To pull the terminate event.
|
||||
@changed 1.3 Added filter argument.
|
||||
]]
|
||||
function pullEvent(filter) end
|
||||
|
||||
--[[- Pause execution of the current thread and waits for events, including the
|
||||
`terminate` event.
|
||||
|
||||
This behaves almost the same as @{os.pullEvent}, except it allows you to handle
|
||||
the `terminate` event yourself - the program will not stop execution when
|
||||
<kbd>Ctrl+T</kbd> is pressed.
|
||||
|
||||
@tparam[opt] string filter Event to filter for.
|
||||
@treturn string event The name of the event that fired.
|
||||
@treturn any param... Optional additional parameters of the event.
|
||||
@usage Listen for `terminate` events.
|
||||
|
||||
while true do
|
||||
local event = os.pullEventRaw()
|
||||
if event == "terminate" then
|
||||
print("Caught terminate event!")
|
||||
end
|
||||
end
|
||||
|
||||
@see os.pullEvent To pull events normally.
|
||||
]]
|
||||
function pullEventRaw(filter) end
|
||||
|
||||
--- Pauses execution for the specified number of seconds, alias of @{_G.sleep}.
|
||||
--
|
||||
-- @tparam number time The number of seconds to sleep for, rounded up to the
|
||||
-- nearest multiple of 0.05.
|
||||
function sleep(time) end
|
||||
|
||||
--- Get the current CraftOS version (for example, `CraftOS 1.8`).
|
||||
--
|
||||
-- This is defined by `bios.lua`. For the current version of CC:Tweaked, this
|
||||
-- should return `CraftOS 1.8`.
|
||||
--
|
||||
-- @treturn string The current CraftOS version.
|
||||
-- @usage os.version()
|
||||
function version() end
|
||||
|
||||
--[[- Run the program at the given path with the specified environment and
|
||||
arguments.
|
||||
|
||||
This function does not resolve program names like the shell does. This means
|
||||
that, for example, `os.run("edit")` will not work. As well as this, it does not
|
||||
provide access to the @{shell} API in the environment. For this behaviour, use
|
||||
@{shell.run} instead.
|
||||
|
||||
If the program cannot be found, or failed to run, it will print the error and
|
||||
return `false`. If you want to handle this more gracefully, use an alternative
|
||||
such as @{loadfile}.
|
||||
|
||||
@tparam table env The environment to run the program with.
|
||||
@tparam string path The exact path of the program to run.
|
||||
@param ... The arguments to pass to the program.
|
||||
@treturn boolean Whether or not the program ran successfully.
|
||||
@usage Run the default shell from within your program:
|
||||
|
||||
os.run({}, "/rom/programs/shell.lua")
|
||||
|
||||
@see shell.run
|
||||
@see loadfile
|
||||
]]
|
||||
function run(env, path, ...) end
|
14
doc/stub/turtle.lua
Normal file
14
doc/stub/turtle.lua
Normal file
@ -0,0 +1,14 @@
|
||||
--[[- Craft a recipe based on the turtle's inventory.
|
||||
|
||||
The turtle's inventory should set up like a crafting grid. For instance, to
|
||||
craft sticks, slots 1 and 5 should contain planks. _All_ other slots should be
|
||||
empty, including those outside the crafting "grid".
|
||||
|
||||
@tparam[opt=64] number limit The maximum number of crafting steps to run.
|
||||
@throws When limit is less than 1 or greater than 64.
|
||||
@treturn[1] true If crafting succeeds.
|
||||
@treturn[2] false If crafting fails.
|
||||
@treturn string A string describing why crafting failed.
|
||||
@since 1.4
|
||||
]]
|
||||
function craft(limit) end
|
@ -6,12 +6,10 @@ mod_version=1.97.2
|
||||
|
||||
# Minecraft properties
|
||||
mc_version=1.17.1
|
||||
mappings_version=61
|
||||
|
||||
# Dependencies
|
||||
cloth_config_version=5.0.34
|
||||
fabric_loader_version=0.11.7
|
||||
fabric_api_version=0.40.1+1.17
|
||||
fabric_loader_version=0.12.0
|
||||
|
||||
cloth_api_version=2.0.54
|
||||
cloth_config_version=5.0.34
|
||||
jankson_version=1.2.0
|
||||
modmenu_version=2.0.2
|
||||
cloth_api_version=2.0.54
|
||||
|
115
illuaminate.sexp
Normal file
115
illuaminate.sexp
Normal file
@ -0,0 +1,115 @@
|
||||
; -*- mode: Lisp;-*-
|
||||
|
||||
(sources
|
||||
/doc/stub/
|
||||
/doc/events/
|
||||
/build/docs/luaJavadoc/
|
||||
/src/main/resources/*/computercraft/lua/bios.lua
|
||||
/src/main/resources/*/computercraft/lua/rom/
|
||||
/src/test/resources/test-rom
|
||||
/src/web/mount)
|
||||
|
||||
|
||||
(doc
|
||||
(destination build/docs/lua)
|
||||
(index doc/index.md)
|
||||
|
||||
(site
|
||||
(title "CC: Tweaked")
|
||||
(logo src/main/resources/pack.png)
|
||||
(url https://tweaked.cc/)
|
||||
(source-link https://github.com/cc-tweaked/CC-Tweaked/blob/${commit}/${path}#L${line})
|
||||
|
||||
(styles src/web/styles.css)
|
||||
(scripts build/rollup/index.js)
|
||||
(head doc/head.html))
|
||||
|
||||
(module-kinds
|
||||
(peripheral Peripherals)
|
||||
(generic_peripheral "Generic Peripherals")
|
||||
(event Events))
|
||||
|
||||
(library-path
|
||||
/doc/stub/
|
||||
/build/docs/luaJavadoc/
|
||||
|
||||
/src/main/resources/*/computercraft/lua/rom/apis/
|
||||
/src/main/resources/*/computercraft/lua/rom/apis/command/
|
||||
/src/main/resources/*/computercraft/lua/rom/apis/turtle/
|
||||
|
||||
/src/main/resources/*/computercraft/lua/rom/modules/main/
|
||||
/src/main/resources/*/computercraft/lua/rom/modules/command/
|
||||
/src/main/resources/*/computercraft/lua/rom/modules/turtle/))
|
||||
|
||||
(at /
|
||||
(linters
|
||||
syntax:string-index
|
||||
|
||||
;; It'd be nice to avoid this, but right now there's a lot of instances of
|
||||
;; it.
|
||||
-var:set-loop
|
||||
|
||||
;; It's useful to name arguments for documentation, so we allow this. It'd
|
||||
;; be good to find a compromise in the future, but this works for now.
|
||||
-var:unused-arg)
|
||||
|
||||
(lint
|
||||
(bracket-spaces
|
||||
(call no-space)
|
||||
(function-args no-space)
|
||||
(parens no-space)
|
||||
(table space)
|
||||
(index no-space))
|
||||
|
||||
(allow-clarifying-parens true)
|
||||
|
||||
;; colours imports from colors, and we don't handle that right now.
|
||||
;; keys is entirely dynamic, so we skip it.
|
||||
(dynamic-modules colours keys _G)
|
||||
|
||||
(globals
|
||||
:max
|
||||
_CC_DEFAULT_SETTINGS
|
||||
_CC_DISABLE_LUA51_FEATURES
|
||||
_HOST
|
||||
;; Ideally we'd pick these up from bios.lua, but illuaminate currently
|
||||
;; isn't smart enough.
|
||||
sleep write printError read rs)))
|
||||
|
||||
;; We disable the unused global linter in bios.lua and the APIs. In the future
|
||||
;; hopefully we'll get illuaminate to handle this.
|
||||
(at
|
||||
(/src/main/resources/*/computercraft/lua/bios.lua
|
||||
/src/main/resources/*/computercraft/lua/rom/apis/)
|
||||
(linters -var:unused-global)
|
||||
(lint (allow-toplevel-global true)))
|
||||
|
||||
;; Silence some variable warnings in documentation stubs.
|
||||
(at (/doc/stub/ /build/docs/luaJavadoc/)
|
||||
(linters -var:unused-global)
|
||||
(lint (allow-toplevel-global true)))
|
||||
|
||||
;; Suppress warnings for currently undocumented modules.
|
||||
(at
|
||||
(; Lua APIs
|
||||
/src/main/resources/*/computercraft/lua/rom/apis/io.lua
|
||||
/src/main/resources/*/computercraft/lua/rom/apis/window.lua)
|
||||
|
||||
(linters -doc:undocumented -doc:undocumented-arg -doc:undocumented-return))
|
||||
|
||||
;; Suppress warnings for various APIs using its own deprecated members.
|
||||
(at
|
||||
(/src/main/resources/*/computercraft/lua/bios.lua
|
||||
/src/main/resources/*/computercraft/lua/rom/apis/turtle/turtle.lua)
|
||||
(linters -var:deprecated))
|
||||
|
||||
(at /src/test/resources/test-rom
|
||||
; We should still be able to test deprecated members.
|
||||
(linters -var:deprecated)
|
||||
|
||||
(lint
|
||||
(globals
|
||||
:max sleep write
|
||||
cct_test describe expect howlci fail it pending stub)))
|
||||
|
||||
(at /src/web/mount/expr_template.lua (lint (globals :max __expr__)))
|
@ -6,7 +6,6 @@
|
||||
|
||||
package dan200.computercraft;
|
||||
|
||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
||||
import dan200.computercraft.core.apis.http.options.Action;
|
||||
import dan200.computercraft.core.apis.http.options.AddressRule;
|
||||
import dan200.computercraft.shared.ComputerCraftRegistry.ModBlocks;
|
||||
@ -31,16 +30,15 @@ import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
|
||||
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -91,7 +89,6 @@ public final class ComputerCraft implements ModInitializer
|
||||
public static int advancedTurtleFuelLimit = 100000;
|
||||
public static boolean turtlesObeyBlockProtection = true;
|
||||
public static boolean turtlesCanPush = true;
|
||||
public static EnumSet<TurtleAction> turtleDisabledActions = EnumSet.noneOf( TurtleAction.class );
|
||||
|
||||
public static int computerTermWidth = 51;
|
||||
public static int computerTermHeight = 19;
|
||||
@ -111,30 +108,30 @@ public final class ComputerCraft implements ModInitializer
|
||||
// Logging
|
||||
public static final Logger log = LogManager.getLogger( MOD_ID );
|
||||
|
||||
public static ItemGroup MAIN_GROUP = FabricItemGroupBuilder.build( new Identifier( MOD_ID, "main" ), () -> new ItemStack( ModBlocks.COMPUTER_NORMAL ) );
|
||||
public static CreativeModeTab MAIN_GROUP = FabricItemGroupBuilder.build( new ResourceLocation( MOD_ID, "main" ), () -> new ItemStack( ModBlocks.COMPUTER_NORMAL ) );
|
||||
|
||||
@Override
|
||||
public void onInitialize()
|
||||
{
|
||||
ComputerCraftProxyCommon.init();
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "colour" ), ColourableRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "computer_upgrade" ), ComputerUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "colour" ), ColourableRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "computer_upgrade" ), ComputerUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER,
|
||||
new Identifier( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ),
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, "pocket_computer_upgrade" ),
|
||||
PocketComputerUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "disk" ), DiskRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "printout" ), PrintoutRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle" ), TurtleRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "turtle_upgrade" ), TurtleUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shaped" ), ImpostorRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new Identifier( ComputerCraft.MOD_ID, "impostor_shapeless" ), ImpostorShapelessRecipe.SERIALIZER );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new Identifier( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.TYPE );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "disk" ), DiskRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "printout" ), PrintoutRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ), TurtleRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "turtle_upgrade" ), TurtleUpgradeRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shaped" ), ImpostorRecipe.SERIALIZER );
|
||||
Registry.register( Registry.RECIPE_SERIALIZER, new ResourceLocation( ComputerCraft.MOD_ID, "impostor_shapeless" ), ImpostorShapelessRecipe.SERIALIZER );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "block_named" ), BlockNamedEntityLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "player_creative" ), PlayerCreativeLootCondition.TYPE );
|
||||
Registry.register( Registry.LOOT_CONDITION_TYPE, new ResourceLocation( ComputerCraft.MOD_ID, "has_id" ), HasComputerIdLootCondition.TYPE );
|
||||
init();
|
||||
FabricLoader.getInstance().getModContainer( MOD_ID ).ifPresent( modContainer -> {
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "classic" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new Identifier( MOD_ID, "overhaul" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new ResourceLocation( MOD_ID, "classic" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
ResourceManagerHelper.registerBuiltinResourcePack( new ResourceLocation( MOD_ID, "overhaul" ), modContainer, ResourcePackActivationType.NORMAL );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ import dan200.computercraft.shared.util.IDAssigner;
|
||||
import dan200.computercraft.shared.wired.WiredNode;
|
||||
import me.shedaniel.cloth.api.utils.v1.GameInstanceUtils;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.resource.ReloadableResourceManager;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -62,10 +62,10 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
MinecraftServer server = GameInstanceUtils.getServer();
|
||||
if( server != null )
|
||||
{
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).getServerResourceManager().getResourceManager();
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).callGetResourceManager();
|
||||
try
|
||||
{
|
||||
return manager.getResource( new Identifier( domain, subPath ) )
|
||||
return manager.getResource( new ResourceLocation( domain, subPath ) )
|
||||
.getInputStream();
|
||||
}
|
||||
catch( IOException ignored )
|
||||
@ -93,13 +93,13 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||
public int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath )
|
||||
{
|
||||
return IDAssigner.getNextId( parentSubPath );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
||||
public IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity )
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -117,7 +117,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
MinecraftServer server = GameInstanceUtils.getServer();
|
||||
if( server != null )
|
||||
{
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).getServerResourceManager().getResourceManager();
|
||||
ReloadableResourceManager manager = (ReloadableResourceManager) ((MinecraftServerAccess) server).callGetResourceManager();
|
||||
ResourceMount mount = ResourceMount.get( domain, subPath, manager );
|
||||
return mount.exists( "" ) ? mount : null;
|
||||
}
|
||||
@ -143,7 +143,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return BundledRedstone.getDefaultOutput( world, pos, side );
|
||||
}
|
||||
@ -188,7 +188,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
BlockEntity tile = world.getBlockEntity( pos );
|
||||
if( tile instanceof TileCable )
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api;
|
||||
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
@ -21,10 +20,10 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -32,19 +31,11 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* The static entry point to the ComputerCraft API.
|
||||
*
|
||||
* Members in this class must be called after mod_ComputerCraft has been initialised, but may be called before it is fully loaded.
|
||||
* Members in this class must be called after mod_ComputerCraft has been initialised, but may be called before it is
|
||||
* fully loaded.
|
||||
*/
|
||||
public final class ComputerCraftAPI
|
||||
{
|
||||
private static IComputerCraftAPI instance;
|
||||
|
||||
@Nonnull
|
||||
@Deprecated
|
||||
public static String getAPIVersion()
|
||||
{
|
||||
return getInstalledVersion();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static String getInstalledVersion()
|
||||
{
|
||||
@ -52,23 +43,10 @@ public final class ComputerCraftAPI
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static IComputerCraftAPI getInstance()
|
||||
@Deprecated
|
||||
public static String getAPIVersion()
|
||||
{
|
||||
if( instance != null )
|
||||
{
|
||||
return instance;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return instance = (IComputerCraftAPI) Class.forName( "dan200.computercraft.ComputerCraftAPIImpl" )
|
||||
.getField( "INSTANCE" )
|
||||
.get( null );
|
||||
}
|
||||
catch( ReflectiveOperationException e )
|
||||
{
|
||||
throw new IllegalStateException( "Cannot find ComputerCraft API", e );
|
||||
}
|
||||
return getInstalledVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,10 +58,11 @@ public final class ComputerCraftAPI
|
||||
* @param parentSubPath The folder path within the save directory where the new directory should be created. eg: "computercraft/disk"
|
||||
* @return The numerical value of the name of the new folder, or -1 if the folder could not be created for some reason.
|
||||
*
|
||||
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now available for writing.
|
||||
* @see #createSaveDirMount(World, String, long)
|
||||
* eg: if createUniqueNumberedSaveDir( world, "computer/disk" ) was called returns 42, then "computer/disk/42" is now
|
||||
* available for writing.
|
||||
* @see #createSaveDirMount(Level, String, long)
|
||||
*/
|
||||
public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||
public static int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath )
|
||||
{
|
||||
return getInstance().createUniqueNumberedSaveDir( world, parentSubPath );
|
||||
}
|
||||
@ -91,23 +70,23 @@ public final class ComputerCraftAPI
|
||||
/**
|
||||
* Creates a file system mount that maps to a subfolder of the save directory for a given world, and returns it.
|
||||
*
|
||||
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the users save directory onto a computers
|
||||
* file system.
|
||||
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a folder from the
|
||||
* users save directory onto a computers file system.
|
||||
*
|
||||
* @param world The world for which the save dir can be found. This should be the server side world object.
|
||||
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42". Use createUniqueNumberedSaveDir()
|
||||
* to create a new numbered folder to use.
|
||||
* @param subPath The folder path within the save directory that the mount should map to. eg: "computer/disk/42".
|
||||
* Use createUniqueNumberedSaveDir() to create a new numbered folder to use.
|
||||
* @param capacity The amount of data that can be stored in the directory before it fills up, in bytes.
|
||||
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable() to mount this on a
|
||||
* Computers' file system.
|
||||
* @see #createUniqueNumberedSaveDir(World, String)
|
||||
* @return The mount, or null if it could be created for some reason. Use IComputerAccess.mount() or IComputerAccess.mountWritable()
|
||||
* to mount this on a Computers' file system.
|
||||
* @see #createUniqueNumberedSaveDir(Level, String)
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||
* @see IMount
|
||||
* @see IWritableMount
|
||||
*/
|
||||
@Nullable
|
||||
public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
||||
public static IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity )
|
||||
{
|
||||
return getInstance().createSaveDirMount( world, subPath, capacity );
|
||||
}
|
||||
@ -115,8 +94,8 @@ public final class ComputerCraftAPI
|
||||
/**
|
||||
* Creates a file system mount to a resource folder, and returns it.
|
||||
*
|
||||
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a resource folder onto a computer's file
|
||||
* system.
|
||||
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
|
||||
* resource folder onto a computer's file system.
|
||||
*
|
||||
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
|
||||
* resources with the same domain and path. For instance, ComputerCraft's resources are stored in
|
||||
@ -137,7 +116,7 @@ public final class ComputerCraftAPI
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
|
||||
* rers a peripheral provider to convert blocks into {@link IPeripheral} implementations.
|
||||
*
|
||||
* @param provider The peripheral provider to register.
|
||||
* @see IPeripheral
|
||||
@ -160,8 +139,9 @@ public final class ComputerCraftAPI
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new turtle turtle for use in ComputerCraft. After calling this, users should be able to craft Turtles with your new turtle. It is
|
||||
* recommended to call this during the load() method of your mod.
|
||||
* Registers a new turtle turtle for use in ComputerCraft. After calling this,
|
||||
* users should be able to craft Turtles with your new turtle. It is recommended to call
|
||||
* this during the load() method of your mod.
|
||||
*
|
||||
* @param upgrade The turtle upgrade to register.
|
||||
* @see ITurtleUpgrade
|
||||
@ -188,11 +168,11 @@ public final class ComputerCraftAPI
|
||||
* @param world The world this block is in.
|
||||
* @param pos The position this block is at.
|
||||
* @param side The side to extract the bundled redstone output from.
|
||||
* @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. If there is no block
|
||||
* capable of emitting bundled redstone at the location, -1 will be returned.
|
||||
* @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned.
|
||||
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
|
||||
* @see IBundledRedstoneProvider
|
||||
*/
|
||||
public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public static int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return getInstance().getBundledRedstoneOutput( world, pos, side );
|
||||
}
|
||||
@ -251,20 +231,38 @@ public final class ComputerCraftAPI
|
||||
* @see IWiredElement#getNode()
|
||||
*/
|
||||
@Nullable
|
||||
public static IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
public static IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return getInstance().getWiredElementAt( world, pos, side );
|
||||
}
|
||||
|
||||
private static IComputerCraftAPI instance;
|
||||
|
||||
@Nonnull
|
||||
private static IComputerCraftAPI getInstance()
|
||||
{
|
||||
if( instance != null ) return instance;
|
||||
|
||||
try
|
||||
{
|
||||
return instance = (IComputerCraftAPI) Class.forName( "dan200.computercraft.ComputerCraftAPIImpl" )
|
||||
.getField( "INSTANCE" ).get( null );
|
||||
}
|
||||
catch( ReflectiveOperationException e )
|
||||
{
|
||||
throw new IllegalStateException( "Cannot find ComputerCraft API", e );
|
||||
}
|
||||
}
|
||||
|
||||
public interface IComputerCraftAPI
|
||||
{
|
||||
@Nonnull
|
||||
String getInstalledVersion();
|
||||
|
||||
int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath );
|
||||
int createUniqueNumberedSaveDir( @Nonnull Level world, @Nonnull String parentSubPath );
|
||||
|
||||
@Nullable
|
||||
IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity );
|
||||
IWritableMount createSaveDirMount( @Nonnull Level world, @Nonnull String subPath, long capacity );
|
||||
|
||||
@Nullable
|
||||
IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath );
|
||||
@ -277,7 +275,7 @@ public final class ComputerCraftAPI
|
||||
|
||||
void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
|
||||
|
||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
|
||||
void registerMediaProvider( @Nonnull IMediaProvider provider );
|
||||
|
||||
@ -292,6 +290,6 @@ public final class ComputerCraftAPI
|
||||
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
|
||||
|
||||
@Nullable
|
||||
IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
IWiredElement getWiredElementAt( @Nonnull BlockGetter world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ package dan200.computercraft.api;
|
||||
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -28,7 +28,7 @@ public interface IUpgradeBase
|
||||
* @return The unique ID for this upgrade.
|
||||
*/
|
||||
@Nonnull
|
||||
Identifier getUpgradeID();
|
||||
ResourceLocation getUpgradeID();
|
||||
|
||||
/**
|
||||
* Return an unlocalised string to describe this type of computer in item names.
|
||||
@ -67,8 +67,6 @@ public interface IUpgradeBase
|
||||
* @param stack The stack to check. This is guaranteed to be non-empty and have the same item as
|
||||
* {@link #getCraftingItem()}.
|
||||
* @return If this stack may be used to equip this upgrade.
|
||||
* @see net.minecraftforge.common.crafting.NBTIngredient#test(ItemStack) For the implementation of the default
|
||||
* check.
|
||||
*/
|
||||
default boolean isItemSuitable( @Nonnull ItemStack stack )
|
||||
{
|
||||
@ -76,8 +74,8 @@ public interface IUpgradeBase
|
||||
|
||||
// A more expanded form of ItemStack.areShareTagsEqual, but allowing an empty tag to be equal to a
|
||||
// null one.
|
||||
NbtCompound shareTag = stack.getNbt();
|
||||
NbtCompound craftingShareTag = crafting.getNbt();
|
||||
CompoundTag shareTag = stack.getTag();
|
||||
CompoundTag craftingShareTag = crafting.getTag();
|
||||
if( shareTag == craftingShareTag ) return true;
|
||||
if( shareTag == null ) return craftingShareTag.isEmpty();
|
||||
if( craftingShareTag == null ) return shareTag.isEmpty();
|
||||
|
@ -6,16 +6,16 @@
|
||||
|
||||
package dan200.computercraft.api.client;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.render.model.BakedModelManager;
|
||||
import net.minecraft.client.util.ModelIdentifier;
|
||||
import net.minecraft.util.math.AffineTransformation;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Vec3f;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
@ -27,9 +27,9 @@ import java.util.Objects;
|
||||
public final class TransformedModel
|
||||
{
|
||||
private final BakedModel model;
|
||||
private final AffineTransformation matrix;
|
||||
private final Transformation matrix;
|
||||
|
||||
public TransformedModel( @Nonnull BakedModel model, @Nonnull AffineTransformation matrix )
|
||||
public TransformedModel( @Nonnull BakedModel model, @Nonnull Transformation matrix )
|
||||
{
|
||||
this.model = Objects.requireNonNull( model );
|
||||
this.matrix = Objects.requireNonNull( matrix );
|
||||
@ -38,22 +38,18 @@ public final class TransformedModel
|
||||
public TransformedModel( @Nonnull BakedModel model )
|
||||
{
|
||||
this.model = Objects.requireNonNull( model );
|
||||
matrix = AffineTransformation.identity();
|
||||
matrix = Transformation.identity();
|
||||
}
|
||||
|
||||
public static TransformedModel of( @Nonnull ModelIdentifier location )
|
||||
public static TransformedModel of( @Nonnull ModelResourceLocation location )
|
||||
{
|
||||
BakedModelManager modelManager = MinecraftClient.getInstance()
|
||||
.getBakedModelManager();
|
||||
ModelManager modelManager = Minecraft.getInstance().getModelManager();
|
||||
return new TransformedModel( modelManager.getModel( location ) );
|
||||
}
|
||||
|
||||
public static TransformedModel of( @Nonnull ItemStack item, @Nonnull AffineTransformation transform )
|
||||
public static TransformedModel of( @Nonnull ItemStack item, @Nonnull Transformation transform )
|
||||
{
|
||||
BakedModel model = MinecraftClient.getInstance()
|
||||
.getItemRenderer()
|
||||
.getModels()
|
||||
.getModel( item );
|
||||
BakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getItemModel( item );
|
||||
return new TransformedModel( model, transform );
|
||||
}
|
||||
|
||||
@ -64,23 +60,23 @@ public final class TransformedModel
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public AffineTransformation getMatrix()
|
||||
public Transformation getMatrix()
|
||||
{
|
||||
return matrix;
|
||||
}
|
||||
|
||||
public void push( MatrixStack matrixStack )
|
||||
public void push( PoseStack matrixStack )
|
||||
{
|
||||
matrixStack.push();
|
||||
matrixStack.pushPose();
|
||||
|
||||
Vec3f translation = matrix.getTranslation();
|
||||
matrixStack.translate( translation.getX(), translation.getY(), translation.getZ() );
|
||||
Vector3f translation = matrix.getTranslation();
|
||||
matrixStack.translate( translation.x(), translation.y(), translation.z() );
|
||||
|
||||
matrixStack.multiply( matrix.getRotation2() );
|
||||
matrixStack.mulPose( matrix.getLeftRotation() );
|
||||
|
||||
Vec3f scale = matrix.getScale();
|
||||
matrixStack.scale( scale.getX(), scale.getY(), scale.getZ() );
|
||||
Vector3f scale = matrix.getScale();
|
||||
matrixStack.scale( scale.x(), scale.y(), scale.z() );
|
||||
|
||||
matrixStack.multiply( matrix.getRotation1() );
|
||||
matrixStack.mulPose( matrix.getRightRotation() );
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.filesystem;
|
||||
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.filesystem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.filesystem;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -3,12 +3,11 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.filesystem;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -17,55 +16,20 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}.
|
||||
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
||||
* {@link IComputerAccess#mount(String, IMount)}.
|
||||
*
|
||||
* Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or {@link
|
||||
* ComputerCraftAPI#createResourceMount(String, String)}, or you're free to implement it yourselves!
|
||||
* Ready made implementations of this interface can be created using
|
||||
* {@link ComputerCraftAPI#createSaveDirMount(Level, String, long)} or
|
||||
* {@link ComputerCraftAPI#createResourceMount(String, String)}, or you're free to implement it yourselves!
|
||||
*
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IWritableMount
|
||||
*/
|
||||
public interface IMount
|
||||
{
|
||||
/**
|
||||
* Returns the file names of all the files in a directory.
|
||||
*
|
||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
|
||||
* @param contents A list of strings. Add all the file names to this list.
|
||||
* @throws IOException If the file was not a directory, or could not be listed.
|
||||
*/
|
||||
void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
|
||||
*
|
||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
||||
* @return A channel representing the contents of the file. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to
|
||||
* seek to arbitrary positions when using binary mode.
|
||||
* @throws IOException If the file does not exist, or could not be opened.
|
||||
*/
|
||||
@Nonnull
|
||||
ReadableByteChannel openForRead( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Get attributes about the given file.
|
||||
*
|
||||
* @param path The path to query.
|
||||
* @return File attributes for the given file.
|
||||
* @throws IOException If the file does not exist, or attributes could not be fetched.
|
||||
*/
|
||||
@Nonnull
|
||||
default BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
|
||||
{
|
||||
if( !exists( path ) )
|
||||
{
|
||||
throw new FileOperationException( path, "No such file" );
|
||||
}
|
||||
return new FileAttributes( isDirectory( path ), getSize( path ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether a file with a given path exists or not.
|
||||
*
|
||||
@ -84,6 +48,15 @@ public interface IMount
|
||||
*/
|
||||
boolean isDirectory( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the file names of all the files in a directory.
|
||||
*
|
||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprograms".
|
||||
* @param contents A list of strings. Add all the file names to this list.
|
||||
* @throws IOException If the file was not a directory, or could not be listed.
|
||||
*/
|
||||
void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the size of a file with a given path, in bytes.
|
||||
*
|
||||
@ -92,4 +65,30 @@ public interface IMount
|
||||
* @throws IOException If the file does not exist, or its size could not be determined.
|
||||
*/
|
||||
long getSize( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Opens a file with a given path, and returns an {@link ReadableByteChannel} representing its contents.
|
||||
*
|
||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
||||
* @return A channel representing the contents of the file. If the channel implements
|
||||
* {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary positions when using binary
|
||||
* mode.
|
||||
* @throws IOException If the file does not exist, or could not be opened.
|
||||
*/
|
||||
@Nonnull
|
||||
ReadableByteChannel openForRead( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Get attributes about the given file.
|
||||
*
|
||||
* @param path The path to query.
|
||||
* @return File attributes for the given file.
|
||||
* @throws IOException If the file does not exist, or attributes could not be fetched.
|
||||
*/
|
||||
@Nonnull
|
||||
default BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
|
||||
{
|
||||
if( !exists( path ) ) throw new FileOperationException( path, "No such file" );
|
||||
return new FileAttributes( isDirectory( path ), getSize( path ) );
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,11 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.filesystem;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@ -17,13 +16,13 @@ import java.nio.channels.WritableByteChannel;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
/**
|
||||
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)} or {@link
|
||||
* IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
|
||||
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
|
||||
* or {@link IComputerAccess#mountWritable(String, IWritableMount)}, that can also be written to.
|
||||
*
|
||||
* Ready made implementations of this interface can be created using {@link ComputerCraftAPI#createSaveDirMount(World, String, long)}, or you're free to
|
||||
* implement it yourselves!
|
||||
* Ready made implementations of this interface can be created using
|
||||
* {@link ComputerCraftAPI#createSaveDirMount(Level, String, long)}, or you're free to implement it yourselves!
|
||||
*
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see IComputerAccess#mount(String, IMount)
|
||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||
* @see IMount
|
||||
@ -50,8 +49,8 @@ public interface IWritableMount extends IMount
|
||||
* Opens a file with a given path, and returns an {@link OutputStream} for writing to it.
|
||||
*
|
||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
||||
* @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary
|
||||
* positions when using binary mode.
|
||||
* @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one
|
||||
* will be able to seek to arbitrary positions when using binary mode.
|
||||
* @throws IOException If the file could not be opened for writing.
|
||||
*/
|
||||
@Nonnull
|
||||
@ -61,16 +60,16 @@ public interface IWritableMount extends IMount
|
||||
* Opens a file with a given path, and returns an {@link OutputStream} for appending to it.
|
||||
*
|
||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
||||
* @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one will be able to seek to arbitrary
|
||||
* positions when using binary mode.
|
||||
* @return A stream for writing to. If the channel implements {@link java.nio.channels.SeekableByteChannel}, one
|
||||
* will be able to seek to arbitrary positions when using binary mode.
|
||||
* @throws IOException If the file could not be opened for writing.
|
||||
*/
|
||||
@Nonnull
|
||||
WritableByteChannel openForAppend( @Nonnull String path ) throws IOException;
|
||||
|
||||
/**
|
||||
* Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the mount, and write operations should fail
|
||||
* once it reaches zero.
|
||||
* Get the amount of free space on the mount, in bytes. You should decrease this value as the user writes to the
|
||||
* mount, and write operations should fail once it reaches zero.
|
||||
*
|
||||
* @return The amount of free space, in bytes.
|
||||
* @throws IOException If the remaining space could not be computed.
|
||||
@ -78,7 +77,8 @@ public interface IWritableMount extends IMount
|
||||
long getRemainingSpace() throws IOException;
|
||||
|
||||
/**
|
||||
* Get the capacity of this mount. This should be equal to the size of all files/directories on this mount, minus the {@link #getRemainingSpace()}.
|
||||
* Get the capacity of this mount. This should be equal to the size of all files/directories on this mount, minus
|
||||
* the {@link #getRemainingSpace()}.
|
||||
*
|
||||
* @return The capacity of this mount, in bytes.
|
||||
*/
|
||||
|
@ -9,7 +9,8 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||
import dan200.computercraft.core.asm.LuaMethod;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.Container;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -18,20 +19,19 @@ import javax.annotation.Nonnull;
|
||||
*
|
||||
* Unlike normal objects ({@link IDynamicLuaObject} or {@link IPeripheral}), methods do not target this object but
|
||||
* instead are defined as {@code static} and accept their target as the first parameter. This allows you to inject
|
||||
* methods onto objects you do not own, as well as declaring methods for a specific "trait" (for instance, a
|
||||
* {@link Capability}).
|
||||
* methods onto objects you do not own, as well as declaring methods for a specific "trait" (well, interface).
|
||||
*
|
||||
* Currently the "generic peripheral" system is incompatible with normal peripherals. Normal {@link IPeripheralProvider}
|
||||
* or {@link IPeripheral} implementations take priority. Tile entities which use this system are given a peripheral name
|
||||
* determined by their id, rather than any peripheral provider. This will hopefully change in the future, once a suitable
|
||||
* design has been established.
|
||||
*
|
||||
* For example, the main CC: Tweaked mod defines a generic source for inventories, which works on {@link IItemHandler}s:
|
||||
* For example, the main CC: Tweaked mod defines a generic source for inventories, which works on {@link Container}s:
|
||||
*
|
||||
* <pre>{@code
|
||||
* public class InventoryMethods implements GenericSource {
|
||||
* \@LuaFunction( mainThread = true )
|
||||
* public static int size(IItemHandler inventory) {
|
||||
* public static int size(Container inventory) {
|
||||
* return inventory.getSlots();
|
||||
* }
|
||||
*
|
||||
@ -40,8 +40,6 @@ import javax.annotation.Nonnull;
|
||||
* }</pre>
|
||||
*
|
||||
* @see ComputerCraftAPI#registerGenericSource(GenericSource)
|
||||
* @see ComputerCraftAPI#registerGenericCapability(Capability) New capabilities (those not built into Forge) must be
|
||||
* explicitly given to the generic peripheral system, as there is no way to enumerate all capabilities.
|
||||
*/
|
||||
public interface GenericSource
|
||||
{
|
||||
@ -54,5 +52,5 @@ public interface GenericSource
|
||||
* @return This source's identifier.
|
||||
*/
|
||||
@Nonnull
|
||||
Identifier id();
|
||||
ResourceLocation id();
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -19,25 +18,6 @@ import static dan200.computercraft.api.lua.LuaValues.checkFinite;
|
||||
*/
|
||||
public interface IArguments
|
||||
{
|
||||
/**
|
||||
* Drop a number of arguments. The returned arguments instance will access arguments at position {@code i + count}, rather than {@code i}. However,
|
||||
* errors will still use the given argument index.
|
||||
*
|
||||
* @param count The number of arguments to drop.
|
||||
* @return The new {@link IArguments} instance.
|
||||
*/
|
||||
IArguments drop( int count );
|
||||
|
||||
default Object[] getAll()
|
||||
{
|
||||
Object[] result = new Object[count()];
|
||||
for( int i = 0; i < result.length; i++ )
|
||||
{
|
||||
result[i] = get( i );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of arguments passed to this function.
|
||||
*
|
||||
@ -62,6 +42,37 @@ public interface IArguments
|
||||
@Nullable
|
||||
Object get( int index );
|
||||
|
||||
/**
|
||||
* Drop a number of arguments. The returned arguments instance will access arguments at position {@code i + count},
|
||||
* rather than {@code i}. However, errors will still use the given argument index.
|
||||
*
|
||||
* @param count The number of arguments to drop.
|
||||
* @return The new {@link IArguments} instance.
|
||||
*/
|
||||
IArguments drop( int count );
|
||||
|
||||
default Object[] getAll()
|
||||
{
|
||||
Object[] result = new Object[count()];
|
||||
for( int i = 0; i < result.length; i++ ) result[i] = get( i );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a double.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value.
|
||||
* @throws LuaException If the value is not a number.
|
||||
* @see #getFiniteDouble(int) if you require this to be finite (i.e. not infinite or NaN).
|
||||
*/
|
||||
default double getDouble( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
|
||||
return ((Number) value).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as an integer.
|
||||
*
|
||||
@ -84,12 +95,8 @@ public interface IArguments
|
||||
default long getLong( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( !(value instanceof Number) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "number", value );
|
||||
}
|
||||
return LuaValues.checkFiniteNum( index, (Number) value )
|
||||
.longValue();
|
||||
if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
|
||||
return LuaValues.checkFiniteNum( index, (Number) value ).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,24 +111,6 @@ public interface IArguments
|
||||
return checkFinite( index, getDouble( index ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a double.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value.
|
||||
* @throws LuaException If the value is not a number.
|
||||
* @see #getFiniteDouble(int) if you require this to be finite (i.e. not infinite or NaN).
|
||||
*/
|
||||
default double getDouble( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( !(value instanceof Number) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "number", value );
|
||||
}
|
||||
return ((Number) value).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a boolean.
|
||||
*
|
||||
@ -132,26 +121,10 @@ public interface IArguments
|
||||
default boolean getBoolean( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( !(value instanceof Boolean) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "boolean", value );
|
||||
}
|
||||
if( !(value instanceof Boolean) ) throw LuaValues.badArgumentOf( index, "boolean", value );
|
||||
return (Boolean) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string argument as a byte array.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value. This is a <em>read only</em> buffer.
|
||||
* @throws LuaException If the value is not a string.
|
||||
*/
|
||||
@Nonnull
|
||||
default ByteBuffer getBytes( int index ) throws LuaException
|
||||
{
|
||||
return LuaValues.encode( getString( index ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a string.
|
||||
*
|
||||
@ -163,13 +136,23 @@ public interface IArguments
|
||||
default String getString( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( !(value instanceof String) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "string", value );
|
||||
}
|
||||
if( !(value instanceof String) ) throw LuaValues.badArgumentOf( index, "string", value );
|
||||
return (String) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string argument as a byte array.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value. This is a <em>read only</em> buffer.
|
||||
* @throws LuaException If the value is not a string.
|
||||
*/
|
||||
@Nonnull
|
||||
default ByteBuffer getBytes( int index ) throws LuaException
|
||||
{
|
||||
return LuaValues.encode( getString( index ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string argument as an enum value.
|
||||
*
|
||||
@ -196,75 +179,10 @@ public interface IArguments
|
||||
default Map<?, ?> getTable( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( !(value instanceof Map) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "table", value );
|
||||
}
|
||||
if( !(value instanceof Map) ) throw LuaValues.badArgumentOf( index, "table", value );
|
||||
return (Map<?, ?>) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string argument as a byte array.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present. This is a <em>read only</em> buffer.
|
||||
* @throws LuaException If the value is not a string.
|
||||
*/
|
||||
default Optional<ByteBuffer> optBytes( int index ) throws LuaException
|
||||
{
|
||||
return optString( index ).map( LuaValues::encode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a string.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not a string.
|
||||
*/
|
||||
default Optional<String> optString( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null )
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
if( !(value instanceof String) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "string", value );
|
||||
}
|
||||
return Optional.of( (String) value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string argument as an enum value.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @param klass The type of enum to parse.
|
||||
* @param <T> The type of enum to parse.
|
||||
* @return The argument's value.
|
||||
* @throws LuaException If the value is not a string or not a valid option for this enum.
|
||||
*/
|
||||
@Nonnull
|
||||
default <T extends Enum<T>> Optional<T> optEnum( int index, Class<T> klass ) throws LuaException
|
||||
{
|
||||
Optional<String> str = optString( index );
|
||||
return str.isPresent() ? Optional.of( LuaValues.checkEnum( index, klass, str.get() ) ) : Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a double.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @param def The default value, if this argument is not given.
|
||||
* @return The argument's value, or {@code def} if none was provided.
|
||||
* @throws LuaException If the value is not a number.
|
||||
*/
|
||||
default double optDouble( int index, double def ) throws LuaException
|
||||
{
|
||||
return optDouble( index ).orElse( def );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a double.
|
||||
*
|
||||
@ -276,30 +194,11 @@ public interface IArguments
|
||||
default Optional<Double> optDouble( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null )
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
if( !(value instanceof Number) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "number", value );
|
||||
}
|
||||
if( value == null ) return Optional.empty();
|
||||
if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
|
||||
return Optional.of( ((Number) value).doubleValue() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as an int.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @param def The default value, if this argument is not given.
|
||||
* @return The argument's value, or {@code def} if none was provided.
|
||||
* @throws LuaException If the value is not a number.
|
||||
*/
|
||||
default int optInt( int index, int def ) throws LuaException
|
||||
{
|
||||
return optInt( index ).orElse( def );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as an int.
|
||||
*
|
||||
@ -323,16 +222,122 @@ public interface IArguments
|
||||
default Optional<Long> optLong( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null )
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
if( !(value instanceof Number) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "number", value );
|
||||
}
|
||||
return Optional.of( LuaValues.checkFiniteNum( index, (Number) value )
|
||||
.longValue() );
|
||||
if( value == null ) return Optional.empty();
|
||||
if( !(value instanceof Number) ) throw LuaValues.badArgumentOf( index, "number", value );
|
||||
return Optional.of( LuaValues.checkFiniteNum( index, (Number) value ).longValue() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a finite number (not infinite or NaN).
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not finite.
|
||||
*/
|
||||
default Optional<Double> optFiniteDouble( int index ) throws LuaException
|
||||
{
|
||||
Optional<Double> value = optDouble( index );
|
||||
if( value.isPresent() ) LuaValues.checkFiniteNum( index, value.get() );
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a boolean.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not a boolean.
|
||||
*/
|
||||
default Optional<Boolean> optBoolean( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null ) return Optional.empty();
|
||||
if( !(value instanceof Boolean) ) throw LuaValues.badArgumentOf( index, "boolean", value );
|
||||
return Optional.of( (Boolean) value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a string.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not a string.
|
||||
*/
|
||||
default Optional<String> optString( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null ) return Optional.empty();
|
||||
if( !(value instanceof String) ) throw LuaValues.badArgumentOf( index, "string", value );
|
||||
return Optional.of( (String) value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string argument as a byte array.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present. This is a <em>read only</em> buffer.
|
||||
* @throws LuaException If the value is not a string.
|
||||
*/
|
||||
default Optional<ByteBuffer> optBytes( int index ) throws LuaException
|
||||
{
|
||||
return optString( index ).map( LuaValues::encode );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string argument as an enum value.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @param klass The type of enum to parse.
|
||||
* @param <T> The type of enum to parse.
|
||||
* @return The argument's value.
|
||||
* @throws LuaException If the value is not a string or not a valid option for this enum.
|
||||
*/
|
||||
@Nonnull
|
||||
default <T extends Enum<T>> Optional<T> optEnum( int index, Class<T> klass ) throws LuaException
|
||||
{
|
||||
Optional<String> str = optString( index );
|
||||
return str.isPresent() ? Optional.of( LuaValues.checkEnum( index, klass, str.get() ) ) : Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a table.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not a table.
|
||||
*/
|
||||
default Optional<Map<?, ?>> optTable( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null ) return Optional.empty();
|
||||
if( !(value instanceof Map) ) throw LuaValues.badArgumentOf( index, "map", value );
|
||||
return Optional.of( (Map<?, ?>) value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a double.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @param def The default value, if this argument is not given.
|
||||
* @return The argument's value, or {@code def} if none was provided.
|
||||
* @throws LuaException If the value is not a number.
|
||||
*/
|
||||
default double optDouble( int index, double def ) throws LuaException
|
||||
{
|
||||
return optDouble( index ).orElse( def );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as an int.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @param def The default value, if this argument is not given.
|
||||
* @return The argument's value, or {@code def} if none was provided.
|
||||
* @throws LuaException If the value is not a number.
|
||||
*/
|
||||
default int optInt( int index, int def ) throws LuaException
|
||||
{
|
||||
return optInt( index ).orElse( def );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -361,23 +366,6 @@ public interface IArguments
|
||||
return optFiniteDouble( index ).orElse( def );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a finite number (not infinite or NaN).
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not finite.
|
||||
*/
|
||||
default Optional<Double> optFiniteDouble( int index ) throws LuaException
|
||||
{
|
||||
Optional<Double> value = optDouble( index );
|
||||
if( value.isPresent() )
|
||||
{
|
||||
LuaValues.checkFiniteNum( index, value.get() );
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a boolean.
|
||||
*
|
||||
@ -391,27 +379,6 @@ public interface IArguments
|
||||
return optBoolean( index ).orElse( def );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a boolean.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not a boolean.
|
||||
*/
|
||||
default Optional<Boolean> optBoolean( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null )
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
if( !(value instanceof Boolean) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "boolean", value );
|
||||
}
|
||||
return Optional.of( (Boolean) value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a string.
|
||||
*
|
||||
@ -437,25 +404,4 @@ public interface IArguments
|
||||
{
|
||||
return optTable( index ).orElse( def );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument as a table.
|
||||
*
|
||||
* @param index The argument number.
|
||||
* @return The argument's value, or {@link Optional#empty()} if not present.
|
||||
* @throws LuaException If the value is not a table.
|
||||
*/
|
||||
default Optional<Map<?, ?>> optTable( int index ) throws LuaException
|
||||
{
|
||||
Object value = get( index );
|
||||
if( value == null )
|
||||
{
|
||||
return Optional.empty();
|
||||
}
|
||||
if( !(value instanceof Map) )
|
||||
{
|
||||
throw LuaValues.badArgumentOf( index, "map", value );
|
||||
}
|
||||
return Optional.of( (Map<?, ?>) value );
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import dan200.computercraft.api.filesystem.IFileSystem;
|
||||
@ -12,7 +11,8 @@ import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* An interface passed to {@link ILuaAPIFactory} in order to provide additional information about a computer.
|
||||
* An interface passed to {@link ILuaAPIFactory} in order to provide additional information
|
||||
* about a computer.
|
||||
*/
|
||||
public interface IComputerSystem extends IComputerAccess
|
||||
{
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IDynamicPeripheral;
|
||||
@ -13,13 +12,15 @@ import javax.annotation.Nonnull;
|
||||
/**
|
||||
* An interface for representing custom objects returned by peripherals or other Lua objects.
|
||||
*
|
||||
* Generally, one does not need to implement this type - it is sufficient to return an object with some methods annotated with {@link LuaFunction}. {@link
|
||||
* IDynamicLuaObject} is useful when you wish your available methods to change at runtime.
|
||||
* Generally, one does not need to implement this type - it is sufficient to return an object with some methods
|
||||
* annotated with {@link LuaFunction}. {@link IDynamicLuaObject} is useful when you wish your available methods to
|
||||
* change at runtime.
|
||||
*/
|
||||
public interface IDynamicLuaObject
|
||||
{
|
||||
/**
|
||||
* Get the names of the methods that this object implements. This should not change over the course of the object's lifetime.
|
||||
* Get the names of the methods that this object implements. This should not change over the course of the object's
|
||||
* lifetime.
|
||||
*
|
||||
* @return The method names this object provides.
|
||||
* @see IDynamicPeripheral#getMethodNames()
|
||||
@ -30,10 +31,13 @@ public interface IDynamicLuaObject
|
||||
/**
|
||||
* Called when a user calls one of the methods that this object implements.
|
||||
*
|
||||
* @param context The context of the currently running lua thread. This can be used to wait for events or otherwise yield.
|
||||
* @param method An integer identifying which method index from {@link #getMethodNames()} the computer wishes to call.
|
||||
* @param context The context of the currently running lua thread. This can be used to wait for events
|
||||
* or otherwise yield.
|
||||
* @param method An integer identifying which method index from {@link #getMethodNames()} the computer wishes
|
||||
* to call.
|
||||
* @param arguments The arguments for this method.
|
||||
* @return The result of this function. Either an immediate value ({@link MethodResult#of(Object...)} or an instruction to yield.
|
||||
* @return The result of this function. Either an immediate value ({@link MethodResult#of(Object...)} or an
|
||||
* instruction to yield.
|
||||
* @throws LuaException If the function threw an exception.
|
||||
*/
|
||||
@Nonnull
|
||||
|
@ -3,17 +3,16 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
|
||||
/**
|
||||
* Represents a Lua object which is stored as a global variable on computer startup. This must either provide {@link LuaFunction} annotated functions or
|
||||
* implement {@link IDynamicLuaObject}.
|
||||
* Represents a Lua object which is stored as a global variable on computer startup. This must either provide
|
||||
* {@link LuaFunction} annotated functions or implement {@link IDynamicLuaObject}.
|
||||
*
|
||||
* Before implementing this interface, consider alternative methods of providing methods. It is generally preferred to use peripherals to provide
|
||||
* functionality to users.
|
||||
* Before implementing this interface, consider alternative methods of providing methods. It is generally preferred
|
||||
* to use peripherals to provide functionality to users.
|
||||
*
|
||||
* @see ILuaAPIFactory
|
||||
* @see ComputerCraftAPI#registerAPIFactory(ILuaAPIFactory)
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -18,7 +17,8 @@ public interface ILuaCallback
|
||||
/**
|
||||
* Resume this coroutine.
|
||||
*
|
||||
* @param args The result of resuming this coroutine. These will have the same form as described in {@link LuaFunction}.
|
||||
* @param args The result of resuming this coroutine. These will have the same form as described in
|
||||
* {@link LuaFunction}.
|
||||
* @return The result of this continuation. Either the result to return to the callee, or another yield.
|
||||
* @throws LuaException On an error.
|
||||
*/
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -41,5 +40,8 @@ public interface ILuaContext
|
||||
* @throws LuaException If the task could not be queued, or if the task threw an exception.
|
||||
*/
|
||||
@Nonnull
|
||||
MethodResult executeMainThreadTask( @Nonnull ILuaTask task ) throws LuaException;
|
||||
default MethodResult executeMainThreadTask( @Nonnull ILuaTask task ) throws LuaException
|
||||
{
|
||||
return TaskCallback.make( this, task );
|
||||
}
|
||||
}
|
||||
|
@ -3,14 +3,13 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* A function, which can be called from Lua. If you need to return a table of functions, it is recommended to use an object with {@link LuaFunction}
|
||||
* methods, or implement {@link IDynamicLuaObject}.
|
||||
* A function, which can be called from Lua. If you need to return a table of functions, it is recommended to use
|
||||
* an object with {@link LuaFunction} methods, or implement {@link IDynamicLuaObject}.
|
||||
*
|
||||
* @see MethodResult#of(Object)
|
||||
*/
|
||||
@ -18,8 +17,8 @@ import javax.annotation.Nonnull;
|
||||
public interface ILuaFunction
|
||||
{
|
||||
/**
|
||||
* Call this function with a series of arguments. Note, this will <em>always</em> be called on the computer thread, and so its implementation must be
|
||||
* thread-safe.
|
||||
* Call this function with a series of arguments. Note, this will <em>always</em> be called on the computer thread,
|
||||
* and so its implementation must be thread-safe.
|
||||
*
|
||||
* @param arguments The arguments for this function
|
||||
* @return The result of calling this function.
|
||||
|
@ -3,14 +3,14 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A task which can be executed via {@link ILuaContext#issueMainThreadTask(ILuaTask)} This will be run on the main thread, at the beginning of the next
|
||||
* tick.
|
||||
* A task which can be executed via {@link ILuaContext#issueMainThreadTask(ILuaTask)} This will be run on the main
|
||||
* thread, at the beginning of the
|
||||
* next tick.
|
||||
*
|
||||
* @see ILuaContext#issueMainThreadTask(ILuaTask)
|
||||
*/
|
||||
@ -21,8 +21,9 @@ public interface ILuaTask
|
||||
* Execute this task.
|
||||
*
|
||||
* @return The arguments to add to the {@code task_completed} event.
|
||||
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the same message as your exception. Use this
|
||||
* to throw appropriate errors if the wrong arguments are supplied to your method.
|
||||
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the
|
||||
* same message as your exception. Use this to throw appropriate errors if the wrong
|
||||
* arguments are supplied to your method.
|
||||
*/
|
||||
@Nullable
|
||||
Object[] execute() throws LuaException;
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -42,7 +41,8 @@ public class LuaException extends Exception
|
||||
}
|
||||
|
||||
/**
|
||||
* The level this error is raised at. Level 1 is the function's caller, level 2 is that function's caller, and so on.
|
||||
* The level this error is raised at. Level 1 is the function's caller, level 2 is that function's caller, and so
|
||||
* on.
|
||||
*
|
||||
* @return The level to raise the error at.
|
||||
*/
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
@ -16,8 +15,8 @@ import java.util.Optional;
|
||||
/**
|
||||
* Used to mark a Java function which is callable from Lua.
|
||||
*
|
||||
* Methods annotated with {@link LuaFunction} must be public final instance methods. They can have any number of parameters, but they must be of the
|
||||
* following types:
|
||||
* Methods annotated with {@link LuaFunction} must be public final instance methods. They can have any number of
|
||||
* parameters, but they must be of the following types:
|
||||
*
|
||||
* <ul>
|
||||
* <li>{@link ILuaContext} (and {@link IComputerAccess} if on a {@link IPeripheral})</li>
|
||||
@ -49,7 +48,8 @@ public @interface LuaFunction
|
||||
String[] value() default {};
|
||||
|
||||
/**
|
||||
* Run this function on the main server thread. This should be specified for any method which interacts with Minecraft in a thread-unsafe manner.
|
||||
* Run this function on the main server thread. This should be specified for any method which interacts with
|
||||
* Minecraft in a thread-unsafe manner.
|
||||
*
|
||||
* @return Whether this functi
|
||||
* @see ILuaContext#issueMainThreadTask(ILuaTask)
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -38,8 +37,41 @@ public final class LuaValues
|
||||
chars[i] = c < 256 ? (byte) c : 63;
|
||||
}
|
||||
|
||||
return ByteBuffer.wrap( chars )
|
||||
.asReadOnlyBuffer();
|
||||
return ByteBuffer.wrap( chars ).asReadOnlyBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a more detailed representation of this number's type. If this is finite, it will just return "number",
|
||||
* otherwise it returns whether it is infinite or NaN.
|
||||
*
|
||||
* @param value The value to extract the type for.
|
||||
* @return This value's numeric type.
|
||||
*/
|
||||
@Nonnull
|
||||
public static String getNumericType( double value )
|
||||
{
|
||||
if( Double.isNaN( value ) ) return "nan";
|
||||
if( value == Double.POSITIVE_INFINITY ) return "inf";
|
||||
if( value == Double.NEGATIVE_INFINITY ) return "-inf";
|
||||
return "number";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the given value's type.
|
||||
*
|
||||
* @param value The value whose type we are trying to compute.
|
||||
* @return A string representation of the given value's type, in a similar format to that provided by Lua's
|
||||
* {@code type} function.
|
||||
*/
|
||||
@Nonnull
|
||||
public static String getType( @Nullable Object value )
|
||||
{
|
||||
if( value == null ) return "nil";
|
||||
if( value instanceof String ) return "string";
|
||||
if( value instanceof Boolean ) return "boolean";
|
||||
if( value instanceof Number ) return "number";
|
||||
if( value instanceof Map ) return "table";
|
||||
return "userdata";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,38 +102,6 @@ public final class LuaValues
|
||||
return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string representation of the given value's type.
|
||||
*
|
||||
* @param value The value whose type we are trying to compute.
|
||||
* @return A string representation of the given value's type, in a similar format to that provided by Lua's {@code type} function.
|
||||
*/
|
||||
@Nonnull
|
||||
public static String getType( @Nullable Object value )
|
||||
{
|
||||
if( value == null )
|
||||
{
|
||||
return "nil";
|
||||
}
|
||||
if( value instanceof String )
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
if( value instanceof Boolean )
|
||||
{
|
||||
return "boolean";
|
||||
}
|
||||
if( value instanceof Number )
|
||||
{
|
||||
return "number";
|
||||
}
|
||||
if( value instanceof Map )
|
||||
{
|
||||
return "table";
|
||||
}
|
||||
return "userdata";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a numeric argument is finite (i.e. not infinite or {@link Double#NaN}.
|
||||
*
|
||||
@ -126,38 +126,10 @@ public final class LuaValues
|
||||
*/
|
||||
public static double checkFinite( int index, double value ) throws LuaException
|
||||
{
|
||||
if( !Double.isFinite( value ) )
|
||||
{
|
||||
throw badArgument( index, "number", getNumericType( value ) );
|
||||
}
|
||||
if( !Double.isFinite( value ) ) throw badArgument( index, "number", getNumericType( value ) );
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a more detailed representation of this number's type. If this is finite, it will just return "number", otherwise it returns whether it is
|
||||
* infinite or NaN.
|
||||
*
|
||||
* @param value The value to extract the type for.
|
||||
* @return This value's numeric type.
|
||||
*/
|
||||
@Nonnull
|
||||
public static String getNumericType( double value )
|
||||
{
|
||||
if( Double.isNaN( value ) )
|
||||
{
|
||||
return "nan";
|
||||
}
|
||||
if( value == Double.POSITIVE_INFINITY )
|
||||
{
|
||||
return "inf";
|
||||
}
|
||||
if( value == Double.NEGATIVE_INFINITY )
|
||||
{
|
||||
return "-inf";
|
||||
}
|
||||
return "number";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a string is a valid enum value.
|
||||
*
|
||||
@ -172,11 +144,7 @@ public final class LuaValues
|
||||
{
|
||||
for( T possibility : klass.getEnumConstants() )
|
||||
{
|
||||
if( possibility.name()
|
||||
.equalsIgnoreCase( value ) )
|
||||
{
|
||||
return possibility;
|
||||
}
|
||||
if( possibility.name().equalsIgnoreCase( value ) ) return possibility;
|
||||
}
|
||||
|
||||
throw new LuaException( "bad argument #" + (index + 1) + " (unknown option " + value + ")" );
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
@ -18,8 +17,8 @@ import java.util.Objects;
|
||||
/**
|
||||
* The result of invoking a Lua method.
|
||||
*
|
||||
* Method results either return a value immediately ({@link #of(Object...)} or yield control to the parent coroutine. When the current coroutine is resumed,
|
||||
* we invoke the provided {@link ILuaCallback#resume(Object[])} callback.
|
||||
* Method results either return a value immediately ({@link #of(Object...)} or yield control to the parent coroutine.
|
||||
* When the current coroutine is resumed, we invoke the provided {@link ILuaCallback#resume(Object[])} callback.
|
||||
*/
|
||||
public final class MethodResult
|
||||
{
|
||||
@ -57,11 +56,12 @@ public final class MethodResult
|
||||
/**
|
||||
* Return a single value immediately.
|
||||
*
|
||||
* Integers, doubles, floats, strings, booleans, {@link Map}, {@link Collection}s, arrays and {@code null} will be converted to their corresponding Lua
|
||||
* type. {@code byte[]} and {@link ByteBuffer} will be treated as binary strings. {@link ILuaFunction} will be treated as a function.
|
||||
* Integers, doubles, floats, strings, booleans, {@link Map}, {@link Collection}s, arrays and {@code null} will be
|
||||
* converted to their corresponding Lua type. {@code byte[]} and {@link ByteBuffer} will be treated as binary
|
||||
* strings. {@link ILuaFunction} will be treated as a function.
|
||||
*
|
||||
* In order to provide a custom object with methods, one may return a {@link IDynamicLuaObject}, or an arbitrary class with {@link LuaFunction}
|
||||
* annotations. Anything else will be converted to {@code nil}.
|
||||
* In order to provide a custom object with methods, one may return a {@link IDynamicLuaObject}, or an arbitrary
|
||||
* class with {@link LuaFunction} annotations. Anything else will be converted to {@code nil}.
|
||||
*
|
||||
* @param value The value to return to the calling Lua function.
|
||||
* @return A method result which returns immediately with the given value.
|
||||
@ -85,8 +85,8 @@ public final class MethodResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly equivalent to {@code os.pullEvent()} in
|
||||
* lua.
|
||||
* Wait for an event to occur on the computer, suspending the thread until it arises. This method is exactly
|
||||
* equivalent to {@code os.pullEvent()} in lua.
|
||||
*
|
||||
* @param filter A specific event to wait for, or null to wait for any event.
|
||||
* @param callback The callback to resume with the name of the event that occurred, and any event parameters.
|
||||
@ -98,17 +98,15 @@ public final class MethodResult
|
||||
{
|
||||
Objects.requireNonNull( callback, "callback cannot be null" );
|
||||
return new MethodResult( new Object[] { filter }, results -> {
|
||||
if( results.length >= 1 && results[0].equals( "terminate" ) )
|
||||
{
|
||||
throw new LuaException( "Terminated", 0 );
|
||||
}
|
||||
if( results.length >= 1 && results[0].equals( "terminate" ) ) throw new LuaException( "Terminated", 0 );
|
||||
return callback.resume( results );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as {@link #pullEvent(String, ILuaCallback)}, except "terminated" events are ignored. Only use this if you want to prevent program
|
||||
* termination, which is not recommended. This method is exactly equivalent to {@code os.pullEventRaw()} in Lua.
|
||||
* The same as {@link #pullEvent(String, ILuaCallback)}, except "terminated" events are ignored. Only use this if
|
||||
* you want to prevent program termination, which is not recommended. This method is exactly equivalent to
|
||||
* {@code os.pullEventRaw()} in Lua.
|
||||
*
|
||||
* @param filter A specific event to wait for, or null to wait for any event.
|
||||
* @param callback The callback to resume with the name of the event that occurred, and any event parameters.
|
||||
@ -123,8 +121,8 @@ public final class MethodResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to {@code coroutine.yield()} in lua. Use
|
||||
* {@code pullEvent()} if you wish to wait for events.
|
||||
* Yield the current coroutine with some arguments until it is resumed. This method is exactly equivalent to
|
||||
* {@code coroutine.yield()} in lua. Use {@code pullEvent()} if you wish to wait for events.
|
||||
*
|
||||
* @param arguments An object array containing the arguments to pass to coroutine.yield()
|
||||
* @param callback The callback to resume with an array containing the return values from coroutine.yield()
|
||||
@ -156,7 +154,8 @@ public final class MethodResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the Lua error by a specific amount. One should never need to use this function - it largely exists for some CC internal code.
|
||||
* Increase the Lua error by a specific amount. One should never need to use this function - it largely exists for
|
||||
* some CC internal code.
|
||||
*
|
||||
* @param adjust The amount to increase the level by.
|
||||
* @return The new {@link MethodResult} with an adjusted error. This has no effect on immediate results.
|
||||
@ -164,14 +163,8 @@ public final class MethodResult
|
||||
@Nonnull
|
||||
public MethodResult adjustError( int adjust )
|
||||
{
|
||||
if( adjust < 0 )
|
||||
{
|
||||
throw new IllegalArgumentException( "cannot adjust by a negative amount" );
|
||||
}
|
||||
if( adjust == 0 || callback == null )
|
||||
{
|
||||
return this;
|
||||
}
|
||||
if( adjust < 0 ) throw new IllegalArgumentException( "cannot adjust by a negative amount" );
|
||||
if( adjust == 0 || callback == null ) return this;
|
||||
return new MethodResult( result, callback, this.adjust + adjust );
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -36,41 +35,32 @@ public final class ObjectArguments implements IArguments
|
||||
this.args = Objects.requireNonNull( args );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArguments drop( int count )
|
||||
{
|
||||
if( count < 0 )
|
||||
{
|
||||
throw new IllegalStateException( "count cannot be negative" );
|
||||
}
|
||||
if( count == 0 )
|
||||
{
|
||||
return this;
|
||||
}
|
||||
if( count >= args.size() )
|
||||
{
|
||||
return EMPTY;
|
||||
}
|
||||
|
||||
return new ObjectArguments( args.subList( count, args.size() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getAll()
|
||||
{
|
||||
return args.toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int count()
|
||||
{
|
||||
return args.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IArguments drop( int count )
|
||||
{
|
||||
if( count < 0 ) throw new IllegalStateException( "count cannot be negative" );
|
||||
if( count == 0 ) return this;
|
||||
if( count >= args.size() ) return EMPTY;
|
||||
|
||||
return new ObjectArguments( args.subList( count, args.size() ) );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object get( int index )
|
||||
{
|
||||
return index >= args.size() ? null : args.get( index );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getAll()
|
||||
{
|
||||
return args.toArray();
|
||||
}
|
||||
}
|
||||
|
53
src/main/java/dan200/computercraft/api/lua/TaskCallback.java
Normal file
53
src/main/java/dan200/computercraft/api/lua/TaskCallback.java
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
package dan200.computercraft.api.lua;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Arrays;
|
||||
|
||||
final class TaskCallback implements ILuaCallback
|
||||
{
|
||||
private final MethodResult pull = MethodResult.pullEvent( "task_complete", this );
|
||||
private final long task;
|
||||
|
||||
private TaskCallback( long task )
|
||||
{
|
||||
this.task = task;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public MethodResult resume( Object[] response ) throws LuaException
|
||||
{
|
||||
if( response.length < 3 || !(response[1] instanceof Number) || !(response[2] instanceof Boolean) )
|
||||
{
|
||||
return pull;
|
||||
}
|
||||
|
||||
if( ((Number) response[1]).longValue() != task ) return pull;
|
||||
|
||||
if( (Boolean) response[2] )
|
||||
{
|
||||
// Extract the return values from the event and return them
|
||||
return MethodResult.of( Arrays.copyOfRange( response, 3, response.length ) );
|
||||
}
|
||||
else if( response.length >= 4 && response[3] instanceof String )
|
||||
{
|
||||
// Extract the error message from the event and raise it
|
||||
throw new LuaException( (String) response[3] );
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new LuaException( "error" );
|
||||
}
|
||||
}
|
||||
|
||||
static MethodResult make( ILuaContext context, ILuaTask func ) throws LuaException
|
||||
{
|
||||
long task = context.issueMainThreadTask( func );
|
||||
return new TaskCallback( task ).pull;
|
||||
}
|
||||
}
|
@ -3,14 +3,13 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.media;
|
||||
|
||||
import dan200.computercraft.api.filesystem.IMount;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -18,7 +17,8 @@ import javax.annotation.Nullable;
|
||||
/**
|
||||
* Represents an item that can be placed in a disk drive and used by a Computer.
|
||||
*
|
||||
* Implement this interface on your {@link Item} class to allow it to be used in the drive. Alternatively, register a {@link IMediaProvider}.
|
||||
* Implement this interface on your {@link Item} class to allow it to be used in the drive. Alternatively, register
|
||||
* a {@link IMediaProvider}.
|
||||
*/
|
||||
public interface IMedia
|
||||
{
|
||||
@ -44,7 +44,8 @@ public interface IMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* If this disk represents an item with audio (like a record), get the readable name of the audio track. ie: "Jonathan Coulton - Still Alive"
|
||||
* If this disk represents an item with audio (like a record), get the readable name of the audio track. ie:
|
||||
* "Jonathan Coulton - Still Alive"
|
||||
*
|
||||
* @param stack The {@link ItemStack} to modify.
|
||||
* @return The name, or null if this item does not represent an item with audio.
|
||||
@ -68,20 +69,20 @@ public interface IMedia
|
||||
}
|
||||
|
||||
/**
|
||||
* If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will be mounted onto the filesystem of
|
||||
* the computer while the media is in the disk drive.
|
||||
* If this disk represents an item with data (like a floppy disk), get a mount representing it's contents. This will
|
||||
* be mounted onto the filesystem of the computer while the media is in the disk drive.
|
||||
*
|
||||
* @param stack The {@link ItemStack} to modify.
|
||||
* @param world The world in which the item and disk drive reside.
|
||||
* @return The mount, or null if this item does not represent an item with data. If the mount returned also implements {@link
|
||||
* dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
|
||||
* @return The mount, or null if this item does not represent an item with data. If the mount returned also
|
||||
* implements {@link dan200.computercraft.api.filesystem.IWritableMount}, it will mounted using mountWritable()
|
||||
* @see IMount
|
||||
* @see dan200.computercraft.api.filesystem.IWritableMount
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#createResourceMount(String, String)
|
||||
*/
|
||||
@Nullable
|
||||
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull World world )
|
||||
default IMount createDataMount( @Nonnull ItemStack stack, @Nonnull Level world )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -3,10 +3,9 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.media;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -38,8 +37,8 @@ public interface IPacketNetwork
|
||||
boolean isWireless();
|
||||
|
||||
/**
|
||||
* Submit a packet for transmitting across the network. This will route the packet through the network, sending it to all receivers within range (or any
|
||||
* interdimensional ones).
|
||||
* Submit a packet for transmitting across the network. This will route the packet through the network, sending it
|
||||
* to all receivers within range (or any interdimensional ones).
|
||||
*
|
||||
* @param packet The packet to send.
|
||||
* @param range The maximum distance this packet will be sent.
|
||||
@ -49,8 +48,8 @@ public interface IPacketNetwork
|
||||
void transmitSameDimension( @Nonnull Packet packet, double range );
|
||||
|
||||
/**
|
||||
* Submit a packet for transmitting across the network. This will route the packet through the network, sending it to all receivers across all
|
||||
* dimensions.
|
||||
* Submit a packet for transmitting across the network. This will route the packet through the network, sending it
|
||||
* to all receivers across all dimensions.
|
||||
*
|
||||
* @param packet The packet to send.
|
||||
* @see #transmitSameDimension(Packet, double)
|
||||
|
@ -3,11 +3,10 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -22,7 +21,7 @@ public interface IPacketReceiver
|
||||
* @return The receivers's world.
|
||||
*/
|
||||
@Nonnull
|
||||
World getWorld();
|
||||
Level getLevel();
|
||||
|
||||
/**
|
||||
* Get the position in the world at which this receiver exists.
|
||||
@ -30,13 +29,14 @@ public interface IPacketReceiver
|
||||
* @return The receiver's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vec3 getPosition();
|
||||
|
||||
/**
|
||||
* Get the maximum distance this receiver can send and receive messages.
|
||||
*
|
||||
* When determining whether a receiver can receive a message, the largest distance of the packet and receiver is used - ensuring it is within range. If
|
||||
* the packet or receiver is inter-dimensional, then the packet will always be received.
|
||||
* When determining whether a receiver can receive a message, the largest distance of the packet and receiver is
|
||||
* used - ensuring it is within range. If the packet or receiver is inter-dimensional, then the packet will always
|
||||
* be received.
|
||||
*
|
||||
* @return The maximum distance this device can send and receive messages.
|
||||
* @see #isInterdimensional()
|
||||
@ -60,8 +60,8 @@ public interface IPacketReceiver
|
||||
/**
|
||||
* Receive a network packet from the same dimension.
|
||||
*
|
||||
* @param packet The packet to receive. Generally you should check that you are listening on the given channel and, if so, queue the appropriate
|
||||
* modem event.
|
||||
* @param packet The packet to receive. Generally you should check that you are listening on the given channel and,
|
||||
* if so, queue the appropriate modem event.
|
||||
* @param distance The distance this packet has travelled from the source.
|
||||
* @see Packet
|
||||
* @see #getRange()
|
||||
@ -73,8 +73,8 @@ public interface IPacketReceiver
|
||||
/**
|
||||
* Receive a network packet from a different dimension.
|
||||
*
|
||||
* @param packet The packet to receive. Generally you should check that you are listening on the given channel and, if so, queue the appropriate
|
||||
* modem event.
|
||||
* @param packet The packet to receive. Generally you should check that you are listening on the given channel and,
|
||||
* if so, queue the appropriate modem event.
|
||||
* @see Packet
|
||||
* @see IPacketNetwork#transmitInterdimensional(Packet)
|
||||
* @see IPacketNetwork#transmitSameDimension(Packet, double)
|
||||
|
@ -3,11 +3,10 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -22,7 +21,7 @@ public interface IPacketSender
|
||||
* @return The sender's world.
|
||||
*/
|
||||
@Nonnull
|
||||
World getWorld();
|
||||
Level getLevel();
|
||||
|
||||
/**
|
||||
* Get the position in the world at which this sender exists.
|
||||
@ -30,11 +29,11 @@ public interface IPacketSender
|
||||
* @return The sender's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vec3 getPosition();
|
||||
|
||||
/**
|
||||
* Get some sort of identification string for this sender. This does not strictly need to be unique, but you should be able to extract some identifiable
|
||||
* information from it.
|
||||
* Get some sort of identification string for this sender. This does not strictly need to be unique, but you
|
||||
* should be able to extract some identifiable information from it.
|
||||
*
|
||||
* @return This device's id.
|
||||
*/
|
||||
|
@ -3,128 +3,28 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a packet which may be sent across a {@link IPacketNetwork}.
|
||||
*
|
||||
* @param channel The channel to send the packet along. Receiving devices should only process packets from on
|
||||
* channels they are listening to.
|
||||
* @param replyChannel The channel to reply on.
|
||||
* @param payload The contents of this packet. This should be a "valid" Lua object, safe for queuing as an
|
||||
* event or returning from a peripheral call.
|
||||
* @param sender The object which sent this packet.
|
||||
* @see IPacketSender
|
||||
* @see IPacketNetwork#transmitSameDimension(Packet, double)
|
||||
* @see IPacketNetwork#transmitInterdimensional(Packet)
|
||||
* @see IPacketReceiver#receiveDifferentDimension(Packet)
|
||||
* @see IPacketReceiver#receiveSameDimension(Packet, double)
|
||||
*/
|
||||
public class Packet
|
||||
public record Packet(
|
||||
int channel,
|
||||
int replyChannel,
|
||||
Object payload,
|
||||
IPacketSender sender
|
||||
)
|
||||
{
|
||||
private final int channel;
|
||||
private final int replyChannel;
|
||||
private final Object payload;
|
||||
|
||||
private final IPacketSender sender;
|
||||
|
||||
/**
|
||||
* Create a new packet, ready for transmitting across the network.
|
||||
*
|
||||
* @param channel The channel to send the packet along. Receiving devices should only process packets from on channels they are listening to.
|
||||
* @param replyChannel The channel to reply on.
|
||||
* @param payload The contents of this packet. This should be a "valid" Lua object, safe for queuing as an event or returning from a peripheral
|
||||
* call.
|
||||
* @param sender The object which sent this packet.
|
||||
*/
|
||||
public Packet( int channel, int replyChannel, @Nullable Object payload, @Nonnull IPacketSender sender )
|
||||
{
|
||||
Objects.requireNonNull( sender, "sender cannot be null" );
|
||||
|
||||
this.channel = channel;
|
||||
this.replyChannel = replyChannel;
|
||||
this.payload = payload;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channel this packet is sent along. Receivers should generally only process packets from on channels they are listening to.
|
||||
*
|
||||
* @return This packet's channel.
|
||||
*/
|
||||
public int getChannel()
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The channel to reply on. Objects which will reply should send it along this channel.
|
||||
*
|
||||
* @return This channel to reply on.
|
||||
*/
|
||||
public int getReplyChannel()
|
||||
{
|
||||
return replyChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* The actual data of this packet. This should be a "valid" Lua object, safe for queuing as an event or returning from a peripheral call.
|
||||
*
|
||||
* @return The packet's payload
|
||||
*/
|
||||
@Nullable
|
||||
public Object getPayload()
|
||||
{
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* The object which sent this message.
|
||||
*
|
||||
* @return The sending object.
|
||||
*/
|
||||
@Nonnull
|
||||
public IPacketSender getSender()
|
||||
{
|
||||
return sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result;
|
||||
result = channel;
|
||||
result = 31 * result + replyChannel;
|
||||
result = 31 * result + (payload != null ? payload.hashCode() : 0);
|
||||
result = 31 * result + sender.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Packet packet = (Packet) o;
|
||||
|
||||
if( channel != packet.channel )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( replyChannel != packet.replyChannel )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !Objects.equals( payload, packet.payload ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return sender.equals( packet.sender );
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network.wired;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
@ -13,16 +12,18 @@ import javax.annotation.Nonnull;
|
||||
/**
|
||||
* An object which may be part of a wired network.
|
||||
*
|
||||
* Elements should construct a node using {@link ComputerCraftAPI#createWiredNodeForElement(IWiredElement)}. This acts as a proxy for all network objects.
|
||||
* Whilst the node may change networks, an element's node should remain constant for its lifespan.
|
||||
* Elements should construct a node using {@link ComputerCraftAPI#createWiredNodeForElement(IWiredElement)}. This acts
|
||||
* as a proxy for all network objects. Whilst the node may change networks, an element's node should remain constant
|
||||
* for its lifespan.
|
||||
*
|
||||
* Elements are generally tied to a block or tile entity in world. In such as case, one should provide the {@link IWiredElement} capability for the
|
||||
* appropriate sides.
|
||||
* Elements are generally tied to a block or tile entity in world. In such as case, one should provide the
|
||||
* {@link IWiredElement} capability for the appropriate sides.
|
||||
*/
|
||||
public interface IWiredElement extends IWiredSender
|
||||
{
|
||||
/**
|
||||
* Called when objects on the network change. This may occur when network nodes are added or removed, or when peripherals change.
|
||||
* Called when objects on the network change. This may occur when network nodes are added or removed, or when
|
||||
* peripherals change.
|
||||
*
|
||||
* @param change The change which occurred.
|
||||
* @see IWiredNetworkChange
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network.wired;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
@ -12,14 +11,16 @@ import javax.annotation.Nonnull;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A wired network is composed of one of more {@link IWiredNode}s, a set of connections between them, and a series of peripherals.
|
||||
* A wired network is composed of one of more {@link IWiredNode}s, a set of connections between them, and a series
|
||||
* of peripherals.
|
||||
*
|
||||
* Networks from a connected graph. This means there is some path between all nodes on the network. Further more, if there is some path between two nodes
|
||||
* then they must be on the same network. {@link IWiredNetwork} will automatically handle the merging and splitting of networks (and thus changing of
|
||||
* available nodes and peripherals) as connections change.
|
||||
* Networks from a connected graph. This means there is some path between all nodes on the network. Further more, if
|
||||
* there is some path between two nodes then they must be on the same network. {@link IWiredNetwork} will automatically
|
||||
* handle the merging and splitting of networks (and thus changing of available nodes and peripherals) as connections
|
||||
* change.
|
||||
*
|
||||
* This does mean one can not rely on the network remaining consistent between subsequent operations. Consequently, it is generally preferred to use the
|
||||
* methods provided by {@link IWiredNode}.
|
||||
* This does mean one can not rely on the network remaining consistent between subsequent operations. Consequently,
|
||||
* it is generally preferred to use the methods provided by {@link IWiredNode}.
|
||||
*
|
||||
* @see IWiredNode#getNetwork()
|
||||
*/
|
||||
@ -58,10 +59,12 @@ public interface IWiredNetwork
|
||||
/**
|
||||
* Sever all connections this node has, removing it from this network.
|
||||
*
|
||||
* This should only be used on the server thread. You should only call this on nodes that your network element owns.
|
||||
* This should only be used on the server thread. You should only call this on nodes
|
||||
* that your network element owns.
|
||||
*
|
||||
* @param node The node to remove
|
||||
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the only element.
|
||||
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
|
||||
* only element.
|
||||
* @throws IllegalArgumentException If the node is not in the network.
|
||||
* @see IWiredNode#remove()
|
||||
*/
|
||||
@ -70,7 +73,8 @@ public interface IWiredNetwork
|
||||
/**
|
||||
* Update the peripherals a node provides.
|
||||
*
|
||||
* This should only be used on the server thread. You should only call this on nodes that your network element owns.
|
||||
* This should only be used on the server thread. You should only call this on nodes
|
||||
* that your network element owns.
|
||||
*
|
||||
* @param node The node to attach peripherals for.
|
||||
* @param peripherals The new peripherals for this node.
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network.wired;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
@ -19,8 +18,8 @@ import java.util.Map;
|
||||
public interface IWiredNetworkChange
|
||||
{
|
||||
/**
|
||||
* A set of peripherals which have been removed. Note that there may be entries with the same name in the added and removed set, but with a different
|
||||
* peripheral.
|
||||
* A set of peripherals which have been removed. Note that there may be entries with the same name
|
||||
* in the added and removed set, but with a different peripheral.
|
||||
*
|
||||
* @return The set of removed peripherals.
|
||||
*/
|
||||
@ -28,8 +27,8 @@ public interface IWiredNetworkChange
|
||||
Map<String, IPeripheral> peripheralsRemoved();
|
||||
|
||||
/**
|
||||
* A set of peripherals which have been added. Note that there may be entries with the same name in the added and removed set, but with a different
|
||||
* peripheral.
|
||||
* A set of peripherals which have been added. Note that there may be entries with the same name
|
||||
* in the added and removed set, but with a different peripheral.
|
||||
*
|
||||
* @return The set of added peripherals.
|
||||
*/
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network.wired;
|
||||
|
||||
import dan200.computercraft.api.network.IPacketNetwork;
|
||||
@ -15,14 +14,15 @@ import java.util.Map;
|
||||
/**
|
||||
* Wired nodes act as a layer between {@link IWiredElement}s and {@link IWiredNetwork}s.
|
||||
*
|
||||
* Firstly, a node acts as a packet network, capable of sending and receiving modem messages to connected nodes. These methods may be safely used on any
|
||||
* thread.
|
||||
* Firstly, a node acts as a packet network, capable of sending and receiving modem messages to connected nodes. These
|
||||
* methods may be safely used on any thread.
|
||||
*
|
||||
* When sending a packet, the system will attempt to find the shortest path between the two nodes based on their element's position. Note that packet
|
||||
* senders and receivers can have different locations from their associated element: the distance between the two will be added to the total packet's
|
||||
* distance.
|
||||
* When sending a packet, the system will attempt to find the shortest path between the two nodes based on their
|
||||
* element's position. Note that packet senders and receivers can have different locations from their associated
|
||||
* element: the distance between the two will be added to the total packet's distance.
|
||||
*
|
||||
* Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever be used on the main server thread.
|
||||
* Wired nodes also provide several convenience methods for interacting with a wired network. These should only ever
|
||||
* be used on the main server thread.
|
||||
*/
|
||||
public interface IWiredNode extends IPacketNetwork
|
||||
{
|
||||
@ -34,6 +34,17 @@ public interface IWiredNode extends IPacketNetwork
|
||||
@Nonnull
|
||||
IWiredElement getElement();
|
||||
|
||||
/**
|
||||
* The network this node is currently connected to. Note that this may change
|
||||
* after any network operation, so it should not be cached.
|
||||
*
|
||||
* This should only be used on the server thread.
|
||||
*
|
||||
* @return This node's network.
|
||||
*/
|
||||
@Nonnull
|
||||
IWiredNetwork getNetwork();
|
||||
|
||||
/**
|
||||
* Create a connection from this node to another.
|
||||
*
|
||||
@ -49,16 +60,6 @@ public interface IWiredNode extends IPacketNetwork
|
||||
return getNetwork().connect( this, node );
|
||||
}
|
||||
|
||||
/**
|
||||
* The network this node is currently connected to. Note that this may change after any network operation, so it should not be cached.
|
||||
*
|
||||
* This should only be used on the server thread.
|
||||
*
|
||||
* @return This node's network.
|
||||
*/
|
||||
@Nonnull
|
||||
IWiredNetwork getNetwork();
|
||||
|
||||
/**
|
||||
* Destroy a connection between this node and another.
|
||||
*
|
||||
@ -78,9 +79,11 @@ public interface IWiredNode extends IPacketNetwork
|
||||
/**
|
||||
* Sever all connections this node has, removing it from this network.
|
||||
*
|
||||
* This should only be used on the server thread. You should only call this on nodes that your network element owns.
|
||||
* This should only be used on the server thread. You should only call this on nodes
|
||||
* that your network element owns.
|
||||
*
|
||||
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the only element.
|
||||
* @return Whether this node was removed from the network. One cannot remove a node from a network where it is the
|
||||
* only element.
|
||||
* @throws IllegalArgumentException If the node is not in the network.
|
||||
* @see IWiredNetwork#remove(IWiredNode)
|
||||
*/
|
||||
@ -92,7 +95,8 @@ public interface IWiredNode extends IPacketNetwork
|
||||
/**
|
||||
* Mark this node's peripherals as having changed.
|
||||
*
|
||||
* This should only be used on the server thread. You should only call this on nodes that your network element owns.
|
||||
* This should only be used on the server thread. You should only call this on nodes
|
||||
* that your network element owns.
|
||||
*
|
||||
* @param peripherals The new peripherals for this node.
|
||||
* @see IWiredNetwork#updatePeripherals(IWiredNode, Map)
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.network.wired;
|
||||
|
||||
import dan200.computercraft.api.network.IPacketSender;
|
||||
@ -13,14 +12,16 @@ import javax.annotation.Nonnull;
|
||||
/**
|
||||
* An object on a {@link IWiredNetwork} capable of sending packets.
|
||||
*
|
||||
* Unlike a regular {@link IPacketSender}, this must be associated with the node you are attempting to to send the packet from.
|
||||
* Unlike a regular {@link IPacketSender}, this must be associated with the node you are attempting to
|
||||
* to send the packet from.
|
||||
*/
|
||||
public interface IWiredSender extends IPacketSender
|
||||
{
|
||||
/**
|
||||
* The node in the network representing this object.
|
||||
*
|
||||
* This should be used as a proxy for the main network. One should send packets and register receivers through this object.
|
||||
* This should be used as a proxy for the main network. One should send packets
|
||||
* and register receivers through this object.
|
||||
*
|
||||
* @return The node for this element.
|
||||
*/
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import dan200.computercraft.api.lua.GenericSource;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* A {@link GenericSource} which provides methods for a peripheral.
|
||||
*
|
||||
* Unlike a {@link GenericSource}, all methods <strong>should</strong> target the same type, for instance a
|
||||
* {@link BlockEntity} subclass or a capability interface. This is not currently enforced.
|
||||
*/
|
||||
public interface GenericPeripheral extends GenericSource
|
||||
{
|
||||
/**
|
||||
* Get the type of the exposed peripheral.
|
||||
*
|
||||
* Unlike normal {@link IPeripheral}s, {@link GenericPeripheral} do not have to have a type. By default, the
|
||||
* resulting peripheral uses the resource name of the wrapped {@link BlockEntity} (for instance {@literal minecraft:chest}).
|
||||
*
|
||||
* However, in some cases it may be more appropriate to specify a more readable name. Overriding this method allows
|
||||
* you to do so.
|
||||
*
|
||||
* When multiple {@link GenericPeripheral}s return a non-empty peripheral type for a single tile entity, the
|
||||
* lexicographically smallest will be chosen. In order to avoid this conflict, this method should only be
|
||||
* implemented when your peripheral targets a single tile entity <strong>AND</strong> it's likely that you're the
|
||||
* only mod to do so. Similarly this should <strong>NOT</strong> be implemented when your methods target an
|
||||
* interface (i.e. {@link Container}).
|
||||
*
|
||||
* @return The type of this peripheral or {@link PeripheralType#untyped()}.
|
||||
* @see IPeripheral#getType()
|
||||
*/
|
||||
@Nonnull
|
||||
default PeripheralType getType()
|
||||
{
|
||||
return PeripheralType.untyped();
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
@ -13,15 +12,16 @@ import dan200.computercraft.api.lua.ILuaCallback;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.lua.ILuaTask;
|
||||
import dan200.computercraft.api.lua.MethodResult;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The interface passed to peripherals by computers or turtles, providing methods that they can call. This should not be implemented by your classes. Do not
|
||||
* interact with computers except via this interface.
|
||||
* The interface passed to peripherals by computers or turtles, providing methods
|
||||
* that they can call. This should not be implemented by your classes. Do not interact
|
||||
* with computers except via this interface.
|
||||
*/
|
||||
public interface IComputerAccess
|
||||
{
|
||||
@ -30,10 +30,10 @@ public interface IComputerAccess
|
||||
*
|
||||
* @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
|
||||
* @param mount The mount object to mount on the computer.
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a file in the desired location.
|
||||
* Store this value if you wish to unmount the mount later.
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount, String)
|
||||
* @see #mountWritable(String, IWritableMount)
|
||||
@ -52,10 +52,10 @@ public interface IComputerAccess
|
||||
* @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
|
||||
* @param mount The mount object to mount on the computer.
|
||||
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a file in the desired location.
|
||||
* Store this value if you wish to unmount the mount later.
|
||||
* @return The location on the computer's file system where you the mount mounted, or {@code null} if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #mountWritable(String, IWritableMount)
|
||||
@ -65,26 +65,15 @@ public interface IComputerAccess
|
||||
@Nullable
|
||||
String mount( @Nonnull String desiredLocation, @Nonnull IMount mount, @Nonnull String driveName );
|
||||
|
||||
/**
|
||||
* Get a string, unique to the computer, by which the computer refers to this peripheral. For directly attached peripherals this will be
|
||||
* "left","right","front","back",etc, but for peripherals attached remotely it will be different. It is good practice to supply this string when raising
|
||||
* events to the computer, so that the computer knows from which peripheral the event came.
|
||||
*
|
||||
* @return A string unique to the computer, but not globally.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
*/
|
||||
@Nonnull
|
||||
String getAttachmentName();
|
||||
|
||||
/**
|
||||
* Mount a mount onto the computer's file system in a writable mode.
|
||||
*
|
||||
* @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
|
||||
* @param mount The mount object to mount on the computer.
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store
|
||||
* this value if you wish to unmount the mount later.
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #unmount(String)
|
||||
@ -102,10 +91,10 @@ public interface IComputerAccess
|
||||
* @param desiredLocation The location on the computer's file system where you would like the mount to be mounted.
|
||||
* @param mount The mount object to mount on the computer.
|
||||
* @param driveName A custom name to give for this mount location, as returned by {@code fs.getDrive()}.
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a file in the desired location. Store
|
||||
* this value if you wish to unmount the mount later.
|
||||
* @return The location on the computer's file system where you the mount mounted, or null if there was already a
|
||||
* file in the desired location. Store this value if you wish to unmount the mount later.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @see ComputerCraftAPI#createSaveDirMount(World, String, long)
|
||||
* @see ComputerCraftAPI#createSaveDirMount(Level, String, long)
|
||||
* @see ComputerCraftAPI#createResourceMount(String, String)
|
||||
* @see #mount(String, IMount)
|
||||
* @see #unmount(String)
|
||||
@ -114,16 +103,18 @@ public interface IComputerAccess
|
||||
String mountWritable( @Nonnull String desiredLocation, @Nonnull IWritableMount mount, @Nonnull String driveName );
|
||||
|
||||
/**
|
||||
* Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)} or {@link #mountWritable(String,
|
||||
* IWritableMount)}.
|
||||
* Unmounts a directory previously mounted onto the computers file system by {@link #mount(String, IMount)}
|
||||
* or {@link #mountWritable(String, IWritableMount)}.
|
||||
*
|
||||
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to access it. All directories
|
||||
* mounted by a mount or mountWritable are automatically unmounted when the peripheral is attached if they have not been explicitly unmounted.
|
||||
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be
|
||||
* able to access it. All directories mounted by a mount or mountWritable are automatically unmounted when the
|
||||
* peripheral is attached if they have not been explicitly unmounted.
|
||||
*
|
||||
* Note that you cannot unmount another peripheral's mounts.
|
||||
*
|
||||
* @param location The desired location in the computers file system of the directory to unmount. This must be the location of a directory
|
||||
* previously mounted by {@link #mount(String, IMount)} or {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
|
||||
* @param location The desired location in the computers file system of the directory to unmount.
|
||||
* This must be the location of a directory previously mounted by {@link #mount(String, IMount)} or
|
||||
* {@link #mountWritable(String, IWritableMount)}, as indicated by their return value.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
* @throws IllegalStateException If the mount does not exist, or was mounted by another peripheral.
|
||||
* @see #mount(String, IMount)
|
||||
@ -134,22 +125,26 @@ public interface IComputerAccess
|
||||
/**
|
||||
* Returns the numerical ID of this computer.
|
||||
*
|
||||
* This is the same number obtained by calling {@code os.getComputerID()} or running the "id" program from lua, and is guaranteed unique. This number
|
||||
* will be positive.
|
||||
* This is the same number obtained by calling {@code os.getComputerID()} or running the "id" program from lua,
|
||||
* and is guaranteed unique. This number will be positive.
|
||||
*
|
||||
* @return The identifier.
|
||||
*/
|
||||
int getID();
|
||||
|
||||
/**
|
||||
* Causes an event to be raised on this computer, which the computer can respond to by calling {@code os.pullEvent()}. This can be used to notify the
|
||||
* computer when things happen in the world or to this peripheral.
|
||||
* Causes an event to be raised on this computer, which the computer can respond to by calling
|
||||
* {@code os.pullEvent()}. This can be used to notify the computer when things happen in the world or to
|
||||
* this peripheral.
|
||||
*
|
||||
* @param event A string identifying the type of event that has occurred, this will be returned as the first value from {@code os.pullEvent()}. It
|
||||
* is recommended that you you choose a name that is unique, and recognisable as originating from your peripheral. eg: If your peripheral type is
|
||||
* "button", a suitable event would be "button_pressed".
|
||||
* @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will be supplied as extra return values to
|
||||
* os.pullEvent(). Objects in the array will be converted to lua data types in the same fashion as the return values of IPeripheral.callMethod().
|
||||
* @param event A string identifying the type of event that has occurred, this will be
|
||||
* returned as the first value from {@code os.pullEvent()}. It is recommended that you
|
||||
* you choose a name that is unique, and recognisable as originating from your
|
||||
* peripheral. eg: If your peripheral type is "button", a suitable event would be
|
||||
* "button_pressed".
|
||||
* @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will
|
||||
* be supplied as extra return values to os.pullEvent(). Objects in the array will be converted
|
||||
* to lua data types in the same fashion as the return values of IPeripheral.callMethod().
|
||||
*
|
||||
* You may supply {@code null} to indicate that no arguments are to be supplied.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
@ -157,6 +152,19 @@ public interface IComputerAccess
|
||||
*/
|
||||
void queueEvent( @Nonnull String event, @Nullable Object... arguments );
|
||||
|
||||
/**
|
||||
* Get a string, unique to the computer, by which the computer refers to this peripheral.
|
||||
* For directly attached peripherals this will be "left","right","front","back",etc, but
|
||||
* for peripherals attached remotely it will be different. It is good practice to supply
|
||||
* this string when raising events to the computer, so that the computer knows from
|
||||
* which peripheral the event came.
|
||||
*
|
||||
* @return A string unique to the computer, but not globally.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
*/
|
||||
@Nonnull
|
||||
String getAttachmentName();
|
||||
|
||||
/**
|
||||
* Get a set of peripherals that this computer access can "see", along with their attachment name.
|
||||
*
|
||||
@ -171,8 +179,8 @@ public interface IComputerAccess
|
||||
Map<String, IPeripheral> getAvailablePeripherals();
|
||||
|
||||
/**
|
||||
* Get a reachable peripheral with the given attachment name. This is a equivalent to {@link #getAvailablePeripherals()}{@code .get(name)}, though may
|
||||
* be more efficient.
|
||||
* Get a reachable peripheral with the given attachment name. This is a equivalent to
|
||||
* {@link #getAvailablePeripherals()}{@code .get(name)}, though may be more efficient.
|
||||
*
|
||||
* @param name The peripheral's attached name
|
||||
* @return The reachable peripheral, or {@code null} if none can be found.
|
||||
@ -184,11 +192,13 @@ public interface IComputerAccess
|
||||
/**
|
||||
* Get a {@link IWorkMonitor} for tasks your peripheral might execute on the main (server) thread.
|
||||
*
|
||||
* This should be used to ensure your peripheral integrates with ComputerCraft's monitoring and limiting of how much server time each computer consumes.
|
||||
* You should not need to use this if you use {@link ILuaContext#issueMainThreadTask(ILuaTask)} - this is intended for mods with their own system for
|
||||
* running work on the main thread.
|
||||
* This should be used to ensure your peripheral integrates with ComputerCraft's monitoring and limiting of how much
|
||||
* server time each computer consumes. You should not need to use this if you use
|
||||
* {@link ILuaContext#issueMainThreadTask(ILuaTask)} - this is intended for mods with their own system for running
|
||||
* work on the main thread.
|
||||
*
|
||||
* Please note that the returned implementation is <em>not</em> thread-safe, and should only be used from the main thread.
|
||||
* Please note that the returned implementation is <em>not</em> thread-safe, and should only be used from the main
|
||||
* thread.
|
||||
*
|
||||
* @return The work monitor for the main thread, or {@code null} if this computer does not have one.
|
||||
* @throws NotAttachedException If the peripheral has been detached.
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import dan200.computercraft.api.lua.*;
|
||||
@ -13,14 +12,14 @@ import javax.annotation.Nonnull;
|
||||
/**
|
||||
* A peripheral whose methods are not known at runtime.
|
||||
*
|
||||
* This behaves similarly to {@link IDynamicLuaObject}, though also accepting the current {@link IComputerAccess}. Generally one may use {@link LuaFunction}
|
||||
* instead of implementing this interface.
|
||||
* This behaves similarly to {@link IDynamicLuaObject}, though also accepting the current {@link IComputerAccess}.
|
||||
* Generally one may use {@link LuaFunction} instead of implementing this interface.
|
||||
*/
|
||||
public interface IDynamicPeripheral extends IPeripheral
|
||||
{
|
||||
/**
|
||||
* Should return an array of strings that identify the methods that this peripheral exposes to Lua. This will be called once before each attachment, and
|
||||
* should not change when called multiple times.
|
||||
* Should return an array of strings that identify the methods that this peripheral exposes to Lua. This will be
|
||||
* called once before each attachment, and should not change when called multiple times.
|
||||
*
|
||||
* @return An array of strings representing method names.
|
||||
* @see #callMethod
|
||||
@ -29,19 +28,24 @@ public interface IDynamicPeripheral extends IPeripheral
|
||||
String[] getMethodNames();
|
||||
|
||||
/**
|
||||
* This is called when a lua program on an attached computer calls {@code peripheral.call()} with one of the methods exposed by {@link
|
||||
* #getMethodNames()}.
|
||||
* This is called when a lua program on an attached computer calls {@code peripheral.call()} with
|
||||
* one of the methods exposed by {@link #getMethodNames()}.
|
||||
*
|
||||
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe when interacting with Minecraft objects.
|
||||
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe when interacting
|
||||
* with Minecraft objects.
|
||||
*
|
||||
* @param computer The interface to the computer that is making the call. Remember that multiple computers can be attached to a peripheral at once.
|
||||
* @param context The context of the currently running lua thread. This can be used to wait for events or otherwise yield.
|
||||
* @param method An integer identifying which of the methods from getMethodNames() the computercraft wishes to call. The integer indicates the index
|
||||
* into the getMethodNames() table that corresponds to the string passed into peripheral.call()
|
||||
* @param computer The interface to the computer that is making the call. Remember that multiple
|
||||
* computers can be attached to a peripheral at once.
|
||||
* @param context The context of the currently running lua thread. This can be used to wait for events
|
||||
* or otherwise yield.
|
||||
* @param method An integer identifying which of the methods from getMethodNames() the computercraft
|
||||
* wishes to call. The integer indicates the index into the getMethodNames() table
|
||||
* that corresponds to the string passed into peripheral.call()
|
||||
* @param arguments The arguments for this method.
|
||||
* @return A {@link MethodResult} containing the values to return or the action to perform.
|
||||
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the same message as your exception. Use this
|
||||
* to throw appropriate errors if the wrong arguments are supplied to your method.
|
||||
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the
|
||||
* same message as your exception. Use this to throw appropriate errors if the wrong
|
||||
* arguments are supplied to your method.
|
||||
* @see #getMethodNames()
|
||||
*/
|
||||
@Nonnull
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
@ -17,12 +16,14 @@ import javax.annotation.Nullable;
|
||||
* In order to expose a peripheral for your block or tile entity, you register a {@link IPeripheralProvider}. This <em>cannot</em> be implemented {@link
|
||||
* IPeripheral} directly on the tile.
|
||||
*
|
||||
* Peripherals should provide a series of methods to the user, either using {@link LuaFunction} or by implementing {@link IDynamicPeripheral}.
|
||||
* Peripherals should provide a series of methods to the user, either using {@link LuaFunction} or by implementing
|
||||
* {@link IDynamicPeripheral}.
|
||||
*/
|
||||
public interface IPeripheral
|
||||
{
|
||||
/**
|
||||
* Should return a string that uniquely identifies this type of peripheral. This can be queried from lua by calling {@code peripheral.getType()}
|
||||
* Should return a string that uniquely identifies this type of peripheral.
|
||||
* This can be queried from lua by calling {@code peripheral.getType()}
|
||||
*
|
||||
* @return A string identifying the type of peripheral.
|
||||
*/
|
||||
@ -32,15 +33,19 @@ public interface IPeripheral
|
||||
/**
|
||||
* Is called when when a computer is attaching to the peripheral.
|
||||
*
|
||||
* This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a peripheral, when a turtle travels into
|
||||
* a square next to a peripheral, or when a wired modem adjacent to this peripheral is does any of the above.
|
||||
* This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a
|
||||
* peripheral, when a turtle travels into a square next to a peripheral, or when a wired modem adjacent to this
|
||||
* peripheral is does any of the above.
|
||||
*
|
||||
* Between calls to attach and {@link #detach}, the attached computer can make method calls on the peripheral using {@code peripheral.call()}. This
|
||||
* method can be used to keep track of which computers are attached to the peripheral, or to take action when attachment occurs.
|
||||
* Between calls to attach and {@link #detach}, the attached computer can make method calls on the peripheral using
|
||||
* {@code peripheral.call()}. This method can be used to keep track of which computers are attached to the
|
||||
* peripheral, or to take action when attachment occurs.
|
||||
*
|
||||
* Be aware that will be called from both the server thread and ComputerCraft Lua thread, and so must be thread-safe and reentrant.
|
||||
* Be aware that will be called from both the server thread and ComputerCraft Lua thread, and so must be thread-safe
|
||||
* and reentrant.
|
||||
*
|
||||
* @param computer The interface to the computer that is being attached. Remember that multiple computers can be attached to a peripheral at once.
|
||||
* @param computer The interface to the computer that is being attached. Remember that multiple computers can be
|
||||
* attached to a peripheral at once.
|
||||
* @see #detach
|
||||
*/
|
||||
default void attach( @Nonnull IComputerAccess computer )
|
||||
@ -50,14 +55,18 @@ public interface IPeripheral
|
||||
/**
|
||||
* Called when a computer is detaching from the peripheral.
|
||||
*
|
||||
* This will occur when a computer shuts down, when the peripheral is removed while attached to computers, when a turtle moves away from a block
|
||||
* attached to a peripheral, or when a wired modem adjacent to this peripheral is detached.
|
||||
* This will occur when a computer shuts down, when the peripheral is removed while attached to computers, when a
|
||||
* turtle moves away from a block attached to a peripheral, or when a wired modem adjacent to this peripheral is
|
||||
* detached.
|
||||
*
|
||||
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment occurs.
|
||||
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when
|
||||
* detachment occurs.
|
||||
*
|
||||
* Be aware that this will be called from both the server and ComputerCraft Lua thread, and must be thread-safe and reentrant.
|
||||
* Be aware that this will be called from both the server and ComputerCraft Lua thread, and must be thread-safe
|
||||
* and reentrant.
|
||||
*
|
||||
* @param computer The interface to the computer that is being detached. Remember that multiple computers can be attached to a peripheral at once.
|
||||
* @param computer The interface to the computer that is being detached. Remember that multiple computers can be
|
||||
* attached to a peripheral at once.
|
||||
* @see #attach
|
||||
*/
|
||||
default void detach( @Nonnull IComputerAccess computer )
|
||||
@ -65,7 +74,8 @@ public interface IPeripheral
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object that this peripheral provides methods for. This will generally be the tile entity or block, but may be an inventory, entity, etc...
|
||||
* Get the object that this peripheral provides methods for. This will generally be the tile entity
|
||||
* or block, but may be an inventory, entity, etc...
|
||||
*
|
||||
* @return The object this peripheral targets
|
||||
*/
|
||||
@ -78,8 +88,8 @@ public interface IPeripheral
|
||||
/**
|
||||
* Determine whether this peripheral is equivalent to another one.
|
||||
*
|
||||
* The minimal example should at least check whether they are the same object. However, you may wish to check if they point to the same block or tile
|
||||
* entity.
|
||||
* The minimal example should at least check whether they are the same object. However, you may wish to check if
|
||||
* they point to the same block or tile entity.
|
||||
*
|
||||
* @param other The peripheral to compare against. This may be {@code null}.
|
||||
* @return Whether these peripherals are equivalent.
|
||||
|
@ -3,22 +3,18 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This interface is used to create peripheral implementations for blocks.
|
||||
*
|
||||
* If you have a {@link BlockEntity} which acts as a peripheral, you may alternatively expose the {@link IPeripheral} capability.
|
||||
*
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||
*/
|
||||
@FunctionalInterface
|
||||
@ -30,9 +26,9 @@ public interface IPeripheralProvider
|
||||
* @param world The world the block is in.
|
||||
* @param pos The position the block is at.
|
||||
* @param side The side to get the peripheral from.
|
||||
* @return A peripheral, or {@link Optional#empty()} if there is not a peripheral here you'd like to handle.
|
||||
* @return A peripheral or {@literal null} if there is not a peripheral here you'd like to handle.
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||
*/
|
||||
@Nonnull
|
||||
IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
@Nullable
|
||||
IPeripheral getPeripheral( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
|
@ -5,15 +5,15 @@
|
||||
*/
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A {@link net.minecraft.block.entity.BlockEntity} which may act as a peripheral.
|
||||
* A {@link net.minecraft.world.level.block.entity.BlockEntity} which may act as a peripheral.
|
||||
*
|
||||
* If you need more complex capabilities (such as handling TEs not belonging to your mod), you should use {@link IPeripheralProvider}.
|
||||
*/
|
||||
@ -24,7 +24,7 @@ public interface IPeripheralTile
|
||||
*
|
||||
* @param side The side to get the peripheral from.
|
||||
* @return A peripheral, or {@code null} if there is not a peripheral here.
|
||||
* @see IPeripheralProvider#getPeripheral(World, BlockPos, Direction)
|
||||
* @see IPeripheralProvider#getPeripheral(Level, BlockPos, Direction)
|
||||
*/
|
||||
@Nullable
|
||||
IPeripheral getPeripheral( @Nonnull Direction side );
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -11,14 +10,15 @@ import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Monitors "work" associated with a computer, keeping track of how much a computer has done, and ensuring every computer receives a fair share of any
|
||||
* processing time.
|
||||
* Monitors "work" associated with a computer, keeping track of how much a computer has done, and ensuring every
|
||||
* computer receives a fair share of any processing time.
|
||||
*
|
||||
* This is primarily intended for work done by peripherals on the main thread (such as on a tile entity's tick), but could be used for other purposes (such
|
||||
* as complex computations done on another thread).
|
||||
* This is primarily intended for work done by peripherals on the main thread (such as on a tile entity's tick), but
|
||||
* could be used for other purposes (such as complex computations done on another thread).
|
||||
*
|
||||
* Before running a task, one should call {@link #canWork()} to determine if the computer is currently allowed to execute work. If that returns true, you
|
||||
* should execute the task and use {@link #trackWork(long, TimeUnit)} to inform the monitor how long that task took.
|
||||
* Before running a task, one should call {@link #canWork()} to determine if the computer is currently allowed to
|
||||
* execute work. If that returns true, you should execute the task and use {@link #trackWork(long, TimeUnit)} to inform
|
||||
* the monitor how long that task took.
|
||||
*
|
||||
* Alternatively, use {@link #runWork(Runnable)} to run and keep track of work.
|
||||
*
|
||||
@ -26,16 +26,31 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public interface IWorkMonitor
|
||||
{
|
||||
/**
|
||||
* If the owning computer is currently allowed to execute work.
|
||||
*
|
||||
* @return If we can execute work right now.
|
||||
*/
|
||||
boolean canWork();
|
||||
|
||||
/**
|
||||
* If the owning computer is currently allowed to execute work, and has ample time to do so.
|
||||
*
|
||||
* This is effectively a more restrictive form of {@link #canWork()}. One should use that in order to determine if you may do an initial piece of work,
|
||||
* and shouldWork to determine if any additional task may be performed.
|
||||
* This is effectively a more restrictive form of {@link #canWork()}. One should use that in order to determine if
|
||||
* you may do an initial piece of work, and shouldWork to determine if any additional task may be performed.
|
||||
*
|
||||
* @return If we should execute work right now.
|
||||
*/
|
||||
boolean shouldWork();
|
||||
|
||||
/**
|
||||
* Inform the monitor how long some piece of work took to execute.
|
||||
*
|
||||
* @param time The time some task took to run
|
||||
* @param unit The unit that {@code time} was measured in.
|
||||
*/
|
||||
void trackWork( long time, @Nonnull TimeUnit unit );
|
||||
|
||||
/**
|
||||
* Run a task if possible, and inform the monitor of how long it took.
|
||||
*
|
||||
@ -45,10 +60,7 @@ public interface IWorkMonitor
|
||||
default boolean runWork( @Nonnull Runnable runnable )
|
||||
{
|
||||
Objects.requireNonNull( runnable, "runnable should not be null" );
|
||||
if( !canWork() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !canWork() ) return false;
|
||||
|
||||
long start = System.nanoTime();
|
||||
try
|
||||
@ -62,19 +74,4 @@ public interface IWorkMonitor
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the owning computer is currently allowed to execute work.
|
||||
*
|
||||
* @return If we can execute work right now.
|
||||
*/
|
||||
boolean canWork();
|
||||
|
||||
/**
|
||||
* Inform the monitor how long some piece of work took to execute.
|
||||
*
|
||||
* @param time The time some task took to run
|
||||
* @param unit The unit that {@code time} was measured in.
|
||||
*/
|
||||
void trackWork( long time, @Nonnull TimeUnit unit );
|
||||
}
|
||||
|
@ -3,11 +3,11 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
/**
|
||||
* Thrown when performing operations on {@link IComputerAccess} when the current peripheral is no longer attached to the computer.
|
||||
* Thrown when performing operations on {@link IComputerAccess} when the current peripheral is no longer attached to
|
||||
* the computer.
|
||||
*/
|
||||
public class NotAttachedException extends IllegalStateException
|
||||
{
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
package dan200.computercraft.api.peripheral;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* The type of a {@link GenericPeripheral}.
|
||||
*
|
||||
* When determining the final type of the resulting peripheral, the union of all types is taken, with the
|
||||
* lexicographically smallest non-empty name being chosen.
|
||||
*/
|
||||
public final class PeripheralType
|
||||
{
|
||||
private static final PeripheralType UNTYPED = new PeripheralType( null );
|
||||
|
||||
private final String type;
|
||||
|
||||
public PeripheralType( String type )
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty peripheral type, used when a {@link GenericPeripheral} does not have an explicit type.
|
||||
*
|
||||
* @return The empty peripheral type.
|
||||
*/
|
||||
public static PeripheralType untyped()
|
||||
{
|
||||
return UNTYPED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new non-empty peripheral type.
|
||||
*
|
||||
* @param type The name of the type.
|
||||
* @return The constructed peripheral type.
|
||||
*/
|
||||
public static PeripheralType ofType( @Nonnull String type )
|
||||
{
|
||||
if( Strings.isNullOrEmpty( type ) ) throw new IllegalArgumentException( "type cannot be null or empty" );
|
||||
return new PeripheralType( type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this peripheral type. This may be {@literal null}.
|
||||
*
|
||||
* @return The type of this peripheral.
|
||||
*/
|
||||
@Nullable
|
||||
public String getPrimaryType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
@ -3,15 +3,14 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.pocket;
|
||||
|
||||
import dan200.computercraft.shared.util.NonNullSupplier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Supplier;
|
||||
@ -23,55 +22,55 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||
{
|
||||
private final Identifier id;
|
||||
private final ResourceLocation id;
|
||||
private final String adjective;
|
||||
private final NonNullSupplier<ItemStack> stack;
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
this.id = id;
|
||||
this.adjective = adjective;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, NonNullSupplier<ItemStack> item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, NonNullSupplier<ItemStack> item )
|
||||
{
|
||||
this( id, Util.createTranslationKey( "upgrade", id ) + ".adjective", item );
|
||||
this( id, Util.makeDescriptionId( "upgrade", id ) + ".adjective", item );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemStack stack )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemStack stack )
|
||||
{
|
||||
this( id, adjective, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, ItemStack stack )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, ItemStack stack )
|
||||
{
|
||||
this( id, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemConvertible item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemLike item )
|
||||
{
|
||||
this( id, adjective, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, ItemConvertible item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, ItemLike item )
|
||||
{
|
||||
this( id, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, String adjective, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, adjective, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( Identifier id, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final Identifier getUpgradeID()
|
||||
public final ResourceLocation getUpgradeID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
@ -97,11 +96,11 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||
*/
|
||||
private static final class CachedStack implements NonNullSupplier<ItemStack>
|
||||
{
|
||||
private final Supplier<? extends ItemConvertible> provider;
|
||||
private final Supplier<? extends ItemLike> provider;
|
||||
private Item item;
|
||||
private ItemStack stack;
|
||||
|
||||
CachedStack( Supplier<? extends ItemConvertible> provider )
|
||||
CachedStack( Supplier<? extends ItemLike> provider )
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
@ -3,13 +3,12 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.pocket;
|
||||
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -33,7 +32,8 @@ public interface IPocketAccess
|
||||
/**
|
||||
* Get the colour of this pocket computer as a RGB number.
|
||||
*
|
||||
* @return The colour this pocket computer is. This will be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or -1 if it has no colour.
|
||||
* @return The colour this pocket computer is. This will be a RGB colour between {@code 0x000000} and
|
||||
* {@code 0xFFFFFF} or -1 if it has no colour.
|
||||
* @see #setColour(int)
|
||||
*/
|
||||
int getColour();
|
||||
@ -41,8 +41,8 @@ public interface IPocketAccess
|
||||
/**
|
||||
* Set the colour of the pocket computer to a RGB number.
|
||||
*
|
||||
* @param colour The colour this pocket computer should be changed to. This should be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or
|
||||
* -1 to reset to the default colour.
|
||||
* @param colour The colour this pocket computer should be changed to. This should be a RGB colour between
|
||||
* {@code 0x000000} and {@code 0xFFFFFF} or -1 to reset to the default colour.
|
||||
* @see #getColour()
|
||||
*/
|
||||
void setColour( int colour );
|
||||
@ -50,7 +50,8 @@ public interface IPocketAccess
|
||||
/**
|
||||
* Get the colour of this pocket computer's light as a RGB number.
|
||||
*
|
||||
* @return The colour this light is. This will be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or -1 if it has no colour.
|
||||
* @return The colour this light is. This will be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or
|
||||
* -1 if it has no colour.
|
||||
* @see #setLight(int)
|
||||
*/
|
||||
int getLight();
|
||||
@ -58,8 +59,8 @@ public interface IPocketAccess
|
||||
/**
|
||||
* Set the colour of the pocket computer's light to a RGB number.
|
||||
*
|
||||
* @param colour The colour this modem's light will be changed to. This should be a RGB colour between {@code 0x000000} and {@code 0xFFFFFF} or -1
|
||||
* to reset to the default colour.
|
||||
* @param colour The colour this modem's light will be changed to. This should be a RGB colour between
|
||||
* {@code 0x000000} and {@code 0xFFFFFF} or -1 to reset to the default colour.
|
||||
* @see #getLight()
|
||||
*/
|
||||
void setLight( int colour );
|
||||
@ -73,7 +74,7 @@ public interface IPocketAccess
|
||||
* @see #updateUpgradeNBTData()
|
||||
*/
|
||||
@Nonnull
|
||||
NbtCompound getUpgradeNBTData();
|
||||
CompoundTag getUpgradeNBTData();
|
||||
|
||||
/**
|
||||
* Mark the upgrade-specific NBT as dirty.
|
||||
@ -93,5 +94,5 @@ public interface IPocketAccess
|
||||
* @return A collection of all upgrade names.
|
||||
*/
|
||||
@Nonnull
|
||||
Map<Identifier, IPeripheral> getUpgrades();
|
||||
Map<ResourceLocation, IPeripheral> getUpgrades();
|
||||
}
|
||||
|
@ -3,13 +3,12 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.pocket;
|
||||
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.api.IUpgradeBase;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -24,8 +23,9 @@ public interface IPocketUpgrade extends IUpgradeBase
|
||||
/**
|
||||
* Creates a peripheral for the pocket computer.
|
||||
*
|
||||
* The peripheral created will be stored for the lifetime of the upgrade, will be passed an argument to {@link #update(IPocketAccess, IPeripheral)} and
|
||||
* will be attached, detached and have methods called in the same manner as an ordinary peripheral.
|
||||
* The peripheral created will be stored for the lifetime of the upgrade, will be passed an argument to
|
||||
* {@link #update(IPocketAccess, IPeripheral)} and will be attached, detached and have methods called in the same
|
||||
* manner as an ordinary peripheral.
|
||||
*
|
||||
* @param access The access object for the pocket item stack.
|
||||
* @return The newly created peripheral.
|
||||
@ -51,11 +51,12 @@ public interface IPocketUpgrade extends IUpgradeBase
|
||||
* @param world The world the computer is in.
|
||||
* @param access The access object for the pocket item stack.
|
||||
* @param peripheral The peripheral for this upgrade.
|
||||
* @return {@code true} to stop the GUI from opening, otherwise false. You should always provide some code path which returns {@code false}, such as
|
||||
* requiring the player to be sneaking - otherwise they will be unable to access the GUI.
|
||||
* @return {@code true} to stop the GUI from opening, otherwise false. You should always provide some code path
|
||||
* which returns {@code false}, such as requiring the player to be sneaking - otherwise they will be unable to
|
||||
* access the GUI.
|
||||
* @see #createPeripheral(IPocketAccess)
|
||||
*/
|
||||
default boolean onRightClick( @Nonnull World world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||
default boolean onRightClick( @Nonnull Level world, @Nonnull IPocketAccess access, @Nullable IPeripheral peripheral )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -3,12 +3,11 @@
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. This API may be redistributed unmodified and in full only.
|
||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||
*/
|
||||
|
||||
package dan200.computercraft.api.redstone;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -26,8 +25,9 @@ public interface IBundledRedstoneProvider
|
||||
* @param world The world this block is in.
|
||||
* @param pos The position this block is at.
|
||||
* @param side The side to extract the bundled redstone output from.
|
||||
* @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block.
|
||||
* @return A number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to
|
||||
* handle this block.
|
||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
||||
*/
|
||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
int getBundledRedstoneOutput( @Nonnull Level world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||
}
|
||||
|
@ -7,11 +7,11 @@
|
||||
package dan200.computercraft.api.turtle;
|
||||
|
||||
import dan200.computercraft.shared.util.NonNullSupplier;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Supplier;
|
||||
@ -23,12 +23,12 @@ import java.util.function.Supplier;
|
||||
*/
|
||||
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
{
|
||||
private final Identifier id;
|
||||
private final ResourceLocation id;
|
||||
private final TurtleUpgradeType type;
|
||||
private final String adjective;
|
||||
private final NonNullSupplier<ItemStack> stack;
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
@ -36,44 +36,44 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, NonNullSupplier<ItemStack> stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
this( id, type, Util.createTranslationKey( "upgrade", id ) + ".adjective", stack );
|
||||
this( id, type, Util.makeDescriptionId( "upgrade", id ) + ".adjective", stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||
{
|
||||
this( id, type, adjective, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemStack stack )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, ItemStack stack )
|
||||
{
|
||||
this( id, type, () -> stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemConvertible item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemLike item )
|
||||
{
|
||||
this( id, type, adjective, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemConvertible item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, ItemLike item )
|
||||
{
|
||||
this( id, type, new CachedStack( () -> item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, type, adjective, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, Supplier<? extends ItemConvertible> item )
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, Supplier<? extends ItemLike> item )
|
||||
{
|
||||
this( id, type, new CachedStack( item ) );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final Identifier getUpgradeID()
|
||||
public final ResourceLocation getUpgradeID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
@ -106,11 +106,11 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
*/
|
||||
private static final class CachedStack implements NonNullSupplier<ItemStack>
|
||||
{
|
||||
private final Supplier<? extends ItemConvertible> provider;
|
||||
private final Supplier<? extends ItemLike> provider;
|
||||
private Item item;
|
||||
private ItemStack stack;
|
||||
|
||||
CachedStack( Supplier<? extends ItemConvertible> provider )
|
||||
CachedStack( Supplier<? extends ItemLike> provider )
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
@ -9,30 +9,34 @@ import com.mojang.authlib.GameProfile;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import net.minecraft.block.entity.CommandBlockBlockEntity;
|
||||
import net.minecraft.block.entity.SignBlockEntity;
|
||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.passive.HorseBaseEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.*;
|
||||
import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket;
|
||||
import net.minecraft.network.packet.c2s.play.VehicleMoveC2SPacket;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.village.TradeOfferList;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.ConnectionProtocol;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.trading.MerchantOffers;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.block.entity.CommandBlockEntity;
|
||||
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.crypto.Cipher;
|
||||
@ -41,26 +45,26 @@ import java.util.OptionalInt;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A wrapper for {@link ServerPlayerEntity} which denotes a "fake" player.
|
||||
* A wrapper for {@link ServerPlayer} which denotes a "fake" player.
|
||||
*
|
||||
* Please note that this does not implement any of the traditional fake player behaviour. It simply exists to prevent me passing in normal players.
|
||||
*/
|
||||
public class FakePlayer extends ServerPlayerEntity
|
||||
public class FakePlayer extends ServerPlayer
|
||||
{
|
||||
public FakePlayer( ServerWorld world, GameProfile gameProfile )
|
||||
public FakePlayer( ServerLevel world, GameProfile gameProfile )
|
||||
{
|
||||
super( world.getServer(), world, gameProfile );
|
||||
networkHandler = new FakeNetHandler( this );
|
||||
connection = new FakeNetHandler( this );
|
||||
}
|
||||
|
||||
// region Direct networkHandler access
|
||||
@Override
|
||||
public void enterCombat()
|
||||
public void onEnterCombat()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endCombat()
|
||||
public void onLeaveCombat()
|
||||
{
|
||||
}
|
||||
|
||||
@ -70,23 +74,23 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTick()
|
||||
public void doTick()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath( DamageSource damage )
|
||||
public void die( DamageSource damage )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity moveToWorld( ServerWorld destination )
|
||||
public Entity changeDimension( ServerLevel destination )
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void wakeUp( boolean bl, boolean updateSleepingPlayers )
|
||||
public void stopSleepInBed( boolean bl, boolean updateSleepingPlayers )
|
||||
{
|
||||
|
||||
}
|
||||
@ -103,33 +107,33 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openEditSignScreen( SignBlockEntity tile )
|
||||
public void openTextEdit( SignBlockEntity tile )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public OptionalInt openHandledScreen( @Nullable NamedScreenHandlerFactory container )
|
||||
public OptionalInt openMenu( @Nullable MenuProvider container )
|
||||
{
|
||||
return OptionalInt.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTradeOffers( int id, TradeOfferList list, int level, int experience, boolean levelled, boolean refreshable )
|
||||
public void sendMerchantOffers( int id, MerchantOffers list, int level, int experience, boolean levelled, boolean refreshable )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openHorseInventory( HorseBaseEntity horse, Inventory inventory )
|
||||
public void openHorseInventory( AbstractHorse horse, Container inventory )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useBook( ItemStack stack, Hand hand )
|
||||
public void openItemGui( ItemStack stack, InteractionHand hand )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openCommandBlockScreen( CommandBlockBlockEntity block )
|
||||
public void openCommandBlock( CommandBlockEntity block )
|
||||
{
|
||||
}
|
||||
|
||||
@ -149,7 +153,7 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void closeHandledScreen()
|
||||
public void closeContainer()
|
||||
{
|
||||
}
|
||||
|
||||
@ -159,55 +163,55 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int unlockRecipes( Collection<Recipe<?>> recipes )
|
||||
public int awardRecipes( Collection<Recipe<?>> recipes )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Indirect
|
||||
@Override
|
||||
public int lockRecipes( Collection<Recipe<?>> recipes )
|
||||
public int resetRecipes( Collection<Recipe<?>> recipes )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage( Text textComponent, boolean status )
|
||||
public void displayClientMessage( Component textComponent, boolean status )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void consumeItem()
|
||||
protected void completeUsingItem()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookAt( EntityAnchorArgumentType.EntityAnchor anchor, Vec3d vec3d )
|
||||
public void lookAt( EntityAnchorArgument.Anchor anchor, Vec3 vec3d )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lookAtEntity( EntityAnchorArgumentType.EntityAnchor self, Entity entity, EntityAnchorArgumentType.EntityAnchor target )
|
||||
public void lookAt( EntityAnchorArgument.Anchor self, Entity entity, EntityAnchorArgument.Anchor target )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectApplied( StatusEffectInstance statusEffectInstance, @Nullable Entity source )
|
||||
protected void onEffectAdded( MobEffectInstance statusEffectInstance, @Nullable Entity source )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectUpgraded( StatusEffectInstance statusEffectInstance, boolean particles, @Nullable Entity source )
|
||||
protected void onEffectUpdated( MobEffectInstance statusEffectInstance, boolean particles, @Nullable Entity source )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStatusEffectRemoved( StatusEffectInstance statusEffectInstance )
|
||||
protected void onEffectRemoved( MobEffectInstance statusEffectInstance )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestTeleport( double x, double y, double z )
|
||||
public void teleportTo( double x, double y, double z )
|
||||
{
|
||||
}
|
||||
|
||||
@ -217,13 +221,13 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void sendMessage( Text message, MessageType type, UUID senderUuid )
|
||||
public void sendMessage( Component message, ChatType type, UUID senderUuid )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIp()
|
||||
public String getIpAddress()
|
||||
{
|
||||
return "[Fake Player]";
|
||||
}
|
||||
@ -239,63 +243,63 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void setCameraEntity( Entity entity )
|
||||
public void setCamera( Entity entity )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teleport( ServerWorld serverWorld, double x, double y, double z, float pitch, float yaw )
|
||||
public void teleportTo( ServerLevel serverWorld, double x, double y, double z, float pitch, float yaw )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendInitialChunkPackets( ChunkPos chunkPos, Packet<?> packet, Packet<?> packet2 )
|
||||
public void trackChunk( ChunkPos chunkPos, Packet<?> packet, Packet<?> packet2 )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendUnloadChunkPacket( ChunkPos chunkPos )
|
||||
public void untrackChunk( ChunkPos chunkPos )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound( SoundEvent soundEvent, SoundCategory soundCategory, float volume, float pitch )
|
||||
public void playNotifySound( SoundEvent soundEvent, SoundSource soundCategory, float volume, float pitch )
|
||||
{
|
||||
}
|
||||
|
||||
private static class FakeNetHandler extends ServerPlayNetworkHandler
|
||||
private static class FakeNetHandler extends ServerGamePacketListenerImpl
|
||||
{
|
||||
FakeNetHandler( ServerPlayerEntity player )
|
||||
FakeNetHandler( ServerPlayer player )
|
||||
{
|
||||
super( player.server, new FakeConnection(), player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect( Text message )
|
||||
public void disconnect( Component message )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVehicleMove( VehicleMoveC2SPacket move )
|
||||
public void handleMoveVehicle( ServerboundMoveVehiclePacket move )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestCommandCompletions( RequestCommandCompletionsC2SPacket packet )
|
||||
public void handleCustomCommandSuggestions( ServerboundCommandSuggestionPacket packet )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPacket( Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> listener )
|
||||
public void send( Packet<?> packet, @Nullable GenericFutureListener<? extends Future<? super Void>> listener )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static class FakeConnection extends ClientConnection
|
||||
private static class FakeConnection extends Connection
|
||||
{
|
||||
FakeConnection()
|
||||
{
|
||||
super( NetworkSide.CLIENTBOUND );
|
||||
super( PacketFlow.CLIENTBOUND );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -304,7 +308,7 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState( NetworkState state )
|
||||
public void setProtocol( ConnectionProtocol state )
|
||||
{
|
||||
}
|
||||
|
||||
@ -329,18 +333,18 @@ public class FakePlayer extends ServerPlayerEntity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect( Text message )
|
||||
public void disconnect( Component message )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupEncryption( Cipher cipher, Cipher cipher2 )
|
||||
public void setEncryptionKey( Cipher cipher, Cipher cipher2 )
|
||||
{
|
||||
super.setupEncryption( cipher, cipher2 );
|
||||
super.setEncryptionKey( cipher, cipher2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disableAutoRead()
|
||||
public void setReadOnly()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user