mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-07 08:52:59 +00:00
Compare commits
66 Commits
v1.15.2-1.
...
v1.12.2-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
161a5b4707 | ||
|
|
c6b6b4479c | ||
|
|
96e7b60285 | ||
|
|
086fccd997 | ||
|
|
a4ae36b6b3 | ||
|
|
ac075d9f53 | ||
|
|
05d7be0362 | ||
|
|
9a71dc1a26 | ||
|
|
156023b154 | ||
|
|
6b3773a862 | ||
|
|
376d628cf0 | ||
|
|
44062ebd52 | ||
|
|
5739285fc2 | ||
|
|
70b457ed18 | ||
|
|
1547ecbeb3 | ||
|
|
550ada2f9e | ||
|
|
17b7727262 | ||
|
|
4553e404b2 | ||
|
|
a565a571f9 | ||
|
|
fb64b6017b | ||
|
|
ed4229ab70 | ||
|
|
3fb906ef6c | ||
|
|
e1663f3df0 | ||
|
|
447c3ab125 | ||
|
|
8fac68386e | ||
|
|
ae7ef66dfa | ||
|
|
9748679484 | ||
|
|
da419b24e7 | ||
|
|
7f57a977a1 | ||
|
|
2f42a4e85b | ||
|
|
f3de97d67f | ||
|
|
544f276ff0 | ||
|
|
463635a459 | ||
|
|
3b7b845930 | ||
|
|
1fc0214857 | ||
|
|
11bf601db9 | ||
|
|
7c1154ddfc | ||
|
|
cea8be7efa | ||
|
|
c5f918ad95 | ||
|
|
b14c7842fc | ||
|
|
eead8b5755 | ||
|
|
10a27a7a25 | ||
|
|
865fc239a0 | ||
|
|
f9f94b8304 | ||
|
|
cb8135a0d1 | ||
|
|
ef4b0a5632 | ||
|
|
6a6a87489c | ||
|
|
062977336a | ||
|
|
e52d98ad8b | ||
|
|
ef8da8054f | ||
|
|
1ccd687c00 | ||
|
|
a8ce5a5b20 | ||
|
|
68e6bc464b | ||
|
|
68762fe84c | ||
|
|
0ffd5fcf85 | ||
|
|
239bd769df | ||
|
|
79f42e35ce | ||
|
|
be89fc25f9 | ||
|
|
8eae02c037 | ||
|
|
930fd59298 | ||
|
|
bf13bac152 | ||
|
|
0de5969ec1 | ||
|
|
3f98b2785e | ||
|
|
798868427e | ||
|
|
c79f643ba7 | ||
|
|
1db3a14c54 |
@@ -14,5 +14,9 @@ trim_trailing_whitespace = false
|
|||||||
[*.sexp]
|
[*.sexp]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.yml]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
|
||||||
[*.properties]
|
[*.properties]
|
||||||
insert_final_newline = false
|
insert_final_newline = false
|
||||||
|
|||||||
16
.github/workflows/main-ci.yml
vendored
16
.github/workflows/main-ci.yml
vendored
@@ -15,6 +15,14 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
java-version: 1.8
|
java-version: 1.8
|
||||||
|
|
||||||
|
- name: Cache gradle dependencies
|
||||||
|
uses: actions/cache@v1
|
||||||
|
with:
|
||||||
|
path: ~/.gradle/caches
|
||||||
|
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-gradle-
|
||||||
|
|
||||||
- name: Build with Gradle
|
- name: Build with Gradle
|
||||||
run: ./gradlew build --no-daemon
|
run: ./gradlew build --no-daemon
|
||||||
|
|
||||||
@@ -24,6 +32,9 @@ jobs:
|
|||||||
name: CC-Tweaked
|
name: CC-Tweaked
|
||||||
path: build/libs
|
path: build/libs
|
||||||
|
|
||||||
|
- name: Upload Coverage
|
||||||
|
run: bash <(curl -s https://codecov.io/bash)
|
||||||
|
|
||||||
lint-lua:
|
lint-lua:
|
||||||
name: Lint Lua
|
name: Lint Lua
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -34,6 +45,9 @@ jobs:
|
|||||||
- name: Lint Lua code
|
- name: Lint Lua code
|
||||||
run: |
|
run: |
|
||||||
test -d bin || mkdir bin
|
test -d bin || mkdir bin
|
||||||
test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/bin/illuaminate
|
test -f bin/illuaminate || wget -q -Obin/illuaminate https://squiddev.cc/illuaminate/linux-x86-64/illuaminate
|
||||||
chmod +x bin/illuaminate
|
chmod +x bin/illuaminate
|
||||||
bin/illuaminate lint
|
bin/illuaminate lint
|
||||||
|
|
||||||
|
- name: Check whitespace
|
||||||
|
run: python3 tools/check-lines.py
|
||||||
|
|||||||
16
.github/workflows/make-doc.sh
vendored
Executable file
16
.github/workflows/make-doc.sh
vendored
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
DEST="${GITHUB_REF#refs/*/}"
|
||||||
|
echo "Uploading docs to https://tweaked.cc/$DEST"
|
||||||
|
|
||||||
|
# Setup ssh key
|
||||||
|
mkdir -p "$HOME/.ssh/"
|
||||||
|
echo "$SSH_KEY" > "$HOME/.ssh/key"
|
||||||
|
chmod 600 "$HOME/.ssh/key"
|
||||||
|
|
||||||
|
# And upload
|
||||||
|
rsync -avc -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no -p $SSH_PORT" \
|
||||||
|
"$GITHUB_WORKSPACE/doc/" \
|
||||||
|
"$SSH_USER@$SSH_HOST:/var/www/tweaked.cc/$DEST"
|
||||||
29
.github/workflows/make-doc.yml
vendored
Normal file
29
.github/workflows/make-doc.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: Build documentation
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
tags:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
make_doc:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Build documentation
|
||||||
|
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
|
||||||
|
bin/illuaminate doc-gen
|
||||||
|
|
||||||
|
- name: Upload documentation
|
||||||
|
run: .github/workflows/make-doc.sh 2> /dev/null
|
||||||
|
env:
|
||||||
|
SSH_KEY: ${{ secrets.SSH_KEY }}
|
||||||
|
SSH_USER: ${{ secrets.SSH_USER }}
|
||||||
|
SSH_HOST: ${{ secrets.SSH_HOST }}
|
||||||
|
SSH_PORT: ${{ secrets.SSH_PORT }}
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,6 +3,8 @@
|
|||||||
/logs
|
/logs
|
||||||
/build
|
/build
|
||||||
/out
|
/out
|
||||||
|
/doc/**/*.html
|
||||||
|
/doc/index.json
|
||||||
|
|
||||||
# Runtime directories
|
# Runtime directories
|
||||||
/run
|
/run
|
||||||
|
|||||||
36
CONTRIBUTING.md
Normal file
36
CONTRIBUTING.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Contributing to CC: Tweaked
|
||||||
|
As with many open source projects, CC: Tweaked thrives on contributions from other people! This document (hopefully)
|
||||||
|
provides an introduction as to how to get started in helping out.
|
||||||
|
|
||||||
|
If you've any other questions, [just ask the community][community] or [open an issue][new-issue].
|
||||||
|
|
||||||
|
## Reporting issues
|
||||||
|
If you have a bug, suggestion, or other feedback, the best thing to do is [file an issue][new-issue]. When doing so,
|
||||||
|
do use the issue templates - they provide a useful hint on what information to provide.
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
In order to develop CC: Tweaked, you'll need to download the source code and then run it. This is a pretty simple
|
||||||
|
process.
|
||||||
|
|
||||||
|
- **Clone the repository:** `git clone https://github.com/SquidDev-CC/CC-Tweaked.git && cd CC-Tweaked`
|
||||||
|
- **Setup Forge:** `./gradlew setupDecompWorkspace`
|
||||||
|
- **Run Minecraft:** `./gradlew runClient` (or run the `GradleStart` class from your IDE).
|
||||||
|
|
||||||
|
If you want to run CC:T in a normal Minecraft instance, run `./gradlew build` and copy the `.jar` from `build/libs`.
|
||||||
|
These commands may take a few minutes to run the first time, as the environment is set up, but should be much faster
|
||||||
|
afterwards.
|
||||||
|
|
||||||
|
### Code linters
|
||||||
|
CC: Tweaked uses a couple of "linters" on its source code, to enforce a consistent style across the project. While these
|
||||||
|
are run whenever you submit a PR, it's often useful to run this before committing.
|
||||||
|
|
||||||
|
- **[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.
|
||||||
|
|
||||||
|
[new-issue]: https://github.com/SquidDev-CC/CC-Tweaked/issues/new/choose "Create a new issue"
|
||||||
|
[community]: README.md#Community "Get in touch with the community."
|
||||||
|
[checkstyle]: https://checkstyle.org/
|
||||||
|
[illuaminate]: https://github.com/SquidDev/illuaminate/
|
||||||
|
[illuaminate-usage]: https://github.com/SquidDev/illuaminate/blob/master/README.md#usage
|
||||||
18
README.md
18
README.md
@@ -1,4 +1,4 @@
|
|||||||
# 
|
# 
|
||||||
[](https://github.com/SquidDev-CC/CC-Tweaked/actions "Current build status") [](https://minecraft.curseforge.com/projects/cc-tweaked "Download CC: Tweaked on CurseForge")
|
[](https://github.com/SquidDev-CC/CC-Tweaked/actions "Current build status") [](https://minecraft.curseforge.com/projects/cc-tweaked "Download CC: Tweaked on CurseForge")
|
||||||
|
|
||||||
CC: Tweaked is a fork of [ComputerCraft](https://github.com/dan200/ComputerCraft), adding programmable computers,
|
CC: Tweaked is a fork of [ComputerCraft](https://github.com/dan200/ComputerCraft), adding programmable computers,
|
||||||
@@ -37,20 +37,14 @@ several features have been included, such as full block modems, the Cobalt runti
|
|||||||
computers.
|
computers.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
Any contribution is welcome, be that using the mod, reporting bugs or contributing code. In order to start helping
|
Any contribution is welcome, be that using the mod, reporting bugs or contributing code. If you want to get started
|
||||||
develop CC:T, you'll need to follow these steps:
|
developing the mod, [check out the instructions here](CONTRIBUTING.md#developing).
|
||||||
|
|
||||||
- **Clone the repository:** `git clone https://github.com/SquidDev-CC/CC-Tweaked.git && cd CC-Tweaked`
|
|
||||||
- **Setup Forge:** `./gradlew build`
|
|
||||||
- **Test your changes:** `./gradlew runClient` (or run the `GradleStart` class from your IDE).
|
|
||||||
|
|
||||||
If you want to run CC:T in a normal Minecraft instance, run `./gradlew build` and copy the `.jar` from `build/libs`.
|
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
|
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.gg/H2UyJXe)!
|
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
|
There's also a fairly populated, albeit quiet [IRC channel](http://webchat.esper.net/?channels=computercraft), if that's
|
||||||
that's more your cup of tea.
|
more your cup of tea.
|
||||||
|
|
||||||
I'd generally recommend you don't contact me directly (email, DM, etc...) unless absolutely necessary (i.e. in order to
|
I'd generally recommend you don't contact me directly (email, DM, etc...) unless absolutely necessary (i.e. in order to
|
||||||
report exploits). You'll get a far quicker response if you ask the whole community!
|
report exploits). You'll get a far quicker response if you ask the whole community!
|
||||||
|
|||||||
130
build.gradle
130
build.gradle
@@ -1,7 +1,8 @@
|
|||||||
|
|
||||||
|
// For those who want the bleeding edge
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
mavenCentral()
|
|
||||||
maven {
|
maven {
|
||||||
name = "forge"
|
name = "forge"
|
||||||
url = "https://files.minecraftforge.net/maven"
|
url = "https://files.minecraftforge.net/maven"
|
||||||
@@ -9,20 +10,21 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.google.code.gson:gson:2.8.1'
|
classpath 'com.google.code.gson:gson:2.8.1'
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:3.0.159'
|
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
|
||||||
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
|
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta1'
|
||||||
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "checkstyle"
|
id "checkstyle"
|
||||||
|
id "jacoco"
|
||||||
id "com.github.hierynomus.license" version "0.15.0"
|
id "com.github.hierynomus.license" version "0.15.0"
|
||||||
id "com.matthewprenger.cursegradle" version "1.3.0"
|
id "com.matthewprenger.cursegradle" version "1.3.0"
|
||||||
id "com.github.breadmoirai.github-release" version "2.2.4"
|
id "com.github.breadmoirai.github-release" version "2.2.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'net.minecraftforge.gradle'
|
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||||
apply plugin: 'org.ajoberstar.grgit'
|
apply plugin: 'org.ajoberstar.grgit'
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
@@ -33,46 +35,27 @@ group = "org.squiddev"
|
|||||||
archivesBaseName = "cc-tweaked-${mc_version}"
|
archivesBaseName = "cc-tweaked-${mc_version}"
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
runs {
|
version = "${mc_version}-${forge_version}"
|
||||||
client {
|
runDir = "run"
|
||||||
workingDirectory project.file('run')
|
replace '${version}', mod_version
|
||||||
property 'forge.logging.markers', 'REGISTRIES'
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
|
|
||||||
mods {
|
mappings = mappings_version
|
||||||
computercraft {
|
makeObfSourceJar = false
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
workingDirectory project.file('run')
|
|
||||||
property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
|
|
||||||
mods {
|
|
||||||
computercraft {
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mappings channel: 'snapshot', version: "${mappings_version}".toString()
|
|
||||||
|
|
||||||
accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
|
||||||
name "JEI"
|
|
||||||
url "https://dvs1.progwml6.com/files/maven"
|
|
||||||
}
|
|
||||||
maven {
|
maven {
|
||||||
name "SquidDev"
|
name "SquidDev"
|
||||||
url "https://squiddev.cc/maven"
|
url "https://squiddev.cc/maven"
|
||||||
}
|
}
|
||||||
|
ivy {
|
||||||
|
name "Charset"
|
||||||
|
artifactPattern "https://asie.pl/files/mods/Charset/LibOnly/[module]-[revision](-[classifier]).[ext]"
|
||||||
|
}
|
||||||
|
maven {
|
||||||
|
name "Amadornes"
|
||||||
|
url "https://maven.amadornes.com/"
|
||||||
|
}
|
||||||
maven {
|
maven {
|
||||||
name "CraftTweaker"
|
name "CraftTweaker"
|
||||||
url "https://maven.blamejared.com/"
|
url "https://maven.blamejared.com/"
|
||||||
@@ -88,12 +71,14 @@ configurations {
|
|||||||
dependencies {
|
dependencies {
|
||||||
checkstyle "com.puppycrawl.tools:checkstyle:8.25"
|
checkstyle "com.puppycrawl.tools:checkstyle:8.25"
|
||||||
|
|
||||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
deobfProvided "CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.554"
|
||||||
|
deobfProvided "MCMultiPart2:MCMultiPart:2.5.3"
|
||||||
|
deobfProvided "mezz.jei:jei_1.12.2:4.15.0.269:api"
|
||||||
|
deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
|
||||||
|
|
||||||
compileOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.2:api")
|
runtime "mezz.jei:jei_1.12.2:4.15.0.269"
|
||||||
runtimeOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.2")
|
|
||||||
|
|
||||||
shade 'org.squiddev:Cobalt:0.5.0-SNAPSHOT'
|
shade 'org.squiddev:Cobalt:0.5.1-SNAPSHOT'
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
|
||||||
@@ -101,15 +86,6 @@ dependencies {
|
|||||||
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
|
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
java {
|
|
||||||
exclude 'dan200/computercraft/client/render_old'
|
|
||||||
exclude 'dan200/computercraft/shared/integration/crafttweaker'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compile tasks
|
// Compile tasks
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
@@ -120,13 +96,7 @@ jar {
|
|||||||
dependsOn javadoc
|
dependsOn javadoc
|
||||||
|
|
||||||
manifest {
|
manifest {
|
||||||
attributes(["Specification-Title": "computercraft",
|
attributes('FMLAT': 'computercraft_at.cfg')
|
||||||
"Specification-Vendor": "SquidDev",
|
|
||||||
"Specification-Version": "1",
|
|
||||||
"Implementation-Title": "CC: Tweaked",
|
|
||||||
"Implementation-Version": "${mod_version}",
|
|
||||||
"Implementation-Vendor" :"SquidDev",
|
|
||||||
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
from (sourceSets.main.allSource) {
|
from (sourceSets.main.allSource) {
|
||||||
@@ -138,7 +108,7 @@ jar {
|
|||||||
|
|
||||||
[compileJava, compileTestJava].forEach {
|
[compileJava, compileTestJava].forEach {
|
||||||
it.configure {
|
it.configure {
|
||||||
options.compilerArgs << "-Xlint" << "-Xlint:-processing"
|
options.compilerArgs << "-Xlint" << "-Xlint:-processing" << "-Werror"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,14 +145,10 @@ task proguard(type: ProGuardTask, dependsOn: jar) {
|
|||||||
dontobfuscate; dontoptimize; keepattributes; keepparameternames
|
dontobfuscate; dontoptimize; keepattributes; keepparameternames
|
||||||
|
|
||||||
// Proguard will remove directories by default, but that breaks JarMount.
|
// Proguard will remove directories by default, but that breaks JarMount.
|
||||||
keepdirectories 'data/computercraft/lua**'
|
keepdirectories 'assets/computercraft/lua**'
|
||||||
|
|
||||||
// Preserve ComputerCraft classes - we only want to strip shadowed files.
|
// Preserve ComputerCraft classes - we only want to strip shadowed files.
|
||||||
keep 'class dan200.computercraft.** { *; }'
|
keep 'class dan200.computercraft.** { *; }'
|
||||||
|
|
||||||
// LWJGL and Apache bundle Java 9 versions, which is great, but rather breaks Proguard
|
|
||||||
dontwarn 'module-info'
|
|
||||||
dontwarn 'org.apache.**,org.lwjgl.**'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
task proguardMove(dependsOn: proguard) {
|
task proguardMove(dependsOn: proguard) {
|
||||||
@@ -198,7 +164,7 @@ task proguardMove(dependsOn: proguard) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reobfJar.dependsOn proguardMove
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", mod_version
|
inputs.property "version", mod_version
|
||||||
@@ -220,8 +186,8 @@ processResources {
|
|||||||
inputs.property "commithash", hash
|
inputs.property "commithash", hash
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
include 'META-INF/mods.toml'
|
include 'mcmod.info'
|
||||||
include 'data/computercraft/lua/rom/help/credits.txt'
|
include 'assets/computercraft/lua/rom/help/credits.txt'
|
||||||
|
|
||||||
expand 'version': mod_version,
|
expand 'version': mod_version,
|
||||||
'mcversion': mc_version,
|
'mcversion': mc_version,
|
||||||
@@ -229,12 +195,12 @@ processResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
exclude 'META-INF/mods.toml'
|
exclude 'mcmod.info'
|
||||||
exclude 'data/computercraft/lua/rom/help/credits.txt'
|
exclude 'assets/computercraft/lua/rom/help/credits.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task compressJson(dependsOn: jar) {
|
task compressJson(dependsOn: extractAnnotationsJar) {
|
||||||
group "compact"
|
group "compact"
|
||||||
description "Minifies all JSON files, stripping whitespace"
|
description "Minifies all JSON files, stripping whitespace"
|
||||||
|
|
||||||
@@ -286,6 +252,15 @@ test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jacocoTestReport {
|
||||||
|
reports {
|
||||||
|
xml.enabled true
|
||||||
|
html.enabled true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
check.dependsOn jacocoTestReport
|
||||||
|
|
||||||
license {
|
license {
|
||||||
mapping("java", "SLASHSTAR_STYLE")
|
mapping("java", "SLASHSTAR_STYLE")
|
||||||
strictCheck true
|
strictCheck true
|
||||||
@@ -332,14 +307,14 @@ task checkRelease {
|
|||||||
description "Verifies that everything is ready for a release"
|
description "Verifies that everything is ready for a release"
|
||||||
|
|
||||||
inputs.property "version", mod_version
|
inputs.property "version", mod_version
|
||||||
inputs.file("src/main/resources/data/computercraft/lua/rom/help/changelog.txt")
|
inputs.file("src/main/resources/assets/computercraft/lua/rom/help/changelog.txt")
|
||||||
inputs.file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
|
inputs.file("src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt")
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
def ok = true
|
def ok = true
|
||||||
|
|
||||||
// Check we're targetting the current version
|
// Check we're targetting the current version
|
||||||
def whatsnew = new File("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt").readLines()
|
def whatsnew = new File("src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt").readLines()
|
||||||
if (whatsnew[0] != "New features in CC: Tweaked $mod_version") {
|
if (whatsnew[0] != "New features in CC: Tweaked $mod_version") {
|
||||||
ok = false
|
ok = false
|
||||||
project.logger.error("Expected `whatsnew.txt' to target $mod_version.")
|
project.logger.error("Expected `whatsnew.txt' to target $mod_version.")
|
||||||
@@ -356,7 +331,7 @@ task checkRelease {
|
|||||||
|
|
||||||
// Check whatsnew and changelog match.
|
// Check whatsnew and changelog match.
|
||||||
def versionChangelog = "# " + whatsnew.join("\n")
|
def versionChangelog = "# " + whatsnew.join("\n")
|
||||||
def changelog = new File("src/main/resources/data/computercraft/lua/rom/help/changelog.txt").getText()
|
def changelog = new File("src/main/resources/assets/computercraft/lua/rom/help/changelog.txt").getText()
|
||||||
if (!changelog.startsWith(versionChangelog)) {
|
if (!changelog.startsWith(versionChangelog)) {
|
||||||
ok = false
|
ok = false
|
||||||
project.logger.error("whatsnew and changelog are not in sync")
|
project.logger.error("whatsnew and changelog are not in sync")
|
||||||
@@ -371,7 +346,7 @@ curseforge {
|
|||||||
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
||||||
project {
|
project {
|
||||||
id = '282001'
|
id = '282001'
|
||||||
releaseType = 'alpha'
|
releaseType = 'release'
|
||||||
changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
|
changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
|
||||||
|
|
||||||
relations {
|
relations {
|
||||||
@@ -384,7 +359,7 @@ publishing {
|
|||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
// artifact sourceJar
|
artifact sourceJar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,12 +419,12 @@ githubRelease {
|
|||||||
tagName "v${mc_version}-${mod_version}"
|
tagName "v${mc_version}-${mod_version}"
|
||||||
releaseName "[${mc_version}] ${mod_version}"
|
releaseName "[${mc_version}] ${mod_version}"
|
||||||
body {
|
body {
|
||||||
"## " + new File("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
|
"## " + new File("src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt")
|
||||||
.readLines()
|
.readLines()
|
||||||
.takeWhile { it != 'Type "help changelog" to see the full version history.' }
|
.takeWhile { it != 'Type "help changelog" to see the full version history.' }
|
||||||
.join("\n").trim()
|
.join("\n").trim()
|
||||||
}
|
}
|
||||||
prerelease true
|
prerelease false
|
||||||
}
|
}
|
||||||
|
|
||||||
def uploadTasks = ["uploadArchives", "curseforge", "githubRelease"]
|
def uploadTasks = ["uploadArchives", "curseforge", "githubRelease"]
|
||||||
@@ -459,3 +434,6 @@ task uploadAll(dependsOn: uploadTasks) {
|
|||||||
group "upload"
|
group "upload"
|
||||||
description "Uploads to all repositories (Maven, Curse, GitHub release)"
|
description "Uploads to all repositories (Maven, Curse, GitHub release)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runClient.outputs.upToDateWhen { false }
|
||||||
|
runServer.outputs.upToDateWhen { false }
|
||||||
|
|||||||
@@ -10,10 +10,6 @@
|
|||||||
<property name="file" value="config/checkstyle/suppressions.xml" />
|
<property name="file" value="config/checkstyle/suppressions.xml" />
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
<module name="BeforeExecutionExclusionFileFilter">
|
|
||||||
<property name="fileNamePattern" value="render_old"/>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="TreeWalker">
|
<module name="TreeWalker">
|
||||||
<!-- Annotations -->
|
<!-- Annotations -->
|
||||||
<module name="AnnotationLocation" />
|
<module name="AnnotationLocation" />
|
||||||
@@ -160,7 +156,7 @@
|
|||||||
<module name="WhitespaceAround">
|
<module name="WhitespaceAround">
|
||||||
<property name="allowEmptyConstructors" value="true" />
|
<property name="allowEmptyConstructors" value="true" />
|
||||||
<property name="ignoreEnhancedForColon" value="false" />
|
<property name="ignoreEnhancedForColon" value="false" />
|
||||||
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_RETURN,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND" />
|
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,DO_WHILE,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_RETURN,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND" />
|
||||||
</module>
|
</module>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
11
doc/index.md
Normal file
11
doc/index.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#  [](https://minecraft.curseforge.com/projects/cc-tweaked "Download CC: Tweaked on CurseForge")
|
||||||
|
|
||||||
|
CC: Tweaked is a fork of [ComputerCraft], adding programmable computers, turtles and more to Minecraft.
|
||||||
|
|
||||||
|
This website contains documentation for all Lua libraries and APIs from the latest version of CC: Tweaked. This
|
||||||
|
documentation is still in development, so will most likely be incomplete. If you've found something you think is wrong,
|
||||||
|
or would like to help out [please get in touch on GitHub][gh].
|
||||||
|
|
||||||
|
[bug]: https://github.com/SquidDev-CC/CC-Tweaked/issues/new/choose
|
||||||
|
[computercraft]: https://github.com/dan200/ComputerCraft "ComputerCraft on GitHub"
|
||||||
|
[gh]: https://github.com/SquidDev-CC/CC-Tweaked "CC:Tweaked on GitHub"
|
||||||
|
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 2.2 KiB |
77
doc/stub/commands.lua
Normal file
77
doc/stub/commands.lua
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
--- Execute a specific command.
|
||||||
|
--
|
||||||
|
-- @tparam string command The command to execute.
|
||||||
|
-- @treturn boolean Whether the command executed successfully.
|
||||||
|
-- @treturn { string... } The output of this command, as a list of lines.
|
||||||
|
-- @treturn number|nil The number of "affected" objects, or `nil` if the command
|
||||||
|
-- failed. The definition of this varies from command to command.
|
||||||
|
-- @usage Set the block above the command computer to stone.
|
||||||
|
--
|
||||||
|
-- commands.exec("setblock ~ ~1 ~ minecraft:stone")
|
||||||
|
function exec(command) end
|
||||||
|
|
||||||
|
--- Asynchronously execute a command.
|
||||||
|
--
|
||||||
|
-- Unlike @{exec}, this will immediately return, instead of waiting for the
|
||||||
|
-- command to execute. This allows you to run multiple commands at the same
|
||||||
|
-- time.
|
||||||
|
--
|
||||||
|
-- When this command has finished executing, it will queue a `task_complete`
|
||||||
|
-- event containing the result of executing this command (what @{exec} would
|
||||||
|
-- return).
|
||||||
|
--
|
||||||
|
-- @tparam string command The command to execute.
|
||||||
|
-- @treturn number The "task id". When this command has been executed, it will
|
||||||
|
-- queue a `task_complete` event with a matching id.
|
||||||
|
-- @usage Asynchronously sets the block above the computer to stone.
|
||||||
|
--
|
||||||
|
-- commands.execAsync("~ ~1 ~ minecraft:stone")
|
||||||
|
-- @see parallel One may also use the parallel API to run multiple commands at
|
||||||
|
-- once.
|
||||||
|
function execAsync(commad) end
|
||||||
|
|
||||||
|
--- List all available commands which the computer has permission to execute.
|
||||||
|
--
|
||||||
|
-- @treturn { string... } A list of all available commands
|
||||||
|
function list() end
|
||||||
|
|
||||||
|
--- Get the position of the current command computer.
|
||||||
|
--
|
||||||
|
-- @treturn number This computer's x position.
|
||||||
|
-- @treturn number This computer's y position.
|
||||||
|
-- @treturn number This computer's z position.
|
||||||
|
-- @see gps.locate To get the position of a non-command computer.
|
||||||
|
function getBlockPosition() end
|
||||||
|
|
||||||
|
--- Get some basic information about a block.
|
||||||
|
--
|
||||||
|
-- The returned table contains the current name, metadata and block state (as
|
||||||
|
-- with @{turtle.inspect}). If there is a tile entity for that block, its NBT
|
||||||
|
-- will also be returned.
|
||||||
|
--
|
||||||
|
-- @tparam number x The x position of the block to query.
|
||||||
|
-- @tparam number y The y position of the block to query.
|
||||||
|
-- @tparam number z The z position of the block to query.
|
||||||
|
-- @treturn table The given block's information.
|
||||||
|
-- @throws If the coordinates are not within the world, or are not currently
|
||||||
|
-- loaded.
|
||||||
|
function getBlockInfo(x, y, z) end
|
||||||
|
|
||||||
|
--- Get information about a range of blocks.
|
||||||
|
--
|
||||||
|
-- This returns the same information as @{getBlockInfo}, just for multiple
|
||||||
|
-- blocks at once.
|
||||||
|
--
|
||||||
|
-- Blocks are traversed by ascending y level, followed by z and x - the returned
|
||||||
|
-- table may be indexed using `x + z*width + y*depth*depth`.
|
||||||
|
--
|
||||||
|
-- @tparam number min_x The start x coordinate of the range to query.
|
||||||
|
-- @tparam number min_y The start y coordinate of the range to query.
|
||||||
|
-- @tparam number min_z The start z coordinate of the range to query.
|
||||||
|
-- @tparam number max_x The end x coordinate of the range to query.
|
||||||
|
-- @tparam number max_y The end y coordinate of the range to query.
|
||||||
|
-- @tparam number max_z The end z coordinate of the range to query.
|
||||||
|
-- @treturn { table... } A list of information about each block.
|
||||||
|
-- @throws If the coordinates are not within the world.
|
||||||
|
-- @throws If trying to get information about more than 4096 blocks.
|
||||||
|
function getBlockInfos(min_x, min_y, min_z, max_x, max_y, max_z) end
|
||||||
84
doc/stub/fs.lua
Normal file
84
doc/stub/fs.lua
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
--- The FS API allows you to manipulate files and the filesystem.
|
||||||
|
--
|
||||||
|
-- @module fs
|
||||||
|
|
||||||
|
function list(path) end
|
||||||
|
function combine(base, child) end
|
||||||
|
function getName(path) end
|
||||||
|
function getSize(path) end
|
||||||
|
function exists(path) end
|
||||||
|
function isDir(path) end
|
||||||
|
function isReadOnly(path) end
|
||||||
|
function makeDir(path) end
|
||||||
|
function move(from, to) end
|
||||||
|
function copy(from, to) end
|
||||||
|
function delete(path) end
|
||||||
|
function open(path, mode) end
|
||||||
|
function getDrive(path) end
|
||||||
|
function getFreeSpace(path) end
|
||||||
|
function find(pattern) end
|
||||||
|
function getDir(path) end
|
||||||
|
|
||||||
|
--- Returns true if a path is mounted to the parent filesystem.
|
||||||
|
--
|
||||||
|
-- The root filesystem "/" is considered a mount, along with disk folders and
|
||||||
|
-- the rom folder. Other programs (such as network shares) can exstend this to
|
||||||
|
-- make other mount types by correctly assigning their return value for getDrive.
|
||||||
|
--
|
||||||
|
-- @tparam string path The path to check.
|
||||||
|
-- @treturn boolean If the path is mounted, rather than a normal file/folder.
|
||||||
|
-- @throws If the path does not exist.
|
||||||
|
-- @see getDrive
|
||||||
|
function isDriveRoot(path) end
|
||||||
|
|
||||||
|
--- Get the capacity of the drive at the given path.
|
||||||
|
--
|
||||||
|
-- This may be used in conjunction with @{getFreeSpace} to determine what
|
||||||
|
-- percentage of this drive has been used.
|
||||||
|
--
|
||||||
|
-- @tparam string path The path of the drive to get.
|
||||||
|
-- @treturn number This drive's capacity. This will be 0 for "read-only" drives,
|
||||||
|
-- such as the ROM or treasure disks.
|
||||||
|
function getCapacity(path) end
|
||||||
|
|
||||||
|
--- Get attributes about a specific file or folder.
|
||||||
|
--
|
||||||
|
-- The returned attributes table contains information about the size of the
|
||||||
|
-- file, whether it is a directory, and when it was created and last modified.
|
||||||
|
--
|
||||||
|
-- The creation and modification times are given as the number of milliseconds
|
||||||
|
-- since the UNIX epoch. This may be given to @{os.date} in order to convert it
|
||||||
|
-- to more usable form.
|
||||||
|
--
|
||||||
|
-- @tparam string path The path to get attributes for.
|
||||||
|
-- @treturn { size = number, isDir = boolean, created = number, modified = number }
|
||||||
|
-- The resulting attributes.
|
||||||
|
-- @throws If the path does not exist.
|
||||||
|
-- @see getSize If you only care about the file's size.
|
||||||
|
-- @see isDir If you only care whether a path is a directory or not.
|
||||||
|
function attributes(path) end
|
||||||
|
|
||||||
|
-- Defined in bios.lua
|
||||||
|
function complete(sPath, sLocation, bIncludeFiles, bIncludeDirs) end
|
||||||
|
|
||||||
|
--- A file handle which can be read from.
|
||||||
|
--
|
||||||
|
-- @type ReadHandle
|
||||||
|
-- @see fs.open
|
||||||
|
local ReadHandle = {}
|
||||||
|
function ReadHandle.read(count) end
|
||||||
|
function ReadHandle.readAll() end
|
||||||
|
function ReadHandle.readLine(with_trailing) end
|
||||||
|
function ReadHandle.seek(whence, offset) end
|
||||||
|
function ReadHandle.close() end
|
||||||
|
|
||||||
|
--- A file handle which can be written to.
|
||||||
|
--
|
||||||
|
-- @type WriteHandle
|
||||||
|
-- @see fs.open
|
||||||
|
local WriteHandle = {}
|
||||||
|
function WriteHandle.write(text) end
|
||||||
|
function WriteHandle.writeLine(text) end
|
||||||
|
function WriteHandle.flush(text) end
|
||||||
|
function WriteHandle.seek(whence, offset) end
|
||||||
|
function WriteHandle.close() end
|
||||||
229
doc/stub/http.lua
Normal file
229
doc/stub/http.lua
Normal file
@@ -0,0 +1,229 @@
|
|||||||
|
--- The http library allows communicating with web servers, sending and
|
||||||
|
-- receiving data from them.
|
||||||
|
--
|
||||||
|
-- #### `http_check` event
|
||||||
|
--
|
||||||
|
-- @module http
|
||||||
|
|
||||||
|
--- Asynchronously make a HTTP request to the given url.
|
||||||
|
--
|
||||||
|
-- This returns immediately, a [`http_success`](#http-success-event) or
|
||||||
|
-- [`http_failure`](#http-failure-event) will be queued once the request has
|
||||||
|
-- completed.
|
||||||
|
--
|
||||||
|
-- @tparam string url The url to request
|
||||||
|
-- @tparam[opt] string body An optional string containing the body of the
|
||||||
|
-- request. If specified, a `POST` request will be made instead.
|
||||||
|
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||||
|
-- of this request.
|
||||||
|
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
|
||||||
|
-- the body will not be UTF-8 encoded, and the received response will not be
|
||||||
|
-- decoded.
|
||||||
|
--
|
||||||
|
-- @tparam[2] {
|
||||||
|
-- url = string, body? = string, headers? = { [string] = string },
|
||||||
|
-- binary? = boolean, method? = string, redirect? = boolean,
|
||||||
|
-- } request Options for the request.
|
||||||
|
--
|
||||||
|
-- This table form is an expanded version of the previous syntax. All arguments
|
||||||
|
-- from above are passed in as fields instead (for instance,
|
||||||
|
-- `http.request("https://example.com")` becomes `http.request { url =
|
||||||
|
-- "https://example.com" }`).
|
||||||
|
--
|
||||||
|
-- This table also accepts several additional options:
|
||||||
|
--
|
||||||
|
-- - `method`: Which HTTP method to use, for instance `"PATCH"` or `"DELETE"`.
|
||||||
|
-- - `redirect`: Whether to follow HTTP redirects. Defaults to true.
|
||||||
|
--
|
||||||
|
-- @see http.get For a synchronous way to make GET requests.
|
||||||
|
-- @see http.post For a synchronous way to make POST requests.
|
||||||
|
function request(...) end
|
||||||
|
|
||||||
|
--- Make a HTTP GET request to the given url.
|
||||||
|
--
|
||||||
|
-- @tparam string url The url to request
|
||||||
|
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||||
|
-- of this request.
|
||||||
|
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
|
||||||
|
-- the body will not be UTF-8 encoded, and the received response will not be
|
||||||
|
-- decoded.
|
||||||
|
--
|
||||||
|
-- @tparam[2] {
|
||||||
|
-- url = string, headers? = { [string] = string },
|
||||||
|
-- binary? = boolean, method? = string, redirect? = boolean,
|
||||||
|
-- } request Options for the request. See @{http.request} for details on how
|
||||||
|
-- these options behave.
|
||||||
|
--
|
||||||
|
-- @treturn Response The resulting http response, which can be read from.
|
||||||
|
-- @treturn[2] nil When the http request failed, such as in the event of a 404
|
||||||
|
-- error or connection timeout.
|
||||||
|
-- @treturn string A message detailing why the request failed.
|
||||||
|
-- @treturn Response|nil The failing http response, if available.
|
||||||
|
--
|
||||||
|
-- @usage Make a request to [example.computercraft.cc](https://example.computercraft.cc),
|
||||||
|
-- and print the returned page.
|
||||||
|
-- ```lua
|
||||||
|
-- local request = http.get("https://example.computercraft.cc")
|
||||||
|
-- print(request.readAll())
|
||||||
|
-- -- => HTTP is working!
|
||||||
|
-- request.close()
|
||||||
|
-- ```
|
||||||
|
function get(...) end
|
||||||
|
|
||||||
|
--- Make a HTTP POST request to the given url.
|
||||||
|
--
|
||||||
|
-- @tparam string url The url to request
|
||||||
|
-- @tparam string body The body of the POST request.
|
||||||
|
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||||
|
-- of this request.
|
||||||
|
-- @tparam[opt] boolean binary Whether to make a binary HTTP request. If true,
|
||||||
|
-- the body will not be UTF-8 encoded, and the received response will not be
|
||||||
|
-- decoded.
|
||||||
|
--
|
||||||
|
-- @tparam[2] {
|
||||||
|
-- url = string, body? = string, headers? = { [string] = string },
|
||||||
|
-- binary? = boolean, method? = string, redirect? = boolean,
|
||||||
|
-- } request Options for the request. See @{http.request} for details on how
|
||||||
|
-- these options behave.
|
||||||
|
--
|
||||||
|
-- @treturn Response The resulting http response, which can be read from.
|
||||||
|
-- @treturn[2] nil When the http request failed, such as in the event of a 404
|
||||||
|
-- error or connection timeout.
|
||||||
|
-- @treturn string A message detailing why the request failed.
|
||||||
|
-- @treturn Response|nil The failing http response, if available.
|
||||||
|
function post(...) end
|
||||||
|
|
||||||
|
--- A http response. This acts very much like a @{fs.ReadHandle|file}, though
|
||||||
|
-- provides some http specific methods.
|
||||||
|
--
|
||||||
|
-- #### `http_success` event
|
||||||
|
-- #### `http_failure` event
|
||||||
|
--
|
||||||
|
-- @type Response
|
||||||
|
-- @see http.request On how to make a http request.
|
||||||
|
local Response = {}
|
||||||
|
|
||||||
|
--- Returns the response code and response message returned by the server
|
||||||
|
--
|
||||||
|
-- @treturn number The response code (i.e. 200)
|
||||||
|
-- @treturn string The response message (i.e. "OK")
|
||||||
|
function Response.getResponseCode() end
|
||||||
|
|
||||||
|
--- Get a table containing the response's headers, in a format similar to that
|
||||||
|
-- required by @{http.request}. If multiple headers are sent with the same
|
||||||
|
-- name, they will be combined with a comma.
|
||||||
|
--
|
||||||
|
-- @treturn { [string]=string } The response's headers.
|
||||||
|
-- Make a request to [example.computercraft.cc](https://example.computercraft.cc),
|
||||||
|
-- and print the returned headers.
|
||||||
|
-- ```lua
|
||||||
|
-- local request = http.get("https://example.computercraft.cc")
|
||||||
|
-- print(textutils.serialize(request.getResponseHeaders()))
|
||||||
|
-- -- => {
|
||||||
|
-- -- [ "Content-Type" ] = "text/plain; charset=utf8",
|
||||||
|
-- -- [ "content-length" ] = 17,
|
||||||
|
-- -- ...
|
||||||
|
-- -- }
|
||||||
|
-- request.close()
|
||||||
|
-- ```
|
||||||
|
function Response.getResponseHeaders() end
|
||||||
|
|
||||||
|
function Response.read(count) end
|
||||||
|
function Response.readAll() end
|
||||||
|
function Response.readLine(with_trailing) end
|
||||||
|
function Response.seek(whence, offset) end
|
||||||
|
function Response.close() end
|
||||||
|
|
||||||
|
--- Asynchronously determine whether a URL can be requested.
|
||||||
|
--
|
||||||
|
-- If this returns `true`, one should also listen for [`http_check`
|
||||||
|
-- events](#http-check-event) which will container further information about
|
||||||
|
-- whether the URL is allowed or not.
|
||||||
|
--
|
||||||
|
-- @tparam string url The URL to check.
|
||||||
|
-- @treturn true When this url is not invalid. This does not imply that it is
|
||||||
|
-- allowed - see the comment above.
|
||||||
|
-- @treturn[2] false When this url is invalid.
|
||||||
|
-- @treturn string A reason why this URL is not valid (for instance, if it is
|
||||||
|
-- malformed, or blocked).
|
||||||
|
--
|
||||||
|
-- @see http.checkURL For a synchronous version.
|
||||||
|
function checkURLAsync(url) end
|
||||||
|
|
||||||
|
--- Determine whether a URL can be requested.
|
||||||
|
--
|
||||||
|
-- If this returns `true`, one should also listen for [`http_check`
|
||||||
|
-- events](#http-check-event) which will container further information about
|
||||||
|
-- whether the URL is allowed or not.
|
||||||
|
--
|
||||||
|
-- @tparam string url The URL to check.
|
||||||
|
-- @treturn true When this url is valid and can be requested via @{http.request}.
|
||||||
|
-- @treturn[2] false When this url is invalid.
|
||||||
|
-- @treturn string A reason why this URL is not valid (for instance, if it is
|
||||||
|
-- malformed, or blocked).
|
||||||
|
--
|
||||||
|
-- @see http.checkURLAsync For an asynchronous version.
|
||||||
|
--
|
||||||
|
-- @usage
|
||||||
|
-- ```lua
|
||||||
|
-- print(http.checkURL("https://example.computercraft.cc/"))
|
||||||
|
-- -- => true
|
||||||
|
-- print(http.checkURL("http://localhost/"))
|
||||||
|
-- -- => false Domain not permitted
|
||||||
|
-- print(http.checkURL("not a url"))
|
||||||
|
-- -- => false URL malformed
|
||||||
|
-- ```
|
||||||
|
function checkURL(url) end
|
||||||
|
|
||||||
|
--- Open a websocket.
|
||||||
|
--
|
||||||
|
-- @tparam string url The websocket url to connect to. This should have the
|
||||||
|
-- `ws://` or `wss://` protocol.
|
||||||
|
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||||
|
-- of the initial websocket connection.
|
||||||
|
--
|
||||||
|
-- @treturn Websocket The websocket connection.
|
||||||
|
-- @treturn[2] false If the websocket connection failed.
|
||||||
|
-- @treturn string An error message describing why the connection failed.
|
||||||
|
function websocket(url, headers) end
|
||||||
|
|
||||||
|
--- Asynchronously open a websocket.
|
||||||
|
--
|
||||||
|
-- This returns immediately, a [`websocket_success`](#websocket-success-event)
|
||||||
|
-- or [`websocket_failure`](#websocket-failure-event) will be queued once the
|
||||||
|
-- request has completed.
|
||||||
|
--
|
||||||
|
-- @tparam string url The websocket url to connect to. This should have the
|
||||||
|
-- `ws://` or `wss://` protocol.
|
||||||
|
-- @tparam[opt] { [string] = string } headers Additional headers to send as part
|
||||||
|
-- of the initial websocket connection.
|
||||||
|
function websocketAsync(url, headers) end
|
||||||
|
|
||||||
|
--- A websocket, which can be used to send an receive messages with a web
|
||||||
|
-- server.
|
||||||
|
--
|
||||||
|
-- @type Websocket
|
||||||
|
-- @see http.websocket On how to open a websocket.
|
||||||
|
local Websocket = {}
|
||||||
|
|
||||||
|
--- Send a websocket message to the connected server.
|
||||||
|
--
|
||||||
|
-- @tparam string message The message to send.
|
||||||
|
-- @tparam[opt] boolean binary Whether this message should be treated as a
|
||||||
|
-- binary string, rather than encoded text.
|
||||||
|
-- @throws If the websocket has been closed.
|
||||||
|
function Websocket.send(message, binary) end
|
||||||
|
|
||||||
|
--- Wait for a message from the server.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number timeout The number of seconds to wait if no message is
|
||||||
|
-- received.
|
||||||
|
-- @treturn[1] string The received message.
|
||||||
|
-- @treturn boolean If this was a binary message.
|
||||||
|
-- @treturn[2] nil If the websocket was closed while waiting, or if we timed out.
|
||||||
|
-- @throws If the websocket has been closed.
|
||||||
|
function Websocket.receive(timeout) end
|
||||||
|
|
||||||
|
--- Close this websocket. This will terminate the connection, meaning messages
|
||||||
|
-- can no longer be sent or received along it.
|
||||||
|
function Websocket.close() end
|
||||||
24
doc/stub/os.lua
Normal file
24
doc/stub/os.lua
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
function queueEvent(event, ...) end
|
||||||
|
function startTimer(delay) end
|
||||||
|
function setAlarm(time) end
|
||||||
|
function shutdown() end
|
||||||
|
function reboot() end
|
||||||
|
function getComputerID() end
|
||||||
|
computerID = getComputerID
|
||||||
|
function setComputerLabel(label) end
|
||||||
|
function getComputerLabel() end
|
||||||
|
computerLabel = getComputerLabel
|
||||||
|
function clock() end
|
||||||
|
function time(timezone) end
|
||||||
|
function day(timezone) end
|
||||||
|
function cancelTimer(id) end
|
||||||
|
function cancelAlarm(id) end
|
||||||
|
function epoch(timezone) end
|
||||||
|
function date(format, time) end
|
||||||
|
|
||||||
|
-- Defined in bios.lua
|
||||||
|
function loadAPI(path) end
|
||||||
|
function pullEvent(filter) end
|
||||||
|
function pullEventRaw(filter) end
|
||||||
|
function version() end
|
||||||
|
function run(env, path, ...) end
|
||||||
28
doc/stub/pocket.lua
Normal file
28
doc/stub/pocket.lua
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
--[[-
|
||||||
|
Control the current pocket computer, adding or removing upgrades.
|
||||||
|
|
||||||
|
This API is only available on pocket computers. As such, you may use its
|
||||||
|
presence to determine what kind of computer you are using:
|
||||||
|
|
||||||
|
```lua
|
||||||
|
if pocket then
|
||||||
|
print("On a pocket computer")
|
||||||
|
else
|
||||||
|
print("On something else")
|
||||||
|
end
|
||||||
|
```
|
||||||
|
]]
|
||||||
|
|
||||||
|
--- Search the player's inventory for another upgrade, replacing the existing
|
||||||
|
-- one with that item if found.
|
||||||
|
--
|
||||||
|
-- This inventory search starts from the player's currently selected slot,
|
||||||
|
-- allowing you to prioritise upgrades.
|
||||||
|
--
|
||||||
|
-- @throws If an upgrade cannot be found.
|
||||||
|
function equipBack() end
|
||||||
|
|
||||||
|
--- Remove the pocket computer's current upgrade.
|
||||||
|
--
|
||||||
|
-- @throws If this pocket computer does not currently have an upgrade.
|
||||||
|
function unequipBack() end
|
||||||
120
doc/stub/redstone.lua
Normal file
120
doc/stub/redstone.lua
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
--[[- Interact with redstone attached to this computer.
|
||||||
|
|
||||||
|
The @{redstone} library exposes three "types" of redstone control:
|
||||||
|
- Binary input/output (@{setOutput}/@{getInput}): These simply check if a
|
||||||
|
redstone wire has any input or output. A signal strength of 1 and 15 are
|
||||||
|
treated the same.
|
||||||
|
- Analogue input/output (@{setAnalogueOutput}/@{getAnalogueInput}): These
|
||||||
|
work with the actual signal strength of the redstone wired, from 0 to 15.
|
||||||
|
- Bundled cables (@{setBundledOutput}/@{getBundledInput}): These interact with
|
||||||
|
"bundled" cables, such as those from Project:Red. These allow you to send
|
||||||
|
16 separate on/off signals. Each channel corresponds to a colour, with the
|
||||||
|
first being @{colors.white} and the last @{colors.black}.
|
||||||
|
|
||||||
|
Whenever a redstone input changes, a `redstone` event will be fired. This may
|
||||||
|
be used in or
|
||||||
|
|
||||||
|
This module may also be referred to as `rs`. For example, one may call
|
||||||
|
`rs.getSides()` instead of @{redstone.getSides}.
|
||||||
|
|
||||||
|
@module redstone
|
||||||
|
@usage Toggle the redstone signal above the computer every 0.5 seconds.
|
||||||
|
|
||||||
|
while true do
|
||||||
|
redstone.setOutput("top", not redstone.getOutput("top"))
|
||||||
|
sleep(0.5)
|
||||||
|
end
|
||||||
|
@usage Mimic a redstone comparator in [subtraction mode][comparator].
|
||||||
|
|
||||||
|
while true do
|
||||||
|
local rear = rs.getAnalogueInput("back")
|
||||||
|
local sides = math.max(rs.getAnalogueInput("left"), rs.getAnalogueInput("right"))
|
||||||
|
rs.setAnalogueOutput("front", math.max(rear - sides, 0))
|
||||||
|
|
||||||
|
os.pullEvent("redstone") -- Wait for a change to inputs.
|
||||||
|
end
|
||||||
|
|
||||||
|
[comparator]: https://minecraft.gamepedia.com/Redstone_Comparator#Subtract_signal_strength "Redstone Comparator on the Minecraft wiki."
|
||||||
|
]]
|
||||||
|
|
||||||
|
--- Returns a table containing the six sides of the computer. Namely, "top",
|
||||||
|
-- "bottom", "left", "right", "front" and "back".
|
||||||
|
--
|
||||||
|
-- @treturn { string... } A table of valid sides.
|
||||||
|
function getSides() end
|
||||||
|
|
||||||
|
--- Turn the redstone signal of a specific side on or off.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to set.
|
||||||
|
-- @tparam boolean on Whether the redstone signal should be on or off. When on,
|
||||||
|
-- a signal strength of 15 is emitted.
|
||||||
|
function setOutput(side, on) end
|
||||||
|
|
||||||
|
--- Get the current redstone output of a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to get.
|
||||||
|
-- @treturn boolean Whether the redstone output is on or off.
|
||||||
|
-- @see setOutput
|
||||||
|
function getOutput(side) end
|
||||||
|
|
||||||
|
--- Get the current redstone input of a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to get.
|
||||||
|
-- @treturn boolean Whether the redstone input is on or off.
|
||||||
|
function getInput(side) end
|
||||||
|
|
||||||
|
--- Set the redstone signal strength for a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to set.
|
||||||
|
-- @tparam number value The signal strength, between 0 and 15.
|
||||||
|
-- @throws If `value` is not between 0 and 15.
|
||||||
|
function setAnalogOutput(side, value) end
|
||||||
|
setAnalogueOutput = setAnalogOutput
|
||||||
|
|
||||||
|
--- Get the redstone output signal strength for a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to get.
|
||||||
|
-- @treturn number The output signal strength, between 0 and 15.
|
||||||
|
-- @see setAnalogueOutput
|
||||||
|
function getAnalogOutput(sid) end
|
||||||
|
getAnalogueOutput = getAnalogOutput
|
||||||
|
|
||||||
|
--- Get the redstone input signal strength for a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to get.
|
||||||
|
-- @treturn number The input signal strength, between 0 and 15.
|
||||||
|
function getAnalogInput(side) end
|
||||||
|
getAnalogueInput = getAnalogInput
|
||||||
|
|
||||||
|
--- Set the bundled cable output for a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to set.
|
||||||
|
-- @tparam number The colour bitmask to set.
|
||||||
|
-- @see colors.subtract For removing a colour from the bitmask.
|
||||||
|
-- @see colors.combine For adding a colour to the bitmask.
|
||||||
|
function setBundledOutput(side, output) end
|
||||||
|
|
||||||
|
--- Get the bundled cable output for a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to get.
|
||||||
|
-- @treturn number The bundled cable's output.
|
||||||
|
function getBundledOutput(side) end
|
||||||
|
|
||||||
|
--- Get the bundled cable input for a specific side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to get.
|
||||||
|
-- @treturn number The bundled cable's input.
|
||||||
|
-- @see testBundledInput To determine if a specific colour is set.
|
||||||
|
function getBundledInput(side) end
|
||||||
|
|
||||||
|
--- Determine if a specific combination of colours are on for the given side.
|
||||||
|
--
|
||||||
|
-- @tparam string side The side to test.
|
||||||
|
-- @tparam number mask The mask to test.
|
||||||
|
-- @see getBundledInput
|
||||||
|
-- @see colors.combine For adding a colour to the bitmask.
|
||||||
|
-- @usage Check if @{colors.white} and @{colors.black} are on for above the
|
||||||
|
-- computer.
|
||||||
|
--
|
||||||
|
-- print(redstone.testBundledInput("top", colors.combine(colors.white, colors.black)))
|
||||||
|
function testBundledInput(side, mask) end
|
||||||
52
doc/stub/term.lua
Normal file
52
doc/stub/term.lua
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
function write(text) end
|
||||||
|
function scroll(lines) end
|
||||||
|
function setCursorPos(x, y) end
|
||||||
|
function setCursorBlink(blink) end
|
||||||
|
function getCursorPos() end
|
||||||
|
function getSize() end
|
||||||
|
function clear() end
|
||||||
|
function clearLine() end
|
||||||
|
function setTextColour(colour) end
|
||||||
|
setTextColor = setTextColour
|
||||||
|
function setBackgroundColour(colour) end
|
||||||
|
setBackgroundColor = setBackgroundColour
|
||||||
|
function isColour() end
|
||||||
|
isColor = isColour
|
||||||
|
function getTextColour() end
|
||||||
|
getTextColor = getTextColor
|
||||||
|
function getBackgroundColour() end
|
||||||
|
getBackgroundColor = getBackgroundColour
|
||||||
|
function blit(text, text_colours, background_colours) end
|
||||||
|
function setPaletteColour(colour, ...) end
|
||||||
|
setPaletteColor = setPaletteColour
|
||||||
|
function getPaletteColour(colour, ...) end
|
||||||
|
getPaletteColor = getPaletteColour
|
||||||
|
function nativePaletteColour(colour) end
|
||||||
|
nativePaletteColor = nativePaletteColour
|
||||||
|
|
||||||
|
--- @type Redirect
|
||||||
|
local Redirect = {}
|
||||||
|
|
||||||
|
Redirect.write = write
|
||||||
|
Redirect.scroll = scroll
|
||||||
|
Redirect.setCursorPos = setCursorPos
|
||||||
|
Redirect.setCursorBlink = setCursorBlink
|
||||||
|
Redirect.getCursorPos = getCursorPos
|
||||||
|
Redirect.getSize = getSize
|
||||||
|
Redirect.clear = clear
|
||||||
|
Redirect.clearLine = clearLine
|
||||||
|
Redirect.setTextColour = setTextColour
|
||||||
|
Redirect.setTextColor = setTextColor
|
||||||
|
Redirect.setBackgroundColour = setBackgroundColour
|
||||||
|
Redirect.setBackgroundColor = setBackgroundColor
|
||||||
|
Redirect.isColour = isColour
|
||||||
|
Redirect.isColor = isColor
|
||||||
|
Redirect.getTextColour = getTextColour
|
||||||
|
Redirect.getTextColor = getTextColor
|
||||||
|
Redirect.getBackgroundColour = getBackgroundColour
|
||||||
|
Redirect.getBackgroundColor = getBackgroundColor
|
||||||
|
Redirect.blit = blit
|
||||||
|
Redirect.setPaletteColour = setPaletteColour
|
||||||
|
Redirect.setPaletteColor = setPaletteColor
|
||||||
|
Redirect.getPaletteColour = getPaletteColour
|
||||||
|
Redirect.getPaletteColor = getPaletteColor
|
||||||
230
doc/stub/turtle.lua
Normal file
230
doc/stub/turtle.lua
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
--- Move the turtle forward one block.
|
||||||
|
-- @treturn boolean Whether the turtle could successfully move.
|
||||||
|
-- @treturn string|nil The reason the turtle could not move.
|
||||||
|
function forward() end
|
||||||
|
|
||||||
|
--- Move the turtle backwards one block.
|
||||||
|
-- @treturn boolean Whether the turtle could successfully move.
|
||||||
|
-- @treturn string|nil The reason the turtle could not move.
|
||||||
|
function back() end
|
||||||
|
|
||||||
|
--- Move the turtle up one block.
|
||||||
|
-- @treturn boolean Whether the turtle could successfully move.
|
||||||
|
-- @treturn string|nil The reason the turtle could not move.
|
||||||
|
function up() end
|
||||||
|
|
||||||
|
--- Move the turtle down one block.
|
||||||
|
-- @treturn boolean Whether the turtle could successfully move.
|
||||||
|
-- @treturn string|nil The reason the turtle could not move.
|
||||||
|
function down() end
|
||||||
|
|
||||||
|
--- Rotate the turtle 90 degress to the left.
|
||||||
|
function turnLeft() end
|
||||||
|
|
||||||
|
--- Rotate the turtle 90 degress to the right.
|
||||||
|
function turnRight() end
|
||||||
|
|
||||||
|
--- Attempt to break the block in front of the turtle.
|
||||||
|
--
|
||||||
|
-- This requires a turtle tool capable of breaking the block. Diamond pickaxes
|
||||||
|
-- (mining turtles) can break any vanilla block, but other tools (such as axes)
|
||||||
|
-- are more limited.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] "left"|"right" side The specific tool to use.
|
||||||
|
-- @treturn boolean Whether a block was broken.
|
||||||
|
-- @treturn string|nil The reason no block was broken.
|
||||||
|
function dig(side) end
|
||||||
|
|
||||||
|
--- Attempt to break the block above the turtle. See @{dig} for full details.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] "left"|"right" side The specific tool to use.
|
||||||
|
-- @treturn boolean Whether a block was broken.
|
||||||
|
-- @treturn string|nil The reason no block was broken.
|
||||||
|
function digUp(side) end
|
||||||
|
|
||||||
|
--- Attempt to break the block below the turtle. See @{dig} for full details.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] "left"|"right" side The specific tool to use.
|
||||||
|
-- @treturn boolean Whether a block was broken.
|
||||||
|
-- @treturn string|nil The reason no block was broken.
|
||||||
|
function digDown(side) end
|
||||||
|
|
||||||
|
--- Attack the entity in front of the turtle.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] "left"|"right" side The specific tool to use.
|
||||||
|
-- @treturn boolean Whether an entity was attacked.
|
||||||
|
-- @treturn string|nil The reason nothing was attacked.
|
||||||
|
function attack(side) end
|
||||||
|
|
||||||
|
--- Attack the entity above the turtle.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] "left"|"right" side The specific tool to use.
|
||||||
|
-- @treturn boolean Whether an entity was attacked.
|
||||||
|
-- @treturn string|nil The reason nothing was attacked.
|
||||||
|
function attackUp(side) end
|
||||||
|
|
||||||
|
--- Attack the entity below the turtle.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] "left"|"right" side The specific tool to use.
|
||||||
|
-- @treturn boolean Whether an entity was attacked.
|
||||||
|
-- @treturn string|nil The reason nothing was attacked.
|
||||||
|
function attackDown(side) end
|
||||||
|
|
||||||
|
--- Place a block or item into the world in front of the turtle.
|
||||||
|
--
|
||||||
|
-- @treturn boolean Whether the block could be placed.
|
||||||
|
-- @treturn string|nil The reason the block was not placed.
|
||||||
|
function place() end
|
||||||
|
|
||||||
|
--- Place a block or item into the world above the turtle.
|
||||||
|
--
|
||||||
|
-- @treturn boolean Whether the block could be placed.
|
||||||
|
-- @treturn string|nil The reason the block was not placed.
|
||||||
|
function placeUp() end
|
||||||
|
|
||||||
|
--- Place a block or item into the world below the turtle.
|
||||||
|
--
|
||||||
|
-- @treturn boolean Whether the block could be placed.
|
||||||
|
-- @treturn string|nil The reason the block was not placed.
|
||||||
|
function placeDown() end
|
||||||
|
|
||||||
|
--- Drop the currently selected stack into the inventory in front of the turtle,
|
||||||
|
-- or as an item into the world if there is no inventory.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number count The number of items to drop. If not given, the
|
||||||
|
-- entire stack will be dropped.
|
||||||
|
-- @treturn boolean Whether items were dropped.
|
||||||
|
-- @treturn string|nil The reason the no items were dropped.
|
||||||
|
-- @see select
|
||||||
|
function drop(count) end
|
||||||
|
|
||||||
|
--- Drop the currently selected stack into the inventory above the turtle, or as
|
||||||
|
-- an item into the world if there is no inventory.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number count The number of items to drop. If not given, the
|
||||||
|
-- entire stack will be dropped.
|
||||||
|
-- @treturn boolean Whether items were dropped.
|
||||||
|
-- @treturn string|nil The reason the no items were dropped.
|
||||||
|
-- @see select
|
||||||
|
function dropUp(count) end
|
||||||
|
|
||||||
|
--- Drop the currently selected stack into the inventory below the turtle, or as
|
||||||
|
-- an item into the world if there is no inventory.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number count The number of items to drop. If not given, the
|
||||||
|
-- entire stack will be dropped.
|
||||||
|
-- @treturn boolean Whether items were dropped.
|
||||||
|
-- @treturn string|nil The reason the no items were dropped.
|
||||||
|
-- @see select
|
||||||
|
function dropDown(count) end
|
||||||
|
|
||||||
|
--- Suck an item from the inventory in front of the turtle, or from an item
|
||||||
|
-- floating in the world.
|
||||||
|
--
|
||||||
|
-- This will pull items into the first acceptable slot, starting at the
|
||||||
|
-- @{select|currently selected} one.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number count The number of items to suck. If not given, up to a
|
||||||
|
-- stack of items will be picked up.
|
||||||
|
-- @treturn boolean Whether items were picked up.
|
||||||
|
-- @treturn string|nil The reason the no items were picked up.
|
||||||
|
function suck(count) end
|
||||||
|
|
||||||
|
--- Suck an item from the inventory above the turtle, or from an item floating
|
||||||
|
-- in the world.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number count The number of items to suck. If not given, up to a
|
||||||
|
-- stack of items will be picked up.
|
||||||
|
-- @treturn boolean Whether items were picked up.
|
||||||
|
-- @treturn string|nil The reason the no items were picked up.
|
||||||
|
function suckUp(count) end
|
||||||
|
|
||||||
|
--- Suck an item from the inventory below the turtle, or from an item floating
|
||||||
|
-- in the world.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number count The number of items to suck. If not given, up to a
|
||||||
|
-- stack of items will be picked up.
|
||||||
|
-- @treturn boolean Whether items were picked up.
|
||||||
|
-- @treturn string|nil The reason the no items were picked up.
|
||||||
|
function suckDown(count) end
|
||||||
|
|
||||||
|
--- Check if there is a solid block in front of the turtle. In this case, solid
|
||||||
|
-- refers to any non-air or liquid block.
|
||||||
|
--
|
||||||
|
-- @treturn boolean If there is a solid block in front.
|
||||||
|
function detect() end
|
||||||
|
|
||||||
|
--- Check if there is a solid block above the turtle.
|
||||||
|
--
|
||||||
|
-- @treturn boolean If there is a solid block above.
|
||||||
|
function detectUp() end
|
||||||
|
|
||||||
|
--- Check if there is a solid block below the turtle.
|
||||||
|
--
|
||||||
|
-- @treturn boolean If there is a solid block below.
|
||||||
|
function detectDown() end
|
||||||
|
|
||||||
|
function compare() end
|
||||||
|
function compareUp() end
|
||||||
|
function compareDown() end
|
||||||
|
|
||||||
|
function inspect() end
|
||||||
|
function inspectUp() end
|
||||||
|
function inspectDown() end
|
||||||
|
|
||||||
|
|
||||||
|
--- Change the currently selected slot.
|
||||||
|
--
|
||||||
|
-- The selected slot is determines what slot actions like @{drop} or
|
||||||
|
-- @{getItemCount} act on.
|
||||||
|
--
|
||||||
|
-- @tparam number slot The slot to select.
|
||||||
|
-- @see getSelectedSlot
|
||||||
|
function select(slot) end
|
||||||
|
|
||||||
|
--- Get the currently selected slot.
|
||||||
|
--
|
||||||
|
-- @treturn number The current slot.
|
||||||
|
-- @see select
|
||||||
|
function getSelectedSlot() end
|
||||||
|
|
||||||
|
--- Get the number of items in the given slot.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number slot The slot we wish to check. Defaults to the @{turtle.select|selected slot}.
|
||||||
|
-- @treturn number The number of items in this slot.
|
||||||
|
function getItemCount(slot) end
|
||||||
|
|
||||||
|
--- Get the remaining number of items which may be stored in this stack.
|
||||||
|
--
|
||||||
|
-- For instance, if a slot contains 13 blocks of dirt, it has room for another 51.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number slot The slot we wish to check. Defaults to the @{turtle.select|selected slot}.
|
||||||
|
-- @treturn number The space left in this slot.
|
||||||
|
function getItemSpace(slot) end
|
||||||
|
|
||||||
|
|
||||||
|
--- Get detailed information about the items in the given slot.
|
||||||
|
--
|
||||||
|
-- @tparam[opt] number slot The slot to get information about. Defaults to the @{turtle.select|selected slot}.
|
||||||
|
-- @treturn nil|table Information about the given slot, or @{nil} if it is empty.
|
||||||
|
-- @usage Print the current slot, assuming it contains 13 dirt.
|
||||||
|
--
|
||||||
|
-- print(textutils.serialize(turtle.getItemDetail()))
|
||||||
|
-- -- => {
|
||||||
|
-- -- name = "minecraft:dirt",
|
||||||
|
-- -- damage = 0,
|
||||||
|
-- -- count = 13,
|
||||||
|
-- -- }
|
||||||
|
function getItemDetail(slot) end
|
||||||
|
|
||||||
|
function getFuelLevel() end
|
||||||
|
|
||||||
|
function refuel(count) end
|
||||||
|
function compareTo(slot) end
|
||||||
|
function transferTo(slot, count) end
|
||||||
|
|
||||||
|
function getFuelLimit() end
|
||||||
|
function equipLeft() end
|
||||||
|
function equipRight() end
|
||||||
|
|
||||||
|
function craft(limit) end
|
||||||
186
doc/styles.css
Normal file
186
doc/styles.css
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
/* Basic reset on elements */
|
||||||
|
h1, h2, h3, h4, p, table, div, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
font-size: 100%;
|
||||||
|
font: inherit;
|
||||||
|
vertical-align: baseline;
|
||||||
|
}
|
||||||
|
/* Make the page a little more airy */
|
||||||
|
body {
|
||||||
|
margin: 20px auto;
|
||||||
|
max-width: 1200px;
|
||||||
|
padding: 0 10px;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: #222;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try to use system default fonts. */
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans",
|
||||||
|
"Droid Sans", "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
||||||
|
}
|
||||||
|
|
||||||
|
code, pre, .parameter, .type, .definition-name, .reference-code {
|
||||||
|
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Some definitions of basic tags */
|
||||||
|
code {
|
||||||
|
color: #c7254e;
|
||||||
|
background-color: #f9f2f4;
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
margin: 0.9em 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 1.5em;
|
||||||
|
font-weight: lighter;
|
||||||
|
border-bottom: solid 1px #aaa;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2, h3, h4 { margin: 1.4em 0 0.3em;}
|
||||||
|
h2 { font-size: 1.25em; }
|
||||||
|
h3 { font-size: 1.15em; font-weight: bold; }
|
||||||
|
h4 { font-size: 1.06em; }
|
||||||
|
|
||||||
|
a, a:visited, a:active { font-weight: bold; color: #004080; text-decoration: none; }
|
||||||
|
a:hover { text-decoration: underline; }
|
||||||
|
|
||||||
|
blockquote { margin-left: 3em; }
|
||||||
|
|
||||||
|
/* Stop sublists from having initial vertical space */
|
||||||
|
ul ul { margin-top: 0px; }
|
||||||
|
ol ul { margin-top: 0px; }
|
||||||
|
ol ol { margin-top: 0px; }
|
||||||
|
ul ol { margin-top: 0px; }
|
||||||
|
|
||||||
|
/* Make the target distinct; helps when we're navigating to a function */
|
||||||
|
a:target + * { background-color: #FFFF99; }
|
||||||
|
|
||||||
|
/* Allow linking to any subsection */
|
||||||
|
a[name]::before { content: "#"; }
|
||||||
|
|
||||||
|
/* Layout */
|
||||||
|
#main {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
min-height: calc(100vh - 100px);
|
||||||
|
}
|
||||||
|
|
||||||
|
#main > nav {
|
||||||
|
flex-basis: 30%;
|
||||||
|
min-width: 150px;
|
||||||
|
max-width: 250px;
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav h1, nav ul { padding: 0em 10px; }
|
||||||
|
|
||||||
|
nav h2 {
|
||||||
|
background-color:#e7e7e7;
|
||||||
|
font-size: 1.1em;
|
||||||
|
color:#000000;
|
||||||
|
padding: 5px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
nav ul {
|
||||||
|
list-style-type: none;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
flex-shrink: 1;
|
||||||
|
flex-basis: 80%;
|
||||||
|
padding: 0px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
text-align: right;
|
||||||
|
font-size: 0.8em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The definition lists at the top of each page */
|
||||||
|
table.definition-list {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.definition-list td, table.definition-list th {
|
||||||
|
border: 1px solid #cccccc;
|
||||||
|
padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.definition-list th {
|
||||||
|
background-color: #f0f0f0;
|
||||||
|
min-width: 200px;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.definition-list td { width: 100%; }
|
||||||
|
|
||||||
|
dl.definition dt {
|
||||||
|
border-top: 1px solid #ccc;
|
||||||
|
padding-top: 1em;
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl.definition dt .definition-name {
|
||||||
|
padding: 0 0.1em;
|
||||||
|
margin: 0 0.1em;
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
dl.definition dd {
|
||||||
|
padding-bottom: 1em;
|
||||||
|
margin: 10px 0 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
dl.definition h3 {
|
||||||
|
font-size: .95em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Links to source-code */
|
||||||
|
.source-link { font-size: 0.8em; }
|
||||||
|
.source-link::before { content: '[' }
|
||||||
|
.source-link::after { content: ']' }
|
||||||
|
a.source-link, a.source-link:visited, a.source-link:active { color: #505050; }
|
||||||
|
|
||||||
|
/* Method definitions */
|
||||||
|
span.parameter:after { content:":"; padding-left: 0.3em; }
|
||||||
|
.optional { text-decoration: underline dotted; }
|
||||||
|
|
||||||
|
/** Fancy colour display. */
|
||||||
|
.colour-ref {
|
||||||
|
display: inline-block;
|
||||||
|
width: 0.8em;
|
||||||
|
height: 0.8em;
|
||||||
|
margin: 0.1em 0.1em 0.3em 0.1em; /* Terrrible hack to force vertical alignment. */
|
||||||
|
border: solid 1px black;
|
||||||
|
box-sizing: border-box;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* styles for prettification of source */
|
||||||
|
.highlight .comment { color: #558817; }
|
||||||
|
.highlight .constant { color: #a8660d; }
|
||||||
|
.highlight .escape { color: #844631; }
|
||||||
|
.highlight .keyword { color: #aa5050; font-weight: bold; }
|
||||||
|
.highlight .library { color: #0e7c6b; }
|
||||||
|
.highlight .marker { color: #512b1e; background: #fedc56; font-weight: bold; }
|
||||||
|
.highlight .string { color: #8080ff; }
|
||||||
|
.highlight .literal-kw { color: #8080ff; }
|
||||||
|
.highlight .number { color: #f8660d; }
|
||||||
|
.highlight .operator { color: #2239a8; font-weight: bold; }
|
||||||
|
.highlight .preprocessor, pre .prepro { color: #a33243; }
|
||||||
|
.highlight .global { color: #800080; }
|
||||||
|
.highlight .user-keyword { color: #800080; }
|
||||||
|
.highlight .prompt { color: #558817; }
|
||||||
|
.highlight .url { color: #272fc2; text-decoration: underline; }
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
# Mod properties
|
# Mod properties
|
||||||
mod_version=1.86.2
|
mod_version=1.88.0
|
||||||
|
|
||||||
# Minecraft properties (update mods.toml when changing)
|
# Minecraft properties
|
||||||
mc_version=1.15.2
|
mc_version=1.12.2
|
||||||
forge_version=31.0.1
|
forge_version=14.23.4.2749
|
||||||
mappings_version=20200124-1.15.1
|
mappings_version=snapshot_20180724
|
||||||
|
|||||||
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
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
|
||||||
|
|||||||
@@ -1,28 +1,95 @@
|
|||||||
; -*- mode: Lisp;-*-
|
; -*- mode: Lisp;-*-
|
||||||
|
|
||||||
(sources
|
(sources
|
||||||
/src/main/resources/assets/computercraft/lua/bios.lua
|
/doc/stub/
|
||||||
/src/main/resources/assets/computercraft/lua/rom/
|
/src/main/resources/*/computercraft/lua/bios.lua
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/
|
||||||
/src/test/resources/test-rom)
|
/src/test/resources/test-rom)
|
||||||
|
|
||||||
|
|
||||||
|
(doc
|
||||||
|
(title "CC: Tweaked")
|
||||||
|
(index doc/index.md)
|
||||||
|
(source-link https://github.com/SquidDev-CC/CC-Tweaked/blob/${commit}/${path}#L${line})
|
||||||
|
|
||||||
|
(library-path
|
||||||
|
/doc/stub/
|
||||||
|
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/apis
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/apis/command
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/apis/turtle
|
||||||
|
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/modules/main
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/modules/command
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/modules/turtle))
|
||||||
|
|
||||||
(at /
|
(at /
|
||||||
(linters
|
(linters
|
||||||
|
syntax:string-index
|
||||||
|
|
||||||
;; It'd be nice to avoid this, but right now there's a lot of instances of
|
;; It'd be nice to avoid this, but right now there's a lot of instances of
|
||||||
;; it.
|
;; it.
|
||||||
-var:set-loop
|
-var:set-loop
|
||||||
|
|
||||||
;; It's useful to name arguments for documentation, so we allow this. It'd
|
;; It's useful to name arguments for documentation, so we allow this. It'd
|
||||||
;; be good to find a compromise in the future, but this works for now.
|
;; be good to find a compromise in the future, but this works for now.
|
||||||
-var:unused-arg))
|
-var:unused-arg)
|
||||||
|
|
||||||
|
(lint
|
||||||
|
(bracket-spaces
|
||||||
|
(call no-space)
|
||||||
|
(function-args no-space)
|
||||||
|
(parens no-space)
|
||||||
|
(table space)
|
||||||
|
(index no-space))
|
||||||
|
|
||||||
|
;; colours imports from colors, and we don't handle that right now.
|
||||||
|
;; keys is entirely dynamic, so we skip it.
|
||||||
|
(dynamic-modules colours keys)
|
||||||
|
|
||||||
|
(globals
|
||||||
|
:max
|
||||||
|
_CC_DEFAULT_SETTINGS
|
||||||
|
_CC_DISABLE_LUA51_FEATURES
|
||||||
|
;; Ideally we'd pick these up from bios.lua, but illuaminate currently
|
||||||
|
;; isn't smart enough.
|
||||||
|
sleep write printError read rs)))
|
||||||
|
|
||||||
;; We disable the unused global linter in bios.lua and the APIs. In the future
|
;; We disable the unused global linter in bios.lua and the APIs. In the future
|
||||||
;; hopefully we'll get illuaminate to handle this.
|
;; hopefully we'll get illuaminate to handle this.
|
||||||
(at
|
(at
|
||||||
(/src/main/resources/assets/computercraft/lua/bios.lua
|
(/src/main/resources/*/computercraft/lua/bios.lua
|
||||||
/src/main/resources/assets/computercraft/lua/rom/apis/)
|
/src/main/resources/*/computercraft/lua/rom/apis/)
|
||||||
(linters -var:unused-global)
|
(linters -var:unused-global)
|
||||||
(lint
|
(lint (allow-toplevel-global true)))
|
||||||
(allow-toplevel-global true)))
|
|
||||||
|
|
||||||
;; These warnings are broken right now
|
;; Silence some variable warnings in documentation stubs.
|
||||||
(at (bios.lua worm.lua) (linters -control:unreachable))
|
(at /doc/stub
|
||||||
|
(linters -var:unused-global)
|
||||||
|
(lint (allow-toplevel-global true)))
|
||||||
|
|
||||||
|
;; Suppress warnings for currently undocumented modules.
|
||||||
|
(at
|
||||||
|
(/doc/stub/fs.lua
|
||||||
|
/doc/stub/http.lua
|
||||||
|
/doc/stub/os.lua
|
||||||
|
/doc/stub/term.lua
|
||||||
|
/doc/stub/turtle.lua
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/apis/io.lua
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/apis/window.lua)
|
||||||
|
|
||||||
|
(linters -doc:undocumented -doc:undocumented-arg))
|
||||||
|
|
||||||
|
;; These currently rely on unknown references.
|
||||||
|
(at
|
||||||
|
(/src/main/resources/*/computercraft/lua/rom/apis/textutils.lua
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/modules/main/cc/completion.lua
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/modules/main/cc/shell/completion.lua
|
||||||
|
/src/main/resources/*/computercraft/lua/rom/programs/shell.lua)
|
||||||
|
(linters -doc:unresolved-reference))
|
||||||
|
|
||||||
|
(at /src/test/resources/test-rom
|
||||||
|
(lint
|
||||||
|
(globals
|
||||||
|
:max sleep write
|
||||||
|
cct_test describe expect howlci fail it pending stub)))
|
||||||
|
|||||||
29
src/main/java/dan200/computercraft/CCTweaked.java
Normal file
29
src/main/java/dan200/computercraft/CCTweaked.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.network.NetworkCheckHandler;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A stub mod for CC: Tweaked. This doesn't have any functionality (everything of note is done in
|
||||||
|
* {@link ComputerCraft}), but people may depend on this if they require CC: Tweaked functionality.
|
||||||
|
*/
|
||||||
|
@Mod(
|
||||||
|
modid = "cctweaked", name = ComputerCraft.NAME, version = ComputerCraft.VERSION,
|
||||||
|
acceptableRemoteVersions = "*"
|
||||||
|
)
|
||||||
|
public class CCTweaked
|
||||||
|
{
|
||||||
|
@NetworkCheckHandler
|
||||||
|
public boolean onNetworkConnect( Map<String, String> mods, Side side )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,49 +5,96 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft;
|
package dan200.computercraft;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
|
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
||||||
|
import dan200.computercraft.api.media.IMedia;
|
||||||
|
import dan200.computercraft.api.media.IMediaProvider;
|
||||||
|
import dan200.computercraft.api.network.IPacketNetwork;
|
||||||
|
import dan200.computercraft.api.network.wired.IWiredElement;
|
||||||
|
import dan200.computercraft.api.network.wired.IWiredNode;
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||||
|
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
|
||||||
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
|
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||||
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
import dan200.computercraft.api.turtle.event.TurtleAction;
|
||||||
import dan200.computercraft.core.apis.AddressPredicate;
|
import dan200.computercraft.core.apis.AddressPredicate;
|
||||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
import dan200.computercraft.core.apis.ApiFactories;
|
||||||
import dan200.computercraft.shared.Config;
|
import dan200.computercraft.core.computer.MainThread;
|
||||||
|
import dan200.computercraft.core.filesystem.ComboMount;
|
||||||
|
import dan200.computercraft.core.filesystem.FileMount;
|
||||||
|
import dan200.computercraft.core.filesystem.JarMount;
|
||||||
|
import dan200.computercraft.core.tracking.Tracking;
|
||||||
|
import dan200.computercraft.shared.*;
|
||||||
|
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
|
||||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
|
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
|
||||||
|
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
|
||||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
import dan200.computercraft.shared.media.items.ItemDiskExpanded;
|
||||||
|
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
||||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||||
import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
|
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
|
||||||
|
import dan200.computercraft.shared.peripheral.common.ItemPeripheral;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.ItemBlockCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.ItemCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
|
import dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
|
import dan200.computercraft.shared.peripheral.modem.wireless.ItemAdvancedModem;
|
||||||
import dan200.computercraft.shared.peripheral.printer.BlockPrinter;
|
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
||||||
import dan200.computercraft.shared.peripheral.speaker.BlockSpeaker;
|
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
import dan200.computercraft.shared.pocket.peripherals.PocketModem;
|
||||||
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
import dan200.computercraft.shared.pocket.peripherals.PocketSpeaker;
|
||||||
|
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
||||||
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtle;
|
import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced;
|
||||||
|
import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy;
|
||||||
|
import dan200.computercraft.shared.turtle.items.ItemTurtleNormal;
|
||||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||||
import net.minecraft.resources.IReloadableResourceManager;
|
import dan200.computercraft.shared.util.CreativeTabMain;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import dan200.computercraft.shared.util.IDAssigner;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import dan200.computercraft.shared.util.IoUtil;
|
||||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
import dan200.computercraft.shared.wired.CapabilityWiredElement;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import dan200.computercraft.shared.wired.WiredNode;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemBlock;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.IBlockAccess;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.DimensionManager;
|
||||||
|
import net.minecraftforge.fml.common.*;
|
||||||
|
import net.minecraftforge.fml.common.event.*;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.io.InputStream;
|
import java.net.MalformedURLException;
|
||||||
import java.util.EnumSet;
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
@Mod( ComputerCraft.MOD_ID )
|
@Mod(
|
||||||
public final class ComputerCraft
|
modid = ComputerCraft.MOD_ID, name = ComputerCraft.NAME, version = ComputerCraft.VERSION,
|
||||||
|
guiFactory = "dan200.computercraft.client.gui.GuiConfigCC$Factory",
|
||||||
|
dependencies = "required:forge@[14.23.4.2746,)"
|
||||||
|
)
|
||||||
|
public class ComputerCraft
|
||||||
{
|
{
|
||||||
public static final String MOD_ID = "computercraft";
|
public static final String MOD_ID = "computercraft";
|
||||||
|
static final String VERSION = "${version}";
|
||||||
public static final int DATAFIXER_VERSION = 0;
|
static final String NAME = "CC: Tweaked";
|
||||||
|
|
||||||
// Configuration options
|
// Configuration options
|
||||||
public static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" };
|
public static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" };
|
||||||
@@ -65,7 +112,8 @@ public final class ComputerCraft
|
|||||||
public static boolean disable_lua51_features = false;
|
public static boolean disable_lua51_features = false;
|
||||||
public static String default_computer_settings = "";
|
public static String default_computer_settings = "";
|
||||||
public static boolean debug_enable = true;
|
public static boolean debug_enable = true;
|
||||||
public static boolean logPeripheralErrors = false;
|
public static boolean logPeripheralErrors = true;
|
||||||
|
public static boolean commandRequireCreative = true;
|
||||||
|
|
||||||
public static int computer_threads = 1;
|
public static int computer_threads = 1;
|
||||||
public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );
|
public static long maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( 10 );
|
||||||
@@ -81,7 +129,7 @@ public final class ComputerCraft
|
|||||||
public static long httpMaxDownload = 16 * 1024 * 1024;
|
public static long httpMaxDownload = 16 * 1024 * 1024;
|
||||||
public static long httpMaxUpload = 4 * 1024 * 1024;
|
public static long httpMaxUpload = 4 * 1024 * 1024;
|
||||||
public static int httpMaxWebsockets = 4;
|
public static int httpMaxWebsockets = 4;
|
||||||
public static int httpMaxWebsocketMessage = Websocket.MAX_MESSAGE_SIZE;
|
public static int httpMaxWebsocketMessage = 128 * 1024;
|
||||||
|
|
||||||
public static boolean enableCommandBlock = false;
|
public static boolean enableCommandBlock = false;
|
||||||
public static int modem_range = 64;
|
public static int modem_range = 64;
|
||||||
@@ -89,6 +137,7 @@ public final class ComputerCraft
|
|||||||
public static int modem_rangeDuringStorm = 64;
|
public static int modem_rangeDuringStorm = 64;
|
||||||
public static int modem_highAltitudeRangeDuringStorm = 384;
|
public static int modem_highAltitudeRangeDuringStorm = 384;
|
||||||
public static int maxNotesPerTick = 8;
|
public static int maxNotesPerTick = 8;
|
||||||
|
public static MonitorRenderer monitorRenderer = MonitorRenderer.BEST;
|
||||||
|
|
||||||
public static boolean turtlesNeedFuel = true;
|
public static boolean turtlesNeedFuel = true;
|
||||||
public static int turtleFuelLimit = 20000;
|
public static int turtleFuelLimit = 20000;
|
||||||
@@ -109,54 +158,46 @@ public final class ComputerCraft
|
|||||||
// Blocks and Items
|
// Blocks and Items
|
||||||
public static final class Blocks
|
public static final class Blocks
|
||||||
{
|
{
|
||||||
public static BlockComputer computerNormal;
|
public static BlockComputer computer;
|
||||||
public static BlockComputer computerAdvanced;
|
public static BlockCommandComputer commandComputer;
|
||||||
public static BlockComputer computerCommand;
|
|
||||||
|
|
||||||
public static BlockTurtle turtleNormal;
|
public static BlockTurtle turtle;
|
||||||
|
public static BlockTurtle turtleExpanded;
|
||||||
public static BlockTurtle turtleAdvanced;
|
public static BlockTurtle turtleAdvanced;
|
||||||
|
|
||||||
public static BlockSpeaker speaker;
|
public static BlockPeripheral peripheral;
|
||||||
public static BlockDiskDrive diskDrive;
|
|
||||||
public static BlockPrinter printer;
|
|
||||||
|
|
||||||
public static BlockMonitor monitorNormal;
|
|
||||||
public static BlockMonitor monitorAdvanced;
|
|
||||||
|
|
||||||
public static BlockWirelessModem wirelessModemNormal;
|
|
||||||
public static BlockWirelessModem wirelessModemAdvanced;
|
|
||||||
|
|
||||||
public static BlockWiredModemFull wiredModemFull;
|
|
||||||
public static BlockCable cable;
|
public static BlockCable cable;
|
||||||
|
public static BlockAdvancedModem advancedModem;
|
||||||
|
public static BlockWiredModemFull wiredModemFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Items
|
public static final class Items
|
||||||
{
|
{
|
||||||
public static ItemComputer computerNormal;
|
public static ItemComputer computer;
|
||||||
public static ItemComputer computerAdvanced;
|
public static ItemCommandComputer commandComputer;
|
||||||
public static ItemComputer computerCommand;
|
|
||||||
|
|
||||||
public static ItemPocketComputer pocketComputerNormal;
|
public static ItemTurtleLegacy turtle;
|
||||||
public static ItemPocketComputer pocketComputerAdvanced;
|
public static ItemTurtleNormal turtleExpanded;
|
||||||
|
public static ItemTurtleAdvanced turtleAdvanced;
|
||||||
|
|
||||||
public static ItemTurtle turtleNormal;
|
public static ItemPocketComputer pocketComputer;
|
||||||
public static ItemTurtle turtleAdvanced;
|
|
||||||
|
|
||||||
public static ItemDisk disk;
|
public static ItemDiskLegacy disk;
|
||||||
|
public static ItemDiskExpanded diskExpanded;
|
||||||
public static ItemTreasureDisk treasureDisk;
|
public static ItemTreasureDisk treasureDisk;
|
||||||
|
|
||||||
public static ItemPrintout printedPage;
|
public static ItemPrintout printout;
|
||||||
public static ItemPrintout printedPages;
|
|
||||||
public static ItemPrintout printedBook;
|
|
||||||
|
|
||||||
public static ItemBlockCable.Cable cable;
|
public static ItemPeripheral peripheral;
|
||||||
public static ItemBlockCable.WiredModem wiredModem;
|
public static ItemAdvancedModem advancedModem;
|
||||||
|
public static ItemCable cable;
|
||||||
|
public static ItemBlock wiredModemFull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class TurtleUpgrades
|
public static final class TurtleUpgrades
|
||||||
{
|
{
|
||||||
public static TurtleModem wirelessModemNormal;
|
public static TurtleModem wirelessModem;
|
||||||
public static TurtleModem wirelessModemAdvanced;
|
public static TurtleModem advancedModem;
|
||||||
public static TurtleSpeaker speaker;
|
public static TurtleSpeaker speaker;
|
||||||
|
|
||||||
public static TurtleCraftingTable craftingTable;
|
public static TurtleCraftingTable craftingTable;
|
||||||
@@ -169,38 +210,457 @@ public final class ComputerCraft
|
|||||||
|
|
||||||
public static final class PocketUpgrades
|
public static final class PocketUpgrades
|
||||||
{
|
{
|
||||||
public static PocketModem wirelessModemNormal;
|
public static PocketModem wirelessModem;
|
||||||
public static PocketModem wirelessModemAdvanced;
|
public static PocketModem advancedModem;
|
||||||
public static PocketSpeaker speaker;
|
public static PocketSpeaker speaker;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static PocketSpeaker pocketSpeaker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static final class Upgrades
|
||||||
|
{
|
||||||
|
public static TurtleModem advancedModem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registries
|
// Registries
|
||||||
public static final ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
|
public static final ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
|
||||||
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
|
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
|
||||||
|
|
||||||
// Logging
|
// Creative
|
||||||
public static final Logger log = LogManager.getLogger( MOD_ID );
|
public static CreativeTabMain mainCreativeTab;
|
||||||
|
|
||||||
public ComputerCraft()
|
// Logging
|
||||||
|
public static Logger log;
|
||||||
|
|
||||||
|
// Peripheral providers. This is still here to ensure compatibility with Plethora and Computronics
|
||||||
|
public static List<IPeripheralProvider> peripheralProviders = new ArrayList<>();
|
||||||
|
|
||||||
|
// Implementation
|
||||||
|
@Mod.Instance( ComputerCraft.MOD_ID )
|
||||||
|
public static ComputerCraft instance;
|
||||||
|
|
||||||
|
@SidedProxy(
|
||||||
|
clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient",
|
||||||
|
serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon"
|
||||||
|
)
|
||||||
|
private static ComputerCraftProxyCommon proxy;
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void preInit( FMLPreInitializationEvent event )
|
||||||
{
|
{
|
||||||
Config.load();
|
log = event.getModLog();
|
||||||
|
|
||||||
|
// Load config
|
||||||
|
Config.load( event.getSuggestedConfigurationFile() );
|
||||||
|
|
||||||
|
proxy.preInit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void init( FMLInitializationEvent event )
|
||||||
|
{
|
||||||
|
proxy.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onServerStarting( FMLServerStartingEvent event )
|
||||||
|
{
|
||||||
|
ComputerCraftProxyCommon.initServer( event.getServer() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onServerStart( FMLServerStartedEvent event )
|
||||||
|
{
|
||||||
|
if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
|
||||||
|
{
|
||||||
|
ComputerCraft.serverComputerRegistry.reset();
|
||||||
|
WirelessNetwork.resetNetworks();
|
||||||
|
MainThread.reset();
|
||||||
|
Tracking.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Mod.EventHandler
|
||||||
|
public void onServerStopped( FMLServerStoppedEvent event )
|
||||||
|
{
|
||||||
|
if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
|
||||||
|
{
|
||||||
|
ComputerCraft.serverComputerRegistry.reset();
|
||||||
|
WirelessNetwork.resetNetworks();
|
||||||
|
MainThread.reset();
|
||||||
|
Tracking.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersion()
|
public static String getVersion()
|
||||||
{
|
{
|
||||||
return "${version}";
|
return VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream getResourceFile( String domain, String subPath )
|
private static File getBaseDir()
|
||||||
|
{
|
||||||
|
return FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File getResourcePackDir()
|
||||||
|
{
|
||||||
|
return new File( getBaseDir(), "resourcepacks" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void registerPermissionProvider( ITurtlePermissionProvider provider )
|
||||||
|
{
|
||||||
|
TurtlePermissions.register( provider );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void registerPocketUpgrade( IPocketUpgrade upgrade )
|
||||||
|
{
|
||||||
|
dan200.computercraft.shared.PocketUpgrades.register( upgrade );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void registerPeripheralProvider( IPeripheralProvider provider )
|
||||||
|
{
|
||||||
|
Peripherals.register( provider );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void registerBundledRedstoneProvider( IBundledRedstoneProvider provider )
|
||||||
|
{
|
||||||
|
BundledRedstone.register( provider );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void registerMediaProvider( IMediaProvider provider )
|
||||||
|
{
|
||||||
|
MediaProviders.register( provider );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void registerAPIFactory( ILuaAPIFactory factory )
|
||||||
|
{
|
||||||
|
ApiFactories.register( factory );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IWiredNode createWiredNodeForElement( IWiredElement element )
|
||||||
|
{
|
||||||
|
return new WiredNode( element );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IWiredElement getWiredElementAt( IBlockAccess world, BlockPos pos, EnumFacing side )
|
||||||
|
{
|
||||||
|
TileEntity tile = world.getTileEntity( pos );
|
||||||
|
return tile != null && tile.hasCapability( CapabilityWiredElement.CAPABILITY, side )
|
||||||
|
? tile.getCapability( CapabilityWiredElement.CAPABILITY, side )
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
|
||||||
|
{
|
||||||
|
return BundledRedstone.getDefaultOutput( world, pos, side );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IPacketNetwork getWirelessNetwork()
|
||||||
|
{
|
||||||
|
return WirelessNetwork.getUniversal();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
|
||||||
|
{
|
||||||
|
return IDAssigner.getNextIDFromDirectory( parentSubPath );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
|
||||||
{
|
{
|
||||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
|
return new FileMount( new File( getWorldDir(), subPath ), capacity );
|
||||||
}
|
}
|
||||||
catch( IOException ignored )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void loadFromFile( List<IMount> mounts, File file, String path, boolean allowMissing )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if( file.isFile() )
|
||||||
|
{
|
||||||
|
mounts.add( new JarMount( file, path ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
File subResource = new File( file, path );
|
||||||
|
if( subResource.exists() ) mounts.add( new FileMount( subResource, 0 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( IOException | RuntimeException e )
|
||||||
|
{
|
||||||
|
if( allowMissing && e instanceof FileNotFoundException ) return;
|
||||||
|
ComputerCraft.log.error( "Could not load mount '" + path + " 'from '" + file.getName() + "'", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IMount createResourceMount( Class<?> modClass, String domain, String subPath )
|
||||||
|
{
|
||||||
|
// Start building list of mounts
|
||||||
|
List<IMount> mounts = new ArrayList<>();
|
||||||
|
subPath = "assets/" + domain + "/" + subPath;
|
||||||
|
|
||||||
|
// Mount from debug dir
|
||||||
|
File codeDir = getDebugCodeDir( modClass );
|
||||||
|
if( codeDir != null )
|
||||||
|
{
|
||||||
|
File subResource = new File( codeDir, subPath );
|
||||||
|
if( subResource.exists() )
|
||||||
|
{
|
||||||
|
IMount resourcePackMount = new FileMount( subResource, 0 );
|
||||||
|
mounts.add( resourcePackMount );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mount from mod jars, preferring the specified one.
|
||||||
|
File modJar = getContainingJar( modClass );
|
||||||
|
Set<File> otherMods = new HashSet<>();
|
||||||
|
for( ModContainer container : Loader.instance().getActiveModList() )
|
||||||
|
{
|
||||||
|
File modFile = container.getSource();
|
||||||
|
if( modFile != null && !modFile.equals( modJar ) && modFile.exists() )
|
||||||
|
{
|
||||||
|
otherMods.add( container.getSource() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( File file : otherMods )
|
||||||
|
{
|
||||||
|
loadFromFile( mounts, file, subPath, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( modJar != null )
|
||||||
|
{
|
||||||
|
loadFromFile( mounts, modJar, subPath, false );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mount from resource packs
|
||||||
|
File resourcePackDir = getResourcePackDir();
|
||||||
|
if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
|
||||||
|
{
|
||||||
|
String[] resourcePacks = resourcePackDir.list();
|
||||||
|
for( String resourcePackName : resourcePacks )
|
||||||
|
{
|
||||||
|
File resourcePack = new File( resourcePackDir, resourcePackName );
|
||||||
|
loadFromFile( mounts, resourcePack, subPath, true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the combination of all the mounts found
|
||||||
|
if( mounts.size() >= 2 )
|
||||||
|
{
|
||||||
|
IMount[] mountArray = new IMount[mounts.size()];
|
||||||
|
mounts.toArray( mountArray );
|
||||||
|
return new ComboMount( mountArray );
|
||||||
|
}
|
||||||
|
else if( mounts.size() == 1 )
|
||||||
|
{
|
||||||
|
return mounts.get( 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputStream getResourceFile( Class<?> modClass, String domain, String subPath )
|
||||||
|
{
|
||||||
|
// Start searching in possible locations
|
||||||
|
subPath = "assets/" + domain + "/" + subPath;
|
||||||
|
|
||||||
|
// Look in resource packs
|
||||||
|
File resourcePackDir = getResourcePackDir();
|
||||||
|
if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
|
||||||
|
{
|
||||||
|
String[] resourcePacks = resourcePackDir.list();
|
||||||
|
for( String resourcePackPath : resourcePacks )
|
||||||
|
{
|
||||||
|
File resourcePack = new File( resourcePackDir, resourcePackPath );
|
||||||
|
if( resourcePack.isDirectory() )
|
||||||
|
{
|
||||||
|
// Mount a resource pack from a folder
|
||||||
|
File subResource = new File( resourcePack, subPath );
|
||||||
|
if( subResource.exists() && subResource.isFile() )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new FileInputStream( subResource );
|
||||||
|
}
|
||||||
|
catch( FileNotFoundException ignored )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ZipFile zipFile = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final ZipFile zip = zipFile = new ZipFile( resourcePack );
|
||||||
|
ZipEntry entry = zipFile.getEntry( subPath );
|
||||||
|
if( entry != null )
|
||||||
|
{
|
||||||
|
// Return a custom InputStream which will close the original zip when finished.
|
||||||
|
return new FilterInputStream( zipFile.getInputStream( entry ) )
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException
|
||||||
|
{
|
||||||
|
super.close();
|
||||||
|
zip.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IoUtil.closeQuietly( zipFile );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( IOException e )
|
||||||
|
{
|
||||||
|
if( zipFile != null ) IoUtil.closeQuietly( zipFile );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look in debug dir
|
||||||
|
File codeDir = getDebugCodeDir( modClass );
|
||||||
|
if( codeDir != null )
|
||||||
|
{
|
||||||
|
File subResource = new File( codeDir, subPath );
|
||||||
|
if( subResource.exists() && subResource.isFile() )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new FileInputStream( subResource );
|
||||||
|
}
|
||||||
|
catch( FileNotFoundException ignored )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look in class loader
|
||||||
|
return modClass.getClassLoader().getResourceAsStream( subPath );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File getContainingJar( Class<?> modClass )
|
||||||
|
{
|
||||||
|
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
|
int bangIndex = path.indexOf( '!' );
|
||||||
|
if( bangIndex >= 0 )
|
||||||
|
{
|
||||||
|
path = path.substring( 0, bangIndex );
|
||||||
|
}
|
||||||
|
|
||||||
|
URL url;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
url = new URL( path );
|
||||||
|
}
|
||||||
|
catch( MalformedURLException e1 )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
file = new File( url.toURI() );
|
||||||
|
}
|
||||||
|
catch( URISyntaxException e )
|
||||||
|
{
|
||||||
|
file = new File( url.getPath() );
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static File getDebugCodeDir( Class<?> modClass )
|
||||||
|
{
|
||||||
|
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
|
||||||
|
int bangIndex = path.indexOf( '!' );
|
||||||
|
return bangIndex >= 0 ? null : new File( new File( path ).getParentFile(), "../.." );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static void registerTurtleUpgrade( ITurtleUpgrade upgrade )
|
||||||
|
{
|
||||||
|
dan200.computercraft.shared.TurtleUpgrades.register( upgrade );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static File getWorldDir()
|
||||||
|
{
|
||||||
|
return DimensionManager.getCurrentSaveRootDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
//region Compatibility
|
||||||
|
@Deprecated
|
||||||
|
public static File getWorldDir( World world )
|
||||||
|
{
|
||||||
|
return DimensionManager.getCurrentSaveRootDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IMedia getMedia( ItemStack stack )
|
||||||
|
{
|
||||||
|
return MediaProviders.get( stack );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IPocketUpgrade getPocketUpgrade( ItemStack stack )
|
||||||
|
{
|
||||||
|
return dan200.computercraft.shared.PocketUpgrades.get( stack );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static ITurtleUpgrade getTurtleUpgrade( ItemStack stack )
|
||||||
|
{
|
||||||
|
return dan200.computercraft.shared.TurtleUpgrades.get( stack );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IPocketUpgrade getPocketUpgrade( String id )
|
||||||
|
{
|
||||||
|
return dan200.computercraft.shared.PocketUpgrades.get( id );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static ITurtleUpgrade getTurtleUpgrade( String id )
|
||||||
|
{
|
||||||
|
return dan200.computercraft.shared.TurtleUpgrades.get( id );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static IPeripheral getPeripheralAt( World world, BlockPos pos, EnumFacing side )
|
||||||
|
{
|
||||||
|
return Peripherals.getPeripheral( world, pos, side );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static boolean canPlayerUseCommands( EntityPlayer player )
|
||||||
|
{
|
||||||
|
MinecraftServer server = player.getServer();
|
||||||
|
return server != null && server.getPlayerList().canSendCommands( player.getGameProfile() );
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,152 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
package dan200.computercraft;
|
|
||||||
|
|
||||||
import com.google.common.collect.MapMaker;
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI.IComputerCraftAPI;
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
|
||||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
|
||||||
import dan200.computercraft.api.media.IMediaProvider;
|
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
|
||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|
||||||
import dan200.computercraft.core.apis.ApiFactories;
|
|
||||||
import dan200.computercraft.core.filesystem.FileMount;
|
|
||||||
import dan200.computercraft.core.filesystem.ResourceMount;
|
|
||||||
import dan200.computercraft.shared.*;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
|
||||||
import dan200.computercraft.shared.util.IDAssigner;
|
|
||||||
import dan200.computercraft.shared.wired.CapabilityWiredElement;
|
|
||||||
import dan200.computercraft.shared.wired.WiredNode;
|
|
||||||
import net.minecraft.resources.IReloadableResourceManager;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
|
||||||
{
|
|
||||||
public static final ComputerCraftAPIImpl INSTANCE = new ComputerCraftAPIImpl();
|
|
||||||
|
|
||||||
private ComputerCraftAPIImpl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private WeakReference<IReloadableResourceManager> currentResources;
|
|
||||||
private final Map<ResourceLocation, ResourceMount> mountCache = new MapMaker().weakValues().concurrencyLevel( 1 ).makeMap();
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public String getInstalledVersion()
|
|
||||||
{
|
|
||||||
return "${version}";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
|
||||||
{
|
|
||||||
return IDAssigner.getNextId( parentSubPath );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new FileMount( new File( IDAssigner.getDir(), subPath ), capacity );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
|
|
||||||
{
|
|
||||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
|
|
||||||
ResourceMount mount = ResourceMount.get( domain, subPath, manager );
|
|
||||||
return mount.exists( "" ) ? mount : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
|
|
||||||
{
|
|
||||||
Peripherals.register( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
|
|
||||||
{
|
|
||||||
TurtleUpgrades.register( upgrade );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
|
|
||||||
{
|
|
||||||
BundledRedstone.register( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
|
||||||
{
|
|
||||||
return BundledRedstone.getDefaultOutput( world, pos, side );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerMediaProvider( @Nonnull IMediaProvider provider )
|
|
||||||
{
|
|
||||||
MediaProviders.register( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
|
|
||||||
{
|
|
||||||
PocketUpgrades.register( upgrade );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public IPacketNetwork getWirelessNetwork()
|
|
||||||
{
|
|
||||||
return WirelessNetwork.getUniversal();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
|
|
||||||
{
|
|
||||||
ApiFactories.register( factory );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
|
|
||||||
{
|
|
||||||
return new WiredNode( element );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
|
||||||
{
|
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
|
||||||
return tile == null ? LazyOptional.empty() : tile.getCapability( CapabilityWiredElement.CAPABILITY, side );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,10 +7,10 @@ package dan200.computercraft.api;
|
|||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
import dan200.computercraft.api.turtle.TurtleUpgradeType;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.IItemProvider;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.Util;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -22,31 +22,43 @@ import javax.annotation.Nonnull;
|
|||||||
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||||
{
|
{
|
||||||
private final ResourceLocation id;
|
private final ResourceLocation id;
|
||||||
|
private final int legacyId;
|
||||||
private final TurtleUpgradeType type;
|
private final TurtleUpgradeType type;
|
||||||
private final String adjective;
|
private final String adjective;
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.legacyId = legacyId;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.adjective = adjective;
|
this.adjective = adjective;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, IItemProvider item )
|
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Item item )
|
||||||
{
|
{
|
||||||
this( id, type, adjective, new ItemStack( item ) );
|
this( id, legacyId, type, adjective, new ItemStack( item ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, ItemStack stack )
|
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Block block )
|
||||||
{
|
{
|
||||||
this( id, type, Util.makeTranslationKey( "upgrade", id ) + ".adjective", stack );
|
this( id, legacyId, type, adjective, new ItemStack( block ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, IItemProvider item )
|
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, ItemStack stack )
|
||||||
{
|
{
|
||||||
this( id, type, new ItemStack( item ) );
|
this( id, legacyId, type, "upgrade." + id + ".adjective", stack );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Item item )
|
||||||
|
{
|
||||||
|
this( id, legacyId, type, new ItemStack( item ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Block block )
|
||||||
|
{
|
||||||
|
this( id, legacyId, type, new ItemStack( block ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -56,6 +68,12 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final int getLegacyUpgradeID()
|
||||||
|
{
|
||||||
|
return legacyId;
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public final String getUnlocalisedAdjective()
|
public final String getUnlocalisedAdjective()
|
||||||
|
|||||||
@@ -16,17 +16,18 @@ import dan200.computercraft.api.network.wired.IWiredNode;
|
|||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||||
|
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
|
||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockAccess;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The static entry point to the ComputerCraft API.
|
* The static entry point to the ComputerCraft API.
|
||||||
@@ -36,10 +37,28 @@ import javax.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
public final class ComputerCraftAPI
|
public final class ComputerCraftAPI
|
||||||
{
|
{
|
||||||
|
public static boolean isInstalled()
|
||||||
|
{
|
||||||
|
findCC();
|
||||||
|
return computerCraft != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String getInstalledVersion()
|
public static String getInstalledVersion()
|
||||||
{
|
{
|
||||||
return getInstance().getInstalledVersion();
|
findCC();
|
||||||
|
if( computerCraft_getVersion != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (String) computerCraft_getVersion.invoke( null );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -63,7 +82,19 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||||
{
|
{
|
||||||
return getInstance().createUniqueNumberedSaveDir( world, parentSubPath );
|
findCC();
|
||||||
|
if( computerCraft_createUniqueNumberedSaveDir != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (Integer) computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,54 +118,55 @@ public final class ComputerCraftAPI
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
||||||
{
|
{
|
||||||
return getInstance().createSaveDirMount( world, subPath, capacity );
|
findCC();
|
||||||
|
if( computerCraft_createSaveDirMount != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (IWritableMount) computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a file system mount to a resource folder, and returns it.
|
* Creates a file system mount to a resource folder, and returns it.
|
||||||
*
|
*
|
||||||
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
|
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder
|
||||||
* resource folder onto a computer's file system.
|
* onto a computer's file system.
|
||||||
*
|
*
|
||||||
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
|
* The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain
|
||||||
* resources with the same domain and path.
|
* resources with the same domain and path.
|
||||||
*
|
*
|
||||||
* @param domain The domain under which to look for resources. eg: "mymod".
|
* @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class
|
||||||
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
* @param domain The domain under which to look for resources. eg: "mymod".
|
||||||
* @return The mount, or {@code null} if it could be created for some reason.
|
* @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles".
|
||||||
|
* @return The mount, or {@code null} if it could be created for some reason. Use IComputerAccess.mount() or
|
||||||
|
* IComputerAccess.mountWritable() to mount this on a Computers' file system.
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
* @see IComputerAccess#mount(String, IMount)
|
||||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||||
* @see IMount
|
* @see IMount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
|
public static IMount createResourceMount( @Nonnull Class<?> modClass, @Nonnull String domain, @Nonnull String subPath )
|
||||||
{
|
{
|
||||||
return getInstance().createResourceMount( domain, subPath );
|
findCC();
|
||||||
}
|
if( computerCraft_createResourceMount != null )
|
||||||
|
{
|
||||||
/**
|
try
|
||||||
* Creates a file system mount to a resource folder, and returns it.
|
{
|
||||||
*
|
return (IMount) computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
|
||||||
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
|
}
|
||||||
* resource folder onto a computer's file system.
|
catch( Exception e )
|
||||||
*
|
{
|
||||||
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
|
// It failed
|
||||||
* resources with the same domain and path.
|
}
|
||||||
*
|
}
|
||||||
* @param klass The mod class to which the files belong.
|
return null;
|
||||||
* @param domain The domain under which to look for resources. eg: "mymod".
|
|
||||||
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
|
||||||
* @return The mount, or {@code null} if it could be created for some reason.
|
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
|
||||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
|
||||||
* @see IMount
|
|
||||||
* @deprecated Use {@link #createResourceMount(String, String)} instead.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
@Deprecated
|
|
||||||
public static IMount createResourceMount( Class<?> klass, @Nonnull String domain, @Nonnull String subPath )
|
|
||||||
{
|
|
||||||
return getInstance().createResourceMount( domain, subPath );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,7 +178,18 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
|
public static void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
|
||||||
{
|
{
|
||||||
getInstance().registerPeripheralProvider( provider );
|
findCC();
|
||||||
|
if( computerCraft_registerPeripheralProvider != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft_registerPeripheralProvider.invoke( null, provider );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +202,21 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
|
public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
|
||||||
{
|
{
|
||||||
getInstance().registerTurtleUpgrade( upgrade );
|
if( upgrade != null )
|
||||||
|
{
|
||||||
|
findCC();
|
||||||
|
if( computerCraft_registerTurtleUpgrade != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft_registerTurtleUpgrade.invoke( null, upgrade );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,7 +227,18 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
|
public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
|
||||||
{
|
{
|
||||||
getInstance().registerBundledRedstoneProvider( provider );
|
findCC();
|
||||||
|
if( computerCraft_registerBundledRedstoneProvider != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft_registerBundledRedstoneProvider.invoke( null, provider );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,9 +251,21 @@ public final class ComputerCraftAPI
|
|||||||
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
|
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
|
||||||
* @see IBundledRedstoneProvider
|
* @see IBundledRedstoneProvider
|
||||||
*/
|
*/
|
||||||
public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
||||||
{
|
{
|
||||||
return getInstance().getBundledRedstoneOutput( world, pos, side );
|
findCC();
|
||||||
|
if( computerCraft_getDefaultBundledRedstoneOutput != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (Integer) computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,12 +276,58 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static void registerMediaProvider( @Nonnull IMediaProvider provider )
|
public static void registerMediaProvider( @Nonnull IMediaProvider provider )
|
||||||
{
|
{
|
||||||
getInstance().registerMediaProvider( provider );
|
findCC();
|
||||||
|
if( computerCraft_registerMediaProvider != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft_registerMediaProvider.invoke( null, provider );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a permission provider to restrict where turtles can move or build.
|
||||||
|
*
|
||||||
|
* @param provider The turtle permission provider to register.
|
||||||
|
* @see ITurtlePermissionProvider
|
||||||
|
* @deprecated Prefer using {@link dan200.computercraft.api.turtle.event.TurtleBlockEvent} or the standard Forge events.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void registerPermissionProvider( @Nonnull ITurtlePermissionProvider provider )
|
||||||
|
{
|
||||||
|
findCC();
|
||||||
|
if( computerCraft_registerPermissionProvider != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft_registerPermissionProvider.invoke( null, provider );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
|
public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
|
||||||
{
|
{
|
||||||
getInstance().registerPocketUpgrade( upgrade );
|
findCC();
|
||||||
|
if( computerCraft_registerPocketUpgrade != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft_registerPocketUpgrade.invoke( null, upgrade );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -211,12 +337,36 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static IPacketNetwork getWirelessNetwork()
|
public static IPacketNetwork getWirelessNetwork()
|
||||||
{
|
{
|
||||||
return getInstance().getWirelessNetwork();
|
findCC();
|
||||||
|
if( computerCraft_getWirelessNetwork != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (IPacketNetwork) computerCraft_getWirelessNetwork.invoke( null );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
|
public static void registerAPIFactory( @Nonnull ILuaAPIFactory upgrade )
|
||||||
{
|
{
|
||||||
getInstance().registerAPIFactory( factory );
|
findCC();
|
||||||
|
if( computerCraft_registerAPIFactory != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft_registerAPIFactory.invoke( null, upgrade );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
// It failed
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -229,7 +379,22 @@ public final class ComputerCraftAPI
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
public static IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
|
public static IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
|
||||||
{
|
{
|
||||||
return getInstance().createWiredNodeForElement( element );
|
findCC();
|
||||||
|
if( computerCraft_createWiredNodeForElement != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (IWiredNode) computerCraft_createWiredNodeForElement.invoke( null, element );
|
||||||
|
}
|
||||||
|
catch( ReflectiveOperationException e )
|
||||||
|
{
|
||||||
|
throw new IllegalStateException( "Error creating wired node", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalStateException( "ComputerCraft cannot be found" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -241,64 +406,118 @@ public final class ComputerCraftAPI
|
|||||||
* @return The element's node
|
* @return The element's node
|
||||||
* @see IWiredElement#getNode()
|
* @see IWiredElement#getNode()
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nullable
|
||||||
public static LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
public static IWiredElement getWiredElementAt( @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
||||||
{
|
{
|
||||||
return getInstance().getWiredElementAt( world, pos, side );
|
findCC();
|
||||||
|
if( computerCraft_getWiredElementAt != null )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (IWiredElement) computerCraft_getWiredElementAt.invoke( null, world, pos, side );
|
||||||
|
}
|
||||||
|
catch( ReflectiveOperationException ignored )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IComputerCraftAPI instance;
|
// The functions below here are private, and are used to interface with the non-API ComputerCraft classes.
|
||||||
|
// Reflection is used here so you can develop your mod without decompiling ComputerCraft and including
|
||||||
|
// it in your solution, and so your mod won't crash if ComputerCraft is installed.
|
||||||
|
|
||||||
@Nonnull
|
private static void findCC()
|
||||||
private static IComputerCraftAPI getInstance()
|
|
||||||
{
|
{
|
||||||
if( instance != null ) return instance;
|
if( !ccSearched )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" );
|
||||||
|
computerCraft_getVersion = findCCMethod( "getVersion", new Class<?>[] {
|
||||||
|
} );
|
||||||
|
computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class<?>[] {
|
||||||
|
World.class, String.class,
|
||||||
|
} );
|
||||||
|
computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class<?>[] {
|
||||||
|
World.class, String.class, Long.TYPE,
|
||||||
|
} );
|
||||||
|
computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class<?>[] {
|
||||||
|
Class.class, String.class, String.class,
|
||||||
|
} );
|
||||||
|
computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class<?>[] {
|
||||||
|
IPeripheralProvider.class,
|
||||||
|
} );
|
||||||
|
computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class<?>[] {
|
||||||
|
ITurtleUpgrade.class,
|
||||||
|
} );
|
||||||
|
computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class<?>[] {
|
||||||
|
IBundledRedstoneProvider.class,
|
||||||
|
} );
|
||||||
|
computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class<?>[] {
|
||||||
|
World.class, BlockPos.class, EnumFacing.class,
|
||||||
|
} );
|
||||||
|
computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class<?>[] {
|
||||||
|
IMediaProvider.class,
|
||||||
|
} );
|
||||||
|
computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class<?>[] {
|
||||||
|
ITurtlePermissionProvider.class,
|
||||||
|
} );
|
||||||
|
computerCraft_registerPocketUpgrade = findCCMethod( "registerPocketUpgrade", new Class<?>[] {
|
||||||
|
IPocketUpgrade.class,
|
||||||
|
} );
|
||||||
|
computerCraft_getWirelessNetwork = findCCMethod( "getWirelessNetwork", new Class<?>[] {
|
||||||
|
} );
|
||||||
|
computerCraft_registerAPIFactory = findCCMethod( "registerAPIFactory", new Class<?>[] {
|
||||||
|
ILuaAPIFactory.class,
|
||||||
|
} );
|
||||||
|
computerCraft_createWiredNodeForElement = findCCMethod( "createWiredNodeForElement", new Class<?>[] {
|
||||||
|
IWiredElement.class,
|
||||||
|
} );
|
||||||
|
computerCraft_getWiredElementAt = findCCMethod( "getWiredElementAt", new Class<?>[] {
|
||||||
|
IBlockAccess.class, BlockPos.class, EnumFacing.class,
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
System.err.println( "ComputerCraftAPI: ComputerCraft not found." );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ccSearched = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Method findCCMethod( String name, Class<?>[] args )
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return instance = (IComputerCraftAPI) Class.forName( "dan200.computercraft.ComputerCraftAPIImpl" )
|
return computerCraft != null ? computerCraft.getMethod( name, args ) : null;
|
||||||
.getField( "INSTANCE" ).get( null );
|
|
||||||
}
|
}
|
||||||
catch( ReflectiveOperationException e )
|
catch( NoSuchMethodException e )
|
||||||
{
|
{
|
||||||
throw new IllegalStateException( "Cannot find ComputerCraft API", e );
|
System.err.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IComputerCraftAPI
|
private static boolean ccSearched = false;
|
||||||
{
|
private static Class<?> computerCraft = null;
|
||||||
@Nonnull
|
private static Method computerCraft_getVersion = null;
|
||||||
String getInstalledVersion();
|
private static Method computerCraft_createUniqueNumberedSaveDir = null;
|
||||||
|
private static Method computerCraft_createSaveDirMount = null;
|
||||||
int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath );
|
private static Method computerCraft_createResourceMount = null;
|
||||||
|
private static Method computerCraft_registerPeripheralProvider = null;
|
||||||
@Nullable
|
private static Method computerCraft_registerTurtleUpgrade = null;
|
||||||
IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity );
|
private static Method computerCraft_registerBundledRedstoneProvider = null;
|
||||||
|
private static Method computerCraft_getDefaultBundledRedstoneOutput = null;
|
||||||
@Nullable
|
private static Method computerCraft_registerMediaProvider = null;
|
||||||
IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath );
|
private static Method computerCraft_registerPermissionProvider = null;
|
||||||
|
private static Method computerCraft_registerPocketUpgrade = null;
|
||||||
void registerPeripheralProvider( @Nonnull IPeripheralProvider provider );
|
private static Method computerCraft_getWirelessNetwork = null;
|
||||||
|
private static Method computerCraft_registerAPIFactory = null;
|
||||||
void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade );
|
private static Method computerCraft_createWiredNodeForElement = null;
|
||||||
|
private static Method computerCraft_getWiredElementAt = null;
|
||||||
void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
|
|
||||||
|
|
||||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
|
||||||
|
|
||||||
void registerMediaProvider( @Nonnull IMediaProvider provider );
|
|
||||||
|
|
||||||
void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade );
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
IPacketNetwork getWirelessNetwork();
|
|
||||||
|
|
||||||
void registerAPIFactory( @Nonnull ILuaAPIFactory factory );
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,61 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.api.client;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.TransformationMatrix;
|
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.model.ModelManager;
|
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A model to render, combined with a transformation matrix to apply.
|
|
||||||
*/
|
|
||||||
public final class TransformedModel
|
|
||||||
{
|
|
||||||
private final IBakedModel model;
|
|
||||||
private final TransformationMatrix matrix;
|
|
||||||
|
|
||||||
public TransformedModel( @Nonnull IBakedModel model, @Nonnull TransformationMatrix matrix )
|
|
||||||
{
|
|
||||||
this.model = Objects.requireNonNull( model );
|
|
||||||
this.matrix = Objects.requireNonNull( matrix );
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransformedModel( @Nonnull IBakedModel model )
|
|
||||||
{
|
|
||||||
this.model = Objects.requireNonNull( model );
|
|
||||||
this.matrix = TransformationMatrix.identity();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TransformedModel of( @Nonnull ModelResourceLocation location )
|
|
||||||
{
|
|
||||||
ModelManager modelManager = Minecraft.getInstance().getModelManager();
|
|
||||||
return new TransformedModel( modelManager.getModel( location ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TransformedModel of( @Nonnull ItemStack item, @Nonnull TransformationMatrix transform )
|
|
||||||
{
|
|
||||||
IBakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getItemModel( item );
|
|
||||||
return new TransformedModel( model, transform );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public IBakedModel getModel()
|
|
||||||
{
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
public TransformationMatrix getMatrix()
|
|
||||||
{
|
|
||||||
return matrix;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.api.filesystem;
|
||||||
|
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.nio.file.attribute.FileTime;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A simple version of {@link BasicFileAttributes}, which provides what information a {@link IMount} already exposes.
|
||||||
|
*/
|
||||||
|
final class FileAttributes implements BasicFileAttributes
|
||||||
|
{
|
||||||
|
private static final FileTime EPOCH = FileTime.from( Instant.EPOCH );
|
||||||
|
|
||||||
|
private final boolean isDirectory;
|
||||||
|
private final long size;
|
||||||
|
|
||||||
|
FileAttributes( boolean isDirectory, long size )
|
||||||
|
{
|
||||||
|
this.isDirectory = isDirectory;
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileTime lastModifiedTime()
|
||||||
|
{
|
||||||
|
return EPOCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileTime lastAccessTime()
|
||||||
|
{
|
||||||
|
return EPOCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileTime creationTime()
|
||||||
|
{
|
||||||
|
return EPOCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRegularFile()
|
||||||
|
{
|
||||||
|
return !isDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDirectory()
|
||||||
|
{
|
||||||
|
return isDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSymbolicLink()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOther()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long size()
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object fileKey()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ public class FileOperationException extends IOException
|
|||||||
this.filename = filename;
|
this.filename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileOperationException( String message )
|
public FileOperationException( @Nonnull String message )
|
||||||
{
|
{
|
||||||
super( Objects.requireNonNull( message, "message cannot be null" ) );
|
super( Objects.requireNonNull( message, "message cannot be null" ) );
|
||||||
this.filename = null;
|
this.filename = null;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,4 +94,18 @@ public interface IMount
|
|||||||
{
|
{
|
||||||
return Channels.newChannel( openForRead( path ) );
|
return Channels.newChannel( openForRead( path ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get attributes about the given file.
|
||||||
|
*
|
||||||
|
* @param path The path to query.
|
||||||
|
* @return File attributes for the given file.
|
||||||
|
* @throws IOException If the file does not exist, or attributes could not be fetched.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
default BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
|
||||||
|
{
|
||||||
|
if( !exists( path ) ) throw new FileOperationException( path, "No such file" );
|
||||||
|
return new FileAttributes( isDirectory( path ), getSize( path ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
|
import java.util.OptionalLong;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
|
* Represents a part of a virtual filesystem that can be mounted onto a computer using {@link IComputerAccess#mount(String, IMount)}
|
||||||
@@ -105,4 +106,16 @@ public interface IWritableMount extends IMount
|
|||||||
* @throws IOException If the remaining space could not be computed.
|
* @throws IOException If the remaining space could not be computed.
|
||||||
*/
|
*/
|
||||||
long getRemainingSpace() throws IOException;
|
long getRemainingSpace() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the capacity of this mount. This should be equal to the size of all files/directories on this mount, minus
|
||||||
|
* the {@link #getRemainingSpace()}.
|
||||||
|
*
|
||||||
|
* @return The capacity of this mount, in bytes.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
default OptionalLong getCapacity()
|
||||||
|
{
|
||||||
|
return OptionalLong.empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|FileSystem", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.filesystem;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Lua", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.lua;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Media", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.media;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.network;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network|Wired", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.network.wired;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
9
src/main/java/dan200/computercraft/api/package-info.java
Normal file
9
src/main/java/dan200/computercraft/api/package-info.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
@@ -33,5 +33,5 @@ public interface IPeripheralProvider
|
|||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
@@ -25,8 +25,8 @@ public interface IPeripheralTile
|
|||||||
*
|
*
|
||||||
* @param side The side to get the peripheral from.
|
* @param side The side to get the peripheral from.
|
||||||
* @return A peripheral, or {@code null} if there is not a peripheral here.
|
* @return A peripheral, or {@code null} if there is not a peripheral here.
|
||||||
* @see IPeripheralProvider#getPeripheral(World, BlockPos, Direction)
|
* @see IPeripheralProvider#getPeripheral(World, BlockPos, EnumFacing)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
IPeripheral getPeripheral( @Nonnull Direction side );
|
IPeripheral getPeripheral( @Nonnull EnumFacing side );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Peripheral", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.api.permissions;
|
||||||
|
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface is used to restrict where turtles can move or build.
|
||||||
|
*
|
||||||
|
* Turtles will call these methods before attempting to perform an action, allowing them to be cancelled.
|
||||||
|
*
|
||||||
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider)
|
||||||
|
*/
|
||||||
|
public interface ITurtlePermissionProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether a block can be entered by a turtle.
|
||||||
|
*
|
||||||
|
* @param world The world the block exists in
|
||||||
|
* @param pos The location of the block.
|
||||||
|
* @return Whether the turtle can move into this block.
|
||||||
|
*/
|
||||||
|
boolean isBlockEnterable( @Nonnull World world, @Nonnull BlockPos pos );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether a block can be modified by a turtle.
|
||||||
|
*
|
||||||
|
* This includes breaking and placing blocks.
|
||||||
|
*
|
||||||
|
* @param world The world the block exists in
|
||||||
|
* @param pos The location of the block.
|
||||||
|
* @return Whether the turtle can modify this block.
|
||||||
|
*/
|
||||||
|
boolean isBlockEditable( @Nonnull World world, @Nonnull BlockPos pos );
|
||||||
|
}
|
||||||
9
src/main/java/dan200/computercraft/api/permissions/package-info.java
Executable file
9
src/main/java/dan200/computercraft/api/permissions/package-info.java
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Permissions", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.permissions;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -6,9 +6,7 @@
|
|||||||
package dan200.computercraft.api.pocket;
|
package dan200.computercraft.api.pocket;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.IItemProvider;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.Util;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -30,14 +28,9 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
|||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, IItemProvider item )
|
protected AbstractPocketUpgrade( ResourceLocation id, ItemStack stack )
|
||||||
{
|
{
|
||||||
this( id, adjective, new ItemStack( item ) );
|
this( id, "upgrade." + id + ".adjective", stack );
|
||||||
}
|
|
||||||
|
|
||||||
protected AbstractPocketUpgrade( ResourceLocation id, IItemProvider item )
|
|
||||||
{
|
|
||||||
this( id, Util.makeTranslationKey( "upgrade", id ) + ".adjective", new ItemStack( item ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package dan200.computercraft.api.pocket;
|
|||||||
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -22,12 +22,22 @@ public interface IPocketAccess
|
|||||||
/**
|
/**
|
||||||
* Gets the entity holding this item.
|
* Gets the entity holding this item.
|
||||||
*
|
*
|
||||||
|
* @return The holding entity. This may be {@code null}.
|
||||||
|
* @deprecated Use {@link #getValidEntity()} where possible.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
@Deprecated
|
||||||
|
Entity getEntity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the entity holding this item with additional safety checks.
|
||||||
|
*
|
||||||
* This must be called on the server thread.
|
* This must be called on the server thread.
|
||||||
*
|
*
|
||||||
* @return The holding entity, or {@code null} if none exists.
|
* @return The holding entity, or {@code null} if none exists.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Entity getEntity();
|
Entity getValidEntity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the colour of this pocket computer as a RGB number.
|
* Get the colour of this pocket computer as a RGB number.
|
||||||
@@ -74,7 +84,7 @@ public interface IPocketAccess
|
|||||||
* @see #updateUpgradeNBTData()
|
* @see #updateUpgradeNBTData()
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
CompoundNBT getUpgradeNBTData();
|
NBTTagCompound getUpgradeNBTData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the upgrade-specific NBT as dirty.
|
* Mark the upgrade-specific NBT as dirty.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.redstone;
|
package dan200.computercraft.api.redstone;
|
||||||
|
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
@@ -29,5 +29,5 @@ public interface IBundledRedstoneProvider
|
|||||||
* handle this block.
|
* handle this block.
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
||||||
*/
|
*/
|
||||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Redstone", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.redstone;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -10,8 +10,8 @@ import dan200.computercraft.api.lua.ILuaContext;
|
|||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
@@ -53,7 +53,8 @@ public interface ITurtleAccess
|
|||||||
* @param world The new world to move it to
|
* @param world The new world to move it to
|
||||||
* @param pos The new position to move it to.
|
* @param pos The new position to move it to.
|
||||||
* @return Whether the movement was successful. It may fail if the block was not loaded or the block placement
|
* @return Whether the movement was successful. It may fail if the block was not loaded or the block placement
|
||||||
* was cancelled.
|
* was cancelled. Note this will not check
|
||||||
|
* {@link dan200.computercraft.api.permissions.ITurtlePermissionProvider#isBlockEnterable(World, BlockPos)}.
|
||||||
* @throws UnsupportedOperationException When attempting to teleport on the client side.
|
* @throws UnsupportedOperationException When attempting to teleport on the client side.
|
||||||
*/
|
*/
|
||||||
boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos );
|
boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos );
|
||||||
@@ -82,10 +83,10 @@ public interface ITurtleAccess
|
|||||||
* Returns the world direction the turtle is currently facing.
|
* Returns the world direction the turtle is currently facing.
|
||||||
*
|
*
|
||||||
* @return The world direction the turtle is currently facing.
|
* @return The world direction the turtle is currently facing.
|
||||||
* @see #setDirection(Direction)
|
* @see #setDirection(EnumFacing)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Direction getDirection();
|
EnumFacing getDirection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to
|
* Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to
|
||||||
@@ -94,7 +95,7 @@ public interface ITurtleAccess
|
|||||||
* @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west).
|
* @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west).
|
||||||
* @see #getDirection()
|
* @see #getDirection()
|
||||||
*/
|
*/
|
||||||
void setDirection( @Nonnull Direction dir );
|
void setDirection( @Nonnull EnumFacing dir );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently selected slot in the turtle's inventory.
|
* Get the currently selected slot in the turtle's inventory.
|
||||||
@@ -293,7 +294,7 @@ public interface ITurtleAccess
|
|||||||
* @see #updateUpgradeNBTData(TurtleSide)
|
* @see #updateUpgradeNBTData(TurtleSide)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
CompoundNBT getUpgradeNBTData( @Nullable TurtleSide side );
|
NBTTagCompound getUpgradeNBTData( @Nullable TurtleSide side );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
|
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
|
||||||
|
|||||||
@@ -6,21 +6,23 @@
|
|||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
|
import dan200.computercraft.api.turtle.event.TurtleAttackEvent;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
import dan200.computercraft.api.turtle.event.TurtleBlockEvent;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
import net.minecraftforge.event.world.BlockEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.vecmath.Matrix4f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The primary interface for defining an update for Turtles. A turtle update
|
* The primary interface for defining an update for Turtles. A turtle update
|
||||||
@@ -41,6 +43,17 @@ public interface ITurtleUpgrade
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
ResourceLocation getUpgradeID();
|
ResourceLocation getUpgradeID();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a numerical identifier representing this type of turtle upgrade,
|
||||||
|
* for backwards compatibility with pre-1.76 worlds. If your upgrade was
|
||||||
|
* not released for older ComputerCraft versions, you can return -1 here.
|
||||||
|
* The turtle will fail registration if an already used positive ID is specified.
|
||||||
|
*
|
||||||
|
* @return The legacy ID, or -1 if is needed.
|
||||||
|
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
||||||
|
*/
|
||||||
|
int getLegacyUpgradeID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an unlocalised string to describe this type of turtle in turtle item names.
|
* Return an unlocalised string to describe this type of turtle in turtle item names.
|
||||||
*
|
*
|
||||||
@@ -110,7 +123,7 @@ public interface ITurtleUpgrade
|
|||||||
* to be called.
|
* to be called.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction )
|
default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
|
||||||
{
|
{
|
||||||
return TurtleCommandResult.failure();
|
return TurtleCommandResult.failure();
|
||||||
}
|
}
|
||||||
@@ -119,16 +132,17 @@ public interface ITurtleUpgrade
|
|||||||
* Called to obtain the model to be used when rendering a turtle peripheral.
|
* Called to obtain the model to be used when rendering a turtle peripheral.
|
||||||
*
|
*
|
||||||
* This can be obtained from {@link net.minecraft.client.renderer.ItemModelMesher#getItemModel(ItemStack)},
|
* This can be obtained from {@link net.minecraft.client.renderer.ItemModelMesher#getItemModel(ItemStack)},
|
||||||
* {@link net.minecraft.client.renderer.model.ModelManager#getModel(ModelResourceLocation)} or any other
|
* {@link net.minecraft.client.renderer.block.model.ModelManager#getModel(ModelResourceLocation)} or any other
|
||||||
* source.
|
* source.
|
||||||
*
|
*
|
||||||
* @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
|
* @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
|
||||||
* @param side Which side of the turtle (left or right) the upgrade resides on.
|
* @param side Which side of the turtle (left or right) the upgrade resides on.
|
||||||
* @return The model that you wish to be used to render your upgrade.
|
* @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning
|
||||||
|
* a transformation of {@code null} has the same effect as the identify matrix.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@OnlyIn( Dist.CLIENT )
|
@SideOnly( Side.CLIENT )
|
||||||
TransformedModel getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
|
Pair<IBakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called once per tick for each turtle which has the upgrade equipped.
|
* Called once per tick for each turtle which has the upgrade equipped.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -14,7 +14,7 @@ import javax.annotation.Nullable;
|
|||||||
* Used to indicate the result of executing a turtle command.
|
* Used to indicate the result of executing a turtle command.
|
||||||
*
|
*
|
||||||
* @see ITurtleCommand#execute(ITurtleAccess)
|
* @see ITurtleCommand#execute(ITurtleAccess)
|
||||||
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
|
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
|
||||||
*/
|
*/
|
||||||
public final class TurtleCommandResult
|
public final class TurtleCommandResult
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by
|
* An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by
|
||||||
* a turtle.
|
* a turtle.
|
||||||
*
|
*
|
||||||
* @see ITurtleUpgrade#getType()
|
* @see ITurtleUpgrade#getType()
|
||||||
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
|
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
|
||||||
*/
|
*/
|
||||||
public enum TurtleVerb
|
public enum TurtleVerb
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package dan200.computercraft.api.turtle.event;
|
|||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
||||||
import net.minecraftforge.eventbus.api.Cancelable;
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* Fired when a turtle attempts to attack an entity.
|
* Fired when a turtle attempts to attack an entity.
|
||||||
*
|
*
|
||||||
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
|
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)},
|
||||||
* as the base {@code turtle.attack()} command does not fire it.
|
* as the base {@code turtle.attack()} command does not fire it.
|
||||||
*
|
*
|
||||||
* Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both.
|
* Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both.
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
import net.minecraftforge.common.util.FakePlayer;
|
||||||
@@ -74,7 +74,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
/**
|
/**
|
||||||
* Fired when a turtle attempts to dig a block.
|
* Fired when a turtle attempts to dig a block.
|
||||||
*
|
*
|
||||||
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
|
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)},
|
||||||
* as the base {@code turtle.dig()} command does not fire it.
|
* as the base {@code turtle.dig()} command does not fire it.
|
||||||
*
|
*
|
||||||
* Note that such commands should also fire {@link BlockEvent.BreakEvent}, so you do not need to listen to both.
|
* Note that such commands should also fire {@link BlockEvent.BreakEvent}, so you do not need to listen to both.
|
||||||
@@ -83,11 +83,11 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
*/
|
*/
|
||||||
public static class Dig extends TurtleBlockEvent
|
public static class Dig extends TurtleBlockEvent
|
||||||
{
|
{
|
||||||
private final BlockState block;
|
private final IBlockState block;
|
||||||
private final ITurtleUpgrade upgrade;
|
private final ITurtleUpgrade upgrade;
|
||||||
private final TurtleSide side;
|
private final TurtleSide side;
|
||||||
|
|
||||||
public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
|
public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
|
||||||
{
|
{
|
||||||
super( turtle, TurtleAction.DIG, player, world, pos );
|
super( turtle, TurtleAction.DIG, player, world, pos );
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
* @return The block which is going to be broken.
|
* @return The block which is going to be broken.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public BlockState getBlock()
|
public IBlockState getBlock()
|
||||||
{
|
{
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
@@ -184,10 +184,10 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
*/
|
*/
|
||||||
public static class Inspect extends TurtleBlockEvent
|
public static class Inspect extends TurtleBlockEvent
|
||||||
{
|
{
|
||||||
private final BlockState state;
|
private final IBlockState state;
|
||||||
private final Map<String, Object> data;
|
private final Map<String, Object> data;
|
||||||
|
|
||||||
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Map<String, Object> data )
|
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Map<String, Object> data )
|
||||||
{
|
{
|
||||||
super( turtle, TurtleAction.INSPECT, player, world, pos );
|
super( turtle, TurtleAction.INSPECT, player, world, pos );
|
||||||
|
|
||||||
@@ -203,7 +203,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
* @return The inspected block state.
|
* @return The inspected block state.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public BlockState getState()
|
public IBlockState getState()
|
||||||
{
|
{
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
package dan200.computercraft.api.turtle.event;
|
package dan200.computercraft.api.turtle.event;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle|Event", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.turtle.event;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle", apiVersion = "${version}" )
|
||||||
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
|
import net.minecraftforge.fml.common.API;
|
||||||
@@ -7,80 +7,104 @@ package dan200.computercraft.client;
|
|||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.client.render.TurtleModelLoader;
|
import dan200.computercraft.client.render.TurtleModelLoader;
|
||||||
import dan200.computercraft.shared.common.IColouredItem;
|
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
||||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
|
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
|
||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.inventory.container.PlayerContainer;
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||||
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureMap;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.ColorHandlerEvent;
|
import net.minecraftforge.client.event.ColorHandlerEvent;
|
||||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
|
import net.minecraftforge.client.model.IModel;
|
||||||
import net.minecraftforge.client.model.ModelLoader;
|
import net.minecraftforge.client.model.ModelLoader;
|
||||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||||
import net.minecraftforge.client.model.SimpleModelTransform;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers textures and models for items.
|
* Registers textures and models for items.
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
public final class ClientRegistry
|
public final class ClientRegistry
|
||||||
{
|
{
|
||||||
private static final String[] EXTRA_MODELS = new String[] {
|
private static final String[] EXTRA_MODELS = new String[] {
|
||||||
"turtle_modem_normal_off_left",
|
"turtle_modem_off_left",
|
||||||
"turtle_modem_normal_on_left",
|
"turtle_modem_on_left",
|
||||||
"turtle_modem_normal_off_right",
|
"turtle_modem_off_right",
|
||||||
"turtle_modem_normal_on_right",
|
"turtle_modem_on_right",
|
||||||
|
|
||||||
"turtle_modem_advanced_off_left",
|
|
||||||
"turtle_modem_advanced_on_left",
|
|
||||||
"turtle_modem_advanced_off_right",
|
|
||||||
"turtle_modem_advanced_on_right",
|
|
||||||
"turtle_crafting_table_left",
|
"turtle_crafting_table_left",
|
||||||
"turtle_crafting_table_right",
|
"turtle_crafting_table_right",
|
||||||
|
"advanced_turtle_modem_off_left",
|
||||||
|
"advanced_turtle_modem_on_left",
|
||||||
|
"advanced_turtle_modem_off_right",
|
||||||
|
"advanced_turtle_modem_on_right",
|
||||||
"turtle_speaker_upgrade_left",
|
"turtle_speaker_upgrade_left",
|
||||||
"turtle_speaker_upgrade_right",
|
"turtle_speaker_upgrade_right",
|
||||||
|
|
||||||
"turtle_colour",
|
"turtle_white",
|
||||||
"turtle_elf_overlay",
|
"turtle_elf_overlay",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] EXTRA_TEXTURES = new String[] {
|
|
||||||
// TODO: Gather these automatically from the model. Sadly the model loader isn't available
|
|
||||||
// when stitching textures.
|
|
||||||
"block/turtle_colour",
|
|
||||||
"block/turtle_elf_overlay",
|
|
||||||
"block/turtle_crafty_face",
|
|
||||||
"block/turtle_speaker_face",
|
|
||||||
};
|
|
||||||
|
|
||||||
private ClientRegistry() {}
|
private ClientRegistry() {}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void registerModels( ModelRegistryEvent event )
|
public static void registerModels( ModelRegistryEvent event )
|
||||||
{
|
{
|
||||||
ModelLoaderRegistry.registerLoader( new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ), TurtleModelLoader.INSTANCE );
|
ModelLoaderRegistry.registerLoader( TurtleModelLoader.INSTANCE );
|
||||||
|
|
||||||
|
// Register item models
|
||||||
|
registerUniversalItemModel( ComputerCraft.Items.computer, "computer" );
|
||||||
|
registerItemModel( ComputerCraft.Items.commandComputer, 0, "command_computer" );
|
||||||
|
|
||||||
|
registerItemModel( ComputerCraft.Items.pocketComputer, 0, "pocket_computer" );
|
||||||
|
registerItemModel( ComputerCraft.Items.pocketComputer, 1, "advanced_pocket_computer" );
|
||||||
|
|
||||||
|
registerItemModel( ComputerCraft.Items.peripheral, 0, "peripheral" );
|
||||||
|
registerItemModel( ComputerCraft.Items.peripheral, 1, "wireless_modem" );
|
||||||
|
registerItemModel( ComputerCraft.Items.peripheral, 2, "monitor" );
|
||||||
|
registerItemModel( ComputerCraft.Items.peripheral, 3, "printer" );
|
||||||
|
registerItemModel( ComputerCraft.Items.peripheral, 4, "advanced_monitor" );
|
||||||
|
registerItemModel( ComputerCraft.Items.cable, 0, "cable" );
|
||||||
|
registerItemModel( ComputerCraft.Items.cable, 1, "wired_modem" );
|
||||||
|
registerItemModel( ComputerCraft.Items.advancedModem, 0, "advanced_modem" );
|
||||||
|
registerItemModel( ComputerCraft.Items.peripheral, 5, "speaker" );
|
||||||
|
registerItemModel( ComputerCraft.Items.wiredModemFull, 0, "wired_modem_full" );
|
||||||
|
|
||||||
|
registerUniversalItemModel( ComputerCraft.Items.disk, "disk" );
|
||||||
|
registerItemModel( ComputerCraft.Items.diskExpanded, 0, "disk_expanded" );
|
||||||
|
registerItemModel( ComputerCraft.Items.treasureDisk, 0, "treasure_disk" );
|
||||||
|
|
||||||
|
registerItemModel( ComputerCraft.Items.printout, 0, "printout" );
|
||||||
|
registerItemModel( ComputerCraft.Items.printout, 1, "pages" );
|
||||||
|
registerItemModel( ComputerCraft.Items.printout, 2, "book" );
|
||||||
|
|
||||||
|
registerUniversalItemModel( ComputerCraft.Items.turtle, "turtle" );
|
||||||
|
registerUniversalItemModel( ComputerCraft.Items.turtleExpanded, "turtle" );
|
||||||
|
registerUniversalItemModel( ComputerCraft.Items.turtleAdvanced, "turtle_advanced" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
||||||
{
|
{
|
||||||
if( !event.getMap().getBasePath().equals( PlayerContainer.LOCATION_BLOCKS_TEXTURE ) ) return;
|
// Load all textures for the extra models
|
||||||
|
TextureMap map = event.getMap();
|
||||||
for( String extra : EXTRA_TEXTURES )
|
for( String upgrade : EXTRA_MODELS )
|
||||||
{
|
{
|
||||||
event.addSprite( new ResourceLocation( ComputerCraft.MOD_ID, extra ) );
|
IModel model = ModelLoaderRegistry.getModelOrMissing( new ResourceLocation( "computercraft", "block/" + upgrade ) );
|
||||||
|
for( ResourceLocation texture : model.getTextures() ) map.registerSprite( texture );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,57 +112,73 @@ public final class ClientRegistry
|
|||||||
public static void onModelBakeEvent( ModelBakeEvent event )
|
public static void onModelBakeEvent( ModelBakeEvent event )
|
||||||
{
|
{
|
||||||
// Load all extra models
|
// Load all extra models
|
||||||
ModelLoader loader = event.getModelLoader();
|
for( String model : EXTRA_MODELS ) loadBlockModel( event, model );
|
||||||
Map<ResourceLocation, IBakedModel> registry = event.getModelRegistry();
|
|
||||||
|
|
||||||
for( String modelName : EXTRA_MODELS )
|
|
||||||
{
|
|
||||||
ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, "item/" + modelName );
|
|
||||||
IUnbakedModel model = loader.getUnbakedModel( location );
|
|
||||||
model.getTextures( loader::getUnbakedModel, new HashSet<>() );
|
|
||||||
|
|
||||||
IBakedModel baked = model.bakeModel( loader, ModelLoader.defaultTextureGetter(), SimpleModelTransform.IDENTITY, location );
|
|
||||||
if( baked != null )
|
|
||||||
{
|
|
||||||
registry.put( new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, modelName ), "inventory" ), baked );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onItemColours( ColorHandlerEvent.Item event )
|
public static void onItemColours( ColorHandlerEvent.Item event )
|
||||||
{
|
{
|
||||||
if( ComputerCraft.Items.disk == null || ComputerCraft.Blocks.turtleNormal == null )
|
event.getItemColors().registerItemColorHandler(
|
||||||
{
|
( stack, layer ) -> layer == 1 ? ((ItemDiskLegacy) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
||||||
ComputerCraft.log.warn( "Block/item registration has failed. Skipping registration of item colours." );
|
ComputerCraft.Items.disk, ComputerCraft.Items.diskExpanded
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.getItemColors().register(
|
|
||||||
( stack, layer ) -> layer == 1 ? ((ItemDisk) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
|
||||||
ComputerCraft.Items.disk
|
|
||||||
);
|
);
|
||||||
|
|
||||||
event.getItemColors().register( ( stack, layer ) -> {
|
event.getItemColors().registerItemColorHandler( ( stack, layer ) -> {
|
||||||
switch( layer )
|
switch( layer )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
return 0xFFFFFF;
|
return 0xFFFFFF;
|
||||||
case 1: // Frame colour
|
case 1: // Frame colour
|
||||||
return IColouredItem.getColourBasic( stack );
|
return ComputerCraft.Items.pocketComputer.getColour( stack );
|
||||||
case 2: // Light colour
|
case 2: // Light colour
|
||||||
{
|
{
|
||||||
int light = ItemPocketComputer.getLightState( stack );
|
int light = ItemPocketComputer.getLightState( stack );
|
||||||
return light == -1 ? Colour.Black.getHex() : light;
|
return light == -1 ? Colour.Black.getHex() : light;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, ComputerCraft.Items.pocketComputerNormal, ComputerCraft.Items.pocketComputerAdvanced );
|
}, ComputerCraft.Items.pocketComputer );
|
||||||
|
|
||||||
// Setup turtle colours
|
// Setup turtle colours
|
||||||
event.getItemColors().register(
|
event.getItemColors().registerItemColorHandler(
|
||||||
( stack, tintIndex ) -> tintIndex == 0 ? ((IColouredItem) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
( stack, tintIndex ) -> tintIndex == 0 ? ((ItemTurtleBase) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
||||||
ComputerCraft.Blocks.turtleNormal, ComputerCraft.Blocks.turtleAdvanced
|
ComputerCraft.Blocks.turtle, ComputerCraft.Blocks.turtleExpanded, ComputerCraft.Blocks.turtleAdvanced
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void registerItemModel( Item item, int damage, String name )
|
||||||
|
{
|
||||||
|
ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
||||||
|
final ModelResourceLocation res = new ModelResourceLocation( location, "inventory" );
|
||||||
|
ModelBakery.registerItemVariants( item, location );
|
||||||
|
ModelLoader.setCustomModelResourceLocation( item, damage, res );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerUniversalItemModel( Item item, String mainModel )
|
||||||
|
{
|
||||||
|
ResourceLocation mainLocation = new ResourceLocation( ComputerCraft.MOD_ID, mainModel );
|
||||||
|
ModelBakery.registerItemVariants( item, mainLocation );
|
||||||
|
|
||||||
|
final ModelResourceLocation mainModelLocation = new ModelResourceLocation( mainLocation, "inventory" );
|
||||||
|
ModelLoader.setCustomMeshDefinition( item, new ItemMeshDefinition()
|
||||||
|
{
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
|
||||||
|
{
|
||||||
|
return mainModelLocation;
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadBlockModel( ModelBakeEvent event, String name )
|
||||||
|
{
|
||||||
|
IModel model = ModelLoaderRegistry.getModelOrMissing( new ResourceLocation( ComputerCraft.MOD_ID, "block/" + name ) );
|
||||||
|
IBakedModel bakedModel = model.bake(
|
||||||
|
model.getDefaultState(), DefaultVertexFormats.ITEM,
|
||||||
|
location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite( location.toString() )
|
||||||
|
);
|
||||||
|
|
||||||
|
event.getModelRegistry().putObject( new ModelResourceLocation( ComputerCraft.MOD_ID + ":" + name, "inventory" ), bakedModel );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import dan200.computercraft.shared.command.text.TableFormatter;
|
|||||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
import net.minecraft.client.gui.NewChatGui;
|
import net.minecraft.client.gui.GuiNewChat;
|
||||||
import net.minecraft.client.gui.RenderComponentsUtil;
|
import net.minecraft.client.gui.GuiUtilRenderComponents;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
@@ -29,7 +29,7 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
|
|
||||||
private static FontRenderer renderer()
|
private static FontRenderer renderer()
|
||||||
{
|
{
|
||||||
return Minecraft.getInstance().fontRenderer;
|
return Minecraft.getMinecraft().fontRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -41,7 +41,7 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
|
|
||||||
FontRenderer renderer = renderer();
|
FontRenderer renderer = renderer();
|
||||||
|
|
||||||
float spaceWidth = renderer.getStringWidth( " " );
|
float spaceWidth = renderer.getCharWidth( ' ' );
|
||||||
int spaces = MathHelper.floor( extraWidth / spaceWidth );
|
int spaces = MathHelper.floor( extraWidth / spaceWidth );
|
||||||
int extra = extraWidth - (int) (spaces * spaceWidth);
|
int extra = extraWidth - (int) (spaces * spaceWidth);
|
||||||
|
|
||||||
@@ -63,19 +63,19 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
@Override
|
@Override
|
||||||
public void writeLine( int id, ITextComponent component )
|
public void writeLine( int id, ITextComponent component )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
NewChatGui chat = mc.ingameGUI.getChatGUI();
|
GuiNewChat chat = mc.ingameGUI.getChatGUI();
|
||||||
|
|
||||||
// Trim the text if it goes over the allowed length
|
// Trim the text if it goes over the allowed length
|
||||||
int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() );
|
int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getChatScale() );
|
||||||
List<ITextComponent> list = RenderComponentsUtil.splitText( component, maxWidth, mc.fontRenderer, false, false );
|
List<ITextComponent> list = GuiUtilRenderComponents.splitText( component, maxWidth, mc.fontRenderer, false, false );
|
||||||
if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
|
if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int display( TableBuilder table )
|
public int display( TableBuilder table )
|
||||||
{
|
{
|
||||||
NewChatGui chat = Minecraft.getInstance().ingameGUI.getChatGUI();
|
GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();
|
||||||
|
|
||||||
int lastHeight = lastHeights.get( table.getId() );
|
int lastHeight = lastHeights.get( table.getId() );
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,12 @@
|
|||||||
package dan200.computercraft.client;
|
package dan200.computercraft.client;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.event.TickEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
public final class FrameInfo
|
public final class FrameInfo
|
||||||
{
|
{
|
||||||
private static int tick;
|
private static int tick;
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import dan200.computercraft.client.FrameInfo;
|
import dan200.computercraft.client.FrameInfo;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.*;
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
@@ -24,10 +24,21 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
public final class FixedWidthFontRenderer
|
public final class FixedWidthFontRenderer
|
||||||
{
|
{
|
||||||
private static final Matrix4f IDENTITY = TransformationMatrix.identity().getMatrix();
|
|
||||||
|
|
||||||
private static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
|
private static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like {@link DefaultVertexFormats#POSITION_TEX_COLOR}, but flipped. This is backported from 1.15, hence the
|
||||||
|
* custom format.
|
||||||
|
*/
|
||||||
|
public static final VertexFormat POSITION_COLOR_TEX = new VertexFormat();
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
POSITION_COLOR_TEX.addElement( DefaultVertexFormats.POSITION_3F );
|
||||||
|
POSITION_COLOR_TEX.addElement( DefaultVertexFormats.COLOR_4UB );
|
||||||
|
POSITION_COLOR_TEX.addElement( DefaultVertexFormats.TEX_2F );
|
||||||
|
}
|
||||||
|
|
||||||
public static final int FONT_HEIGHT = 9;
|
public static final int FONT_HEIGHT = 9;
|
||||||
public static final int FONT_WIDTH = 6;
|
public static final int FONT_WIDTH = 6;
|
||||||
public static final float WIDTH = 256.0f;
|
public static final float WIDTH = 256.0f;
|
||||||
@@ -35,118 +46,120 @@ public final class FixedWidthFontRenderer
|
|||||||
public static final float BACKGROUND_START = (WIDTH - 6.0f) / WIDTH;
|
public static final float BACKGROUND_START = (WIDTH - 6.0f) / WIDTH;
|
||||||
public static final float BACKGROUND_END = (WIDTH - 4.0f) / WIDTH;
|
public static final float BACKGROUND_END = (WIDTH - 4.0f) / WIDTH;
|
||||||
|
|
||||||
public static final RenderType TYPE = Type.MAIN;
|
|
||||||
|
|
||||||
private FixedWidthFontRenderer()
|
private FixedWidthFontRenderer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float toGreyscale( double[] rgb )
|
public static float toGreyscale( double[] rgb )
|
||||||
{
|
{
|
||||||
return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3);
|
return (float) ((rgb[0] + rgb[1] + rgb[2]) / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawChar( Matrix4f transform, IVertexBuilder buffer, float x, float y, int index, float r, float g, float b )
|
public static int getColour( char c, Colour def )
|
||||||
{
|
{
|
||||||
|
return 15 - Terminal.getColour( c, def );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawChar( BufferBuilder buffer, float x, float y, int index, float r, float g, float b )
|
||||||
|
{
|
||||||
|
// Short circuit to avoid the common case - the texture should be blank here after all.
|
||||||
|
if( index == '\0' || index == ' ' ) return;
|
||||||
|
|
||||||
int column = index % 16;
|
int column = index % 16;
|
||||||
int row = index / 16;
|
int row = index / 16;
|
||||||
|
|
||||||
int xStart = 1 + column * (FONT_WIDTH + 2);
|
int xStart = 1 + column * (FONT_WIDTH + 2);
|
||||||
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
||||||
|
|
||||||
buffer.pos( transform, x, y, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, yStart / WIDTH ).endVertex();
|
buffer.pos( x, y, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, yStart / WIDTH ).endVertex();
|
||||||
buffer.pos( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
buffer.pos( x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||||
buffer.pos( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
buffer.pos( x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
||||||
buffer.pos( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
buffer.pos( x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
||||||
buffer.pos( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
buffer.pos( x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||||
buffer.pos( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
buffer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, float r, float g, float b )
|
private static void drawQuad( BufferBuilder buffer, float x, float y, float width, float height, float r, float g, float b )
|
||||||
{
|
{
|
||||||
buffer.pos( transform, x, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_START ).endVertex();
|
buffer.pos( x, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_START ).endVertex();
|
||||||
buffer.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
buffer.pos( x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
||||||
buffer.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
buffer.pos( x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
||||||
buffer.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
buffer.pos( x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
||||||
buffer.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
buffer.pos( x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
||||||
buffer.pos( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_END ).endVertex();
|
buffer.pos( x + width, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_END ).endVertex();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void drawQuad( BufferBuilder buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex )
|
||||||
|
{
|
||||||
|
double[] colour = palette.getColour( getColour( colourIndex, Colour.Black ) );
|
||||||
|
float r, g, b;
|
||||||
|
if( greyscale )
|
||||||
|
{
|
||||||
|
r = g = b = toGreyscale( colour );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r = (float) colour[0];
|
||||||
|
g = (float) colour[1];
|
||||||
|
b = (float) colour[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
drawQuad( buffer, x, y, width, height, r, g, b );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawBackground(
|
private static void drawBackground(
|
||||||
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder renderer, float x, float y,
|
@Nonnull BufferBuilder renderer, float x, float y,
|
||||||
@Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale,
|
@Nonnull TextBuffer backgroundColour, @Nonnull Palette palette, boolean greyscale,
|
||||||
float leftMarginSize, float rightMarginSize, float height
|
float leftMarginSize, float rightMarginSize, float height
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( leftMarginSize > 0 )
|
if( leftMarginSize > 0 )
|
||||||
{
|
{
|
||||||
double[] colour = palette.getColour( 15 - "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) ) );
|
drawQuad( renderer, x - leftMarginSize, y, leftMarginSize, height, palette, greyscale, backgroundColour.charAt( 0 ) );
|
||||||
float r, g, b;
|
|
||||||
if( greyscale )
|
|
||||||
{
|
|
||||||
r = g = b = toGreyscale( colour );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = (float) colour[0];
|
|
||||||
g = (float) colour[1];
|
|
||||||
b = (float) colour[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
drawQuad( transform, renderer, x - leftMarginSize, y, leftMarginSize, height, r, g, b );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( rightMarginSize > 0 )
|
if( rightMarginSize > 0 )
|
||||||
{
|
{
|
||||||
double[] colour = palette.getColour( 15 - "0123456789abcdef".indexOf( backgroundColour.charAt( backgroundColour.length() - 1 ) ) );
|
drawQuad( renderer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, palette, greyscale, backgroundColour.charAt( backgroundColour.length() - 1 ) );
|
||||||
float r, g, b;
|
|
||||||
if( greyscale )
|
|
||||||
{
|
|
||||||
r = g = b = toGreyscale( colour );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = (float) colour[0];
|
|
||||||
g = (float) colour[1];
|
|
||||||
b = (float) colour[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
drawQuad( transform, renderer, x + backgroundColour.length() * FONT_WIDTH, y, rightMarginSize, height, r, g, b );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Batch together runs of identical background cells.
|
||||||
|
int blockStart = 0;
|
||||||
|
char blockColour = '\0';
|
||||||
for( int i = 0; i < backgroundColour.length(); i++ )
|
for( int i = 0; i < backgroundColour.length(); i++ )
|
||||||
{
|
{
|
||||||
double[] colour = palette.getColour( 15 - "0123456789abcdef".indexOf( backgroundColour.charAt( i ) ) );
|
char colourIndex = backgroundColour.charAt( i );
|
||||||
float r, g, b;
|
if( colourIndex == blockColour ) continue;
|
||||||
if( greyscale )
|
|
||||||
|
if( blockColour != '\0' )
|
||||||
{
|
{
|
||||||
r = g = b = toGreyscale( colour );
|
drawQuad( renderer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (i - blockStart), height, palette, greyscale, blockColour );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
r = (float) colour[0];
|
|
||||||
g = (float) colour[1];
|
|
||||||
b = (float) colour[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
drawQuad( transform, renderer, x + i * FONT_WIDTH, y, FONT_WIDTH, height, r, g, b );
|
blockColour = colourIndex;
|
||||||
|
blockStart = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( blockColour != '\0' )
|
||||||
|
{
|
||||||
|
drawQuad( renderer, x + blockStart * FONT_WIDTH, y, FONT_WIDTH * (backgroundColour.length() - blockStart), height, palette, greyscale, blockColour );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawString(
|
public static void drawString(
|
||||||
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder renderer, float x, float y,
|
@Nonnull BufferBuilder renderer, float x, float y,
|
||||||
@Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour,
|
@Nonnull TextBuffer text, @Nonnull TextBuffer textColour, @Nullable TextBuffer backgroundColour,
|
||||||
@Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize
|
@Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if( backgroundColour != null )
|
if( backgroundColour != null )
|
||||||
{
|
{
|
||||||
drawBackground( transform, renderer, x, y, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize, FONT_HEIGHT );
|
drawBackground( renderer, x, y, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize, FONT_HEIGHT );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < text.length(); i++ )
|
for( int i = 0; i < text.length(); i++ )
|
||||||
{
|
{
|
||||||
double[] colour = palette.getColour( 15 - "0123456789abcdef".indexOf( textColour.charAt( i ) ) );
|
double[] colour = palette.getColour( getColour( textColour.charAt( i ), Colour.White ) );
|
||||||
float r, g, b;
|
float r, g, b;
|
||||||
if( greyscale )
|
if( greyscale )
|
||||||
{
|
{
|
||||||
@@ -162,7 +175,7 @@ public final class FixedWidthFontRenderer
|
|||||||
// Draw char
|
// Draw char
|
||||||
int index = text.charAt( i );
|
int index = text.charAt( i );
|
||||||
if( index > 255 ) index = '?';
|
if( index > 255 ) index = '?';
|
||||||
drawChar( transform, renderer, x + i * FONT_WIDTH, y, index, r, g, b );
|
drawChar( renderer, x + i * FONT_WIDTH, y, index, r, g, b );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -172,16 +185,17 @@ public final class FixedWidthFontRenderer
|
|||||||
@Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize
|
@Nonnull Palette palette, boolean greyscale, float leftMarginSize, float rightMarginSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( FONT );
|
bindFont();
|
||||||
// TODO: RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
|
||||||
|
|
||||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
drawString( IDENTITY, ((IRenderTypeBuffer) renderer).getBuffer( TYPE ), x, y, text, textColour, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize );
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
renderer.finish();
|
begin( buffer );
|
||||||
|
drawString( buffer, x, y, text, textColour, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize );
|
||||||
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminalWithoutCursor(
|
public static void drawTerminalWithoutCursor(
|
||||||
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y,
|
@Nonnull BufferBuilder buffer, float x, float y,
|
||||||
@Nonnull Terminal terminal, boolean greyscale,
|
@Nonnull Terminal terminal, boolean greyscale,
|
||||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
)
|
)
|
||||||
@@ -191,13 +205,13 @@ public final class FixedWidthFontRenderer
|
|||||||
|
|
||||||
// Top and bottom margins
|
// Top and bottom margins
|
||||||
drawBackground(
|
drawBackground(
|
||||||
transform, buffer, x, y - topMarginSize,
|
buffer, x, y - topMarginSize,
|
||||||
terminal.getBackgroundColourLine( 0 ), palette, greyscale,
|
terminal.getBackgroundColourLine( 0 ), palette, greyscale,
|
||||||
leftMarginSize, rightMarginSize, topMarginSize
|
leftMarginSize, rightMarginSize, topMarginSize
|
||||||
);
|
);
|
||||||
|
|
||||||
drawBackground(
|
drawBackground(
|
||||||
transform, buffer, x, y + height * FONT_HEIGHT,
|
buffer, x, y + height * FONT_HEIGHT,
|
||||||
terminal.getBackgroundColourLine( height - 1 ), palette, greyscale,
|
terminal.getBackgroundColourLine( height - 1 ), palette, greyscale,
|
||||||
leftMarginSize, rightMarginSize, bottomMarginSize
|
leftMarginSize, rightMarginSize, bottomMarginSize
|
||||||
);
|
);
|
||||||
@@ -206,7 +220,7 @@ public final class FixedWidthFontRenderer
|
|||||||
for( int i = 0; i < height; i++ )
|
for( int i = 0; i < height; i++ )
|
||||||
{
|
{
|
||||||
drawString(
|
drawString(
|
||||||
transform, buffer, x, y + FixedWidthFontRenderer.FONT_HEIGHT * i,
|
buffer, x, y + FixedWidthFontRenderer.FONT_HEIGHT * i,
|
||||||
terminal.getLine( i ), terminal.getTextColourLine( i ), terminal.getBackgroundColourLine( i ),
|
terminal.getLine( i ), terminal.getTextColourLine( i ), terminal.getBackgroundColourLine( i ),
|
||||||
palette, greyscale, leftMarginSize, rightMarginSize
|
palette, greyscale, leftMarginSize, rightMarginSize
|
||||||
);
|
);
|
||||||
@@ -214,7 +228,7 @@ public final class FixedWidthFontRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void drawCursor(
|
public static void drawCursor(
|
||||||
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y,
|
@Nonnull BufferBuilder buffer, float x, float y,
|
||||||
@Nonnull Terminal terminal, boolean greyscale
|
@Nonnull Terminal terminal, boolean greyscale
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@@ -239,18 +253,18 @@ public final class FixedWidthFontRenderer
|
|||||||
b = (float) colour[2];
|
b = (float) colour[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
drawChar( transform, buffer, x + cursorX * FONT_WIDTH, y + cursorY * FONT_HEIGHT, '_', r, g, b );
|
drawChar( buffer, x + cursorX * FONT_WIDTH, y + cursorY * FONT_HEIGHT, '_', r, g, b );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminal(
|
public static void drawTerminal(
|
||||||
@Nonnull Matrix4f transform, @Nonnull IVertexBuilder buffer, float x, float y,
|
@Nonnull BufferBuilder buffer, float x, float y,
|
||||||
@Nonnull Terminal terminal, boolean greyscale,
|
@Nonnull Terminal terminal, boolean greyscale,
|
||||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
drawTerminalWithoutCursor( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
drawTerminalWithoutCursor( buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||||
drawCursor( transform, buffer, x, y, terminal, greyscale );
|
drawCursor( buffer, x, y, terminal, greyscale );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawTerminal(
|
public static void drawTerminal(
|
||||||
@@ -258,69 +272,56 @@ public final class FixedWidthFontRenderer
|
|||||||
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
float topMarginSize, float bottomMarginSize, float leftMarginSize, float rightMarginSize
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( FONT );
|
bindFont();
|
||||||
// TODO: Is this the most sane thing?
|
|
||||||
RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
|
||||||
|
|
||||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
IVertexBuilder buffer = renderer.getBuffer( TYPE );
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
drawTerminal( IDENTITY, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
begin( buffer );
|
||||||
renderer.finish( TYPE );
|
drawTerminal( buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||||
}
|
tessellator.draw();
|
||||||
|
|
||||||
public static void drawEmptyTerminal( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height )
|
|
||||||
{
|
|
||||||
Colour colour = Colour.Black;
|
|
||||||
drawQuad( transform, renderer.getBuffer( TYPE ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawEmptyTerminal( float x, float y, float width, float height )
|
public static void drawEmptyTerminal( float x, float y, float width, float height )
|
||||||
{
|
{
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( FONT );
|
bindFont();
|
||||||
RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
|
||||||
|
|
||||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
drawEmptyTerminal( IDENTITY, renderer, x, y, width, height );
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
renderer.finish();
|
begin( buffer );
|
||||||
|
|
||||||
|
Colour colour = Colour.Black;
|
||||||
|
drawQuad( buffer, x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void drawBlocker( @Nonnull Matrix4f transform, @Nonnull IRenderTypeBuffer renderer, float x, float y, float width, float height )
|
public static void drawBlocker( @Nonnull BufferBuilder buffer, float x, float y, float width, float height )
|
||||||
{
|
{
|
||||||
Colour colour = Colour.Black;
|
Colour colour = Colour.Black;
|
||||||
drawQuad( transform, renderer.getBuffer( Type.BLOCKER ), x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
drawQuad( buffer, x, y, width, height, colour.getR(), colour.getG(), colour.getB() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class Type extends RenderState
|
public static void drawBlocker( float x, float y, float width, float height )
|
||||||
{
|
{
|
||||||
private static final int GL_MODE = GL11.GL_TRIANGLES;
|
bindFont();
|
||||||
|
|
||||||
private static final VertexFormat FORMAT = DefaultVertexFormats.POSITION_COLOR_TEX;
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
begin( buffer );
|
||||||
|
drawBlocker( buffer, x, y, width, height );
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
static final RenderType MAIN = RenderType.get(
|
public static void bindFont()
|
||||||
"terminal_font", FORMAT, GL_MODE, 1024,
|
{
|
||||||
false, false, // useDelegate, needsSorting
|
Minecraft.getMinecraft().getTextureManager().bindTexture( FONT );
|
||||||
RenderType.State.builder()
|
GlStateManager.glTexParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||||
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
|
||||||
.alpha( DEFAULT_ALPHA )
|
|
||||||
.lightmap( LIGHTMAP_DISABLED )
|
|
||||||
.writeMask( COLOR_WRITE )
|
|
||||||
.build( false )
|
|
||||||
);
|
|
||||||
|
|
||||||
static final RenderType BLOCKER = RenderType.get(
|
GlStateManager.enableTexture2D();
|
||||||
"terminal_blocker", FORMAT, GL_MODE, 256,
|
}
|
||||||
false, false, // useDelegate, needsSorting
|
|
||||||
RenderType.State.builder()
|
|
||||||
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
|
||||||
.alpha( DEFAULT_ALPHA )
|
|
||||||
.writeMask( DEPTH_WRITE )
|
|
||||||
.lightmap( LIGHTMAP_DISABLED )
|
|
||||||
.build( false )
|
|
||||||
);
|
|
||||||
|
|
||||||
private Type( String name, Runnable setup, Runnable destroy )
|
public static void begin( BufferBuilder buffer )
|
||||||
{
|
{
|
||||||
super( name, setup, destroy );
|
buffer.begin( GL11.GL_TRIANGLES, POSITION_COLOR_TEX );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,25 +5,25 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
|
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
|
import dan200.computercraft.shared.computer.core.IComputer;
|
||||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||||
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
public final class GuiComputer<T extends ContainerComputerBase> extends ContainerScreen<T>
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class GuiComputer extends GuiContainer
|
||||||
{
|
{
|
||||||
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" );
|
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners.png" );
|
||||||
public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" );
|
public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" );
|
||||||
public static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" );
|
public static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" );
|
||||||
public static final ResourceLocation BACKGROUND_COLOUR = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_colour.png" );
|
public static final ResourceLocation BACKGROUND_COLOUR = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_colour.png" );
|
||||||
@@ -32,147 +32,151 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Containe
|
|||||||
private final ClientComputer m_computer;
|
private final ClientComputer m_computer;
|
||||||
private final int m_termWidth;
|
private final int m_termWidth;
|
||||||
private final int m_termHeight;
|
private final int m_termHeight;
|
||||||
|
private WidgetTerminal m_terminal;
|
||||||
|
|
||||||
private WidgetTerminal terminal;
|
public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
||||||
private WidgetWrapper terminalWrapper;
|
|
||||||
|
|
||||||
private GuiComputer(
|
|
||||||
T container, PlayerInventory player, ITextComponent title, int termWidth, int termHeight
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
super( container, player, title );
|
super( container );
|
||||||
m_family = container.getFamily();
|
m_family = family;
|
||||||
m_computer = (ClientComputer) container.getComputer();
|
m_computer = computer;
|
||||||
m_termWidth = termWidth;
|
m_termWidth = termWidth;
|
||||||
m_termHeight = termHeight;
|
m_termHeight = termHeight;
|
||||||
terminal = null;
|
m_terminal = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GuiComputer<ContainerComputer> create( ContainerComputer container, PlayerInventory inventory, ITextComponent component )
|
@Deprecated
|
||||||
|
public GuiComputer( Container container, ComputerFamily family, IComputer computer, int termWidth, int termHeight )
|
||||||
{
|
{
|
||||||
return new GuiComputer<>(
|
this( container, family, (ClientComputer) computer, termWidth, termHeight );
|
||||||
container, inventory, component,
|
}
|
||||||
ComputerCraft.terminalWidth_computer, ComputerCraft.terminalHeight_computer
|
|
||||||
|
public GuiComputer( TileComputer computer )
|
||||||
|
{
|
||||||
|
this(
|
||||||
|
new ContainerComputer( computer ),
|
||||||
|
computer.getFamily(),
|
||||||
|
computer.createClientComputer(),
|
||||||
|
ComputerCraft.terminalWidth_computer,
|
||||||
|
ComputerCraft.terminalHeight_computer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GuiComputer<ContainerPocketComputer> createPocket( ContainerPocketComputer container, PlayerInventory inventory, ITextComponent component )
|
|
||||||
{
|
|
||||||
return new GuiComputer<>(
|
|
||||||
container, inventory, component,
|
|
||||||
ComputerCraft.terminalWidth_pocketComputer, ComputerCraft.terminalHeight_pocketComputer
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GuiComputer<ContainerViewComputer> createView( ContainerViewComputer container, PlayerInventory inventory, ITextComponent component )
|
|
||||||
{
|
|
||||||
return new GuiComputer<>(
|
|
||||||
container, inventory, component,
|
|
||||||
container.getWidth(), container.getHeight()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init()
|
public void initGui()
|
||||||
{
|
{
|
||||||
minecraft.keyboardListener.enableRepeatEvents( true );
|
super.initGui();
|
||||||
|
Keyboard.enableRepeatEvents( true );
|
||||||
|
|
||||||
int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
m_terminal = new WidgetTerminal( 0, 0, m_termWidth, m_termHeight, () -> m_computer, 2, 2, 2, 2 );
|
||||||
int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
m_terminal.setAllowFocusLoss( false );
|
||||||
|
xSize = m_terminal.getWidth() + 24;
|
||||||
xSize = termPxWidth + 4 + 24;
|
ySize = m_terminal.getHeight() + 24;
|
||||||
ySize = termPxHeight + 4 + 24;
|
|
||||||
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
terminal = new WidgetTerminal( minecraft, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
|
|
||||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight );
|
|
||||||
|
|
||||||
children.add( terminalWrapper );
|
|
||||||
setFocused( terminalWrapper );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removed()
|
public void onGuiClosed()
|
||||||
{
|
{
|
||||||
super.removed();
|
super.onGuiClosed();
|
||||||
children.remove( terminal );
|
Keyboard.enableRepeatEvents( false );
|
||||||
terminal = null;
|
|
||||||
minecraft.keyboardListener.enableRepeatEvents( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void updateScreen()
|
||||||
{
|
{
|
||||||
super.tick();
|
super.updateScreen();
|
||||||
terminal.update();
|
m_terminal.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
protected void keyTyped( char c, int k ) throws IOException
|
||||||
{
|
{
|
||||||
// Forward the tab key to the terminal, rather than moving between controls.
|
if( k == 1 )
|
||||||
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper )
|
|
||||||
{
|
{
|
||||||
return getFocused().keyPressed( key, scancode, modifiers );
|
super.keyTyped( c, k );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_terminal.onKeyTyped( c, k ) ) keyHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.keyPressed( key, scancode, modifiers );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void mouseClicked( int x, int y, int button )
|
||||||
|
{
|
||||||
|
int startX = (width - m_terminal.getWidth()) / 2;
|
||||||
|
int startY = (height - m_terminal.getHeight()) / 2;
|
||||||
|
m_terminal.mouseClicked( x - startX, y - startY, button );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMouseInput() throws IOException
|
||||||
|
{
|
||||||
|
super.handleMouseInput();
|
||||||
|
|
||||||
|
int x = Mouse.getEventX() * width / mc.displayWidth;
|
||||||
|
int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
|
||||||
|
int startX = (width - m_terminal.getWidth()) / 2;
|
||||||
|
int startY = (height - m_terminal.getHeight()) / 2;
|
||||||
|
m_terminal.handleMouseInput( x - startX, y - startY );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleKeyboardInput() throws IOException
|
||||||
|
{
|
||||||
|
super.handleKeyboardInput();
|
||||||
|
if( m_terminal.onKeyboardInput() ) keyHandled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawGuiContainerForegroundLayer( int par1, int par2 )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void drawGuiContainerBackgroundLayer( float var1, int var2, int var3 )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
// Work out where to draw
|
// Work out where to draw
|
||||||
int startX = terminalWrapper.getX() - 2;
|
int startX = (width - m_terminal.getWidth()) / 2;
|
||||||
int startY = terminalWrapper.getY() - 2;
|
int startY = (height - m_terminal.getHeight()) / 2;
|
||||||
int endX = startX + terminalWrapper.getWidth() + 4;
|
int endX = startX + m_terminal.getWidth();
|
||||||
int endY = startY + terminalWrapper.getHeight() + 4;
|
int endY = startY + m_terminal.getHeight();
|
||||||
|
|
||||||
|
// Draw background
|
||||||
|
drawDefaultBackground();
|
||||||
|
|
||||||
// Draw terminal
|
// Draw terminal
|
||||||
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
|
m_terminal.draw( mc, startX, startY, mouseX, mouseY );
|
||||||
|
|
||||||
// Draw a border around the terminal
|
// Draw a border around the terminal
|
||||||
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
switch( m_family )
|
switch( m_family )
|
||||||
{
|
{
|
||||||
case Normal:
|
case Normal:
|
||||||
default:
|
default:
|
||||||
minecraft.getTextureManager().bindTexture( BACKGROUND_NORMAL );
|
mc.getTextureManager().bindTexture( BACKGROUND_NORMAL );
|
||||||
break;
|
break;
|
||||||
case Advanced:
|
case Advanced:
|
||||||
minecraft.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
|
mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
|
||||||
break;
|
break;
|
||||||
case Command:
|
case Command:
|
||||||
minecraft.getTextureManager().bindTexture( BACKGROUND_COMMAND );
|
mc.getTextureManager().bindTexture( BACKGROUND_COMMAND );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
blit( startX - 12, startY - 12, 12, 28, 12, 12 );
|
drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 );
|
||||||
blit( startX - 12, endY, 12, 40, 12, 12 );
|
drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 12 );
|
||||||
blit( endX, startY - 12, 24, 28, 12, 12 );
|
drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 );
|
||||||
blit( endX, endY, 24, 40, 12, 12 );
|
drawTexturedModalRect( endX, endY, 24, 40, 12, 12 );
|
||||||
|
|
||||||
blit( startX, startY - 12, 0, 0, endX - startX, 12 );
|
drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 );
|
||||||
blit( startX, endY, 0, 12, endX - startX, 12 );
|
drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 12 );
|
||||||
|
|
||||||
blit( startX - 12, startY, 0, 28, 12, endY - startY );
|
drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
|
||||||
blit( endX, startY, 36, 28, 12, endY - startY );
|
drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY );
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
|
||||||
{
|
|
||||||
renderBackground();
|
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
|
|
||||||
{
|
|
||||||
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|
|
||||||
|| super.mouseDragged( x, y, button, deltaX, deltaY );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.shared.Config;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraftforge.fml.client.IModGuiFactory;
|
||||||
|
import net.minecraftforge.fml.client.config.GuiConfig;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class GuiConfigCC extends GuiConfig
|
||||||
|
{
|
||||||
|
public GuiConfigCC( GuiScreen parentScreen )
|
||||||
|
{
|
||||||
|
super( parentScreen, Config.getConfigElements(), ComputerCraft.MOD_ID, false, false, "CC: Tweaked" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory implements IModGuiFactory
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void initialize( Minecraft minecraft )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasConfigGui()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GuiScreen createConfigGui( GuiScreen parentScreen )
|
||||||
|
{
|
||||||
|
return new GuiConfigCC( parentScreen );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,43 +5,45 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
|
|
||||||
public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
|
public class GuiDiskDrive extends GuiContainer
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
|
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/diskdrive.png" );
|
||||||
|
|
||||||
public GuiDiskDrive( ContainerDiskDrive container, PlayerInventory player, ITextComponent title )
|
private final ContainerDiskDrive m_container;
|
||||||
|
|
||||||
|
public GuiDiskDrive( ContainerDiskDrive container )
|
||||||
{
|
{
|
||||||
super( container, player, title );
|
super( container );
|
||||||
|
m_container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
String title = this.title.getFormattedText();
|
String title = m_container.getDiskDrive().getDisplayName().getUnformattedText();
|
||||||
font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
|
||||||
font.drawString( title, 8, ySize - 96 + 2, 0x404040 );
|
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
mc.getTextureManager().bindTexture( BACKGROUND );
|
||||||
blit( guiLeft, guiTop, 0, 0, xSize, ySize );
|
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
renderBackground();
|
drawDefaultBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
||||||
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
|
|
||||||
|
public class GuiPocketComputer extends GuiComputer
|
||||||
|
{
|
||||||
|
public GuiPocketComputer( ContainerHeldItem container )
|
||||||
|
{
|
||||||
|
super(
|
||||||
|
container,
|
||||||
|
ComputerCraft.Items.pocketComputer.getFamily( container.getStack() ),
|
||||||
|
ItemPocketComputer.createClientComputer( container.getStack() ),
|
||||||
|
ComputerCraft.terminalWidth_pocketComputer,
|
||||||
|
ComputerCraft.terminalHeight_pocketComputer
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,46 +5,47 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
|
|
||||||
public class GuiPrinter extends ContainerScreen<ContainerPrinter>
|
public class GuiPrinter extends GuiContainer
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
||||||
|
|
||||||
public GuiPrinter( ContainerPrinter container, PlayerInventory player, ITextComponent title )
|
private final ContainerPrinter container;
|
||||||
|
|
||||||
|
public GuiPrinter( ContainerPrinter container )
|
||||||
{
|
{
|
||||||
super( container, player, title );
|
super( container );
|
||||||
|
this.container = container;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
String title = getTitle().getFormattedText();
|
String title = container.getPrinter().getDisplayName().getUnformattedText();
|
||||||
font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
|
||||||
font.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
mc.getTextureManager().bindTexture( BACKGROUND );
|
||||||
blit( guiLeft, guiTop, 0, 0, xSize, ySize );
|
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||||
|
|
||||||
if( getContainer().isPrinting() ) blit( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 );
|
if( container.isPrinting() ) drawTexturedModalRect( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
renderBackground();
|
drawDefaultBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,18 +5,18 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
||||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import org.lwjgl.input.Mouse;
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||||
|
|
||||||
public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
public class GuiPrintout extends GuiContainer
|
||||||
{
|
{
|
||||||
private final boolean m_book;
|
private final boolean m_book;
|
||||||
private final int m_pages;
|
private final int m_pages;
|
||||||
@@ -24,9 +24,9 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
|||||||
private final TextBuffer[] m_colours;
|
private final TextBuffer[] m_colours;
|
||||||
private int m_page;
|
private int m_page;
|
||||||
|
|
||||||
public GuiPrintout( ContainerHeldItem container, PlayerInventory player, ITextComponent title )
|
public GuiPrintout( ContainerHeldItem container )
|
||||||
{
|
{
|
||||||
super( container, player, title );
|
super( container );
|
||||||
|
|
||||||
ySize = Y_SIZE;
|
ySize = Y_SIZE;
|
||||||
|
|
||||||
@@ -40,70 +40,63 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
|||||||
|
|
||||||
m_page = 0;
|
m_page = 0;
|
||||||
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
||||||
m_book = ((ItemPrintout) container.getStack().getItem()).getType() == ItemPrintout.Type.BOOK;
|
m_book = ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
protected void keyTyped( char c, int k ) throws IOException
|
||||||
{
|
{
|
||||||
if( super.keyPressed( key, scancode, modifiers ) ) return true;
|
super.keyTyped( c, k );
|
||||||
|
|
||||||
if( key == GLFW.GLFW_KEY_RIGHT )
|
if( k == 205 )
|
||||||
{
|
{
|
||||||
|
// Right
|
||||||
if( m_page < m_pages - 1 ) m_page++;
|
if( m_page < m_pages - 1 ) m_page++;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
else if( k == 203 )
|
||||||
if( key == GLFW.GLFW_KEY_LEFT )
|
|
||||||
{
|
{
|
||||||
|
// Left
|
||||||
if( m_page > 0 ) m_page--;
|
if( m_page > 0 ) m_page--;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled( double x, double y, double delta )
|
public void handleMouseInput() throws IOException
|
||||||
{
|
{
|
||||||
if( super.mouseScrolled( x, y, delta ) ) return true;
|
super.handleMouseInput();
|
||||||
if( delta < 0 )
|
|
||||||
|
int mouseWheelChange = Mouse.getEventDWheel();
|
||||||
|
if( mouseWheelChange < 0 )
|
||||||
{
|
{
|
||||||
// Scroll up goes to the next page
|
// Scroll up goes to the next page
|
||||||
if( m_page < m_pages - 1 ) m_page++;
|
if( m_page < m_pages - 1 ) m_page++;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
else if( mouseWheelChange > 0 )
|
||||||
if( delta > 0 )
|
|
||||||
{
|
{
|
||||||
// Scroll down goes to the previous page
|
// Scroll down goes to the previous page
|
||||||
if( m_page > 0 ) m_page--;
|
if( m_page > 0 ) m_page--;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
// Draw the printout
|
// Draw the printout
|
||||||
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
RenderSystem.enableDepthTest();
|
|
||||||
|
|
||||||
drawBorder( guiLeft, guiTop, getBlitOffset(), m_page, m_pages, m_book );
|
drawBorder( guiLeft, guiTop, zLevel, m_page, m_pages, m_book );
|
||||||
drawText( guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours );
|
drawText( guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
// We must take the background further back in order to not overlap with our printed pages.
|
// We must take the background further back in order to not overlap with our printed pages.
|
||||||
setBlitOffset( getBlitOffset() - 1 );
|
zLevel--;
|
||||||
renderBackground();
|
drawDefaultBackground();
|
||||||
setBlitOffset( getBlitOffset() + 1 );
|
zLevel++;
|
||||||
|
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,104 +5,121 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||||
import dan200.computercraft.client.gui.widgets.WidgetWrapper;
|
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import org.lwjgl.input.Keyboard;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class GuiTurtle extends GuiContainer
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" );
|
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle.png" );
|
||||||
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
|
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
|
||||||
|
|
||||||
private ContainerTurtle m_container;
|
private ContainerTurtle m_container;
|
||||||
|
|
||||||
private final ComputerFamily m_family;
|
private final ComputerFamily m_family;
|
||||||
private final ClientComputer m_computer;
|
private final ClientComputer m_computer;
|
||||||
|
private WidgetTerminal m_terminalGui;
|
||||||
|
|
||||||
private WidgetTerminal terminal;
|
public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
|
||||||
private WidgetWrapper terminalWrapper;
|
|
||||||
|
|
||||||
public GuiTurtle( ContainerTurtle container, PlayerInventory player, ITextComponent title )
|
|
||||||
{
|
{
|
||||||
super( container, player, title );
|
super( container );
|
||||||
|
|
||||||
m_container = container;
|
m_container = container;
|
||||||
m_family = container.getFamily();
|
m_family = turtle.getFamily();
|
||||||
m_computer = (ClientComputer) container.getComputer();
|
m_computer = turtle.getClientComputer();
|
||||||
|
|
||||||
xSize = 254;
|
xSize = 254;
|
||||||
ySize = 217;
|
ySize = 217;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void init()
|
public void initGui()
|
||||||
{
|
{
|
||||||
super.init();
|
super.initGui();
|
||||||
minecraft.keyboardListener.enableRepeatEvents( true );
|
Keyboard.enableRepeatEvents( true );
|
||||||
|
m_terminalGui = new WidgetTerminal(
|
||||||
int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
|
guiLeft + 8,
|
||||||
int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
|
guiTop + 8,
|
||||||
|
|
||||||
terminal = new WidgetTerminal(
|
|
||||||
minecraft, () -> m_computer,
|
|
||||||
ComputerCraft.terminalWidth_turtle,
|
ComputerCraft.terminalWidth_turtle,
|
||||||
ComputerCraft.terminalHeight_turtle,
|
ComputerCraft.terminalHeight_turtle,
|
||||||
|
() -> m_computer,
|
||||||
2, 2, 2, 2
|
2, 2, 2, 2
|
||||||
);
|
);
|
||||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + guiLeft, 2 + 8 + guiTop, termPxWidth, termPxHeight );
|
m_terminalGui.setAllowFocusLoss( false );
|
||||||
|
|
||||||
children.add( terminalWrapper );
|
|
||||||
setFocused( terminalWrapper );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removed()
|
public void onGuiClosed()
|
||||||
{
|
{
|
||||||
super.removed();
|
super.onGuiClosed();
|
||||||
children.remove( terminal );
|
Keyboard.enableRepeatEvents( false );
|
||||||
terminal = null;
|
|
||||||
minecraft.keyboardListener.enableRepeatEvents( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void updateScreen()
|
||||||
{
|
{
|
||||||
super.tick();
|
super.updateScreen();
|
||||||
terminal.update();
|
m_terminalGui.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
protected void keyTyped( char c, int k ) throws IOException
|
||||||
{
|
{
|
||||||
// Forward the tab key to the terminal, rather than moving between controls.
|
if( k == 1 )
|
||||||
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper )
|
|
||||||
{
|
{
|
||||||
return getFocused().keyPressed( key, scancode, modifiers );
|
super.keyTyped( c, k );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_terminalGui.onKeyTyped( c, k ) ) keyHandled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.keyPressed( key, scancode, modifiers );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawSelectionSlot( boolean advanced )
|
@Override
|
||||||
|
protected void mouseClicked( int x, int y, int button ) throws IOException
|
||||||
|
{
|
||||||
|
super.mouseClicked( x, y, button );
|
||||||
|
m_terminalGui.mouseClicked( x, y, button );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMouseInput() throws IOException
|
||||||
|
{
|
||||||
|
super.handleMouseInput();
|
||||||
|
int x = Mouse.getEventX() * width / mc.displayWidth;
|
||||||
|
int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
|
||||||
|
m_terminalGui.handleMouseInput( x, y );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleKeyboardInput() throws IOException
|
||||||
|
{
|
||||||
|
super.handleKeyboardInput();
|
||||||
|
if( m_terminalGui.onKeyboardInput() ) keyHandled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawSelectionSlot( boolean advanced )
|
||||||
{
|
{
|
||||||
// Draw selection slot
|
// Draw selection slot
|
||||||
int slot = m_container.getSelectedSlot();
|
int slot = m_container.getSelectedSlot();
|
||||||
if( slot >= 0 )
|
if( slot >= 0 )
|
||||||
{
|
{
|
||||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
int slotX = slot % 4;
|
int slotX = slot % 4;
|
||||||
int slotY = slot / 4;
|
int slotY = slot / 4;
|
||||||
minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||||
blit( guiLeft + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18, guiTop + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18, 0, 217, 24, 24 );
|
drawTexturedModalRect( guiLeft + m_container.turtleInvStartX - 2 + slotX * 18, guiTop + m_container.playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,28 +128,21 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
|||||||
{
|
{
|
||||||
// Draw term
|
// Draw term
|
||||||
boolean advanced = m_family == ComputerFamily.Advanced;
|
boolean advanced = m_family == ComputerFamily.Advanced;
|
||||||
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
|
m_terminalGui.draw( Minecraft.getMinecraft(), 0, 0, mouseX, mouseY );
|
||||||
|
|
||||||
// Draw border/inventory
|
// Draw border/inventory
|
||||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||||
blit( guiLeft, guiTop, 0, 0, xSize, ySize );
|
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||||
|
|
||||||
drawSelectionSlot( advanced );
|
drawSelectionSlot( advanced );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
renderBackground();
|
drawDefaultBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
|
|
||||||
{
|
|
||||||
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|
|
||||||
|| super.mouseDragged( x, y, button, deltaX, deltaY );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.gui.widgets;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.Gui;
|
||||||
|
|
||||||
|
public abstract class Widget extends Gui
|
||||||
|
{
|
||||||
|
private int m_xPosition;
|
||||||
|
private int m_yPosition;
|
||||||
|
private int m_width;
|
||||||
|
private int m_height;
|
||||||
|
|
||||||
|
protected Widget( int x, int y, int width, int height )
|
||||||
|
{
|
||||||
|
m_xPosition = x;
|
||||||
|
m_yPosition = y;
|
||||||
|
m_width = width;
|
||||||
|
m_height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getXPosition()
|
||||||
|
{
|
||||||
|
return m_xPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYPosition()
|
||||||
|
{
|
||||||
|
return m_yPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth()
|
||||||
|
{
|
||||||
|
return m_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight()
|
||||||
|
{
|
||||||
|
return m_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleMouseInput( int mouseX, int mouseY )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onKeyboardInput()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void handleKeyboardInput()
|
||||||
|
{
|
||||||
|
onKeyboardInput();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked( int mouseX, int mouseY, int mouseButton )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onKeyTyped( char c, int k )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void keyTyped( char c, int k )
|
||||||
|
{
|
||||||
|
onKeyTyped( c, k );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,236 +7,133 @@ package dan200.computercraft.client.gui.widgets;
|
|||||||
|
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
|
||||||
import dan200.computercraft.shared.computer.core.IComputer;
|
import dan200.computercraft.shared.computer.core.IComputer;
|
||||||
|
import dan200.computercraft.shared.computer.core.IComputerContainer;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.IGuiEventListener;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.util.SharedConstants;
|
import net.minecraft.util.ChatAllowedCharacters;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.ArrayList;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
public class WidgetTerminal extends Widget
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
|
||||||
|
|
||||||
public class WidgetTerminal implements IGuiEventListener
|
|
||||||
{
|
{
|
||||||
private static final float TERMINATE_TIME = 0.5f;
|
private static final float TERMINATE_TIME = 0.5f;
|
||||||
|
|
||||||
private final Minecraft client;
|
private final IComputerContainer m_computer;
|
||||||
|
|
||||||
private boolean focused;
|
private float m_terminateTimer = 0.0f;
|
||||||
|
private float m_rebootTimer = 0.0f;
|
||||||
|
private float m_shutdownTimer = 0.0f;
|
||||||
|
|
||||||
private final Supplier<ClientComputer> computer;
|
private int m_lastClickButton = -1;
|
||||||
private final int termWidth;
|
private int m_lastClickX = -1;
|
||||||
private final int termHeight;
|
private int m_lastClickY = -1;
|
||||||
|
|
||||||
private float terminateTimer = -1;
|
private boolean m_focus = false;
|
||||||
private float rebootTimer = -1;
|
private boolean m_allowFocusLoss = true;
|
||||||
private float shutdownTimer = -1;
|
|
||||||
|
|
||||||
private int lastMouseButton = -1;
|
|
||||||
private int lastMouseX = -1;
|
|
||||||
private int lastMouseY = -1;
|
|
||||||
|
|
||||||
private final int leftMargin;
|
private final int leftMargin;
|
||||||
private final int rightMargin;
|
private final int rightMargin;
|
||||||
private final int topMargin;
|
private final int topMargin;
|
||||||
private final int bottomMargin;
|
private final int bottomMargin;
|
||||||
|
|
||||||
private final BitSet keysDown = new BitSet( 256 );
|
private final ArrayList<Integer> m_keysDown = new ArrayList<>();
|
||||||
|
|
||||||
public WidgetTerminal( Minecraft client, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
public WidgetTerminal( int x, int y, int termWidth, int termHeight, IComputerContainer computer, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
||||||
{
|
{
|
||||||
this.client = client;
|
super(
|
||||||
this.computer = computer;
|
x, y,
|
||||||
this.termWidth = termWidth;
|
leftMargin + rightMargin + termWidth * FixedWidthFontRenderer.FONT_WIDTH,
|
||||||
this.termHeight = termHeight;
|
topMargin + bottomMargin + termHeight * FixedWidthFontRenderer.FONT_HEIGHT
|
||||||
|
);
|
||||||
|
|
||||||
|
m_computer = computer;
|
||||||
|
|
||||||
this.leftMargin = leftMargin;
|
this.leftMargin = leftMargin;
|
||||||
this.rightMargin = rightMargin;
|
this.rightMargin = rightMargin;
|
||||||
this.topMargin = topMargin;
|
this.topMargin = topMargin;
|
||||||
this.bottomMargin = bottomMargin;
|
this.bottomMargin = bottomMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setAllowFocusLoss( boolean allowFocusLoss )
|
||||||
public boolean charTyped( char ch, int modifiers )
|
|
||||||
{
|
{
|
||||||
if( ch >= 32 && ch <= 126 || ch >= 160 && ch <= 255 ) // printable chars in byte range
|
m_allowFocusLoss = allowFocusLoss;
|
||||||
{
|
m_focus = m_focus || !allowFocusLoss;
|
||||||
// Queue the "char" event
|
|
||||||
queueEvent( "char", Character.toString( ch ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
public boolean onKeyTyped( char ch, int key )
|
||||||
{
|
{
|
||||||
if( key == GLFW.GLFW_KEY_ESCAPE ) return false;
|
if( m_focus )
|
||||||
if( (modifiers & GLFW.GLFW_MOD_CONTROL) != 0 )
|
|
||||||
{
|
{
|
||||||
switch( key )
|
// Ctrl+V for paste
|
||||||
|
if( ch == 22 )
|
||||||
{
|
{
|
||||||
case GLFW.GLFW_KEY_T:
|
String clipboard = GuiScreen.getClipboardString();
|
||||||
if( terminateTimer < 0 ) terminateTimer = 0;
|
if( clipboard != null )
|
||||||
return true;
|
{
|
||||||
case GLFW.GLFW_KEY_S:
|
// Clip to the first occurrence of \r or \n
|
||||||
if( shutdownTimer < 0 ) shutdownTimer = 0;
|
int newLineIndex1 = clipboard.indexOf( '\r' );
|
||||||
return true;
|
int newLineIndex2 = clipboard.indexOf( '\n' );
|
||||||
case GLFW.GLFW_KEY_R:
|
if( newLineIndex1 >= 0 && newLineIndex2 >= 0 )
|
||||||
if( rebootTimer < 0 ) rebootTimer = 0;
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case GLFW.GLFW_KEY_V:
|
|
||||||
// Ctrl+V for paste
|
|
||||||
String clipboard = client.keyboardListener.getClipboardString();
|
|
||||||
if( clipboard != null )
|
|
||||||
{
|
{
|
||||||
// Clip to the first occurrence of \r or \n
|
clipboard = clipboard.substring( 0, Math.min( newLineIndex1, newLineIndex2 ) );
|
||||||
int newLineIndex1 = clipboard.indexOf( "\r" );
|
}
|
||||||
int newLineIndex2 = clipboard.indexOf( "\n" );
|
else if( newLineIndex1 >= 0 )
|
||||||
if( newLineIndex1 >= 0 && newLineIndex2 >= 0 )
|
{
|
||||||
{
|
clipboard = clipboard.substring( 0, newLineIndex1 );
|
||||||
clipboard = clipboard.substring( 0, Math.min( newLineIndex1, newLineIndex2 ) );
|
}
|
||||||
}
|
else if( newLineIndex2 >= 0 )
|
||||||
else if( newLineIndex1 >= 0 )
|
{
|
||||||
{
|
clipboard = clipboard.substring( 0, newLineIndex2 );
|
||||||
clipboard = clipboard.substring( 0, newLineIndex1 );
|
|
||||||
}
|
|
||||||
else if( newLineIndex2 >= 0 )
|
|
||||||
{
|
|
||||||
clipboard = clipboard.substring( 0, newLineIndex2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter the string
|
|
||||||
clipboard = SharedConstants.filterAllowedCharacters( clipboard );
|
|
||||||
if( !clipboard.isEmpty() )
|
|
||||||
{
|
|
||||||
// Clip to 512 characters and queue the event
|
|
||||||
if( clipboard.length() > 512 ) clipboard = clipboard.substring( 0, 512 );
|
|
||||||
queueEvent( "paste", clipboard );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( key >= 0 && terminateTimer < 0 && rebootTimer < 0 && shutdownTimer < 0 )
|
// Filter the string
|
||||||
{
|
clipboard = ChatAllowedCharacters.filterAllowedCharacters( clipboard );
|
||||||
// Queue the "key" event and add to the down set
|
|
||||||
boolean repeat = keysDown.get( key );
|
|
||||||
keysDown.set( key );
|
|
||||||
IComputer computer = this.computer.get();
|
|
||||||
if( computer != null ) computer.keyDown( key, repeat );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
if( !clipboard.isEmpty() )
|
||||||
}
|
{
|
||||||
|
// Clip to 512 characters
|
||||||
|
if( clipboard.length() > 512 )
|
||||||
|
{
|
||||||
|
clipboard = clipboard.substring( 0, 512 );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
// Queue the "paste" event
|
||||||
public boolean keyReleased( int key, int scancode, int modifiers )
|
queueEvent( "paste", new Object[] { clipboard } );
|
||||||
{
|
}
|
||||||
// Queue the "key_up" event and remove from the down set
|
}
|
||||||
if( key >= 0 && keysDown.get( key ) )
|
return true;
|
||||||
{
|
|
||||||
keysDown.set( key, false );
|
|
||||||
IComputer computer = this.computer.get();
|
|
||||||
if( computer != null ) computer.keyUp( key );
|
|
||||||
}
|
|
||||||
|
|
||||||
switch( key )
|
|
||||||
{
|
|
||||||
case GLFW.GLFW_KEY_T:
|
|
||||||
terminateTimer = -1;
|
|
||||||
break;
|
|
||||||
case GLFW.GLFW_KEY_R:
|
|
||||||
rebootTimer = -1;
|
|
||||||
break;
|
|
||||||
case GLFW.GLFW_KEY_S:
|
|
||||||
shutdownTimer = -1;
|
|
||||||
break;
|
|
||||||
case GLFW.GLFW_KEY_LEFT_CONTROL:
|
|
||||||
case GLFW.GLFW_KEY_RIGHT_CONTROL:
|
|
||||||
terminateTimer = rebootTimer = shutdownTimer = -1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked( double mouseX, double mouseY, int button )
|
|
||||||
{
|
|
||||||
ClientComputer computer = this.computer.get();
|
|
||||||
if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
|
|
||||||
|
|
||||||
Terminal term = computer.getTerminal();
|
|
||||||
if( term != null )
|
|
||||||
{
|
|
||||||
int charX = (int) (mouseX / FONT_WIDTH);
|
|
||||||
int charY = (int) (mouseY / FONT_HEIGHT);
|
|
||||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
|
||||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
|
||||||
|
|
||||||
computer.mouseClick( button + 1, charX + 1, charY + 1 );
|
|
||||||
|
|
||||||
lastMouseButton = button;
|
|
||||||
lastMouseX = charX;
|
|
||||||
lastMouseY = charY;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseReleased( double mouseX, double mouseY, int button )
|
|
||||||
{
|
|
||||||
ClientComputer computer = this.computer.get();
|
|
||||||
if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
|
|
||||||
|
|
||||||
Terminal term = computer.getTerminal();
|
|
||||||
if( term != null )
|
|
||||||
{
|
|
||||||
int charX = (int) (mouseX / FONT_WIDTH);
|
|
||||||
int charY = (int) (mouseY / FONT_HEIGHT);
|
|
||||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
|
||||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
|
||||||
|
|
||||||
if( lastMouseButton == button )
|
|
||||||
{
|
|
||||||
computer.mouseUp( lastMouseButton + 1, charX + 1, charY + 1 );
|
|
||||||
lastMouseButton = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastMouseX = charX;
|
// Regular keys normally
|
||||||
lastMouseY = charY;
|
if( m_terminateTimer <= 0.0f && m_rebootTimer <= 0.0f && m_shutdownTimer <= 0.0f )
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseDragged( double mouseX, double mouseY, int button, double v2, double v3 )
|
|
||||||
{
|
|
||||||
ClientComputer computer = this.computer.get();
|
|
||||||
if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
|
|
||||||
|
|
||||||
Terminal term = computer.getTerminal();
|
|
||||||
if( term != null )
|
|
||||||
{
|
|
||||||
int charX = (int) (mouseX / FONT_WIDTH);
|
|
||||||
int charY = (int) (mouseY / FONT_HEIGHT);
|
|
||||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
|
||||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
|
||||||
|
|
||||||
if( button == lastMouseButton && (charX != lastMouseX || charY != lastMouseY) )
|
|
||||||
{
|
{
|
||||||
computer.mouseDrag( button + 1, charX + 1, charY + 1 );
|
boolean repeat = Keyboard.isRepeatEvent();
|
||||||
lastMouseX = charX;
|
boolean handled = false;
|
||||||
lastMouseY = charY;
|
if( key > 0 )
|
||||||
|
{
|
||||||
|
if( !repeat )
|
||||||
|
{
|
||||||
|
m_keysDown.add( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue the "key" event
|
||||||
|
IComputer computer = m_computer.getComputer();
|
||||||
|
if( computer != null ) computer.keyDown( key, repeat );
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range
|
||||||
|
{
|
||||||
|
// Queue the "char" event
|
||||||
|
queueEvent( "char", new Object[] { Character.toString( ch ) } );
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return handled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,111 +141,218 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled( double mouseX, double mouseY, double delta )
|
public void mouseClicked( int mouseX, int mouseY, int button )
|
||||||
{
|
{
|
||||||
ClientComputer computer = this.computer.get();
|
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
|
||||||
if( computer == null || !computer.isColour() || delta == 0 ) return false;
|
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() )
|
||||||
|
|
||||||
Terminal term = computer.getTerminal();
|
|
||||||
if( term != null )
|
|
||||||
{
|
{
|
||||||
int charX = (int) (mouseX / FONT_WIDTH);
|
if( !m_focus && button == 0 )
|
||||||
int charY = (int) (mouseY / FONT_HEIGHT);
|
{
|
||||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
m_focus = true;
|
||||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
}
|
||||||
|
|
||||||
computer.mouseScroll( delta < 0 ? 1 : -1, charX + 1, charY + 1 );
|
if( m_focus )
|
||||||
|
{
|
||||||
|
IComputer computer = m_computer.getComputer();
|
||||||
|
if( computer != null && computer.isColour() && button >= 0 && button <= 2 )
|
||||||
|
{
|
||||||
|
Terminal term = computer.getTerminal();
|
||||||
|
if( term != null )
|
||||||
|
{
|
||||||
|
int charX = (mouseX - (getXPosition() + leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
|
int charY = (mouseY - (getYPosition() + topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
|
|
||||||
lastMouseX = charX;
|
computer.mouseClick( button + 1, charX + 1, charY + 1 );
|
||||||
lastMouseY = charY;
|
|
||||||
|
m_lastClickButton = button;
|
||||||
|
m_lastClickX = charX;
|
||||||
|
m_lastClickY = charY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_focus && button == 0 && m_allowFocusLoss )
|
||||||
|
{
|
||||||
|
m_focus = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyboardInput()
|
||||||
|
{
|
||||||
|
boolean handled = false;
|
||||||
|
for( int i = m_keysDown.size() - 1; i >= 0; --i )
|
||||||
|
{
|
||||||
|
int key = m_keysDown.get( i );
|
||||||
|
if( !Keyboard.isKeyDown( key ) )
|
||||||
|
{
|
||||||
|
m_keysDown.remove( i );
|
||||||
|
if( m_focus )
|
||||||
|
{
|
||||||
|
// Queue the "key_up" event
|
||||||
|
IComputer computer = m_computer.getComputer();
|
||||||
|
if( computer != null ) computer.keyUp( key );
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleMouseInput( int mouseX, int mouseY )
|
||||||
|
{
|
||||||
|
IComputer computer = m_computer.getComputer();
|
||||||
|
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
|
||||||
|
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() &&
|
||||||
|
computer != null && computer.isColour() )
|
||||||
|
{
|
||||||
|
Terminal term = computer.getTerminal();
|
||||||
|
if( term != null )
|
||||||
|
{
|
||||||
|
int charX = (mouseX - (getXPosition() + leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
|
int charY = (mouseY - (getYPosition() + topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
|
|
||||||
|
if( m_lastClickButton >= 0 && !Mouse.isButtonDown( m_lastClickButton ) )
|
||||||
|
{
|
||||||
|
if( m_focus ) computer.mouseUp( m_lastClickButton + 1, charX + 1, charY + 1 );
|
||||||
|
m_lastClickButton = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wheelChange = Mouse.getEventDWheel();
|
||||||
|
if( wheelChange == 0 && m_lastClickButton == -1 )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m_focus )
|
||||||
|
{
|
||||||
|
if( wheelChange < 0 )
|
||||||
|
{
|
||||||
|
computer.mouseScroll( 1, charX + 1, charY + 1 );
|
||||||
|
}
|
||||||
|
else if( wheelChange > 0 )
|
||||||
|
{
|
||||||
|
computer.mouseScroll( -1, charX + 1, charY + 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( m_lastClickButton >= 0 && (charX != m_lastClickX || charY != m_lastClickY) )
|
||||||
|
{
|
||||||
|
computer.mouseDrag( m_lastClickButton + 1, charX + 1, charY + 1 );
|
||||||
|
m_lastClickX = charX;
|
||||||
|
m_lastClickY = charY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
if( terminateTimer >= 0 && terminateTimer < TERMINATE_TIME && (terminateTimer += 0.05f) > TERMINATE_TIME )
|
// Handle special keys
|
||||||
|
if( m_focus && (Keyboard.isKeyDown( 29 ) || Keyboard.isKeyDown( 157 )) )
|
||||||
{
|
{
|
||||||
queueEvent( "terminate" );
|
// Ctrl+T for terminate
|
||||||
}
|
if( Keyboard.isKeyDown( 20 ) )
|
||||||
|
|
||||||
if( shutdownTimer >= 0 && shutdownTimer < TERMINATE_TIME && (shutdownTimer += 0.05f) > TERMINATE_TIME )
|
|
||||||
{
|
|
||||||
ClientComputer computer = this.computer.get();
|
|
||||||
if( computer != null ) computer.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( rebootTimer >= 0 && rebootTimer < TERMINATE_TIME && (rebootTimer += 0.05f) > TERMINATE_TIME )
|
|
||||||
{
|
|
||||||
ClientComputer computer = this.computer.get();
|
|
||||||
if( computer != null ) computer.reboot();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean changeFocus( boolean reversed )
|
|
||||||
{
|
|
||||||
if( focused )
|
|
||||||
{
|
|
||||||
// When blurring, we should make all keys go up
|
|
||||||
for( int key = 0; key < keysDown.size(); key++ )
|
|
||||||
{
|
{
|
||||||
if( keysDown.get( key ) ) queueEvent( "key_up", key );
|
if( m_terminateTimer < TERMINATE_TIME )
|
||||||
}
|
{
|
||||||
keysDown.clear();
|
m_terminateTimer += 0.05f;
|
||||||
|
if( m_terminateTimer >= TERMINATE_TIME ) queueEvent( "terminate" );
|
||||||
// When blurring, we should make the last mouse button go up
|
}
|
||||||
if( lastMouseButton > 0 )
|
|
||||||
{
|
|
||||||
IComputer computer = this.computer.get();
|
|
||||||
if( computer != null ) computer.mouseUp( lastMouseButton + 1, lastMouseX + 1, lastMouseY + 1 );
|
|
||||||
lastMouseButton = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
shutdownTimer = terminateTimer = rebootTimer = -1;
|
|
||||||
}
|
|
||||||
focused = !focused;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw( int originX, int originY )
|
|
||||||
{
|
|
||||||
synchronized( computer )
|
|
||||||
{
|
|
||||||
// Draw the screen contents
|
|
||||||
ClientComputer computer = this.computer.get();
|
|
||||||
Terminal terminal = computer != null ? computer.getTerminal() : null;
|
|
||||||
if( terminal != null )
|
|
||||||
{
|
|
||||||
FixedWidthFontRenderer.drawTerminal( originX, originY, terminal, !computer.isColour(), topMargin, bottomMargin, leftMargin, rightMargin );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FixedWidthFontRenderer.drawEmptyTerminal(
|
m_terminateTimer = 0.0f;
|
||||||
originX - leftMargin, originY - rightMargin,
|
}
|
||||||
termWidth * FONT_WIDTH + leftMargin + rightMargin,
|
|
||||||
termHeight * FONT_HEIGHT + topMargin + bottomMargin
|
// Ctrl+R for reboot
|
||||||
|
if( Keyboard.isKeyDown( 19 ) )
|
||||||
|
{
|
||||||
|
if( m_rebootTimer < TERMINATE_TIME )
|
||||||
|
{
|
||||||
|
m_rebootTimer += 0.05f;
|
||||||
|
if( m_rebootTimer >= TERMINATE_TIME )
|
||||||
|
{
|
||||||
|
IComputer computer = m_computer.getComputer();
|
||||||
|
if( computer != null ) computer.reboot();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_rebootTimer = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ctrl+S for shutdown
|
||||||
|
if( Keyboard.isKeyDown( 31 ) )
|
||||||
|
{
|
||||||
|
if( m_shutdownTimer < TERMINATE_TIME )
|
||||||
|
{
|
||||||
|
m_shutdownTimer += 0.05f;
|
||||||
|
if( m_shutdownTimer >= TERMINATE_TIME )
|
||||||
|
{
|
||||||
|
IComputer computer = m_computer.getComputer();
|
||||||
|
if( computer != null ) computer.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_shutdownTimer = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_terminateTimer = 0.0f;
|
||||||
|
m_rebootTimer = 0.0f;
|
||||||
|
m_shutdownTimer = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
||||||
|
{
|
||||||
|
int startX = xOrigin + getXPosition();
|
||||||
|
int startY = yOrigin + getYPosition();
|
||||||
|
|
||||||
|
synchronized( m_computer )
|
||||||
|
{
|
||||||
|
// Draw the screen contents
|
||||||
|
IComputer computer = m_computer.getComputer();
|
||||||
|
Terminal terminal = computer != null ? computer.getTerminal() : null;
|
||||||
|
if( terminal != null )
|
||||||
|
{
|
||||||
|
FixedWidthFontRenderer.drawTerminal(
|
||||||
|
startX + topMargin, startY + bottomMargin,
|
||||||
|
terminal, !computer.isColour(), topMargin, bottomMargin, leftMargin, rightMargin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
FixedWidthFontRenderer.drawEmptyTerminal( startX, startY, getWidth(), getHeight() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueEvent( String event )
|
private void queueEvent( String event )
|
||||||
{
|
{
|
||||||
ClientComputer computer = this.computer.get();
|
IComputer computer = m_computer.getComputer();
|
||||||
if( computer != null ) computer.queueEvent( event );
|
if( computer != null ) computer.queueEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueEvent( String event, Object... args )
|
private void queueEvent( String event, Object[] args )
|
||||||
{
|
{
|
||||||
ClientComputer computer = this.computer.get();
|
IComputer computer = m_computer.getComputer();
|
||||||
if( computer != null ) computer.queueEvent( event, args );
|
if( computer != null ) computer.queueEvent( event, args );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMouseOver( double x, double y )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.client.gui.widgets;
|
|
||||||
|
|
||||||
import net.minecraft.client.gui.IGuiEventListener;
|
|
||||||
|
|
||||||
public class WidgetWrapper implements IGuiEventListener
|
|
||||||
{
|
|
||||||
private final IGuiEventListener listener;
|
|
||||||
private final int x;
|
|
||||||
private final int y;
|
|
||||||
private final int width;
|
|
||||||
private final int height;
|
|
||||||
|
|
||||||
public WidgetWrapper( IGuiEventListener listener, int x, int y, int width, int height )
|
|
||||||
{
|
|
||||||
this.listener = listener;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
this.width = width;
|
|
||||||
this.height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean changeFocus( boolean b )
|
|
||||||
{
|
|
||||||
return listener.changeFocus( b );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked( double x, double y, int button )
|
|
||||||
{
|
|
||||||
double dx = x - this.x, dy = y - this.y;
|
|
||||||
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseClicked( dx, dy, button );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseReleased( double x, double y, int button )
|
|
||||||
{
|
|
||||||
double dx = x - this.x, dy = y - this.y;
|
|
||||||
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseReleased( dx, dy, button );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
|
|
||||||
{
|
|
||||||
double dx = x - this.x, dy = y - this.y;
|
|
||||||
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseDragged( dx, dy, button, deltaX, deltaY );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseScrolled( double x, double y, double delta )
|
|
||||||
{
|
|
||||||
double dx = x - this.x, dy = y - this.y;
|
|
||||||
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseScrolled( dx, dy, delta );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
|
||||||
{
|
|
||||||
return listener.keyPressed( key, scancode, modifiers );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyReleased( int key, int scancode, int modifiers )
|
|
||||||
{
|
|
||||||
return listener.keyReleased( key, scancode, modifiers );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean charTyped( char character, int modifiers )
|
|
||||||
{
|
|
||||||
return listener.charTyped( character, modifiers );
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getX()
|
|
||||||
{
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getY()
|
|
||||||
{
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWidth()
|
|
||||||
{
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeight()
|
|
||||||
{
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMouseOver( double x, double y )
|
|
||||||
{
|
|
||||||
double dx = x - this.x, dy = y - this.y;
|
|
||||||
return dx >= 0 && dx < width && dy >= 0 && dy < height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,79 +6,56 @@
|
|||||||
package dan200.computercraft.client.proxy;
|
package dan200.computercraft.client.proxy;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.client.gui.*;
|
import dan200.computercraft.client.render.TileEntityCableRenderer;
|
||||||
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
||||||
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
||||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
import dan200.computercraft.shared.command.CommandCopy;
|
||||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
|
||||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
|
||||||
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
||||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
import net.minecraftforge.client.ClientCommandHandler;
|
||||||
import net.minecraft.client.gui.ScreenManager;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
|
public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||||
public final class ComputerCraftProxyClient
|
|
||||||
{
|
{
|
||||||
@SubscribeEvent
|
@Override
|
||||||
public static void setupClient( FMLClientSetupEvent event )
|
public void preInit()
|
||||||
{
|
{
|
||||||
registerContainers();
|
super.preInit();
|
||||||
|
|
||||||
// While turtles themselves are not transparent, their upgrades may be.
|
// Register any client-specific commands
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleNormal, RenderType.translucent() );
|
ClientCommandHandler.instance.registerCommand( CommandCopy.INSTANCE );
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.turtleAdvanced, RenderType.translucent() );
|
|
||||||
|
|
||||||
// Monitors' textures have _entirely_ transparent sections which, while not translucent, requires being rendered
|
|
||||||
// as transparent.
|
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorNormal, RenderType.translucent() );
|
|
||||||
RenderTypeLookup.setRenderLayer( ComputerCraft.Blocks.monitorAdvanced, RenderType.translucent() );
|
|
||||||
|
|
||||||
// Setup TESRs
|
|
||||||
ClientRegistry.bindTileEntityRenderer( TileMonitor.FACTORY_NORMAL, TileEntityMonitorRenderer::new );
|
|
||||||
ClientRegistry.bindTileEntityRenderer( TileMonitor.FACTORY_ADVANCED, TileEntityMonitorRenderer::new );
|
|
||||||
ClientRegistry.bindTileEntityRenderer( TileTurtle.FACTORY_NORMAL, TileEntityTurtleRenderer::new );
|
|
||||||
ClientRegistry.bindTileEntityRenderer( TileTurtle.FACTORY_ADVANCED, TileEntityTurtleRenderer::new );
|
|
||||||
// TODO: ClientRegistry.bindTileEntityRenderer( TileCable.FACTORY, x -> new TileEntityCableRenderer() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerContainers()
|
@Override
|
||||||
|
public void init()
|
||||||
{
|
{
|
||||||
// My IDE doesn't think so, but we do actually need these generics.
|
super.init();
|
||||||
|
|
||||||
ScreenManager.<ContainerComputer, GuiComputer<ContainerComputer>>registerFactory( ContainerComputer.TYPE, GuiComputer::create );
|
// Setup renderers
|
||||||
ScreenManager.<ContainerPocketComputer, GuiComputer<ContainerPocketComputer>>registerFactory( ContainerPocketComputer.TYPE, GuiComputer::createPocket );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
||||||
ScreenManager.registerFactory( ContainerTurtle.TYPE, GuiTurtle::new );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
|
||||||
|
ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() );
|
||||||
ScreenManager.registerFactory( ContainerPrinter.TYPE, GuiPrinter::new );
|
|
||||||
ScreenManager.registerFactory( ContainerDiskDrive.TYPE, GuiDiskDrive::new );
|
|
||||||
ScreenManager.registerFactory( ContainerHeldItem.PRINTOUT_TYPE, GuiPrintout::new );
|
|
||||||
|
|
||||||
ScreenManager.<ContainerViewComputer, GuiComputer<ContainerViewComputer>>registerFactory( ContainerViewComputer.TYPE, GuiComputer::createView );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
public static final class ForgeHandlers
|
public static final class ForgeHandlers
|
||||||
{
|
{
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onWorldUnload( WorldEvent.Unload event )
|
public static void onWorldUnload( WorldEvent.Unload event )
|
||||||
{
|
{
|
||||||
if( event.getWorld().isRemote() )
|
if( event.getWorld().isRemote )
|
||||||
{
|
{
|
||||||
ClientMonitor.destroyAll();
|
ClientMonitor.destroyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,221 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
||||||
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.RenderGlobal;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
|
public final class CableHighlightRenderer
|
||||||
|
{
|
||||||
|
private static final float EXPAND = 0.002f;
|
||||||
|
private static final double MIN = CableBounds.MIN - EXPAND;
|
||||||
|
private static final double MAX = CableBounds.MAX + EXPAND;
|
||||||
|
|
||||||
|
private CableHighlightRenderer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void drawHighlight( DrawBlockHighlightEvent event )
|
||||||
|
{
|
||||||
|
if( event.getTarget().typeOfHit != RayTraceResult.Type.BLOCK ) return;
|
||||||
|
|
||||||
|
BlockPos pos = event.getTarget().getBlockPos();
|
||||||
|
World world = event.getPlayer().getEntityWorld();
|
||||||
|
|
||||||
|
IBlockState state = world.getBlockState( pos );
|
||||||
|
if( state.getBlock() != ComputerCraft.Blocks.cable ) return;
|
||||||
|
|
||||||
|
state = state.getActualState( world, pos );
|
||||||
|
|
||||||
|
event.setCanceled( true );
|
||||||
|
PeripheralType type = BlockCable.getPeripheralType( state );
|
||||||
|
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0 );
|
||||||
|
GlStateManager.color( 0.0f, 0.0f, 0.0f, 0.4f );
|
||||||
|
GL11.glLineWidth( 2.0F );
|
||||||
|
GlStateManager.disableTexture2D();
|
||||||
|
GlStateManager.depthMask( false );
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
|
||||||
|
{
|
||||||
|
EntityPlayer player = event.getPlayer();
|
||||||
|
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
|
||||||
|
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
||||||
|
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
||||||
|
|
||||||
|
GlStateManager.translate( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( type != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), event.getTarget().hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||||
|
{
|
||||||
|
RenderGlobal.drawSelectionBoundingBox( CableBounds.getModemBounds( state ), 0, 0, 0, 0.4f );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int flags = 0;
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
|
||||||
|
for( EnumFacing facing : EnumFacing.VALUES )
|
||||||
|
{
|
||||||
|
if( BlockCable.doesConnectVisually( state, world, pos, facing ) )
|
||||||
|
{
|
||||||
|
flags |= 1 << facing.ordinal();
|
||||||
|
|
||||||
|
|
||||||
|
switch( facing.getAxis() )
|
||||||
|
{
|
||||||
|
case X:
|
||||||
|
{
|
||||||
|
double offset = facing == EnumFacing.WEST ? -EXPAND : 1 + EXPAND;
|
||||||
|
double centre = facing == EnumFacing.WEST ? MIN : MAX;
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION );
|
||||||
|
buffer.pos( offset, MIN, MIN ).endVertex();
|
||||||
|
buffer.pos( offset, MAX, MIN ).endVertex();
|
||||||
|
buffer.pos( offset, MAX, MAX ).endVertex();
|
||||||
|
buffer.pos( offset, MIN, MAX ).endVertex();
|
||||||
|
buffer.pos( offset, MIN, MIN ).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
||||||
|
buffer.pos( offset, MIN, MIN ).endVertex();
|
||||||
|
buffer.pos( centre, MIN, MIN ).endVertex();
|
||||||
|
buffer.pos( offset, MAX, MIN ).endVertex();
|
||||||
|
buffer.pos( centre, MAX, MIN ).endVertex();
|
||||||
|
buffer.pos( offset, MAX, MAX ).endVertex();
|
||||||
|
buffer.pos( centre, MAX, MAX ).endVertex();
|
||||||
|
buffer.pos( offset, MIN, MAX ).endVertex();
|
||||||
|
buffer.pos( centre, MIN, MAX ).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Y:
|
||||||
|
{
|
||||||
|
double offset = facing == EnumFacing.DOWN ? -EXPAND : 1 + EXPAND;
|
||||||
|
double centre = facing == EnumFacing.DOWN ? MIN : MAX;
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION );
|
||||||
|
buffer.pos( MIN, offset, MIN ).endVertex();
|
||||||
|
buffer.pos( MAX, offset, MIN ).endVertex();
|
||||||
|
buffer.pos( MAX, offset, MAX ).endVertex();
|
||||||
|
buffer.pos( MIN, offset, MAX ).endVertex();
|
||||||
|
buffer.pos( MIN, offset, MIN ).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
||||||
|
buffer.pos( MIN, offset, MIN ).endVertex();
|
||||||
|
buffer.pos( MIN, centre, MIN ).endVertex();
|
||||||
|
buffer.pos( MAX, offset, MIN ).endVertex();
|
||||||
|
buffer.pos( MAX, centre, MIN ).endVertex();
|
||||||
|
buffer.pos( MAX, offset, MAX ).endVertex();
|
||||||
|
buffer.pos( MAX, centre, MAX ).endVertex();
|
||||||
|
buffer.pos( MIN, offset, MAX ).endVertex();
|
||||||
|
buffer.pos( MIN, centre, MAX ).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Z:
|
||||||
|
{
|
||||||
|
double offset = facing == EnumFacing.NORTH ? -EXPAND : 1 + EXPAND;
|
||||||
|
double centre = facing == EnumFacing.NORTH ? MIN : MAX;
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION );
|
||||||
|
buffer.pos( MIN, MIN, offset ).endVertex();
|
||||||
|
buffer.pos( MAX, MIN, offset ).endVertex();
|
||||||
|
buffer.pos( MAX, MAX, offset ).endVertex();
|
||||||
|
buffer.pos( MIN, MAX, offset ).endVertex();
|
||||||
|
buffer.pos( MIN, MIN, offset ).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
||||||
|
buffer.pos( MIN, MIN, offset ).endVertex();
|
||||||
|
buffer.pos( MIN, MIN, centre ).endVertex();
|
||||||
|
buffer.pos( MAX, MIN, offset ).endVertex();
|
||||||
|
buffer.pos( MAX, MIN, centre ).endVertex();
|
||||||
|
buffer.pos( MAX, MAX, offset ).endVertex();
|
||||||
|
buffer.pos( MAX, MAX, centre ).endVertex();
|
||||||
|
buffer.pos( MIN, MAX, offset ).endVertex();
|
||||||
|
buffer.pos( MIN, MAX, centre ).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
||||||
|
|
||||||
|
draw( buffer, flags, EnumFacing.WEST, EnumFacing.DOWN, EnumFacing.Axis.Z );
|
||||||
|
draw( buffer, flags, EnumFacing.WEST, EnumFacing.UP, EnumFacing.Axis.Z );
|
||||||
|
draw( buffer, flags, EnumFacing.EAST, EnumFacing.DOWN, EnumFacing.Axis.Z );
|
||||||
|
draw( buffer, flags, EnumFacing.EAST, EnumFacing.UP, EnumFacing.Axis.Z );
|
||||||
|
|
||||||
|
draw( buffer, flags, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.Axis.Y );
|
||||||
|
draw( buffer, flags, EnumFacing.WEST, EnumFacing.SOUTH, EnumFacing.Axis.Y );
|
||||||
|
draw( buffer, flags, EnumFacing.EAST, EnumFacing.NORTH, EnumFacing.Axis.Y );
|
||||||
|
draw( buffer, flags, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.Axis.Y );
|
||||||
|
|
||||||
|
draw( buffer, flags, EnumFacing.DOWN, EnumFacing.NORTH, EnumFacing.Axis.X );
|
||||||
|
draw( buffer, flags, EnumFacing.DOWN, EnumFacing.SOUTH, EnumFacing.Axis.X );
|
||||||
|
draw( buffer, flags, EnumFacing.UP, EnumFacing.NORTH, EnumFacing.Axis.X );
|
||||||
|
draw( buffer, flags, EnumFacing.UP, EnumFacing.SOUTH, EnumFacing.Axis.X );
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
GlStateManager.depthMask( true );
|
||||||
|
GlStateManager.enableTexture2D();
|
||||||
|
GlStateManager.disableBlend();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void draw( BufferBuilder buffer, int flags, EnumFacing a, EnumFacing b, EnumFacing.Axis other )
|
||||||
|
{
|
||||||
|
if( ((flags >> a.ordinal()) & 1) != ((flags >> b.ordinal()) & 1) ) return;
|
||||||
|
|
||||||
|
double offA = a.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? MIN : MAX;
|
||||||
|
double offB = b.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? MIN : MAX;
|
||||||
|
switch( other )
|
||||||
|
{
|
||||||
|
case X:
|
||||||
|
buffer.pos( MIN, offA, offB ).endVertex();
|
||||||
|
buffer.pos( MAX, offA, offB ).endVertex();
|
||||||
|
break;
|
||||||
|
case Y:
|
||||||
|
buffer.pos( offA, MIN, offB ).endVertex();
|
||||||
|
buffer.pos( offA, MAX, offB ).endVertex();
|
||||||
|
break;
|
||||||
|
case Z:
|
||||||
|
buffer.pos( offA, offB, MIN ).endVertex();
|
||||||
|
buffer.pos( offA, offB, MAX ).endVertex();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.ItemRenderer;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.EnumHand;
|
||||||
|
import net.minecraft.util.EnumHandSide;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
public abstract class ItemMapLikeRenderer
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The main rendering method for the item.
|
||||||
|
*
|
||||||
|
* @param stack The stack to render
|
||||||
|
* @see ItemRenderer#renderMapFirstPerson(ItemStack)
|
||||||
|
*/
|
||||||
|
protected abstract void renderItem( ItemStack stack );
|
||||||
|
|
||||||
|
protected void renderItemFirstPerson( EnumHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
|
{
|
||||||
|
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||||
|
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
|
||||||
|
{
|
||||||
|
renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
renderItemFirstPersonSide(
|
||||||
|
hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
|
||||||
|
equipProgress, swingProgress, stack
|
||||||
|
);
|
||||||
|
}
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the item to one side of the player.
|
||||||
|
*
|
||||||
|
* @param side The side to render on
|
||||||
|
* @param equipProgress The equip progress of this item
|
||||||
|
* @param swingProgress The swing progress of this item
|
||||||
|
* @param stack The stack to render
|
||||||
|
* @see ItemRenderer#renderMapFirstPersonSide(float, EnumHandSide, float, ItemStack)
|
||||||
|
*/
|
||||||
|
private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
|
{
|
||||||
|
Minecraft minecraft = Minecraft.getMinecraft();
|
||||||
|
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
|
||||||
|
GlStateManager.translate( offset * 0.125f, -0.125f, 0f );
|
||||||
|
|
||||||
|
// If the player is not invisible then render a single arm
|
||||||
|
if( !minecraft.player.isInvisible() )
|
||||||
|
{
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.rotate( offset * 10f, 0f, 0f, 1f );
|
||||||
|
minecraft.getItemRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup the appropriate transformations. This is just copied from the
|
||||||
|
// corresponding method in ItemRenderer.
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
||||||
|
float f1 = MathHelper.sqrt( swingProgress );
|
||||||
|
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
||||||
|
float f3 = -0.5f * f2;
|
||||||
|
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
||||||
|
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||||
|
GlStateManager.translate( offset * f3, f4 - 0.3f * f2, f5 );
|
||||||
|
GlStateManager.rotate( f2 * -45f, 1f, 0f, 0f );
|
||||||
|
GlStateManager.rotate( offset * f2 * -30f, 0f, 1f, 0f );
|
||||||
|
|
||||||
|
renderItem( stack );
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render an item in the middle of the screen.
|
||||||
|
*
|
||||||
|
* @param pitch The pitch of the player
|
||||||
|
* @param equipProgress The equip progress of this item
|
||||||
|
* @param swingProgress The swing progress of this item
|
||||||
|
* @param stack The stack to render
|
||||||
|
* @see ItemRenderer#renderMapFirstPerson(float, float, float)
|
||||||
|
*/
|
||||||
|
private void renderItemFirstPersonCenter( float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
|
{
|
||||||
|
ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer();
|
||||||
|
|
||||||
|
// Setup the appropriate transformations. This is just copied from the
|
||||||
|
// corresponding method in ItemRenderer.
|
||||||
|
float swingRt = MathHelper.sqrt( swingProgress );
|
||||||
|
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||||
|
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
||||||
|
GlStateManager.translate( 0f, -tX / 2f, tZ );
|
||||||
|
float pitchAngle = itemRenderer.getMapAngleFromPitch( pitch );
|
||||||
|
GlStateManager.translate( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
||||||
|
GlStateManager.rotate( pitchAngle * -85f, 1f, 0f, 0f );
|
||||||
|
itemRenderer.renderArms();
|
||||||
|
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
||||||
|
GlStateManager.rotate( rX * 20f, 1f, 0f, 0f );
|
||||||
|
GlStateManager.scale( 2f, 2f, 2f );
|
||||||
|
|
||||||
|
renderItem( stack );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,38 +5,33 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.client.FrameInfo;
|
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.RenderSpecificHandEvent;
|
import net.minecraftforge.client.event.RenderSpecificHandEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
import static dan200.computercraft.client.gui.GuiComputer.*;
|
import static dan200.computercraft.client.gui.GuiComputer.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emulates map rendering for pocket computers.
|
* Emulates map rendering for pocket computers.
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||||
{
|
{
|
||||||
private static final int MARGIN = 2;
|
private static final int MARGIN = 2;
|
||||||
@@ -56,16 +51,11 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
if( !(stack.getItem() instanceof ItemPocketComputer) ) return;
|
if( !(stack.getItem() instanceof ItemPocketComputer) ) return;
|
||||||
|
|
||||||
event.setCanceled( true );
|
event.setCanceled( true );
|
||||||
Minecraft minecraft = Minecraft.getInstance();
|
INSTANCE.renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
|
||||||
INSTANCE.renderItemFirstPerson(
|
|
||||||
event.getMatrixStack(), minecraft.func_228019_au_().func_228487_b_(),
|
|
||||||
minecraft.getRenderManager().func_229085_a_( minecraft.player, event.getPartialTicks() ),
|
|
||||||
event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack )
|
protected void renderItem( ItemStack stack )
|
||||||
{
|
{
|
||||||
ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
|
ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
|
||||||
Terminal terminal = computer == null ? null : computer.getTerminal();
|
Terminal terminal = computer == null ? null : computer.getTerminal();
|
||||||
@@ -87,22 +77,22 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
|
|
||||||
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
||||||
// in ItemRenderer
|
// in ItemRenderer
|
||||||
transform.push();
|
GlStateManager.pushMatrix();
|
||||||
// TODO: RenderSystem.disableLighting();
|
|
||||||
// TODO: RenderSystem.disableDepthTest();
|
|
||||||
|
|
||||||
RenderSystem.rotatef( 180f, 0f, 1f, 0f );
|
GlStateManager.disableLighting();
|
||||||
RenderSystem.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.disableDepth();
|
||||||
transform.scale( 0.5f, 0.5f, 0.5f );
|
|
||||||
|
|
||||||
float scale = 0.75f / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT );
|
GlStateManager.rotate( 180f, 0f, 1f, 0f );
|
||||||
transform.scale( scale, scale, 0 );
|
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
||||||
transform.translate( -0.5 * width, -0.5 * height, 0 );
|
GlStateManager.scale( 0.5, 0.5, 0.5 );
|
||||||
|
|
||||||
|
double scale = 0.75 / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT );
|
||||||
|
GlStateManager.scale( scale, scale, 0 );
|
||||||
|
GlStateManager.translate( -0.5 * width, -0.5 * height, 0 );
|
||||||
|
|
||||||
// Render the main frame
|
// Render the main frame
|
||||||
ItemPocketComputer item = (ItemPocketComputer) stack.getItem();
|
ComputerFamily family = ComputerCraft.Items.pocketComputer.getFamily( stack );
|
||||||
ComputerFamily family = item.getFamily();
|
int frameColour = ComputerCraft.Items.pocketComputer.getColour( stack );
|
||||||
int frameColour = item.getColour( stack );
|
|
||||||
renderFrame( family, frameColour, width, height );
|
renderFrame( family, frameColour, width, height );
|
||||||
|
|
||||||
// Render the light
|
// Render the light
|
||||||
@@ -112,32 +102,22 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
|
|
||||||
if( computer != null && terminal != null )
|
if( computer != null && terminal != null )
|
||||||
{
|
{
|
||||||
// If we've a computer and terminal then attempt to render it.
|
FixedWidthFontRenderer.drawTerminal( MARGIN, MARGIN, terminal, !computer.isColour(), MARGIN, MARGIN, MARGIN, MARGIN );
|
||||||
renderTerminal( terminal, !computer.isColour() );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Otherwise render a plain background
|
FixedWidthFontRenderer.drawEmptyTerminal( 0, 0, width, height );
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( BACKGROUND );
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
|
|
||||||
Colour black = Colour.Black;
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION );
|
|
||||||
renderTexture( buffer, 0, 0, 0, 0, width, height, black.getR(), black.getG(), black.getB() );
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: RenderSystem.enableDepthTest();
|
GlStateManager.enableDepth();
|
||||||
// TODO: RenderSystem.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
transform.pop();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderFrame( ComputerFamily family, int colour, int width, int height )
|
private static void renderFrame( ComputerFamily family, int colour, int width, int height )
|
||||||
{
|
{
|
||||||
|
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( colour != -1
|
Minecraft.getMinecraft().getTextureManager().bindTexture( colour != -1
|
||||||
? BACKGROUND_COLOUR
|
? BACKGROUND_COLOUR
|
||||||
: family == ComputerFamily.Normal ? BACKGROUND_NORMAL : BACKGROUND_ADVANCED
|
: family == ComputerFamily.Normal ? BACKGROUND_NORMAL : BACKGROUND_ADVANCED
|
||||||
);
|
);
|
||||||
@@ -178,8 +158,8 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
|
|
||||||
private static void renderLight( int colour, int width, int height )
|
private static void renderLight( int colour, int width, int height )
|
||||||
{
|
{
|
||||||
RenderSystem.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
RenderSystem.disableTexture();
|
GlStateManager.disableTexture2D();
|
||||||
|
|
||||||
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
||||||
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
||||||
@@ -194,62 +174,15 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
buffer.pos( width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
buffer.pos( width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
||||||
|
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
RenderSystem.enableTexture();
|
GlStateManager.enableTexture2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderTerminal( Terminal terminal, boolean greyscale )
|
private static void renderTexture( BufferBuilder builder, int x, int y, int textureX, int textureY, int width, int height, float r, float g, float b )
|
||||||
{
|
|
||||||
synchronized( terminal )
|
|
||||||
{
|
|
||||||
int termWidth = terminal.getWidth();
|
|
||||||
int termHeight = terminal.getHeight();
|
|
||||||
|
|
||||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
|
||||||
Palette palette = terminal.getPalette();
|
|
||||||
|
|
||||||
// Render top/bottom borders
|
|
||||||
TextBuffer emptyLine = new TextBuffer( ' ', termWidth );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
emptyLine, MARGIN, 0,
|
|
||||||
terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
fontRenderer.drawString(
|
|
||||||
emptyLine, MARGIN, 2 * MARGIN + (termHeight - 1) * FixedWidthFontRenderer.FONT_HEIGHT,
|
|
||||||
terminal.getTextColourLine( termHeight - 1 ), terminal.getBackgroundColourLine( termHeight - 1 ), MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
|
|
||||||
// Render the actual text
|
|
||||||
for( int line = 0; line < termWidth; line++ )
|
|
||||||
{
|
|
||||||
TextBuffer text = terminal.getLine( line );
|
|
||||||
TextBuffer colour = terminal.getTextColourLine( line );
|
|
||||||
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
text, MARGIN, MARGIN + line * FONT_HEIGHT,
|
|
||||||
colour, backgroundColour, MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// And render the cursor;
|
|
||||||
int tx = terminal.getCursorX(), ty = terminal.getCursorY();
|
|
||||||
if( terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink() &&
|
|
||||||
tx >= 0 && ty >= 0 && tx < termWidth && ty < termHeight )
|
|
||||||
{
|
|
||||||
TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
new TextBuffer( '_', 1 ), MARGIN + FONT_WIDTH * tx, MARGIN + FONT_HEIGHT * ty,
|
|
||||||
cursorColour, null, 0, 0, greyscale, palette
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderTexture( IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, float r, float g, float b )
|
|
||||||
{
|
{
|
||||||
renderTexture( builder, x, y, textureX, textureY, width, height, width, height, r, g, b );
|
renderTexture( builder, x, y, textureX, textureY, width, height, width, height, r, g, b );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderTexture( IVertexBuilder builder, int x, int y, int textureX, int textureY, int width, int height, int textureWidth, int textureHeight, float r, float g, float b )
|
private static void renderTexture( BufferBuilder builder, int x, int y, int textureX, int textureY, int width, int height, int textureWidth, int textureHeight, float r, float g, float b )
|
||||||
{
|
{
|
||||||
float scale = 1 / 255.0f;
|
float scale = 1 / 255.0f;
|
||||||
builder.pos( x, y + height, 0 ).tex( textureX * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex();
|
builder.pos( x, y + height, 0 ).tex( textureX * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex();
|
||||||
@@ -5,15 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.RenderItemInFrameEvent;
|
import net.minecraftforge.client.event.RenderItemInFrameEvent;
|
||||||
import net.minecraftforge.client.event.RenderSpecificHandEvent;
|
import net.minecraftforge.client.event.RenderSpecificHandEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
@@ -24,7 +24,7 @@ import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENG
|
|||||||
/**
|
/**
|
||||||
* Emulates map and item-frame rendering for printouts.
|
* Emulates map and item-frame rendering for printouts.
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||||
{
|
{
|
||||||
private static final ItemPrintoutRenderer INSTANCE = new ItemPrintoutRenderer();
|
private static final ItemPrintoutRenderer INSTANCE = new ItemPrintoutRenderer();
|
||||||
@@ -37,9 +37,10 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
public static void onRenderInHand( RenderSpecificHandEvent event )
|
public static void onRenderInHand( RenderSpecificHandEvent event )
|
||||||
{
|
{
|
||||||
ItemStack stack = event.getItemStack();
|
ItemStack stack = event.getItemStack();
|
||||||
if( !(stack.getItem() instanceof ItemPrintout) ) return;
|
if( stack.getItem() != ComputerCraft.Items.printout ) return;
|
||||||
|
|
||||||
event.setCanceled( true );
|
event.setCanceled( true );
|
||||||
|
|
||||||
INSTANCE.renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
|
INSTANCE.renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,45 +48,45 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
protected void renderItem( ItemStack stack )
|
protected void renderItem( ItemStack stack )
|
||||||
{
|
{
|
||||||
// Setup various transformations. Note that these are partially adapated from the corresponding method
|
// Setup various transformations. Note that these are partially adapated from the corresponding method
|
||||||
// in FirstPersonRenderer.renderFirstPersonMap
|
// in ItemRenderer.renderMapFirstPerson
|
||||||
RenderSystem.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
RenderSystem.rotatef( 180f, 0f, 1f, 0f );
|
GlStateManager.rotate( 180f, 0f, 1f, 0f );
|
||||||
RenderSystem.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
||||||
RenderSystem.scalef( 0.42f, 0.42f, -0.42f );
|
GlStateManager.scale( 0.42f, 0.42f, -0.42f );
|
||||||
RenderSystem.translatef( -0.5f, -0.48f, 0.0f );
|
GlStateManager.translate( -0.5f, -0.48f, 0.0f );
|
||||||
|
|
||||||
drawPrintout( stack );
|
drawPrintout( stack );
|
||||||
|
|
||||||
RenderSystem.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onRenderInFrame( RenderItemInFrameEvent event )
|
public static void onRenderInFrame( RenderItemInFrameEvent event )
|
||||||
{
|
{
|
||||||
ItemStack stack = event.getItem();
|
ItemStack stack = event.getItem();
|
||||||
if( !(stack.getItem() instanceof ItemPrintout) ) return;
|
if( stack.getItem() != ComputerCraft.Items.printout ) return;
|
||||||
|
|
||||||
event.setCanceled( true );
|
event.setCanceled( true );
|
||||||
|
|
||||||
RenderSystem.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
// Move a little bit forward to ensure we're not clipping with the frame
|
// Move a little bit forward to ensure we're not clipping with the frame
|
||||||
RenderSystem.translatef( 0.0f, 0.0f, -0.001f );
|
GlStateManager.translate( 0.0f, 0.0f, -0.001f );
|
||||||
RenderSystem.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
||||||
RenderSystem.scalef( 0.95f, 0.95f, -0.95f );
|
GlStateManager.scale( 0.95f, 0.95f, -0.95f );
|
||||||
RenderSystem.translatef( -0.5f, -0.5f, 0.0f );
|
GlStateManager.translate( -0.5f, -0.5f, 0.0f );
|
||||||
|
|
||||||
drawPrintout( stack );
|
drawPrintout( stack );
|
||||||
|
|
||||||
RenderSystem.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
RenderSystem.disableBlend();
|
GlStateManager.disableBlend();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawPrintout( ItemStack stack )
|
private static void drawPrintout( ItemStack stack )
|
||||||
{
|
{
|
||||||
int pages = ItemPrintout.getPageCount( stack );
|
int pages = ItemPrintout.getPageCount( stack );
|
||||||
boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK;
|
boolean book = ItemPrintout.getType( stack ) == ItemPrintout.Type.Book;
|
||||||
|
|
||||||
double width = LINE_MAX_LENGTH * FONT_WIDTH + X_TEXT_MARGIN * 2;
|
double width = LINE_MAX_LENGTH * FONT_WIDTH + X_TEXT_MARGIN * 2;
|
||||||
double height = LINES_PER_PAGE * FONT_HEIGHT + Y_TEXT_MARGIN * 2;
|
double height = LINES_PER_PAGE * FONT_HEIGHT + Y_TEXT_MARGIN * 2;
|
||||||
@@ -106,8 +107,8 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
|
|
||||||
// Scale the printout to fit correctly.
|
// Scale the printout to fit correctly.
|
||||||
double scale = 1.0 / max;
|
double scale = 1.0 / max;
|
||||||
RenderSystem.scaled( scale, scale, scale );
|
GlStateManager.scale( scale, scale, scale );
|
||||||
RenderSystem.translated( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
|
GlStateManager.translate( (max - width) / 2.0f, (max - height) / 2.0f, 0.0f );
|
||||||
|
|
||||||
drawBorder( 0, 0, -0.01, 0, pages, book );
|
drawBorder( 0, 0, -0.01, 0, pages, book );
|
||||||
drawText( X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) );
|
drawText( X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) );
|
||||||
@@ -0,0 +1,269 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||||
|
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||||
|
import net.minecraftforge.client.model.pipeline.VertexTransformer;
|
||||||
|
import net.minecraftforge.common.model.TRSRTransformation;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.vecmath.Matrix4f;
|
||||||
|
import javax.vecmath.Point3f;
|
||||||
|
import javax.vecmath.Vector3f;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transforms vertices of a model, remaining aware of winding order, and rearranging
|
||||||
|
* vertices if needed.
|
||||||
|
*/
|
||||||
|
public final class ModelTransformer
|
||||||
|
{
|
||||||
|
private static final Matrix4f identity;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
identity = new Matrix4f();
|
||||||
|
identity.setIdentity();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ModelTransformer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void transformQuadsTo( List<BakedQuad> output, List<BakedQuad> input, Matrix4f transform )
|
||||||
|
{
|
||||||
|
if( transform == null || transform.equals( identity ) )
|
||||||
|
{
|
||||||
|
output.addAll( input );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Matrix4f normalMatrix = new Matrix4f( transform );
|
||||||
|
normalMatrix.invert();
|
||||||
|
normalMatrix.transpose();
|
||||||
|
|
||||||
|
for( BakedQuad quad : input ) output.add( doTransformQuad( quad, transform, normalMatrix ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BakedQuad transformQuad( BakedQuad input, Matrix4f transform )
|
||||||
|
{
|
||||||
|
if( transform == null || transform.equals( identity ) ) return input;
|
||||||
|
|
||||||
|
Matrix4f normalMatrix = new Matrix4f( transform );
|
||||||
|
normalMatrix.invert();
|
||||||
|
normalMatrix.transpose();
|
||||||
|
return doTransformQuad( input, transform, normalMatrix );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BakedQuad doTransformQuad( BakedQuad input, Matrix4f positionMatrix, Matrix4f normalMatrix )
|
||||||
|
{
|
||||||
|
|
||||||
|
BakedQuadBuilder builder = new BakedQuadBuilder( input.getFormat() );
|
||||||
|
NormalAwareTransformer transformer = new NormalAwareTransformer( builder, positionMatrix, normalMatrix );
|
||||||
|
input.pipe( transformer );
|
||||||
|
|
||||||
|
if( transformer.areNormalsInverted() )
|
||||||
|
{
|
||||||
|
builder.swap( 1, 3 );
|
||||||
|
transformer.areNormalsInverted();
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A vertex transformer that tracks whether the normals have been inverted and so the vertices
|
||||||
|
* should be reordered so backface culling works as expected.
|
||||||
|
*/
|
||||||
|
private static class NormalAwareTransformer extends VertexTransformer
|
||||||
|
{
|
||||||
|
private final Matrix4f positionMatrix;
|
||||||
|
private final Matrix4f normalMatrix;
|
||||||
|
|
||||||
|
private int vertexIndex = 0, elementIndex = 0;
|
||||||
|
private final Point3f[] before = new Point3f[4];
|
||||||
|
private final Point3f[] after = new Point3f[4];
|
||||||
|
|
||||||
|
NormalAwareTransformer( IVertexConsumer parent, Matrix4f positionMatrix, Matrix4f normalMatrix )
|
||||||
|
{
|
||||||
|
super( parent );
|
||||||
|
this.positionMatrix = positionMatrix;
|
||||||
|
this.normalMatrix = normalMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setQuadOrientation( @Nonnull EnumFacing orientation )
|
||||||
|
{
|
||||||
|
super.setQuadOrientation( orientation == null ? orientation : TRSRTransformation.rotate( positionMatrix, orientation ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put( int element, @Nonnull float... data )
|
||||||
|
{
|
||||||
|
switch( getVertexFormat().getElement( element ).getUsage() )
|
||||||
|
{
|
||||||
|
case POSITION:
|
||||||
|
{
|
||||||
|
Point3f vec = new Point3f( data );
|
||||||
|
Point3f newVec = new Point3f();
|
||||||
|
positionMatrix.transform( vec, newVec );
|
||||||
|
|
||||||
|
float[] newData = new float[4];
|
||||||
|
newVec.get( newData );
|
||||||
|
super.put( element, newData );
|
||||||
|
|
||||||
|
|
||||||
|
before[vertexIndex] = vec;
|
||||||
|
after[vertexIndex] = newVec;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NORMAL:
|
||||||
|
{
|
||||||
|
Vector3f vec = new Vector3f( data );
|
||||||
|
normalMatrix.transform( vec );
|
||||||
|
|
||||||
|
float[] newData = new float[4];
|
||||||
|
vec.get( newData );
|
||||||
|
super.put( element, newData );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
super.put( element, data );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
elementIndex++;
|
||||||
|
if( elementIndex == getVertexFormat().getElementCount() )
|
||||||
|
{
|
||||||
|
vertexIndex++;
|
||||||
|
elementIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean areNormalsInverted()
|
||||||
|
{
|
||||||
|
Vector3f temp1 = new Vector3f(), temp2 = new Vector3f();
|
||||||
|
Vector3f crossBefore = new Vector3f(), crossAfter = new Vector3f();
|
||||||
|
|
||||||
|
// Determine what cross product we expect to have
|
||||||
|
temp1.sub( before[1], before[0] );
|
||||||
|
temp2.sub( before[1], before[2] );
|
||||||
|
crossBefore.cross( temp1, temp2 );
|
||||||
|
normalMatrix.transform( crossBefore );
|
||||||
|
|
||||||
|
// And determine what cross product we actually have
|
||||||
|
temp1.sub( after[1], after[0] );
|
||||||
|
temp2.sub( after[1], after[2] );
|
||||||
|
crossAfter.cross( temp1, temp2 );
|
||||||
|
|
||||||
|
// If the angle between expected and actual cross product is greater than
|
||||||
|
// pi/2 radians then we will need to reorder our quads.
|
||||||
|
return Math.abs( crossBefore.angle( crossAfter ) ) >= Math.PI / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A vertex consumer which is capable of building {@link BakedQuad}s.
|
||||||
|
*
|
||||||
|
* Equivalent to {@link net.minecraftforge.client.model.pipeline.UnpackedBakedQuad.Builder} but more memory
|
||||||
|
* efficient.
|
||||||
|
*
|
||||||
|
* This also provides the ability to swap vertices through {@link #swap(int, int)} to allow reordering.
|
||||||
|
*/
|
||||||
|
private static final class BakedQuadBuilder implements IVertexConsumer
|
||||||
|
{
|
||||||
|
private final VertexFormat format;
|
||||||
|
|
||||||
|
private final int[] vertexData;
|
||||||
|
private int vertexIndex = 0, elementIndex = 0;
|
||||||
|
|
||||||
|
private EnumFacing orientation;
|
||||||
|
private int quadTint;
|
||||||
|
private boolean diffuse;
|
||||||
|
private TextureAtlasSprite texture;
|
||||||
|
|
||||||
|
private BakedQuadBuilder( VertexFormat format )
|
||||||
|
{
|
||||||
|
this.format = format;
|
||||||
|
vertexData = new int[format.getSize()];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public VertexFormat getVertexFormat()
|
||||||
|
{
|
||||||
|
return format;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setQuadTint( int tint )
|
||||||
|
{
|
||||||
|
quadTint = tint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setQuadOrientation( @Nonnull EnumFacing orientation )
|
||||||
|
{
|
||||||
|
this.orientation = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplyDiffuseLighting( boolean diffuse )
|
||||||
|
{
|
||||||
|
this.diffuse = diffuse;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTexture( @Nonnull TextureAtlasSprite texture )
|
||||||
|
{
|
||||||
|
this.texture = texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void put( int element, @Nonnull float... data )
|
||||||
|
{
|
||||||
|
LightUtil.pack( data, vertexData, format, vertexIndex, element );
|
||||||
|
|
||||||
|
elementIndex++;
|
||||||
|
if( elementIndex == getVertexFormat().getElementCount() )
|
||||||
|
{
|
||||||
|
vertexIndex++;
|
||||||
|
elementIndex = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void swap( int a, int b )
|
||||||
|
{
|
||||||
|
int length = vertexData.length / 4;
|
||||||
|
for( int i = 0; i < length; i++ )
|
||||||
|
{
|
||||||
|
int temp = vertexData[a * length + i];
|
||||||
|
vertexData[a * length + i] = vertexData[b * length + i];
|
||||||
|
vertexData[b * length + i] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BakedQuad build()
|
||||||
|
{
|
||||||
|
if( elementIndex != 0 || vertexIndex != 4 )
|
||||||
|
{
|
||||||
|
throw new IllegalStateException( "Got an unexpected number of elements/vertices" );
|
||||||
|
}
|
||||||
|
if( texture == null )
|
||||||
|
{
|
||||||
|
throw new IllegalStateException( "Texture has not been set" );
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BakedQuad( vertexData, quadTint, orientation, texture, diffuse, format );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import static net.minecraft.util.EnumFacing.*;
|
||||||
|
|
||||||
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
|
public final class MonitorHighlightRenderer
|
||||||
|
{
|
||||||
|
private static final float EXPAND = 0.002f;
|
||||||
|
|
||||||
|
private MonitorHighlightRenderer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void drawHighlight( DrawBlockHighlightEvent event )
|
||||||
|
{
|
||||||
|
if( event.getTarget().typeOfHit != RayTraceResult.Type.BLOCK || event.getPlayer().isSneaking() ) return;
|
||||||
|
|
||||||
|
World world = event.getPlayer().getEntityWorld();
|
||||||
|
BlockPos pos = event.getTarget().getBlockPos();
|
||||||
|
|
||||||
|
if( world.getBlockState( pos ).getBlock() != ComputerCraft.Blocks.peripheral ) return;
|
||||||
|
|
||||||
|
TileEntity tile = world.getTileEntity( pos );
|
||||||
|
if( !(tile instanceof TileMonitor) ) return;
|
||||||
|
|
||||||
|
TileMonitor monitor = (TileMonitor) tile;
|
||||||
|
event.setCanceled( true );
|
||||||
|
|
||||||
|
// Determine which sides are part of the external faces of the monitor, and so which need to be rendered.
|
||||||
|
EnumSet<EnumFacing> faces = EnumSet.allOf( EnumFacing.class );
|
||||||
|
EnumFacing front = monitor.getFront();
|
||||||
|
faces.remove( front );
|
||||||
|
if( monitor.getXIndex() != 0 ) faces.remove( monitor.getRight().getOpposite() );
|
||||||
|
if( monitor.getXIndex() != monitor.getWidth() - 1 ) faces.remove( monitor.getRight() );
|
||||||
|
if( monitor.getYIndex() != 0 ) faces.remove( monitor.getDown().getOpposite() );
|
||||||
|
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
||||||
|
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
||||||
|
GL11.glLineWidth( 2.0F );
|
||||||
|
GlStateManager.disableTexture2D();
|
||||||
|
GlStateManager.depthMask( false );
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
|
||||||
|
EntityPlayer player = event.getPlayer();
|
||||||
|
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
|
||||||
|
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
||||||
|
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
||||||
|
|
||||||
|
GlStateManager.translate( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
||||||
|
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR );
|
||||||
|
|
||||||
|
// I wish I could think of a better way to do this
|
||||||
|
if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, 0, 0, 0, UP );
|
||||||
|
if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, 0, 0, 1, UP );
|
||||||
|
if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, 1, 0, 0, UP );
|
||||||
|
if( faces.contains( SOUTH ) || faces.contains( EAST ) ) line( buffer, 1, 0, 1, UP );
|
||||||
|
if( faces.contains( NORTH ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 0, EAST );
|
||||||
|
if( faces.contains( SOUTH ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 1, EAST );
|
||||||
|
if( faces.contains( NORTH ) || faces.contains( UP ) ) line( buffer, 0, 1, 0, EAST );
|
||||||
|
if( faces.contains( SOUTH ) || faces.contains( UP ) ) line( buffer, 0, 1, 1, EAST );
|
||||||
|
if( faces.contains( WEST ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 0, SOUTH );
|
||||||
|
if( faces.contains( EAST ) || faces.contains( DOWN ) ) line( buffer, 1, 0, 0, SOUTH );
|
||||||
|
if( faces.contains( WEST ) || faces.contains( UP ) ) line( buffer, 0, 1, 0, SOUTH );
|
||||||
|
if( faces.contains( EAST ) || faces.contains( UP ) ) line( buffer, 1, 1, 0, SOUTH );
|
||||||
|
|
||||||
|
tessellator.draw();
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
GlStateManager.depthMask( true );
|
||||||
|
GlStateManager.enableTexture2D();
|
||||||
|
GlStateManager.disableBlend();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void line( BufferBuilder buffer, int x, int y, int z, EnumFacing direction )
|
||||||
|
{
|
||||||
|
double minX = x == 0 ? -EXPAND : 1 + EXPAND;
|
||||||
|
double minY = y == 0 ? -EXPAND : 1 + EXPAND;
|
||||||
|
double minZ = z == 0 ? -EXPAND : 1 + EXPAND;
|
||||||
|
|
||||||
|
buffer.pos( minX, minY, minZ ).color( 0, 0, 0, 0.4f ).endVertex();
|
||||||
|
buffer.pos(
|
||||||
|
minX + direction.getXOffset() * (1 + EXPAND * 2),
|
||||||
|
minY + direction.getYOffset() * (1 + EXPAND * 2),
|
||||||
|
minZ + direction.getZOffset() * (1 + EXPAND * 2)
|
||||||
|
).color( 0, 0, 0, 0.4f ).endVertex();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
|
import dan200.computercraft.shared.util.Palette;
|
||||||
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL13;
|
||||||
|
import org.lwjgl.opengl.GL20;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
|
|
||||||
|
class MonitorTextureBufferShader
|
||||||
|
{
|
||||||
|
static final int TEXTURE_INDEX = GL13.GL_TEXTURE3;
|
||||||
|
|
||||||
|
private static final FloatBuffer MATRIX_BUFFER = BufferUtils.createFloatBuffer( 16 );
|
||||||
|
private static final FloatBuffer PALETTE_BUFFER = BufferUtils.createFloatBuffer( 16 * 3 );
|
||||||
|
|
||||||
|
private static int uniformMv;
|
||||||
|
private static int uniformP;
|
||||||
|
|
||||||
|
private static int uniformFont;
|
||||||
|
private static int uniformWidth;
|
||||||
|
private static int uniformHeight;
|
||||||
|
private static int uniformTbo;
|
||||||
|
private static int uniformPalette;
|
||||||
|
|
||||||
|
private static boolean initialised;
|
||||||
|
private static boolean ok;
|
||||||
|
private static int program;
|
||||||
|
|
||||||
|
static void setupUniform( int width, int height, Palette palette, boolean greyscale )
|
||||||
|
{
|
||||||
|
MATRIX_BUFFER.rewind();
|
||||||
|
GL11.glGetFloat( GL11.GL_MODELVIEW_MATRIX, MATRIX_BUFFER );
|
||||||
|
MATRIX_BUFFER.rewind();
|
||||||
|
OpenGlHelper.glUniformMatrix4( uniformMv, false, MATRIX_BUFFER );
|
||||||
|
|
||||||
|
MATRIX_BUFFER.rewind();
|
||||||
|
GL11.glGetFloat( GL11.GL_PROJECTION_MATRIX, MATRIX_BUFFER );
|
||||||
|
MATRIX_BUFFER.rewind();
|
||||||
|
OpenGlHelper.glUniformMatrix4( uniformP, false, MATRIX_BUFFER );
|
||||||
|
|
||||||
|
OpenGlHelper.glUniform1i( uniformWidth, width );
|
||||||
|
OpenGlHelper.glUniform1i( uniformHeight, height );
|
||||||
|
|
||||||
|
PALETTE_BUFFER.rewind();
|
||||||
|
for( int i = 0; i < 16; i++ )
|
||||||
|
{
|
||||||
|
double[] colour = palette.getColour( i );
|
||||||
|
if( greyscale )
|
||||||
|
{
|
||||||
|
float f = FixedWidthFontRenderer.toGreyscale( colour );
|
||||||
|
PALETTE_BUFFER.put( f ).put( f ).put( f );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PALETTE_BUFFER.put( (float) colour[0] ).put( (float) colour[1] ).put( (float) colour[2] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PALETTE_BUFFER.flip();
|
||||||
|
OpenGlHelper.glUniform3( uniformPalette, PALETTE_BUFFER );
|
||||||
|
}
|
||||||
|
|
||||||
|
static boolean use()
|
||||||
|
{
|
||||||
|
if( initialised )
|
||||||
|
{
|
||||||
|
if( ok ) OpenGlHelper.glUseProgram( program );
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ok = load() )
|
||||||
|
{
|
||||||
|
GL20.glUseProgram( program );
|
||||||
|
OpenGlHelper.glUniform1i( uniformFont, 0 );
|
||||||
|
OpenGlHelper.glUniform1i( uniformTbo, TEXTURE_INDEX - GL13.GL_TEXTURE0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean load()
|
||||||
|
{
|
||||||
|
initialised = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int vertexShader = loadShader( GL20.GL_VERTEX_SHADER, "assets/computercraft/shaders/monitor.vert" );
|
||||||
|
int fragmentShader = loadShader( GL20.GL_FRAGMENT_SHADER, "assets/computercraft/shaders/monitor.frag" );
|
||||||
|
|
||||||
|
program = OpenGlHelper.glCreateProgram();
|
||||||
|
OpenGlHelper.glAttachShader( program, vertexShader );
|
||||||
|
OpenGlHelper.glAttachShader( program, fragmentShader );
|
||||||
|
GL20.glBindAttribLocation( program, 0, "v_pos" );
|
||||||
|
|
||||||
|
OpenGlHelper.glLinkProgram( program );
|
||||||
|
boolean ok = OpenGlHelper.glGetProgrami( program, GL20.GL_LINK_STATUS ) != 0;
|
||||||
|
String log = OpenGlHelper.glGetProgramInfoLog( program, Short.MAX_VALUE ).trim();
|
||||||
|
if( !Strings.isNullOrEmpty( log ) )
|
||||||
|
{
|
||||||
|
ComputerCraft.log.warn( "Problems when linking monitor shader: {}", log );
|
||||||
|
}
|
||||||
|
|
||||||
|
GL20.glDetachShader( program, vertexShader );
|
||||||
|
GL20.glDetachShader( program, fragmentShader );
|
||||||
|
OpenGlHelper.glDeleteShader( vertexShader );
|
||||||
|
OpenGlHelper.glDeleteShader( fragmentShader );
|
||||||
|
|
||||||
|
if( !ok ) return false;
|
||||||
|
|
||||||
|
uniformMv = getUniformLocation( program, "u_mv" );
|
||||||
|
uniformP = getUniformLocation( program, "u_p" );
|
||||||
|
|
||||||
|
uniformFont = getUniformLocation( program, "u_font" );
|
||||||
|
uniformWidth = getUniformLocation( program, "u_width" );
|
||||||
|
uniformHeight = getUniformLocation( program, "u_height" );
|
||||||
|
uniformTbo = getUniformLocation( program, "u_tbo" );
|
||||||
|
uniformPalette = getUniformLocation( program, "u_palette" );
|
||||||
|
|
||||||
|
ComputerCraft.log.info( "Loaded monitor shader." );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
ComputerCraft.log.error( "Cannot load monitor shaders", e );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int loadShader( int kind, String path ) throws IOException
|
||||||
|
{
|
||||||
|
InputStream stream = TileEntityMonitorRenderer.class.getClassLoader().getResourceAsStream( path );
|
||||||
|
if( stream == null ) throw new IllegalArgumentException( "Cannot find " + path );
|
||||||
|
byte[] contents = IOUtils.toByteArray( new BufferedInputStream( stream ) );
|
||||||
|
ByteBuffer buffer = BufferUtils.createByteBuffer( contents.length );
|
||||||
|
buffer.put( contents );
|
||||||
|
buffer.position( 0 );
|
||||||
|
|
||||||
|
int shader = OpenGlHelper.glCreateShader( kind );
|
||||||
|
|
||||||
|
OpenGlHelper.glShaderSource( shader, buffer );
|
||||||
|
OpenGlHelper.glCompileShader( shader );
|
||||||
|
|
||||||
|
boolean ok = OpenGlHelper.glGetShaderi( shader, GL20.GL_COMPILE_STATUS ) != 0;
|
||||||
|
String log = OpenGlHelper.glGetShaderInfoLog( shader, Short.MAX_VALUE ).trim();
|
||||||
|
if( !Strings.isNullOrEmpty( log ) )
|
||||||
|
{
|
||||||
|
ComputerCraft.log.warn( "Problems when loading monitor shader {}: {}", path, log );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !ok ) throw new IllegalStateException( "Cannot compile shader " + path );
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getUniformLocation( int program, String name )
|
||||||
|
{
|
||||||
|
int uniform = OpenGlHelper.glGetUniformLocation( program, name );
|
||||||
|
if( uniform == -1 ) throw new IllegalStateException( "Cannot find uniform " + name );
|
||||||
|
return uniform;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,14 +5,14 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager.DestFactor;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
@@ -24,7 +24,7 @@ import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAG
|
|||||||
public final class PrintoutRenderer
|
public final class PrintoutRenderer
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BG = new ResourceLocation( "computercraft", "textures/gui/printout.png" );
|
private static final ResourceLocation BG = new ResourceLocation( "computercraft", "textures/gui/printout.png" );
|
||||||
private static final float BG_SIZE = 256.0f;
|
private static final double BG_SIZE = 256.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Width of a page.
|
* Width of a page.
|
||||||
@@ -72,14 +72,31 @@ public final class PrintoutRenderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void drawText( int x, int y, int start, String[] text, String[] colours )
|
||||||
|
{
|
||||||
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.enableTexture2D();
|
||||||
|
GlStateManager.tryBlendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
|
||||||
|
|
||||||
|
for( int line = 0; line < LINES_PER_PAGE && line < text.length; line++ )
|
||||||
|
{
|
||||||
|
FixedWidthFontRenderer.drawString(
|
||||||
|
x, y + line * FONT_HEIGHT,
|
||||||
|
new TextBuffer( text[start + line] ), new TextBuffer( colours[start + line] ),
|
||||||
|
null, Palette.DEFAULT, false, 0, 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void drawBorder( double x, double y, double z, int page, int pages, boolean isBook )
|
public static void drawBorder( double x, double y, double z, int page, int pages, boolean isBook )
|
||||||
{
|
{
|
||||||
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
RenderSystem.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
RenderSystem.enableTexture();
|
GlStateManager.enableTexture2D();
|
||||||
RenderSystem.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
|
GlStateManager.tryBlendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
|
||||||
|
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( BG );
|
Minecraft.getMinecraft().getTextureManager().bindTexture( BG );
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
@@ -109,8 +126,8 @@ public final class PrintoutRenderer
|
|||||||
while( borderX < right )
|
while( borderX < right )
|
||||||
{
|
{
|
||||||
double thisWidth = Math.min( right - borderX, X_SIZE );
|
double thisWidth = Math.min( right - borderX, X_SIZE );
|
||||||
drawTexture( buffer, borderX, y - 8, z - 0.02, 0, COVER_Y, (float) thisWidth, COVER_SIZE );
|
drawTexture( buffer, borderX, y - 8, z - 0.02, 0, COVER_Y, thisWidth, COVER_SIZE );
|
||||||
drawTexture( buffer, borderX, y + Y_SIZE - 4, z - 0.02, 0, COVER_Y + COVER_SIZE, (float) thisWidth, COVER_SIZE );
|
drawTexture( buffer, borderX, y + Y_SIZE - 4, z - 0.02, 0, COVER_Y + COVER_SIZE, thisWidth, COVER_SIZE );
|
||||||
borderX += thisWidth;
|
borderX += thisWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +159,7 @@ public final class PrintoutRenderer
|
|||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, float u, float v, float width, float height )
|
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double u, double v, double width, double height )
|
||||||
{
|
{
|
||||||
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
||||||
buffer.pos( x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
buffer.pos( x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
||||||
@@ -150,7 +167,7 @@ public final class PrintoutRenderer
|
|||||||
buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double width, double height, float u, float v, float tWidth, float tHeight )
|
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double width, double height, double u, double v, double tWidth, double tHeight )
|
||||||
{
|
{
|
||||||
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
||||||
buffer.pos( x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
buffer.pos( x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
||||||
|
|||||||
@@ -0,0 +1,132 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.shared.peripheral.PeripheralType;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCableModemVariant;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.RenderGlobal;
|
||||||
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
|
import net.minecraft.util.BlockRenderLayer;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.client.ForgeHooksClient;
|
||||||
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render breaking animation only over part of a {@link TileCable}.
|
||||||
|
*/
|
||||||
|
public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void render( @Nonnull TileCable te, double x, double y, double z, float partialTicks, int destroyStage, float alpha )
|
||||||
|
{
|
||||||
|
if( destroyStage < 0 ) return;
|
||||||
|
|
||||||
|
BlockPos pos = te.getPos();
|
||||||
|
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
|
RayTraceResult hit = mc.objectMouseOver;
|
||||||
|
if( hit == null || !hit.getBlockPos().equals( pos ) ) return;
|
||||||
|
|
||||||
|
if( MinecraftForgeClient.getRenderPass() != 0 ) return;
|
||||||
|
|
||||||
|
World world = te.getWorld();
|
||||||
|
IBlockState state = world.getBlockState( pos );
|
||||||
|
Block block = state.getBlock();
|
||||||
|
if( block != ComputerCraft.Blocks.cable ) return;
|
||||||
|
|
||||||
|
state = state.getActualState( world, pos );
|
||||||
|
if( te.getPeripheralType() != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||||
|
{
|
||||||
|
state = block.getDefaultState().withProperty( BlockCable.MODEM, state.getValue( BlockCable.MODEM ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state = state.withProperty( BlockCable.MODEM, BlockCableModemVariant.None );
|
||||||
|
}
|
||||||
|
|
||||||
|
IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state );
|
||||||
|
if( model == null ) return;
|
||||||
|
|
||||||
|
preRenderDamagedBlocks();
|
||||||
|
|
||||||
|
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
|
||||||
|
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.BLOCK );
|
||||||
|
buffer.setTranslation( x - pos.getX(), y - pos.getY(), z - pos.getZ() );
|
||||||
|
buffer.noColor();
|
||||||
|
|
||||||
|
ForgeHooksClient.setRenderLayer( block.getRenderLayer() );
|
||||||
|
|
||||||
|
// See BlockRendererDispatcher#renderBlockDamage
|
||||||
|
TextureAtlasSprite breakingTexture = mc.getTextureMapBlocks().getAtlasSprite( "minecraft:blocks/destroy_stage_" + destroyStage );
|
||||||
|
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
|
||||||
|
world,
|
||||||
|
ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos ),
|
||||||
|
state, pos, buffer, true
|
||||||
|
);
|
||||||
|
|
||||||
|
ForgeHooksClient.setRenderLayer( BlockRenderLayer.SOLID );
|
||||||
|
|
||||||
|
buffer.setTranslation( 0, 0, 0 );
|
||||||
|
Tessellator.getInstance().draw();
|
||||||
|
|
||||||
|
postRenderDamagedBlocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the state for rendering block-breaking progress.
|
||||||
|
*
|
||||||
|
* @see RenderGlobal#preRenderDamagedBlocks()
|
||||||
|
*/
|
||||||
|
private void preRenderDamagedBlocks()
|
||||||
|
{
|
||||||
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.tryBlendFuncSeparate( GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 0.5F );
|
||||||
|
GlStateManager.doPolygonOffset( -3.0F, -3.0F );
|
||||||
|
GlStateManager.enablePolygonOffset();
|
||||||
|
GlStateManager.alphaFunc( 516, 0.1F );
|
||||||
|
GlStateManager.enableAlpha();
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tear down the state for rendering block-breaking progress.
|
||||||
|
*
|
||||||
|
* @see RenderGlobal#postRenderDamagedBlocks()
|
||||||
|
*/
|
||||||
|
private void postRenderDamagedBlocks()
|
||||||
|
{
|
||||||
|
GlStateManager.disableAlpha();
|
||||||
|
GlStateManager.doPolygonOffset( 0.0F, 0.0F );
|
||||||
|
GlStateManager.disablePolygonOffset();
|
||||||
|
GlStateManager.disablePolygonOffset();
|
||||||
|
GlStateManager.depthMask( true );
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,40 +5,44 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import dan200.computercraft.client.FrameInfo;
|
import dan200.computercraft.client.FrameInfo;
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
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.peripheral.monitor.TileMonitor;
|
||||||
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.shared.util.DirectionUtil;
|
import dan200.computercraft.shared.util.DirectionUtil;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.*;
|
import net.minecraft.client.renderer.*;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.client.renderer.vertex.VertexBuffer;
|
import net.minecraft.client.renderer.vertex.VertexBuffer;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
import org.lwjgl.opengl.GL13;
|
||||||
|
import org.lwjgl.opengl.GL15;
|
||||||
|
import org.lwjgl.opengl.GL31;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
|
||||||
|
import static dan200.computercraft.shared.peripheral.monitor.TileMonitor.RENDER_MARGIN;
|
||||||
|
|
||||||
|
public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMonitor>
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* {@link TileMonitor#RENDER_MARGIN}, but a tiny bit of additional padding to ensure that there is no space between
|
|
||||||
* the monitor frame and contents.
|
|
||||||
*/
|
|
||||||
private static final float MARGIN = (float) (TileMonitor.RENDER_MARGIN * 1.1);
|
private static final float MARGIN = (float) (TileMonitor.RENDER_MARGIN * 1.1);
|
||||||
|
|
||||||
private static final Matrix4f IDENTITY = TransformationMatrix.identity().getMatrix();
|
@Override
|
||||||
|
public void render( @Nonnull TileMonitor tileEntity, double posX, double posY, double posZ, float f, int i, float f2 )
|
||||||
public TileEntityMonitorRenderer( TileEntityRendererDispatcher rendererDispatcher )
|
|
||||||
{
|
{
|
||||||
super( rendererDispatcher );
|
renderMonitorAt( tileEntity, posX, posY, posZ, f, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static void renderMonitorAt( TileMonitor monitor, double posX, double posY, double posZ, float f, int i )
|
||||||
public void render( @Nonnull TileMonitor monitor, float partialTicks, @Nonnull MatrixStack transform, @Nonnull IRenderTypeBuffer renderer, int lightmapCoord, int overlayLight )
|
|
||||||
{
|
{
|
||||||
// Render from the origin monitor
|
// Render from the origin monitor
|
||||||
ClientMonitor originTerminal = monitor.getClientMonitor();
|
ClientMonitor originTerminal = monitor.getClientMonitor();
|
||||||
@@ -60,101 +64,198 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
originTerminal.lastRenderPos = monitorPos;
|
originTerminal.lastRenderPos = monitorPos;
|
||||||
|
|
||||||
BlockPos originPos = origin.getPos();
|
BlockPos originPos = origin.getPos();
|
||||||
|
posX += originPos.getX() - monitorPos.getX();
|
||||||
|
posY += originPos.getY() - monitorPos.getY();
|
||||||
|
posZ += originPos.getZ() - monitorPos.getZ();
|
||||||
|
|
||||||
// Determine orientation
|
// Determine orientation
|
||||||
Direction dir = origin.getDirection();
|
EnumFacing dir = origin.getDirection();
|
||||||
Direction front = origin.getFront();
|
EnumFacing front = origin.getFront();
|
||||||
float yaw = dir.getHorizontalAngle();
|
float yaw = dir.getHorizontalAngle();
|
||||||
float pitch = DirectionUtil.toPitchAngle( front );
|
float pitch = DirectionUtil.toPitchAngle( front );
|
||||||
|
|
||||||
// Setup initial transform
|
GlStateManager.pushMatrix();
|
||||||
transform.push();
|
|
||||||
transform.translate(
|
|
||||||
originPos.getX() - monitorPos.getX() + 0.5,
|
|
||||||
originPos.getY() - monitorPos.getY() + 0.5,
|
|
||||||
originPos.getZ() - monitorPos.getZ() + 0.5
|
|
||||||
);
|
|
||||||
|
|
||||||
transform.rotate( Vector3f.YN.rotationDegrees( yaw ) );
|
// Setup initial transform
|
||||||
transform.rotate( Vector3f.XP.rotationDegrees( pitch ) );
|
GlStateManager.translate( posX + 0.5, posY + 0.5, posZ + 0.5 );
|
||||||
transform.translate(
|
GlStateManager.rotate( -yaw, 0.0f, 1.0f, 0.0f );
|
||||||
-0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
|
GlStateManager.rotate( pitch, 1.0f, 0.0f, 0.0f );
|
||||||
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0,
|
GlStateManager.translate(
|
||||||
|
-0.5 + TileMonitor.RENDER_BORDER + RENDER_MARGIN,
|
||||||
|
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + RENDER_MARGIN),
|
||||||
0.5
|
0.5
|
||||||
);
|
);
|
||||||
double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
double xSize = origin.getWidth() - 2.0 * (RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||||
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
double ySize = origin.getHeight() - 2.0 * (RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||||
|
|
||||||
|
// Get renderers
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
|
// Set up render state for monitors. We disable writing to the depth buffer (we draw a "blocker" later),
|
||||||
|
// and setup lighting so that we render with a glow.
|
||||||
|
GlStateManager.depthMask( false );
|
||||||
|
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, 0xFF, 0xFF );
|
||||||
|
GlStateManager.disableLighting();
|
||||||
|
mc.entityRenderer.disableLightmap();
|
||||||
|
|
||||||
// Draw the contents
|
|
||||||
Terminal terminal = originTerminal.getTerminal();
|
Terminal terminal = originTerminal.getTerminal();
|
||||||
if( terminal != null )
|
if( terminal != null )
|
||||||
{
|
{
|
||||||
boolean redraw = originTerminal.pollTerminalChanged();
|
|
||||||
if( originTerminal.buffer == null )
|
|
||||||
{
|
|
||||||
originTerminal.createBuffer();
|
|
||||||
redraw = true;
|
|
||||||
}
|
|
||||||
VertexBuffer vbo = originTerminal.buffer;
|
|
||||||
|
|
||||||
// Draw a terminal
|
// Draw a terminal
|
||||||
double xScale = xSize / (terminal.getWidth() * FixedWidthFontRenderer.FONT_WIDTH);
|
double xScale = xSize / (terminal.getWidth() * FONT_WIDTH);
|
||||||
double yScale = ySize / (terminal.getHeight() * FixedWidthFontRenderer.FONT_HEIGHT);
|
double yScale = ySize / (terminal.getHeight() * FONT_HEIGHT);
|
||||||
transform.push();
|
|
||||||
transform.scale( (float) xScale, (float) -yScale, 1.0f );
|
|
||||||
|
|
||||||
float xMargin = (float) (MARGIN / xScale);
|
GlStateManager.pushMatrix();
|
||||||
float yMargin = (float) (MARGIN / yScale);
|
GlStateManager.scale( (float) xScale, (float) -yScale, 1.0f );
|
||||||
|
|
||||||
Matrix4f matrix = transform.getLast().getPositionMatrix();
|
renderTerminal( originTerminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale) );
|
||||||
|
|
||||||
if( redraw )
|
GlStateManager.popMatrix();
|
||||||
{
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder builder = tessellator.getBuffer();
|
|
||||||
builder.begin( FixedWidthFontRenderer.TYPE.getGlMode(), FixedWidthFontRenderer.TYPE.getVertexFormat() );
|
|
||||||
FixedWidthFontRenderer.drawTerminalWithoutCursor(
|
|
||||||
IDENTITY, builder, 0, 0,
|
|
||||||
terminal, !originTerminal.isColour(), yMargin, yMargin, xMargin, xMargin
|
|
||||||
);
|
|
||||||
|
|
||||||
builder.finishDrawing();
|
|
||||||
vbo.upload( builder );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sneaky hack here: we get a buffer now in order to flush existing ones and set up the appropriate
|
|
||||||
// render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick
|
|
||||||
// for now.
|
|
||||||
IVertexBuilder buffer = renderer.getBuffer( FixedWidthFontRenderer.TYPE );
|
|
||||||
FixedWidthFontRenderer.TYPE.enable();
|
|
||||||
|
|
||||||
vbo.bindBuffer();
|
|
||||||
FixedWidthFontRenderer.TYPE.getVertexFormat().setupBufferState( 0L );
|
|
||||||
vbo.draw( matrix, FixedWidthFontRenderer.TYPE.getGlMode() );
|
|
||||||
VertexBuffer.unbindBuffer();
|
|
||||||
FixedWidthFontRenderer.TYPE.getVertexFormat().clearBufferState();
|
|
||||||
|
|
||||||
// We don't draw the cursor with the VBO, as it's dynamic and so we'll end up refreshing far more than is
|
|
||||||
// reasonable.
|
|
||||||
FixedWidthFontRenderer.drawCursor( matrix, buffer, 0, 0, terminal, !originTerminal.isColour() );
|
|
||||||
|
|
||||||
transform.pop();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FixedWidthFontRenderer.drawEmptyTerminal(
|
FixedWidthFontRenderer.drawEmptyTerminal(
|
||||||
transform.getLast().getPositionMatrix(), renderer,
|
|
||||||
-MARGIN, MARGIN,
|
-MARGIN, MARGIN,
|
||||||
(float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2)
|
(float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tear down render state for monitors.
|
||||||
|
GlStateManager.depthMask( true );
|
||||||
|
mc.entityRenderer.enableLightmap();
|
||||||
|
GlStateManager.enableLighting();
|
||||||
|
|
||||||
|
// Draw the depth blocker
|
||||||
|
GlStateManager.colorMask( false, false, false, false );
|
||||||
FixedWidthFontRenderer.drawBlocker(
|
FixedWidthFontRenderer.drawBlocker(
|
||||||
transform.getLast().getPositionMatrix(), renderer,
|
|
||||||
(float) -TileMonitor.RENDER_MARGIN, (float) TileMonitor.RENDER_MARGIN,
|
(float) -TileMonitor.RENDER_MARGIN, (float) TileMonitor.RENDER_MARGIN,
|
||||||
(float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2)
|
(float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2)
|
||||||
);
|
);
|
||||||
|
GlStateManager.colorMask( true, true, true, true );
|
||||||
|
|
||||||
transform.pop();
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderTerminal( ClientMonitor monitor, float xMargin, float yMargin )
|
||||||
|
{
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
|
||||||
|
boolean redraw = monitor.pollTerminalChanged();
|
||||||
|
|
||||||
|
// Setup the buffers if needed. We get the renderer here, to avoid the (unlikely) race condition between
|
||||||
|
// creating the buffers and rendering.
|
||||||
|
MonitorRenderer renderer = MonitorRenderer.current();
|
||||||
|
if( monitor.createBuffer( renderer ) ) redraw = true;
|
||||||
|
|
||||||
|
FixedWidthFontRenderer.bindFont();
|
||||||
|
|
||||||
|
switch( renderer )
|
||||||
|
{
|
||||||
|
case TBO:
|
||||||
|
{
|
||||||
|
if( !MonitorTextureBufferShader.use() ) return;
|
||||||
|
|
||||||
|
Terminal terminal = monitor.getTerminal();
|
||||||
|
int width = terminal.getWidth(), height = terminal.getHeight();
|
||||||
|
int pixelWidth = width * FONT_WIDTH, pixelHeight = height * FONT_HEIGHT;
|
||||||
|
|
||||||
|
if( redraw )
|
||||||
|
{
|
||||||
|
ByteBuffer monitorBuffer = GLAllocation.createDirectByteBuffer( width * height * 3 );
|
||||||
|
for( int y = 0; y < height; y++ )
|
||||||
|
{
|
||||||
|
TextBuffer text = terminal.getLine( y ), textColour = terminal.getTextColourLine( y ), background = terminal.getBackgroundColourLine( y );
|
||||||
|
for( int x = 0; x < width; x++ )
|
||||||
|
{
|
||||||
|
monitorBuffer.put( (byte) (text.charAt( x ) & 0xFF) );
|
||||||
|
monitorBuffer.put( (byte) getColour( textColour.charAt( x ), Colour.White ) );
|
||||||
|
monitorBuffer.put( (byte) getColour( background.charAt( x ), Colour.Black ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
monitorBuffer.flip();
|
||||||
|
|
||||||
|
OpenGlHelper.glBindBuffer( GL31.GL_TEXTURE_BUFFER, monitor.tboBuffer );
|
||||||
|
OpenGlHelper.glBufferData( GL31.GL_TEXTURE_BUFFER, monitorBuffer, GL15.GL_STATIC_DRAW );
|
||||||
|
OpenGlHelper.glBindBuffer( GL31.GL_TEXTURE_BUFFER, 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bind TBO texture and set up the uniforms. We've already set up the main font above.
|
||||||
|
GlStateManager.setActiveTexture( MonitorTextureBufferShader.TEXTURE_INDEX );
|
||||||
|
GL11.glBindTexture( GL31.GL_TEXTURE_BUFFER, monitor.tboTexture );
|
||||||
|
GlStateManager.setActiveTexture( GL13.GL_TEXTURE0 );
|
||||||
|
|
||||||
|
MonitorTextureBufferShader.setupUniform( width, height, terminal.getPalette(), !monitor.isColour() );
|
||||||
|
|
||||||
|
buffer.begin( GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION );
|
||||||
|
buffer.pos( -xMargin, -yMargin, 0 ).endVertex();
|
||||||
|
buffer.pos( -xMargin, pixelHeight + yMargin, 0 ).endVertex();
|
||||||
|
buffer.pos( pixelWidth + xMargin, -yMargin, 0 ).endVertex();
|
||||||
|
buffer.pos( pixelWidth + xMargin, pixelHeight + yMargin, 0 ).endVertex();
|
||||||
|
tessellator.draw();
|
||||||
|
|
||||||
|
OpenGlHelper.glUseProgram( 0 );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case VBO:
|
||||||
|
{
|
||||||
|
VertexBuffer vbo = monitor.buffer;
|
||||||
|
if( redraw )
|
||||||
|
{
|
||||||
|
renderTerminalTo( monitor, buffer, xMargin, yMargin );
|
||||||
|
buffer.finishDrawing();
|
||||||
|
buffer.reset();
|
||||||
|
vbo.bufferData( buffer.getByteBuffer() );
|
||||||
|
}
|
||||||
|
|
||||||
|
vbo.bindBuffer();
|
||||||
|
setupBufferFormat();
|
||||||
|
vbo.drawArrays( GL11.GL_TRIANGLES );
|
||||||
|
vbo.unbindBuffer();
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case DISPLAY_LIST:
|
||||||
|
if( redraw )
|
||||||
|
{
|
||||||
|
GlStateManager.glNewList( monitor.displayList, GL11.GL_COMPILE );
|
||||||
|
renderTerminalTo( monitor, buffer, xMargin, yMargin );
|
||||||
|
tessellator.draw();
|
||||||
|
GlStateManager.glEndList();
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateManager.callList( monitor.displayList );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We don't draw the cursor with a buffer, as it's dynamic and so we'll end up refreshing far more than is
|
||||||
|
// reasonable.
|
||||||
|
FixedWidthFontRenderer.begin( buffer );
|
||||||
|
FixedWidthFontRenderer.drawCursor( buffer, 0, 0, monitor.getTerminal(), !monitor.isColour() );
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderTerminalTo( ClientMonitor monitor, BufferBuilder buffer, float xMargin, float yMargin )
|
||||||
|
{
|
||||||
|
FixedWidthFontRenderer.begin( buffer );
|
||||||
|
FixedWidthFontRenderer.drawTerminalWithoutCursor(
|
||||||
|
buffer, 0, 0,
|
||||||
|
monitor.getTerminal(), !monitor.isColour(), yMargin, yMargin, xMargin, xMargin
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setupBufferFormat()
|
||||||
|
{
|
||||||
|
int stride = FixedWidthFontRenderer.POSITION_COLOR_TEX.getSize();
|
||||||
|
GlStateManager.glVertexPointer( 3, GL11.GL_FLOAT, stride, 0 );
|
||||||
|
GlStateManager.glEnableClientState( GL11.GL_VERTEX_ARRAY );
|
||||||
|
|
||||||
|
GlStateManager.glColorPointer( 4, GL11.GL_UNSIGNED_BYTE, stride, 12 );
|
||||||
|
GlStateManager.glEnableClientState( GL11.GL_COLOR_ARRAY );
|
||||||
|
|
||||||
|
GlStateManager.glTexCoordPointer( 2, GL11.GL_FLOAT, stride, 16 );
|
||||||
|
GlStateManager.glEnableClientState( GL11.GL_TEXTURE_COORD_ARRAY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,51 +5,48 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.util.DirectionUtil;
|
|
||||||
import dan200.computercraft.shared.util.Holiday;
|
import dan200.computercraft.shared.util.Holiday;
|
||||||
import dan200.computercraft.shared.util.HolidayUtil;
|
import dan200.computercraft.shared.util.HolidayUtil;
|
||||||
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.renderer.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.Atlases;
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.Matrix4f;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.Vector3f;
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||||
import net.minecraft.client.renderer.model.ModelManager;
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.texture.TextureMap;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
import net.minecraftforge.client.ForgeHooksClient;
|
||||||
|
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.vecmath.Matrix4f;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurtle>
|
||||||
{
|
{
|
||||||
private static final ModelResourceLocation NORMAL_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_normal", "inventory" );
|
private static final ModelResourceLocation NORMAL_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle", "inventory" );
|
||||||
private static final ModelResourceLocation ADVANCED_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_advanced", "inventory" );
|
private static final ModelResourceLocation ADVANCED_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_advanced", "inventory" );
|
||||||
private static final ModelResourceLocation COLOUR_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_colour", "inventory" );
|
private static final ModelResourceLocation COLOUR_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_white", "inventory" );
|
||||||
private static final ModelResourceLocation ELF_OVERLAY_MODEL = new ModelResourceLocation( "computercraft:turtle_elf_overlay", "inventory" );
|
private static final ModelResourceLocation ELF_OVERLAY_MODEL = new ModelResourceLocation( "computercraft:turtle_elf_overlay", "inventory" );
|
||||||
|
|
||||||
private final Random random = new Random( 0 );
|
@Override
|
||||||
|
public void render( TileTurtle tileEntity, double posX, double posY, double posZ, float partialTicks, int breaking, float f2 )
|
||||||
public TileEntityTurtleRenderer( TileEntityRendererDispatcher renderDispatcher )
|
|
||||||
{
|
{
|
||||||
super( renderDispatcher );
|
if( tileEntity != null ) renderTurtleAt( tileEntity, posX, posY, posZ, partialTicks );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModelResourceLocation getTurtleModel( ComputerFamily family, boolean coloured )
|
public static ModelResourceLocation getTurtleModel( ComputerFamily family, boolean coloured )
|
||||||
@@ -66,126 +63,169 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
|
|
||||||
public static ModelResourceLocation getTurtleOverlayModel( ResourceLocation overlay, boolean christmas )
|
public static ModelResourceLocation getTurtleOverlayModel( ResourceLocation overlay, boolean christmas )
|
||||||
{
|
{
|
||||||
if( overlay != null ) return new ModelResourceLocation( overlay, "inventory" );
|
if( overlay != null )
|
||||||
if( christmas ) return ELF_OVERLAY_MODEL;
|
{
|
||||||
return null;
|
return new ModelResourceLocation( overlay, "inventory" );
|
||||||
|
}
|
||||||
|
else if( christmas )
|
||||||
|
{
|
||||||
|
return ELF_OVERLAY_MODEL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void renderTurtleAt( TileTurtle turtle, double posX, double posY, double posZ, float partialTicks )
|
||||||
public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull MatrixStack transform, @Nonnull IRenderTypeBuffer renderer, int lightmapCoord, int overlayLight )
|
|
||||||
{
|
{
|
||||||
// Render the label
|
// Render the label
|
||||||
String label = turtle.createProxy().getLabel();
|
String label = turtle.createProxy().getLabel();
|
||||||
RayTraceResult hit = renderDispatcher.cameraHitResult;
|
if( label != null && rendererDispatcher.cameraHitResult != null && turtle.getPos().equals( rendererDispatcher.cameraHitResult.getBlockPos() ) )
|
||||||
if( label != null && hit.getType() == RayTraceResult.Type.BLOCK && turtle.getPos().equals( ((BlockRayTraceResult) hit).getPos() ) )
|
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getInstance();
|
setLightmapDisabled( true );
|
||||||
FontRenderer font = renderDispatcher.fontRenderer;
|
EntityRenderer.drawNameplate(
|
||||||
|
getFontRenderer(), label,
|
||||||
transform.push();
|
(float) posX + 0.5F, (float) posY + 1.2F, (float) posZ + 0.5F, 0,
|
||||||
transform.translate( 0.5, 1.2, 0.5 );
|
rendererDispatcher.entityYaw, rendererDispatcher.entityPitch, false, false
|
||||||
transform.rotate( mc.getRenderManager().getCameraOrientation() );
|
);
|
||||||
transform.scale( -0.025f, -0.025f, 0.025f );
|
setLightmapDisabled( false );
|
||||||
|
|
||||||
Matrix4f matrix = transform.getLast().getPositionMatrix();
|
|
||||||
int opacity = (int) (mc.gameSettings.getTextBackgroundOpacity( 0.25f ) * 255) << 24;
|
|
||||||
float width = -font.getStringWidth( label ) / 2.0f;
|
|
||||||
font.renderString( label, width, (float) 0, 0x20ffffff, false, matrix, renderer, true, opacity, lightmapCoord );
|
|
||||||
font.renderString( label, width, (float) 0, 0xffffffff, false, matrix, renderer, false, 0, lightmapCoord );
|
|
||||||
|
|
||||||
transform.pop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transform.push();
|
GlStateManager.pushMatrix();
|
||||||
|
try
|
||||||
// Setup the transform.
|
|
||||||
Vec3d offset = turtle.getRenderOffset( partialTicks );
|
|
||||||
float yaw = turtle.getRenderYaw( partialTicks );
|
|
||||||
transform.translate( offset.x, offset.y, offset.z );
|
|
||||||
|
|
||||||
transform.translate( 0.5f, 0.5f, 0.5f );
|
|
||||||
transform.rotate( Vector3f.YP.rotationDegrees( 180.0f - yaw ) );
|
|
||||||
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
|
||||||
{
|
{
|
||||||
// Flip the model
|
IBlockState state = turtle.getWorld().getBlockState( turtle.getPos() );
|
||||||
transform.scale( 1.0f, -1.0f, 1.0f );
|
// Setup the transform
|
||||||
}
|
Vec3d offset = turtle.getRenderOffset( partialTicks );
|
||||||
transform.translate( -0.5f, -0.5f, -0.5f );
|
float yaw = turtle.getRenderYaw( partialTicks );
|
||||||
|
GlStateManager.translate( posX + offset.x, posY + offset.y, posZ + offset.z );
|
||||||
|
|
||||||
// Render the turtle
|
// Render the turtle
|
||||||
int colour = turtle.getColour();
|
GlStateManager.translate( 0.5f, 0.5f, 0.5f );
|
||||||
ComputerFamily family = turtle.getFamily();
|
GlStateManager.rotate( 180.0f - yaw, 0.0f, 1.0f, 0.0f );
|
||||||
ResourceLocation overlay = turtle.getOverlay();
|
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
||||||
|
|
||||||
IVertexBuilder buffer = renderer.getBuffer( Atlases.getTranslucentCullBlockType() );
|
|
||||||
renderModel( transform, buffer, lightmapCoord, overlayLight, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
|
|
||||||
|
|
||||||
// Render the overlay
|
|
||||||
ModelResourceLocation overlayModel = getTurtleOverlayModel( overlay, HolidayUtil.getCurrentHoliday() == Holiday.Christmas );
|
|
||||||
if( overlayModel != null )
|
|
||||||
{
|
|
||||||
renderModel( transform, buffer, lightmapCoord, overlayLight, overlayModel, null );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render the upgrades
|
|
||||||
renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.Left, partialTicks );
|
|
||||||
renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.Right, partialTicks );
|
|
||||||
|
|
||||||
transform.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderUpgrade( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, TileTurtle turtle, TurtleSide side, float f )
|
|
||||||
{
|
|
||||||
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
|
||||||
if( upgrade == null ) return;
|
|
||||||
transform.push();
|
|
||||||
|
|
||||||
float toolAngle = turtle.getToolRenderAngle( side, f );
|
|
||||||
transform.translate( 0.0f, 0.5f, 0.5f );
|
|
||||||
transform.rotate( Vector3f.XN.rotationDegrees( toolAngle ) );
|
|
||||||
transform.translate( 0.0f, -0.5f, -0.5f );
|
|
||||||
|
|
||||||
TransformedModel model = upgrade.getModel( turtle.getAccess(), side );
|
|
||||||
model.getMatrix().push( transform );
|
|
||||||
renderModel( transform, renderer, lightmapCoord, overlayLight, model.getModel(), null );
|
|
||||||
transform.pop();
|
|
||||||
|
|
||||||
transform.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderModel( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, ModelResourceLocation modelLocation, int[] tints )
|
|
||||||
{
|
|
||||||
ModelManager modelManager = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getModelManager();
|
|
||||||
renderModel( transform, renderer, lightmapCoord, overlayLight, modelManager.getModel( modelLocation ), tints );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderModel( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, IBakedModel model, int[] tints )
|
|
||||||
{
|
|
||||||
random.setSeed( 0 );
|
|
||||||
renderQuads( transform, renderer, lightmapCoord, overlayLight, model.getQuads( null, null, random, EmptyModelData.INSTANCE ), tints );
|
|
||||||
for( Direction facing : DirectionUtil.FACINGS )
|
|
||||||
{
|
|
||||||
renderQuads( transform, renderer, lightmapCoord, overlayLight, model.getQuads( null, facing, random, EmptyModelData.INSTANCE ), tints );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderQuads( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder buffer, int lightmapCoord, int overlayLight, List<BakedQuad> quads, int[] tints )
|
|
||||||
{
|
|
||||||
MatrixStack.Entry matrix = transform.getLast();
|
|
||||||
|
|
||||||
for( BakedQuad bakedquad : quads )
|
|
||||||
{
|
|
||||||
int tint = -1;
|
|
||||||
if( tints != null && bakedquad.hasTintIndex() )
|
|
||||||
{
|
{
|
||||||
int idx = bakedquad.getTintIndex();
|
// Flip the model and swap the cull face as winding order will have changed.
|
||||||
if( idx >= 0 && idx < tints.length ) tint = tints[bakedquad.getTintIndex()];
|
GlStateManager.scale( 1.0f, -1.0f, 1.0f );
|
||||||
|
GlStateManager.cullFace( GlStateManager.CullFace.FRONT );
|
||||||
|
}
|
||||||
|
GlStateManager.translate( -0.5f, -0.5f, -0.5f );
|
||||||
|
// Render the turtle
|
||||||
|
int colour = turtle.getColour();
|
||||||
|
ComputerFamily family = turtle.getFamily();
|
||||||
|
ResourceLocation overlay = turtle.getOverlay();
|
||||||
|
|
||||||
|
renderModel( state, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
|
||||||
|
|
||||||
|
// Render the overlay
|
||||||
|
ModelResourceLocation overlayModel = getTurtleOverlayModel(
|
||||||
|
overlay,
|
||||||
|
HolidayUtil.getCurrentHoliday() == Holiday.Christmas
|
||||||
|
);
|
||||||
|
if( overlayModel != null )
|
||||||
|
{
|
||||||
|
GlStateManager.disableCull();
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.blendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
renderModel( state, overlayModel, null );
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
GlStateManager.disableBlend();
|
||||||
|
GlStateManager.enableCull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float f = (float) (tint >> 16 & 255) / 255.0F;
|
// Render the upgrades
|
||||||
float f1 = (float) (tint >> 8 & 255) / 255.0F;
|
renderUpgrade( state, turtle, TurtleSide.Left, partialTicks );
|
||||||
float f2 = (float) (tint & 255) / 255.0F;
|
renderUpgrade( state, turtle, TurtleSide.Right, partialTicks );
|
||||||
buffer.addVertexData( matrix, bakedquad, f, f1, f2, lightmapCoord, overlayLight, true );
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
GlStateManager.cullFace( GlStateManager.CullFace.BACK );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void renderUpgrade( IBlockState state, TileTurtle turtle, TurtleSide side, float f )
|
||||||
|
{
|
||||||
|
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
||||||
|
if( upgrade != null )
|
||||||
|
{
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
float toolAngle = turtle.getToolRenderAngle( side, f );
|
||||||
|
GlStateManager.translate( 0.0f, 0.5f, 0.5f );
|
||||||
|
GlStateManager.rotate( -toolAngle, 1.0f, 0.0f, 0.0f );
|
||||||
|
GlStateManager.translate( 0.0f, -0.5f, -0.5f );
|
||||||
|
|
||||||
|
Pair<IBakedModel, Matrix4f> pair = upgrade.getModel( turtle.getAccess(), side );
|
||||||
|
if( pair != null )
|
||||||
|
{
|
||||||
|
if( pair.getRight() != null )
|
||||||
|
{
|
||||||
|
ForgeHooksClient.multiplyCurrentGlMatrix( pair.getRight() );
|
||||||
|
}
|
||||||
|
if( pair.getLeft() != null )
|
||||||
|
{
|
||||||
|
renderModel( state, pair.getLeft(), null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderModel( IBlockState state, ModelResourceLocation modelLocation, int[] tints )
|
||||||
|
{
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
ModelManager modelManager = mc.getRenderItem().getItemModelMesher().getModelManager();
|
||||||
|
renderModel( state, modelManager.getModel( modelLocation ), tints );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderModel( IBlockState state, IBakedModel model, int[] tints )
|
||||||
|
{
|
||||||
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
|
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
||||||
|
renderQuads( tessellator, model.getQuads( state, null, 0 ), tints );
|
||||||
|
for( EnumFacing facing : EnumFacing.VALUES )
|
||||||
|
{
|
||||||
|
renderQuads( tessellator, model.getQuads( state, facing, 0 ), tints );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void renderQuads( Tessellator tessellator, List<BakedQuad> quads, int[] tints )
|
||||||
|
{
|
||||||
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
VertexFormat format = DefaultVertexFormats.ITEM;
|
||||||
|
buffer.begin( GL11.GL_QUADS, format );
|
||||||
|
for( BakedQuad quad : quads )
|
||||||
|
{
|
||||||
|
VertexFormat quadFormat = quad.getFormat();
|
||||||
|
if( quadFormat != format )
|
||||||
|
{
|
||||||
|
tessellator.draw();
|
||||||
|
format = quadFormat;
|
||||||
|
buffer.begin( GL11.GL_QUADS, format );
|
||||||
|
}
|
||||||
|
|
||||||
|
int colour = 0xFFFFFFFF;
|
||||||
|
if( quad.hasTintIndex() && tints != null )
|
||||||
|
{
|
||||||
|
int index = quad.getTintIndex();
|
||||||
|
if( index >= 0 && index < tints.length ) colour = tints[index] | 0xFF000000;
|
||||||
|
}
|
||||||
|
|
||||||
|
LightUtil.renderQuadColor( buffer, quad, colour );
|
||||||
|
}
|
||||||
|
tessellator.draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,28 +5,26 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import net.minecraft.client.renderer.model.*;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.resources.IResourceManager;
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
import net.minecraft.util.JSONUtils;
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.client.model.IModelConfiguration;
|
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||||
import net.minecraftforge.client.model.IModelLoader;
|
import net.minecraftforge.client.model.IModel;
|
||||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||||
|
import net.minecraftforge.common.model.IModelState;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.TurtleModel>
|
public final class TurtleModelLoader implements ICustomModelLoader
|
||||||
{
|
{
|
||||||
private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_colour" );
|
private static final ResourceLocation NORMAL_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle" );
|
||||||
|
private static final ResourceLocation ADVANCED_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/advanced_turtle" );
|
||||||
|
private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_white" );
|
||||||
|
|
||||||
public static final TurtleModelLoader INSTANCE = new TurtleModelLoader();
|
public static final TurtleModelLoader INSTANCE = new TurtleModelLoader();
|
||||||
|
|
||||||
@@ -39,39 +37,84 @@ public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.T
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public TurtleModel read( @Nonnull JsonDeserializationContext deserializationContext, @Nonnull JsonObject modelContents )
|
public boolean accepts( @Nonnull ResourceLocation name )
|
||||||
{
|
{
|
||||||
ResourceLocation model = new ResourceLocation( JSONUtils.getString( modelContents, "model" ) );
|
return name.getNamespace().equals( ComputerCraft.MOD_ID )
|
||||||
return new TurtleModel( model );
|
&& (name.getPath().equals( "turtle" ) || name.getPath().equals( "turtle_advanced" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class TurtleModel implements IModelGeometry<TurtleModel>
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IModel loadModel( @Nonnull ResourceLocation name ) throws Exception
|
||||||
{
|
{
|
||||||
private final ResourceLocation family;
|
if( name.getNamespace().equals( ComputerCraft.MOD_ID ) )
|
||||||
|
{
|
||||||
|
IModel colourModel = ModelLoaderRegistry.getModel( COLOUR_TURTLE_MODEL );
|
||||||
|
switch( name.getPath() )
|
||||||
|
{
|
||||||
|
case "turtle":
|
||||||
|
return new TurtleModel( ModelLoaderRegistry.getModel( NORMAL_TURTLE_MODEL ), colourModel );
|
||||||
|
case "turtle_advanced":
|
||||||
|
return new TurtleModel( ModelLoaderRegistry.getModel( ADVANCED_TURTLE_MODEL ), colourModel );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private TurtleModel( ResourceLocation family )
|
throw new IllegalStateException( "Loader does not accept " + name );
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class TurtleModel implements IModel
|
||||||
|
{
|
||||||
|
private final IModel family;
|
||||||
|
private final IModel colour;
|
||||||
|
|
||||||
|
private TurtleModel( IModel family, IModel colour )
|
||||||
{
|
{
|
||||||
this.family = family;
|
this.family = family;
|
||||||
|
this.colour = colour;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Collection<Material> getTextures( IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors )
|
public IBakedModel bake( @Nonnull IModelState state, @Nonnull VertexFormat format, @Nonnull Function<ResourceLocation, TextureAtlasSprite> function )
|
||||||
{
|
|
||||||
Set<Material> materials = new HashSet<>();
|
|
||||||
materials.addAll( modelGetter.apply( family ).getTextures( modelGetter, missingTextureErrors ) );
|
|
||||||
materials.addAll( modelGetter.apply( COLOUR_TURTLE_MODEL ).getTextures( modelGetter, missingTextureErrors ) );
|
|
||||||
return materials;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBakedModel bake( IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform transform, ItemOverrideList overrides, ResourceLocation modelLocation )
|
|
||||||
{
|
{
|
||||||
return new TurtleSmartItemModel(
|
return new TurtleSmartItemModel(
|
||||||
bakery.getBakedModel( family, transform, spriteGetter ),
|
family.bake( state, format, function ),
|
||||||
bakery.getBakedModel( COLOUR_TURTLE_MODEL, transform, spriteGetter )
|
colour.bake( state, format, function )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private TurtleModel copy( IModel family, IModel colour )
|
||||||
|
{
|
||||||
|
return this.family == family && this.colour == colour ? this : new TurtleModel( family, colour );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IModel smoothLighting( boolean value )
|
||||||
|
{
|
||||||
|
return copy( family.smoothLighting( value ), colour.smoothLighting( value ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IModel gui3d( boolean value )
|
||||||
|
{
|
||||||
|
return copy( family.gui3d( value ), colour.gui3d( value ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IModel uvlock( boolean value )
|
||||||
|
{
|
||||||
|
return copy( family.uvlock( value ), colour.uvlock( value ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IModel retexture( ImmutableMap<String, String> textures )
|
||||||
|
{
|
||||||
|
return copy( family.retexture( textures ), colour.retexture( textures ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,53 +5,48 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.TransformationMatrix;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
|
||||||
import net.minecraftforge.client.model.data.IModelData;
|
|
||||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
|
||||||
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.*;
|
import javax.vecmath.Matrix4f;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class TurtleMultiModel implements IBakedModel
|
public class TurtleMultiModel implements IBakedModel
|
||||||
{
|
{
|
||||||
private final IBakedModel m_baseModel;
|
private final IBakedModel m_baseModel;
|
||||||
private final IBakedModel m_overlayModel;
|
private final IBakedModel m_overlayModel;
|
||||||
private final TransformationMatrix m_generalTransform;
|
private final Matrix4f m_generalTransform;
|
||||||
private final TransformedModel m_leftUpgradeModel;
|
private final IBakedModel m_leftUpgradeModel;
|
||||||
private final TransformedModel m_rightUpgradeModel;
|
private final Matrix4f m_leftUpgradeTransform;
|
||||||
|
private final IBakedModel m_rightUpgradeModel;
|
||||||
|
private final Matrix4f m_rightUpgradeTransform;
|
||||||
private List<BakedQuad> m_generalQuads = null;
|
private List<BakedQuad> m_generalQuads = null;
|
||||||
private Map<Direction, List<BakedQuad>> m_faceQuads = new EnumMap<>( Direction.class );
|
private Map<EnumFacing, List<BakedQuad>> m_faceQuads = new EnumMap<>( EnumFacing.class );
|
||||||
|
|
||||||
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, TransformationMatrix generalTransform, TransformedModel leftUpgradeModel, TransformedModel rightUpgradeModel )
|
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, Matrix4f generalTransform, IBakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, IBakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform )
|
||||||
{
|
{
|
||||||
// Get the models
|
// Get the models
|
||||||
m_baseModel = baseModel;
|
m_baseModel = baseModel;
|
||||||
m_overlayModel = overlayModel;
|
m_overlayModel = overlayModel;
|
||||||
m_leftUpgradeModel = leftUpgradeModel;
|
m_leftUpgradeModel = leftUpgradeModel;
|
||||||
|
m_leftUpgradeTransform = leftUpgradeTransform;
|
||||||
m_rightUpgradeModel = rightUpgradeModel;
|
m_rightUpgradeModel = rightUpgradeModel;
|
||||||
|
m_rightUpgradeTransform = rightUpgradeTransform;
|
||||||
m_generalTransform = generalTransform;
|
m_generalTransform = generalTransform;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, long rand )
|
||||||
public List<BakedQuad> getQuads( BlockState state, Direction side, @Nonnull Random rand )
|
|
||||||
{
|
|
||||||
return getQuads( state, side, rand, EmptyModelData.INSTANCE );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public List<BakedQuad> getQuads( BlockState state, Direction side, @Nonnull Random rand, @Nonnull IModelData data )
|
|
||||||
{
|
{
|
||||||
if( side != null )
|
if( side != null )
|
||||||
{
|
{
|
||||||
@@ -65,25 +60,37 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BakedQuad> buildQuads( BlockState state, Direction side, Random rand )
|
private List<BakedQuad> buildQuads( IBlockState state, EnumFacing side, long rand )
|
||||||
{
|
{
|
||||||
ArrayList<BakedQuad> quads = new ArrayList<>();
|
ArrayList<BakedQuad> quads = new ArrayList<>();
|
||||||
|
ModelTransformer.transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand ), m_generalTransform );
|
||||||
|
|
||||||
transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform );
|
|
||||||
if( m_overlayModel != null )
|
if( m_overlayModel != null )
|
||||||
{
|
{
|
||||||
transformQuadsTo( quads, m_overlayModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform );
|
ModelTransformer.transformQuadsTo( quads, m_overlayModel.getQuads( state, side, rand ), m_generalTransform );
|
||||||
|
}
|
||||||
|
if( m_overlayModel != null )
|
||||||
|
{
|
||||||
|
ModelTransformer.transformQuadsTo( quads, m_overlayModel.getQuads( state, side, rand ), m_generalTransform );
|
||||||
}
|
}
|
||||||
if( m_leftUpgradeModel != null )
|
if( m_leftUpgradeModel != null )
|
||||||
{
|
{
|
||||||
TransformationMatrix upgradeTransform = m_generalTransform.compose( m_leftUpgradeModel.getMatrix() );
|
Matrix4f upgradeTransform = m_generalTransform;
|
||||||
transformQuadsTo( quads, m_leftUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
if( m_leftUpgradeTransform != null )
|
||||||
|
{
|
||||||
|
upgradeTransform = new Matrix4f( m_generalTransform );
|
||||||
|
upgradeTransform.mul( m_leftUpgradeTransform );
|
||||||
|
}
|
||||||
|
ModelTransformer.transformQuadsTo( quads, m_leftUpgradeModel.getQuads( state, side, rand ), upgradeTransform );
|
||||||
}
|
}
|
||||||
if( m_rightUpgradeModel != null )
|
if( m_rightUpgradeModel != null )
|
||||||
{
|
{
|
||||||
TransformationMatrix upgradeTransform = m_generalTransform.compose( m_rightUpgradeModel.getMatrix() );
|
Matrix4f upgradeTransform = m_generalTransform;
|
||||||
transformQuadsTo( quads, m_rightUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
if( m_rightUpgradeTransform != null )
|
||||||
|
{
|
||||||
|
upgradeTransform = new Matrix4f( m_generalTransform );
|
||||||
|
upgradeTransform.mul( m_rightUpgradeTransform );
|
||||||
|
}
|
||||||
|
ModelTransformer.transformQuadsTo( quads, m_rightUpgradeModel.getQuads( state, side, rand ), upgradeTransform );
|
||||||
}
|
}
|
||||||
quads.trimToSize();
|
quads.trimToSize();
|
||||||
return quads;
|
return quads;
|
||||||
@@ -107,15 +114,8 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
return m_baseModel.isBuiltInRenderer();
|
return m_baseModel.isBuiltInRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean func_230044_c_()
|
|
||||||
{
|
|
||||||
return m_baseModel.func_230044_c_();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public TextureAtlasSprite getParticleTexture()
|
public TextureAtlasSprite getParticleTexture()
|
||||||
{
|
{
|
||||||
return m_baseModel.getParticleTexture();
|
return m_baseModel.getParticleTexture();
|
||||||
@@ -124,7 +124,7 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public net.minecraft.client.renderer.model.ItemCameraTransforms getItemCameraTransforms()
|
public ItemCameraTransforms getItemCameraTransforms()
|
||||||
{
|
{
|
||||||
return m_baseModel.getItemCameraTransforms();
|
return m_baseModel.getItemCameraTransforms();
|
||||||
}
|
}
|
||||||
@@ -133,17 +133,6 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
@Override
|
@Override
|
||||||
public ItemOverrideList getOverrides()
|
public ItemOverrideList getOverrides()
|
||||||
{
|
{
|
||||||
return ItemOverrideList.EMPTY;
|
return ItemOverrideList.NONE;
|
||||||
}
|
|
||||||
|
|
||||||
private void transformQuadsTo( List<BakedQuad> output, List<BakedQuad> quads, TransformationMatrix transform )
|
|
||||||
{
|
|
||||||
for( BakedQuad quad : quads )
|
|
||||||
{
|
|
||||||
BakedQuadBuilder builder = new BakedQuadBuilder();
|
|
||||||
TRSRTransformer transformer = new TRSRTransformer( builder, transform );
|
|
||||||
quad.pipe( transformer );
|
|
||||||
output.add( builder.build() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,43 +6,42 @@
|
|||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import dan200.computercraft.api.client.TransformedModel;
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtle;
|
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
|
||||||
import dan200.computercraft.shared.util.Holiday;
|
import dan200.computercraft.shared.util.Holiday;
|
||||||
import dan200.computercraft.shared.util.HolidayUtil;
|
import dan200.computercraft.shared.util.HolidayUtil;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.TransformationMatrix;
|
import net.minecraft.client.renderer.block.model.*;
|
||||||
import net.minecraft.client.renderer.model.*;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.model.data.IModelData;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.vecmath.Matrix4f;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class TurtleSmartItemModel implements IBakedModel
|
public class TurtleSmartItemModel implements IBakedModel
|
||||||
{
|
{
|
||||||
private static final TransformationMatrix identity, flip;
|
private static final Matrix4f s_identity, s_flip;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
MatrixStack stack = new MatrixStack();
|
s_identity = new Matrix4f();
|
||||||
stack.scale( 0, -1, 0 );
|
s_identity.setIdentity();
|
||||||
stack.translate( 0, 0, 1 );
|
|
||||||
|
|
||||||
identity = TransformationMatrix.identity();
|
s_flip = new Matrix4f();
|
||||||
flip = new TransformationMatrix( stack.getLast().getPositionMatrix() );
|
s_flip.setIdentity();
|
||||||
|
s_flip.m11 = -1; // Flip on the y axis
|
||||||
|
s_flip.m13 = 1; // Models go from (0,0,0) to (1,1,1), so push back up.
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class TurtleModelCombination
|
private static class TurtleModelCombination
|
||||||
@@ -106,13 +105,13 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
this.colourModel = colourModel;
|
this.colourModel = colourModel;
|
||||||
|
|
||||||
m_cachedModels = new HashMap<>();
|
m_cachedModels = new HashMap<>();
|
||||||
m_overrides = new ItemOverrideList()
|
m_overrides = new ItemOverrideList( new ArrayList<>() )
|
||||||
{
|
{
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IBakedModel getModelWithOverrides( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable LivingEntity entity )
|
public IBakedModel handleItemState( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity )
|
||||||
{
|
{
|
||||||
ItemTurtle turtle = (ItemTurtle) stack.getItem();
|
ItemTurtleBase turtle = (ItemTurtleBase) stack.getItem();
|
||||||
int colour = turtle.getColour( stack );
|
int colour = turtle.getColour( stack );
|
||||||
ITurtleUpgrade leftUpgrade = turtle.getUpgrade( stack, TurtleSide.Left );
|
ITurtleUpgrade leftUpgrade = turtle.getUpgrade( stack, TurtleSide.Left );
|
||||||
ITurtleUpgrade rightUpgrade = turtle.getUpgrade( stack, TurtleSide.Right );
|
ITurtleUpgrade rightUpgrade = turtle.getUpgrade( stack, TurtleSide.Right );
|
||||||
@@ -138,34 +137,40 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
|
|
||||||
private IBakedModel buildModel( TurtleModelCombination combo )
|
private IBakedModel buildModel( TurtleModelCombination combo )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager();
|
ModelManager modelManager = mc.getRenderItem().getItemModelMesher().getModelManager();
|
||||||
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas );
|
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas );
|
||||||
|
|
||||||
IBakedModel baseModel = combo.m_colour ? colourModel : familyModel;
|
IBakedModel baseModel = combo.m_colour ? colourModel : familyModel;
|
||||||
IBakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
|
IBakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
|
||||||
TransformationMatrix transform = combo.m_flip ? flip : identity;
|
Matrix4f transform = combo.m_flip ? s_flip : s_identity;
|
||||||
TransformedModel leftModel = combo.m_leftUpgrade != null ? combo.m_leftUpgrade.getModel( null, TurtleSide.Left ) : null;
|
Pair<IBakedModel, Matrix4f> leftModel = combo.m_leftUpgrade != null ? combo.m_leftUpgrade.getModel( null, TurtleSide.Left ) : null;
|
||||||
TransformedModel rightModel = combo.m_rightUpgrade != null ? combo.m_rightUpgrade.getModel( null, TurtleSide.Right ) : null;
|
Pair<IBakedModel, Matrix4f> rightModel = combo.m_rightUpgrade != null ? combo.m_rightUpgrade.getModel( null, TurtleSide.Right ) : null;
|
||||||
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel, rightModel );
|
if( leftModel != null && rightModel != null )
|
||||||
|
{
|
||||||
|
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel.getLeft(), leftModel.getRight(), rightModel.getLeft(), rightModel.getRight() );
|
||||||
|
}
|
||||||
|
else if( leftModel != null )
|
||||||
|
{
|
||||||
|
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel.getLeft(), leftModel.getRight(), null, null );
|
||||||
|
}
|
||||||
|
else if( rightModel != null )
|
||||||
|
{
|
||||||
|
return new TurtleMultiModel( baseModel, overlayModel, transform, null, null, rightModel.getLeft(), rightModel.getRight() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new TurtleMultiModel( baseModel, overlayModel, transform, null, null, null, null );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, long rand )
|
||||||
public List<BakedQuad> getQuads( BlockState state, Direction facing, @Nonnull Random rand )
|
|
||||||
{
|
{
|
||||||
return familyModel.getQuads( state, facing, rand );
|
return familyModel.getQuads( state, facing, rand );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public List<BakedQuad> getQuads( BlockState state, Direction facing, @Nonnull Random rand, @Nonnull IModelData data )
|
|
||||||
{
|
|
||||||
return familyModel.getQuads( state, facing, rand, data );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAmbientOcclusion()
|
public boolean isAmbientOcclusion()
|
||||||
{
|
{
|
||||||
@@ -184,15 +189,8 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
return familyModel.isBuiltInRenderer();
|
return familyModel.isBuiltInRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean func_230044_c_()
|
|
||||||
{
|
|
||||||
return familyModel.func_230044_c_();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
|
||||||
public TextureAtlasSprite getParticleTexture()
|
public TextureAtlasSprite getParticleTexture()
|
||||||
{
|
{
|
||||||
return familyModel.getParticleTexture();
|
return familyModel.getParticleTexture();
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.client.render;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
|
||||||
import net.minecraft.client.renderer.WorldRenderer;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.DrawHighlightEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
|
||||||
public final class CableHighlightRenderer
|
|
||||||
{
|
|
||||||
private CableHighlightRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw an outline for a specific part of a cable "Multipart".
|
|
||||||
*
|
|
||||||
* @param event The event to observe
|
|
||||||
* @see WorldRenderer#drawSelectionBox(ActiveRenderInfo, RayTraceResult, int)
|
|
||||||
*/
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void drawHighlight( DrawHighlightEvent.HighlightBlock event )
|
|
||||||
{
|
|
||||||
BlockRayTraceResult hit = event.getTarget();
|
|
||||||
BlockPos pos = hit.getPos();
|
|
||||||
World world = event.getInfo().getRenderViewEntity().getEntityWorld();
|
|
||||||
ActiveRenderInfo info = event.getInfo();
|
|
||||||
|
|
||||||
BlockState state = world.getBlockState( pos );
|
|
||||||
|
|
||||||
// We only care about instances with both cable and modem.
|
|
||||||
if( state.getBlock() != ComputerCraft.Blocks.cable || state.get( BlockCable.MODEM ).getFacing() == null || !state.get( BlockCable.CABLE ) )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCanceled( true );
|
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
|
||||||
RenderSystem.lineWidth( Math.max( 2.5F, mc.getMainWindow().getFramebufferWidth() / 1920.0F * 2.5F ) );
|
|
||||||
RenderSystem.disableTexture();
|
|
||||||
RenderSystem.depthMask( false );
|
|
||||||
RenderSystem.matrixMode( GL11.GL_PROJECTION );
|
|
||||||
RenderSystem.pushMatrix();
|
|
||||||
RenderSystem.scalef( 1.0F, 1.0F, 0.999F );
|
|
||||||
|
|
||||||
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
|
||||||
? CableShapes.getModemShape( state )
|
|
||||||
: CableShapes.getCableShape( state );
|
|
||||||
|
|
||||||
Vec3d cameraPos = info.getProjectedView();
|
|
||||||
WorldRenderer.drawShape(
|
|
||||||
shape, pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ(),
|
|
||||||
0.0F, 0.0F, 0.0F, 0.4F
|
|
||||||
);
|
|
||||||
|
|
||||||
RenderSystem.popMatrix();
|
|
||||||
RenderSystem.matrixMode( GL11.GL_MODELVIEW );
|
|
||||||
RenderSystem.depthMask( true );
|
|
||||||
RenderSystem.enableTexture();
|
|
||||||
RenderSystem.disableBlend();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.client.render;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
|
||||||
import net.minecraft.client.renderer.FirstPersonRenderer;
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
|
||||||
import net.minecraft.client.renderer.Vector3f;
|
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.Hand;
|
|
||||||
import net.minecraft.util.HandSide;
|
|
||||||
import net.minecraft.util.math.MathHelper;
|
|
||||||
|
|
||||||
public abstract class ItemMapLikeRenderer
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* The main rendering method for the item.
|
|
||||||
*
|
|
||||||
* @param transform The matrix transformation stack
|
|
||||||
* @param render The buffer to render to
|
|
||||||
* @param stack The stack to render
|
|
||||||
* @see FirstPersonRenderer#renderItemInFirstPerson(AbstractClientPlayerEntity, float, float, Hand, float, ItemStack, float, MatrixStack, IRenderTypeBuffer, int)
|
|
||||||
*/
|
|
||||||
protected abstract void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack );
|
|
||||||
|
|
||||||
protected void renderItemFirstPerson( MatrixStack transform, IRenderTypeBuffer render, int lightTexture, Hand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
|
||||||
{
|
|
||||||
PlayerEntity player = Minecraft.getInstance().player;
|
|
||||||
|
|
||||||
transform.push();
|
|
||||||
if( hand == Hand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
|
|
||||||
{
|
|
||||||
renderItemFirstPersonCenter( transform, render, lightTexture, pitch, equipProgress, swingProgress, stack );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
renderItemFirstPersonSide(
|
|
||||||
transform, render, lightTexture,
|
|
||||||
hand == Hand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
|
|
||||||
equipProgress, swingProgress, stack
|
|
||||||
);
|
|
||||||
}
|
|
||||||
transform.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Renders the item to one side of the player.
|
|
||||||
*
|
|
||||||
* @param side The side to render on
|
|
||||||
* @param equipProgress The equip progress of this item
|
|
||||||
* @param swingProgress The swing progress of this item
|
|
||||||
* @param stack The stack to render
|
|
||||||
* @see FirstPersonRenderer#renderMapFirstPersonSide(MatrixStack, IRenderTypeBuffer, int, float, HandSide, float, ItemStack)
|
|
||||||
*/
|
|
||||||
private void renderItemFirstPersonSide( MatrixStack transform, IRenderTypeBuffer render, int lightTexture, HandSide side, float equipProgress, float swingProgress, ItemStack stack )
|
|
||||||
{
|
|
||||||
Minecraft minecraft = Minecraft.getInstance();
|
|
||||||
float offset = side == HandSide.RIGHT ? 1f : -1f;
|
|
||||||
transform.translate( offset * 0.125f, -0.125f, 0f );
|
|
||||||
|
|
||||||
// If the player is not invisible then render a single arm
|
|
||||||
if( !minecraft.player.isInvisible() )
|
|
||||||
{
|
|
||||||
transform.push();
|
|
||||||
transform.rotate( Vector3f.field_229183_f_.func_229187_a_( offset * 10f ) );
|
|
||||||
minecraft.getFirstPersonRenderer().renderArmFirstPerson( transform, render, lightTexture, equipProgress, swingProgress, side );
|
|
||||||
transform.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup the appropriate transformations. This is just copied from the
|
|
||||||
// corresponding method in ItemRenderer.
|
|
||||||
transform.push();
|
|
||||||
transform.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
|
||||||
float f1 = MathHelper.sqrt( swingProgress );
|
|
||||||
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
|
||||||
float f3 = -0.5f * f2;
|
|
||||||
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
|
||||||
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
|
||||||
transform.translate( offset * f3, f4 - 0.3f * f2, f5 );
|
|
||||||
transform.rotate( Vector3f.field_229179_b_.func_229187_a_( f2 * -45f ) );
|
|
||||||
transform.rotate( Vector3f.field_229181_d_.func_229187_a_( offset * f2 * -30f ) );
|
|
||||||
|
|
||||||
renderItem( transform, render, stack );
|
|
||||||
|
|
||||||
transform.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render an item in the middle of the screen.
|
|
||||||
*
|
|
||||||
* @param pitch The pitch of the player
|
|
||||||
* @param equipProgress The equip progress of this item
|
|
||||||
* @param swingProgress The swing progress of this item
|
|
||||||
* @param stack The stack to render
|
|
||||||
* @see FirstPersonRenderer#renderMapFirstPerson(MatrixStack, IRenderTypeBuffer, int, float, float, float)
|
|
||||||
*/
|
|
||||||
private void renderItemFirstPersonCenter( MatrixStack transform, IRenderTypeBuffer render, int lightTexture, float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
|
||||||
{
|
|
||||||
Minecraft minecraft = Minecraft.getInstance();
|
|
||||||
FirstPersonRenderer renderer = minecraft.getFirstPersonRenderer();
|
|
||||||
|
|
||||||
// Setup the appropriate transformations. This is just copied from the
|
|
||||||
// corresponding method in ItemRenderer.
|
|
||||||
float swingRt = MathHelper.sqrt( swingProgress );
|
|
||||||
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
|
|
||||||
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
|
||||||
transform.translate( 0, -tX / 2, tZ );
|
|
||||||
|
|
||||||
float pitchAngle = renderer.getMapAngleFromPitch( pitch );
|
|
||||||
transform.translate( 0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
|
||||||
transform.rotate( Vector3f.field_229179_b_.func_229187_a_( pitchAngle * -85.0f ) );
|
|
||||||
if( !minecraft.player.isInvisible() )
|
|
||||||
{
|
|
||||||
transform.push();
|
|
||||||
transform.rotate( Vector3f.field_229181_d_.func_229187_a_( 90.0F ) );
|
|
||||||
renderer.renderArm( transform, render, lightTexture, HandSide.RIGHT );
|
|
||||||
renderer.renderArm( transform, render, lightTexture, HandSide.LEFT );
|
|
||||||
transform.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
|
||||||
transform.rotate( Vector3f.field_229179_b_.func_229187_a_( rX * 20.0F ) );
|
|
||||||
transform.scale( 2.0F, 2.0F, 2.0F );
|
|
||||||
|
|
||||||
renderItem( transform, render, stack );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.client.render;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.Matrix4f;
|
|
||||||
import net.minecraft.client.renderer.RenderType;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Direction;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.DrawHighlightEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import static net.minecraft.util.Direction.*;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
|
||||||
public final class MonitorHighlightRenderer
|
|
||||||
{
|
|
||||||
private static final float EXPAND = 0.002f;
|
|
||||||
|
|
||||||
private MonitorHighlightRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void drawHighlight( DrawHighlightEvent.HighlightBlock event )
|
|
||||||
{
|
|
||||||
if( event.getInfo().getRenderViewEntity().isCrouching() ) return;
|
|
||||||
|
|
||||||
World world = event.getInfo().getRenderViewEntity().getEntityWorld();
|
|
||||||
BlockPos pos = event.getTarget().getPos();
|
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
|
||||||
if( !(tile instanceof TileMonitor) ) return;
|
|
||||||
|
|
||||||
TileMonitor monitor = (TileMonitor) tile;
|
|
||||||
event.setCanceled( true );
|
|
||||||
|
|
||||||
// Determine which sides are part of the external faces of the monitor, and so which need to be rendered.
|
|
||||||
EnumSet<Direction> faces = EnumSet.allOf( Direction.class );
|
|
||||||
Direction front = monitor.getFront();
|
|
||||||
faces.remove( front );
|
|
||||||
if( monitor.getXIndex() != 0 ) faces.remove( monitor.getRight().getOpposite() );
|
|
||||||
if( monitor.getXIndex() != monitor.getWidth() - 1 ) faces.remove( monitor.getRight() );
|
|
||||||
if( monitor.getYIndex() != 0 ) faces.remove( monitor.getDown().getOpposite() );
|
|
||||||
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
|
||||||
|
|
||||||
IVertexBuilder buffer = Minecraft.getInstance().func_228019_au_().func_228487_b_().getBuffer( RenderType.lines() );
|
|
||||||
|
|
||||||
Vec3d cameraPos = event.getInfo().getProjectedView();
|
|
||||||
transformStack.translate( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() );
|
|
||||||
|
|
||||||
// I wish I could think of a better way to do this
|
|
||||||
Matrix4f transform = transformStack.getLast().getPositionMatrix();
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 0, UP );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 1, UP );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, transform, 1, 0, 0, UP );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( EAST ) ) line( buffer, transform, 1, 0, 1, UP );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( DOWN ) ) line( buffer, transform, 0, 0, 0, EAST );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( DOWN ) ) line( buffer, transform, 0, 0, 1, EAST );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( UP ) ) line( buffer, transform, 0, 1, 0, EAST );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( UP ) ) line( buffer, transform, 0, 1, 1, EAST );
|
|
||||||
if( faces.contains( WEST ) || faces.contains( DOWN ) ) line( buffer, transform, 0, 0, 0, SOUTH );
|
|
||||||
if( faces.contains( EAST ) || faces.contains( DOWN ) ) line( buffer, transform, 1, 0, 0, SOUTH );
|
|
||||||
if( faces.contains( WEST ) || faces.contains( UP ) ) line( buffer, transform, 0, 1, 0, SOUTH );
|
|
||||||
if( faces.contains( EAST ) || faces.contains( UP ) ) line( buffer, transform, 1, 1, 0, SOUTH );
|
|
||||||
|
|
||||||
transformStack.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void line( IVertexBuilder buffer, Matrix4f transform, float x, float y, float z, Direction direction )
|
|
||||||
{
|
|
||||||
float minX = x == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
float minY = y == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
float minZ = z == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
|
|
||||||
buffer.pos( transform, minX, minY, minZ ).color( 0, 0, 0, 0.4f ).endVertex();
|
|
||||||
buffer.pos( transform,
|
|
||||||
minX + direction.getXOffset() * (1 + EXPAND * 2),
|
|
||||||
minY + direction.getYOffset() * (1 + EXPAND * 2),
|
|
||||||
minZ + direction.getZOffset() * (1 + EXPAND * 2)
|
|
||||||
).color( 0, 0, 0, 0.4f ).endVertex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
package dan200.computercraft.client.render;
|
|
||||||
|
|
||||||
import com.mojang.blaze3d.platform.GlStateManager;
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.block.BlockState;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.WorldRenderer;
|
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.util.BlockRenderLayer;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.BlockRayTraceResult;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Render breaking animation only over part of a {@link TileCable}.
|
|
||||||
*/
|
|
||||||
public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
|
|
||||||
{
|
|
||||||
private static final ResourceLocation[] DESTROY_STAGES = new ResourceLocation[10];
|
|
||||||
private static final Random random = new Random();
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
for( int i = 0; i < DESTROY_STAGES.length; i++ )
|
|
||||||
{
|
|
||||||
DESTROY_STAGES[i] = new ResourceLocation( "block/destroy_stage_" + i );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render( @Nonnull TileCable te, double x, double y, double z, float partialTicks, int destroyStage )
|
|
||||||
{
|
|
||||||
if( destroyStage < 0 ) return;
|
|
||||||
|
|
||||||
BlockPos pos = te.getPos();
|
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
|
|
||||||
RayTraceResult hit = mc.objectMouseOver;
|
|
||||||
if( hit == null || hit.getType() != RayTraceResult.Type.BLOCK || !((BlockRayTraceResult) hit).getPos().equals( pos ) )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
World world = te.getWorld();
|
|
||||||
BlockState state = world.getBlockState( pos );
|
|
||||||
Block block = state.getBlock();
|
|
||||||
if( block != ComputerCraft.Blocks.cable ) return;
|
|
||||||
|
|
||||||
state = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
|
||||||
? block.getDefaultState().with( BlockCable.MODEM, state.get( BlockCable.MODEM ) )
|
|
||||||
: state.with( BlockCable.MODEM, CableModemVariant.None );
|
|
||||||
|
|
||||||
IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state );
|
|
||||||
|
|
||||||
preRenderDamagedBlocks();
|
|
||||||
|
|
||||||
ForgeHooksClient.setRenderLayer( block.getRenderLayer() );
|
|
||||||
|
|
||||||
// See BlockRendererDispatcher#renderBlockDamage
|
|
||||||
TextureAtlasSprite breakingTexture = mc.getTextureMap().getSprite( DESTROY_STAGES[destroyStage] );
|
|
||||||
|
|
||||||
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.BLOCK );
|
|
||||||
buffer.setTranslation( x - pos.getX(), y - pos.getY(), z - pos.getZ() );
|
|
||||||
buffer.noColor();
|
|
||||||
|
|
||||||
mc.getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
|
|
||||||
world,
|
|
||||||
ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos, 0 ),
|
|
||||||
state, pos, buffer, true, random, state.getPositionRandom( pos ), EmptyModelData.INSTANCE
|
|
||||||
);
|
|
||||||
|
|
||||||
ForgeHooksClient.setRenderLayer( BlockRenderLayer.SOLID );
|
|
||||||
|
|
||||||
buffer.setTranslation( 0, 0, 0 );
|
|
||||||
Tessellator.getInstance().draw();
|
|
||||||
|
|
||||||
postRenderDamagedBlocks();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up the state for rendering block-breaking progress.
|
|
||||||
*
|
|
||||||
* @see WorldRenderer#preRenderDamagedBlocks()
|
|
||||||
*/
|
|
||||||
private void preRenderDamagedBlocks()
|
|
||||||
{
|
|
||||||
RenderSystem.disableLighting();
|
|
||||||
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.blendFuncSeparate( GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
|
||||||
RenderSystem.enableBlend();
|
|
||||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 0.5F );
|
|
||||||
RenderSystem.polygonOffset( -3.0F, -3.0F );
|
|
||||||
RenderSystem.enablePolygonOffset();
|
|
||||||
RenderSystem.alphaFunc( 516, 0.1F );
|
|
||||||
RenderSystem.enableAlphaTest();
|
|
||||||
RenderSystem.pushMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tear down the state for rendering block-breaking progress.
|
|
||||||
*
|
|
||||||
* @see WorldRenderer#postRenderDamagedBlocks()
|
|
||||||
*/
|
|
||||||
private void postRenderDamagedBlocks()
|
|
||||||
{
|
|
||||||
RenderSystem.disableAlphaTest();
|
|
||||||
RenderSystem.polygonOffset( 0.0F, 0.0F );
|
|
||||||
RenderSystem.disablePolygonOffset();
|
|
||||||
RenderSystem.disablePolygonOffset();
|
|
||||||
RenderSystem.depthMask( true );
|
|
||||||
RenderSystem.popMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,6 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -50,11 +49,6 @@ public class AddressPredicate
|
|||||||
private final List<HostRange> ranges;
|
private final List<HostRange> ranges;
|
||||||
|
|
||||||
public AddressPredicate( String... filters )
|
public AddressPredicate( String... filters )
|
||||||
{
|
|
||||||
this( Arrays.asList( filters ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public AddressPredicate( Iterable<? extends String> filters )
|
|
||||||
{
|
{
|
||||||
List<Pattern> wildcards = this.wildcards = new ArrayList<>();
|
List<Pattern> wildcards = this.wildcards = new ArrayList<>();
|
||||||
List<HostRange> ranges = this.ranges = new ArrayList<>();
|
List<HostRange> ranges = this.ranges = new ArrayList<>();
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public final class ApiFactories
|
|||||||
private static final Collection<ILuaAPIFactory> factories = new LinkedHashSet<>();
|
private static final Collection<ILuaAPIFactory> factories = new LinkedHashSet<>();
|
||||||
private static final Collection<ILuaAPIFactory> factoriesView = Collections.unmodifiableCollection( factories );
|
private static final Collection<ILuaAPIFactory> factoriesView = Collections.unmodifiableCollection( factories );
|
||||||
|
|
||||||
public static synchronized void register( @Nonnull ILuaAPIFactory factory )
|
public static void register( @Nonnull ILuaAPIFactory factory )
|
||||||
{
|
{
|
||||||
Objects.requireNonNull( factory, "provider cannot be null" );
|
Objects.requireNonNull( factory, "provider cannot be null" );
|
||||||
factories.add( factory );
|
factories.add( factory );
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ import java.io.BufferedReader;
|
|||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.nio.file.attribute.FileTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.OptionalLong;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
|
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
|
||||||
@@ -76,6 +81,8 @@ public class FSAPI implements ILuaAPI
|
|||||||
"getFreeSpace",
|
"getFreeSpace",
|
||||||
"find",
|
"find",
|
||||||
"getDir",
|
"getDir",
|
||||||
|
"getCapacity",
|
||||||
|
"attributes",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,9 +322,8 @@ public class FSAPI implements ILuaAPI
|
|||||||
throw new LuaException( e.getMessage() );
|
throw new LuaException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 14:
|
case 14: // find
|
||||||
{
|
{
|
||||||
// find
|
|
||||||
String path = getString( args, 0 );
|
String path = getString( args, 0 );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -329,15 +335,50 @@ public class FSAPI implements ILuaAPI
|
|||||||
throw new LuaException( e.getMessage() );
|
throw new LuaException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 15:
|
case 15: // getDir
|
||||||
{
|
{
|
||||||
// getDir
|
|
||||||
String path = getString( args, 0 );
|
String path = getString( args, 0 );
|
||||||
return new Object[] { FileSystem.getDirectory( path ) };
|
return new Object[] { FileSystem.getDirectory( path ) };
|
||||||
}
|
}
|
||||||
|
case 16: // getCapacity
|
||||||
|
{
|
||||||
|
String path = getString( args, 0 );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
OptionalLong capacity = m_fileSystem.getCapacity( path );
|
||||||
|
return new Object[] { capacity.isPresent() ? capacity.getAsLong() : null };
|
||||||
|
}
|
||||||
|
catch( FileSystemException e )
|
||||||
|
{
|
||||||
|
throw new LuaException( e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 17: // attributes
|
||||||
|
{
|
||||||
|
String path = getString( args, 0 );
|
||||||
|
try
|
||||||
|
{
|
||||||
|
BasicFileAttributes attributes = m_fileSystem.getAttributes( path );
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put( "modification", getFileTime( attributes.lastModifiedTime() ) );
|
||||||
|
result.put( "created", getFileTime( attributes.creationTime() ) );
|
||||||
|
result.put( "size", attributes.isDirectory() ? 0 : attributes.size() );
|
||||||
|
result.put( "isDir", attributes.isDirectory() );
|
||||||
|
return new Object[] { result };
|
||||||
|
}
|
||||||
|
catch( FileSystemException e )
|
||||||
|
{
|
||||||
|
throw new LuaException( e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
assert false;
|
assert false;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static long getFileTime( FileTime time )
|
||||||
|
{
|
||||||
|
return time == null ? 0 : time.toMillis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2020. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.core.apis;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A Lua exception which does not contain its stack trace.
|
||||||
|
*/
|
||||||
|
public class FastLuaException extends LuaException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 5957864899303561143L;
|
||||||
|
|
||||||
|
public FastLuaException( @Nullable String message )
|
||||||
|
{
|
||||||
|
super( message );
|
||||||
|
}
|
||||||
|
|
||||||
|
public FastLuaException( @Nullable String message, int level )
|
||||||
|
{
|
||||||
|
super( message, level );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized Throwable fillInStackTrace()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,8 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
public interface IAPIEnvironment
|
public interface IAPIEnvironment
|
||||||
{
|
{
|
||||||
|
String TIMER_EVENT = "timer";
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface IPeripheralChangeListener
|
interface IPeripheralChangeListener
|
||||||
{
|
{
|
||||||
@@ -64,6 +66,10 @@ public interface IAPIEnvironment
|
|||||||
|
|
||||||
void setLabel( @Nullable String label );
|
void setLabel( @Nullable String label );
|
||||||
|
|
||||||
|
int startTimer( long ticks );
|
||||||
|
|
||||||
|
void cancelTimer( int id );
|
||||||
|
|
||||||
void addTrackingChange( @Nonnull TrackingField field, long change );
|
void addTrackingChange( @Nonnull TrackingField field, long change );
|
||||||
|
|
||||||
default void addTrackingChange( @Nonnull TrackingField field )
|
default void addTrackingChange( @Nonnull TrackingField field )
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import dan200.computercraft.api.lua.ILuaAPI;
|
|||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
import dan200.computercraft.shared.util.StringUtil;
|
import dan200.computercraft.shared.util.StringUtil;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@@ -24,24 +26,12 @@ public class OSAPI implements ILuaAPI
|
|||||||
{
|
{
|
||||||
private IAPIEnvironment m_apiEnvironment;
|
private IAPIEnvironment m_apiEnvironment;
|
||||||
|
|
||||||
private final Map<Integer, Timer> m_timers;
|
private final Int2ObjectMap<Alarm> m_alarms = new Int2ObjectOpenHashMap<>();
|
||||||
private final Map<Integer, Alarm> m_alarms;
|
|
||||||
private int m_clock;
|
private int m_clock;
|
||||||
private double m_time;
|
private double m_time;
|
||||||
private int m_day;
|
private int m_day;
|
||||||
|
|
||||||
private int m_nextTimerToken;
|
private int m_nextAlarmToken = 0;
|
||||||
private int m_nextAlarmToken;
|
|
||||||
|
|
||||||
private static class Timer
|
|
||||||
{
|
|
||||||
int m_ticksLeft;
|
|
||||||
|
|
||||||
Timer( int ticksLeft )
|
|
||||||
{
|
|
||||||
m_ticksLeft = ticksLeft;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Alarm implements Comparable<Alarm>
|
private static class Alarm implements Comparable<Alarm>
|
||||||
{
|
{
|
||||||
@@ -66,10 +56,6 @@ public class OSAPI implements ILuaAPI
|
|||||||
public OSAPI( IAPIEnvironment environment )
|
public OSAPI( IAPIEnvironment environment )
|
||||||
{
|
{
|
||||||
m_apiEnvironment = environment;
|
m_apiEnvironment = environment;
|
||||||
m_nextTimerToken = 0;
|
|
||||||
m_nextAlarmToken = 0;
|
|
||||||
m_timers = new HashMap<>();
|
|
||||||
m_alarms = new HashMap<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ILuaAPI implementation
|
// ILuaAPI implementation
|
||||||
@@ -87,11 +73,6 @@ public class OSAPI implements ILuaAPI
|
|||||||
m_day = m_apiEnvironment.getComputerEnvironment().getDay();
|
m_day = m_apiEnvironment.getComputerEnvironment().getDay();
|
||||||
m_clock = 0;
|
m_clock = 0;
|
||||||
|
|
||||||
synchronized( m_timers )
|
|
||||||
{
|
|
||||||
m_timers.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized( m_alarms )
|
synchronized( m_alarms )
|
||||||
{
|
{
|
||||||
m_alarms.clear();
|
m_alarms.clear();
|
||||||
@@ -101,26 +82,7 @@ public class OSAPI implements ILuaAPI
|
|||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
synchronized( m_timers )
|
m_clock++;
|
||||||
{
|
|
||||||
// Update the clock
|
|
||||||
m_clock++;
|
|
||||||
|
|
||||||
// Countdown all of our active timers
|
|
||||||
Iterator<Map.Entry<Integer, Timer>> it = m_timers.entrySet().iterator();
|
|
||||||
while( it.hasNext() )
|
|
||||||
{
|
|
||||||
Map.Entry<Integer, Timer> entry = it.next();
|
|
||||||
Timer timer = entry.getValue();
|
|
||||||
timer.m_ticksLeft--;
|
|
||||||
if( timer.m_ticksLeft <= 0 )
|
|
||||||
{
|
|
||||||
// Queue the "timer" event
|
|
||||||
queueLuaEvent( "timer", new Object[] { entry.getKey() } );
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for all of our alarms
|
// Wait for all of our alarms
|
||||||
synchronized( m_alarms )
|
synchronized( m_alarms )
|
||||||
@@ -155,11 +117,6 @@ public class OSAPI implements ILuaAPI
|
|||||||
@Override
|
@Override
|
||||||
public void shutdown()
|
public void shutdown()
|
||||||
{
|
{
|
||||||
synchronized( m_timers )
|
|
||||||
{
|
|
||||||
m_timers.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized( m_alarms )
|
synchronized( m_alarms )
|
||||||
{
|
{
|
||||||
m_alarms.clear();
|
m_alarms.clear();
|
||||||
@@ -229,11 +186,8 @@ public class OSAPI implements ILuaAPI
|
|||||||
{
|
{
|
||||||
// startTimer
|
// startTimer
|
||||||
double timer = getFiniteDouble( args, 0 );
|
double timer = getFiniteDouble( args, 0 );
|
||||||
synchronized( m_timers )
|
int id = m_apiEnvironment.startTimer( Math.round( timer / 0.05 ) );
|
||||||
{
|
return new Object[] { id };
|
||||||
m_timers.put( m_nextTimerToken, new Timer( (int) Math.round( timer / 0.05 ) ) );
|
|
||||||
return new Object[] { m_nextTimerToken++ };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
@@ -278,10 +232,7 @@ public class OSAPI implements ILuaAPI
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 10: // clock
|
case 10: // clock
|
||||||
synchronized( m_timers )
|
return new Object[] { m_clock * 0.05 };
|
||||||
{
|
|
||||||
return new Object[] { m_clock * 0.05 };
|
|
||||||
}
|
|
||||||
case 11:
|
case 11:
|
||||||
{
|
{
|
||||||
// time
|
// time
|
||||||
@@ -345,10 +296,7 @@ public class OSAPI implements ILuaAPI
|
|||||||
{
|
{
|
||||||
// cancelTimer
|
// cancelTimer
|
||||||
int token = getInt( args, 0 );
|
int token = getInt( args, 0 );
|
||||||
synchronized( m_timers )
|
m_apiEnvironment.cancelTimer( token );
|
||||||
{
|
|
||||||
m_timers.remove( token );
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 14:
|
case 14:
|
||||||
|
|||||||
@@ -383,22 +383,30 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
String methodName = getString( args, 1 );
|
String methodName = getString( args, 1 );
|
||||||
Object[] methodArgs = Arrays.copyOfRange( args, 2, args.length );
|
Object[] methodArgs = Arrays.copyOfRange( args, 2, args.length );
|
||||||
|
|
||||||
if( side != null )
|
if( side == null ) throw new LuaException( "No peripheral attached" );
|
||||||
|
|
||||||
|
PeripheralWrapper p;
|
||||||
|
synchronized( m_peripherals )
|
||||||
{
|
{
|
||||||
PeripheralWrapper p;
|
p = m_peripherals[side.ordinal()];
|
||||||
synchronized( m_peripherals )
|
}
|
||||||
{
|
if( p == null ) throw new LuaException( "No peripheral attached" );
|
||||||
p = m_peripherals[side.ordinal()];
|
|
||||||
}
|
try
|
||||||
if( p != null )
|
{
|
||||||
{
|
return p.call( context, methodName, methodArgs );
|
||||||
return p.call( context, methodName, methodArgs );
|
}
|
||||||
}
|
catch( LuaException e )
|
||||||
|
{
|
||||||
|
// We increase the error level by one in order to shift the error level to where peripheral.call was
|
||||||
|
// invoked. It would be possible to do it in Lua code, but would add significantly more overhead.
|
||||||
|
if( e.getLevel() > 0 ) throw new FastLuaException( e.getMessage(), e.getLevel() + 1 );
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
throw new LuaException( "No peripheral attached" );
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ import static dan200.computercraft.api.lua.ArgumentHelper.*;
|
|||||||
|
|
||||||
public class RedstoneAPI implements ILuaAPI
|
public class RedstoneAPI implements ILuaAPI
|
||||||
{
|
{
|
||||||
private IAPIEnvironment m_environment;
|
private final IAPIEnvironment environment;
|
||||||
|
|
||||||
public RedstoneAPI( IAPIEnvironment environment )
|
public RedstoneAPI( IAPIEnvironment environment )
|
||||||
{
|
{
|
||||||
m_environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,31 +63,31 @@ public class RedstoneAPI implements ILuaAPI
|
|||||||
// setOutput
|
// setOutput
|
||||||
ComputerSide side = parseSide( args );
|
ComputerSide side = parseSide( args );
|
||||||
boolean output = getBoolean( args, 1 );
|
boolean output = getBoolean( args, 1 );
|
||||||
m_environment.setOutput( side, output ? 15 : 0 );
|
environment.setOutput( side, output ? 15 : 0 );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 2: // getOutput
|
case 2: // getOutput
|
||||||
return new Object[] { m_environment.getOutput( parseSide( args ) ) > 0 };
|
return new Object[] { environment.getOutput( parseSide( args ) ) > 0 };
|
||||||
case 3: // getInput
|
case 3: // getInput
|
||||||
return new Object[] { m_environment.getInput( parseSide( args ) ) > 0 };
|
return new Object[] { environment.getInput( parseSide( args ) ) > 0 };
|
||||||
case 4:
|
case 4:
|
||||||
{
|
{
|
||||||
// setBundledOutput
|
// setBundledOutput
|
||||||
ComputerSide side = parseSide( args );
|
ComputerSide side = parseSide( args );
|
||||||
int output = getInt( args, 1 );
|
int output = getInt( args, 1 );
|
||||||
m_environment.setBundledOutput( side, output );
|
environment.setBundledOutput( side, output );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 5: // getBundledOutput
|
case 5: // getBundledOutput
|
||||||
return new Object[] { m_environment.getBundledOutput( parseSide( args ) ) };
|
return new Object[] { environment.getBundledOutput( parseSide( args ) ) };
|
||||||
case 6: // getBundledInput
|
case 6: // getBundledInput
|
||||||
return new Object[] { m_environment.getBundledInput( parseSide( args ) ) };
|
return new Object[] { environment.getBundledInput( parseSide( args ) ) };
|
||||||
case 7:
|
case 7:
|
||||||
{
|
{
|
||||||
// testBundledInput
|
// testBundledInput
|
||||||
ComputerSide side = parseSide( args );
|
ComputerSide side = parseSide( args );
|
||||||
int mask = getInt( args, 1 );
|
int mask = getInt( args, 1 );
|
||||||
int input = m_environment.getBundledInput( side );
|
int input = environment.getBundledInput( side );
|
||||||
return new Object[] { (input & mask) == mask };
|
return new Object[] { (input & mask) == mask };
|
||||||
}
|
}
|
||||||
case 8:
|
case 8:
|
||||||
@@ -100,15 +100,15 @@ public class RedstoneAPI implements ILuaAPI
|
|||||||
{
|
{
|
||||||
throw new LuaException( "Expected number in range 0-15" );
|
throw new LuaException( "Expected number in range 0-15" );
|
||||||
}
|
}
|
||||||
m_environment.setOutput( side, output );
|
environment.setOutput( side, output );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 10:
|
case 10:
|
||||||
case 11: // getAnalogOutput/getAnalogueOutput
|
case 11: // getAnalogOutput/getAnalogueOutput
|
||||||
return new Object[] { m_environment.getOutput( parseSide( args ) ) };
|
return new Object[] { environment.getOutput( parseSide( args ) ) };
|
||||||
case 12:
|
case 12:
|
||||||
case 13: // getAnalogInput/getAnalogueInput
|
case 13: // getAnalogInput/getAnalogueInput
|
||||||
return new Object[] { m_environment.getInput( parseSide( args ) ) };
|
return new Object[] { environment.getInput( parseSide( args ) ) };
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user