mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-07 08:52:59 +00:00
Compare commits
19 Commits
v1.12.2-1.
...
v1.14-1.82
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f15a278f3b | ||
|
|
26b73c2ff3 | ||
|
|
4a25e7a178 | ||
|
|
55d54fec63 | ||
|
|
220e4bd660 | ||
|
|
c1e08fc3c7 | ||
|
|
b9ec6f236d | ||
|
|
b1fff97bff | ||
|
|
c81bc70475 | ||
|
|
362dbd97ac | ||
|
|
aa0e1883d1 | ||
|
|
9cdbcb4332 | ||
|
|
23ddd4feb5 | ||
|
|
fcaa777c95 | ||
|
|
55a7ee4acf | ||
|
|
7afc3e5260 | ||
|
|
f9e13ca67a | ||
|
|
810258e9b8 | ||
|
|
5e462adc5c |
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`.
|
|
||||||
18
.github/workflows/main-ci.yml
vendored
18
.github/workflows/main-ci.yml
vendored
@@ -1,18 +0,0 @@
|
|||||||
name: Build
|
|
||||||
|
|
||||||
on: [push, pull_request]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
|
|
||||||
- name: Set up JDK 1.8
|
|
||||||
uses: actions/setup-java@v1
|
|
||||||
with:
|
|
||||||
java-version: 1.8
|
|
||||||
|
|
||||||
- name: Build with Gradle
|
|
||||||
run: ./gradlew build --no-daemon
|
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -15,9 +15,3 @@
|
|||||||
.idea
|
.idea
|
||||||
.gradle
|
.gradle
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
|
||||||
.classpath
|
|
||||||
.project
|
|
||||||
.settings/
|
|
||||||
bin/
|
|
||||||
*.launch
|
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ ignore = {
|
|||||||
-- are largely unsupported.
|
-- are largely unsupported.
|
||||||
include_files = {
|
include_files = {
|
||||||
'src/main/resources/assets/computercraft/lua/rom',
|
'src/main/resources/assets/computercraft/lua/rom',
|
||||||
'src/main/resources/assets/computercraft/lua/bios.lua',
|
'src/main/resources/assets/computercraft/lua/bios.lua'
|
||||||
'src/test/resources/test-rom',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
files['src/main/resources/assets/computercraft/lua/bios.lua'] = {
|
files['src/main/resources/assets/computercraft/lua/bios.lua'] = {
|
||||||
|
|||||||
14
.travis.yml
Normal file
14
.travis.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
language: java
|
||||||
|
|
||||||
|
script: ./gradlew build --no-daemon
|
||||||
|
|
||||||
|
before_cache:
|
||||||
|
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
||||||
|
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.gradle/caches/
|
||||||
|
- $HOME/.gradle/wrapper/s
|
||||||
|
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
15
README.md
15
README.md
@@ -1,5 +1,5 @@
|
|||||||
# 
|
# 
|
||||||
[](https://github.com/SquidDev-CC/CC-Tweaked/actions "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.
|
||||||
|
|
||||||
|
|||||||
236
build.gradle
236
build.gradle
@@ -1,29 +1,17 @@
|
|||||||
|
|
||||||
// For those who want the bleeding edge
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
maven {
|
|
||||||
name = "forge"
|
|
||||||
url = "https://files.minecraftforge.net/maven"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.google.code.gson:gson:2.8.1'
|
classpath 'com.google.code.gson:gson:2.8.1'
|
||||||
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
|
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta2'
|
||||||
classpath 'net.sf.proguard:proguard-gradle:6.1.0beta1'
|
|
||||||
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
classpath 'org.ajoberstar.grgit:grgit-gradle:3.0.0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id "checkstyle"
|
id '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.forge'
|
|
||||||
apply plugin: 'org.ajoberstar.grgit'
|
apply plugin: 'org.ajoberstar.grgit'
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
@@ -34,18 +22,13 @@ group = "org.squiddev"
|
|||||||
archivesBaseName = "cc-tweaked-${mc_version}"
|
archivesBaseName = "cc-tweaked-${mc_version}"
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = "${mc_version}-${forge_version}"
|
|
||||||
runDir = "run"
|
|
||||||
replace '${version}', mod_version
|
|
||||||
|
|
||||||
mappings = mappings_version
|
|
||||||
makeObfSourceJar = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
maven {
|
maven {
|
||||||
name "JEI"
|
name "JEI"
|
||||||
url "https://dvs1.progwml6.com/files/maven"
|
url "http://dvs1.progwml6.com/files/maven"
|
||||||
}
|
}
|
||||||
maven {
|
maven {
|
||||||
name "SquidDev"
|
name "SquidDev"
|
||||||
@@ -57,7 +40,7 @@ repositories {
|
|||||||
}
|
}
|
||||||
maven {
|
maven {
|
||||||
name "Amadornes"
|
name "Amadornes"
|
||||||
url "https://maven.amadornes.com/"
|
url "http://maven.amadornes.com/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,23 +51,43 @@ configurations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
checkstyle "com.puppycrawl.tools:checkstyle:8.25"
|
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"
|
||||||
|
|
||||||
deobfProvided "mezz.jei:jei_1.12.2:4.15.0.269:api"
|
/*
|
||||||
deobfProvided "pl.asie:Charset-Lib:0.5.4.6"
|
modCompile "net.fabricmc:fabric-lib:0.1.0"
|
||||||
deobfProvided "MCMultiPart2:MCMultiPart:2.5.3"
|
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"
|
||||||
|
*/
|
||||||
|
|
||||||
runtime "mezz.jei:jei_1.12.2:4.15.0.269"
|
implementation 'com.google.code.findbugs:jsr305:3.0.2'
|
||||||
|
|
||||||
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.4.2'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
|
||||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.4.2'
|
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
|
||||||
|
|
||||||
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
|
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile tasks
|
sourceSets {
|
||||||
|
main {
|
||||||
|
java {
|
||||||
|
exclude 'dan200/computercraft/shared/integration'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
javadoc {
|
javadoc {
|
||||||
include "dan200/computercraft/api/**/*.java"
|
include "dan200/computercraft/api/**/*.java"
|
||||||
@@ -94,7 +97,13 @@ jar {
|
|||||||
dependsOn javadoc
|
dependsOn javadoc
|
||||||
|
|
||||||
manifest {
|
manifest {
|
||||||
attributes('FMLAT': 'computercraft_at.cfg')
|
attributes(["Specification-Title": "computercraft",
|
||||||
|
"Specification-Vendor": "SquidDev",
|
||||||
|
"Specification-Version": "25.0",
|
||||||
|
"Implementation-Title": "CC: Tweaked",
|
||||||
|
"Implementation-Version": "${mod_version}",
|
||||||
|
"Implementation-Vendor" :"SquidDev",
|
||||||
|
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")])
|
||||||
}
|
}
|
||||||
|
|
||||||
from (sourceSets.main.allSource) {
|
from (sourceSets.main.allSource) {
|
||||||
@@ -104,22 +113,12 @@ jar {
|
|||||||
from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
|
from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
[compileJava, compileTestJava].forEach {
|
|
||||||
it.configure {
|
|
||||||
options.compilerArgs << "-Xlint" << "-Xlint:-processing" << "-Werror"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.nio.file.*
|
import java.nio.file.*
|
||||||
import java.util.zip.*
|
import java.util.zip.*
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@@ -149,6 +148,10 @@ task proguard(type: ProGuardTask, dependsOn: jar) {
|
|||||||
|
|
||||||
// Preserve the constructors in Cobalt library class, as we init them via reflection
|
// Preserve the constructors in Cobalt library class, as we init them via reflection
|
||||||
keepclassmembers 'class org.squiddev.cobalt.lib.** { <init>(...); }'
|
keepclassmembers 'class org.squiddev.cobalt.lib.** { <init>(...); }'
|
||||||
|
|
||||||
|
// LWJGL and Apache bundle Java 9 versions, which is great, but rather breaks Proguard
|
||||||
|
dontwarn 'module-info'
|
||||||
|
dontwarn 'org.apache.**,org.lwjgl.**'
|
||||||
}
|
}
|
||||||
|
|
||||||
task proguardMove(dependsOn: proguard) {
|
task proguardMove(dependsOn: proguard) {
|
||||||
@@ -164,7 +167,7 @@ task proguardMove(dependsOn: proguard) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reobfJar.dependsOn proguardMove
|
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", mod_version
|
inputs.property "version", mod_version
|
||||||
@@ -186,8 +189,8 @@ processResources {
|
|||||||
inputs.property "commithash", hash
|
inputs.property "commithash", hash
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
include 'mcmod.info'
|
include 'fabric.mods.json'
|
||||||
include 'assets/computercraft/lua/rom/help/credits.txt'
|
include 'data/computercraft/lua/rom/help/credits.txt'
|
||||||
|
|
||||||
expand 'version': mod_version,
|
expand 'version': mod_version,
|
||||||
'mcversion': mc_version,
|
'mcversion': mc_version,
|
||||||
@@ -195,12 +198,12 @@ processResources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
from(sourceSets.main.resources.srcDirs) {
|
from(sourceSets.main.resources.srcDirs) {
|
||||||
exclude 'mcmod.info'
|
exclude 'fabric.mods.json'
|
||||||
exclude 'assets/computercraft/lua/rom/help/credits.txt'
|
exclude 'data/computercraft/lua/rom/help/credits.txt'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task compressJson(dependsOn: extractAnnotationsJar) {
|
task compressJson(dependsOn: jar) {
|
||||||
group "compact"
|
group "compact"
|
||||||
description "Minifies all JSON files, stripping whitespace"
|
description "Minifies all JSON files, stripping whitespace"
|
||||||
|
|
||||||
@@ -215,7 +218,6 @@ task compressJson(dependsOn: extractAnnotationsJar) {
|
|||||||
// 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) {
|
||||||
@@ -243,106 +245,13 @@ task compressJson(dependsOn: extractAnnotationsJar) {
|
|||||||
|
|
||||||
assemble.dependsOn compressJson
|
assemble.dependsOn compressJson
|
||||||
|
|
||||||
// Check tasks
|
|
||||||
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
testLogging {
|
|
||||||
events "skipped", "failed"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gradle.projectsEvaluated {
|
|
||||||
tasks.withType(LicenseFormat) {
|
|
||||||
outputs.upToDateWhen { false }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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/assets/computercraft/lua/rom/help/changelog.txt")
|
|
||||||
inputs.file("src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt")
|
|
||||||
|
|
||||||
doLast {
|
|
||||||
def ok = true
|
|
||||||
|
|
||||||
// Check we're targetting the current version
|
|
||||||
def whatsnew = new File("src/main/resources/assets/computercraft/lua/rom/help/whatsnew.txt").readLines()
|
|
||||||
if (whatsnew[0] != "New features in CC: Tweaked $mod_version") {
|
|
||||||
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/assets/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")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
check.dependsOn checkRelease
|
|
||||||
|
|
||||||
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"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +259,7 @@ publishing {
|
|||||||
publications {
|
publications {
|
||||||
mavenJava(MavenPublication) {
|
mavenJava(MavenPublication) {
|
||||||
from components.java
|
from components.java
|
||||||
artifact sourceJar
|
// artifact sourceJar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,28 +312,33 @@ 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'
|
||||||
try {
|
targetCommitish "mc-1.14-fabric" // TODO: Pull from GrGit
|
||||||
targetCommitish = Grgit.open(dir: '.').branch.current().name
|
|
||||||
} catch(Exception ignored) { }
|
|
||||||
|
|
||||||
tagName "v${mc_version}-${mod_version}"
|
tagName "v${mc_version}-${mod_version}"
|
||||||
releaseName "[${mc_version}] ${mod_version}"
|
releaseName "[${mc_version}] ${mod_version}"
|
||||||
body {
|
body ''
|
||||||
"## " + new File("src/main/resources/assets/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)"
|
||||||
}
|
}
|
||||||
|
|
||||||
runClient.outputs.upToDateWhen { false }
|
test {
|
||||||
runServer.outputs.upToDateWhen { false }
|
useJUnitPlatform()
|
||||||
|
testLogging {
|
||||||
|
events "passed", "skipped", "failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gradle.projectsEvaluated {
|
||||||
|
remapJar.dependsOn proguardMove
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile) {
|
||||||
|
options.compilerArgs << "-Xlint" << "-Xlint:-processing" // Causes Forge build to fail << "-Werror"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,169 +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" />
|
|
||||||
<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" />
|
|
||||||
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration" />
|
|
||||||
<module name="UnnecessarySemicolonInTryWithResources" />
|
|
||||||
<module name="UnnecessarySemicolonInEnumeration" />
|
|
||||||
|
|
||||||
<!-- Imports -->
|
|
||||||
<module name="CustomImportOrder" />
|
|
||||||
<module name="IllegalImport" />
|
|
||||||
<module name="RedundantImport" />
|
|
||||||
<module name="UnusedImports" />
|
|
||||||
|
|
||||||
<!-- Javadoc -->
|
|
||||||
<!-- TODO: Missing* checks for the dan200.computercraft.api package? -->
|
|
||||||
<module name="AtclauseOrder" />
|
|
||||||
<module name="InvalidJavadocPosition" />
|
|
||||||
<module name="JavadocBlockTagLocation" />
|
|
||||||
<module name="JavadocMethod"/>
|
|
||||||
<module name="JavadocType"/>
|
|
||||||
<module name="JavadocStyle" />
|
|
||||||
<module name="NonEmptyAtclauseDescription" />
|
|
||||||
<module name="SingleLineJavadoc" />
|
|
||||||
<module name="SummaryJavadocCheck"/>
|
|
||||||
|
|
||||||
<!-- 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 name="RegexpSingleline">
|
|
||||||
<property name="format" value="\s+$"/>
|
|
||||||
<property name="message" value="Trailing whitespace"/>
|
|
||||||
</module>
|
|
||||||
</module>
|
|
||||||
@@ -1,12 +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>
|
|
||||||
<!-- All the config options and method fields. -->
|
|
||||||
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraft.java" />
|
|
||||||
<suppress checks="StaticVariableName" files=".*[\\/]ComputerCraftAPI.java" />
|
|
||||||
|
|
||||||
<!-- Do not check for missing package Javadoc. -->
|
|
||||||
<suppress checks="JavadocStyle" files=".*[\\/]package-info.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.85.2
|
mod_version=1.82.3
|
||||||
|
|
||||||
# Minecraft properties
|
# Minecraft properties
|
||||||
mc_version=1.12.2
|
mc_version=1.14
|
||||||
forge_version=14.23.4.2749
|
mappings_version=1
|
||||||
mappings_version=snapshot_20180724
|
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
|
|
||||||
|
|||||||
@@ -1 +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"
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dan200.computercraft;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.network.NetworkCheckHandler;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A stub mod for CC: Tweaked. This doesn't have any functionality (everything of note is done in
|
|
||||||
* {@link ComputerCraft}), but people may depend on this if they require CC: Tweaked functionality.
|
|
||||||
*/
|
|
||||||
@Mod(
|
|
||||||
modid = "cctweaked", name = ComputerCraft.NAME, version = ComputerCraft.VERSION,
|
|
||||||
acceptableRemoteVersions = "*"
|
|
||||||
)
|
|
||||||
public class CCTweaked
|
|
||||||
{
|
|
||||||
@NetworkCheckHandler
|
|
||||||
public boolean onNetworkConnect( Map<String, String> mods, Side side )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,95 +7,50 @@
|
|||||||
package dan200.computercraft;
|
package dan200.computercraft;
|
||||||
|
|
||||||
import dan200.computercraft.api.filesystem.IMount;
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
import dan200.computercraft.api.filesystem.IWritableMount;
|
|
||||||
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
|
||||||
import dan200.computercraft.api.media.IMedia;
|
|
||||||
import dan200.computercraft.api.media.IMediaProvider;
|
|
||||||
import dan200.computercraft.api.network.IPacketNetwork;
|
|
||||||
import dan200.computercraft.api.network.wired.IWiredElement;
|
|
||||||
import dan200.computercraft.api.network.wired.IWiredNode;
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
|
||||||
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
|
|
||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
|
||||||
import dan200.computercraft.api.turtle.event.TurtleAction;
|
import dan200.computercraft.api.turtle.event.TurtleAction;
|
||||||
|
import dan200.computercraft.client.proxy.ComputerCraftProxyClient;
|
||||||
import dan200.computercraft.core.apis.AddressPredicate;
|
import dan200.computercraft.core.apis.AddressPredicate;
|
||||||
import dan200.computercraft.core.apis.ApiFactories;
|
|
||||||
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
import dan200.computercraft.core.apis.http.websocket.Websocket;
|
||||||
import dan200.computercraft.core.computer.MainThread;
|
import dan200.computercraft.core.filesystem.ResourceMount;
|
||||||
import dan200.computercraft.core.filesystem.ComboMount;
|
|
||||||
import dan200.computercraft.core.filesystem.FileMount;
|
|
||||||
import dan200.computercraft.core.filesystem.JarMount;
|
|
||||||
import dan200.computercraft.core.tracking.Tracking;
|
|
||||||
import dan200.computercraft.shared.*;
|
|
||||||
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
|
|
||||||
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
import dan200.computercraft.shared.computer.blocks.BlockComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
|
||||||
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
|
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
|
||||||
import dan200.computercraft.shared.computer.items.ItemCommandComputer;
|
|
||||||
import dan200.computercraft.shared.computer.items.ItemComputer;
|
import dan200.computercraft.shared.computer.items.ItemComputer;
|
||||||
import dan200.computercraft.shared.media.items.ItemDiskExpanded;
|
import dan200.computercraft.shared.media.items.ItemDisk;
|
||||||
import dan200.computercraft.shared.media.items.ItemDiskLegacy;
|
|
||||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||||
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
import dan200.computercraft.shared.media.items.ItemTreasureDisk;
|
||||||
import dan200.computercraft.shared.peripheral.common.BlockPeripheral;
|
import dan200.computercraft.shared.peripheral.diskdrive.BlockDiskDrive;
|
||||||
import dan200.computercraft.shared.peripheral.common.ItemPeripheral;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockWiredModemFull;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.ItemCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.ItemBlockCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wireless.BlockAdvancedModem;
|
import dan200.computercraft.shared.peripheral.modem.wireless.BlockWirelessModem;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wireless.ItemAdvancedModem;
|
import dan200.computercraft.shared.peripheral.monitor.BlockMonitor;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
import dan200.computercraft.shared.peripheral.printer.BlockPrinter;
|
||||||
|
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.proxy.ComputerCraftProxyCommon;
|
||||||
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
import dan200.computercraft.shared.turtle.blocks.BlockTurtle;
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtleAdvanced;
|
import dan200.computercraft.shared.turtle.items.ItemTurtle;
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtleLegacy;
|
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtleNormal;
|
|
||||||
import dan200.computercraft.shared.turtle.upgrades.*;
|
import dan200.computercraft.shared.turtle.upgrades.*;
|
||||||
import dan200.computercraft.shared.util.CreativeTabMain;
|
import net.fabricmc.api.EnvType;
|
||||||
import dan200.computercraft.shared.util.IDAssigner;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import dan200.computercraft.shared.util.IoUtil;
|
import net.minecraft.resource.ReloadableResourceManager;
|
||||||
import dan200.computercraft.shared.wired.CapabilityWiredElement;
|
import net.minecraft.util.Identifier;
|
||||||
import dan200.computercraft.shared.wired.WiredNode;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.item.ItemBlock;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.IBlockAccess;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.DimensionManager;
|
|
||||||
import net.minecraftforge.fml.common.*;
|
|
||||||
import net.minecraftforge.fml.common.event.*;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.io.InputStream;
|
||||||
import java.net.URISyntaxException;
|
import java.util.EnumSet;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
|
|
||||||
@Mod(
|
public final class ComputerCraft implements ModInitializer
|
||||||
modid = ComputerCraft.MOD_ID, name = ComputerCraft.NAME, version = ComputerCraft.VERSION,
|
|
||||||
guiFactory = "dan200.computercraft.client.gui.GuiConfigCC$Factory",
|
|
||||||
dependencies = "required:forge@[14.23.4.2746,)"
|
|
||||||
)
|
|
||||||
public class ComputerCraft
|
|
||||||
{
|
{
|
||||||
public static final String MOD_ID = "computercraft";
|
public static final String MOD_ID = "computercraft";
|
||||||
static final String VERSION = "${version}";
|
|
||||||
static final String NAME = "CC: Tweaked";
|
public static final int DATAFIXER_VERSION = 0;
|
||||||
|
|
||||||
// Configuration options
|
// Configuration options
|
||||||
public static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" };
|
public static final String[] DEFAULT_HTTP_WHITELIST = new String[] { "*" };
|
||||||
@@ -157,46 +112,54 @@ public class ComputerCraft
|
|||||||
// Blocks and Items
|
// Blocks and Items
|
||||||
public static final class Blocks
|
public static final class Blocks
|
||||||
{
|
{
|
||||||
public static BlockComputer computer;
|
public static BlockComputer computerNormal;
|
||||||
public static BlockCommandComputer commandComputer;
|
public static BlockComputer computerAdvanced;
|
||||||
|
public static BlockComputer computerCommand;
|
||||||
|
|
||||||
public static BlockTurtle turtle;
|
public static BlockTurtle turtleNormal;
|
||||||
public static BlockTurtle turtleExpanded;
|
|
||||||
public static BlockTurtle turtleAdvanced;
|
public static BlockTurtle turtleAdvanced;
|
||||||
|
|
||||||
public static BlockPeripheral peripheral;
|
public static BlockSpeaker speaker;
|
||||||
public static BlockCable cable;
|
public static BlockDiskDrive diskDrive;
|
||||||
public static BlockAdvancedModem advancedModem;
|
public static BlockPrinter printer;
|
||||||
|
|
||||||
|
public static BlockMonitor monitorNormal;
|
||||||
|
public static BlockMonitor monitorAdvanced;
|
||||||
|
|
||||||
|
public static BlockWirelessModem wirelessModemNormal;
|
||||||
|
public static BlockWirelessModem wirelessModemAdvanced;
|
||||||
|
|
||||||
public static BlockWiredModemFull wiredModemFull;
|
public static BlockWiredModemFull wiredModemFull;
|
||||||
|
public static BlockCable cable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class Items
|
public static final class Items
|
||||||
{
|
{
|
||||||
public static ItemComputer computer;
|
public static ItemComputer computerNormal;
|
||||||
public static ItemCommandComputer commandComputer;
|
public static ItemComputer computerAdvanced;
|
||||||
|
public static ItemComputer computerCommand;
|
||||||
|
|
||||||
public static ItemTurtleLegacy turtle;
|
public static ItemPocketComputer pocketComputerNormal;
|
||||||
public static ItemTurtleNormal turtleExpanded;
|
public static ItemPocketComputer pocketComputerAdvanced;
|
||||||
public static ItemTurtleAdvanced turtleAdvanced;
|
|
||||||
|
|
||||||
public static ItemPocketComputer pocketComputer;
|
public static ItemTurtle turtleNormal;
|
||||||
|
public static ItemTurtle turtleAdvanced;
|
||||||
|
|
||||||
public static ItemDiskLegacy disk;
|
public static ItemDisk disk;
|
||||||
public static ItemDiskExpanded diskExpanded;
|
|
||||||
public static ItemTreasureDisk treasureDisk;
|
public static ItemTreasureDisk treasureDisk;
|
||||||
|
|
||||||
public static ItemPrintout printout;
|
public static ItemPrintout printedPage;
|
||||||
|
public static ItemPrintout printedPages;
|
||||||
|
public static ItemPrintout printedBook;
|
||||||
|
|
||||||
public static ItemPeripheral peripheral;
|
public static ItemBlockCable.Cable cable;
|
||||||
public static ItemAdvancedModem advancedModem;
|
public static ItemBlockCable.WiredModem wiredModem;
|
||||||
public static ItemCable cable;
|
|
||||||
public static ItemBlock wiredModemFull;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class TurtleUpgrades
|
public static final class TurtleUpgrades
|
||||||
{
|
{
|
||||||
public static TurtleModem wirelessModem;
|
public static TurtleModem wirelessModemNormal;
|
||||||
public static TurtleModem advancedModem;
|
public static TurtleModem wirelessModemAdvanced;
|
||||||
public static TurtleSpeaker speaker;
|
public static TurtleSpeaker speaker;
|
||||||
|
|
||||||
public static TurtleCraftingTable craftingTable;
|
public static TurtleCraftingTable craftingTable;
|
||||||
@@ -209,457 +172,58 @@ public class ComputerCraft
|
|||||||
|
|
||||||
public static final class PocketUpgrades
|
public static final class PocketUpgrades
|
||||||
{
|
{
|
||||||
public static PocketModem wirelessModem;
|
public static PocketModem wirelessModemNormal;
|
||||||
public static PocketModem advancedModem;
|
public static PocketModem wirelessModemAdvanced;
|
||||||
public static PocketSpeaker speaker;
|
public static PocketSpeaker speaker;
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static PocketSpeaker pocketSpeaker;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static final class Upgrades
|
|
||||||
{
|
|
||||||
public static TurtleModem advancedModem;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registries
|
// Registries
|
||||||
public static final ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
|
public static final ClientComputerRegistry clientComputerRegistry = new ClientComputerRegistry();
|
||||||
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
|
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
|
||||||
|
|
||||||
// Creative
|
|
||||||
public static CreativeTabMain mainCreativeTab;
|
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
public static Logger log;
|
public static final Logger log = LogManager.getLogger( MOD_ID );
|
||||||
|
|
||||||
// Peripheral providers. This is still here to ensure compatibility with Plethora and Computronics
|
|
||||||
public static List<IPeripheralProvider> peripheralProviders = new ArrayList<>();
|
|
||||||
|
|
||||||
// Implementation
|
// Implementation
|
||||||
@Mod.Instance( ComputerCraft.MOD_ID )
|
|
||||||
public static ComputerCraft instance;
|
public static ComputerCraft instance;
|
||||||
|
|
||||||
@SidedProxy(
|
public ComputerCraft()
|
||||||
clientSide = "dan200.computercraft.client.proxy.ComputerCraftProxyClient",
|
|
||||||
serverSide = "dan200.computercraft.shared.proxy.ComputerCraftProxyCommon"
|
|
||||||
)
|
|
||||||
private static ComputerCraftProxyCommon proxy;
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
public void preInit( FMLPreInitializationEvent event )
|
|
||||||
{
|
{
|
||||||
log = event.getModLog();
|
instance = this;
|
||||||
|
|
||||||
// Load config
|
|
||||||
Config.load( event.getSuggestedConfigurationFile() );
|
|
||||||
|
|
||||||
proxy.preInit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Override
|
||||||
public void init( FMLInitializationEvent event )
|
public void onInitialize()
|
||||||
{
|
{
|
||||||
proxy.init();
|
ComputerCraftProxyCommon.setup();
|
||||||
}
|
if( net.fabricmc.loader.api.FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT )
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
public void onServerStarting( FMLServerStartingEvent event )
|
|
||||||
{
|
|
||||||
ComputerCraftProxyCommon.initServer( event.getServer() );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
public void onServerStart( FMLServerStartedEvent event )
|
|
||||||
{
|
|
||||||
if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
|
|
||||||
{
|
{
|
||||||
ComputerCraft.serverComputerRegistry.reset();
|
ComputerCraftProxyClient.setup();
|
||||||
WirelessNetwork.resetNetworks();
|
|
||||||
MainThread.reset();
|
|
||||||
Tracking.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Mod.EventHandler
|
|
||||||
public void onServerStopped( FMLServerStoppedEvent event )
|
|
||||||
{
|
|
||||||
if( FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER )
|
|
||||||
{
|
|
||||||
ComputerCraft.serverComputerRegistry.reset();
|
|
||||||
WirelessNetwork.resetNetworks();
|
|
||||||
MainThread.reset();
|
|
||||||
Tracking.reset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersion()
|
public static String getVersion()
|
||||||
{
|
{
|
||||||
return VERSION;
|
return "${version}";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File getBaseDir()
|
static IMount createResourceMount( String domain, String subPath )
|
||||||
{
|
{
|
||||||
return FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory();
|
ReloadableResourceManager manager = ComputerCraftProxyCommon.getServer().getDataManager();
|
||||||
|
ResourceMount mount = new ResourceMount( domain, subPath, manager );
|
||||||
|
return mount.exists( "" ) ? mount : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File getResourcePackDir()
|
public static InputStream getResourceFile( String domain, String subPath )
|
||||||
{
|
|
||||||
return new File( getBaseDir(), "resourcepacks" );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void registerPermissionProvider( ITurtlePermissionProvider provider )
|
|
||||||
{
|
|
||||||
TurtlePermissions.register( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void registerPocketUpgrade( IPocketUpgrade upgrade )
|
|
||||||
{
|
|
||||||
dan200.computercraft.shared.PocketUpgrades.register( upgrade );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void registerPeripheralProvider( IPeripheralProvider provider )
|
|
||||||
{
|
|
||||||
Peripherals.register( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void registerBundledRedstoneProvider( IBundledRedstoneProvider provider )
|
|
||||||
{
|
|
||||||
BundledRedstone.register( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void registerMediaProvider( IMediaProvider provider )
|
|
||||||
{
|
|
||||||
MediaProviders.register( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void registerAPIFactory( ILuaAPIFactory factory )
|
|
||||||
{
|
|
||||||
ApiFactories.register( factory );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IWiredNode createWiredNodeForElement( IWiredElement element )
|
|
||||||
{
|
|
||||||
return new WiredNode( element );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IWiredElement getWiredElementAt( IBlockAccess world, BlockPos pos, EnumFacing side )
|
|
||||||
{
|
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
|
||||||
return tile != null && tile.hasCapability( CapabilityWiredElement.CAPABILITY, side )
|
|
||||||
? tile.getCapability( CapabilityWiredElement.CAPABILITY, side )
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static int getDefaultBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side )
|
|
||||||
{
|
|
||||||
return BundledRedstone.getDefaultOutput( world, pos, side );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IPacketNetwork getWirelessNetwork()
|
|
||||||
{
|
|
||||||
return WirelessNetwork.getUniversal();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static int createUniqueNumberedSaveDir( World world, String parentSubPath )
|
|
||||||
{
|
|
||||||
return IDAssigner.getNextIDFromDirectory( parentSubPath );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IWritableMount createSaveDirMount( World world, String subPath, long capacity )
|
|
||||||
{
|
{
|
||||||
|
ReloadableResourceManager manager = ComputerCraftProxyCommon.getServer().getDataManager();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new FileMount( new File( getWorldDir(), subPath ), capacity );
|
return manager.getResource( new Identifier( domain, subPath ) ).getInputStream();
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( IOException ignored )
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadFromFile( List<IMount> mounts, File file, String path, boolean allowMissing )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if( file.isFile() )
|
|
||||||
{
|
|
||||||
mounts.add( new JarMount( file, path ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
File subResource = new File( file, path );
|
|
||||||
if( subResource.exists() ) mounts.add( new FileMount( subResource, 0 ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( IOException | RuntimeException e )
|
|
||||||
{
|
|
||||||
if( allowMissing && e instanceof FileNotFoundException ) return;
|
|
||||||
ComputerCraft.log.error( "Could not load mount '" + path + " 'from '" + file.getName() + "'", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IMount createResourceMount( Class<?> modClass, String domain, String subPath )
|
|
||||||
{
|
|
||||||
// Start building list of mounts
|
|
||||||
List<IMount> mounts = new ArrayList<>();
|
|
||||||
subPath = "assets/" + domain + "/" + subPath;
|
|
||||||
|
|
||||||
// Mount from debug dir
|
|
||||||
File codeDir = getDebugCodeDir( modClass );
|
|
||||||
if( codeDir != null )
|
|
||||||
{
|
|
||||||
File subResource = new File( codeDir, subPath );
|
|
||||||
if( subResource.exists() )
|
|
||||||
{
|
|
||||||
IMount resourcePackMount = new FileMount( subResource, 0 );
|
|
||||||
mounts.add( resourcePackMount );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount from mod jars, preferring the specified one.
|
|
||||||
File modJar = getContainingJar( modClass );
|
|
||||||
Set<File> otherMods = new HashSet<>();
|
|
||||||
for( ModContainer container : Loader.instance().getActiveModList() )
|
|
||||||
{
|
|
||||||
File modFile = container.getSource();
|
|
||||||
if( modFile != null && !modFile.equals( modJar ) && modFile.exists() )
|
|
||||||
{
|
|
||||||
otherMods.add( container.getSource() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for( File file : otherMods )
|
|
||||||
{
|
|
||||||
loadFromFile( mounts, file, subPath, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( modJar != null )
|
|
||||||
{
|
|
||||||
loadFromFile( mounts, modJar, subPath, false );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mount from resource packs
|
|
||||||
File resourcePackDir = getResourcePackDir();
|
|
||||||
if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
|
|
||||||
{
|
|
||||||
String[] resourcePacks = resourcePackDir.list();
|
|
||||||
for( String resourcePackName : resourcePacks )
|
|
||||||
{
|
|
||||||
File resourcePack = new File( resourcePackDir, resourcePackName );
|
|
||||||
loadFromFile( mounts, resourcePack, subPath, true );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the combination of all the mounts found
|
|
||||||
if( mounts.size() >= 2 )
|
|
||||||
{
|
|
||||||
IMount[] mountArray = new IMount[mounts.size()];
|
|
||||||
mounts.toArray( mountArray );
|
|
||||||
return new ComboMount( mountArray );
|
|
||||||
}
|
|
||||||
else if( mounts.size() == 1 )
|
|
||||||
{
|
|
||||||
return mounts.get( 0 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InputStream getResourceFile( Class<?> modClass, String domain, String subPath )
|
|
||||||
{
|
|
||||||
// Start searching in possible locations
|
|
||||||
subPath = "assets/" + domain + "/" + subPath;
|
|
||||||
|
|
||||||
// Look in resource packs
|
|
||||||
File resourcePackDir = getResourcePackDir();
|
|
||||||
if( resourcePackDir.exists() && resourcePackDir.isDirectory() )
|
|
||||||
{
|
|
||||||
String[] resourcePacks = resourcePackDir.list();
|
|
||||||
for( String resourcePackPath : resourcePacks )
|
|
||||||
{
|
|
||||||
File resourcePack = new File( resourcePackDir, resourcePackPath );
|
|
||||||
if( resourcePack.isDirectory() )
|
|
||||||
{
|
|
||||||
// Mount a resource pack from a folder
|
|
||||||
File subResource = new File( resourcePack, subPath );
|
|
||||||
if( subResource.exists() && subResource.isFile() )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new FileInputStream( subResource );
|
|
||||||
}
|
|
||||||
catch( FileNotFoundException ignored )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ZipFile zipFile = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final ZipFile zip = zipFile = new ZipFile( resourcePack );
|
|
||||||
ZipEntry entry = zipFile.getEntry( subPath );
|
|
||||||
if( entry != null )
|
|
||||||
{
|
|
||||||
// Return a custom InputStream which will close the original zip when finished.
|
|
||||||
return new FilterInputStream( zipFile.getInputStream( entry ) )
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void close() throws IOException
|
|
||||||
{
|
|
||||||
super.close();
|
|
||||||
zip.close();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IoUtil.closeQuietly( zipFile );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch( IOException e )
|
|
||||||
{
|
|
||||||
if( zipFile != null ) IoUtil.closeQuietly( zipFile );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look in debug dir
|
|
||||||
File codeDir = getDebugCodeDir( modClass );
|
|
||||||
if( codeDir != null )
|
|
||||||
{
|
|
||||||
File subResource = new File( codeDir, subPath );
|
|
||||||
if( subResource.exists() && subResource.isFile() )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return new FileInputStream( subResource );
|
|
||||||
}
|
|
||||||
catch( FileNotFoundException ignored )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look in class loader
|
|
||||||
return modClass.getClassLoader().getResourceAsStream( subPath );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File getContainingJar( Class<?> modClass )
|
|
||||||
{
|
|
||||||
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
|
|
||||||
int bangIndex = path.indexOf( '!' );
|
|
||||||
if( bangIndex >= 0 )
|
|
||||||
{
|
|
||||||
path = path.substring( 0, bangIndex );
|
|
||||||
}
|
|
||||||
|
|
||||||
URL url;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
url = new URL( path );
|
|
||||||
}
|
|
||||||
catch( MalformedURLException e1 )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
File file;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
file = new File( url.toURI() );
|
|
||||||
}
|
|
||||||
catch( URISyntaxException e )
|
|
||||||
{
|
|
||||||
file = new File( url.getPath() );
|
|
||||||
}
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File getDebugCodeDir( Class<?> modClass )
|
|
||||||
{
|
|
||||||
String path = modClass.getProtectionDomain().getCodeSource().getLocation().getPath();
|
|
||||||
int bangIndex = path.indexOf( '!' );
|
|
||||||
return bangIndex >= 0 ? null : new File( new File( path ).getParentFile(), "../.." );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static void registerTurtleUpgrade( ITurtleUpgrade upgrade )
|
|
||||||
{
|
|
||||||
dan200.computercraft.shared.TurtleUpgrades.register( upgrade );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static File getWorldDir()
|
|
||||||
{
|
|
||||||
return DimensionManager.getCurrentSaveRootDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
//region Compatibility
|
|
||||||
@Deprecated
|
|
||||||
public static File getWorldDir( World world )
|
|
||||||
{
|
|
||||||
return DimensionManager.getCurrentSaveRootDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IMedia getMedia( ItemStack stack )
|
|
||||||
{
|
|
||||||
return MediaProviders.get( stack );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IPocketUpgrade getPocketUpgrade( ItemStack stack )
|
|
||||||
{
|
|
||||||
return dan200.computercraft.shared.PocketUpgrades.get( stack );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static ITurtleUpgrade getTurtleUpgrade( ItemStack stack )
|
|
||||||
{
|
|
||||||
return dan200.computercraft.shared.TurtleUpgrades.get( stack );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IPocketUpgrade getPocketUpgrade( String id )
|
|
||||||
{
|
|
||||||
return dan200.computercraft.shared.PocketUpgrades.get( id );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static ITurtleUpgrade getTurtleUpgrade( String id )
|
|
||||||
{
|
|
||||||
return dan200.computercraft.shared.TurtleUpgrades.get( id );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IPeripheral getPeripheralAt( World world, BlockPos pos, EnumFacing side )
|
|
||||||
{
|
|
||||||
return Peripherals.getPeripheral( world, pos, side );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static boolean canPlayerUseCommands( EntityPlayer player )
|
|
||||||
{
|
|
||||||
MinecraftServer server = player.getServer();
|
|
||||||
return server != null && server.getPlayerList().canSendCommands( player.getGameProfile() );
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
}
|
}
|
||||||
|
|||||||
150
src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
Normal file
150
src/main/java/dan200/computercraft/ComputerCraftAPIImpl.java
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft;
|
||||||
|
|
||||||
|
import dan200.computercraft.api.ComputerCraftAPI.IComputerCraftAPI;
|
||||||
|
import dan200.computercraft.api.filesystem.IMount;
|
||||||
|
import dan200.computercraft.api.filesystem.IWritableMount;
|
||||||
|
import dan200.computercraft.api.lua.ILuaAPIFactory;
|
||||||
|
import dan200.computercraft.api.media.IMediaProvider;
|
||||||
|
import dan200.computercraft.api.network.IPacketNetwork;
|
||||||
|
import dan200.computercraft.api.network.wired.IWiredElement;
|
||||||
|
import dan200.computercraft.api.network.wired.IWiredNode;
|
||||||
|
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||||
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
|
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||||
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
|
import dan200.computercraft.core.apis.ApiFactories;
|
||||||
|
import dan200.computercraft.core.filesystem.FileMount;
|
||||||
|
import dan200.computercraft.shared.*;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wired.TileWiredModemFull;
|
||||||
|
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
|
||||||
|
import dan200.computercraft.shared.util.IDAssigner;
|
||||||
|
import dan200.computercraft.shared.wired.WiredNode;
|
||||||
|
import net.minecraft.block.entity.BlockEntity;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||||
|
{
|
||||||
|
public static final ComputerCraftAPIImpl INSTANCE = new ComputerCraftAPIImpl();
|
||||||
|
|
||||||
|
private ComputerCraftAPIImpl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public String getInstalledVersion()
|
||||||
|
{
|
||||||
|
return "${version}";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||||
|
{
|
||||||
|
return IDAssigner.getNextId( world, parentSubPath );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new FileMount( new File( IDAssigner.getDir( world ), subPath ), capacity );
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
|
||||||
|
{
|
||||||
|
return ComputerCraft.createResourceMount( domain, subPath );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
|
||||||
|
{
|
||||||
|
Peripherals.register( provider );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
|
||||||
|
{
|
||||||
|
TurtleUpgrades.register( upgrade );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
|
||||||
|
{
|
||||||
|
BundledRedstone.register( provider );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
|
{
|
||||||
|
return BundledRedstone.getDefaultOutput( world, pos, side );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerMediaProvider( @Nonnull IMediaProvider provider )
|
||||||
|
{
|
||||||
|
MediaProviders.register( provider );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
|
||||||
|
{
|
||||||
|
PocketUpgrades.register( upgrade );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IPacketNetwork getWirelessNetwork()
|
||||||
|
{
|
||||||
|
return WirelessNetwork.getUniversal();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
|
||||||
|
{
|
||||||
|
ApiFactories.register( factory );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
|
||||||
|
{
|
||||||
|
return new WiredNode( element );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
|
{
|
||||||
|
BlockEntity tile = world.getBlockEntity( pos );
|
||||||
|
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.block.Block;
|
import net.minecraft.item.ItemProvider;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.SystemUtil;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -21,59 +22,41 @@ 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 int legacyId;
|
|
||||||
private final TurtleUpgradeType type;
|
private final TurtleUpgradeType type;
|
||||||
private final String adjective;
|
private final String adjective;
|
||||||
private final ItemStack stack;
|
private final ItemStack stack;
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, ItemStack stack )
|
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||||
{
|
{
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.legacyId = legacyId;
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.adjective = adjective;
|
this.adjective = adjective;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Item item )
|
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, String adjective, ItemProvider item )
|
||||||
{
|
{
|
||||||
this( id, legacyId, type, adjective, new ItemStack( item ) );
|
this( id, type, adjective, new ItemStack( item ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, String adjective, Block block )
|
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemStack stack )
|
||||||
{
|
{
|
||||||
this( id, legacyId, type, adjective, new ItemStack( block ) );
|
this( id, type, SystemUtil.createTranslationKey( "upgrade", id ) + ".adjective", stack );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, ItemStack stack )
|
protected AbstractTurtleUpgrade( Identifier id, TurtleUpgradeType type, ItemProvider item )
|
||||||
{
|
{
|
||||||
this( id, legacyId, type, "upgrade." + id + ".adjective", stack );
|
this( id, type, new ItemStack( item ) );
|
||||||
}
|
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Item item )
|
|
||||||
{
|
|
||||||
this( id, legacyId, type, new ItemStack( item ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
protected AbstractTurtleUpgrade( ResourceLocation id, int legacyId, TurtleUpgradeType type, Block block )
|
|
||||||
{
|
|
||||||
this( id, legacyId, type, new ItemStack( block ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public final ResourceLocation getUpgradeID()
|
public final Identifier getUpgradeID()
|
||||||
{
|
{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int getLegacyUpgradeID()
|
|
||||||
{
|
|
||||||
return legacyId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public final String getUnlocalisedAdjective()
|
public final String getUnlocalisedAdjective()
|
||||||
|
|||||||
@@ -17,49 +17,28 @@ import dan200.computercraft.api.network.wired.IWiredNode;
|
|||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||||
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
import dan200.computercraft.api.peripheral.IPeripheralProvider;
|
||||||
import dan200.computercraft.api.permissions.ITurtlePermissionProvider;
|
|
||||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||||
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
import dan200.computercraft.api.redstone.IBundledRedstoneProvider;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockAccess;
|
import net.minecraft.util.math.Direction;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
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;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The static entry point to the ComputerCraft API.
|
* The static entry point to the ComputerCraft API.
|
||||||
*
|
* Members in this class must be called after mod_ComputerCraft has been initialised,
|
||||||
* Members in this class must be called after mod_ComputerCraft has been initialised, but may be called before it is
|
* but may be called before it is fully loaded.
|
||||||
* fully loaded.
|
|
||||||
*/
|
*/
|
||||||
public final class ComputerCraftAPI
|
public final class ComputerCraftAPI
|
||||||
{
|
{
|
||||||
public static boolean isInstalled()
|
|
||||||
{
|
|
||||||
findCC();
|
|
||||||
return computerCraft != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String getInstalledVersion()
|
public static String getInstalledVersion()
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().getInstalledVersion();
|
||||||
if( computerCraft_getVersion != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (String) computerCraft_getVersion.invoke( null );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@@ -83,19 +62,7 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
public static int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath )
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().createUniqueNumberedSaveDir( world, parentSubPath );
|
||||||
if( computerCraft_createUniqueNumberedSaveDir != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (Integer) computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -119,55 +86,54 @@ public final class ComputerCraftAPI
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
public static IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity )
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().createSaveDirMount( world, subPath, capacity );
|
||||||
if( computerCraft_createSaveDirMount != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (IWritableMount) computerCraft_createSaveDirMount.invoke( null, world, subPath, capacity );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a file system mount to a resource folder, and returns it.
|
* Creates a file system mount to a resource folder, and returns it.
|
||||||
*
|
*
|
||||||
* Use in conjunction with IComputerAccess.mount() or IComputerAccess.mountWritable() to mount a resource folder
|
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
|
||||||
* onto a computer's file system.
|
* resource folder onto a computer's file system.
|
||||||
*
|
*
|
||||||
* The files in this mount will be a combination of files in the specified mod jar, and resource packs that contain
|
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
|
||||||
* resources with the same domain and path.
|
* resources with the same domain and path.
|
||||||
*
|
*
|
||||||
* @param modClass A class in whose jar to look first for the resources to mount. Using your main mod class is recommended. eg: MyMod.class
|
* @param domain The domain under which to look for resources. eg: "mymod".
|
||||||
* @param domain The domain under which to look for resources. eg: "mymod".
|
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
||||||
* @param subPath The domain under which to look for resources. eg: "mymod/lua/myfiles".
|
* @return The mount, or {@code null} if it could be created for some reason.
|
||||||
* @return The mount, or {@code null} if it could be created for some reason. Use IComputerAccess.mount() or
|
|
||||||
* IComputerAccess.mountWritable() to mount this on a Computers' file system.
|
|
||||||
* @see IComputerAccess#mount(String, IMount)
|
* @see IComputerAccess#mount(String, IMount)
|
||||||
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||||
* @see IMount
|
* @see IMount
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static IMount createResourceMount( @Nonnull Class<?> modClass, @Nonnull String domain, @Nonnull String subPath )
|
public static IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().createResourceMount( domain, subPath );
|
||||||
if( computerCraft_createResourceMount != null )
|
}
|
||||||
{
|
|
||||||
try
|
/**
|
||||||
{
|
* Creates a file system mount to a resource folder, and returns it.
|
||||||
return (IMount) computerCraft_createResourceMount.invoke( null, modClass, domain, subPath );
|
*
|
||||||
}
|
* Use in conjunction with {@link IComputerAccess#mount} or {@link IComputerAccess#mountWritable} to mount a
|
||||||
catch( Exception e )
|
* resource folder onto a computer's file system.
|
||||||
{
|
*
|
||||||
// It failed
|
* The files in this mount will be a combination of files in all mod jar, and data packs that contain
|
||||||
}
|
* resources with the same domain and path.
|
||||||
}
|
*
|
||||||
return null;
|
* @param klass The mod class to which the files belong.
|
||||||
|
* @param domain The domain under which to look for resources. eg: "mymod".
|
||||||
|
* @param subPath The subPath under which to look for resources. eg: "lua/myfiles".
|
||||||
|
* @return The mount, or {@code null} if it could be created for some reason.
|
||||||
|
* @see IComputerAccess#mount(String, IMount)
|
||||||
|
* @see IComputerAccess#mountWritable(String, IWritableMount)
|
||||||
|
* @see IMount
|
||||||
|
* @deprecated Use {@link #createResourceMount(String, String)} instead.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
@Deprecated
|
||||||
|
public static IMount createResourceMount( Class<?> klass, @Nonnull String domain, @Nonnull String subPath )
|
||||||
|
{
|
||||||
|
return getInstance().createResourceMount( domain, subPath );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -179,18 +145,7 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
|
public static void registerPeripheralProvider( @Nonnull IPeripheralProvider provider )
|
||||||
{
|
{
|
||||||
findCC();
|
getInstance().registerPeripheralProvider( provider );
|
||||||
if( computerCraft_registerPeripheralProvider != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft_registerPeripheralProvider.invoke( null, provider );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -203,21 +158,7 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
|
public static void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade )
|
||||||
{
|
{
|
||||||
if( upgrade != null )
|
getInstance().registerTurtleUpgrade( upgrade );
|
||||||
{
|
|
||||||
findCC();
|
|
||||||
if( computerCraft_registerTurtleUpgrade != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft_registerTurtleUpgrade.invoke( null, upgrade );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -228,18 +169,7 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
|
public static void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider )
|
||||||
{
|
{
|
||||||
findCC();
|
getInstance().registerBundledRedstoneProvider( provider );
|
||||||
if( computerCraft_registerBundledRedstoneProvider != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft_registerBundledRedstoneProvider.invoke( null, provider );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -252,83 +182,25 @@ 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 )
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().getBundledRedstoneOutput( world, pos, side );
|
||||||
if( computerCraft_getDefaultBundledRedstoneOutput != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (Integer) computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a media provider to provide {@link IMedia} implementations for Items.
|
* Registers a media provider to provide {@link IMedia} implementations for Items
|
||||||
*
|
*
|
||||||
* @param provider The media provider to register.
|
* @param provider The media provider to register.
|
||||||
* @see IMediaProvider
|
* @see IMediaProvider
|
||||||
*/
|
*/
|
||||||
public static void registerMediaProvider( @Nonnull IMediaProvider provider )
|
public static void registerMediaProvider( @Nonnull IMediaProvider provider )
|
||||||
{
|
{
|
||||||
findCC();
|
getInstance().registerMediaProvider( provider );
|
||||||
if( computerCraft_registerMediaProvider != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft_registerMediaProvider.invoke( null, provider );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Registers a permission provider to restrict where turtles can move or build.
|
|
||||||
*
|
|
||||||
* @param provider The turtle permission provider to register.
|
|
||||||
* @see ITurtlePermissionProvider
|
|
||||||
* @deprecated Prefer using {@link dan200.computercraft.api.turtle.event.TurtleBlockEvent} or the standard Forge events.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static void registerPermissionProvider( @Nonnull ITurtlePermissionProvider provider )
|
|
||||||
{
|
|
||||||
findCC();
|
|
||||||
if( computerCraft_registerPermissionProvider != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft_registerPermissionProvider.invoke( null, provider );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
|
public static void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade )
|
||||||
{
|
{
|
||||||
findCC();
|
getInstance().registerPocketUpgrade( upgrade );
|
||||||
if( computerCraft_registerPocketUpgrade != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft_registerPocketUpgrade.invoke( null, upgrade );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -338,40 +210,16 @@ public final class ComputerCraftAPI
|
|||||||
*/
|
*/
|
||||||
public static IPacketNetwork getWirelessNetwork()
|
public static IPacketNetwork getWirelessNetwork()
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().getWirelessNetwork();
|
||||||
if( computerCraft_getWirelessNetwork != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (IPacketNetwork) computerCraft_getWirelessNetwork.invoke( null );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerAPIFactory( @Nonnull ILuaAPIFactory upgrade )
|
public static void registerAPIFactory( @Nonnull ILuaAPIFactory factory )
|
||||||
{
|
{
|
||||||
findCC();
|
getInstance().registerAPIFactory( factory );
|
||||||
if( computerCraft_registerAPIFactory != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft_registerAPIFactory.invoke( null, upgrade );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
// It failed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new wired node for a given wired element.
|
* Construct a new wired node for a given wired element
|
||||||
*
|
*
|
||||||
* @param element The element to construct it for
|
* @param element The element to construct it for
|
||||||
* @return The element's node
|
* @return The element's node
|
||||||
@@ -380,26 +228,11 @@ public final class ComputerCraftAPI
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
public static IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
|
public static IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element )
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().createWiredNodeForElement( element );
|
||||||
if( computerCraft_createWiredNodeForElement != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (IWiredNode) computerCraft_createWiredNodeForElement.invoke( null, element );
|
|
||||||
}
|
|
||||||
catch( ReflectiveOperationException e )
|
|
||||||
{
|
|
||||||
throw new IllegalStateException( "Error creating wired node", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new IllegalStateException( "ComputerCraft cannot be found" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the wired network element for a block in world.
|
* Get the wired network element for a block in world
|
||||||
*
|
*
|
||||||
* @param world The world the block exists in
|
* @param world The world the block exists in
|
||||||
* @param pos The position the block exists in
|
* @param pos The position the block exists in
|
||||||
@@ -408,117 +241,63 @@ public final class ComputerCraftAPI
|
|||||||
* @see IWiredElement#getNode()
|
* @see IWiredElement#getNode()
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static IWiredElement getWiredElementAt( @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull EnumFacing side )
|
public static IWiredElement getWiredElementAt( @Nonnull BlockView world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||||
{
|
{
|
||||||
findCC();
|
return getInstance().getWiredElementAt( world, pos, side );
|
||||||
if( computerCraft_getWiredElementAt != null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return (IWiredElement) computerCraft_getWiredElementAt.invoke( null, world, pos, side );
|
|
||||||
}
|
|
||||||
catch( ReflectiveOperationException ignored )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The functions below here are private, and are used to interface with the non-API ComputerCraft classes.
|
private static IComputerCraftAPI instance;
|
||||||
// Reflection is used here so you can develop your mod without decompiling ComputerCraft and including
|
|
||||||
// it in your solution, and so your mod won't crash if ComputerCraft is installed.
|
|
||||||
|
|
||||||
private static void findCC()
|
@Nonnull
|
||||||
|
private static IComputerCraftAPI getInstance()
|
||||||
{
|
{
|
||||||
if( !ccSearched )
|
if( instance != null ) return instance;
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" );
|
|
||||||
computerCraft_getVersion = findCCMethod( "getVersion", new Class<?>[] {
|
|
||||||
} );
|
|
||||||
computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class<?>[] {
|
|
||||||
World.class, String.class,
|
|
||||||
} );
|
|
||||||
computerCraft_createSaveDirMount = findCCMethod( "createSaveDirMount", new Class<?>[] {
|
|
||||||
World.class, String.class, Long.TYPE,
|
|
||||||
} );
|
|
||||||
computerCraft_createResourceMount = findCCMethod( "createResourceMount", new Class<?>[] {
|
|
||||||
Class.class, String.class, String.class,
|
|
||||||
} );
|
|
||||||
computerCraft_registerPeripheralProvider = findCCMethod( "registerPeripheralProvider", new Class<?>[] {
|
|
||||||
IPeripheralProvider.class,
|
|
||||||
} );
|
|
||||||
computerCraft_registerTurtleUpgrade = findCCMethod( "registerTurtleUpgrade", new Class<?>[] {
|
|
||||||
ITurtleUpgrade.class,
|
|
||||||
} );
|
|
||||||
computerCraft_registerBundledRedstoneProvider = findCCMethod( "registerBundledRedstoneProvider", new Class<?>[] {
|
|
||||||
IBundledRedstoneProvider.class,
|
|
||||||
} );
|
|
||||||
computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class<?>[] {
|
|
||||||
World.class, BlockPos.class, EnumFacing.class,
|
|
||||||
} );
|
|
||||||
computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class<?>[] {
|
|
||||||
IMediaProvider.class,
|
|
||||||
} );
|
|
||||||
computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class<?>[] {
|
|
||||||
ITurtlePermissionProvider.class,
|
|
||||||
} );
|
|
||||||
computerCraft_registerPocketUpgrade = findCCMethod( "registerPocketUpgrade", new Class<?>[] {
|
|
||||||
IPocketUpgrade.class,
|
|
||||||
} );
|
|
||||||
computerCraft_getWirelessNetwork = findCCMethod( "getWirelessNetwork", new Class<?>[] {
|
|
||||||
} );
|
|
||||||
computerCraft_registerAPIFactory = findCCMethod( "registerAPIFactory", new Class<?>[] {
|
|
||||||
ILuaAPIFactory.class,
|
|
||||||
} );
|
|
||||||
computerCraft_createWiredNodeForElement = findCCMethod( "createWiredNodeForElement", new Class<?>[] {
|
|
||||||
IWiredElement.class,
|
|
||||||
} );
|
|
||||||
computerCraft_getWiredElementAt = findCCMethod( "getWiredElementAt", new Class<?>[] {
|
|
||||||
IBlockAccess.class, BlockPos.class, EnumFacing.class,
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
System.err.println( "ComputerCraftAPI: ComputerCraft not found." );
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
ccSearched = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Method findCCMethod( String name, Class<?>[] args )
|
|
||||||
{
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return computerCraft != null ? computerCraft.getMethod( name, args ) : null;
|
return instance = (IComputerCraftAPI) Class.forName( "dan200.computercraft.ComputerCraftAPIImpl" )
|
||||||
|
.getField( "INSTANCE" ).get( null );
|
||||||
}
|
}
|
||||||
catch( NoSuchMethodException e )
|
catch( ReflectiveOperationException e )
|
||||||
{
|
{
|
||||||
System.err.println( "ComputerCraftAPI: ComputerCraft method " + name + " not found." );
|
throw new IllegalStateException( "Cannot find ComputerCraft API", e );
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean ccSearched = false;
|
public interface IComputerCraftAPI
|
||||||
private static Class<?> computerCraft = null;
|
{
|
||||||
private static Method computerCraft_getVersion = null;
|
@Nonnull
|
||||||
private static Method computerCraft_createUniqueNumberedSaveDir = null;
|
String getInstalledVersion();
|
||||||
private static Method computerCraft_createSaveDirMount = null;
|
|
||||||
private static Method computerCraft_createResourceMount = null;
|
int createUniqueNumberedSaveDir( @Nonnull World world, @Nonnull String parentSubPath );
|
||||||
private static Method computerCraft_registerPeripheralProvider = null;
|
|
||||||
private static Method computerCraft_registerTurtleUpgrade = null;
|
@Nullable
|
||||||
private static Method computerCraft_registerBundledRedstoneProvider = null;
|
IWritableMount createSaveDirMount( @Nonnull World world, @Nonnull String subPath, long capacity );
|
||||||
private static Method computerCraft_getDefaultBundledRedstoneOutput = null;
|
|
||||||
private static Method computerCraft_registerMediaProvider = null;
|
@Nullable
|
||||||
private static Method computerCraft_registerPermissionProvider = null;
|
IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath );
|
||||||
private static Method computerCraft_registerPocketUpgrade = null;
|
|
||||||
private static Method computerCraft_getWirelessNetwork = null;
|
void registerPeripheralProvider( @Nonnull IPeripheralProvider provider );
|
||||||
private static Method computerCraft_registerAPIFactory = null;
|
|
||||||
private static Method computerCraft_createWiredNodeForElement = null;
|
void registerTurtleUpgrade( @Nonnull ITurtleUpgrade upgrade );
|
||||||
private static Method computerCraft_getWiredElementAt = null;
|
|
||||||
|
void registerBundledRedstoneProvider( @Nonnull IBundledRedstoneProvider provider );
|
||||||
|
|
||||||
|
int getBundledRedstoneOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side );
|
||||||
|
|
||||||
|
void registerMediaProvider( @Nonnull IMediaProvider provider );
|
||||||
|
|
||||||
|
void registerPocketUpgrade( @Nonnull IPocketUpgrade upgrade );
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
IPacketNetwork getWirelessNetwork();
|
||||||
|
|
||||||
|
void registerAPIFactory( @Nonnull ILuaAPIFactory factory );
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
IWiredNode createWiredNodeForElement( @Nonnull IWiredElement element );
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
* Represents a read only part of a virtual filesystem that can be mounted onto a computer using
|
||||||
* {@link IComputerAccess#mount(String, IMount)}.
|
* {@link IComputerAccess#mount(String, IMount)}
|
||||||
*
|
*
|
||||||
* Ready made implementations of this interface can be created using
|
* Ready made implementations of this interface can be created using
|
||||||
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
|
* {@link ComputerCraftAPI#createSaveDirMount(World, String, long)} or
|
||||||
@@ -60,7 +60,7 @@ public interface IMount
|
|||||||
void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
|
void list( @Nonnull String path, @Nonnull List<String> contents ) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the size of a file with a given path, in bytes.
|
* Returns the size of a file with a given path, in bytes
|
||||||
*
|
*
|
||||||
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
* @param path A file path in normalised format, relative to the mount location. ie: "programs/myprogram".
|
||||||
* @return The size of the file, in bytes.
|
* @return The size of the file, in bytes.
|
||||||
@@ -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 ) );
|
||||||
|
|||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|FileSystem", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.filesystem;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -1,335 +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.lua;
|
|
||||||
|
|
||||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
|
||||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides methods for extracting values and validating Lua arguments, such as those provided to
|
|
||||||
* {@link ILuaObject#callMethod(ILuaContext, int, Object[])} or
|
|
||||||
* {@link IPeripheral#callMethod(IComputerAccess, ILuaContext, int, Object[])}.
|
|
||||||
*
|
|
||||||
* This provides two sets of functions: the {@code get*} methods, which require an argument to be valid, and
|
|
||||||
* {@code opt*}, which accept a default value and return that if the argument was not present or was {@code null}.
|
|
||||||
* If the argument is of the wrong type, a suitable error message will be thrown, with a similar format to Lua's own
|
|
||||||
* error messages.
|
|
||||||
*
|
|
||||||
* <h2>Example usage:</h2>
|
|
||||||
* <pre>
|
|
||||||
* {@code
|
|
||||||
* int slot = getInt( args, 0 );
|
|
||||||
* int amount = optInt( args, 1, 64 );
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*/
|
|
||||||
public final class ArgumentHelper
|
|
||||||
{
|
|
||||||
private ArgumentHelper()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a string representation of the given value's type.
|
|
||||||
*
|
|
||||||
* @param value The value whose type we are trying to compute.
|
|
||||||
* @return A string representation of the given value's type, in a similar format to that provided by Lua's
|
|
||||||
* {@code type} function.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public static String getType( @Nullable Object value )
|
|
||||||
{
|
|
||||||
if( value == null ) return "nil";
|
|
||||||
if( value instanceof String ) return "string";
|
|
||||||
if( value instanceof Boolean ) return "boolean";
|
|
||||||
if( value instanceof Number ) return "number";
|
|
||||||
if( value instanceof Map ) return "table";
|
|
||||||
return "userdata";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a "bad argument" exception, from an expected type and the actual value provided.
|
|
||||||
*
|
|
||||||
* @param index The argument number, starting from 0.
|
|
||||||
* @param expected The expected type for this argument.
|
|
||||||
* @param actual The actual value provided for this argument.
|
|
||||||
* @return The constructed exception, which should be thrown immediately.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public static LuaException badArgumentOf( int index, @Nonnull String expected, @Nullable Object actual )
|
|
||||||
{
|
|
||||||
return badArgument( index, expected, getType( actual ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a "bad argument" exception, from an expected and actual type.
|
|
||||||
*
|
|
||||||
* @param index The argument number, starting from 0.
|
|
||||||
* @param expected The expected type for this argument.
|
|
||||||
* @param actual The provided type for this argument.
|
|
||||||
* @return The constructed exception, which should be thrown immediately.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
|
|
||||||
{
|
|
||||||
return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a double.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @return The argument's value.
|
|
||||||
* @throws LuaException If the value is not a number.
|
|
||||||
* @see #getFiniteDouble(Object[], int) if you require this to be finite (i.e. not infinite or NaN).
|
|
||||||
*/
|
|
||||||
public static double getDouble( @Nonnull Object[] args, int index ) throws LuaException
|
|
||||||
{
|
|
||||||
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
|
||||||
Object value = args[index];
|
|
||||||
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
|
||||||
return ((Number) value).doubleValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as an integer.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @return The argument's value.
|
|
||||||
* @throws LuaException If the value is not an integer.
|
|
||||||
*/
|
|
||||||
public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
|
|
||||||
{
|
|
||||||
return (int) getLong( args, index );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a long.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @return The argument's value.
|
|
||||||
* @throws LuaException If the value is not a long.
|
|
||||||
*/
|
|
||||||
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
|
|
||||||
{
|
|
||||||
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
|
||||||
Object value = args[index];
|
|
||||||
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
|
||||||
return checkFinite( index, (Number) value ).longValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a finite number (not infinite or NaN).
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @return The argument's value.
|
|
||||||
* @throws LuaException If the value is not finite.
|
|
||||||
*/
|
|
||||||
public static double getFiniteDouble( @Nonnull Object[] args, int index ) throws LuaException
|
|
||||||
{
|
|
||||||
return checkFinite( index, getDouble( args, index ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a boolean.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @return The argument's value.
|
|
||||||
* @throws LuaException If the value is not a boolean.
|
|
||||||
*/
|
|
||||||
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
|
|
||||||
{
|
|
||||||
if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
|
|
||||||
Object value = args[index];
|
|
||||||
if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
|
|
||||||
return (Boolean) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a string.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @return The argument's value.
|
|
||||||
* @throws LuaException If the value is not a string.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public static String getString( @Nonnull Object[] args, int index ) throws LuaException
|
|
||||||
{
|
|
||||||
if( index >= args.length ) throw badArgument( index, "string", "nil" );
|
|
||||||
Object value = args[index];
|
|
||||||
if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
|
|
||||||
return (String) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a table.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @return The argument's value.
|
|
||||||
* @throws LuaException If the value is not a table.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public static Map<?, ?> getTable( @Nonnull Object[] args, int index ) throws LuaException
|
|
||||||
{
|
|
||||||
if( index >= args.length ) throw badArgument( index, "table", "nil" );
|
|
||||||
Object value = args[index];
|
|
||||||
if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
|
|
||||||
return (Map<?, ?>) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a double.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @param def The default value, if this argument is not given.
|
|
||||||
* @return The argument's value, or {@code def} if none was provided.
|
|
||||||
* @throws LuaException If the value is not a number.
|
|
||||||
*/
|
|
||||||
public static double optDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
|
|
||||||
{
|
|
||||||
Object value = index < args.length ? args[index] : null;
|
|
||||||
if( value == null ) return def;
|
|
||||||
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
|
||||||
return ((Number) value).doubleValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as an int.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @param def The default value, if this argument is not given.
|
|
||||||
* @return The argument's value, or {@code def} if none was provided.
|
|
||||||
* @throws LuaException If the value is not a number.
|
|
||||||
*/
|
|
||||||
public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
|
|
||||||
{
|
|
||||||
return (int) optLong( args, index, def );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a long.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @param def The default value, if this argument is not given.
|
|
||||||
* @return The argument's value, or {@code def} if none was provided.
|
|
||||||
* @throws LuaException If the value is not a number.
|
|
||||||
*/
|
|
||||||
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
|
|
||||||
{
|
|
||||||
Object value = index < args.length ? args[index] : null;
|
|
||||||
if( value == null ) return def;
|
|
||||||
if( !(value instanceof Number) ) throw badArgumentOf( index, "number", value );
|
|
||||||
return checkFinite( index, (Number) value ).longValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a finite number (not infinite or NaN).
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @param def The default value, if this argument is not given.
|
|
||||||
* @return The argument's value, or {@code def} if none was provided.
|
|
||||||
* @throws LuaException If the value is not finite.
|
|
||||||
*/
|
|
||||||
public static double optFiniteDouble( @Nonnull Object[] args, int index, double def ) throws LuaException
|
|
||||||
{
|
|
||||||
return checkFinite( index, optDouble( args, index, def ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a boolean.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @param def The default value, if this argument is not given.
|
|
||||||
* @return The argument's value, or {@code def} if none was provided.
|
|
||||||
* @throws LuaException If the value is not a boolean.
|
|
||||||
*/
|
|
||||||
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
|
|
||||||
{
|
|
||||||
Object value = index < args.length ? args[index] : null;
|
|
||||||
if( value == null ) return def;
|
|
||||||
if( !(value instanceof Boolean) ) throw badArgumentOf( index, "boolean", value );
|
|
||||||
return (Boolean) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a string.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @param def The default value, if this argument is not given.
|
|
||||||
* @return The argument's value, or {@code def} if none was provided.
|
|
||||||
* @throws LuaException If the value is not a string.
|
|
||||||
*/
|
|
||||||
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
|
|
||||||
{
|
|
||||||
Object value = index < args.length ? args[index] : null;
|
|
||||||
if( value == null ) return def;
|
|
||||||
if( !(value instanceof String) ) throw badArgumentOf( index, "string", value );
|
|
||||||
return (String) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an argument as a table.
|
|
||||||
*
|
|
||||||
* @param args The arguments to extract from.
|
|
||||||
* @param index The index into the argument array to read from.
|
|
||||||
* @param def The default value, if this argument is not given.
|
|
||||||
* @return The argument's value, or {@code def} if none was provided.
|
|
||||||
* @throws LuaException If the value is not a table.
|
|
||||||
*/
|
|
||||||
public static Map<?, ?> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
|
|
||||||
{
|
|
||||||
Object value = index < args.length ? args[index] : null;
|
|
||||||
if( value == null ) return def;
|
|
||||||
if( !(value instanceof Map) ) throw badArgumentOf( index, "table", value );
|
|
||||||
return (Map<?, ?>) value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Number checkFinite( int index, Number value ) throws LuaException
|
|
||||||
{
|
|
||||||
checkFinite( index, value.doubleValue() );
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double checkFinite( int index, double value ) throws LuaException
|
|
||||||
{
|
|
||||||
if( !Double.isFinite( value ) ) throw badArgument( index, "number", getNumericType( value ) );
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a more detailed representation of this number's type. If this is finite, it will just return "number",
|
|
||||||
* otherwise it returns whether it is infinite or NaN.
|
|
||||||
*
|
|
||||||
* @param value The value to extract the type for.
|
|
||||||
* @return This value's numeric type.
|
|
||||||
*/
|
|
||||||
@Nonnull
|
|
||||||
public static String getNumericType( double value )
|
|
||||||
{
|
|
||||||
if( Double.isNaN( value ) ) return "nan";
|
|
||||||
if( value == Double.POSITIVE_INFINITY ) return "inf";
|
|
||||||
if( value == Double.NEGATIVE_INFINITY ) return "-inf";
|
|
||||||
return "number";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,7 +26,7 @@ public interface IComputerSystem extends IComputerAccess
|
|||||||
IFileSystem getFileSystem();
|
IFileSystem getFileSystem();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the label for this computer.
|
* Get the label for this computer
|
||||||
*
|
*
|
||||||
* @return This computer's label, or {@code null} if it is not set.
|
* @return This computer's label, or {@code null} if it is not set.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Lua", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.lua;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Media", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.media;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.network;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Network|Wired", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.network.wired;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
package dan200.computercraft.api.peripheral;
|
package dan200.computercraft.api.peripheral;
|
||||||
|
|
||||||
import dan200.computercraft.api.lua.ArgumentHelper;
|
|
||||||
import dan200.computercraft.api.lua.ILuaContext;
|
import dan200.computercraft.api.lua.ILuaContext;
|
||||||
import dan200.computercraft.api.lua.LuaException;
|
import dan200.computercraft.api.lua.LuaException;
|
||||||
|
|
||||||
@@ -59,11 +58,9 @@ public interface IPeripheral
|
|||||||
* Lua values of type "table" will be represented by Object type Map.<br>
|
* Lua values of type "table" will be represented by Object type Map.<br>
|
||||||
* Lua values of any other type will be represented by a null object.<br>
|
* Lua values of any other type will be represented by a null object.<br>
|
||||||
* This array will be empty if no arguments are passed.
|
* This array will be empty if no arguments are passed.
|
||||||
*
|
|
||||||
* It is recommended you use {@link ArgumentHelper} in order to validate and process arguments.
|
|
||||||
* @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats,
|
* @return An array of objects, representing values you wish to return to the lua program. Integers, Doubles, Floats,
|
||||||
* Strings, Booleans, Maps, ILuaObject and null be converted to their corresponding lua type. All other types will
|
* Strings, Booleans, Maps and ILuaObject and null be converted to their corresponding lua type. All other types
|
||||||
* be converted to nil.
|
* will be converted to nil.
|
||||||
*
|
*
|
||||||
* You may return null to indicate no values should be returned.
|
* You may return null to indicate no values should be returned.
|
||||||
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the
|
* @throws LuaException If you throw any exception from this function, a lua error will be raised with the
|
||||||
@@ -73,7 +70,6 @@ public interface IPeripheral
|
|||||||
* InterruptedException will be thrown. This exception must not be caught or
|
* InterruptedException will be thrown. This exception must not be caught or
|
||||||
* intercepted, or the computer will leak memory and end up in a broken state.
|
* intercepted, or the computer will leak memory and end up in a broken state.
|
||||||
* @see #getMethodNames
|
* @see #getMethodNames
|
||||||
* @see ArgumentHelper
|
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException;
|
Object[] callMethod( @Nonnull IComputerAccess computer, @Nonnull ILuaContext context, int method, @Nonnull Object[] arguments ) throws LuaException, InterruptedException;
|
||||||
|
|||||||
@@ -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,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Peripheral", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.peripheral;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -1,42 +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.permissions;
|
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface is used to restrict where turtles can move or build.
|
|
||||||
*
|
|
||||||
* Turtles will call these methods before attempting to perform an action, allowing them to be cancelled.
|
|
||||||
*
|
|
||||||
* @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider)
|
|
||||||
*/
|
|
||||||
public interface ITurtlePermissionProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Determine whether a block can be entered by a turtle.
|
|
||||||
*
|
|
||||||
* @param world The world the block exists in
|
|
||||||
* @param pos The location of the block.
|
|
||||||
* @return Whether the turtle can move into this block.
|
|
||||||
*/
|
|
||||||
boolean isBlockEnterable( @Nonnull World world, @Nonnull BlockPos pos );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine whether a block can be modified by a turtle.
|
|
||||||
*
|
|
||||||
* This includes breaking and placing blocks.
|
|
||||||
*
|
|
||||||
* @param world The world the block exists in
|
|
||||||
* @param pos The location of the block.
|
|
||||||
* @return Whether the turtle can modify this block.
|
|
||||||
*/
|
|
||||||
boolean isBlockEditable( @Nonnull World world, @Nonnull BlockPos pos );
|
|
||||||
}
|
|
||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Permissions", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.permissions;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -1,12 +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.ResourceLocation;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.SystemUtil;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
@@ -17,25 +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, ItemStack stack )
|
protected AbstractPocketUpgrade( Identifier identifier, String adjective, ItemProvider item )
|
||||||
{
|
{
|
||||||
this( id, "upgrade." + id + ".adjective", stack );
|
this( identifier, adjective, new ItemStack( item ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected AbstractPocketUpgrade( Identifier id, ItemProvider 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,37 +8,27 @@ 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;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper class for pocket computers.
|
* Wrapper class for pocket computers
|
||||||
*/
|
*/
|
||||||
public interface IPocketAccess
|
public interface IPocketAccess
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Gets the entity holding this item.
|
* Gets the entity holding this item.
|
||||||
*
|
*
|
||||||
* @return The holding entity. This may be {@code null}.
|
|
||||||
* @deprecated Use {@link #getValidEntity()} where possible.
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
@Deprecated
|
|
||||||
Entity getEntity();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the entity holding this item with additional safety checks.
|
|
||||||
*
|
|
||||||
* This must be called on the server thread.
|
* This must be called on the server thread.
|
||||||
*
|
*
|
||||||
* @return The holding entity, or {@code null} if none exists.
|
* @return The holding entity, or {@code null} if none exists.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Entity getValidEntity();
|
Entity getEntity();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the colour of this pocket computer as a RGB number.
|
* Get the colour of this pocket computer as a RGB number.
|
||||||
@@ -85,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.
|
||||||
@@ -105,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 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Redstone", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.redstone;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -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;
|
||||||
@@ -54,8 +53,7 @@ public interface ITurtleAccess
|
|||||||
* @param world The new world to move it to
|
* @param world The new world to move it to
|
||||||
* @param pos The new position to move it to.
|
* @param pos The new position to move it to.
|
||||||
* @return Whether the movement was successful. It may fail if the block was not loaded or the block placement
|
* @return Whether the movement was successful. It may fail if the block was not loaded or the block placement
|
||||||
* was cancelled. Note this will not check
|
* was cancelled.
|
||||||
* {@link dan200.computercraft.api.permissions.ITurtlePermissionProvider#isBlockEnterable(World, BlockPos)}.
|
|
||||||
* @throws UnsupportedOperationException When attempting to teleport on the client side.
|
* @throws UnsupportedOperationException When attempting to teleport on the client side.
|
||||||
*/
|
*/
|
||||||
boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos );
|
boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos );
|
||||||
@@ -84,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
|
||||||
@@ -96,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.
|
||||||
@@ -145,28 +143,12 @@ public interface ITurtleAccess
|
|||||||
GameProfile getOwningPlayer();
|
GameProfile getOwningPlayer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the inventory of this turtle.
|
* Get the inventory of this turtle
|
||||||
*
|
|
||||||
* Note: this inventory should only be accessed and modified on the server thread.
|
|
||||||
*
|
*
|
||||||
* @return This turtle's inventory
|
* @return This turtle's inventory
|
||||||
* @see #getItemHandler()
|
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
IInventory getInventory();
|
Inventory getInventory();
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the inventory of this turtle as an {@link IItemHandlerModifiable}.
|
|
||||||
*
|
|
||||||
* Note: this inventory should only be accessed and modified on the server thread.
|
|
||||||
*
|
|
||||||
* @return This turtle's inventory
|
|
||||||
* @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.
|
||||||
@@ -295,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.block.model.IBakedModel;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.minecraft.client.renderer.block.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.event.entity.player.AttackEntityEvent;
|
|
||||||
import net.minecraftforge.event.world.BlockEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@@ -42,18 +40,7 @@ public interface ITurtleUpgrade
|
|||||||
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
ResourceLocation getUpgradeID();
|
Identifier getUpgradeID();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets a numerical identifier representing this type of turtle upgrade,
|
|
||||||
* for backwards compatibility with pre-1.76 worlds. If your upgrade was
|
|
||||||
* not released for older ComputerCraft versions, you can return -1 here.
|
|
||||||
* The turtle will fail registration if an already used positive ID is specified.
|
|
||||||
*
|
|
||||||
* @return The legacy ID, or -1 if is needed.
|
|
||||||
* @see ComputerCraftAPI#registerTurtleUpgrade(ITurtleUpgrade)
|
|
||||||
*/
|
|
||||||
int getLegacyUpgradeID();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an unlocalised string to describe this type of turtle in turtle item names.
|
* Return an unlocalised string to describe this type of turtle in turtle item names.
|
||||||
@@ -109,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
|
* Conforming implementations should fire {@code BlockEvent.BreakEvent} and {@link TurtleBlockEvent.Dig}for digging,
|
||||||
* 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.
|
||||||
@@ -124,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();
|
||||||
}
|
}
|
||||||
@@ -132,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.block.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!
|
||||||
@@ -142,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
|
||||||
@SideOnly( Side.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
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ package dan200.computercraft.api.turtle;
|
|||||||
public enum TurtleSide
|
public enum TurtleSide
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle).
|
* The turtle's left side (where the pickaxe usually is on a Wireless Mining Turtle)
|
||||||
*/
|
*/
|
||||||
Left,
|
Left,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The turtle's right side (where the modem usually is on a Wireless Mining Turtle).
|
* The turtle's right side (where the modem usually is on a Wireless Mining Turtle)
|
||||||
*/
|
*/
|
||||||
Right,
|
Right,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,24 +6,24 @@
|
|||||||
|
|
||||||
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
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}.
|
* The turtle called {@code turtle.dig()}, {@code turtle.digUp()} or {@code turtle.digDown()}
|
||||||
*/
|
*/
|
||||||
Dig,
|
Dig,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}.
|
* The turtle called {@code turtle.attack()}, {@code turtle.attackUp()} or {@code turtle.attackDown()}
|
||||||
*/
|
*/
|
||||||
Attack,
|
Attack,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,7 +71,7 @@ public enum TurtleAction
|
|||||||
EQUIP,
|
EQUIP,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inspect a block in world.
|
* Inspect a block in world
|
||||||
*
|
*
|
||||||
* @see TurtleBlockEvent.Inspect
|
* @see TurtleBlockEvent.Inspect
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,7 +8,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.fml.common.eventhandler.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,13 +105,13 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the upgrade doing the digging.
|
* Get the upgrade doing the digging
|
||||||
*
|
*
|
||||||
* @return The upgrade doing the digging.
|
* @return The upgrade doing the digging.
|
||||||
*/
|
*/
|
||||||
@@ -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.fml.common.eventhandler.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,21 +21,21 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the inventory being interacted with.
|
* Get the inventory being interacted with
|
||||||
*
|
*
|
||||||
* @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
|
* @return The inventory being interacted with, {@code null} if the item will be dropped to/sucked from the world.
|
||||||
*/
|
*/
|
||||||
@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;
|
||||||
|
|||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle|Event", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.turtle.event;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -1,10 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@API( owner = "ComputerCraft", provides = "ComputerCraft|API|Turtle", apiVersion = "${version}" )
|
|
||||||
package dan200.computercraft.api.turtle;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.common.API;
|
|
||||||
@@ -7,179 +7,140 @@
|
|||||||
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.media.items.ItemDiskLegacy;
|
import dan200.computercraft.shared.media.items.ItemDisk;
|
||||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
|
|
||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.fabricmc.fabric.api.client.render.ColorProviderRegistry;
|
||||||
import net.minecraft.client.renderer.ItemMeshDefinition;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.block.model.ModelBakery;
|
import net.minecraft.client.render.model.ModelLoader;
|
||||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
import net.minecraft.client.render.model.ModelRotation;
|
||||||
import net.minecraft.client.renderer.texture.TextureMap;
|
import net.minecraft.client.render.model.UnbakedModel;
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
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.IModel;
|
|
||||||
import net.minecraftforge.client.model.ModelLoader;
|
|
||||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import java.util.HashSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers textures and models for items.
|
* Registers textures and models for items.
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
|
||||||
public final class ClientRegistry
|
public final class ClientRegistry
|
||||||
{
|
{
|
||||||
private static final String[] EXTRA_MODELS = new String[] {
|
private static final String[] EXTRA_MODELS = new String[] {
|
||||||
"turtle_modem_off_left",
|
"turtle_modem_normal_off_left",
|
||||||
"turtle_modem_on_left",
|
"turtle_modem_normal_on_left",
|
||||||
"turtle_modem_off_right",
|
"turtle_modem_normal_off_right",
|
||||||
"turtle_modem_on_right",
|
"turtle_modem_normal_on_right",
|
||||||
|
|
||||||
|
"turtle_modem_advanced_off_left",
|
||||||
|
"turtle_modem_advanced_on_left",
|
||||||
|
"turtle_modem_advanced_off_right",
|
||||||
|
"turtle_modem_advanced_on_right",
|
||||||
"turtle_crafting_table_left",
|
"turtle_crafting_table_left",
|
||||||
"turtle_crafting_table_right",
|
"turtle_crafting_table_right",
|
||||||
"advanced_turtle_modem_off_left",
|
|
||||||
"advanced_turtle_modem_on_left",
|
|
||||||
"advanced_turtle_modem_off_right",
|
|
||||||
"advanced_turtle_modem_on_right",
|
|
||||||
"turtle_speaker_upgrade_left",
|
"turtle_speaker_upgrade_left",
|
||||||
"turtle_speaker_upgrade_right",
|
"turtle_speaker_upgrade_right",
|
||||||
|
|
||||||
"turtle_white",
|
"turtle_colour",
|
||||||
"turtle_elf_overlay",
|
"turtle_elf_overlay",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final String[] EXTRA_TEXTURES = new String[] {
|
||||||
|
// TODO: Gather these automatically from the model. I'm unable to get this working with Forge's current
|
||||||
|
// model loading code.
|
||||||
|
"block/turtle_colour",
|
||||||
|
"block/turtle_elf_overlay",
|
||||||
|
"block/turtle_crafty_face",
|
||||||
|
"block/turtle_speaker_face",
|
||||||
|
};
|
||||||
|
|
||||||
private ClientRegistry() {}
|
private ClientRegistry() {}
|
||||||
|
|
||||||
@SubscribeEvent
|
/*
|
||||||
|
TODO: @SubscribeEvent
|
||||||
public static void registerModels( ModelRegistryEvent event )
|
public static void registerModels( ModelRegistryEvent event )
|
||||||
{
|
{
|
||||||
ModelLoaderRegistry.registerLoader( TurtleModelLoader.INSTANCE );
|
ModelLoaderRegistry.registerLoader( TurtleModelLoader.INSTANCE );
|
||||||
|
|
||||||
// Register item models
|
|
||||||
registerUniversalItemModel( ComputerCraft.Items.computer, "computer" );
|
|
||||||
registerItemModel( ComputerCraft.Items.commandComputer, 0, "command_computer" );
|
|
||||||
|
|
||||||
registerItemModel( ComputerCraft.Items.pocketComputer, 0, "pocket_computer" );
|
|
||||||
registerItemModel( ComputerCraft.Items.pocketComputer, 1, "advanced_pocket_computer" );
|
|
||||||
|
|
||||||
registerItemModel( ComputerCraft.Items.peripheral, 0, "peripheral" );
|
|
||||||
registerItemModel( ComputerCraft.Items.peripheral, 1, "wireless_modem" );
|
|
||||||
registerItemModel( ComputerCraft.Items.peripheral, 2, "monitor" );
|
|
||||||
registerItemModel( ComputerCraft.Items.peripheral, 3, "printer" );
|
|
||||||
registerItemModel( ComputerCraft.Items.peripheral, 4, "advanced_monitor" );
|
|
||||||
registerItemModel( ComputerCraft.Items.cable, 0, "cable" );
|
|
||||||
registerItemModel( ComputerCraft.Items.cable, 1, "wired_modem" );
|
|
||||||
registerItemModel( ComputerCraft.Items.advancedModem, 0, "advanced_modem" );
|
|
||||||
registerItemModel( ComputerCraft.Items.peripheral, 5, "speaker" );
|
|
||||||
registerItemModel( ComputerCraft.Items.wiredModemFull, 0, "wired_modem_full" );
|
|
||||||
|
|
||||||
registerUniversalItemModel( ComputerCraft.Items.disk, "disk" );
|
|
||||||
registerItemModel( ComputerCraft.Items.diskExpanded, 0, "disk_expanded" );
|
|
||||||
registerItemModel( ComputerCraft.Items.treasureDisk, 0, "treasure_disk" );
|
|
||||||
|
|
||||||
registerItemModel( ComputerCraft.Items.printout, 0, "printout" );
|
|
||||||
registerItemModel( ComputerCraft.Items.printout, 1, "pages" );
|
|
||||||
registerItemModel( ComputerCraft.Items.printout, 2, "book" );
|
|
||||||
|
|
||||||
registerUniversalItemModel( ComputerCraft.Items.turtle, "turtle" );
|
|
||||||
registerUniversalItemModel( ComputerCraft.Items.turtleExpanded, "turtle" );
|
|
||||||
registerUniversalItemModel( ComputerCraft.Items.turtleAdvanced, "turtle_advanced" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
TODO: @SubscribeEvent
|
||||||
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
||||||
{
|
{
|
||||||
// Load all textures for the extra models
|
ResourceManager manager = MinecraftClient.getInstance().getResourceManager();
|
||||||
TextureMap map = event.getMap();
|
for( String extra : EXTRA_TEXTURES )
|
||||||
for( String upgrade : EXTRA_MODELS )
|
|
||||||
{
|
{
|
||||||
IModel model = ModelLoaderRegistry.getModelOrMissing( new ResourceLocation( "computercraft", "block/" + upgrade ) );
|
event.getMap().registerSprite( manager, new Identifier( ComputerCraft.MOD_ID, extra ) );
|
||||||
for( ResourceLocation texture : model.getTextures() ) map.registerSprite( texture );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
TODO: @SubscribeEvent
|
||||||
public static void onModelBakeEvent( ModelBakeEvent event )
|
public static void onModelBakeEvent( ModelBakeEvent event )
|
||||||
{
|
{
|
||||||
// Load all extra models
|
// Load all extra models
|
||||||
for( String model : EXTRA_MODELS ) loadBlockModel( event, model );
|
ModelLoader loader = event.getModelLoader();
|
||||||
}
|
Map<ModelIdentifier, BakedModel> registry = event.getModelRegistry();
|
||||||
|
|
||||||
@SubscribeEvent
|
for( String model : EXTRA_MODELS )
|
||||||
public static void onItemColours( ColorHandlerEvent.Item event )
|
{
|
||||||
{
|
BakedModel bakedModel = bake( loader, loader.getOrLoadModel( new Identifier( ComputerCraft.MOD_ID, "item/" + model ) ) );
|
||||||
event.getItemColors().registerItemColorHandler(
|
|
||||||
( stack, layer ) -> layer == 1 ? ((ItemDiskLegacy) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
if( bakedModel != null )
|
||||||
ComputerCraft.Items.disk, ComputerCraft.Items.diskExpanded
|
{
|
||||||
|
registry.put(
|
||||||
|
new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, model ), "inventory" ),
|
||||||
|
bakedModel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// And load the custom turtle models in too.
|
||||||
|
registry.put(
|
||||||
|
new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, "turtle_normal" ), "inventory" ),
|
||||||
|
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new Identifier( ComputerCraft.MOD_ID, "item/turtle_normal" ) ) )
|
||||||
);
|
);
|
||||||
|
|
||||||
event.getItemColors().registerItemColorHandler( ( stack, layer ) -> {
|
registry.put(
|
||||||
|
new ModelIdentifier( new Identifier( ComputerCraft.MOD_ID, "turtle_advanced" ), "inventory" ),
|
||||||
|
bake( loader, TurtleModelLoader.INSTANCE.loadModel( new Identifier( ComputerCraft.MOD_ID, "item/turtle_advanced" ) ) )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void onItemColours()
|
||||||
|
{
|
||||||
|
ColorProviderRegistry.ITEM.register(
|
||||||
|
( stack, layer ) -> layer == 1 ? ((ItemDisk) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
||||||
|
ComputerCraft.Items.disk
|
||||||
|
);
|
||||||
|
|
||||||
|
ColorProviderRegistry.ITEM.register( ( stack, layer ) -> {
|
||||||
switch( layer )
|
switch( layer )
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
return 0xFFFFFF;
|
return 0xFFFFFF;
|
||||||
case 1: // Frame colour
|
case 1: // Frame colour
|
||||||
return ComputerCraft.Items.pocketComputer.getColour( stack );
|
return IColouredItem.getColourBasic( stack );
|
||||||
case 2: // Light colour
|
case 2: // Light colour
|
||||||
{
|
{
|
||||||
int light = ItemPocketComputer.getLightState( stack );
|
int light = ItemPocketComputer.getLightState( stack );
|
||||||
return light == -1 ? Colour.Black.getHex() : light;
|
return light == -1 ? Colour.Black.getHex() : light;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, ComputerCraft.Items.pocketComputer );
|
}, ComputerCraft.Items.pocketComputerNormal, ComputerCraft.Items.pocketComputerAdvanced );
|
||||||
|
|
||||||
// Setup turtle colours
|
// Setup turtle colours
|
||||||
event.getItemColors().registerItemColorHandler(
|
ColorProviderRegistry.ITEM.register(
|
||||||
( stack, tintIndex ) -> tintIndex == 0 ? ((ItemTurtleBase) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
( stack, tintIndex ) -> tintIndex == 0 ? ((IColouredItem) stack.getItem()).getColour( stack ) : 0xFFFFFF,
|
||||||
ComputerCraft.Blocks.turtle, ComputerCraft.Blocks.turtleExpanded, ComputerCraft.Blocks.turtleAdvanced
|
ComputerCraft.Blocks.turtleNormal, ComputerCraft.Blocks.turtleAdvanced
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerItemModel( Item item, int damage, String name )
|
private static BakedModel bake( ModelLoader loader, UnbakedModel model )
|
||||||
{
|
{
|
||||||
ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
model.getTextureDependencies( loader::getOrLoadModel, new HashSet<>() );
|
||||||
final ModelResourceLocation res = new ModelResourceLocation( location, "inventory" );
|
SpriteAtlasTexture sprite = MinecraftClient.getInstance().getSpriteAtlas();
|
||||||
ModelBakery.registerItemVariants( item, location );
|
return model.bake( loader, sprite::getSprite, ModelRotation.X0_Y0 );
|
||||||
ModelLoader.setCustomModelResourceLocation( item, damage, res );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void registerUniversalItemModel( Item item, String mainModel )
|
|
||||||
{
|
|
||||||
ResourceLocation mainLocation = new ResourceLocation( ComputerCraft.MOD_ID, mainModel );
|
|
||||||
ModelBakery.registerItemVariants( item, mainLocation );
|
|
||||||
|
|
||||||
final ModelResourceLocation mainModelLocation = new ModelResourceLocation( mainLocation, "inventory" );
|
|
||||||
ModelLoader.setCustomMeshDefinition( item, new ItemMeshDefinition()
|
|
||||||
{
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public ModelResourceLocation getModelLocation( @Nonnull ItemStack stack )
|
|
||||||
{
|
|
||||||
return mainModelLocation;
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void loadBlockModel( ModelBakeEvent event, String name )
|
|
||||||
{
|
|
||||||
IModel model = ModelLoaderRegistry.getModelOrMissing( new ResourceLocation( ComputerCraft.MOD_ID, "block/" + name ) );
|
|
||||||
IBakedModel bakedModel = model.bake(
|
|
||||||
model.getDefaultState(), DefaultVertexFormats.ITEM,
|
|
||||||
location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite( location.toString() )
|
|
||||||
);
|
|
||||||
|
|
||||||
event.getModelRegistry().putObject( new ModelResourceLocation( ComputerCraft.MOD_ID + ":" + name, "inventory" ), bakedModel );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.getMinecraft().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.getCharWidth( ' ' );
|
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.getMinecraft();
|
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.getChatScale() );
|
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.getMinecraft().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.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.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.getMinecraft().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.glTexParameteri( 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,55 +6,50 @@
|
|||||||
|
|
||||||
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.shared.computer.blocks.TileComputer;
|
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ClientComputer;
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.computer.core.IComputer;
|
|
||||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.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 org.lwjgl.input.Keyboard;
|
import net.minecraft.util.Identifier;
|
||||||
import org.lwjgl.input.Mouse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
public class GuiComputer<T extends Container> extends ContainerScreen<T>
|
||||||
|
|
||||||
public class GuiComputer extends GuiContainer
|
|
||||||
{
|
{
|
||||||
public static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/corners.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;
|
||||||
private final int m_termWidth;
|
private final int m_termWidth;
|
||||||
private final int m_termHeight;
|
private final int m_termHeight;
|
||||||
private WidgetTerminal m_terminal;
|
|
||||||
|
|
||||||
public GuiComputer( Container container, ComputerFamily family, ClientComputer computer, int termWidth, int termHeight )
|
private WidgetTerminal terminal;
|
||||||
|
private WidgetWrapper terminalWrapper;
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
m_termHeight = termHeight;
|
m_termHeight = termHeight;
|
||||||
m_terminal = null;
|
terminal = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
public static GuiComputer<ContainerComputer> create( int id, TileComputer computer, PlayerInventory player )
|
||||||
public GuiComputer( Container container, ComputerFamily family, IComputer computer, int termWidth, int termHeight )
|
|
||||||
{
|
{
|
||||||
this( container, family, (ClientComputer) computer, termWidth, termHeight );
|
return new GuiComputer<>(
|
||||||
}
|
new ContainerComputer( id, computer ), player,
|
||||||
|
|
||||||
public GuiComputer( TileComputer computer )
|
|
||||||
{
|
|
||||||
this(
|
|
||||||
new ContainerComputer( computer ),
|
|
||||||
computer.getFamily(),
|
computer.getFamily(),
|
||||||
computer.createClientComputer(),
|
computer.createClientComputer(),
|
||||||
ComputerCraft.terminalWidth_computer,
|
ComputerCraft.terminalWidth_computer,
|
||||||
@@ -63,121 +58,100 @@ public class GuiComputer extends GuiContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initGui()
|
protected void init()
|
||||||
{
|
{
|
||||||
super.initGui();
|
minecraft.keyboard.enableRepeatEvents( true );
|
||||||
Keyboard.enableRepeatEvents( true );
|
|
||||||
|
|
||||||
m_terminal = new WidgetTerminal( 0, 0, m_termWidth, m_termHeight, () -> m_computer, 2, 2, 2, 2 );
|
int termPxWidth = m_termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
m_terminal.setAllowFocusLoss( false );
|
int termPxHeight = m_termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
xSize = m_terminal.getWidth() + 24;
|
|
||||||
ySize = m_terminal.getHeight() + 24;
|
containerWidth = termPxWidth + 4 + 24;
|
||||||
|
containerHeight = termPxHeight + 4 + 24;
|
||||||
|
|
||||||
|
super.init();
|
||||||
|
|
||||||
|
terminal = new WidgetTerminal( minecraft, () -> m_computer, m_termWidth, m_termHeight, 2, 2, 2, 2 );
|
||||||
|
terminalWrapper = new WidgetWrapper( terminal, 2 + 12 + left, 2 + 12 + top, termPxWidth, termPxHeight );
|
||||||
|
|
||||||
|
children.add( terminalWrapper );
|
||||||
|
setFocused( terminalWrapper );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed()
|
public void removed()
|
||||||
{
|
{
|
||||||
super.onGuiClosed();
|
super.removed();
|
||||||
Keyboard.enableRepeatEvents( false );
|
children.remove( terminal );
|
||||||
|
terminal = null;
|
||||||
|
minecraft.keyboard.enableRepeatEvents( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen()
|
public void tick()
|
||||||
{
|
{
|
||||||
super.updateScreen();
|
super.tick();
|
||||||
m_terminal.update();
|
terminal.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped( char c, int k ) throws IOException
|
public void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
|
||||||
if( k == 1 )
|
|
||||||
{
|
|
||||||
super.keyTyped( c, k );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_terminal.onKeyTyped( c, k ) ) keyHandled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void mouseClicked( int x, int y, int button )
|
|
||||||
{
|
|
||||||
int startX = (width - m_terminal.getWidth()) / 2;
|
|
||||||
int startY = (height - m_terminal.getHeight()) / 2;
|
|
||||||
m_terminal.mouseClicked( x - startX, y - startY, button );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseInput() throws IOException
|
|
||||||
{
|
|
||||||
super.handleMouseInput();
|
|
||||||
|
|
||||||
int x = Mouse.getEventX() * width / mc.displayWidth;
|
|
||||||
int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
|
|
||||||
int startX = (width - m_terminal.getWidth()) / 2;
|
|
||||||
int startY = (height - m_terminal.getHeight()) / 2;
|
|
||||||
m_terminal.handleMouseInput( x - startX, y - startY );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleKeyboardInput() throws IOException
|
|
||||||
{
|
|
||||||
super.handleKeyboardInput();
|
|
||||||
if( m_terminal.onKeyboardInput() ) keyHandled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void drawGuiContainerForegroundLayer( int par1, int par2 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void drawGuiContainerBackgroundLayer( float var1, int var2, int var3 )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
|
||||||
{
|
{
|
||||||
// Work out where to draw
|
// Work out where to draw
|
||||||
int startX = (width - m_terminal.getWidth()) / 2;
|
int startX = terminalWrapper.getX() - 2;
|
||||||
int startY = (height - m_terminal.getHeight()) / 2;
|
int startY = terminalWrapper.getY() - 2;
|
||||||
int endX = startX + m_terminal.getWidth();
|
int endX = startX + terminalWrapper.getWidth() + 4;
|
||||||
int endY = startY + m_terminal.getHeight();
|
int endY = startY + terminalWrapper.getHeight() + 4;
|
||||||
|
|
||||||
// Draw background
|
|
||||||
drawDefaultBackground();
|
|
||||||
|
|
||||||
// Draw terminal
|
// Draw terminal
|
||||||
m_terminal.draw( mc, startX, startY, mouseX, mouseY );
|
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
|
||||||
|
|
||||||
// Draw a border around the terminal
|
// Draw a border around the terminal
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
switch( m_family )
|
switch( m_family )
|
||||||
{
|
{
|
||||||
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
|
||||||
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
|
{
|
||||||
|
renderBackground( 0 );
|
||||||
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
|
||||||
|
{
|
||||||
|
return (getFocused() != null && getFocused().mouseDragged( x, y, button, deltaX, deltaY ))
|
||||||
|
|| super.mouseDragged( x, y, button, deltaX, deltaY );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseReleased( double x, double y, int button )
|
||||||
|
{
|
||||||
|
return (getFocused() != null && getFocused().mouseReleased( x, y, button ))
|
||||||
|
|| super.mouseReleased( x, y, button );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dan200.computercraft.client.gui;
|
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
|
||||||
import dan200.computercraft.shared.Config;
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
|
||||||
import net.minecraftforge.fml.client.IModGuiFactory;
|
|
||||||
import net.minecraftforge.fml.client.config.GuiConfig;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class GuiConfigCC extends GuiConfig
|
|
||||||
{
|
|
||||||
public GuiConfigCC( GuiScreen parentScreen )
|
|
||||||
{
|
|
||||||
super( parentScreen, Config.getConfigElements(), ComputerCraft.MOD_ID, false, false, "CC: Tweaked" );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Factory implements IModGuiFactory
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void initialize( Minecraft minecraft )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasConfigGui()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GuiScreen createConfigGui( GuiScreen parentScreen )
|
|
||||||
{
|
|
||||||
return new GuiConfigCC( parentScreen );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<RuntimeOptionCategoryElement> runtimeGuiCategories()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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/diskdrive.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().getUnformattedText();
|
String title = getTitle().getFormattedText();
|
||||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 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.color( 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 drawScreen( int mouseX, int mouseY, float partialTicks )
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
renderBackground();
|
||||||
super.drawScreen( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,29 @@
|
|||||||
package dan200.computercraft.client.gui;
|
package dan200.computercraft.client.gui;
|
||||||
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import dan200.computercraft.shared.media.inventory.ContainerHeldItem;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
|
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.ItemStack;
|
||||||
|
|
||||||
public class GuiPocketComputer extends GuiComputer
|
public class GuiPocketComputer extends GuiComputer<ContainerPocketComputer>
|
||||||
{
|
{
|
||||||
public GuiPocketComputer( ContainerHeldItem container )
|
public GuiPocketComputer( ContainerPocketComputer container, PlayerInventory player )
|
||||||
{
|
{
|
||||||
super(
|
super(
|
||||||
container,
|
container, player,
|
||||||
ComputerCraft.Items.pocketComputer.getFamily( container.getStack() ),
|
getFamily( container.getStack() ),
|
||||||
ItemPocketComputer.createClientComputer( container.getStack() ),
|
ItemPocketComputer.createClientComputer( container.getStack() ),
|
||||||
ComputerCraft.terminalWidth_pocketComputer,
|
ComputerCraft.terminalWidth_pocketComputer,
|
||||||
ComputerCraft.terminalHeight_pocketComputer
|
ComputerCraft.terminalHeight_pocketComputer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ComputerFamily getFamily( ItemStack stack )
|
||||||
|
{
|
||||||
|
Item item = stack.getItem();
|
||||||
|
return item instanceof ItemPocketComputer ? ((ItemPocketComputer) item).getFamily() : ComputerFamily.Normal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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().getUnformattedText();
|
String title = getTitle().getFormattedText();
|
||||||
fontRenderer.drawString( title, (xSize - fontRenderer.getStringWidth( title )) / 2, 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.color( 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 drawScreen( int mouseX, int mouseY, float partialTicks )
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
renderBackground();
|
||||||
super.drawScreen( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +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.media.inventory.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.input.Mouse;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||||
|
|
||||||
public class GuiPrintout extends 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;
|
||||||
@@ -25,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];
|
||||||
@@ -41,63 +40,70 @@ public class GuiPrintout extends GuiContainer
|
|||||||
|
|
||||||
m_page = 0;
|
m_page = 0;
|
||||||
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
||||||
m_book = ItemPrintout.getType( container.getStack() ) == ItemPrintout.Type.Book;
|
m_book = ((ItemPrintout) container.getStack().getItem()).getType() == ItemPrintout.Type.BOOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void keyTyped( char c, int k ) throws IOException
|
public boolean keyPressed( int key, int scancode, int modifiers )
|
||||||
{
|
{
|
||||||
super.keyTyped( c, k );
|
if( super.keyPressed( key, scancode, modifiers ) ) return true;
|
||||||
|
|
||||||
if( k == 205 )
|
if( key == GLFW.GLFW_KEY_RIGHT )
|
||||||
{
|
{
|
||||||
// Right
|
|
||||||
if( m_page < m_pages - 1 ) m_page++;
|
if( m_page < m_pages - 1 ) m_page++;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if( k == 203 )
|
|
||||||
|
if( key == GLFW.GLFW_KEY_LEFT )
|
||||||
{
|
{
|
||||||
// Left
|
|
||||||
if( m_page > 0 ) m_page--;
|
if( m_page > 0 ) m_page--;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMouseInput() throws IOException
|
public boolean mouseScrolled( double x, double y, double delta )
|
||||||
{
|
{
|
||||||
super.handleMouseInput();
|
if( super.mouseScrolled( x, y, delta ) ) return true;
|
||||||
|
if( delta < 0 )
|
||||||
int mouseWheelChange = Mouse.getEventDWheel();
|
|
||||||
if( mouseWheelChange < 0 )
|
|
||||||
{
|
{
|
||||||
// Scroll up goes to the next page
|
// Scroll up goes to the next page
|
||||||
if( m_page < m_pages - 1 ) m_page++;
|
if( m_page < m_pages - 1 ) m_page++;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if( mouseWheelChange > 0 )
|
|
||||||
|
if( delta > 0 )
|
||||||
{
|
{
|
||||||
// Scroll down goes to the previous page
|
// Scroll down goes to the previous page
|
||||||
if( m_page > 0 ) m_page--;
|
if( m_page > 0 ) m_page--;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void drawGuiContainerBackgroundLayer( float partialTicks, int mouseX, int mouseY )
|
public void drawBackground( float partialTicks, int mouseX, int mouseY )
|
||||||
{
|
{
|
||||||
// Draw the printout
|
// Draw the printout
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
|
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 drawScreen( 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.drawScreen( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,144 +6,114 @@
|
|||||||
|
|
||||||
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.shared.computer.core.ClientComputer;
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.gui.ContainerScreen;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import org.lwjgl.input.Keyboard;
|
|
||||||
import org.lwjgl.input.Mouse;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
||||||
|
|
||||||
public class GuiTurtle extends GuiContainer
|
|
||||||
{
|
{
|
||||||
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle.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;
|
||||||
|
|
||||||
private final ComputerFamily m_family;
|
private final ComputerFamily m_family;
|
||||||
private final ClientComputer m_computer;
|
private final ClientComputer m_computer;
|
||||||
private WidgetTerminal m_terminalGui;
|
|
||||||
|
|
||||||
public GuiTurtle( TileTurtle turtle, ContainerTurtle container )
|
private WidgetTerminal terminal;
|
||||||
|
private WidgetWrapper terminalWrapper;
|
||||||
|
|
||||||
|
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
|
||||||
public void initGui()
|
protected void init()
|
||||||
{
|
{
|
||||||
super.initGui();
|
super.init();
|
||||||
Keyboard.enableRepeatEvents( true );
|
minecraft.keyboard.enableRepeatEvents( true );
|
||||||
m_terminalGui = new WidgetTerminal(
|
|
||||||
guiLeft + 8,
|
int termPxWidth = ComputerCraft.terminalWidth_turtle * FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
guiTop + 8,
|
int termPxHeight = ComputerCraft.terminalHeight_turtle * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
|
|
||||||
|
terminal = new WidgetTerminal(
|
||||||
|
minecraft, () -> m_computer,
|
||||||
ComputerCraft.terminalWidth_turtle,
|
ComputerCraft.terminalWidth_turtle,
|
||||||
ComputerCraft.terminalHeight_turtle,
|
ComputerCraft.terminalHeight_turtle,
|
||||||
() -> m_computer,
|
|
||||||
2, 2, 2, 2
|
2, 2, 2, 2
|
||||||
);
|
);
|
||||||
m_terminalGui.setAllowFocusLoss( false );
|
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + left, 2 + 8 + top, termPxWidth, termPxHeight );
|
||||||
|
|
||||||
|
children.add( terminalWrapper );
|
||||||
|
setFocused( terminalWrapper );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGuiClosed()
|
public void removed()
|
||||||
{
|
{
|
||||||
super.onGuiClosed();
|
super.removed();
|
||||||
Keyboard.enableRepeatEvents( false );
|
children.remove( terminal );
|
||||||
|
terminal = null;
|
||||||
|
minecraft.keyboard.enableRepeatEvents( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScreen()
|
public void tick()
|
||||||
{
|
{
|
||||||
super.updateScreen();
|
super.tick();
|
||||||
m_terminalGui.update();
|
terminal.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void drawSelectionSlot( boolean advanced )
|
||||||
protected void keyTyped( char c, int k ) throws IOException
|
|
||||||
{
|
|
||||||
if( k == 1 )
|
|
||||||
{
|
|
||||||
super.keyTyped( c, k );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_terminalGui.onKeyTyped( c, k ) ) keyHandled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void mouseClicked( int x, int y, int button ) throws IOException
|
|
||||||
{
|
|
||||||
super.mouseClicked( x, y, button );
|
|
||||||
m_terminalGui.mouseClicked( x, y, button );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseInput() throws IOException
|
|
||||||
{
|
|
||||||
super.handleMouseInput();
|
|
||||||
int x = Mouse.getEventX() * width / mc.displayWidth;
|
|
||||||
int y = height - Mouse.getEventY() * height / mc.displayHeight - 1;
|
|
||||||
m_terminalGui.handleMouseInput( x, y );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleKeyboardInput() throws IOException
|
|
||||||
{
|
|
||||||
super.handleKeyboardInput();
|
|
||||||
if( m_terminalGui.onKeyboardInput() ) keyHandled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void drawSelectionSlot( boolean advanced )
|
|
||||||
{
|
{
|
||||||
// Draw selection slot
|
// Draw selection slot
|
||||||
int slot = m_container.getSelectedSlot();
|
int slot = m_container.getSelectedSlot();
|
||||||
if( slot >= 0 )
|
if( slot >= 0 )
|
||||||
{
|
{
|
||||||
GlStateManager.color( 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;
|
||||||
m_terminalGui.draw( Minecraft.getMinecraft(), 0, 0, mouseX, mouseY );
|
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
|
||||||
|
|
||||||
// Draw border/inventory
|
// Draw border/inventory
|
||||||
GlStateManager.color( 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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawScreen( int mouseX, int mouseY, float partialTicks )
|
public void render( int mouseX, int mouseY, float partialTicks )
|
||||||
{
|
{
|
||||||
drawDefaultBackground();
|
renderBackground();
|
||||||
super.drawScreen( mouseX, mouseY, partialTicks );
|
super.render( mouseX, mouseY, partialTicks );
|
||||||
renderHoveredToolTip( mouseX, mouseY );
|
drawMouseoverTooltip( mouseX, mouseY );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
||||||
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
||||||
* Send enquiries to dratcliffe@gmail.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dan200.computercraft.client.gui.widgets;
|
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.Gui;
|
|
||||||
|
|
||||||
public abstract class Widget extends Gui
|
|
||||||
{
|
|
||||||
private int m_xPosition;
|
|
||||||
private int m_yPosition;
|
|
||||||
private int m_width;
|
|
||||||
private int m_height;
|
|
||||||
|
|
||||||
protected Widget( int x, int y, int width, int height )
|
|
||||||
{
|
|
||||||
m_xPosition = x;
|
|
||||||
m_yPosition = y;
|
|
||||||
m_width = width;
|
|
||||||
m_height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getXPosition()
|
|
||||||
{
|
|
||||||
return m_xPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getYPosition()
|
|
||||||
{
|
|
||||||
return m_yPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getWidth()
|
|
||||||
{
|
|
||||||
return m_width;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHeight()
|
|
||||||
{
|
|
||||||
return m_height;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleMouseInput( int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onKeyboardInput()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void handleKeyboardInput()
|
|
||||||
{
|
|
||||||
onKeyboardInput();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mouseClicked( int mouseX, int mouseY, int mouseButton )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean onKeyTyped( char c, int k )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public void keyTyped( char c, int k )
|
|
||||||
{
|
|
||||||
onKeyTyped( c, k );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,375 +6,367 @@
|
|||||||
|
|
||||||
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;
|
||||||
import dan200.computercraft.core.terminal.TextBuffer;
|
import dan200.computercraft.core.terminal.TextBuffer;
|
||||||
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
import dan200.computercraft.shared.computer.core.IComputer;
|
import dan200.computercraft.shared.computer.core.IComputer;
|
||||||
import dan200.computercraft.shared.computer.core.IComputerContainer;
|
|
||||||
import dan200.computercraft.shared.util.Colour;
|
import dan200.computercraft.shared.util.Colour;
|
||||||
import dan200.computercraft.shared.util.Palette;
|
import dan200.computercraft.shared.util.Palette;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.SharedConstants;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
import net.minecraft.client.gui.Element;
|
||||||
import net.minecraft.util.ChatAllowedCharacters;
|
import net.minecraft.client.render.BufferBuilder;
|
||||||
import org.lwjgl.input.Keyboard;
|
import net.minecraft.client.render.Tessellator;
|
||||||
import org.lwjgl.input.Mouse;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.BitSet;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.BACKGROUND;
|
||||||
|
|
||||||
public class WidgetTerminal extends Widget
|
public class WidgetTerminal implements Element
|
||||||
{
|
{
|
||||||
private static final float TERMINATE_TIME = 0.5f;
|
private static final float TERMINATE_TIME = 0.5f;
|
||||||
|
|
||||||
private final IComputerContainer m_computer;
|
private final MinecraftClient minecraft;
|
||||||
|
|
||||||
private float m_terminateTimer = 0.0f;
|
private final Supplier<ClientComputer> computer;
|
||||||
private float m_rebootTimer = 0.0f;
|
private final int termWidth;
|
||||||
private float m_shutdownTimer = 0.0f;
|
private final int termHeight;
|
||||||
|
|
||||||
private int m_lastClickButton = -1;
|
private boolean focused;
|
||||||
private int m_lastClickX = -1;
|
|
||||||
private int m_lastClickY = -1;
|
|
||||||
|
|
||||||
private boolean m_focus = false;
|
private float terminateTimer = -1;
|
||||||
private boolean m_allowFocusLoss = true;
|
private float rebootTimer = -1;
|
||||||
|
private float shutdownTimer = -1;
|
||||||
|
|
||||||
private int m_leftMargin;
|
private int lastMouseButton = -1;
|
||||||
private int m_rightMargin;
|
private int lastMouseX = -1;
|
||||||
private int m_topMargin;
|
private int lastMouseY = -1;
|
||||||
private int m_bottomMargin;
|
|
||||||
|
|
||||||
private final ArrayList<Integer> m_keysDown = new ArrayList<>();
|
private final int leftMargin;
|
||||||
|
private final int rightMargin;
|
||||||
|
private final int topMargin;
|
||||||
|
private final int bottomMargin;
|
||||||
|
|
||||||
public WidgetTerminal( int x, int y, int termWidth, int termHeight, IComputerContainer computer, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
private final BitSet keysDown = new BitSet( 256 );
|
||||||
|
|
||||||
|
public WidgetTerminal( MinecraftClient minecraft, Supplier<ClientComputer> computer, int termWidth, int termHeight, int leftMargin, int rightMargin, int topMargin, int bottomMargin )
|
||||||
{
|
{
|
||||||
super(
|
this.minecraft = minecraft;
|
||||||
x, y,
|
this.computer = computer;
|
||||||
leftMargin + rightMargin + termWidth * FixedWidthFontRenderer.FONT_WIDTH,
|
this.termWidth = termWidth;
|
||||||
topMargin + bottomMargin + termHeight * FixedWidthFontRenderer.FONT_HEIGHT
|
this.termHeight = termHeight;
|
||||||
);
|
this.leftMargin = leftMargin;
|
||||||
|
this.rightMargin = rightMargin;
|
||||||
m_computer = computer;
|
this.topMargin = topMargin;
|
||||||
|
this.bottomMargin = bottomMargin;
|
||||||
m_leftMargin = leftMargin;
|
|
||||||
m_rightMargin = rightMargin;
|
|
||||||
m_topMargin = topMargin;
|
|
||||||
m_bottomMargin = bottomMargin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAllowFocusLoss( boolean allowFocusLoss )
|
|
||||||
{
|
|
||||||
m_allowFocusLoss = allowFocusLoss;
|
|
||||||
m_focus = m_focus || !allowFocusLoss;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyTyped( char ch, int key )
|
public boolean charTyped( char ch, int modifiers )
|
||||||
{
|
{
|
||||||
if( m_focus )
|
if( ch >= 32 && ch <= 126 || ch >= 160 && ch <= 255 ) // printable chars in byte range
|
||||||
{
|
{
|
||||||
// Ctrl+V for paste
|
// Queue the "char" event
|
||||||
if( ch == 22 )
|
queueEvent( "char", Character.toString( ch ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyPressed( int key, int scancode, int modifiers )
|
||||||
|
{
|
||||||
|
if( key == GLFW.GLFW_KEY_ESCAPE ) return false;
|
||||||
|
if( (modifiers & GLFW.GLFW_MOD_CONTROL) != 0 )
|
||||||
|
{
|
||||||
|
switch( key )
|
||||||
{
|
{
|
||||||
String clipboard = GuiScreen.getClipboardString();
|
case GLFW.GLFW_KEY_T:
|
||||||
if( clipboard != null )
|
if( terminateTimer < 0 ) terminateTimer = 0;
|
||||||
{
|
return true;
|
||||||
// Clip to the first occurrence of \r or \n
|
case GLFW.GLFW_KEY_S:
|
||||||
int newLineIndex1 = clipboard.indexOf( '\r' );
|
if( shutdownTimer < 0 ) shutdownTimer = 0;
|
||||||
int newLineIndex2 = clipboard.indexOf( '\n' );
|
return true;
|
||||||
if( newLineIndex1 >= 0 && newLineIndex2 >= 0 )
|
case GLFW.GLFW_KEY_R:
|
||||||
{
|
if( rebootTimer < 0 ) rebootTimer = 0;
|
||||||
clipboard = clipboard.substring( 0, Math.min( newLineIndex1, newLineIndex2 ) );
|
return true;
|
||||||
}
|
|
||||||
else if( newLineIndex1 >= 0 )
|
|
||||||
{
|
|
||||||
clipboard = clipboard.substring( 0, newLineIndex1 );
|
|
||||||
}
|
|
||||||
else if( newLineIndex2 >= 0 )
|
|
||||||
{
|
|
||||||
clipboard = clipboard.substring( 0, newLineIndex2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter the string
|
case GLFW.GLFW_KEY_V:
|
||||||
clipboard = ChatAllowedCharacters.filterAllowedCharacters( clipboard );
|
// Ctrl+V for paste
|
||||||
|
String clipboard = minecraft.keyboard.getClipboard();
|
||||||
if( !clipboard.isEmpty() )
|
if( clipboard != null )
|
||||||
{
|
{
|
||||||
// Clip to 512 characters
|
// Clip to the first occurrence of \r or \n
|
||||||
if( clipboard.length() > 512 )
|
int newLineIndex1 = clipboard.indexOf( "\r" );
|
||||||
|
int newLineIndex2 = clipboard.indexOf( "\n" );
|
||||||
|
if( newLineIndex1 >= 0 && newLineIndex2 >= 0 )
|
||||||
{
|
{
|
||||||
clipboard = clipboard.substring( 0, 512 );
|
clipboard = clipboard.substring( 0, Math.min( newLineIndex1, newLineIndex2 ) );
|
||||||
|
}
|
||||||
|
else if( newLineIndex1 >= 0 )
|
||||||
|
{
|
||||||
|
clipboard = clipboard.substring( 0, newLineIndex1 );
|
||||||
|
}
|
||||||
|
else if( newLineIndex2 >= 0 )
|
||||||
|
{
|
||||||
|
clipboard = clipboard.substring( 0, newLineIndex2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Queue the "paste" event
|
// Filter the string
|
||||||
queueEvent( "paste", new Object[] { clipboard } );
|
clipboard = SharedConstants.stripInvalidChars( clipboard );
|
||||||
}
|
if( !clipboard.isEmpty() )
|
||||||
}
|
{
|
||||||
return true;
|
// Clip to 512 characters and queue the event
|
||||||
}
|
if( clipboard.length() > 512 ) clipboard = clipboard.substring( 0, 512 );
|
||||||
|
queueEvent( "paste", clipboard );
|
||||||
|
}
|
||||||
|
|
||||||
// Regular keys normally
|
return true;
|
||||||
if( m_terminateTimer <= 0.0f && m_rebootTimer <= 0.0f && m_shutdownTimer <= 0.0f )
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( key >= 0 && terminateTimer < 0 && rebootTimer < 0 && shutdownTimer < 0 )
|
||||||
|
{
|
||||||
|
// Queue the "key" event and add to the down set
|
||||||
|
boolean repeat = keysDown.get( key );
|
||||||
|
keysDown.set( key );
|
||||||
|
IComputer computer = this.computer.get();
|
||||||
|
if( computer != null ) computer.keyDown( key, repeat );
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyReleased( int key, int scancode, int modifiers )
|
||||||
|
{
|
||||||
|
// Queue the "key_up" event and remove from the down set
|
||||||
|
if( key >= 0 && keysDown.get( key ) )
|
||||||
|
{
|
||||||
|
keysDown.set( key, false );
|
||||||
|
IComputer computer = this.computer.get();
|
||||||
|
if( computer != null ) computer.keyUp( key );
|
||||||
|
}
|
||||||
|
|
||||||
|
switch( key )
|
||||||
|
{
|
||||||
|
case GLFW.GLFW_KEY_T:
|
||||||
|
terminateTimer = -1;
|
||||||
|
break;
|
||||||
|
case GLFW.GLFW_KEY_R:
|
||||||
|
rebootTimer = -1;
|
||||||
|
break;
|
||||||
|
case GLFW.GLFW_KEY_S:
|
||||||
|
shutdownTimer = -1;
|
||||||
|
break;
|
||||||
|
case GLFW.GLFW_KEY_LEFT_CONTROL:
|
||||||
|
case GLFW.GLFW_KEY_RIGHT_CONTROL:
|
||||||
|
terminateTimer = rebootTimer = shutdownTimer = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked( double mouseX, double mouseY, int button )
|
||||||
|
{
|
||||||
|
ClientComputer computer = this.computer.get();
|
||||||
|
if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
|
||||||
|
|
||||||
|
Terminal term = computer.getTerminal();
|
||||||
|
if( term != null )
|
||||||
|
{
|
||||||
|
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||||
|
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||||
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
|
|
||||||
|
computer.mouseClick( button + 1, charX + 1, charY + 1 );
|
||||||
|
|
||||||
|
lastMouseButton = button;
|
||||||
|
lastMouseX = charX;
|
||||||
|
lastMouseY = charY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseReleased( double mouseX, double mouseY, int button )
|
||||||
|
{
|
||||||
|
ClientComputer computer = this.computer.get();
|
||||||
|
if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
|
||||||
|
|
||||||
|
Terminal term = computer.getTerminal();
|
||||||
|
if( term != null )
|
||||||
|
{
|
||||||
|
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||||
|
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||||
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
|
|
||||||
|
if( lastMouseButton == button )
|
||||||
{
|
{
|
||||||
boolean repeat = Keyboard.isRepeatEvent();
|
computer.mouseUp( lastMouseButton + 1, charX + 1, charY + 1 );
|
||||||
boolean handled = false;
|
lastMouseButton = -1;
|
||||||
if( key > 0 )
|
|
||||||
{
|
|
||||||
if( !repeat )
|
|
||||||
{
|
|
||||||
m_keysDown.add( key );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Queue the "key" event
|
|
||||||
IComputer computer = m_computer.getComputer();
|
|
||||||
if( computer != null ) computer.keyDown( key, repeat );
|
|
||||||
handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( (ch >= 32 && ch <= 126) || (ch >= 160 && ch <= 255) ) // printable chars in byte range
|
|
||||||
{
|
|
||||||
// Queue the "char" event
|
|
||||||
queueEvent( "char", new Object[] { Character.toString( ch ) } );
|
|
||||||
handled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return handled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastMouseX = charX;
|
||||||
|
lastMouseY = charY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked( int mouseX, int mouseY, int button )
|
public boolean mouseDragged( double mouseX, double mouseY, int button, double v2, double v3 )
|
||||||
{
|
{
|
||||||
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
|
ClientComputer computer = this.computer.get();
|
||||||
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() )
|
if( computer == null || !computer.isColour() || button < 0 || button > 2 ) return false;
|
||||||
|
|
||||||
|
Terminal term = computer.getTerminal();
|
||||||
|
if( term != null )
|
||||||
{
|
{
|
||||||
if( !m_focus && button == 0 )
|
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||||
{
|
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||||
m_focus = true;
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
}
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
|
|
||||||
if( m_focus )
|
computer.mouseDrag( button + 1, charX + 1, charY + 1 );
|
||||||
{
|
|
||||||
IComputer computer = m_computer.getComputer();
|
|
||||||
if( computer != null && computer.isColour() && button >= 0 && button <= 2 )
|
|
||||||
{
|
|
||||||
Terminal term = computer.getTerminal();
|
|
||||||
if( term != null )
|
|
||||||
{
|
|
||||||
int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
|
||||||
int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
|
||||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
|
||||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
|
||||||
|
|
||||||
computer.mouseClick( button + 1, charX + 1, charY + 1 );
|
lastMouseX = charX;
|
||||||
|
lastMouseY = charY;
|
||||||
m_lastClickButton = button;
|
lastMouseButton = button;
|
||||||
m_lastClickX = charX;
|
|
||||||
m_lastClickY = charY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( m_focus && button == 0 && m_allowFocusLoss )
|
|
||||||
{
|
|
||||||
m_focus = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyboardInput()
|
public boolean mouseScrolled( double mouseX, double mouseY, double delta )
|
||||||
{
|
{
|
||||||
boolean handled = false;
|
ClientComputer computer = this.computer.get();
|
||||||
for( int i = m_keysDown.size() - 1; i >= 0; --i )
|
if( computer == null || !computer.isColour() || delta == 0 ) return false;
|
||||||
|
|
||||||
|
Terminal term = computer.getTerminal();
|
||||||
|
if( term != null )
|
||||||
{
|
{
|
||||||
int key = m_keysDown.get( i );
|
int charX = (int) (mouseX / FixedWidthFontRenderer.FONT_WIDTH);
|
||||||
if( !Keyboard.isKeyDown( key ) )
|
int charY = (int) (mouseY / FixedWidthFontRenderer.FONT_HEIGHT);
|
||||||
{
|
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
||||||
m_keysDown.remove( i );
|
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
||||||
if( m_focus )
|
|
||||||
{
|
computer.mouseScroll( delta < 0 ? 1 : -1, charX + 1, charY + 1 );
|
||||||
// Queue the "key_up" event
|
|
||||||
IComputer computer = m_computer.getComputer();
|
lastMouseX = charX;
|
||||||
if( computer != null ) computer.keyUp( key );
|
lastMouseY = charY;
|
||||||
handled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMouseInput( int mouseX, int mouseY )
|
|
||||||
{
|
|
||||||
IComputer computer = m_computer.getComputer();
|
|
||||||
if( mouseX >= getXPosition() && mouseX < getXPosition() + getWidth() &&
|
|
||||||
mouseY >= getYPosition() && mouseY < getYPosition() + getHeight() &&
|
|
||||||
computer != null && computer.isColour() )
|
|
||||||
{
|
|
||||||
Terminal term = computer.getTerminal();
|
|
||||||
if( term != null )
|
|
||||||
{
|
|
||||||
int charX = (mouseX - (getXPosition() + m_leftMargin)) / FixedWidthFontRenderer.FONT_WIDTH;
|
|
||||||
int charY = (mouseY - (getYPosition() + m_topMargin)) / FixedWidthFontRenderer.FONT_HEIGHT;
|
|
||||||
charX = Math.min( Math.max( charX, 0 ), term.getWidth() - 1 );
|
|
||||||
charY = Math.min( Math.max( charY, 0 ), term.getHeight() - 1 );
|
|
||||||
|
|
||||||
if( m_lastClickButton >= 0 && !Mouse.isButtonDown( m_lastClickButton ) )
|
|
||||||
{
|
|
||||||
if( m_focus ) computer.mouseUp( m_lastClickButton + 1, charX + 1, charY + 1 );
|
|
||||||
m_lastClickButton = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int wheelChange = Mouse.getEventDWheel();
|
|
||||||
if( wheelChange == 0 && m_lastClickButton == -1 )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( m_focus )
|
|
||||||
{
|
|
||||||
if( wheelChange < 0 )
|
|
||||||
{
|
|
||||||
computer.mouseScroll( 1, charX + 1, charY + 1 );
|
|
||||||
}
|
|
||||||
else if( wheelChange > 0 )
|
|
||||||
{
|
|
||||||
computer.mouseScroll( -1, charX + 1, charY + 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( m_lastClickButton >= 0 && (charX != m_lastClickX || charY != m_lastClickY) )
|
|
||||||
{
|
|
||||||
computer.mouseDrag( m_lastClickButton + 1, charX + 1, charY + 1 );
|
|
||||||
m_lastClickX = charX;
|
|
||||||
m_lastClickY = charY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
// Handle special keys
|
if( terminateTimer >= 0 && terminateTimer < TERMINATE_TIME && (terminateTimer += 0.05f) > TERMINATE_TIME )
|
||||||
if( m_focus && (Keyboard.isKeyDown( 29 ) || Keyboard.isKeyDown( 157 )) )
|
|
||||||
{
|
{
|
||||||
// Ctrl+T for terminate
|
queueEvent( "terminate" );
|
||||||
if( Keyboard.isKeyDown( 20 ) )
|
|
||||||
{
|
|
||||||
if( m_terminateTimer < TERMINATE_TIME )
|
|
||||||
{
|
|
||||||
m_terminateTimer += 0.05f;
|
|
||||||
if( m_terminateTimer >= TERMINATE_TIME ) queueEvent( "terminate" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_terminateTimer = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ctrl+R for reboot
|
|
||||||
if( Keyboard.isKeyDown( 19 ) )
|
|
||||||
{
|
|
||||||
if( m_rebootTimer < TERMINATE_TIME )
|
|
||||||
{
|
|
||||||
m_rebootTimer += 0.05f;
|
|
||||||
if( m_rebootTimer >= TERMINATE_TIME )
|
|
||||||
{
|
|
||||||
IComputer computer = m_computer.getComputer();
|
|
||||||
if( computer != null ) computer.reboot();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_rebootTimer = 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ctrl+S for shutdown
|
|
||||||
if( Keyboard.isKeyDown( 31 ) )
|
|
||||||
{
|
|
||||||
if( m_shutdownTimer < TERMINATE_TIME )
|
|
||||||
{
|
|
||||||
m_shutdownTimer += 0.05f;
|
|
||||||
if( m_shutdownTimer >= TERMINATE_TIME )
|
|
||||||
{
|
|
||||||
IComputer computer = m_computer.getComputer();
|
|
||||||
if( computer != null ) computer.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_shutdownTimer = 0.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if( shutdownTimer >= 0 && shutdownTimer < TERMINATE_TIME && (shutdownTimer += 0.05f) > TERMINATE_TIME )
|
||||||
{
|
{
|
||||||
m_terminateTimer = 0.0f;
|
ClientComputer computer = this.computer.get();
|
||||||
m_rebootTimer = 0.0f;
|
if( computer != null ) computer.shutdown();
|
||||||
m_shutdownTimer = 0.0f;
|
}
|
||||||
|
|
||||||
|
if( rebootTimer >= 0 && rebootTimer < TERMINATE_TIME && (rebootTimer += 0.05f) > TERMINATE_TIME )
|
||||||
|
{
|
||||||
|
ClientComputer computer = this.computer.get();
|
||||||
|
if( computer != null ) computer.reboot();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw( Minecraft mc, int xOrigin, int yOrigin, int mouseX, int mouseY )
|
public boolean changeFocus( boolean reverse )
|
||||||
{
|
{
|
||||||
int startX = xOrigin + getXPosition();
|
if( focused )
|
||||||
int startY = yOrigin + getYPosition();
|
{
|
||||||
|
// When blurring, we should make all keys go up
|
||||||
|
for( int key = 0; key < keysDown.size(); key++ )
|
||||||
|
{
|
||||||
|
if( keysDown.get( key ) ) queueEvent( "key_up", key );
|
||||||
|
}
|
||||||
|
keysDown.clear();
|
||||||
|
|
||||||
synchronized( m_computer )
|
// When blurring, we should make the last mouse button go up
|
||||||
|
if( lastMouseButton > 0 )
|
||||||
|
{
|
||||||
|
IComputer computer = this.computer.get();
|
||||||
|
if( computer != null ) computer.mouseUp( lastMouseButton + 1, lastMouseX + 1, lastMouseY + 1 );
|
||||||
|
lastMouseButton = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
shutdownTimer = terminateTimer = rebootTimer = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
focused = !focused;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw( int originX, int originY )
|
||||||
|
{
|
||||||
|
synchronized( computer )
|
||||||
{
|
{
|
||||||
// Draw the screen contents
|
// Draw the screen contents
|
||||||
IComputer computer = m_computer.getComputer();
|
ClientComputer computer = this.computer.get();
|
||||||
Terminal terminal = computer != null ? computer.getTerminal() : null;
|
Terminal terminal = computer != null ? computer.getTerminal() : null;
|
||||||
if( terminal != null )
|
if( terminal != null )
|
||||||
{
|
{
|
||||||
// Draw the terminal
|
// Draw the terminal
|
||||||
boolean greyscale = !computer.isColour();
|
boolean greyscale = !computer.isColour();
|
||||||
|
|
||||||
Palette palette = terminal.getPalette();
|
Palette palette = terminal.getPalette();
|
||||||
|
|
||||||
// Get the data from the terminal first
|
// Get the data from the terminal first
|
||||||
// Unfortunately we have to keep the lock for the whole of drawing, so the text doesn't change under us.
|
// Unfortunately we have to keep the lock for the whole of drawing, so the text doesn't change under us.
|
||||||
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
FixedWidthFontRenderer fontRenderer = FixedWidthFontRenderer.instance();
|
||||||
boolean tblink = m_focus && terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink();
|
boolean tblink = terminal.getCursorBlink() && FrameInfo.getGlobalCursorBlink();
|
||||||
int tw = terminal.getWidth();
|
int tw = terminal.getWidth();
|
||||||
int th = terminal.getHeight();
|
int th = terminal.getHeight();
|
||||||
int tx = terminal.getCursorX();
|
int tx = terminal.getCursorX();
|
||||||
int ty = terminal.getCursorY();
|
int ty = terminal.getCursorY();
|
||||||
|
|
||||||
int x = startX + m_leftMargin;
|
|
||||||
int y = startY + m_topMargin;
|
|
||||||
|
|
||||||
// Draw margins
|
// Draw margins
|
||||||
TextBuffer emptyLine = new TextBuffer( ' ', tw );
|
TextBuffer emptyLine = new TextBuffer( ' ', tw );
|
||||||
if( m_topMargin > 0 )
|
if( topMargin > 0 )
|
||||||
{
|
{
|
||||||
fontRenderer.drawString( emptyLine, x, startY, terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ), m_leftMargin, m_rightMargin, greyscale, palette );
|
fontRenderer.drawString( emptyLine, originX, originY - topMargin,
|
||||||
|
terminal.getTextColourLine( 0 ), terminal.getBackgroundColourLine( 0 ),
|
||||||
|
leftMargin, rightMargin, greyscale, palette );
|
||||||
}
|
}
|
||||||
if( m_bottomMargin > 0 )
|
|
||||||
|
if( bottomMargin > 0 )
|
||||||
{
|
{
|
||||||
fontRenderer.drawString( emptyLine, x, startY + 2 * m_bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT, terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ), m_leftMargin, m_rightMargin, greyscale, palette );
|
fontRenderer.drawString( emptyLine, originX, originY + bottomMargin + (th - 1) * FixedWidthFontRenderer.FONT_HEIGHT,
|
||||||
|
terminal.getTextColourLine( th - 1 ), terminal.getBackgroundColourLine( th - 1 ),
|
||||||
|
leftMargin, rightMargin, greyscale, palette );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw lines
|
// Draw lines
|
||||||
|
int y = originY;
|
||||||
for( int line = 0; line < th; line++ )
|
for( int line = 0; line < th; line++ )
|
||||||
{
|
{
|
||||||
TextBuffer text = terminal.getLine( line );
|
TextBuffer text = terminal.getLine( line );
|
||||||
TextBuffer colour = terminal.getTextColourLine( line );
|
TextBuffer colour = terminal.getTextColourLine( line );
|
||||||
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
TextBuffer backgroundColour = terminal.getBackgroundColourLine( line );
|
||||||
fontRenderer.drawString( text, x, y, colour, backgroundColour, m_leftMargin, m_rightMargin, greyscale, palette );
|
fontRenderer.drawString( text, originX, y, colour, backgroundColour, leftMargin, rightMargin, greyscale, palette );
|
||||||
y += FixedWidthFontRenderer.FONT_HEIGHT;
|
y += FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,8 +377,8 @@ public class WidgetTerminal extends Widget
|
|||||||
|
|
||||||
fontRenderer.drawString(
|
fontRenderer.drawString(
|
||||||
cursor,
|
cursor,
|
||||||
x + FixedWidthFontRenderer.FONT_WIDTH * tx,
|
originX + FixedWidthFontRenderer.FONT_WIDTH * tx,
|
||||||
startY + m_topMargin + FixedWidthFontRenderer.FONT_HEIGHT * ty,
|
originY + FixedWidthFontRenderer.FONT_HEIGHT * ty,
|
||||||
cursorColour, null,
|
cursorColour, null,
|
||||||
0, 0,
|
0, 0,
|
||||||
greyscale,
|
greyscale,
|
||||||
@@ -397,16 +389,29 @@ public class WidgetTerminal extends Widget
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Draw a black background
|
// Draw a black background
|
||||||
mc.getTextureManager().bindTexture( BACKGROUND );
|
|
||||||
Colour black = Colour.Black;
|
Colour black = Colour.Black;
|
||||||
GlStateManager.color( black.getR(), black.getG(), black.getB(), 1.0f );
|
GlStateManager.color4f( black.getR(), black.getG(), black.getB(), 1.0f );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
drawTexturedModalRect( startX, startY, 0, 0, getWidth(), getHeight() );
|
int x = originX - leftMargin;
|
||||||
|
int y = originY - rightMargin;
|
||||||
|
int width = termWidth * FixedWidthFontRenderer.FONT_WIDTH + leftMargin + rightMargin;
|
||||||
|
int height = termHeight * FixedWidthFontRenderer.FONT_HEIGHT + topMargin + bottomMargin;
|
||||||
|
|
||||||
|
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||||
|
|
||||||
|
Tessellator tesslector = Tessellator.getInstance();
|
||||||
|
BufferBuilder buffer = tesslector.getBufferBuilder();
|
||||||
|
buffer.begin( GL11.GL_QUADS, VertexFormats.POSITION_UV );
|
||||||
|
buffer.vertex( x, y + height, 0 ).texture( 0 / 256.0, height / 256.0 ).next();
|
||||||
|
buffer.vertex( x + width, y + height, 0 ).texture( width / 256.0, height / 256.0 ).next();
|
||||||
|
buffer.vertex( x + width, y, 0 ).texture( width / 256.0, 0 / 256.0 ).next();
|
||||||
|
buffer.vertex( x, y, 0 ).texture( 0 / 256.0, 0 / 256.0 ).next();
|
||||||
|
tesslector.draw();
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -414,13 +419,13 @@ public class WidgetTerminal extends Widget
|
|||||||
|
|
||||||
private void queueEvent( String event )
|
private void queueEvent( String event )
|
||||||
{
|
{
|
||||||
IComputer computer = m_computer.getComputer();
|
ClientComputer computer = this.computer.get();
|
||||||
if( computer != null ) computer.queueEvent( event );
|
if( computer != null ) computer.queueEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void queueEvent( String event, Object[] args )
|
private void queueEvent( String event, Object... args )
|
||||||
{
|
{
|
||||||
IComputer computer = m_computer.getComputer();
|
ClientComputer computer = this.computer.get();
|
||||||
if( computer != null ) computer.queueEvent( event, args );
|
if( computer != null ) computer.queueEvent( event, args );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||||
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
||||||
|
* Send enquiries to dratcliffe@gmail.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dan200.computercraft.client.gui.widgets;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.Element;
|
||||||
|
|
||||||
|
public class WidgetWrapper implements Element
|
||||||
|
{
|
||||||
|
private final Element listener;
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final int width;
|
||||||
|
private final int height;
|
||||||
|
|
||||||
|
public WidgetWrapper( Element listener, int x, int y, int width, int height )
|
||||||
|
{
|
||||||
|
this.listener = listener;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseMoved( double x, double y )
|
||||||
|
{
|
||||||
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
if( dx >= 0 && dx < width && dy >= 0 && dy < height ) listener.mouseMoved( dx, dy );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean changeFocus( boolean reverse )
|
||||||
|
{
|
||||||
|
return listener.changeFocus( reverse );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseClicked( double x, double y, int button )
|
||||||
|
{
|
||||||
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseClicked( dx, dy, button );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseReleased( double x, double y, int button )
|
||||||
|
{
|
||||||
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseReleased( dx, dy, button );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseDragged( double x, double y, int button, double deltaX, double deltaY )
|
||||||
|
{
|
||||||
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseDragged( dx, dy, button, deltaX, deltaY );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseScrolled( double x, double y, double delta )
|
||||||
|
{
|
||||||
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
return dx >= 0 && dx < width && dy >= 0 && dy < height && listener.mouseScrolled( dx, dy, delta );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyPressed( int key, int scancode, int modifiers )
|
||||||
|
{
|
||||||
|
return listener.keyPressed( key, scancode, modifiers );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyReleased( int key, int scancode, int modifiers )
|
||||||
|
{
|
||||||
|
return listener.keyReleased( key, scancode, modifiers );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean charTyped( char character, int modifiers )
|
||||||
|
{
|
||||||
|
return listener.charTyped( character, modifiers );
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX()
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY()
|
||||||
|
{
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth()
|
||||||
|
{
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight()
|
||||||
|
{
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMouseOver( double x, double y )
|
||||||
|
{
|
||||||
|
double dx = x - this.x, dy = y - this.y;
|
||||||
|
return dx >= 0 && dx < width && dy >= 0 && dy < height;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,56 +7,72 @@
|
|||||||
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.render.TileEntityCableRenderer;
|
import dan200.computercraft.client.render.TileEntityCableRenderer;
|
||||||
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
||||||
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
||||||
import dan200.computercraft.shared.command.CommandCopy;
|
import dan200.computercraft.shared.computer.blocks.TileComputer;
|
||||||
|
import dan200.computercraft.shared.computer.core.ClientComputer;
|
||||||
|
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||||
|
import dan200.computercraft.shared.network.container.*;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.TileCable;
|
||||||
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
|
||||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||||
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
import net.minecraftforge.client.ClientCommandHandler;
|
import dan200.computercraft.shared.turtle.inventory.ContainerTurtle;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.fabricmc.fabric.api.client.render.BlockEntityRendererRegistry;
|
||||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
|
|
||||||
public class ComputerCraftProxyClient extends ComputerCraftProxyCommon
|
public final class ComputerCraftProxyClient
|
||||||
{
|
{
|
||||||
@Override
|
public static void setup()
|
||||||
public void preInit()
|
|
||||||
{
|
{
|
||||||
super.preInit();
|
registerContainers();
|
||||||
|
|
||||||
// Register any client-specific commands
|
// Setup TESRs
|
||||||
ClientCommandHandler.instance.registerCommand( CommandCopy.INSTANCE );
|
BlockEntityRendererRegistry.INSTANCE.register( TileMonitor.class, new TileEntityMonitorRenderer() );
|
||||||
|
BlockEntityRendererRegistry.INSTANCE.register( TileCable.class, new TileEntityCableRenderer() );
|
||||||
|
BlockEntityRendererRegistry.INSTANCE.register( TileTurtle.class, new TileEntityTurtleRenderer() );
|
||||||
|
|
||||||
|
ClientRegistry.onItemColours();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static void registerContainers()
|
||||||
public void init()
|
|
||||||
{
|
{
|
||||||
super.init();
|
ContainerType.registerGui( TileEntityContainerType::computer, ( id, packet, player ) ->
|
||||||
|
GuiComputer.create( id, (TileComputer) packet.getTileEntity( player ), player.inventory ) );
|
||||||
|
ContainerType.registerGui( TileEntityContainerType::diskDrive, GuiDiskDrive::new );
|
||||||
|
ContainerType.registerGui( TileEntityContainerType::printer, GuiPrinter::new );
|
||||||
|
ContainerType.registerGui( TileEntityContainerType::turtle, ( id, packet, player ) -> {
|
||||||
|
TileTurtle turtle = (TileTurtle) packet.getTileEntity( player );
|
||||||
|
return new GuiTurtle( turtle, new ContainerTurtle( id, player.inventory, turtle.getAccess(), turtle.getClientComputer() ), player.inventory );
|
||||||
|
} );
|
||||||
|
|
||||||
// Setup renderers
|
ContainerType.registerGui( PocketComputerContainerType::new, GuiPocketComputer::new );
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileMonitor.class, new TileEntityMonitorRenderer() );
|
ContainerType.registerGui( PrintoutContainerType::new, GuiPrintout::new );
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileCable.class, new TileEntityCableRenderer() );
|
ContainerType.registerGui( ViewComputerContainerType::new, ( id, packet, player ) -> {
|
||||||
ClientRegistry.bindTileEntitySpecialRenderer( TileTurtle.class, new TileEntityTurtleRenderer() );
|
ClientComputer computer = ComputerCraft.clientComputerRegistry.get( packet.instanceId );
|
||||||
|
if( computer == null )
|
||||||
|
{
|
||||||
|
ComputerCraft.clientComputerRegistry.add( packet.instanceId, computer = new ClientComputer( packet.instanceId ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
ContainerViewComputer container = new ContainerViewComputer( id, computer );
|
||||||
|
return new GuiComputer<>( container, player.inventory, packet.family, computer, packet.width, packet.height );
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
/*
|
||||||
|
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
||||||
public static final class ForgeHandlers
|
public static final class ForgeHandlers
|
||||||
{
|
{
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onWorldUnload( WorldEvent.Unload event )
|
public static void onWorldUnload( WorldEvent.Unload event )
|
||||||
{
|
{
|
||||||
if( event.getWorld().isRemote )
|
if( event.getWorld().isRemote() )
|
||||||
{
|
{
|
||||||
ClientMonitor.destroyAll();
|
ClientMonitor.destroyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,222 +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.PeripheralType;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
|
||||||
import dan200.computercraft.shared.util.WorldUtil;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
|
||||||
import net.minecraft.client.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.client.renderer.RenderGlobal;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
|
||||||
public final class CableHighlightRenderer
|
|
||||||
{
|
|
||||||
private static final float EXPAND = 0.002f;
|
|
||||||
private static final double MIN = CableBounds.MIN - EXPAND;
|
|
||||||
private static final double MAX = CableBounds.MAX + EXPAND;
|
|
||||||
|
|
||||||
private CableHighlightRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void drawHighlight( DrawBlockHighlightEvent event )
|
|
||||||
{
|
|
||||||
if( event.getTarget().typeOfHit != RayTraceResult.Type.BLOCK ) return;
|
|
||||||
|
|
||||||
BlockPos pos = event.getTarget().getBlockPos();
|
|
||||||
World world = event.getPlayer().getEntityWorld();
|
|
||||||
|
|
||||||
IBlockState state = world.getBlockState( pos );
|
|
||||||
if( state.getBlock() != ComputerCraft.Blocks.cable ) return;
|
|
||||||
|
|
||||||
state = state.getActualState( world, pos );
|
|
||||||
|
|
||||||
event.setCanceled( true );
|
|
||||||
PeripheralType type = BlockCable.getPeripheralType( state );
|
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.tryBlendFuncSeparate( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0 );
|
|
||||||
GlStateManager.color( 0.0f, 0.0f, 0.0f, 0.4f );
|
|
||||||
GL11.glLineWidth( 2.0F );
|
|
||||||
GlStateManager.disableTexture2D();
|
|
||||||
GlStateManager.depthMask( false );
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
|
|
||||||
{
|
|
||||||
EntityPlayer player = event.getPlayer();
|
|
||||||
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
|
|
||||||
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
|
||||||
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
|
||||||
|
|
||||||
GlStateManager.translate( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
|
||||||
}
|
|
||||||
|
|
||||||
if( type != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), event.getTarget().hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
|
||||||
{
|
|
||||||
RenderGlobal.drawSelectionBoundingBox( CableBounds.getModemBounds( state ), 0, 0, 0, 0.4f );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int flags = 0;
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
|
|
||||||
for( EnumFacing facing : EnumFacing.VALUES )
|
|
||||||
{
|
|
||||||
if( BlockCable.doesConnectVisually( state, world, pos, facing ) )
|
|
||||||
{
|
|
||||||
flags |= 1 << facing.ordinal();
|
|
||||||
|
|
||||||
|
|
||||||
switch( facing.getAxis() )
|
|
||||||
{
|
|
||||||
case X:
|
|
||||||
{
|
|
||||||
double offset = facing == EnumFacing.WEST ? -EXPAND : 1 + EXPAND;
|
|
||||||
double centre = facing == EnumFacing.WEST ? MIN : MAX;
|
|
||||||
|
|
||||||
buffer.begin( GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION );
|
|
||||||
buffer.pos( offset, MIN, MIN ).endVertex();
|
|
||||||
buffer.pos( offset, MAX, MIN ).endVertex();
|
|
||||||
buffer.pos( offset, MAX, MAX ).endVertex();
|
|
||||||
buffer.pos( offset, MIN, MAX ).endVertex();
|
|
||||||
buffer.pos( offset, MIN, MIN ).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
|
|
||||||
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
|
||||||
buffer.pos( offset, MIN, MIN ).endVertex();
|
|
||||||
buffer.pos( centre, MIN, MIN ).endVertex();
|
|
||||||
buffer.pos( offset, MAX, MIN ).endVertex();
|
|
||||||
buffer.pos( centre, MAX, MIN ).endVertex();
|
|
||||||
buffer.pos( offset, MAX, MAX ).endVertex();
|
|
||||||
buffer.pos( centre, MAX, MAX ).endVertex();
|
|
||||||
buffer.pos( offset, MIN, MAX ).endVertex();
|
|
||||||
buffer.pos( centre, MIN, MAX ).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Y:
|
|
||||||
{
|
|
||||||
double offset = facing == EnumFacing.DOWN ? -EXPAND : 1 + EXPAND;
|
|
||||||
double centre = facing == EnumFacing.DOWN ? MIN : MAX;
|
|
||||||
|
|
||||||
buffer.begin( GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION );
|
|
||||||
buffer.pos( MIN, offset, MIN ).endVertex();
|
|
||||||
buffer.pos( MAX, offset, MIN ).endVertex();
|
|
||||||
buffer.pos( MAX, offset, MAX ).endVertex();
|
|
||||||
buffer.pos( MIN, offset, MAX ).endVertex();
|
|
||||||
buffer.pos( MIN, offset, MIN ).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
|
|
||||||
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
|
||||||
buffer.pos( MIN, offset, MIN ).endVertex();
|
|
||||||
buffer.pos( MIN, centre, MIN ).endVertex();
|
|
||||||
buffer.pos( MAX, offset, MIN ).endVertex();
|
|
||||||
buffer.pos( MAX, centre, MIN ).endVertex();
|
|
||||||
buffer.pos( MAX, offset, MAX ).endVertex();
|
|
||||||
buffer.pos( MAX, centre, MAX ).endVertex();
|
|
||||||
buffer.pos( MIN, offset, MAX ).endVertex();
|
|
||||||
buffer.pos( MIN, centre, MAX ).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case Z:
|
|
||||||
{
|
|
||||||
double offset = facing == EnumFacing.NORTH ? -EXPAND : 1 + EXPAND;
|
|
||||||
double centre = facing == EnumFacing.NORTH ? MIN : MAX;
|
|
||||||
|
|
||||||
buffer.begin( GL11.GL_LINE_STRIP, DefaultVertexFormats.POSITION );
|
|
||||||
buffer.pos( MIN, MIN, offset ).endVertex();
|
|
||||||
buffer.pos( MAX, MIN, offset ).endVertex();
|
|
||||||
buffer.pos( MAX, MAX, offset ).endVertex();
|
|
||||||
buffer.pos( MIN, MAX, offset ).endVertex();
|
|
||||||
buffer.pos( MIN, MIN, offset ).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
|
|
||||||
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
|
||||||
buffer.pos( MIN, MIN, offset ).endVertex();
|
|
||||||
buffer.pos( MIN, MIN, centre ).endVertex();
|
|
||||||
buffer.pos( MAX, MIN, offset ).endVertex();
|
|
||||||
buffer.pos( MAX, MIN, centre ).endVertex();
|
|
||||||
buffer.pos( MAX, MAX, offset ).endVertex();
|
|
||||||
buffer.pos( MAX, MAX, centre ).endVertex();
|
|
||||||
buffer.pos( MIN, MAX, offset ).endVertex();
|
|
||||||
buffer.pos( MIN, MAX, centre ).endVertex();
|
|
||||||
tessellator.draw();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION );
|
|
||||||
|
|
||||||
draw( buffer, flags, EnumFacing.WEST, EnumFacing.DOWN, EnumFacing.Axis.Z );
|
|
||||||
draw( buffer, flags, EnumFacing.WEST, EnumFacing.UP, EnumFacing.Axis.Z );
|
|
||||||
draw( buffer, flags, EnumFacing.EAST, EnumFacing.DOWN, EnumFacing.Axis.Z );
|
|
||||||
draw( buffer, flags, EnumFacing.EAST, EnumFacing.UP, EnumFacing.Axis.Z );
|
|
||||||
|
|
||||||
draw( buffer, flags, EnumFacing.WEST, EnumFacing.NORTH, EnumFacing.Axis.Y );
|
|
||||||
draw( buffer, flags, EnumFacing.WEST, EnumFacing.SOUTH, EnumFacing.Axis.Y );
|
|
||||||
draw( buffer, flags, EnumFacing.EAST, EnumFacing.NORTH, EnumFacing.Axis.Y );
|
|
||||||
draw( buffer, flags, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.Axis.Y );
|
|
||||||
|
|
||||||
draw( buffer, flags, EnumFacing.DOWN, EnumFacing.NORTH, EnumFacing.Axis.X );
|
|
||||||
draw( buffer, flags, EnumFacing.DOWN, EnumFacing.SOUTH, EnumFacing.Axis.X );
|
|
||||||
draw( buffer, flags, EnumFacing.UP, EnumFacing.NORTH, EnumFacing.Axis.X );
|
|
||||||
draw( buffer, flags, EnumFacing.UP, EnumFacing.SOUTH, EnumFacing.Axis.X );
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
GlStateManager.depthMask( true );
|
|
||||||
GlStateManager.enableTexture2D();
|
|
||||||
GlStateManager.disableBlend();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void draw( BufferBuilder buffer, int flags, EnumFacing a, EnumFacing b, EnumFacing.Axis other )
|
|
||||||
{
|
|
||||||
if( ((flags >> a.ordinal()) & 1) != ((flags >> b.ordinal()) & 1) ) return;
|
|
||||||
|
|
||||||
double offA = a.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? MIN : MAX;
|
|
||||||
double offB = b.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ? MIN : MAX;
|
|
||||||
switch( other )
|
|
||||||
{
|
|
||||||
case X:
|
|
||||||
buffer.pos( MIN, offA, offB ).endVertex();
|
|
||||||
buffer.pos( MAX, offA, offB ).endVertex();
|
|
||||||
break;
|
|
||||||
case Y:
|
|
||||||
buffer.pos( offA, MIN, offB ).endVertex();
|
|
||||||
buffer.pos( offA, MAX, offB ).endVertex();
|
|
||||||
break;
|
|
||||||
case Z:
|
|
||||||
buffer.pos( offA, offB, MIN ).endVertex();
|
|
||||||
buffer.pos( offA, offB, MAX ).endVertex();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,38 +6,39 @@
|
|||||||
|
|
||||||
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.GlStateManager;
|
import dan200.computercraft.shared.mixed.MixedFirstPersonRenderer;
|
||||||
import net.minecraft.client.renderer.ItemRenderer;
|
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
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* 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 ItemRenderer#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.getMinecraft().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,35 +52,35 @@ public abstract class ItemMapLikeRenderer
|
|||||||
* @param equipProgress The equip progress of this item
|
* @param equipProgress The equip progress of this item
|
||||||
* @param swingProgress The swing progress of this item
|
* @param swingProgress The swing progress of this item
|
||||||
* @param stack The stack to render
|
* @param stack The stack to render
|
||||||
* @see ItemRenderer#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.getMinecraft();
|
MinecraftClient minecraft = MinecraftClient.getInstance();
|
||||||
float offset = side == EnumHandSide.RIGHT ? 1f : -1f;
|
float offset = side == AbsoluteHand.RIGHT ? 1f : -1f;
|
||||||
GlStateManager.translate( 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
|
||||||
if( !minecraft.player.isInvisible() )
|
if( !minecraft.player.isInvisible() )
|
||||||
{
|
{
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
GlStateManager.rotate( offset * 10f, 0f, 0f, 1f );
|
GlStateManager.rotatef( offset * 10f, 0f, 0f, 1f );
|
||||||
minecraft.getItemRenderer().renderArmFirstPerson( equipProgress, swingProgress, side );
|
((MixedFirstPersonRenderer) minecraft.getFirstPersonRenderer()).renderArmFirstPerson_CC( equipProgress, swingProgress, side );
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the appropriate transformations. This is just copied from the
|
// Setup the appropriate transformations. This is just copied from the
|
||||||
// corresponding method in ItemRenderer.
|
// corresponding method in ItemRenderer.
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
GlStateManager.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
GlStateManager.translatef( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
||||||
float f1 = MathHelper.sqrt( swingProgress );
|
float f1 = MathHelper.sqrt( swingProgress );
|
||||||
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
||||||
float f3 = -0.5f * f2;
|
float f3 = -0.5f * f2;
|
||||||
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
||||||
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||||
GlStateManager.translate( offset * f3, f4 - 0.3f * f2, f5 );
|
GlStateManager.translatef( offset * f3, f4 - 0.3f * f2, f5 );
|
||||||
GlStateManager.rotate( f2 * -45f, 1f, 0f, 0f );
|
GlStateManager.rotatef( f2 * -45f, 1f, 0f, 0f );
|
||||||
GlStateManager.rotate( offset * f2 * -30f, 0f, 1f, 0f );
|
GlStateManager.rotatef( offset * f2 * -30f, 0f, 1f, 0f );
|
||||||
|
|
||||||
renderItem( stack );
|
renderItem( stack );
|
||||||
|
|
||||||
@@ -87,31 +88,31 @@ public abstract class ItemMapLikeRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an item in the middle of the screen.
|
* Render an item in the middle of the screen
|
||||||
*
|
*
|
||||||
* @param pitch The pitch of the player
|
* @param pitch The pitch of the player
|
||||||
* @param equipProgress The equip progress of this item
|
* @param equipProgress The equip progress of this item
|
||||||
* @param swingProgress The swing progress of this item
|
* @param swingProgress The swing progress of this item
|
||||||
* @param stack The stack to render
|
* @param stack The stack to render
|
||||||
* @see ItemRenderer#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 )
|
||||||
{
|
{
|
||||||
ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer();
|
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.
|
||||||
float swingRt = MathHelper.sqrt( swingProgress );
|
float swingRt = MathHelper.sqrt( swingProgress );
|
||||||
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
|
float tX = -0.2f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||||
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
||||||
GlStateManager.translate( 0f, -tX / 2f, tZ );
|
GlStateManager.translatef( 0f, -tX / 2f, tZ );
|
||||||
float pitchAngle = itemRenderer.getMapAngleFromPitch( pitch );
|
float pitchAngle = renderer.getMapAngleFromPitch_CC( pitch );
|
||||||
GlStateManager.translate( 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.rotate( pitchAngle * -85f, 1f, 0f, 0f );
|
GlStateManager.rotatef( pitchAngle * -85f, 1f, 0f, 0f );
|
||||||
itemRenderer.renderArms();
|
renderer.renderArms_CC();
|
||||||
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
||||||
GlStateManager.rotate( rX * 20f, 1f, 0f, 0f );
|
GlStateManager.rotatef( rX * 20f, 1f, 0f, 0f );
|
||||||
GlStateManager.scale( 2f, 2f, 2f );
|
GlStateManager.scalef( 2f, 2f, 2f );
|
||||||
|
|
||||||
renderItem( stack );
|
renderItem( stack );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,248 +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.client.event.RenderSpecificHandEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.*;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
import static dan200.computercraft.client.gui.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 = Side.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.disableDepth();
|
|
||||||
|
|
||||||
GlStateManager.rotate( 180f, 0f, 1f, 0f );
|
GlStateManager.rotatef( 180f, 0f, 1f, 0f );
|
||||||
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
||||||
GlStateManager.scale( 0.5, 0.5, 0.5 );
|
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.scale( scale, scale, 0 );
|
|
||||||
GlStateManager.translate( -0.5 * width, -0.5 * height, 0 );
|
|
||||||
|
|
||||||
// Render the main frame
|
|
||||||
ComputerFamily family = ComputerCraft.Items.pocketComputer.getFamily( stack );
|
|
||||||
int frameColour = ComputerCraft.Items.pocketComputer.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.getMinecraft().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.enableDepth();
|
|
||||||
GlStateManager.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void renderFrame( ComputerFamily family, int colour, int width, int height )
|
|
||||||
{
|
|
||||||
|
|
||||||
Minecraft.getMinecraft().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.client.event.RenderItemInFrameEvent;
|
|
||||||
import net.minecraftforge.client.event.RenderSpecificHandEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
|
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_WIDTH;
|
||||||
@@ -23,60 +20,58 @@ import static dan200.computercraft.shared.media.items.ItemPrintout.LINES_PER_PAG
|
|||||||
import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH;
|
import static dan200.computercraft.shared.media.items.ItemPrintout.LINE_MAX_LENGTH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emulates map and item-frame rendering for printouts.
|
* Emulates map and item-frame rendering for printouts
|
||||||
*/
|
*/
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.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 )
|
||||||
{
|
{
|
||||||
ItemStack stack = event.getItemStack();
|
ItemStack stack = event.getItemStack();
|
||||||
if( stack.getItem() != ComputerCraft.Items.printout ) return;
|
if( !(stack.getItem() instanceof ItemPrintout) ) return;
|
||||||
|
|
||||||
event.setCanceled( true );
|
event.setCanceled( true );
|
||||||
|
|
||||||
INSTANCE.renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
|
INSTANCE.renderItemFirstPerson( event.getHand(), event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress(), event.getItemStack() );
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderItem( ItemStack stack )
|
protected void renderItem( ItemStack stack )
|
||||||
{
|
{
|
||||||
// Setup various transformations. Note that these are partially adapated from the corresponding method
|
// Setup various transformations. Note that these are partially adapated from the corresponding method
|
||||||
// in ItemRenderer.renderMapFirstPerson
|
// in FirstPersonRenderer.renderFirstPersonMap
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
GlStateManager.rotate( 180f, 0f, 1f, 0f );
|
GlStateManager.rotatef( 180f, 0f, 1f, 0f );
|
||||||
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
||||||
GlStateManager.scale( 0.42f, 0.42f, -0.42f );
|
GlStateManager.scalef( 0.42f, 0.42f, -0.42f );
|
||||||
GlStateManager.translate( -0.5f, -0.48f, 0.0f );
|
GlStateManager.translatef( -0.5f, -0.48f, 0.0f );
|
||||||
|
|
||||||
drawPrintout( stack );
|
drawPrintout( stack );
|
||||||
|
|
||||||
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() != ComputerCraft.Items.printout ) 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.translate( 0.0f, 0.0f, -0.001f );
|
GlStateManager.translatef( 0.0f, 0.0f, -0.001f );
|
||||||
GlStateManager.rotate( 180f, 0f, 0f, 1f );
|
GlStateManager.rotatef( 180f, 0f, 0f, 1f );
|
||||||
GlStateManager.scale( 0.95f, 0.95f, -0.95f );
|
GlStateManager.scalef( 0.95f, 0.95f, -0.95f );
|
||||||
GlStateManager.translate( -0.5f, -0.5f, 0.0f );
|
GlStateManager.translatef( -0.5f, -0.5f, 0.0f );
|
||||||
|
|
||||||
drawPrintout( stack );
|
drawPrintout( stack );
|
||||||
|
|
||||||
@@ -87,7 +82,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
private static void drawPrintout( ItemStack stack )
|
private static void drawPrintout( ItemStack stack )
|
||||||
{
|
{
|
||||||
int pages = ItemPrintout.getPageCount( stack );
|
int pages = ItemPrintout.getPageCount( stack );
|
||||||
boolean book = ItemPrintout.getType( stack ) == ItemPrintout.Type.Book;
|
boolean book = ((ItemPrintout) stack.getItem()).getType() == ItemPrintout.Type.BOOK;
|
||||||
|
|
||||||
double width = LINE_MAX_LENGTH * FONT_WIDTH + X_TEXT_MARGIN * 2;
|
double width = LINE_MAX_LENGTH * FONT_WIDTH + X_TEXT_MARGIN * 2;
|
||||||
double height = LINES_PER_PAGE * FONT_HEIGHT + Y_TEXT_MARGIN * 2;
|
double height = LINES_PER_PAGE * FONT_HEIGHT + Y_TEXT_MARGIN * 2;
|
||||||
@@ -108,8 +103,8 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
|||||||
|
|
||||||
// Scale the printout to fit correctly.
|
// Scale the printout to fit correctly.
|
||||||
double scale = 1.0 / max;
|
double scale = 1.0 / max;
|
||||||
GlStateManager.scale( scale, scale, scale );
|
GlStateManager.scaled( scale, scale, scale );
|
||||||
GlStateManager.translate( (max - width) / 2.0f, (max - height) / 2.0f, 0.0f );
|
GlStateManager.translated( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
|
||||||
|
|
||||||
drawBorder( 0, 0, -0.01, 0, pages, book );
|
drawBorder( 0, 0, -0.01, 0, pages, book );
|
||||||
drawText( X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) );
|
drawText( X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack ) );
|
||||||
|
|||||||
@@ -6,19 +6,13 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.block.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,118 +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.renderer.BufferBuilder;
|
|
||||||
import net.minecraft.client.renderer.GlStateManager;
|
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
|
||||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
import java.util.EnumSet;
|
|
||||||
|
|
||||||
import static net.minecraft.util.EnumFacing.*;
|
|
||||||
|
|
||||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Side.CLIENT )
|
|
||||||
public final class MonitorHighlightRenderer
|
|
||||||
{
|
|
||||||
private static final float EXPAND = 0.002f;
|
|
||||||
|
|
||||||
private MonitorHighlightRenderer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void drawHighlight( DrawBlockHighlightEvent event )
|
|
||||||
{
|
|
||||||
if( event.getTarget().typeOfHit != RayTraceResult.Type.BLOCK || event.getPlayer().isSneaking() ) return;
|
|
||||||
|
|
||||||
World world = event.getPlayer().getEntityWorld();
|
|
||||||
BlockPos pos = event.getTarget().getBlockPos();
|
|
||||||
|
|
||||||
if( world.getBlockState( pos ).getBlock() != ComputerCraft.Blocks.peripheral ) return;
|
|
||||||
|
|
||||||
TileEntity tile = world.getTileEntity( pos );
|
|
||||||
if( !(tile instanceof TileMonitor) ) return;
|
|
||||||
|
|
||||||
TileMonitor monitor = (TileMonitor) tile;
|
|
||||||
event.setCanceled( true );
|
|
||||||
|
|
||||||
// Determine which sides are part of the external faces of the monitor, and so which need to be rendered.
|
|
||||||
EnumSet<EnumFacing> faces = EnumSet.allOf( EnumFacing.class );
|
|
||||||
EnumFacing front = monitor.getFront();
|
|
||||||
faces.remove( front );
|
|
||||||
if( monitor.getXIndex() != 0 ) faces.remove( monitor.getRight().getOpposite() );
|
|
||||||
if( monitor.getXIndex() != monitor.getWidth() - 1 ) faces.remove( monitor.getRight() );
|
|
||||||
if( monitor.getYIndex() != 0 ) faces.remove( monitor.getDown().getOpposite() );
|
|
||||||
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
|
||||||
GlStateManager.tryBlendFuncSeparate( GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
|
||||||
GL11.glLineWidth( 2.0F );
|
|
||||||
GlStateManager.disableTexture2D();
|
|
||||||
GlStateManager.depthMask( false );
|
|
||||||
GlStateManager.pushMatrix();
|
|
||||||
|
|
||||||
EntityPlayer player = event.getPlayer();
|
|
||||||
double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks();
|
|
||||||
double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks();
|
|
||||||
double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks();
|
|
||||||
|
|
||||||
GlStateManager.translate( -x + pos.getX(), -y + pos.getY(), -z + pos.getZ() );
|
|
||||||
|
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
|
||||||
BufferBuilder buffer = tessellator.getBuffer();
|
|
||||||
buffer.begin( GL11.GL_LINES, DefaultVertexFormats.POSITION_COLOR );
|
|
||||||
|
|
||||||
// I wish I could think of a better way to do this
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, 0, 0, 0, UP );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, 0, 0, 1, UP );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, 1, 0, 0, UP );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( EAST ) ) line( buffer, 1, 0, 1, UP );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 0, EAST );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 1, EAST );
|
|
||||||
if( faces.contains( NORTH ) || faces.contains( UP ) ) line( buffer, 0, 1, 0, EAST );
|
|
||||||
if( faces.contains( SOUTH ) || faces.contains( UP ) ) line( buffer, 0, 1, 1, EAST );
|
|
||||||
if( faces.contains( WEST ) || faces.contains( DOWN ) ) line( buffer, 0, 0, 0, SOUTH );
|
|
||||||
if( faces.contains( EAST ) || faces.contains( DOWN ) ) line( buffer, 1, 0, 0, SOUTH );
|
|
||||||
if( faces.contains( WEST ) || faces.contains( UP ) ) line( buffer, 0, 1, 0, SOUTH );
|
|
||||||
if( faces.contains( EAST ) || faces.contains( UP ) ) line( buffer, 1, 1, 0, SOUTH );
|
|
||||||
|
|
||||||
tessellator.draw();
|
|
||||||
|
|
||||||
GlStateManager.popMatrix();
|
|
||||||
GlStateManager.depthMask( true );
|
|
||||||
GlStateManager.enableTexture2D();
|
|
||||||
GlStateManager.disableBlend();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void line( BufferBuilder buffer, int x, int y, int z, EnumFacing direction )
|
|
||||||
{
|
|
||||||
double minX = x == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
double minY = y == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
double minZ = z == 0 ? -EXPAND : 1 + EXPAND;
|
|
||||||
|
|
||||||
buffer.pos( minX, minY, minZ ).color( 0, 0, 0, 0.4f ).endVertex();
|
|
||||||
buffer.pos(
|
|
||||||
minX + direction.getXOffset() * (1 + EXPAND * 2),
|
|
||||||
minY + direction.getYOffset() * (1 + EXPAND * 2),
|
|
||||||
minZ + direction.getZOffset() * (1 + EXPAND * 2)
|
|
||||||
).color( 0, 0, 0, 0.4f ).endVertex();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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,36 +24,36 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Width of a page.
|
* Width of a page
|
||||||
*/
|
*/
|
||||||
public static final int X_SIZE = 172;
|
public static final int X_SIZE = 172;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Height of a page.
|
* Height of a page
|
||||||
*/
|
*/
|
||||||
public static final int Y_SIZE = 209;
|
public static final int Y_SIZE = 209;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Padding between the left and right of a page and the text.
|
* Padding between the left and right of a page and the text
|
||||||
*/
|
*/
|
||||||
public static final int X_TEXT_MARGIN = 13;
|
public static final int X_TEXT_MARGIN = 13;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Padding between the top and bottom of a page and the text.
|
* Padding between the top and bottom of a page and the text
|
||||||
*/
|
*/
|
||||||
public static final int Y_TEXT_MARGIN = 11;
|
public static final int Y_TEXT_MARGIN = 11;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Width of the extra page texture.
|
* Width of the extra page texture
|
||||||
*/
|
*/
|
||||||
private static final int X_FOLD_SIZE = 12;
|
private static final int X_FOLD_SIZE = 12;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of the leather cover.
|
* Size of the leather cover
|
||||||
*/
|
*/
|
||||||
public static final int COVER_SIZE = 12;
|
public static final int COVER_SIZE = 12;
|
||||||
|
|
||||||
@@ -74,10 +74,10 @@ public final class PrintoutRenderer
|
|||||||
|
|
||||||
public static void drawText( int x, int y, int start, String[] text, String[] colours )
|
public static void drawText( int x, int y, int start, String[] text, String[] colours )
|
||||||
{
|
{
|
||||||
GlStateManager.color( 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.tryBlendFuncSeparate( 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();
|
||||||
|
|
||||||
@@ -89,16 +89,16 @@ public final class PrintoutRenderer
|
|||||||
|
|
||||||
public static void drawBorder( double x, double y, double z, int page, int pages, boolean isBook )
|
public static void drawBorder( double x, double y, double z, int page, int pages, boolean isBook )
|
||||||
{
|
{
|
||||||
GlStateManager.color( 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.tryBlendFuncSeparate( 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.getMinecraft().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,125 +6,104 @@
|
|||||||
|
|
||||||
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.PeripheralType;
|
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
import dan200.computercraft.shared.peripheral.modem.wired.BlockCable;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.BlockCableModemVariant;
|
import dan200.computercraft.shared.peripheral.modem.wired.CableModemVariant;
|
||||||
import dan200.computercraft.shared.peripheral.modem.wired.CableBounds;
|
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.RenderGlobal;
|
import net.minecraft.client.render.VertexFormats;
|
||||||
import net.minecraft.client.renderer.Tessellator;
|
import net.minecraft.client.render.WorldRenderer;
|
||||||
import net.minecraft.client.renderer.block.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.TileEntitySpecialRenderer;
|
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 org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render breaking animation only over part of a {@link TileCable}.
|
* Render breaking animation only over part of a {@link TileCable}.
|
||||||
*/
|
*/
|
||||||
public class TileEntityCableRenderer extends TileEntitySpecialRenderer<TileCable>
|
public class TileEntityCableRenderer extends BlockEntityRenderer<TileCable>
|
||||||
{
|
{
|
||||||
|
private static final Random random = new Random();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render( @Nonnull TileCable te, double x, double y, double z, float partialTicks, int destroyStage, float alpha )
|
public void render( @Nonnull TileCable te, double x, double y, double z, float partialTicks, int destroyStage )
|
||||||
{
|
{
|
||||||
if( destroyStage < 0 ) return;
|
if( destroyStage < 0 ) return;
|
||||||
|
|
||||||
BlockPos pos = te.getPos();
|
BlockPos pos = te.getPos();
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
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 = state.getActualState( world, pos );
|
state = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getPos().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
||||||
if( te.getPeripheralType() != PeripheralType.Cable && WorldUtil.isVecInsideInclusive( CableBounds.getModemBounds( state ), hit.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ) ) )
|
? block.getDefaultState().with( BlockCable.MODEM, state.get( BlockCable.MODEM ) )
|
||||||
{
|
: state.with( BlockCable.MODEM, CableModemVariant.None );
|
||||||
state = block.getDefaultState().withProperty( BlockCable.MODEM, state.getValue( BlockCable.MODEM ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state = state.withProperty( BlockCable.MODEM, BlockCableModemVariant.None );
|
|
||||||
}
|
|
||||||
|
|
||||||
IBakedModel model = mc.getBlockRendererDispatcher().getModelForState( state );
|
BakedModel model = mc.getBlockRenderManager().getModel( state );
|
||||||
if( model == null ) return;
|
|
||||||
|
|
||||||
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.getTextureMapBlocks().getAtlasSprite( "minecraft:blocks/destroy_stage_" + destroyStage );
|
Sprite breakingTexture = mc.getSpriteAtlas().getSprite( DESTROY_STAGE_TEXTURES[destroyStage] );
|
||||||
Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
|
mc.getBlockRenderManager().tesselateDamage( state, pos, breakingTexture, world );
|
||||||
world,
|
|
||||||
ForgeHooksClient.getDamageModel( model, breakingTexture, state, world, pos ),
|
|
||||||
state, pos, buffer, true
|
|
||||||
);
|
|
||||||
|
|
||||||
ForgeHooksClient.setRenderLayer( BlockRenderLayer.SOLID );
|
buffer.setOffset( 0, 0, 0 );
|
||||||
|
|
||||||
buffer.setTranslation( 0, 0, 0 );
|
|
||||||
Tessellator.getInstance().draw();
|
Tessellator.getInstance().draw();
|
||||||
|
|
||||||
postRenderDamagedBlocks();
|
postRenderDamagedBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the state for rendering block-breaking progress.
|
* @see WorldRenderer#preRenderDamagedBlocks()
|
||||||
*
|
|
||||||
* @see RenderGlobal#preRenderDamagedBlocks()
|
|
||||||
*/
|
*/
|
||||||
private void preRenderDamagedBlocks()
|
private void preRenderDamagedBlocks()
|
||||||
{
|
{
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
|
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.tryBlendFuncSeparate( GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
GlStateManager.blendFuncSeparate( GlStateManager.SourceFactor.DST_COLOR, GlStateManager.DestFactor.SRC_COLOR, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO );
|
||||||
GlStateManager.enableBlend();
|
GlStateManager.enableBlend();
|
||||||
GlStateManager.color( 1.0F, 1.0F, 1.0F, 0.5F );
|
GlStateManager.color4f( 1.0F, 1.0F, 1.0F, 0.5F );
|
||||||
GlStateManager.doPolygonOffset( -3.0F, -3.0F );
|
GlStateManager.polygonOffset( -3.0F, -3.0F );
|
||||||
GlStateManager.enablePolygonOffset();
|
GlStateManager.enablePolygonOffset();
|
||||||
GlStateManager.alphaFunc( 516, 0.1F );
|
GlStateManager.alphaFunc( 516, 0.1F );
|
||||||
GlStateManager.enableAlpha();
|
GlStateManager.enableAlphaTest();
|
||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tear down the state for rendering block-breaking progress.
|
* @see WorldRenderer#postRenderDamagedBlocks()
|
||||||
*
|
|
||||||
* @see RenderGlobal#postRenderDamagedBlocks()
|
|
||||||
*/
|
*/
|
||||||
private void postRenderDamagedBlocks()
|
private void postRenderDamagedBlocks()
|
||||||
{
|
{
|
||||||
GlStateManager.disableAlpha();
|
GlStateManager.disableAlphaTest();
|
||||||
GlStateManager.doPolygonOffset( 0.0F, 0.0F );
|
GlStateManager.polygonOffset( 0.0F, 0.0F );
|
||||||
GlStateManager.disablePolygonOffset();
|
GlStateManager.disablePolygonOffset();
|
||||||
GlStateManager.disablePolygonOffset();
|
GlStateManager.disablePolygonOffset();
|
||||||
GlStateManager.depthMask( true );
|
GlStateManager.depthMask( true );
|
||||||
|
|||||||
@@ -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,21 +17,19 @@ 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.TileEntitySpecialRenderer;
|
|
||||||
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 TileEntitySpecialRenderer<TileMonitor>
|
public class TileEntityMonitorRenderer extends BlockEntityRenderer<TileMonitor>
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void render( TileMonitor tileEntity, double posX, double posY, double posZ, float f, int i, float f2 )
|
public void render( TileMonitor tileEntity, double posX, double posY, double posZ, float f, int i )
|
||||||
{
|
{
|
||||||
if( tileEntity != null )
|
if( tileEntity != null )
|
||||||
{
|
{
|
||||||
@@ -64,39 +64,39 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
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();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Setup initial transform
|
// Setup initial transform
|
||||||
GlStateManager.translate( posX + 0.5, posY + 0.5, posZ + 0.5 );
|
GlStateManager.translated( posX + 0.5, posY + 0.5, posZ + 0.5 );
|
||||||
GlStateManager.rotate( -yaw, 0.0f, 1.0f, 0.0f );
|
GlStateManager.rotatef( -yaw, 0.0f, 1.0f, 0.0f );
|
||||||
GlStateManager.rotate( pitch, 1.0f, 0.0f, 0.0f );
|
GlStateManager.rotatef( pitch, 1.0f, 0.0f, 0.0f );
|
||||||
GlStateManager.translate(
|
GlStateManager.translated(
|
||||||
-0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
|
-0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
|
||||||
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN),
|
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0,
|
||||||
0.5
|
0.5
|
||||||
);
|
);
|
||||||
double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
double xSize = origin.getWidth() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||||
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
double ySize = origin.getHeight() - 2.0 * (TileMonitor.RENDER_MARGIN + TileMonitor.RENDER_BORDER);
|
||||||
|
|
||||||
// Get renderers
|
// Get renderers
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
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.setLightmapTextureCoords( OpenGlHelper.lightmapTexUnit, 0xFF, 0xFF );
|
GLX.glMultiTexCoord2f( GLX.GL_TEXTURE1, 0xFFFF, 0xFFFF );
|
||||||
GlStateManager.disableLighting();
|
GlStateManager.disableLighting();
|
||||||
mc.entityRenderer.disableLightmap();
|
mc.gameRenderer.disableLightmap();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Terminal terminal = originTerminal.getTerminal();
|
Terminal terminal = originTerminal.getTerminal();
|
||||||
@@ -124,14 +124,14 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
{
|
{
|
||||||
double xScale = xSize / (width * FixedWidthFontRenderer.FONT_WIDTH);
|
double xScale = xSize / (width * FixedWidthFontRenderer.FONT_WIDTH);
|
||||||
double yScale = ySize / (height * FixedWidthFontRenderer.FONT_HEIGHT);
|
double yScale = ySize / (height * FixedWidthFontRenderer.FONT_HEIGHT);
|
||||||
GlStateManager.scale( xScale, -yScale, 1.0 );
|
GlStateManager.scaled( xScale, -yScale, 1.0 );
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.BACKGROUND );
|
mc.getTextureManager().bindTexture( FixedWidthFontRenderer.BACKGROUND );
|
||||||
if( redraw )
|
if( redraw )
|
||||||
{
|
{
|
||||||
// Build background display list
|
// Build background display list
|
||||||
GlStateManager.glNewList( originTerminal.renderDisplayLists[0], GL11.GL_COMPILE );
|
GlStateManager.newList( originTerminal.renderDisplayLists[0], GL11.GL_COMPILE );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
double marginXSize = TileMonitor.RENDER_MARGIN / xScale;
|
double marginXSize = TileMonitor.RENDER_MARGIN / xScale;
|
||||||
@@ -142,10 +142,10 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
GlStateManager.pushMatrix();
|
GlStateManager.pushMatrix();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
GlStateManager.scale( 1.0, marginSquash, 1.0 );
|
GlStateManager.scaled( 1.0, marginSquash, 1.0 );
|
||||||
GlStateManager.translate( 0.0, -marginYSize / marginSquash, 0.0 );
|
GlStateManager.translated( 0.0, -marginYSize / marginSquash, 0.0 );
|
||||||
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( 0 ), marginXSize, marginXSize, greyscale, palette );
|
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( 0 ), marginXSize, marginXSize, greyscale, palette );
|
||||||
GlStateManager.translate( 0.0, (marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT) / marginSquash, 0.0 );
|
GlStateManager.translated( 0.0, (marginYSize + height * FixedWidthFontRenderer.FONT_HEIGHT) / marginSquash, 0.0 );
|
||||||
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( height - 1 ), marginXSize, marginXSize, greyscale, palette );
|
fontRenderer.drawStringBackgroundPart( 0, 0, terminal.getBackgroundColourLine( height - 1 ), marginXSize, marginXSize, greyscale, palette );
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -167,18 +167,18 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.glEndList();
|
GlStateManager.endList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[0] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[0] );
|
||||||
GlStateManager.resetColor();
|
GlStateManager.clearCurrentColor();
|
||||||
|
|
||||||
// Draw text
|
// Draw text
|
||||||
fontRenderer.bindFont();
|
fontRenderer.bindFont();
|
||||||
if( redraw )
|
if( redraw )
|
||||||
{
|
{
|
||||||
// Build text display list
|
// Build text display list
|
||||||
GlStateManager.glNewList( originTerminal.renderDisplayLists[1], GL11.GL_COMPILE );
|
GlStateManager.newList( originTerminal.renderDisplayLists[1], GL11.GL_COMPILE );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Lines
|
// Lines
|
||||||
@@ -195,18 +195,18 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.glEndList();
|
GlStateManager.endList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[1] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[1] );
|
||||||
GlStateManager.resetColor();
|
GlStateManager.clearCurrentColor();
|
||||||
|
|
||||||
// Draw cursor
|
// Draw cursor
|
||||||
fontRenderer.bindFont();
|
fontRenderer.bindFont();
|
||||||
if( redraw )
|
if( redraw )
|
||||||
{
|
{
|
||||||
// Build cursor display list
|
// Build cursor display list
|
||||||
GlStateManager.glNewList( originTerminal.renderDisplayLists[2], GL11.GL_COMPILE );
|
GlStateManager.newList( originTerminal.renderDisplayLists[2], GL11.GL_COMPILE );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Cursor
|
// Cursor
|
||||||
@@ -227,13 +227,13 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.glEndList();
|
GlStateManager.endList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( FrameInfo.getGlobalCursorBlink() )
|
if( FrameInfo.getGlobalCursorBlink() )
|
||||||
{
|
{
|
||||||
GlStateManager.callList( originTerminal.renderDisplayLists[2] );
|
GlStateManager.callList( originTerminal.renderDisplayLists[2] );
|
||||||
GlStateManager.resetColor();
|
GlStateManager.clearCurrentColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
@@ -251,18 +251,18 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.depthMask( true );
|
GlStateManager.depthMask( true );
|
||||||
mc.entityRenderer.enableLightmap();
|
mc.gameRenderer.enableLightmap();
|
||||||
GlStateManager.enableLighting();
|
GlStateManager.enableLighting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,11 +271,11 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
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
|
||||||
@@ -285,7 +285,7 @@ public class TileEntityMonitorRenderer extends TileEntitySpecialRenderer<TileMon
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.color( 1.0f, 1.0f, 1.0f, 1.0f );
|
GlStateManager.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,51 +6,53 @@
|
|||||||
|
|
||||||
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;
|
||||||
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
|
||||||
|
import dan200.computercraft.shared.util.DirectionUtil;
|
||||||
import dan200.computercraft.shared.util.Holiday;
|
import dan200.computercraft.shared.util.Holiday;
|
||||||
import dan200.computercraft.shared.util.HolidayUtil;
|
import dan200.computercraft.shared.util.HolidayUtil;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.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.EntityRenderer;
|
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.block.model.BakedQuad;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||||
import net.minecraft.client.renderer.block.model.ModelManager;
|
import net.minecraft.client.util.ModelIdentifier;
|
||||||
import net.minecraft.client.renderer.block.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.TileEntitySpecialRenderer;
|
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.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;
|
||||||
|
|
||||||
public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurtle>
|
public class TileEntityTurtleRenderer extends BlockEntityRenderer<TileTurtle>
|
||||||
{
|
{
|
||||||
private static final ModelResourceLocation NORMAL_TURTLE_MODEL = new ModelResourceLocation( "computercraft:turtle", "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_white", "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, float f2 )
|
public void render( TileTurtle tileEntity, double posX, double posY, double posZ, float partialTicks, int breaking )
|
||||||
{
|
{
|
||||||
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 )
|
||||||
{
|
{
|
||||||
@@ -62,11 +64,11 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 )
|
||||||
{
|
{
|
||||||
@@ -82,45 +84,44 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
|||||||
{
|
{
|
||||||
// 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 );
|
||||||
EntityRenderer.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.getWorld().getBlockState( turtle.getPos() );
|
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 );
|
||||||
GlStateManager.translate( posX + offset.x, posY + offset.y, posZ + offset.z );
|
GlStateManager.translated( posX + offset.x, posY + offset.y, posZ + offset.z );
|
||||||
|
|
||||||
// Render the turtle
|
// Render the turtle
|
||||||
GlStateManager.translate( 0.5f, 0.5f, 0.5f );
|
GlStateManager.translatef( 0.5f, 0.5f, 0.5f );
|
||||||
GlStateManager.rotate( 180.0f - yaw, 0.0f, 1.0f, 0.0f );
|
GlStateManager.rotatef( 180.0f - yaw, 0.0f, 1.0f, 0.0f );
|
||||||
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
||||||
{
|
{
|
||||||
// Flip the model and swap the cull face as winding order will have changed.
|
// Flip the model and swap the cull face as winding order will have changed.
|
||||||
GlStateManager.scale( 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.translate( -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
|
||||||
);
|
);
|
||||||
@@ -147,11 +148,11 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
GlStateManager.cullFace( GlStateManager.CullFace.BACK );
|
GlStateManager.cullFace( GlStateManager.FaceSides.BACK );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static 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 )
|
||||||
@@ -160,16 +161,25 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
float toolAngle = turtle.getToolRenderAngle( side, f );
|
float toolAngle = turtle.getToolRenderAngle( side, f );
|
||||||
GlStateManager.translate( 0.0f, 0.5f, 0.5f );
|
GlStateManager.translatef( 0.0f, 0.5f, 0.5f );
|
||||||
GlStateManager.rotate( -toolAngle, 1.0f, 0.0f, 0.0f );
|
GlStateManager.rotatef( -toolAngle, 1.0f, 0.0f, 0.0f );
|
||||||
GlStateManager.translate( 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 )
|
||||||
{
|
{
|
||||||
@@ -184,48 +194,43 @@ public class TileEntityTurtleRenderer extends TileEntitySpecialRenderer<TileTurt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderModel( IBlockState state, ModelResourceLocation modelLocation, int[] tints )
|
private void renderModel( BlockState state, ModelIdentifier modelLocation, int[] tints )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
ModelManager modelManager = mc.getRenderItem().getItemModelMesher().getModelManager();
|
BakedModelManager modelManager = mc.getItemRenderer().getModels().getModelManager();
|
||||||
renderModel( state, modelManager.getModel( modelLocation ), tints );
|
renderModel( state, modelManager.getModel( modelLocation ), tints );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void renderModel( IBlockState state, IBakedModel model, int[] tints )
|
private void renderModel( BlockState state, BakedModel model, int[] tints )
|
||||||
{
|
{
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
Random random = new Random( 0 );
|
||||||
Tessellator tessellator = Tessellator.getInstance();
|
Tessellator tessellator = Tessellator.getInstance();
|
||||||
mc.getTextureManager().bindTexture( TextureMap.LOCATION_BLOCKS_TEXTURE );
|
renderManager.textureManager.bindTexture( SpriteAtlasTexture.BLOCK_ATLAS_TEX );
|
||||||
renderQuads( tessellator, model.getQuads( state, null, 0 ), tints );
|
renderQuads( tessellator, model.getQuads( state, null, random ), tints );
|
||||||
for( EnumFacing facing : EnumFacing.VALUES )
|
for( Direction facing : DirectionUtil.FACINGS )
|
||||||
{
|
{
|
||||||
renderQuads( tessellator, model.getQuads( state, facing, 0 ), 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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,26 +6,27 @@
|
|||||||
|
|
||||||
package dan200.computercraft.client.render;
|
package dan200.computercraft.client.render;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import dan200.computercraft.ComputerCraft;
|
import dan200.computercraft.ComputerCraft;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.render.model.ModelBakeSettings;
|
||||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
import net.minecraft.client.render.model.ModelLoader;
|
||||||
import net.minecraft.client.resources.IResourceManager;
|
import net.minecraft.client.render.model.UnbakedModel;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraftforge.client.model.ICustomModelLoader;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraftforge.client.model.IModel;
|
|
||||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
|
||||||
import net.minecraftforge.common.model.IModelState;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class TurtleModelLoader implements ICustomModelLoader
|
public final class TurtleModelLoader
|
||||||
{
|
{
|
||||||
private static final ResourceLocation NORMAL_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle" );
|
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/advanced_turtle" );
|
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_white" );
|
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();
|
||||||
|
|
||||||
@@ -33,89 +34,59 @@ 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( "turtle" ) || name.getPath().equals( "turtle_advanced" ));
|
&& (name.getPath().equals( "item/turtle_normal" ) || name.getPath().equals( "item/turtle_advanced" ));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
public UnbakedModel loadModel( @Nonnull Identifier name )
|
||||||
public IModel loadModel( @Nonnull ResourceLocation name ) throws Exception
|
|
||||||
{
|
{
|
||||||
if( name.getNamespace().equals( ComputerCraft.MOD_ID ) )
|
if( name.getNamespace().equals( ComputerCraft.MOD_ID ) )
|
||||||
{
|
{
|
||||||
IModel colourModel = ModelLoaderRegistry.getModel( COLOUR_TURTLE_MODEL );
|
|
||||||
switch( name.getPath() )
|
switch( name.getPath() )
|
||||||
{
|
{
|
||||||
case "turtle":
|
case "item/turtle_normal":
|
||||||
return new TurtleModel( ModelLoaderRegistry.getModel( NORMAL_TURTLE_MODEL ), colourModel );
|
return new TurtleModel( NORMAL_TURTLE_MODEL );
|
||||||
case "turtle_advanced":
|
case "item/turtle_advanced":
|
||||||
return new TurtleModel( ModelLoaderRegistry.getModel( ADVANCED_TURTLE_MODEL ), colourModel );
|
return new TurtleModel( ADVANCED_TURTLE_MODEL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalStateException( "Loader does not accept " + name );
|
throw new IllegalStateException( "Loader does not accept " + name );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class TurtleModel implements IModel
|
private static final class TurtleModel implements UnbakedModel
|
||||||
{
|
{
|
||||||
private final IModel family;
|
private final Identifier family;
|
||||||
private final IModel colour;
|
|
||||||
|
|
||||||
private TurtleModel( IModel family, IModel colour )
|
private TurtleModel( Identifier family ) {this.family = family;}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
@Override
|
||||||
|
public Collection<Identifier> getModelDependencies()
|
||||||
{
|
{
|
||||||
this.family = family;
|
return Arrays.asList( family, COLOUR_TURTLE_MODEL );
|
||||||
this.colour = colour;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IBakedModel bake( @Nonnull IModelState state, @Nonnull VertexFormat format, @Nonnull Function<ResourceLocation, TextureAtlasSprite> function )
|
public Collection<Identifier> getTextureDependencies( @Nonnull Function<Identifier, UnbakedModel> modelGetter, @Nonnull Set<String> missingTextureErrors )
|
||||||
|
{
|
||||||
|
return getModelDependencies().stream()
|
||||||
|
.flatMap( x -> modelGetter.apply( x ).getTextureDependencies( modelGetter, missingTextureErrors ).stream() )
|
||||||
|
.collect( Collectors.toSet() );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public BakedModel bake( @Nonnull ModelLoader loader, @Nonnull Function<Identifier, Sprite> spriteGetter, @Nonnull ModelBakeSettings state )
|
||||||
{
|
{
|
||||||
return new TurtleSmartItemModel(
|
return new TurtleSmartItemModel(
|
||||||
family.bake( state, format, function ),
|
loader.getOrLoadModel( family ).bake( loader, spriteGetter, state ),
|
||||||
colour.bake( state, format, function )
|
loader.getOrLoadModel( COLOUR_TURTLE_MODEL ).bake( loader, spriteGetter, state )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TurtleModel copy( IModel family, IModel colour )
|
|
||||||
{
|
|
||||||
return this.family == family && this.colour == colour ? this : new TurtleModel( family, colour );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public IModel smoothLighting( boolean value )
|
|
||||||
{
|
|
||||||
return copy( family.smoothLighting( value ), colour.smoothLighting( value ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public IModel gui3d( boolean value )
|
|
||||||
{
|
|
||||||
return copy( family.gui3d( value ), colour.gui3d( value ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public IModel uvlock( boolean value )
|
|
||||||
{
|
|
||||||
return copy( family.uvlock( value ), colour.uvlock( value ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
|
||||||
public IModel retexture( ImmutableMap<String, String> textures )
|
|
||||||
{
|
|
||||||
return copy( family.retexture( textures ), colour.retexture( textures ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,34 +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.block.model.BakedQuad;
|
import net.minecraft.client.render.model.BakedModel;
|
||||||
import net.minecraft.client.renderer.block.model.IBakedModel;
|
import net.minecraft.client.render.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
import net.minecraft.client.render.model.json.ModelItemPropertyOverrideList;
|
||||||
import net.minecraft.client.renderer.block.model.ItemOverrideList;
|
import net.minecraft.client.render.model.json.ModelTransformation;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.texture.Sprite;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.math.Direction;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.vecmath.Matrix4f;
|
import javax.vecmath.Matrix4f;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.EnumMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -47,7 +44,7 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing side, long rand )
|
public List<BakedQuad> getQuads( BlockState state, Direction side, Random rand )
|
||||||
{
|
{
|
||||||
if( side != null )
|
if( side != null )
|
||||||
{
|
{
|
||||||
@@ -61,7 +58,7 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<BakedQuad> buildQuads( IBlockState state, EnumFacing side, long 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 ), m_generalTransform );
|
ModelTransformer.transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand ), m_generalTransform );
|
||||||
@@ -98,42 +95,38 @@ public class TurtleMultiModel implements IBakedModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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 ItemCameraTransforms getItemCameraTransforms()
|
|
||||||
{
|
{
|
||||||
return m_baseModel.getItemCameraTransforms();
|
return m_baseModel.getTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ItemOverrideList getOverrides()
|
public ModelItemPropertyOverrideList getItemPropertyOverrides()
|
||||||
{
|
{
|
||||||
return ItemOverrideList.NONE;
|
return ModelItemPropertyOverrideList.EMPTY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,28 +9,34 @@ package dan200.computercraft.client.render;
|
|||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||||
import dan200.computercraft.api.turtle.TurtleSide;
|
import dan200.computercraft.api.turtle.TurtleSide;
|
||||||
import dan200.computercraft.shared.turtle.items.ItemTurtleBase;
|
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.block.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 org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.vecmath.Matrix4f;
|
import javax.vecmath.Matrix4f;
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class TurtleSmartItemModel implements IBakedModel
|
public class TurtleSmartItemModel implements BakedModel
|
||||||
{
|
{
|
||||||
private static final Matrix4f s_identity, s_flip;
|
private static final Matrix4f s_identity, s_flip;
|
||||||
|
|
||||||
@@ -50,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;
|
||||||
@@ -94,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( new ArrayList<>() )
|
m_overrides = new ModelItemPropertyOverrideList( null, null, null, Collections.emptyList() )
|
||||||
{
|
{
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IBakedModel handleItemState( @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 )
|
||||||
{
|
{
|
||||||
ItemTurtleBase turtle = (ItemTurtleBase) 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;
|
||||||
}
|
}
|
||||||
@@ -131,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.getMinecraft();
|
MinecraftClient mc = MinecraftClient.getInstance();
|
||||||
ModelManager modelManager = mc.getRenderItem().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() );
|
||||||
@@ -167,42 +173,38 @@ public class TurtleSmartItemModel implements IBakedModel
|
|||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public List<BakedQuad> getQuads( IBlockState state, EnumFacing facing, long rand )
|
public List<BakedQuad> getQuads( BlockState state, Direction facing, Random rand )
|
||||||
{
|
{
|
||||||
return familyModel.getQuads( state, facing, rand );
|
return familyModel.getQuads( state, facing, rand );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAmbientOcclusion()
|
public boolean useAmbientOcclusion()
|
||||||
{
|
{
|
||||||
return familyModel.isAmbientOcclusion();
|
return familyModel.useAmbientOcclusion();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGui3d()
|
public boolean hasDepthInGui()
|
||||||
{
|
{
|
||||||
return familyModel.isGui3d();
|
return familyModel.hasDepthInGui();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isBuiltInRenderer()
|
public boolean isBuiltin()
|
||||||
{
|
{
|
||||||
return familyModel.isBuiltInRenderer();
|
return familyModel.isBuiltin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public TextureAtlasSprite getParticleTexture()
|
public Sprite getSprite()
|
||||||
{
|
{
|
||||||
return familyModel.getParticleTexture();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
public ModelTransformation getTransformation()
|
||||||
public ItemCameraTransforms getItemCameraTransforms()
|
|
||||||
{
|
{
|
||||||
return familyModel.getItemCameraTransforms();
|
return familyModel.getTransformation();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import java.net.Inet6Address;
|
import java.net.Inet6Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -50,6 +51,11 @@ public class AddressPredicate
|
|||||||
private final List<HostRange> ranges;
|
private final List<HostRange> ranges;
|
||||||
|
|
||||||
public AddressPredicate( String... filters )
|
public AddressPredicate( String... filters )
|
||||||
|
{
|
||||||
|
this( Arrays.asList( filters ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public AddressPredicate( Iterable<? extends String> filters )
|
||||||
{
|
{
|
||||||
List<Pattern> wildcards = this.wildcards = new ArrayList<>();
|
List<Pattern> wildcards = this.wildcards = new ArrayList<>();
|
||||||
List<HostRange> ranges = this.ranges = new ArrayList<>();
|
List<HostRange> ranges = this.ranges = new ArrayList<>();
|
||||||
@@ -154,7 +160,7 @@ public class AddressPredicate
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine whether the given address matches a series of patterns.
|
* Determine whether the given address matches a series of patterns
|
||||||
*
|
*
|
||||||
* @param address The address to check.
|
* @param address The address to check.
|
||||||
* @return Whether it matches any of these patterns.
|
* @return Whether it matches any of these patterns.
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public final class ApiFactories
|
|||||||
private static final Collection<ILuaAPIFactory> factories = new LinkedHashSet<>();
|
private static final Collection<ILuaAPIFactory> factories = new LinkedHashSet<>();
|
||||||
private static final Collection<ILuaAPIFactory> factoriesView = Collections.unmodifiableCollection( factories );
|
private static final Collection<ILuaAPIFactory> factoriesView = Collections.unmodifiableCollection( factories );
|
||||||
|
|
||||||
public static void register( @Nonnull ILuaAPIFactory factory )
|
public static synchronized void register( @Nonnull ILuaAPIFactory factory )
|
||||||
{
|
{
|
||||||
Objects.requireNonNull( factory, "provider cannot be null" );
|
Objects.requireNonNull( factory, "provider cannot be null" );
|
||||||
factories.add( factory );
|
factories.add( factory );
|
||||||
|
|||||||
@@ -13,106 +13,256 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A stub for any mods which depended on this version of the argument helper.
|
* Various helpers for arguments
|
||||||
*
|
|
||||||
* @deprecated Use {@link dan200.computercraft.api.lua.ArgumentHelper}.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public final class ArgumentHelper
|
public final class ArgumentHelper
|
||||||
{
|
{
|
||||||
private ArgumentHelper()
|
private ArgumentHelper()
|
||||||
{
|
{
|
||||||
|
throw new IllegalStateException( "Cannot instantiate singleton " + getClass().getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String getType( @Nullable Object type )
|
public static String getType( @Nullable Object type )
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.getType( type );
|
if( type == null ) return "nil";
|
||||||
|
if( type instanceof String ) return "string";
|
||||||
|
if( type instanceof Boolean ) return "boolean";
|
||||||
|
if( type instanceof Number ) return "number";
|
||||||
|
if( type instanceof Map ) return "table";
|
||||||
|
|
||||||
|
Class<?> klass = type.getClass();
|
||||||
|
if( klass.isArray() )
|
||||||
|
{
|
||||||
|
StringBuilder name = new StringBuilder();
|
||||||
|
while( klass.isArray() )
|
||||||
|
{
|
||||||
|
name.append( "[]" );
|
||||||
|
klass = klass.getComponentType();
|
||||||
|
}
|
||||||
|
name.insert( 0, klass.getName() );
|
||||||
|
return name.toString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return klass.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static LuaException badArgument( int index, @Nonnull String expected, @Nullable Object actual )
|
public static LuaException badArgument( int index, @Nonnull String expected, @Nullable Object actual )
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.badArgumentOf( index, expected, actual );
|
return badArgument( index, expected, getType( actual ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
|
public static LuaException badArgument( int index, @Nonnull String expected, @Nonnull String actual )
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.badArgument( index, expected, actual );
|
return new LuaException( "bad argument #" + (index + 1) + " (" + expected + " expected, got " + actual + ")" );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException
|
public static double getNumber( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.getDouble( args, index );
|
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( value instanceof Number )
|
||||||
|
{
|
||||||
|
return ((Number) value).doubleValue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "number", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
|
public static int getInt( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.getInt( args, index );
|
return (int) getLong( args, index );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
|
public static long getLong( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.getLong( args, index );
|
if( index >= args.length ) throw badArgument( index, "number", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( value instanceof Number )
|
||||||
|
{
|
||||||
|
return checkReal( index, (Number) value ).longValue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "number", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getReal( @Nonnull Object[] args, int index ) throws LuaException
|
public static double getReal( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.getFiniteDouble( args, index );
|
return checkReal( index, getNumber( args, index ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
|
public static boolean getBoolean( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.getBoolean( args, index );
|
if( index >= args.length ) throw badArgument( index, "boolean", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( value instanceof Boolean )
|
||||||
|
{
|
||||||
|
return (Boolean) value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "boolean", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static String getString( @Nonnull Object[] args, int index ) throws LuaException
|
public static String getString( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.getString( args, index );
|
if( index >= args.length ) throw badArgument( index, "string", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( value instanceof String )
|
||||||
|
{
|
||||||
|
return (String) value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "string", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
|
@Nonnull
|
||||||
public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException
|
public static Map<Object, Object> getTable( @Nonnull Object[] args, int index ) throws LuaException
|
||||||
{
|
{
|
||||||
return (Map<Object, Object>) dan200.computercraft.api.lua.ArgumentHelper.getTable( args, index );
|
if( index >= args.length ) throw badArgument( index, "table", "nil" );
|
||||||
|
Object value = args[index];
|
||||||
|
if( value instanceof Map )
|
||||||
|
{
|
||||||
|
return (Map<Object, Object>) value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "table", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException
|
public static double optNumber( @Nonnull Object[] args, int index, double def ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.optDouble( args, index, def );
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null )
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
else if( value instanceof Number )
|
||||||
|
{
|
||||||
|
return ((Number) value).doubleValue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "number", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
|
public static int optInt( @Nonnull Object[] args, int index, int def ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.optInt( args, index, def );
|
return (int) optLong( args, index, def );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
|
public static long optLong( @Nonnull Object[] args, int index, long def ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.optLong( args, index, def );
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null )
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
else if( value instanceof Number )
|
||||||
|
{
|
||||||
|
return checkReal( index, (Number) value ).longValue();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "number", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double optReal( @Nonnull Object[] args, int index, double def ) throws LuaException
|
public static double optReal( @Nonnull Object[] args, int index, double def ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.optFiniteDouble( args, index, def );
|
return checkReal( index, optNumber( args, index, def ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
|
public static boolean optBoolean( @Nonnull Object[] args, int index, boolean def ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.optBoolean( args, index, def );
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null )
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
else if( value instanceof Boolean )
|
||||||
|
{
|
||||||
|
return (Boolean) value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "boolean", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
|
public static String optString( @Nonnull Object[] args, int index, String def ) throws LuaException
|
||||||
{
|
{
|
||||||
return dan200.computercraft.api.lua.ArgumentHelper.optString( args, index, def );
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null )
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
else if( value instanceof String )
|
||||||
|
{
|
||||||
|
return (String) value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "string", value );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings( "unchecked" )
|
@SuppressWarnings( "unchecked" )
|
||||||
public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
|
public static Map<Object, Object> optTable( @Nonnull Object[] args, int index, Map<Object, Object> def ) throws LuaException
|
||||||
{
|
{
|
||||||
return (Map<Object, Object>) dan200.computercraft.api.lua.ArgumentHelper.optTable( args, index, def );
|
Object value = index < args.length ? args[index] : null;
|
||||||
|
if( value == null )
|
||||||
|
{
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
else if( value instanceof Map )
|
||||||
|
{
|
||||||
|
return (Map<Object, Object>) value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw badArgument( index, "table", value );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Number checkReal( int index, Number value ) throws LuaException
|
||||||
|
{
|
||||||
|
checkReal( index, value.doubleValue() );
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double checkReal( int index, double value ) throws LuaException
|
||||||
|
{
|
||||||
|
if( Double.isNaN( value ) )
|
||||||
|
{
|
||||||
|
throw badArgument( index, "number", "nan" );
|
||||||
|
}
|
||||||
|
else if( value == Double.POSITIVE_INFINITY )
|
||||||
|
{
|
||||||
|
throw badArgument( index, "number", "inf" );
|
||||||
|
}
|
||||||
|
else if( value == Double.NEGATIVE_INFINITY )
|
||||||
|
{
|
||||||
|
throw badArgument( index, "number", "-inf" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static dan200.computercraft.api.lua.ArgumentHelper.getString;
|
import static dan200.computercraft.core.apis.ArgumentHelper.getString;
|
||||||
|
|
||||||
public class FSAPI implements ILuaAPI
|
public class FSAPI implements ILuaAPI
|
||||||
{
|
{
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static dan200.computercraft.api.lua.ArgumentHelper.*;
|
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
||||||
import static dan200.computercraft.core.apis.TableHelper.*;
|
import static dan200.computercraft.core.apis.TableHelper.*;
|
||||||
|
|
||||||
public class HTTPAPI implements ILuaAPI
|
public class HTTPAPI implements ILuaAPI
|
||||||
@@ -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 )
|
||||||
@@ -89,12 +90,12 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
case 0: // request
|
case 0: // request
|
||||||
{
|
{
|
||||||
String address, postString, requestMethod;
|
String address, postString, requestMethod;
|
||||||
Map<?, ?> headerTable;
|
Map<Object, Object> headerTable;
|
||||||
boolean binary, redirect;
|
boolean binary, redirect;
|
||||||
|
|
||||||
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 );
|
||||||
@@ -172,7 +174,7 @@ public class HTTPAPI implements ILuaAPI
|
|||||||
case 2: // websocket
|
case 2: // websocket
|
||||||
{
|
{
|
||||||
String address = getString( args, 0 );
|
String address = getString( args, 0 );
|
||||||
Map<?, ?> headerTbl = optTable( args, 1, Collections.emptyMap() );
|
Map<Object, Object> headerTbl = optTable( args, 1, Collections.emptyMap() );
|
||||||
|
|
||||||
if( !ComputerCraft.http_websocket_enable )
|
if( !ComputerCraft.http_websocket_enable )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user