mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-08 01:12:59 +00:00
Compare commits
57 Commits
mc-1.13.x
...
v1.12.2-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ae70fed13 | ||
|
|
121802a683 | ||
|
|
08cf55e55f | ||
|
|
3c8c0d78ef | ||
|
|
c4d18aa9ca | ||
|
|
a8fadabaf1 | ||
|
|
38f9a015ca | ||
|
|
c311cdc6f5 | ||
|
|
a93e0f3284 | ||
|
|
14b3065ba4 | ||
|
|
c802290437 | ||
|
|
418420523a | ||
|
|
813e91073d | ||
|
|
7250f22ff6 | ||
|
|
db31a53bba | ||
|
|
3023f235a4 | ||
|
|
79cd8b4da5 | ||
|
|
8e4d311cd9 | ||
|
|
9bd8c86a94 | ||
|
|
cbc0c1d0b6 | ||
|
|
49c37857d4 | ||
|
|
a802f25dd6 | ||
|
|
a80302c513 | ||
|
|
1c46949da7 | ||
|
|
46d78af068 | ||
|
|
eb5cff1045 | ||
|
|
35c7792aa2 | ||
|
|
521688d630 | ||
|
|
75e2845c01 | ||
|
|
2f96283286 | ||
|
|
cbe6e9b5f5 | ||
|
|
2ab79cf474 | ||
|
|
6ce34aba79 | ||
|
|
5eeb320b60 | ||
|
|
93310850d2 | ||
|
|
a2880b12ca | ||
|
|
303b57779a | ||
|
|
6279816ecc | ||
|
|
4ae77261fa | ||
|
|
4b7d843b78 | ||
|
|
1c28df65c3 | ||
|
|
85b740f484 | ||
|
|
f9929cb27d | ||
|
|
bafab1ac07 | ||
|
|
e05c262468 | ||
|
|
7a3f7d3bba | ||
|
|
95aa48c456 | ||
|
|
904a168d5c | ||
|
|
724441eddc | ||
|
|
f68ab3edd1 | ||
|
|
29dce26bf6 | ||
|
|
717ab69093 | ||
|
|
138a2cf08f | ||
|
|
81daf82647 | ||
|
|
f3798bfb63 | ||
|
|
bc07dfad2e | ||
|
|
309cbdb8be |
18
.github/workflows/main-ci.yml
vendored
Normal file
18
.github/workflows/main-ci.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
name: Build
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Set up JDK 1.8
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 1.8
|
||||||
|
|
||||||
|
- name: Build with Gradle
|
||||||
|
run: ./gradlew build --no-daemon
|
||||||
@@ -17,7 +17,8 @@ ignore = {
|
|||||||
-- are largely unsupported.
|
-- are largely unsupported.
|
||||||
include_files = {
|
include_files = {
|
||||||
'src/main/resources/assets/computercraft/lua/rom',
|
'src/main/resources/assets/computercraft/lua/rom',
|
||||||
'src/main/resources/assets/computercraft/lua/bios.lua'
|
'src/main/resources/assets/computercraft/lua/bios.lua',
|
||||||
|
'src/test/resources/test-rom',
|
||||||
}
|
}
|
||||||
|
|
||||||
files['src/main/resources/assets/computercraft/lua/bios.lua'] = {
|
files['src/main/resources/assets/computercraft/lua/bios.lua'] = {
|
||||||
|
|||||||
14
.travis.yml
14
.travis.yml
@@ -1,14 +0,0 @@
|
|||||||
language: java
|
|
||||||
|
|
||||||
script: ./gradlew build --no-daemon
|
|
||||||
|
|
||||||
before_cache:
|
|
||||||
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
|
||||||
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.gradle/caches/
|
|
||||||
- $HOME/.gradle/wrapper/s
|
|
||||||
|
|
||||||
jdk:
|
|
||||||
- oraclejdk8
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
# 
|
# 
|
||||||
[](https://travis-ci.org/SquidDev-CC/CC-Tweaked "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,
|
||||||
turtles and more to Minecraft.
|
turtles and more to Minecraft.
|
||||||
|
|||||||
163
build.gradle
163
build.gradle
@@ -1,16 +1,17 @@
|
|||||||
|
|
||||||
|
// For those who want the bleeding edge
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
mavenCentral()
|
|
||||||
maven {
|
maven {
|
||||||
name = "forge"
|
name = "forge"
|
||||||
url = "http://files.minecraftforge.net/maven"
|
url = "https://files.minecraftforge.net/maven"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.117'
|
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'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,7 +23,7 @@ plugins {
|
|||||||
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,41 +34,18 @@ 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 {
|
maven {
|
||||||
name "JEI"
|
name "JEI"
|
||||||
url "http://dvs1.progwml6.com/files/maven"
|
url "https://dvs1.progwml6.com/files/maven"
|
||||||
}
|
}
|
||||||
maven {
|
maven {
|
||||||
name "SquidDev"
|
name "SquidDev"
|
||||||
@@ -79,7 +57,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
maven {
|
maven {
|
||||||
name "Amadornes"
|
name "Amadornes"
|
||||||
url "http://maven.amadornes.com/"
|
url "https://maven.amadornes.com/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,32 +68,23 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
checkstyle "com.puppycrawl.tools:checkstyle:8.21"
|
checkstyle "com.puppycrawl.tools:checkstyle:8.25"
|
||||||
|
|
||||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
deobfProvided "mezz.jei:jei_1.12.2:4.15.0.269:api"
|
||||||
|
deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
|
||||||
|
deobfProvided "MCMultiPart2:MCMultiPart:2.5.3"
|
||||||
|
|
||||||
compileOnly fg.deobf("mezz.jei:jei-1.13.2:5.0.0.20:api")
|
runtime "mezz.jei:jei_1.12.2:4.15.0.269"
|
||||||
// deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
|
|
||||||
// deobfProvided "MCMultiPart2:MCMultiPart:2.5.3"
|
|
||||||
|
|
||||||
runtimeOnly fg.deobf("mezz.jei:jei-1.13.2:5.0.0.20")
|
|
||||||
|
|
||||||
shade 'org.squiddev:Cobalt:0.5.0-SNAPSHOT'
|
shade 'org.squiddev:Cobalt:0.5.0-SNAPSHOT'
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.4.2'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
|
||||||
|
|
||||||
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
|
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
// Compile tasks
|
||||||
main {
|
|
||||||
java {
|
|
||||||
exclude 'dan200/computercraft/shared/integration/mcmp'
|
|
||||||
exclude 'dan200/computercraft/shared/integration/charset'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
include "dan200/computercraft/api/**/*.java"
|
include "dan200/computercraft/api/**/*.java"
|
||||||
@@ -125,13 +94,7 @@ jar {
|
|||||||
dependsOn javadoc
|
dependsOn javadoc
|
||||||
|
|
||||||
manifest {
|
manifest {
|
||||||
attributes(["Specification-Title": "computercraft",
|
attributes('FMLAT': 'computercraft_at.cfg')
|
||||||
"Specification-Vendor": "SquidDev",
|
|
||||||
"Specification-Version": "25.0",
|
|
||||||
"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) {
|
||||||
@@ -141,6 +104,14 @@ jar {
|
|||||||
from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
|
from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[compileJava, compileTestJava].forEach {
|
||||||
|
it.configure {
|
||||||
|
options.compilerArgs << "-Xlint" << "-Xlint:-processing" << "-Werror"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.nio.file.*
|
import java.nio.file.*
|
||||||
import java.util.zip.*
|
import java.util.zip.*
|
||||||
@@ -171,17 +142,13 @@ 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.** { *; }'
|
||||||
|
|
||||||
// Preserve the constructors in Cobalt library class, as we init them via reflection
|
// Preserve the constructors in Cobalt library class, as we init them via reflection
|
||||||
keepclassmembers 'class org.squiddev.cobalt.lib.** { <init>(...); }'
|
keepclassmembers 'class org.squiddev.cobalt.lib.** { <init>(...); }'
|
||||||
|
|
||||||
// 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) {
|
||||||
@@ -197,7 +164,7 @@ task proguardMove(dependsOn: proguard) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reobfJar.dependsOn proguardMove
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", mod_version
|
inputs.property "version", mod_version
|
||||||
@@ -219,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,
|
||||||
@@ -228,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"
|
||||||
|
|
||||||
@@ -276,7 +243,14 @@ task compressJson(dependsOn: jar) {
|
|||||||
|
|
||||||
assemble.dependsOn compressJson
|
assemble.dependsOn compressJson
|
||||||
|
|
||||||
/* Check tasks */
|
// Check tasks
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
testLogging {
|
||||||
|
events "skipped", "failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
license {
|
license {
|
||||||
mapping("java", "SLASHSTAR_STYLE")
|
mapping("java", "SLASHSTAR_STYLE")
|
||||||
@@ -300,6 +274,13 @@ license {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gradle.projectsEvaluated {
|
||||||
|
tasks.withType(LicenseFormat) {
|
||||||
|
outputs.upToDateWhen { false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
task licenseAPI(type: LicenseCheck);
|
task licenseAPI(type: LicenseCheck);
|
||||||
task licenseFormatAPI(type: LicenseFormat);
|
task licenseFormatAPI(type: LicenseFormat);
|
||||||
[licenseAPI, licenseFormatAPI].forEach {
|
[licenseAPI, licenseFormatAPI].forEach {
|
||||||
@@ -310,21 +291,21 @@ task licenseFormatAPI(type: LicenseFormat);
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Upload tasks */
|
// Upload tasks
|
||||||
|
|
||||||
task checkRelease {
|
task checkRelease {
|
||||||
group "upload"
|
group "upload"
|
||||||
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.")
|
||||||
@@ -341,7 +322,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")
|
||||||
@@ -350,6 +331,7 @@ task checkRelease {
|
|||||||
if (!ok) throw new IllegalStateException("Could not check release")
|
if (!ok) throw new IllegalStateException("Could not check release")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
check.dependsOn checkRelease
|
||||||
|
|
||||||
curseforge {
|
curseforge {
|
||||||
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
||||||
@@ -368,7 +350,7 @@ publishing {
|
|||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
// artifact sourceJar
|
artifact sourceJar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -421,12 +403,14 @@ githubRelease {
|
|||||||
token project.hasProperty('githubApiKey') ? project.githubApiKey : ''
|
token project.hasProperty('githubApiKey') ? project.githubApiKey : ''
|
||||||
owner 'SquidDev-CC'
|
owner 'SquidDev-CC'
|
||||||
repo 'CC-Tweaked'
|
repo 'CC-Tweaked'
|
||||||
targetCommitish { Grgit.open(dir: '.').branch.current().name }
|
try {
|
||||||
|
targetCommitish = Grgit.open(dir: '.').branch.current().name
|
||||||
|
} catch(Exception ignored) { }
|
||||||
|
|
||||||
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()
|
||||||
@@ -442,22 +426,5 @@ task uploadAll(dependsOn: uploadTasks) {
|
|||||||
description "Uploads to all repositories (Maven, Curse, GitHub release)"
|
description "Uploads to all repositories (Maven, Curse, GitHub release)"
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
runClient.outputs.upToDateWhen { false }
|
||||||
useJUnitPlatform()
|
runServer.outputs.upToDateWhen { false }
|
||||||
testLogging {
|
|
||||||
events "passed", "skipped", "failed"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gradle.projectsEvaluated {
|
|
||||||
reobfJar.dependsOn proguardMove
|
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
|
||||||
options.compilerArgs << "-Xlint" << "-Xlint:-processing" // Causes Forge build to fail << "-Werror"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(LicenseFormat) {
|
|
||||||
outputs.upToDateWhen { false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,7 @@
|
|||||||
<!-- Annotations -->
|
<!-- Annotations -->
|
||||||
<module name="AnnotationLocation" />
|
<module name="AnnotationLocation" />
|
||||||
<module name="AnnotationUseStyle" />
|
<module name="AnnotationUseStyle" />
|
||||||
<module name="MissingDeprecated">
|
<module name="MissingDeprecated" />
|
||||||
<property name="skipNoJavadoc" value="true" />
|
|
||||||
</module>
|
|
||||||
<module name="MissingOverride" />
|
<module name="MissingOverride" />
|
||||||
|
|
||||||
<!-- Blocks -->
|
<!-- Blocks -->
|
||||||
@@ -57,6 +55,9 @@
|
|||||||
<module name="SimplifyBooleanReturn" />
|
<module name="SimplifyBooleanReturn" />
|
||||||
<module name="StringLiteralEquality" />
|
<module name="StringLiteralEquality" />
|
||||||
<module name="UnnecessaryParentheses" />
|
<module name="UnnecessaryParentheses" />
|
||||||
|
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
|
||||||
|
<module name="UnnecessarySemicolonInTryWithResources" />
|
||||||
|
<module name="UnnecessarySemicolonInEnumeration" />
|
||||||
|
|
||||||
<!-- Imports -->
|
<!-- Imports -->
|
||||||
<module name="CustomImportOrder" />
|
<module name="CustomImportOrder" />
|
||||||
@@ -65,10 +66,16 @@
|
|||||||
<module name="UnusedImports" />
|
<module name="UnusedImports" />
|
||||||
|
|
||||||
<!-- Javadoc -->
|
<!-- Javadoc -->
|
||||||
|
<!-- TODO: Missing* checks for the dan200.computercraft.api package? -->
|
||||||
<module name="AtclauseOrder" />
|
<module name="AtclauseOrder" />
|
||||||
<!-- TODO: Cleanup our documentation before enabling JavadocMethod, JavadocStyle, JavadocType and SummaryJavadoc. -->
|
<module name="InvalidJavadocPosition" />
|
||||||
|
<module name="JavadocBlockTagLocation" />
|
||||||
|
<module name="JavadocMethod"/>
|
||||||
|
<module name="JavadocType"/>
|
||||||
|
<module name="JavadocStyle" />
|
||||||
<module name="NonEmptyAtclauseDescription" />
|
<module name="NonEmptyAtclauseDescription" />
|
||||||
<module name="SingleLineJavadoc" />
|
<module name="SingleLineJavadoc" />
|
||||||
|
<module name="SummaryJavadocCheck"/>
|
||||||
|
|
||||||
<!-- Misc -->
|
<!-- Misc -->
|
||||||
<module name="ArrayTypeStyle" />
|
<module name="ArrayTypeStyle" />
|
||||||
@@ -155,5 +162,8 @@
|
|||||||
|
|
||||||
<module name="FileTabCharacter" />
|
<module name="FileTabCharacter" />
|
||||||
<module name="NewlineAtEndOfFile" />
|
<module name="NewlineAtEndOfFile" />
|
||||||
|
<module name="RegexpSingleline">
|
||||||
|
<property name="format" value="\s+$"/>
|
||||||
|
<property name="message" value="Trailing whitespace"/>
|
||||||
|
</module>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
||||||
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
||||||
<suppressions>
|
<suppressions>
|
||||||
<!-- Has a public m_label field. We need to check if this is used in other projects before renaming it. -->
|
|
||||||
<suppress checks="MemberName" files=".*[\\/]TileComputerBase.java"
|
|
||||||
message="Name 'm_label' must match pattern .*" />
|
|
||||||
|
|
||||||
<!-- All the config options and method fields. -->
|
<!-- All the config options and method fields. -->
|
||||||
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraft.java" />
|
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraft.java" />
|
||||||
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraftAPI.java" />
|
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraftAPI.java" />
|
||||||
|
|
||||||
|
<!-- Do not check for missing package Javadoc. -->
|
||||||
|
<suppress checks="JavadocStyle" files=".*[\\/]package-info.java" />
|
||||||
</suppressions>
|
</suppressions>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Mod properties
|
# Mod properties
|
||||||
mod_version=1.83.1
|
mod_version=1.85.2
|
||||||
|
|
||||||
# Minecraft properties
|
# Minecraft properties
|
||||||
mc_version=1.13.2
|
mc_version=1.12.2
|
||||||
forge_version=25.0.219
|
forge_version=14.23.4.2749
|
||||||
mappings_version=20190530-1.13.2
|
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
|
||||||
|
|||||||
30
src/main/java/dan200/computercraft/CCTweaked.java
Normal file
30
src/main/java/dan200/computercraft/CCTweaked.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,50 +7,95 @@
|
|||||||
package dan200.computercraft;
|
package dan200.computercraft;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
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.ApiFactories;
|
||||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
||||||
import dan200.computercraft.core.filesystem.ResourceMount;
|
import dan200.computercraft.core.computer.MainThread;
|
||||||
import dan200.computercraft.shared.Config;
|
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.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[] { "*" };
|
||||||
@@ -112,54 +157,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;
|
||||||
@@ -172,45 +209,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IMount createResourceMount( String domain, String subPath )
|
private static File getBaseDir()
|
||||||
{
|
{
|
||||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
|
return FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory();
|
||||||
ResourceMount mount = new ResourceMount( domain, subPath, manager );
|
|
||||||
return mount.exists( "" ) ? mount : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream getResourceFile( String domain, String subPath )
|
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,141 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dan200.computercraft;
|
|
||||||
|
|
||||||
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.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.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.util.LazyOptional;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
|
||||||
{
|
|
||||||
public static final ComputerCraftAPIImpl INSTANCE = new ComputerCraftAPIImpl();
|
|
||||||
|
|
||||||
private ComputerCraftAPIImpl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 )
|
|
||||||
{
|
|
||||||
return ComputerCraft.createResourceMount( domain, subPath );
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 EnumFacing 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 EnumFacing 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()
|
||||||
|
|||||||
@@ -17,29 +17,49 @@ 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.EnumFacing;
|
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.
|
||||||
* Members in this class must be called after mod_ComputerCraft has been initialised,
|
*
|
||||||
* but may be called before it is fully loaded.
|
* Members in this class must be called after mod_ComputerCraft has been initialised, but may be called before it is
|
||||||
|
* fully loaded.
|
||||||
*/
|
*/
|
||||||
public final class ComputerCraftAPI
|
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 +83,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 +119,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 +179,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 +203,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 +228,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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -185,23 +254,81 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a media provider to provide {@link IMedia} implementations for Items
|
* Registers a media provider to provide {@link IMedia} implementations for Items.
|
||||||
*
|
*
|
||||||
* @param provider The media provider to register.
|
* @param provider The media provider to register.
|
||||||
* @see IMediaProvider
|
* @see IMediaProvider
|
||||||
*/
|
*/
|
||||||
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,16 +338,40 @@ 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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new wired node for a given wired element
|
* Construct a new wired node for a given wired element.
|
||||||
*
|
*
|
||||||
* @param element The element to construct it for
|
* @param element The element to construct it for
|
||||||
* @return The element's node
|
* @return The element's node
|
||||||
@@ -229,11 +380,26 @@ 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" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the wired network element for a block in world
|
* Get the wired network element for a block in world.
|
||||||
*
|
*
|
||||||
* @param world The world the block exists in
|
* @param world The world the block exists in
|
||||||
* @param pos The position the block exists in
|
* @param pos The position the block exists in
|
||||||
@@ -241,64 +407,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 EnumFacing 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 EnumFacing 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 EnumFacing side );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
||||||
* {@link IComputerAccess#mount(String, IMount)}
|
* {@link IComputerAccess#mount(String, IMount)}.
|
||||||
*
|
*
|
||||||
* Ready made implementations of this interface can be created using
|
* Ready made implementations of this interface can be created using
|
||||||
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
|
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
|
||||||
@@ -60,7 +60,7 @@ public interface IMount
|
|||||||
void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
|
void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of a file with a given path, in bytes
|
* Returns the size of a file with a given path, in bytes.
|
||||||
*
|
*
|
||||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
||||||
* @return The size of the file, in bytes.
|
* @return The size of the file, in bytes.
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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;
|
||||||
335
src/main/java/dan200/computercraft/api/lua/ArgumentHelper.java
Normal file
335
src/main/java/dan200/computercraft/api/lua/ArgumentHelper.java
Normal file
@@ -0,0 +1,335 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
|
||||||
|
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.api.lua;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides methods for extracting values and validating Lua arguments, such as those provided to
|
||||||
|
* {@link ILuaObject#callMethod(ILuaContext, int, Object[])} or
|
||||||
|
* {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}.
|
||||||
|
*
|
||||||
|
* This provides two sets of functions: the {@code get*} methods, which require an argument to be valid, and
|
||||||
|
* {@code opt*}, which accept a default value and return that if the argument was not present or was {@code null}.
|
||||||
|
* If the argument is of the wrong type, a suitable error message will be thrown, with a similar format to Lua's own
|
||||||
|
* error messages.
|
||||||
|
*
|
||||||
|
* <h2>Example usage:</h2>
|
||||||
|
* <pre>
|
||||||
|
* {@code
|
||||||
|
* int slot = getInt( args, 0 );
|
||||||
|
* int amount = optInt( args, 1, 64 );
|
||||||
|
* }
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public final class ArgumentHelper
|
||||||
|
{
|
||||||
|
private ArgumentHelper()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a string representation of the given value's type.
|
||||||
|
*
|
||||||
|
* @param value The value whose type we are trying to compute.
|
||||||
|
* @return A string representation of the given value's type, in a similar format to that provided by Lua's
|
||||||
|
* {@code type} function.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static String getType( @Nullable Object value )
|
||||||
|
{
|
||||||
|
if( value == null ) return "nil";
|
||||||
|
if( value instanceof String ) return "string";
|
||||||
|
if( value instanceof Boolean ) return "boolean";
|
||||||
|
if( value instanceof Number ) return "number";
|
||||||
|
if( value instanceof Map ) return "table";
|
||||||
|
return "userdata";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a "bad argument" exception, from an expected type and the actual value provided.
|
||||||
|
*
|
||||||
|
* @param index The argument number, starting from 0.
|
||||||
|
* @param expected The expected type for this argument.
|
||||||
|
* @param actual The actual value provided for this argument.
|
||||||
|
* @return The constructed exception, which should be thrown immediately.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static LuaException badArgumentOf( int index, @Nonnull String expected, @Nullable Object actual )
|
||||||
|
{
|
||||||
|
return badArgument( index, expected, getType( actual ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a "bad argument" exception, from an expected and actual type.
|
||||||
|
*
|
||||||
|
* @param index The argument number, starting from 0.
|
||||||
|
* @param expected The expected type for this argument.
|
||||||
|
* @param actual The provided type for this argument.
|
||||||
|
* @return The constructed exception, which should be thrown immediately.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
|
||||||
|
{
|
||||||
|
return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a double.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @return The argument's value.
|
||||||
|
* @throws LuaException If the value is not a number.
|
||||||
|
* @see #getFiniteDouble(Object[], int) if you require this to be finite (i.e. not infinite or NaN).
|
||||||
|
*/
|
||||||
|
public static double getDouble( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
|
{
|
||||||
|
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
||||||
|
return ((Number) value).doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as an integer.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @return The argument's value.
|
||||||
|
* @throws LuaException If the value is not an integer.
|
||||||
|
*/
|
||||||
|
public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
|
{
|
||||||
|
return (int) getLong( args, index );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a long.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @return The argument's value.
|
||||||
|
* @throws LuaException If the value is not a long.
|
||||||
|
*/
|
||||||
|
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
|
{
|
||||||
|
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
||||||
|
return checkFinite( index, (Number) value ).longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a finite number (not infinite or NaN).
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @return The argument's value.
|
||||||
|
* @throws LuaException If the value is not finite.
|
||||||
|
*/
|
||||||
|
public static double getFiniteDouble( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
|
{
|
||||||
|
return checkFinite( index, getDouble( args, index ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a boolean.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @return The argument's value.
|
||||||
|
* @throws LuaException If the value is not a boolean.
|
||||||
|
*/
|
||||||
|
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
|
{
|
||||||
|
if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
|
||||||
|
return (Boolean) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a string.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @return The argument's value.
|
||||||
|
* @throws LuaException If the value is not a string.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static String getString( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
|
{
|
||||||
|
if( index >= args.length ) throw badArgument( index, "string", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
|
||||||
|
return (String) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a table.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @return The argument's value.
|
||||||
|
* @throws LuaException If the value is not a table.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static Map<?, ?> getTable( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
|
{
|
||||||
|
if( index >= args.length ) throw badArgument( index, "table", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
|
||||||
|
return (Map<?, ?>) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a double.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @param def The default value, if this argument is not given.
|
||||||
|
* @return The argument's value, or {@code def} if none was provided.
|
||||||
|
* @throws LuaException If the value is not a number.
|
||||||
|
*/
|
||||||
|
public static double optDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
|
||||||
|
{
|
||||||
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null ) return def;
|
||||||
|
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
||||||
|
return ((Number) value).doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as an int.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @param def The default value, if this argument is not given.
|
||||||
|
* @return The argument's value, or {@code def} if none was provided.
|
||||||
|
* @throws LuaException If the value is not a number.
|
||||||
|
*/
|
||||||
|
public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
|
||||||
|
{
|
||||||
|
return (int) optLong( args, index, def );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a long.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @param def The default value, if this argument is not given.
|
||||||
|
* @return The argument's value, or {@code def} if none was provided.
|
||||||
|
* @throws LuaException If the value is not a number.
|
||||||
|
*/
|
||||||
|
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
|
||||||
|
{
|
||||||
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null ) return def;
|
||||||
|
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
||||||
|
return checkFinite( index, (Number) value ).longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a finite number (not infinite or NaN).
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @param def The default value, if this argument is not given.
|
||||||
|
* @return The argument's value, or {@code def} if none was provided.
|
||||||
|
* @throws LuaException If the value is not finite.
|
||||||
|
*/
|
||||||
|
public static double optFiniteDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
|
||||||
|
{
|
||||||
|
return checkFinite( index, optDouble( args, index, def ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a boolean.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @param def The default value, if this argument is not given.
|
||||||
|
* @return The argument's value, or {@code def} if none was provided.
|
||||||
|
* @throws LuaException If the value is not a boolean.
|
||||||
|
*/
|
||||||
|
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
|
||||||
|
{
|
||||||
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null ) return def;
|
||||||
|
if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
|
||||||
|
return (Boolean) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a string.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @param def The default value, if this argument is not given.
|
||||||
|
* @return The argument's value, or {@code def} if none was provided.
|
||||||
|
* @throws LuaException If the value is not a string.
|
||||||
|
*/
|
||||||
|
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
|
||||||
|
{
|
||||||
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null ) return def;
|
||||||
|
if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
|
||||||
|
return (String) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an argument as a table.
|
||||||
|
*
|
||||||
|
* @param args The arguments to extract from.
|
||||||
|
* @param index The index into the argument array to read from.
|
||||||
|
* @param def The default value, if this argument is not given.
|
||||||
|
* @return The argument's value, or {@code def} if none was provided.
|
||||||
|
* @throws LuaException If the value is not a table.
|
||||||
|
*/
|
||||||
|
public static Map<?, ?> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
|
||||||
|
{
|
||||||
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null ) return def;
|
||||||
|
if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
|
||||||
|
return (Map<?, ?>) value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Number checkFinite( int index, Number value ) throws LuaException
|
||||||
|
{
|
||||||
|
checkFinite( index, value.doubleValue() );
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double checkFinite( int index, double value ) throws LuaException
|
||||||
|
{
|
||||||
|
if( !Double.isFinite( value ) ) throw badArgument( index, "number", getNumericType( value ) );
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a more detailed representation of this number's type. If this is finite, it will just return "number",
|
||||||
|
* otherwise it returns whether it is infinite or NaN.
|
||||||
|
*
|
||||||
|
* @param value The value to extract the type for.
|
||||||
|
* @return This value's numeric type.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static String getNumericType( double value )
|
||||||
|
{
|
||||||
|
if( Double.isNaN( value ) ) return "nan";
|
||||||
|
if( value == Double.POSITIVE_INFINITY ) return "inf";
|
||||||
|
if( value == Double.NEGATIVE_INFINITY ) return "-inf";
|
||||||
|
return "number";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ public interface IComputerSystem extends IComputerAccess
|
|||||||
IFileSystem getFileSystem();
|
IFileSystem getFileSystem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the label for this computer
|
* Get the label for this computer.
|
||||||
*
|
*
|
||||||
* @return This computer's label, or {@code null} if it is not set.
|
* @return This computer's label, or {@code null} if it is not set.
|
||||||
*/
|
*/
|
||||||
|
|||||||
10
src/main/java/dan200/computercraft/api/lua/package-info.java
Normal file
10
src/main/java/dan200/computercraft/api/lua/package-info.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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;
|
||||||
10
src/main/java/dan200/computercraft/api/package-info.java
Normal file
10
src/main/java/dan200/computercraft/api/package-info.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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,6 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.lua.ArgumentHelper;
|
||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
|
||||||
@@ -58,9 +59,11 @@ public interface IPeripheral
|
|||||||
* Lua values of type "table" will be represented by Object type Map.<br>
|
* Lua values of type "table" will be represented by Object type Map.<br>
|
||||||
* Lua values of any other type will be represented by a null object.<br>
|
* Lua values of any other type will be represented by a null object.<br>
|
||||||
* This array will be empty if no arguments are passed.
|
* This array will be empty if no arguments are passed.
|
||||||
|
*
|
||||||
|
* It is recommended you use {@link ArgumentHelper} in order to validate and process arguments.
|
||||||
* @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats,
|
* @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats,
|
||||||
* Strings, Booleans, Maps and ILuaObject and null be converted to their corresponding lua type. All other types
|
* Strings, Booleans, Maps, ILuaObject and null be converted to their corresponding lua type. All other types will
|
||||||
* will be converted to nil.
|
* be converted to nil.
|
||||||
*
|
*
|
||||||
* You may return null to indicate no values should be returned.
|
* You may return null to indicate no values should be returned.
|
||||||
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the
|
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the
|
||||||
@@ -70,6 +73,7 @@ public interface IPeripheral
|
|||||||
* InterruptedException will be thrown. This exception must not be caught or
|
* InterruptedException will be thrown. This exception must not be caught or
|
||||||
* intercepted, or the computer will leak memory and end up in a broken state.
|
* intercepted, or the computer will leak memory and end up in a broken state.
|
||||||
* @see #getMethodNames
|
* @see #getMethodNames
|
||||||
|
* @see ArgumentHelper
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException;
|
Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException;
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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,42 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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 );
|
||||||
|
}
|
||||||
10
src/main/java/dan200/computercraft/api/permissions/package-info.java
Executable file
10
src/main/java/dan200/computercraft/api/permissions/package-info.java
Executable file
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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
|
||||||
|
|||||||
@@ -16,19 +16,29 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper class for pocket computers
|
* Wrapper class for pocket computers.
|
||||||
*/
|
*/
|
||||||
public interface IPocketAccess
|
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.
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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;
|
||||||
@@ -54,7 +54,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 );
|
||||||
@@ -144,7 +145,9 @@ public interface ITurtleAccess
|
|||||||
GameProfile getOwningPlayer();
|
GameProfile getOwningPlayer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the inventory of this turtle
|
* Get the inventory of this turtle.
|
||||||
|
*
|
||||||
|
* Note: this inventory should only be accessed and modified on the server thread.
|
||||||
*
|
*
|
||||||
* @return This turtle's inventory
|
* @return This turtle's inventory
|
||||||
* @see #getItemHandler()
|
* @see #getItemHandler()
|
||||||
@@ -155,6 +158,8 @@ public interface ITurtleAccess
|
|||||||
/**
|
/**
|
||||||
* Get the inventory of this turtle as an {@link IItemHandlerModifiable}.
|
* Get the inventory of this turtle as an {@link IItemHandlerModifiable}.
|
||||||
*
|
*
|
||||||
|
* Note: this inventory should only be accessed and modified on the server thread.
|
||||||
|
*
|
||||||
* @return This turtle's inventory
|
* @return This turtle's inventory
|
||||||
* @see #getInventory()
|
* @see #getInventory()
|
||||||
* @see IItemHandlerModifiable
|
* @see IItemHandlerModifiable
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
|||||||
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.IBakedModel;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
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 org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -44,6 +44,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.
|
||||||
*
|
*
|
||||||
@@ -98,8 +109,8 @@ public interface ITurtleUpgrade
|
|||||||
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
|
* Will only be called for Tool turtle. Called when turtle.dig() or turtle.attack() is called
|
||||||
* by the turtle, and the tool is required to do some work.
|
* by the turtle, and the tool is required to do some work.
|
||||||
*
|
*
|
||||||
* Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig}for digging,
|
* Conforming implementations should fire {@link BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig} for
|
||||||
* {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
|
* digging, {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
|
||||||
*
|
*
|
||||||
* @param turtle Access to the turtle that the tool resides on.
|
* @param turtle Access to the turtle that the tool resides on.
|
||||||
* @param side Which side of the turtle (left or right) the tool resides on.
|
* @param side Which side of the turtle (left or right) the tool resides on.
|
||||||
@@ -122,7 +133,7 @@ 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!
|
||||||
@@ -131,7 +142,7 @@ public interface ITurtleUpgrade
|
|||||||
* a transformation of {@code null} has the same effect as the identify matrix.
|
* a transformation of {@code null} has the same effect as the identify matrix.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@OnlyIn( Dist.CLIENT )
|
@SideOnly( Side.CLIENT )
|
||||||
Pair<IBakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
|
Pair<IBakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ package dan200.computercraft.api.turtle;
|
|||||||
public enum TurtleSide
|
public enum TurtleSide
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle)
|
* The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle).
|
||||||
*/
|
*/
|
||||||
Left,
|
Left,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The turtle's right side (where the modem usually is on a Wireless Mining Turtle)
|
* The turtle's right side (where the modem usually is on a Wireless Mining Turtle).
|
||||||
*/
|
*/
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ import net.minecraft.util.EnumFacing;
|
|||||||
public enum TurtleVerb
|
public enum TurtleVerb
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}
|
* The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}.
|
||||||
*/
|
*/
|
||||||
Dig,
|
Dig,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}
|
* The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}.
|
||||||
*/
|
*/
|
||||||
Attack,
|
Attack,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public enum TurtleAction
|
|||||||
EQUIP,
|
EQUIP,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inspect a block in world
|
* Inspect a block in world.
|
||||||
*
|
*
|
||||||
* @see TurtleBlockEvent.Inspect
|
* @see TurtleBlockEvent.Inspect
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,7 +8,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;
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the upgrade doing the digging
|
* Get the upgrade doing the digging.
|
||||||
*
|
*
|
||||||
* @return The upgrade doing the digging.
|
* @return The upgrade doing the digging.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,7 +7,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;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the inventory being interacted with
|
* Get the inventory being interacted with.
|
||||||
*
|
*
|
||||||
* @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
|
* @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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,10 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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;
|
||||||
@@ -8,81 +8,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.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
||||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.ModelBakery;
|
||||||
import net.minecraft.client.renderer.model.ModelRotation;
|
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.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.resources.IResourceManager;
|
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.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 )
|
@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. I'm unable to get this working with Forge's current
|
|
||||||
// model loading code.
|
|
||||||
"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( 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 )
|
||||||
{
|
{
|
||||||
IResourceManager manager = Minecraft.getInstance().getResourceManager();
|
// Load all textures for the extra models
|
||||||
for( String extra : EXTRA_TEXTURES )
|
TextureMap map = event.getMap();
|
||||||
|
for( String upgrade : EXTRA_MODELS )
|
||||||
{
|
{
|
||||||
event.getMap().registerSprite( manager, new ResourceLocation( ComputerCraft.MOD_ID, extra ) );
|
IModel model = ModelLoaderRegistry.getModelOrMissing( new ResourceLocation( "computercraft", "block/" + upgrade ) );
|
||||||
|
for( ResourceLocation texture : model.getTextures() ) map.registerSprite( texture );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,79 +113,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<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();
|
|
||||||
|
|
||||||
for( String model : EXTRA_MODELS )
|
|
||||||
{
|
|
||||||
IBakedModel bakedModel = bake( loader, loader.getUnbakedModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/" + model ) ) );
|
|
||||||
|
|
||||||
if( bakedModel != null )
|
|
||||||
{
|
|
||||||
registry.put(
|
|
||||||
new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, model ), "inventory" ),
|
|
||||||
bakedModel
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// And load the custom turtle models in too.
|
|
||||||
registry.put(
|
|
||||||
new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_normal" ), "inventory" ),
|
|
||||||
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/turtle_normal" ) ) )
|
|
||||||
);
|
|
||||||
|
|
||||||
registry.put(
|
|
||||||
new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ), "inventory" ),
|
|
||||||
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/turtle_advanced" ) ) )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 IBakedModel bake( ModelLoader loader, IUnbakedModel model )
|
private static void registerItemModel( Item item, int damage, String name )
|
||||||
{
|
{
|
||||||
model.getTextures( loader::getUnbakedModel, new HashSet<>() );
|
ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
||||||
|
final ModelResourceLocation res = new ModelResourceLocation( location, "inventory" );
|
||||||
|
ModelBakery.registerItemVariants( item, location );
|
||||||
|
ModelLoader.setCustomModelResourceLocation( item, damage, res );
|
||||||
|
}
|
||||||
|
|
||||||
return model.bake(
|
private static void registerUniversalItemModel( Item item, String mainModel )
|
||||||
loader::getUnbakedModel,
|
{
|
||||||
ModelLoader.defaultTextureGetter(),
|
ResourceLocation mainLocation = new ResourceLocation( ComputerCraft.MOD_ID, mainModel );
|
||||||
ModelRotation.X0_Y0, false, DefaultVertexFormats.BLOCK
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
|
|
||||||
private static FontRenderer renderer()
|
private static FontRenderer renderer()
|
||||||
{
|
{
|
||||||
return Minecraft.getInstance().fontRenderer;
|
return Minecraft.getMinecraft().fontRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -42,7 +42,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);
|
||||||
|
|
||||||
@@ -64,11 +64,11 @@ 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();
|
||||||
GuiNewChat 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 = GuiUtilRenderComponents.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 );
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
@Override
|
@Override
|
||||||
public int display( TableBuilder table )
|
public int display( TableBuilder table )
|
||||||
{
|
{
|
||||||
GuiNewChat chat = Minecraft.getInstance().ingameGUI.getChatGUI();
|
GuiNewChat chat = Minecraft.getMinecraft().ingameGUI.getChatGUI();
|
||||||
|
|
||||||
int lastHeight = lastHeights.get( table.getId() );
|
int lastHeight = lastHeights.get( table.getId() );
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,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.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.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;
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public final class FixedWidthFontRenderer
|
|||||||
|
|
||||||
private FixedWidthFontRenderer()
|
private FixedWidthFontRenderer()
|
||||||
{
|
{
|
||||||
m_textureManager = Minecraft.getInstance().getTextureManager();
|
m_textureManager = Minecraft.getMinecraft().getTextureManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void greyscaleify( double[] rgb )
|
private static void greyscaleify( double[] rgb )
|
||||||
@@ -195,6 +195,6 @@ public final class FixedWidthFontRenderer
|
|||||||
public void bindFont()
|
public void bindFont()
|
||||||
{
|
{
|
||||||
m_textureManager.bindTexture( FONT );
|
m_textureManager.bindTexture( FONT );
|
||||||
GlStateManager.texParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
GlStateManager.glTexParameteri( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,19 +8,23 @@ package dan200.computercraft.client.gui;
|
|||||||
|
|
||||||
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.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 net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class GuiComputer extends GuiContainer
|
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" );
|
||||||
@@ -29,9 +33,7 @@ public class GuiComputer extends GuiContainer
|
|||||||
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;
|
|
||||||
private WidgetWrapper terminalWrapper;
|
|
||||||
|
|
||||||
public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
||||||
{
|
{
|
||||||
@@ -40,7 +42,13 @@ public class GuiComputer extends GuiContainer
|
|||||||
m_computer = computer;
|
m_computer = computer;
|
||||||
m_termWidth = termWidth;
|
m_termWidth = termWidth;
|
||||||
m_termHeight = termHeight;
|
m_termHeight = termHeight;
|
||||||
terminal = null;
|
m_terminal = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public GuiComputer( Container container, ComputerFamily family, IComputer computer, int termWidth, int termHeight )
|
||||||
|
{
|
||||||
|
this( container, family, (ClientComputer) computer, termWidth, termHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiComputer( TileComputer computer )
|
public GuiComputer( TileComputer computer )
|
||||||
@@ -55,55 +63,98 @@ public class GuiComputer extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initGui()
|
public void initGui()
|
||||||
{
|
{
|
||||||
mc.keyboardListener.enableRepeatEvents( true );
|
|
||||||
|
|
||||||
int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
|
||||||
int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
|
||||||
|
|
||||||
xSize = termPxWidth + 4 + 24;
|
|
||||||
ySize = termPxHeight + 4 + 24;
|
|
||||||
|
|
||||||
super.initGui();
|
super.initGui();
|
||||||
|
Keyboard.enableRepeatEvents( true );
|
||||||
|
|
||||||
terminal = new WidgetTerminal( mc, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
|
m_terminal = new WidgetTerminal( 0, 0, m_termWidth, m_termHeight, () -> m_computer, 2, 2, 2, 2 );
|
||||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight );
|
m_terminal.setAllowFocusLoss( false );
|
||||||
|
xSize = m_terminal.getWidth() + 24;
|
||||||
children.add( terminalWrapper );
|
ySize = m_terminal.getHeight() + 24;
|
||||||
setFocused( terminalWrapper );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed()
|
public void onGuiClosed()
|
||||||
{
|
{
|
||||||
super.onGuiClosed();
|
super.onGuiClosed();
|
||||||
children.remove( terminal );
|
Keyboard.enableRepeatEvents( false );
|
||||||
terminal = null;
|
|
||||||
mc.keyboardListener.enableRepeatEvents( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void updateScreen()
|
||||||
{
|
{
|
||||||
super.tick();
|
super.updateScreen();
|
||||||
terminal.update();
|
m_terminal.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void keyTyped( char c, int k ) throws IOException
|
||||||
|
{
|
||||||
|
if( k == 1 )
|
||||||
|
{
|
||||||
|
super.keyTyped( c, k );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_terminal.onKeyTyped( c, k ) ) keyHandled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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
|
||||||
GlStateManager.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:
|
||||||
@@ -129,26 +180,4 @@ public class GuiComputer extends GuiContainer
|
|||||||
drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
|
drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
|
||||||
drawTexturedModalRect( 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 )
|
|
||||||
{
|
|
||||||
drawDefaultBackground();
|
|
||||||
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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseReleased( double x, double y, int button )
|
|
||||||
{
|
|
||||||
return (getFocused() != null && getFocused().mouseReleased( x, y, button ))
|
|
||||||
|| super.mouseReleased( x, y, button );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ import net.minecraft.util.ResourceLocation;
|
|||||||
|
|
||||||
public class GuiDiskDrive extends GuiContainer
|
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" );
|
||||||
|
|
||||||
private final ContainerDiskDrive m_container;
|
private final ContainerDiskDrive m_container;
|
||||||
|
|
||||||
@@ -27,24 +27,24 @@ public class GuiDiskDrive extends GuiContainer
|
|||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
String title = m_container.getDiskDrive().getDisplayName().getString();
|
String title = m_container.getDiskDrive().getDisplayName().getUnformattedText();
|
||||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
|
||||||
fontRenderer.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 )
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND );
|
mc.getTextureManager().bindTexture( BACKGROUND );
|
||||||
drawTexturedModalRect( 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 )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
drawDefaultBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,28 +7,19 @@
|
|||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
||||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
|
|
||||||
public class GuiPocketComputer extends GuiComputer
|
public class GuiPocketComputer extends GuiComputer
|
||||||
{
|
{
|
||||||
public GuiPocketComputer( ContainerPocketComputer container )
|
public GuiPocketComputer( ContainerHeldItem container )
|
||||||
{
|
{
|
||||||
super(
|
super(
|
||||||
container,
|
container,
|
||||||
getFamily( container.getStack() ),
|
ComputerCraft.Items.pocketComputer.getFamily( container.getStack() ),
|
||||||
ItemPocketComputer.createClientComputer( container.getStack() ),
|
ItemPocketComputer.createClientComputer( container.getStack() ),
|
||||||
ComputerCraft.terminalWidth_pocketComputer,
|
ComputerCraft.terminalWidth_pocketComputer,
|
||||||
ComputerCraft.terminalHeight_pocketComputer
|
ComputerCraft.terminalHeight_pocketComputer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ComputerFamily getFamily( ItemStack stack )
|
|
||||||
{
|
|
||||||
Item item = stack.getItem();
|
|
||||||
return item instanceof ItemPocketComputer ? ((ItemPocketComputer) item).getFamily() : ComputerFamily.Normal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ public class GuiPrinter extends GuiContainer
|
|||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
String title = container.getPrinter().getDisplayName().getString();
|
String title = container.getPrinter().getDisplayName().getUnformattedText();
|
||||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 6, 0x404040 );
|
||||||
fontRenderer.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 )
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND );
|
mc.getTextureManager().bindTexture( BACKGROUND );
|
||||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||||
|
|
||||||
@@ -43,10 +43,10 @@ public class GuiPrinter extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
drawDefaultBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,13 @@
|
|||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
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.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||||
|
|
||||||
@@ -39,70 +41,63 @@ public class GuiPrintout extends GuiContainer
|
|||||||
|
|
||||||
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 delta )
|
public void handleMouseInput() throws IOException
|
||||||
{
|
{
|
||||||
if( super.mouseScrolled( 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
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.enableDepthTest();
|
|
||||||
|
|
||||||
drawBorder( guiLeft, guiTop, zLevel, 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.
|
||||||
zLevel--;
|
zLevel--;
|
||||||
drawDefaultBackground();
|
drawDefaultBackground();
|
||||||
zLevel++;
|
zLevel++;
|
||||||
|
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,27 +8,29 @@ package dan200.computercraft.client.gui;
|
|||||||
|
|
||||||
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.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class GuiTurtle extends GuiContainer
|
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;
|
|
||||||
private WidgetWrapper terminalWrapper;
|
|
||||||
|
|
||||||
public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
|
public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
|
||||||
{
|
{
|
||||||
@@ -43,48 +45,78 @@ public class GuiTurtle extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initGui()
|
public void initGui()
|
||||||
{
|
{
|
||||||
super.initGui();
|
super.initGui();
|
||||||
mc.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(
|
|
||||||
mc, () -> 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 onGuiClosed()
|
public void onGuiClosed()
|
||||||
{
|
{
|
||||||
children.remove( terminal );
|
super.onGuiClosed();
|
||||||
terminal = null;
|
Keyboard.enableRepeatEvents( false );
|
||||||
mc.keyboardListener.enableRepeatEvents( false );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick()
|
public void updateScreen()
|
||||||
{
|
{
|
||||||
super.tick();
|
super.updateScreen();
|
||||||
terminal.update();
|
m_terminalGui.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawSelectionSlot( boolean advanced )
|
@Override
|
||||||
|
protected void keyTyped( char c, int k ) throws IOException
|
||||||
|
{
|
||||||
|
if( k == 1 )
|
||||||
|
{
|
||||||
|
super.keyTyped( c, k );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_terminalGui.onKeyTyped( c, k ) ) keyHandled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 )
|
||||||
{
|
{
|
||||||
GlStateManager.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;
|
||||||
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||||
@@ -97,10 +129,10 @@ public class GuiTurtle extends GuiContainer
|
|||||||
{
|
{
|
||||||
// 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
|
||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||||
|
|
||||||
@@ -108,10 +140,10 @@ public class GuiTurtle extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
drawDefaultBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.drawScreen( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
renderHoveredToolTip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. 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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,349 +10,371 @@ 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.core.terminal.TextBuffer;
|
||||||
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 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.gui.IGuiEventListener;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.util.ChatAllowedCharacters;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import org.lwjgl.input.Keyboard;
|
||||||
import net.minecraft.util.SharedConstants;
|
import org.lwjgl.input.Mouse;
|
||||||
import org.lwjgl.glfw.GLFW;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.ArrayList;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
|
||||||
|
|
||||||
public class WidgetTerminal implements IGuiEventListener
|
public class WidgetTerminal extends Widget
|
||||||
{
|
{
|
||||||
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 final Supplier<ClientComputer> computer;
|
private float m_terminateTimer = 0.0f;
|
||||||
private final int termWidth;
|
private float m_rebootTimer = 0.0f;
|
||||||
private final int termHeight;
|
private float m_shutdownTimer = 0.0f;
|
||||||
|
|
||||||
private float terminateTimer = -1;
|
private int m_lastClickButton = -1;
|
||||||
private float rebootTimer = -1;
|
private int m_lastClickX = -1;
|
||||||
private float shutdownTimer = -1;
|
private int m_lastClickY = -1;
|
||||||
|
|
||||||
private int lastMouseButton = -1;
|
private boolean m_focus = false;
|
||||||
private int lastMouseX = -1;
|
private boolean m_allowFocusLoss = true;
|
||||||
private int lastMouseY = -1;
|
|
||||||
|
|
||||||
private final int leftMargin;
|
private int m_leftMargin;
|
||||||
private final int rightMargin;
|
private int m_rightMargin;
|
||||||
private final int topMargin;
|
private int m_topMargin;
|
||||||
private final int bottomMargin;
|
private int m_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
|
||||||
this.leftMargin = leftMargin;
|
);
|
||||||
this.rightMargin = rightMargin;
|
|
||||||
this.topMargin = topMargin;
|
m_computer = computer;
|
||||||
this.bottomMargin = bottomMargin;
|
|
||||||
|
m_leftMargin = leftMargin;
|
||||||
|
m_rightMargin = rightMargin;
|
||||||
|
m_topMargin = topMargin;
|
||||||
|
m_bottomMargin = bottomMargin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAllowFocusLoss( boolean allowFocusLoss )
|
||||||
|
{
|
||||||
|
m_allowFocusLoss = allowFocusLoss;
|
||||||
|
m_focus = m_focus || !allowFocusLoss;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean charTyped( char ch, int modifiers )
|
public boolean onKeyTyped( char ch, int key )
|
||||||
{
|
{
|
||||||
if( ch >= 32 && ch <= 126 || ch >= 160 && ch <= 255 ) // printable chars in byte range
|
if( m_focus )
|
||||||
{
|
{
|
||||||
// Queue the "char" event
|
// Ctrl+V for paste
|
||||||
queueEvent( "char", Character.toString( ch ) );
|
if( ch == 22 )
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
|
||||||
{
|
|
||||||
if( key == GLFW.GLFW_KEY_ESCAPE ) return false;
|
|
||||||
if( (modifiers & GLFW.GLFW_MOD_CONTROL) != 0 )
|
|
||||||
{
|
|
||||||
switch( key )
|
|
||||||
{
|
{
|
||||||
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" );
|
|
||||||
if( newLineIndex1 >= 0 && newLineIndex2 >= 0 )
|
|
||||||
{
|
|
||||||
clipboard = clipboard.substring( 0, Math.min( newLineIndex1, newLineIndex2 ) );
|
|
||||||
}
|
|
||||||
else if( newLineIndex1 >= 0 )
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
else if( newLineIndex1 >= 0 )
|
||||||
|
{
|
||||||
|
clipboard = clipboard.substring( 0, newLineIndex1 );
|
||||||
|
}
|
||||||
|
else if( newLineIndex2 >= 0 )
|
||||||
|
{
|
||||||
|
clipboard = clipboard.substring( 0, newLineIndex2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter the string
|
||||||
|
clipboard = ChatAllowedCharacters.filterAllowedCharacters( clipboard );
|
||||||
|
|
||||||
|
if( !clipboard.isEmpty() )
|
||||||
|
{
|
||||||
|
// Clip to 512 characters
|
||||||
|
if( clipboard.length() > 512 )
|
||||||
|
{
|
||||||
|
clipboard = clipboard.substring( 0, 512 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue the "paste" event
|
||||||
|
queueEvent( "paste", new Object[] { clipboard } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if( key >= 0 && terminateTimer < 0 && rebootTimer < 0 && shutdownTimer < 0 )
|
// Regular keys normally
|
||||||
{
|
if( m_terminateTimer <= 0.0f && m_rebootTimer <= 0.0f && m_shutdownTimer <= 0.0f )
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean keyReleased( int key, int scancode, int modifiers )
|
|
||||||
{
|
|
||||||
// Queue the "key_up" event and remove from the down set
|
|
||||||
if( key >= 0 && keysDown.get( key ) )
|
|
||||||
{
|
|
||||||
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 / FixedWidthFontRenderer.FONT_WIDTH);
|
|
||||||
int charY = (int) (mouseY / FixedWidthFontRenderer.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 / FixedWidthFontRenderer.FONT_WIDTH);
|
|
||||||
int charY = (int) (mouseY / FixedWidthFontRenderer.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 );
|
boolean repeat = Keyboard.isRepeatEvent();
|
||||||
lastMouseButton = -1;
|
boolean handled = false;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked( int mouseX, int mouseY, int button )
|
||||||
|
{
|
||||||
|
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
|
||||||
|
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() )
|
||||||
|
{
|
||||||
|
if( !m_focus && button == 0 )
|
||||||
|
{
|
||||||
|
m_focus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastMouseX = charX;
|
if( m_focus )
|
||||||
lastMouseY = charY;
|
{
|
||||||
}
|
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() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
|
int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
|
|
||||||
return false;
|
computer.mouseClick( button + 1, charX + 1, charY + 1 );
|
||||||
|
|
||||||
|
m_lastClickButton = button;
|
||||||
|
m_lastClickX = charX;
|
||||||
|
m_lastClickY = charY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( m_focus && button == 0 && m_allowFocusLoss )
|
||||||
|
{
|
||||||
|
m_focus = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseDragged( double mouseX, double mouseY, int button, double v2, double v3 )
|
public boolean onKeyboardInput()
|
||||||
{
|
{
|
||||||
ClientComputer computer = this.computer.get();
|
boolean handled = false;
|
||||||
if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
|
for( int i = m_keysDown.size() - 1; i >= 0; --i )
|
||||||
|
|
||||||
Terminal term = computer.getTerminal();
|
|
||||||
if( term != null )
|
|
||||||
{
|
{
|
||||||
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
int key = m_keysDown.get( i );
|
||||||
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
if( !Keyboard.isKeyDown( key ) )
|
||||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
{
|
||||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
m_keysDown.remove( i );
|
||||||
|
if( m_focus )
|
||||||
computer.mouseDrag( button + 1, charX + 1, charY + 1 );
|
{
|
||||||
|
// Queue the "key_up" event
|
||||||
lastMouseX = charX;
|
IComputer computer = m_computer.getComputer();
|
||||||
lastMouseY = charY;
|
if( computer != null ) computer.keyUp( key );
|
||||||
lastMouseButton = button;
|
handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled( double delta )
|
public void handleMouseInput( int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
ClientComputer computer = this.computer.get();
|
IComputer computer = m_computer.getComputer();
|
||||||
if( computer == null || !computer.isColour() ) return false;
|
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
|
||||||
|
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() &&
|
||||||
if( lastMouseX >= 0 && lastMouseY >= 0 && delta != 0 )
|
computer != null && computer.isColour() )
|
||||||
{
|
{
|
||||||
queueEvent( "mouse_scroll", delta < 0 ? 1 : -1, lastMouseX + 1, lastMouseY + 1 );
|
Terminal term = computer.getTerminal();
|
||||||
}
|
if( term != null )
|
||||||
|
{
|
||||||
|
int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
|
int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
|
|
||||||
return true;
|
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( m_terminateTimer < TERMINATE_TIME )
|
||||||
|
{
|
||||||
|
m_terminateTimer += 0.05f;
|
||||||
|
if( m_terminateTimer >= TERMINATE_TIME ) queueEvent( "terminate" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_terminateTimer = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
if( shutdownTimer >= 0 && shutdownTimer < TERMINATE_TIME && (shutdownTimer += 0.05f) > TERMINATE_TIME )
|
// Ctrl+R for reboot
|
||||||
{
|
if( Keyboard.isKeyDown( 19 ) )
|
||||||
ClientComputer computer = this.computer.get();
|
{
|
||||||
if( computer != null ) computer.shutdown();
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
if( rebootTimer >= 0 && rebootTimer < TERMINATE_TIME && (rebootTimer += 0.05f) > TERMINATE_TIME )
|
// 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
|
||||||
{
|
{
|
||||||
ClientComputer computer = this.computer.get();
|
m_terminateTimer = 0.0f;
|
||||||
if( computer != null ) computer.reboot();
|
m_rebootTimer = 0.0f;
|
||||||
|
m_shutdownTimer = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusChanged( boolean focused )
|
public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
if( !focused )
|
int startX = xOrigin + getXPosition();
|
||||||
{
|
int startY = yOrigin + getYPosition();
|
||||||
// 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 );
|
|
||||||
}
|
|
||||||
keysDown.clear();
|
|
||||||
|
|
||||||
// When blurring, we should make the last mouse button go up
|
synchronized( m_computer )
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw( int originX, int originY )
|
|
||||||
{
|
|
||||||
synchronized( computer )
|
|
||||||
{
|
{
|
||||||
// Draw the screen contents
|
// Draw the screen contents
|
||||||
ClientComputer computer = this.computer.get();
|
IComputer computer = m_computer.getComputer();
|
||||||
Terminal terminal = computer != null ? computer.getTerminal() : null;
|
Terminal terminal = computer != null ? computer.getTerminal() : null;
|
||||||
if( terminal != null )
|
if( terminal != null )
|
||||||
{
|
{
|
||||||
// Draw the terminal
|
// Draw the terminal
|
||||||
boolean greyscale = !computer.isColour();
|
boolean greyscale = !computer.isColour();
|
||||||
|
|
||||||
Palette palette = terminal.getPalette();
|
Palette palette = terminal.getPalette();
|
||||||
|
|
||||||
// Get the data from the terminal first
|
// Get the data from the terminal first
|
||||||
// Unfortunately we have to keep the lock for the whole of drawing, so the text doesn't change under us.
|
// Unfortunately we have to keep the lock for the whole of drawing, so the text doesn't change under us.
|
||||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
||||||
boolean tblink = terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink();
|
boolean tblink = m_focus && terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink();
|
||||||
int tw = terminal.getWidth();
|
int tw = terminal.getWidth();
|
||||||
int th = terminal.getHeight();
|
int th = terminal.getHeight();
|
||||||
int tx = terminal.getCursorX();
|
int tx = terminal.getCursorX();
|
||||||
int ty = terminal.getCursorY();
|
int ty = terminal.getCursorY();
|
||||||
|
|
||||||
|
int x = startX + m_leftMargin;
|
||||||
|
int y = startY + m_topMargin;
|
||||||
|
|
||||||
// Draw margins
|
// Draw margins
|
||||||
TextBuffer emptyLine = new TextBuffer( ' ', tw );
|
TextBuffer emptyLine = new TextBuffer( ' ', tw );
|
||||||
if( topMargin > 0 )
|
if( m_topMargin > 0 )
|
||||||
{
|
{
|
||||||
fontRenderer.drawString( emptyLine, originX, originY - topMargin,
|
fontRenderer.drawString( emptyLine, x, startY, terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), m_leftMargin, m_rightMargin, greyscale, palette );
|
||||||
terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ),
|
|
||||||
leftMargin, rightMargin, greyscale, palette );
|
|
||||||
}
|
}
|
||||||
|
if( m_bottomMargin > 0 )
|
||||||
if( bottomMargin > 0 )
|
|
||||||
{
|
{
|
||||||
fontRenderer.drawString( emptyLine, originX, originY + bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT,
|
fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette );
|
||||||
terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ),
|
|
||||||
leftMargin, rightMargin, greyscale, palette );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw lines
|
// Draw lines
|
||||||
int y = originY;
|
|
||||||
for( int line = 0; line < th; line++ )
|
for( int line = 0; line < th; line++ )
|
||||||
{
|
{
|
||||||
TextBuffer text = terminal.getLine( line );
|
TextBuffer text = terminal.getLine( line );
|
||||||
TextBuffer colour = terminal.getTextColourLine( line );
|
TextBuffer colour = terminal.getTextColourLine( line );
|
||||||
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
||||||
fontRenderer.drawString( text, originX, y, colour, backgroundColour, leftMargin, rightMargin, greyscale, palette );
|
fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale, palette );
|
||||||
y += FixedWidthFontRenderer.FONT_HEIGHT;
|
y += FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +385,8 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
|
|
||||||
fontRenderer.drawString(
|
fontRenderer.drawString(
|
||||||
cursor,
|
cursor,
|
||||||
originX + FixedWidthFontRenderer.FONT_WIDTH * tx,
|
x + FixedWidthFontRenderer.FONT_WIDTH * tx,
|
||||||
originY + FixedWidthFontRenderer.FONT_HEIGHT * ty,
|
startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty,
|
||||||
cursorColour, null,
|
cursorColour, null,
|
||||||
0, 0,
|
0, 0,
|
||||||
greyscale,
|
greyscale,
|
||||||
@@ -375,29 +397,16 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Draw a black background
|
// Draw a black background
|
||||||
|
mc.getTextureManager().bindTexture( BACKGROUND );
|
||||||
Colour black = Colour.Black;
|
Colour black = Colour.Black;
|
||||||
GlStateManager.color4f( black.getR(), black.getG(), black.getB(), 1.0f );
|
GlStateManager.color( black.getR(), black.getG(), black.getB(), 1.0f );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int x = originX - leftMargin;
|
drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() );
|
||||||
int y = originY - rightMargin;
|
|
||||||
int width = termWidth * FixedWidthFontRenderer.FONT_WIDTH + leftMargin + rightMargin;
|
|
||||||
int height = termHeight * FixedWidthFontRenderer.FONT_HEIGHT + topMargin + bottomMargin;
|
|
||||||
|
|
||||||
client.getTextureManager().bindTexture( BACKGROUND );
|
|
||||||
|
|
||||||
Tessellator tesslector = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tesslector.getBuffer();
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX );
|
|
||||||
buffer.pos( x, y + height, 0 ).tex( 0 / 256.0, height / 256.0 ).endVertex();
|
|
||||||
buffer.pos( x + width, y + height, 0 ).tex( width / 256.0, height / 256.0 ).endVertex();
|
|
||||||
buffer.pos( x + width, y, 0 ).tex( width / 256.0, 0 / 256.0 ).endVertex();
|
|
||||||
buffer.pos( x, y, 0 ).tex( 0 / 256.0, 0 / 256.0 ).endVertex();
|
|
||||||
tesslector.draw();
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,13 +414,13 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
|
|
||||||
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. 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 void focusChanged( boolean b )
|
|
||||||
{
|
|
||||||
listener.focusChanged( b );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canFocus()
|
|
||||||
{
|
|
||||||
return listener.canFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 delta )
|
|
||||||
{
|
|
||||||
return listener.mouseScrolled( 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,90 +7,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.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.computer.blocks.TileComputer;
|
import dan200.computercraft.shared.command.CommandCopy;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
|
||||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
|
||||||
import dan200.computercraft.shared.network.container.*;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
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.proxy.ComputerCraftProxyCommon;
|
||||||
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.Minecraft;
|
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
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.ExtensionPoint;
|
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
|
||||||
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;
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
|
|
||||||
public final class ComputerCraftProxyClient
|
|
||||||
{
|
{
|
||||||
@SubscribeEvent
|
@Override
|
||||||
public static void setupClient( FMLClientSetupEvent event )
|
public void preInit()
|
||||||
{
|
{
|
||||||
registerContainers();
|
super.preInit();
|
||||||
|
|
||||||
// Setup TESRs
|
// Register any client-specific commands
|
||||||
|
ClientCommandHandler.instance.registerCommand( CommandCopy.INSTANCE );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init()
|
||||||
|
{
|
||||||
|
super.init();
|
||||||
|
|
||||||
|
// Setup renderers
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() );
|
ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerContainers()
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
{
|
|
||||||
ContainerType.registerGui( TileEntityContainerType::computer, ( packet, player ) ->
|
|
||||||
new GuiComputer( (TileComputer) packet.getTileEntity( player ) ) );
|
|
||||||
ContainerType.registerGui( TileEntityContainerType::diskDrive, GuiDiskDrive::new );
|
|
||||||
ContainerType.registerGui( TileEntityContainerType::printer, GuiPrinter::new );
|
|
||||||
ContainerType.registerGui( TileEntityContainerType::turtle, ( packet, player ) -> {
|
|
||||||
TileTurtle turtle = (TileTurtle) packet.getTileEntity( player );
|
|
||||||
return new GuiTurtle( turtle, new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getClientComputer() ) );
|
|
||||||
} );
|
|
||||||
|
|
||||||
ContainerType.registerGui( PocketComputerContainerType::new, GuiPocketComputer::new );
|
|
||||||
ContainerType.registerGui( PrintoutContainerType::new, GuiPrintout::new );
|
|
||||||
ContainerType.registerGui( ViewComputerContainerType::new, ( packet, player ) -> {
|
|
||||||
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( packet.instanceId );
|
|
||||||
if( computer == null )
|
|
||||||
{
|
|
||||||
ComputerCraft.clientComputerRegistry.add( packet.instanceId, computer = new ClientComputer( packet.instanceId ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
ContainerViewComputer container = new ContainerViewComputer( computer );
|
|
||||||
return new GuiComputer( container, packet.family, computer, packet.width, packet.height );
|
|
||||||
} );
|
|
||||||
|
|
||||||
ModLoadingContext.get().registerExtensionPoint( ExtensionPoint.GUIFACTORY, () -> packet -> {
|
|
||||||
ContainerType<?> type = ContainerType.factories.get( packet.getId() ).get();
|
|
||||||
if( packet.getAdditionalData() != null ) type.fromBytes( packet.getAdditionalData() );
|
|
||||||
@SuppressWarnings( "unchecked" )
|
|
||||||
BiFunction<ContainerType<?>, EntityPlayer, GuiContainer> factory = (BiFunction<ContainerType<?>, EntityPlayer, GuiContainer>) ContainerType.guiFactories.get( packet.getId() );
|
|
||||||
return factory.apply( type, Minecraft.getInstance().player );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,82 +7,216 @@
|
|||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
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.BlockCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
import net.minecraft.block.state.IBlockState;
|
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.GlStateManager;
|
||||||
import net.minecraft.client.renderer.WorldRenderer;
|
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.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||||
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;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
public final class CableHighlightRenderer
|
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()
|
private CableHighlightRenderer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw an outline for a specific part of a cable "Multipart".
|
|
||||||
*
|
|
||||||
* @param event The event to observe
|
|
||||||
* @see WorldRenderer#drawSelectionBox(EntityPlayer, RayTraceResult, int, float)
|
|
||||||
*/
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void drawHighlight( DrawBlockHighlightEvent event )
|
public static void drawHighlight( DrawBlockHighlightEvent event )
|
||||||
{
|
{
|
||||||
if( event.getTarget().type != RayTraceResult.Type.BLOCK ) return;
|
if( event.getTarget().typeOfHit != RayTraceResult.Type.BLOCK ) return;
|
||||||
|
|
||||||
BlockPos pos = event.getTarget().getBlockPos();
|
BlockPos pos = event.getTarget().getBlockPos();
|
||||||
World world = event.getPlayer().getEntityWorld();
|
World world = event.getPlayer().getEntityWorld();
|
||||||
|
|
||||||
IBlockState state = world.getBlockState( pos );
|
IBlockState state = world.getBlockState( pos );
|
||||||
|
if( state.getBlock() != ComputerCraft.Blocks.cable ) return;
|
||||||
|
|
||||||
// We only care about instances with both cable and modem.
|
state = state.getActualState( world, pos );
|
||||||
if( state.getBlock() != ComputerCraft.Blocks.cable || state.get( BlockCable.MODEM ).getFacing() == null || !state.get( BlockCable.CABLE ) )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCanceled( true );
|
event.setCanceled( true );
|
||||||
|
PeripheralType type = BlockCable.getPeripheralType( state );
|
||||||
EntityPlayer player = event.getPlayer();
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
float partialTicks = event.getPartialTicks();
|
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
GlStateManager.tryBlendFuncSeparate( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0 );
|
||||||
GlStateManager.lineWidth( Math.max( 2.5F, mc.mainWindow.getFramebufferWidth() / 1920.0F * 2.5F ) );
|
GlStateManager.color( 0.0f, 0.0f, 0.0f, 0.4f );
|
||||||
|
GL11.glLineWidth( 2.0F );
|
||||||
GlStateManager.disableTexture2D();
|
GlStateManager.disableTexture2D();
|
||||||
GlStateManager.depthMask( false );
|
GlStateManager.depthMask( false );
|
||||||
GlStateManager.matrixMode( GL11.GL_PROJECTION );
|
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
GlStateManager.scalef( 1.0F, 1.0F, 0.999F );
|
|
||||||
|
|
||||||
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
|
{
|
||||||
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
|
EntityPlayer player = event.getPlayer();
|
||||||
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
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();
|
||||||
|
|
||||||
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), event.getTarget().hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
GlStateManager.translate( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
||||||
? CableShapes.getModemShape( state )
|
}
|
||||||
: CableShapes.getCableShape( state );
|
|
||||||
|
|
||||||
WorldRenderer.drawShape( shape, pos.getX() - x, pos.getY() - y, pos.getZ() - z, 0.0F, 0.0F, 0.0F, 0.4F );
|
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.popMatrix();
|
||||||
GlStateManager.matrixMode( GL11.GL_MODELVIEW );
|
|
||||||
GlStateManager.depthMask( true );
|
GlStateManager.depthMask( true );
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture2D();
|
||||||
GlStateManager.disableBlend();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.FirstPersonRenderer;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
|
import net.minecraft.client.renderer.ItemRenderer;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
@@ -18,16 +18,16 @@ import net.minecraft.util.math.MathHelper;
|
|||||||
public abstract class ItemMapLikeRenderer
|
public abstract class ItemMapLikeRenderer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The main rendering method for the item
|
* The main rendering method for the item.
|
||||||
*
|
*
|
||||||
* @param stack The stack to render
|
* @param stack The stack to render
|
||||||
* @see FirstPersonRenderer#renderMapFirstPerson(ItemStack)
|
* @see ItemRenderer#renderMapFirstPerson(ItemStack)
|
||||||
*/
|
*/
|
||||||
protected abstract void renderItem( ItemStack stack );
|
protected abstract void renderItem( ItemStack stack );
|
||||||
|
|
||||||
protected void renderItemFirstPerson( EnumHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
protected void renderItemFirstPerson( EnumHand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
{
|
{
|
||||||
EntityPlayer player = Minecraft.getInstance().player;
|
EntityPlayer player = Minecraft.getMinecraft().player;
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
|
if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
|
||||||
@@ -51,35 +51,35 @@ public abstract class ItemMapLikeRenderer
|
|||||||
* @param equipProgress The equip progress of this item
|
* @param equipProgress The equip progress of this item
|
||||||
* @param swingProgress The swing progress of this item
|
* @param swingProgress The swing progress of this item
|
||||||
* @param stack The stack to render
|
* @param stack The stack to render
|
||||||
* @see FirstPersonRenderer#renderMapFirstPersonSide(float, EnumHandSide, float, ItemStack)
|
* @see ItemRenderer#renderMapFirstPersonSide(float, EnumHandSide, float, ItemStack)
|
||||||
*/
|
*/
|
||||||
private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack )
|
private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
{
|
{
|
||||||
Minecraft minecraft = Minecraft.getInstance();
|
Minecraft minecraft = Minecraft.getMinecraft();
|
||||||
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
|
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
|
||||||
GlStateManager.translatef( offset * 0.125f, -0.125f, 0f );
|
GlStateManager.translate( offset * 0.125f, -0.125f, 0f );
|
||||||
|
|
||||||
// If the player is not invisible then render a single arm
|
// If the player is not invisible then render a single arm
|
||||||
if( !minecraft.player.isInvisible() )
|
if( !minecraft.player.isInvisible() )
|
||||||
{
|
{
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
GlStateManager.rotatef( offset * 10f, 0f, 0f, 1f );
|
GlStateManager.rotate( offset * 10f, 0f, 0f, 1f );
|
||||||
minecraft.getFirstPersonRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
|
minecraft.getItemRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the appropriate transformations. This is just copied from the
|
// Setup the appropriate transformations. This is just copied from the
|
||||||
// corresponding method in ItemRenderer.
|
// corresponding method in ItemRenderer.
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
GlStateManager.translatef( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
GlStateManager.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
||||||
float f1 = MathHelper.sqrt( swingProgress );
|
float f1 = MathHelper.sqrt( swingProgress );
|
||||||
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
||||||
float f3 = -0.5f * f2;
|
float f3 = -0.5f * f2;
|
||||||
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
||||||
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||||
GlStateManager.translatef( offset * f3, f4 - 0.3f * f2, f5 );
|
GlStateManager.translate( offset * f3, f4 - 0.3f * f2, f5 );
|
||||||
GlStateManager.rotatef( f2 * -45f, 1f, 0f, 0f );
|
GlStateManager.rotate( f2 * -45f, 1f, 0f, 0f );
|
||||||
GlStateManager.rotatef( offset * f2 * -30f, 0f, 1f, 0f );
|
GlStateManager.rotate( offset * f2 * -30f, 0f, 1f, 0f );
|
||||||
|
|
||||||
renderItem( stack );
|
renderItem( stack );
|
||||||
|
|
||||||
@@ -87,31 +87,31 @@ public abstract class ItemMapLikeRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an item in the middle of the screen
|
* Render an item in the middle of the screen.
|
||||||
*
|
*
|
||||||
* @param pitch The pitch of the player
|
* @param pitch The pitch of the player
|
||||||
* @param equipProgress The equip progress of this item
|
* @param equipProgress The equip progress of this item
|
||||||
* @param swingProgress The swing progress of this item
|
* @param swingProgress The swing progress of this item
|
||||||
* @param stack The stack to render
|
* @param stack The stack to render
|
||||||
* @see FirstPersonRenderer#renderMapFirstPerson(float, float, float)
|
* @see ItemRenderer#renderMapFirstPerson(float, float, float)
|
||||||
*/
|
*/
|
||||||
private void renderItemFirstPersonCenter( float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
private void renderItemFirstPersonCenter( float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
{
|
{
|
||||||
FirstPersonRenderer renderer = Minecraft.getInstance().getFirstPersonRenderer();
|
ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer();
|
||||||
|
|
||||||
// Setup the appropriate transformations. This is just copied from the
|
// Setup the appropriate transformations. This is just copied from the
|
||||||
// corresponding method in ItemRenderer.
|
// corresponding method in ItemRenderer.
|
||||||
float swingRt = MathHelper.sqrt( swingProgress );
|
float swingRt = MathHelper.sqrt( swingProgress );
|
||||||
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
|
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||||
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
||||||
GlStateManager.translatef( 0f, -tX / 2f, tZ );
|
GlStateManager.translate( 0f, -tX / 2f, tZ );
|
||||||
float pitchAngle = renderer.getMapAngleFromPitch( pitch );
|
float pitchAngle = itemRenderer.getMapAngleFromPitch( pitch );
|
||||||
GlStateManager.translatef( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
GlStateManager.translate( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
||||||
GlStateManager.rotatef( pitchAngle * -85f, 1f, 0f, 0f );
|
GlStateManager.rotate( pitchAngle * -85f, 1f, 0f, 0f );
|
||||||
renderer.renderArms();
|
itemRenderer.renderArms();
|
||||||
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
||||||
GlStateManager.rotatef( rX * 20f, 1f, 0f, 0f );
|
GlStateManager.rotate( rX * 20f, 1f, 0f, 0f );
|
||||||
GlStateManager.scalef( 2f, 2f, 2f );
|
GlStateManager.scale( 2f, 2f, 2f );
|
||||||
|
|
||||||
renderItem( stack );
|
renderItem( stack );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,19 +22,19 @@ 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.*;
|
||||||
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;
|
||||||
@@ -83,20 +83,19 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
|
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
GlStateManager.disableDepthTest();
|
GlStateManager.disableDepth();
|
||||||
|
|
||||||
GlStateManager.rotatef( 180f, 0f, 1f, 0f );
|
GlStateManager.rotate( 180f, 0f, 1f, 0f );
|
||||||
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
||||||
GlStateManager.scalef( 0.5f, 0.5f, 0.5f );
|
GlStateManager.scale( 0.5, 0.5, 0.5 );
|
||||||
|
|
||||||
double scale = 0.75 / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT );
|
double scale = 0.75 / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT );
|
||||||
GlStateManager.scaled( scale, scale, 0 );
|
GlStateManager.scale( scale, scale, 0 );
|
||||||
GlStateManager.translated( -0.5 * width, -0.5 * height, 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,7 +111,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Otherwise render a plain background
|
// Otherwise render a plain background
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( BACKGROUND );
|
Minecraft.getMinecraft().getTextureManager().bindTexture( BACKGROUND );
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
@@ -123,7 +122,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
GlStateManager.enableDepthTest();
|
GlStateManager.enableDepth();
|
||||||
GlStateManager.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
@@ -131,7 +130,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
|||||||
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
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ 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.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;
|
||||||
@@ -23,9 +23,9 @@ import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAG
|
|||||||
import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH;
|
import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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();
|
||||||
@@ -38,9 +38,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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,13 +49,13 @@ 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
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
GlStateManager.rotatef( 180f, 0f, 1f, 0f );
|
GlStateManager.rotate( 180f, 0f, 1f, 0f );
|
||||||
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
||||||
GlStateManager.scalef( 0.42f, 0.42f, -0.42f );
|
GlStateManager.scale( 0.42f, 0.42f, -0.42f );
|
||||||
GlStateManager.translatef( -0.5f, -0.48f, 0.0f );
|
GlStateManager.translate( -0.5f, -0.48f, 0.0f );
|
||||||
|
|
||||||
drawPrintout( stack );
|
drawPrintout( stack );
|
||||||
|
|
||||||
@@ -65,17 +66,17 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
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 );
|
||||||
|
|
||||||
GlStateManager.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
|
||||||
GlStateManager.translatef( 0.0f, 0.0f, -0.001f );
|
GlStateManager.translate( 0.0f, 0.0f, -0.001f );
|
||||||
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
||||||
GlStateManager.scalef( 0.95f, 0.95f, -0.95f );
|
GlStateManager.scale( 0.95f, 0.95f, -0.95f );
|
||||||
GlStateManager.translatef( -0.5f, -0.5f, 0.0f );
|
GlStateManager.translate( -0.5f, -0.5f, 0.0f );
|
||||||
|
|
||||||
drawPrintout( stack );
|
drawPrintout( stack );
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
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;
|
||||||
@@ -107,8 +108,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;
|
||||||
GlStateManager.scaled( scale, scale, scale );
|
GlStateManager.scale( scale, scale, scale );
|
||||||
GlStateManager.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 ) );
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package dan200.computercraft.client.render;
|
|||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
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;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
@@ -19,17 +18,17 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
||||||
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 java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import static net.minecraft.util.EnumFacing.*;
|
import static net.minecraft.util.EnumFacing.*;
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
||||||
public final class MonitorHighlightRenderer
|
public final class MonitorHighlightRenderer
|
||||||
{
|
{
|
||||||
private static final float EXPAND = 0.002f;
|
private static final float EXPAND = 0.002f;
|
||||||
@@ -41,11 +40,13 @@ public final class MonitorHighlightRenderer
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void drawHighlight( DrawBlockHighlightEvent event )
|
public static void drawHighlight( DrawBlockHighlightEvent event )
|
||||||
{
|
{
|
||||||
if( event.getTarget().type != RayTraceResult.Type.BLOCK || event.getPlayer().isSneaking() ) return;
|
if( event.getTarget().typeOfHit != RayTraceResult.Type.BLOCK || event.getPlayer().isSneaking() ) return;
|
||||||
|
|
||||||
World world = event.getPlayer().getEntityWorld();
|
World world = event.getPlayer().getEntityWorld();
|
||||||
BlockPos pos = event.getTarget().getBlockPos();
|
BlockPos pos = event.getTarget().getBlockPos();
|
||||||
|
|
||||||
|
if( world.getBlockState( pos ).getBlock() != ComputerCraft.Blocks.peripheral ) return;
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
TileEntity tile = world.getTileEntity( pos );
|
||||||
if( !(tile instanceof TileMonitor) ) return;
|
if( !(tile instanceof TileMonitor) ) return;
|
||||||
|
|
||||||
@@ -62,8 +63,8 @@ public final class MonitorHighlightRenderer
|
|||||||
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
GlStateManager.tryBlendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
||||||
GlStateManager.lineWidth( Math.max( 2.5F, (float) Minecraft.getInstance().mainWindow.getFramebufferWidth() / 1920.0F * 2.5F ) );
|
GL11.glLineWidth( 2.0F );
|
||||||
GlStateManager.disableTexture2D();
|
GlStateManager.disableTexture2D();
|
||||||
GlStateManager.depthMask( false );
|
GlStateManager.depthMask( false );
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
@@ -73,7 +74,7 @@ public final class MonitorHighlightRenderer
|
|||||||
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
||||||
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
||||||
|
|
||||||
GlStateManager.translated( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
GlStateManager.translate( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
BufferBuilder buffer = tessellator.getBuffer();
|
||||||
|
|||||||
@@ -28,32 +28,32 @@ public final class PrintoutRenderer
|
|||||||
private static final double BG_SIZE = 256.0;
|
private static final double BG_SIZE = 256.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Width of a page
|
* Width of a page.
|
||||||
*/
|
*/
|
||||||
public static final int X_SIZE = 172;
|
public static final int X_SIZE = 172;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Height of a page
|
* Height of a page.
|
||||||
*/
|
*/
|
||||||
public static final int Y_SIZE = 209;
|
public static final int Y_SIZE = 209;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Padding between the left and right of a page and the text
|
* Padding between the left and right of a page and the text.
|
||||||
*/
|
*/
|
||||||
public static final int X_TEXT_MARGIN = 13;
|
public static final int X_TEXT_MARGIN = 13;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Padding between the top and bottom of a page and the text
|
* Padding between the top and bottom of a page and the text.
|
||||||
*/
|
*/
|
||||||
public static final int Y_TEXT_MARGIN = 11;
|
public static final int Y_TEXT_MARGIN = 11;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Width of the extra page texture
|
* Width of the extra page texture.
|
||||||
*/
|
*/
|
||||||
private static final int X_FOLD_SIZE = 12;
|
private static final int X_FOLD_SIZE = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of the leather cover
|
* Size of the leather cover.
|
||||||
*/
|
*/
|
||||||
public static final int COVER_SIZE = 12;
|
public static final int COVER_SIZE = 12;
|
||||||
|
|
||||||
@@ -74,10 +74,10 @@ public final class PrintoutRenderer
|
|||||||
|
|
||||||
public static void drawText( int x, int y, int start, String[] text, String[] colours )
|
public static void drawText( int x, int y, int start, String[] text, String[] colours )
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture2D();
|
||||||
GlStateManager.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 );
|
||||||
|
|
||||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
||||||
|
|
||||||
@@ -89,12 +89,12 @@ public final class PrintoutRenderer
|
|||||||
|
|
||||||
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 )
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture2D();
|
||||||
GlStateManager.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();
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
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.BlockCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCableModemVariant;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@@ -17,11 +18,11 @@ import net.minecraft.block.state.IBlockState;
|
|||||||
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;
|
||||||
|
import net.minecraft.client.renderer.RenderGlobal;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.WorldRenderer;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.util.BlockRenderLayer;
|
import net.minecraft.util.BlockRenderLayer;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -29,27 +30,23 @@ import net.minecraft.util.math.RayTraceResult;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
import net.minecraftforge.client.ForgeHooksClient;
|
||||||
import net.minecraftforge.client.MinecraftForgeClient;
|
import net.minecraftforge.client.MinecraftForgeClient;
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render breaking animation only over part of a {@link TileCable}.
|
* Render breaking animation only over part of a {@link TileCable}.
|
||||||
*/
|
*/
|
||||||
public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
|
public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable>
|
||||||
{
|
{
|
||||||
private static final Random random = new Random();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( @Nonnull TileCable te, double x, double y, double z, float partialTicks, int destroyStage )
|
public void render( @Nonnull TileCable te, double x, double y, double z, float partialTicks, int destroyStage, float alpha )
|
||||||
{
|
{
|
||||||
if( destroyStage < 0 ) return;
|
if( destroyStage < 0 ) return;
|
||||||
|
|
||||||
BlockPos pos = te.getPos();
|
BlockPos pos = te.getPos();
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
RayTraceResult hit = mc.objectMouseOver;
|
RayTraceResult hit = mc.objectMouseOver;
|
||||||
if( hit == null || !hit.getBlockPos().equals( pos ) ) return;
|
if( hit == null || !hit.getBlockPos().equals( pos ) ) return;
|
||||||
@@ -61,11 +58,18 @@ public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
|
|||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
if( block != ComputerCraft.Blocks.cable ) return;
|
if( block != ComputerCraft.Blocks.cable ) return;
|
||||||
|
|
||||||
state = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
state = state.getActualState( world, pos );
|
||||||
? block.getDefaultState().with( BlockCable.MODEM, state.get( BlockCable.MODEM ) )
|
if( te.getPeripheralType() != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
||||||
: state.with( BlockCable.MODEM, CableModemVariant.None );
|
{
|
||||||
|
state = block.getDefaultState().withProperty( BlockCable.MODEM, state.getValue( BlockCable.MODEM ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state = state.withProperty( BlockCable.MODEM, BlockCableModemVariant.None );
|
||||||
|
}
|
||||||
|
|
||||||
IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state );
|
IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state );
|
||||||
|
if( model == null ) return;
|
||||||
|
|
||||||
preRenderDamagedBlocks();
|
preRenderDamagedBlocks();
|
||||||
|
|
||||||
@@ -77,11 +81,11 @@ public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
|
|||||||
ForgeHooksClient.setRenderLayer( block.getRenderLayer() );
|
ForgeHooksClient.setRenderLayer( block.getRenderLayer() );
|
||||||
|
|
||||||
// See BlockRendererDispatcher#renderBlockDamage
|
// See BlockRendererDispatcher#renderBlockDamage
|
||||||
TextureAtlasSprite breakingTexture = mc.getTextureMap().getSprite( DESTROY_STAGES[destroyStage] );
|
TextureAtlasSprite breakingTexture = mc.getTextureMapBlocks().getAtlasSprite( "minecraft:blocks/destroy_stage_" + destroyStage );
|
||||||
mc.getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
|
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
|
||||||
world,
|
world,
|
||||||
ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos ),
|
ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos ),
|
||||||
state, pos, buffer, true, random, state.getPositionRandom( pos ), EmptyModelData.INSTANCE
|
state, pos, buffer, true
|
||||||
);
|
);
|
||||||
|
|
||||||
ForgeHooksClient.setRenderLayer( BlockRenderLayer.SOLID );
|
ForgeHooksClient.setRenderLayer( BlockRenderLayer.SOLID );
|
||||||
@@ -93,30 +97,34 @@ public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see WorldRenderer#preRenderDamagedBlocks()
|
* Set up the state for rendering block-breaking progress.
|
||||||
|
*
|
||||||
|
* @see RenderGlobal#preRenderDamagedBlocks()
|
||||||
*/
|
*/
|
||||||
private void preRenderDamagedBlocks()
|
private void preRenderDamagedBlocks()
|
||||||
{
|
{
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
GlStateManager.tryBlendFuncSeparate( GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 0.5F );
|
GlStateManager.color( 1.0F, 1.0F, 1.0F, 0.5F );
|
||||||
GlStateManager.polygonOffset( -3.0F, -3.0F );
|
GlStateManager.doPolygonOffset( -3.0F, -3.0F );
|
||||||
GlStateManager.enablePolygonOffset();
|
GlStateManager.enablePolygonOffset();
|
||||||
GlStateManager.alphaFunc( 516, 0.1F );
|
GlStateManager.alphaFunc( 516, 0.1F );
|
||||||
GlStateManager.enableAlphaTest();
|
GlStateManager.enableAlpha();
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see WorldRenderer#postRenderDamagedBlocks()
|
* Tear down the state for rendering block-breaking progress.
|
||||||
|
*
|
||||||
|
* @see RenderGlobal#postRenderDamagedBlocks()
|
||||||
*/
|
*/
|
||||||
private void postRenderDamagedBlocks()
|
private void postRenderDamagedBlocks()
|
||||||
{
|
{
|
||||||
GlStateManager.disableAlphaTest();
|
GlStateManager.disableAlpha();
|
||||||
GlStateManager.polygonOffset( 0.0F, 0.0F );
|
GlStateManager.doPolygonOffset( 0.0F, 0.0F );
|
||||||
GlStateManager.disablePolygonOffset();
|
GlStateManager.disablePolygonOffset();
|
||||||
GlStateManager.disablePolygonOffset();
|
GlStateManager.disablePolygonOffset();
|
||||||
GlStateManager.depthMask( true );
|
GlStateManager.depthMask( true );
|
||||||
|
|||||||
@@ -20,16 +20,16 @@ import net.minecraft.client.renderer.BufferBuilder;
|
|||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.OpenGlHelper;
|
import net.minecraft.client.renderer.OpenGlHelper;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||||
import net.minecraft.util.EnumFacing;
|
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.GL11;
|
||||||
|
|
||||||
public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMonitor>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void render( TileMonitor tileEntity, double posX, double posY, double posZ, float f, int i )
|
public void render( TileMonitor tileEntity, double posX, double posY, double posZ, float f, int i, float f2 )
|
||||||
{
|
{
|
||||||
if( tileEntity != null )
|
if( tileEntity != null )
|
||||||
{
|
{
|
||||||
@@ -73,19 +73,19 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Setup initial transform
|
// Setup initial transform
|
||||||
GlStateManager.translated( posX + 0.5, posY + 0.5, posZ + 0.5 );
|
GlStateManager.translate( posX + 0.5, posY + 0.5, posZ + 0.5 );
|
||||||
GlStateManager.rotatef( -yaw, 0.0f, 1.0f, 0.0f );
|
GlStateManager.rotate( -yaw, 0.0f, 1.0f, 0.0f );
|
||||||
GlStateManager.rotatef( pitch, 1.0f, 0.0f, 0.0f );
|
GlStateManager.rotate( pitch, 1.0f, 0.0f, 0.0f );
|
||||||
GlStateManager.translated(
|
GlStateManager.translate(
|
||||||
-0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
|
-0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
|
||||||
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0,
|
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN),
|
||||||
0.5
|
0.5
|
||||||
);
|
);
|
||||||
double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||||
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||||
|
|
||||||
// Get renderers
|
// Get renderers
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder renderer = tessellator.getBuffer();
|
BufferBuilder renderer = tessellator.getBuffer();
|
||||||
|
|
||||||
@@ -94,9 +94,9 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
|
|
||||||
// Draw the contents
|
// Draw the contents
|
||||||
GlStateManager.depthMask( false );
|
GlStateManager.depthMask( false );
|
||||||
OpenGlHelper.glMultiTexCoord2f( OpenGlHelper.GL_TEXTURE1, 0xFFFF, 0xFFFF );
|
OpenGlHelper.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, 0xFF, 0xFF );
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
mc.gameRenderer.disableLightmap();
|
mc.entityRenderer.disableLightmap();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Terminal terminal = originTerminal.getTerminal();
|
Terminal terminal = originTerminal.getTerminal();
|
||||||
@@ -124,14 +124,14 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
{
|
{
|
||||||
double xScale = xSize / (width * FixedWidthFontRenderer.FONT_WIDTH);
|
double xScale = xSize / (width * FixedWidthFontRenderer.FONT_WIDTH);
|
||||||
double yScale = ySize / (height * FixedWidthFontRenderer.FONT_HEIGHT);
|
double yScale = ySize / (height * FixedWidthFontRenderer.FONT_HEIGHT);
|
||||||
GlStateManager.scaled( xScale, -yScale, 1.0 );
|
GlStateManager.scale( xScale, -yScale, 1.0 );
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.BACKGROUND );
|
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.BACKGROUND );
|
||||||
if( redraw )
|
if( redraw )
|
||||||
{
|
{
|
||||||
// Build background display list
|
// Build background display list
|
||||||
GlStateManager.newList( originTerminal.renderDisplayLists[0], GL11.GL_COMPILE );
|
GlStateManager.glNewList( originTerminal.renderDisplayLists[0], GL11.GL_COMPILE );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
double marginXSize = TileMonitor.RENDER_MARGIN / xScale;
|
double marginXSize = TileMonitor.RENDER_MARGIN / xScale;
|
||||||
@@ -142,10 +142,10 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GlStateManager.scaled( 1.0, marginSquash, 1.0 );
|
GlStateManager.scale( 1.0, marginSquash, 1.0 );
|
||||||
GlStateManager.translated( 0.0, -marginYSize / marginSquash, 0.0 );
|
GlStateManager.translate( 0.0, -marginYSize / marginSquash, 0.0 );
|
||||||
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( 0 ), marginXSize, marginXSize, greyscale, palette );
|
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( 0 ), marginXSize, marginXSize, greyscale, palette );
|
||||||
GlStateManager.translated( 0.0, (marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT) / marginSquash, 0.0 );
|
GlStateManager.translate( 0.0, (marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT) / marginSquash, 0.0 );
|
||||||
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( height - 1 ), marginXSize, marginXSize, greyscale, palette );
|
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( height - 1 ), marginXSize, marginXSize, greyscale, palette );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -167,7 +167,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.endList();
|
GlStateManager.glEndList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[0] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[0] );
|
||||||
@@ -178,7 +178,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
if( redraw )
|
if( redraw )
|
||||||
{
|
{
|
||||||
// Build text display list
|
// Build text display list
|
||||||
GlStateManager.newList( originTerminal.renderDisplayLists[1], GL11.GL_COMPILE );
|
GlStateManager.glNewList( originTerminal.renderDisplayLists[1], GL11.GL_COMPILE );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Lines
|
// Lines
|
||||||
@@ -195,7 +195,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.endList();
|
GlStateManager.glEndList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[1] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[1] );
|
||||||
@@ -206,7 +206,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
if( redraw )
|
if( redraw )
|
||||||
{
|
{
|
||||||
// Build cursor display list
|
// Build cursor display list
|
||||||
GlStateManager.newList( originTerminal.renderDisplayLists[2], GL11.GL_COMPILE );
|
GlStateManager.glNewList( originTerminal.renderDisplayLists[2], GL11.GL_COMPILE );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Cursor
|
// Cursor
|
||||||
@@ -227,7 +227,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.endList();
|
GlStateManager.glEndList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( FrameInfo.getGlobalCursorBlink() )
|
if( FrameInfo.getGlobalCursorBlink() )
|
||||||
@@ -262,7 +262,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.depthMask( true );
|
GlStateManager.depthMask( true );
|
||||||
mc.gameRenderer.enableLightmap();
|
mc.entityRenderer.enableLightmap();
|
||||||
GlStateManager.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,45 +10,42 @@ 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.block.state.IBlockState;
|
||||||
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.GameRenderer;
|
import net.minecraft.client.renderer.EntityRenderer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.renderer.Tessellator;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.ModelManager;
|
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
import net.minecraft.client.renderer.texture.TextureMap;
|
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.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.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
import net.minecraftforge.client.ForgeHooksClient;
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
|
||||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
import net.minecraftforge.client.model.pipeline.LightUtil;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import javax.vecmath.Matrix4f;
|
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" );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( TileTurtle tileEntity, double posX, double posY, double posZ, float partialTicks, int breaking )
|
public void render( TileTurtle tileEntity, double posX, double posY, double posZ, float partialTicks, int breaking, float f2 )
|
||||||
{
|
{
|
||||||
if( tileEntity != null ) renderTurtleAt( tileEntity, posX, posY, posZ, partialTicks );
|
if( tileEntity != null ) renderTurtleAt( tileEntity, posX, posY, posZ, partialTicks );
|
||||||
}
|
}
|
||||||
@@ -88,7 +85,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
if( label != null && rendererDispatcher.cameraHitResult != null && turtle.getPos().equals( rendererDispatcher.cameraHitResult.getBlockPos() ) )
|
if( label != null && rendererDispatcher.cameraHitResult != null && turtle.getPos().equals( rendererDispatcher.cameraHitResult.getBlockPos() ) )
|
||||||
{
|
{
|
||||||
setLightmapDisabled( true );
|
setLightmapDisabled( true );
|
||||||
GameRenderer.drawNameplate(
|
EntityRenderer.drawNameplate(
|
||||||
getFontRenderer(), label,
|
getFontRenderer(), label,
|
||||||
(float) posX + 0.5F, (float) posY + 1.2F, (float) posZ + 0.5F, 0,
|
(float) posX + 0.5F, (float) posY + 1.2F, (float) posZ + 0.5F, 0,
|
||||||
rendererDispatcher.entityYaw, rendererDispatcher.entityPitch, false, false
|
rendererDispatcher.entityYaw, rendererDispatcher.entityPitch, false, false
|
||||||
@@ -99,21 +96,22 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IBlockState state = turtle.getBlockState();
|
IBlockState state = turtle.getWorld().getBlockState( turtle.getPos() );
|
||||||
// Setup the transform
|
// Setup the transform
|
||||||
Vec3d offset = turtle.getRenderOffset( partialTicks );
|
Vec3d offset = turtle.getRenderOffset( partialTicks );
|
||||||
float yaw = turtle.getRenderYaw( partialTicks );
|
float yaw = turtle.getRenderYaw( partialTicks );
|
||||||
GlStateManager.translated( posX + offset.x, posY + offset.y, posZ + offset.z );
|
GlStateManager.translate( posX + offset.x, posY + offset.y, posZ + offset.z );
|
||||||
|
|
||||||
// Render the turtle
|
// Render the turtle
|
||||||
GlStateManager.translatef( 0.5f, 0.5f, 0.5f );
|
GlStateManager.translate( 0.5f, 0.5f, 0.5f );
|
||||||
GlStateManager.rotatef( 180.0f - yaw, 0.0f, 1.0f, 0.0f );
|
GlStateManager.rotate( 180.0f - yaw, 0.0f, 1.0f, 0.0f );
|
||||||
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
||||||
{
|
{
|
||||||
// Flip the model and swap the cull face as winding order will have changed.
|
// Flip the model and swap the cull face as winding order will have changed.
|
||||||
GlStateManager.scalef( 1.0f, -1.0f, 1.0f );
|
GlStateManager.scale( 1.0f, -1.0f, 1.0f );
|
||||||
GlStateManager.cullFace( GlStateManager.CullFace.FRONT );
|
GlStateManager.cullFace( GlStateManager.CullFace.FRONT );
|
||||||
}
|
}
|
||||||
GlStateManager.translatef( -0.5f, -0.5f, -0.5f );
|
GlStateManager.translate( -0.5f, -0.5f, -0.5f );
|
||||||
// Render the turtle
|
// Render the turtle
|
||||||
int colour = turtle.getColour();
|
int colour = turtle.getColour();
|
||||||
ComputerFamily family = turtle.getFamily();
|
ComputerFamily family = turtle.getFamily();
|
||||||
@@ -153,7 +151,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderUpgrade( IBlockState state, TileTurtle turtle, TurtleSide side, float f )
|
private static void renderUpgrade( IBlockState state, TileTurtle turtle, TurtleSide side, float f )
|
||||||
{
|
{
|
||||||
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
||||||
if( upgrade != null )
|
if( upgrade != null )
|
||||||
@@ -162,9 +160,9 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
float toolAngle = turtle.getToolRenderAngle( side, f );
|
float toolAngle = turtle.getToolRenderAngle( side, f );
|
||||||
GlStateManager.translatef( 0.0f, 0.5f, 0.5f );
|
GlStateManager.translate( 0.0f, 0.5f, 0.5f );
|
||||||
GlStateManager.rotatef( -toolAngle, 1.0f, 0.0f, 0.0f );
|
GlStateManager.rotate( -toolAngle, 1.0f, 0.0f, 0.0f );
|
||||||
GlStateManager.translatef( 0.0f, -0.5f, -0.5f );
|
GlStateManager.translate( 0.0f, -0.5f, -0.5f );
|
||||||
|
|
||||||
Pair<IBakedModel, Matrix4f> pair = upgrade.getModel( turtle.getAccess(), side );
|
Pair<IBakedModel, Matrix4f> pair = upgrade.getModel( turtle.getAccess(), side );
|
||||||
if( pair != null )
|
if( pair != null )
|
||||||
@@ -186,22 +184,22 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderModel( IBlockState state, ModelResourceLocation modelLocation, int[] tints )
|
private static void renderModel( IBlockState state, ModelResourceLocation modelLocation, int[] tints )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getInstance();
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager();
|
ModelManager modelManager = mc.getRenderItem().getItemModelMesher().getModelManager();
|
||||||
renderModel( state, modelManager.getModel( modelLocation ), tints );
|
renderModel( state, modelManager.getModel( modelLocation ), tints );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderModel( IBlockState state, IBakedModel model, int[] tints )
|
private static void renderModel( IBlockState state, IBakedModel model, int[] tints )
|
||||||
{
|
{
|
||||||
Random random = new Random( 0 );
|
Minecraft mc = Minecraft.getMinecraft();
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
rendererDispatcher.textureManager.bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
||||||
renderQuads( tessellator, model.getQuads( state, null, random, EmptyModelData.INSTANCE ), tints );
|
renderQuads( tessellator, model.getQuads( state, null, 0 ), tints );
|
||||||
for( EnumFacing facing : DirectionUtil.FACINGS )
|
for( EnumFacing facing : EnumFacing.VALUES )
|
||||||
{
|
{
|
||||||
renderQuads( tessellator, model.getQuads( state, facing, random, EmptyModelData.INSTANCE ), tints );
|
renderQuads( tessellator, model.getQuads( state, facing, 0 ), tints );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,29 +6,26 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||||
import net.minecraft.resources.IResourceManager;
|
import net.minecraft.client.resources.IResourceManager;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
import net.minecraftforge.client.model.ICustomModelLoader;
|
||||||
|
import net.minecraftforge.client.model.IModel;
|
||||||
|
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||||
import net.minecraftforge.common.model.IModelState;
|
import net.minecraftforge.common.model.IModelState;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public final class TurtleModelLoader implements ICustomModelLoader
|
public final class TurtleModelLoader implements ICustomModelLoader
|
||||||
{
|
{
|
||||||
private static final ResourceLocation NORMAL_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_normal" );
|
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/turtle_advanced" );
|
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_colour" );
|
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();
|
||||||
|
|
||||||
@@ -45,60 +42,80 @@ public final class TurtleModelLoader implements ICustomModelLoader
|
|||||||
public boolean accepts( @Nonnull ResourceLocation name )
|
public boolean accepts( @Nonnull ResourceLocation name )
|
||||||
{
|
{
|
||||||
return name.getNamespace().equals( ComputerCraft.MOD_ID )
|
return name.getNamespace().equals( ComputerCraft.MOD_ID )
|
||||||
&& (name.getPath().equals( "item/turtle_normal" ) || name.getPath().equals( "item/turtle_advanced" ));
|
&& (name.getPath().equals( "turtle" ) || name.getPath().equals( "turtle_advanced" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IUnbakedModel loadModel( @Nonnull ResourceLocation name )
|
public IModel loadModel( @Nonnull ResourceLocation name ) throws Exception
|
||||||
{
|
{
|
||||||
if( name.getNamespace().equals( ComputerCraft.MOD_ID ) )
|
if( name.getNamespace().equals( ComputerCraft.MOD_ID ) )
|
||||||
{
|
{
|
||||||
|
IModel colourModel = ModelLoaderRegistry.getModel( COLOUR_TURTLE_MODEL );
|
||||||
switch( name.getPath() )
|
switch( name.getPath() )
|
||||||
{
|
{
|
||||||
case "item/turtle_normal":
|
case "turtle":
|
||||||
return new TurtleModel( NORMAL_TURTLE_MODEL );
|
return new TurtleModel( ModelLoaderRegistry.getModel( NORMAL_TURTLE_MODEL ), colourModel );
|
||||||
case "item/turtle_advanced":
|
case "turtle_advanced":
|
||||||
return new TurtleModel( ADVANCED_TURTLE_MODEL );
|
return new TurtleModel( ModelLoaderRegistry.getModel( ADVANCED_TURTLE_MODEL ), colourModel );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalStateException( "Loader does not accept " + name );
|
throw new IllegalStateException( "Loader does not accept " + name );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TurtleModel implements IUnbakedModel
|
private static final class TurtleModel implements IModel
|
||||||
{
|
{
|
||||||
private final ResourceLocation family;
|
private final IModel family;
|
||||||
|
private final IModel colour;
|
||||||
|
|
||||||
private TurtleModel( ResourceLocation family )
|
private TurtleModel( IModel family, IModel colour )
|
||||||
{
|
{
|
||||||
this.family = family;
|
this.family = family;
|
||||||
|
this.colour = colour;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Collection<ResourceLocation> getDependencies()
|
public IBakedModel bake( @Nonnull IModelState state, @Nonnull VertexFormat format, @Nonnull Function<ResourceLocation, TextureAtlasSprite> function )
|
||||||
{
|
|
||||||
return Arrays.asList( family, COLOUR_TURTLE_MODEL );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public Collection<ResourceLocation> getTextures( @Nonnull Function<ResourceLocation, IUnbakedModel> modelGetter, @Nonnull Set<String> missingTextureErrors )
|
|
||||||
{
|
|
||||||
return getDependencies().stream()
|
|
||||||
.flatMap( x -> modelGetter.apply( x ).getTextures( modelGetter, missingTextureErrors ).stream() )
|
|
||||||
.collect( Collectors.toSet() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public IBakedModel bake( @Nonnull Function<ResourceLocation, IUnbakedModel> modelGetter, @Nonnull Function<ResourceLocation, TextureAtlasSprite> spriteGetter, @Nonnull IModelState state, boolean uvlock, @Nonnull VertexFormat format )
|
|
||||||
{
|
{
|
||||||
return new TurtleSmartItemModel(
|
return new TurtleSmartItemModel(
|
||||||
modelGetter.apply( family ).bake( modelGetter, spriteGetter, state, uvlock, format ),
|
family.bake( state, format, function ),
|
||||||
modelGetter.apply( COLOUR_TURTLE_MODEL ).bake( modelGetter, spriteGetter, state, uvlock, format )
|
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 ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,17 +7,19 @@
|
|||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.renderer.block.model.IBakedModel;
|
||||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||||
|
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
|
||||||
import net.minecraftforge.client.model.data.IModelData;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.vecmath.Matrix4f;
|
import javax.vecmath.Matrix4f;
|
||||||
import java.util.*;
|
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
|
||||||
{
|
{
|
||||||
@@ -45,15 +47,7 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, long rand )
|
||||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, @Nonnull Random rand )
|
|
||||||
{
|
|
||||||
return getQuads( state, side, rand, EmptyModelData.INSTANCE );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, @Nonnull Random rand, @Nonnull IModelData data )
|
|
||||||
{
|
{
|
||||||
if( side != null )
|
if( side != null )
|
||||||
{
|
{
|
||||||
@@ -67,13 +61,17 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BakedQuad> buildQuads( IBlockState state, EnumFacing 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, EmptyModelData.INSTANCE ), m_generalTransform );
|
ModelTransformer.transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand ), m_generalTransform );
|
||||||
if( m_overlayModel != null )
|
if( m_overlayModel != null )
|
||||||
{
|
{
|
||||||
ModelTransformer.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 )
|
||||||
{
|
{
|
||||||
@@ -83,7 +81,7 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
upgradeTransform = new Matrix4f( m_generalTransform );
|
upgradeTransform = new Matrix4f( m_generalTransform );
|
||||||
upgradeTransform.mul( m_leftUpgradeTransform );
|
upgradeTransform.mul( m_leftUpgradeTransform );
|
||||||
}
|
}
|
||||||
ModelTransformer.transformQuadsTo( quads, m_leftUpgradeModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
ModelTransformer.transformQuadsTo( quads, m_leftUpgradeModel.getQuads( state, side, rand ), upgradeTransform );
|
||||||
}
|
}
|
||||||
if( m_rightUpgradeModel != null )
|
if( m_rightUpgradeModel != null )
|
||||||
{
|
{
|
||||||
@@ -93,7 +91,7 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
upgradeTransform = new Matrix4f( m_generalTransform );
|
upgradeTransform = new Matrix4f( m_generalTransform );
|
||||||
upgradeTransform.mul( m_rightUpgradeTransform );
|
upgradeTransform.mul( m_rightUpgradeTransform );
|
||||||
}
|
}
|
||||||
ModelTransformer.transformQuadsTo( quads, m_rightUpgradeModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
ModelTransformer.transformQuadsTo( quads, m_rightUpgradeModel.getQuads( state, side, rand ), upgradeTransform );
|
||||||
}
|
}
|
||||||
quads.trimToSize();
|
quads.trimToSize();
|
||||||
return quads;
|
return quads;
|
||||||
@@ -127,7 +125,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();
|
||||||
}
|
}
|
||||||
@@ -136,6 +134,6 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
@Override
|
@Override
|
||||||
public ItemOverrideList getOverrides()
|
public ItemOverrideList getOverrides()
|
||||||
{
|
{
|
||||||
return ItemOverrideList.EMPTY;
|
return ItemOverrideList.NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,27 +9,26 @@ package dan200.computercraft.client.render;
|
|||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
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.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.renderer.model.*;
|
import net.minecraft.client.renderer.block.model.*;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
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 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 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
|
||||||
{
|
{
|
||||||
@@ -107,13 +106,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 EntityLivingBase 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 );
|
||||||
@@ -139,8 +138,8 @@ 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;
|
||||||
@@ -168,20 +167,11 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, long rand )
|
||||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, @Nonnull Random rand )
|
|
||||||
{
|
{
|
||||||
return familyModel.getQuads( state, facing, rand );
|
return familyModel.getQuads( state, facing, rand );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, @Nonnull Random rand, @Nonnull IModelData data )
|
|
||||||
{
|
|
||||||
return familyModel.getQuads( state, facing, rand, data );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAmbientOcclusion()
|
public boolean isAmbientOcclusion()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,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;
|
||||||
|
|
||||||
@@ -51,11 +50,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<>();
|
||||||
@@ -160,7 +154,7 @@ public class AddressPredicate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether the given address matches a series of patterns
|
* Determine whether the given address matches a series of patterns.
|
||||||
*
|
*
|
||||||
* @param address The address to check.
|
* @param address The address to check.
|
||||||
* @return Whether it matches any of these patterns.
|
* @return Whether it matches any of these patterns.
|
||||||
|
|||||||
@@ -23,7 +23,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 );
|
||||||
|
|||||||
@@ -13,256 +13,106 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various helpers for arguments
|
* A stub for any mods which depended on this version of the argument helper.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link dan200.computercraft.api.lua.ArgumentHelper}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public final class ArgumentHelper
|
public final class ArgumentHelper
|
||||||
{
|
{
|
||||||
private ArgumentHelper()
|
private ArgumentHelper()
|
||||||
{
|
{
|
||||||
throw new IllegalStateException( "Cannot instantiate singleton " + getClass().getName() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String getType( @Nullable Object type )
|
public static String getType( @Nullable Object type )
|
||||||
{
|
{
|
||||||
if( type == null ) return "nil";
|
return dan200.computercraft.api.lua.ArgumentHelper.getType( type );
|
||||||
if( type instanceof String ) return "string";
|
|
||||||
if( type instanceof Boolean ) return "boolean";
|
|
||||||
if( type instanceof Number ) return "number";
|
|
||||||
if( type instanceof Map ) return "table";
|
|
||||||
|
|
||||||
Class<?> klass = type.getClass();
|
|
||||||
if( klass.isArray() )
|
|
||||||
{
|
|
||||||
StringBuilder name = new StringBuilder();
|
|
||||||
while( klass.isArray() )
|
|
||||||
{
|
|
||||||
name.append( "[]" );
|
|
||||||
klass = klass.getComponentType();
|
|
||||||
}
|
|
||||||
name.insert( 0, klass.getName() );
|
|
||||||
return name.toString();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return klass.getName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static LuaException badArgument( int index, @Nonnull String expected, @Nullable Object actual )
|
public static LuaException badArgument( int index, @Nonnull String expected, @Nullable Object actual )
|
||||||
{
|
{
|
||||||
return badArgument( index, expected, getType( actual ) );
|
return dan200.computercraft.api.lua.ArgumentHelper.badArgumentOf( index, expected, actual );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
|
public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
|
||||||
{
|
{
|
||||||
return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
|
return dan200.computercraft.api.lua.ArgumentHelper.badArgument( index, expected, actual );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException
|
public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
return dan200.computercraft.api.lua.ArgumentHelper.getDouble( args, index );
|
||||||
Object value = args[index];
|
|
||||||
if( value instanceof Number )
|
|
||||||
{
|
|
||||||
return ((Number) value).doubleValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "number", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
|
public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return (int) getLong( args, index );
|
return dan200.computercraft.api.lua.ArgumentHelper.getInt( args, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
|
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
return dan200.computercraft.api.lua.ArgumentHelper.getLong( args, index );
|
||||||
Object value = args[index];
|
|
||||||
if( value instanceof Number )
|
|
||||||
{
|
|
||||||
return checkReal( index, (Number) value ).longValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "number", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getReal( @Nonnull Object[] args, int index ) throws LuaException
|
public static double getReal( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return checkReal( index, getNumber( args, index ) );
|
return dan200.computercraft.api.lua.ArgumentHelper.getFiniteDouble( args, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
|
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
|
return dan200.computercraft.api.lua.ArgumentHelper.getBoolean( args, index );
|
||||||
Object value = args[index];
|
|
||||||
if( value instanceof Boolean )
|
|
||||||
{
|
|
||||||
return (Boolean) value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "boolean", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String getString( @Nonnull Object[] args, int index ) throws LuaException
|
public static String getString( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
if( index >= args.length ) throw badArgument( index, "string", "nil" );
|
return dan200.computercraft.api.lua.ArgumentHelper.getString( args, index );
|
||||||
Object value = args[index];
|
|
||||||
if( value instanceof String )
|
|
||||||
{
|
|
||||||
return (String) value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "string", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@SuppressWarnings( "unchecked" )
|
||||||
public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException
|
public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
if( index >= args.length ) throw badArgument( index, "table", "nil" );
|
return (Map<Object, Object>) dan200.computercraft.api.lua.ArgumentHelper.getTable( args, index );
|
||||||
Object value = args[index];
|
|
||||||
if( value instanceof Map )
|
|
||||||
{
|
|
||||||
return (Map<Object, Object>) value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "table", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException
|
public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException
|
||||||
{
|
{
|
||||||
Object value = index < args.length ? args[index] : null;
|
return dan200.computercraft.api.lua.ArgumentHelper.optDouble( args, index, def );
|
||||||
if( value == null )
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
else if( value instanceof Number )
|
|
||||||
{
|
|
||||||
return ((Number) value).doubleValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "number", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
|
public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
|
||||||
{
|
{
|
||||||
return (int) optLong( args, index, def );
|
return dan200.computercraft.api.lua.ArgumentHelper.optInt( args, index, def );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
|
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
|
||||||
{
|
{
|
||||||
Object value = index < args.length ? args[index] : null;
|
return dan200.computercraft.api.lua.ArgumentHelper.optLong( args, index, def );
|
||||||
if( value == null )
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
else if( value instanceof Number )
|
|
||||||
{
|
|
||||||
return checkReal( index, (Number) value ).longValue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "number", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double optReal( @Nonnull Object[] args, int index, double def ) throws LuaException
|
public static double optReal( @Nonnull Object[] args, int index, double def ) throws LuaException
|
||||||
{
|
{
|
||||||
return checkReal( index, optNumber( args, index, def ) );
|
return dan200.computercraft.api.lua.ArgumentHelper.optFiniteDouble( args, index, def );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
|
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
|
||||||
{
|
{
|
||||||
Object value = index < args.length ? args[index] : null;
|
return dan200.computercraft.api.lua.ArgumentHelper.optBoolean( args, index, def );
|
||||||
if( value == null )
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
else if( value instanceof Boolean )
|
|
||||||
{
|
|
||||||
return (Boolean) value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "boolean", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
|
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
|
||||||
{
|
{
|
||||||
Object value = index < args.length ? args[index] : null;
|
return dan200.computercraft.api.lua.ArgumentHelper.optString( args, index, def );
|
||||||
if( value == null )
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
else if( value instanceof String )
|
|
||||||
{
|
|
||||||
return (String) value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "string", value );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
|
public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
|
||||||
{
|
{
|
||||||
Object value = index < args.length ? args[index] : null;
|
return (Map<Object, Object>) dan200.computercraft.api.lua.ArgumentHelper.optTable( args, index, def );
|
||||||
if( value == null )
|
|
||||||
{
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
else if( value instanceof Map )
|
|
||||||
{
|
|
||||||
return (Map<Object, Object>) value;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw badArgument( index, "table", value );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Number checkReal( int index, Number value ) throws LuaException
|
|
||||||
{
|
|
||||||
checkReal( index, value.doubleValue() );
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double checkReal( int index, double value ) throws LuaException
|
|
||||||
{
|
|
||||||
if( Double.isNaN( value ) )
|
|
||||||
{
|
|
||||||
throw badArgument( index, "number", "nan" );
|
|
||||||
}
|
|
||||||
else if( value == Double.POSITIVE_INFINITY )
|
|
||||||
{
|
|
||||||
throw badArgument( index, "number", "inf" );
|
|
||||||
}
|
|
||||||
else if( value == Double.NEGATIVE_INFINITY )
|
|
||||||
{
|
|
||||||
throw badArgument( index, "number", "-inf" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
|
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
|
||||||
|
|
||||||
public class FSAPI implements ILuaAPI
|
public class FSAPI implements ILuaAPI
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
import static dan200.computercraft.api.lua.ArgumentHelper.*;
|
||||||
import static dan200.computercraft.core.apis.TableHelper.*;
|
import static dan200.computercraft.core.apis.TableHelper.*;
|
||||||
|
|
||||||
public class HTTPAPI implements ILuaAPI
|
public class HTTPAPI implements ILuaAPI
|
||||||
@@ -89,7 +89,7 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
case 0: // request
|
case 0: // request
|
||||||
{
|
{
|
||||||
String address, postString, requestMethod;
|
String address, postString, requestMethod;
|
||||||
Map<Object, Object> headerTable;
|
Map<?, ?> headerTable;
|
||||||
boolean binary, redirect;
|
boolean binary, redirect;
|
||||||
|
|
||||||
if( args.length >= 1 && args[0] instanceof Map )
|
if( args.length >= 1 && args[0] instanceof Map )
|
||||||
@@ -172,7 +172,7 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
case 2: // websocket
|
case 2: // websocket
|
||||||
{
|
{
|
||||||
String address = getString( args, 0 );
|
String address = getString( args, 0 );
|
||||||
Map<Object, Object> headerTbl = optTable( args, 1, Collections.emptyMap() );
|
Map<?, ?> headerTbl = optTable( args, 1, Collections.emptyMap() );
|
||||||
|
|
||||||
if( !ComputerCraft.http_websocket_enable )
|
if( !ComputerCraft.http_websocket_enable )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import java.time.ZonedDateTime;
|
|||||||
import java.time.format.DateTimeFormatterBuilder;
|
import java.time.format.DateTimeFormatterBuilder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
import static dan200.computercraft.api.lua.ArgumentHelper.*;
|
||||||
|
|
||||||
public class OSAPI implements ILuaAPI
|
public class OSAPI implements ILuaAPI
|
||||||
{
|
{
|
||||||
@@ -229,7 +229,7 @@ public class OSAPI implements ILuaAPI
|
|||||||
case 1:
|
case 1:
|
||||||
{
|
{
|
||||||
// startTimer
|
// startTimer
|
||||||
double timer = getReal( args, 0 );
|
double timer = getFiniteDouble( args, 0 );
|
||||||
synchronized( m_timers )
|
synchronized( m_timers )
|
||||||
{
|
{
|
||||||
m_timers.put( m_nextTimerToken, new Timer( (int) Math.round( timer / 0.05 ) ) );
|
m_timers.put( m_nextTimerToken, new Timer( (int) Math.round( timer / 0.05 ) ) );
|
||||||
@@ -239,7 +239,7 @@ public class OSAPI implements ILuaAPI
|
|||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
// setAlarm
|
// setAlarm
|
||||||
double time = getReal( args, 0 );
|
double time = getFiniteDouble( args, 0 );
|
||||||
if( time < 0.0 || time >= 24.0 )
|
if( time < 0.0 || time >= 24.0 )
|
||||||
{
|
{
|
||||||
throw new LuaException( "Number out of range" );
|
throw new LuaException( "Number out of range" );
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
|
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
|
||||||
|
|
||||||
public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChangeListener
|
public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChangeListener
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import javax.annotation.Nonnull;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
import static dan200.computercraft.api.lua.ArgumentHelper.*;
|
||||||
|
|
||||||
public class RedstoneAPI implements ILuaAPI
|
public class RedstoneAPI implements ILuaAPI
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,14 +6,17 @@
|
|||||||
|
|
||||||
package dan200.computercraft.core.apis;
|
package dan200.computercraft.core.apis;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.lua.ArgumentHelper;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static dan200.computercraft.api.lua.ArgumentHelper.getNumericType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Various helpers for tables
|
* Various helpers for tables.
|
||||||
*/
|
*/
|
||||||
public final class TableHelper
|
public final class TableHelper
|
||||||
{
|
{
|
||||||
@@ -200,21 +203,7 @@ public final class TableHelper
|
|||||||
|
|
||||||
private static double checkReal( @Nonnull String key, double value ) throws LuaException
|
private static double checkReal( @Nonnull String key, double value ) throws LuaException
|
||||||
{
|
{
|
||||||
if( Double.isNaN( value ) )
|
if( !Double.isFinite( value ) ) throw badKey( key, "number", getNumericType( value ) );
|
||||||
{
|
return value;
|
||||||
throw badKey( key, "number", "nan" );
|
|
||||||
}
|
|
||||||
else if( value == Double.POSITIVE_INFINITY )
|
|
||||||
{
|
|
||||||
throw badKey( key, "number", "inf" );
|
|
||||||
}
|
|
||||||
else if( value == Double.NEGATIVE_INFINITY )
|
|
||||||
{
|
|
||||||
throw badKey( key, "number", "-inf" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import org.apache.commons.lang3.ArrayUtils;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
import static dan200.computercraft.api.lua.ArgumentHelper.*;
|
||||||
|
|
||||||
public class TermAPI implements ILuaAPI
|
public class TermAPI implements ILuaAPI
|
||||||
{
|
{
|
||||||
@@ -242,9 +242,9 @@ public class TermAPI implements ILuaAPI
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
double r = getReal( args, 1 );
|
double r = getFiniteDouble( args, 1 );
|
||||||
double g = getReal( args, 2 );
|
double g = getFiniteDouble( args, 2 );
|
||||||
double b = getReal( args, 3 );
|
double b = getFiniteDouble( args, 3 );
|
||||||
setColour( m_terminal, colour, r, g, b );
|
setColour( m_terminal, colour, r, g, b );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.getInt;
|
import static dan200.computercraft.api.lua.ArgumentHelper.getInt;
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
|
import static dan200.computercraft.api.lua.ArgumentHelper.optBoolean;
|
||||||
|
|
||||||
public class BinaryReadableHandle extends HandleGeneric
|
public class BinaryReadableHandle extends HandleGeneric
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
package dan200.computercraft.core.apis.handles;
|
package dan200.computercraft.core.apis.handles;
|
||||||
|
|
||||||
import com.google.common.collect.ObjectArrays;
|
import com.google.common.collect.ObjectArrays;
|
||||||
|
import dan200.computercraft.api.lua.ArgumentHelper;
|
||||||
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.core.apis.ArgumentHelper;
|
|
||||||
import dan200.computercraft.shared.util.StringUtil;
|
import dan200.computercraft.shared.util.StringUtil;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -73,7 +73,7 @@ public class BinaryWritableHandle extends HandleGeneric
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw ArgumentHelper.badArgument( 0, "string or number", args.length > 0 ? args[0] : null );
|
throw ArgumentHelper.badArgumentOf( 0, "string or number", args.length > 0 ? args[0] : null );
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ import java.nio.charset.CharsetDecoder;
|
|||||||
import java.nio.charset.CodingErrorAction;
|
import java.nio.charset.CodingErrorAction;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
|
import static dan200.computercraft.api.lua.ArgumentHelper.optBoolean;
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.optInt;
|
import static dan200.computercraft.api.lua.ArgumentHelper.optInt;
|
||||||
|
|
||||||
public class EncodedReadableHandle extends HandleGeneric
|
public class EncodedReadableHandle extends HandleGeneric
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import java.io.IOException;
|
|||||||
import java.nio.channels.Channel;
|
import java.nio.channels.Channel;
|
||||||
import java.nio.channels.SeekableByteChannel;
|
import java.nio.channels.SeekableByteChannel;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.optLong;
|
import static dan200.computercraft.api.lua.ArgumentHelper.optLong;
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.optString;
|
import static dan200.computercraft.api.lua.ArgumentHelper.optString;
|
||||||
|
|
||||||
public abstract class HandleGeneric implements ILuaObject
|
public abstract class HandleGeneric implements ILuaObject
|
||||||
{
|
{
|
||||||
@@ -47,7 +47,7 @@ public abstract class HandleGeneric implements ILuaObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shared implementation for various file handle types
|
* Shared implementation for various file handle types.
|
||||||
*
|
*
|
||||||
* @param channel The channel to seek in
|
* @param channel The channel to seek in
|
||||||
* @param args The Lua arguments to process, like Lua's {@code file:seek}.
|
* @param args The Lua arguments to process, like Lua's {@code file:seek}.
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public final class NetworkUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks a host is allowed
|
* Checks a host is allowed.
|
||||||
*
|
*
|
||||||
* @param host The domain to check against
|
* @param host The domain to check against
|
||||||
* @throws HTTPRequestException If the host is not permitted.
|
* @throws HTTPRequestException If the host is not permitted.
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A holder for one or more resources, with a lifetime.
|
* A holder for one or more resources, with a lifetime.
|
||||||
|
*
|
||||||
|
* @param <T> The type of this resource. Should be the class extending from {@link Resource}.
|
||||||
*/
|
*/
|
||||||
public abstract class Resource<T extends Resource<T>> implements Closeable
|
public abstract class Resource<T extends Resource<T>> implements Closeable
|
||||||
{
|
{
|
||||||
@@ -42,8 +44,9 @@ public abstract class Resource<T extends Resource<T>> implements Closeable
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this has been cancelled. If so, it'll clean up any
|
* Checks if this has been cancelled. If so, it'll clean up any existing resources and cancel any pending futures.
|
||||||
* existing resources and cancel any pending futures.
|
*
|
||||||
|
* @return Whether this resource has been closed.
|
||||||
*/
|
*/
|
||||||
public final boolean checkClosed()
|
public final boolean checkClosed()
|
||||||
{
|
{
|
||||||
@@ -80,6 +83,7 @@ public abstract class Resource<T extends Resource<T>> implements Closeable
|
|||||||
/**
|
/**
|
||||||
* Create a {@link WeakReference} which will close {@code this} when collected.
|
* Create a {@link WeakReference} which will close {@code this} when collected.
|
||||||
*
|
*
|
||||||
|
* @param <R> The object we are wrapping in a reference.
|
||||||
* @param object The object to reference to
|
* @param object The object to reference to
|
||||||
* @return The weak reference.
|
* @return The weak reference.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection of {@link Resource}s, with an upper bound on capacity.
|
* A collection of {@link Resource}s, with an upper bound on capacity.
|
||||||
|
*
|
||||||
|
* @param <T> The type of the resource this group manages.
|
||||||
*/
|
*/
|
||||||
public class ResourceGroup<T extends Resource<T>>
|
public class ResourceGroup<T extends Resource<T>>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import java.util.function.Supplier;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ResourceGroup} which will queue items when the group at capacity.
|
* A {@link ResourceGroup} which will queue items when the group at capacity.
|
||||||
|
*
|
||||||
|
* @param <T> The type of the resource this queue manages.
|
||||||
*/
|
*/
|
||||||
public class ResourceQueue<T extends Resource<T>> extends ResourceGroup<T>
|
public class ResourceQueue<T extends Resource<T>> extends ResourceGroup<T>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents one or more
|
* Represents an in-progress HTTP request.
|
||||||
*/
|
*/
|
||||||
public class HttpRequest extends Resource<HttpRequest>
|
public class HttpRequest extends Resource<HttpRequest>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -226,7 +226,11 @@ public final class HttpRequestHandler extends SimpleChannelInboundHandler<HttpOb
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the redirect from this response
|
* Determine the redirect from this response.
|
||||||
|
*
|
||||||
|
* @param status The status of the HTTP response.
|
||||||
|
* @param headers The headers of the HTTP response.
|
||||||
|
* @return The URI to redirect to, or {@code null} if no redirect should occur.
|
||||||
*/
|
*/
|
||||||
private URI getRedirect( HttpResponseStatus status, HttpHeaders headers )
|
private URI getRedirect( HttpResponseStatus status, HttpHeaders headers )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import javax.annotation.Nullable;
|
|||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
|
import static dan200.computercraft.api.lua.ArgumentHelper.optBoolean;
|
||||||
import static dan200.computercraft.core.apis.http.websocket.Websocket.CLOSE_EVENT;
|
import static dan200.computercraft.core.apis.http.websocket.Websocket.CLOSE_EVENT;
|
||||||
import static dan200.computercraft.core.apis.http.websocket.Websocket.MESSAGE_EVENT;
|
import static dan200.computercraft.core.apis.http.websocket.Websocket.MESSAGE_EVENT;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
package dan200.computercraft.core.computer;
|
package dan200.computercraft.core.computer;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
import dan200.computercraft.api.lua.ILuaAPI;
|
import dan200.computercraft.api.lua.ILuaAPI;
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
||||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||||
import dan200.computercraft.core.filesystem.FileSystem;
|
import dan200.computercraft.core.filesystem.FileSystem;
|
||||||
@@ -217,4 +219,37 @@ public class Computer
|
|||||||
{
|
{
|
||||||
executor.addApi( api );
|
executor.addApi( api );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public IPeripheral getPeripheral( int side )
|
||||||
|
{
|
||||||
|
return internalEnvironment.getPeripheral( ComputerSide.valueOf( side ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void setPeripheral( int side, IPeripheral peripheral )
|
||||||
|
{
|
||||||
|
internalEnvironment.setPeripheral( ComputerSide.valueOf( side ), peripheral );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void addAPI( dan200.computercraft.core.apis.ILuaAPI api )
|
||||||
|
{
|
||||||
|
addApi( api );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public void advance( double dt )
|
||||||
|
{
|
||||||
|
tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public IWritableMount getRootMount()
|
||||||
|
{
|
||||||
|
return executor.getRootMount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static final String[] s_sideNames = ComputerSide.NAMES;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ final class ComputerExecutor
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue an event if the computer is on
|
* Queue an event if the computer is on.
|
||||||
*
|
*
|
||||||
* @param event The event's name
|
* @param event The event's name
|
||||||
* @param args The event's arguments
|
* @param args The event's arguments
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ import static dan200.computercraft.core.computer.TimeoutState.TIMEOUT;
|
|||||||
public final class ComputerThread
|
public final class ComputerThread
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* How often the computer thread monitor should run, in milliseconds
|
* How often the computer thread monitor should run, in milliseconds.
|
||||||
*
|
*
|
||||||
* @see Monitor
|
* @see Monitor
|
||||||
*/
|
*/
|
||||||
@@ -83,7 +83,7 @@ public final class ComputerThread
|
|||||||
private static final Object threadLock = new Object();
|
private static final Object threadLock = new Object();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the computer thread system is currently running
|
* Whether the computer thread system is currently running.
|
||||||
*/
|
*/
|
||||||
private static volatile boolean running = false;
|
private static volatile boolean running = false;
|
||||||
|
|
||||||
@@ -105,7 +105,7 @@ public final class ComputerThread
|
|||||||
private static final Condition hasWork = computerLock.newCondition();
|
private static final Condition hasWork = computerLock.newCondition();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Active queues to execute
|
* Active queues to execute.
|
||||||
*/
|
*/
|
||||||
private static final TreeSet<ComputerExecutor> computerQueue = new TreeSet<>( ( a, b ) -> {
|
private static final TreeSet<ComputerExecutor> computerQueue = new TreeSet<>( ( a, b ) -> {
|
||||||
if( a == b ) return 0; // Should never happen, but let's be consistent here
|
if( a == b ) return 0; // Should never happen, but let's be consistent here
|
||||||
@@ -126,7 +126,7 @@ public final class ComputerThread
|
|||||||
private ComputerThread() {}
|
private ComputerThread() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the computer thread
|
* Start the computer thread.
|
||||||
*/
|
*/
|
||||||
static void start()
|
static void start()
|
||||||
{
|
{
|
||||||
@@ -194,7 +194,7 @@ public final class ComputerThread
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark a computer as having work, enqueuing it on the thread
|
* Mark a computer as having work, enqueuing it on the thread.
|
||||||
*
|
*
|
||||||
* You must be holding {@link ComputerExecutor}'s {@code queueLock} when calling this method - it should only
|
* You must be holding {@link ComputerExecutor}'s {@code queueLock} when calling this method - it should only
|
||||||
* be called from {@code enqueue}.
|
* be called from {@code enqueue}.
|
||||||
@@ -244,6 +244,8 @@ public final class ComputerThread
|
|||||||
* {@link #minimumVirtualRuntime} based on the current tasks.
|
* {@link #minimumVirtualRuntime} based on the current tasks.
|
||||||
*
|
*
|
||||||
* This is called before queueing tasks, to ensure that {@link #minimumVirtualRuntime} is up-to-date.
|
* This is called before queueing tasks, to ensure that {@link #minimumVirtualRuntime} is up-to-date.
|
||||||
|
*
|
||||||
|
* @param current The machine which we updating runtimes from.
|
||||||
*/
|
*/
|
||||||
private static void updateRuntimes( @Nullable ComputerExecutor current )
|
private static void updateRuntimes( @Nullable ComputerExecutor current )
|
||||||
{
|
{
|
||||||
@@ -321,7 +323,7 @@ public final class ComputerThread
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The scaled period for a single task
|
* The scaled period for a single task.
|
||||||
*
|
*
|
||||||
* @return The scaled period for the task
|
* @return The scaled period for the task
|
||||||
* @see #DEFAULT_LATENCY
|
* @see #DEFAULT_LATENCY
|
||||||
@@ -336,7 +338,7 @@ public final class ComputerThread
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the thread has computers queued up
|
* Determine if the thread has computers queued up.
|
||||||
*
|
*
|
||||||
* @return If we have work queued up.
|
* @return If we have work queued up.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -36,12 +36,12 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public final class TimeoutState
|
public final class TimeoutState
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The total time a task is allowed to run before aborting in nanoseconds
|
* The total time a task is allowed to run before aborting in nanoseconds.
|
||||||
*/
|
*/
|
||||||
static final long TIMEOUT = TimeUnit.MILLISECONDS.toNanos( 7000 );
|
static final long TIMEOUT = TimeUnit.MILLISECONDS.toNanos( 7000 );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The time the task is allowed to run after each abort in nanoseconds
|
* The time the task is allowed to run after each abort in nanoseconds.
|
||||||
*/
|
*/
|
||||||
static final long ABORT_TIMEOUT = TimeUnit.MILLISECONDS.toNanos( 1500 );
|
static final long ABORT_TIMEOUT = TimeUnit.MILLISECONDS.toNanos( 1500 );
|
||||||
|
|
||||||
@@ -111,6 +111,8 @@ public final class TimeoutState
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If the machine should be passively aborted.
|
* If the machine should be passively aborted.
|
||||||
|
*
|
||||||
|
* @return {@code true} if we should throw a timeout error.
|
||||||
*/
|
*/
|
||||||
public boolean isSoftAborted()
|
public boolean isSoftAborted()
|
||||||
{
|
{
|
||||||
@@ -118,7 +120,9 @@ public final class TimeoutState
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the machine should be forcibly aborted.
|
* Determine if the machine should be forcibly aborted.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the machine should be forcibly shut down.
|
||||||
*/
|
*/
|
||||||
public boolean isHardAborted()
|
public boolean isHardAborted()
|
||||||
{
|
{
|
||||||
@@ -146,7 +150,7 @@ public final class TimeoutState
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pauses the cumulative time, to be resumed by {@link #startTimer()}
|
* Pauses the cumulative time, to be resumed by {@link #startTimer()}.
|
||||||
*
|
*
|
||||||
* @see #nanoCumulative()
|
* @see #nanoCumulative()
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,274 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dan200.computercraft.core.filesystem;
|
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
|
||||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
|
||||||
import net.minecraft.resources.IReloadableResourceManager;
|
|
||||||
import net.minecraft.resources.IResource;
|
|
||||||
import net.minecraft.resources.IResourceManager;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.resource.IResourceType;
|
|
||||||
import net.minecraftforge.resource.ISelectiveResourceReloadListener;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.channels.Channels;
|
|
||||||
import java.nio.channels.ReadableByteChannel;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class ResourceMount implements IMount
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Only cache files smaller than 1MiB.
|
|
||||||
*/
|
|
||||||
private static final int MAX_CACHED_SIZE = 1 << 20;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Limit the entire cache to 64MiB.
|
|
||||||
*/
|
|
||||||
private static final int MAX_CACHE_SIZE = 64 << 20;
|
|
||||||
|
|
||||||
private static final byte[] TEMP_BUFFER = new byte[8192];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* We maintain a cache of the contents of all files in the mount. This allows us to allow
|
|
||||||
* seeking within ROM files, and reduces the amount we need to access disk for computer startup.
|
|
||||||
*/
|
|
||||||
private static final Cache<FileEntry, byte[]> CONTENTS_CACHE = CacheBuilder.newBuilder()
|
|
||||||
.concurrencyLevel( 4 )
|
|
||||||
.expireAfterAccess( 60, TimeUnit.SECONDS )
|
|
||||||
.maximumWeight( MAX_CACHE_SIZE )
|
|
||||||
.weakKeys()
|
|
||||||
.<FileEntry, byte[]>weigher( ( k, v ) -> v.length )
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final String namespace;
|
|
||||||
private final String subPath;
|
|
||||||
private final IReloadableResourceManager manager;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private FileEntry root;
|
|
||||||
|
|
||||||
public ResourceMount( String namespace, String subPath, IReloadableResourceManager manager )
|
|
||||||
{
|
|
||||||
this.namespace = namespace;
|
|
||||||
this.subPath = subPath;
|
|
||||||
this.manager = manager;
|
|
||||||
|
|
||||||
Listener.INSTANCE.add( manager, this );
|
|
||||||
if( root == null ) load();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
boolean hasAny = false;
|
|
||||||
FileEntry newRoot = new FileEntry( new ResourceLocation( namespace, subPath ) );
|
|
||||||
for( ResourceLocation file : manager.getAllResourceLocations( subPath, s -> true ) )
|
|
||||||
{
|
|
||||||
if( !file.getNamespace().equals( namespace ) ) continue;
|
|
||||||
|
|
||||||
String localPath = FileSystem.toLocal( file.getPath(), subPath );
|
|
||||||
create( newRoot, localPath );
|
|
||||||
hasAny = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
root = hasAny ? newRoot : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileEntry get( String path )
|
|
||||||
{
|
|
||||||
FileEntry lastEntry = root;
|
|
||||||
int lastIndex = 0;
|
|
||||||
|
|
||||||
while( lastEntry != null && lastIndex < path.length() )
|
|
||||||
{
|
|
||||||
int nextIndex = path.indexOf( '/', lastIndex );
|
|
||||||
if( nextIndex < 0 ) nextIndex = path.length();
|
|
||||||
|
|
||||||
lastEntry = lastEntry.children == null ? null : lastEntry.children.get( path.substring( lastIndex, nextIndex ) );
|
|
||||||
lastIndex = nextIndex + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void create( FileEntry lastEntry, String path )
|
|
||||||
{
|
|
||||||
int lastIndex = 0;
|
|
||||||
while( lastIndex < path.length() )
|
|
||||||
{
|
|
||||||
int nextIndex = path.indexOf( '/', lastIndex );
|
|
||||||
if( nextIndex < 0 ) nextIndex = path.length();
|
|
||||||
|
|
||||||
String part = path.substring( lastIndex, nextIndex );
|
|
||||||
if( lastEntry.children == null ) lastEntry.children = new HashMap<>();
|
|
||||||
|
|
||||||
FileEntry nextEntry = lastEntry.children.get( part );
|
|
||||||
if( nextEntry == null )
|
|
||||||
{
|
|
||||||
lastEntry.children.put( part, nextEntry = new FileEntry( new ResourceLocation( namespace, subPath + "/" + path ) ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
lastEntry = nextEntry;
|
|
||||||
lastIndex = nextIndex + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean exists( @Nonnull String path )
|
|
||||||
{
|
|
||||||
return get( path ) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDirectory( @Nonnull String path )
|
|
||||||
{
|
|
||||||
FileEntry file = get( path );
|
|
||||||
return file != null && file.isDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException
|
|
||||||
{
|
|
||||||
FileEntry file = get( path );
|
|
||||||
if( file == null || !file.isDirectory() ) throw new IOException( "/" + path + ": Not a directory" );
|
|
||||||
|
|
||||||
file.list( contents );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getSize( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
FileEntry file = get( path );
|
|
||||||
if( file != null )
|
|
||||||
{
|
|
||||||
if( file.size != -1 ) return file.size;
|
|
||||||
if( file.isDirectory() ) return file.size = 0;
|
|
||||||
|
|
||||||
byte[] contents = CONTENTS_CACHE.getIfPresent( file );
|
|
||||||
if( contents != null ) return file.size = contents.length;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IResource resource = manager.getResource( file.identifier );
|
|
||||||
InputStream s = resource.getInputStream();
|
|
||||||
int total = 0, read = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
total += read;
|
|
||||||
read = s.read( TEMP_BUFFER );
|
|
||||||
} while ( read > 0 );
|
|
||||||
|
|
||||||
return file.size = total;
|
|
||||||
}
|
|
||||||
catch( IOException e )
|
|
||||||
{
|
|
||||||
return file.size = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IOException( "/" + path + ": No such file" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
return Channels.newInputStream( openChannelForRead( path ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
|
||||||
{
|
|
||||||
FileEntry file = get( path );
|
|
||||||
if( file != null && !file.isDirectory() )
|
|
||||||
{
|
|
||||||
byte[] contents = CONTENTS_CACHE.getIfPresent( file );
|
|
||||||
if( contents != null ) return new ArrayByteChannel( contents );
|
|
||||||
|
|
||||||
try( InputStream stream = manager.getResource( file.identifier ).getInputStream() )
|
|
||||||
{
|
|
||||||
if( stream.available() > MAX_CACHED_SIZE ) return Channels.newChannel( stream );
|
|
||||||
|
|
||||||
contents = ByteStreams.toByteArray( stream );
|
|
||||||
CONTENTS_CACHE.put( file, contents );
|
|
||||||
return new ArrayByteChannel( contents );
|
|
||||||
}
|
|
||||||
catch( FileNotFoundException ignored )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new IOException( "/" + path + ": No such file" );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class FileEntry
|
|
||||||
{
|
|
||||||
final ResourceLocation identifier;
|
|
||||||
Map<String, FileEntry> children;
|
|
||||||
long size = -1;
|
|
||||||
|
|
||||||
FileEntry( ResourceLocation identifier )
|
|
||||||
{
|
|
||||||
this.identifier = identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isDirectory()
|
|
||||||
{
|
|
||||||
return children != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
void list( List<String> contents )
|
|
||||||
{
|
|
||||||
if( children != null ) contents.addAll( children.keySet() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link ISelectiveResourceReloadListener} which reloads any associated mounts.
|
|
||||||
*
|
|
||||||
* While people should really be keeping a permanent reference to this, some people construct it every
|
|
||||||
* method call, so let's make this as small as possible.
|
|
||||||
*/
|
|
||||||
static class Listener implements ISelectiveResourceReloadListener
|
|
||||||
{
|
|
||||||
private static final Listener INSTANCE = new Listener();
|
|
||||||
|
|
||||||
private final Set<ResourceMount> mounts = Collections.newSetFromMap( new WeakHashMap<>() );
|
|
||||||
private final Set<IReloadableResourceManager> managers = Collections.newSetFromMap( new WeakHashMap<>() );
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResourceManagerReload( @Nonnull IResourceManager manager )
|
|
||||||
{
|
|
||||||
// FIXME: Remove this. We need this patch in order to prevent trying to load ReloadRequirements.
|
|
||||||
onResourceManagerReload( manager, x -> true );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onResourceManagerReload( @Nonnull IResourceManager manager, @Nonnull Predicate<IResourceType> predicate )
|
|
||||||
{
|
|
||||||
for( ResourceMount mount : mounts ) mount.load();
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized void add( IReloadableResourceManager manager, ResourceMount mount )
|
|
||||||
{
|
|
||||||
if( managers.add( manager ) ) manager.addReloadListener( this );
|
|
||||||
mounts.add( mount );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -38,7 +38,7 @@ public final class MachineResult
|
|||||||
public static final MachineResult TIMEOUT = new MachineResult( true, false, TimeoutState.ABORT_MESSAGE );
|
public static final MachineResult TIMEOUT = new MachineResult( true, false, TimeoutState.ABORT_MESSAGE );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An error with no user-friendly error message
|
* An error with no user-friendly error message.
|
||||||
*/
|
*/
|
||||||
public static final MachineResult GENERIC_ERROR = new MachineResult( true, false, null );
|
public static final MachineResult GENERIC_ERROR = new MachineResult( true, false, null );
|
||||||
|
|
||||||
|
|||||||
@@ -314,6 +314,9 @@ public class Terminal
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Determine whether this terminal has changed.
|
||||||
|
*
|
||||||
|
* @return If this terminal is dirty.
|
||||||
* @deprecated All {@code *Changed()} methods are deprecated: one should pass in a callback
|
* @deprecated All {@code *Changed()} methods are deprecated: one should pass in a callback
|
||||||
* instead.
|
* instead.
|
||||||
*/
|
*/
|
||||||
@@ -336,16 +339,16 @@ public class Terminal
|
|||||||
|
|
||||||
public synchronized NBTTagCompound writeToNBT( NBTTagCompound nbt )
|
public synchronized NBTTagCompound writeToNBT( NBTTagCompound nbt )
|
||||||
{
|
{
|
||||||
nbt.putInt( "term_cursorX", m_cursorX );
|
nbt.setInteger( "term_cursorX", m_cursorX );
|
||||||
nbt.putInt( "term_cursorY", m_cursorY );
|
nbt.setInteger( "term_cursorY", m_cursorY );
|
||||||
nbt.putBoolean( "term_cursorBlink", m_cursorBlink );
|
nbt.setBoolean( "term_cursorBlink", m_cursorBlink );
|
||||||
nbt.putInt( "term_textColour", m_cursorColour );
|
nbt.setInteger( "term_textColour", m_cursorColour );
|
||||||
nbt.putInt( "term_bgColour", m_cursorBackgroundColour );
|
nbt.setInteger( "term_bgColour", m_cursorBackgroundColour );
|
||||||
for( int n = 0; n < m_height; n++ )
|
for( int n = 0; n < m_height; n++ )
|
||||||
{
|
{
|
||||||
nbt.putString( "term_text_" + n, m_text[n].toString() );
|
nbt.setString( "term_text_" + n, m_text[n].toString() );
|
||||||
nbt.putString( "term_textColour_" + n, m_textColour[n].toString() );
|
nbt.setString( "term_textColour_" + n, m_textColour[n].toString() );
|
||||||
nbt.putString( "term_textBgColour_" + n, m_backgroundColour[n].toString() );
|
nbt.setString( "term_textBgColour_" + n, m_backgroundColour[n].toString() );
|
||||||
}
|
}
|
||||||
if( m_palette != null )
|
if( m_palette != null )
|
||||||
{
|
{
|
||||||
@@ -356,26 +359,26 @@ public class Terminal
|
|||||||
|
|
||||||
public synchronized void readFromNBT( NBTTagCompound nbt )
|
public synchronized void readFromNBT( NBTTagCompound nbt )
|
||||||
{
|
{
|
||||||
m_cursorX = nbt.getInt( "term_cursorX" );
|
m_cursorX = nbt.getInteger( "term_cursorX" );
|
||||||
m_cursorY = nbt.getInt( "term_cursorY" );
|
m_cursorY = nbt.getInteger( "term_cursorY" );
|
||||||
m_cursorBlink = nbt.getBoolean( "term_cursorBlink" );
|
m_cursorBlink = nbt.getBoolean( "term_cursorBlink" );
|
||||||
m_cursorColour = nbt.getInt( "term_textColour" );
|
m_cursorColour = nbt.getInteger( "term_textColour" );
|
||||||
m_cursorBackgroundColour = nbt.getInt( "term_bgColour" );
|
m_cursorBackgroundColour = nbt.getInteger( "term_bgColour" );
|
||||||
|
|
||||||
for( int n = 0; n < m_height; n++ )
|
for( int n = 0; n < m_height; n++ )
|
||||||
{
|
{
|
||||||
m_text[n].fill( ' ' );
|
m_text[n].fill( ' ' );
|
||||||
if( nbt.contains( "term_text_" + n ) )
|
if( nbt.hasKey( "term_text_" + n ) )
|
||||||
{
|
{
|
||||||
m_text[n].write( nbt.getString( "term_text_" + n ) );
|
m_text[n].write( nbt.getString( "term_text_" + n ) );
|
||||||
}
|
}
|
||||||
m_textColour[n].fill( base16.charAt( m_cursorColour ) );
|
m_textColour[n].fill( base16.charAt( m_cursorColour ) );
|
||||||
if( nbt.contains( "term_textColour_" + n ) )
|
if( nbt.hasKey( "term_textColour_" + n ) )
|
||||||
{
|
{
|
||||||
m_textColour[n].write( nbt.getString( "term_textColour_" + n ) );
|
m_textColour[n].write( nbt.getString( "term_textColour_" + n ) );
|
||||||
}
|
}
|
||||||
m_backgroundColour[n].fill( base16.charAt( m_cursorBackgroundColour ) );
|
m_backgroundColour[n].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||||
if( nbt.contains( "term_textBgColour_" + n ) )
|
if( nbt.hasKey( "term_textBgColour_" + n ) )
|
||||||
{
|
{
|
||||||
m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ import dan200.computercraft.core.computer.Computer;
|
|||||||
|
|
||||||
public interface Tracker
|
public interface Tracker
|
||||||
{
|
{
|
||||||
|
@Deprecated
|
||||||
|
default void addTiming( Computer computer, long time )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report how long a task executed on the computer thread took.
|
* Report how long a task executed on the computer thread took.
|
||||||
*
|
*
|
||||||
@@ -20,6 +25,8 @@ public interface Tracker
|
|||||||
*/
|
*/
|
||||||
default void addTaskTiming( Computer computer, long time )
|
default void addTaskTiming( Computer computer, long time )
|
||||||
{
|
{
|
||||||
|
//noinspection deprecation
|
||||||
|
addTiming( computer, time );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
package dan200.computercraft.core.tracking;
|
package dan200.computercraft.core.tracking;
|
||||||
|
|
||||||
|
import dan200.computercraft.shared.util.StringUtil;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -13,29 +15,31 @@ import java.util.function.LongFunction;
|
|||||||
|
|
||||||
public final class TrackingField
|
public final class TrackingField
|
||||||
{
|
{
|
||||||
|
public static final String TRANSLATE_PREFIX = "tracking_field.computercraft.";
|
||||||
|
|
||||||
private static final Map<String, TrackingField> fields = new HashMap<>();
|
private static final Map<String, TrackingField> fields = new HashMap<>();
|
||||||
|
|
||||||
public static final TrackingField TASKS = TrackingField.of( "tasks", x -> String.format( "%4d", x ) );
|
public static final TrackingField TASKS = TrackingField.of( "tasks", "Tasks", x -> String.format( "%4d", x ) );
|
||||||
public static final TrackingField TOTAL_TIME = TrackingField.of( "total", x -> String.format( "%7.1fms", x / 1e6 ) );
|
public static final TrackingField TOTAL_TIME = TrackingField.of( "total", "Total time", x -> String.format( "%7.1fms", x / 1e6 ) );
|
||||||
public static final TrackingField AVERAGE_TIME = TrackingField.of( "average", x -> String.format( "%4.1fms", x / 1e6 ) );
|
public static final TrackingField AVERAGE_TIME = TrackingField.of( "average", "Average time", x -> String.format( "%4.1fms", x / 1e6 ) );
|
||||||
public static final TrackingField MAX_TIME = TrackingField.of( "max", x -> String.format( "%5.1fms", x / 1e6 ) );
|
public static final TrackingField MAX_TIME = TrackingField.of( "max", "Max time", x -> String.format( "%5.1fms", x / 1e6 ) );
|
||||||
|
|
||||||
public static final TrackingField SERVER_COUNT = TrackingField.of( "server_count", x -> String.format( "%4d", x ) );
|
public static final TrackingField SERVER_COUNT = TrackingField.of( "server_count", "Server task count", x -> String.format( "%4d", x ) );
|
||||||
public static final TrackingField SERVER_TIME = TrackingField.of( "server_time", x -> String.format( "%7.1fms", x / 1e6 ) );
|
public static final TrackingField SERVER_TIME = TrackingField.of( "server_time", "Server task time", x -> String.format( "%7.1fms", x / 1e6 ) );
|
||||||
|
|
||||||
public static final TrackingField PERIPHERAL_OPS = TrackingField.of( "peripheral", TrackingField::formatDefault );
|
public static final TrackingField PERIPHERAL_OPS = TrackingField.of( "peripheral", "Peripheral calls", TrackingField::formatDefault );
|
||||||
public static final TrackingField FS_OPS = TrackingField.of( "fs", TrackingField::formatDefault );
|
public static final TrackingField FS_OPS = TrackingField.of( "fs", "Filesystem operations", TrackingField::formatDefault );
|
||||||
public static final TrackingField TURTLE_OPS = TrackingField.of( "turtle", TrackingField::formatDefault );
|
public static final TrackingField TURTLE_OPS = TrackingField.of( "turtle", "Turtle operations", TrackingField::formatDefault );
|
||||||
|
|
||||||
public static final TrackingField HTTP_REQUESTS = TrackingField.of( "http", TrackingField::formatDefault );
|
public static final TrackingField HTTP_REQUESTS = TrackingField.of( "http", "HTTP requests", TrackingField::formatDefault );
|
||||||
public static final TrackingField HTTP_UPLOAD = TrackingField.of( "http_upload", TrackingField::formatBytes );
|
public static final TrackingField HTTP_UPLOAD = TrackingField.of( "http_upload", "HTTP upload", TrackingField::formatBytes );
|
||||||
public static final TrackingField HTTP_DOWNLOAD = TrackingField.of( "http_download", TrackingField::formatBytes );
|
public static final TrackingField HTTP_DOWNLOAD = TrackingField.of( "http_download", "HTTP download", TrackingField::formatBytes );
|
||||||
|
|
||||||
public static final TrackingField WEBSOCKET_INCOMING = TrackingField.of( "websocket_incoming", TrackingField::formatBytes );
|
public static final TrackingField WEBSOCKET_INCOMING = TrackingField.of( "websocket_incoming", "Websocket incoming", TrackingField::formatBytes );
|
||||||
public static final TrackingField WEBSOCKET_OUTGOING = TrackingField.of( "websocket_outgoing", TrackingField::formatBytes );
|
public static final TrackingField WEBSOCKET_OUTGOING = TrackingField.of( "websocket_outgoing", "Websocket outgoing", TrackingField::formatBytes );
|
||||||
|
|
||||||
public static final TrackingField COROUTINES_CREATED = TrackingField.of( "coroutines_created", x -> String.format( "%4d", x ) );
|
public static final TrackingField COROUTINES_CREATED = TrackingField.of( "coroutines_created", "Coroutines created", x -> String.format( "%4d", x ) );
|
||||||
public static final TrackingField COROUTINES_DISPOSED = TrackingField.of( "coroutines_dead", x -> String.format( "%4d", x ) );
|
public static final TrackingField COROUTINES_DISPOSED = TrackingField.of( "coroutines_dead", "Coroutines disposed", x -> String.format( "%4d", x ) );
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String translationKey;
|
private final String translationKey;
|
||||||
@@ -51,6 +55,12 @@ public final class TrackingField
|
|||||||
return translationKey;
|
return translationKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public String displayName()
|
||||||
|
{
|
||||||
|
return StringUtil.translate( translationKey() );
|
||||||
|
}
|
||||||
|
|
||||||
private TrackingField( String id, LongFunction<String> format )
|
private TrackingField( String id, LongFunction<String> format )
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -63,7 +73,7 @@ public final class TrackingField
|
|||||||
return format.apply( value );
|
return format.apply( value );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TrackingField of( String id, LongFunction<String> format )
|
public static TrackingField of( String id, String displayName, LongFunction<String> format )
|
||||||
{
|
{
|
||||||
TrackingField field = new TrackingField( id, format );
|
TrackingField field = new TrackingField( id, format );
|
||||||
fields.put( id, field );
|
fields.put( id, field );
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user