mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-07 08:52:59 +00:00
Compare commits
7 Commits
mc-1.13.x
...
v1.14-1.82
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f15a278f3b | ||
|
|
26b73c2ff3 | ||
|
|
c1e08fc3c7 | ||
|
|
b9ec6f236d | ||
|
|
b1fff97bff | ||
|
|
c81bc70475 | ||
|
|
55a7ee4acf |
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
name: Bug report
|
name: Bug report
|
||||||
about: Report some misbehaviour in the mod
|
about: Report some misbehaviour in the mod
|
||||||
labels: bug
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|||||||
4
.github/ISSUE_TEMPLATE/feature_request.md
vendored
4
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
name: Feature request
|
name: Feature request
|
||||||
about: Suggest an idea or improvement
|
about: Suggest an idea or improvement
|
||||||
labels: enhancement
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
@@ -11,4 +11,4 @@ labels: enhancement
|
|||||||
|
|
||||||
## Useful information to include:
|
## Useful information to include:
|
||||||
- Explanation of how the feature/change should work.
|
- Explanation of how the feature/change should work.
|
||||||
- Some rationale/use case for a feature. My general approach to designing new features is to ask yourself "what issue are we trying to solve" and _then_ "is this the best way to solve this issue?".
|
- Some rationale/use case for a feature. I'd like to keep CC:T as minimal as possible, so I like have a solid justification for each feature.
|
||||||
|
|||||||
3
.github/pull_request_template.md
vendored
3
.github/pull_request_template.md
vendored
@@ -1,3 +0,0 @@
|
|||||||
## A quick checklist
|
|
||||||
- If there's a existing issue, please link to it. If not, provide fill out the same information you would in a normal issue - reproduction steps for bugs, rationale for use-case.
|
|
||||||
- If you're working on CraftOS, try to write a few test cases so we can ensure everything continues to work in the future. Tests live in `src/test/resources/test-rom/spec` and can be run with `./gradlew check`.
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -15,9 +15,3 @@
|
|||||||
.idea
|
.idea
|
||||||
.gradle
|
.gradle
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
|
||||||
.classpath
|
|
||||||
.project
|
|
||||||
.settings/
|
|
||||||
bin/
|
|
||||||
*.launch
|
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -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://travis-ci.org/SquidDev-CC/CC-Tweaked)
|
||||||
|
|
||||||
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.
|
||||||
@@ -9,7 +9,7 @@ ComputerCraft has always held a fond place in my heart: it's the mod which reall
|
|||||||
mod which has kept me playing it for many years. However, development of the original mod has slowed, as the original
|
mod which has kept me playing it for many years. However, development of the original mod has slowed, as the original
|
||||||
developers have had less time to work on the mod, and moved onto other projects and commitments.
|
developers have had less time to work on the mod, and moved onto other projects and commitments.
|
||||||
|
|
||||||
CC: Tweaked (or CC:T for short) is an attempt to continue ComputerCraft's legacy. It's not intended to be a competitor
|
CC:Tweaked (or CC:T for short) is an attempt to continue ComputerCraft's legacy. It's not intended to be a competitor
|
||||||
to CC, nor do I want to take it in a vastly different direction to the original mod. Instead, CC:T focuses on making the
|
to CC, nor do I want to take it in a vastly different direction to the original mod. Instead, CC:T focuses on making the
|
||||||
ComputerCraft experience as _solid_ as possible, ironing out any wrinkles that may have developed over time.
|
ComputerCraft experience as _solid_ as possible, ironing out any wrinkles that may have developed over time.
|
||||||
|
|
||||||
@@ -46,17 +46,8 @@ develop CC:T, you'll need to follow these steps:
|
|||||||
|
|
||||||
If you want to run CC:T in a normal Minecraft instance, run `./gradlew build` and copy the `.jar` from `build/libs`.
|
If you want to run CC:T in a normal Minecraft instance, run `./gradlew build` and copy the `.jar` from `build/libs`.
|
||||||
|
|
||||||
## Community
|
|
||||||
If you need help getting started with CC: Tweaked, want to show off your latest project, or just want to chat about
|
|
||||||
ComputerCraft we have a [forum](https://forums.computercraft.cc/) and [Discord guild](https://discord.gg/H2UyJXe)!
|
|
||||||
There's also a fairly populated, albeit quiet [IRC channel](http://webchat.esper.net/?channels=#computercraft), if
|
|
||||||
that's more your cup of tea.
|
|
||||||
|
|
||||||
I'd generally recommend you don't contact me directly (email, DM, etc...) unless absolutely necessary (i.e. in order to
|
|
||||||
report exploits). You'll get a far quicker response if you ask the whole community!
|
|
||||||
|
|
||||||
## Using
|
## Using
|
||||||
If you want to depend on CC: Tweaked, we have a maven repo. However, you should be wary that some functionality is only
|
If you want to depend on CC:Tweaked, we have a maven repo. However, you should be wary that some functionality is only
|
||||||
exposed by CC:T's API and not vanilla ComputerCraft. If you wish to support all variations of ComputerCraft, I recommend
|
exposed by CC:T's API and not vanilla ComputerCraft. If you wish to support all variations of ComputerCraft, I recommend
|
||||||
using [cc.crzd.me's maven](https://cc.crzd.me/maven/) instead.
|
using [cc.crzd.me's maven](https://cc.crzd.me/maven/) instead.
|
||||||
|
|
||||||
|
|||||||
189
build.gradle
189
build.gradle
@@ -1,28 +1,17 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
mavenCentral()
|
|
||||||
maven {
|
|
||||||
name = "forge"
|
|
||||||
url = "http://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.sf.proguard:proguard-gradle:6.1.0beta2'
|
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
|
||||||
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "checkstyle"
|
id 'fabric-loom' version '0.2.2-SNAPSHOT'
|
||||||
id "com.github.hierynomus.license" version "0.15.0"
|
id 'com.matthewprenger.cursegradle' version '1.2.0'
|
||||||
id "com.matthewprenger.cursegradle" version "1.3.0"
|
|
||||||
id "com.github.breadmoirai.github-release" version "2.2.4"
|
id "com.github.breadmoirai.github-release" version "2.2.4"
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'net.minecraftforge.gradle'
|
|
||||||
apply plugin: 'org.ajoberstar.grgit'
|
apply plugin: 'org.ajoberstar.grgit'
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
@@ -33,38 +22,10 @@ group = "org.squiddev"
|
|||||||
archivesBaseName = "cc-tweaked-${mc_version}"
|
archivesBaseName = "cc-tweaked-${mc_version}"
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
runs {
|
|
||||||
client {
|
|
||||||
workingDirectory project.file('run')
|
|
||||||
property 'forge.logging.markers', 'REGISTRIES'
|
|
||||||
property 'forge.logging.console.level', 'debug'
|
|
||||||
|
|
||||||
mods {
|
|
||||||
computercraft {
|
|
||||||
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 {
|
||||||
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
name "JEI"
|
name "JEI"
|
||||||
url "http://dvs1.progwml6.com/files/maven"
|
url "http://dvs1.progwml6.com/files/maven"
|
||||||
@@ -90,17 +51,29 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
checkstyle "com.puppycrawl.tools:checkstyle:8.21"
|
minecraft "com.mojang:minecraft:${mc_version}"
|
||||||
|
mappings "net.fabricmc:yarn:${mc_version}+build.${mappings_version}"
|
||||||
|
modCompile "net.fabricmc:fabric-loader:0.4.2+build.132"
|
||||||
|
modCompile "net.fabricmc:fabric:0.2.7+build.126"
|
||||||
|
|
||||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
/*
|
||||||
|
modCompile "net.fabricmc:fabric-lib:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-networking:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-networking-blockentity:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-object-builders:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-containers:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-item-groups:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-client-registries:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-commands:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-events-lifecycle:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-events-interaction:0.1.0"
|
||||||
|
modCompile "net.fabricmc:fabric-resource-loader:0.1.0"
|
||||||
|
*/
|
||||||
|
|
||||||
compileOnly fg.deobf("mezz.jei:jei-1.13.2:5.0.0.20:api")
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
// 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'
|
||||||
|
shade 'javax.vecmath:vecmath:1.5.2'
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
|
||||||
@@ -111,8 +84,7 @@ dependencies {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
java {
|
java {
|
||||||
exclude 'dan200/computercraft/shared/integration/mcmp'
|
exclude 'dan200/computercraft/shared/integration'
|
||||||
exclude 'dan200/computercraft/shared/integration/charset'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -147,8 +119,6 @@ import java.util.zip.*
|
|||||||
|
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
import com.hierynomus.gradle.license.tasks.LicenseCheck
|
|
||||||
import com.hierynomus.gradle.license.tasks.LicenseFormat
|
|
||||||
import org.ajoberstar.grgit.Grgit
|
import org.ajoberstar.grgit.Grgit
|
||||||
import proguard.gradle.ProGuardTask
|
import proguard.gradle.ProGuardTask
|
||||||
|
|
||||||
@@ -171,7 +141,7 @@ 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.** { *; }'
|
||||||
@@ -219,7 +189,7 @@ 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 'fabric.mods.json'
|
||||||
include 'data/computercraft/lua/rom/help/credits.txt'
|
include 'data/computercraft/lua/rom/help/credits.txt'
|
||||||
|
|
||||||
expand 'version': mod_version,
|
expand 'version': mod_version,
|
||||||
@@ -228,7 +198,7 @@ processResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
exclude 'META-INF/mods.toml'
|
exclude 'fabric.mods.json'
|
||||||
exclude 'data/computercraft/lua/rom/help/credits.txt'
|
exclude 'data/computercraft/lua/rom/help/credits.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +218,6 @@ task compressJson(dependsOn: jar) {
|
|||||||
// Copy over all files in the current jar to the new one, running json files from GSON. As pretty printing
|
// Copy over all files in the current jar to the new one, running json files from GSON. As pretty printing
|
||||||
// is turned off, they should be minified.
|
// is turned off, they should be minified.
|
||||||
new ZipFile(jarPath).withCloseable { inJar ->
|
new ZipFile(jarPath).withCloseable { inJar ->
|
||||||
tempPath.getParentFile().mkdirs()
|
|
||||||
new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tempPath))).withCloseable { outJar ->
|
new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tempPath))).withCloseable { outJar ->
|
||||||
inJar.entries().each { entry ->
|
inJar.entries().each { entry ->
|
||||||
if(entry.directory) {
|
if(entry.directory) {
|
||||||
@@ -276,91 +245,13 @@ task compressJson(dependsOn: jar) {
|
|||||||
|
|
||||||
assemble.dependsOn compressJson
|
assemble.dependsOn compressJson
|
||||||
|
|
||||||
/* Check tasks */
|
|
||||||
|
|
||||||
license {
|
|
||||||
mapping("java", "SLASHSTAR_STYLE")
|
|
||||||
strictCheck true
|
|
||||||
|
|
||||||
ext.year = Calendar.getInstance().get(Calendar.YEAR)
|
|
||||||
}
|
|
||||||
|
|
||||||
[licenseMain, licenseFormatMain].forEach {
|
|
||||||
it.configure {
|
|
||||||
include("**/*.java")
|
|
||||||
exclude("dan200/computercraft/api/**")
|
|
||||||
header rootProject.file('config/license/main.txt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[licenseTest, licenseFormatTest].forEach {
|
|
||||||
it.configure {
|
|
||||||
include("**/*.java")
|
|
||||||
header rootProject.file('config/license/main.txt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
task licenseAPI(type: LicenseCheck);
|
|
||||||
task licenseFormatAPI(type: LicenseFormat);
|
|
||||||
[licenseAPI, licenseFormatAPI].forEach {
|
|
||||||
it.configure {
|
|
||||||
source = sourceSets.main.java
|
|
||||||
include("dan200/computercraft/api/**")
|
|
||||||
header rootProject.file('config/license/api.txt')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Upload tasks */
|
|
||||||
|
|
||||||
task checkRelease {
|
|
||||||
group "upload"
|
|
||||||
description "Verifies that everything is ready for a release"
|
|
||||||
|
|
||||||
inputs.property "version", mod_version
|
|
||||||
inputs.file("src/main/resources/data/computercraft/lua/rom/help/changelog.txt")
|
|
||||||
inputs.file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
def ok = true
|
|
||||||
|
|
||||||
// Check we're targetting the current version
|
|
||||||
def whatsnew = new File("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt").readLines()
|
|
||||||
if (whatsnew[0] != "New features in CC: Tweaked $mod_version") {
|
|
||||||
ok = false
|
|
||||||
project.logger.error("Expected `whatsnew.txt' to target $mod_version.")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check "read more" exists and trim it
|
|
||||||
def idx = whatsnew.findIndexOf { it == 'Type "help changelog" to see the full version history.' }
|
|
||||||
if (idx == -1) {
|
|
||||||
ok = false
|
|
||||||
project.logger.error("Must mention the changelog in whatsnew.txt")
|
|
||||||
} else {
|
|
||||||
whatsnew = whatsnew.getAt(0 ..< idx)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check whatsnew and changelog match.
|
|
||||||
def versionChangelog = "# " + whatsnew.join("\n")
|
|
||||||
def changelog = new File("src/main/resources/data/computercraft/lua/rom/help/changelog.txt").getText()
|
|
||||||
if (!changelog.startsWith(versionChangelog)) {
|
|
||||||
ok = false
|
|
||||||
project.logger.error("whatsnew and changelog are not in sync")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ok) throw new IllegalStateException("Could not check release")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
curseforge {
|
curseforge {
|
||||||
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
|
||||||
project {
|
project {
|
||||||
id = '282001'
|
id = '282001'
|
||||||
releaseType = 'release'
|
addGameVersion '1.14-Snapshot'
|
||||||
|
releaseType = 'alpha'
|
||||||
changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
|
changelog = "Release notes can be found on the GitHub repository (https://github.com/SquidDev-CC/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
|
||||||
|
|
||||||
relations {
|
|
||||||
incompatible "computercraft"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -421,23 +312,17 @@ 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 }
|
targetCommitish "mc-1.14-fabric" // TODO: Pull from GrGit
|
||||||
|
|
||||||
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")
|
prerelease true
|
||||||
.readLines()
|
|
||||||
.takeWhile { it != 'Type "help changelog" to see the full version history.' }
|
releaseAssets.from(jar.archivePath)
|
||||||
.join("\n").trim()
|
|
||||||
}
|
|
||||||
prerelease false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def uploadTasks = ["uploadArchives", "curseforge", "githubRelease"]
|
task uploadAll(dependsOn: [uploadArchives, "curseforge", "githubRelease"]) {
|
||||||
uploadTasks.forEach { tasks.getByName(it).dependsOn checkRelease }
|
|
||||||
|
|
||||||
task uploadAll(dependsOn: uploadTasks) {
|
|
||||||
group "upload"
|
group "upload"
|
||||||
description "Uploads to all repositories (Maven, Curse, GitHub release)"
|
description "Uploads to all repositories (Maven, Curse, GitHub release)"
|
||||||
}
|
}
|
||||||
@@ -450,14 +335,10 @@ test {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gradle.projectsEvaluated {
|
gradle.projectsEvaluated {
|
||||||
reobfJar.dependsOn proguardMove
|
remapJar.dependsOn proguardMove
|
||||||
|
|
||||||
tasks.withType(JavaCompile) {
|
tasks.withType(JavaCompile) {
|
||||||
options.compilerArgs << "-Xlint" << "-Xlint:-processing" // Causes Forge build to fail << "-Werror"
|
options.compilerArgs << "-Xlint" << "-Xlint:-processing" // Causes Forge build to fail << "-Werror"
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.withType(LicenseFormat) {
|
|
||||||
outputs.upToDateWhen { false }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,159 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE module PUBLIC
|
|
||||||
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
|
|
||||||
"https://checkstyle.org/dtds/configuration_1_3.dtd">
|
|
||||||
<module name="Checker">
|
|
||||||
<property name="tabWidth" value="4"/>
|
|
||||||
<property name="charset" value="UTF-8" />
|
|
||||||
|
|
||||||
<module name="SuppressionFilter">
|
|
||||||
<property name="file" value="config/checkstyle/suppressions.xml" />
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="TreeWalker">
|
|
||||||
<!-- Annotations -->
|
|
||||||
<module name="AnnotationLocation" />
|
|
||||||
<module name="AnnotationUseStyle" />
|
|
||||||
<module name="MissingDeprecated">
|
|
||||||
<property name="skipNoJavadoc" value="true" />
|
|
||||||
</module>
|
|
||||||
<module name="MissingOverride" />
|
|
||||||
|
|
||||||
<!-- Blocks -->
|
|
||||||
<module name="EmptyBlock" />
|
|
||||||
<module name="EmptyCatchBlock">
|
|
||||||
<property name="exceptionVariableName" value="ignored" />
|
|
||||||
</module>
|
|
||||||
<module name="LeftCurly">
|
|
||||||
<property name="option" value="nl" />
|
|
||||||
<!-- The defaults, minus lambdas. -->
|
|
||||||
<property name="tokens" value="ANNOTATION_DEF,CLASS_DEF,CTOR_DEF,ENUM_CONSTANT_DEF,ENUM_DEF,INTERFACE_DEF,LITERAL_CASE,LITERAL_CATCH,LITERAL_DEFAULT,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,METHOD_DEF,OBJBLOCK,STATIC_INIT" />
|
|
||||||
</module>
|
|
||||||
<module name="NeedBraces">
|
|
||||||
<property name="allowSingleLineStatement" value="true"/>
|
|
||||||
</module>
|
|
||||||
<module name="RightCurly">
|
|
||||||
<property name="option" value="alone" />
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<!-- Class design. As if we've ever followed good practice here. -->
|
|
||||||
<module name="FinalClass" />
|
|
||||||
<module name="InterfaceIsType" />
|
|
||||||
<module name="MutableException" />
|
|
||||||
<module name="OneTopLevelClass" />
|
|
||||||
|
|
||||||
<!-- Coding -->
|
|
||||||
<module name="ArrayTrailingComma" />
|
|
||||||
<module name="EqualsHashCode" />
|
|
||||||
<!-- FallThrough does not handle unreachable code well -->
|
|
||||||
<module name="IllegalInstantiation" />
|
|
||||||
<module name="IllegalThrows" />
|
|
||||||
<module name="ModifiedControlVariable" />
|
|
||||||
<module name="NoClone" />
|
|
||||||
<module name="NoFinalizer" />
|
|
||||||
<module name="OneStatementPerLine" />
|
|
||||||
<module name="PackageDeclaration" />
|
|
||||||
<module name="SimplifyBooleanExpression" />
|
|
||||||
<module name="SimplifyBooleanReturn" />
|
|
||||||
<module name="StringLiteralEquality" />
|
|
||||||
<module name="UnnecessaryParentheses" />
|
|
||||||
|
|
||||||
<!-- Imports -->
|
|
||||||
<module name="CustomImportOrder" />
|
|
||||||
<module name="IllegalImport" />
|
|
||||||
<module name="RedundantImport" />
|
|
||||||
<module name="UnusedImports" />
|
|
||||||
|
|
||||||
<!-- Javadoc -->
|
|
||||||
<module name="AtclauseOrder" />
|
|
||||||
<!-- TODO: Cleanup our documentation before enabling JavadocMethod, JavadocStyle, JavadocType and SummaryJavadoc. -->
|
|
||||||
<module name="NonEmptyAtclauseDescription" />
|
|
||||||
<module name="SingleLineJavadoc" />
|
|
||||||
|
|
||||||
<!-- Misc -->
|
|
||||||
<module name="ArrayTypeStyle" />
|
|
||||||
<module name="CommentsIndentation" />
|
|
||||||
<module name="Indentation" />
|
|
||||||
<module name="OuterTypeFilename" />
|
|
||||||
|
|
||||||
<!-- Modifiers -->
|
|
||||||
<module name="ModifierOrder" />
|
|
||||||
<module name="RedundantModifier" />
|
|
||||||
|
|
||||||
<!-- Naming -->
|
|
||||||
<module name="ClassTypeParameterName" />
|
|
||||||
<module name="InterfaceTypeParameterName" />
|
|
||||||
<module name="LambdaParameterName" />
|
|
||||||
<module name="LocalFinalVariableName" />
|
|
||||||
<module name="LocalVariableName" />
|
|
||||||
<!-- Allow an optional m_ on private members -->
|
|
||||||
<module name="MemberName">
|
|
||||||
<property name="applyToPrivate" value="false" />
|
|
||||||
<property name="applyToPackage" value="false" />
|
|
||||||
</module>
|
|
||||||
<module name="MemberName">
|
|
||||||
<property name="format" value="^(m_)?[a-z][a-zA-Z0-9]*$" />
|
|
||||||
<property name="applyToPrivate" value="true" />
|
|
||||||
<property name="applyToPackage" value="true" />
|
|
||||||
</module>
|
|
||||||
<module name="MethodName" />
|
|
||||||
<module name="MethodTypeParameterName" />
|
|
||||||
<module name="PackageName">
|
|
||||||
<property name="format" value="^dan200\.computercraf(\.[a-z][a-z0-9]*)*" />
|
|
||||||
</module>
|
|
||||||
<module name="ParameterName" />
|
|
||||||
<module name="StaticVariableName">
|
|
||||||
<property name="format" value="^[a-z][a-zA-Z0-9]*|CAPABILITY(_[A-Z]+)?$" />
|
|
||||||
<property name="applyToPrivate" value="false" />
|
|
||||||
</module>
|
|
||||||
<module name="StaticVariableName">
|
|
||||||
<property name="format" value="^(s_)?[a-z][a-zA-Z0-9]*|CAPABILITY(_[A-Z]+)?$" />
|
|
||||||
<property name="applyToPrivate" value="true" />
|
|
||||||
</module>
|
|
||||||
<module name="TypeName" />
|
|
||||||
|
|
||||||
<!-- Whitespace -->
|
|
||||||
<module name="EmptyForInitializerPad"/>
|
|
||||||
<module name="EmptyForIteratorPad">
|
|
||||||
<property name="option" value="space"/>
|
|
||||||
</module>
|
|
||||||
<module name="GenericWhitespace" />
|
|
||||||
<module name="MethodParamPad" />
|
|
||||||
<module name="NoLineWrap" />
|
|
||||||
<module name="NoWhitespaceAfter">
|
|
||||||
<property name="tokens" value="AT,INC,DEC,UNARY_MINUS,UNARY_PLUS,BNOT,LNOT,DOT,ARRAY_DECLARATOR,INDEX_OP" />
|
|
||||||
</module>
|
|
||||||
<module name="NoWhitespaceBefore" />
|
|
||||||
<!-- TODO: Decide on an OperatorWrap style. -->
|
|
||||||
<module name="ParenPad">
|
|
||||||
<property name="option" value="space" />
|
|
||||||
<property name="tokens" value="ANNOTATION,ANNOTATION_FIELD_DEF,CTOR_CALL,CTOR_DEF,ENUM_CONSTANT_DEF,LITERAL_CATCH,LITERAL_DO,LITERAL_FOR,LITERAL_IF,LITERAL_NEW,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_WHILE,METHOD_CALL,METHOD_DEF,RESOURCE_SPECIFICATION,SUPER_CTOR_CALL,LAMBDA" />
|
|
||||||
</module>
|
|
||||||
<module name="ParenPad">
|
|
||||||
<property name="option" value="nospace" />
|
|
||||||
<property name="tokens" value="DOT,EXPR,QUESTION" />
|
|
||||||
</module>
|
|
||||||
<module name="SeparatorWrap">
|
|
||||||
<property name="option" value="eol" />
|
|
||||||
<property name="tokens" value="COMMA,SEMI,ELLIPSIS,ARRAY_DECLARATOR,RBRACK,METHOD_REF" />
|
|
||||||
</module>
|
|
||||||
<module name="SeparatorWrap">
|
|
||||||
<property name="option" value="nl" />
|
|
||||||
<property name="tokens" value="DOT,AT" />
|
|
||||||
</module>
|
|
||||||
<module name="SingleSpaceSeparator" />
|
|
||||||
<module name="TypecastParenPad" />
|
|
||||||
<module name="WhitespaceAfter">
|
|
||||||
<property name="tokens" value="COMMA" />
|
|
||||||
</module>
|
|
||||||
<module name="WhitespaceAround">
|
|
||||||
<property name="allowEmptyConstructors" value="true" />
|
|
||||||
<property name="ignoreEnhancedForColon" value="false" />
|
|
||||||
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,DO_WHILE,EQUAL,GE,GT,LAMBDA,LAND,LCURLY,LE,LITERAL_RETURN,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND" />
|
|
||||||
</module>
|
|
||||||
</module>
|
|
||||||
|
|
||||||
<module name="FileTabCharacter" />
|
|
||||||
<module name="NewlineAtEndOfFile" />
|
|
||||||
</module>
|
|
||||||
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE suppressions PUBLIC
|
|
||||||
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
|
|
||||||
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
|
|
||||||
<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. -->
|
|
||||||
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraft.java" />
|
|
||||||
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraftAPI.java" />
|
|
||||||
</suppressions>
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This file is part of the public ComputerCraft API - http://www.computercraft.info
|
|
||||||
Copyright Daniel Ratcliffe, 2011-${year}. 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.
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
Copyright Daniel Ratcliffe, 2011-${year}. Do not distribute without permission.
|
|
||||||
Send enquiries to dratcliffe@gmail.com
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
# Mod properties
|
# Mod properties
|
||||||
mod_version=1.83.1
|
mod_version=1.82.3
|
||||||
|
|
||||||
# Minecraft properties
|
# Minecraft properties
|
||||||
mc_version=1.13.2
|
mc_version=1.14
|
||||||
forge_version=25.0.219
|
mappings_version=1
|
||||||
mappings_version=20190530-1.13.2
|
|
||||||
|
|||||||
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
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -1 +1,12 @@
|
|||||||
rootProject.name = "cc-tweaked-${mc_version}"
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
jcenter()
|
||||||
|
maven {
|
||||||
|
name = 'Fabric'
|
||||||
|
url = 'https://maven.fabricmc.net/'
|
||||||
|
}
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rootProject.name = "cc-tweaked-${mc_version}-fabric"
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ package dan200.computercraft;
|
|||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
import dan200.computercraft.api.turtle.event.TurtleAction;
|
||||||
|
import dan200.computercraft.client.proxy.ComputerCraftProxyClient;
|
||||||
import dan200.computercraft.core.apis.AddressPredicate;
|
import dan200.computercraft.core.apis.AddressPredicate;
|
||||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
||||||
import dan200.computercraft.core.filesystem.ResourceMount;
|
import dan200.computercraft.core.filesystem.ResourceMount;
|
||||||
import dan200.computercraft.shared.Config;
|
|
||||||
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;
|
||||||
@@ -30,13 +30,14 @@ 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.ItemTurtle;
|
||||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||||
import net.minecraft.resources.IReloadableResourceManager;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraft.resource.ReloadableResourceManager;
|
||||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
import net.minecraft.util.Identifier;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -45,8 +46,7 @@ import java.io.InputStream;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Mod( ComputerCraft.MOD_ID )
|
public final class ComputerCraft implements ModInitializer
|
||||||
public final class ComputerCraft
|
|
||||||
{
|
{
|
||||||
public static final String MOD_ID = "computercraft";
|
public static final String MOD_ID = "computercraft";
|
||||||
|
|
||||||
@@ -184,9 +184,22 @@ public final class ComputerCraft
|
|||||||
// Logging
|
// Logging
|
||||||
public static final Logger log = LogManager.getLogger( MOD_ID );
|
public static final Logger log = LogManager.getLogger( MOD_ID );
|
||||||
|
|
||||||
|
// Implementation
|
||||||
|
public static ComputerCraft instance;
|
||||||
|
|
||||||
public ComputerCraft()
|
public ComputerCraft()
|
||||||
{
|
{
|
||||||
Config.load();
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onInitialize()
|
||||||
|
{
|
||||||
|
ComputerCraftProxyCommon.setup();
|
||||||
|
if( net.fabricmc.loader.api.FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT )
|
||||||
|
{
|
||||||
|
ComputerCraftProxyClient.setup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersion()
|
public static String getVersion()
|
||||||
@@ -196,17 +209,17 @@ public final class ComputerCraft
|
|||||||
|
|
||||||
static IMount createResourceMount( String domain, String subPath )
|
static IMount createResourceMount( String domain, String subPath )
|
||||||
{
|
{
|
||||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
|
ReloadableResourceManager manager = ComputerCraftProxyCommon.getServer().getDataManager();
|
||||||
ResourceMount mount = new ResourceMount( domain, subPath, manager );
|
ResourceMount mount = new ResourceMount( domain, subPath, manager );
|
||||||
return mount.exists( "" ) ? mount : null;
|
return mount.exists( "" ) ? mount : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream getResourceFile( String domain, String subPath )
|
public static InputStream getResourceFile( String domain, String subPath )
|
||||||
{
|
{
|
||||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResourceManager();
|
ReloadableResourceManager manager = ComputerCraftProxyCommon.getServer().getDataManager();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
|
return manager.getResource( new Identifier( domain, subPath ) ).getInputStream();
|
||||||
}
|
}
|
||||||
catch( IOException ignored )
|
catch( IOException ignored )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,18 +21,19 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|||||||
import dan200.computercraft.core.apis.ApiFactories;
|
import dan200.computercraft.core.apis.ApiFactories;
|
||||||
import dan200.computercraft.core.filesystem.FileMount;
|
import dan200.computercraft.core.filesystem.FileMount;
|
||||||
import dan200.computercraft.shared.*;
|
import dan200.computercraft.shared.*;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.TileWiredModemFull;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
||||||
import dan200.computercraft.shared.util.IDAssigner;
|
import dan200.computercraft.shared.util.IDAssigner;
|
||||||
import dan200.computercraft.shared.wired.CapabilityWiredElement;
|
|
||||||
import dan200.computercraft.shared.wired.WiredNode;
|
import dan200.computercraft.shared.wired.WiredNode;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
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.util.math.Direction;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
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 java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||||
@@ -53,7 +54,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
|||||||
@Override
|
@Override
|
||||||
public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||||
{
|
{
|
||||||
return IDAssigner.getNextId( parentSubPath );
|
return IDAssigner.getNextId( world, parentSubPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -61,7 +62,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new FileMount( new File( IDAssigner.getDir(), subPath ), capacity );
|
return new FileMount( new File( IDAssigner.getDir( world ), subPath ), capacity );
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
@@ -94,7 +95,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
{
|
{
|
||||||
return BundledRedstone.getDefaultOutput( world, pos, side );
|
return BundledRedstone.getDefaultOutput( world, pos, side );
|
||||||
}
|
}
|
||||||
@@ -131,11 +132,19 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
|||||||
return new WiredNode( element );
|
return new WiredNode( element );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
public IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
{
|
{
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
return tile == null ? LazyOptional.empty() : tile.getCapability( CapabilityWiredElement.CAPABILITY, side );
|
if( tile instanceof TileCable )
|
||||||
|
{
|
||||||
|
return ((TileCable) tile).getElement( side );
|
||||||
|
}
|
||||||
|
else if( tile instanceof TileWiredModemFull )
|
||||||
|
{
|
||||||
|
return ((TileWiredModemFull) tile).getElement();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package dan200.computercraft.api;
|
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.item.ItemProvider;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.IItemProvider;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.SystemUtil;
|
||||||
import net.minecraft.util.Util;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -21,12 +22,12 @@ import javax.annotation.Nonnull;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||||
{
|
{
|
||||||
private final ResourceLocation id;
|
private final Identifier id;
|
||||||
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( Identifier id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -34,24 +35,24 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
|||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, IItemProvider item )
|
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemProvider item )
|
||||||
{
|
{
|
||||||
this( id, type, adjective, new ItemStack( item ) );
|
this( id, type, adjective, new ItemStack( item ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, ItemStack stack )
|
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemStack stack )
|
||||||
{
|
{
|
||||||
this( id, type, Util.makeTranslationKey( "upgrade", id ) + ".adjective", stack );
|
this( id, type, SystemUtil.createTranslationKey( "upgrade", id ) + ".adjective", stack );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, IItemProvider item )
|
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemProvider item )
|
||||||
{
|
{
|
||||||
this( id, type, new ItemStack( item ) );
|
this( id, type, new ItemStack( item ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public final ResourceLocation getUpgradeID()
|
public final Identifier getUpgradeID()
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,10 @@ import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
|||||||
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.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
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;
|
||||||
@@ -183,7 +182,7 @@ public final class ComputerCraftAPI
|
|||||||
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
|
* If there is no block capable of emitting bundled redstone at the location, -1 will be returned.
|
||||||
* @see IBundledRedstoneProvider
|
* @see IBundledRedstoneProvider
|
||||||
*/
|
*/
|
||||||
public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
public static int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
{
|
{
|
||||||
return getInstance().getBundledRedstoneOutput( world, pos, side );
|
return getInstance().getBundledRedstoneOutput( world, pos, side );
|
||||||
}
|
}
|
||||||
@@ -241,8 +240,8 @@ 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 BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
{
|
{
|
||||||
return getInstance().getWiredElementAt( world, pos, side );
|
return getInstance().getWiredElementAt( world, pos, side );
|
||||||
}
|
}
|
||||||
@@ -284,7 +283,7 @@ public final class ComputerCraftAPI
|
|||||||
|
|
||||||
void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
|
void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
|
||||||
|
|
||||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
|
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||||
|
|
||||||
void registerMediaProvider( @Nonnull IMediaProvider provider );
|
void registerMediaProvider( @Nonnull IMediaProvider provider );
|
||||||
|
|
||||||
@@ -298,7 +297,7 @@ public final class ComputerCraftAPI
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
|
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
|
||||||
|
|
||||||
@Nonnull
|
@Nullable
|
||||||
LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
|
IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.filesystem;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An {@link IOException} which occurred on a specific file.
|
|
||||||
*
|
|
||||||
* This may be thrown from a {@link IMount} or {@link IWritableMount} to give more information about a failure.
|
|
||||||
*/
|
|
||||||
public class FileOperationException extends IOException
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = -8809108200853029849L;
|
|
||||||
|
|
||||||
private final String filename;
|
|
||||||
|
|
||||||
public FileOperationException( @Nullable String filename, @Nonnull String message )
|
|
||||||
{
|
|
||||||
super( Objects.requireNonNull( message, "message cannot be null" ) );
|
|
||||||
this.filename = filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public FileOperationException( String message )
|
|
||||||
{
|
|
||||||
super( Objects.requireNonNull( message, "message cannot be null" ) );
|
|
||||||
this.filename = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getFilename()
|
|
||||||
{
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -90,6 +90,7 @@ public interface IMount
|
|||||||
* @throws IOException If the file does not exist, or could not be opened.
|
* @throws IOException If the file does not exist, or could not be opened.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@SuppressWarnings( "deprecation" )
|
||||||
default ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
default ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
return Channels.newChannel( openForRead( path ) );
|
return Channels.newChannel( openForRead( path ) );
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public interface IWritableMount extends IMount
|
|||||||
* @throws IOException If the file could not be opened for writing.
|
* @throws IOException If the file could not be opened for writing.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@SuppressWarnings( "deprecation" )
|
||||||
default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
default WritableByteChannel openChannelForWrite( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
return Channels.newChannel( openForWrite( path ) );
|
return Channels.newChannel( openForWrite( path ) );
|
||||||
@@ -93,6 +94,7 @@ public interface IWritableMount extends IMount
|
|||||||
* @throws IOException If the file could not be opened for writing.
|
* @throws IOException If the file could not be opened for writing.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@SuppressWarnings( "deprecation" )
|
||||||
default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
default WritableByteChannel openChannelForAppend( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
return Channels.newChannel( openForAppend( path ) );
|
return Channels.newChannel( openForAppend( path ) );
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ package dan200.computercraft.api.media;
|
|||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.SoundEvent;
|
import net.minecraft.sound.SoundEvent;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|||||||
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -17,7 +17,8 @@ import javax.annotation.Nullable;
|
|||||||
/**
|
/**
|
||||||
* This interface is used to create peripheral implementations for blocks.
|
* This interface is used to create peripheral implementations for blocks.
|
||||||
*
|
*
|
||||||
* If you have a {@link TileEntity} which acts as a peripheral, you may alternatively implement {@link IPeripheralTile}.
|
* If you have a {@link BlockEntity} which acts as a peripheral, you may alternatively implement
|
||||||
|
* {@link IPeripheralTile}.
|
||||||
*
|
*
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||||
*/
|
*/
|
||||||
@@ -34,5 +35,5 @@ public interface IPeripheralProvider
|
|||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
|
IPeripheral getPeripheral( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,15 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link net.minecraft.tileentity.TileEntity} which may act as a peripheral.
|
* A {@link net.minecraft.block.entity.BlockEntity} which may act as a peripheral.
|
||||||
*
|
*
|
||||||
* If you need more complex capabilities (such as handling TEs not belonging to your mod), you should use
|
* If you need more complex capabilities (such as handling TEs not belonging to your mod), you should use
|
||||||
* {@link IPeripheralProvider}.
|
* {@link IPeripheralProvider}.
|
||||||
@@ -25,8 +25,8 @@ public interface IPeripheralTile
|
|||||||
*
|
*
|
||||||
* @param side The side to get the peripheral from.
|
* @param side The side to get the peripheral from.
|
||||||
* @return A peripheral, or {@code null} if there is not a peripheral here.
|
* @return A peripheral, or {@code null} if there is not a peripheral here.
|
||||||
* @see IPeripheralProvider#getPeripheral(World, BlockPos, EnumFacing)
|
* @see IPeripheralProvider#getPeripheral(World, BlockPos, Direction)
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
IPeripheral getPeripheral( @Nonnull EnumFacing side );
|
IPeripheral getPeripheral( @Nonnull Direction side );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package dan200.computercraft.api.pocket;
|
package dan200.computercraft.api.pocket;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemProvider;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.IItemProvider;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.SystemUtil;
|
||||||
import net.minecraft.util.Util;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -19,30 +20,30 @@ import javax.annotation.Nonnull;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||||
{
|
{
|
||||||
private final ResourceLocation id;
|
private final Identifier id;
|
||||||
private final String adjective;
|
private final String adjective;
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
|
|
||||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemStack stack )
|
protected AbstractPocketUpgrade( Identifier id, String adjective, ItemStack stack )
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.adjective = adjective;
|
this.adjective = adjective;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, IItemProvider item )
|
protected AbstractPocketUpgrade( Identifier identifier, String adjective, ItemProvider item )
|
||||||
{
|
{
|
||||||
this( id, adjective, new ItemStack( item ) );
|
this( identifier, adjective, new ItemStack( item ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractPocketUpgrade( ResourceLocation id, IItemProvider item )
|
protected AbstractPocketUpgrade( Identifier id, ItemProvider item )
|
||||||
{
|
{
|
||||||
this( id, Util.makeTranslationKey( "upgrade", id ) + ".adjective", new ItemStack( item ) );
|
this( id, SystemUtil.createTranslationKey( "upgrade", id ) + ".adjective", new ItemStack( item ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public final ResourceLocation getUpgradeID()
|
public final Identifier getUpgradeID()
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ package dan200.computercraft.api.pocket;
|
|||||||
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -75,7 +75,7 @@ public interface IPocketAccess
|
|||||||
* @see #updateUpgradeNBTData()
|
* @see #updateUpgradeNBTData()
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
NBTTagCompound getUpgradeNBTData();
|
CompoundTag getUpgradeNBTData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the upgrade-specific NBT as dirty.
|
* Mark the upgrade-specific NBT as dirty.
|
||||||
@@ -95,5 +95,5 @@ public interface IPocketAccess
|
|||||||
* @return A collection of all upgrade names.
|
* @return A collection of all upgrade names.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
Map<ResourceLocation, IPeripheral> getUpgrades();
|
Map<Identifier, IPeripheral> getUpgrades();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import dan200.computercraft.api.ComputerCraftAPI;
|
|||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -36,7 +36,7 @@ public interface IPocketUpgrade
|
|||||||
* @see ComputerCraftAPI#registerPocketUpgrade(IPocketUpgrade)
|
* @see ComputerCraftAPI#registerPocketUpgrade(IPocketUpgrade)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
ResourceLocation getUpgradeID();
|
Identifier getUpgradeID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an unlocalised string to describe the type of pocket computer this upgrade provides.
|
* Return an unlocalised string to describe the type of pocket computer this upgrade provides.
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
package dan200.computercraft.api.redstone;
|
package dan200.computercraft.api.redstone;
|
||||||
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -30,5 +30,5 @@ public interface IBundledRedstoneProvider
|
|||||||
* handle this block.
|
* handle this block.
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
* @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider)
|
||||||
*/
|
*/
|
||||||
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side );
|
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,12 @@ import com.mojang.authlib.GameProfile;
|
|||||||
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.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -83,10 +82,10 @@ public interface ITurtleAccess
|
|||||||
* Returns the world direction the turtle is currently facing.
|
* Returns the world direction the turtle is currently facing.
|
||||||
*
|
*
|
||||||
* @return The world direction the turtle is currently facing.
|
* @return The world direction the turtle is currently facing.
|
||||||
* @see #setDirection(EnumFacing)
|
* @see #setDirection(Direction)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
EnumFacing getDirection();
|
Direction getDirection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to
|
* Set the direction the turtle is facing. Note that this will not play a rotation animation, you will also need to
|
||||||
@@ -95,7 +94,7 @@ public interface ITurtleAccess
|
|||||||
* @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west).
|
* @param dir The new direction to set. This should be on either the x or z axis (so north, south, east or west).
|
||||||
* @see #getDirection()
|
* @see #getDirection()
|
||||||
*/
|
*/
|
||||||
void setDirection( @Nonnull EnumFacing dir );
|
void setDirection( @Nonnull Direction dir );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently selected slot in the turtle's inventory.
|
* Get the currently selected slot in the turtle's inventory.
|
||||||
@@ -147,21 +146,9 @@ public interface ITurtleAccess
|
|||||||
* Get the inventory of this turtle
|
* Get the inventory of this turtle
|
||||||
*
|
*
|
||||||
* @return This turtle's inventory
|
* @return This turtle's inventory
|
||||||
* @see #getItemHandler()
|
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
IInventory getInventory();
|
Inventory getInventory();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the inventory of this turtle as an {@link IItemHandlerModifiable}.
|
|
||||||
*
|
|
||||||
* @return This turtle's inventory
|
|
||||||
* @see #getInventory()
|
|
||||||
* @see IItemHandlerModifiable
|
|
||||||
* @see net.minecraftforge.items.CapabilityItemHandler#ITEM_HANDLER_CAPABILITY
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
IItemHandlerModifiable getItemHandler();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether this turtle will require fuel when performing actions.
|
* Determine whether this turtle will require fuel when performing actions.
|
||||||
@@ -290,7 +277,7 @@ public interface ITurtleAccess
|
|||||||
* @see #updateUpgradeNBTData(TurtleSide)
|
* @see #updateUpgradeNBTData(TurtleSide)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
NBTTagCompound getUpgradeNBTData( @Nullable TurtleSide side );
|
CompoundTag getUpgradeNBTData( @Nullable TurtleSide side );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
|
* Mark the upgrade-specific data as dirty on a specific side. This is required for the data to be synced to the
|
||||||
|
|||||||
@@ -10,15 +10,13 @@ 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.fabricmc.api.EnvType;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
|
import net.minecraft.client.util.ModelIdentifier;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
|
||||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -42,7 +40,7 @@ public interface ITurtleUpgrade
|
|||||||
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
ResourceLocation getUpgradeID();
|
Identifier getUpgradeID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 +96,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 {@code BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig}for digging,
|
||||||
* {@link AttackEntityEvent} and {@link TurtleAttackEvent} for attacking.
|
* {@code 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.
|
||||||
@@ -113,7 +111,7 @@ public interface ITurtleUpgrade
|
|||||||
* to be called.
|
* to be called.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull EnumFacing direction )
|
default TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction )
|
||||||
{
|
{
|
||||||
return TurtleCommandResult.failure();
|
return TurtleCommandResult.failure();
|
||||||
}
|
}
|
||||||
@@ -121,8 +119,8 @@ 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.render.item.ItemModels#getModel(ItemStack)},
|
||||||
* {@link net.minecraft.client.renderer.model.ModelManager#getModel(ModelResourceLocation)} or any other
|
* {@link net.minecraft.client.render.model.BakedModelManager#getModel(ModelIdentifier)} 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,8 +129,8 @@ 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 )
|
@Environment( EnvType.CLIENT )
|
||||||
Pair<IBakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
|
Pair<BakedModel, Matrix4f> getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called once per tick for each turtle which has the upgrade equipped.
|
* Called once per tick for each turtle which has the upgrade equipped.
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -15,7 +15,7 @@ import javax.annotation.Nullable;
|
|||||||
* Used to indicate the result of executing a turtle command.
|
* Used to indicate the result of executing a turtle command.
|
||||||
*
|
*
|
||||||
* @see ITurtleCommand#execute(ITurtleAccess)
|
* @see ITurtleCommand#execute(ITurtleAccess)
|
||||||
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
|
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
|
||||||
*/
|
*/
|
||||||
public final class TurtleCommandResult
|
public final class TurtleCommandResult
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
|
|
||||||
package dan200.computercraft.api.turtle;
|
package dan200.computercraft.api.turtle;
|
||||||
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by
|
* An enum representing the different actions that an {@link ITurtleUpgrade} of type Tool may be called on to perform by
|
||||||
* a turtle.
|
* a turtle.
|
||||||
*
|
*
|
||||||
* @see ITurtleUpgrade#getType()
|
* @see ITurtleUpgrade#getType()
|
||||||
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)
|
* @see ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)
|
||||||
*/
|
*/
|
||||||
public enum TurtleVerb
|
public enum TurtleVerb
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2018. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.api.turtle.event;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper for {@link ServerPlayerEntity} which denotes a "fake" player.
|
||||||
|
*
|
||||||
|
* Please note that this does not implement any of the traditional fake player behaviour. It simply exists to prevent
|
||||||
|
* me passing in normal players.
|
||||||
|
*/
|
||||||
|
public class FakePlayer extends ServerPlayerEntity
|
||||||
|
{
|
||||||
|
public FakePlayer( ServerWorld world, GameProfile gameProfile )
|
||||||
|
{
|
||||||
|
super( world.getServer(), world, gameProfile, new ServerPlayerInteractionManager( world ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ 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 javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -17,11 +16,11 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* An event fired when a turtle is performing a known action.
|
* An event fired when a turtle is performing a known action.
|
||||||
*/
|
*/
|
||||||
@Cancelable
|
|
||||||
public class TurtleActionEvent extends TurtleEvent
|
public class TurtleActionEvent extends TurtleEvent
|
||||||
{
|
{
|
||||||
private final TurtleAction action;
|
private final TurtleAction action;
|
||||||
private String failureMessage;
|
private String failureMessage;
|
||||||
|
private boolean cancelled = false;
|
||||||
|
|
||||||
public TurtleActionEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action )
|
public TurtleActionEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action )
|
||||||
{
|
{
|
||||||
@@ -45,7 +44,6 @@ public class TurtleActionEvent extends TurtleEvent
|
|||||||
* @see TurtleCommandResult#failure()
|
* @see TurtleCommandResult#failure()
|
||||||
* @deprecated Use {@link #setCanceled(boolean, String)} instead.
|
* @deprecated Use {@link #setCanceled(boolean, String)} instead.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void setCanceled( boolean cancel )
|
public void setCanceled( boolean cancel )
|
||||||
{
|
{
|
||||||
@@ -63,7 +61,7 @@ public class TurtleActionEvent extends TurtleEvent
|
|||||||
*/
|
*/
|
||||||
public void setCanceled( boolean cancel, @Nullable String failureMessage )
|
public void setCanceled( boolean cancel, @Nullable String failureMessage )
|
||||||
{
|
{
|
||||||
super.setCanceled( cancel );
|
this.cancelled = true;
|
||||||
this.failureMessage = cancel ? failureMessage : null;
|
this.failureMessage = cancel ? failureMessage : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,4 +77,15 @@ public class TurtleActionEvent extends TurtleEvent
|
|||||||
{
|
{
|
||||||
return failureMessage;
|
return failureMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if this event is cancelled
|
||||||
|
*
|
||||||
|
* @return If this event is cancelled
|
||||||
|
* @see #setCanceled(boolean, String)
|
||||||
|
*/
|
||||||
|
public boolean isCancelled()
|
||||||
|
{
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
|
||||||
import net.minecraftforge.event.entity.player.AttackEntityEvent;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -21,10 +19,11 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* Fired when a turtle attempts to attack an entity.
|
* Fired when a turtle attempts to attack an entity.
|
||||||
*
|
*
|
||||||
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)},
|
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
|
||||||
* as the base {@code turtle.attack()} command does not fire it.
|
* as the base {@code turtle.attack()} command does not fire it.
|
||||||
*
|
*
|
||||||
* Note that such commands should also fire {@link AttackEntityEvent}, so you do not need to listen to both.
|
* Note that such commands should also fire {@link net.fabricmc.fabric.api.event.player.AttackEntityCallback}, so you do
|
||||||
|
* not need to listen to both.
|
||||||
*
|
*
|
||||||
* @see TurtleAction#ATTACK
|
* @see TurtleAction#ATTACK
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ import dan200.computercraft.api.turtle.ITurtleAccess;
|
|||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.api.turtle.TurtleVerb;
|
import dan200.computercraft.api.turtle.TurtleVerb;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -75,20 +73,21 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
/**
|
/**
|
||||||
* Fired when a turtle attempts to dig a block.
|
* Fired when a turtle attempts to dig a block.
|
||||||
*
|
*
|
||||||
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, EnumFacing)},
|
* This must be fired by {@link ITurtleUpgrade#useTool(ITurtleAccess, TurtleSide, TurtleVerb, Direction)},
|
||||||
* as the base {@code turtle.dig()} command does not fire it.
|
* as the base {@code turtle.dig()} command does not fire it.
|
||||||
*
|
*
|
||||||
* Note that such commands should also fire {@link BlockEvent.BreakEvent}, so you do not need to listen to both.
|
* Note that such commands should also fire {@link net.fabricmc.fabric.api.event.player.AttackBlockCallback}, so you
|
||||||
|
* do not need to listen to both.
|
||||||
*
|
*
|
||||||
* @see TurtleAction#DIG
|
* @see TurtleAction#DIG
|
||||||
*/
|
*/
|
||||||
public static class Dig extends TurtleBlockEvent
|
public static class Dig extends TurtleBlockEvent
|
||||||
{
|
{
|
||||||
private final IBlockState block;
|
private final BlockState block;
|
||||||
private final ITurtleUpgrade upgrade;
|
private final ITurtleUpgrade upgrade;
|
||||||
private final TurtleSide side;
|
private final TurtleSide side;
|
||||||
|
|
||||||
public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
|
public Dig( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState block, @Nonnull ITurtleUpgrade upgrade, @Nonnull TurtleSide side )
|
||||||
{
|
{
|
||||||
super( turtle, TurtleAction.DIG, player, world, pos );
|
super( turtle, TurtleAction.DIG, player, world, pos );
|
||||||
|
|
||||||
@@ -106,7 +105,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
* @return The block which is going to be broken.
|
* @return The block which is going to be broken.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public IBlockState getBlock()
|
public BlockState getBlock()
|
||||||
{
|
{
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
@@ -185,10 +184,10 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
*/
|
*/
|
||||||
public static class Inspect extends TurtleBlockEvent
|
public static class Inspect extends TurtleBlockEvent
|
||||||
{
|
{
|
||||||
private final IBlockState state;
|
private final BlockState state;
|
||||||
private final Map<String, Object> data;
|
private final Map<String, Object> data;
|
||||||
|
|
||||||
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull IBlockState state, @Nonnull Map<String, Object> data )
|
public Inspect( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull Map<String, Object> data )
|
||||||
{
|
{
|
||||||
super( turtle, TurtleAction.INSPECT, player, world, pos );
|
super( turtle, TurtleAction.INSPECT, player, world, pos );
|
||||||
|
|
||||||
@@ -204,7 +203,7 @@ public abstract class TurtleBlockEvent extends TurtlePlayerEvent
|
|||||||
* @return The inspected block state.
|
* @return The inspected block state.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public IBlockState getState()
|
public BlockState getState()
|
||||||
{
|
{
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
package dan200.computercraft.api.turtle.event;
|
package dan200.computercraft.api.turtle.event;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.EventBus;
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
import net.minecraftforge.eventbus.api.Event;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -20,8 +20,10 @@ import java.util.Objects;
|
|||||||
*
|
*
|
||||||
* @see TurtleActionEvent
|
* @see TurtleActionEvent
|
||||||
*/
|
*/
|
||||||
public abstract class TurtleEvent extends Event
|
public abstract class TurtleEvent
|
||||||
{
|
{
|
||||||
|
public static final EventBus EVENT_BUS = new EventBus();
|
||||||
|
|
||||||
private final ITurtleAccess turtle;
|
private final ITurtleAccess turtle;
|
||||||
|
|
||||||
protected TurtleEvent( @Nonnull ITurtleAccess turtle )
|
protected TurtleEvent( @Nonnull ITurtleAccess turtle )
|
||||||
@@ -40,4 +42,10 @@ public abstract class TurtleEvent extends Event
|
|||||||
{
|
{
|
||||||
return turtle;
|
return turtle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean post( TurtleActionEvent event )
|
||||||
|
{
|
||||||
|
EVENT_BUS.post( event );
|
||||||
|
return event.isCancelled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package dan200.computercraft.api.turtle.event;
|
package dan200.computercraft.api.turtle.event;
|
||||||
|
|
||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
|
|||||||
@@ -7,11 +7,10 @@
|
|||||||
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.minecraft.inventory.Inventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.FakePlayer;
|
|
||||||
import net.minecraftforge.items.IItemHandler;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -22,9 +21,9 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
||||||
{
|
{
|
||||||
private final IItemHandler handler;
|
private final Inventory handler;
|
||||||
|
|
||||||
protected TurtleInventoryEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler )
|
protected TurtleInventoryEvent( @Nonnull ITurtleAccess turtle, @Nonnull TurtleAction action, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler )
|
||||||
{
|
{
|
||||||
super( turtle, action, player, world, pos );
|
super( turtle, action, player, world, pos );
|
||||||
this.handler = handler;
|
this.handler = handler;
|
||||||
@@ -36,7 +35,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
|||||||
* @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.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public IItemHandler getItemHandler()
|
public Inventory getItemHandler()
|
||||||
{
|
{
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
@@ -48,7 +47,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
|||||||
*/
|
*/
|
||||||
public static class Suck extends TurtleInventoryEvent
|
public static class Suck extends TurtleInventoryEvent
|
||||||
{
|
{
|
||||||
public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler )
|
public Suck( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler )
|
||||||
{
|
{
|
||||||
super( turtle, TurtleAction.SUCK, player, world, pos, handler );
|
super( turtle, TurtleAction.SUCK, player, world, pos, handler );
|
||||||
}
|
}
|
||||||
@@ -63,7 +62,7 @@ public abstract class TurtleInventoryEvent extends TurtleBlockEvent
|
|||||||
{
|
{
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
|
|
||||||
public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable IItemHandler handler, @Nonnull ItemStack stack )
|
public Drop( @Nonnull ITurtleAccess turtle, @Nonnull FakePlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nullable Inventory handler, @Nonnull ItemStack stack )
|
||||||
{
|
{
|
||||||
super( turtle, TurtleAction.DROP, player, world, pos, handler );
|
super( turtle, TurtleAction.DROP, player, world, pos, handler );
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
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.common.util.FakePlayer;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of the public ComputerCraft API - http://www.computercraft.info
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. This API may be redistributed unmodified and in full only.
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
* For help using the API, and posting your mods, visit the forums at computercraft.info.
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package dan200.computercraft.api.turtle.event;
|
package dan200.computercraft.api.turtle.event;
|
||||||
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleAccess;
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
||||||
|
|||||||
@@ -7,36 +7,23 @@
|
|||||||
package dan200.computercraft.client;
|
package dan200.computercraft.client;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.client.render.TurtleModelLoader;
|
|
||||||
import dan200.computercraft.shared.common.IColouredItem;
|
import dan200.computercraft.shared.common.IColouredItem;
|
||||||
import dan200.computercraft.shared.media.items.ItemDisk;
|
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.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.fabricmc.fabric.api.client.render.ColorProviderRegistry;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.client.render.model.ModelLoader;
|
||||||
import net.minecraft.client.renderer.model.ModelRotation;
|
import net.minecraft.client.render.model.ModelRotation;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.render.model.UnbakedModel;
|
||||||
import net.minecraft.resources.IResourceManager;
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.ColorHandlerEvent;
|
|
||||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
|
||||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
|
||||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
|
||||||
import net.minecraftforge.client.model.ModelLoader;
|
|
||||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
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 )
|
|
||||||
public final class ClientRegistry
|
public final class ClientRegistry
|
||||||
{
|
{
|
||||||
private static final String[] EXTRA_MODELS = new String[] {
|
private static final String[] EXTRA_MODELS = new String[] {
|
||||||
@@ -70,37 +57,38 @@ public final class ClientRegistry
|
|||||||
|
|
||||||
private ClientRegistry() {}
|
private ClientRegistry() {}
|
||||||
|
|
||||||
@SubscribeEvent
|
/*
|
||||||
|
TODO: @SubscribeEvent
|
||||||
public static void registerModels( ModelRegistryEvent event )
|
public static void registerModels( ModelRegistryEvent event )
|
||||||
{
|
{
|
||||||
ModelLoaderRegistry.registerLoader( TurtleModelLoader.INSTANCE );
|
ModelLoaderRegistry.registerLoader( TurtleModelLoader.INSTANCE );
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
TODO: @SubscribeEvent
|
||||||
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
||||||
{
|
{
|
||||||
IResourceManager manager = Minecraft.getInstance().getResourceManager();
|
ResourceManager manager = MinecraftClient.getInstance().getResourceManager();
|
||||||
for( String extra : EXTRA_TEXTURES )
|
for( String extra : EXTRA_TEXTURES )
|
||||||
{
|
{
|
||||||
event.getMap().registerSprite( manager, new ResourceLocation( ComputerCraft.MOD_ID, extra ) );
|
event.getMap().registerSprite( manager, new Identifier( ComputerCraft.MOD_ID, extra ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
TODO: @SubscribeEvent
|
||||||
public static void onModelBakeEvent( ModelBakeEvent event )
|
public static void onModelBakeEvent( ModelBakeEvent event )
|
||||||
{
|
{
|
||||||
// Load all extra models
|
// Load all extra models
|
||||||
ModelLoader loader = event.getModelLoader();
|
ModelLoader loader = event.getModelLoader();
|
||||||
Map<ModelResourceLocation, IBakedModel> registry = event.getModelRegistry();
|
Map<ModelIdentifier, BakedModel> registry = event.getModelRegistry();
|
||||||
|
|
||||||
for( String model : EXTRA_MODELS )
|
for( String model : EXTRA_MODELS )
|
||||||
{
|
{
|
||||||
IBakedModel bakedModel = bake( loader, loader.getUnbakedModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/" + model ) ) );
|
BakedModel bakedModel = bake( loader, loader.getOrLoadModel( new Identifier( ComputerCraft.MOD_ID, "item/" + model ) ) );
|
||||||
|
|
||||||
if( bakedModel != null )
|
if( bakedModel != null )
|
||||||
{
|
{
|
||||||
registry.put(
|
registry.put(
|
||||||
new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, model ), "inventory" ),
|
new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, model ), "inventory" ),
|
||||||
bakedModel
|
bakedModel
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -108,31 +96,25 @@ public final class ClientRegistry
|
|||||||
|
|
||||||
// And load the custom turtle models in too.
|
// And load the custom turtle models in too.
|
||||||
registry.put(
|
registry.put(
|
||||||
new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_normal" ), "inventory" ),
|
new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, "turtle_normal" ), "inventory" ),
|
||||||
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/turtle_normal" ) ) )
|
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new Identifier( ComputerCraft.MOD_ID, "item/turtle_normal" ) ) )
|
||||||
);
|
);
|
||||||
|
|
||||||
registry.put(
|
registry.put(
|
||||||
new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_advanced" ), "inventory" ),
|
new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, "turtle_advanced" ), "inventory" ),
|
||||||
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new ResourceLocation( ComputerCraft.MOD_ID, "item/turtle_advanced" ) ) )
|
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new Identifier( ComputerCraft.MOD_ID, "item/turtle_advanced" ) ) )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@SubscribeEvent
|
public static void onItemColours()
|
||||||
public static void onItemColours( ColorHandlerEvent.Item event )
|
|
||||||
{
|
{
|
||||||
if( ComputerCraft.Items.disk == null || ComputerCraft.Blocks.turtleNormal == null )
|
ColorProviderRegistry.ITEM.register(
|
||||||
{
|
|
||||||
ComputerCraft.log.warn( "Block/item registration has failed. Skipping registration of item colours." );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.getItemColors().register(
|
|
||||||
( stack, layer ) -> layer == 1 ? ((ItemDisk) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
( stack, layer ) -> layer == 1 ? ((ItemDisk) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
||||||
ComputerCraft.Items.disk
|
ComputerCraft.Items.disk
|
||||||
);
|
);
|
||||||
|
|
||||||
event.getItemColors().register( ( stack, layer ) -> {
|
ColorProviderRegistry.ITEM.register( ( stack, layer ) -> {
|
||||||
switch( layer )
|
switch( layer )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -149,20 +131,16 @@ public final class ClientRegistry
|
|||||||
}, ComputerCraft.Items.pocketComputerNormal, ComputerCraft.Items.pocketComputerAdvanced );
|
}, ComputerCraft.Items.pocketComputerNormal, ComputerCraft.Items.pocketComputerAdvanced );
|
||||||
|
|
||||||
// Setup turtle colours
|
// Setup turtle colours
|
||||||
event.getItemColors().register(
|
ColorProviderRegistry.ITEM.register(
|
||||||
( stack, tintIndex ) -> tintIndex == 0 ? ((IColouredItem) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
( stack, tintIndex ) -> tintIndex == 0 ? ((IColouredItem) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
||||||
ComputerCraft.Blocks.turtleNormal, ComputerCraft.Blocks.turtleAdvanced
|
ComputerCraft.Blocks.turtleNormal, ComputerCraft.Blocks.turtleAdvanced
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IBakedModel bake( ModelLoader loader, IUnbakedModel model )
|
private static BakedModel bake( ModelLoader loader, UnbakedModel model )
|
||||||
{
|
{
|
||||||
model.getTextures( loader::getUnbakedModel, new HashSet<>() );
|
model.getTextureDependencies( loader::getOrLoadModel, new HashSet<>() );
|
||||||
|
SpriteAtlasTexture sprite = MinecraftClient.getInstance().getSpriteAtlas();
|
||||||
return model.bake(
|
return model.bake( loader, sprite::getSprite, ModelRotation.X0_Y0 );
|
||||||
loader::getUnbakedModel,
|
|
||||||
ModelLoader.defaultTextureGetter(),
|
|
||||||
ModelRotation.X0_Y0, false, DefaultVertexFormats.BLOCK
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,13 @@ import dan200.computercraft.shared.command.text.ChatHelpers;
|
|||||||
import dan200.computercraft.shared.command.text.TableBuilder;
|
import dan200.computercraft.shared.command.text.TableBuilder;
|
||||||
import dan200.computercraft.shared.command.text.TableFormatter;
|
import dan200.computercraft.shared.command.text.TableFormatter;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.font.TextRenderer;
|
||||||
import net.minecraft.client.gui.GuiNewChat;
|
import net.minecraft.client.gui.hud.ChatHud;
|
||||||
import net.minecraft.client.gui.GuiUtilRenderComponents;
|
import net.minecraft.client.util.TextComponentUtil;
|
||||||
|
import net.minecraft.text.TextComponent;
|
||||||
|
import net.minecraft.text.TextFormat;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -28,25 +28,25 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
|
|
||||||
private static Int2IntOpenHashMap lastHeights = new Int2IntOpenHashMap();
|
private static Int2IntOpenHashMap lastHeights = new Int2IntOpenHashMap();
|
||||||
|
|
||||||
private static FontRenderer renderer()
|
private static TextRenderer renderer()
|
||||||
{
|
{
|
||||||
return Minecraft.getInstance().fontRenderer;
|
return MinecraftClient.getInstance().textRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ITextComponent getPadding( ITextComponent component, int width )
|
public TextComponent getPadding( TextComponent component, int width )
|
||||||
{
|
{
|
||||||
int extraWidth = width - getWidth( component );
|
int extraWidth = width - getWidth( component );
|
||||||
if( extraWidth <= 0 ) return null;
|
if( extraWidth <= 0 ) return null;
|
||||||
|
|
||||||
FontRenderer renderer = renderer();
|
TextRenderer 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);
|
||||||
|
|
||||||
return ChatHelpers.coloured( StringUtils.repeat( ' ', spaces ) + StringUtils.repeat( (char) 712, extra ), TextFormatting.GRAY );
|
return ChatHelpers.coloured( StringUtils.repeat( ' ', spaces ) + StringUtils.repeat( (char) 712, extra ), TextFormat.GRAY );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,34 +56,34 @@ public class ClientTableFormatter implements TableFormatter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getWidth( ITextComponent component )
|
public int getWidth( TextComponent component )
|
||||||
{
|
{
|
||||||
return renderer().getStringWidth( component.getFormattedText() );
|
return renderer().getStringWidth( component.getFormattedText() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeLine( int id, ITextComponent component )
|
public void writeLine( int id, TextComponent component )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getInstance();
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
GuiNewChat chat = mc.ingameGUI.getChatGUI();
|
ChatHud chat = mc.inGameHud.getChatHud();
|
||||||
|
|
||||||
// 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.getWidth() / chat.getScale() );
|
||||||
List<ITextComponent> list = GuiUtilRenderComponents.splitText( component, maxWidth, mc.fontRenderer, false, false );
|
List<TextComponent> list = TextComponentUtil.wrapLines( component, maxWidth, mc.textRenderer, false, false );
|
||||||
if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
|
if( !list.isEmpty() ) chat.addMessage( list.get( 0 ), id );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int display( TableBuilder table )
|
public int display( TableBuilder table )
|
||||||
{
|
{
|
||||||
GuiNewChat chat = Minecraft.getInstance().ingameGUI.getChatGUI();
|
ChatHud chat = MinecraftClient.getInstance().inGameHud.getChatHud();
|
||||||
|
|
||||||
int lastHeight = lastHeights.get( table.getId() );
|
int lastHeight = lastHeights.get( table.getId() );
|
||||||
|
|
||||||
int height = TableFormatter.super.display( table );
|
int height = TableFormatter.super.display( table );
|
||||||
lastHeights.put( table.getId(), height );
|
lastHeights.put( table.getId(), height );
|
||||||
|
|
||||||
for( int i = height; i < lastHeight; i++ ) chat.deleteChatLine( i + table.getId() );
|
for( int i = height; i < lastHeight; i++ ) chat.removeMessage( i + table.getId() );
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,6 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client;
|
package dan200.computercraft.client;
|
||||||
|
|
||||||
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.gameevent.TickEvent;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
|
||||||
public final class FrameInfo
|
public final class FrameInfo
|
||||||
{
|
{
|
||||||
private static int tick;
|
private static int tick;
|
||||||
@@ -32,15 +25,13 @@ public final class FrameInfo
|
|||||||
return renderFrame;
|
return renderFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
public static void onTick()
|
||||||
public static void onTick( TickEvent.ClientTickEvent event )
|
|
||||||
{
|
{
|
||||||
if( event.phase == TickEvent.Phase.START ) tick++;
|
tick++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
public static void onRenderFrame()
|
||||||
public static void onRenderTick( TickEvent.RenderTickEvent event )
|
|
||||||
{
|
{
|
||||||
if( event.phase == TickEvent.Phase.START ) renderFrame++;
|
renderFrame++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,23 +6,23 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.render.Tessellator;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.renderer.texture.TextureManager;
|
import net.minecraft.client.texture.TextureManager;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public final class FixedWidthFontRenderer
|
public final class FixedWidthFontRenderer
|
||||||
{
|
{
|
||||||
private static final ResourceLocation FONT = new ResourceLocation( "computercraft", "textures/gui/term_font.png" );
|
private static final Identifier FONT = new Identifier( "computercraft", "textures/gui/term_font.png" );
|
||||||
public static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/term_background.png" );
|
public static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/term_background.png" );
|
||||||
|
|
||||||
public static final int FONT_HEIGHT = 9;
|
public static final int FONT_HEIGHT = 9;
|
||||||
public static final int FONT_WIDTH = 6;
|
public static final int FONT_WIDTH = 6;
|
||||||
@@ -39,7 +39,7 @@ public final class FixedWidthFontRenderer
|
|||||||
|
|
||||||
private FixedWidthFontRenderer()
|
private FixedWidthFontRenderer()
|
||||||
{
|
{
|
||||||
m_textureManager = Minecraft.getInstance().getTextureManager();
|
m_textureManager = MinecraftClient.getInstance().getTextureManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void greyscaleify( double[] rgb )
|
private static void greyscaleify( double[] rgb )
|
||||||
@@ -64,12 +64,12 @@ public final class FixedWidthFontRenderer
|
|||||||
int xStart = 1 + column * (FONT_WIDTH + 2);
|
int xStart = 1 + column * (FONT_WIDTH + 2);
|
||||||
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
||||||
|
|
||||||
renderer.pos( x, y, 0.0 ).tex( xStart / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x, y, 0.0 ).texture( xStart / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).texture( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x + FONT_WIDTH, y, 0.0 ).texture( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x + FONT_WIDTH, y, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x + FONT_WIDTH, y, 0.0 ).texture( (xStart + FONT_WIDTH) / 256.0, yStart / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).tex( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).texture( xStart / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).tex( (xStart + FONT_WIDTH) / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x + FONT_WIDTH, y + FONT_HEIGHT, 0.0 ).texture( (xStart + FONT_WIDTH) / 256.0, (yStart + FONT_HEIGHT) / 256.0 ).color( r, g, b, 1.0f ).next();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawQuad( BufferBuilder renderer, double x, double y, int color, double width, Palette p, boolean greyscale )
|
private void drawQuad( BufferBuilder renderer, double x, double y, int color, double width, Palette p, boolean greyscale )
|
||||||
@@ -83,12 +83,12 @@ public final class FixedWidthFontRenderer
|
|||||||
float g = (float) colour[1];
|
float g = (float) colour[1];
|
||||||
float b = (float) colour[2];
|
float b = (float) colour[2];
|
||||||
|
|
||||||
renderer.pos( x, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x, y, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x + width, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x + width, y, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x + width, y, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x + width, y, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( x + width, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( x + width, y + FONT_HEIGHT, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isGreyScale( int colour )
|
private boolean isGreyScale( int colour )
|
||||||
@@ -100,8 +100,8 @@ public final class FixedWidthFontRenderer
|
|||||||
{
|
{
|
||||||
// Draw the quads
|
// Draw the quads
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder renderer = tessellator.getBuffer();
|
BufferBuilder renderer = tessellator.getBufferBuilder();
|
||||||
renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR );
|
renderer.begin( GL11.GL_TRIANGLES, VertexFormats.POSITION_COLOR );
|
||||||
if( leftMarginSize > 0.0 )
|
if( leftMarginSize > 0.0 )
|
||||||
{
|
{
|
||||||
int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) );
|
int colour1 = "0123456789abcdef".indexOf( backgroundColour.charAt( 0 ) );
|
||||||
@@ -129,17 +129,17 @@ public final class FixedWidthFontRenderer
|
|||||||
}
|
}
|
||||||
drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH, p, greyScale );
|
drawQuad( renderer, x + i * FONT_WIDTH, y, colour, FONT_WIDTH, p, greyScale );
|
||||||
}
|
}
|
||||||
GlStateManager.disableTexture2D();
|
GlStateManager.disableTexture();
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale, Palette p )
|
public void drawStringTextPart( int x, int y, TextBuffer s, TextBuffer textColour, boolean greyScale, Palette p )
|
||||||
{
|
{
|
||||||
// Draw the quads
|
// Draw the quads
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder renderer = tessellator.getBuffer();
|
BufferBuilder renderer = tessellator.getBufferBuilder();
|
||||||
renderer.begin( GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_TEX_COLOR );
|
renderer.begin( GL11.GL_TRIANGLES, VertexFormats.POSITION_UV_COLOR );
|
||||||
for( int i = 0; i < s.length(); i++ )
|
for( int i = 0; i < s.length(); i++ )
|
||||||
{
|
{
|
||||||
// Switch colour
|
// Switch colour
|
||||||
@@ -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.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
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.client.gui.widgets.WidgetWrapper;
|
||||||
@@ -13,17 +14,17 @@ 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.inventory.ContainerComputer;
|
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.ContainerScreen;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.container.Container;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.text.StringTextComponent;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class GuiComputer extends GuiContainer
|
public class GuiComputer<T extends Container> extends ContainerScreen<T>
|
||||||
{
|
{
|
||||||
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_normal.png" );
|
private static final Identifier BACKGROUND_NORMAL = new Identifier( "computercraft", "textures/gui/corners_normal.png" );
|
||||||
public static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_advanced.png" );
|
private static final Identifier BACKGROUND_ADVANCED = new Identifier( "computercraft", "textures/gui/corners_advanced.png" );
|
||||||
public static final ResourceLocation BACKGROUND_COMMAND = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_command.png" );
|
private static final Identifier BACKGROUND_COMMAND = new Identifier( "computercraft", "textures/gui/corners_command.png" );
|
||||||
public static final ResourceLocation BACKGROUND_COLOUR = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners_colour.png" );
|
|
||||||
|
|
||||||
private final ComputerFamily m_family;
|
private final ComputerFamily m_family;
|
||||||
private final ClientComputer m_computer;
|
private final ClientComputer m_computer;
|
||||||
@@ -33,9 +34,11 @@ public class GuiComputer extends GuiContainer
|
|||||||
private WidgetTerminal terminal;
|
private WidgetTerminal terminal;
|
||||||
private WidgetWrapper terminalWrapper;
|
private WidgetWrapper terminalWrapper;
|
||||||
|
|
||||||
public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
|
||||||
|
public GuiComputer( T container, PlayerInventory player, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
||||||
{
|
{
|
||||||
super( container );
|
super( container, player, new StringTextComponent( "" ) );
|
||||||
|
|
||||||
m_family = family;
|
m_family = family;
|
||||||
m_computer = computer;
|
m_computer = computer;
|
||||||
m_termWidth = termWidth;
|
m_termWidth = termWidth;
|
||||||
@@ -43,10 +46,10 @@ public class GuiComputer extends GuiContainer
|
|||||||
terminal = null;
|
terminal = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuiComputer( TileComputer computer )
|
public static GuiComputer<ContainerComputer> create( int id, TileComputer computer, PlayerInventory player )
|
||||||
{
|
{
|
||||||
this(
|
return new GuiComputer<>(
|
||||||
new ContainerComputer( computer ),
|
new ContainerComputer( id, computer ), player,
|
||||||
computer.getFamily(),
|
computer.getFamily(),
|
||||||
computer.createClientComputer(),
|
computer.createClientComputer(),
|
||||||
ComputerCraft.terminalWidth_computer,
|
ComputerCraft.terminalWidth_computer,
|
||||||
@@ -55,32 +58,32 @@ public class GuiComputer extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initGui()
|
protected void init()
|
||||||
{
|
{
|
||||||
mc.keyboardListener.enableRepeatEvents( true );
|
minecraft.keyboard.enableRepeatEvents( true );
|
||||||
|
|
||||||
int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
|
||||||
xSize = termPxWidth + 4 + 24;
|
containerWidth = termPxWidth + 4 + 24;
|
||||||
ySize = termPxHeight + 4 + 24;
|
containerHeight = termPxHeight + 4 + 24;
|
||||||
|
|
||||||
super.initGui();
|
super.init();
|
||||||
|
|
||||||
terminal = new WidgetTerminal( mc, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
|
terminal = new WidgetTerminal( minecraft, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
|
||||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + guiLeft, 2 + 12 + guiTop, termPxWidth, termPxHeight );
|
terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + left, 2 + 12 + top, termPxWidth, termPxHeight );
|
||||||
|
|
||||||
children.add( terminalWrapper );
|
children.add( terminalWrapper );
|
||||||
setFocused( terminalWrapper );
|
setFocused( terminalWrapper );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed()
|
public void removed()
|
||||||
{
|
{
|
||||||
super.onGuiClosed();
|
super.removed();
|
||||||
children.remove( terminal );
|
children.remove( terminal );
|
||||||
terminal = null;
|
terminal = null;
|
||||||
mc.keyboardListener.enableRepeatEvents( false );
|
minecraft.keyboard.enableRepeatEvents( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,7 +94,7 @@ public class GuiComputer extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
public void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
// Work out where to draw
|
// Work out where to draw
|
||||||
int startX = terminalWrapper.getX() - 2;
|
int startX = terminalWrapper.getX() - 2;
|
||||||
@@ -108,34 +111,34 @@ public class GuiComputer extends GuiContainer
|
|||||||
{
|
{
|
||||||
case Normal:
|
case Normal:
|
||||||
default:
|
default:
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND_NORMAL );
|
minecraft.getTextureManager().bindTexture( BACKGROUND_NORMAL );
|
||||||
break;
|
break;
|
||||||
case Advanced:
|
case Advanced:
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
|
minecraft.getTextureManager().bindTexture( BACKGROUND_ADVANCED );
|
||||||
break;
|
break;
|
||||||
case Command:
|
case Command:
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND_COMMAND );
|
minecraft.getTextureManager().bindTexture( BACKGROUND_COMMAND );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
drawTexturedModalRect( startX - 12, startY - 12, 12, 28, 12, 12 );
|
blit( startX - 12, startY - 12, 12, 28, 12, 12 );
|
||||||
drawTexturedModalRect( startX - 12, endY, 12, 40, 12, 12 );
|
blit( startX - 12, endY, 12, 40, 12, 16 );
|
||||||
drawTexturedModalRect( endX, startY - 12, 24, 28, 12, 12 );
|
blit( endX, startY - 12, 24, 28, 12, 12 );
|
||||||
drawTexturedModalRect( endX, endY, 24, 40, 12, 12 );
|
blit( endX, endY, 24, 40, 12, 16 );
|
||||||
|
|
||||||
drawTexturedModalRect( startX, startY - 12, 0, 0, endX - startX, 12 );
|
blit( startX, startY - 12, 0, 0, endX - startX, 12 );
|
||||||
drawTexturedModalRect( startX, endY, 0, 12, endX - startX, 12 );
|
blit( startX, endY, 0, 12, endX - startX, 16 );
|
||||||
|
|
||||||
drawTexturedModalRect( startX - 12, startY, 0, 28, 12, endY - startY );
|
blit( startX - 12, startY, 0, 28, 12, endY - startY );
|
||||||
drawTexturedModalRect( endX, startY, 36, 28, 12, endY - startY );
|
blit( endX, startY, 36, 28, 12, endY - startY );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
renderBackground( 0 );
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,45 +6,44 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.ContainerScreen;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class GuiDiskDrive extends GuiContainer
|
public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
|
private static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/disk_drive.png" );
|
||||||
|
|
||||||
private final ContainerDiskDrive m_container;
|
public GuiDiskDrive( ContainerDiskDrive container, PlayerInventory inventory )
|
||||||
|
|
||||||
public GuiDiskDrive( ContainerDiskDrive container )
|
|
||||||
{
|
{
|
||||||
super( container );
|
super( container, inventory, ComputerCraft.Blocks.diskDrive.getTextComponent() );
|
||||||
m_container = container;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
protected void drawForeground( int par1, int par2 )
|
||||||
{
|
{
|
||||||
String title = m_container.getDiskDrive().getDisplayName().getString();
|
String title = getTitle().getFormattedText();
|
||||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
font.draw( title, (containerWidth - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
||||||
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
font.draw( I18n.translate( "container.inventory" ), 8, (containerHeight - 96) + 2, 0x404040 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND );
|
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
blit( left, top, 0, 0, containerWidth, containerHeight );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
renderBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,15 +10,16 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class GuiPocketComputer extends GuiComputer
|
public class GuiPocketComputer extends GuiComputer<ContainerPocketComputer>
|
||||||
{
|
{
|
||||||
public GuiPocketComputer( ContainerPocketComputer container )
|
public GuiPocketComputer( ContainerPocketComputer container, PlayerInventory player )
|
||||||
{
|
{
|
||||||
super(
|
super(
|
||||||
container,
|
container, player,
|
||||||
getFamily( container.getStack() ),
|
getFamily( container.getStack() ),
|
||||||
ItemPocketComputer.createClientComputer( container.getStack() ),
|
ItemPocketComputer.createClientComputer( container.getStack() ),
|
||||||
ComputerCraft.terminalWidth_pocketComputer,
|
ComputerCraft.terminalWidth_pocketComputer,
|
||||||
|
|||||||
@@ -6,47 +6,46 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.ContainerScreen;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.resource.language.I18n;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class GuiPrinter extends GuiContainer
|
public class GuiPrinter extends ContainerScreen<ContainerPrinter>
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
private static final Identifier BACKGROUND = new Identifier( "computercraft", "textures/gui/printer.png" );
|
||||||
|
|
||||||
private final ContainerPrinter container;
|
public GuiPrinter( ContainerPrinter container, PlayerInventory player )
|
||||||
|
|
||||||
public GuiPrinter( ContainerPrinter container )
|
|
||||||
{
|
{
|
||||||
super( container );
|
super( container, player, ComputerCraft.Blocks.printer.getTextComponent() );
|
||||||
this.container = container;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
protected void drawForeground( int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
String title = container.getPrinter().getDisplayName().getString();
|
String title = getTitle().getFormattedText();
|
||||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
font.draw( title, (containerWidth - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
||||||
fontRenderer.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
font.draw( I18n.translate( "container.inventory" ), 8, containerHeight - 96 + 2, 0x404040 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void drawBackground( float f, int i, int j )
|
||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND );
|
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
blit( left, top, 0, 0, containerWidth, containerHeight );
|
||||||
|
|
||||||
if( container.isPrinting() ) drawTexturedModalRect( guiLeft + 34, guiTop + 21, 176, 0, 25, 45 );
|
if( container.isPrinting() ) blit( left + 34, top + 21, 176, 0, 25, 45 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
renderBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,17 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
import dan200.computercraft.shared.common.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.ContainerScreen;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||||
|
|
||||||
public class GuiPrintout extends GuiContainer
|
public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||||
{
|
{
|
||||||
private final boolean m_book;
|
private final boolean m_book;
|
||||||
private final int m_pages;
|
private final int m_pages;
|
||||||
@@ -23,11 +24,11 @@ public class GuiPrintout extends GuiContainer
|
|||||||
private final TextBuffer[] m_colours;
|
private final TextBuffer[] m_colours;
|
||||||
private int m_page;
|
private int m_page;
|
||||||
|
|
||||||
public GuiPrintout( ContainerHeldItem container )
|
public GuiPrintout( ContainerHeldItem container, PlayerInventory player )
|
||||||
{
|
{
|
||||||
super( container );
|
super( container, player, container.getStack().getDisplayName() );
|
||||||
|
|
||||||
ySize = Y_SIZE;
|
containerHeight = Y_SIZE;
|
||||||
|
|
||||||
String[] text = ItemPrintout.getText( container.getStack() );
|
String[] text = ItemPrintout.getText( container.getStack() );
|
||||||
m_text = new TextBuffer[text.length];
|
m_text = new TextBuffer[text.length];
|
||||||
@@ -63,9 +64,9 @@ public class GuiPrintout extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled( double delta )
|
public boolean mouseScrolled( double x, double y, double delta )
|
||||||
{
|
{
|
||||||
if( super.mouseScrolled( delta ) ) return true;
|
if( super.mouseScrolled( x, y, delta ) ) return true;
|
||||||
if( delta < 0 )
|
if( delta < 0 )
|
||||||
{
|
{
|
||||||
// Scroll up goes to the next page
|
// Scroll up goes to the next page
|
||||||
@@ -84,25 +85,25 @@ public class GuiPrintout extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
public void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
// Draw the printout
|
// Draw the printout
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.enableDepthTest();
|
GlStateManager.enableDepthTest();
|
||||||
|
|
||||||
drawBorder( guiLeft, guiTop, zLevel, m_page, m_pages, m_book );
|
drawBorder( left, top, blitOffset, 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( left + X_TEXT_MARGIN, top + 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 render( 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--;
|
blitOffset--;
|
||||||
drawDefaultBackground();
|
renderBackground();
|
||||||
zLevel++;
|
blitOffset++;
|
||||||
|
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
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.client.gui.widgets.WidgetWrapper;
|
||||||
@@ -13,14 +14,14 @@ 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.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.ContainerScreen;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
public class GuiTurtle extends GuiContainer
|
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" );
|
private static final Identifier BACKGROUND_NORMAL = new Identifier( "computercraft", "textures/gui/turtle_normal.png" );
|
||||||
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
|
private static final Identifier BACKGROUND_ADVANCED = new Identifier( "computercraft", "textures/gui/turtle_advanced.png" );
|
||||||
|
|
||||||
private ContainerTurtle m_container;
|
private ContainerTurtle m_container;
|
||||||
|
|
||||||
@@ -30,45 +31,46 @@ public class GuiTurtle extends GuiContainer
|
|||||||
private WidgetTerminal terminal;
|
private WidgetTerminal terminal;
|
||||||
private WidgetWrapper terminalWrapper;
|
private WidgetWrapper terminalWrapper;
|
||||||
|
|
||||||
public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
|
public GuiTurtle( TileTurtle turtle, ContainerTurtle container, PlayerInventory player )
|
||||||
{
|
{
|
||||||
super( container );
|
super( container, player, turtle.getDisplayName() );
|
||||||
|
|
||||||
m_container = container;
|
m_container = container;
|
||||||
m_family = turtle.getFamily();
|
m_family = turtle.getFamily();
|
||||||
m_computer = turtle.getClientComputer();
|
m_computer = turtle.getClientComputer();
|
||||||
|
|
||||||
xSize = 254;
|
containerWidth = 254;
|
||||||
ySize = 217;
|
containerHeight = 217;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void initGui()
|
protected void init()
|
||||||
{
|
{
|
||||||
super.initGui();
|
super.init();
|
||||||
mc.keyboardListener.enableRepeatEvents( true );
|
minecraft.keyboard.enableRepeatEvents( true );
|
||||||
|
|
||||||
int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
|
int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
|
int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
|
||||||
terminal = new WidgetTerminal(
|
terminal = new WidgetTerminal(
|
||||||
mc, () -> m_computer,
|
minecraft, () -> m_computer,
|
||||||
ComputerCraft.terminalWidth_turtle,
|
ComputerCraft.terminalWidth_turtle,
|
||||||
ComputerCraft.terminalHeight_turtle,
|
ComputerCraft.terminalHeight_turtle,
|
||||||
2, 2, 2, 2
|
2, 2, 2, 2
|
||||||
);
|
);
|
||||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + guiLeft, 2 + 8 + guiTop, termPxWidth, termPxHeight );
|
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + left, 2 + 8 + top, termPxWidth, termPxHeight );
|
||||||
|
|
||||||
children.add( terminalWrapper );
|
children.add( terminalWrapper );
|
||||||
setFocused( terminalWrapper );
|
setFocused( terminalWrapper );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed()
|
public void removed()
|
||||||
{
|
{
|
||||||
|
super.removed();
|
||||||
children.remove( terminal );
|
children.remove( terminal );
|
||||||
terminal = null;
|
terminal = null;
|
||||||
mc.keyboardListener.enableRepeatEvents( false );
|
minecraft.keyboard.enableRepeatEvents( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,13 +89,13 @@ public class GuiTurtle extends GuiContainer
|
|||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color4f( 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 );
|
minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||||
drawTexturedModalRect( guiLeft + m_container.turtleInvStartX - 2 + slotX * 18, guiTop + m_container.playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
|
blit( left + m_container.m_turtleInvStartX - 2 + slotX * 18, top + m_container.m_playerInvStartY - 2 + slotY * 18, 0, 217, 24, 24 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
protected void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
// Draw term
|
// Draw term
|
||||||
boolean advanced = m_family == ComputerFamily.Advanced;
|
boolean advanced = m_family == ComputerFamily.Advanced;
|
||||||
@@ -101,8 +103,8 @@ public class GuiTurtle extends GuiContainer
|
|||||||
|
|
||||||
// Draw border/inventory
|
// Draw border/inventory
|
||||||
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
mc.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
minecraft.getTextureManager().bindTexture( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||||
drawTexturedModalRect( guiLeft, guiTop, 0, 0, xSize, ySize );
|
blit( left, top, 0, 0, containerWidth, containerHeight );
|
||||||
|
|
||||||
drawSelectionSlot( advanced );
|
drawSelectionSlot( advanced );
|
||||||
}
|
}
|
||||||
@@ -110,8 +112,8 @@ public class GuiTurtle extends GuiContainer
|
|||||||
@Override
|
@Override
|
||||||
public void render( int mouseX, int mouseY, float partialTicks )
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
renderBackground();
|
||||||
super.render( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui.widgets;
|
package dan200.computercraft.client.gui.widgets;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.client.FrameInfo;
|
import dan200.computercraft.client.FrameInfo;
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
@@ -14,13 +15,12 @@ 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.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.SharedConstants;
|
||||||
import net.minecraft.client.gui.IGuiEventListener;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.gui.Element;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.render.Tessellator;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.util.SharedConstants;
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
@@ -29,16 +29,18 @@ 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 implements Element
|
||||||
{
|
{
|
||||||
private static final float TERMINATE_TIME = 0.5f;
|
private static final float TERMINATE_TIME = 0.5f;
|
||||||
|
|
||||||
private final Minecraft client;
|
private final MinecraftClient minecraft;
|
||||||
|
|
||||||
private final Supplier<ClientComputer> computer;
|
private final Supplier<ClientComputer> computer;
|
||||||
private final int termWidth;
|
private final int termWidth;
|
||||||
private final int termHeight;
|
private final int termHeight;
|
||||||
|
|
||||||
|
private boolean focused;
|
||||||
|
|
||||||
private float terminateTimer = -1;
|
private float terminateTimer = -1;
|
||||||
private float rebootTimer = -1;
|
private float rebootTimer = -1;
|
||||||
private float shutdownTimer = -1;
|
private float shutdownTimer = -1;
|
||||||
@@ -54,9 +56,9 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
|
|
||||||
private final BitSet keysDown = new BitSet( 256 );
|
private final BitSet keysDown = new BitSet( 256 );
|
||||||
|
|
||||||
public WidgetTerminal( Minecraft client, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
public WidgetTerminal( MinecraftClient minecraft, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.minecraft = minecraft;
|
||||||
this.computer = computer;
|
this.computer = computer;
|
||||||
this.termWidth = termWidth;
|
this.termWidth = termWidth;
|
||||||
this.termHeight = termHeight;
|
this.termHeight = termHeight;
|
||||||
@@ -98,7 +100,7 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
|
|
||||||
case GLFW.GLFW_KEY_V:
|
case GLFW.GLFW_KEY_V:
|
||||||
// Ctrl+V for paste
|
// Ctrl+V for paste
|
||||||
String clipboard = client.keyboardListener.getClipboardString();
|
String clipboard = minecraft.keyboard.getClipboard();
|
||||||
if( clipboard != null )
|
if( clipboard != null )
|
||||||
{
|
{
|
||||||
// Clip to the first occurrence of \r or \n
|
// Clip to the first occurrence of \r or \n
|
||||||
@@ -118,7 +120,7 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Filter the string
|
// Filter the string
|
||||||
clipboard = SharedConstants.filterAllowedCharacters( clipboard );
|
clipboard = SharedConstants.stripInvalidChars( clipboard );
|
||||||
if( !clipboard.isEmpty() )
|
if( !clipboard.isEmpty() )
|
||||||
{
|
{
|
||||||
// Clip to 512 characters and queue the event
|
// Clip to 512 characters and queue the event
|
||||||
@@ -250,14 +252,23 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled( double delta )
|
public boolean mouseScrolled( double mouseX, double mouseY, double delta )
|
||||||
{
|
{
|
||||||
ClientComputer computer = this.computer.get();
|
ClientComputer computer = this.computer.get();
|
||||||
if( computer == null || !computer.isColour() ) return false;
|
if( computer == null || !computer.isColour() || delta == 0 ) return false;
|
||||||
|
|
||||||
if( lastMouseX >= 0 && lastMouseY >= 0 && delta != 0 )
|
Terminal term = computer.getTerminal();
|
||||||
|
if( term != null )
|
||||||
{
|
{
|
||||||
queueEvent( "mouse_scroll", delta < 0 ? 1 : -1, lastMouseX + 1, lastMouseY + 1 );
|
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.mouseScroll( delta < 0 ? 1 : -1, charX + 1, charY + 1 );
|
||||||
|
|
||||||
|
lastMouseX = charX;
|
||||||
|
lastMouseY = charY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -284,9 +295,9 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusChanged( boolean focused )
|
public boolean changeFocus( boolean reverse )
|
||||||
{
|
{
|
||||||
if( !focused )
|
if( focused )
|
||||||
{
|
{
|
||||||
// When blurring, we should make all keys go up
|
// When blurring, we should make all keys go up
|
||||||
for( int key = 0; key < keysDown.size(); key++ )
|
for( int key = 0; key < keysDown.size(); key++ )
|
||||||
@@ -305,6 +316,9 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
|
|
||||||
shutdownTimer = terminateTimer = rebootTimer = -1;
|
shutdownTimer = terminateTimer = rebootTimer = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
focused = !focused;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw( int originX, int originY )
|
public void draw( int originX, int originY )
|
||||||
@@ -384,15 +398,15 @@ public class WidgetTerminal implements IGuiEventListener
|
|||||||
int width = termWidth * FixedWidthFontRenderer.FONT_WIDTH + leftMargin + rightMargin;
|
int width = termWidth * FixedWidthFontRenderer.FONT_WIDTH + leftMargin + rightMargin;
|
||||||
int height = termHeight * FixedWidthFontRenderer.FONT_HEIGHT + topMargin + bottomMargin;
|
int height = termHeight * FixedWidthFontRenderer.FONT_HEIGHT + topMargin + bottomMargin;
|
||||||
|
|
||||||
client.getTextureManager().bindTexture( BACKGROUND );
|
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||||
|
|
||||||
Tessellator tesslector = Tessellator.getInstance();
|
Tessellator tesslector = Tessellator.getInstance();
|
||||||
BufferBuilder buffer = tesslector.getBuffer();
|
BufferBuilder buffer = tesslector.getBufferBuilder();
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX );
|
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_UV );
|
||||||
buffer.pos( x, y + height, 0 ).tex( 0 / 256.0, height / 256.0 ).endVertex();
|
buffer.vertex( x, y + height, 0 ).texture( 0 / 256.0, height / 256.0 ).next();
|
||||||
buffer.pos( x + width, y + height, 0 ).tex( width / 256.0, height / 256.0 ).endVertex();
|
buffer.vertex( x + width, y + height, 0 ).texture( width / 256.0, height / 256.0 ).next();
|
||||||
buffer.pos( x + width, y, 0 ).tex( width / 256.0, 0 / 256.0 ).endVertex();
|
buffer.vertex( x + width, y, 0 ).texture( width / 256.0, 0 / 256.0 ).next();
|
||||||
buffer.pos( x, y, 0 ).tex( 0 / 256.0, 0 / 256.0 ).endVertex();
|
buffer.vertex( x, y, 0 ).texture( 0 / 256.0, 0 / 256.0 ).next();
|
||||||
tesslector.draw();
|
tesslector.draw();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -6,17 +6,17 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.gui.widgets;
|
package dan200.computercraft.client.gui.widgets;
|
||||||
|
|
||||||
import net.minecraft.client.gui.IGuiEventListener;
|
import net.minecraft.client.gui.Element;
|
||||||
|
|
||||||
public class WidgetWrapper implements IGuiEventListener
|
public class WidgetWrapper implements Element
|
||||||
{
|
{
|
||||||
private final IGuiEventListener listener;
|
private final Element listener;
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int y;
|
private final int y;
|
||||||
private final int width;
|
private final int width;
|
||||||
private final int height;
|
private final int height;
|
||||||
|
|
||||||
public WidgetWrapper( IGuiEventListener listener, int x, int y, int width, int height )
|
public WidgetWrapper( Element listener, int x, int y, int width, int height )
|
||||||
{
|
{
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@@ -26,15 +26,16 @@ public class WidgetWrapper implements IGuiEventListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusChanged( boolean b )
|
public void mouseMoved( double x, double y )
|
||||||
{
|
{
|
||||||
listener.focusChanged( b );
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
if( dx >= 0 && dx < width && dy >= 0 && dy < height ) listener.mouseMoved( dx, dy );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canFocus()
|
public boolean changeFocus( boolean reverse )
|
||||||
{
|
{
|
||||||
return listener.canFocus();
|
return listener.changeFocus( reverse );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,9 +60,10 @@ public class WidgetWrapper implements IGuiEventListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseScrolled( double delta )
|
public boolean mouseScrolled( double x, double y, double delta )
|
||||||
{
|
{
|
||||||
return listener.mouseScrolled( delta );
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseScrolled( dx, dy, delta );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,4 +103,11 @@ public class WidgetWrapper implements IGuiEventListener
|
|||||||
{
|
{
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMouseOver( double x, double y )
|
||||||
|
{
|
||||||
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
return dx >= 0 && dx < width && dy >= 0 && dy < height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
package dan200.computercraft.client.proxy;
|
package dan200.computercraft.client.proxy;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.client.ClientRegistry;
|
||||||
import dan200.computercraft.client.gui.*;
|
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;
|
||||||
@@ -16,71 +17,51 @@ import dan200.computercraft.shared.computer.core.ClientComputer;
|
|||||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||||
import dan200.computercraft.shared.network.container.*;
|
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.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
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.fabricmc.fabric.api.client.render.BlockEntityRendererRegistry;
|
||||||
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.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.ExtensionPoint;
|
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
|
||||||
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
|
|
||||||
public final class ComputerCraftProxyClient
|
public final class ComputerCraftProxyClient
|
||||||
{
|
{
|
||||||
@SubscribeEvent
|
public static void setup()
|
||||||
public static void setupClient( FMLClientSetupEvent event )
|
|
||||||
{
|
{
|
||||||
registerContainers();
|
registerContainers();
|
||||||
|
|
||||||
// Setup TESRs
|
// Setup TESRs
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
BlockEntityRendererRegistry.INSTANCE.register( TileMonitor.class, new TileEntityMonitorRenderer() );
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
|
BlockEntityRendererRegistry.INSTANCE.register( TileCable.class, new TileEntityCableRenderer() );
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() );
|
BlockEntityRendererRegistry.INSTANCE.register( TileTurtle.class, new TileEntityTurtleRenderer() );
|
||||||
|
|
||||||
|
ClientRegistry.onItemColours();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerContainers()
|
private static void registerContainers()
|
||||||
{
|
{
|
||||||
ContainerType.registerGui( TileEntityContainerType::computer, ( packet, player ) ->
|
ContainerType.registerGui( TileEntityContainerType::computer, ( id, packet, player ) ->
|
||||||
new GuiComputer( (TileComputer) packet.getTileEntity( player ) ) );
|
GuiComputer.create( id, (TileComputer) packet.getTileEntity( player ), player.inventory ) );
|
||||||
ContainerType.registerGui( TileEntityContainerType::diskDrive, GuiDiskDrive::new );
|
ContainerType.registerGui( TileEntityContainerType::diskDrive, GuiDiskDrive::new );
|
||||||
ContainerType.registerGui( TileEntityContainerType::printer, GuiPrinter::new );
|
ContainerType.registerGui( TileEntityContainerType::printer, GuiPrinter::new );
|
||||||
ContainerType.registerGui( TileEntityContainerType::turtle, ( packet, player ) -> {
|
ContainerType.registerGui( TileEntityContainerType::turtle, ( id, packet, player ) -> {
|
||||||
TileTurtle turtle = (TileTurtle) packet.getTileEntity( player );
|
TileTurtle turtle = (TileTurtle) packet.getTileEntity( player );
|
||||||
return new GuiTurtle( turtle, new ContainerTurtle( player.inventory, turtle.getAccess(), turtle.getClientComputer() ) );
|
return new GuiTurtle( turtle, new ContainerTurtle( id, player.inventory, turtle.getAccess(), turtle.getClientComputer() ), player.inventory );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
ContainerType.registerGui( PocketComputerContainerType::new, GuiPocketComputer::new );
|
ContainerType.registerGui( PocketComputerContainerType::new, GuiPocketComputer::new );
|
||||||
ContainerType.registerGui( PrintoutContainerType::new, GuiPrintout::new );
|
ContainerType.registerGui( PrintoutContainerType::new, GuiPrintout::new );
|
||||||
ContainerType.registerGui( ViewComputerContainerType::new, ( packet, player ) -> {
|
ContainerType.registerGui( ViewComputerContainerType::new, ( id, packet, player ) -> {
|
||||||
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( packet.instanceId );
|
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( packet.instanceId );
|
||||||
if( computer == null )
|
if( computer == null )
|
||||||
{
|
{
|
||||||
ComputerCraft.clientComputerRegistry.add( packet.instanceId, computer = new ClientComputer( packet.instanceId ) );
|
ComputerCraft.clientComputerRegistry.add( packet.instanceId, computer = new ClientComputer( packet.instanceId ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainerViewComputer container = new ContainerViewComputer( computer );
|
ContainerViewComputer container = new ContainerViewComputer( id, computer );
|
||||||
return new GuiComputer( container, packet.family, computer, packet.width, packet.height );
|
return new GuiComputer<>( container, player.inventory, 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 )
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
||||||
public static final class ForgeHandlers
|
public static final class ForgeHandlers
|
||||||
{
|
{
|
||||||
@@ -93,4 +74,5 @@ public final class ComputerCraftProxyClient
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,88 +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.render;
|
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.client.renderer.WorldRenderer;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
|
||||||
public final class CableHighlightRenderer
|
|
||||||
{
|
|
||||||
private CableHighlightRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw an outline for a specific part of a cable "Multipart".
|
|
||||||
*
|
|
||||||
* @param event The event to observe
|
|
||||||
* @see WorldRenderer#drawSelectionBox(EntityPlayer, RayTraceResult, int, float)
|
|
||||||
*/
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void drawHighlight( DrawBlockHighlightEvent event )
|
|
||||||
{
|
|
||||||
if( event.getTarget().type != RayTraceResult.Type.BLOCK ) return;
|
|
||||||
|
|
||||||
BlockPos pos = event.getTarget().getBlockPos();
|
|
||||||
World world = event.getPlayer().getEntityWorld();
|
|
||||||
|
|
||||||
IBlockState state = world.getBlockState( pos );
|
|
||||||
|
|
||||||
// We only care about instances with both cable and modem.
|
|
||||||
if( state.getBlock() != ComputerCraft.Blocks.cable || state.get( BlockCable.MODEM ).getFacing() == null || !state.get( BlockCable.CABLE ) )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCanceled( true );
|
|
||||||
|
|
||||||
EntityPlayer player = event.getPlayer();
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
|
||||||
float partialTicks = event.getPartialTicks();
|
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
|
||||||
GlStateManager.lineWidth( Math.max( 2.5F, mc.mainWindow.getFramebufferWidth() / 1920.0F * 2.5F ) );
|
|
||||||
GlStateManager.disableTexture2D();
|
|
||||||
GlStateManager.depthMask( false );
|
|
||||||
GlStateManager.matrixMode( GL11.GL_PROJECTION );
|
|
||||||
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;
|
|
||||||
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
|
|
||||||
|
|
||||||
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), event.getTarget().hitVec.subtract( pos.getX(), pos.getY(), 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 );
|
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
GlStateManager.matrixMode( GL11.GL_MODELVIEW );
|
|
||||||
GlStateManager.depthMask( true );
|
|
||||||
GlStateManager.enableTexture2D();
|
|
||||||
GlStateManager.disableBlend();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,13 +6,14 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import net.minecraft.client.renderer.FirstPersonRenderer;
|
import dan200.computercraft.shared.mixed.MixedFirstPersonRenderer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.client.render.FirstPersonRenderer;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.AbsoluteHand;
|
||||||
import net.minecraft.util.EnumHandSide;
|
import net.minecraft.util.Hand;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
public abstract class ItemMapLikeRenderer
|
public abstract class ItemMapLikeRenderer
|
||||||
@@ -21,23 +22,23 @@ 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 FirstPersonRenderer#renderFirstPersonMap(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 )
|
public void renderItemFirstPerson( Hand hand, float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
{
|
{
|
||||||
EntityPlayer player = Minecraft.getInstance().player;
|
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
if( hand == EnumHand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
|
if( hand == Hand.MAIN && player.getOffHandStack().isEmpty() )
|
||||||
{
|
{
|
||||||
renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack );
|
renderItemFirstPersonCenter( pitch, equipProgress, swingProgress, stack );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
renderItemFirstPersonSide(
|
renderItemFirstPersonSide(
|
||||||
hand == EnumHand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
|
hand == Hand.MAIN ? player.getMainHand() : player.getMainHand().getOpposite(),
|
||||||
equipProgress, swingProgress, stack
|
equipProgress, swingProgress, stack
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -51,12 +52,12 @@ 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 FirstPersonRenderer#method_3222(float, AbsoluteHand, float, ItemStack) // renderMapFirstPersonSide
|
||||||
*/
|
*/
|
||||||
private void renderItemFirstPersonSide( EnumHandSide side, float equipProgress, float swingProgress, ItemStack stack )
|
private void renderItemFirstPersonSide( AbsoluteHand side, float equipProgress, float swingProgress, ItemStack stack )
|
||||||
{
|
{
|
||||||
Minecraft minecraft = Minecraft.getInstance();
|
MinecraftClient minecraft = MinecraftClient.getInstance();
|
||||||
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
|
float offset = side == AbsoluteHand.RIGHT ? 1f : -1f;
|
||||||
GlStateManager.translatef( offset * 0.125f, -0.125f, 0f );
|
GlStateManager.translatef( 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
|
||||||
@@ -64,7 +65,7 @@ public abstract class ItemMapLikeRenderer
|
|||||||
{
|
{
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
GlStateManager.rotatef( offset * 10f, 0f, 0f, 1f );
|
GlStateManager.rotatef( offset * 10f, 0f, 0f, 1f );
|
||||||
minecraft.getFirstPersonRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
|
((MixedFirstPersonRenderer) minecraft.getFirstPersonRenderer()).renderArmFirstPerson_CC( equipProgress, swingProgress, side );
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,11 +94,11 @@ 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#renderMapFirstPerson(float, float, float)
|
* @see FirstPersonRenderer#renderFirstPersonMap(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();
|
MixedFirstPersonRenderer renderer = (MixedFirstPersonRenderer) MinecraftClient.getInstance().getFirstPersonRenderer();
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -105,10 +106,10 @@ public abstract class ItemMapLikeRenderer
|
|||||||
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.translatef( 0f, -tX / 2f, tZ );
|
||||||
float pitchAngle = renderer.getMapAngleFromPitch( pitch );
|
float pitchAngle = renderer.getMapAngleFromPitch_CC( pitch );
|
||||||
GlStateManager.translatef( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
GlStateManager.translatef( 0f, 0.04f + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
||||||
GlStateManager.rotatef( pitchAngle * -85f, 1f, 0f, 0f );
|
GlStateManager.rotatef( pitchAngle * -85f, 1f, 0f, 0f );
|
||||||
renderer.renderArms();
|
renderer.renderArms_CC();
|
||||||
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
||||||
GlStateManager.rotatef( rX * 20f, 1f, 0f, 0f );
|
GlStateManager.rotatef( rX * 20f, 1f, 0f, 0f );
|
||||||
GlStateManager.scalef( 2f, 2f, 2f );
|
GlStateManager.scalef( 2f, 2f, 2f );
|
||||||
|
|||||||
@@ -6,249 +6,152 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.client.FrameInfo;
|
import dan200.computercraft.client.FrameInfo;
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
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.fabricmc.api.EnvType;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.render.item.ItemRenderer;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||||
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
|
import net.minecraft.client.texture.TextureManager;
|
||||||
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.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
import static dan200.computercraft.client.gui.GuiComputer.*;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emulates map rendering for pocket computers
|
* Emulates map rendering for pocket computers
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Environment( EnvType.CLIENT )
|
||||||
public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||||
{
|
{
|
||||||
private static final int MARGIN = 2;
|
public static final ItemPocketRenderer INSTANCE = new ItemPocketRenderer();
|
||||||
private static final int FRAME = 12;
|
|
||||||
private static final int LIGHT_HEIGHT = 8;
|
|
||||||
|
|
||||||
private static final ItemPocketRenderer INSTANCE = new ItemPocketRenderer();
|
|
||||||
|
|
||||||
private ItemPocketRenderer()
|
private ItemPocketRenderer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void renderItem( RenderSpecificHandEvent event )
|
|
||||||
{
|
|
||||||
ItemStack stack = event.getItemStack();
|
|
||||||
if( !(stack.getItem() instanceof ItemPocketComputer) ) return;
|
|
||||||
|
|
||||||
event.setCanceled( true );
|
|
||||||
INSTANCE.renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderItem( ItemStack stack )
|
protected void renderItem( ItemStack stack )
|
||||||
{
|
{
|
||||||
ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
|
|
||||||
Terminal terminal = computer == null ? null : computer.getTerminal();
|
|
||||||
|
|
||||||
int termWidth, termHeight;
|
|
||||||
if( terminal == null )
|
|
||||||
{
|
|
||||||
termWidth = ComputerCraft.terminalWidth_pocketComputer;
|
|
||||||
termHeight = ComputerCraft.terminalHeight_pocketComputer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
termWidth = terminal.getWidth();
|
|
||||||
termHeight = terminal.getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
int width = termWidth * FONT_WIDTH + MARGIN * 2;
|
|
||||||
int height = termHeight * FONT_HEIGHT + MARGIN * 2;
|
|
||||||
|
|
||||||
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
||||||
// in ItemRenderer
|
// in ItemRenderer
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
|
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
GlStateManager.disableDepthTest();
|
|
||||||
|
|
||||||
GlStateManager.rotatef( 180f, 0f, 1f, 0f );
|
GlStateManager.rotatef( 180f, 0f, 1f, 0f );
|
||||||
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
||||||
GlStateManager.scalef( 0.5f, 0.5f, 0.5f );
|
GlStateManager.scalef( 0.5f, 0.5f, 0.5f );
|
||||||
|
|
||||||
double scale = 0.75 / Math.max( width + FRAME * 2, height + FRAME * 2 + LIGHT_HEIGHT );
|
ClientComputer computer = ItemPocketComputer.createClientComputer( stack );
|
||||||
GlStateManager.scaled( scale, scale, 0 );
|
|
||||||
GlStateManager.translated( -0.5 * width, -0.5 * height, 0 );
|
|
||||||
|
|
||||||
// Render the main frame
|
|
||||||
ItemPocketComputer item = (ItemPocketComputer) stack.getItem();
|
|
||||||
ComputerFamily family = item.getFamily();
|
|
||||||
int frameColour = item.getColour( stack );
|
|
||||||
renderFrame( family, frameColour, width, height );
|
|
||||||
|
|
||||||
// Render the light
|
|
||||||
int lightColour = ItemPocketComputer.getLightState( stack );
|
|
||||||
if( lightColour == -1 ) lightColour = Colour.Black.getHex();
|
|
||||||
renderLight( lightColour, width, height );
|
|
||||||
|
|
||||||
if( computer != null && terminal != null )
|
|
||||||
{
|
{
|
||||||
// If we've a computer and terminal then attempt to render it.
|
// First render the background item. We use the item's model rather than a direct texture as this ensures
|
||||||
renderTerminal( terminal, !computer.isColour(), width, height );
|
// we display the pocket light and other such decorations.
|
||||||
}
|
GlStateManager.pushMatrix();
|
||||||
else
|
|
||||||
{
|
|
||||||
// Otherwise render a plain background
|
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( BACKGROUND );
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
GlStateManager.scalef( 1.0f, -1.0f, 1.0f );
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
|
|
||||||
Colour black = Colour.Black;
|
MinecraftClient minecraft = MinecraftClient.getInstance();
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION );
|
TextureManager textureManager = minecraft.getTextureManager();
|
||||||
renderTexture( buffer, 0, 0, 0, 0, width, height, black.getR(), black.getG(), black.getB() );
|
ItemRenderer renderItem = minecraft.getItemRenderer();
|
||||||
tessellator.draw();
|
|
||||||
|
// Copy of RenderItem#renderItemModelIntoGUI but without the translation or scaling
|
||||||
|
textureManager.bindTexture( SpriteAtlasTexture.BLOCK_ATLAS_TEX );
|
||||||
|
textureManager.getTexture( SpriteAtlasTexture.BLOCK_ATLAS_TEX ).pushFilter( false, false );
|
||||||
|
|
||||||
|
GlStateManager.enableRescaleNormal();
|
||||||
|
GlStateManager.enableAlphaTest();
|
||||||
|
GlStateManager.alphaFunc( GL11.GL_GREATER, 0.1F );
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.blendFunc( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA );
|
||||||
|
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||||
|
|
||||||
|
BakedModel baked = renderItem.getModel( stack, null, null );
|
||||||
|
baked.getTransformation().applyGl( ModelTransformation.Type.GUI );
|
||||||
|
renderItem.renderItemAndGlow( stack, baked );
|
||||||
|
|
||||||
|
GlStateManager.disableAlphaTest();
|
||||||
|
GlStateManager.disableRescaleNormal();
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we've a computer and terminal then attempt to render it.
|
||||||
|
if( computer != null )
|
||||||
|
{
|
||||||
|
Terminal terminal = computer.getTerminal();
|
||||||
|
if( terminal != null )
|
||||||
|
{
|
||||||
|
synchronized( terminal )
|
||||||
|
{
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.disableDepthTest();
|
||||||
|
|
||||||
|
// Reset the position to be at the top left corner of the pocket computer
|
||||||
|
// Note we translate towards the screen slightly too.
|
||||||
|
GlStateManager.translated( -8 / 16.0, -8 / 16.0, 0.5 / 16.0 );
|
||||||
|
// Translate to the top left of the screen.
|
||||||
|
GlStateManager.translated( 4 / 16.0, 3 / 16.0, 0 );
|
||||||
|
|
||||||
|
// Work out the scaling required to resize the terminal in order to fit on the computer
|
||||||
|
final int margin = 2;
|
||||||
|
int tw = terminal.getWidth();
|
||||||
|
int th = terminal.getHeight();
|
||||||
|
int width = tw * FONT_WIDTH + margin * 2;
|
||||||
|
int height = th * FONT_HEIGHT + margin * 2;
|
||||||
|
int max = Math.max( height, width );
|
||||||
|
|
||||||
|
// The grid is 8 * 8 wide, so we start with a base of 1/2 (8 / 16).
|
||||||
|
double scale = 1.0 / 2.0 / max;
|
||||||
|
GlStateManager.scaled( scale, scale, scale );
|
||||||
|
|
||||||
|
// The margin/start positions are determined in order for the terminal to be centred.
|
||||||
|
int startX = (max - width) / 2 + margin;
|
||||||
|
int startY = (max - height) / 2 + margin;
|
||||||
|
|
||||||
|
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
||||||
|
boolean greyscale = !computer.isColour();
|
||||||
|
Palette palette = terminal.getPalette();
|
||||||
|
|
||||||
|
// Render the actual text
|
||||||
|
for( int line = 0; line < th; line++ )
|
||||||
|
{
|
||||||
|
TextBuffer text = terminal.getLine( line );
|
||||||
|
TextBuffer colour = terminal.getTextColourLine( line );
|
||||||
|
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
||||||
|
fontRenderer.drawString(
|
||||||
|
text, startX, startY + line * FONT_HEIGHT,
|
||||||
|
colour, backgroundColour, margin, margin, greyscale, palette
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// And render the cursor;
|
||||||
|
int tx = terminal.getCursorX(), ty = terminal.getCursorY();
|
||||||
|
if( terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink() &&
|
||||||
|
tx >= 0 && ty >= 0 && tx < tw && ty < th )
|
||||||
|
{
|
||||||
|
TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 );
|
||||||
|
fontRenderer.drawString(
|
||||||
|
new TextBuffer( '_', 1 ), startX + FONT_WIDTH * tx, startY + FONT_HEIGHT * ty,
|
||||||
|
cursorColour, null, 0, 0, greyscale, palette
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
GlStateManager.enableDepthTest();
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GlStateManager.enableDepthTest();
|
|
||||||
GlStateManager.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderFrame( ComputerFamily family, int colour, int width, int height )
|
|
||||||
{
|
|
||||||
|
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( colour != -1
|
|
||||||
? BACKGROUND_COLOUR
|
|
||||||
: family == ComputerFamily.Normal ? BACKGROUND_NORMAL : BACKGROUND_ADVANCED
|
|
||||||
);
|
|
||||||
|
|
||||||
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
|
||||||
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
|
||||||
float b = (colour & 0xFF) / 255.0f;
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR );
|
|
||||||
|
|
||||||
// Top left, middle, right
|
|
||||||
renderTexture( buffer, -FRAME, -FRAME, 12, 28, FRAME, FRAME, r, g, b );
|
|
||||||
renderTexture( buffer, 0, -FRAME, 0, 0, width, FRAME, r, g, b );
|
|
||||||
renderTexture( buffer, width, -FRAME, 24, 28, FRAME, FRAME, r, g, b );
|
|
||||||
|
|
||||||
// Left and bright border
|
|
||||||
renderTexture( buffer, -FRAME, 0, 0, 28, FRAME, height, r, g, b );
|
|
||||||
renderTexture( buffer, width, 0, 36, 28, FRAME, height, r, g, b );
|
|
||||||
|
|
||||||
// Bottom left, middle, right. We do this in three portions: the top inner corners, an extended region for
|
|
||||||
// lights, and then the bottom outer corners.
|
|
||||||
renderTexture( buffer, -FRAME, height, 12, 40, FRAME, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, 0, height, 0, 12, width, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, width, height, 24, 40, FRAME, FRAME / 2, r, g, b );
|
|
||||||
|
|
||||||
renderTexture( buffer, -FRAME, height + FRAME / 2, 12, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
|
||||||
renderTexture( buffer, 0, height + FRAME / 2, 0, 16, width, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
|
||||||
renderTexture( buffer, width, height + FRAME / 2, 24, 44, FRAME, LIGHT_HEIGHT, FRAME, 4, r, g, b );
|
|
||||||
|
|
||||||
renderTexture( buffer, -FRAME, height + LIGHT_HEIGHT + FRAME / 2, 12, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, 0, height + LIGHT_HEIGHT + FRAME / 2, 0, 12 + FRAME / 2, width, FRAME / 2, r, g, b );
|
|
||||||
renderTexture( buffer, width, height + LIGHT_HEIGHT + FRAME / 2, 24, 40 + FRAME / 2, FRAME, FRAME / 2, r, g, b );
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderLight( int colour, int width, int height )
|
|
||||||
{
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.disableTexture2D();
|
|
||||||
|
|
||||||
float r = ((colour >>> 16) & 0xFF) / 255.0f;
|
|
||||||
float g = ((colour >>> 8) & 0xFF) / 255.0f;
|
|
||||||
float b = (colour & 0xFF) / 255.0f;
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR );
|
|
||||||
buffer.pos( width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
buffer.pos( width, height + LIGHT_HEIGHT + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
buffer.pos( width, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
buffer.pos( width - LIGHT_HEIGHT * 2, height + FRAME / 2.0f, 0.0D ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
GlStateManager.enableTexture2D();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderTerminal( Terminal terminal, boolean greyscale, int width, int height )
|
|
||||||
{
|
|
||||||
synchronized( terminal )
|
|
||||||
{
|
|
||||||
int termWidth = terminal.getWidth();
|
|
||||||
int termHeight = terminal.getHeight();
|
|
||||||
|
|
||||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
|
||||||
Palette palette = terminal.getPalette();
|
|
||||||
|
|
||||||
// Render top/bottom borders
|
|
||||||
TextBuffer emptyLine = new TextBuffer( ' ', termWidth );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
emptyLine, MARGIN, 0,
|
|
||||||
terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
fontRenderer.drawString(
|
|
||||||
emptyLine, MARGIN, 2 * MARGIN + (termHeight - 1) * FixedWidthFontRenderer.FONT_HEIGHT,
|
|
||||||
terminal.getTextColourLine( termHeight - 1 ), terminal.getBackgroundColourLine( termHeight - 1 ), MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
|
|
||||||
// Render the actual text
|
|
||||||
for( int line = 0; line < termWidth; line++ )
|
|
||||||
{
|
|
||||||
TextBuffer text = terminal.getLine( line );
|
|
||||||
TextBuffer colour = terminal.getTextColourLine( line );
|
|
||||||
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
text, MARGIN, MARGIN + line * FONT_HEIGHT,
|
|
||||||
colour, backgroundColour, MARGIN, MARGIN, greyscale, palette
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// And render the cursor;
|
|
||||||
int tx = terminal.getCursorX(), ty = terminal.getCursorY();
|
|
||||||
if( terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink() &&
|
|
||||||
tx >= 0 && ty >= 0 && tx < termWidth && ty < termHeight )
|
|
||||||
{
|
|
||||||
TextBuffer cursorColour = new TextBuffer( "0123456789abcdef".charAt( terminal.getTextColour() ), 1 );
|
|
||||||
fontRenderer.drawString(
|
|
||||||
new TextBuffer( '_', 1 ), MARGIN + FONT_WIDTH * tx, MARGIN + FONT_HEIGHT * ty,
|
|
||||||
cursorColour, null, 0, 0, greyscale, palette
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderTexture( BufferBuilder builder, int x, int y, int textureX, int textureY, int width, int height, float r, float g, float b )
|
|
||||||
{
|
|
||||||
renderTexture( builder, x, y, textureX, textureY, width, height, width, height, r, g, b );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderTexture( BufferBuilder builder, int x, int y, int textureX, int textureY, int width, int height, int textureWidth, int textureHeight, float r, float g, float b )
|
|
||||||
{
|
|
||||||
float scale = 1 / 255.0f;
|
|
||||||
builder.pos( x, y + height, 0 ).tex( textureX * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
builder.pos( x + width, y + height, 0 ).tex( (textureX + textureWidth) * scale, (textureY + textureHeight) * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
builder.pos( x + width, y, 0 ).tex( (textureX + textureWidth) * scale, textureY * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
builder.pos( x, y, 0 ).tex( textureX * scale, textureY * scale ).color( r, g, b, 1.0f ).endVertex();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,12 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.fabricmc.api.EnvType;
|
||||||
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||||
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.RenderSpecificHandEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -25,15 +22,16 @@ import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENG
|
|||||||
/**
|
/**
|
||||||
* Emulates map and item-frame rendering for printouts
|
* Emulates map and item-frame rendering for printouts
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
@Environment( EnvType.CLIENT )
|
||||||
public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||||
{
|
{
|
||||||
private static final ItemPrintoutRenderer INSTANCE = new ItemPrintoutRenderer();
|
public static final ItemPrintoutRenderer INSTANCE = new ItemPrintoutRenderer();
|
||||||
|
|
||||||
private ItemPrintoutRenderer()
|
private ItemPrintoutRenderer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onRenderInHand( RenderSpecificHandEvent event )
|
public static void onRenderInHand( RenderSpecificHandEvent event )
|
||||||
{
|
{
|
||||||
@@ -43,6 +41,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
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() );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderItem( ItemStack stack )
|
protected void renderItem( ItemStack stack )
|
||||||
@@ -61,16 +60,13 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
GlStateManager.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
public void renderInFrame( ItemFrameEntity entity, ItemStack stack )
|
||||||
public static void onRenderInFrame( RenderItemInFrameEvent event )
|
|
||||||
{
|
{
|
||||||
ItemStack stack = event.getItem();
|
|
||||||
if( !(stack.getItem() instanceof ItemPrintout) ) return;
|
|
||||||
|
|
||||||
event.setCanceled( true );
|
|
||||||
|
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
|
int rotation = entity.getRotation();
|
||||||
|
GlStateManager.rotatef( (float) rotation * 360.0F / 8.0F, 0.0F, 0.0F, 1.0F );
|
||||||
|
|
||||||
// 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.translatef( 0.0f, 0.0f, -0.001f );
|
||||||
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
||||||
|
|||||||
@@ -6,19 +6,13 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.render.VertexFormat;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.render.VertexFormatElement;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
|
||||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
|
||||||
import net.minecraftforge.client.model.pipeline.VertexTransformer;
|
|
||||||
import net.minecraftforge.common.model.TRSRTransformation;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.vecmath.Matrix4f;
|
import javax.vecmath.Matrix4f;
|
||||||
import javax.vecmath.Point3f;
|
import javax.vecmath.Vector4f;
|
||||||
import javax.vecmath.Vector3f;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,6 +34,11 @@ public final class ModelTransformer
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void transformQuadsTo( List<BakedQuad> output, List<BakedQuad> input, Matrix4f transform )
|
public static void transformQuadsTo( List<BakedQuad> output, List<BakedQuad> input, Matrix4f transform )
|
||||||
|
{
|
||||||
|
transformQuadsTo( VertexFormats.POSITION_COLOR_UV_NORMAL, output, input, transform );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void transformQuadsTo( VertexFormat format, List<BakedQuad> output, List<BakedQuad> input, Matrix4f transform )
|
||||||
{
|
{
|
||||||
if( transform == null || transform.equals( identity ) )
|
if( transform == null || transform.equals( identity ) )
|
||||||
{
|
{
|
||||||
@@ -47,224 +46,55 @@ public final class ModelTransformer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Matrix4f normalMatrix = new Matrix4f( transform );
|
for( BakedQuad quad : input ) output.add( doTransformQuad( format, quad, transform ) );
|
||||||
normalMatrix.invert();
|
|
||||||
normalMatrix.transpose();
|
|
||||||
|
|
||||||
for( BakedQuad quad : input ) output.add( doTransformQuad( quad, transform, normalMatrix ) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BakedQuad transformQuad( BakedQuad input, Matrix4f transform )
|
public static BakedQuad transformQuad( VertexFormat format, BakedQuad input, Matrix4f transform )
|
||||||
{
|
{
|
||||||
if( transform == null || transform.equals( identity ) ) return input;
|
if( transform == null || transform.equals( identity ) ) return input;
|
||||||
|
return doTransformQuad( format, input, transform );
|
||||||
Matrix4f normalMatrix = new Matrix4f( transform );
|
|
||||||
normalMatrix.invert();
|
|
||||||
normalMatrix.transpose();
|
|
||||||
return doTransformQuad( input, transform, normalMatrix );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BakedQuad doTransformQuad( BakedQuad input, Matrix4f positionMatrix, Matrix4f normalMatrix )
|
private static BakedQuad doTransformQuad( VertexFormat format, BakedQuad quad, Matrix4f transform )
|
||||||
{
|
{
|
||||||
|
int[] vertexData = quad.getVertexData().clone();
|
||||||
BakedQuadBuilder builder = new BakedQuadBuilder( input.getFormat() );
|
int offset = 0;
|
||||||
NormalAwareTransformer transformer = new NormalAwareTransformer( builder, positionMatrix, normalMatrix );
|
BakedQuad copy = new BakedQuad( vertexData, -1, quad.getFace(), quad.getSprite() );
|
||||||
input.pipe( transformer );
|
for( int i = 0; i < format.getElementCount(); ++i ) // For each vertex element
|
||||||
|
|
||||||
if( transformer.areNormalsInverted() )
|
|
||||||
{
|
{
|
||||||
builder.swap( 1, 3 );
|
VertexFormatElement element = format.getElement( i );
|
||||||
transformer.areNormalsInverted();
|
if( element.isPosition() &&
|
||||||
}
|
element.getFormat() == VertexFormatElement.Format.FLOAT &&
|
||||||
|
element.getCount() == 3 ) // When we find a position element
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A vertex transformer that tracks whether the normals have been inverted and so the vertices
|
|
||||||
* should be reordered so backface culling works as expected.
|
|
||||||
*/
|
|
||||||
private static class NormalAwareTransformer extends VertexTransformer
|
|
||||||
{
|
|
||||||
private final Matrix4f positionMatrix;
|
|
||||||
private final Matrix4f normalMatrix;
|
|
||||||
|
|
||||||
private int vertexIndex = 0, elementIndex = 0;
|
|
||||||
private final Point3f[] before = new Point3f[4];
|
|
||||||
private final Point3f[] after = new Point3f[4];
|
|
||||||
|
|
||||||
NormalAwareTransformer( IVertexConsumer parent, Matrix4f positionMatrix, Matrix4f normalMatrix )
|
|
||||||
{
|
|
||||||
super( parent );
|
|
||||||
this.positionMatrix = positionMatrix;
|
|
||||||
this.normalMatrix = normalMatrix;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setQuadOrientation( @Nonnull EnumFacing orientation )
|
|
||||||
{
|
|
||||||
super.setQuadOrientation( orientation == null ? orientation : TRSRTransformation.rotate( positionMatrix, orientation ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void put( int element, @Nonnull float... data )
|
|
||||||
{
|
|
||||||
switch( getVertexFormat().getElement( element ).getUsage() )
|
|
||||||
{
|
{
|
||||||
case POSITION:
|
for( int j = 0; j < 4; ++j ) // For each corner of the quad
|
||||||
{
|
{
|
||||||
Point3f vec = new Point3f( data );
|
int start = offset + j * format.getVertexSize();
|
||||||
Point3f newVec = new Point3f();
|
if( (start % 4) == 0 )
|
||||||
positionMatrix.transform( vec, newVec );
|
{
|
||||||
|
start = start / 4;
|
||||||
|
|
||||||
float[] newData = new float[4];
|
// Extract the position
|
||||||
newVec.get( newData );
|
Vector4f pos = new Vector4f(
|
||||||
super.put( element, newData );
|
Float.intBitsToFloat( vertexData[start] ),
|
||||||
|
Float.intBitsToFloat( vertexData[start + 1] ),
|
||||||
|
Float.intBitsToFloat( vertexData[start + 2] ),
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
// Transform the position
|
||||||
|
transform.transform( pos );
|
||||||
|
|
||||||
before[vertexIndex] = vec;
|
// Insert the position
|
||||||
after[vertexIndex] = newVec;
|
vertexData[start] = Float.floatToRawIntBits( pos.x );
|
||||||
break;
|
vertexData[start + 1] = Float.floatToRawIntBits( pos.y );
|
||||||
|
vertexData[start + 2] = Float.floatToRawIntBits( pos.z );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case NORMAL:
|
|
||||||
{
|
|
||||||
Vector3f vec = new Vector3f( data );
|
|
||||||
normalMatrix.transform( vec );
|
|
||||||
|
|
||||||
float[] newData = new float[4];
|
|
||||||
vec.get( newData );
|
|
||||||
super.put( element, newData );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
super.put( element, data );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
elementIndex++;
|
|
||||||
if( elementIndex == getVertexFormat().getElementCount() )
|
|
||||||
{
|
|
||||||
vertexIndex++;
|
|
||||||
elementIndex = 0;
|
|
||||||
}
|
}
|
||||||
|
offset += element.getSize();
|
||||||
}
|
}
|
||||||
|
return copy;
|
||||||
public boolean areNormalsInverted()
|
|
||||||
{
|
|
||||||
Vector3f temp1 = new Vector3f(), temp2 = new Vector3f();
|
|
||||||
Vector3f crossBefore = new Vector3f(), crossAfter = new Vector3f();
|
|
||||||
|
|
||||||
// Determine what cross product we expect to have
|
|
||||||
temp1.sub( before[1], before[0] );
|
|
||||||
temp2.sub( before[1], before[2] );
|
|
||||||
crossBefore.cross( temp1, temp2 );
|
|
||||||
normalMatrix.transform( crossBefore );
|
|
||||||
|
|
||||||
// And determine what cross product we actually have
|
|
||||||
temp1.sub( after[1], after[0] );
|
|
||||||
temp2.sub( after[1], after[2] );
|
|
||||||
crossAfter.cross( temp1, temp2 );
|
|
||||||
|
|
||||||
// If the angle between expected and actual cross product is greater than
|
|
||||||
// pi/2 radians then we will need to reorder our quads.
|
|
||||||
return Math.abs( crossBefore.angle( crossAfter ) ) >= Math.PI / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A vertex consumer which is capable of building {@link BakedQuad}s.
|
|
||||||
*
|
|
||||||
* Equivalent to {@link net.minecraftforge.client.model.pipeline.UnpackedBakedQuad.Builder} but more memory
|
|
||||||
* efficient.
|
|
||||||
*
|
|
||||||
* This also provides the ability to swap vertices through {@link #swap(int, int)} to allow reordering.
|
|
||||||
*/
|
|
||||||
private static final class BakedQuadBuilder implements IVertexConsumer
|
|
||||||
{
|
|
||||||
private final VertexFormat format;
|
|
||||||
|
|
||||||
private final int[] vertexData;
|
|
||||||
private int vertexIndex = 0, elementIndex = 0;
|
|
||||||
|
|
||||||
private EnumFacing orientation;
|
|
||||||
private int quadTint;
|
|
||||||
private boolean diffuse;
|
|
||||||
private TextureAtlasSprite texture;
|
|
||||||
|
|
||||||
private BakedQuadBuilder( VertexFormat format )
|
|
||||||
{
|
|
||||||
this.format = format;
|
|
||||||
vertexData = new int[format.getSize()];
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public VertexFormat getVertexFormat()
|
|
||||||
{
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setQuadTint( int tint )
|
|
||||||
{
|
|
||||||
quadTint = tint;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setQuadOrientation( @Nonnull EnumFacing orientation )
|
|
||||||
{
|
|
||||||
this.orientation = orientation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setApplyDiffuseLighting( boolean diffuse )
|
|
||||||
{
|
|
||||||
this.diffuse = diffuse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setTexture( @Nonnull TextureAtlasSprite texture )
|
|
||||||
{
|
|
||||||
this.texture = texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void put( int element, @Nonnull float... data )
|
|
||||||
{
|
|
||||||
LightUtil.pack( data, vertexData, format, vertexIndex, element );
|
|
||||||
|
|
||||||
elementIndex++;
|
|
||||||
if( elementIndex == getVertexFormat().getElementCount() )
|
|
||||||
{
|
|
||||||
vertexIndex++;
|
|
||||||
elementIndex = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void swap( int a, int b )
|
|
||||||
{
|
|
||||||
int length = vertexData.length / 4;
|
|
||||||
for( int i = 0; i < length; i++ )
|
|
||||||
{
|
|
||||||
int temp = vertexData[a * length + i];
|
|
||||||
vertexData[a * length + i] = vertexData[b * length + i];
|
|
||||||
vertexData[b * length + i] = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BakedQuad build()
|
|
||||||
{
|
|
||||||
if( elementIndex != 0 || vertexIndex != 4 )
|
|
||||||
{
|
|
||||||
throw new IllegalStateException( "Got an unexpected number of elements/vertices" );
|
|
||||||
}
|
|
||||||
if( texture == null )
|
|
||||||
{
|
|
||||||
throw new IllegalStateException( "Texture has not been set" );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new BakedQuad( vertexData, quadTint, orientation, texture, diffuse, format );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,117 +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.render;
|
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
|
||||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import static net.minecraft.util.EnumFacing.*;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
|
||||||
public final class MonitorHighlightRenderer
|
|
||||||
{
|
|
||||||
private static final float EXPAND = 0.002f;
|
|
||||||
|
|
||||||
private MonitorHighlightRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void drawHighlight( DrawBlockHighlightEvent event )
|
|
||||||
{
|
|
||||||
if( event.getTarget().type != RayTraceResult.Type.BLOCK || event.getPlayer().isSneaking() ) return;
|
|
||||||
|
|
||||||
World world = event.getPlayer().getEntityWorld();
|
|
||||||
BlockPos pos = event.getTarget().getBlockPos();
|
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
|
||||||
if( !(tile instanceof TileMonitor) ) return;
|
|
||||||
|
|
||||||
TileMonitor monitor = (TileMonitor) tile;
|
|
||||||
event.setCanceled( true );
|
|
||||||
|
|
||||||
// Determine which sides are part of the external faces of the monitor, and so which need to be rendered.
|
|
||||||
EnumSet<EnumFacing> faces = EnumSet.allOf( EnumFacing.class );
|
|
||||||
EnumFacing front = monitor.getFront();
|
|
||||||
faces.remove( front );
|
|
||||||
if( monitor.getXIndex() != 0 ) faces.remove( monitor.getRight().getOpposite() );
|
|
||||||
if( monitor.getXIndex() != monitor.getWidth() - 1 ) faces.remove( monitor.getRight() );
|
|
||||||
if( monitor.getYIndex() != 0 ) faces.remove( monitor.getDown().getOpposite() );
|
|
||||||
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.blendFuncSeparate( 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 ) );
|
|
||||||
GlStateManager.disableTexture2D();
|
|
||||||
GlStateManager.depthMask( false );
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
|
|
||||||
EntityPlayer player = event.getPlayer();
|
|
||||||
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
|
|
||||||
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
|
||||||
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
|
||||||
|
|
||||||
GlStateManager.translated( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR );
|
|
||||||
|
|
||||||
// I wish I could think of a better way to do this
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, 0, 0, 0, UP );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, 0, 0, 1, UP );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, 1, 0, 0, UP );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( EAST ) ) line( buffer, 1, 0, 1, UP );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 0, EAST );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 1, EAST );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( UP ) ) line( buffer, 0, 1, 0, EAST );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( UP ) ) line( buffer, 0, 1, 1, EAST );
|
|
||||||
if( faces.contains( WEST ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 0, SOUTH );
|
|
||||||
if( faces.contains( EAST ) || faces.contains( DOWN ) ) line( buffer, 1, 0, 0, SOUTH );
|
|
||||||
if( faces.contains( WEST ) || faces.contains( UP ) ) line( buffer, 0, 1, 0, SOUTH );
|
|
||||||
if( faces.contains( EAST ) || faces.contains( UP ) ) line( buffer, 1, 1, 0, SOUTH );
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
GlStateManager.depthMask( true );
|
|
||||||
GlStateManager.enableTexture2D();
|
|
||||||
GlStateManager.disableBlend();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void line( BufferBuilder buffer, int x, int y, int z, EnumFacing direction )
|
|
||||||
{
|
|
||||||
double minX = x == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
double minY = y == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
double minZ = z == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
|
|
||||||
buffer.pos( minX, minY, minZ ).color( 0, 0, 0, 0.4f ).endVertex();
|
|
||||||
buffer.pos(
|
|
||||||
minX + direction.getXOffset() * (1 + EXPAND * 2),
|
|
||||||
minY + direction.getYOffset() * (1 + EXPAND * 2),
|
|
||||||
minZ + direction.getZOffset() * (1 + EXPAND * 2)
|
|
||||||
).color( 0, 0, 0, 0.4f ).endVertex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,17 +6,17 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.render.Tessellator;
|
||||||
import net.minecraft.client.renderer.GlStateManager.DestFactor;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.renderer.GlStateManager.SourceFactor;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
@@ -24,7 +24,7 @@ import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAG
|
|||||||
|
|
||||||
public final class PrintoutRenderer
|
public final class PrintoutRenderer
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BG = new ResourceLocation( "computercraft", "textures/gui/printout.png" );
|
private static final Identifier BG = new Identifier( "computercraft", "textures/gui/printout.png" );
|
||||||
private static final double BG_SIZE = 256.0;
|
private static final double BG_SIZE = 256.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,7 +76,7 @@ public final class PrintoutRenderer
|
|||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture();
|
||||||
GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
|
GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
|
||||||
|
|
||||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
||||||
@@ -91,14 +91,14 @@ public final class PrintoutRenderer
|
|||||||
{
|
{
|
||||||
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture();
|
||||||
GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
|
GlStateManager.blendFuncSeparate( SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO );
|
||||||
|
|
||||||
Minecraft.getInstance().getTextureManager().bindTexture( BG );
|
MinecraftClient.getInstance().getTextureManager().bindTexture( BG );
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
BufferBuilder buffer = tessellator.getBufferBuilder();
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX );
|
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_UV );
|
||||||
|
|
||||||
int leftPages = page;
|
int leftPages = page;
|
||||||
int rightPages = pages - page - 1;
|
int rightPages = pages - page - 1;
|
||||||
@@ -159,18 +159,18 @@ public final class PrintoutRenderer
|
|||||||
|
|
||||||
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double u, double v, double width, double height )
|
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double u, double v, double width, double height )
|
||||||
{
|
{
|
||||||
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
buffer.vertex( x, y + height, z ).texture( u / BG_SIZE, (v + height) / BG_SIZE ).next();
|
||||||
buffer.pos( x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
buffer.vertex( x + width, y + height, z ).texture( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).next();
|
||||||
buffer.pos( x + width, y, z ).tex( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex();
|
buffer.vertex( x + width, y, z ).texture( (u + width) / BG_SIZE, v / BG_SIZE ).next();
|
||||||
buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
buffer.vertex( x, y, z ).texture( u / BG_SIZE, v / BG_SIZE ).next();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double width, double height, double u, double v, double tWidth, double tHeight )
|
private static void drawTexture( BufferBuilder buffer, double x, double y, double z, double width, double height, double u, double v, double tWidth, double tHeight )
|
||||||
{
|
{
|
||||||
buffer.pos( x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
buffer.vertex( x, y + height, z ).texture( u / BG_SIZE, (v + tHeight) / BG_SIZE ).next();
|
||||||
buffer.pos( x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
buffer.vertex( x + width, y + height, z ).texture( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).next();
|
||||||
buffer.pos( x + width, y, z ).tex( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex();
|
buffer.vertex( x + width, y, z ).texture( (u + tWidth) / BG_SIZE, v / BG_SIZE ).next();
|
||||||
buffer.pos( x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
buffer.vertex( x, y, z ).texture( u / BG_SIZE, v / BG_SIZE ).next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double offsetAt( int page )
|
public static double offsetAt( int page )
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* 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.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
|
import dan200.computercraft.ComputerCraft;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
||||||
|
import dan200.computercraft.shared.util.WorldUtil;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.render.WorldRenderer;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
|
import net.minecraft.util.hit.HitResult;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
|
public final class RenderOverlayCable
|
||||||
|
{
|
||||||
|
private RenderOverlayCable()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw an outline for a specific part of a cable "Multipart".
|
||||||
|
*
|
||||||
|
* @see WorldRenderer#drawHighlightedBlockOutline(Entity, HitResult, int, float)
|
||||||
|
*/
|
||||||
|
// TODO @SubscribeEvent
|
||||||
|
public static void drawHighlight()
|
||||||
|
{
|
||||||
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
|
if( mc.hitResult == null || mc.hitResult.getType() != HitResult.Type.BLOCK ) return;
|
||||||
|
|
||||||
|
BlockPos pos = ((BlockHitResult) mc.hitResult).getBlockPos();
|
||||||
|
World world = mc.world;
|
||||||
|
|
||||||
|
BlockState state = world.getBlockState( pos );
|
||||||
|
|
||||||
|
// We only care about instances with both cable and modem.
|
||||||
|
if( state.getBlock() != ComputerCraft.Blocks.cable || state.get( BlockCable.MODEM ).getFacing() == null || !state.get( BlockCable.CABLE ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerEntity player = mc.player;
|
||||||
|
float partialTicks = mc.getTickDelta();
|
||||||
|
|
||||||
|
GlStateManager.enableBlend();
|
||||||
|
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
||||||
|
GlStateManager.lineWidth( Math.max( 2.5F, mc.window.getFramebufferWidth() / 1920.0F * 2.5F ) );
|
||||||
|
GlStateManager.disableTexture();
|
||||||
|
GlStateManager.depthMask( false );
|
||||||
|
GlStateManager.matrixMode( GL11.GL_PROJECTION );
|
||||||
|
GlStateManager.pushMatrix();
|
||||||
|
GlStateManager.scalef( 1.0F, 1.0F, 0.999F );
|
||||||
|
|
||||||
|
double x = player.prevX + (player.x - player.prevX) * partialTicks;
|
||||||
|
double y = player.prevY + (player.y - player.prevY) * partialTicks;
|
||||||
|
double z = player.prevZ + (player.z - player.prevZ) * partialTicks;
|
||||||
|
|
||||||
|
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), mc.hitResult.getPos().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
||||||
|
? CableShapes.getModemShape( state )
|
||||||
|
: CableShapes.getCableShape( state );
|
||||||
|
|
||||||
|
WorldRenderer.drawShapeOutline( shape, pos.getX() - x, pos.getY() - y, pos.getZ() - z, 0.0F, 0.0F, 0.0F, 0.4F );
|
||||||
|
|
||||||
|
GlStateManager.popMatrix();
|
||||||
|
GlStateManager.matrixMode( GL11.GL_MODELVIEW );
|
||||||
|
GlStateManager.depthMask( true );
|
||||||
|
GlStateManager.enableTexture();
|
||||||
|
GlStateManager.disableBlend();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
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.CableModemVariant;
|
||||||
@@ -13,23 +14,19 @@ import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
|||||||
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;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.render.Tessellator;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.renderer.WorldRenderer;
|
import net.minecraft.client.render.WorldRenderer;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.BlockRenderLayer;
|
import net.minecraft.util.hit.HitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
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.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;
|
||||||
@@ -38,7 +35,7 @@ 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 BlockEntityRenderer<TileCable>
|
||||||
{
|
{
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
@@ -49,44 +46,34 @@ public class TileEntityCableRenderer extends TileEntityRenderer<TileCable>
|
|||||||
|
|
||||||
BlockPos pos = te.getPos();
|
BlockPos pos = te.getPos();
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getInstance();
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
|
|
||||||
RayTraceResult hit = mc.objectMouseOver;
|
HitResult hit = mc.hitResult;
|
||||||
if( hit == null || !hit.getBlockPos().equals( pos ) ) return;
|
if( !(hit instanceof BlockHitResult) || !((BlockHitResult) hit).getBlockPos().equals( pos ) ) return;
|
||||||
|
|
||||||
if( MinecraftForgeClient.getRenderPass() != 0 ) return;
|
|
||||||
|
|
||||||
World world = te.getWorld();
|
World world = te.getWorld();
|
||||||
IBlockState state = world.getBlockState( pos );
|
BlockState state = te.getCachedState();
|
||||||
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 = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getPos().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
||||||
? block.getDefaultState().with( BlockCable.MODEM, state.get( BlockCable.MODEM ) )
|
? block.getDefaultState().with( BlockCable.MODEM, state.get( BlockCable.MODEM ) )
|
||||||
: state.with( BlockCable.MODEM, CableModemVariant.None );
|
: state.with( BlockCable.MODEM, CableModemVariant.None );
|
||||||
|
|
||||||
IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state );
|
BakedModel model = mc.getBlockRenderManager().getModel( state );
|
||||||
|
|
||||||
preRenderDamagedBlocks();
|
preRenderDamagedBlocks();
|
||||||
|
|
||||||
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
|
BufferBuilder buffer = Tessellator.getInstance().getBufferBuilder();
|
||||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.BLOCK );
|
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_COLOR_UV_LMAP );
|
||||||
buffer.setTranslation( x - pos.getX(), y - pos.getY(), z - pos.getZ() );
|
buffer.setOffset( x - pos.getX(), y - pos.getY(), z - pos.getZ() );
|
||||||
buffer.noColor();
|
buffer.disableColor();
|
||||||
|
|
||||||
ForgeHooksClient.setRenderLayer( block.getRenderLayer() );
|
|
||||||
|
|
||||||
// See BlockRendererDispatcher#renderBlockDamage
|
// See BlockRendererDispatcher#renderBlockDamage
|
||||||
TextureAtlasSprite breakingTexture = mc.getTextureMap().getSprite( DESTROY_STAGES[destroyStage] );
|
Sprite breakingTexture = mc.getSpriteAtlas().getSprite( DESTROY_STAGE_TEXTURES[destroyStage] );
|
||||||
mc.getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
|
mc.getBlockRenderManager().tesselateDamage( state, pos, breakingTexture, world );
|
||||||
world,
|
|
||||||
ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos ),
|
|
||||||
state, pos, buffer, true, random, state.getPositionRandom( pos ), EmptyModelData.INSTANCE
|
|
||||||
);
|
|
||||||
|
|
||||||
ForgeHooksClient.setRenderLayer( BlockRenderLayer.SOLID );
|
buffer.setOffset( 0, 0, 0 );
|
||||||
|
|
||||||
buffer.setTranslation( 0, 0, 0 );
|
|
||||||
Tessellator.getInstance().draw();
|
Tessellator.getInstance().draw();
|
||||||
|
|
||||||
postRenderDamagedBlocks();
|
postRenderDamagedBlocks();
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GLX;
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.client.FrameInfo;
|
import dan200.computercraft.client.FrameInfo;
|
||||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||||
import dan200.computercraft.core.terminal.Terminal;
|
import dan200.computercraft.core.terminal.Terminal;
|
||||||
@@ -15,18 +17,16 @@ import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
|||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.shared.util.DirectionUtil;
|
import dan200.computercraft.shared.util.DirectionUtil;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.render.Tessellator;
|
||||||
import net.minecraft.client.renderer.OpenGlHelper;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
public class TileEntityMonitorRenderer extends BlockEntityRenderer<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 )
|
||||||
@@ -64,9 +64,9 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
posZ += originPos.getZ() - monitorPos.getZ();
|
posZ += originPos.getZ() - monitorPos.getZ();
|
||||||
|
|
||||||
// Determine orientation
|
// Determine orientation
|
||||||
EnumFacing dir = origin.getDirection();
|
Direction dir = origin.getDirection();
|
||||||
EnumFacing front = origin.getFront();
|
Direction front = origin.getFront();
|
||||||
float yaw = dir.getHorizontalAngle();
|
float yaw = dir.asRotation();
|
||||||
float pitch = DirectionUtil.toPitchAngle( front );
|
float pitch = DirectionUtil.toPitchAngle( front );
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
@@ -85,16 +85,16 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
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();
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
BufferBuilder renderer = tessellator.getBuffer();
|
BufferBuilder renderer = tessellator.getBufferBuilder();
|
||||||
|
|
||||||
// Get terminal
|
// Get terminal
|
||||||
boolean redraw = originTerminal.pollTerminalChanged();
|
boolean redraw = originTerminal.pollTerminalChanged();
|
||||||
|
|
||||||
// Draw the contents
|
// Draw the contents
|
||||||
GlStateManager.depthMask( false );
|
GlStateManager.depthMask( false );
|
||||||
OpenGlHelper.glMultiTexCoord2f( OpenGlHelper.GL_TEXTURE1, 0xFFFF, 0xFFFF );
|
GLX.glMultiTexCoord2f( GLX.GL_TEXTURE1, 0xFFFF, 0xFFFF );
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
mc.gameRenderer.disableLightmap();
|
mc.gameRenderer.disableLightmap();
|
||||||
try
|
try
|
||||||
@@ -171,7 +171,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[0] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[0] );
|
||||||
GlStateManager.resetColor();
|
GlStateManager.clearCurrentColor();
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
fontRenderer.bindFont();
|
fontRenderer.bindFont();
|
||||||
@@ -199,7 +199,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[1] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[1] );
|
||||||
GlStateManager.resetColor();
|
GlStateManager.clearCurrentColor();
|
||||||
|
|
||||||
// Draw cursor
|
// Draw cursor
|
||||||
fontRenderer.bindFont();
|
fontRenderer.bindFont();
|
||||||
@@ -233,7 +233,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
if( FrameInfo.getGlobalCursorBlink() )
|
if( FrameInfo.getGlobalCursorBlink() )
|
||||||
{
|
{
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[2] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[2] );
|
||||||
GlStateManager.resetColor();
|
GlStateManager.clearCurrentColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -251,11 +251,11 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
final float g = colour.getG();
|
final float g = colour.getG();
|
||||||
final float b = colour.getB();
|
final float b = colour.getB();
|
||||||
|
|
||||||
renderer.begin( GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_TEX_COLOR );
|
renderer.begin( GL11.GL_TRIANGLE_STRIP, VertexFormats.POSITION_UV_COLOR );
|
||||||
renderer.pos( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 0.0, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).texture( 0.0, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 0.0, 1.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).texture( 0.0, 1.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).tex( 1.0, 0.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0D ).texture( 1.0, 0.0 ).color( r, g, b, 1.0f ).next();
|
||||||
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).tex( 1.0, 1.0 ).color( r, g, b, 1.0f ).endVertex();
|
renderer.vertex( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).texture( 1.0, 1.0 ).color( r, g, b, 1.0f ).next();
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,11 +271,11 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.BACKGROUND );
|
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.BACKGROUND );
|
||||||
renderer.begin( GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION );
|
renderer.begin( GL11.GL_TRIANGLE_STRIP, VertexFormats.POSITION );
|
||||||
renderer.pos( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
|
renderer.vertex( -TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0 ).next();
|
||||||
renderer.pos( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
|
renderer.vertex( -TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).next();
|
||||||
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
|
renderer.vertex( xSize + TileMonitor.RENDER_MARGIN, TileMonitor.RENDER_MARGIN, 0.0 ).next();
|
||||||
renderer.pos( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).endVertex();
|
renderer.vertex( xSize + TileMonitor.RENDER_MARGIN, -ySize - TileMonitor.RENDER_MARGIN, 0.0 ).next();
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.platform.GlStateManager;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
@@ -13,39 +14,37 @@ import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
|||||||
import dan200.computercraft.shared.util.DirectionUtil;
|
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.BlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
import net.minecraft.client.render.*;
|
||||||
import net.minecraft.client.renderer.GameRenderer;
|
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.render.model.BakedModelManager;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
import net.minecraft.client.renderer.model.ModelManager;
|
import net.minecraft.client.util.ModelIdentifier;
|
||||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.client.renderer.texture.TextureMap;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraftforge.client.ForgeHooksClient;
|
import net.minecraft.util.math.Vec3i;
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
|
||||||
import net.minecraftforge.client.model.pipeline.LightUtil;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import javax.vecmath.Matrix4f;
|
import javax.vecmath.Matrix4f;
|
||||||
|
import java.nio.FloatBuffer;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
public class TileEntityTurtleRenderer extends BlockEntityRenderer<TileTurtle>
|
||||||
{
|
{
|
||||||
private static final ModelResourceLocation NORMAL_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_normal", "inventory" );
|
private static final ModelIdentifier NORMAL_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_normal", "inventory" );
|
||||||
private static final ModelResourceLocation ADVANCED_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_advanced", "inventory" );
|
private static final ModelIdentifier ADVANCED_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_advanced", "inventory" );
|
||||||
private static final ModelResourceLocation COLOUR_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle_colour", "inventory" );
|
private static final ModelIdentifier COLOUR_TURTLE_MODEL = new ModelIdentifier( "computercraft:turtle_colour", "inventory" );
|
||||||
private static final ModelResourceLocation ELF_OVERLAY_MODEL = new ModelResourceLocation( "computercraft:turtle_elf_overlay", "inventory" );
|
private static final ModelIdentifier ELF_OVERLAY_MODEL = new ModelIdentifier( "computercraft:turtle_elf_overlay", "inventory" );
|
||||||
|
|
||||||
|
private static final FloatBuffer matrixBuf = BufferUtils.createFloatBuffer( 16 );
|
||||||
|
|
||||||
@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 )
|
||||||
@@ -53,7 +52,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
if( tileEntity != null ) renderTurtleAt( tileEntity, posX, posY, posZ, partialTicks );
|
if( tileEntity != null ) renderTurtleAt( tileEntity, posX, posY, posZ, partialTicks );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModelResourceLocation getTurtleModel( ComputerFamily family, boolean coloured )
|
public static ModelIdentifier getTurtleModel( ComputerFamily family, boolean coloured )
|
||||||
{
|
{
|
||||||
switch( family )
|
switch( family )
|
||||||
{
|
{
|
||||||
@@ -65,11 +64,11 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModelResourceLocation getTurtleOverlayModel( ResourceLocation overlay, boolean christmas )
|
public static ModelIdentifier getTurtleOverlayModel( Identifier overlay, boolean christmas )
|
||||||
{
|
{
|
||||||
if( overlay != null )
|
if( overlay != null )
|
||||||
{
|
{
|
||||||
return new ModelResourceLocation( overlay, "inventory" );
|
return new ModelIdentifier( overlay, "inventory" );
|
||||||
}
|
}
|
||||||
else if( christmas )
|
else if( christmas )
|
||||||
{
|
{
|
||||||
@@ -85,21 +84,21 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
{
|
{
|
||||||
// Render the label
|
// Render the label
|
||||||
String label = turtle.createProxy().getLabel();
|
String label = turtle.createProxy().getLabel();
|
||||||
if( label != null && rendererDispatcher.cameraHitResult != null && turtle.getPos().equals( rendererDispatcher.cameraHitResult.getBlockPos() ) )
|
if( label != null && renderManager.hitResult != null && renderManager.hitResult instanceof BlockHitResult && turtle.getPos().equals( ((BlockHitResult) renderManager.hitResult).getBlockPos() ) )
|
||||||
{
|
{
|
||||||
setLightmapDisabled( true );
|
disableLightmap( true );
|
||||||
GameRenderer.drawNameplate(
|
GameRenderer.renderFloatingText(
|
||||||
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
|
renderManager.cameraEntity.getYaw(), renderManager.cameraEntity.getPitch(), false
|
||||||
);
|
);
|
||||||
setLightmapDisabled( false );
|
disableLightmap( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IBlockState state = turtle.getBlockState();
|
BlockState state = turtle.getCachedState();
|
||||||
// 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 );
|
||||||
@@ -111,18 +110,18 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
{
|
{
|
||||||
// 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.scalef( 1.0f, -1.0f, 1.0f );
|
||||||
GlStateManager.cullFace( GlStateManager.CullFace.FRONT );
|
GlStateManager.cullFace( GlStateManager.FaceSides.FRONT );
|
||||||
}
|
}
|
||||||
GlStateManager.translatef( -0.5f, -0.5f, -0.5f );
|
GlStateManager.translatef( -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();
|
||||||
ResourceLocation overlay = turtle.getOverlay();
|
Identifier overlay = turtle.getOverlay();
|
||||||
|
|
||||||
renderModel( state, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
|
renderModel( state, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
|
||||||
|
|
||||||
// Render the overlay
|
// Render the overlay
|
||||||
ModelResourceLocation overlayModel = getTurtleOverlayModel(
|
ModelIdentifier overlayModel = getTurtleOverlayModel(
|
||||||
overlay,
|
overlay,
|
||||||
HolidayUtil.getCurrentHoliday() == Holiday.Christmas
|
HolidayUtil.getCurrentHoliday() == Holiday.Christmas
|
||||||
);
|
);
|
||||||
@@ -149,11 +148,11 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
GlStateManager.cullFace( GlStateManager.CullFace.BACK );
|
GlStateManager.cullFace( GlStateManager.FaceSides.BACK );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderUpgrade( IBlockState state, TileTurtle turtle, TurtleSide side, float f )
|
private void renderUpgrade( BlockState state, TileTurtle turtle, TurtleSide side, float f )
|
||||||
{
|
{
|
||||||
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
||||||
if( upgrade != null )
|
if( upgrade != null )
|
||||||
@@ -166,12 +165,21 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
GlStateManager.rotatef( -toolAngle, 1.0f, 0.0f, 0.0f );
|
GlStateManager.rotatef( -toolAngle, 1.0f, 0.0f, 0.0f );
|
||||||
GlStateManager.translatef( 0.0f, -0.5f, -0.5f );
|
GlStateManager.translatef( 0.0f, -0.5f, -0.5f );
|
||||||
|
|
||||||
Pair<IBakedModel, Matrix4f> pair = upgrade.getModel( turtle.getAccess(), side );
|
Pair<BakedModel, Matrix4f> pair = upgrade.getModel( turtle.getAccess(), side );
|
||||||
if( pair != null )
|
if( pair != null )
|
||||||
{
|
{
|
||||||
if( pair.getRight() != null )
|
if( pair.getRight() != null )
|
||||||
{
|
{
|
||||||
ForgeHooksClient.multiplyCurrentGlMatrix( pair.getRight() );
|
matrixBuf.clear();
|
||||||
|
float[] t = new float[4];
|
||||||
|
for( int i = 0; i < 4; i++ )
|
||||||
|
{
|
||||||
|
pair.getRight().getColumn( i, t );
|
||||||
|
matrixBuf.put( t );
|
||||||
|
}
|
||||||
|
matrixBuf.flip();
|
||||||
|
|
||||||
|
GlStateManager.multMatrix( matrixBuf );
|
||||||
}
|
}
|
||||||
if( pair.getLeft() != null )
|
if( pair.getLeft() != null )
|
||||||
{
|
{
|
||||||
@@ -186,48 +194,43 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderModel( IBlockState state, ModelResourceLocation modelLocation, int[] tints )
|
private void renderModel( BlockState state, ModelIdentifier modelLocation, int[] tints )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getInstance();
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager();
|
BakedModelManager modelManager = mc.getItemRenderer().getModels().getModelManager();
|
||||||
renderModel( state, modelManager.getModel( modelLocation ), tints );
|
renderModel( state, modelManager.getModel( modelLocation ), tints );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderModel( IBlockState state, IBakedModel model, int[] tints )
|
private void renderModel( BlockState state, BakedModel model, int[] tints )
|
||||||
{
|
{
|
||||||
Random random = new Random( 0 );
|
Random random = new Random( 0 );
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
rendererDispatcher.textureManager.bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
renderManager.textureManager.bindTexture( SpriteAtlasTexture.BLOCK_ATLAS_TEX );
|
||||||
renderQuads( tessellator, model.getQuads( state, null, random, EmptyModelData.INSTANCE ), tints );
|
renderQuads( tessellator, model.getQuads( state, null, random ), tints );
|
||||||
for( EnumFacing facing : DirectionUtil.FACINGS )
|
for( Direction facing : DirectionUtil.FACINGS )
|
||||||
{
|
{
|
||||||
renderQuads( tessellator, model.getQuads( state, facing, random, EmptyModelData.INSTANCE ), tints );
|
renderQuads( tessellator, model.getQuads( state, facing, random ), tints );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderQuads( Tessellator tessellator, List<BakedQuad> quads, int[] tints )
|
private static void renderQuads( Tessellator tessellator, List<BakedQuad> quads, int[] tints )
|
||||||
{
|
{
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
BufferBuilder buffer = tessellator.getBufferBuilder();
|
||||||
VertexFormat format = DefaultVertexFormats.ITEM;
|
VertexFormat format = VertexFormats.POSITION_COLOR_UV_NORMAL;
|
||||||
buffer.begin( GL11.GL_QUADS, format );
|
buffer.begin( GL11.GL_QUADS, format );
|
||||||
for( BakedQuad quad : quads )
|
for( BakedQuad quad : quads )
|
||||||
{
|
{
|
||||||
VertexFormat quadFormat = quad.getFormat();
|
|
||||||
if( quadFormat != format )
|
|
||||||
{
|
|
||||||
tessellator.draw();
|
|
||||||
format = quadFormat;
|
|
||||||
buffer.begin( GL11.GL_QUADS, format );
|
|
||||||
}
|
|
||||||
|
|
||||||
int colour = 0xFFFFFFFF;
|
int colour = 0xFFFFFFFF;
|
||||||
if( quad.hasTintIndex() && tints != null )
|
if( quad.hasColor() && tints != null )
|
||||||
{
|
{
|
||||||
int index = quad.getTintIndex();
|
int index = quad.getColorIndex();
|
||||||
if( index >= 0 && index < tints.length ) colour = tints[index] | 0xFF000000;
|
if( index >= 0 && index < tints.length ) colour = tints[index] | 0xFF000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
LightUtil.renderQuadColor( buffer, quad, colour );
|
buffer.putVertexData( quad.getVertexData() );
|
||||||
|
buffer.setQuadColor( colour );
|
||||||
|
Vec3i normal = quad.getFace().getVector();
|
||||||
|
buffer.postNormal( normal.getX(), normal.getY(), normal.getZ() );
|
||||||
}
|
}
|
||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,14 +7,12 @@
|
|||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.model.IUnbakedModel;
|
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.render.model.ModelLoader;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.render.model.UnbakedModel;
|
||||||
import net.minecraft.resources.IResourceManager;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
|
||||||
import net.minecraftforge.common.model.IModelState;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -24,11 +22,11 @@ import java.util.Set;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class TurtleModelLoader implements ICustomModelLoader
|
public final class TurtleModelLoader
|
||||||
{
|
{
|
||||||
private static final ResourceLocation NORMAL_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_normal" );
|
private static final Identifier NORMAL_TURTLE_MODEL = new Identifier( ComputerCraft.MOD_ID, "block/turtle_normal" );
|
||||||
private static final ResourceLocation ADVANCED_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_advanced" );
|
private static final Identifier ADVANCED_TURTLE_MODEL = new Identifier( ComputerCraft.MOD_ID, "block/turtle_advanced" );
|
||||||
private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_colour" );
|
private static final Identifier COLOUR_TURTLE_MODEL = new Identifier( ComputerCraft.MOD_ID, "block/turtle_colour" );
|
||||||
|
|
||||||
public static final TurtleModelLoader INSTANCE = new TurtleModelLoader();
|
public static final TurtleModelLoader INSTANCE = new TurtleModelLoader();
|
||||||
|
|
||||||
@@ -36,21 +34,14 @@ public final class TurtleModelLoader implements ICustomModelLoader
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean accepts( @Nonnull Identifier name )
|
||||||
public void onResourceManagerReload( @Nonnull IResourceManager manager )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
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( "item/turtle_normal" ) || name.getPath().equals( "item/turtle_advanced" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
public UnbakedModel loadModel( @Nonnull Identifier name )
|
||||||
public IUnbakedModel loadModel( @Nonnull ResourceLocation name )
|
|
||||||
{
|
{
|
||||||
if( name.getNamespace().equals( ComputerCraft.MOD_ID ) )
|
if( name.getNamespace().equals( ComputerCraft.MOD_ID ) )
|
||||||
{
|
{
|
||||||
@@ -66,38 +57,35 @@ public final class TurtleModelLoader implements ICustomModelLoader
|
|||||||
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 UnbakedModel
|
||||||
{
|
{
|
||||||
private final ResourceLocation family;
|
private final Identifier family;
|
||||||
|
|
||||||
private TurtleModel( ResourceLocation family )
|
private TurtleModel( Identifier family ) {this.family = family;}
|
||||||
{
|
|
||||||
this.family = family;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Collection<ResourceLocation> getDependencies()
|
public Collection<Identifier> getModelDependencies()
|
||||||
{
|
{
|
||||||
return Arrays.asList( family, COLOUR_TURTLE_MODEL );
|
return Arrays.asList( family, COLOUR_TURTLE_MODEL );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Collection<ResourceLocation> getTextures( @Nonnull Function<ResourceLocation, IUnbakedModel> modelGetter, @Nonnull Set<String> missingTextureErrors )
|
public Collection<Identifier> getTextureDependencies( @Nonnull Function<Identifier, UnbakedModel> modelGetter, @Nonnull Set<String> missingTextureErrors )
|
||||||
{
|
{
|
||||||
return getDependencies().stream()
|
return getModelDependencies().stream()
|
||||||
.flatMap( x -> modelGetter.apply( x ).getTextures( modelGetter, missingTextureErrors ).stream() )
|
.flatMap( x -> modelGetter.apply( x ).getTextureDependencies( modelGetter, missingTextureErrors ).stream() )
|
||||||
.collect( Collectors.toSet() );
|
.collect( Collectors.toSet() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public IBakedModel bake( @Nonnull Function<ResourceLocation, IUnbakedModel> modelGetter, @Nonnull Function<ResourceLocation, TextureAtlasSprite> spriteGetter, @Nonnull IModelState state, boolean uvlock, @Nonnull VertexFormat format )
|
public BakedModel bake( @Nonnull ModelLoader loader, @Nonnull Function<Identifier, Sprite> spriteGetter, @Nonnull ModelBakeSettings state )
|
||||||
{
|
{
|
||||||
return new TurtleSmartItemModel(
|
return new TurtleSmartItemModel(
|
||||||
modelGetter.apply( family ).bake( modelGetter, spriteGetter, state, uvlock, format ),
|
loader.getOrLoadModel( family ).bake( loader, spriteGetter, state ),
|
||||||
modelGetter.apply( COLOUR_TURTLE_MODEL ).bake( modelGetter, spriteGetter, state, uvlock, format )
|
loader.getOrLoadModel( COLOUR_TURTLE_MODEL ).bake( loader, spriteGetter, state )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,32 +6,31 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.client.renderer.model.BakedQuad;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.model.IBakedModel;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
import net.minecraft.client.render.model.json.ModelItemPropertyOverrideList;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
import net.minecraft.util.math.Direction;
|
||||||
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.*;
|
||||||
|
|
||||||
public class TurtleMultiModel implements IBakedModel
|
public class TurtleMultiModel implements BakedModel
|
||||||
{
|
{
|
||||||
private final IBakedModel m_baseModel;
|
private final BakedModel m_baseModel;
|
||||||
private final IBakedModel m_overlayModel;
|
private final BakedModel m_overlayModel;
|
||||||
private final Matrix4f m_generalTransform;
|
private final Matrix4f m_generalTransform;
|
||||||
private final IBakedModel m_leftUpgradeModel;
|
private final BakedModel m_leftUpgradeModel;
|
||||||
private final Matrix4f m_leftUpgradeTransform;
|
private final Matrix4f m_leftUpgradeTransform;
|
||||||
private final IBakedModel m_rightUpgradeModel;
|
private final BakedModel m_rightUpgradeModel;
|
||||||
private final Matrix4f m_rightUpgradeTransform;
|
private final Matrix4f m_rightUpgradeTransform;
|
||||||
private List<BakedQuad> m_generalQuads = null;
|
private List<BakedQuad> m_generalQuads = null;
|
||||||
private Map<EnumFacing, List<BakedQuad>> m_faceQuads = new EnumMap<>( EnumFacing.class );
|
private Map<Direction, List<BakedQuad>> m_faceQuads = new EnumMap<>( Direction.class );
|
||||||
|
|
||||||
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, Matrix4f generalTransform, IBakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, IBakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform )
|
public TurtleMultiModel( BakedModel baseModel, BakedModel overlayModel, Matrix4f generalTransform, BakedModel leftUpgradeModel, Matrix4f leftUpgradeTransform, BakedModel rightUpgradeModel, Matrix4f rightUpgradeTransform )
|
||||||
{
|
{
|
||||||
// Get the models
|
// Get the models
|
||||||
m_baseModel = baseModel;
|
m_baseModel = baseModel;
|
||||||
@@ -45,15 +44,7 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public List<BakedQuad> getQuads( BlockState state, Direction side, Random 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 +58,17 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BakedQuad> buildQuads( IBlockState state, EnumFacing side, Random rand )
|
private List<BakedQuad> buildQuads( BlockState state, Direction side, Random 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 +78,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,49 +88,45 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAmbientOcclusion()
|
public boolean useAmbientOcclusion()
|
||||||
{
|
{
|
||||||
return m_baseModel.isAmbientOcclusion();
|
return m_baseModel.useAmbientOcclusion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGui3d()
|
public boolean hasDepthInGui()
|
||||||
{
|
{
|
||||||
return m_baseModel.isGui3d();
|
return m_baseModel.hasDepthInGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBuiltInRenderer()
|
public boolean isBuiltin()
|
||||||
{
|
{
|
||||||
return m_baseModel.isBuiltInRenderer();
|
return m_baseModel.isBuiltin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public TextureAtlasSprite getParticleTexture()
|
public Sprite getSprite()
|
||||||
{
|
{
|
||||||
return m_baseModel.getParticleTexture();
|
return m_baseModel.getSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ModelTransformation getTransformation()
|
||||||
public net.minecraft.client.renderer.model.ItemCameraTransforms getItemCameraTransforms()
|
|
||||||
{
|
{
|
||||||
return m_baseModel.getItemCameraTransforms();
|
return m_baseModel.getTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ItemOverrideList getOverrides()
|
public ModelItemPropertyOverrideList getItemPropertyOverrides()
|
||||||
{
|
{
|
||||||
return ItemOverrideList.EMPTY;
|
return ModelItemPropertyOverrideList.EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,26 +12,31 @@ import dan200.computercraft.api.turtle.TurtleSide;
|
|||||||
import dan200.computercraft.shared.turtle.items.ItemTurtle;
|
import dan200.computercraft.shared.turtle.items.ItemTurtle;
|
||||||
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.BlockState;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.model.*;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.render.model.BakedModelManager;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
|
import net.minecraft.client.render.model.json.ModelItemPropertyOverrideList;
|
||||||
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||||
|
import net.minecraft.client.texture.Sprite;
|
||||||
|
import net.minecraft.client.util.ModelIdentifier;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.math.Direction;
|
||||||
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.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class TurtleSmartItemModel implements IBakedModel
|
public class TurtleSmartItemModel implements BakedModel
|
||||||
{
|
{
|
||||||
private static final Matrix4f s_identity, s_flip;
|
private static final Matrix4f s_identity, s_flip;
|
||||||
|
|
||||||
@@ -51,11 +56,11 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
final boolean m_colour;
|
final boolean m_colour;
|
||||||
final ITurtleUpgrade m_leftUpgrade;
|
final ITurtleUpgrade m_leftUpgrade;
|
||||||
final ITurtleUpgrade m_rightUpgrade;
|
final ITurtleUpgrade m_rightUpgrade;
|
||||||
final ResourceLocation m_overlay;
|
final Identifier m_overlay;
|
||||||
final boolean m_christmas;
|
final boolean m_christmas;
|
||||||
final boolean m_flip;
|
final boolean m_flip;
|
||||||
|
|
||||||
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas, boolean flip )
|
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, Identifier overlay, boolean christmas, boolean flip )
|
||||||
{
|
{
|
||||||
m_colour = colour;
|
m_colour = colour;
|
||||||
m_leftUpgrade = leftUpgrade;
|
m_leftUpgrade = leftUpgrade;
|
||||||
@@ -95,35 +100,35 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IBakedModel familyModel;
|
private final BakedModel familyModel;
|
||||||
private final IBakedModel colourModel;
|
private final BakedModel colourModel;
|
||||||
|
|
||||||
private HashMap<TurtleModelCombination, IBakedModel> m_cachedModels;
|
private HashMap<TurtleModelCombination, BakedModel> m_cachedModels;
|
||||||
private ItemOverrideList m_overrides;
|
private ModelItemPropertyOverrideList m_overrides;
|
||||||
|
|
||||||
public TurtleSmartItemModel( IBakedModel familyModel, IBakedModel colourModel )
|
public TurtleSmartItemModel( BakedModel familyModel, BakedModel colourModel )
|
||||||
{
|
{
|
||||||
this.familyModel = familyModel;
|
this.familyModel = familyModel;
|
||||||
this.colourModel = colourModel;
|
this.colourModel = colourModel;
|
||||||
|
|
||||||
m_cachedModels = new HashMap<>();
|
m_cachedModels = new HashMap<>();
|
||||||
m_overrides = new ItemOverrideList()
|
m_overrides = new ModelItemPropertyOverrideList( null, null, null, Collections.emptyList() )
|
||||||
{
|
{
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IBakedModel getModelWithOverrides( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity )
|
public BakedModel apply( @Nonnull BakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable LivingEntity entity )
|
||||||
{
|
{
|
||||||
ItemTurtle turtle = (ItemTurtle) stack.getItem();
|
ItemTurtle turtle = (ItemTurtle) 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 );
|
||||||
ResourceLocation overlay = turtle.getOverlay( stack );
|
Identifier overlay = turtle.getOverlay( stack );
|
||||||
boolean christmas = HolidayUtil.getCurrentHoliday() == Holiday.Christmas;
|
boolean christmas = HolidayUtil.getCurrentHoliday() == Holiday.Christmas;
|
||||||
String label = turtle.getLabel( stack );
|
String label = turtle.getLabel( stack );
|
||||||
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
|
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
|
||||||
TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
|
TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
|
||||||
|
|
||||||
IBakedModel model = m_cachedModels.get( combo );
|
BakedModel model = m_cachedModels.get( combo );
|
||||||
if( model == null ) m_cachedModels.put( combo, model = buildModel( combo ) );
|
if( model == null ) m_cachedModels.put( combo, model = buildModel( combo ) );
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
@@ -132,22 +137,22 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ItemOverrideList getOverrides()
|
public ModelItemPropertyOverrideList getItemPropertyOverrides()
|
||||||
{
|
{
|
||||||
return m_overrides;
|
return m_overrides;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IBakedModel buildModel( TurtleModelCombination combo )
|
private BakedModel buildModel( TurtleModelCombination combo )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getInstance();
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager();
|
BakedModelManager modelManager = mc.getItemRenderer().getModels().getModelManager();
|
||||||
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas );
|
ModelIdentifier overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas );
|
||||||
|
|
||||||
IBakedModel baseModel = combo.m_colour ? colourModel : familyModel;
|
BakedModel baseModel = combo.m_colour ? colourModel : familyModel;
|
||||||
IBakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
|
BakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
|
||||||
Matrix4f transform = combo.m_flip ? s_flip : s_identity;
|
Matrix4f transform = combo.m_flip ? s_flip : s_identity;
|
||||||
Pair<IBakedModel, Matrix4f> leftModel = combo.m_leftUpgrade != null ? combo.m_leftUpgrade.getModel( null, TurtleSide.Left ) : null;
|
Pair<BakedModel, Matrix4f> leftModel = combo.m_leftUpgrade != null ? combo.m_leftUpgrade.getModel( null, TurtleSide.Left ) : null;
|
||||||
Pair<IBakedModel, Matrix4f> rightModel = combo.m_rightUpgrade != null ? combo.m_rightUpgrade.getModel( null, TurtleSide.Right ) : null;
|
Pair<BakedModel, Matrix4f> rightModel = combo.m_rightUpgrade != null ? combo.m_rightUpgrade.getModel( null, TurtleSide.Right ) : null;
|
||||||
if( leftModel != null && rightModel != null )
|
if( leftModel != null && rightModel != null )
|
||||||
{
|
{
|
||||||
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel.getLeft(), leftModel.getRight(), rightModel.getLeft(), rightModel.getRight() );
|
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel.getLeft(), leftModel.getRight(), rightModel.getLeft(), rightModel.getRight() );
|
||||||
@@ -168,51 +173,38 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public List<BakedQuad> getQuads( BlockState state, Direction facing, Random 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
|
@Override
|
||||||
@Deprecated
|
public boolean useAmbientOcclusion()
|
||||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, @Nonnull Random rand, @Nonnull IModelData data )
|
|
||||||
{
|
{
|
||||||
return familyModel.getQuads( state, facing, rand, data );
|
return familyModel.useAmbientOcclusion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAmbientOcclusion()
|
public boolean hasDepthInGui()
|
||||||
{
|
{
|
||||||
return familyModel.isAmbientOcclusion();
|
return familyModel.hasDepthInGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGui3d()
|
public boolean isBuiltin()
|
||||||
{
|
{
|
||||||
return familyModel.isGui3d();
|
return familyModel.isBuiltin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBuiltInRenderer()
|
public Sprite getSprite()
|
||||||
{
|
{
|
||||||
return familyModel.isBuiltInRenderer();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public TextureAtlasSprite getParticleTexture()
|
public ModelTransformation getTransformation()
|
||||||
{
|
{
|
||||||
return familyModel.getParticleTexture();
|
return familyModel.getTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public ItemCameraTransforms getItemCameraTransforms()
|
|
||||||
{
|
|
||||||
return familyModel.getItemCameraTransforms();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ public class FSAPI implements ILuaAPI
|
|||||||
@Override
|
@Override
|
||||||
public String[] getNames()
|
public String[] getNames()
|
||||||
{
|
{
|
||||||
return new String[] { "fs" };
|
return new String[] {
|
||||||
|
"fs"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
@Override
|
@Override
|
||||||
public String[] getNames()
|
public String[] getNames()
|
||||||
{
|
{
|
||||||
return new String[] { "http" };
|
return new String[] {
|
||||||
|
"http"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -81,7 +83,6 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings( "resource" )
|
|
||||||
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException
|
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException
|
||||||
{
|
{
|
||||||
switch( method )
|
switch( method )
|
||||||
@@ -94,7 +95,7 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
|
|
||||||
if( args.length >= 1 && args[0] instanceof Map )
|
if( args.length >= 1 && args[0] instanceof Map )
|
||||||
{
|
{
|
||||||
Map<?, ?> options = (Map<?, ?>) args[0];
|
Map<?, ?> options = (Map) args[0];
|
||||||
address = getStringField( options, "url" );
|
address = getStringField( options, "url" );
|
||||||
postString = optStringField( options, "body", null );
|
postString = optStringField( options, "body", null );
|
||||||
headerTable = optTableField( options, "headers", Collections.emptyMap() );
|
headerTable = optTableField( options, "headers", Collections.emptyMap() );
|
||||||
@@ -134,6 +135,7 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
URI uri = HttpRequest.checkUri( address );
|
URI uri = HttpRequest.checkUri( address );
|
||||||
|
|
||||||
HttpRequest request = new HttpRequest( requests, m_apiEnvironment, address, postString, headers, binary, redirect );
|
HttpRequest request = new HttpRequest( requests, m_apiEnvironment, address, postString, headers, binary, redirect );
|
||||||
|
|
||||||
long requestBody = request.body().readableBytes() + HttpRequest.getHeaderSize( headers );
|
long requestBody = request.body().readableBytes() + HttpRequest.getHeaderSize( headers );
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ package dan200.computercraft.core.apis;
|
|||||||
* This exists purely to ensure binary compatibility.
|
* This exists purely to ensure binary compatibility.
|
||||||
*
|
*
|
||||||
* @see dan200.computercraft.api.lua.ILuaAPI
|
* @see dan200.computercraft.api.lua.ILuaAPI
|
||||||
* @deprecated Use the version in the public API. Only exists for compatibility with CCEmuX.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public interface ILuaAPI extends dan200.computercraft.api.lua.ILuaAPI
|
public interface ILuaAPI extends dan200.computercraft.api.lua.ILuaAPI
|
||||||
|
|||||||
@@ -1,281 +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.apis;
|
|
||||||
|
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.format.DateTimeFormatterBuilder;
|
|
||||||
import java.time.format.TextStyle;
|
|
||||||
import java.time.temporal.*;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.LongUnaryOperator;
|
|
||||||
|
|
||||||
final class LuaDateTime
|
|
||||||
{
|
|
||||||
private LuaDateTime()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void format( DateTimeFormatterBuilder formatter, String format, ZoneOffset offset ) throws LuaException
|
|
||||||
{
|
|
||||||
for( int i = 0; i < format.length(); )
|
|
||||||
{
|
|
||||||
char c;
|
|
||||||
switch( c = format.charAt( i++ ) )
|
|
||||||
{
|
|
||||||
case '\n':
|
|
||||||
formatter.appendLiteral( '\n' );
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
formatter.appendLiteral( c );
|
|
||||||
break;
|
|
||||||
case '%':
|
|
||||||
if( i >= format.length() ) break;
|
|
||||||
switch( c = format.charAt( i++ ) )
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
throw new LuaException( "bad argument #1: invalid conversion specifier '%" + c + "'" );
|
|
||||||
|
|
||||||
case '%':
|
|
||||||
formatter.appendLiteral( '%' );
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
formatter.appendText( ChronoField.DAY_OF_WEEK, TextStyle.SHORT );
|
|
||||||
break;
|
|
||||||
case 'A':
|
|
||||||
formatter.appendText( ChronoField.DAY_OF_WEEK, TextStyle.FULL );
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
case 'h':
|
|
||||||
formatter.appendText( ChronoField.MONTH_OF_YEAR, TextStyle.SHORT );
|
|
||||||
break;
|
|
||||||
case 'B':
|
|
||||||
formatter.appendText( ChronoField.MONTH_OF_YEAR, TextStyle.FULL );
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
format( formatter, "%a %b %e %H:%M:%S %Y", offset );
|
|
||||||
break;
|
|
||||||
case 'C':
|
|
||||||
formatter.appendValueReduced( CENTURY, 2, 2, 0 );
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
formatter.appendValue( ChronoField.DAY_OF_MONTH, 2 );
|
|
||||||
break;
|
|
||||||
case 'D':
|
|
||||||
case 'x':
|
|
||||||
format( formatter, "%m/%d/%y", offset );
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
formatter.padNext( 2 ).appendValue( ChronoField.DAY_OF_MONTH );
|
|
||||||
break;
|
|
||||||
case 'F':
|
|
||||||
format( formatter, "%Y-%m-%d", offset );
|
|
||||||
break;
|
|
||||||
case 'g':
|
|
||||||
formatter.appendValueReduced( IsoFields.WEEK_BASED_YEAR, 2, 2, 0 );
|
|
||||||
break;
|
|
||||||
case 'G':
|
|
||||||
formatter.appendValue( IsoFields.WEEK_BASED_YEAR );
|
|
||||||
break;
|
|
||||||
case 'H':
|
|
||||||
formatter.appendValue( ChronoField.HOUR_OF_DAY, 2 );
|
|
||||||
break;
|
|
||||||
case 'I':
|
|
||||||
formatter.appendValue( ChronoField.HOUR_OF_AMPM );
|
|
||||||
break;
|
|
||||||
case 'j':
|
|
||||||
formatter.appendValue( ChronoField.DAY_OF_YEAR, 3 );
|
|
||||||
break;
|
|
||||||
case 'm':
|
|
||||||
formatter.appendValue( ChronoField.MONTH_OF_YEAR, 2 );
|
|
||||||
break;
|
|
||||||
case 'M':
|
|
||||||
formatter.appendValue( ChronoField.MINUTE_OF_HOUR, 2 );
|
|
||||||
break;
|
|
||||||
case 'n':
|
|
||||||
formatter.appendLiteral( '\n' );
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
formatter.appendText( ChronoField.AMPM_OF_DAY );
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
format( formatter, "%I:%M:%S %p", offset );
|
|
||||||
break;
|
|
||||||
case 'R':
|
|
||||||
format( formatter, "%H:%M", offset );
|
|
||||||
break;
|
|
||||||
case 'S':
|
|
||||||
formatter.appendValue( ChronoField.SECOND_OF_MINUTE, 2 );
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
formatter.appendLiteral( '\t' );
|
|
||||||
break;
|
|
||||||
case 'T':
|
|
||||||
case 'X':
|
|
||||||
format( formatter, "%H:%M:%S", offset );
|
|
||||||
break;
|
|
||||||
case 'u':
|
|
||||||
formatter.appendValue( ChronoField.DAY_OF_WEEK );
|
|
||||||
break;
|
|
||||||
case 'U':
|
|
||||||
formatter.appendValue( ChronoField.ALIGNED_WEEK_OF_YEAR, 2 );
|
|
||||||
break;
|
|
||||||
case 'V':
|
|
||||||
formatter.appendValue( IsoFields.WEEK_OF_WEEK_BASED_YEAR, 2 );
|
|
||||||
break;
|
|
||||||
case 'w':
|
|
||||||
formatter.appendValue( ZERO_WEEK );
|
|
||||||
break;
|
|
||||||
case 'W':
|
|
||||||
formatter.appendValue( WeekFields.ISO.weekOfYear(), 2 );
|
|
||||||
break;
|
|
||||||
case 'y':
|
|
||||||
formatter.appendValueReduced( ChronoField.YEAR, 2, 2, 0 );
|
|
||||||
break;
|
|
||||||
case 'Y':
|
|
||||||
formatter.appendValue( ChronoField.YEAR );
|
|
||||||
break;
|
|
||||||
case 'z':
|
|
||||||
formatter.appendOffset( "+HHMM", "+0000" );
|
|
||||||
break;
|
|
||||||
case 'Z':
|
|
||||||
formatter.appendChronologyId();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static long fromTable( Map<?, ?> table ) throws LuaException
|
|
||||||
{
|
|
||||||
int year = getField( table, "year", -1 );
|
|
||||||
int month = getField( table, "month", -1 );
|
|
||||||
int day = getField( table, "day", -1 );
|
|
||||||
int hour = getField( table, "hour", 12 );
|
|
||||||
int minute = getField( table, "min", 12 );
|
|
||||||
int second = getField( table, "sec", 12 );
|
|
||||||
LocalDateTime time = LocalDateTime.of( year, month, day, hour, minute, second );
|
|
||||||
|
|
||||||
Boolean isDst = getBoolField( table, "isdst" );
|
|
||||||
if( isDst != null )
|
|
||||||
{
|
|
||||||
boolean requireDst = isDst;
|
|
||||||
for( ZoneOffset possibleOffset : ZoneOffset.systemDefault().getRules().getValidOffsets( time ) )
|
|
||||||
{
|
|
||||||
Instant instant = time.toInstant( possibleOffset );
|
|
||||||
if( possibleOffset.getRules().getDaylightSavings( instant ).isZero() == requireDst )
|
|
||||||
{
|
|
||||||
return instant.getEpochSecond();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ZoneOffset offset = ZoneOffset.systemDefault().getRules().getOffset( time );
|
|
||||||
return time.toInstant( offset ).getEpochSecond();
|
|
||||||
}
|
|
||||||
|
|
||||||
static Map<String, ?> toTable( TemporalAccessor date, ZoneId offset, Instant instant )
|
|
||||||
{
|
|
||||||
HashMap<String, Object> table = new HashMap<>( 9 );
|
|
||||||
table.put( "year", date.getLong( ChronoField.YEAR ) );
|
|
||||||
table.put( "month", date.getLong( ChronoField.MONTH_OF_YEAR ) );
|
|
||||||
table.put( "day", date.getLong( ChronoField.DAY_OF_MONTH ) );
|
|
||||||
table.put( "hour", date.getLong( ChronoField.HOUR_OF_DAY ) );
|
|
||||||
table.put( "min", date.getLong( ChronoField.MINUTE_OF_HOUR ) );
|
|
||||||
table.put( "sec", date.getLong( ChronoField.SECOND_OF_MINUTE ) );
|
|
||||||
table.put( "wday", date.getLong( WeekFields.SUNDAY_START.dayOfWeek() ) );
|
|
||||||
table.put( "yday", date.getLong( ChronoField.DAY_OF_YEAR ) );
|
|
||||||
table.put( "isdst", offset.getRules().isDaylightSavings( instant ) );
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getField( Map<?, ?> table, String field, int def ) throws LuaException
|
|
||||||
{
|
|
||||||
Object value = table.get( field );
|
|
||||||
if( value instanceof Number ) return ((Number) value).intValue();
|
|
||||||
if( def < 0 ) throw new LuaException( "field \"" + field + "\" missing in date table" );
|
|
||||||
return def;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Boolean getBoolField( Map<?, ?> table, String field ) throws LuaException
|
|
||||||
{
|
|
||||||
Object value = table.get( field );
|
|
||||||
if( value instanceof Boolean || value == null ) return (Boolean) value;
|
|
||||||
throw new LuaException( "field \"" + field + "\" missing in date table" );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final TemporalField CENTURY = map( ChronoField.YEAR, ValueRange.of( 0, 6 ), x -> (x / 100) % 100 );
|
|
||||||
private static final TemporalField ZERO_WEEK = map( WeekFields.SUNDAY_START.dayOfWeek(), ValueRange.of( 0, 6 ), x -> x - 1 );
|
|
||||||
|
|
||||||
private static TemporalField map( TemporalField field, ValueRange range, LongUnaryOperator convert )
|
|
||||||
{
|
|
||||||
return new TemporalField()
|
|
||||||
{
|
|
||||||
private final ValueRange range = ValueRange.of( 0, 99 );
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TemporalUnit getBaseUnit()
|
|
||||||
{
|
|
||||||
return field.getBaseUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TemporalUnit getRangeUnit()
|
|
||||||
{
|
|
||||||
return field.getRangeUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ValueRange range()
|
|
||||||
{
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDateBased()
|
|
||||||
{
|
|
||||||
return field.isDateBased();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isTimeBased()
|
|
||||||
{
|
|
||||||
return field.isTimeBased();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSupportedBy( TemporalAccessor temporal )
|
|
||||||
{
|
|
||||||
return field.isSupportedBy( temporal );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ValueRange rangeRefinedBy( TemporalAccessor temporal )
|
|
||||||
{
|
|
||||||
return range;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getFrom( TemporalAccessor temporal )
|
|
||||||
{
|
|
||||||
return convert.applyAsLong( temporal.getLong( field ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings( "unchecked" )
|
|
||||||
public <R extends Temporal> R adjustInto( R temporal, long newValue )
|
|
||||||
{
|
|
||||||
return (R) temporal.with( field, newValue );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,11 +12,6 @@ import dan200.computercraft.api.lua.LuaException;
|
|||||||
import dan200.computercraft.shared.util.StringUtil;
|
import dan200.computercraft.shared.util.StringUtil;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.time.ZoneOffset;
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.time.format.DateTimeFormatterBuilder;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
||||||
@@ -36,9 +31,9 @@ public class OSAPI implements ILuaAPI
|
|||||||
|
|
||||||
private static class Timer
|
private static class Timer
|
||||||
{
|
{
|
||||||
int m_ticksLeft;
|
public int m_ticksLeft;
|
||||||
|
|
||||||
Timer( int ticksLeft )
|
public Timer( int ticksLeft )
|
||||||
{
|
{
|
||||||
m_ticksLeft = ticksLeft;
|
m_ticksLeft = ticksLeft;
|
||||||
}
|
}
|
||||||
@@ -46,10 +41,10 @@ public class OSAPI implements ILuaAPI
|
|||||||
|
|
||||||
private static class Alarm implements Comparable<Alarm>
|
private static class Alarm implements Comparable<Alarm>
|
||||||
{
|
{
|
||||||
final double m_time;
|
public final double m_time;
|
||||||
final int m_day;
|
public final int m_day;
|
||||||
|
|
||||||
Alarm( double time, int day )
|
public Alarm( double time, int day )
|
||||||
{
|
{
|
||||||
m_time = time;
|
m_time = time;
|
||||||
m_day = day;
|
m_day = day;
|
||||||
@@ -78,7 +73,9 @@ public class OSAPI implements ILuaAPI
|
|||||||
@Override
|
@Override
|
||||||
public String[] getNames()
|
public String[] getNames()
|
||||||
{
|
{
|
||||||
return new String[] { "os" };
|
return new String[] {
|
||||||
|
"os"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -187,12 +184,11 @@ public class OSAPI implements ILuaAPI
|
|||||||
"day",
|
"day",
|
||||||
"cancelTimer",
|
"cancelTimer",
|
||||||
"cancelAlarm",
|
"cancelAlarm",
|
||||||
"epoch",
|
"epoch"
|
||||||
"date",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float getTimeForCalendar( Calendar c )
|
private float getTimeForCalendar( Calendar c )
|
||||||
{
|
{
|
||||||
float time = c.get( Calendar.HOUR_OF_DAY );
|
float time = c.get( Calendar.HOUR_OF_DAY );
|
||||||
time += c.get( Calendar.MINUTE ) / 60.0f;
|
time += c.get( Calendar.MINUTE ) / 60.0f;
|
||||||
@@ -200,7 +196,7 @@ public class OSAPI implements ILuaAPI
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getDayForCalendar( Calendar c )
|
private int getDayForCalendar( Calendar c )
|
||||||
{
|
{
|
||||||
GregorianCalendar g = c instanceof GregorianCalendar ? (GregorianCalendar) c : new GregorianCalendar();
|
GregorianCalendar g = c instanceof GregorianCalendar ? (GregorianCalendar) c : new GregorianCalendar();
|
||||||
int year = c.get( Calendar.YEAR );
|
int year = c.get( Calendar.YEAR );
|
||||||
@@ -213,7 +209,7 @@ public class OSAPI implements ILuaAPI
|
|||||||
return day;
|
return day;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long getEpochForCalendar( Calendar c )
|
private long getEpochForCalendar( Calendar c )
|
||||||
{
|
{
|
||||||
return c.getTime().getTime();
|
return c.getTime().getTime();
|
||||||
}
|
}
|
||||||
@@ -286,9 +282,6 @@ public class OSAPI implements ILuaAPI
|
|||||||
case 11:
|
case 11:
|
||||||
{
|
{
|
||||||
// time
|
// time
|
||||||
Object value = args.length > 0 ? args[0] : null;
|
|
||||||
if( value instanceof Map ) return new Object[] { LuaDateTime.fromTable( (Map<?, ?>) value ) };
|
|
||||||
|
|
||||||
String param = optString( args, 0, "ingame" );
|
String param = optString( args, 0, "ingame" );
|
||||||
switch( param.toLowerCase( Locale.ROOT ) )
|
switch( param.toLowerCase( Locale.ROOT ) )
|
||||||
{
|
{
|
||||||
@@ -362,8 +355,9 @@ public class OSAPI implements ILuaAPI
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 15: // epoch
|
case 15:
|
||||||
{
|
{
|
||||||
|
// epoch
|
||||||
String param = optString( args, 0, "ingame" );
|
String param = optString( args, 0, "ingame" );
|
||||||
switch( param.toLowerCase( Locale.ROOT ) )
|
switch( param.toLowerCase( Locale.ROOT ) )
|
||||||
{
|
{
|
||||||
@@ -383,39 +377,14 @@ public class OSAPI implements ILuaAPI
|
|||||||
// Get in-game epoch
|
// Get in-game epoch
|
||||||
synchronized( m_alarms )
|
synchronized( m_alarms )
|
||||||
{
|
{
|
||||||
return new Object[] { m_day * 86400000 + (int) (m_time * 3600000.0f) };
|
return new Object[] {
|
||||||
|
m_day * 86400000 + (int) (m_time * 3600000.0f)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new LuaException( "Unsupported operation" );
|
throw new LuaException( "Unsupported operation" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 16: // date
|
|
||||||
{
|
|
||||||
String format = optString( args, 0, "%c" );
|
|
||||||
long time = optLong( args, 1, Instant.now().getEpochSecond() );
|
|
||||||
|
|
||||||
Instant instant = Instant.ofEpochSecond( time );
|
|
||||||
ZonedDateTime date;
|
|
||||||
ZoneOffset offset;
|
|
||||||
if( format.startsWith( "!" ) )
|
|
||||||
{
|
|
||||||
offset = ZoneOffset.UTC;
|
|
||||||
date = ZonedDateTime.ofInstant( instant, offset );
|
|
||||||
format = format.substring( 1 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ZoneId id = ZoneId.systemDefault();
|
|
||||||
offset = id.getRules().getOffset( instant );
|
|
||||||
date = ZonedDateTime.ofInstant( instant, id );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( format.equals( "*t" ) ) return new Object[] { LuaDateTime.toTable( date, offset, instant ) };
|
|
||||||
|
|
||||||
DateTimeFormatterBuilder formatter = new DateTimeFormatterBuilder();
|
|
||||||
LuaDateTime.format( formatter, format, offset );
|
|
||||||
return new Object[] { formatter.toFormatter( Locale.ROOT ).format( date ) };
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
private Map<String, Integer> m_methodMap;
|
private Map<String, Integer> m_methodMap;
|
||||||
private boolean m_attached;
|
private boolean m_attached;
|
||||||
|
|
||||||
PeripheralWrapper( IPeripheral peripheral, String side )
|
public PeripheralWrapper( IPeripheral peripheral, String side )
|
||||||
{
|
{
|
||||||
super( m_environment );
|
super( m_environment );
|
||||||
m_side = side;
|
m_side = side;
|
||||||
@@ -282,7 +282,9 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
@Override
|
@Override
|
||||||
public String[] getNames()
|
public String[] getNames()
|
||||||
{
|
{
|
||||||
return new String[] { "peripheral" };
|
return new String[] {
|
||||||
|
"peripheral"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -324,7 +326,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
"isPresent",
|
"isPresent",
|
||||||
"getType",
|
"getType",
|
||||||
"getMethods",
|
"getMethods",
|
||||||
"call",
|
"call"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,6 +356,7 @@ public class PeripheralAPI implements ILuaAPI, IAPIEnvironment.IPeripheralChange
|
|||||||
ComputerSide side = ComputerSide.valueOfInsensitive( getString( args, 0 ) );
|
ComputerSide side = ComputerSide.valueOfInsensitive( getString( args, 0 ) );
|
||||||
if( side != null )
|
if( side != null )
|
||||||
{
|
{
|
||||||
|
String type = null;
|
||||||
synchronized( m_peripherals )
|
synchronized( m_peripherals )
|
||||||
{
|
{
|
||||||
PeripheralWrapper p = m_peripherals[side.ordinal()];
|
PeripheralWrapper p = m_peripherals[side.ordinal()];
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ public class RedstoneAPI implements ILuaAPI
|
|||||||
@Override
|
@Override
|
||||||
public String[] getNames()
|
public String[] getNames()
|
||||||
{
|
{
|
||||||
return new String[] { "rs", "redstone" };
|
return new String[] {
|
||||||
|
"rs", "redstone"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ public class TermAPI implements ILuaAPI
|
|||||||
@Override
|
@Override
|
||||||
public String[] getNames()
|
public String[] getNames()
|
||||||
{
|
{
|
||||||
return new String[] { "term" };
|
return new String[] {
|
||||||
|
"term"
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -87,7 +89,9 @@ public class TermAPI implements ILuaAPI
|
|||||||
|
|
||||||
public static Object[] encodeColour( int colour ) throws LuaException
|
public static Object[] encodeColour( int colour ) throws LuaException
|
||||||
{
|
{
|
||||||
return new Object[] { 1 << colour };
|
return new Object[] {
|
||||||
|
1 << colour
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setColour( Terminal terminal, int colour, double r, double g, double b )
|
public static void setColour( Terminal terminal, int colour, double r, double g, double b )
|
||||||
|
|||||||
@@ -212,7 +212,6 @@ public class BinaryReadableHandle extends HandleGeneric
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 3: // close
|
case 3: // close
|
||||||
checkOpen();
|
|
||||||
close();
|
close();
|
||||||
return null;
|
return null;
|
||||||
case 4: // seek
|
case 4: // seek
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ public class BinaryWritableHandle extends HandleGeneric
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 2: // close
|
case 2: // close
|
||||||
checkOpen();
|
|
||||||
close();
|
close();
|
||||||
return null;
|
return null;
|
||||||
case 3: // seek
|
case 3: // seek
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ public class EncodedReadableHandle extends HandleGeneric
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 3: // close
|
case 3: // close
|
||||||
checkOpen();
|
|
||||||
close();
|
close();
|
||||||
return null;
|
return null;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ public class EncodedWritableHandle extends HandleGeneric
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
case 3: // close
|
case 3: // close
|
||||||
checkOpen();
|
|
||||||
close();
|
close();
|
||||||
return null;
|
return null;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -37,13 +37,8 @@ public abstract class HandleGeneric implements ILuaObject
|
|||||||
protected final void close()
|
protected final void close()
|
||||||
{
|
{
|
||||||
m_open = false;
|
m_open = false;
|
||||||
|
IoUtil.closeQuietly( m_closable );
|
||||||
Closeable closeable = m_closable;
|
m_closable = null;
|
||||||
if( closeable != null )
|
|
||||||
{
|
|
||||||
IoUtil.closeQuietly( closeable );
|
|
||||||
m_closable = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ public abstract class Resource<T extends Resource<T>> implements Closeable
|
|||||||
*/
|
*/
|
||||||
protected void dispose()
|
protected void dispose()
|
||||||
{
|
{
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" ) T thisT = (T) this;
|
||||||
T thisT = (T) this;
|
|
||||||
limiter.release( thisT );
|
limiter.release( thisT );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +95,7 @@ public abstract class Resource<T extends Resource<T>> implements Closeable
|
|||||||
|
|
||||||
public boolean queue( Consumer<T> task )
|
public boolean queue( Consumer<T> task )
|
||||||
{
|
{
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" ) T thisT = (T) this;
|
||||||
T thisT = (T) this;
|
|
||||||
return limiter.queue( thisT, () -> task.accept( thisT ) );
|
return limiter.queue( thisT, () -> task.accept( thisT ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import java.io.Closeable;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
|
import static dan200.computercraft.core.apis.ArgumentHelper.optBoolean;
|
||||||
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;
|
||||||
|
|
||||||
public class WebsocketHandle implements ILuaObject, Closeable
|
public class WebsocketHandle implements ILuaObject, Closeable
|
||||||
@@ -54,18 +53,15 @@ public class WebsocketHandle implements ILuaObject, Closeable
|
|||||||
switch( method )
|
switch( method )
|
||||||
{
|
{
|
||||||
case 0: // receive
|
case 0: // receive
|
||||||
checkOpen();
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
Object[] event = context.pullEvent( null );
|
checkOpen();
|
||||||
if( event.length >= 3 && Objects.equal( event[0], MESSAGE_EVENT ) && Objects.equal( event[1], websocket.address() ) )
|
|
||||||
|
Object[] event = context.pullEvent( MESSAGE_EVENT );
|
||||||
|
if( event.length >= 3 && Objects.equal( event[1], websocket.address() ) )
|
||||||
{
|
{
|
||||||
return Arrays.copyOfRange( event, 2, event.length );
|
return Arrays.copyOfRange( event, 2, event.length );
|
||||||
}
|
}
|
||||||
else if( event.length >= 2 && Objects.equal( event[0], CLOSE_EVENT ) && Objects.equal( event[1], websocket.address() ) && closed )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1: // send
|
case 1: // send
|
||||||
|
|||||||
@@ -30,10 +30,7 @@ public enum ComputerSide
|
|||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
ComputerSide( String name )
|
ComputerSide( String name ) {this.name = name;}
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static ComputerSide valueOf( int side )
|
public static ComputerSide valueOf( int side )
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ public final class ComputerThread
|
|||||||
synchronized( threadLock )
|
synchronized( threadLock )
|
||||||
{
|
{
|
||||||
running = true;
|
running = true;
|
||||||
|
if( monitor == null || !monitor.isAlive() ) (monitor = monitorFactory.newThread( new Monitor() )).start();
|
||||||
|
|
||||||
if( runners == null )
|
if( runners == null )
|
||||||
{
|
{
|
||||||
@@ -157,8 +158,6 @@ public final class ComputerThread
|
|||||||
runnerFactory.newThread( runners[i] = new TaskRunner() ).start();
|
runnerFactory.newThread( runners[i] = new TaskRunner() ).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( monitor == null || !monitor.isAlive() ) (monitor = monitorFactory.newThread( new Monitor() )).start();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,16 +368,7 @@ public final class ComputerThread
|
|||||||
{
|
{
|
||||||
TaskRunner runner = currentRunners[i];
|
TaskRunner runner = currentRunners[i];
|
||||||
// If we've no runner, skip.
|
// If we've no runner, skip.
|
||||||
if( runner == null || runner.owner == null || !runner.owner.isAlive() )
|
if( runner == null ) continue;
|
||||||
{
|
|
||||||
if( !running ) continue;
|
|
||||||
|
|
||||||
// Mark the old runner as dead and start a new one.
|
|
||||||
ComputerCraft.log.warn( "Previous runner ({}) has crashed, restarting!",
|
|
||||||
runner != null && runner.owner != null ? runner.owner.getName() : runner );
|
|
||||||
if( runner != null ) runner.running = false;
|
|
||||||
runnerFactory.newThread( runners[i] = new TaskRunner() ).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the runner has no work, skip
|
// If the runner has no work, skip
|
||||||
ComputerExecutor executor = runner.currentExecutor.get();
|
ComputerExecutor executor = runner.currentExecutor.get();
|
||||||
@@ -502,7 +492,7 @@ public final class ComputerThread
|
|||||||
{
|
{
|
||||||
executor.work();
|
executor.work();
|
||||||
}
|
}
|
||||||
catch( Exception | LinkageError | VirtualMachineError e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
ComputerCraft.log.error( "Error running task on computer #" + executor.getComputer().getID(), e );
|
ComputerCraft.log.error( "Error running task on computer #" + executor.getComputer().getID(), e );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public final class MainThread
|
|||||||
// Of course, we'll go over the MAX_TICK_TIME most of the time, but eventually that overrun will accumulate
|
// Of course, we'll go over the MAX_TICK_TIME most of the time, but eventually that overrun will accumulate
|
||||||
// and we'll skip a whole tick - bringing the average back down again.
|
// and we'll skip a whole tick - bringing the average back down again.
|
||||||
currentTick++;
|
currentTick++;
|
||||||
budget = Math.min( budget + ComputerCraft.maxMainGlobalTime, ComputerCraft.maxMainGlobalTime );
|
budget += Math.min( budget + ComputerCraft.maxMainGlobalTime, ComputerCraft.maxMainGlobalTime );
|
||||||
canExecute = budget > 0;
|
canExecute = budget > 0;
|
||||||
|
|
||||||
// Cool down any warm computers.
|
// Cool down any warm computers.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
import dan200.computercraft.api.peripheral.IWorkMonitor;
|
||||||
import dan200.computercraft.core.tracking.Tracking;
|
import dan200.computercraft.core.tracking.Tracking;
|
||||||
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
import dan200.computercraft.shared.turtle.core.TurtleBrain;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* this tick. At the beginning of the tick, we execute as many {@link MainThread} tasks as possible, until our
|
* this tick. At the beginning of the tick, we execute as many {@link MainThread} tasks as possible, until our
|
||||||
* time-frame or the global time frame has expired.
|
* time-frame or the global time frame has expired.
|
||||||
*
|
*
|
||||||
* Then, when other objects (such as {@link TileEntity}) are ticked, we update how much time we've used using
|
* Then, when other objects (such as {@link BlockEntity}) are ticked, we update how much time we've used using
|
||||||
* {@link IWorkMonitor#trackWork(long, TimeUnit)}.
|
* {@link IWorkMonitor#trackWork(long, TimeUnit)}.
|
||||||
*
|
*
|
||||||
* Now, if anywhere during this period, we use more than our allocated time slice, the executor is marked as
|
* Now, if anywhere during this period, we use more than our allocated time slice, the executor is marked as
|
||||||
@@ -224,7 +224,7 @@ final class MainThreadExecutor implements IWorkMonitor
|
|||||||
{
|
{
|
||||||
state = State.COOLING;
|
state = State.COOLING;
|
||||||
currentTick = MainThread.currentTick();
|
currentTick = MainThread.currentTick();
|
||||||
budget = Math.min( budget + ComputerCraft.maxMainComputerTime, ComputerCraft.maxMainComputerTime );
|
budget += Math.min( budget + ComputerCraft.maxMainComputerTime, ComputerCraft.maxMainComputerTime );
|
||||||
if( budget < ComputerCraft.maxMainComputerTime ) return false;
|
if( budget < ComputerCraft.maxMainComputerTime ) return false;
|
||||||
|
|
||||||
state = State.COOL;
|
state = State.COOL;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
package dan200.computercraft.core.filesystem;
|
package dan200.computercraft.core.filesystem;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.FileOperationException;
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -96,7 +95,7 @@ public class ComboMount implements IMount
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "Not a directory" );
|
throw new IOException( "/" + path + ": Not a directory" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +110,7 @@ public class ComboMount implements IMount
|
|||||||
return part.getSize( path );
|
return part.getSize( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -127,7 +126,7 @@ public class ComboMount implements IMount
|
|||||||
return part.openForRead( path );
|
return part.openForRead( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -142,6 +141,6 @@ public class ComboMount implements IMount
|
|||||||
return part.openChannelForRead( path );
|
return part.openChannelForRead( path );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
package dan200.computercraft.core.filesystem;
|
package dan200.computercraft.core.filesystem;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.FileOperationException;
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -45,7 +44,7 @@ public class EmptyMount implements IMount
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public InputStream openForRead( @Nonnull String path ) throws IOException
|
public InputStream openForRead( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -53,6 +52,6 @@ public class EmptyMount implements IMount
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
public ReadableByteChannel openChannelForRead( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
package dan200.computercraft.core.filesystem;
|
package dan200.computercraft.core.filesystem;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import dan200.computercraft.api.filesystem.FileOperationException;
|
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -168,12 +167,12 @@ public class FileMount implements IWritableMount
|
|||||||
{
|
{
|
||||||
if( !created() )
|
if( !created() )
|
||||||
{
|
{
|
||||||
if( !path.isEmpty() ) throw new FileOperationException( path, "Not a directory" );
|
if( !path.isEmpty() ) throw new IOException( "/" + path + ": Not a directory" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = getRealPath( path );
|
File file = getRealPath( path );
|
||||||
if( !file.exists() || !file.isDirectory() ) throw new FileOperationException( path, "Not a directory" );
|
if( !file.exists() || !file.isDirectory() ) throw new IOException( "/" + path + ": Not a directory" );
|
||||||
|
|
||||||
String[] paths = file.list();
|
String[] paths = file.list();
|
||||||
for( String subPath : paths )
|
for( String subPath : paths )
|
||||||
@@ -195,7 +194,7 @@ public class FileMount implements IWritableMount
|
|||||||
if( file.exists() ) return file.isDirectory() ? 0 : file.length();
|
if( file.exists() ) return file.isDirectory() ? 0 : file.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -209,7 +208,7 @@ public class FileMount implements IWritableMount
|
|||||||
if( file.exists() && !file.isDirectory() ) return new FileInputStream( file );
|
if( file.exists() && !file.isDirectory() ) return new FileInputStream( file );
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -222,7 +221,7 @@ public class FileMount implements IWritableMount
|
|||||||
if( file.exists() && !file.isDirectory() ) return FileChannel.open( file.toPath(), READ_OPTIONS );
|
if( file.exists() && !file.isDirectory() ) return FileChannel.open( file.toPath(), READ_OPTIONS );
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
// IWritableMount implementation
|
// IWritableMount implementation
|
||||||
@@ -234,7 +233,7 @@ public class FileMount implements IWritableMount
|
|||||||
File file = getRealPath( path );
|
File file = getRealPath( path );
|
||||||
if( file.exists() )
|
if( file.exists() )
|
||||||
{
|
{
|
||||||
if( !file.isDirectory() ) throw new FileOperationException( path, "File exists" );
|
if( !file.isDirectory() ) throw new IOException( "/" + path + ": File exists" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +247,7 @@ public class FileMount implements IWritableMount
|
|||||||
|
|
||||||
if( getRemainingSpace() < dirsToCreate * MINIMUM_FILE_SIZE )
|
if( getRemainingSpace() < dirsToCreate * MINIMUM_FILE_SIZE )
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "Out of space" );
|
throw new IOException( "/" + path + ": Out of space" );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( file.mkdirs() )
|
if( file.mkdirs() )
|
||||||
@@ -257,14 +256,14 @@ public class FileMount implements IWritableMount
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "Access denied" );
|
throw new IOException( "/" + path + ": Access denied" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete( @Nonnull String path ) throws IOException
|
public void delete( @Nonnull String path ) throws IOException
|
||||||
{
|
{
|
||||||
if( path.isEmpty() ) throw new FileOperationException( path, "Access denied" );
|
if( path.isEmpty() ) throw new IOException( "/" + path + ": Access denied" );
|
||||||
|
|
||||||
if( created() )
|
if( created() )
|
||||||
{
|
{
|
||||||
@@ -320,7 +319,7 @@ public class FileMount implements IWritableMount
|
|||||||
{
|
{
|
||||||
create();
|
create();
|
||||||
File file = getRealPath( path );
|
File file = getRealPath( path );
|
||||||
if( file.exists() && file.isDirectory() ) throw new FileOperationException( path, "Cannot write to directory" );
|
if( file.exists() && file.isDirectory() ) throw new IOException( "/" + path + ": Cannot write to directory" );
|
||||||
|
|
||||||
if( file.exists() )
|
if( file.exists() )
|
||||||
{
|
{
|
||||||
@@ -328,7 +327,7 @@ public class FileMount implements IWritableMount
|
|||||||
}
|
}
|
||||||
else if( getRemainingSpace() < MINIMUM_FILE_SIZE )
|
else if( getRemainingSpace() < MINIMUM_FILE_SIZE )
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "Out of space" );
|
throw new IOException( "/" + path + ": Out of space" );
|
||||||
}
|
}
|
||||||
m_usedSpace += MINIMUM_FILE_SIZE;
|
m_usedSpace += MINIMUM_FILE_SIZE;
|
||||||
|
|
||||||
@@ -341,12 +340,12 @@ public class FileMount implements IWritableMount
|
|||||||
{
|
{
|
||||||
if( !created() )
|
if( !created() )
|
||||||
{
|
{
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
File file = getRealPath( path );
|
File file = getRealPath( path );
|
||||||
if( !file.exists() ) throw new FileOperationException( path, "No such file" );
|
if( !file.exists() ) throw new IOException( "/" + path + ": No such file" );
|
||||||
if( file.isDirectory() ) throw new FileOperationException( path, "Cannot write to directory" );
|
if( file.isDirectory() ) throw new IOException( "/" + path + ": Cannot write to directory" );
|
||||||
|
|
||||||
// Allowing seeking when appending is not recommended, so we use a separate channel.
|
// Allowing seeking when appending is not recommended, so we use a separate channel.
|
||||||
return new WritableCountingChannel(
|
return new WritableCountingChannel(
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ package dan200.computercraft.core.filesystem;
|
|||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.filesystem.FileOperationException;
|
|
||||||
import dan200.computercraft.api.filesystem.IFileSystem;
|
import dan200.computercraft.api.filesystem.IFileSystem;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
@@ -46,7 +45,7 @@ public class FileSystem
|
|||||||
m_writableMount = null;
|
m_writableMount = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MountWrapper( String label, String location, IWritableMount mount )
|
public MountWrapper( String label, String location, IWritableMount mount )
|
||||||
{
|
{
|
||||||
this( label, location, (IMount) mount );
|
this( label, location, (IMount) mount );
|
||||||
m_writableMount = mount;
|
m_writableMount = mount;
|
||||||
@@ -108,7 +107,7 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,12 +122,12 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw localExceptionOf( path, "Not a directory" );
|
throw new FileSystemException( "/" + path + ": Not a directory" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,12 +149,12 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw localExceptionOf( path, "No such file" );
|
throw new FileSystemException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,12 +169,12 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw localExceptionOf( path, "No such file" );
|
throw new FileSystemException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,14 +182,19 @@ public class FileSystem
|
|||||||
|
|
||||||
public void makeDirectory( String path ) throws FileSystemException
|
public void makeDirectory( String path ) throws FileSystemException
|
||||||
{
|
{
|
||||||
if( m_writableMount == null ) throw exceptionOf( path, "Access denied" );
|
if( m_writableMount == null )
|
||||||
|
{
|
||||||
path = toLocal( path );
|
throw new FileSystemException( "/" + path + ": Access denied" );
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
path = toLocal( path );
|
||||||
if( m_mount.exists( path ) )
|
if( m_mount.exists( path ) )
|
||||||
{
|
{
|
||||||
if( !m_mount.isDirectory( path ) ) throw localExceptionOf( path, "File exists" );
|
if( !m_mount.isDirectory( path ) )
|
||||||
|
{
|
||||||
|
throw new FileSystemException( "/" + path + ": File exists" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -199,14 +203,16 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete( String path ) throws FileSystemException
|
public void delete( String path ) throws FileSystemException
|
||||||
{
|
{
|
||||||
if( m_writableMount == null ) throw exceptionOf( path, "Access denied" );
|
if( m_writableMount == null )
|
||||||
|
{
|
||||||
|
throw new FileSystemException( "/" + path + ": Access denied" );
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
path = toLocal( path );
|
path = toLocal( path );
|
||||||
@@ -221,20 +227,22 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WritableByteChannel openForWrite( String path ) throws FileSystemException
|
public WritableByteChannel openForWrite( String path ) throws FileSystemException
|
||||||
{
|
{
|
||||||
if( m_writableMount == null ) throw exceptionOf( path, "Access denied" );
|
if( m_writableMount == null )
|
||||||
|
{
|
||||||
path = toLocal( path );
|
throw new FileSystemException( "/" + path + ": Access denied" );
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
path = toLocal( path );
|
||||||
if( m_mount.exists( path ) && m_mount.isDirectory( path ) )
|
if( m_mount.exists( path ) && m_mount.isDirectory( path ) )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( path, "Cannot write to directory" );
|
throw new FileSystemException( "/" + path + ": Cannot write to directory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -255,17 +263,19 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public WritableByteChannel openForAppend( String path ) throws FileSystemException
|
public WritableByteChannel openForAppend( String path ) throws FileSystemException
|
||||||
{
|
{
|
||||||
if( m_writableMount == null ) throw exceptionOf( path, "Access denied" );
|
if( m_writableMount == null )
|
||||||
|
{
|
||||||
path = toLocal( path );
|
throw new FileSystemException( "/" + path + ": Access denied" );
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
path = toLocal( path );
|
||||||
if( !m_mount.exists( path ) )
|
if( !m_mount.exists( path ) )
|
||||||
{
|
{
|
||||||
if( !path.isEmpty() )
|
if( !path.isEmpty() )
|
||||||
@@ -280,7 +290,7 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
else if( m_mount.isDirectory( path ) )
|
else if( m_mount.isDirectory( path ) )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( path, "Cannot write to directory" );
|
throw new FileSystemException( "/" + path + ": Cannot write to directory" );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -293,36 +303,16 @@ public class FileSystem
|
|||||||
}
|
}
|
||||||
catch( IOException e )
|
catch( IOException e )
|
||||||
{
|
{
|
||||||
throw localExceptionOf( e );
|
throw new FileSystemException( e.getMessage() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private members
|
||||||
|
|
||||||
private String toLocal( String path )
|
private String toLocal( String path )
|
||||||
{
|
{
|
||||||
return FileSystem.toLocal( path, m_location );
|
return FileSystem.toLocal( path, m_location );
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileSystemException localExceptionOf( IOException e )
|
|
||||||
{
|
|
||||||
if( !m_location.isEmpty() && e instanceof FileOperationException )
|
|
||||||
{
|
|
||||||
FileOperationException ex = (FileOperationException) e;
|
|
||||||
if( ex.getFilename() != null ) return localExceptionOf( ex.getFilename(), ex.getMessage() );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new FileSystemException( e.getMessage() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private FileSystemException localExceptionOf( String path, String message )
|
|
||||||
{
|
|
||||||
if( !m_location.isEmpty() ) path = path.isEmpty() ? m_location : m_location + "/" + path;
|
|
||||||
return exceptionOf( path, message );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static FileSystemException exceptionOf( String path, String message )
|
|
||||||
{
|
|
||||||
return new FileSystemException( "/" + path + ": " + message );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final FileSystemWrapperMount m_wrapper = new FileSystemWrapperMount( this );
|
private final FileSystemWrapperMount m_wrapper = new FileSystemWrapperMount( this );
|
||||||
@@ -779,7 +769,7 @@ public class FileSystem
|
|||||||
|
|
||||||
// Clean the path or illegal characters.
|
// Clean the path or illegal characters.
|
||||||
final char[] specialChars = new char[] {
|
final char[] specialChars = new char[] {
|
||||||
'"', ':', '<', '>', '?', '|', // Sorted by ascii value (important)
|
'"', ':', '<', '>', '?', '|' // Sorted by ascii value (important)
|
||||||
};
|
};
|
||||||
|
|
||||||
StringBuilder cleanName = new StringBuilder();
|
StringBuilder cleanName = new StringBuilder();
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ package dan200.computercraft.core.filesystem;
|
|||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import dan200.computercraft.api.filesystem.FileOperationException;
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||||
import dan200.computercraft.shared.util.IoUtil;
|
import dan200.computercraft.shared.util.IoUtil;
|
||||||
@@ -93,7 +92,7 @@ public class JarMount implements IMount
|
|||||||
new MountReference( this );
|
new MountReference( this );
|
||||||
|
|
||||||
// Read in all the entries
|
// Read in all the entries
|
||||||
root = new FileEntry();
|
root = new FileEntry( "" );
|
||||||
Enumeration<? extends ZipEntry> zipEntries = zip.entries();
|
Enumeration<? extends ZipEntry> zipEntries = zip.entries();
|
||||||
while( zipEntries.hasMoreElements() )
|
while( zipEntries.hasMoreElements() )
|
||||||
{
|
{
|
||||||
@@ -140,7 +139,7 @@ public class JarMount implements IMount
|
|||||||
FileEntry nextEntry = lastEntry.children.get( part );
|
FileEntry nextEntry = lastEntry.children.get( part );
|
||||||
if( nextEntry == null || !nextEntry.isDirectory() )
|
if( nextEntry == null || !nextEntry.isDirectory() )
|
||||||
{
|
{
|
||||||
lastEntry.children.put( part, nextEntry = new FileEntry() );
|
lastEntry.children.put( part, nextEntry = new FileEntry( part ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
lastEntry = nextEntry;
|
lastEntry = nextEntry;
|
||||||
@@ -167,7 +166,7 @@ public class JarMount implements IMount
|
|||||||
public void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException
|
public void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException
|
||||||
{
|
{
|
||||||
FileEntry file = get( path );
|
FileEntry file = get( path );
|
||||||
if( file == null || !file.isDirectory() ) throw new FileOperationException( path, "Not a directory" );
|
if( file == null || !file.isDirectory() ) throw new IOException( "/" + path + ": Not a directory" );
|
||||||
|
|
||||||
file.list( contents );
|
file.list( contents );
|
||||||
}
|
}
|
||||||
@@ -177,7 +176,7 @@ public class JarMount implements IMount
|
|||||||
{
|
{
|
||||||
FileEntry file = get( path );
|
FileEntry file = get( path );
|
||||||
if( file != null ) return file.size;
|
if( file != null ) return file.size;
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -219,15 +218,22 @@ public class JarMount implements IMount
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new FileOperationException( path, "No such file" );
|
throw new IOException( "/" + path + ": No such file" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class FileEntry
|
private static class FileEntry
|
||||||
{
|
{
|
||||||
|
final String name;
|
||||||
|
|
||||||
String path;
|
String path;
|
||||||
long size;
|
long size;
|
||||||
Map<String, FileEntry> children;
|
Map<String, FileEntry> children;
|
||||||
|
|
||||||
|
FileEntry( String name )
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
void setup( ZipEntry entry )
|
void setup( ZipEntry entry )
|
||||||
{
|
{
|
||||||
path = entry.getName();
|
path = entry.getName();
|
||||||
|
|||||||
@@ -11,12 +11,9 @@ import com.google.common.cache.CacheBuilder;
|
|||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
|
||||||
import net.minecraft.resources.IReloadableResourceManager;
|
import net.minecraft.resource.*;
|
||||||
import net.minecraft.resources.IResource;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.resources.IResourceManager;
|
import net.minecraft.util.profiler.Profiler;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.resource.IResourceType;
|
|
||||||
import net.minecraftforge.resource.ISelectiveResourceReloadListener;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@@ -27,7 +24,6 @@ import java.nio.channels.Channels;
|
|||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
public class ResourceMount implements IMount
|
public class ResourceMount implements IMount
|
||||||
{
|
{
|
||||||
@@ -57,12 +53,12 @@ public class ResourceMount implements IMount
|
|||||||
|
|
||||||
private final String namespace;
|
private final String namespace;
|
||||||
private final String subPath;
|
private final String subPath;
|
||||||
private final IReloadableResourceManager manager;
|
private final ReloadableResourceManager manager;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private FileEntry root;
|
private FileEntry root;
|
||||||
|
|
||||||
public ResourceMount( String namespace, String subPath, IReloadableResourceManager manager )
|
public ResourceMount( String namespace, String subPath, ReloadableResourceManager manager )
|
||||||
{
|
{
|
||||||
this.namespace = namespace;
|
this.namespace = namespace;
|
||||||
this.subPath = subPath;
|
this.subPath = subPath;
|
||||||
@@ -75,8 +71,8 @@ public class ResourceMount implements IMount
|
|||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
boolean hasAny = false;
|
boolean hasAny = false;
|
||||||
FileEntry newRoot = new FileEntry( new ResourceLocation( namespace, subPath ) );
|
FileEntry newRoot = new FileEntry( new Identifier( namespace, subPath ) );
|
||||||
for( ResourceLocation file : manager.getAllResourceLocations( subPath, s -> true ) )
|
for( Identifier file : manager.findResources( subPath, s -> true ) )
|
||||||
{
|
{
|
||||||
if( !file.getNamespace().equals( namespace ) ) continue;
|
if( !file.getNamespace().equals( namespace ) ) continue;
|
||||||
|
|
||||||
@@ -119,7 +115,7 @@ public class ResourceMount implements IMount
|
|||||||
FileEntry nextEntry = lastEntry.children.get( part );
|
FileEntry nextEntry = lastEntry.children.get( part );
|
||||||
if( nextEntry == null )
|
if( nextEntry == null )
|
||||||
{
|
{
|
||||||
lastEntry.children.put( part, nextEntry = new FileEntry( new ResourceLocation( namespace, subPath + "/" + path ) ) );
|
lastEntry.children.put( part, nextEntry = new FileEntry( new Identifier( namespace, subPath + "/" + path ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
lastEntry = nextEntry;
|
lastEntry = nextEntry;
|
||||||
@@ -163,14 +159,14 @@ public class ResourceMount implements IMount
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IResource resource = manager.getResource( file.identifier );
|
Resource resource = manager.getResource( file.identifier );
|
||||||
InputStream s = resource.getInputStream();
|
InputStream s = resource.getInputStream();
|
||||||
int total = 0, read = 0;
|
int total = 0, read = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
total += read;
|
total += read;
|
||||||
read = s.read( TEMP_BUFFER );
|
read = s.read( TEMP_BUFFER );
|
||||||
} while ( read > 0 );
|
} while( read > 0 );
|
||||||
|
|
||||||
return file.size = total;
|
return file.size = total;
|
||||||
}
|
}
|
||||||
@@ -219,11 +215,11 @@ public class ResourceMount implements IMount
|
|||||||
|
|
||||||
private static class FileEntry
|
private static class FileEntry
|
||||||
{
|
{
|
||||||
final ResourceLocation identifier;
|
final Identifier identifier;
|
||||||
Map<String, FileEntry> children;
|
Map<String, FileEntry> children;
|
||||||
long size = -1;
|
long size = -1;
|
||||||
|
|
||||||
FileEntry( ResourceLocation identifier )
|
FileEntry( Identifier identifier )
|
||||||
{
|
{
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
}
|
}
|
||||||
@@ -240,34 +236,41 @@ public class ResourceMount implements IMount
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ISelectiveResourceReloadListener} which reloads any associated mounts.
|
* A {@link ResourceReloadListener} which reloads any associated mounts.
|
||||||
*
|
*
|
||||||
* While people should really be keeping a permanent reference to this, some people construct it every
|
* 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.
|
* method call, so let's make this as small as possible.
|
||||||
*/
|
*/
|
||||||
static class Listener implements ISelectiveResourceReloadListener
|
static class Listener extends SupplyingResourceReloadListener<Void>
|
||||||
{
|
{
|
||||||
private static final Listener INSTANCE = new Listener();
|
private static final Listener INSTANCE = new Listener();
|
||||||
|
|
||||||
private final Set<ResourceMount> mounts = Collections.newSetFromMap( new WeakHashMap<>() );
|
private final Set<ResourceMount> mounts = Collections.newSetFromMap( new WeakHashMap<>() );
|
||||||
private final Set<IReloadableResourceManager> managers = Collections.newSetFromMap( new WeakHashMap<>() );
|
private final Set<ReloadableResourceManager> managers = Collections.newSetFromMap( new WeakHashMap<>() );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResourceManagerReload( @Nonnull IResourceManager manager )
|
protected synchronized Void load( ResourceManager manager, Profiler profiler )
|
||||||
{
|
{
|
||||||
// FIXME: Remove this. We need this patch in order to prevent trying to load ReloadRequirements.
|
profiler.push( "Mount reloading" );
|
||||||
onResourceManagerReload( manager, x -> true );
|
try
|
||||||
|
{
|
||||||
|
for( ResourceMount mount : mounts ) mount.load();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
profiler.pop();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onResourceManagerReload( @Nonnull IResourceManager manager, @Nonnull Predicate<IResourceType> predicate )
|
protected void apply( Void res, ResourceManager manager, Profiler profiler )
|
||||||
{
|
{
|
||||||
for( ResourceMount mount : mounts ) mount.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized void add( IReloadableResourceManager manager, ResourceMount mount )
|
synchronized void add( ReloadableResourceManager manager, ResourceMount mount )
|
||||||
{
|
{
|
||||||
if( managers.add( manager ) ) manager.addReloadListener( this );
|
if( managers.add( manager ) ) manager.registerListener( this );
|
||||||
mounts.add( mount );
|
mounts.add( mount );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -550,7 +550,7 @@ public class CobaltLuaMachine implements ILuaMachine
|
|||||||
{
|
{
|
||||||
if( ComputerCraft.logPeripheralErrors ) ComputerCraft.log.error( "Error running task", t );
|
if( ComputerCraft.logPeripheralErrors ) ComputerCraft.log.error( "Error running task", t );
|
||||||
m_computer.queueEvent( "task_complete", new Object[] {
|
m_computer.queueEvent( "task_complete", new Object[] {
|
||||||
taskID, false, "Java Exception Thrown: " + t,
|
taskID, false, "Java Exception Thrown: " + t
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
package dan200.computercraft.core.terminal;
|
package dan200.computercraft.core.terminal;
|
||||||
|
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
|
||||||
public class Terminal
|
public class Terminal
|
||||||
{
|
{
|
||||||
@@ -334,7 +334,7 @@ public class Terminal
|
|||||||
m_changed = false;
|
m_changed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized NBTTagCompound writeToNBT( NBTTagCompound nbt )
|
public synchronized CompoundTag writeToNBT( CompoundTag nbt )
|
||||||
{
|
{
|
||||||
nbt.putInt( "term_cursorX", m_cursorX );
|
nbt.putInt( "term_cursorX", m_cursorX );
|
||||||
nbt.putInt( "term_cursorY", m_cursorY );
|
nbt.putInt( "term_cursorY", m_cursorY );
|
||||||
@@ -354,7 +354,7 @@ public class Terminal
|
|||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void readFromNBT( NBTTagCompound nbt )
|
public synchronized void readFromNBT( CompoundTag nbt )
|
||||||
{
|
{
|
||||||
m_cursorX = nbt.getInt( "term_cursorX" );
|
m_cursorX = nbt.getInt( "term_cursorX" );
|
||||||
m_cursorY = nbt.getInt( "term_cursorY" );
|
m_cursorY = nbt.getInt( "term_cursorY" );
|
||||||
@@ -365,17 +365,17 @@ public class Terminal
|
|||||||
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.containsKey( "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.containsKey( "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.containsKey( "term_textBgColour_" + n ) )
|
||||||
{
|
{
|
||||||
m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ package dan200.computercraft.core.terminal;
|
|||||||
|
|
||||||
public class TextBuffer
|
public class TextBuffer
|
||||||
{
|
{
|
||||||
private final char[] m_text;
|
public char[] m_text;
|
||||||
|
|
||||||
public TextBuffer( char c, int length )
|
public TextBuffer( char c, int length )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ package dan200.computercraft.shared;
|
|||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||||
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -24,18 +24,18 @@ public final class BundledRedstone
|
|||||||
|
|
||||||
private BundledRedstone() {}
|
private BundledRedstone() {}
|
||||||
|
|
||||||
public static synchronized void register( @Nonnull IBundledRedstoneProvider provider )
|
public static void register( @Nonnull IBundledRedstoneProvider provider )
|
||||||
{
|
{
|
||||||
Objects.requireNonNull( provider, "provider cannot be null" );
|
Objects.requireNonNull( provider, "provider cannot be null" );
|
||||||
providers.add( provider );
|
providers.add( provider );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
{
|
{
|
||||||
return World.isValid( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1;
|
return World.isValid( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getUnmaskedOutput( World world, BlockPos pos, EnumFacing side )
|
private static int getUnmaskedOutput( World world, BlockPos pos, Direction side )
|
||||||
{
|
{
|
||||||
if( !World.isValid( pos ) ) return -1;
|
if( !World.isValid( pos ) ) return -1;
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public final class BundledRedstone
|
|||||||
return combinedSignal;
|
return combinedSignal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getOutput( World world, BlockPos pos, EnumFacing side )
|
public static int getOutput( World world, BlockPos pos, Direction side )
|
||||||
{
|
{
|
||||||
int signal = getUnmaskedOutput( world, pos, side );
|
int signal = getUnmaskedOutput( world, pos, side );
|
||||||
return signal >= 0 ? signal : 0;
|
return signal >= 0 ? signal : 0;
|
||||||
|
|||||||
@@ -1,344 +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.shared;
|
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
|
||||||
import com.google.common.base.Converter;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
|
||||||
import dan200.computercraft.core.apis.AddressPredicate;
|
|
||||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.config.ModConfig;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import static dan200.computercraft.ComputerCraft.DEFAULT_HTTP_BLACKLIST;
|
|
||||||
import static dan200.computercraft.ComputerCraft.DEFAULT_HTTP_WHITELIST;
|
|
||||||
import static net.minecraftforge.common.ForgeConfigSpec.Builder;
|
|
||||||
import static net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD )
|
|
||||||
public final class Config
|
|
||||||
{
|
|
||||||
private static final int MODEM_MAX_RANGE = 100000;
|
|
||||||
|
|
||||||
private static final String TRANSLATION_PREFIX = "gui.computercraft.config.";
|
|
||||||
|
|
||||||
private static ConfigValue<Integer> computerSpaceLimit;
|
|
||||||
private static ConfigValue<Integer> floppySpaceLimit;
|
|
||||||
private static ConfigValue<Integer> maximumFilesOpen;
|
|
||||||
private static ConfigValue<Boolean> disableLua51Features;
|
|
||||||
private static ConfigValue<String> defaultComputerSettings;
|
|
||||||
private static ConfigValue<Boolean> debugEnabled;
|
|
||||||
private static ConfigValue<Boolean> logComputerErrors;
|
|
||||||
|
|
||||||
private static ConfigValue<Integer> computerThreads;
|
|
||||||
private static ConfigValue<Integer> maxMainGlobalTime;
|
|
||||||
private static ConfigValue<Integer> maxMainComputerTime;
|
|
||||||
|
|
||||||
private static ConfigValue<Boolean> httpEnabled;
|
|
||||||
private static ConfigValue<Boolean> httpWebsocketEnabled;
|
|
||||||
private static ConfigValue<List<? extends String>> httpWhitelist;
|
|
||||||
private static ConfigValue<List<? extends String>> httpBlacklist;
|
|
||||||
|
|
||||||
private static ConfigValue<Integer> httpTimeout;
|
|
||||||
private static ConfigValue<Integer> httpMaxRequests;
|
|
||||||
private static ConfigValue<Integer> httpMaxDownload;
|
|
||||||
private static ConfigValue<Integer> httpMaxUpload;
|
|
||||||
private static ConfigValue<Integer> httpMaxWebsockets;
|
|
||||||
private static ConfigValue<Integer> httpMaxWebsocketMessage;
|
|
||||||
|
|
||||||
private static ConfigValue<Boolean> commandBlockEnabled;
|
|
||||||
private static ConfigValue<Integer> modemRange;
|
|
||||||
private static ConfigValue<Integer> modemHighAltitudeRange;
|
|
||||||
private static ConfigValue<Integer> modemRangeDuringStorm;
|
|
||||||
private static ConfigValue<Integer> modemHighAltitudeRangeDuringStorm;
|
|
||||||
private static ConfigValue<Integer> maxNotesPerTick;
|
|
||||||
|
|
||||||
private static ConfigValue<Boolean> turtlesNeedFuel;
|
|
||||||
private static ConfigValue<Integer> turtleFuelLimit;
|
|
||||||
private static ConfigValue<Integer> advancedTurtleFuelLimit;
|
|
||||||
private static ConfigValue<Boolean> turtlesObeyBlockProtection;
|
|
||||||
private static ConfigValue<Boolean> turtlesCanPush;
|
|
||||||
private static ConfigValue<List<? extends String>> turtleDisabledActions;
|
|
||||||
|
|
||||||
private static final ForgeConfigSpec spec;
|
|
||||||
|
|
||||||
private Config() {}
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
Builder builder = new Builder();
|
|
||||||
|
|
||||||
{ // General computers
|
|
||||||
computerSpaceLimit = builder
|
|
||||||
.comment( "The disk space limit for computers and turtles, in bytes" )
|
|
||||||
.translation( TRANSLATION_PREFIX + "computer_space_limit" )
|
|
||||||
.define( "computer_space_limit", ComputerCraft.computerSpaceLimit );
|
|
||||||
|
|
||||||
floppySpaceLimit = builder
|
|
||||||
.comment( "The disk space limit for floppy disks, in bytes" )
|
|
||||||
.translation( TRANSLATION_PREFIX + "floppy_space_limit" )
|
|
||||||
.define( "floppy_space_limit", ComputerCraft.floppySpaceLimit );
|
|
||||||
|
|
||||||
maximumFilesOpen = builder
|
|
||||||
.comment( "Set how many files a computer can have open at the same time. Set to 0 for unlimited." )
|
|
||||||
.translation( TRANSLATION_PREFIX + "maximum_open_files" )
|
|
||||||
.defineInRange( "maximum_open_files", ComputerCraft.maximumFilesOpen, 0, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
disableLua51Features = builder
|
|
||||||
.comment( "Set this to true to disable Lua 5.1 functions that will be removed in a future update. " +
|
|
||||||
"Useful for ensuring forward compatibility of your programs now." )
|
|
||||||
.define( "disable_lua51_features", ComputerCraft.disable_lua51_features );
|
|
||||||
|
|
||||||
defaultComputerSettings = builder
|
|
||||||
.comment( "A comma separated list of default system settings to set on new computers. Example: " +
|
|
||||||
"\"shell.autocomplete=false,lua.autocomplete=false,edit.autocomplete=false\" will disable all " +
|
|
||||||
"autocompletion" )
|
|
||||||
.define( "default_computer_settings", ComputerCraft.default_computer_settings );
|
|
||||||
|
|
||||||
debugEnabled = builder
|
|
||||||
.comment( "Enable Lua's debug library. This is sandboxed to each computer, so is generally safe to be used by players." )
|
|
||||||
.define( "debug_enabled", ComputerCraft.debug_enable );
|
|
||||||
|
|
||||||
logComputerErrors = builder
|
|
||||||
.comment( "Log exceptions thrown by peripherals and other Lua objects.\n" +
|
|
||||||
"This makes it easier for mod authors to debug problems, but may result in log spam should people use buggy methods." )
|
|
||||||
.define( "log_computer_errors", ComputerCraft.logPeripheralErrors );
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
builder.comment( "Controls execution behaviour of computers. This is largely intended for fine-tuning " +
|
|
||||||
"servers, and generally shouldn't need to be touched" );
|
|
||||||
builder.push( "execution" );
|
|
||||||
|
|
||||||
computerThreads = builder
|
|
||||||
.comment( "Set the number of threads computers can run on. A higher number means more computers can run " +
|
|
||||||
"at once, but may induce lag.\n" +
|
|
||||||
"Please note that some mods may not work with a thread count higher than 1. Use with caution." )
|
|
||||||
.worldRestart()
|
|
||||||
.defineInRange( "computer_threads", ComputerCraft.computer_threads, 1, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
maxMainGlobalTime = builder
|
|
||||||
.comment( "The maximum time that can be spent executing tasks in a single tick, in milliseconds.\n" +
|
|
||||||
"Note, we will quite possibly go over this limit, as there's no way to tell how long a will take " +
|
|
||||||
"- this aims to be the upper bound of the average time." )
|
|
||||||
.defineInRange( "max_main_global_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainGlobalTime ), 1, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
maxMainComputerTime = builder
|
|
||||||
.comment( "The ideal maximum time a computer can execute for in a tick, in milliseconds.\n" +
|
|
||||||
"Note, we will quite possibly go over this limit, as there's no way to tell how long a will take " +
|
|
||||||
"- this aims to be the upper bound of the average time." )
|
|
||||||
.defineInRange( "max_main_computer_time", (int) TimeUnit.NANOSECONDS.toMillis( ComputerCraft.maxMainComputerTime ), 1, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
builder.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // HTTP
|
|
||||||
builder.comment( "Controls the HTTP API" );
|
|
||||||
builder.push( "http" );
|
|
||||||
|
|
||||||
httpEnabled = builder
|
|
||||||
.comment( "Enable the \"http\" API on Computers (see \"http_whitelist\" and \"http_blacklist\" for more " +
|
|
||||||
"fine grained control than this)" )
|
|
||||||
.define( "enabled", ComputerCraft.http_enable );
|
|
||||||
|
|
||||||
httpWebsocketEnabled = builder
|
|
||||||
.comment( "Enable use of http websockets. This requires the \"http_enable\" option to also be true." )
|
|
||||||
.define( "websocket_enabled", ComputerCraft.http_websocket_enable );
|
|
||||||
|
|
||||||
httpWhitelist = builder
|
|
||||||
.comment( "A list of wildcards for domains or IP ranges that can be accessed through the \"http\" API on Computers.\n" +
|
|
||||||
"Set this to \"*\" to access to the entire internet. Example: \"*.pastebin.com\" will restrict access to just subdomains of pastebin.com.\n" +
|
|
||||||
"You can use domain names (\"pastebin.com\"), wilcards (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\")." )
|
|
||||||
.defineList( "whitelist", Arrays.asList( DEFAULT_HTTP_WHITELIST ), x -> true );
|
|
||||||
|
|
||||||
httpBlacklist = builder
|
|
||||||
.comment( "A list of wildcards for domains or IP ranges that cannot be accessed through the \"http\" API on Computers.\n" +
|
|
||||||
"If this is empty then all whitelisted domains will be accessible. Example: \"*.github.com\" will block access to all subdomains of github.com.\n" +
|
|
||||||
"You can use domain names (\"pastebin.com\"), wilcards (\"*.pastebin.com\") or CIDR notation (\"127.0.0.0/8\")." )
|
|
||||||
.defineList( "blacklist", Arrays.asList( DEFAULT_HTTP_BLACKLIST ), x -> true );
|
|
||||||
|
|
||||||
httpTimeout = builder
|
|
||||||
.comment( "The period of time (in milliseconds) to wait before a HTTP request times out. Set to 0 for unlimited." )
|
|
||||||
.defineInRange( "timeout", ComputerCraft.httpTimeout, 0, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
httpMaxRequests = builder
|
|
||||||
.comment( "The number of http requests a computer can make at one time. Additional requests will be queued, and sent when the running requests have finished. Set to 0 for unlimited." )
|
|
||||||
.defineInRange( "max_requests", ComputerCraft.httpMaxRequests, 0, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
httpMaxDownload = builder
|
|
||||||
.comment( "The maximum size (in bytes) that a computer can download in a single request. Note that responses may receive more data than allowed, but this data will not be returned to the client." )
|
|
||||||
.defineInRange( "max_download", (int) ComputerCraft.httpMaxDownload, 0, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
httpMaxUpload = builder
|
|
||||||
.comment( "The maximum size (in bytes) that a computer can upload in a single request. This includes headers and POST text." )
|
|
||||||
.defineInRange( "max_upload", (int) ComputerCraft.httpMaxUpload, 0, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
httpMaxWebsockets = builder
|
|
||||||
.comment( "The number of websockets a computer can have open at one time. Set to 0 for unlimited." )
|
|
||||||
.defineInRange( "max_websockets", ComputerCraft.httpMaxWebsockets, 1, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
httpMaxWebsocketMessage = builder
|
|
||||||
.comment( "The maximum size (in bytes) that a computer can send or receive in one websocket packet." )
|
|
||||||
.defineInRange( "max_websocket_message", ComputerCraft.httpMaxWebsocketMessage, 0, Websocket.MAX_MESSAGE_SIZE );
|
|
||||||
|
|
||||||
builder.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // Peripherals
|
|
||||||
builder.comment( "Various options relating to peripherals." );
|
|
||||||
builder.push( "peripheral" );
|
|
||||||
|
|
||||||
commandBlockEnabled = builder
|
|
||||||
.comment( "Enable Command Block peripheral support" )
|
|
||||||
.define( "command_block_enabled", ComputerCraft.enableCommandBlock );
|
|
||||||
|
|
||||||
modemRange = builder
|
|
||||||
.comment( "The range of Wireless Modems at low altitude in clear weather, in meters" )
|
|
||||||
.defineInRange( "modem_range", ComputerCraft.modem_range, 0, MODEM_MAX_RANGE );
|
|
||||||
|
|
||||||
modemHighAltitudeRange = builder
|
|
||||||
.comment( "The range of Wireless Modems at maximum altitude in clear weather, in meters" )
|
|
||||||
.defineInRange( "modem_high_altitude_range", ComputerCraft.modem_highAltitudeRange, 0, MODEM_MAX_RANGE );
|
|
||||||
|
|
||||||
modemRangeDuringStorm = builder
|
|
||||||
.comment( "The range of Wireless Modems at low altitude in stormy weather, in meters" )
|
|
||||||
.defineInRange( "modem_range_during_storm", ComputerCraft.modem_rangeDuringStorm, 0, MODEM_MAX_RANGE );
|
|
||||||
|
|
||||||
modemHighAltitudeRangeDuringStorm = builder
|
|
||||||
.comment( "The range of Wireless Modems at maximum altitude in stormy weather, in meters" )
|
|
||||||
.defineInRange( "modem_high_altitude_range_during_storm", ComputerCraft.modem_highAltitudeRangeDuringStorm, 0, MODEM_MAX_RANGE );
|
|
||||||
|
|
||||||
maxNotesPerTick = builder
|
|
||||||
.comment( "Maximum amount of notes a speaker can play at once" )
|
|
||||||
.defineInRange( "max_notes_per_tick", ComputerCraft.maxNotesPerTick, 1, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
builder.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // Turtles
|
|
||||||
builder.comment( "Various options relating to turtles." );
|
|
||||||
builder.push( "turtle" );
|
|
||||||
|
|
||||||
turtlesNeedFuel = builder
|
|
||||||
.comment( "Set whether Turtles require fuel to move" )
|
|
||||||
.define( "need_fuel", ComputerCraft.turtlesNeedFuel );
|
|
||||||
|
|
||||||
turtleFuelLimit = builder
|
|
||||||
.comment( "The fuel limit for Turtles" )
|
|
||||||
.defineInRange( "normal_fuel_limit", ComputerCraft.turtleFuelLimit, 0, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
advancedTurtleFuelLimit = builder
|
|
||||||
.comment( "The fuel limit for Advanced Turtles" )
|
|
||||||
.defineInRange( "advanced_fuel_limit", ComputerCraft.advancedTurtleFuelLimit, 0, Integer.MAX_VALUE );
|
|
||||||
|
|
||||||
turtlesObeyBlockProtection = builder
|
|
||||||
.comment( "If set to true, Turtles will be unable to build, dig, or enter protected areas (such as near the server spawn point)" )
|
|
||||||
.define( "obey_block_protection", ComputerCraft.turtlesObeyBlockProtection );
|
|
||||||
|
|
||||||
turtlesCanPush = builder
|
|
||||||
.comment( "If set to true, Turtles will push entities out of the way instead of stopping if there is space to do so" )
|
|
||||||
.define( "can_push", ComputerCraft.turtlesCanPush );
|
|
||||||
|
|
||||||
turtleDisabledActions = builder
|
|
||||||
.comment( "A list of turtle actions which are disabled." )
|
|
||||||
.defineList( "disabled_actions", Collections.emptyList(), x -> x instanceof String && getAction( (String) x ) != null );
|
|
||||||
|
|
||||||
builder.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
spec = builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void load()
|
|
||||||
{
|
|
||||||
ModLoadingContext.get().registerConfig( ModConfig.Type.COMMON, spec );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sync()
|
|
||||||
{
|
|
||||||
// General
|
|
||||||
ComputerCraft.computerSpaceLimit = computerSpaceLimit.get();
|
|
||||||
ComputerCraft.floppySpaceLimit = floppySpaceLimit.get();
|
|
||||||
ComputerCraft.maximumFilesOpen = maximumFilesOpen.get();
|
|
||||||
ComputerCraft.disable_lua51_features = disableLua51Features.get();
|
|
||||||
ComputerCraft.default_computer_settings = defaultComputerSettings.get();
|
|
||||||
ComputerCraft.debug_enable = debugEnabled.get();
|
|
||||||
ComputerCraft.computer_threads = computerThreads.get();
|
|
||||||
ComputerCraft.logPeripheralErrors = logComputerErrors.get();
|
|
||||||
|
|
||||||
// Execution
|
|
||||||
ComputerCraft.computer_threads = computerThreads.get();
|
|
||||||
ComputerCraft.maxMainGlobalTime = TimeUnit.MILLISECONDS.toNanos( maxMainGlobalTime.get() );
|
|
||||||
ComputerCraft.maxMainComputerTime = TimeUnit.MILLISECONDS.toNanos( maxMainComputerTime.get() );
|
|
||||||
|
|
||||||
// HTTP
|
|
||||||
ComputerCraft.http_enable = httpEnabled.get();
|
|
||||||
ComputerCraft.http_websocket_enable = httpWebsocketEnabled.get();
|
|
||||||
ComputerCraft.http_whitelist = new AddressPredicate( httpWhitelist.get() );
|
|
||||||
ComputerCraft.http_blacklist = new AddressPredicate( httpBlacklist.get() );
|
|
||||||
|
|
||||||
ComputerCraft.httpTimeout = httpTimeout.get();
|
|
||||||
ComputerCraft.httpMaxRequests = httpMaxRequests.get();
|
|
||||||
ComputerCraft.httpMaxDownload = httpMaxDownload.get();
|
|
||||||
ComputerCraft.httpMaxUpload = httpMaxUpload.get();
|
|
||||||
ComputerCraft.httpMaxWebsockets = httpMaxWebsockets.get();
|
|
||||||
ComputerCraft.httpMaxWebsocketMessage = httpMaxWebsocketMessage.get();
|
|
||||||
|
|
||||||
// Peripheral
|
|
||||||
ComputerCraft.enableCommandBlock = commandBlockEnabled.get();
|
|
||||||
ComputerCraft.maxNotesPerTick = maxNotesPerTick.get();
|
|
||||||
ComputerCraft.modem_range = modemRange.get();
|
|
||||||
ComputerCraft.modem_highAltitudeRange = modemHighAltitudeRange.get();
|
|
||||||
ComputerCraft.modem_rangeDuringStorm = modemRangeDuringStorm.get();
|
|
||||||
ComputerCraft.modem_highAltitudeRangeDuringStorm = modemHighAltitudeRangeDuringStorm.get();
|
|
||||||
|
|
||||||
// Turtles
|
|
||||||
ComputerCraft.turtlesNeedFuel = turtlesNeedFuel.get();
|
|
||||||
ComputerCraft.turtleFuelLimit = turtleFuelLimit.get();
|
|
||||||
ComputerCraft.advancedTurtleFuelLimit = advancedTurtleFuelLimit.get();
|
|
||||||
ComputerCraft.turtlesObeyBlockProtection = turtlesObeyBlockProtection.get();
|
|
||||||
ComputerCraft.turtlesCanPush = turtlesCanPush.get();
|
|
||||||
|
|
||||||
ComputerCraft.turtleDisabledActions.clear();
|
|
||||||
for( String value : turtleDisabledActions.get() ) ComputerCraft.turtleDisabledActions.add( getAction( value ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void sync( ModConfig.Loading event )
|
|
||||||
{
|
|
||||||
sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void sync( ModConfig.ConfigReloading event )
|
|
||||||
{
|
|
||||||
sync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE );
|
|
||||||
|
|
||||||
private static TurtleAction getAction( String value )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return TurtleAction.valueOf( converter.convert( value ) );
|
|
||||||
}
|
|
||||||
catch( IllegalArgumentException e )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user