mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-03 15:13:07 +00:00
Compare commits
54 Commits
v1.19-1.10
...
v1.18.2-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08895cdecc | ||
|
|
5be290a1e2 | ||
|
|
371f931140 | ||
|
|
da5956e943 | ||
|
|
e7533f2353 | ||
|
|
0b7fbcde53 | ||
|
|
c3b7302108 | ||
|
|
61ac48c99f | ||
|
|
d22e138413 | ||
|
|
ba64e06ca7 | ||
|
|
db8c979a06 | ||
|
|
9d18487dc5 | ||
|
|
feb7681c9c | ||
|
|
ad4a2aa68d | ||
|
|
4228011b84 | ||
|
|
bd19fdf350 | ||
|
|
e2041f7438 | ||
|
|
d61202e2b8 | ||
|
|
6ce88a7dcf | ||
|
|
5d65b3e654 | ||
|
|
abf857f864 | ||
|
|
ebef3117f2 | ||
|
|
b28c1ac8e0 | ||
|
|
69b211b4fb | ||
|
|
48147fa61c | ||
|
|
ba976f9a16 | ||
|
|
969feb4a1c | ||
|
|
bd5de11ad5 | ||
|
|
5366fcb9c8 | ||
|
|
6335e77da6 | ||
|
|
4cfd0a2d1c | ||
|
|
be3a960273 | ||
|
|
f25a73b8f2 | ||
|
|
954254e7e4 | ||
|
|
56f0e0674f | ||
|
|
4e438df9ad | ||
|
|
51c3a9d8af | ||
|
|
d967730085 | ||
|
|
d6afee8deb | ||
|
|
41bddcab9f | ||
|
|
b8d7695392 | ||
|
|
b7fa4102df | ||
|
|
d2f94f2653 | ||
|
|
718111787c | ||
|
|
bb0e449560 | ||
|
|
ee495b3359 | ||
|
|
d1e952770d | ||
|
|
2d30208631 | ||
|
|
03f50f9298 | ||
|
|
1a0e3fc2fa | ||
|
|
6d5b13dbbc | ||
|
|
f9f8233ef4 | ||
|
|
b7f698d6f7 | ||
|
|
93f3cd4a53 |
2
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
2
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
@@ -9,8 +9,8 @@ body:
|
||||
description: What version of Minecraft are you using?
|
||||
options:
|
||||
- 1.16.x
|
||||
- 1.17.x
|
||||
- 1.18.x
|
||||
- 1.19.x
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
|
||||
5
.github/ISSUE_TEMPLATE/config.yml
vendored
5
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,8 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: ComputerCraft Discord
|
||||
url: https://discord.computercraft.cc
|
||||
about: Get help on the ComputerCraft Discord.
|
||||
- name: GitHub Discussions
|
||||
url: https://github.com/cc-tweaked/CC-Tweaked/discussions
|
||||
about: Or ask questions on GitHub Discussions.
|
||||
about: Ask questions on GitHub Discussions.
|
||||
|
||||
27
.github/workflows/main-ci.yml
vendored
27
.github/workflows/main-ci.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
with:
|
||||
java-version: 8
|
||||
|
||||
- name: Cache gradle dependencies
|
||||
- name: Cache Gradle dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
@@ -32,7 +32,7 @@ jobs:
|
||||
run: |
|
||||
./gradlew assemble || ./gradlew assemble
|
||||
./gradlew downloadAssets || ./gradlew downloadAssets
|
||||
xvfb-run ./gradlew build
|
||||
./gradlew build
|
||||
|
||||
- name: Upload Jar
|
||||
uses: actions/upload-artifact@v2
|
||||
@@ -40,31 +40,12 @@ jobs:
|
||||
name: CC-Tweaked
|
||||
path: build/libs
|
||||
|
||||
- name: Upload Screnshots
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Screenshots
|
||||
path: test-files/client/screenshots
|
||||
if-no-files-found: ignore
|
||||
retention-days: 5
|
||||
if: failure()
|
||||
|
||||
- name: Upload Coverage
|
||||
- name: Upload coverage
|
||||
uses: codecov/codecov-action@v2
|
||||
|
||||
- name: Parse test reports
|
||||
run: ./tools/parse-reports.py
|
||||
if: ${{ failure() }}
|
||||
|
||||
- name: Cache pre-commit
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.cache/pre-commit
|
||||
key: ${{ runner.os }}-pre-commit-${{ hashFiles('config/pre-commit/config.yml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pre-commit-
|
||||
|
||||
- name: Run linters
|
||||
run: |
|
||||
pip install pre-commit
|
||||
pre-commit run --config config/pre-commit/config.yml --show-diff-on-failure --all --color=always
|
||||
uses: pre-commit/action@v3.0.0
|
||||
|
||||
6
.github/workflows/make-doc.yml
vendored
6
.github/workflows/make-doc.yml
vendored
@@ -26,12 +26,6 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- name: Setup illuaminate
|
||||
run: |
|
||||
test -d bin || mkdir bin
|
||||
test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/linux-x86-64/illuaminate
|
||||
chmod +x bin/illuaminate
|
||||
|
||||
- name: Setup node
|
||||
run: npm ci
|
||||
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
/classes
|
||||
/logs
|
||||
/build
|
||||
/buildSrc/build
|
||||
/out
|
||||
/doc/out/
|
||||
/node_modules
|
||||
|
||||
@@ -17,6 +17,6 @@ vscode:
|
||||
|
||||
tasks:
|
||||
- name: Setup pre-commit hool
|
||||
init: pre-commit install --config config/pre-commit/config.yml --allow-missing-config
|
||||
init: pre-commit install --allow-missing-config
|
||||
- name: Install npm packages
|
||||
init: npm ci
|
||||
|
||||
@@ -41,8 +41,8 @@ repos:
|
||||
- id: illuaminate
|
||||
name: Check Lua code
|
||||
files: ".*\\.(lua|java|md)"
|
||||
language: script
|
||||
entry: config/pre-commit/illuaminate-lint.sh
|
||||
language: system
|
||||
entry: ./gradlew lintLua -i
|
||||
pass_filenames: false
|
||||
require_serial: true
|
||||
|
||||
133
CODE_OF_CONDUCT.md
Normal file
133
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,133 @@
|
||||
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
We as members, contributors, and leaders pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, caste, color, religion, or sexual
|
||||
identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the overall
|
||||
community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or advances of
|
||||
any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email address,
|
||||
without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Community leaders are responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Community leaders have the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies within all community spaces, and also applies when
|
||||
an individual is officially representing the community in public spaces.
|
||||
Examples of representing our community include using an official e-mail address,
|
||||
posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported to the community leaders responsible for enforcement at
|
||||
"conduct AT squiddev DOT cc". All complaints will be reviewed and investigated
|
||||
promptly and fairly.
|
||||
|
||||
All community leaders are obligated to respect the privacy and security of the
|
||||
reporter of any incident.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series of
|
||||
actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or permanent
|
||||
ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within the
|
||||
community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.1, available at
|
||||
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||
|
||||
Community Impact Guidelines were inspired by
|
||||
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
||||
[https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||
[FAQ]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
||||
@@ -39,40 +39,30 @@ are run whenever you submit a PR, it's often useful to run this before committin
|
||||
|
||||
- **[Checkstyle]:** Checks Java code to ensure it is consistently formatted. This can be run with `./gradlew build` or
|
||||
`./gradle check`.
|
||||
- **[illuaminate]:** Checks Lua code for semantic and styleistic issues. See [the usage section][illuaminate-usage] for
|
||||
how to download and run it. You may need to generate the Java documentation stubs (see "Documentation" below) for all
|
||||
lints to pass.
|
||||
- **[illuaminate]:** Checks Lua code for semantic and styleistic issues. This can be run with `./gradlew lintLua`.
|
||||
|
||||
### Documentation
|
||||
When writing documentation for [CC: Tweaked's documentation website][docs], it may be useful to build the documentation
|
||||
and preview it yourself before submitting a PR.
|
||||
|
||||
Building all documentation is, sadly, a multi-stage process (though this is largely hidden by Gradle). First we need to
|
||||
convert Java doc-comments into Lua ones, we also generate some Javascript to embed. All of this is then finally fed into
|
||||
illuaminate, which spits out our HTML.
|
||||
Our documentation generation pipeline is rather complex, and involves invoking several external tools. Most of this
|
||||
complexity is hidden by Gradle, but you will need to perform some initial setup:
|
||||
|
||||
#### Setting up the tooling
|
||||
For various reasons, getting the environment set up to build documentation can be pretty complex. I'd quite like to
|
||||
automate this via Docker and/or nix in the future, but this needs to be done manually for now.
|
||||
- Install [Node/npm][node].
|
||||
- Run `npm ci` to install our Node dependencies.
|
||||
|
||||
This tooling is only needed if you need to build the whole website. If you just want to generate the Lua stubs, you can
|
||||
skp this section.
|
||||
- Install Node/npm and install our Node packages with `npm ci`.
|
||||
- Install [illuaminate][illuaminate-usage] as described above.
|
||||
|
||||
#### Building documentation
|
||||
Gradle should be your entrypoint to building most documentation. There's two tasks which are of interest:
|
||||
|
||||
- `./gradlew luaJavadoc` - Generate documentation stubs for Java methods.
|
||||
- `./gradlew docWebsite` - Generate the whole website (including Javascript pages). The resulting HTML is stored at
|
||||
`./build/docs/site/`.
|
||||
You can now run `./gradlew docWebsite`. This generates documentation from our Lua and Java code, writing the resulting
|
||||
HTML into `./build/docs/site`.
|
||||
|
||||
#### Writing documentation
|
||||
illuaminate's documentation system is not currently documented (somewhat ironic), but is _largely_ the same as
|
||||
[ldoc][ldoc]. Documentation comments are written in Markdown,
|
||||
|
||||
Our markdown engine does _not_ support GitHub flavoured markdown, and so does not support all the features one might
|
||||
expect (such as tables). It is very much recommended that you build and preview the docs locally first.
|
||||
expect. It is recommended that you build and preview the docs locally first.
|
||||
|
||||
When iterating on documentation, you can get Gradle to rebuild the website every time a file changes by running
|
||||
`./gradlew docWebsite -t`. This will take a couple of seconds to run, but definitely beats running it manually!
|
||||
|
||||
### Testing
|
||||
Thankfully running tests is much simpler than running the documentation generator! `./gradlew check` will run the
|
||||
@@ -90,11 +80,10 @@ Before we get into writing tests, it's worth mentioning the various test suites
|
||||
|
||||
These tests are run by the '"Core" Java' test suite, and so are also run with `./gradlew test`.
|
||||
|
||||
- In-game (`./src/testMod/java/dan200/computercraft/ingame/`): These tests are run on an actual Minecraft server and client,
|
||||
using [the same system Mojang do][mc-test]. The aim of these is to test in-game behaviour of blocks and peripherals.
|
||||
- In-game (`./src/testMod/java/dan200/computercraft/ingame/`): These tests are run on an actual Minecraft server, using
|
||||
the same system Mojang do][mc-test]. The aim of these is to test in-game behaviour of blocks and peripherals.
|
||||
|
||||
These are run by `./gradlew testClient` and `./gradlew testServer`. You may want to run the client under `xvfb-run`
|
||||
or similar when running in a headless environment.
|
||||
These tests are run with `./gradlew testServer`.
|
||||
|
||||
## CraftOS tests
|
||||
CraftOS's tests are written using a test system called "mcfly", heavily inspired by [busted] (and thus RSpec). Groups of
|
||||
@@ -107,9 +96,9 @@ asserts that your variable `foo` is equal to the expected value `"bar"`.
|
||||
[community]: README.md#Community "Get in touch with the community."
|
||||
[checkstyle]: https://checkstyle.org/
|
||||
[illuaminate]: https://github.com/SquidDev/illuaminate/ "Illuaminate on GitHub"
|
||||
[illuaminate-usage]: https://github.com/SquidDev/illuaminate/blob/master/README.md#usage "Installing Illuaminate"
|
||||
[weblate]: https://i18n.tweaked.cc/projects/cc-tweaked/minecraft/ "CC: Tweaked weblate instance"
|
||||
[docs]: https://tweaked.cc/ "CC: Tweaked documentation"
|
||||
[ldoc]: http://stevedonovan.github.io/ldoc/ "ldoc, a Lua documentation generator."
|
||||
[mc-test]: https://www.youtube.com/watch?v=vXaWOJTCYNg
|
||||
[busted]: https://github.com/Olivine-Labs/busted "busted: Elegant Lua unit testing."
|
||||
[node]: https://nodejs.org/en/ "Node.js"
|
||||
|
||||
11
README.md
11
README.md
@@ -13,9 +13,8 @@ developing the mod, [check out the instructions here](CONTRIBUTING.md#developing
|
||||
|
||||
## Community
|
||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
|
||||
ComputerCraft we have a [forum](https://forums.computercraft.cc/) and [Discord guild](https://discord.computercraft.cc)!
|
||||
There's also a fairly populated, albeit quiet [IRC channel](http://webchat.esper.net/?channels=computercraft), if that's
|
||||
more your cup of tea.
|
||||
ComputerCraft, do check out our [forum] and [GitHub discussions page][GitHub discussions]! There's also a fairly
|
||||
populated, albeit quiet [IRC channel][irc], if that's more your cup of tea.
|
||||
|
||||
We also host fairly comprehensive documentation at [tweaked.cc](https://tweaked.cc/ "The CC: Tweaked website").
|
||||
|
||||
@@ -35,7 +34,8 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fg.deobf("org.squiddev:cc-tweaked-${mc_version}:${cct_version}")
|
||||
compileOnly fg.deobf("org.squiddev:cc-tweaked-${mc_version}:${cct_version}:api")
|
||||
runtimeOnly fg.deobf("org.squiddev:cc-tweaked-${mc_version}:${cct_version}")
|
||||
}
|
||||
```
|
||||
|
||||
@@ -51,3 +51,6 @@ the generated documentation [can be browsed online](https://tweaked.cc/javadoc/)
|
||||
[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"
|
||||
[forum]: https://forums.computercraft.cc/
|
||||
[GitHub Discussions]: https://github.com/cc-tweaked/CC-Tweaked/discussions
|
||||
[IRC]: http://webchat.esper.net/?channels=computercraft "#computercraft on EsperNet"
|
||||
|
||||
284
build.gradle
284
build.gradle
@@ -1,30 +1,22 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url = "https://maven.minecraftforge.net" }
|
||||
maven { url = 'https://maven.parchmentmc.org' }
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:5.1.+'
|
||||
classpath "org.spongepowered:mixingradle:0.7.+"
|
||||
classpath 'org.parchmentmc:librarian:1.+'
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "checkstyle"
|
||||
id "jacoco"
|
||||
id "maven-publish"
|
||||
id "com.github.hierynomus.license" version "0.16.1"
|
||||
id "org.cadixdev.licenser" version "0.6.1"
|
||||
id "com.matthewprenger.cursegradle" version "1.4.0"
|
||||
id "com.github.breadmoirai.github-release" version "2.2.12"
|
||||
id "org.jetbrains.kotlin.jvm" version "1.6.0"
|
||||
id "com.modrinth.minotaur" version "1.2.1"
|
||||
id "org.jetbrains.kotlin.jvm" version "1.7.0"
|
||||
id "com.modrinth.minotaur" version "2.+"
|
||||
id "net.minecraftforge.gradle" version "5.1.+"
|
||||
id "org.spongepowered.mixin" version "0.7.+"
|
||||
id "org.parchmentmc.librarian.forgegradle" version "1.+"
|
||||
id "com.github.johnrengelman.shadow" version "7.1.2"
|
||||
id "cc-tweaked.illuaminate"
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
apply plugin: "org.spongepowered.mixin"
|
||||
apply plugin: 'org.parchmentmc.librarian.forgegradle'
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
import cc.tweaked.gradle.IlluaminateExec
|
||||
import cc.tweaked.gradle.IlluaminateExecToDir
|
||||
|
||||
version = mod_version
|
||||
|
||||
@@ -39,12 +31,7 @@ java {
|
||||
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
tasks.withType(JavaExec).configureEach {
|
||||
javaLauncher = javaToolchains.launcherFor {
|
||||
languageVersion = javaVersion
|
||||
}
|
||||
registerFeature("extraMods") { usingSourceSet(sourceSets.main) }
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
@@ -64,6 +51,7 @@ minecraft {
|
||||
|
||||
property 'forge.logging.markers', 'REGISTRIES'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
forceExit = false
|
||||
|
||||
mods {
|
||||
computercraft {
|
||||
@@ -108,6 +96,8 @@ minecraft {
|
||||
gameTestServer {
|
||||
workingDirectory project.file('test-files/server')
|
||||
|
||||
property("forge.logging.console.level", "info")
|
||||
|
||||
mods {
|
||||
cctest {
|
||||
source sourceSets.testMod
|
||||
@@ -132,6 +122,10 @@ mixin {
|
||||
add sourceSets.main, 'computercraft.mixins.refmap.json'
|
||||
}
|
||||
|
||||
reobf {
|
||||
shadowJar {}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
@@ -141,7 +135,7 @@ repositories {
|
||||
}
|
||||
|
||||
configurations {
|
||||
shade
|
||||
shade { transitive = false }
|
||||
implementation.extendsFrom shade
|
||||
|
||||
cctJavadoc
|
||||
@@ -157,8 +151,9 @@ dependencies {
|
||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
||||
annotationProcessor 'org.spongepowered:mixin:0.8.4:processor'
|
||||
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.116:api")
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.116")
|
||||
extraModsCompileOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.116:api")
|
||||
extraModsRuntimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.116")
|
||||
extraModsCompileOnly fg.deobf("maven.modrinth:oculus:1.18.2-1.2.5")
|
||||
|
||||
shade 'org.squiddev:Cobalt:0.5.5'
|
||||
|
||||
@@ -166,28 +161,36 @@ dependencies {
|
||||
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.6.0'
|
||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
|
||||
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0'
|
||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2'
|
||||
|
||||
testModImplementation sourceSets.main.output
|
||||
testModExtra('org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0') {
|
||||
exclude group: "org.jetbrains", module: "annotations"
|
||||
}
|
||||
|
||||
cctJavadoc 'cc.tweaked:cct-javadoc:1.4.6'
|
||||
cctJavadoc 'cc.tweaked:cct-javadoc:1.4.7'
|
||||
}
|
||||
|
||||
illuaminate {
|
||||
version.set("0.1.0-3-g0f40379")
|
||||
}
|
||||
|
||||
// Compile tasks
|
||||
|
||||
compileTestModJava {
|
||||
dependsOn(compileJava)
|
||||
}
|
||||
|
||||
javadoc {
|
||||
include "dan200/computercraft/api/**/*.java"
|
||||
}
|
||||
|
||||
task luaJavadoc(type: Javadoc) {
|
||||
def apiJar = tasks.register("apiJar", Jar.class) {
|
||||
archiveClassifier.set("api")
|
||||
from(sourceSets.main.output) {
|
||||
include "dan200/computercraft/api/**/*"
|
||||
}
|
||||
}
|
||||
assemble.dependsOn(apiJar)
|
||||
|
||||
def luaJavadoc = tasks.register("luaJavadoc", Javadoc.class) {
|
||||
description "Generates documentation for Java-side Lua functions."
|
||||
group "documentation"
|
||||
|
||||
@@ -205,6 +208,9 @@ task luaJavadoc(type: Javadoc) {
|
||||
}
|
||||
|
||||
jar {
|
||||
finalizedBy("reobfJar")
|
||||
|
||||
archiveClassifier.set("slim")
|
||||
manifest {
|
||||
attributes([
|
||||
"Specification-Title" : "computercraft",
|
||||
@@ -213,18 +219,28 @@ jar {
|
||||
"Implementation-Title" : "CC: Tweaked",
|
||||
"Implementation-Version" : "${mod_version}",
|
||||
"Implementation-Vendor" : "SquidDev",
|
||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
,
|
||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
|
||||
"MixinConfigs" : "computercraft.mixins.json",
|
||||
])
|
||||
}
|
||||
|
||||
from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
|
||||
jar.finalizedBy('reobfJar')
|
||||
shadowJar {
|
||||
finalizedBy("reobfShadowJar")
|
||||
|
||||
[compileJava, compileTestJava, compileTestModJava].forEach {
|
||||
archiveClassifier.set("")
|
||||
configurations = [project.configurations.shade]
|
||||
relocate("org.squiddev.cobalt", "cc.tweaked.internal.cobalt")
|
||||
minimize()
|
||||
}
|
||||
|
||||
assemble.dependsOn("shadowJar")
|
||||
|
||||
[
|
||||
tasks.named("compileJava", JavaCompile.class),
|
||||
tasks.named("compileTestJava", JavaCompile.class),
|
||||
tasks.named("compileTestModJava", JavaCompile.class)
|
||||
].forEach {
|
||||
it.configure {
|
||||
options.compilerArgs << "-Xlint" << "-Xlint:-processing"
|
||||
}
|
||||
@@ -288,17 +304,11 @@ sourcesJar {
|
||||
|
||||
// Web tasks
|
||||
|
||||
|
||||
import com.hierynomus.gradle.license.tasks.LicenseCheck
|
||||
import com.hierynomus.gradle.license.tasks.LicenseFormat
|
||||
import com.modrinth.minotaur.TaskModrinthUpload
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
|
||||
List<String> mkCommand(String command) {
|
||||
return Os.isFamily(Os.FAMILY_WINDOWS) ? ["cmd", "/c", command] : ["sh", "-c", command]
|
||||
}
|
||||
|
||||
task rollup(type: Exec) {
|
||||
def rollup = tasks.register("rollup", Exec.class) {
|
||||
group = "build"
|
||||
description = "Bundles JS into rollup"
|
||||
|
||||
@@ -311,36 +321,46 @@ task rollup(type: Exec) {
|
||||
commandLine mkCommand('"node_modules/.bin/rollup" --config rollup.config.js')
|
||||
}
|
||||
|
||||
task illuaminateDocs(type: Exec, dependsOn: [rollup, luaJavadoc]) {
|
||||
group = "build"
|
||||
def illuaminateDocs = tasks.register("illuaminateDocs", IlluaminateExecToDir.class) {
|
||||
group = "documentation"
|
||||
description = "Generates docs using Illuaminate"
|
||||
dependsOn(rollup)
|
||||
|
||||
inputs.files(fileTree("doc")).withPropertyName("docs")
|
||||
inputs.files(fileTree("src/main/resources/data/computercraft/lua/rom")).withPropertyName("lua rom")
|
||||
// Config files
|
||||
inputs.file("illuaminate.sexp").withPropertyName("illuaminate.sexp")
|
||||
inputs.dir("$buildDir/docs/luaJavadoc")
|
||||
// Sources
|
||||
inputs.files(fileTree("doc")).withPropertyName("docs")
|
||||
inputs.files(fileTree("src/main/resources/data/computercraft/lua")).withPropertyName("lua rom")
|
||||
inputs.files(luaJavadoc)
|
||||
// Additional assets
|
||||
inputs.file("$buildDir/rollup/index.js").withPropertyName("scripts")
|
||||
inputs.file("src/web/styles.css").withPropertyName("styles")
|
||||
outputs.dir("$buildDir/docs/lua")
|
||||
|
||||
commandLine mkCommand('"bin/illuaminate" doc-gen')
|
||||
// Output directory. Also defined in illuaminate.sexp and transform.tsx
|
||||
output.set(new File(buildDir, "docs/lua"))
|
||||
|
||||
args = ["doc-gen"]
|
||||
}
|
||||
|
||||
task jsxDocs(type: Exec, dependsOn: [illuaminateDocs]) {
|
||||
group = "build"
|
||||
def jsxDocs = tasks.register("jsxDocs", Exec) {
|
||||
group = "documentation"
|
||||
description = "Post-processes documentation to statically render some dynamic content."
|
||||
|
||||
inputs.files(fileTree("src/web")).withPropertyName("sources")
|
||||
inputs.file("src/generated/export/index.json").withPropertyName("export")
|
||||
inputs.file("package-lock.json").withPropertyName("package-lock.json")
|
||||
inputs.file("tsconfig.json").withPropertyName("Typescript config")
|
||||
inputs.files(fileTree("$buildDir/docs/lua"))
|
||||
inputs.files(illuaminateDocs)
|
||||
outputs.dir("$buildDir/docs/site")
|
||||
|
||||
commandLine mkCommand('"node_modules/.bin/ts-node" --esm src/web/transform.tsx')
|
||||
commandLine mkCommand('"node_modules/.bin/ts-node" -T --esm src/web/transform.tsx')
|
||||
}
|
||||
|
||||
task docWebsite(type: Copy, dependsOn: [jsxDocs]) {
|
||||
def docWebsite = tasks.register("docWebsite", Copy.class) {
|
||||
group = "documentation"
|
||||
description = "Copy additional assets to the website directory."
|
||||
dependsOn(jsxDocs)
|
||||
|
||||
from('doc') {
|
||||
include 'logo.png'
|
||||
include 'images/**'
|
||||
@@ -375,94 +395,92 @@ jacocoTestReport {
|
||||
}
|
||||
}
|
||||
|
||||
check.dependsOn jacocoTestReport
|
||||
test.finalizedBy("jacocoTestReport")
|
||||
|
||||
license {
|
||||
mapping("java", "SLASHSTAR_STYLE")
|
||||
strictCheck true
|
||||
header = file('config/license/main.txt')
|
||||
lineEnding = '\n'
|
||||
newLine = false
|
||||
|
||||
ext.year = Calendar.getInstance().get(Calendar.YEAR)
|
||||
}
|
||||
properties {
|
||||
year = Calendar.getInstance().get(Calendar.YEAR)
|
||||
}
|
||||
|
||||
[licenseMain, licenseFormatMain].forEach {
|
||||
it.configure {
|
||||
include("**/*.java")
|
||||
exclude("dan200/computercraft/api/**")
|
||||
header file('config/license/main.txt')
|
||||
include("**/*.java") // We could apply to Kotlin, but for now let's not
|
||||
matching("dan200/computercraft/api/**") {
|
||||
header = file('config/license/api.txt')
|
||||
}
|
||||
}
|
||||
|
||||
[licenseTest, licenseFormatTest, licenseTestMod, licenseFormatTestMod].forEach {
|
||||
it.configure {
|
||||
include("**/*.java")
|
||||
header file('config/license/main.txt')
|
||||
}
|
||||
check.dependsOn("licenseCheck")
|
||||
|
||||
def lintLua = tasks.register("lintLua", IlluaminateExec.class) {
|
||||
group = JavaBasePlugin.VERIFICATION_GROUP
|
||||
description = "Lint Lua (and Lua docs) with illuaminate"
|
||||
|
||||
// Config files
|
||||
inputs.file("illuaminate.sexp").withPropertyName("illuaminate.sexp")
|
||||
// Sources
|
||||
inputs.files(fileTree("doc")).withPropertyName("docs")
|
||||
inputs.files(fileTree("src/main/resources/data/computercraft/lua")).withPropertyName("lua rom")
|
||||
inputs.files(luaJavadoc)
|
||||
|
||||
args = ["lint"]
|
||||
|
||||
doFirst { if (System.getenv("GITHUB_ACTIONS") != null) println("::add-matcher::.github/matchers/illuaminate.json") }
|
||||
doLast { if (System.getenv("GITHUB_ACTIONS") != null) println("::remove-matcher owner=illuaminate::") }
|
||||
}
|
||||
|
||||
gradle.projectsEvaluated {
|
||||
tasks.withType(LicenseFormat) {
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
}
|
||||
def testServerClassDumpDir = new File(buildDir, "jacocoClassDump/runTestServer")
|
||||
|
||||
|
||||
task licenseAPI(type: LicenseCheck)
|
||||
task licenseFormatAPI(type: LicenseFormat)
|
||||
[licenseAPI, licenseFormatAPI].forEach {
|
||||
it.configure {
|
||||
source = sourceSets.main.java
|
||||
include("dan200/computercraft/api/**")
|
||||
header file('config/license/api.txt')
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("testServer", JavaExec.class).configure {
|
||||
it.group('In-game tests')
|
||||
it.description("Runs tests on a temporary Minecraft instance.")
|
||||
it.dependsOn("prepareRunGameTestServer", "cleanTestServer", 'compileTestModJava')
|
||||
def testServer = tasks.register("testServer", JavaExec.class) {
|
||||
group("In-game tests")
|
||||
description("Runs tests on a temporary Minecraft instance.")
|
||||
dependsOn("cleanTestServer")
|
||||
finalizedBy("jacocoTestServerReport")
|
||||
|
||||
// Copy from runTestServer. We do it in this slightly odd way as runTestServer
|
||||
// isn't created until the task is configured (which is no good for us).
|
||||
JavaExec exec = tasks.getByName("runGameTestServer")
|
||||
dependsOn(exec.getDependsOn())
|
||||
exec.copyTo(it)
|
||||
it.setClasspath(exec.getClasspath())
|
||||
it.mainClass = exec.mainClass
|
||||
it.setArgs(exec.getArgs())
|
||||
setClasspath(exec.getClasspath())
|
||||
mainClass = exec.mainClass
|
||||
javaLauncher = exec.javaLauncher
|
||||
setArgs(exec.getArgs())
|
||||
|
||||
// Jacoco and modlauncher don't play well together as the classes loaded in-game don't
|
||||
// match up with those written to disk. We get Jacoco to dump all classes to disk, and
|
||||
// use that when generating the report.
|
||||
def coverageOut = new File(buildDir, "jacocoClassDump/testServer")
|
||||
jacoco.applyTo(it)
|
||||
it.jacoco.setIncludes(["dan200.computercraft.*"])
|
||||
it.jacoco.setClassDumpDir(coverageOut)
|
||||
it.outputs.dir(coverageOut)
|
||||
it.jacoco.setClassDumpDir(testServerClassDumpDir)
|
||||
outputs.dir(testServerClassDumpDir)
|
||||
// Older versions of modlauncher don't include a protection domain (and thus no code
|
||||
// source). Jacoco skips such classes by default, so we need to explicitly include them.
|
||||
it.jacoco.setIncludeNoLocationClasses(true)
|
||||
}
|
||||
|
||||
tasks.register("jacocoTestServerReport", JacocoReport.class).configure {
|
||||
it.group('In-game')
|
||||
it.description("Generate coverage reports for testServer")
|
||||
it.dependsOn("testServer")
|
||||
tasks.register("jacocoTestServerReport", JacocoReport.class) {
|
||||
group("In-game tests")
|
||||
description("Generate coverage reports for testServer")
|
||||
dependsOn(testServer)
|
||||
|
||||
it.executionData(new File(buildDir, "jacoco/testServer.exec"))
|
||||
it.sourceDirectories.from(sourceSets.main.allJava.srcDirs)
|
||||
it.classDirectories.from(new File(buildDir, "jacocoClassDump/testServer"))
|
||||
executionData(new File(buildDir, "jacoco/testServer.exec"))
|
||||
sourceDirectories.from(sourceSets.main.allJava.srcDirs)
|
||||
classDirectories.from(testServerClassDumpDir)
|
||||
|
||||
it.reports {
|
||||
reports {
|
||||
xml.enabled true
|
||||
html.enabled true
|
||||
}
|
||||
}
|
||||
|
||||
check.dependsOn("jacocoTestServerReport")
|
||||
|
||||
check.dependsOn(testServer)
|
||||
|
||||
// Upload tasks
|
||||
|
||||
task checkRelease {
|
||||
def checkRelease = tasks.register("checkRelease") {
|
||||
group "upload"
|
||||
description "Verifies that everything is ready for a release"
|
||||
|
||||
@@ -500,7 +518,7 @@ task checkRelease {
|
||||
if (!ok) throw new IllegalStateException("Could not check release")
|
||||
}
|
||||
}
|
||||
check.dependsOn checkRelease
|
||||
check.dependsOn(checkRelease)
|
||||
|
||||
def isStable = true
|
||||
|
||||
@@ -510,36 +528,29 @@ curseforge {
|
||||
id = '282001'
|
||||
releaseType = isStable ? 'release' : 'alpha'
|
||||
changelog = "Release notes can be found on the GitHub repository (https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
|
||||
mainArtifact(shadowJar)
|
||||
|
||||
addGameVersion "${mc_version}"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('publishModrinth', TaskModrinthUpload.class).configure {
|
||||
dependsOn('assemble', 'reobfJar')
|
||||
onlyIf {
|
||||
project.hasProperty('modrinthApiKey')
|
||||
}
|
||||
|
||||
modrinth {
|
||||
token = project.hasProperty('modrinthApiKey') ? project.getProperty('modrinthApiKey') : ''
|
||||
projectId = 'gu7yAYhd'
|
||||
versionNumber = "${project.mc_version}-${project.mod_version}"
|
||||
uploadFile = jar
|
||||
versionType = isStable ? 'RELEASE' : 'ALPHA'
|
||||
addGameVersion(project.mc_version)
|
||||
versionName = "${project.mod_version}"
|
||||
versionType = isStable ? 'release' : 'alpha'
|
||||
uploadFile = shadowJar
|
||||
gameVersions = [project.mc_version]
|
||||
changelog = "Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
|
||||
addLoader('forge')
|
||||
}
|
||||
|
||||
tasks.withType(GenerateModuleMetadata) {
|
||||
// We can't generate metadata as that includes Forge as a dependency.
|
||||
enabled = false
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
maven(MavenPublication) {
|
||||
from components.java
|
||||
artifact(apiJar)
|
||||
fg.component(it)
|
||||
|
||||
pom {
|
||||
name = 'CC: Tweaked'
|
||||
@@ -558,11 +569,9 @@ publishing {
|
||||
licenses {
|
||||
license {
|
||||
name = 'ComputerCraft Public License, Version 1.0'
|
||||
url = 'https://github.com/cc-tweaked/CC-Tweaked/blob/mc-1.15.x/LICENSE'
|
||||
url = 'https://github.com/cc-tweaked/CC-Tweaked/blob/mc-1.16.x/LICENSE'
|
||||
}
|
||||
}
|
||||
|
||||
withXml { asNode().remove(asNode().get("dependencies")) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -610,10 +619,11 @@ githubRelease {
|
||||
prerelease !isStable
|
||||
}
|
||||
|
||||
def uploadTasks = ["publish", "curseforge", "publishModrinth", "githubRelease"]
|
||||
uploadTasks.forEach { tasks.getByName(it).dependsOn checkRelease }
|
||||
def uploadTasks = ["publish", "curseforge", "modrinth", "githubRelease"]
|
||||
uploadTasks.forEach { tasks.named(it) { dependsOn(checkRelease) } }
|
||||
|
||||
task uploadAll(dependsOn: uploadTasks) {
|
||||
group "upload"
|
||||
description "Uploads to all repositories (Maven, Curse, Modrinth, GitHub release)"
|
||||
tasks.register("uploadAll") {
|
||||
group = "upload"
|
||||
description = "Uploads to all repositories (Maven, Curse, Modrinth, GitHub release)"
|
||||
dependsOn(uploadTasks)
|
||||
}
|
||||
|
||||
18
buildSrc/build.gradle.kts
Normal file
18
buildSrc/build.gradle.kts
Normal file
@@ -0,0 +1,18 @@
|
||||
plugins {
|
||||
`java-gradle-plugin`
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
register("cc-tweaked.illuaminate") {
|
||||
id = "cc-tweaked.illuaminate"
|
||||
implementationClass = "cc.tweaked.gradle.IlluaminatePlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
11
buildSrc/src/main/kotlin/cc/tweaked/gradle/ExecTasks.kt
Normal file
11
buildSrc/src/main/kotlin/cc/tweaked/gradle/ExecTasks.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package cc.tweaked.gradle
|
||||
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.AbstractExecTask
|
||||
import org.gradle.api.tasks.OutputDirectory
|
||||
import java.io.File
|
||||
|
||||
abstract class ExecToDir : AbstractExecTask<ExecToDir>(ExecToDir::class.java) {
|
||||
@get:OutputDirectory
|
||||
abstract val output: Property<File>
|
||||
}
|
||||
121
buildSrc/src/main/kotlin/cc/tweaked/gradle/Illuaminate.kt
Normal file
121
buildSrc/src/main/kotlin/cc/tweaked/gradle/Illuaminate.kt
Normal file
@@ -0,0 +1,121 @@
|
||||
package cc.tweaked.gradle
|
||||
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.artifacts.Dependency
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.AbstractExecTask
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import java.io.File
|
||||
|
||||
abstract class IlluaminateExtension {
|
||||
/** The version of illuaminate to use. */
|
||||
abstract val version: Property<String>
|
||||
|
||||
/** The path to illuaminate. If not given, illuaminate will be downloaded automatically. */
|
||||
abstract val file: Property<File>
|
||||
}
|
||||
|
||||
class IlluaminatePlugin : Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
val extension = project.extensions.create("illuaminate", IlluaminateExtension::class.java)
|
||||
extension.file.convention(setupDependency(project, extension.version))
|
||||
|
||||
project.tasks.register(SetupIlluaminate.NAME, SetupIlluaminate::class.java) {
|
||||
file.set(extension.file.map { it.absolutePath })
|
||||
}
|
||||
}
|
||||
|
||||
/** Set up a repository for illuaminate and download our binary from it. */
|
||||
private fun setupDependency(project: Project, version: Provider<String>): Provider<File> {
|
||||
project.repositories.ivy {
|
||||
name = "Illuaminate"
|
||||
setUrl("https://squiddev.cc/illuaminate/bin/")
|
||||
patternLayout {
|
||||
artifact("[revision]/[artifact]-[ext]")
|
||||
}
|
||||
metadataSources {
|
||||
artifact()
|
||||
}
|
||||
content {
|
||||
includeModule("cc.squiddev", "illuaminate")
|
||||
}
|
||||
}
|
||||
|
||||
return version.map {
|
||||
val dep = illuaminateArtifact(project, it)
|
||||
val configuration = project.configurations.detachedConfiguration(dep)
|
||||
configuration.isTransitive = false
|
||||
configuration.resolve().single()
|
||||
}
|
||||
}
|
||||
|
||||
/** Define a dependency for illuaminate from a version number and the current operating system. */
|
||||
private fun illuaminateArtifact(project: Project, version: String): Dependency {
|
||||
val osName = System.getProperty("os.name").toLowerCase()
|
||||
val (os, suffix) = when {
|
||||
osName.contains("windows") -> Pair("windows", ".exe")
|
||||
osName.contains("mac os") || osName.contains("darwin") -> Pair("macos", "")
|
||||
osName.contains("linux") -> Pair("linux", "")
|
||||
else -> error("Unsupported OS $osName for illuaminate")
|
||||
}
|
||||
|
||||
val osArch = System.getProperty("os.arch").toLowerCase()
|
||||
val arch = when {
|
||||
osArch == "arm" || osArch.startsWith("aarch") -> error("Unsupported architecture '$osArch' for illuaminate")
|
||||
osArch.contains("64") -> "x86_64"
|
||||
else -> error("Unsupported architecture $osArch for illuaminate")
|
||||
}
|
||||
|
||||
return project.dependencies.create(
|
||||
mapOf(
|
||||
"group" to "cc.squiddev",
|
||||
"name" to "illuaminate",
|
||||
"version" to version,
|
||||
"ext" to "$os-$arch$suffix",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private val Task.illuaminatePath: String? // "?" needed to avoid overload ambiguity in setExecutable below.
|
||||
get() = project.extensions.getByType(IlluaminateExtension::class.java).file.get().absolutePath
|
||||
|
||||
/** Prepares illuaminate for being run. This simply requests the dependency and then marks it as executable. */
|
||||
abstract class SetupIlluaminate : DefaultTask() {
|
||||
@get:Input
|
||||
abstract val file: Property<String>
|
||||
|
||||
@TaskAction
|
||||
fun setExecutable() {
|
||||
val file = File(this.file.get())
|
||||
if (file.canExecute()) {
|
||||
didWork = false
|
||||
return
|
||||
}
|
||||
|
||||
file.setExecutable(true)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NAME: String = "setupIlluaminate"
|
||||
}
|
||||
}
|
||||
|
||||
abstract class IlluaminateExec : AbstractExecTask<IlluaminateExec>(IlluaminateExec::class.java) {
|
||||
init {
|
||||
dependsOn(SetupIlluaminate.NAME)
|
||||
executable = illuaminatePath
|
||||
}
|
||||
}
|
||||
|
||||
abstract class IlluaminateExecToDir : ExecToDir() {
|
||||
init {
|
||||
dependsOn(SetupIlluaminate.NAME)
|
||||
executable = illuaminatePath
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
set -e
|
||||
|
||||
test -d bin || mkdir bin
|
||||
test -f bin/illuaminate || curl -s -obin/illuaminate https://squiddev.cc/illuaminate/linux-x86-64/illuaminate
|
||||
chmod +x bin/illuaminate
|
||||
|
||||
if [ -n ${GITHUB_ACTIONS+x} ]; then
|
||||
# Register a problem matcher (see https://github.com/actions/toolkit/blob/master/docs/problem-matchers.md)
|
||||
# for illuaminate.
|
||||
echo "::add-matcher::.github/matchers/illuaminate.json"
|
||||
trap 'echo "::remove-matcher owner=illuaminate::"' EXIT
|
||||
fi
|
||||
|
||||
./gradlew luaJavadoc
|
||||
bin/illuaminate lint
|
||||
90
doc/guides/gps_setup.md
Normal file
90
doc/guides/gps_setup.md
Normal file
@@ -0,0 +1,90 @@
|
||||
---
|
||||
module: [kind=guide] gps_setup
|
||||
---
|
||||
|
||||
# Setting up GPS
|
||||
The @{gps} API allows computers and turtles to find their current position using wireless modems.
|
||||
|
||||
In order to use GPS, you'll need to set up multiple *GPS hosts*. These are computers running the special `gps host`
|
||||
program, which tell other computers the host's position. Several hosts running together are known as a *GPS
|
||||
constellation*.
|
||||
|
||||
In order to give the best results, a GPS constellation needs at least four computers. More than four GPS hosts per
|
||||
constellation is redundant, but it does not cause problems.
|
||||
|
||||
## Building a GPS constellation
|
||||
{.big-image}
|
||||
|
||||
We are going to build our GPS constellation as shown in the image above. You will need 4 computers and either 4 wireless
|
||||
modems or 4 ender modems. Try not to mix ender and wireless modems together as you might get some odd behavior when your
|
||||
requesting computers are out of range.
|
||||
|
||||
:::tip Ender modems vs wireless modems
|
||||
Ender modems have a very large range, which makes them very useful for setting up GPS hosts. If you do this then you
|
||||
will likely only need one GPS constellation for the whole dimension (such as the Overworld or Nether).
|
||||
|
||||
If you do use wireless modems then you may find that you need multiple GPS constellations to cover your needs.
|
||||
|
||||
A computer needs a wireless or ender modem and to be in range of a GPS constellation that is in the same dimension as it
|
||||
to use the GPS API. The reason for this is that ComputerCraft mimics real-life GPS by making use of the distance
|
||||
parameter of @{modem_message|modem messages} and some maths.
|
||||
:::
|
||||
|
||||
Locate where you want to place your GPS constellation. You will need an area at least 6 blocks high, 6 blocks wide, and
|
||||
6 blocks deep (6x6x6). If you are using wireless modems then you may want to build your constellation as high as you can
|
||||
because high altitude boosts modem message range and thus the radius that your constellation covers.
|
||||
|
||||
The GPS constellation will only work when it is in a loaded chunk. If you want your constellation to always be
|
||||
accessible, you may want to permanently load the chunk using a vanilla or modded chunk loader. Make sure that your 6x6x6
|
||||
area fits in a single chunk to reduce the number of chunks that need to be kept loaded.
|
||||
|
||||
Let's get started building the constellation! Place your first computer in one of the corners of your 6x6x6. Remember
|
||||
which computer this is as other computers need to be placed relative to it. Place the second computer 4 blocks above the
|
||||
first. Go back to your first computer and place your third computer 5 blocks in front of your first computer, leaving 4
|
||||
blocks of air between them. Finally for the fourth computer, go back to your first computer and place it 5 blocks right
|
||||
of your first computer, leaving 4 blocks of air between them.
|
||||
|
||||
With all four computers placed within the 6x6x6, place one modem on top of each computer. You should have 4 modems and 4
|
||||
computers all within your 6x6x6 where each modem is attached to a computer and each computer has a modem.
|
||||
|
||||
Currently your GPS constellation will not work, that's because each host is not aware that it's a GPS host. We will fix
|
||||
this in the next section.
|
||||
|
||||
## Configuring the constellation
|
||||
Now that the structure of your constellation is built, we need to configure each host in it.
|
||||
|
||||
Go back to the first computer that you placed and create a startup file, by running `edit startup`.
|
||||
|
||||
Type the following code into the file:
|
||||
```lua
|
||||
shell.run("gps", "host", x, y, z)
|
||||
```
|
||||
|
||||
Escape from the computer GUI and then press <kbd>F3</kbd> to open Minecraft's debug screen and then look at the computer
|
||||
(without opening the GUI). On the right of the screen about halfway down you should see an entry labeled `Targeted
|
||||
Block`, the numbers correspond to the position of the block that you are looking at. Replace `x` with the first number,
|
||||
`y` with the second number, and `z` with the third number.
|
||||
|
||||
For example, if I had a computer at x = 59, y = 5, z = -150, then my <kbd>F3</kbd> debug screen entry would be `Target
|
||||
Block: 59, 5, -150` and I would change my startup file to this `shell.run("gps", "host", 59, 5, -150)`.
|
||||
|
||||
To hide Minecraft's debug screen, press <kbd>F3</kbd> again.
|
||||
|
||||
Create similar startup files for the other computers in your constellation, making sure to input the each computer's own
|
||||
coordinates.
|
||||
|
||||
:::caution Modem messages come from the computer's position, not the modem's
|
||||
Wireless modems transmit from the block that they are attached to *not* the block space that they occupy, the
|
||||
coordinates that you input into your GPS host should be the position of the computer and not the position of the modem.
|
||||
:::
|
||||
|
||||
Congratulations, your constellation is now fully set up! You can test it by placing another computer close by, placing a
|
||||
wireless modem on it, and running the `gps locate` program (or calling the @{gps.locate} function).
|
||||
|
||||
:::info Why use Minecraft's coordinates?
|
||||
CC doesn't care if you use Minecraft's coordinate system, so long as all of the GPS hosts with overlapping ranges use
|
||||
the same reference point (requesting computers will get confused if hosts have different reference points). However,
|
||||
using MC's coordinate system does provide a nice standard to adopt server-wide. It also is consistent with how command
|
||||
computers get their location, they use MC's command system to get their block which returns that in MC's coordinate
|
||||
system.
|
||||
:::
|
||||
@@ -185,7 +185,7 @@ end
|
||||
|
||||
:::note Confused?
|
||||
Don't worry if you don't understand this example. It's quite advanced, and does use some ideas that this guide doesn't
|
||||
cover. That said, don't be afraid to ask on [Discord] or [IRC] either!
|
||||
cover. That said, don't be afraid to ask on [GitHub Discussions] or [IRC] either!
|
||||
:::
|
||||
|
||||
It's worth noting that the examples of audio processing we've mentioned here are about manipulating the _amplitude_ of
|
||||
@@ -200,6 +200,5 @@ This is, I'm afraid, left as an exercise to the reader.
|
||||
[PCM]: https://en.wikipedia.org/wiki/Pulse-code_modulation "Pulse-code Modulation - Wikipedia"
|
||||
[Ring Buffer]: https://en.wikipedia.org/wiki/Circular_buffer "Circular buffer - Wikipedia"
|
||||
[Sine Wave]: https://en.wikipedia.org/wiki/Sine_wave "Sine wave - Wikipedia"
|
||||
|
||||
[Discord]: https://discord.computercraft.cc "The Minecraft Computer Mods Discord"
|
||||
[IRC]: http://webchat.esper.net/?channels=computercraft "IRC webchat on EsperNet"
|
||||
[GitHub Discussions]: https://github.com/cc-tweaked/CC-Tweaked/discussions
|
||||
[IRC]: http://webchat.esper.net/?channels=computercraft "#computercraft on EsperNet"
|
||||
|
||||
BIN
doc/images/gps-constellation-example.png
Normal file
BIN
doc/images/gps-constellation-example.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 331 KiB |
@@ -37,8 +37,7 @@ little daunting getting started. Thankfully, there's several fantastic tutorials
|
||||
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].
|
||||
If you get stuck, do [ask a question on GitHub][GitHub Discussions] or pop in to the 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].
|
||||
@@ -51,5 +50,5 @@ CC: Tweaked lives on [GitHub]. If you've got any ideas, feedback or bugs please
|
||||
[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"
|
||||
[GitHub Discussions]: https://github.com/cc-tweaked/CC-Tweaked/discussions
|
||||
[IRC]: http://webchat.esper.net/?channels=computercraft "#computercraft on EsperNet"
|
||||
|
||||
@@ -14,7 +14,7 @@ thread, not the whole program.
|
||||
|
||||
:::tip
|
||||
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
|
||||
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.
|
||||
:::
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
org.gradle.jvmargs=-Xmx3G
|
||||
kotlin.stdlib.default.dependency=false
|
||||
|
||||
# Mod properties
|
||||
mod_version=1.100.6
|
||||
mod_version=1.100.10
|
||||
|
||||
# Minecraft properties (update mods.toml when changing)
|
||||
mc_version=1.18.2
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
640
package-lock.json
generated
640
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-typescript": "^8.2.5",
|
||||
"@rollup/plugin-url": "^6.1.0",
|
||||
"@rollup/plugin-url": "^7.0.0",
|
||||
"@types/glob": "^7.2.0",
|
||||
"@types/react-dom": "^18.0.5",
|
||||
"glob": "^8.0.3",
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
rootProject.name = "cc-tweaked-${mc_version}"
|
||||
17
settings.gradle.kts
Normal file
17
settings.gradle.kts
Normal file
@@ -0,0 +1,17 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://maven.minecraftforge.net")
|
||||
maven("https://maven.parchmentmc.org")
|
||||
}
|
||||
resolutionStrategy {
|
||||
eachPlugin {
|
||||
if (requested.id.id == "org.spongepowered.mixin") {
|
||||
useModule("org.spongepowered:mixingradle:${requested.version}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val mc_version: String by settings
|
||||
rootProject.name = "cc-tweaked-${mc_version}"
|
||||
@@ -13,8 +13,8 @@ import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
||||
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -81,7 +81,7 @@ public final class ComputerCraft
|
||||
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
|
||||
|
||||
// Logging
|
||||
public static final Logger log = LogManager.getLogger( MOD_ID );
|
||||
public static final Logger log = LoggerFactory.getLogger( MOD_ID );
|
||||
|
||||
public ComputerCraft()
|
||||
{
|
||||
|
||||
@@ -8,7 +8,6 @@ package dan200.computercraft.client.gui;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
@@ -99,9 +98,8 @@ public class GuiPrintout extends AbstractContainerScreen<ContainerHeldItem>
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
MultiBufferSource.BufferSource renderer = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() );
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
drawBorder( matrix, renderer, leftPos, topPos, getBlitOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP );
|
||||
drawText( matrix, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours );
|
||||
drawBorder( transform, renderer, leftPos, topPos, getBlitOffset(), page, pages, book, FULL_BRIGHT_LIGHTMAP );
|
||||
drawText( transform, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, FULL_BRIGHT_LIGHTMAP, text, colours );
|
||||
renderer.endBatch();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ package dan200.computercraft.client.gui.widgets;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
@@ -316,11 +315,10 @@ public class WidgetTerminal extends AbstractWidget
|
||||
public void render( @Nonnull PoseStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
if( !visible ) return;
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
Terminal terminal = computer.getTerminal();
|
||||
|
||||
var bufferSource = MultiBufferSource.immediate( Tesselator.getInstance().getBuilder() );
|
||||
var emitter = FixedWidthFontRenderer.toVertexConsumer( matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ) );
|
||||
var emitter = FixedWidthFontRenderer.toVertexConsumer( transform, bufferSource.getBuffer( RenderTypes.TERMINAL ) );
|
||||
|
||||
if( terminal != null )
|
||||
{
|
||||
|
||||
@@ -96,23 +96,19 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
// Render the light
|
||||
int lightColour = ItemPocketComputer.getLightState( stack );
|
||||
if( lightColour == -1 ) lightColour = Colour.BLACK.getHex();
|
||||
renderLight( matrix, bufferSource, lightColour, width, height );
|
||||
renderLight( transform, bufferSource, lightColour, width, height );
|
||||
|
||||
if( computer != null && terminal != null )
|
||||
{
|
||||
FixedWidthFontRenderer.drawTerminal(
|
||||
FixedWidthFontRenderer.toVertexConsumer( matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH ) ),
|
||||
FixedWidthFontRenderer.toVertexConsumer( transform, bufferSource.getBuffer( RenderTypes.TERMINAL ) ),
|
||||
MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN
|
||||
);
|
||||
FixedWidthFontRenderer.drawBlocker(
|
||||
FixedWidthFontRenderer.toVertexConsumer( matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_BLOCKER ) ),
|
||||
0, 0, width, height
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FixedWidthFontRenderer.drawEmptyTerminal(
|
||||
FixedWidthFontRenderer.toVertexConsumer( matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ) ),
|
||||
FixedWidthFontRenderer.toVertexConsumer( transform, bufferSource.getBuffer( RenderTypes.TERMINAL ) ),
|
||||
0, 0, width, height
|
||||
);
|
||||
}
|
||||
@@ -131,14 +127,14 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
ComputerBorderRenderer.render( transform, render.getBuffer( ComputerBorderRenderer.getRenderType( texture ) ), 0, 0, 0, light, width, height, true, r, g, b );
|
||||
}
|
||||
|
||||
private static void renderLight( Matrix4f transform, MultiBufferSource render, int colour, int width, int height )
|
||||
private static void renderLight( PoseStack transform, MultiBufferSource render, int colour, int width, int height )
|
||||
{
|
||||
byte r = (byte) ((colour >>> 16) & 0xFF);
|
||||
byte g = (byte) ((colour >>> 8) & 0xFF);
|
||||
byte b = (byte) (colour & 0xFF);
|
||||
byte[] c = new byte[] { r, g, b, (byte) 255 };
|
||||
|
||||
VertexConsumer buffer = render.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH );
|
||||
VertexConsumer buffer = render.getBuffer( RenderTypes.TERMINAL );
|
||||
FixedWidthFontRenderer.drawQuad(
|
||||
FixedWidthFontRenderer.toVertexConsumer( transform, buffer ),
|
||||
width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, 0.001f, LIGHT_HEIGHT * 2, LIGHT_HEIGHT,
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
@@ -106,10 +105,9 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||
transform.scale( scale, scale, scale );
|
||||
transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
|
||||
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book, light );
|
||||
drawBorder( transform, render, 0, 0, -0.01f, 0, pages, book, light );
|
||||
drawText(
|
||||
matrix, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, light,
|
||||
transform, render, X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, light,
|
||||
ItemPrintout.getText( stack ), ItemPrintout.getColours( stack )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.render;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
|
||||
@@ -54,7 +55,7 @@ public final class PrintoutRenderer
|
||||
|
||||
private PrintoutRenderer() {}
|
||||
|
||||
public static void drawText( Matrix4f transform, MultiBufferSource bufferSource, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours )
|
||||
public static void drawText( PoseStack transform, MultiBufferSource bufferSource, int x, int y, int start, int light, TextBuffer[] text, TextBuffer[] colours )
|
||||
{
|
||||
var buffer = bufferSource.getBuffer( RenderTypes.PRINTOUT_TEXT );
|
||||
var emitter = FixedWidthFontRenderer.toVertexConsumer( transform, buffer );
|
||||
@@ -67,7 +68,7 @@ public final class PrintoutRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawText( Matrix4f transform, MultiBufferSource bufferSource, int x, int y, int start, int light, String[] text, String[] colours )
|
||||
public static void drawText( PoseStack transform, MultiBufferSource bufferSource, int x, int y, int start, int light, String[] text, String[] colours )
|
||||
{
|
||||
var buffer = bufferSource.getBuffer( RenderTypes.PRINTOUT_TEXT );
|
||||
var emitter = FixedWidthFontRenderer.toVertexConsumer( transform, buffer );
|
||||
@@ -81,8 +82,9 @@ public final class PrintoutRenderer
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawBorder( Matrix4f transform, MultiBufferSource bufferSource, float x, float y, float z, int page, int pages, boolean isBook, int light )
|
||||
public static void drawBorder( PoseStack transform, MultiBufferSource bufferSource, float x, float y, float z, int page, int pages, boolean isBook, int light )
|
||||
{
|
||||
var matrix = transform.last().pose();
|
||||
int leftPages = page;
|
||||
int rightPages = pages - page - 1;
|
||||
|
||||
@@ -96,11 +98,11 @@ public final class PrintoutRenderer
|
||||
float right = x + X_SIZE + offset - 4;
|
||||
|
||||
// Left and right border
|
||||
drawTexture( transform, buffer, left - 4, y - 8, z - 0.02f, COVER_X, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
|
||||
drawTexture( transform, buffer, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
|
||||
drawTexture( matrix, buffer, left - 4, y - 8, z - 0.02f, COVER_X, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
|
||||
drawTexture( matrix, buffer, right, y - 8, z - 0.02f, COVER_X + COVER_SIZE, 0, COVER_SIZE, Y_SIZE + COVER_SIZE * 2, light );
|
||||
|
||||
// Draw centre panel (just stretched texture, sorry).
|
||||
drawTexture( transform, buffer,
|
||||
drawTexture( matrix, buffer,
|
||||
x - offset, y, z - 0.02f, X_SIZE + offset * 2, Y_SIZE,
|
||||
COVER_X + COVER_SIZE / 2.0f, COVER_SIZE, COVER_SIZE, Y_SIZE,
|
||||
light
|
||||
@@ -110,17 +112,20 @@ public final class PrintoutRenderer
|
||||
while( borderX < right )
|
||||
{
|
||||
double thisWidth = Math.min( right - borderX, X_SIZE );
|
||||
drawTexture( transform, buffer, borderX, y - 8, z - 0.02f, 0, COVER_Y, (float) thisWidth, COVER_SIZE, light );
|
||||
drawTexture( transform, buffer, borderX, y + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE, light );
|
||||
drawTexture( matrix, buffer, borderX, y - 8, z - 0.02f, 0, COVER_Y, (float) thisWidth, COVER_SIZE, light );
|
||||
drawTexture( matrix, buffer, borderX, y + Y_SIZE - 4, z - 0.02f, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE, light );
|
||||
borderX += thisWidth;
|
||||
}
|
||||
}
|
||||
|
||||
// Left half
|
||||
drawTexture( transform, buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2.0f, Y_SIZE, light );
|
||||
// Current page background: Z-offset is interleaved between the "zeroth" left/right page and the first
|
||||
// left/right page, so that the "bold" border can be drawn over the edge where appropriate.
|
||||
drawTexture( matrix, buffer, x, y, z - 1e-3f * 0.5f, X_FOLD_SIZE * 2, 0, X_SIZE, Y_SIZE, light );
|
||||
|
||||
// Left pages
|
||||
for( int n = 0; n <= leftPages; n++ )
|
||||
{
|
||||
drawTexture( transform, buffer,
|
||||
drawTexture( matrix, buffer,
|
||||
x - offsetAt( n ), y, z - 1e-3f * n,
|
||||
// Use the left "bold" fold for the outermost page
|
||||
n == leftPages ? 0 : X_FOLD_SIZE, 0,
|
||||
@@ -128,11 +133,10 @@ public final class PrintoutRenderer
|
||||
);
|
||||
}
|
||||
|
||||
// Right half
|
||||
drawTexture( transform, buffer, x + X_SIZE / 2.0f, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2.0f, 0, X_SIZE / 2.0f, Y_SIZE, light );
|
||||
// Right pages
|
||||
for( int n = 0; n <= rightPages; n++ )
|
||||
{
|
||||
drawTexture( transform, buffer,
|
||||
drawTexture( matrix, buffer,
|
||||
x + (X_SIZE - X_FOLD_SIZE) + offsetAt( n ), y, z - 1e-3f * n,
|
||||
// Two folds, then the main page. Use the right "bold" fold for the outermost page.
|
||||
X_FOLD_SIZE * 2 + X_SIZE + (n == rightPages ? X_FOLD_SIZE : 0), 0,
|
||||
|
||||
@@ -30,24 +30,9 @@ public class RenderTypes
|
||||
private static MonitorTextureBufferShader monitorTboShader;
|
||||
|
||||
/**
|
||||
* Renders a fullbright terminal without writing to the depth layer. This is used in combination with
|
||||
* {@link #TERMINAL_BLOCKER} to ensure we can render a terminal without z-fighting.
|
||||
* Renders a fullbright terminal.
|
||||
*/
|
||||
public static final RenderType TERMINAL_WITHOUT_DEPTH = Types.TERMINAL_WITHOUT_DEPTH;
|
||||
|
||||
/**
|
||||
* A transparent texture which only writes to the depth layer.
|
||||
*/
|
||||
public static final RenderType TERMINAL_BLOCKER = Types.TERMINAL_BLOCKER;
|
||||
|
||||
/**
|
||||
* Renders a fullbright terminal which also writes to the depth layer. This is used when z-fighting isn't an issue -
|
||||
* for instance rendering an empty terminal or inside a GUI.
|
||||
*
|
||||
* This is identical to <em>vanilla's</em> {@link RenderType#text}. Forge overrides one with a definition which sets
|
||||
* sortOnUpload to true, which is entirely broken!
|
||||
*/
|
||||
public static final RenderType TERMINAL_WITH_DEPTH = Types.TERMINAL_WITH_DEPTH;
|
||||
public static final RenderType TERMINAL = RenderType.text( FixedWidthFontRenderer.FONT );
|
||||
|
||||
/**
|
||||
* Renders a monitor with the TBO shader.
|
||||
@@ -57,7 +42,7 @@ public class RenderTypes
|
||||
public static final RenderType MONITOR_TBO = Types.MONITOR_TBO;
|
||||
|
||||
/**
|
||||
* A variant of {@link #TERMINAL_WITH_DEPTH} which uses the lightmap rather than rendering fullbright.
|
||||
* A variant of {@link #TERMINAL} which uses the lightmap rather than rendering fullbright.
|
||||
*/
|
||||
public static final RenderType PRINTOUT_TEXT = RenderType.text( FixedWidthFontRenderer.FONT );
|
||||
|
||||
@@ -77,7 +62,7 @@ public class RenderTypes
|
||||
@Nonnull
|
||||
static ShaderInstance getTerminalShader()
|
||||
{
|
||||
return GameRenderer.getPositionColorTexShader();
|
||||
return GameRenderer.getRendertypeTextShader();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -99,8 +84,6 @@ public class RenderTypes
|
||||
FixedWidthFontRenderer.FONT,
|
||||
false, false // blur, minimap
|
||||
);
|
||||
private static final VertexFormat TERM_FORMAT = DefaultVertexFormat.POSITION_COLOR_TEX;
|
||||
private static final ShaderStateShard TERM_SHADER = new ShaderStateShard( RenderTypes::getTerminalShader );
|
||||
|
||||
static final RenderType MONITOR_TBO = RenderType.create(
|
||||
"monitor_tbo", DefaultVertexFormat.POSITION_TEX, VertexFormat.Mode.TRIANGLE_STRIP, 128,
|
||||
@@ -111,36 +94,6 @@ public class RenderTypes
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
static final RenderType TERMINAL_WITHOUT_DEPTH = RenderType.create(
|
||||
"terminal_without_depth", TERM_FORMAT, VertexFormat.Mode.QUADS, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderType.CompositeState.builder()
|
||||
.setTextureState( TERM_FONT_TEXTURE )
|
||||
.setShaderState( TERM_SHADER )
|
||||
.setLightmapState( LIGHTMAP )
|
||||
.setWriteMaskState( COLOR_WRITE )
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
static final RenderType TERMINAL_BLOCKER = RenderType.create(
|
||||
"terminal_blocker", DefaultVertexFormat.POSITION, VertexFormat.Mode.QUADS, 256,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderType.CompositeState.builder()
|
||||
.setShaderState( POSITION_SHADER )
|
||||
.setWriteMaskState( DEPTH_WRITE )
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
static final RenderType TERMINAL_WITH_DEPTH = RenderType.create(
|
||||
"terminal_with_depth", TERM_FORMAT, VertexFormat.Mode.QUADS, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderType.CompositeState.builder()
|
||||
.setTextureState( TERM_FONT_TEXTURE )
|
||||
.setShaderState( TERM_SHADER )
|
||||
.setLightmapState( LIGHTMAP )
|
||||
.createCompositeState( false )
|
||||
);
|
||||
|
||||
private Types( String name, Runnable setup, Runnable destroy )
|
||||
{
|
||||
super( name, setup, destroy );
|
||||
|
||||
@@ -8,8 +8,11 @@ package dan200.computercraft.client.render;
|
||||
import com.mojang.blaze3d.platform.GlStateManager;
|
||||
import com.mojang.blaze3d.platform.MemoryTracker;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix3f;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
@@ -17,13 +20,15 @@ import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.client.render.text.DirectFixedWidthFontRenderer;
|
||||
import dan200.computercraft.client.render.text.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.client.util.DirectBuffers;
|
||||
import dan200.computercraft.client.util.DirectVertexBuffer;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.shared.integration.ShaderMod;
|
||||
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||
import dan200.computercraft.shared.util.DirectionUtil;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -34,6 +39,7 @@ import org.lwjgl.opengl.GL31;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.FONT_WIDTH;
|
||||
@@ -45,6 +51,9 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
* the monitor frame and contents.
|
||||
*/
|
||||
private static final float MARGIN = (float) (TileMonitor.RENDER_MARGIN * 1.1);
|
||||
|
||||
private static final Matrix3f IDENTITY_NORMAL = Util.make( new Matrix3f(), Matrix3f::setIdentity );
|
||||
|
||||
private static ByteBuffer backingBuffer;
|
||||
|
||||
public TileEntityMonitorRenderer( BlockEntityRendererProvider.Context context )
|
||||
@@ -101,7 +110,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
|
||||
// Draw the contents
|
||||
Terminal terminal = originTerminal.getTerminal();
|
||||
if( terminal != null )
|
||||
if( terminal != null && !ShaderMod.INSTANCE.isRenderingShadowPass() )
|
||||
{
|
||||
// Draw a terminal
|
||||
int width = terminal.getWidth(), height = terminal.getHeight();
|
||||
@@ -113,14 +122,14 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
|
||||
renderTerminal( bufferSource, matrix, originTerminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale) );
|
||||
renderTerminal( matrix, originTerminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale) );
|
||||
|
||||
transform.popPose();
|
||||
}
|
||||
else
|
||||
{
|
||||
FixedWidthFontRenderer.drawEmptyTerminal(
|
||||
FixedWidthFontRenderer.toVertexConsumer( transform.last().pose(), bufferSource.getBuffer( RenderTypes.TERMINAL_WITH_DEPTH ) ),
|
||||
FixedWidthFontRenderer.toVertexConsumer( transform, bufferSource.getBuffer( RenderTypes.TERMINAL ) ),
|
||||
-MARGIN, MARGIN,
|
||||
(float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2)
|
||||
);
|
||||
@@ -129,7 +138,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
transform.popPose();
|
||||
}
|
||||
|
||||
private static void renderTerminal( @Nonnull MultiBufferSource bufferSource, Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin )
|
||||
private static void renderTerminal( Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin )
|
||||
{
|
||||
Terminal terminal = monitor.getTerminal();
|
||||
int width = terminal.getWidth(), height = terminal.getHeight();
|
||||
@@ -163,59 +172,81 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
|
||||
MonitorTextureBufferShader shader = RenderTypes.getMonitorTextureBufferShader();
|
||||
shader.setupUniform( monitor.tboUniform );
|
||||
|
||||
VertexConsumer buffer = bufferSource.getBuffer( RenderTypes.MONITOR_TBO );
|
||||
BufferBuilder buffer = Tesselator.getInstance().getBuilder();
|
||||
buffer.begin( RenderTypes.MONITOR_TBO.mode(), RenderTypes.MONITOR_TBO.format() );
|
||||
tboVertex( buffer, matrix, -xMargin, -yMargin );
|
||||
tboVertex( buffer, matrix, -xMargin, pixelHeight + yMargin );
|
||||
tboVertex( buffer, matrix, pixelWidth + xMargin, -yMargin );
|
||||
tboVertex( buffer, matrix, pixelWidth + xMargin, pixelHeight + yMargin );
|
||||
RenderTypes.MONITOR_TBO.end( buffer, 0, 0, 0 );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case VBO:
|
||||
{
|
||||
var vbo = monitor.buffer;
|
||||
var backgroundBuffer = monitor.backgroundBuffer;
|
||||
var foregroundBuffer = monitor.foregroundBuffer;
|
||||
if( redraw )
|
||||
{
|
||||
int vertexSize = RenderTypes.TERMINAL_WITHOUT_DEPTH.format().getVertexSize();
|
||||
ByteBuffer buffer = getBuffer( DirectFixedWidthFontRenderer.getVertexCount( terminal ) * vertexSize );
|
||||
int size = DirectFixedWidthFontRenderer.getVertexCount( terminal );
|
||||
|
||||
// Draw the main terminal and store how many vertices it has.
|
||||
DirectFixedWidthFontRenderer.drawTerminalWithoutCursor(
|
||||
buffer, 0, 0, terminal, !monitor.isColour(), yMargin, yMargin, xMargin, xMargin
|
||||
);
|
||||
int termIndexes = buffer.position() / vertexSize;
|
||||
// In an ideal world we could upload these both into one buffer. However, we can't render VBOs with
|
||||
// and starting and ending offset, and so need to use two buffers instead.
|
||||
|
||||
// If the cursor is visible, we append it to the end of our buffer. When rendering, we can either
|
||||
// render n or n+1 quads and so toggle the cursor on and off.
|
||||
DirectFixedWidthFontRenderer.drawCursor( buffer, 0, 0, terminal, !monitor.isColour() );
|
||||
renderToBuffer( backgroundBuffer, size, sink ->
|
||||
DirectFixedWidthFontRenderer.drawTerminalBackground( sink, 0, 0, terminal, !monitor.isColour(), yMargin, yMargin, xMargin, xMargin ) );
|
||||
|
||||
buffer.flip();
|
||||
|
||||
vbo.upload( termIndexes, RenderTypes.TERMINAL_WITHOUT_DEPTH.mode(), RenderTypes.TERMINAL_WITHOUT_DEPTH.format(), buffer );
|
||||
renderToBuffer( foregroundBuffer, size, sink -> {
|
||||
DirectFixedWidthFontRenderer.drawTerminalForeground( sink, 0, 0, terminal, !monitor.isColour() );
|
||||
// If the cursor is visible, we append it to the end of our buffer. When rendering, we can either
|
||||
// render n or n+1 quads and so toggle the cursor on and off.
|
||||
DirectFixedWidthFontRenderer.drawCursor( sink, 0, 0, terminal, !monitor.isColour() );
|
||||
} );
|
||||
}
|
||||
|
||||
bufferSource.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH );
|
||||
RenderTypes.TERMINAL_WITHOUT_DEPTH.setupRenderState();
|
||||
// Our VBO doesn't transform its vertices with the provided pose stack, which means that the inverse view
|
||||
// rotation matrix gives entirely wrong numbers for fog distances. We just set it to the identity which
|
||||
// gives a good enough approximation.
|
||||
Matrix3f oldInverseRotation = RenderSystem.getInverseViewRotationMatrix();
|
||||
RenderSystem.setInverseViewRotationMatrix( IDENTITY_NORMAL );
|
||||
|
||||
vbo.drawWithShader(
|
||||
RenderTypes.TERMINAL.setupRenderState();
|
||||
|
||||
// Render background geometry
|
||||
backgroundBuffer.drawWithShader( matrix, RenderSystem.getProjectionMatrix(), RenderTypes.getTerminalShader() );
|
||||
|
||||
// Render foreground geometry with glPolygonOffset enabled.
|
||||
GL11.glPolygonOffset( -1.0f, -10.0f );
|
||||
GL11.glEnable( GL11.GL_POLYGON_OFFSET_FILL );
|
||||
foregroundBuffer.drawWithShader(
|
||||
matrix, RenderSystem.getProjectionMatrix(), RenderTypes.getTerminalShader(),
|
||||
// As mentioned in the above comment, render the extra cursor quad if it is visible this frame. Each
|
||||
// // quad has an index count of 6.
|
||||
FixedWidthFontRenderer.isCursorVisible( terminal ) && FrameInfo.getGlobalCursorBlink() ? vbo.getIndexCount() + 6 : vbo.getIndexCount()
|
||||
FixedWidthFontRenderer.isCursorVisible( terminal ) && FrameInfo.getGlobalCursorBlink()
|
||||
? foregroundBuffer.getIndexCount() + 6 : foregroundBuffer.getIndexCount()
|
||||
);
|
||||
|
||||
FixedWidthFontRenderer.drawBlocker(
|
||||
FixedWidthFontRenderer.toVertexConsumer( matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_BLOCKER ) ),
|
||||
-xMargin, -yMargin, pixelWidth + xMargin, pixelHeight + yMargin
|
||||
);
|
||||
// Clear state
|
||||
GL11.glPolygonOffset( 0.0f, -0.0f );
|
||||
GL11.glDisable( GL11.GL_POLYGON_OFFSET_FILL );
|
||||
RenderTypes.TERMINAL.clearRenderState();
|
||||
|
||||
RenderSystem.setInverseViewRotationMatrix( oldInverseRotation );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Force a flush of the buffer. WorldRenderer.updateCameraAndRender will "finish" all the built-in buffers
|
||||
// before calling renderer.finish, which means our TBO quad or depth blocker won't be rendered yet!
|
||||
bufferSource.getBuffer( RenderType.solid() );
|
||||
private static void renderToBuffer( DirectVertexBuffer vbo, int size, Consumer<DirectFixedWidthFontRenderer.QuadEmitter> draw )
|
||||
{
|
||||
var sink = ShaderMod.INSTANCE.getQuadEmitter( size, TileEntityMonitorRenderer::getBuffer );
|
||||
var buffer = sink.buffer();
|
||||
|
||||
draw.accept( sink );
|
||||
buffer.flip();
|
||||
vbo.upload( buffer.limit() / sink.format().getVertexSize(), RenderTypes.TERMINAL.mode(), sink.format(), buffer );
|
||||
}
|
||||
|
||||
private static void tboVertex( VertexConsumer builder, Matrix4f matrix, float x, float y )
|
||||
|
||||
@@ -8,6 +8,8 @@ package dan200.computercraft.client.render.text;
|
||||
import com.mojang.blaze3d.platform.MemoryTracker;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
@@ -18,17 +20,16 @@ import javax.annotation.Nonnull;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static dan200.computercraft.client.render.text.FixedWidthFontRenderer.*;
|
||||
import static org.lwjgl.system.MemoryUtil.memPutByte;
|
||||
import static org.lwjgl.system.MemoryUtil.memPutFloat;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
/**
|
||||
* An optimised copy of {@link FixedWidthFontRenderer} emitter emits directly to a {@link ByteBuffer} rather than
|
||||
* An optimised copy of {@link FixedWidthFontRenderer} emitter emits directly to a {@link QuadEmitter} rather than
|
||||
* emitting to {@link VertexConsumer}. This allows us to emit vertices very quickly, when using the VBO renderer.
|
||||
*
|
||||
* There are some limitations here:
|
||||
* <ul>
|
||||
* <li>No transformation matrix (not needed for VBOs).</li>
|
||||
* <li>Only works with {@link DefaultVertexFormat#POSITION_COLOR_TEX}.</li>
|
||||
* <li>Only works with {@link DefaultVertexFormat#POSITION_COLOR_TEX_LIGHTMAP}.</li>
|
||||
* <li>The buffer <strong>MUST</strong> be allocated with {@link MemoryTracker}, and not through any other means.</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -44,7 +45,7 @@ public final class DirectFixedWidthFontRenderer
|
||||
{
|
||||
}
|
||||
|
||||
private static void drawChar( ByteBuffer buffer, float x, float y, int index, byte[] colour )
|
||||
private static void drawChar( QuadEmitter emitter, float x, float y, int index, byte[] colour )
|
||||
{
|
||||
// Short circuit to avoid the common case - the texture should be blank here after all.
|
||||
if( index == '\0' || index == ' ' ) return;
|
||||
@@ -56,30 +57,30 @@ public final class DirectFixedWidthFontRenderer
|
||||
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
||||
|
||||
quad(
|
||||
buffer, x, y, x + FONT_WIDTH, y + FONT_HEIGHT, colour,
|
||||
emitter, x, y, x + FONT_WIDTH, y + FONT_HEIGHT, 0, colour,
|
||||
xStart / WIDTH, yStart / WIDTH, (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH
|
||||
);
|
||||
}
|
||||
|
||||
private static void drawQuad( ByteBuffer emitter, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex )
|
||||
private static void drawQuad( QuadEmitter emitter, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex )
|
||||
{
|
||||
byte[] colour = palette.getByteColour( getColour( colourIndex, Colour.BLACK ), greyscale );
|
||||
quad( emitter, x, y, x + width, y + height, colour, BACKGROUND_START, BACKGROUND_START, BACKGROUND_END, BACKGROUND_END );
|
||||
quad( emitter, x, y, x + width, y + height, 0f, colour, BACKGROUND_START, BACKGROUND_START, BACKGROUND_END, BACKGROUND_END );
|
||||
}
|
||||
|
||||
private static void drawBackground(
|
||||
@Nonnull ByteBuffer buffer, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale,
|
||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale,
|
||||
float leftMarginSize, float rightMarginSize, float height
|
||||
)
|
||||
{
|
||||
if( leftMarginSize > 0 )
|
||||
{
|
||||
drawQuad( buffer, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ) );
|
||||
drawQuad( emitter, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ) );
|
||||
}
|
||||
|
||||
if( rightMarginSize > 0 )
|
||||
{
|
||||
drawQuad( buffer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ) );
|
||||
drawQuad( emitter, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ) );
|
||||
}
|
||||
|
||||
// Batch together runs of identical background cells.
|
||||
@@ -92,7 +93,7 @@ public final class DirectFixedWidthFontRenderer
|
||||
|
||||
if( blockColour != '\0' )
|
||||
{
|
||||
drawQuad( buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour );
|
||||
drawQuad( emitter, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour );
|
||||
}
|
||||
|
||||
blockColour = colourIndex;
|
||||
@@ -101,11 +102,11 @@ public final class DirectFixedWidthFontRenderer
|
||||
|
||||
if( blockColour != '\0' )
|
||||
{
|
||||
drawQuad( buffer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour );
|
||||
drawQuad( emitter, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour );
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawString( @Nonnull ByteBuffer buffer, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette, boolean greyscale )
|
||||
public static void drawString( @Nonnull QuadEmitter emitter, float x, float y, @Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nonnull Palette palette, boolean greyscale )
|
||||
{
|
||||
for( int i = 0; i < text.length(); i++ )
|
||||
{
|
||||
@@ -113,12 +114,29 @@ public final class DirectFixedWidthFontRenderer
|
||||
|
||||
int index = text.charAt( i );
|
||||
if( index > 255 ) index = '?';
|
||||
drawChar( buffer, x + i * FONT_WIDTH, y, index, colour );
|
||||
drawChar( emitter, x + i * FONT_WIDTH, y, index, colour );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void drawTerminalForeground( @Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal, boolean greyscale )
|
||||
{
|
||||
Palette palette = terminal.getPalette();
|
||||
int height = terminal.getHeight();
|
||||
|
||||
// The main text
|
||||
for( int i = 0; i < height; i++ )
|
||||
{
|
||||
float rowY = y + FONT_HEIGHT * i;
|
||||
drawString(
|
||||
emitter, x, rowY, terminal.getLine( i ), terminal.getTextColourLine( i ),
|
||||
palette, greyscale
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTerminalWithoutCursor(
|
||||
@Nonnull ByteBuffer buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale,
|
||||
public static void drawTerminalBackground(
|
||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal, boolean greyscale,
|
||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
@@ -127,12 +145,12 @@ public final class DirectFixedWidthFontRenderer
|
||||
|
||||
// Top and bottom margins
|
||||
drawBackground(
|
||||
buffer, x, y - topMarginSize, terminal.getBackgroundColourLine( 0 ), palette, greyscale,
|
||||
emitter, x, y - topMarginSize, terminal.getBackgroundColourLine( 0 ), palette, greyscale,
|
||||
leftMarginSize, rightMarginSize, topMarginSize
|
||||
);
|
||||
|
||||
drawBackground(
|
||||
buffer, x, y + height * FONT_HEIGHT, terminal.getBackgroundColourLine( height - 1 ), palette, greyscale,
|
||||
emitter, x, y + height * FONT_HEIGHT, terminal.getBackgroundColourLine( height - 1 ), palette, greyscale,
|
||||
leftMarginSize, rightMarginSize, bottomMarginSize
|
||||
);
|
||||
|
||||
@@ -141,43 +159,68 @@ public final class DirectFixedWidthFontRenderer
|
||||
{
|
||||
float rowY = y + FONT_HEIGHT * i;
|
||||
drawBackground(
|
||||
buffer, x, rowY, terminal.getBackgroundColourLine( i ), palette, greyscale,
|
||||
emitter, x, rowY, terminal.getBackgroundColourLine( i ), palette, greyscale,
|
||||
leftMarginSize, rightMarginSize, FONT_HEIGHT
|
||||
);
|
||||
drawString(
|
||||
buffer, x, rowY, terminal.getLine( i ), terminal.getTextColourLine( i ),
|
||||
palette, greyscale
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawCursor( @Nonnull ByteBuffer buffer, float x, float y, @Nonnull Terminal terminal, boolean greyscale )
|
||||
public static void drawCursor( @Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal, boolean greyscale )
|
||||
{
|
||||
if( isCursorVisible( terminal ) )
|
||||
{
|
||||
byte[] colour = terminal.getPalette().getByteColour( 15 - terminal.getTextColour(), greyscale );
|
||||
drawChar( buffer, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour );
|
||||
drawChar( emitter, x + terminal.getCursorX() * FONT_WIDTH, y + terminal.getCursorY() * FONT_HEIGHT, '_', colour );
|
||||
}
|
||||
}
|
||||
|
||||
public static int getVertexCount( Terminal terminal )
|
||||
{
|
||||
return (1 + (terminal.getHeight() + 2) * terminal.getWidth() * 2) * 4;
|
||||
return (terminal.getHeight() + 2) * (terminal.getWidth() + 2) * 2;
|
||||
}
|
||||
|
||||
private static void quad( ByteBuffer buffer, float x1, float y1, float x2, float y2, byte[] rgba, float u1, float v1, float u2, float v2 )
|
||||
private static void quad( QuadEmitter buffer, float x1, float y1, float x2, float y2, float z, byte[] rgba, float u1, float v1, float u2, float v2 )
|
||||
{
|
||||
buffer.quad( x1, y1, x2, y2, z, rgba, u1, v1, u2, v2 );
|
||||
}
|
||||
|
||||
public interface QuadEmitter
|
||||
{
|
||||
VertexFormat format();
|
||||
|
||||
ByteBuffer buffer();
|
||||
|
||||
void quad( float x1, float y1, float x2, float y2, float z, byte[] rgba, float u1, float v1, float u2, float v2 );
|
||||
}
|
||||
|
||||
public record ByteBufferEmitter(ByteBuffer buffer) implements QuadEmitter
|
||||
{
|
||||
@Override
|
||||
public VertexFormat format()
|
||||
{
|
||||
return RenderTypes.TERMINAL.format();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quad( float x1, float y1, float x2, float y2, float z, byte[] rgba, float u1, float v1, float u2, float v2 )
|
||||
{
|
||||
DirectFixedWidthFontRenderer.quad( buffer, x1, y1, x2, y2, z, rgba, u1, v1, u2, v2 );
|
||||
}
|
||||
}
|
||||
|
||||
static void quad( ByteBuffer buffer, float x1, float y1, float x2, float y2, float z, byte[] rgba, float u1, float v1, float u2, float v2 )
|
||||
{
|
||||
// Emit a single quad to our buffer. This uses Unsafe (well, LWJGL's MemoryUtil) to directly blit bytes to the
|
||||
// underlying buffer. This allows us to have a single bounds check up-front, rather than one for every write.
|
||||
// This provides significant performance gains, at the cost of well, using Unsafe.
|
||||
// Each vertex is 24 bytes, giving 96 bytes in total. Vertices are of the form (xyz:FFF)(rgba:BBBB)(uv:FF),
|
||||
// which matches the POSITION_COLOR_TEX vertex format.
|
||||
// Each vertex is 28 bytes, giving 112 bytes in total. Vertices are of the form (xyz:FFF)(rgba:BBBB)(uv1:FF)(uv2:SS),
|
||||
// which matches the POSITION_COLOR_TEX_LIGHTMAP vertex format.
|
||||
|
||||
int position = buffer.position();
|
||||
long addr = MemoryUtil.memAddress( buffer );
|
||||
|
||||
// We're doing terrible unsafe hacks below, so let's be really sure that what we're doing is reasonable.
|
||||
if( position < 0 || 96 > buffer.limit() - position ) throw new IndexOutOfBoundsException();
|
||||
if( position < 0 || 112 > buffer.limit() - position ) throw new IndexOutOfBoundsException();
|
||||
// Require the pointer to be aligned to a 32-bit boundary.
|
||||
if( (addr & 3) != 0 ) throw new IllegalStateException( "Memory is not aligned" );
|
||||
// Also assert the length of the array. This appears to help elide bounds checks on the array in some circumstances.
|
||||
@@ -185,46 +228,54 @@ public final class DirectFixedWidthFontRenderer
|
||||
|
||||
memPutFloat( addr + 0, x1 );
|
||||
memPutFloat( addr + 4, y1 );
|
||||
memPutFloat( addr + 8, 0 );
|
||||
memPutFloat( addr + 8, z );
|
||||
memPutByte( addr + 12, rgba[0] );
|
||||
memPutByte( addr + 13, rgba[1] );
|
||||
memPutByte( addr + 14, rgba[2] );
|
||||
memPutByte( addr + 15, (byte) 255 );
|
||||
memPutFloat( addr + 16, u1 );
|
||||
memPutFloat( addr + 20, v1 );
|
||||
memPutShort( addr + 24, (short) 0xF0 );
|
||||
memPutShort( addr + 26, (short) 0xF0 );
|
||||
|
||||
memPutFloat( addr + 24, x1 );
|
||||
memPutFloat( addr + 28, y2 );
|
||||
memPutFloat( addr + 32, 0 );
|
||||
memPutByte( addr + 36, rgba[0] );
|
||||
memPutByte( addr + 37, rgba[1] );
|
||||
memPutByte( addr + 38, rgba[2] );
|
||||
memPutByte( addr + 39, (byte) 255 );
|
||||
memPutFloat( addr + 40, u1 );
|
||||
memPutFloat( addr + 44, v2 );
|
||||
memPutFloat( addr + 28, x1 );
|
||||
memPutFloat( addr + 32, y2 );
|
||||
memPutFloat( addr + 36, z );
|
||||
memPutByte( addr + 40, rgba[0] );
|
||||
memPutByte( addr + 41, rgba[1] );
|
||||
memPutByte( addr + 42, rgba[2] );
|
||||
memPutByte( addr + 43, (byte) 255 );
|
||||
memPutFloat( addr + 44, u1 );
|
||||
memPutFloat( addr + 48, v2 );
|
||||
memPutShort( addr + 52, (short) 0xF0 );
|
||||
memPutShort( addr + 54, (short) 0xF0 );
|
||||
|
||||
memPutFloat( addr + 48, x2 );
|
||||
memPutFloat( addr + 52, y2 );
|
||||
memPutFloat( addr + 56, 0 );
|
||||
memPutByte( addr + 60, rgba[0] );
|
||||
memPutByte( addr + 61, rgba[1] );
|
||||
memPutByte( addr + 62, rgba[2] );
|
||||
memPutByte( addr + 63, (byte) 255 );
|
||||
memPutFloat( addr + 64, u2 );
|
||||
memPutFloat( addr + 68, v2 );
|
||||
memPutFloat( addr + 56, x2 );
|
||||
memPutFloat( addr + 60, y2 );
|
||||
memPutFloat( addr + 64, z );
|
||||
memPutByte( addr + 68, rgba[0] );
|
||||
memPutByte( addr + 69, rgba[1] );
|
||||
memPutByte( addr + 70, rgba[2] );
|
||||
memPutByte( addr + 71, (byte) 255 );
|
||||
memPutFloat( addr + 72, u2 );
|
||||
memPutFloat( addr + 76, v2 );
|
||||
memPutShort( addr + 80, (short) 0xF0 );
|
||||
memPutShort( addr + 82, (short) 0xF0 );
|
||||
|
||||
memPutFloat( addr + 72, x2 );
|
||||
memPutFloat( addr + 76, y1 );
|
||||
memPutFloat( addr + 80, 0 );
|
||||
memPutByte( addr + 84, rgba[0] );
|
||||
memPutByte( addr + 85, rgba[1] );
|
||||
memPutByte( addr + 86, rgba[2] );
|
||||
memPutByte( addr + 87, (byte) 255 );
|
||||
memPutFloat( addr + 88, u2 );
|
||||
memPutFloat( addr + 92, v1 );
|
||||
memPutFloat( addr + 84, x2 );
|
||||
memPutFloat( addr + 88, y1 );
|
||||
memPutFloat( addr + 92, z );
|
||||
memPutByte( addr + 96, rgba[0] );
|
||||
memPutByte( addr + 97, rgba[1] );
|
||||
memPutByte( addr + 98, rgba[2] );
|
||||
memPutByte( addr + 99, (byte) 255 );
|
||||
memPutFloat( addr + 100, u2 );
|
||||
memPutFloat( addr + 104, v1 );
|
||||
memPutShort( addr + 108, (short) 0xF0 );
|
||||
memPutShort( addr + 110, (short) 0xF0 );
|
||||
|
||||
// Finally increment the position.
|
||||
buffer.position( position + 96 );
|
||||
buffer.position( position + 112 );
|
||||
|
||||
// Well done for getting to the end of this method. I recommend you take a break and go look at cute puppies.
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
*/
|
||||
package dan200.computercraft.client.render.text;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import dan200.computercraft.client.FrameInfo;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import dan200.computercraft.core.terminal.Terminal;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
@@ -26,13 +27,8 @@ import static dan200.computercraft.client.render.RenderTypes.FULL_BRIGHT_LIGHTMA
|
||||
* <ul>
|
||||
* <li>{@link #drawString}: Drawing basic text without a terminal (such as for printouts). Unlike the other methods,
|
||||
* this accepts a lightmap coordinate as, unlike terminals, printed pages render fullbright.</li>
|
||||
* <li>{@link #drawTerminalWithoutCursor}/{@link #drawCursor}: Draw a terminal without a cursor and then draw the cursor
|
||||
* separately. This is used by the monitor renderer to render the terminal to a VBO and draw the cursor dynamically.
|
||||
* </li>
|
||||
* <li>{@link #drawTerminal}: Draw a terminal with a cursor. This is used by the various computer GUIs to render the
|
||||
* whole term.</li>
|
||||
* <li>{@link #drawBlocker}: When rendering a terminal using {@link RenderTypes#TERMINAL_WITHOUT_DEPTH} you need to
|
||||
* render an additional "depth blocker" on top of the monitor.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <strong>IMPORTANT: </strong> When making changes to this class, please check if you need to make the same changes to
|
||||
@@ -50,6 +46,7 @@ public final class FixedWidthFontRenderer
|
||||
static final float BACKGROUND_END = (WIDTH - 4.0f) / WIDTH;
|
||||
|
||||
private static final byte[] BLACK = new byte[] { byteColour( Colour.BLACK.getR() ), byteColour( Colour.BLACK.getR() ), byteColour( Colour.BLACK.getR() ), (byte) 255 };
|
||||
private static final float Z_OFFSET = 1e-3f;
|
||||
|
||||
private FixedWidthFontRenderer()
|
||||
{
|
||||
@@ -149,9 +146,24 @@ public final class FixedWidthFontRenderer
|
||||
|
||||
}
|
||||
|
||||
public static void drawTerminalWithoutCursor(
|
||||
@Nonnull QuadEmitter emitter, float x, float y,
|
||||
@Nonnull Terminal terminal, boolean greyscale,
|
||||
public static void drawTerminalForeground( @Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal, boolean greyscale )
|
||||
{
|
||||
Palette palette = terminal.getPalette();
|
||||
int height = terminal.getHeight();
|
||||
|
||||
// The main text
|
||||
for( int i = 0; i < height; i++ )
|
||||
{
|
||||
float rowY = y + FONT_HEIGHT * i;
|
||||
drawString(
|
||||
emitter, x, rowY, terminal.getLine( i ), terminal.getTextColourLine( i ),
|
||||
palette, greyscale, FULL_BRIGHT_LIGHTMAP
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawTerminalBackground(
|
||||
@Nonnull QuadEmitter emitter, float x, float y, @Nonnull Terminal terminal, boolean greyscale,
|
||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
@@ -172,15 +184,11 @@ public final class FixedWidthFontRenderer
|
||||
// The main text
|
||||
for( int i = 0; i < height; i++ )
|
||||
{
|
||||
float rowY = y + FixedWidthFontRenderer.FONT_HEIGHT * i;
|
||||
float rowY = y + FONT_HEIGHT * i;
|
||||
drawBackground(
|
||||
emitter, x, rowY, terminal.getBackgroundColourLine( i ), palette, greyscale,
|
||||
leftMarginSize, rightMarginSize, FONT_HEIGHT, FULL_BRIGHT_LIGHTMAP
|
||||
);
|
||||
drawString(
|
||||
emitter, x, rowY, terminal.getLine( i ), terminal.getTextColourLine( i ),
|
||||
palette, greyscale, FULL_BRIGHT_LIGHTMAP
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -208,8 +216,21 @@ public final class FixedWidthFontRenderer
|
||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||
)
|
||||
{
|
||||
drawTerminalWithoutCursor( emitter, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||
drawTerminalBackground(
|
||||
emitter, x, y, terminal, greyscale,
|
||||
topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize
|
||||
);
|
||||
|
||||
// Render the foreground with a slight offset. By calling .translate() on the matrix itself, we're translating
|
||||
// in screen space, rather than in model/view space.
|
||||
// It's definitely not perfect, but better than z fighting!
|
||||
var transformBackup = emitter.poseMatrix().copy();
|
||||
emitter.poseMatrix().translate( new Vector3f( 0, 0, Z_OFFSET ) );
|
||||
|
||||
drawTerminalForeground( emitter, x, y, terminal, greyscale );
|
||||
drawCursor( emitter, x, y, terminal, greyscale );
|
||||
|
||||
emitter.poseMatrix().load( transformBackup );
|
||||
}
|
||||
|
||||
public static void drawEmptyTerminal( @Nonnull QuadEmitter emitter, float x, float y, float width, float height )
|
||||
@@ -217,27 +238,24 @@ public final class FixedWidthFontRenderer
|
||||
drawQuad( emitter, x, y, 0, width, height, BLACK, FULL_BRIGHT_LIGHTMAP );
|
||||
}
|
||||
|
||||
public static void drawBlocker( @Nonnull QuadEmitter emitter, float x, float y, float width, float height )
|
||||
public record QuadEmitter(Matrix4f poseMatrix, VertexConsumer consumer)
|
||||
{
|
||||
drawQuad( emitter, x, y, 0, width, height, BLACK, FULL_BRIGHT_LIGHTMAP );
|
||||
}
|
||||
|
||||
public record QuadEmitter(Matrix4f matrix4f, VertexConsumer consumer) {}
|
||||
|
||||
public static QuadEmitter toVertexConsumer( Matrix4f matrix, VertexConsumer consumer )
|
||||
public static QuadEmitter toVertexConsumer( PoseStack transform, VertexConsumer consumer )
|
||||
{
|
||||
return new QuadEmitter( matrix, consumer );
|
||||
return new QuadEmitter( transform.last().pose(), consumer );
|
||||
}
|
||||
|
||||
private static void quad( QuadEmitter c, float x1, float y1, float x2, float y2, float z, byte[] rgba, float u1, float v1, float u2, float v2, int light )
|
||||
{
|
||||
var matrix = c.matrix4f();
|
||||
var poseMatrix = c.poseMatrix();
|
||||
var consumer = c.consumer();
|
||||
byte r = rgba[0], g = rgba[1], b = rgba[2], a = rgba[3];
|
||||
|
||||
consumer.vertex( matrix, x1, y1, z ).color( r, g, b, a ).uv( u1, v1 ).uv2( light ).endVertex();
|
||||
consumer.vertex( matrix, x1, y2, z ).color( r, g, b, a ).uv( u1, v2 ).uv2( light ).endVertex();
|
||||
consumer.vertex( matrix, x2, y2, z ).color( r, g, b, a ).uv( u2, v2 ).uv2( light ).endVertex();
|
||||
consumer.vertex( matrix, x2, y1, z ).color( r, g, b, a ).uv( u2, v1 ).uv2( light ).endVertex();
|
||||
consumer.vertex( poseMatrix, x1, y1, z ).color( r, g, b, a ).uv( u1, v1 ).uv2( light ).endVertex();
|
||||
consumer.vertex( poseMatrix, x1, y2, z ).color( r, g, b, a ).uv( u1, v2 ).uv2( light ).endVertex();
|
||||
consumer.vertex( poseMatrix, x2, y2, z ).color( r, g, b, a ).uv( u2, v2 ).uv2( light ).endVertex();
|
||||
consumer.vertex( poseMatrix, x2, y1, z ).color( r, g, b, a ).uv( u2, v1 ).uv2( light ).endVertex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ final class LuaDateTime
|
||||
{
|
||||
}
|
||||
|
||||
static void format( DateTimeFormatterBuilder formatter, String format, ZoneOffset offset ) throws LuaException
|
||||
static void format( DateTimeFormatterBuilder formatter, String format ) throws LuaException
|
||||
{
|
||||
for( int i = 0; i < format.length(); )
|
||||
{
|
||||
@@ -61,7 +61,7 @@ final class LuaDateTime
|
||||
formatter.appendText( ChronoField.MONTH_OF_YEAR, TextStyle.FULL );
|
||||
break;
|
||||
case 'c':
|
||||
format( formatter, "%a %b %e %H:%M:%S %Y", offset );
|
||||
format( formatter, "%a %b %e %H:%M:%S %Y" );
|
||||
break;
|
||||
case 'C':
|
||||
formatter.appendValueReduced( CENTURY, 2, 2, 0 );
|
||||
@@ -71,13 +71,13 @@ final class LuaDateTime
|
||||
break;
|
||||
case 'D':
|
||||
case 'x':
|
||||
format( formatter, "%m/%d/%y", offset );
|
||||
format( formatter, "%m/%d/%y" );
|
||||
break;
|
||||
case 'e':
|
||||
formatter.padNext( 2 ).appendValue( ChronoField.DAY_OF_MONTH );
|
||||
break;
|
||||
case 'F':
|
||||
format( formatter, "%Y-%m-%d", offset );
|
||||
format( formatter, "%Y-%m-%d" );
|
||||
break;
|
||||
case 'g':
|
||||
formatter.appendValueReduced( IsoFields.WEEK_BASED_YEAR, 2, 2, 0 );
|
||||
@@ -107,10 +107,10 @@ final class LuaDateTime
|
||||
formatter.appendText( ChronoField.AMPM_OF_DAY );
|
||||
break;
|
||||
case 'r':
|
||||
format( formatter, "%I:%M:%S %p", offset );
|
||||
format( formatter, "%I:%M:%S %p" );
|
||||
break;
|
||||
case 'R':
|
||||
format( formatter, "%H:%M", offset );
|
||||
format( formatter, "%H:%M" );
|
||||
break;
|
||||
case 'S':
|
||||
formatter.appendValue( ChronoField.SECOND_OF_MINUTE, 2 );
|
||||
@@ -120,7 +120,7 @@ final class LuaDateTime
|
||||
break;
|
||||
case 'T':
|
||||
case 'X':
|
||||
format( formatter, "%H:%M:%S", offset );
|
||||
format( formatter, "%H:%M:%S" );
|
||||
break;
|
||||
case 'u':
|
||||
formatter.appendValue( ChronoField.DAY_OF_WEEK );
|
||||
@@ -212,15 +212,13 @@ final class LuaDateTime
|
||||
throw new LuaException( "field \"" + field + "\" missing in date table" );
|
||||
}
|
||||
|
||||
private static final TemporalField CENTURY = map( ChronoField.YEAR, ValueRange.of( 0, 6 ), x -> (x / 100) % 100 );
|
||||
private static final TemporalField CENTURY = map( ChronoField.YEAR, ValueRange.of( 0, 99 ), x -> (x / 100) % 100 );
|
||||
private static final TemporalField ZERO_WEEK = map( WeekFields.SUNDAY_START.dayOfWeek(), ValueRange.of( 0, 6 ), x -> x - 1 );
|
||||
|
||||
private static TemporalField map( TemporalField field, ValueRange range, LongUnaryOperator convert )
|
||||
{
|
||||
return new TemporalField()
|
||||
{
|
||||
private final ValueRange range = ValueRange.of( 0, 99 );
|
||||
|
||||
@Override
|
||||
public TemporalUnit getBaseUnit()
|
||||
{
|
||||
|
||||
@@ -316,7 +316,7 @@ public class OSAPI implements ILuaAPI
|
||||
* Returns the current time depending on the string passed in. This will
|
||||
* always be in the range [0.0, 24.0).
|
||||
*
|
||||
* * If called with {@code dan200.computercraft.ingame}, the current world time will be returned.
|
||||
* * If called with {@code ingame}, the current world time will be returned.
|
||||
* This is the default if nothing is passed.
|
||||
* * If called with {@code utc}, returns the hour of the day in UTC time.
|
||||
* * If called with {@code local}, returns the hour of the day in the
|
||||
@@ -326,10 +326,10 @@ public class OSAPI implements ILuaAPI
|
||||
* which will convert the date fields into a UNIX timestamp (number of
|
||||
* seconds since 1 January 1970).
|
||||
*
|
||||
* @param args The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code dan200.computercraft.ingame} locale if not specified.
|
||||
* @param args The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code ingame} locale if not specified.
|
||||
* @return The hour of the selected locale, or a UNIX timestamp from the table, depending on the argument passed in.
|
||||
* @throws LuaException If an invalid locale is passed.
|
||||
* @cc.tparam [opt] string|table locale The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code dan200.computercraft.ingame} locale if not specified.
|
||||
* @cc.tparam [opt] string|table locale The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code ingame} locale if not specified.
|
||||
* @cc.see textutils.formatTime To convert times into a user-readable string.
|
||||
* @cc.usage Print the current in-game time.
|
||||
* <pre>{@code
|
||||
@@ -347,14 +347,14 @@ public class OSAPI implements ILuaAPI
|
||||
Object value = args.get( 0 );
|
||||
if( value instanceof Map ) return LuaDateTime.fromTable( (Map<?, ?>) value );
|
||||
|
||||
String param = args.optString( 0, "dan200.computercraft.ingame" );
|
||||
String param = args.optString( 0, "ingame" );
|
||||
switch( param.toLowerCase( Locale.ROOT ) )
|
||||
{
|
||||
case "utc": // Get Hour of day (UTC)
|
||||
return getTimeForCalendar( Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ) );
|
||||
case "local": // Get Hour of day (local time)
|
||||
return getTimeForCalendar( Calendar.getInstance() );
|
||||
case "dan200.computercraft.ingame": // Get in-game hour
|
||||
case "ingame": // Get in-game hour
|
||||
return time;
|
||||
default:
|
||||
throw new LuaException( "Unsupported operation" );
|
||||
@@ -364,14 +364,14 @@ public class OSAPI implements ILuaAPI
|
||||
/**
|
||||
* Returns the day depending on the locale specified.
|
||||
*
|
||||
* * If called with {@code dan200.computercraft.ingame}, returns the number of days since the
|
||||
* * If called with {@code ingame}, returns the number of days since the
|
||||
* world was created. This is the default.
|
||||
* * If called with {@code utc}, returns the number of days since 1 January
|
||||
* 1970 in the UTC timezone.
|
||||
* * If called with {@code local}, returns the number of days since 1
|
||||
* January 1970 in the server's local timezone.
|
||||
*
|
||||
* @param args The locale to get the day for. Defaults to {@code dan200.computercraft.ingame} if not set.
|
||||
* @param args The locale to get the day for. Defaults to {@code ingame} if not set.
|
||||
* @return The day depending on the selected locale.
|
||||
* @throws LuaException If an invalid locale is passed.
|
||||
* @cc.since 1.48
|
||||
@@ -380,13 +380,13 @@ public class OSAPI implements ILuaAPI
|
||||
@LuaFunction
|
||||
public final int day( Optional<String> args ) throws LuaException
|
||||
{
|
||||
switch( args.orElse( "dan200.computercraft.ingame" ).toLowerCase( Locale.ROOT ) )
|
||||
switch( args.orElse( "ingame" ).toLowerCase( Locale.ROOT ) )
|
||||
{
|
||||
case "utc": // Get numbers of days since 1970-01-01 (utc)
|
||||
return getDayForCalendar( Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ) );
|
||||
case "local": // Get numbers of days since 1970-01-01 (local time)
|
||||
return getDayForCalendar( Calendar.getInstance() );
|
||||
case "dan200.computercraft.ingame":// Get game day
|
||||
case "ingame":// Get game day
|
||||
return day;
|
||||
default:
|
||||
throw new LuaException( "Unsupported operation" );
|
||||
@@ -396,14 +396,14 @@ public class OSAPI implements ILuaAPI
|
||||
/**
|
||||
* Returns the number of milliseconds since an epoch depending on the locale.
|
||||
*
|
||||
* * If called with {@code dan200.computercraft.ingame}, returns the number of milliseconds since the
|
||||
* * If called with {@code ingame}, returns the number of milliseconds since the
|
||||
* world was created. This is the default.
|
||||
* * If called with {@code utc}, returns the number of milliseconds since 1
|
||||
* January 1970 in the UTC timezone.
|
||||
* * If called with {@code local}, returns the number of milliseconds since 1
|
||||
* January 1970 in the server's local timezone.
|
||||
*
|
||||
* @param args The locale to get the milliseconds for. Defaults to {@code dan200.computercraft.ingame} if not set.
|
||||
* @param args The locale to get the milliseconds for. Defaults to {@code ingame} if not set.
|
||||
* @return The milliseconds since the epoch depending on the selected locale.
|
||||
* @throws LuaException If an invalid locale is passed.
|
||||
* @cc.since 1.80pr1
|
||||
@@ -418,7 +418,7 @@ public class OSAPI implements ILuaAPI
|
||||
@LuaFunction
|
||||
public final long epoch( Optional<String> args ) throws LuaException
|
||||
{
|
||||
switch( args.orElse( "dan200.computercraft.ingame" ).toLowerCase( Locale.ROOT ) )
|
||||
switch( args.orElse( "ingame" ).toLowerCase( Locale.ROOT ) )
|
||||
{
|
||||
case "utc":
|
||||
{
|
||||
@@ -432,7 +432,7 @@ public class OSAPI implements ILuaAPI
|
||||
Calendar c = Calendar.getInstance();
|
||||
return getEpochForCalendar( c );
|
||||
}
|
||||
case "dan200.computercraft.ingame":
|
||||
case "ingame":
|
||||
// Get in-game epoch
|
||||
synchronized( alarms )
|
||||
{
|
||||
@@ -493,7 +493,7 @@ public class OSAPI implements ILuaAPI
|
||||
if( format.equals( "*t" ) ) return LuaDateTime.toTable( date, offset, instant );
|
||||
|
||||
DateTimeFormatterBuilder formatter = new DateTimeFormatterBuilder();
|
||||
LuaDateTime.format( formatter, format, offset );
|
||||
LuaDateTime.format( formatter, format );
|
||||
return formatter.toFormatter( Locale.ROOT ).format( date );
|
||||
}
|
||||
|
||||
|
||||
@@ -47,13 +47,15 @@ public class TextBuffer
|
||||
public void write( ByteBuffer text, int start )
|
||||
{
|
||||
int pos = start;
|
||||
int bufferPos = text.position();
|
||||
|
||||
start = Math.max( start, 0 );
|
||||
int length = text.remaining();
|
||||
int end = Math.min( start + length, pos + length );
|
||||
end = Math.min( end, this.text.length );
|
||||
for( int i = start; i < end; i++ )
|
||||
{
|
||||
this.text[i] = (char) (text.get( i - pos ) & 0xFF);
|
||||
this.text[i] = (char) (text.get( bufferPos + i - pos ) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ public final class Config
|
||||
builder.push( "http" );
|
||||
|
||||
httpEnabled = builder
|
||||
.comment( "Enable the \"http\" API on Computers (see \"rules\" for more fine grained control than this)." )
|
||||
.comment( "Enable the \"http\" API on Computers. This also disables the \"pastebin\" and \"wget\"\nprograms, that many users rely on. It's recommended to leave this on and use the\n\"rules\" config option to impose more fine-grained control." )
|
||||
.define( "enabled", ComputerCraft.httpEnabled );
|
||||
|
||||
httpWebsocketEnabled = builder
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.integration;
|
||||
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import dan200.computercraft.client.render.RenderTypes;
|
||||
import dan200.computercraft.client.render.text.DirectFixedWidthFontRenderer;
|
||||
import net.irisshaders.iris.api.v0.IrisApi;
|
||||
import net.irisshaders.iris.api.v0.IrisTextVertexSink;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
public class ShaderMod
|
||||
{
|
||||
public static final ShaderMod INSTANCE
|
||||
= ModList.get().isLoaded( "oculus" ) ? new IrisImpl()
|
||||
: new ShaderMod();
|
||||
|
||||
public boolean isShaderMod()
|
||||
{
|
||||
return Optifine.isLoaded();
|
||||
}
|
||||
|
||||
public boolean isRenderingShadowPass()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public DirectFixedWidthFontRenderer.QuadEmitter getQuadEmitter( int vertexCount, IntFunction<ByteBuffer> makeBuffer )
|
||||
{
|
||||
return new DirectFixedWidthFontRenderer.ByteBufferEmitter(
|
||||
makeBuffer.apply( RenderTypes.TERMINAL.format().getVertexSize() * vertexCount * 4 )
|
||||
);
|
||||
}
|
||||
|
||||
private static final class IrisImpl extends ShaderMod
|
||||
{
|
||||
@Override
|
||||
public boolean isRenderingShadowPass()
|
||||
{
|
||||
return IrisApi.getInstance().isRenderingShadowPass();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShaderMod()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectFixedWidthFontRenderer.QuadEmitter getQuadEmitter( int vertexCount, IntFunction<ByteBuffer> makeBuffer )
|
||||
{
|
||||
return IrisApi.getInstance().getMinorApiRevision() >= 1
|
||||
? new IrisQuadEmitter( vertexCount, makeBuffer )
|
||||
: super.getQuadEmitter( vertexCount, makeBuffer );
|
||||
}
|
||||
|
||||
private static final class IrisQuadEmitter implements DirectFixedWidthFontRenderer.QuadEmitter
|
||||
{
|
||||
private final IrisTextVertexSink sink;
|
||||
|
||||
private IrisQuadEmitter( int vertexCount, IntFunction<ByteBuffer> makeBuffer )
|
||||
{
|
||||
sink = IrisApi.getInstance().createTextVertexSink( vertexCount, makeBuffer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexFormat format()
|
||||
{
|
||||
return sink.getUnderlyingVertexFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer buffer()
|
||||
{
|
||||
return sink.getUnderlyingByteBuffer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void quad( float x1, float y1, float x2, float y2, float z, byte[] rgba, float u1, float v1, float u2, float v2 )
|
||||
{
|
||||
sink.quad( x1, y1, x2, y2, z, pack( rgba[0], rgba[1], rgba[2], rgba[3] ), u1, v1, u2, v2, RenderTypes.FULL_BRIGHT_LIGHTMAP );
|
||||
}
|
||||
|
||||
private static int pack( int r, int g, int b, int a )
|
||||
{
|
||||
return (a & 255) << 24 | (b & 255) << 16 | (g & 255) << 8 | r & 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.ComputerCraftAPI;
|
||||
import dan200.computercraft.shared.network.client.*;
|
||||
import dan200.computercraft.shared.network.server.*;
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -26,7 +28,8 @@ import java.util.function.Function;
|
||||
|
||||
public final class NetworkHandler
|
||||
{
|
||||
public static SimpleChannel network;
|
||||
private static SimpleChannel network;
|
||||
private static final IntSet usedIds = new IntOpenHashSet();
|
||||
|
||||
private NetworkHandler()
|
||||
{
|
||||
@@ -61,7 +64,7 @@ public final class NetworkHandler
|
||||
registerMainThread( 18, NetworkDirection.PLAY_TO_CLIENT, SpeakerPlayClientMessage.class, SpeakerPlayClientMessage::new );
|
||||
registerMainThread( 19, NetworkDirection.PLAY_TO_CLIENT, SpeakerStopClientMessage.class, SpeakerStopClientMessage::new );
|
||||
registerMainThread( 20, NetworkDirection.PLAY_TO_CLIENT, UploadResultMessage.class, UploadResultMessage::new );
|
||||
registerMainThread( 20, NetworkDirection.PLAY_TO_CLIENT, UpgradesLoadedMessage.class, UpgradesLoadedMessage::new );
|
||||
registerMainThread( 21, NetworkDirection.PLAY_TO_CLIENT, UpgradesLoadedMessage.class, UpgradesLoadedMessage::new );
|
||||
}
|
||||
|
||||
public static void sendToPlayer( Player player, NetworkMessage packet )
|
||||
@@ -101,6 +104,7 @@ public final class NetworkHandler
|
||||
*/
|
||||
private static <T extends NetworkMessage> void registerMainThread( int id, NetworkDirection direction, Class<T> type, Function<FriendlyByteBuf, T> decoder )
|
||||
{
|
||||
if( !usedIds.add( id ) ) throw new IllegalStateException( "Duplicate message kind for for id " + id );
|
||||
network.messageBuilder( type, id, direction )
|
||||
.encoder( NetworkMessage::toBytes )
|
||||
.decoder( decoder )
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
|
||||
}
|
||||
|
||||
Component customName;
|
||||
private LockCode lockCode;
|
||||
private LockCode lockCode = LockCode.NO_LOCK;
|
||||
|
||||
private final Map<IComputerAccess, MountInfo> computers = new HashMap<>();
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ public class ItemData
|
||||
}
|
||||
|
||||
data.put( "tags", DataHelpers.getTags( stack.getTags() ) );
|
||||
data.put( "itemGroups", getItemGroups( stack ) );
|
||||
|
||||
CompoundTag tag = stack.getTag();
|
||||
if( tag != null && tag.contains( "display", Tag.TAG_COMPOUND ) )
|
||||
@@ -115,6 +116,30 @@ public class ItemData
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all item groups an item stack pertains to.
|
||||
*
|
||||
* @param stack Stack to analyse
|
||||
* @return A filled list that contains pairs of item group IDs and their display names.
|
||||
*/
|
||||
@Nonnull
|
||||
private static List<Map<String, Object>> getItemGroups( @Nonnull ItemStack stack )
|
||||
{
|
||||
List<Map<String, Object>> groups = new ArrayList<>( 1 );
|
||||
|
||||
for( var group : stack.getItem().getCreativeTabs() )
|
||||
{
|
||||
if( group == null ) continue;
|
||||
|
||||
Map<String, Object> groupData = new HashMap<>( 2 );
|
||||
groupData.put( "id", group.langId );
|
||||
groupData.put( "displayName", group.getDisplayName().getString() );
|
||||
groups.add( groupData );
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all visible enchantments from given stack. Try to follow all tooltip rules : order and visibility.
|
||||
*
|
||||
|
||||
@@ -109,7 +109,9 @@ public class InventoryMethods implements GenericPeripheral
|
||||
*
|
||||
* The returned information contains the same information as each item in
|
||||
* {@link #list}, as well as additional details like the display name
|
||||
* (`displayName`) and item durability (`damage`, `maxDamage`, `durability`).
|
||||
* (`displayName`), item groups (`itemGroups`), which are the creative tabs
|
||||
* an item will appear under, and item and item durability (`damage`,
|
||||
* `maxDamage`, `durability`).
|
||||
*
|
||||
* Some items include more information (such as enchantments) - it is
|
||||
* recommended to print it out using @{textutils.serialize} or in the Lua
|
||||
@@ -129,6 +131,11 @@ public class InventoryMethods implements GenericPeripheral
|
||||
*
|
||||
* print(("%s (%s)"):format(item.displayName, item.name))
|
||||
* print(("Count: %d/%d"):format(item.count, item.maxCount))
|
||||
*
|
||||
* for _, group in pairs(item.itemGroups) do
|
||||
* print(("Group: %s"):format(group.displayName))
|
||||
* end
|
||||
*
|
||||
* if item.damage then
|
||||
* print(("Damage: %d/%d"):format(item.damage, item.maxDamage))
|
||||
* end
|
||||
@@ -168,7 +175,7 @@ public class InventoryMethods implements GenericPeripheral
|
||||
public static int getItemLimit( IItemHandler inventory, int slot ) throws LuaException
|
||||
{
|
||||
assertBetween( slot, 1, inventory.getSlots(), "Slot out of range (%s)" );
|
||||
return inventory.getSlotLimit( slot );
|
||||
return inventory.getSlotLimit( slot - 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,8 @@ public final class ClientMonitor extends ClientTerminal
|
||||
public int tboBuffer;
|
||||
public int tboTexture;
|
||||
public int tboUniform;
|
||||
public DirectVertexBuffer buffer;
|
||||
public DirectVertexBuffer backgroundBuffer;
|
||||
public DirectVertexBuffer foregroundBuffer;
|
||||
|
||||
public ClientMonitor( boolean colour, TileMonitor origin )
|
||||
{
|
||||
@@ -79,10 +80,11 @@ public final class ClientMonitor extends ClientTerminal
|
||||
}
|
||||
|
||||
case VBO:
|
||||
if( buffer != null ) return false;
|
||||
if( backgroundBuffer != null ) return false;
|
||||
|
||||
deleteBuffers();
|
||||
buffer = new DirectVertexBuffer();
|
||||
backgroundBuffer = new DirectVertexBuffer();
|
||||
foregroundBuffer = new DirectVertexBuffer();
|
||||
addMonitor();
|
||||
return true;
|
||||
|
||||
@@ -120,17 +122,23 @@ public final class ClientMonitor extends ClientTerminal
|
||||
tboUniform = 0;
|
||||
}
|
||||
|
||||
if( buffer != null )
|
||||
if( backgroundBuffer != null )
|
||||
{
|
||||
buffer.close();
|
||||
buffer = null;
|
||||
backgroundBuffer.close();
|
||||
backgroundBuffer = null;
|
||||
}
|
||||
|
||||
if( foregroundBuffer != null )
|
||||
{
|
||||
foregroundBuffer.close();
|
||||
foregroundBuffer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public void destroy()
|
||||
{
|
||||
if( tboBuffer != 0 || buffer != null )
|
||||
if( tboBuffer != 0 || backgroundBuffer != null )
|
||||
{
|
||||
synchronized( allMonitors )
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ package dan200.computercraft.shared.peripheral.monitor;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
||||
import dan200.computercraft.shared.integration.Optifine;
|
||||
import dan200.computercraft.shared.integration.ShaderMod;
|
||||
import org.lwjgl.opengl.GL;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -60,7 +60,7 @@ public enum MonitorRenderer
|
||||
return VBO;
|
||||
}
|
||||
|
||||
if( Optifine.isLoaded() )
|
||||
if( ShaderMod.INSTANCE.isShaderMod() )
|
||||
{
|
||||
ComputerCraft.log.warn( "Optifine is loaded, assuming shaders are being used. Falling back to VBO monitor renderer." );
|
||||
return VBO;
|
||||
|
||||
@@ -56,7 +56,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
|
||||
private static final int[] SIDE_SLOTS = new int[] { 0 };
|
||||
|
||||
Component customName;
|
||||
private LockCode lockCode;
|
||||
private LockCode lockCode = LockCode.NO_LOCK;
|
||||
|
||||
private final NonNullList<ItemStack> inventory = NonNullList.withSize( SLOTS, ItemStack.EMPTY );
|
||||
private final SidedCaps<IItemHandler> itemHandlerCaps =
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Optional;
|
||||
* an internal inventory of 16 slots, allowing them to store blocks they have broken or would like to place.
|
||||
*
|
||||
* ## Movement
|
||||
* Turtles are capable of moving throug the world. As turtles are blocks themselves, they are confined to Minecraft's
|
||||
* Turtles are capable of moving through the world. As turtles are blocks themselves, they are confined to Minecraft's
|
||||
* grid, moving a single block at a time.
|
||||
*
|
||||
* {@literal @}{turtle.forward} and @{turtle.back} move the turtle in the direction it is facing, while @{turtle.up} and
|
||||
|
||||
@@ -323,8 +323,9 @@ public class TurtleBrain implements ITurtleAccess
|
||||
|
||||
try
|
||||
{
|
||||
// Create a new turtle
|
||||
if( world.setBlock( pos, newState, 0 ) )
|
||||
// We use Block.UPDATE_CLIENTS here to ensure that neighbour updates caused in Block.updateNeighbourShapes
|
||||
// are sent to the client. We want to avoid doing a full block update until the turtle state is copied over.
|
||||
if( world.setBlock( pos, newState, 2 ) )
|
||||
{
|
||||
Block block = world.getBlockState( pos ).getBlock();
|
||||
if( block == oldBlock.getBlock() )
|
||||
|
||||
@@ -19,3 +19,6 @@ protected com.mojang.blaze3d.vertex.VertexBuffer f_166863_ # indexCount
|
||||
protected com.mojang.blaze3d.vertex.VertexBuffer f_166864_ # mode
|
||||
protected com.mojang.blaze3d.vertex.VertexBuffer f_166865_ # sequentialIndices
|
||||
protected com.mojang.blaze3d.vertex.VertexBuffer f_85917_ # format
|
||||
|
||||
# ItemData
|
||||
public net.minecraft.world.item.CreativeModeTab f_40763_ # langId
|
||||
|
||||
135
src/main/resources/assets/computercraft/lang/nb_no.json
Normal file
135
src/main/resources/assets/computercraft/lang/nb_no.json
Normal file
@@ -0,0 +1,135 @@
|
||||
{
|
||||
"itemGroup.computercraft": "ComputerCraft",
|
||||
"block.computercraft.computer_normal": "Datamaskin",
|
||||
"block.computercraft.computer_advanced": "Avansert Datamaskin",
|
||||
"block.computercraft.computer_command": "Kommando Datamaskin",
|
||||
"block.computercraft.disk_drive": "Diskstasjon",
|
||||
"block.computercraft.printer": "Printer",
|
||||
"block.computercraft.speaker": "Høytaler",
|
||||
"block.computercraft.monitor_normal": "Skjerm",
|
||||
"block.computercraft.monitor_advanced": "Avansert Skjerm",
|
||||
"block.computercraft.wireless_modem_normal": "Trådløst Modem",
|
||||
"block.computercraft.wireless_modem_advanced": "Ender Modem",
|
||||
"block.computercraft.wired_modem": "Kablet Modem",
|
||||
"block.computercraft.cable": "Nettverks kabel",
|
||||
"block.computercraft.wired_modem_full": "Kablet Modem",
|
||||
"block.computercraft.turtle_normal": "Skilpadde",
|
||||
"block.computercraft.turtle_normal.upgraded": "%s Skilpadde",
|
||||
"block.computercraft.turtle_normal.upgraded_twice": "%s %s Skilpadde",
|
||||
"block.computercraft.turtle_advanced": "Avansert Skilpadde",
|
||||
"block.computercraft.turtle_advanced.upgraded": "Avansert %s Skilpadde",
|
||||
"block.computercraft.turtle_advanced.upgraded_twice": "Avansert %s %s Skilpadde",
|
||||
"item.computercraft.disk": "Floppy Disk",
|
||||
"item.computercraft.treasure_disk": "Floppy Disk",
|
||||
"item.computercraft.printed_page": "Printet Side",
|
||||
"item.computercraft.printed_pages": "Printet Sider",
|
||||
"item.computercraft.printed_book": "Printet Bok",
|
||||
"item.computercraft.pocket_computer_normal": "Lomme datamaskin",
|
||||
"item.computercraft.pocket_computer_normal.upgraded": "%s Lomme Datamaskin",
|
||||
"item.computercraft.pocket_computer_advanced": "Avansert Lomme Datamaskin",
|
||||
"item.computercraft.pocket_computer_advanced.upgraded": "Avansert %s Lomme Datamaskin",
|
||||
"upgrade.minecraft.diamond_sword.adjective": "Kjempende",
|
||||
"upgrade.minecraft.diamond_shovel.adjective": "Gravende",
|
||||
"upgrade.minecraft.diamond_pickaxe.adjective": "Brytende",
|
||||
"upgrade.minecraft.diamond_axe.adjective": "Hoggende",
|
||||
"upgrade.minecraft.diamond_hoe.adjective": "Dyrkende",
|
||||
"upgrade.minecraft.crafting_table.adjective": "Håndverks",
|
||||
"upgrade.computercraft.wireless_modem_normal.adjective": "Trådløs",
|
||||
"upgrade.computercraft.wireless_modem_advanced.adjective": "Ender",
|
||||
"upgrade.computercraft.speaker.adjective": "Høylydt",
|
||||
"chat.computercraft.wired_modem.peripheral_connected": "Perifer \"%s\" koblet til nettverk",
|
||||
"chat.computercraft.wired_modem.peripheral_disconnected": "Perifer \"%s\" koblet fra nettverk",
|
||||
"commands.computercraft.synopsis": "Forskjellige kommandoer for å kontrollere datamaskiner.",
|
||||
"commands.computercraft.desc": "Kommandoen /computercraft gir forskjellige feilsøkings- og administratorverktøy for å kontrollere og handle med datamaskiner.",
|
||||
"commands.computercraft.help.synopsis": "Gi hjelp til en spesifikk kommando",
|
||||
"commands.computercraft.help.desc": "Viser denne hjelpemeldingen",
|
||||
"commands.computercraft.help.no_children": "%s har ingen underkommandoer",
|
||||
"commands.computercraft.help.no_command": "Ingen kommando '%s'",
|
||||
"commands.computercraft.dump.synopsis": "Viser statusen av datamaskiner.",
|
||||
"commands.computercraft.dump.desc": "Viser statusen til alle datamaskiner eller spesifikk informasjon om én datamaskin. Du kan spesifisere datamaskinens forekomst id (f. eks 123), datamaskinens id (f. eks #123) eller datamaskinens merkelapp (f. eks \"@Min datamaskin\").",
|
||||
"commands.computercraft.dump.action": "Vis mer informasjon om denne datamaskinen",
|
||||
"commands.computercraft.dump.open_path": "Vis datamaskinens filer",
|
||||
"commands.computercraft.shutdown.synopsis": "Slå av datamaskiner eksternt.",
|
||||
"commands.computercraft.shutdown.desc": "Slå av de oppførte datamaskinene eller alle hvis ingen er spesifisert. Du kan spesifisere datamaskinens forekomst (f. eks 123), datamaskinens id (f. eks #123) eller merkelapp (f.eks \"@Min datamaskin\").",
|
||||
"commands.computercraft.shutdown.done": "Skrudde av %s/%s datamaskiner",
|
||||
"commands.computercraft.turn_on.synopsis": "Slå på datamaskiner eksternt.",
|
||||
"commands.computercraft.turn_on.desc": "Slå på de oppførte datamaskinene. Du kan spesifisere datamaskinens forekomst id (f. eks 123), datamaskinens id (f.eks #123) eller navnelapp (f. eks \"@Min Datamaskin\").",
|
||||
"commands.computercraft.turn_on.done": "Skrudde på %s/%s datamaskiner",
|
||||
"commands.computercraft.tp.synopsis": "Teleporter til en spesifikk datamaskin.",
|
||||
"commands.computercraft.tp.desc": "Teleporter til en datamaskin sin posisjon. Du kan enten spesifisere datamaskinens forekomst id (f. eks 123) eller datamaskinens id (f. eks #123).",
|
||||
"commands.computercraft.tp.action": "Teleporter til denne datamaskinen",
|
||||
"commands.computercraft.tp.not_player": "Kan kun åpne terminalen for spillere",
|
||||
"commands.computercraft.tp.not_there": "Greide ikke å finne datamaskinen i denne verdenen",
|
||||
"commands.computercraft.view.synopsis": "Vis terminal til en datamaskin.",
|
||||
"commands.computercraft.view.desc": "Åpner terminalen til en datamaskin, lar deg fjernstyre den. Dette gir deg ikke tilgang til skilpadders inventar. Du kan enten spesifisere datamaskinens forekomst id (f. eks 123) eller datamaskinens id (f. eks #123).",
|
||||
"commands.computercraft.view.action": "Vis denne datamaskinen",
|
||||
"commands.computercraft.view.not_player": "Kan kun åpne terminal for spillere",
|
||||
"commands.computercraft.track.synopsis": "Spor utførelsestider for datamaskiner.",
|
||||
"commands.computercraft.track.desc": "Spor hvor lenge datamaskiner kjører, samt hvor mange hendelser de handler. Dette presenterer informasjon i en lignende vei til /forge track og kan være nyttig for å diagnostisere lagg.",
|
||||
"commands.computercraft.track.start.synopsis": "Start sporing av alle datamaskiner",
|
||||
"commands.computercraft.track.start.desc": "Start sporing av alle datamaskiners utførselstider og hendelser. Dette vil fjerne resultatene fra tidligere kjøringer.",
|
||||
"commands.computercraft.track.start.stop": "Kjør %s for å stoppe sporingen og vise resultatene",
|
||||
"commands.computercraft.track.stop.synopsis": "Stopp sporing av alle datamaskiner",
|
||||
"commands.computercraft.track.stop.desc": "Stopp sporing av alle datamaskiners hendelser og utførelsestider",
|
||||
"commands.computercraft.track.stop.action": "Klikk for å stoppe sporing",
|
||||
"commands.computercraft.track.stop.not_enabled": "Sporer ingen datamaskiner",
|
||||
"commands.computercraft.track.dump.synopsis": "Dump nyeste sporingsresultater",
|
||||
"commands.computercraft.track.dump.desc": "Dump de nyeste resultatene av datamaskin sporing.",
|
||||
"commands.computercraft.track.dump.no_timings": "Ingen timere tilgjengelige",
|
||||
"commands.computercraft.track.dump.computer": "Datamaskin",
|
||||
"commands.computercraft.reload.synopsis": "Last inn ComputerCraft sin konfigurasjonsfil på nytt",
|
||||
"commands.computercraft.reload.desc": "Last inn ComputerCraft sin konfigurasjonsfil på nytt",
|
||||
"commands.computercraft.reload.done": "Lastet konfigurasjon på nytt",
|
||||
"commands.computercraft.queue.synopsis": "Send en computer_command hendelse til en kommando datamaskin",
|
||||
"commands.computercraft.queue.desc": "Send en computer_command hendelse til en kommando datamaskin, sender også tilleggs-argumentene Dette er hovedsakelig designet for kartskapere, og fungerer som en mer datamaskin vennlig versjon av /trigger. Enhver spiller kan kjøre kommandoen, som mest sannsynlig vil bli gjort gjennom en tekst komponent sin klikk hendelse.",
|
||||
"commands.computercraft.generic.no_position": "<ingen posisjon>",
|
||||
"commands.computercraft.generic.position": "%s, %s, %s",
|
||||
"commands.computercraft.generic.yes": "J",
|
||||
"commands.computercraft.generic.no": "N",
|
||||
"commands.computercraft.generic.exception": "Uhåndtert unntak (%s)",
|
||||
"commands.computercraft.generic.additional_rows": "%d flere rader…",
|
||||
"argument.computercraft.computer.no_matching": "Ingen datamaskiner som samsvarer med '%s'",
|
||||
"argument.computercraft.computer.many_matching": "Flere datamaskiner samsvarer '%s' (%s treff)",
|
||||
"argument.computercraft.tracking_field.no_field": "Ukjent felt '%s'",
|
||||
"argument.computercraft.argument_expected": "Argument forventet",
|
||||
"tracking_field.computercraft.tasks.name": "Jobber",
|
||||
"tracking_field.computercraft.total.name": "Total tid",
|
||||
"tracking_field.computercraft.average.name": "Gjennomsnitt tid",
|
||||
"tracking_field.computercraft.max.name": "Maksimum tid",
|
||||
"tracking_field.computercraft.server_count.name": "Server jobbantall",
|
||||
"tracking_field.computercraft.server_time.name": "Server jobb tid",
|
||||
"tracking_field.computercraft.peripheral.name": "Perifere kjøringer",
|
||||
"tracking_field.computercraft.fs.name": "Filsystem operasjoner",
|
||||
"tracking_field.computercraft.turtle.name": "Skilpadde operasjoner",
|
||||
"tracking_field.computercraft.http.name": "HTTP-forespørsler",
|
||||
"tracking_field.computercraft.http_upload.name": "HTTP-opplasting",
|
||||
"tracking_field.computercraft.http_download.name": "HTTP-nedlasting",
|
||||
"tracking_field.computercraft.websocket_incoming.name": "Innkommende Websocket",
|
||||
"tracking_field.computercraft.websocket_outgoing.name": "Utgående Websocket",
|
||||
"tracking_field.computercraft.coroutines_created.name": "Skapte coroutines",
|
||||
"tracking_field.computercraft.coroutines_dead.name": "Kastede coroutiner",
|
||||
"gui.computercraft.tooltip.copy": "Kopier til utklippstavle",
|
||||
"gui.computercraft.tooltip.computer_id": "Datamaskin ID: %s",
|
||||
"gui.computercraft.tooltip.disk_id": "Disk ID: %s",
|
||||
"gui.computercraft.tooltip.turn_on": "Slå denne datamaskinen på",
|
||||
"gui.computercraft.tooltip.turn_on.key": "Hold Ctrl + R",
|
||||
"gui.computercraft.tooltip.turn_off": "Skru denne datamaskinen av",
|
||||
"gui.computercraft.tooltip.turn_off.key": "Hold Ctrl + S",
|
||||
"gui.computercraft.tooltip.terminate": "Stopp den kjørende koden",
|
||||
"gui.computercraft.tooltip.terminate.key": "Hold Ctrl + T",
|
||||
"gui.computercraft.upload.success": "Vellykket opplasting",
|
||||
"gui.computercraft.upload.success.msg": "%d filer lastet opp.",
|
||||
"gui.computercraft.upload.failed": "Opplasting Feilet",
|
||||
"gui.computercraft.upload.failed.out_of_space": "Ikke nok lagringsplass på datamaskinen for disse filene.",
|
||||
"gui.computercraft.upload.failed.computer_off": "Du må skru på datamaskinen før du kan laste opp filer.",
|
||||
"gui.computercraft.upload.failed.too_much": "Filene dine er for store for å kunne bli lastet opp.",
|
||||
"gui.computercraft.upload.failed.name_too_long": "Fil navnene er for lange til å bli lastet opp.",
|
||||
"gui.computercraft.upload.failed.too_many_files": "Kan ikke laste opp så mange filer.",
|
||||
"gui.computercraft.upload.failed.overwrite_dir": "Kan ikke laste opp %s, siden det allerede er en mappe med det samme navnet.",
|
||||
"gui.computercraft.upload.failed.generic": "Opplasting av filer feilet (%s)",
|
||||
"gui.computercraft.upload.failed.corrupted": "Filene ble korrupt mens opplasting. Vennligst prøv igjen.",
|
||||
"gui.computercraft.upload.overwrite": "Filer ville blitt overskrevet",
|
||||
"gui.computercraft.upload.overwrite.detail": "Følgende filer vil bli overskrevet under opplasting. Fortsette?%s",
|
||||
"gui.computercraft.upload.overwrite_button": "Overskriv",
|
||||
"gui.computercraft.pocket_computer_overlay": "Lommedatamaskin åpen. Trykk ESC for å lukke."
|
||||
}
|
||||
@@ -10,8 +10,8 @@ gps program.
|
||||
|
||||
:::note
|
||||
When entering in the coordinates for the host you need to put in the `x`, `y`,
|
||||
and `z` coordinates of the computer, not the modem, as all modem distances are
|
||||
measured from the block the computer is in.
|
||||
and `z` coordinates of the block that the modem is connected to, not the modem.
|
||||
All modem distances are measured from the block that the modem is placed on.
|
||||
:::
|
||||
|
||||
Also note that you may choose which axes x, y, or z refers to - so long as your
|
||||
@@ -24,6 +24,7 @@ height in the way that Minecraft's debug screen displays.
|
||||
|
||||
@module gps
|
||||
@since 1.31
|
||||
@see gps_setup For more detailed instructions on setting up GPS
|
||||
]]
|
||||
|
||||
local expect = dofile("rom/modules/main/cc/expect.lua").expect
|
||||
|
||||
@@ -259,7 +259,7 @@ input should the whole output not fit on the display.
|
||||
local rows = {}
|
||||
for i = 1, 30 do rows[i] = {("Row #%d"):format(i), math.random(1, 400)} end
|
||||
|
||||
textutils.tabulate(colors.orange, {"Column", "Value"}, colors.lightBlue, table.unpack(rows))
|
||||
textutils.pagedTabulate(colors.orange, {"Column", "Value"}, colors.lightBlue, table.unpack(rows))
|
||||
]]
|
||||
function pagedTabulate(...)
|
||||
return tabulateCommon(true, ...)
|
||||
@@ -749,9 +749,9 @@ suitable for pretty printing.
|
||||
@usage Demonstrates some of the other options
|
||||
|
||||
local tbl = { 1, 2, 3 }
|
||||
print(textutils.serialize({ tbl, tbl }, { allow_repetitions = true }))
|
||||
print(textutils.serialise({ tbl, tbl }, { allow_repetitions = true }))
|
||||
|
||||
print(textutils.serialize(tbl, { compact = true }))
|
||||
print(textutils.serialise(tbl, { compact = true }))
|
||||
]]
|
||||
function serialize(t, opts)
|
||||
local tTracking = {}
|
||||
@@ -770,7 +770,7 @@ serialise = serialize -- GB version
|
||||
|
||||
--- Converts a serialised string back into a reassembled Lua object.
|
||||
--
|
||||
-- This is mainly used together with @{textutils.serialize}.
|
||||
-- This is mainly used together with @{textutils.serialise}.
|
||||
--
|
||||
-- @tparam string s The serialised string to deserialise.
|
||||
-- @return[1] The deserialised object
|
||||
@@ -807,10 +807,10 @@ unserialise = unserialize -- GB version
|
||||
-- @throws If the object contains a value which cannot be
|
||||
-- serialised. This includes functions and tables which appear multiple
|
||||
-- times.
|
||||
-- @usage textutils.serializeJSON({ values = { 1, "2", true } })
|
||||
-- @usage textutils.serialiseJSON({ values = { 1, "2", true } })
|
||||
-- @since 1.7
|
||||
-- @see textutils.json_null Use to serialize a JSON `null` value.
|
||||
-- @see textutils.empty_json_array Use to serialize a JSON empty array.
|
||||
-- @see textutils.json_null Use to serialise a JSON `null` value.
|
||||
-- @see textutils.empty_json_array Use to serialise a JSON empty array.
|
||||
function serializeJSON(t, bNBTStyle)
|
||||
expect(1, t, "table", "string", "number", "boolean")
|
||||
expect(2, bNBTStyle, "boolean", "nil")
|
||||
|
||||
@@ -1,3 +1,33 @@
|
||||
# New features in CC: Tweaked 1.100.10
|
||||
|
||||
* Mention WAV support in speaker help (MCJack123).
|
||||
* Add http programs to the path, even when http is not enabled.
|
||||
|
||||
Several bug fixes:
|
||||
* Fix example in textutils.pagedTabulate docs (IvoLeal72).
|
||||
* Fix help program treating the terminal one line longer than it was.
|
||||
* Send block updates to client when turtle moves (roland-a).
|
||||
* Resolve several monitor issues when running Occulus shaders.
|
||||
|
||||
# New features in CC: Tweaked 1.100.9
|
||||
|
||||
* Add documentation for setting up GPS (Lupus590).
|
||||
* Add WAV support to the `speaker` program (MCJack123).
|
||||
* Expose item groups in `getItemDetail` (itisluiz).
|
||||
* Other fixes to documentation (Erb3, JohnnyIrvin).
|
||||
* Add Norwegian translation (Erb3).
|
||||
|
||||
Several bug fixes:
|
||||
* Fix z-fighting on bold printout borders (toad-dev).
|
||||
* Fix `term.blit` failing on certain strings.
|
||||
* Fix `getItemLimit()` using the wrong slot (heap-underflow).
|
||||
* Increase size of monitor depth blocker.
|
||||
|
||||
# New features in CC: Tweaked 1.100.8
|
||||
|
||||
Several bug fixes:
|
||||
* Fix NPE within disk drive and printer code.
|
||||
|
||||
# New features in CC: Tweaked 1.100.6
|
||||
|
||||
* Various documentation improvements (MCJack123, FayneAldan).
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
The speaker program plays audio files using speakers attached to this computer.
|
||||
|
||||
It supports audio files in a limited number of formats:
|
||||
* DFPWM: You can convert music to DFPWM with external tools like https://music.madefor.cc.
|
||||
* WAV: WAV files must be 8-bit PCM or DFPWM, with exactly one channel and a sample rate of 48kHz.
|
||||
|
||||
## Examples:
|
||||
- `speaker play example.dfpwm left` plays the "example.dfpwm" audio file using the speaker on the left of the computer.
|
||||
- `speaker stop` stops any currently playing audio.
|
||||
* `speaker play example.dfpwm left` plays the "example.dfpwm" audio file using the speaker on the left of the computer.
|
||||
* `speaker stop` stops any currently playing audio.
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
New features in CC: Tweaked 1.100.6
|
||||
New features in CC: Tweaked 1.100.10
|
||||
|
||||
* Various documentation improvements (MCJack123, FayneAldan).
|
||||
* Allow CC's blocks to be rotated when used in structure blocks (Seniorendi).
|
||||
* Several performance improvements to computer execution.
|
||||
* Add parse_empty_array option to textutils.unserialiseJSON (@ChickChicky).
|
||||
* Add an API to allow other mods to provide extra item/block details (Lemmmy).
|
||||
* All blocks with GUIs can now be "locked" (via a command or NBT editing tools) like vanilla inventories. Players can only interact with them with a specific named item.
|
||||
* Mention WAV support in speaker help (MCJack123).
|
||||
* Add http programs to the path, even when http is not enabled.
|
||||
|
||||
Several bug fixes:
|
||||
* Fix printouts being rendered with an offset in item frames (coolsa).
|
||||
* Reduce position latency when playing audio with a noisy pocket computer.
|
||||
* Fix total counts in /computercraft turn-on/shutdown commands.
|
||||
* Fix "Run" command not working in the editor when run from a subdirectory (Wojbie).
|
||||
* Pocket computers correctly preserve their on state.
|
||||
* Fix example in textutils.pagedTabulate docs (IvoLeal72).
|
||||
* Fix help program treating the terminal one line longer than it was.
|
||||
* Send block updates to client when turtle moves (roland-a).
|
||||
* Resolve several monitor issues when running Occulus shaders.
|
||||
|
||||
Type "help changelog" to see the full version history.
|
||||
|
||||
@@ -18,6 +18,14 @@ local function get_speakers(name)
|
||||
end
|
||||
end
|
||||
|
||||
local function pcm_decoder(chunk)
|
||||
local buffer = {}
|
||||
for i = 1, #chunk do
|
||||
buffer[i] = chunk:byte(i) - 128
|
||||
end
|
||||
return buffer
|
||||
end
|
||||
|
||||
|
||||
local cmd = ...
|
||||
if cmd == "stop" then
|
||||
@@ -40,12 +48,63 @@ elseif cmd == "play" then
|
||||
error(err, 0)
|
||||
end
|
||||
|
||||
local start = handle.read(4)
|
||||
local pcm = false
|
||||
local size = 16 * 1024 - 4
|
||||
if start == "RIFF" then
|
||||
handle.read(4)
|
||||
if handle.read(8) ~= "WAVEfmt " then
|
||||
handle.close()
|
||||
error("Could not play audio: Unsupported WAV file", 0)
|
||||
end
|
||||
|
||||
local fmtsize = ("<I4"):unpack(handle.read(4))
|
||||
local fmt = handle.read(fmtsize)
|
||||
local format, channels, rate, _, _, bits = ("<I2I2I4I4I2I2"):unpack(fmt)
|
||||
if not ((format == 1 and bits == 8) or (format == 0xFFFE and bits == 1)) then
|
||||
handle.close()
|
||||
error("Could not play audio: Unsupported WAV file", 0)
|
||||
end
|
||||
if channels ~= 1 or rate ~= 48000 then
|
||||
print("Warning: Only 48 kHz mono WAV files are supported. This file may not play correctly.")
|
||||
end
|
||||
if format == 0xFFFE then
|
||||
local guid = fmt:sub(25)
|
||||
if guid ~= "\x3A\xC1\xFA\x38\x81\x1D\x43\x61\xA4\x0D\xCE\x53\xCA\x60\x7C\xD1" then -- DFPWM format GUID
|
||||
handle.close()
|
||||
error("Could not play audio: Unsupported WAV file", 0)
|
||||
end
|
||||
size = size + 4
|
||||
else
|
||||
pcm = true
|
||||
size = 16 * 1024 * 8
|
||||
end
|
||||
|
||||
repeat
|
||||
local chunk = handle.read(4)
|
||||
if chunk == nil then
|
||||
handle.close()
|
||||
error("Could not play audio: Invalid WAV file", 0)
|
||||
elseif chunk ~= "data" then -- Ignore extra chunks
|
||||
local size = ("<I4"):unpack(handle.read(4))
|
||||
handle.read(size)
|
||||
end
|
||||
until chunk == "data"
|
||||
|
||||
handle.read(4)
|
||||
start = nil
|
||||
end
|
||||
|
||||
print("Playing " .. file)
|
||||
|
||||
local decoder = require "cc.audio.dfpwm".make_decoder()
|
||||
local decoder = pcm and pcm_decoder or require "cc.audio.dfpwm".make_decoder()
|
||||
while true do
|
||||
local chunk = handle.read(16 * 1024)
|
||||
local chunk = handle.read(size)
|
||||
if not chunk then break end
|
||||
if start then
|
||||
chunk, start = start .. chunk, nil
|
||||
size = size + 4
|
||||
end
|
||||
|
||||
local buffer = decoder(chunk)
|
||||
while not speaker.playAudio(buffer) do
|
||||
|
||||
@@ -146,14 +146,17 @@ end
|
||||
|
||||
local contents = file:read("*a")
|
||||
file:close()
|
||||
-- Trim trailing newlines from the file to avoid displaying a blank line.
|
||||
if contents:sub(-1) == "\n" then contents:sub(1, -2) end
|
||||
|
||||
local word_wrap = sFile:sub(-3) == ".md" and word_wrap_markdown or word_wrap_basic
|
||||
local width, height = term.getSize()
|
||||
local content_height = height - 1 -- Height of the content box.
|
||||
local lines, fg, bg, sections = word_wrap(contents, width)
|
||||
local print_height = #lines
|
||||
|
||||
-- If we fit within the screen, just display without pagination.
|
||||
if print_height <= height then
|
||||
if print_height <= content_height then
|
||||
local _, y = term.getCursorPos()
|
||||
for i = 1, print_height do
|
||||
if y + i - 1 > height then
|
||||
@@ -201,7 +204,7 @@ end
|
||||
|
||||
|
||||
local function draw()
|
||||
for y = 1, height - 1 do
|
||||
for y = 1, content_height do
|
||||
term.setCursorPos(1, y)
|
||||
if y + offset > print_height then
|
||||
-- Should only happen if we resize the terminal to a larger one
|
||||
@@ -228,14 +231,14 @@ while true do
|
||||
if param == keys.up and offset > 0 then
|
||||
offset = offset - 1
|
||||
draw()
|
||||
elseif param == keys.down and offset < print_height - height then
|
||||
elseif param == keys.down and offset < print_height - content_height then
|
||||
offset = offset + 1
|
||||
draw()
|
||||
elseif param == keys.pageUp and offset > 0 then
|
||||
offset = math.max(offset - height + 2, 0)
|
||||
offset = math.max(offset - content_height + 1, 0)
|
||||
draw()
|
||||
elseif param == keys.pageDown and offset < print_height - height then
|
||||
offset = math.min(offset + height - 2, print_height - height)
|
||||
elseif param == keys.pageDown and offset < print_height - content_height then
|
||||
offset = math.min(offset + content_height - 1, print_height - content_height)
|
||||
draw()
|
||||
elseif param == keys.home then
|
||||
offset = 0
|
||||
@@ -247,7 +250,7 @@ while true do
|
||||
offset = sections[current_section + 1].offset
|
||||
draw()
|
||||
elseif param == keys["end"] then
|
||||
offset = print_height - height
|
||||
offset = print_height - content_height
|
||||
draw()
|
||||
elseif param == keys.q then
|
||||
sleep(0) -- Super janky, but consumes stray "char" events.
|
||||
@@ -257,7 +260,7 @@ while true do
|
||||
if param < 0 and offset > 0 then
|
||||
offset = offset - 1
|
||||
draw()
|
||||
elseif param > 0 and offset < print_height - height then
|
||||
elseif param > 0 and offset <= print_height - content_height then
|
||||
offset = offset + 1
|
||||
draw()
|
||||
end
|
||||
@@ -270,7 +273,8 @@ while true do
|
||||
end
|
||||
|
||||
width, height = new_width, new_height
|
||||
offset = math.max(math.min(offset, print_height - height), 0)
|
||||
content_height = height - 1
|
||||
offset = math.max(math.min(offset, print_height - content_height), 0)
|
||||
draw()
|
||||
draw_menu()
|
||||
elseif event == "terminate" then
|
||||
|
||||
@@ -13,8 +13,8 @@ if #tArgs < 2 then
|
||||
end
|
||||
|
||||
if not http then
|
||||
printError("Pastebin requires the http API")
|
||||
printError("Set http.enabled to true in CC: Tweaked's config")
|
||||
printError("Pastebin requires the http API, but it is not enabled")
|
||||
printError("Set http.enabled to true in CC: Tweaked's server config")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ end
|
||||
local url = table.remove(tArgs, 1)
|
||||
|
||||
if not http then
|
||||
printError("wget requires the http API")
|
||||
printError("Set http.enabled to true in CC: Tweaked's config")
|
||||
printError("wget requires the http API, but it is not enabled")
|
||||
printError("Set http.enabled to true in CC: Tweaked's server config")
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local completion = require "cc.shell.completion"
|
||||
|
||||
-- Setup paths
|
||||
local sPath = ".:/rom/programs"
|
||||
local sPath = ".:/rom/programs:/rom/programs/http"
|
||||
if term.isColor() then
|
||||
sPath = sPath .. ":/rom/programs/advanced"
|
||||
end
|
||||
@@ -19,9 +19,6 @@ end
|
||||
if commands then
|
||||
sPath = sPath .. ":/rom/programs/command"
|
||||
end
|
||||
if http then
|
||||
sPath = sPath .. ":/rom/programs/http"
|
||||
end
|
||||
shell.setPath(sPath)
|
||||
help.setPath("/rom/help")
|
||||
|
||||
|
||||
@@ -14,9 +14,12 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static dan200.computercraft.core.terminal.TerminalMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class TerminalTest
|
||||
@@ -366,6 +369,19 @@ class TerminalTest
|
||||
callCounter.assertNotCalled();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlitPartialBuffer()
|
||||
{
|
||||
Terminal terminal = new Terminal( 4, 3 );
|
||||
|
||||
ByteBuffer text = LuaValues.encode( "123456" );
|
||||
text.position( 1 );
|
||||
|
||||
terminal.blit( text, LuaValues.encode( "aaaaaa" ), LuaValues.encode( "aaaaaa" ) );
|
||||
|
||||
assertThat( terminal.getLine( 0 ).toString(), equalTo( "2345" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWriteFromOrigin()
|
||||
{
|
||||
|
||||
@@ -118,6 +118,19 @@ describe("The os library", function()
|
||||
end)
|
||||
|
||||
describe("os.time", function()
|
||||
it("supports in-game time", function()
|
||||
expect(os.time("ingame")):equal(os.time())
|
||||
end)
|
||||
|
||||
it("supports local and utc time", function()
|
||||
os.time("utc")
|
||||
os.time("local")
|
||||
end)
|
||||
|
||||
it("fails on other times", function()
|
||||
expect.error(os.time, "unknown"):eq("Unsupported operation")
|
||||
end)
|
||||
|
||||
it("maps directly to seconds", function()
|
||||
local t1 = os.time { year = 2000, month = 10, day = 1, hour = 23, min = 12, sec = 17 }
|
||||
local t2 = os.time { year = 2000, month = 10, day = 1, hour = 23, min = 10, sec = 19 }
|
||||
@@ -125,6 +138,38 @@ describe("The os library", function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("os.day", function()
|
||||
it("supports in-game time", function()
|
||||
expect(os.day("ingame")):equal(os.day())
|
||||
end)
|
||||
|
||||
it("supports local and utc time", function()
|
||||
os.day("utc")
|
||||
os.day("local")
|
||||
end)
|
||||
|
||||
it("fails on other times", function()
|
||||
expect.error(os.day, "unknown"):eq("Unsupported operation")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("os.epoch", function()
|
||||
it("supports in-game time", function()
|
||||
local in_game = os.epoch("ingame")
|
||||
local default = os.epoch()
|
||||
assert(math.abs(default - in_game) < 5)
|
||||
end)
|
||||
|
||||
it("supports local and utc time", function()
|
||||
os.epoch("utc")
|
||||
os.epoch("local")
|
||||
end)
|
||||
|
||||
it("fails on other times", function()
|
||||
expect.error(os.epoch, "unknown"):eq("Unsupported operation")
|
||||
end)
|
||||
end)
|
||||
|
||||
describe("os.loadAPI", function()
|
||||
it("validates arguments", function()
|
||||
expect.error(os.loadAPI, nil):eq("bad argument #1 (expected string, got nil)")
|
||||
|
||||
@@ -1,8 +1,46 @@
|
||||
local capture = require "test_helpers".capture_program
|
||||
local with_window_lines = require "test_helpers".with_window_lines
|
||||
|
||||
describe("The help program", function()
|
||||
local function stub_help(content)
|
||||
local name = "/help_file.txt"
|
||||
io.open(name, "wb"):write(content):close()
|
||||
stub(help, "lookup", function() return name end)
|
||||
end
|
||||
|
||||
local function capture_help(width, height, content)
|
||||
stub_help(content)
|
||||
|
||||
local co = coroutine.create(shell.run)
|
||||
local window = with_window_lines(width, height, function()
|
||||
local ok, err = coroutine.resume(co, "help topic")
|
||||
if not ok then error(err, 0) end
|
||||
end)
|
||||
return coroutine.status(co) == "dead", window
|
||||
end
|
||||
|
||||
it("errors when there is no such help file", function()
|
||||
expect(capture(stub, "help nothing"))
|
||||
:matches { ok = true, error = "No help available\n", output = "" }
|
||||
end)
|
||||
|
||||
it("prints a short file directly", function()
|
||||
local dead, output = capture_help(10, 3, "a short\nfile")
|
||||
expect(dead):eq(true)
|
||||
expect(output):same {
|
||||
"a short ",
|
||||
"file ",
|
||||
" ",
|
||||
}
|
||||
end)
|
||||
|
||||
it("launches the viewer for a longer file", function()
|
||||
local dead, output = capture_help(10, 3, "a longer\nfile\nwith content")
|
||||
expect(dead):eq(false)
|
||||
expect(output):same {
|
||||
"a longer ",
|
||||
"file ",
|
||||
"Help: topi",
|
||||
}
|
||||
end)
|
||||
end)
|
||||
|
||||
@@ -56,7 +56,22 @@ local function with_window(width, height, fn)
|
||||
return redirect
|
||||
end
|
||||
|
||||
--- Run a function redirecting to a new window with the given dimensions,
|
||||
-- returning the content of the window.
|
||||
--
|
||||
-- @tparam number width The window's width
|
||||
-- @tparam number height The window's height
|
||||
-- @tparam function() fn The action to run
|
||||
-- @treturn {string...} The content of the window.
|
||||
local function with_window_lines(width, height, fn)
|
||||
local window = with_window(width, height, fn)
|
||||
local out = {}
|
||||
for i = 1, height do out[i] = window.getLine(i) end
|
||||
return out
|
||||
end
|
||||
|
||||
return {
|
||||
capture_program = capture_program,
|
||||
with_window = with_window,
|
||||
with_window_lines = with_window_lines,
|
||||
}
|
||||
|
||||
@@ -16,10 +16,10 @@ class Disk_Drive_Test {
|
||||
*
|
||||
* @see [#688](https://github.com/cc-tweaked/CC-Tweaked/issues/688)
|
||||
*/
|
||||
@GameTest
|
||||
@GameTest(timeoutTicks = Modem_Test.TIMEOUT)
|
||||
fun Audio_disk(helper: GameTestHelper) = helper.sequence { thenComputerOk() }
|
||||
|
||||
@GameTest
|
||||
@GameTest(timeoutTicks = Modem_Test.TIMEOUT)
|
||||
fun Ejects_disk(helper: GameTestHelper) = helper.sequence {
|
||||
val stackAt = BlockPos(2, 2, 2)
|
||||
this
|
||||
|
||||
@@ -77,7 +77,7 @@ class Turtle_Test {
|
||||
*
|
||||
* Currently not required as turtles can no longer right-click cauldrons.
|
||||
*/
|
||||
@GameTest(required = false)
|
||||
@GameTest(timeoutTicks = COMPUTER_TIMEOUT, required = false)
|
||||
fun Cleaned_with_cauldrons(helper: GameTestHelper) = helper.sequence { thenComputerOk() }
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
:root {
|
||||
--nav-width: 250px;
|
||||
}
|
||||
/* Some misc styles */
|
||||
|
||||
.big-image {
|
||||
|
||||
Reference in New Issue
Block a user