mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-11-01 14:12:59 +00:00
Compare commits
33 Commits
v1.15.2-1.
...
v1.16.4-1.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1edb7288b9 | ||
|
|
4af5bcc0b0 | ||
|
|
96c577482d | ||
|
|
61f8e97f6b | ||
|
|
c92f06cfd9 | ||
|
|
c9f3d315c0 | ||
|
|
83df64e520 | ||
|
|
ab232bd689 | ||
|
|
5bf367af9f | ||
|
|
4766833cf2 | ||
|
|
71563a52ff | ||
|
|
0c6e7b5db5 | ||
|
|
72c1d451fe | ||
|
|
8b4a01df27 | ||
|
|
d0a973fa46 | ||
|
|
26c12ac1a9 | ||
|
|
2c67849b35 | ||
|
|
7809a2eddd | ||
|
|
e8e9294fdf | ||
|
|
99581e1f40 | ||
|
|
29646a7f61 | ||
|
|
50d2712581 | ||
|
|
3093f882d8 | ||
|
|
e5cf0d1c61 | ||
|
|
6b102a8142 | ||
|
|
c8a6888a2f | ||
|
|
9ce33f8a3f | ||
|
|
a1dcd59d95 | ||
|
|
2a17585702 | ||
|
|
087c305b0d | ||
|
|
31764f6d65 | ||
|
|
4efde2b294 | ||
|
|
46595e73df |
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1,3 +1,2 @@
|
||||
# Ignore changes in generated files
|
||||
src/generated/resources/data/** linguist-generated
|
||||
src/test/server-files/structures linguist-generated
|
||||
|
||||
9
.github/workflows/main-ci.yml
vendored
9
.github/workflows/main-ci.yml
vendored
@@ -16,7 +16,7 @@ jobs:
|
||||
java-version: 8
|
||||
|
||||
- name: Cache gradle dependencies
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties') }}
|
||||
@@ -24,13 +24,10 @@ jobs:
|
||||
${{ runner.os }}-gradle-
|
||||
|
||||
- name: Build with Gradle
|
||||
run: |
|
||||
./gradlew assemble --no-daemon || ./gradlew assemble --no-daemon
|
||||
./gradlew downloadAssets --no-daemon || ./gradlew downloadAssets --no-daemon
|
||||
./gradlew build
|
||||
run: ./gradlew build --no-daemon || ./gradlew build --no-daemon
|
||||
|
||||
- name: Upload Jar
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: CC-Tweaked
|
||||
path: build/libs
|
||||
|
||||
4
.github/workflows/make-doc.yml
vendored
4
.github/workflows/make-doc.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: Set up Java 8
|
||||
uses: actions/setup-java@v1
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
java-version: 8
|
||||
|
||||
- name: Cache gradle dependencies
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ~/.gradle/caches
|
||||
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle.properties') }}
|
||||
|
||||
@@ -8,10 +8,6 @@ If you've any other questions, [just ask the community][community] or [open an i
|
||||
If you have a bug, suggestion, or other feedback, the best thing to do is [file an issue][new-issue]. When doing so,
|
||||
do use the issue templates - they provide a useful hint on what information to provide.
|
||||
|
||||
## Translations
|
||||
Translations are managed through [Weblate], an online interface for managing language strings. This is synced
|
||||
automatically with GitHub, so please don't submit PRs adding/changing translations!
|
||||
|
||||
## Developing
|
||||
In order to develop CC: Tweaked, you'll need to download the source code and then run it. This is a pretty simple
|
||||
process. When building on Windows, Use `gradlew.bat` instead of `./gradlew`.
|
||||
@@ -24,11 +20,6 @@ If you want to run CC:T in a normal Minecraft instance, run `./gradlew build` an
|
||||
These commands may take a few minutes to run the first time, as the environment is set up, but should be much faster
|
||||
afterwards.
|
||||
|
||||
The following sections describe the more niche sections of CC: Tweaked's build system. Some bits of these are
|
||||
quite-complex, and (dare I say) over-engineered, so you may wish to ignore them. Well tested/documented PRs are always
|
||||
preferred (and I'd definitely recommend setting up the tooling if you're doing serious development work), but for
|
||||
small changes it can be a lot.
|
||||
|
||||
### Code linters
|
||||
CC: Tweaked uses a couple of "linters" on its source code, to enforce a consistent style across the project. While these
|
||||
are run whenever you submit a PR, it's often useful to run this before committing.
|
||||
@@ -36,83 +27,15 @@ are run whenever you submit a PR, it's often useful to run this before committin
|
||||
- **[Checkstyle]:** Checks Java code to ensure it is consistently formatted. This can be run with `./gradlew build` or
|
||||
`./gradle check`.
|
||||
- **[illuaminate]:** Checks Lua code for semantic and styleistic issues. See [the usage section][illuaminate-usage] for
|
||||
how to download and run it. You may need to generate the Java documentation stubs (see "Documentation" below) for all
|
||||
lints to pass.
|
||||
how to download and run it.
|
||||
|
||||
### Documentation
|
||||
When writing documentation for [CC: Tweaked's documentation website][docs], it may be useful to build the documentation
|
||||
and preview it yourself before submitting a PR.
|
||||
|
||||
Building all documentation is, sadly, a multi-stage process (though this is largely hidden by Gradle). First we need to
|
||||
convert Java doc-comments into Lua ones, we also generate some Javascript to embed. All of this is then finally fed into
|
||||
illuaminate, which spits out our HTML.
|
||||
|
||||
#### Setting up the tooling
|
||||
For various reasons, getting the environment set up to build documentation can be pretty complex. I'd quite like to
|
||||
automate this via Docker and/or nix in the future, but this needs to be done manually for now.
|
||||
|
||||
First, you will need JDK 9+ (in addition to JDK 8 which is required to build Minecraft itself). Sadly our version of
|
||||
Gradle doesn't support multiple toolchains, and so you need to install this yourself.
|
||||
|
||||
Gradle needs to be told about this JDK via the `JAVA_HOME_11_X64` environment variable or adding `java11Home` to
|
||||
`~/.gradle/gradle.properties`. On my system this looks like:
|
||||
|
||||
```properties
|
||||
java11Home=/usr/lib/jvm/java-11-openjdk/
|
||||
```
|
||||
|
||||
If you just want to build the documentation stubs for linting, this is enough. However, if you want to build the full
|
||||
website, you will also need to install a few Node packages by running `npm ci`.
|
||||
|
||||
#### Building documentation
|
||||
Gradle should be your entrypoint to building most documentation. There's two tasks which are of interest:
|
||||
|
||||
- `./gradlew luaJavadoc` - Generate documentation stubs for Java methods.
|
||||
- `./gradlew docWebsite` - Generate the whole website (including Javascript pages). The resulting HTML is stored at
|
||||
`./build/docs/lua/`.
|
||||
|
||||
#### Writing documentation
|
||||
illuaminate's documentation system is not currently documented (somewhat ironic), but is _largely_ the same as
|
||||
[ldoc][ldoc]. Documentation comments are written in Markdown,
|
||||
|
||||
Our markdown engine does _not_ support GitHub flavoured markdown, and so does not support all the features one might
|
||||
expect (such as tables). It is very much recommended that you build and preview the docs locally first.
|
||||
|
||||
### Testing
|
||||
Thankfully running tests is much simpler than running the documentation generator! `./gradlew check` will run the
|
||||
entire test suite (and some additional bits of verification).
|
||||
|
||||
Before we get into writing tests, it's worth mentioning the various test suites that CC: Tweaked has:
|
||||
- "Core" Java (`./src/test/java`): These test core bits of the mod which don't require any Minecraft interaction.
|
||||
This includes the `@LuaFunction` system, file system code, etc...
|
||||
|
||||
These tests are run by `./gradlew test`.
|
||||
|
||||
- CraftOS (`./src/test/resources/test-rom/`): These tests are written in Lua, and ensure the Lua environment, libraries
|
||||
and programs work as expected. These are (generally) written to be able to be run on emulators too, to provide some
|
||||
sort of compliance test.
|
||||
|
||||
These tests are run by the '"Core" Java' test suite, and so are also run with `./gradlew test`.
|
||||
|
||||
- In-game (`./src/test/java/dan200/computercraft/ingame/`): These tests are run on an actual Minecraft server, using
|
||||
[the same system Mojang do][mc-test]. The aim of these is to test in-game behaviour of blocks and peripherals.
|
||||
|
||||
These are run by `./gradlew testInGame`.
|
||||
|
||||
## CraftOS tests
|
||||
CraftOS's tests are written using a test system called "mcfly", heavily inspired by [busted] (and thus RSpec). Groups of
|
||||
tests go inside `describe` blocks, and a single test goes inside `it`.
|
||||
|
||||
Assertions are generally written using `expect` (inspired by Hamcrest and the like). For instance, `expect(foo):eq("bar")`
|
||||
asserts that your variable `foo` is equal to the expected value `"bar"`.
|
||||
## Translations
|
||||
Translations are managed through [Weblate], an online interface for managing language strings. This is synced
|
||||
automatically with GitHub, so please don't submit PRs adding/changing translations!
|
||||
|
||||
[new-issue]: https://github.com/SquidDev-CC/CC-Tweaked/issues/new/choose "Create a new issue"
|
||||
[community]: README.md#Community "Get in touch with the community."
|
||||
[checkstyle]: https://checkstyle.org/
|
||||
[illuaminate]: https://github.com/SquidDev/illuaminate/ "Illuaminate on GitHub"
|
||||
[illuaminate-usage]: https://github.com/SquidDev/illuaminate/blob/master/README.md#usage "Installing Illuaminate"
|
||||
[weblate]: https://i18n.tweaked.cc/projects/cc-tweaked/minecraft/ "CC: Tweaked weblate instance"
|
||||
[docs]: https://tweaked.cc/ "CC: Tweaked documentation"
|
||||
[ldoc]: http://stevedonovan.github.io/ldoc/ "ldoc, a Lua documentation generator."
|
||||
[mc-test]: https://www.youtube.com/watch?v=vXaWOJTCYNg
|
||||
[busted]: https://github.com/Olivine-Labs/busted "busted: Elegant Lua unit testing."
|
||||
[illuaminate]: https://github.com/SquidDev/illuaminate/
|
||||
[illuaminate-usage]: https://github.com/SquidDev/illuaminate/blob/master/README.md#usage
|
||||
[weblate]: https://i18n.tweaked.cc/projects/cc-tweaked/minecraft/
|
||||
|
||||
104
build.gradle
104
build.gradle
@@ -21,7 +21,6 @@ plugins {
|
||||
id "com.github.hierynomus.license" version "0.15.0"
|
||||
id "com.matthewprenger.cursegradle" version "1.3.0"
|
||||
id "com.github.breadmoirai.github-release" version "2.2.4"
|
||||
id "org.jetbrains.kotlin.jvm" version "1.3.72"
|
||||
}
|
||||
|
||||
apply plugin: 'net.minecraftforge.gradle'
|
||||
@@ -51,10 +50,9 @@ minecraft {
|
||||
}
|
||||
|
||||
server {
|
||||
workingDirectory project.file("run/server")
|
||||
property 'forge.logging.markers', 'REGISTRIES'
|
||||
workingDirectory project.file("run/server-${mc_version}")
|
||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
arg "--nogui"
|
||||
|
||||
mods {
|
||||
computercraft {
|
||||
@@ -65,7 +63,7 @@ minecraft {
|
||||
|
||||
data {
|
||||
workingDirectory project.file('run')
|
||||
property 'forge.logging.markers', 'REGISTRIES'
|
||||
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
|
||||
property 'forge.logging.console.level', 'debug'
|
||||
|
||||
args '--mod', 'computercraft', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
|
||||
@@ -75,20 +73,9 @@ minecraft {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
testServer {
|
||||
workingDirectory project.file('test-files/server')
|
||||
parent runs.server
|
||||
|
||||
mods {
|
||||
cctest {
|
||||
source sourceSets.test
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mappings channel: 'official', version: project.mc_version
|
||||
mappings channel: 'snapshot', version: "${mappings_version}".toString()
|
||||
|
||||
accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||
}
|
||||
@@ -119,10 +106,10 @@ dependencies {
|
||||
|
||||
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
||||
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.3:api")
|
||||
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.15.2:6.0.0.9")
|
||||
compileOnly fg.deobf("mezz.jei:jei-1.16.4:7.6.0.58:api")
|
||||
compileOnly fg.deobf("com.blamejared.crafttweaker:CraftTweaker-1.16.4:7.0.0.63")
|
||||
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.15.2:6.0.0.3")
|
||||
runtimeOnly fg.deobf("mezz.jei:jei-1.16.4:7.6.0.58")
|
||||
|
||||
compileOnly 'com.google.auto.service:auto-service:1.0-rc7'
|
||||
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc7'
|
||||
@@ -133,9 +120,6 @@ dependencies {
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||
testImplementation 'org.hamcrest:hamcrest:2.2'
|
||||
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72'
|
||||
testImplementation 'org.jetbrains.kotlin:kotlin-reflect:1.3.72'
|
||||
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.8'
|
||||
|
||||
deployerJars "org.apache.maven.wagon:wagon-ssh:3.0.0"
|
||||
|
||||
@@ -385,7 +369,6 @@ test {
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
dependsOn('test')
|
||||
reports {
|
||||
xml.enabled true
|
||||
html.enabled true
|
||||
@@ -405,14 +388,14 @@ license {
|
||||
it.configure {
|
||||
include("**/*.java")
|
||||
exclude("dan200/computercraft/api/**")
|
||||
header file('config/license/main.txt')
|
||||
header rootProject.file('config/license/main.txt')
|
||||
}
|
||||
}
|
||||
|
||||
[licenseTest, licenseFormatTest].forEach {
|
||||
it.configure {
|
||||
include("**/*.java")
|
||||
header file('config/license/main.txt')
|
||||
header rootProject.file('config/license/main.txt')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,71 +412,10 @@ task licenseFormatAPI(type: LicenseFormat);
|
||||
it.configure {
|
||||
source = sourceSets.main.java
|
||||
include("dan200/computercraft/api/**")
|
||||
header file('config/license/api.txt')
|
||||
header rootProject.file('config/license/api.txt')
|
||||
}
|
||||
}
|
||||
|
||||
task setupServer(type: Copy) {
|
||||
group "test server"
|
||||
description "Sets up the environment for the test server."
|
||||
|
||||
from("src/test/server-files") {
|
||||
include "eula.txt"
|
||||
include "server.properties"
|
||||
}
|
||||
into "test-files/server"
|
||||
}
|
||||
|
||||
tasks.register('testInGame', JavaExec.class).configure {
|
||||
it.group('test server')
|
||||
it.description("Runs tests on a temporary Minecraft server.")
|
||||
it.dependsOn(setupServer, 'prepareRunTestServer')
|
||||
|
||||
// Copy from runTestServer. We do it in this slightly odd way as runTestServer
|
||||
// isn't created until the task is configured (which is no good for us).
|
||||
JavaExec exec = tasks.getByName('runTestServer')
|
||||
it.setWorkingDir(exec.getWorkingDir())
|
||||
it.setSystemProperties(exec.getSystemProperties())
|
||||
it.setBootstrapClasspath(exec.getBootstrapClasspath())
|
||||
it.setClasspath(exec.getClasspath())
|
||||
it.setMain(exec.getMain())
|
||||
it.setEnvironment(exec.getEnvironment())
|
||||
it.setArgs(exec.getArgs())
|
||||
it.setJvmArgs(exec.getJvmArgs())
|
||||
|
||||
it.systemProperty('forge.logging.console.level', 'info')
|
||||
it.systemProperty('cctest.run', 'true')
|
||||
|
||||
// Jacoco and modlauncher don't play well together as the classes loaded in-game don't
|
||||
// match up with those written to disk. We get Jacoco to dump all classes to disk, and
|
||||
// use that when generating the report.
|
||||
def coverageOut = new File(buildDir, 'jacocoClassDump/testInGame')
|
||||
jacoco.applyTo(it)
|
||||
it.jacoco.setIncludes(["dan200.computercraft.*"])
|
||||
it.jacoco.setClassDumpDir(coverageOut)
|
||||
it.outputs.dir(coverageOut)
|
||||
// Older versions of modlauncher don't include a protection domain (and thus no code
|
||||
// source). Jacoco skips such classes by default, so we need to explicitly include them.
|
||||
it.jacoco.setIncludeNoLocationClasses(true)
|
||||
}
|
||||
|
||||
tasks.register('jacocoTestInGameReport', JacocoReport.class).configure {
|
||||
it.group('test server')
|
||||
it.description('Generate coverage reports for in-game tests (testInGame)')
|
||||
it.dependsOn('testInGame')
|
||||
|
||||
it.executionData(new File(buildDir, 'jacoco/testInGame.exec'))
|
||||
it.setSourceDirectories(project.files(sourceSets.main.allJava.srcDirs))
|
||||
it.setClassDirectories(project.files(new File(buildDir, 'jacocoClassDump/testInGame')))
|
||||
|
||||
it.reports {
|
||||
xml.enabled true
|
||||
html.enabled true
|
||||
}
|
||||
}
|
||||
check.dependsOn('jacocoTestInGameReport')
|
||||
|
||||
|
||||
// Upload tasks
|
||||
|
||||
task checkRelease {
|
||||
@@ -508,7 +430,7 @@ task checkRelease {
|
||||
def ok = true
|
||||
|
||||
// Check we're targetting the current version
|
||||
def whatsnew = new File(projectDir, "src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt").readLines()
|
||||
def whatsnew = new File("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt").readLines()
|
||||
if (whatsnew[0] != "New features in CC: Tweaked $mod_version") {
|
||||
ok = false
|
||||
project.logger.error("Expected `whatsnew.txt' to target $mod_version.")
|
||||
@@ -525,7 +447,7 @@ task checkRelease {
|
||||
|
||||
// Check whatsnew and changelog match.
|
||||
def versionChangelog = "# " + whatsnew.join("\n")
|
||||
def changelog = new File(projectDir, "src/main/resources/data/computercraft/lua/rom/help/changelog.txt").getText()
|
||||
def changelog = new File("src/main/resources/data/computercraft/lua/rom/help/changelog.txt").getText()
|
||||
if (!changelog.startsWith(versionChangelog)) {
|
||||
ok = false
|
||||
project.logger.error("whatsnew and changelog are not in sync")
|
||||
@@ -613,7 +535,7 @@ githubRelease {
|
||||
tagName "v${mc_version}-${mod_version}"
|
||||
releaseName "[${mc_version}] ${mod_version}"
|
||||
body {
|
||||
"## " + new File(projectDir, "src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
|
||||
"## " + new File("src/main/resources/data/computercraft/lua/rom/help/whatsnew.txt")
|
||||
.readLines()
|
||||
.takeWhile { it != 'Type "help changelog" to see the full version history.' }
|
||||
.join("\n").trim()
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<property name="charset" value="UTF-8" />
|
||||
|
||||
<module name="SuppressionFilter">
|
||||
<property name="file" value="${config_loc}/suppressions.xml" />
|
||||
<property name="file" value="config/checkstyle/suppressions.xml" />
|
||||
</module>
|
||||
|
||||
<module name="BeforeExecutionExclusionFileFilter">
|
||||
@@ -97,11 +97,20 @@
|
||||
<module name="LambdaParameterName" />
|
||||
<module name="LocalFinalVariableName" />
|
||||
<module name="LocalVariableName" />
|
||||
<module name="MemberName" />
|
||||
<!-- 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\.computercraft(\.[a-z][a-z0-9]*)*" />
|
||||
<property name="format" value="^dan200\.computercraf(\.[a-z][a-z0-9]*)*" />
|
||||
</module>
|
||||
<module name="ParameterName" />
|
||||
<module name="StaticVariableName">
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
module: [kind=event] char
|
||||
see: key To listen to any key press.
|
||||
---
|
||||
|
||||
The @{char} event is fired when a character is _typed_ on the keyboard.
|
||||
|
||||
The @{char} event is different to a key press. Sometimes multiple key presses may result in one character being
|
||||
typed (for instance, on some European keyboards). Similarly, some keys (e.g. <kbd>Ctrl</kbd>) do not have any
|
||||
corresponding character. The @{key} should be used if you want to listen to key presses themselves.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{string}: The string representing the character that was pressed.
|
||||
|
||||
|
||||
## Example
|
||||
Prints each character the user presses:
|
||||
```lua
|
||||
while true do
|
||||
local event, character = os.pullEvent("char")
|
||||
print(character .. " was pressed.")
|
||||
end
|
||||
```
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
module: [kind=event] key
|
||||
---
|
||||
|
||||
This event is fired when any key is pressed while the terminal is focused.
|
||||
|
||||
This event returns a numerical "key code" (for instance, <kbd>F1</kbd> is 290). This value may vary between versions and
|
||||
so it is recommended to use the constants in the @{keys} API rather than hard coding numeric values.
|
||||
|
||||
If the button pressed represented a printable character, then the @{key} event will be followed immediately by a @{char}
|
||||
event. If you are consuming text input, use a @{char} event instead!
|
||||
|
||||
## Return values
|
||||
1. [`string`]: The event name.
|
||||
2. [`number`]: The numerical key value of the key pressed.
|
||||
3. [`boolean`]: Whether the key event was generated while holding the key (@{true}), rather than pressing it the first time (@{false}).
|
||||
|
||||
## Example
|
||||
Prints each key when the user presses it, and if the key is being held.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, key, is_held = os.pullEvent("key")
|
||||
print(("%s held=%s"):format(keys.getName(key), is_held))
|
||||
end
|
||||
```
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
module: [kind=event] key_up
|
||||
see: keys For a lookup table of the given keys.
|
||||
---
|
||||
|
||||
Fired whenever a key is released (or the terminal is closed while a key was being pressed).
|
||||
|
||||
This event returns a numerical "key code" (for instance, <kbd>F1</kbd> is 290). This value may vary between versions and
|
||||
so it is recommended to use the constants in the @{keys} API rather than hard coding numeric values.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The numerical key value of the key pressed.
|
||||
|
||||
## Example
|
||||
Prints each key released on the keyboard whenever a @{key_up} event is fired.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, key = os.pullEvent("key_up")
|
||||
local name = keys.getName(key) or "unknown key"
|
||||
print(name .. " was released.")
|
||||
end
|
||||
```
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
module: [kind=event] mouse_click
|
||||
---
|
||||
|
||||
This event is fired when the terminal is clicked with a mouse. This event is only fired on advanced computers (including
|
||||
advanced turtles and pocket computers).
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The mouse button that was clicked.
|
||||
3. @{number}: The X-coordinate of the click.
|
||||
4. @{number}: The Y-coordinate of the click.
|
||||
|
||||
## Mouse buttons
|
||||
Several mouse events (@{mouse_click}, @{mouse_up}, @{mouse_scroll}) contain a "mouse button" code. This takes a
|
||||
numerical value depending on which button on your mouse was last pressed when this event occurred.
|
||||
|
||||
<table class="pretty-table">
|
||||
<!-- Our markdown parser doesn't work on tables!? Guess I'll have to roll my own soonish :/. -->
|
||||
<tr><th>Button code</th><th>Mouse button</th></tr>
|
||||
<tr><td align="right">1</td><td>Left button</td></tr>
|
||||
<tr><td align="right">2</td><td>Middle button</td></tr>
|
||||
<tr><td align="right">3</td><td>Right button</td></tr>
|
||||
</table>
|
||||
|
||||
## Example
|
||||
Print the button and the coordinates whenever the mouse is clicked.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, button, x, y = os.pullEvent("mouse_click")
|
||||
print(("The mouse button %s was pressed at %d, %d"):format(button, x, y))
|
||||
end
|
||||
```
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
module: [kind=event] mouse_drag
|
||||
see: mouse_click For when a mouse button is initially pressed.
|
||||
---
|
||||
|
||||
This event is fired every time the mouse is moved while a mouse button is being held.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The [mouse button](mouse_click.html#Mouse_buttons) that is being pressed.
|
||||
3. @{number}: The X-coordinate of the mouse.
|
||||
4. @{number}: The Y-coordinate of the mouse.
|
||||
|
||||
## Example
|
||||
Print the button and the coordinates whenever the mouse is dragged.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, button, x, y = os.pullEvent("mouse_drag")
|
||||
print(("The mouse button %s was dragged at %d, %d"):format(button, x, y))
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
module: [kind=event] mouse_scroll
|
||||
---
|
||||
|
||||
This event is fired when a mouse wheel is scrolled in the terminal.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The direction of the scroll. (-1 = up, 1 = down)
|
||||
3. @{number}: The X-coordinate of the mouse when scrolling.
|
||||
4. @{number}: The Y-coordinate of the mouse when scrolling.
|
||||
|
||||
## Example
|
||||
Prints the direction of each scroll, and the position of the mouse at the time.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, dir, x, y = os.pullEvent("mouse_scroll")
|
||||
print(("The mouse was scrolled in direction %s at %d, %d"):format(dir, x, y))
|
||||
end
|
||||
```
|
||||
@@ -1,24 +0,0 @@
|
||||
---
|
||||
module: [kind=event] mouse_up
|
||||
---
|
||||
|
||||
This event is fired when a mouse button is released or a held mouse leaves the computer's terminal.
|
||||
|
||||
## Return values
|
||||
1. @{string}: The event name.
|
||||
2. @{number}: The [mouse button](mouse_click.html#Mouse_buttons) that was released.
|
||||
3. @{number}: The X-coordinate of the mouse.
|
||||
4. @{number}: The Y-coordinate of the mouse.
|
||||
|
||||
## Example
|
||||
Prints the coordinates and button number whenever the mouse is released.
|
||||
|
||||
```lua
|
||||
while true do
|
||||
local event, button, x, y = os.pullEvent("mouse_up")
|
||||
print(("The mouse button %s was released at %d, %d"):format(button, x, y))
|
||||
end
|
||||
```
|
||||
|
||||
[`string`]: string
|
||||
[`number`]: number
|
||||
@@ -1,6 +1,7 @@
|
||||
# Mod properties
|
||||
mod_version=1.95.2
|
||||
mod_version=1.95.1
|
||||
|
||||
# Minecraft properties (update mods.toml when changing)
|
||||
mc_version=1.15.2
|
||||
forge_version=31.1.41
|
||||
mc_version=1.16.4
|
||||
forge_version=35.0.1
|
||||
mappings_version=20201028-1.16.3
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
(sources
|
||||
/doc/stub/
|
||||
/doc/events/
|
||||
/build/docs/luaJavadoc/
|
||||
/src/main/resources/*/computercraft/lua/bios.lua
|
||||
/src/main/resources/*/computercraft/lua/rom/
|
||||
@@ -26,8 +25,7 @@
|
||||
|
||||
(module-kinds
|
||||
(peripheral Peripherals)
|
||||
(generic_peripheral "Generic Peripherals")
|
||||
(event Events))
|
||||
(generic_peripheral "Generic Peripherals"))
|
||||
|
||||
(library-path
|
||||
/doc/stub/
|
||||
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:1118481}"
|
||||
"nbt": "{color:1118481}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:15905484}"
|
||||
"nbt": "{color:15905484}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:8375321}"
|
||||
"nbt": "{color:8375321}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:14605932}"
|
||||
"nbt": "{color:14605932}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:10072818}"
|
||||
"nbt": "{color:10072818}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:15040472}"
|
||||
"nbt": "{color:15040472}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:15905331}"
|
||||
"nbt": "{color:15905331}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:15790320}"
|
||||
"nbt": "{color:15790320}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:13388876}"
|
||||
"nbt": "{color:13388876}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:5744206}"
|
||||
"nbt": "{color:5744206}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:8349260}"
|
||||
"nbt": "{color:8349260}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:3368652}"
|
||||
"nbt": "{color:3368652}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:11691749}"
|
||||
"nbt": "{color:11691749}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:5020082}"
|
||||
"nbt": "{color:5020082}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:10066329}"
|
||||
"nbt": "{color:10066329}"
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,6 @@
|
||||
],
|
||||
"result": {
|
||||
"item": "computercraft:disk",
|
||||
"nbt": "{Color:5000268}"
|
||||
"nbt": "{color:5000268}"
|
||||
}
|
||||
}
|
||||
10
src/generated/resources/data/minecraft/tags/items/piglin_loved.json
generated
Normal file
10
src/generated/resources/data/minecraft/tags/items/piglin_loved.json
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"computercraft:computer_advanced",
|
||||
"computercraft:turtle_advanced",
|
||||
"computercraft:wireless_modem_advanced",
|
||||
"computercraft:pocket_computer_advanced",
|
||||
"computercraft:monitor_advanced"
|
||||
]
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
|
||||
public static InputStream getResourceFile( String domain, String subPath )
|
||||
{
|
||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResources();
|
||||
IReloadableResourceManager manager = (IReloadableResourceManager) ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().getResourceManager();
|
||||
try
|
||||
{
|
||||
return manager.getResource( new ResourceLocation( domain, subPath ) ).getInputStream();
|
||||
@@ -97,7 +97,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
@Override
|
||||
public IMount createResourceMount( @Nonnull String domain, @Nonnull String subPath )
|
||||
{
|
||||
IReloadableResourceManager manager = ServerLifecycleHooks.getCurrentServer().getResources();
|
||||
IReloadableResourceManager manager = (IReloadableResourceManager) ServerLifecycleHooks.getCurrentServer().getDataPackRegistries().getResourceManager();
|
||||
ResourceMount mount = ResourceMount.get( domain, subPath, manager );
|
||||
return mount.exists( "" ) ? mount : null;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ public final class ComputerCraftAPIImpl implements IComputerCraftAPI
|
||||
@Override
|
||||
public LazyOptional<IWiredElement> getWiredElementAt( @Nonnull IBlockReader world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
TileEntity tile = world.getBlockEntity( pos );
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
return tile == null ? LazyOptional.empty() : tile.getCapability( CAPABILITY_WIRED_ELEMENT, side );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
package dan200.computercraft.api.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ModelManager;
|
||||
import net.minecraft.client.renderer.model.ModelResourceLocation;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
@@ -43,7 +43,7 @@ public final class TransformedModel
|
||||
|
||||
public static TransformedModel of( @Nonnull ItemStack item, @Nonnull TransformationMatrix transform )
|
||||
{
|
||||
IBakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getItemModel( item );
|
||||
IBakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getItemModel( item );
|
||||
return new TransformedModel( model, transform );
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -29,7 +29,7 @@ public interface IPacketReceiver
|
||||
* @return The receiver's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vector3d getPosition();
|
||||
|
||||
/**
|
||||
* Get the maximum distance this receiver can send and receive messages.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.api.network;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -29,7 +29,7 @@ public interface IPacketSender
|
||||
* @return The sender's position.
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getPosition();
|
||||
Vector3d getPosition();
|
||||
|
||||
/**
|
||||
* Get some sort of identification string for this sender. This does not strictly need to be unique, but you
|
||||
|
||||
@@ -35,7 +35,7 @@ public abstract class AbstractPocketUpgrade implements IPocketUpgrade
|
||||
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, NonNullSupplier<ItemStack> item )
|
||||
{
|
||||
this( id, Util.makeDescriptionId( "upgrade", id ) + ".adjective", item );
|
||||
this( id, Util.makeTranslationKey( "upgrade", id ) + ".adjective", item );
|
||||
}
|
||||
|
||||
protected AbstractPocketUpgrade( ResourceLocation id, String adjective, ItemStack stack )
|
||||
|
||||
@@ -37,7 +37,7 @@ public abstract class AbstractTurtleUpgrade implements ITurtleUpgrade
|
||||
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, NonNullSupplier<ItemStack> stack )
|
||||
{
|
||||
this( id, type, Util.makeDescriptionId( "upgrade", id ) + ".adjective", stack );
|
||||
this( id, type, Util.makeTranslationKey( "upgrade", id ) + ".adjective", stack );
|
||||
}
|
||||
|
||||
protected AbstractTurtleUpgrade( ResourceLocation id, TurtleUpgradeType type, String adjective, ItemStack stack )
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
@@ -67,7 +67,7 @@ public interface ITurtleAccess
|
||||
* @see #getVisualYaw(float)
|
||||
*/
|
||||
@Nonnull
|
||||
Vec3d getVisualPosition( float f );
|
||||
Vector3d getVisualPosition( float f );
|
||||
|
||||
/**
|
||||
* Returns the yaw the turtle is facing when it is rendered.
|
||||
|
||||
@@ -78,7 +78,7 @@ public final class ClientRegistry
|
||||
@SubscribeEvent
|
||||
public static void onTextureStitchEvent( TextureStitchEvent.Pre event )
|
||||
{
|
||||
if( !event.getMap().location().equals( PlayerContainer.BLOCK_ATLAS ) ) return;
|
||||
if( !event.getMap().getTextureLocation().equals( PlayerContainer.LOCATION_BLOCKS_TEXTURE ) ) return;
|
||||
|
||||
for( String extra : EXTRA_TEXTURES )
|
||||
{
|
||||
@@ -96,10 +96,10 @@ public final class ClientRegistry
|
||||
for( String modelName : EXTRA_MODELS )
|
||||
{
|
||||
ResourceLocation location = new ResourceLocation( ComputerCraft.MOD_ID, "item/" + modelName );
|
||||
IUnbakedModel model = loader.getModel( location );
|
||||
model.getMaterials( loader::getModel, new HashSet<>() );
|
||||
IUnbakedModel model = loader.getUnbakedModel( location );
|
||||
model.getTextures( loader::getUnbakedModel, new HashSet<>() );
|
||||
|
||||
IBakedModel baked = model.bake( loader, ModelLoader.defaultTextureGetter(), SimpleModelTransform.IDENTITY, location );
|
||||
IBakedModel baked = model.bakeModel( loader, ModelLoader.defaultTextureGetter(), SimpleModelTransform.IDENTITY, location );
|
||||
if( baked != null )
|
||||
{
|
||||
registry.put( new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, modelName ), "inventory" ), baked );
|
||||
|
||||
@@ -12,14 +12,12 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.NewChatGui;
|
||||
import net.minecraft.client.gui.RenderComponentsUtil;
|
||||
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 javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientTableFormatter implements TableFormatter
|
||||
{
|
||||
@@ -29,7 +27,7 @@ public class ClientTableFormatter implements TableFormatter
|
||||
|
||||
private static FontRenderer renderer()
|
||||
{
|
||||
return Minecraft.getInstance().font;
|
||||
return Minecraft.getInstance().fontRenderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,7 +39,7 @@ public class ClientTableFormatter implements TableFormatter
|
||||
|
||||
FontRenderer renderer = renderer();
|
||||
|
||||
float spaceWidth = renderer.width( " " );
|
||||
float spaceWidth = renderer.getStringWidth( " " );
|
||||
int spaces = MathHelper.floor( extraWidth / spaceWidth );
|
||||
int extra = extraWidth - (int) (spaces * spaceWidth);
|
||||
|
||||
@@ -57,32 +55,33 @@ public class ClientTableFormatter implements TableFormatter
|
||||
@Override
|
||||
public int getWidth( ITextComponent component )
|
||||
{
|
||||
return renderer().width( component.getColoredString() );
|
||||
return renderer().getStringPropertyWidth( component );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeLine( int id, ITextComponent component )
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
NewChatGui chat = mc.gui.getChat();
|
||||
NewChatGui chat = mc.ingameGUI.getChatGUI();
|
||||
|
||||
// Trim the text if it goes over the allowed length
|
||||
int maxWidth = MathHelper.floor( chat.getWidth() / chat.getScale() );
|
||||
List<ITextComponent> list = RenderComponentsUtil.wrapComponents( component, maxWidth, mc.font, false, false );
|
||||
if( !list.isEmpty() ) chat.addMessage( list.get( 0 ), id );
|
||||
// TODO: Trim the text if it goes over the allowed length
|
||||
// int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() );
|
||||
// List<ITextProperties> list = RenderComponentsUtil.func_238505_a_( component, maxWidth, mc.fontRenderer );
|
||||
// if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
|
||||
chat.printChatMessageWithOptionalDeletion( component, id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int display( TableBuilder table )
|
||||
{
|
||||
NewChatGui chat = Minecraft.getInstance().gui.getChat();
|
||||
NewChatGui chat = Minecraft.getInstance().ingameGUI.getChatGUI();
|
||||
|
||||
int lastHeight = lastHeights.get( table.getId() );
|
||||
|
||||
int height = TableFormatter.super.display( table );
|
||||
lastHeights.put( table.getId(), height );
|
||||
|
||||
for( int i = height; i < lastHeight; i++ ) chat.removeById( i + table.getId() );
|
||||
for( int i = height; i < lastHeight; i++ ) chat.deleteChatLine( i + table.getId() );
|
||||
return height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,14 @@ import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.RenderState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -62,22 +66,22 @@ public final class FixedWidthFontRenderer
|
||||
int xStart = 1 + column * (FONT_WIDTH + 2);
|
||||
int yStart = 1 + row * (FONT_HEIGHT + 2);
|
||||
|
||||
buffer.vertex( transform, x, y, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, yStart / WIDTH ).endVertex();
|
||||
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
||||
buffer.vertex( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||
buffer.vertex( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).uv( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||
buffer.pos( transform, x, y, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, yStart / WIDTH ).endVertex();
|
||||
buffer.pos( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||
buffer.pos( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
||||
buffer.pos( transform, x + FONT_WIDTH, y, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, yStart / WIDTH ).endVertex();
|
||||
buffer.pos( transform, x, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( xStart / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||
buffer.pos( transform, x + FONT_WIDTH, y + FONT_HEIGHT, 0f ).color( r, g, b, 1.0f ).tex( (xStart + FONT_WIDTH) / WIDTH, (yStart + FONT_HEIGHT) / WIDTH ).endVertex();
|
||||
}
|
||||
|
||||
private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, float r, float g, float b )
|
||||
{
|
||||
buffer.vertex( transform, x, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_START ).endVertex();
|
||||
buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
||||
buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
||||
buffer.vertex( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
||||
buffer.vertex( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
||||
buffer.vertex( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).uv( BACKGROUND_END, BACKGROUND_END ).endVertex();
|
||||
buffer.pos( transform, x, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_START ).endVertex();
|
||||
buffer.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
||||
buffer.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
||||
buffer.pos( transform, x + width, y, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_START ).endVertex();
|
||||
buffer.pos( transform, x, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_START, BACKGROUND_END ).endVertex();
|
||||
buffer.pos( transform, x + width, y + height, 0 ).color( r, g, b, 1.0f ).tex( BACKGROUND_END, BACKGROUND_END ).endVertex();
|
||||
}
|
||||
|
||||
private static void drawQuad( Matrix4f transform, IVertexBuilder buffer, float x, float y, float width, float height, Palette palette, boolean greyscale, char colourIndex )
|
||||
@@ -178,9 +182,9 @@ public final class FixedWidthFontRenderer
|
||||
{
|
||||
bindFont();
|
||||
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||
drawString( IDENTITY, ((IRenderTypeBuffer) renderer).getBuffer( TYPE ), x, y, text, textColour, backgroundColour, palette, greyscale, leftMarginSize, rightMarginSize );
|
||||
renderer.endBatch();
|
||||
renderer.finish();
|
||||
}
|
||||
|
||||
public static void drawTerminalWithoutCursor(
|
||||
@@ -263,10 +267,10 @@ public final class FixedWidthFontRenderer
|
||||
{
|
||||
bindFont();
|
||||
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||
IVertexBuilder buffer = renderer.getBuffer( TYPE );
|
||||
drawTerminal( transform, buffer, x, y, terminal, greyscale, topMarginSize, bottomMarginSize, leftMarginSize, rightMarginSize );
|
||||
renderer.endBatch( TYPE );
|
||||
renderer.finish( TYPE );
|
||||
}
|
||||
|
||||
public static void drawTerminal(
|
||||
@@ -287,9 +291,9 @@ public final class FixedWidthFontRenderer
|
||||
{
|
||||
bindFont();
|
||||
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||
drawEmptyTerminal( transform, renderer, x, y, width, height );
|
||||
renderer.endBatch();
|
||||
renderer.finish();
|
||||
}
|
||||
|
||||
public static void drawEmptyTerminal( float x, float y, float width, float height )
|
||||
@@ -305,7 +309,7 @@ public final class FixedWidthFontRenderer
|
||||
|
||||
private static void bindFont()
|
||||
{
|
||||
Minecraft.getInstance().getTextureManager().bind( FONT );
|
||||
Minecraft.getInstance().getTextureManager().bindTexture( FONT );
|
||||
RenderSystem.texParameter( GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP );
|
||||
}
|
||||
|
||||
@@ -315,26 +319,26 @@ public final class FixedWidthFontRenderer
|
||||
|
||||
private static final VertexFormat FORMAT = DefaultVertexFormats.POSITION_COLOR_TEX;
|
||||
|
||||
static final RenderType MAIN = RenderType.create(
|
||||
static final RenderType MAIN = RenderType.makeType(
|
||||
"terminal_font", FORMAT, GL_MODE, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderType.State.builder()
|
||||
.setTextureState( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
||||
.setAlphaState( DEFAULT_ALPHA )
|
||||
.setLightmapState( NO_LIGHTMAP )
|
||||
.setWriteMaskState( COLOR_WRITE )
|
||||
.createCompositeState( false )
|
||||
RenderType.State.getBuilder()
|
||||
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
||||
.alpha( DEFAULT_ALPHA )
|
||||
.lightmap( LIGHTMAP_DISABLED )
|
||||
.writeMask( COLOR_WRITE )
|
||||
.build( false )
|
||||
);
|
||||
|
||||
static final RenderType BLOCKER = RenderType.create(
|
||||
static final RenderType BLOCKER = RenderType.makeType(
|
||||
"terminal_blocker", FORMAT, GL_MODE, 256,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderType.State.builder()
|
||||
.setTextureState( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
||||
.setAlphaState( DEFAULT_ALPHA )
|
||||
.setWriteMaskState( DEPTH_WRITE )
|
||||
.setLightmapState( NO_LIGHTMAP )
|
||||
.createCompositeState( false )
|
||||
RenderType.State.getBuilder()
|
||||
.texture( new RenderState.TextureState( FONT, false, false ) ) // blur, minimap
|
||||
.alpha( DEFAULT_ALPHA )
|
||||
.writeMask( DEPTH_WRITE )
|
||||
.lightmap( LIGHTMAP_DISABLED )
|
||||
.build( false )
|
||||
);
|
||||
|
||||
private Type( String name, Runnable setup, Runnable destroy )
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
@@ -21,6 +22,8 @@ import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.BORDER;
|
||||
import static dan200.computercraft.client.render.ComputerBorderRenderer.MARGIN;
|
||||
|
||||
@@ -74,30 +77,30 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Containe
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( true );
|
||||
minecraft.keyboardListener.enableRepeatEvents( true );
|
||||
|
||||
int termPxWidth = termWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = termHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
imageWidth = termPxWidth + MARGIN * 2 + BORDER * 2;
|
||||
imageHeight = termPxHeight + MARGIN * 2 + BORDER * 2;
|
||||
xSize = termPxWidth + MARGIN * 2 + BORDER * 2;
|
||||
ySize = termPxHeight + MARGIN * 2 + BORDER * 2;
|
||||
|
||||
super.init();
|
||||
|
||||
terminal = new WidgetTerminal( minecraft, () -> computer, termWidth, termHeight, MARGIN, MARGIN, MARGIN, MARGIN );
|
||||
terminalWrapper = new WidgetWrapper( terminal, MARGIN + BORDER + leftPos, MARGIN + BORDER + topPos, termPxWidth, termPxHeight );
|
||||
terminalWrapper = new WidgetWrapper( terminal, MARGIN + BORDER + guiLeft, MARGIN + BORDER + guiTop, termPxWidth, termPxHeight );
|
||||
|
||||
children.add( terminalWrapper );
|
||||
setFocused( terminalWrapper );
|
||||
setListener( terminalWrapper );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed()
|
||||
public void onClose()
|
||||
{
|
||||
super.removed();
|
||||
super.onClose();
|
||||
children.remove( terminal );
|
||||
terminal = null;
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( false );
|
||||
minecraft.keyboardListener.enableRepeatEvents( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,23 +114,23 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Containe
|
||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
||||
{
|
||||
// Forward the tab key to the terminal, rather than moving between controls.
|
||||
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper )
|
||||
if( key == GLFW.GLFW_KEY_TAB && getListener() != null && getListener() == terminalWrapper )
|
||||
{
|
||||
return getFocused().keyPressed( key, scancode, modifiers );
|
||||
return getListener().keyPressed( key, scancode, modifiers );
|
||||
}
|
||||
|
||||
return super.keyPressed( key, scancode, modifiers );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
public void drawGuiContainerBackgroundLayer( @Nonnull MatrixStack stack, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw terminal
|
||||
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
|
||||
|
||||
// Draw a border around the terminal
|
||||
RenderSystem.color4f( 1, 1, 1, 1 );
|
||||
minecraft.getTextureManager().bind( ComputerBorderRenderer.getTexture( family ) );
|
||||
minecraft.getTextureManager().bindTexture( ComputerBorderRenderer.getTexture( family ) );
|
||||
ComputerBorderRenderer.render(
|
||||
terminalWrapper.getX() - MARGIN, terminalWrapper.getY() - MARGIN, getBlitOffset(),
|
||||
terminalWrapper.getWidth() + MARGIN * 2, terminalWrapper.getHeight() + MARGIN * 2
|
||||
@@ -135,17 +138,22 @@ public final class GuiComputer<T extends ContainerComputerBase> extends Containe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
renderHoveredTooltip( stack, 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 ))
|
||||
return (getListener() != null && getListener().mouseDragged( x, y, button, deltaX, deltaY ))
|
||||
|| super.mouseDragged( x, y, button, deltaX, deltaY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.shared.peripheral.diskdrive.ContainerDiskDrive;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
@@ -12,6 +13,8 @@ import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/disk_drive.png" );
|
||||
@@ -22,26 +25,18 @@ public class GuiDiskDrive extends ContainerScreen<ContainerDiskDrive>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels( int mouseX, int mouseY )
|
||||
{
|
||||
String title = this.title.getColoredString();
|
||||
font.draw( title, (imageWidth - font.width( title )) / 2.0f, 6, 0x404040 );
|
||||
font.draw( title, 8, imageHeight - 96 + 2, 0x404040 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void drawGuiContainerBackgroundLayer( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
minecraft.getTextureManager().bind( BACKGROUND );
|
||||
blit( leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||
blit( transform, guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack transform, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
renderBackground( transform );
|
||||
super.render( transform, mouseX, mouseY, partialTicks );
|
||||
renderHoveredTooltip( transform, mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,16 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.shared.peripheral.printer.ContainerPrinter;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiPrinter extends ContainerScreen<ContainerPrinter>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND = new ResourceLocation( "computercraft", "textures/gui/printer.png" );
|
||||
@@ -22,29 +24,29 @@ public class GuiPrinter extends ContainerScreen<ContainerPrinter>
|
||||
super( container, player, title );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels( int mouseX, int mouseY )
|
||||
/*@Override
|
||||
protected void drawGuiContainerForegroundLayer( int mouseX, int mouseY )
|
||||
{
|
||||
String title = getTitle().getColoredString();
|
||||
font.draw( title, (imageWidth - font.width( title )) / 2.0f, 6, 0x404040 );
|
||||
font.draw( I18n.get( "container.inventory" ), 8, imageHeight - 96 + 2, 0x404040 );
|
||||
}
|
||||
String title = getTitle().getFormattedText();
|
||||
font.drawString( title, (xSize - font.getStringWidth( title )) / 2.0f, 6, 0x404040 );
|
||||
font.drawString( I18n.format( "container.inventory" ), 8, ySize - 96 + 2, 0x404040 );
|
||||
}*/
|
||||
|
||||
@Override
|
||||
protected void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void drawGuiContainerBackgroundLayer( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
minecraft.getTextureManager().bind( BACKGROUND );
|
||||
blit( leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
minecraft.getTextureManager().bindTexture( BACKGROUND );
|
||||
blit( transform, guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||
|
||||
if( getMenu().isPrinting() ) blit( leftPos + 34, topPos + 21, 176, 0, 25, 45 );
|
||||
if( getContainer().isPrinting() ) blit( transform, guiLeft + 34, guiTop + 21, 176, 0, 25, 45 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
renderHoveredTooltip( stack, mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.common.ContainerHeldItem;
|
||||
@@ -12,41 +13,40 @@ import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screen.inventory.ContainerScreen;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import static dan200.computercraft.client.render.PrintoutRenderer.*;
|
||||
|
||||
public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||
{
|
||||
private static final Matrix4f IDENTITY = TransformationMatrix.identity().getMatrix();
|
||||
|
||||
private final boolean book;
|
||||
private final int pages;
|
||||
private final TextBuffer[] text;
|
||||
private final TextBuffer[] colours;
|
||||
private int page;
|
||||
private final boolean m_book;
|
||||
private final int m_pages;
|
||||
private final TextBuffer[] m_text;
|
||||
private final TextBuffer[] m_colours;
|
||||
private int m_page;
|
||||
|
||||
public GuiPrintout( ContainerHeldItem container, PlayerInventory player, ITextComponent title )
|
||||
{
|
||||
super( container, player, title );
|
||||
|
||||
imageHeight = Y_SIZE;
|
||||
ySize = Y_SIZE;
|
||||
|
||||
String[] text = ItemPrintout.getText( container.getStack() );
|
||||
this.text = new TextBuffer[text.length];
|
||||
for( int i = 0; i < this.text.length; i++ ) this.text[i] = new TextBuffer( text[i] );
|
||||
m_text = new TextBuffer[text.length];
|
||||
for( int i = 0; i < m_text.length; i++ ) m_text[i] = new TextBuffer( text[i] );
|
||||
|
||||
String[] colours = ItemPrintout.getColours( container.getStack() );
|
||||
this.colours = new TextBuffer[colours.length];
|
||||
for( int i = 0; i < this.colours.length; i++ ) this.colours[i] = new TextBuffer( colours[i] );
|
||||
m_colours = new TextBuffer[colours.length];
|
||||
for( int i = 0; i < m_colours.length; i++ ) m_colours[i] = new TextBuffer( colours[i] );
|
||||
|
||||
page = 0;
|
||||
pages = Math.max( this.text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
||||
book = ((ItemPrintout) container.getStack().getItem()).getType() == ItemPrintout.Type.BOOK;
|
||||
m_page = 0;
|
||||
m_pages = Math.max( m_text.length / ItemPrintout.LINES_PER_PAGE, 1 );
|
||||
m_book = ((ItemPrintout) container.getStack().getItem()).getType() == ItemPrintout.Type.BOOK;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -56,13 +56,13 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||
|
||||
if( key == GLFW.GLFW_KEY_RIGHT )
|
||||
{
|
||||
if( page < pages - 1 ) page++;
|
||||
if( m_page < m_pages - 1 ) m_page++;
|
||||
return true;
|
||||
}
|
||||
|
||||
if( key == GLFW.GLFW_KEY_LEFT )
|
||||
{
|
||||
if( page > 0 ) page--;
|
||||
if( m_page > 0 ) m_page--;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -76,14 +76,14 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||
if( delta < 0 )
|
||||
{
|
||||
// Scroll up goes to the next page
|
||||
if( page < pages - 1 ) page++;
|
||||
if( m_page < m_pages - 1 ) m_page++;
|
||||
return true;
|
||||
}
|
||||
|
||||
if( delta > 0 )
|
||||
{
|
||||
// Scroll down goes to the previous page
|
||||
if( page > 0 ) page--;
|
||||
if( m_page > 0 ) m_page--;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -91,27 +91,33 @@ public class GuiPrintout extends ContainerScreen<ContainerHeldItem>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void drawGuiContainerBackgroundLayer( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw the printout
|
||||
RenderSystem.color4f( 1.0f, 1.0f, 1.0f, 1.0f );
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().renderBuffers().bufferSource();
|
||||
drawBorder( IDENTITY, renderer, leftPos, topPos, getBlitOffset(), page, pages, book );
|
||||
drawText( IDENTITY, renderer, leftPos + X_TEXT_MARGIN, topPos + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * page, text, colours );
|
||||
renderer.endBatch();
|
||||
IRenderTypeBuffer.Impl renderer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
|
||||
Matrix4f matrix = transform.getLast().getMatrix();
|
||||
drawBorder( matrix, renderer, guiLeft, guiTop, getBlitOffset(), m_page, m_pages, m_book );
|
||||
drawText( matrix, renderer, guiLeft + X_TEXT_MARGIN, guiTop + Y_TEXT_MARGIN, ItemPrintout.LINES_PER_PAGE * m_page, m_text, m_colours );
|
||||
renderer.finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
// We must take the background further back in order to not overlap with our printed pages.
|
||||
setBlitOffset( getBlitOffset() - 1 );
|
||||
renderBackground();
|
||||
renderBackground( stack );
|
||||
setBlitOffset( getBlitOffset() + 1 );
|
||||
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
package dan200.computercraft.client.gui;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.widgets.WidgetTerminal;
|
||||
@@ -18,15 +19,17 @@ import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
||||
{
|
||||
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_normal.png" );
|
||||
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( ComputerCraft.MOD_ID, "textures/gui/turtle_advanced.png" );
|
||||
private static final ResourceLocation BACKGROUND_NORMAL = new ResourceLocation( "computercraft", "textures/gui/turtle_normal.png" );
|
||||
private static final ResourceLocation BACKGROUND_ADVANCED = new ResourceLocation( "computercraft", "textures/gui/turtle_advanced.png" );
|
||||
|
||||
private final ContainerTurtle container;
|
||||
private ContainerTurtle m_container;
|
||||
|
||||
private final ComputerFamily family;
|
||||
private final ClientComputer computer;
|
||||
private final ComputerFamily m_family;
|
||||
private final ClientComputer m_computer;
|
||||
|
||||
private WidgetTerminal terminal;
|
||||
private WidgetWrapper terminalWrapper;
|
||||
@@ -35,42 +38,42 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
||||
{
|
||||
super( container, player, title );
|
||||
|
||||
this.container = container;
|
||||
family = container.getFamily();
|
||||
computer = (ClientComputer) container.getComputer();
|
||||
m_container = container;
|
||||
m_family = container.getFamily();
|
||||
m_computer = (ClientComputer) container.getComputer();
|
||||
|
||||
imageWidth = 254;
|
||||
imageHeight = 217;
|
||||
xSize = 254;
|
||||
ySize = 217;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init()
|
||||
{
|
||||
super.init();
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( true );
|
||||
minecraft.keyboardListener.enableRepeatEvents( true );
|
||||
|
||||
int termPxWidth = ComputerCraft.turtleTermWidth * FixedWidthFontRenderer.FONT_WIDTH;
|
||||
int termPxHeight = ComputerCraft.turtleTermHeight * FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
|
||||
terminal = new WidgetTerminal(
|
||||
minecraft, () -> computer,
|
||||
minecraft, () -> m_computer,
|
||||
ComputerCraft.turtleTermWidth,
|
||||
ComputerCraft.turtleTermHeight,
|
||||
2, 2, 2, 2
|
||||
);
|
||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + leftPos, 2 + 8 + topPos, termPxWidth, termPxHeight );
|
||||
terminalWrapper = new WidgetWrapper( terminal, 2 + 8 + guiLeft, 2 + 8 + guiTop, termPxWidth, termPxHeight );
|
||||
|
||||
children.add( terminalWrapper );
|
||||
setFocused( terminalWrapper );
|
||||
setListener( terminalWrapper );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removed()
|
||||
public void onClose()
|
||||
{
|
||||
super.removed();
|
||||
super.onClose();
|
||||
children.remove( terminal );
|
||||
terminal = null;
|
||||
minecraft.keyboardHandler.setSendRepeatsToGui( false );
|
||||
minecraft.keyboardListener.enableRepeatEvents( false );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,55 +87,58 @@ public class GuiTurtle extends ContainerScreen<ContainerTurtle>
|
||||
public boolean keyPressed( int key, int scancode, int modifiers )
|
||||
{
|
||||
// Forward the tab key to the terminal, rather than moving between controls.
|
||||
if( key == GLFW.GLFW_KEY_TAB && getFocused() != null && getFocused() == terminalWrapper )
|
||||
if( key == GLFW.GLFW_KEY_TAB && getListener() != null && getListener() == terminalWrapper )
|
||||
{
|
||||
return getFocused().keyPressed( key, scancode, modifiers );
|
||||
return getListener().keyPressed( key, scancode, modifiers );
|
||||
}
|
||||
|
||||
return super.keyPressed( key, scancode, modifiers );
|
||||
}
|
||||
|
||||
private void drawSelectionSlot( boolean advanced )
|
||||
{
|
||||
// Draw selection slot
|
||||
int slot = container.getSelectedSlot();
|
||||
if( slot >= 0 )
|
||||
{
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
int slotX = slot % 4;
|
||||
int slotY = slot / 4;
|
||||
minecraft.getTextureManager().bind( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
blit( leftPos + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18, topPos + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18, 0, 217, 24, 24 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg( float partialTicks, int mouseX, int mouseY )
|
||||
protected void drawGuiContainerBackgroundLayer( @Nonnull MatrixStack transform, float partialTicks, int mouseX, int mouseY )
|
||||
{
|
||||
// Draw term
|
||||
boolean advanced = family == ComputerFamily.ADVANCED;
|
||||
ResourceLocation texture = m_family == ComputerFamily.ADVANCED ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL;
|
||||
terminal.draw( terminalWrapper.getX(), terminalWrapper.getY() );
|
||||
|
||||
// Draw border/inventory
|
||||
RenderSystem.color4f( 1.0F, 1.0F, 1.0F, 1.0F );
|
||||
minecraft.getTextureManager().bind( advanced ? BACKGROUND_ADVANCED : BACKGROUND_NORMAL );
|
||||
blit( leftPos, topPos, 0, 0, imageWidth, imageHeight );
|
||||
minecraft.getTextureManager().bindTexture( texture );
|
||||
blit( transform, guiLeft, guiTop, 0, 0, xSize, ySize );
|
||||
|
||||
drawSelectionSlot( advanced );
|
||||
// Draw selection slot
|
||||
int slot = m_container.getSelectedSlot();
|
||||
if( slot >= 0 )
|
||||
{
|
||||
int slotX = slot % 4;
|
||||
int slotY = slot / 4;
|
||||
blit( transform,
|
||||
guiLeft + ContainerTurtle.TURTLE_START_X - 2 + slotX * 18,
|
||||
guiTop + ContainerTurtle.PLAYER_START_Y - 2 + slotY * 18,
|
||||
0, 217, 24, 24
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( int mouseX, int mouseY, float partialTicks )
|
||||
public void render( @Nonnull MatrixStack stack, int mouseX, int mouseY, float partialTicks )
|
||||
{
|
||||
renderBackground();
|
||||
super.render( mouseX, mouseY, partialTicks );
|
||||
renderTooltip( mouseX, mouseY );
|
||||
renderBackground( stack );
|
||||
super.render( stack, mouseX, mouseY, partialTicks );
|
||||
renderHoveredTooltip( stack, 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 ))
|
||||
return (getListener() != null && getListener().mouseDragged( x, y, button, deltaX, deltaY ))
|
||||
|| super.mouseDragged( x, y, button, deltaX, deltaY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer( @Nonnull MatrixStack transform, int mouseX, int mouseY )
|
||||
{
|
||||
// Skip rendering labels.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
|
||||
case GLFW.GLFW_KEY_V:
|
||||
// Ctrl+V for paste
|
||||
String clipboard = client.keyboardHandler.getClipboard();
|
||||
String clipboard = client.keyboardListener.getClipboardString();
|
||||
if( clipboard != null )
|
||||
{
|
||||
// Clip to the first occurrence of \r or \n
|
||||
@@ -111,7 +111,7 @@ public class WidgetTerminal implements IGuiEventListener
|
||||
}
|
||||
|
||||
// Filter the string
|
||||
clipboard = SharedConstants.filterText( clipboard );
|
||||
clipboard = SharedConstants.filterAllowedCharacters( clipboard );
|
||||
if( !clipboard.isEmpty() )
|
||||
{
|
||||
// Clip to 512 characters and queue the event
|
||||
|
||||
@@ -11,13 +11,19 @@ import dan200.computercraft.client.render.TileEntityMonitorRenderer;
|
||||
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
|
||||
import dan200.computercraft.client.render.TurtlePlayerRenderer;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerComputer;
|
||||
import dan200.computercraft.shared.computer.inventory.ContainerViewComputer;
|
||||
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
|
||||
import dan200.computercraft.shared.pocket.inventory.ContainerPocketComputer;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import net.minecraft.client.gui.ScreenManager;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.RenderTypeLookup;
|
||||
import net.minecraft.item.IItemPropertyGetter;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemModelsProperties;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -26,6 +32,8 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD )
|
||||
public final class ComputerCraftProxyClient
|
||||
{
|
||||
@@ -35,12 +43,12 @@ public final class ComputerCraftProxyClient
|
||||
registerContainers();
|
||||
|
||||
// While turtles themselves are not transparent, their upgrades may be.
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_NORMAL.get(), RenderType.translucent() );
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_ADVANCED.get(), RenderType.translucent() );
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_NORMAL.get(), RenderType.getTranslucent() );
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.TURTLE_ADVANCED.get(), RenderType.getTranslucent() );
|
||||
|
||||
// Monitors' textures have transparent fronts and so count as cutouts.
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_NORMAL.get(), RenderType.cutout() );
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_ADVANCED.get(), RenderType.cutout() );
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_NORMAL.get(), RenderType.getCutout() );
|
||||
RenderTypeLookup.setRenderLayer( Registry.ModBlocks.MONITOR_ADVANCED.get(), RenderType.getCutout() );
|
||||
|
||||
// Setup TESRs
|
||||
ClientRegistry.bindTileEntityRenderer( Registry.ModTiles.MONITOR_NORMAL.get(), TileEntityMonitorRenderer::new );
|
||||
@@ -49,21 +57,40 @@ public final class ComputerCraftProxyClient
|
||||
ClientRegistry.bindTileEntityRenderer( Registry.ModTiles.TURTLE_ADVANCED.get(), TileEntityTurtleRenderer::new );
|
||||
|
||||
RenderingRegistry.registerEntityRenderingHandler( Registry.ModEntities.TURTLE_PLAYER.get(), TurtlePlayerRenderer::new );
|
||||
|
||||
registerItemProperty( "state",
|
||||
( stack, world, player ) -> ItemPocketComputer.getState( stack ).ordinal(),
|
||||
Registry.ModItems.POCKET_COMPUTER_NORMAL, Registry.ModItems.POCKET_COMPUTER_ADVANCED
|
||||
);
|
||||
registerItemProperty( "state",
|
||||
( stack, world, player ) -> IColouredItem.getColourBasic( stack ) != -1 ? 1 : 0,
|
||||
Registry.ModItems.POCKET_COMPUTER_NORMAL, Registry.ModItems.POCKET_COMPUTER_ADVANCED
|
||||
);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static void registerItemProperty( String name, IItemPropertyGetter getter, Supplier<? extends Item>... items )
|
||||
{
|
||||
ResourceLocation id = new ResourceLocation( ComputerCraft.MOD_ID, name );
|
||||
for( Supplier<? extends Item> item : items )
|
||||
{
|
||||
ItemModelsProperties.registerProperty( item.get(), id, getter );
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerContainers()
|
||||
{
|
||||
// My IDE doesn't think so, but we do actually need these generics.
|
||||
|
||||
ScreenManager.<ContainerComputer, GuiComputer<ContainerComputer>>register( Registry.ModContainers.COMPUTER.get(), GuiComputer::create );
|
||||
ScreenManager.<ContainerPocketComputer, GuiComputer<ContainerPocketComputer>>register( Registry.ModContainers.POCKET_COMPUTER.get(), GuiComputer::createPocket );
|
||||
ScreenManager.register( Registry.ModContainers.TURTLE.get(), GuiTurtle::new );
|
||||
ScreenManager.<ContainerComputer, GuiComputer<ContainerComputer>>registerFactory( Registry.ModContainers.COMPUTER.get(), GuiComputer::create );
|
||||
ScreenManager.<ContainerPocketComputer, GuiComputer<ContainerPocketComputer>>registerFactory( Registry.ModContainers.POCKET_COMPUTER.get(), GuiComputer::createPocket );
|
||||
ScreenManager.registerFactory( Registry.ModContainers.TURTLE.get(), GuiTurtle::new );
|
||||
|
||||
ScreenManager.register( Registry.ModContainers.PRINTER.get(), GuiPrinter::new );
|
||||
ScreenManager.register( Registry.ModContainers.DISK_DRIVE.get(), GuiDiskDrive::new );
|
||||
ScreenManager.register( Registry.ModContainers.PRINTOUT.get(), GuiPrintout::new );
|
||||
ScreenManager.registerFactory( Registry.ModContainers.PRINTER.get(), GuiPrinter::new );
|
||||
ScreenManager.registerFactory( Registry.ModContainers.DISK_DRIVE.get(), GuiDiskDrive::new );
|
||||
ScreenManager.registerFactory( Registry.ModContainers.PRINTOUT.get(), GuiPrintout::new );
|
||||
|
||||
ScreenManager.<ContainerViewComputer, GuiComputer<ContainerViewComputer>>register( Registry.ModContainers.VIEW_COMPUTER.get(), GuiComputer::createView );
|
||||
ScreenManager.<ContainerViewComputer, GuiComputer<ContainerViewComputer>>registerFactory( Registry.ModContainers.VIEW_COMPUTER.get(), GuiComputer::createView );
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, value = Dist.CLIENT )
|
||||
@@ -72,7 +99,7 @@ public final class ComputerCraftProxyClient
|
||||
@SubscribeEvent
|
||||
public static void onWorldUnload( WorldEvent.Unload event )
|
||||
{
|
||||
if( event.getWorld().isClientSide() )
|
||||
if( event.getWorld().isRemote() )
|
||||
{
|
||||
ClientMonitor.destroyAll();
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ import dan200.computercraft.shared.peripheral.modem.wired.CableShapes;
|
||||
import dan200.computercraft.shared.util.WorldUtil;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.ActiveRenderInfo;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.shapes.VoxelShape;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.DrawHighlightEvent;
|
||||
@@ -45,35 +45,35 @@ public final class CableHighlightRenderer
|
||||
public static void drawHighlight( DrawHighlightEvent.HighlightBlock event )
|
||||
{
|
||||
BlockRayTraceResult hit = event.getTarget();
|
||||
BlockPos pos = hit.getBlockPos();
|
||||
World world = event.getInfo().getEntity().getCommandSenderWorld();
|
||||
BlockPos pos = hit.getPos();
|
||||
World world = event.getInfo().getRenderViewEntity().getEntityWorld();
|
||||
ActiveRenderInfo info = event.getInfo();
|
||||
|
||||
BlockState state = world.getBlockState( pos );
|
||||
|
||||
// We only care about instances with both cable and modem.
|
||||
if( state.getBlock() != Registry.ModBlocks.CABLE.get() || state.getValue( BlockCable.MODEM ).getFacing() == null || !state.getValue( BlockCable.CABLE ) )
|
||||
if( state.getBlock() != Registry.ModBlocks.CABLE.get() || state.get( BlockCable.MODEM ).getFacing() == null || !state.get( BlockCable.CABLE ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCanceled( true );
|
||||
|
||||
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getLocation().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
||||
VoxelShape shape = WorldUtil.isVecInside( CableShapes.getModemShape( state ), hit.getHitVec().subtract( pos.getX(), pos.getY(), pos.getZ() ) )
|
||||
? CableShapes.getModemShape( state )
|
||||
: CableShapes.getCableShape( state );
|
||||
|
||||
Vec3d cameraPos = info.getPosition();
|
||||
double xOffset = pos.getX() - cameraPos.x();
|
||||
double yOffset = pos.getY() - cameraPos.y();
|
||||
double zOffset = pos.getZ() - cameraPos.z();
|
||||
Vector3d cameraPos = info.getProjectedView();
|
||||
double xOffset = pos.getX() - cameraPos.getX();
|
||||
double yOffset = pos.getY() - cameraPos.getY();
|
||||
double zOffset = pos.getZ() - cameraPos.getZ();
|
||||
|
||||
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() );
|
||||
Matrix4f matrix4f = event.getMatrix().last().pose();
|
||||
shape.forAllEdges( ( x1, y1, z1, x2, y2, z2 ) -> {
|
||||
buffer.vertex( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) )
|
||||
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() );
|
||||
Matrix4f matrix4f = event.getMatrix().getLast().getMatrix();
|
||||
shape.forEachEdge( ( x1, y1, z1, x2, y2, z2 ) -> {
|
||||
buffer.pos( matrix4f, (float) (x1 + xOffset), (float) (y1 + yOffset), (float) (z1 + zOffset) )
|
||||
.color( 0, 0, 0, 0.4f ).endVertex();
|
||||
buffer.vertex( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) )
|
||||
buffer.pos( matrix4f, (float) (x2 + xOffset), (float) (y2 + yOffset), (float) (z2 + zOffset) )
|
||||
.color( 0, 0, 0, 0.4f ).endVertex();
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@ import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -85,13 +85,13 @@ public class ComputerBorderRenderer
|
||||
public static void render( int x, int y, int z, int width, int height )
|
||||
{
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuilder();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX );
|
||||
|
||||
render( IDENTITY, buffer, x, y, z, width, height );
|
||||
|
||||
RenderSystem.enableAlphaTest();
|
||||
tessellator.end();
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
public static void render( Matrix4f transform, IVertexBuilder buffer, int x, int y, int z, int width, int height )
|
||||
@@ -166,9 +166,9 @@ public class ComputerBorderRenderer
|
||||
|
||||
private void renderTexture( int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight )
|
||||
{
|
||||
builder.vertex( transform, x, y + height, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex();
|
||||
builder.vertex( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex();
|
||||
builder.vertex( transform, x + width, y, z ).color( r, g, b, 1.0f ).uv( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).endVertex();
|
||||
builder.vertex( transform, x, y, z ).color( r, g, b, 1.0f ).uv( u * TEX_SCALE, v * TEX_SCALE ).endVertex();
|
||||
builder.pos( transform, x, y + height, z ).color( r, g, b, 1.0f ).tex( u * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex();
|
||||
builder.pos( transform, x + width, y + height, z ).color( r, g, b, 1.0f ).tex( (u + textureWidth) * TEX_SCALE, (v + textureHeight) * TEX_SCALE ).endVertex();
|
||||
builder.pos( transform, x + width, y, z ).color( r, g, b, 1.0f ).tex( (u + textureWidth) * TEX_SCALE, v * TEX_SCALE ).endVertex();
|
||||
builder.pos( transform, x, y, z ).color( r, g, b, 1.0f ).tex( u * TEX_SCALE, v * TEX_SCALE ).endVertex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.renderer.FirstPersonRenderer;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.HandSide;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
|
||||
public abstract class ItemMapLikeRenderer
|
||||
{
|
||||
@@ -33,8 +33,8 @@ public abstract class ItemMapLikeRenderer
|
||||
{
|
||||
PlayerEntity player = Minecraft.getInstance().player;
|
||||
|
||||
transform.pushPose();
|
||||
if( hand == Hand.MAIN_HAND && player.getOffhandItem().isEmpty() )
|
||||
transform.push();
|
||||
if( hand == Hand.MAIN_HAND && player.getHeldItemOffhand().isEmpty() )
|
||||
{
|
||||
renderItemFirstPersonCenter( transform, render, lightTexture, pitch, equipProgress, swingProgress, stack );
|
||||
}
|
||||
@@ -42,11 +42,11 @@ public abstract class ItemMapLikeRenderer
|
||||
{
|
||||
renderItemFirstPersonSide(
|
||||
transform, render, lightTexture,
|
||||
hand == Hand.MAIN_HAND ? player.getMainArm() : player.getMainArm().getOpposite(),
|
||||
hand == Hand.MAIN_HAND ? player.getPrimaryHand() : player.getPrimaryHand().opposite(),
|
||||
equipProgress, swingProgress, stack
|
||||
);
|
||||
}
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,15 +70,15 @@ public abstract class ItemMapLikeRenderer
|
||||
// If the player is not invisible then render a single arm
|
||||
if( !minecraft.player.isInvisible() )
|
||||
{
|
||||
transform.pushPose();
|
||||
transform.mulPose( Vector3f.ZP.rotationDegrees( offset * 10f ) );
|
||||
minecraft.getItemInHandRenderer().renderPlayerArm( transform, render, combinedLight, equipProgress, swingProgress, side );
|
||||
transform.popPose();
|
||||
transform.push();
|
||||
transform.rotate( Vector3f.ZP.rotationDegrees( offset * 10f ) );
|
||||
minecraft.getFirstPersonRenderer().renderArmFirstPerson( transform, render, combinedLight, equipProgress, swingProgress, side );
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
// Setup the appropriate transformations. This is just copied from the
|
||||
// corresponding method in ItemRenderer.
|
||||
transform.pushPose();
|
||||
transform.push();
|
||||
transform.translate( offset * 0.51f, -0.08f + equipProgress * -1.2f, -0.75f );
|
||||
float f1 = MathHelper.sqrt( swingProgress );
|
||||
float f2 = MathHelper.sin( f1 * (float) Math.PI );
|
||||
@@ -86,12 +86,12 @@ public abstract class ItemMapLikeRenderer
|
||||
float f4 = 0.4f * MathHelper.sin( f1 * ((float) Math.PI * 2f) );
|
||||
float f5 = -0.3f * MathHelper.sin( swingProgress * (float) Math.PI );
|
||||
transform.translate( offset * f3, f4 - 0.3f * f2, f5 );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( f2 * -45f ) );
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) );
|
||||
transform.rotate( Vector3f.XP.rotationDegrees( f2 * -45f ) );
|
||||
transform.rotate( Vector3f.YP.rotationDegrees( offset * f2 * -30f ) );
|
||||
|
||||
renderItem( transform, render, stack );
|
||||
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public abstract class ItemMapLikeRenderer
|
||||
private void renderItemFirstPersonCenter( MatrixStack transform, IRenderTypeBuffer render, int combinedLight, float pitch, float equipProgress, float swingProgress, ItemStack stack )
|
||||
{
|
||||
Minecraft minecraft = Minecraft.getInstance();
|
||||
FirstPersonRenderer renderer = minecraft.getItemInHandRenderer();
|
||||
FirstPersonRenderer renderer = minecraft.getFirstPersonRenderer();
|
||||
|
||||
// Setup the appropriate transformations. This is just copied from the
|
||||
// corresponding method in ItemRenderer.
|
||||
@@ -118,20 +118,20 @@ public abstract class ItemMapLikeRenderer
|
||||
float tZ = -0.4f * MathHelper.sin( swingRt * (float) Math.PI );
|
||||
transform.translate( 0, -tX / 2, tZ );
|
||||
|
||||
float pitchAngle = renderer.calculateMapTilt( pitch );
|
||||
float pitchAngle = renderer.getMapAngleFromPitch( pitch );
|
||||
transform.translate( 0, 0.04F + equipProgress * -1.2f + pitchAngle * -0.5f, -0.72f );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( pitchAngle * -85.0f ) );
|
||||
transform.rotate( Vector3f.XP.rotationDegrees( pitchAngle * -85.0f ) );
|
||||
if( !minecraft.player.isInvisible() )
|
||||
{
|
||||
transform.pushPose();
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( 90.0F ) );
|
||||
renderer.renderMapHand( transform, render, combinedLight, HandSide.RIGHT );
|
||||
renderer.renderMapHand( transform, render, combinedLight, HandSide.LEFT );
|
||||
transform.popPose();
|
||||
transform.push();
|
||||
transform.rotate( Vector3f.YP.rotationDegrees( 90.0F ) );
|
||||
renderer.renderArm( transform, render, combinedLight, HandSide.RIGHT );
|
||||
renderer.renderArm( transform, render, combinedLight, HandSide.LEFT );
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
float rX = MathHelper.sin( swingRt * (float) Math.PI );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( rX * 20.0F ) );
|
||||
transform.rotate( Vector3f.XP.rotationDegrees( rX * 20.0F ) );
|
||||
transform.scale( 2.0F, 2.0F, 2.0F );
|
||||
|
||||
renderItem( transform, render, stack );
|
||||
|
||||
@@ -15,9 +15,13 @@ import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
|
||||
import dan200.computercraft.shared.util.Colour;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
@@ -79,9 +83,9 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
|
||||
// Setup various transformations. Note that these are partially adapted from the corresponding method
|
||||
// in ItemRenderer
|
||||
transform.pushPose();
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( 180f ) );
|
||||
transform.mulPose( Vector3f.ZP.rotationDegrees( 180f ) );
|
||||
transform.push();
|
||||
transform.rotate( Vector3f.YP.rotationDegrees( 180f ) );
|
||||
transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) );
|
||||
transform.scale( 0.5f, 0.5f, 0.5f );
|
||||
|
||||
float scale = 0.75f / Math.max( width + BORDER * 2, height + BORDER * 2 + LIGHT_HEIGHT );
|
||||
@@ -93,7 +97,7 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
ComputerFamily family = item.getFamily();
|
||||
int frameColour = item.getColour( stack );
|
||||
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
Matrix4f matrix = transform.getLast().getMatrix();
|
||||
renderFrame( matrix, family, frameColour, width, height );
|
||||
|
||||
// Render the light
|
||||
@@ -110,26 +114,26 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
FixedWidthFontRenderer.drawEmptyTerminal( matrix, 0, 0, width, height );
|
||||
}
|
||||
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
private static void renderFrame( Matrix4f transform, ComputerFamily family, int colour, int width, int height )
|
||||
{
|
||||
RenderSystem.enableBlend();
|
||||
Minecraft.getInstance().getTextureManager()
|
||||
.bind( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) );
|
||||
.bindTexture( colour != -1 ? ComputerBorderRenderer.BACKGROUND_COLOUR : ComputerBorderRenderer.getTexture( family ) );
|
||||
|
||||
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.getBuilder();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR_TEX );
|
||||
|
||||
ComputerBorderRenderer.render( transform, buffer, 0, 0, 0, width, height, LIGHT_HEIGHT, r, g, b );
|
||||
|
||||
tessellator.end();
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
private static void renderLight( Matrix4f transform, int colour, int width, int height )
|
||||
@@ -141,14 +145,14 @@ public final class ItemPocketRenderer extends ItemMapLikeRenderer
|
||||
float b = (colour & 0xFF) / 255.0f;
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuilder();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin( GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR );
|
||||
buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
buffer.vertex( transform, width, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
buffer.vertex( transform, width, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
buffer.vertex( transform, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
buffer.pos( transform, width, height + LIGHT_HEIGHT + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
buffer.pos( transform, width, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
buffer.pos( transform, width - LIGHT_HEIGHT * 2, height + BORDER / 2.0f, 0 ).color( r, g, b, 1.0f ).endVertex();
|
||||
|
||||
tessellator.end();
|
||||
tessellator.draw();
|
||||
RenderSystem.enableTexture();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.media.items.ItemPrintout;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.RenderHandEvent;
|
||||
import net.minecraftforge.client.event.RenderItemInFrameEvent;
|
||||
@@ -52,7 +52,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||
@Override
|
||||
protected void renderItem( MatrixStack transform, IRenderTypeBuffer render, ItemStack stack )
|
||||
{
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( 180f ) );
|
||||
transform.rotate( Vector3f.XP.rotationDegrees( 180f ) );
|
||||
transform.scale( 0.42f, 0.42f, -0.42f );
|
||||
transform.translate( -0.5f, -0.48f, 0.0f );
|
||||
|
||||
@@ -70,7 +70,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||
|
||||
// Move a little bit forward to ensure we're not clipping with the frame
|
||||
transform.translate( 0.0f, 0.0f, -0.001f );
|
||||
transform.mulPose( Vector3f.ZP.rotationDegrees( 180f ) );
|
||||
transform.rotate( Vector3f.ZP.rotationDegrees( 180f ) );
|
||||
transform.scale( 0.95f, 0.95f, -0.95f );
|
||||
transform.translate( -0.5f, -0.5f, 0.0f );
|
||||
|
||||
@@ -104,7 +104,7 @@ public final class ItemPrintoutRenderer extends ItemMapLikeRenderer
|
||||
transform.scale( scale, scale, scale );
|
||||
transform.translate( (max - width) / 2.0, (max - height) / 2.0, 0.0 );
|
||||
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
Matrix4f matrix = transform.getLast().getMatrix();
|
||||
drawBorder( matrix, render, 0, 0, -0.01f, 0, pages, book );
|
||||
drawText( matrix, render,
|
||||
X_TEXT_MARGIN, Y_TEXT_MARGIN, 0, ItemPrintout.getText( stack ), ItemPrintout.getColours( stack )
|
||||
|
||||
@@ -9,12 +9,12 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.vertex.IVertexBuilder;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.DrawHighlightEvent;
|
||||
@@ -40,12 +40,12 @@ public final class MonitorHighlightRenderer
|
||||
public static void drawHighlight( DrawHighlightEvent.HighlightBlock event )
|
||||
{
|
||||
// Preserve normal behaviour when crouching.
|
||||
if( event.getInfo().getEntity().isCrouching() ) return;
|
||||
if( event.getInfo().getRenderViewEntity().isCrouching() ) return;
|
||||
|
||||
World world = event.getInfo().getEntity().getCommandSenderWorld();
|
||||
BlockPos pos = event.getTarget().getBlockPos();
|
||||
World world = event.getInfo().getRenderViewEntity().getEntityWorld();
|
||||
BlockPos pos = event.getTarget().getPos();
|
||||
|
||||
TileEntity tile = world.getBlockEntity( pos );
|
||||
TileEntity tile = world.getTileEntity( pos );
|
||||
if( !(tile instanceof TileMonitor) ) return;
|
||||
|
||||
TileMonitor monitor = (TileMonitor) tile;
|
||||
@@ -61,13 +61,13 @@ public final class MonitorHighlightRenderer
|
||||
if( monitor.getYIndex() != monitor.getHeight() - 1 ) faces.remove( monitor.getDown() );
|
||||
|
||||
MatrixStack transformStack = event.getMatrix();
|
||||
Vec3d cameraPos = event.getInfo().getPosition();
|
||||
transformStack.pushPose();
|
||||
transformStack.translate( pos.getX() - cameraPos.x(), pos.getY() - cameraPos.y(), pos.getZ() - cameraPos.z() );
|
||||
Vector3d cameraPos = event.getInfo().getProjectedView();
|
||||
transformStack.push();
|
||||
transformStack.translate( pos.getX() - cameraPos.getX(), pos.getY() - cameraPos.getY(), pos.getZ() - cameraPos.getZ() );
|
||||
|
||||
// I wish I could think of a better way to do this
|
||||
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.lines() );
|
||||
Matrix4f transform = transformStack.last().pose();
|
||||
IVertexBuilder buffer = event.getBuffers().getBuffer( RenderType.getLines() );
|
||||
Matrix4f transform = transformStack.getLast().getMatrix();
|
||||
if( faces.contains( NORTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 0, UP );
|
||||
if( faces.contains( SOUTH ) || faces.contains( WEST ) ) line( buffer, transform, 0, 0, 1, UP );
|
||||
if( faces.contains( NORTH ) || faces.contains( EAST ) ) line( buffer, transform, 1, 0, 0, UP );
|
||||
@@ -81,16 +81,16 @@ public final class MonitorHighlightRenderer
|
||||
if( faces.contains( WEST ) || faces.contains( UP ) ) line( buffer, transform, 0, 1, 0, SOUTH );
|
||||
if( faces.contains( EAST ) || faces.contains( UP ) ) line( buffer, transform, 1, 1, 0, SOUTH );
|
||||
|
||||
transformStack.popPose();
|
||||
transformStack.pop();
|
||||
}
|
||||
|
||||
private static void line( IVertexBuilder buffer, Matrix4f transform, float x, float y, float z, Direction direction )
|
||||
{
|
||||
buffer.vertex( transform, x, y, z ).color( 0, 0, 0, 0.4f ).endVertex();
|
||||
buffer.vertex( transform,
|
||||
x + direction.getStepX(),
|
||||
y + direction.getStepY(),
|
||||
z + direction.getStepZ()
|
||||
buffer.pos( transform, x, y, z ).color( 0, 0, 0, 0.4f ).endVertex();
|
||||
buffer.pos( transform,
|
||||
x + direction.getXOffset(),
|
||||
y + direction.getYOffset(),
|
||||
z + direction.getZOffset()
|
||||
).color( 0, 0, 0, 0.4f ).endVertex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
@@ -42,7 +42,7 @@ class MonitorTextureBufferShader
|
||||
static void setupUniform( Matrix4f transform, int width, int height, Palette palette, boolean greyscale )
|
||||
{
|
||||
MATRIX_BUFFER.rewind();
|
||||
transform.store( MATRIX_BUFFER );
|
||||
transform.write( MATRIX_BUFFER );
|
||||
MATRIX_BUFFER.rewind();
|
||||
RenderSystem.glUniformMatrix4( uniformMv, false, MATRIX_BUFFER );
|
||||
|
||||
@@ -71,7 +71,7 @@ class MonitorTextureBufferShader
|
||||
{
|
||||
if( initialised )
|
||||
{
|
||||
if( ok ) GlStateManager._glUseProgram( program );
|
||||
if( ok ) GlStateManager.useProgram( program );
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -94,14 +94,14 @@ class MonitorTextureBufferShader
|
||||
int vertexShader = loadShader( GL20.GL_VERTEX_SHADER, "assets/computercraft/shaders/monitor.vert" );
|
||||
int fragmentShader = loadShader( GL20.GL_FRAGMENT_SHADER, "assets/computercraft/shaders/monitor.frag" );
|
||||
|
||||
program = GlStateManager.glCreateProgram();
|
||||
GlStateManager.glAttachShader( program, vertexShader );
|
||||
GlStateManager.glAttachShader( program, fragmentShader );
|
||||
program = GlStateManager.createProgram();
|
||||
GlStateManager.attachShader( program, vertexShader );
|
||||
GlStateManager.attachShader( program, fragmentShader );
|
||||
GL20.glBindAttribLocation( program, 0, "v_pos" );
|
||||
|
||||
GlStateManager.glLinkProgram( program );
|
||||
boolean ok = GlStateManager.glGetProgrami( program, GL20.GL_LINK_STATUS ) != 0;
|
||||
String log = GlStateManager.glGetProgramInfoLog( program, Short.MAX_VALUE ).trim();
|
||||
GlStateManager.linkProgram( program );
|
||||
boolean ok = GlStateManager.getProgram( program, GL20.GL_LINK_STATUS ) != 0;
|
||||
String log = GlStateManager.getProgramInfoLog( program, Short.MAX_VALUE ).trim();
|
||||
if( !Strings.isNullOrEmpty( log ) )
|
||||
{
|
||||
ComputerCraft.log.warn( "Problems when linking monitor shader: {}", log );
|
||||
@@ -109,8 +109,8 @@ class MonitorTextureBufferShader
|
||||
|
||||
GL20.glDetachShader( program, vertexShader );
|
||||
GL20.glDetachShader( program, fragmentShader );
|
||||
GlStateManager.glDeleteShader( vertexShader );
|
||||
GlStateManager.glDeleteShader( fragmentShader );
|
||||
GlStateManager.deleteShader( vertexShader );
|
||||
GlStateManager.deleteShader( fragmentShader );
|
||||
|
||||
if( !ok ) return false;
|
||||
|
||||
@@ -137,13 +137,13 @@ class MonitorTextureBufferShader
|
||||
if( stream == null ) throw new IllegalArgumentException( "Cannot find " + path );
|
||||
String contents = TextureUtil.readResourceAsString( stream );
|
||||
|
||||
int shader = GlStateManager.glCreateShader( kind );
|
||||
int shader = GlStateManager.createShader( kind );
|
||||
|
||||
GlStateManager.glShaderSource( shader, contents );
|
||||
GlStateManager.glCompileShader( shader );
|
||||
GlStateManager.shaderSource( shader, contents );
|
||||
GlStateManager.compileShader( shader );
|
||||
|
||||
boolean ok = GlStateManager.glGetShaderi( shader, GL20.GL_COMPILE_STATUS ) != 0;
|
||||
String log = GlStateManager.glGetShaderInfoLog( shader, Short.MAX_VALUE ).trim();
|
||||
boolean ok = GlStateManager.getShader( shader, GL20.GL_COMPILE_STATUS ) != 0;
|
||||
String log = GlStateManager.getShaderInfoLog( shader, Short.MAX_VALUE ).trim();
|
||||
if( !Strings.isNullOrEmpty( log ) )
|
||||
{
|
||||
ComputerCraft.log.warn( "Problems when loading monitor shader {}: {}", path, log );
|
||||
@@ -155,7 +155,7 @@ class MonitorTextureBufferShader
|
||||
|
||||
private static int getUniformLocation( int program, String name )
|
||||
{
|
||||
int uniform = GlStateManager._glGetUniformLocation( program, name );
|
||||
int uniform = GlStateManager.getUniformLocation( program, name );
|
||||
if( uniform == -1 ) throw new IllegalStateException( "Cannot find uniform " + name );
|
||||
return uniform;
|
||||
}
|
||||
|
||||
@@ -10,11 +10,11 @@ import dan200.computercraft.client.gui.FixedWidthFontRenderer;
|
||||
import dan200.computercraft.core.terminal.TextBuffer;
|
||||
import dan200.computercraft.shared.util.Palette;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.RenderState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import static dan200.computercraft.client.gui.FixedWidthFontRenderer.FONT_HEIGHT;
|
||||
@@ -146,18 +146,18 @@ public final class PrintoutRenderer
|
||||
|
||||
private static void drawTexture( Matrix4f matrix, IVertexBuilder buffer, float x, float y, float z, float u, float v, float width, float height )
|
||||
{
|
||||
buffer.vertex( matrix, x, y + height, z ).uv( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
||||
buffer.vertex( matrix, x + width, y + height, z ).uv( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
||||
buffer.vertex( matrix, x + width, y, z ).uv( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
buffer.vertex( matrix, x, y, z ).uv( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x, y + height, z ).tex( u / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x + width, y + height, z ).tex( (u + width) / BG_SIZE, (v + height) / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x + width, y, z ).tex( (u + width) / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
}
|
||||
|
||||
private static void drawTexture( Matrix4f matrix, IVertexBuilder buffer, float x, float y, float z, float width, float height, float u, float v, float tWidth, float tHeight )
|
||||
{
|
||||
buffer.vertex( matrix, x, y + height, z ).uv( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
||||
buffer.vertex( matrix, x + width, y + height, z ).uv( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
||||
buffer.vertex( matrix, x + width, y, z ).uv( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
buffer.vertex( matrix, x, y, z ).uv( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x, y + height, z ).tex( u / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x + width, y + height, z ).tex( (u + tWidth) / BG_SIZE, (v + tHeight) / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x + width, y, z ).tex( (u + tWidth) / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
buffer.pos( matrix, x, y, z ).tex( u / BG_SIZE, v / BG_SIZE ).endVertex();
|
||||
}
|
||||
|
||||
public static float offsetAt( int page )
|
||||
@@ -167,14 +167,14 @@ public final class PrintoutRenderer
|
||||
|
||||
private static final class Type extends RenderState
|
||||
{
|
||||
static final RenderType TYPE = RenderType.create(
|
||||
static final RenderType TYPE = RenderType.makeType(
|
||||
"printout_background", DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 1024,
|
||||
false, false, // useDelegate, needsSorting
|
||||
RenderType.State.builder()
|
||||
.setTextureState( new RenderState.TextureState( BG, false, false ) ) // blur, minimap
|
||||
.setAlphaState( DEFAULT_ALPHA )
|
||||
.setLightmapState( NO_LIGHTMAP )
|
||||
.createCompositeState( false )
|
||||
RenderType.State.getBuilder()
|
||||
.texture( new RenderState.TextureState( BG, false, false ) ) // blur, minimap
|
||||
.alpha( DEFAULT_ALPHA )
|
||||
.lightmap( LIGHTMAP_DISABLED )
|
||||
.build( false )
|
||||
);
|
||||
|
||||
private Type( String name, Runnable setup, Runnable destroy )
|
||||
|
||||
@@ -24,6 +24,9 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.client.renderer.vertex.VertexBuffer;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL13;
|
||||
import org.lwjgl.opengl.GL20;
|
||||
@@ -58,7 +61,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
|
||||
if( originTerminal == null ) return;
|
||||
TileMonitor origin = originTerminal.getOrigin();
|
||||
BlockPos monitorPos = monitor.getBlockPos();
|
||||
BlockPos monitorPos = monitor.getPos();
|
||||
|
||||
// Ensure each monitor terminal is rendered only once. We allow rendering a specific tile
|
||||
// multiple times in a single frame to ensure compatibility with shaders which may run a
|
||||
@@ -72,24 +75,24 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
originTerminal.lastRenderFrame = renderFrame;
|
||||
originTerminal.lastRenderPos = monitorPos;
|
||||
|
||||
BlockPos originPos = origin.getBlockPos();
|
||||
BlockPos originPos = origin.getPos();
|
||||
|
||||
// Determine orientation
|
||||
Direction dir = origin.getDirection();
|
||||
Direction front = origin.getFront();
|
||||
float yaw = dir.toYRot();
|
||||
float yaw = dir.getHorizontalAngle();
|
||||
float pitch = DirectionUtil.toPitchAngle( front );
|
||||
|
||||
// Setup initial transform
|
||||
transform.pushPose();
|
||||
transform.push();
|
||||
transform.translate(
|
||||
originPos.getX() - monitorPos.getX() + 0.5,
|
||||
originPos.getY() - monitorPos.getY() + 0.5,
|
||||
originPos.getZ() - monitorPos.getZ() + 0.5
|
||||
);
|
||||
|
||||
transform.mulPose( Vector3f.YN.rotationDegrees( yaw ) );
|
||||
transform.mulPose( Vector3f.XP.rotationDegrees( pitch ) );
|
||||
transform.rotate( Vector3f.YN.rotationDegrees( yaw ) );
|
||||
transform.rotate( Vector3f.XP.rotationDegrees( pitch ) );
|
||||
transform.translate(
|
||||
-0.5 + TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN,
|
||||
origin.getHeight() - 0.5 - (TileMonitor.RENDER_BORDER + TileMonitor.RENDER_MARGIN) + 0,
|
||||
@@ -107,10 +110,10 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
int pixelWidth = width * FONT_WIDTH, pixelHeight = height * FONT_HEIGHT;
|
||||
double xScale = xSize / pixelWidth;
|
||||
double yScale = ySize / pixelHeight;
|
||||
transform.pushPose();
|
||||
transform.push();
|
||||
transform.scale( (float) xScale, (float) -yScale, 1.0f );
|
||||
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
Matrix4f matrix = transform.getLast().getMatrix();
|
||||
|
||||
// Sneaky hack here: we get a buffer now in order to flush existing ones and set up the appropriate
|
||||
// render state. I've no clue how well this'll work in future versions of Minecraft, but it does the trick
|
||||
@@ -124,24 +127,28 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
// reasonable.
|
||||
FixedWidthFontRenderer.drawCursor( matrix, buffer, 0, 0, terminal, !originTerminal.isColour() );
|
||||
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
}
|
||||
else
|
||||
{
|
||||
FixedWidthFontRenderer.drawEmptyTerminal(
|
||||
transform.last().pose(), renderer,
|
||||
transform.getLast().getMatrix(), renderer,
|
||||
-MARGIN, MARGIN,
|
||||
(float) (xSize + 2 * MARGIN), (float) -(ySize + MARGIN * 2)
|
||||
);
|
||||
}
|
||||
|
||||
FixedWidthFontRenderer.drawBlocker(
|
||||
transform.last().pose(), renderer,
|
||||
transform.getLast().getMatrix(), renderer,
|
||||
(float) -TileMonitor.RENDER_MARGIN, (float) TileMonitor.RENDER_MARGIN,
|
||||
(float) (xSize + 2 * TileMonitor.RENDER_MARGIN), (float) -(ySize + TileMonitor.RENDER_MARGIN * 2)
|
||||
);
|
||||
|
||||
transform.popPose();
|
||||
// Force a flush of the blocker. WorldRenderer.updateCameraAndRender will "finish" all the built-in
|
||||
// buffers before calling renderer.finish, which means the blocker isn't actually rendered at that point!
|
||||
renderer.getBuffer( RenderType.getSolid() );
|
||||
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
private static void renderTerminal( Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin )
|
||||
@@ -166,7 +173,7 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
int size = width * height * 3;
|
||||
if( tboContents == null || tboContents.capacity() < size )
|
||||
{
|
||||
tboContents = GLAllocation.createByteBuffer( size );
|
||||
tboContents = GLAllocation.createDirectByteBuffer( size );
|
||||
}
|
||||
|
||||
ByteBuffer monitorBuffer = tboContents;
|
||||
@@ -183,28 +190,28 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
}
|
||||
monitorBuffer.flip();
|
||||
|
||||
GlStateManager._glBindBuffer( GL31.GL_TEXTURE_BUFFER, monitor.tboBuffer );
|
||||
GlStateManager._glBufferData( GL31.GL_TEXTURE_BUFFER, monitorBuffer, GL20.GL_STATIC_DRAW );
|
||||
GlStateManager._glBindBuffer( GL31.GL_TEXTURE_BUFFER, 0 );
|
||||
GlStateManager.bindBuffer( GL31.GL_TEXTURE_BUFFER, monitor.tboBuffer );
|
||||
GlStateManager.bufferData( GL31.GL_TEXTURE_BUFFER, monitorBuffer, GL20.GL_STATIC_DRAW );
|
||||
GlStateManager.bindBuffer( GL31.GL_TEXTURE_BUFFER, 0 );
|
||||
}
|
||||
|
||||
// Nobody knows what they're doing!
|
||||
GlStateManager._activeTexture( MonitorTextureBufferShader.TEXTURE_INDEX );
|
||||
GlStateManager.activeTexture( MonitorTextureBufferShader.TEXTURE_INDEX );
|
||||
GL11.glBindTexture( GL31.GL_TEXTURE_BUFFER, monitor.tboTexture );
|
||||
GlStateManager._activeTexture( GL13.GL_TEXTURE0 );
|
||||
GlStateManager.activeTexture( GL13.GL_TEXTURE0 );
|
||||
|
||||
MonitorTextureBufferShader.setupUniform( matrix, width, height, terminal.getPalette(), !monitor.isColour() );
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuilder();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin( GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION );
|
||||
buffer.vertex( -xMargin, -yMargin, 0 ).endVertex();
|
||||
buffer.vertex( -xMargin, pixelHeight + yMargin, 0 ).endVertex();
|
||||
buffer.vertex( pixelWidth + xMargin, -yMargin, 0 ).endVertex();
|
||||
buffer.vertex( pixelWidth + xMargin, pixelHeight + yMargin, 0 ).endVertex();
|
||||
tessellator.end();
|
||||
buffer.pos( -xMargin, -yMargin, 0 ).endVertex();
|
||||
buffer.pos( -xMargin, pixelHeight + yMargin, 0 ).endVertex();
|
||||
buffer.pos( pixelWidth + xMargin, -yMargin, 0 ).endVertex();
|
||||
buffer.pos( pixelWidth + xMargin, pixelHeight + yMargin, 0 ).endVertex();
|
||||
tessellator.draw();
|
||||
|
||||
GlStateManager._glUseProgram( 0 );
|
||||
GlStateManager.useProgram( 0 );
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -214,22 +221,22 @@ public class TileEntityMonitorRenderer extends TileEntityRenderer<TileMonitor>
|
||||
if( redraw )
|
||||
{
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder builder = tessellator.getBuilder();
|
||||
builder.begin( FixedWidthFontRenderer.TYPE.mode(), FixedWidthFontRenderer.TYPE.format() );
|
||||
BufferBuilder builder = tessellator.getBuffer();
|
||||
builder.begin( FixedWidthFontRenderer.TYPE.getDrawMode(), FixedWidthFontRenderer.TYPE.getVertexFormat() );
|
||||
FixedWidthFontRenderer.drawTerminalWithoutCursor(
|
||||
IDENTITY, builder, 0, 0,
|
||||
terminal, !monitor.isColour(), yMargin, yMargin, xMargin, xMargin
|
||||
);
|
||||
|
||||
builder.end();
|
||||
builder.finishDrawing();
|
||||
vbo.upload( builder );
|
||||
}
|
||||
|
||||
vbo.bind();
|
||||
FixedWidthFontRenderer.TYPE.format().setupBufferState( 0L );
|
||||
vbo.draw( matrix, FixedWidthFontRenderer.TYPE.mode() );
|
||||
VertexBuffer.unbind();
|
||||
FixedWidthFontRenderer.TYPE.format().clearBufferState();
|
||||
vbo.bindBuffer();
|
||||
FixedWidthFontRenderer.TYPE.getVertexFormat().setupBufferState( 0L );
|
||||
vbo.draw( matrix, FixedWidthFontRenderer.TYPE.getDrawMode() );
|
||||
VertexBuffer.unbindBuffer();
|
||||
FixedWidthFontRenderer.TYPE.getVertexFormat().clearBufferState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.Atlases;
|
||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||
import net.minecraft.client.renderer.Matrix4f;
|
||||
import net.minecraft.client.renderer.Vector3f;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ModelManager;
|
||||
@@ -31,7 +29,9 @@ import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
import net.minecraft.util.math.vector.Vector3f;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -72,39 +72,39 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull MatrixStack transform, @Nonnull IRenderTypeBuffer buffers, int lightmapCoord, int overlayLight )
|
||||
public void render( @Nonnull TileTurtle turtle, float partialTicks, @Nonnull MatrixStack transform, @Nonnull IRenderTypeBuffer renderer, int lightmapCoord, int overlayLight )
|
||||
{
|
||||
// Render the label
|
||||
String label = turtle.createProxy().getLabel();
|
||||
RayTraceResult hit = renderer.cameraHitResult;
|
||||
if( label != null && hit.getType() == RayTraceResult.Type.BLOCK && turtle.getBlockPos().equals( ((BlockRayTraceResult) hit).getBlockPos() ) )
|
||||
RayTraceResult hit = renderDispatcher.cameraHitResult;
|
||||
if( label != null && hit.getType() == RayTraceResult.Type.BLOCK && turtle.getPos().equals( ((BlockRayTraceResult) hit).getPos() ) )
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
FontRenderer font = renderer.font;
|
||||
FontRenderer font = renderDispatcher.fontRenderer;
|
||||
|
||||
transform.pushPose();
|
||||
transform.push();
|
||||
transform.translate( 0.5, 1.2, 0.5 );
|
||||
transform.mulPose( mc.getEntityRenderDispatcher().cameraOrientation() );
|
||||
transform.rotate( mc.getRenderManager().getCameraOrientation() );
|
||||
transform.scale( -0.025f, -0.025f, 0.025f );
|
||||
|
||||
Matrix4f matrix = transform.last().pose();
|
||||
int opacity = (int) (mc.options.getBackgroundOpacity( 0.25f ) * 255) << 24;
|
||||
float width = -font.width( label ) / 2.0f;
|
||||
font.drawInBatch( label, width, (float) 0, 0x20ffffff, false, matrix, buffers, true, opacity, lightmapCoord );
|
||||
font.drawInBatch( label, width, (float) 0, 0xffffffff, false, matrix, buffers, false, 0, lightmapCoord );
|
||||
Matrix4f matrix = transform.getLast().getMatrix();
|
||||
int opacity = (int) (mc.gameSettings.getTextBackgroundOpacity( 0.25f ) * 255) << 24;
|
||||
float width = -font.getStringWidth( label ) / 2.0f;
|
||||
font.renderString( label, width, (float) 0, 0x20ffffff, false, matrix, renderer, true, opacity, lightmapCoord );
|
||||
font.renderString( label, width, (float) 0, 0xffffffff, false, matrix, renderer, false, 0, lightmapCoord );
|
||||
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
transform.pushPose();
|
||||
transform.push();
|
||||
|
||||
// Setup the transform.
|
||||
Vec3d offset = turtle.getRenderOffset( partialTicks );
|
||||
Vector3d offset = turtle.getRenderOffset( partialTicks );
|
||||
float yaw = turtle.getRenderYaw( partialTicks );
|
||||
transform.translate( offset.x, offset.y, offset.z );
|
||||
|
||||
transform.translate( 0.5f, 0.5f, 0.5f );
|
||||
transform.mulPose( Vector3f.YP.rotationDegrees( 180.0f - yaw ) );
|
||||
transform.rotate( Vector3f.YP.rotationDegrees( 180.0f - yaw ) );
|
||||
if( label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" )) )
|
||||
{
|
||||
// Flip the model
|
||||
@@ -117,7 +117,7 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
||||
ComputerFamily family = turtle.getFamily();
|
||||
ResourceLocation overlay = turtle.getOverlay();
|
||||
|
||||
IVertexBuilder buffer = buffers.getBuffer( Atlases.translucentCullBlockSheet() );
|
||||
IVertexBuilder buffer = renderer.getBuffer( Atlases.getTranslucentCullBlockType() );
|
||||
renderModel( transform, buffer, lightmapCoord, overlayLight, getTurtleModel( family, colour != -1 ), colour == -1 ? null : new int[] { colour } );
|
||||
|
||||
// Render the overlay
|
||||
@@ -131,31 +131,31 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
||||
renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.LEFT, partialTicks );
|
||||
renderUpgrade( transform, buffer, lightmapCoord, overlayLight, turtle, TurtleSide.RIGHT, partialTicks );
|
||||
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
private void renderUpgrade( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, TileTurtle turtle, TurtleSide side, float f )
|
||||
{
|
||||
ITurtleUpgrade upgrade = turtle.getUpgrade( side );
|
||||
if( upgrade == null ) return;
|
||||
transform.pushPose();
|
||||
transform.push();
|
||||
|
||||
float toolAngle = turtle.getToolRenderAngle( side, f );
|
||||
transform.translate( 0.0f, 0.5f, 0.5f );
|
||||
transform.mulPose( Vector3f.XN.rotationDegrees( toolAngle ) );
|
||||
transform.rotate( Vector3f.XN.rotationDegrees( toolAngle ) );
|
||||
transform.translate( 0.0f, -0.5f, -0.5f );
|
||||
|
||||
TransformedModel model = upgrade.getModel( turtle.getAccess(), side );
|
||||
model.getMatrix().push( transform );
|
||||
renderModel( transform, renderer, lightmapCoord, overlayLight, model.getModel(), null );
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
|
||||
transform.popPose();
|
||||
transform.pop();
|
||||
}
|
||||
|
||||
private void renderModel( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder renderer, int lightmapCoord, int overlayLight, ModelResourceLocation modelLocation, int[] tints )
|
||||
{
|
||||
ModelManager modelManager = Minecraft.getInstance().getItemRenderer().getItemModelShaper().getModelManager();
|
||||
ModelManager modelManager = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getModelManager();
|
||||
renderModel( transform, renderer, lightmapCoord, overlayLight, modelManager.getModel( modelLocation ), tints );
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ public class TileEntityTurtleRenderer extends TileEntityRenderer<TileTurtle>
|
||||
|
||||
private static void renderQuads( @Nonnull MatrixStack transform, @Nonnull IVertexBuilder buffer, int lightmapCoord, int overlayLight, List<BakedQuad> quads, int[] tints )
|
||||
{
|
||||
MatrixStack.Entry matrix = transform.last();
|
||||
MatrixStack.Entry matrix = transform.getLast();
|
||||
|
||||
for( BakedQuad bakedquad : quads )
|
||||
{
|
||||
int tint = -1;
|
||||
if( tints != null && bakedquad.isTinted() )
|
||||
if( tints != null && bakedquad.hasTintIndex() )
|
||||
{
|
||||
int idx = bakedquad.getTintIndex();
|
||||
if( idx >= 0 && idx < tints.length ) tint = tints[bakedquad.getTintIndex()];
|
||||
|
||||
@@ -43,7 +43,7 @@ public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.T
|
||||
@Override
|
||||
public TurtleModel read( @Nonnull JsonDeserializationContext deserializationContext, @Nonnull JsonObject modelContents )
|
||||
{
|
||||
ResourceLocation model = new ResourceLocation( JSONUtils.getAsString( modelContents, "model" ) );
|
||||
ResourceLocation model = new ResourceLocation( JSONUtils.getString( modelContents, "model" ) );
|
||||
return new TurtleModel( model );
|
||||
}
|
||||
|
||||
@@ -57,16 +57,16 @@ public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.T
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Material> getTextures( IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors )
|
||||
public Collection<RenderMaterial> getTextures( IModelConfiguration owner, Function<ResourceLocation, IUnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors )
|
||||
{
|
||||
Set<Material> materials = new HashSet<>();
|
||||
materials.addAll( modelGetter.apply( family ).getMaterials( modelGetter, missingTextureErrors ) );
|
||||
materials.addAll( modelGetter.apply( COLOUR_TURTLE_MODEL ).getMaterials( modelGetter, missingTextureErrors ) );
|
||||
Set<RenderMaterial> materials = new HashSet<>();
|
||||
materials.addAll( modelGetter.apply( family ).getTextures( modelGetter, missingTextureErrors ) );
|
||||
materials.addAll( modelGetter.apply( COLOUR_TURTLE_MODEL ).getTextures( modelGetter, missingTextureErrors ) );
|
||||
return materials;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel bake( IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, IModelTransform transform, ItemOverrideList overrides, ResourceLocation modelLocation )
|
||||
public IBakedModel bake( IModelConfiguration owner, ModelBakery bakery, Function<RenderMaterial, TextureAtlasSprite> spriteGetter, IModelTransform transform, ItemOverrideList overrides, ResourceLocation modelLocation )
|
||||
{
|
||||
return new TurtleSmartItemModel(
|
||||
bakery.getBakedModel( family, transform, spriteGetter ),
|
||||
|
||||
@@ -7,12 +7,12 @@ package dan200.computercraft.client.render;
|
||||
|
||||
import dan200.computercraft.api.client.TransformedModel;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.model.IBakedModel;
|
||||
import net.minecraft.client.renderer.model.ItemOverrideList;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import net.minecraftforge.client.model.data.EmptyModelData;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
@@ -23,22 +23,22 @@ import java.util.*;
|
||||
|
||||
public class TurtleMultiModel implements IBakedModel
|
||||
{
|
||||
private final IBakedModel baseModel;
|
||||
private final IBakedModel overlayModel;
|
||||
private final TransformationMatrix generalTransform;
|
||||
private final TransformedModel leftUpgradeModel;
|
||||
private final TransformedModel rightUpgradeModel;
|
||||
private List<BakedQuad> generalQuads = null;
|
||||
private final Map<Direction, List<BakedQuad>> faceQuads = new EnumMap<>( Direction.class );
|
||||
private final IBakedModel m_baseModel;
|
||||
private final IBakedModel m_overlayModel;
|
||||
private final TransformationMatrix m_generalTransform;
|
||||
private final TransformedModel m_leftUpgradeModel;
|
||||
private final TransformedModel m_rightUpgradeModel;
|
||||
private List<BakedQuad> m_generalQuads = null;
|
||||
private Map<Direction, List<BakedQuad>> m_faceQuads = new EnumMap<>( Direction.class );
|
||||
|
||||
public TurtleMultiModel( IBakedModel baseModel, IBakedModel overlayModel, TransformationMatrix generalTransform, TransformedModel leftUpgradeModel, TransformedModel rightUpgradeModel )
|
||||
{
|
||||
// Get the models
|
||||
this.baseModel = baseModel;
|
||||
this.overlayModel = overlayModel;
|
||||
this.leftUpgradeModel = leftUpgradeModel;
|
||||
this.rightUpgradeModel = rightUpgradeModel;
|
||||
this.generalTransform = generalTransform;
|
||||
m_baseModel = baseModel;
|
||||
m_overlayModel = overlayModel;
|
||||
m_leftUpgradeModel = leftUpgradeModel;
|
||||
m_rightUpgradeModel = rightUpgradeModel;
|
||||
m_generalTransform = generalTransform;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@@ -55,13 +55,13 @@ public class TurtleMultiModel implements IBakedModel
|
||||
{
|
||||
if( side != null )
|
||||
{
|
||||
if( !faceQuads.containsKey( side ) ) faceQuads.put( side, buildQuads( state, side, rand ) );
|
||||
return faceQuads.get( side );
|
||||
if( !m_faceQuads.containsKey( side ) ) m_faceQuads.put( side, buildQuads( state, side, rand ) );
|
||||
return m_faceQuads.get( side );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( generalQuads == null ) generalQuads = buildQuads( state, side, rand );
|
||||
return generalQuads;
|
||||
if( m_generalQuads == null ) m_generalQuads = buildQuads( state, side, rand );
|
||||
return m_generalQuads;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,63 +70,63 @@ public class TurtleMultiModel implements IBakedModel
|
||||
ArrayList<BakedQuad> quads = new ArrayList<>();
|
||||
|
||||
|
||||
transformQuadsTo( quads, baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), generalTransform );
|
||||
if( overlayModel != null )
|
||||
transformQuadsTo( quads, m_baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform );
|
||||
if( m_overlayModel != null )
|
||||
{
|
||||
transformQuadsTo( quads, overlayModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), generalTransform );
|
||||
transformQuadsTo( quads, m_overlayModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), m_generalTransform );
|
||||
}
|
||||
if( leftUpgradeModel != null )
|
||||
if( m_leftUpgradeModel != null )
|
||||
{
|
||||
TransformationMatrix upgradeTransform = generalTransform.compose( leftUpgradeModel.getMatrix() );
|
||||
transformQuadsTo( quads, leftUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
||||
TransformationMatrix upgradeTransform = m_generalTransform.compose( m_leftUpgradeModel.getMatrix() );
|
||||
transformQuadsTo( quads, m_leftUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
||||
}
|
||||
if( rightUpgradeModel != null )
|
||||
if( m_rightUpgradeModel != null )
|
||||
{
|
||||
TransformationMatrix upgradeTransform = generalTransform.compose( rightUpgradeModel.getMatrix() );
|
||||
transformQuadsTo( quads, rightUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
||||
TransformationMatrix upgradeTransform = m_generalTransform.compose( m_rightUpgradeModel.getMatrix() );
|
||||
transformQuadsTo( quads, m_rightUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
|
||||
}
|
||||
quads.trimToSize();
|
||||
return quads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return baseModel.useAmbientOcclusion();
|
||||
return m_baseModel.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return baseModel.isGui3d();
|
||||
return m_baseModel.isGui3d();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomRenderer()
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return baseModel.isCustomRenderer();
|
||||
return m_baseModel.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockLight()
|
||||
public boolean isSideLit()
|
||||
{
|
||||
return baseModel.usesBlockLight();
|
||||
return m_baseModel.isSideLit();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return baseModel.getParticleIcon();
|
||||
return m_baseModel.getParticleTexture();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public net.minecraft.client.renderer.model.ItemCameraTransforms getTransforms()
|
||||
public net.minecraft.client.renderer.model.ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return baseModel.getTransforms();
|
||||
return m_baseModel.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TurtlePlayerRenderer extends EntityRenderer<TurtlePlayer>
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getTextureLocation( @Nonnull TurtlePlayer entity )
|
||||
public ResourceLocation getEntityTexture( @Nonnull TurtlePlayer entity )
|
||||
{
|
||||
return ComputerBorderRenderer.BACKGROUND_NORMAL;
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ import dan200.computercraft.shared.util.Holiday;
|
||||
import dan200.computercraft.shared.util.HolidayUtil;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.TransformationMatrix;
|
||||
import net.minecraft.client.renderer.model.*;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.util.math.vector.TransformationMatrix;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -42,26 +42,26 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
stack.translate( 0, 0, 1 );
|
||||
|
||||
identity = TransformationMatrix.identity();
|
||||
flip = new TransformationMatrix( stack.last().pose() );
|
||||
flip = new TransformationMatrix( stack.getLast().getMatrix() );
|
||||
}
|
||||
|
||||
private static class TurtleModelCombination
|
||||
{
|
||||
final boolean colour;
|
||||
final ITurtleUpgrade leftUpgrade;
|
||||
final ITurtleUpgrade rightUpgrade;
|
||||
final ResourceLocation overlay;
|
||||
final boolean christmas;
|
||||
final boolean flip;
|
||||
final boolean m_colour;
|
||||
final ITurtleUpgrade m_leftUpgrade;
|
||||
final ITurtleUpgrade m_rightUpgrade;
|
||||
final ResourceLocation m_overlay;
|
||||
final boolean m_christmas;
|
||||
final boolean m_flip;
|
||||
|
||||
TurtleModelCombination( boolean colour, ITurtleUpgrade leftUpgrade, ITurtleUpgrade rightUpgrade, ResourceLocation overlay, boolean christmas, boolean flip )
|
||||
{
|
||||
this.colour = colour;
|
||||
this.leftUpgrade = leftUpgrade;
|
||||
this.rightUpgrade = rightUpgrade;
|
||||
this.overlay = overlay;
|
||||
this.christmas = christmas;
|
||||
this.flip = flip;
|
||||
m_colour = colour;
|
||||
m_leftUpgrade = leftUpgrade;
|
||||
m_rightUpgrade = rightUpgrade;
|
||||
m_overlay = overlay;
|
||||
m_christmas = christmas;
|
||||
m_flip = flip;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -71,12 +71,12 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
if( !(other instanceof TurtleModelCombination) ) return false;
|
||||
|
||||
TurtleModelCombination otherCombo = (TurtleModelCombination) other;
|
||||
return otherCombo.colour == colour &&
|
||||
otherCombo.leftUpgrade == leftUpgrade &&
|
||||
otherCombo.rightUpgrade == rightUpgrade &&
|
||||
Objects.equal( otherCombo.overlay, overlay ) &&
|
||||
otherCombo.christmas == christmas &&
|
||||
otherCombo.flip == flip;
|
||||
return otherCombo.m_colour == m_colour &&
|
||||
otherCombo.m_leftUpgrade == m_leftUpgrade &&
|
||||
otherCombo.m_rightUpgrade == m_rightUpgrade &&
|
||||
Objects.equal( otherCombo.m_overlay, m_overlay ) &&
|
||||
otherCombo.m_christmas == m_christmas &&
|
||||
otherCombo.m_flip == m_flip;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,12 +84,12 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 0;
|
||||
result = prime * result + (colour ? 1 : 0);
|
||||
result = prime * result + (leftUpgrade != null ? leftUpgrade.hashCode() : 0);
|
||||
result = prime * result + (rightUpgrade != null ? rightUpgrade.hashCode() : 0);
|
||||
result = prime * result + (overlay != null ? overlay.hashCode() : 0);
|
||||
result = prime * result + (christmas ? 1 : 0);
|
||||
result = prime * result + (flip ? 1 : 0);
|
||||
result = prime * result + (m_colour ? 1 : 0);
|
||||
result = prime * result + (m_leftUpgrade != null ? m_leftUpgrade.hashCode() : 0);
|
||||
result = prime * result + (m_rightUpgrade != null ? m_rightUpgrade.hashCode() : 0);
|
||||
result = prime * result + (m_overlay != null ? m_overlay.hashCode() : 0);
|
||||
result = prime * result + (m_christmas ? 1 : 0);
|
||||
result = prime * result + (m_flip ? 1 : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -97,19 +97,19 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
private final IBakedModel familyModel;
|
||||
private final IBakedModel colourModel;
|
||||
|
||||
private final HashMap<TurtleModelCombination, IBakedModel> cachedModels = new HashMap<>();
|
||||
private final ItemOverrideList overrides;
|
||||
private final HashMap<TurtleModelCombination, IBakedModel> m_cachedModels = new HashMap<>();
|
||||
private final ItemOverrideList m_overrides;
|
||||
|
||||
public TurtleSmartItemModel( IBakedModel familyModel, IBakedModel colourModel )
|
||||
{
|
||||
this.familyModel = familyModel;
|
||||
this.colourModel = colourModel;
|
||||
|
||||
overrides = new ItemOverrideList()
|
||||
m_overrides = new ItemOverrideList()
|
||||
{
|
||||
@Nonnull
|
||||
@Override
|
||||
public IBakedModel resolve( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable LivingEntity entity )
|
||||
public IBakedModel getOverrideModel( @Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity )
|
||||
{
|
||||
ItemTurtle turtle = (ItemTurtle) stack.getItem();
|
||||
int colour = turtle.getColour( stack );
|
||||
@@ -121,8 +121,8 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
|
||||
TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
|
||||
|
||||
IBakedModel model = cachedModels.get( combo );
|
||||
if( model == null ) cachedModels.put( combo, model = buildModel( combo ) );
|
||||
IBakedModel model = m_cachedModels.get( combo );
|
||||
if( model == null ) m_cachedModels.put( combo, model = buildModel( combo ) );
|
||||
return model;
|
||||
}
|
||||
};
|
||||
@@ -132,20 +132,20 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
@Override
|
||||
public ItemOverrideList getOverrides()
|
||||
{
|
||||
return overrides;
|
||||
return m_overrides;
|
||||
}
|
||||
|
||||
private IBakedModel buildModel( TurtleModelCombination combo )
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
ModelManager modelManager = mc.getItemRenderer().getItemModelShaper().getModelManager();
|
||||
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
|
||||
ModelManager modelManager = mc.getItemRenderer().getItemModelMesher().getModelManager();
|
||||
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.m_overlay, combo.m_christmas );
|
||||
|
||||
IBakedModel baseModel = combo.colour ? colourModel : familyModel;
|
||||
IBakedModel baseModel = combo.m_colour ? colourModel : familyModel;
|
||||
IBakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
|
||||
TransformationMatrix transform = combo.flip ? flip : identity;
|
||||
TransformedModel leftModel = combo.leftUpgrade != null ? combo.leftUpgrade.getModel( null, TurtleSide.LEFT ) : null;
|
||||
TransformedModel rightModel = combo.rightUpgrade != null ? combo.rightUpgrade.getModel( null, TurtleSide.RIGHT ) : null;
|
||||
TransformationMatrix transform = combo.m_flip ? flip : identity;
|
||||
TransformedModel leftModel = combo.m_leftUpgrade != null ? combo.m_leftUpgrade.getModel( null, TurtleSide.LEFT ) : null;
|
||||
TransformedModel rightModel = combo.m_rightUpgrade != null ? combo.m_rightUpgrade.getModel( null, TurtleSide.RIGHT ) : null;
|
||||
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel, rightModel );
|
||||
}
|
||||
|
||||
@@ -166,9 +166,9 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
public boolean isAmbientOcclusion()
|
||||
{
|
||||
return familyModel.useAmbientOcclusion();
|
||||
return familyModel.isAmbientOcclusion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -178,31 +178,31 @@ public class TurtleSmartItemModel implements IBakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomRenderer()
|
||||
public boolean isBuiltInRenderer()
|
||||
{
|
||||
return familyModel.isCustomRenderer();
|
||||
return familyModel.isBuiltInRenderer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockLight()
|
||||
public boolean isSideLit()
|
||||
{
|
||||
return familyModel.usesBlockLight();
|
||||
return familyModel.isSideLit();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
public TextureAtlasSprite getParticleTexture()
|
||||
{
|
||||
return familyModel.getParticleIcon();
|
||||
return familyModel.getParticleTexture();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
@Deprecated
|
||||
public ItemCameraTransforms getTransforms()
|
||||
public ItemCameraTransforms getItemCameraTransforms()
|
||||
{
|
||||
return familyModel.getTransforms();
|
||||
return familyModel.getItemCameraTransforms();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,22 +19,22 @@ import java.util.Set;
|
||||
|
||||
public abstract class ComputerAccess implements IComputerAccess
|
||||
{
|
||||
private final IAPIEnvironment environment;
|
||||
private final Set<String> mounts = new HashSet<>();
|
||||
private final IAPIEnvironment m_environment;
|
||||
private final Set<String> m_mounts = new HashSet<>();
|
||||
|
||||
protected ComputerAccess( IAPIEnvironment environment )
|
||||
{
|
||||
this.environment = environment;
|
||||
this.m_environment = environment;
|
||||
}
|
||||
|
||||
public void unmountAll()
|
||||
{
|
||||
FileSystem fileSystem = environment.getFileSystem();
|
||||
for( String mount : mounts )
|
||||
FileSystem fileSystem = m_environment.getFileSystem();
|
||||
for( String mount : m_mounts )
|
||||
{
|
||||
fileSystem.unmount( mount );
|
||||
}
|
||||
mounts.clear();
|
||||
m_mounts.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -46,7 +46,7 @@ public abstract class ComputerAccess implements IComputerAccess
|
||||
|
||||
// Mount the location
|
||||
String location;
|
||||
FileSystem fileSystem = environment.getFileSystem();
|
||||
FileSystem fileSystem = m_environment.getFileSystem();
|
||||
if( fileSystem == null ) throw new IllegalStateException( "File system has not been created" );
|
||||
|
||||
synchronized( fileSystem )
|
||||
@@ -64,7 +64,7 @@ public abstract class ComputerAccess implements IComputerAccess
|
||||
}
|
||||
}
|
||||
|
||||
if( location != null ) mounts.add( location );
|
||||
if( location != null ) m_mounts.add( location );
|
||||
return location;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public abstract class ComputerAccess implements IComputerAccess
|
||||
|
||||
// Mount the location
|
||||
String location;
|
||||
FileSystem fileSystem = environment.getFileSystem();
|
||||
FileSystem fileSystem = m_environment.getFileSystem();
|
||||
if( fileSystem == null ) throw new IllegalStateException( "File system has not been created" );
|
||||
|
||||
synchronized( fileSystem )
|
||||
@@ -95,7 +95,7 @@ public abstract class ComputerAccess implements IComputerAccess
|
||||
}
|
||||
}
|
||||
|
||||
if( location != null ) mounts.add( location );
|
||||
if( location != null ) m_mounts.add( location );
|
||||
return location;
|
||||
}
|
||||
|
||||
@@ -103,37 +103,37 @@ public abstract class ComputerAccess implements IComputerAccess
|
||||
public void unmount( String location )
|
||||
{
|
||||
if( location == null ) return;
|
||||
if( !mounts.contains( location ) ) throw new IllegalStateException( "You didn't mount this location" );
|
||||
if( !m_mounts.contains( location ) ) throw new IllegalStateException( "You didn't mount this location" );
|
||||
|
||||
environment.getFileSystem().unmount( location );
|
||||
mounts.remove( location );
|
||||
m_environment.getFileSystem().unmount( location );
|
||||
m_mounts.remove( location );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID()
|
||||
{
|
||||
return environment.getComputerID();
|
||||
return m_environment.getComputerID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void queueEvent( @Nonnull String event, Object... arguments )
|
||||
{
|
||||
Objects.requireNonNull( event, "event cannot be null" );
|
||||
environment.queueEvent( event, arguments );
|
||||
m_environment.queueEvent( event, arguments );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IWorkMonitor getMainThreadMonitor()
|
||||
{
|
||||
return environment.getMainThreadMonitor();
|
||||
return m_environment.getMainThreadMonitor();
|
||||
}
|
||||
|
||||
private String findFreeLocation( String desiredLoc )
|
||||
{
|
||||
try
|
||||
{
|
||||
FileSystem fileSystem = environment.getFileSystem();
|
||||
FileSystem fileSystem = m_environment.getFileSystem();
|
||||
if( !fileSystem.exists( desiredLoc ) ) return desiredLoc;
|
||||
|
||||
// We used to check foo2, foo3, foo4, etc here but the disk drive does this itself now
|
||||
|
||||
@@ -89,9 +89,9 @@ public class FSAPI implements ILuaAPI
|
||||
*
|
||||
* @param arguments The paths to combine.
|
||||
* @return The new path, with separators added between parts as needed.
|
||||
* @throws LuaException On argument errors.
|
||||
* @cc.tparam string path The first part of the path. For example, a parent directory path.
|
||||
* @cc.tparam string ... Additional parts of the path to combine.
|
||||
* @throws LuaException On argument errors.
|
||||
*/
|
||||
@LuaFunction
|
||||
public final String combine( IArguments arguments ) throws LuaException
|
||||
@@ -471,8 +471,8 @@ public class FSAPI implements ILuaAPI
|
||||
/**
|
||||
* Get attributes about a specific file or folder.
|
||||
*
|
||||
* The returned attributes table contains information about the size of the file, whether it is a directory,
|
||||
* when it was created and last modified, and whether it is read only.
|
||||
* The returned attributes table contains information about the size of the file, whether it is a directory, and
|
||||
* when it was created and last modified.
|
||||
*
|
||||
* The creation and modification times are given as the number of milliseconds since the UNIX epoch. This may be
|
||||
* given to {@link OSAPI#date} in order to convert it to more usable form.
|
||||
@@ -480,7 +480,7 @@ public class FSAPI implements ILuaAPI
|
||||
* @param path The path to get attributes for.
|
||||
* @return The resulting attributes.
|
||||
* @throws LuaException If the path does not exist.
|
||||
* @cc.treturn { size = number, isDir = boolean, isReadOnly = boolean, created = number, modified = number } The resulting attributes.
|
||||
* @cc.treturn { size = number, isDir = boolean, created = number, modified = number } The resulting attributes.
|
||||
* @see #getSize If you only care about the file's size.
|
||||
* @see #isDir If you only care whether a path is a directory or not.
|
||||
*/
|
||||
@@ -496,7 +496,6 @@ public class FSAPI implements ILuaAPI
|
||||
result.put( "created", getFileTime( attributes.creationTime() ) );
|
||||
result.put( "size", attributes.isDirectory() ? 0 : attributes.size() );
|
||||
result.put( "isDir", attributes.isDirectory() );
|
||||
result.put( "isReadOnly", fileSystem.isReadOnly( path ) );
|
||||
return result;
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
|
||||
@@ -34,7 +34,7 @@ import static dan200.computercraft.core.apis.TableHelper.*;
|
||||
*/
|
||||
public class HTTPAPI implements ILuaAPI
|
||||
{
|
||||
private final IAPIEnvironment apiEnvironment;
|
||||
private final IAPIEnvironment m_apiEnvironment;
|
||||
|
||||
private final ResourceGroup<CheckUrl> checkUrls = new ResourceGroup<>();
|
||||
private final ResourceGroup<HttpRequest> requests = new ResourceQueue<>( () -> ComputerCraft.httpMaxRequests );
|
||||
@@ -42,7 +42,7 @@ public class HTTPAPI implements ILuaAPI
|
||||
|
||||
public HTTPAPI( IAPIEnvironment environment )
|
||||
{
|
||||
apiEnvironment = environment;
|
||||
m_apiEnvironment = environment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -123,7 +123,7 @@ public class HTTPAPI implements ILuaAPI
|
||||
try
|
||||
{
|
||||
URI uri = HttpRequest.checkUri( address );
|
||||
HttpRequest request = new HttpRequest( requests, apiEnvironment, address, postString, headers, binary, redirect );
|
||||
HttpRequest request = new HttpRequest( requests, m_apiEnvironment, address, postString, headers, binary, redirect );
|
||||
|
||||
// Make the request
|
||||
request.queue( r -> r.request( uri, httpMethod ) );
|
||||
@@ -142,7 +142,7 @@ public class HTTPAPI implements ILuaAPI
|
||||
try
|
||||
{
|
||||
URI uri = HttpRequest.checkUri( address );
|
||||
new CheckUrl( checkUrls, apiEnvironment, address, uri ).queue( CheckUrl::run );
|
||||
new CheckUrl( checkUrls, m_apiEnvironment, address, uri ).queue( CheckUrl::run );
|
||||
|
||||
return new Object[] { true };
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public class HTTPAPI implements ILuaAPI
|
||||
try
|
||||
{
|
||||
URI uri = Websocket.checkUri( address );
|
||||
if( !new Websocket( websockets, apiEnvironment, uri, address, headers ).queue( Websocket::connect ) )
|
||||
if( !new Websocket( websockets, m_apiEnvironment, uri, address, headers ).queue( Websocket::connect ) )
|
||||
{
|
||||
throw new LuaException( "Too many websockets already open" );
|
||||
}
|
||||
|
||||
@@ -32,29 +32,29 @@ public class OSAPI implements ILuaAPI
|
||||
{
|
||||
private final IAPIEnvironment apiEnvironment;
|
||||
|
||||
private final Int2ObjectMap<Alarm> alarms = new Int2ObjectOpenHashMap<>();
|
||||
private int clock;
|
||||
private double time;
|
||||
private int day;
|
||||
private final Int2ObjectMap<Alarm> m_alarms = new Int2ObjectOpenHashMap<>();
|
||||
private int m_clock;
|
||||
private double m_time;
|
||||
private int m_day;
|
||||
|
||||
private int nextAlarmToken = 0;
|
||||
private int m_nextAlarmToken = 0;
|
||||
|
||||
private static class Alarm implements Comparable<Alarm>
|
||||
{
|
||||
final double time;
|
||||
final int day;
|
||||
final double m_time;
|
||||
final int m_day;
|
||||
|
||||
Alarm( double time, int day )
|
||||
{
|
||||
this.time = time;
|
||||
this.day = day;
|
||||
m_time = time;
|
||||
m_day = day;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo( @Nonnull Alarm o )
|
||||
{
|
||||
double t = day * 24.0 + time;
|
||||
double ot = day * 24.0 + time;
|
||||
double t = m_day * 24.0 + m_time;
|
||||
double ot = m_day * 24.0 + m_time;
|
||||
return Double.compare( t, ot );
|
||||
}
|
||||
}
|
||||
@@ -73,38 +73,38 @@ public class OSAPI implements ILuaAPI
|
||||
@Override
|
||||
public void startup()
|
||||
{
|
||||
time = apiEnvironment.getComputerEnvironment().getTimeOfDay();
|
||||
day = apiEnvironment.getComputerEnvironment().getDay();
|
||||
clock = 0;
|
||||
m_time = apiEnvironment.getComputerEnvironment().getTimeOfDay();
|
||||
m_day = apiEnvironment.getComputerEnvironment().getDay();
|
||||
m_clock = 0;
|
||||
|
||||
synchronized( alarms )
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
alarms.clear();
|
||||
m_alarms.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
{
|
||||
clock++;
|
||||
m_clock++;
|
||||
|
||||
// Wait for all of our alarms
|
||||
synchronized( alarms )
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
double previousTime = time;
|
||||
int previousDay = day;
|
||||
double previousTime = m_time;
|
||||
int previousDay = m_day;
|
||||
double time = apiEnvironment.getComputerEnvironment().getTimeOfDay();
|
||||
int day = apiEnvironment.getComputerEnvironment().getDay();
|
||||
|
||||
if( time > previousTime || day > previousDay )
|
||||
{
|
||||
double now = this.day * 24.0 + this.time;
|
||||
Iterator<Int2ObjectMap.Entry<Alarm>> it = alarms.int2ObjectEntrySet().iterator();
|
||||
double now = m_day * 24.0 + m_time;
|
||||
Iterator<Int2ObjectMap.Entry<Alarm>> it = m_alarms.int2ObjectEntrySet().iterator();
|
||||
while( it.hasNext() )
|
||||
{
|
||||
Int2ObjectMap.Entry<Alarm> entry = it.next();
|
||||
Alarm alarm = entry.getValue();
|
||||
double t = alarm.day * 24.0 + alarm.time;
|
||||
double t = alarm.m_day * 24.0 + alarm.m_time;
|
||||
if( now >= t )
|
||||
{
|
||||
apiEnvironment.queueEvent( "alarm", entry.getIntKey() );
|
||||
@@ -113,17 +113,17 @@ public class OSAPI implements ILuaAPI
|
||||
}
|
||||
}
|
||||
|
||||
this.time = time;
|
||||
this.day = day;
|
||||
m_time = time;
|
||||
m_day = day;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown()
|
||||
{
|
||||
synchronized( alarms )
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
alarms.clear();
|
||||
m_alarms.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ public class OSAPI implements ILuaAPI
|
||||
*
|
||||
* @param timer The number of seconds until the timer fires.
|
||||
* @return The ID of the new timer. This can be used to filter the
|
||||
* {@code timer} event, or {@link #cancelTimer cancel the timer}.
|
||||
* {@code timer} event, or {@link #cancelTimer cancel the timer}.
|
||||
* @throws LuaException If the time is below zero.
|
||||
* @see #cancelTimer To cancel a timer.
|
||||
*/
|
||||
@@ -210,7 +210,7 @@ public class OSAPI implements ILuaAPI
|
||||
*
|
||||
* @param time The time at which to fire the alarm, in the range [0.0, 24.0).
|
||||
* @return The ID of the new alarm. This can be used to filter the
|
||||
* {@code alarm} event, or {@link #cancelAlarm cancel the alarm}.
|
||||
* {@code alarm} event, or {@link #cancelAlarm cancel the alarm}.
|
||||
* @throws LuaException If the time is out of range.
|
||||
* @see #cancelAlarm To cancel an alarm.
|
||||
*/
|
||||
@@ -219,11 +219,11 @@ public class OSAPI implements ILuaAPI
|
||||
{
|
||||
checkFinite( 0, time );
|
||||
if( time < 0.0 || time >= 24.0 ) throw new LuaException( "Number out of range" );
|
||||
synchronized( alarms )
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
int day = time > this.time ? this.day : this.day + 1;
|
||||
alarms.put( nextAlarmToken, new Alarm( time, day ) );
|
||||
return nextAlarmToken++;
|
||||
int day = time > m_time ? m_day : m_day + 1;
|
||||
m_alarms.put( m_nextAlarmToken, new Alarm( time, day ) );
|
||||
return m_nextAlarmToken++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,9 +237,9 @@ public class OSAPI implements ILuaAPI
|
||||
@LuaFunction
|
||||
public final void cancelAlarm( int token )
|
||||
{
|
||||
synchronized( alarms )
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
alarms.remove( token );
|
||||
m_alarms.remove( token );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ public class OSAPI implements ILuaAPI
|
||||
@LuaFunction
|
||||
public final double clock()
|
||||
{
|
||||
return clock * 0.05;
|
||||
return m_clock * 0.05;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -341,7 +341,7 @@ public class OSAPI implements ILuaAPI
|
||||
case "local": // Get Hour of day (local time)
|
||||
return getTimeForCalendar( Calendar.getInstance() );
|
||||
case "ingame": // Get in-game hour
|
||||
return time;
|
||||
return m_time;
|
||||
default:
|
||||
throw new LuaException( "Unsupported operation" );
|
||||
}
|
||||
@@ -371,7 +371,7 @@ public class OSAPI implements ILuaAPI
|
||||
case "local": // Get numbers of days since 1970-01-01 (local time)
|
||||
return getDayForCalendar( Calendar.getInstance() );
|
||||
case "ingame":// Get game day
|
||||
return day;
|
||||
return m_day;
|
||||
default:
|
||||
throw new LuaException( "Unsupported operation" );
|
||||
}
|
||||
@@ -381,11 +381,11 @@ public class OSAPI implements ILuaAPI
|
||||
* Returns the number of milliseconds since an epoch depending on the locale.
|
||||
*
|
||||
* * If called with {@code ingame}, returns the number of milliseconds since the
|
||||
* world was created. This is the default.
|
||||
* world was created. This is the default.
|
||||
* * If called with {@code utc}, returns the number of milliseconds since 1
|
||||
* January 1970 in the UTC timezone.
|
||||
* January 1970 in the UTC timezone.
|
||||
* * If called with {@code local}, returns the number of milliseconds since 1
|
||||
* January 1970 in the server's local timezone.
|
||||
* January 1970 in the server's local timezone.
|
||||
*
|
||||
* @param args The locale to get the milliseconds for. Defaults to {@code ingame} if not set.
|
||||
* @return The milliseconds since the epoch depending on the selected locale.
|
||||
@@ -410,9 +410,9 @@ public class OSAPI implements ILuaAPI
|
||||
}
|
||||
case "ingame":
|
||||
// Get in-game epoch
|
||||
synchronized( alarms )
|
||||
synchronized( m_alarms )
|
||||
{
|
||||
return day * 86400000L + (long) (time * 3600000.0);
|
||||
return m_day * 86400000L + (long) (m_time * 3600000.0);
|
||||
}
|
||||
default:
|
||||
throw new LuaException( "Unsupported operation" );
|
||||
|
||||
@@ -7,9 +7,9 @@ package dan200.computercraft.core.apis.handles;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.core.filesystem.TrackingCloseable;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
@@ -32,14 +32,14 @@ public class BinaryReadableHandle extends HandleGeneric
|
||||
final SeekableByteChannel seekable;
|
||||
private final ByteBuffer single = ByteBuffer.allocate( 1 );
|
||||
|
||||
BinaryReadableHandle( ReadableByteChannel reader, SeekableByteChannel seekable, TrackingCloseable closeable )
|
||||
BinaryReadableHandle( ReadableByteChannel reader, SeekableByteChannel seekable, Closeable closeable )
|
||||
{
|
||||
super( closeable );
|
||||
this.reader = reader;
|
||||
this.seekable = seekable;
|
||||
}
|
||||
|
||||
public static BinaryReadableHandle of( ReadableByteChannel channel, TrackingCloseable closeable )
|
||||
public static BinaryReadableHandle of( ReadableByteChannel channel, Closeable closeable )
|
||||
{
|
||||
SeekableByteChannel seekable = asSeekable( channel );
|
||||
return seekable == null ? new BinaryReadableHandle( channel, null, closeable ) : new Seekable( seekable, closeable );
|
||||
@@ -47,7 +47,7 @@ public class BinaryReadableHandle extends HandleGeneric
|
||||
|
||||
public static BinaryReadableHandle of( ReadableByteChannel channel )
|
||||
{
|
||||
return of( channel, new TrackingCloseable.Impl( channel ) );
|
||||
return of( channel, channel );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,7 +237,7 @@ public class BinaryReadableHandle extends HandleGeneric
|
||||
|
||||
public static class Seekable extends BinaryReadableHandle
|
||||
{
|
||||
Seekable( SeekableByteChannel seekable, TrackingCloseable closeable )
|
||||
Seekable( SeekableByteChannel seekable, Closeable closeable )
|
||||
{
|
||||
super( seekable, seekable, closeable );
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import dan200.computercraft.api.lua.IArguments;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.api.lua.LuaValues;
|
||||
import dan200.computercraft.core.filesystem.TrackingCloseable;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
@@ -30,14 +30,14 @@ public class BinaryWritableHandle extends HandleGeneric
|
||||
final SeekableByteChannel seekable;
|
||||
private final ByteBuffer single = ByteBuffer.allocate( 1 );
|
||||
|
||||
protected BinaryWritableHandle( WritableByteChannel writer, SeekableByteChannel seekable, TrackingCloseable closeable )
|
||||
protected BinaryWritableHandle( WritableByteChannel writer, SeekableByteChannel seekable, Closeable closeable )
|
||||
{
|
||||
super( closeable );
|
||||
this.writer = writer;
|
||||
this.seekable = seekable;
|
||||
}
|
||||
|
||||
public static BinaryWritableHandle of( WritableByteChannel channel, TrackingCloseable closeable )
|
||||
public static BinaryWritableHandle of( WritableByteChannel channel, Closeable closeable )
|
||||
{
|
||||
SeekableByteChannel seekable = asSeekable( channel );
|
||||
return seekable == null ? new BinaryWritableHandle( channel, null, closeable ) : new Seekable( seekable, closeable );
|
||||
@@ -45,7 +45,7 @@ public class BinaryWritableHandle extends HandleGeneric
|
||||
|
||||
public static BinaryWritableHandle of( WritableByteChannel channel )
|
||||
{
|
||||
return of( channel, new TrackingCloseable.Impl( channel ) );
|
||||
return of( channel, channel );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +108,7 @@ public class BinaryWritableHandle extends HandleGeneric
|
||||
|
||||
public static class Seekable extends BinaryWritableHandle
|
||||
{
|
||||
public Seekable( SeekableByteChannel seekable, TrackingCloseable closeable )
|
||||
public Seekable( SeekableByteChannel seekable, Closeable closeable )
|
||||
{
|
||||
super( seekable, seekable, closeable );
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ package dan200.computercraft.core.apis.handles;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.core.filesystem.TrackingCloseable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
@@ -32,7 +32,7 @@ public class EncodedReadableHandle extends HandleGeneric
|
||||
|
||||
private final BufferedReader reader;
|
||||
|
||||
public EncodedReadableHandle( @Nonnull BufferedReader reader, @Nonnull TrackingCloseable closable )
|
||||
public EncodedReadableHandle( @Nonnull BufferedReader reader, @Nonnull Closeable closable )
|
||||
{
|
||||
super( closable );
|
||||
this.reader = reader;
|
||||
@@ -40,7 +40,7 @@ public class EncodedReadableHandle extends HandleGeneric
|
||||
|
||||
public EncodedReadableHandle( @Nonnull BufferedReader reader )
|
||||
{
|
||||
this( reader, new TrackingCloseable.Impl( reader ) );
|
||||
this( reader, reader );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,11 +8,11 @@ package dan200.computercraft.core.apis.handles;
|
||||
import dan200.computercraft.api.lua.IArguments;
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.core.filesystem.TrackingCloseable;
|
||||
import dan200.computercraft.shared.util.StringUtil;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
@@ -30,7 +30,7 @@ public class EncodedWritableHandle extends HandleGeneric
|
||||
{
|
||||
private final BufferedWriter writer;
|
||||
|
||||
public EncodedWritableHandle( @Nonnull BufferedWriter writer, @Nonnull TrackingCloseable closable )
|
||||
public EncodedWritableHandle( @Nonnull BufferedWriter writer, @Nonnull Closeable closable )
|
||||
{
|
||||
super( closable );
|
||||
this.writer = writer;
|
||||
|
||||
@@ -7,10 +7,10 @@ package dan200.computercraft.core.apis.handles;
|
||||
|
||||
import dan200.computercraft.api.lua.LuaException;
|
||||
import dan200.computercraft.api.lua.LuaFunction;
|
||||
import dan200.computercraft.core.filesystem.TrackingCloseable;
|
||||
import dan200.computercraft.shared.util.IoUtil;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.Channel;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
@@ -18,23 +18,25 @@ import java.util.Optional;
|
||||
|
||||
public abstract class HandleGeneric
|
||||
{
|
||||
private TrackingCloseable closeable;
|
||||
private Closeable closable;
|
||||
private boolean open = true;
|
||||
|
||||
protected HandleGeneric( @Nonnull TrackingCloseable closeable )
|
||||
protected HandleGeneric( @Nonnull Closeable closable )
|
||||
{
|
||||
this.closeable = closeable;
|
||||
this.closable = closable;
|
||||
}
|
||||
|
||||
protected void checkOpen() throws LuaException
|
||||
{
|
||||
TrackingCloseable closeable = this.closeable;
|
||||
if( closeable == null || !closeable.isOpen() ) throw new LuaException( "attempt to use a closed file" );
|
||||
if( !open ) throw new LuaException( "attempt to use a closed file" );
|
||||
}
|
||||
|
||||
protected final void close()
|
||||
{
|
||||
IoUtil.closeQuietly( closeable );
|
||||
closeable = null;
|
||||
open = false;
|
||||
|
||||
IoUtil.closeQuietly( closable );
|
||||
closable = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,28 +32,28 @@ public class Computer
|
||||
private static final int START_DELAY = 50;
|
||||
|
||||
// Various properties of the computer
|
||||
private int id;
|
||||
private String label = null;
|
||||
private int m_id;
|
||||
private String m_label = null;
|
||||
|
||||
// Read-only fields about the computer
|
||||
private final IComputerEnvironment environment;
|
||||
private final Terminal terminal;
|
||||
private final IComputerEnvironment m_environment;
|
||||
private final Terminal m_terminal;
|
||||
private final ComputerExecutor executor;
|
||||
private final MainThreadExecutor serverExecutor;
|
||||
|
||||
// Additional state about the computer and its environment.
|
||||
private boolean blinking = false;
|
||||
private boolean m_blinking = false;
|
||||
private final Environment internalEnvironment = new Environment( this );
|
||||
private final AtomicBoolean externalOutputChanged = new AtomicBoolean();
|
||||
|
||||
private boolean startRequested;
|
||||
private int ticksSinceStart = -1;
|
||||
private int m_ticksSinceStart = -1;
|
||||
|
||||
public Computer( IComputerEnvironment environment, Terminal terminal, int id )
|
||||
{
|
||||
this.id = id;
|
||||
this.environment = environment;
|
||||
this.terminal = terminal;
|
||||
m_id = id;
|
||||
m_environment = environment;
|
||||
m_terminal = terminal;
|
||||
|
||||
executor = new ComputerExecutor( this );
|
||||
serverExecutor = new MainThreadExecutor( this );
|
||||
@@ -61,7 +61,7 @@ public class Computer
|
||||
|
||||
IComputerEnvironment getComputerEnvironment()
|
||||
{
|
||||
return environment;
|
||||
return m_environment;
|
||||
}
|
||||
|
||||
FileSystem getFileSystem()
|
||||
@@ -71,7 +71,7 @@ public class Computer
|
||||
|
||||
Terminal getTerminal()
|
||||
{
|
||||
return terminal;
|
||||
return m_terminal;
|
||||
}
|
||||
|
||||
public Environment getEnvironment()
|
||||
@@ -132,33 +132,33 @@ public class Computer
|
||||
|
||||
public int getID()
|
||||
{
|
||||
return id;
|
||||
return m_id;
|
||||
}
|
||||
|
||||
public int assignID()
|
||||
{
|
||||
if( id < 0 )
|
||||
if( m_id < 0 )
|
||||
{
|
||||
id = environment.assignNewID();
|
||||
m_id = m_environment.assignNewID();
|
||||
}
|
||||
return id;
|
||||
return m_id;
|
||||
}
|
||||
|
||||
public void setID( int id )
|
||||
{
|
||||
this.id = id;
|
||||
m_id = id;
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return label;
|
||||
return m_label;
|
||||
}
|
||||
|
||||
public void setLabel( String label )
|
||||
{
|
||||
if( !Objects.equal( label, this.label ) )
|
||||
if( !Objects.equal( label, m_label ) )
|
||||
{
|
||||
this.label = label;
|
||||
m_label = label;
|
||||
externalOutputChanged.set( true );
|
||||
}
|
||||
}
|
||||
@@ -166,14 +166,14 @@ public class Computer
|
||||
public void tick()
|
||||
{
|
||||
// We keep track of the number of ticks since the last start, only
|
||||
if( ticksSinceStart >= 0 && ticksSinceStart <= START_DELAY ) ticksSinceStart++;
|
||||
if( m_ticksSinceStart >= 0 && m_ticksSinceStart <= START_DELAY ) m_ticksSinceStart++;
|
||||
|
||||
if( startRequested && (ticksSinceStart < 0 || ticksSinceStart > START_DELAY) )
|
||||
if( startRequested && (m_ticksSinceStart < 0 || m_ticksSinceStart > START_DELAY) )
|
||||
{
|
||||
startRequested = false;
|
||||
if( !executor.isOn() )
|
||||
{
|
||||
ticksSinceStart = 0;
|
||||
m_ticksSinceStart = 0;
|
||||
executor.queueStart();
|
||||
}
|
||||
}
|
||||
@@ -187,12 +187,12 @@ public class Computer
|
||||
if( internalEnvironment.updateOutput() ) externalOutputChanged.set( true );
|
||||
|
||||
// Set output changed if the terminal has changed from blinking to not
|
||||
boolean blinking = terminal.getCursorBlink() &&
|
||||
terminal.getCursorX() >= 0 && terminal.getCursorX() < terminal.getWidth() &&
|
||||
terminal.getCursorY() >= 0 && terminal.getCursorY() < terminal.getHeight();
|
||||
if( blinking != this.blinking )
|
||||
boolean blinking = m_terminal.getCursorBlink() &&
|
||||
m_terminal.getCursorX() >= 0 && m_terminal.getCursorX() < m_terminal.getWidth() &&
|
||||
m_terminal.getCursorY() >= 0 && m_terminal.getCursorY() < m_terminal.getHeight();
|
||||
if( blinking != m_blinking )
|
||||
{
|
||||
this.blinking = blinking;
|
||||
m_blinking = blinking;
|
||||
externalOutputChanged.set( true );
|
||||
}
|
||||
}
|
||||
@@ -209,7 +209,7 @@ public class Computer
|
||||
|
||||
public boolean isBlinking()
|
||||
{
|
||||
return isOn() && blinking;
|
||||
return isOn() && m_blinking;
|
||||
}
|
||||
|
||||
public void addApi( ILuaAPI api )
|
||||
|
||||
@@ -42,7 +42,7 @@ class ChannelWrapper<T extends Closeable> implements Closeable
|
||||
}
|
||||
}
|
||||
|
||||
T get()
|
||||
public T get()
|
||||
{
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ import java.util.Set;
|
||||
|
||||
public class ComboMount implements IMount
|
||||
{
|
||||
private final IMount[] parts;
|
||||
private IMount[] m_parts;
|
||||
|
||||
public ComboMount( IMount[] parts )
|
||||
{
|
||||
this.parts = parts;
|
||||
m_parts = parts;
|
||||
}
|
||||
|
||||
// IMount implementation
|
||||
@@ -31,9 +31,9 @@ public class ComboMount implements IMount
|
||||
@Override
|
||||
public boolean exists( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i = parts.length - 1; i >= 0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = parts[i];
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) )
|
||||
{
|
||||
return true;
|
||||
@@ -45,9 +45,9 @@ public class ComboMount implements IMount
|
||||
@Override
|
||||
public boolean isDirectory( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i = parts.length - 1; i >= 0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = parts[i];
|
||||
IMount part = m_parts[i];
|
||||
if( part.isDirectory( path ) )
|
||||
{
|
||||
return true;
|
||||
@@ -62,9 +62,9 @@ public class ComboMount implements IMount
|
||||
// Combine the lists from all the mounts
|
||||
List<String> foundFiles = null;
|
||||
int foundDirs = 0;
|
||||
for( int i = parts.length - 1; i >= 0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = parts[i];
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) && part.isDirectory( path ) )
|
||||
{
|
||||
if( foundFiles == null )
|
||||
@@ -102,9 +102,9 @@ public class ComboMount implements IMount
|
||||
@Override
|
||||
public long getSize( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i = parts.length - 1; i >= 0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = parts[i];
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) )
|
||||
{
|
||||
return part.getSize( path );
|
||||
@@ -117,9 +117,9 @@ public class ComboMount implements IMount
|
||||
@Override
|
||||
public ReadableByteChannel openForRead( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i = parts.length - 1; i >= 0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = parts[i];
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) && !part.isDirectory( path ) )
|
||||
{
|
||||
return part.openForRead( path );
|
||||
@@ -132,9 +132,9 @@ public class ComboMount implements IMount
|
||||
@Override
|
||||
public BasicFileAttributes getAttributes( @Nonnull String path ) throws IOException
|
||||
{
|
||||
for( int i = parts.length - 1; i >= 0; --i )
|
||||
for( int i = m_parts.length - 1; i >= 0; --i )
|
||||
{
|
||||
IMount part = parts[i];
|
||||
IMount part = m_parts[i];
|
||||
if( part.exists( path ) && !part.isDirectory( path ) )
|
||||
{
|
||||
return part.getAttributes( path );
|
||||
|
||||
@@ -32,57 +32,57 @@ public class FileMount implements IWritableMount
|
||||
private class WritableCountingChannel implements WritableByteChannel
|
||||
{
|
||||
|
||||
private final WritableByteChannel inner;
|
||||
long ignoredBytesLeft;
|
||||
private final WritableByteChannel m_inner;
|
||||
long m_ignoredBytesLeft;
|
||||
|
||||
WritableCountingChannel( WritableByteChannel inner, long bytesToIgnore )
|
||||
{
|
||||
this.inner = inner;
|
||||
ignoredBytesLeft = bytesToIgnore;
|
||||
m_inner = inner;
|
||||
m_ignoredBytesLeft = bytesToIgnore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int write( @Nonnull ByteBuffer b ) throws IOException
|
||||
{
|
||||
count( b.remaining() );
|
||||
return inner.write( b );
|
||||
return m_inner.write( b );
|
||||
}
|
||||
|
||||
void count( long n ) throws IOException
|
||||
{
|
||||
ignoredBytesLeft -= n;
|
||||
if( ignoredBytesLeft < 0 )
|
||||
m_ignoredBytesLeft -= n;
|
||||
if( m_ignoredBytesLeft < 0 )
|
||||
{
|
||||
long newBytes = -ignoredBytesLeft;
|
||||
ignoredBytesLeft = 0;
|
||||
long newBytes = -m_ignoredBytesLeft;
|
||||
m_ignoredBytesLeft = 0;
|
||||
|
||||
long bytesLeft = capacity - usedSpace;
|
||||
long bytesLeft = m_capacity - m_usedSpace;
|
||||
if( newBytes > bytesLeft ) throw new IOException( "Out of space" );
|
||||
usedSpace += newBytes;
|
||||
m_usedSpace += newBytes;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
return inner.isOpen();
|
||||
return m_inner.isOpen();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
inner.close();
|
||||
m_inner.close();
|
||||
}
|
||||
}
|
||||
|
||||
private class SeekableCountingChannel extends WritableCountingChannel implements SeekableByteChannel
|
||||
{
|
||||
private final SeekableByteChannel inner;
|
||||
private final SeekableByteChannel m_inner;
|
||||
|
||||
SeekableCountingChannel( SeekableByteChannel inner, long bytesToIgnore )
|
||||
{
|
||||
super( inner, bytesToIgnore );
|
||||
this.inner = inner;
|
||||
m_inner = inner;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,17 +94,17 @@ public class FileMount implements IWritableMount
|
||||
throw new IllegalArgumentException( "Cannot seek before the beginning of the stream" );
|
||||
}
|
||||
|
||||
long delta = newPosition - inner.position();
|
||||
long delta = newPosition - m_inner.position();
|
||||
if( delta < 0 )
|
||||
{
|
||||
ignoredBytesLeft -= delta;
|
||||
m_ignoredBytesLeft -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
count( delta );
|
||||
}
|
||||
|
||||
return inner.position( newPosition );
|
||||
return m_inner.position( newPosition );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -116,32 +116,32 @@ public class FileMount implements IWritableMount
|
||||
@Override
|
||||
public int read( ByteBuffer dst ) throws ClosedChannelException
|
||||
{
|
||||
if( !inner.isOpen() ) throw new ClosedChannelException();
|
||||
if( !m_inner.isOpen() ) throw new ClosedChannelException();
|
||||
throw new NonReadableChannelException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long position() throws IOException
|
||||
{
|
||||
return inner.position();
|
||||
return m_inner.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long size() throws IOException
|
||||
{
|
||||
return inner.size();
|
||||
return m_inner.size();
|
||||
}
|
||||
}
|
||||
|
||||
private final File rootPath;
|
||||
private final long capacity;
|
||||
private long usedSpace;
|
||||
private File m_rootPath;
|
||||
private long m_capacity;
|
||||
private long m_usedSpace;
|
||||
|
||||
public FileMount( File rootPath, long capacity )
|
||||
{
|
||||
this.rootPath = rootPath;
|
||||
this.capacity = capacity + MINIMUM_FILE_SIZE;
|
||||
usedSpace = created() ? measureUsedSpace( this.rootPath ) : MINIMUM_FILE_SIZE;
|
||||
m_rootPath = rootPath;
|
||||
m_capacity = capacity + MINIMUM_FILE_SIZE;
|
||||
m_usedSpace = created() ? measureUsedSpace( m_rootPath ) : MINIMUM_FILE_SIZE;
|
||||
}
|
||||
|
||||
// IMount implementation
|
||||
@@ -253,7 +253,7 @@ public class FileMount implements IWritableMount
|
||||
|
||||
if( file.mkdirs() )
|
||||
{
|
||||
usedSpace += dirsToCreate * MINIMUM_FILE_SIZE;
|
||||
m_usedSpace += dirsToCreate * MINIMUM_FILE_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -290,7 +290,7 @@ public class FileMount implements IWritableMount
|
||||
boolean success = file.delete();
|
||||
if( success )
|
||||
{
|
||||
usedSpace -= Math.max( MINIMUM_FILE_SIZE, fileSize );
|
||||
m_usedSpace -= Math.max( MINIMUM_FILE_SIZE, fileSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -308,13 +308,13 @@ public class FileMount implements IWritableMount
|
||||
|
||||
if( file.exists() )
|
||||
{
|
||||
usedSpace -= Math.max( file.length(), MINIMUM_FILE_SIZE );
|
||||
m_usedSpace -= Math.max( file.length(), MINIMUM_FILE_SIZE );
|
||||
}
|
||||
else if( getRemainingSpace() < MINIMUM_FILE_SIZE )
|
||||
{
|
||||
throw new FileOperationException( path, "Out of space" );
|
||||
}
|
||||
usedSpace += MINIMUM_FILE_SIZE;
|
||||
m_usedSpace += MINIMUM_FILE_SIZE;
|
||||
|
||||
return new SeekableCountingChannel( Files.newByteChannel( file.toPath(), WRITE_OPTIONS ), MINIMUM_FILE_SIZE );
|
||||
}
|
||||
@@ -342,31 +342,31 @@ public class FileMount implements IWritableMount
|
||||
@Override
|
||||
public long getRemainingSpace()
|
||||
{
|
||||
return Math.max( capacity - usedSpace, 0 );
|
||||
return Math.max( m_capacity - m_usedSpace, 0 );
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public OptionalLong getCapacity()
|
||||
{
|
||||
return OptionalLong.of( capacity - MINIMUM_FILE_SIZE );
|
||||
return OptionalLong.of( m_capacity - MINIMUM_FILE_SIZE );
|
||||
}
|
||||
|
||||
private File getRealPath( String path )
|
||||
{
|
||||
return new File( rootPath, path );
|
||||
return new File( m_rootPath, path );
|
||||
}
|
||||
|
||||
private boolean created()
|
||||
{
|
||||
return rootPath.exists();
|
||||
return m_rootPath.exists();
|
||||
}
|
||||
|
||||
private void create() throws IOException
|
||||
{
|
||||
if( !rootPath.exists() )
|
||||
if( !m_rootPath.exists() )
|
||||
{
|
||||
boolean success = rootPath.mkdirs();
|
||||
boolean success = m_rootPath.mkdirs();
|
||||
if( !success )
|
||||
{
|
||||
throw new IOException( "Access denied" );
|
||||
|
||||
@@ -37,11 +37,11 @@ public class FileSystem
|
||||
*/
|
||||
private static final int MAX_COPY_DEPTH = 128;
|
||||
|
||||
private final FileSystemWrapperMount wrapper = new FileSystemWrapperMount( this );
|
||||
private final FileSystemWrapperMount m_wrapper = new FileSystemWrapperMount( this );
|
||||
private final Map<String, MountWrapper> mounts = new HashMap<>();
|
||||
|
||||
private final HashMap<WeakReference<FileSystemWrapper<?>>, ChannelWrapper<?>> openFiles = new HashMap<>();
|
||||
private final ReferenceQueue<FileSystemWrapper<?>> openFileQueue = new ReferenceQueue<>();
|
||||
private final HashMap<WeakReference<FileSystemWrapper<?>>, ChannelWrapper<?>> m_openFiles = new HashMap<>();
|
||||
private final ReferenceQueue<FileSystemWrapper<?>> m_openFileQueue = new ReferenceQueue<>();
|
||||
|
||||
public FileSystem( String rootLabel, IMount rootMount ) throws FileSystemException
|
||||
{
|
||||
@@ -56,11 +56,11 @@ public class FileSystem
|
||||
public void close()
|
||||
{
|
||||
// Close all dangling open files
|
||||
synchronized( openFiles )
|
||||
synchronized( m_openFiles )
|
||||
{
|
||||
for( Closeable file : openFiles.values() ) IoUtil.closeQuietly( file );
|
||||
openFiles.clear();
|
||||
while( openFileQueue.poll() != null ) ;
|
||||
for( Closeable file : m_openFiles.values() ) IoUtil.closeQuietly( file );
|
||||
m_openFiles.clear();
|
||||
while( m_openFileQueue.poll() != null ) ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,29 +95,7 @@ public class FileSystem
|
||||
|
||||
public synchronized void unmount( String path )
|
||||
{
|
||||
MountWrapper mount = mounts.remove( sanitizePath( path ) );
|
||||
if( mount == null ) return;
|
||||
|
||||
cleanup();
|
||||
|
||||
// Close any files which belong to this mount - don't want people writing to a disk after it's been ejected!
|
||||
// There's no point storing a Mount -> Wrapper[] map, as openFiles is small and unmount isn't called very
|
||||
// often.
|
||||
synchronized( openFiles )
|
||||
{
|
||||
for( Iterator<WeakReference<FileSystemWrapper<?>>> iterator = openFiles.keySet().iterator(); iterator.hasNext(); )
|
||||
{
|
||||
WeakReference<FileSystemWrapper<?>> reference = iterator.next();
|
||||
FileSystemWrapper<?> wrapper = reference.get();
|
||||
if( wrapper == null ) continue;
|
||||
|
||||
if( wrapper.mount == mount )
|
||||
{
|
||||
wrapper.closeExternally();
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
mounts.remove( sanitizePath( path ) );
|
||||
}
|
||||
|
||||
public String combine( String path, String childPath )
|
||||
@@ -383,22 +361,22 @@ public class FileSystem
|
||||
|
||||
private void cleanup()
|
||||
{
|
||||
synchronized( openFiles )
|
||||
synchronized( m_openFiles )
|
||||
{
|
||||
Reference<?> ref;
|
||||
while( (ref = openFileQueue.poll()) != null )
|
||||
while( (ref = m_openFileQueue.poll()) != null )
|
||||
{
|
||||
IoUtil.closeQuietly( openFiles.remove( ref ) );
|
||||
IoUtil.closeQuietly( m_openFiles.remove( ref ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized <T extends Closeable> FileSystemWrapper<T> openFile( @Nonnull MountWrapper mount, @Nonnull Channel channel, @Nonnull T file ) throws FileSystemException
|
||||
private synchronized <T extends Closeable> FileSystemWrapper<T> openFile( @Nonnull Channel channel, @Nonnull T file ) throws FileSystemException
|
||||
{
|
||||
synchronized( openFiles )
|
||||
synchronized( m_openFiles )
|
||||
{
|
||||
if( ComputerCraft.maximumFilesOpen > 0 &&
|
||||
openFiles.size() >= ComputerCraft.maximumFilesOpen )
|
||||
m_openFiles.size() >= ComputerCraft.maximumFilesOpen )
|
||||
{
|
||||
IoUtil.closeQuietly( file );
|
||||
IoUtil.closeQuietly( channel );
|
||||
@@ -406,17 +384,17 @@ public class FileSystem
|
||||
}
|
||||
|
||||
ChannelWrapper<T> channelWrapper = new ChannelWrapper<>( file, channel );
|
||||
FileSystemWrapper<T> fsWrapper = new FileSystemWrapper<>( this, mount, channelWrapper, openFileQueue );
|
||||
openFiles.put( fsWrapper.self, channelWrapper );
|
||||
FileSystemWrapper<T> fsWrapper = new FileSystemWrapper<>( this, channelWrapper, m_openFileQueue );
|
||||
m_openFiles.put( fsWrapper.self, channelWrapper );
|
||||
return fsWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
void removeFile( FileSystemWrapper<?> handle )
|
||||
synchronized void removeFile( FileSystemWrapper<?> handle )
|
||||
{
|
||||
synchronized( openFiles )
|
||||
synchronized( m_openFiles )
|
||||
{
|
||||
openFiles.remove( handle.self );
|
||||
m_openFiles.remove( handle.self );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,7 +405,11 @@ public class FileSystem
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
ReadableByteChannel channel = mount.openForRead( path );
|
||||
return channel != null ? openFile( mount, channel, open.apply( channel ) ) : null;
|
||||
if( channel != null )
|
||||
{
|
||||
return openFile( channel, open.apply( channel ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized <T extends Closeable> FileSystemWrapper<T> openForWrite( String path, boolean append, Function<WritableByteChannel, T> open ) throws FileSystemException
|
||||
@@ -437,7 +419,11 @@ public class FileSystem
|
||||
path = sanitizePath( path );
|
||||
MountWrapper mount = getMount( path );
|
||||
WritableByteChannel channel = append ? mount.openForAppend( path ) : mount.openForWrite( path );
|
||||
return channel != null ? openFile( mount, channel, open.apply( channel ) ) : null;
|
||||
if( channel != null )
|
||||
{
|
||||
return openFile( channel, open.apply( channel ) );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized long getFreeSpace( String path ) throws FileSystemException
|
||||
@@ -483,7 +469,7 @@ public class FileSystem
|
||||
|
||||
public IFileSystem getMountWrapper()
|
||||
{
|
||||
return wrapper;
|
||||
return m_wrapper;
|
||||
}
|
||||
|
||||
private static String sanitizePath( String path )
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
*/
|
||||
package dan200.computercraft.core.filesystem;
|
||||
|
||||
import dan200.computercraft.shared.util.IoUtil;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@@ -26,18 +24,15 @@ import java.lang.ref.WeakReference;
|
||||
*
|
||||
* @param <T> The type of writer or channel to wrap.
|
||||
*/
|
||||
public class FileSystemWrapper<T extends Closeable> implements TrackingCloseable
|
||||
public class FileSystemWrapper<T extends Closeable> implements Closeable
|
||||
{
|
||||
private final FileSystem fileSystem;
|
||||
final MountWrapper mount;
|
||||
private final ChannelWrapper<T> closeable;
|
||||
final WeakReference<FileSystemWrapper<?>> self;
|
||||
private boolean isOpen = true;
|
||||
|
||||
FileSystemWrapper( FileSystem fileSystem, MountWrapper mount, ChannelWrapper<T> closeable, ReferenceQueue<FileSystemWrapper<?>> queue )
|
||||
FileSystemWrapper( FileSystem fileSystem, ChannelWrapper<T> closeable, ReferenceQueue<FileSystemWrapper<?>> queue )
|
||||
{
|
||||
this.fileSystem = fileSystem;
|
||||
this.mount = mount;
|
||||
this.closeable = closeable;
|
||||
self = new WeakReference<>( this, queue );
|
||||
}
|
||||
@@ -45,23 +40,10 @@ public class FileSystemWrapper<T extends Closeable> implements TrackingCloseable
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
isOpen = false;
|
||||
fileSystem.removeFile( this );
|
||||
closeable.close();
|
||||
}
|
||||
|
||||
void closeExternally()
|
||||
{
|
||||
isOpen = false;
|
||||
IoUtil.closeQuietly( closeable );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public T get()
|
||||
{
|
||||
|
||||
@@ -17,11 +17,11 @@ import java.util.function.Function;
|
||||
|
||||
public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
private final FileSystem filesystem;
|
||||
private final FileSystem m_filesystem;
|
||||
|
||||
public FileSystemWrapperMount( FileSystem filesystem )
|
||||
{
|
||||
this.filesystem = filesystem;
|
||||
this.m_filesystem = filesystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,7 +29,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
filesystem.makeDir( path );
|
||||
m_filesystem.makeDir( path );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -42,7 +42,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
filesystem.delete( path );
|
||||
m_filesystem.delete( path );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -57,7 +57,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
try
|
||||
{
|
||||
// FIXME: Think of a better way of implementing this, so closing this will close on the computer.
|
||||
return filesystem.openForRead( path, Function.identity() ).get();
|
||||
return m_filesystem.openForRead( path, Function.identity() ).get();
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -71,7 +71,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
return filesystem.openForWrite( path, false, Function.identity() ).get();
|
||||
return m_filesystem.openForWrite( path, false, Function.identity() ).get();
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -85,7 +85,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
return filesystem.openForWrite( path, true, Function.identity() ).get();
|
||||
return m_filesystem.openForWrite( path, true, Function.identity() ).get();
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -98,7 +98,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
return filesystem.getFreeSpace( "/" );
|
||||
return m_filesystem.getFreeSpace( "/" );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -111,7 +111,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
return filesystem.exists( path );
|
||||
return m_filesystem.exists( path );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -124,7 +124,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
return filesystem.isDir( path );
|
||||
return m_filesystem.isDir( path );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -137,7 +137,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
Collections.addAll( contents, filesystem.list( path ) );
|
||||
Collections.addAll( contents, m_filesystem.list( path ) );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -150,7 +150,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
return filesystem.getSize( path );
|
||||
return m_filesystem.getSize( path );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -161,7 +161,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
@Override
|
||||
public String combine( String path, String child )
|
||||
{
|
||||
return filesystem.combine( path, child );
|
||||
return m_filesystem.combine( path, child );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -169,7 +169,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
filesystem.copy( from, to );
|
||||
m_filesystem.copy( from, to );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
@@ -182,7 +182,7 @@ public class FileSystemWrapperMount implements IFileSystem
|
||||
{
|
||||
try
|
||||
{
|
||||
filesystem.move( from, to );
|
||||
m_filesystem.move( from, to );
|
||||
}
|
||||
catch( FileSystemException e )
|
||||
{
|
||||
|
||||
@@ -104,7 +104,7 @@ public final class ResourceMount implements IMount
|
||||
{
|
||||
boolean hasAny = false;
|
||||
FileEntry newRoot = new FileEntry( new ResourceLocation( namespace, subPath ) );
|
||||
for( ResourceLocation file : manager.listResources( subPath, s -> true ) )
|
||||
for( ResourceLocation file : manager.getAllResourceLocations( subPath, s -> true ) )
|
||||
{
|
||||
if( !file.getNamespace().equals( namespace ) ) continue;
|
||||
|
||||
@@ -297,7 +297,7 @@ public final class ResourceMount implements IMount
|
||||
|
||||
synchronized void add( IReloadableResourceManager manager, ResourceMount mount )
|
||||
{
|
||||
if( managers.add( manager ) ) manager.registerReloadListener( this );
|
||||
if( managers.add( manager ) ) manager.addReloadListener( this );
|
||||
mounts.add( mount );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ import java.util.List;
|
||||
|
||||
public class SubMount implements IMount
|
||||
{
|
||||
private final IMount parent;
|
||||
private final String subPath;
|
||||
private IMount parent;
|
||||
private String subPath;
|
||||
|
||||
public SubMount( IMount parent, String subPath )
|
||||
{
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.core.filesystem;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A {@link Closeable} which knows when it has been closed.
|
||||
*
|
||||
* This is a quick (though racey) way of providing more friendly (and more similar to Lua)
|
||||
* error messages to the user.
|
||||
*/
|
||||
public interface TrackingCloseable extends Closeable
|
||||
{
|
||||
boolean isOpen();
|
||||
|
||||
class Impl implements TrackingCloseable
|
||||
{
|
||||
private final Closeable object;
|
||||
private boolean isOpen = true;
|
||||
|
||||
public Impl( Closeable object )
|
||||
{
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
return isOpen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
{
|
||||
isOpen = false;
|
||||
object.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,29 +50,29 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
|
||||
private static final LuaMethod FUNCTION_METHOD = ( target, context, args ) -> ((ILuaFunction) target).call( args );
|
||||
|
||||
private final Computer computer;
|
||||
private final Computer m_computer;
|
||||
private final TimeoutState timeout;
|
||||
private final TimeoutDebugHandler debug;
|
||||
private final ILuaContext context = new CobaltLuaContext();
|
||||
|
||||
private LuaState state;
|
||||
private LuaTable globals;
|
||||
private LuaState m_state;
|
||||
private LuaTable m_globals;
|
||||
|
||||
private LuaThread mainRoutine = null;
|
||||
private String eventFilter = null;
|
||||
private LuaThread m_mainRoutine = null;
|
||||
private String m_eventFilter = null;
|
||||
|
||||
public CobaltLuaMachine( Computer computer, TimeoutState timeout )
|
||||
{
|
||||
this.computer = computer;
|
||||
m_computer = computer;
|
||||
this.timeout = timeout;
|
||||
debug = new TimeoutDebugHandler();
|
||||
|
||||
// Create an environment to run in
|
||||
LuaState state = this.state = LuaState.builder()
|
||||
LuaState state = m_state = LuaState.builder()
|
||||
.resourceManipulator( new VoidResourceManipulator() )
|
||||
.debug( debug )
|
||||
.coroutineExecutor( command -> {
|
||||
Tracking.addValue( this.computer, TrackingField.COROUTINES_CREATED, 1 );
|
||||
Tracking.addValue( m_computer, TrackingField.COROUTINES_CREATED, 1 );
|
||||
COROUTINES.execute( () -> {
|
||||
try
|
||||
{
|
||||
@@ -80,38 +80,38 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
}
|
||||
finally
|
||||
{
|
||||
Tracking.addValue( this.computer, TrackingField.COROUTINES_DISPOSED, 1 );
|
||||
Tracking.addValue( m_computer, TrackingField.COROUTINES_DISPOSED, 1 );
|
||||
}
|
||||
} );
|
||||
} )
|
||||
.build();
|
||||
|
||||
globals = new LuaTable();
|
||||
state.setupThread( globals );
|
||||
m_globals = new LuaTable();
|
||||
state.setupThread( m_globals );
|
||||
|
||||
// Add basic libraries
|
||||
globals.load( state, new BaseLib() );
|
||||
globals.load( state, new TableLib() );
|
||||
globals.load( state, new StringLib() );
|
||||
globals.load( state, new MathLib() );
|
||||
globals.load( state, new CoroutineLib() );
|
||||
globals.load( state, new Bit32Lib() );
|
||||
globals.load( state, new Utf8Lib() );
|
||||
if( ComputerCraft.debugEnable ) globals.load( state, new DebugLib() );
|
||||
m_globals.load( state, new BaseLib() );
|
||||
m_globals.load( state, new TableLib() );
|
||||
m_globals.load( state, new StringLib() );
|
||||
m_globals.load( state, new MathLib() );
|
||||
m_globals.load( state, new CoroutineLib() );
|
||||
m_globals.load( state, new Bit32Lib() );
|
||||
m_globals.load( state, new Utf8Lib() );
|
||||
if( ComputerCraft.debugEnable ) m_globals.load( state, new DebugLib() );
|
||||
|
||||
// Remove globals we don't want to expose
|
||||
globals.rawset( "collectgarbage", Constants.NIL );
|
||||
globals.rawset( "dofile", Constants.NIL );
|
||||
globals.rawset( "loadfile", Constants.NIL );
|
||||
globals.rawset( "print", Constants.NIL );
|
||||
m_globals.rawset( "collectgarbage", Constants.NIL );
|
||||
m_globals.rawset( "dofile", Constants.NIL );
|
||||
m_globals.rawset( "loadfile", Constants.NIL );
|
||||
m_globals.rawset( "print", Constants.NIL );
|
||||
|
||||
// Add version globals
|
||||
globals.rawset( "_VERSION", valueOf( "Lua 5.1" ) );
|
||||
globals.rawset( "_HOST", valueOf( computer.getAPIEnvironment().getComputerEnvironment().getHostString() ) );
|
||||
globals.rawset( "_CC_DEFAULT_SETTINGS", valueOf( ComputerCraft.defaultComputerSettings ) );
|
||||
m_globals.rawset( "_VERSION", valueOf( "Lua 5.1" ) );
|
||||
m_globals.rawset( "_HOST", valueOf( computer.getAPIEnvironment().getComputerEnvironment().getHostString() ) );
|
||||
m_globals.rawset( "_CC_DEFAULT_SETTINGS", valueOf( ComputerCraft.defaultComputerSettings ) );
|
||||
if( ComputerCraft.disableLua51Features )
|
||||
{
|
||||
globals.rawset( "_CC_DISABLE_LUA51_FEATURES", Constants.TRUE );
|
||||
m_globals.rawset( "_CC_DISABLE_LUA51_FEATURES", Constants.TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,19 +127,19 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
}
|
||||
|
||||
String[] names = api.getNames();
|
||||
for( String name : names ) globals.rawset( name, table );
|
||||
for( String name : names ) m_globals.rawset( name, table );
|
||||
}
|
||||
|
||||
@Override
|
||||
public MachineResult loadBios( @Nonnull InputStream bios )
|
||||
{
|
||||
// Begin executing a file (ie, the bios)
|
||||
if( mainRoutine != null ) return MachineResult.OK;
|
||||
if( m_mainRoutine != null ) return MachineResult.OK;
|
||||
|
||||
try
|
||||
{
|
||||
LuaFunction value = LoadState.load( state, bios, "@bios.lua", globals );
|
||||
mainRoutine = new LuaThread( state, value, globals );
|
||||
LuaFunction value = LoadState.load( m_state, bios, "@bios.lua", m_globals );
|
||||
m_mainRoutine = new LuaThread( m_state, value, m_globals );
|
||||
return MachineResult.OK;
|
||||
}
|
||||
catch( CompileException e )
|
||||
@@ -158,9 +158,9 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
@Override
|
||||
public MachineResult handleEvent( String eventName, Object[] arguments )
|
||||
{
|
||||
if( mainRoutine == null ) return MachineResult.OK;
|
||||
if( m_mainRoutine == null ) return MachineResult.OK;
|
||||
|
||||
if( eventFilter != null && eventName != null && !eventName.equals( eventFilter ) && !eventName.equals( "terminate" ) )
|
||||
if( m_eventFilter != null && eventName != null && !eventName.equals( m_eventFilter ) && !eventName.equals( "terminate" ) )
|
||||
{
|
||||
return MachineResult.OK;
|
||||
}
|
||||
@@ -178,17 +178,17 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
}
|
||||
|
||||
// Resume the current thread, or the main one when first starting off.
|
||||
LuaThread thread = state.getCurrentThread();
|
||||
if( thread == null || thread == state.getMainThread() ) thread = mainRoutine;
|
||||
LuaThread thread = m_state.getCurrentThread();
|
||||
if( thread == null || thread == m_state.getMainThread() ) thread = m_mainRoutine;
|
||||
|
||||
Varargs results = LuaThread.run( thread, resumeArgs );
|
||||
if( timeout.isHardAborted() ) throw HardAbortError.INSTANCE;
|
||||
if( results == null ) return MachineResult.PAUSE;
|
||||
|
||||
LuaValue filter = results.first();
|
||||
eventFilter = filter.isString() ? filter.toString() : null;
|
||||
m_eventFilter = filter.isString() ? filter.toString() : null;
|
||||
|
||||
if( mainRoutine.getStatus().equals( "dead" ) )
|
||||
if( m_mainRoutine.getStatus().equals( "dead" ) )
|
||||
{
|
||||
close();
|
||||
return MachineResult.GENERIC_ERROR;
|
||||
@@ -214,13 +214,13 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
LuaState state = this.state;
|
||||
LuaState state = m_state;
|
||||
if( state == null ) return;
|
||||
|
||||
state.abandon();
|
||||
mainRoutine = null;
|
||||
this.state = null;
|
||||
globals = null;
|
||||
m_mainRoutine = null;
|
||||
m_state = null;
|
||||
m_globals = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -457,7 +457,7 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
if( (count = (count + 1) & 127) == 0 )
|
||||
{
|
||||
// If we've been hard aborted or closed then abort.
|
||||
if( timeout.isHardAborted() || state == null ) throw HardAbortError.INSTANCE;
|
||||
if( timeout.isHardAborted() || m_state == null ) throw HardAbortError.INSTANCE;
|
||||
|
||||
timeout.refresh();
|
||||
if( timeout.isPaused() )
|
||||
@@ -483,7 +483,7 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
public void poll() throws LuaError
|
||||
{
|
||||
// If we've been hard aborted or closed then abort.
|
||||
LuaState state = CobaltLuaMachine.this.state;
|
||||
LuaState state = m_state;
|
||||
if( timeout.isHardAborted() || state == null ) throw HardAbortError.INSTANCE;
|
||||
|
||||
timeout.refresh();
|
||||
@@ -526,26 +526,26 @@ public class CobaltLuaMachine implements ILuaMachine
|
||||
eventArguments[0] = taskID;
|
||||
eventArguments[1] = true;
|
||||
System.arraycopy( results, 0, eventArguments, 2, results.length );
|
||||
computer.queueEvent( "task_complete", eventArguments );
|
||||
m_computer.queueEvent( "task_complete", eventArguments );
|
||||
}
|
||||
else
|
||||
{
|
||||
computer.queueEvent( "task_complete", new Object[] { taskID, true } );
|
||||
m_computer.queueEvent( "task_complete", new Object[] { taskID, true } );
|
||||
}
|
||||
}
|
||||
catch( LuaException e )
|
||||
{
|
||||
computer.queueEvent( "task_complete", new Object[] { taskID, false, e.getMessage() } );
|
||||
m_computer.queueEvent( "task_complete", new Object[] { taskID, false, e.getMessage() } );
|
||||
}
|
||||
catch( Throwable t )
|
||||
{
|
||||
if( ComputerCraft.logComputerErrors ) ComputerCraft.log.error( "Error running task", t );
|
||||
computer.queueEvent( "task_complete", new Object[] {
|
||||
m_computer.queueEvent( "task_complete", new Object[] {
|
||||
taskID, false, "Java Exception Thrown: " + t,
|
||||
} );
|
||||
}
|
||||
};
|
||||
if( computer.queueMainThread( iTask ) )
|
||||
if( m_computer.queueMainThread( iTask ) )
|
||||
{
|
||||
return taskID;
|
||||
}
|
||||
|
||||
@@ -16,20 +16,20 @@ public class Terminal
|
||||
{
|
||||
private static final String base16 = "0123456789abcdef";
|
||||
|
||||
private int cursorX = 0;
|
||||
private int cursorY = 0;
|
||||
private boolean cursorBlink = false;
|
||||
private int cursorColour = 0;
|
||||
private int cursorBackgroundColour = 15;
|
||||
private int m_cursorX = 0;
|
||||
private int m_cursorY = 0;
|
||||
private boolean m_cursorBlink = false;
|
||||
private int m_cursorColour = 0;
|
||||
private int m_cursorBackgroundColour = 15;
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private int m_width;
|
||||
private int m_height;
|
||||
|
||||
private TextBuffer[] text;
|
||||
private TextBuffer[] textColour;
|
||||
private TextBuffer[] backgroundColour;
|
||||
private TextBuffer[] m_text;
|
||||
private TextBuffer[] m_textColour;
|
||||
private TextBuffer[] m_backgroundColour;
|
||||
|
||||
private final Palette palette = new Palette();
|
||||
private final Palette m_palette = new Palette();
|
||||
|
||||
private final Runnable onChanged;
|
||||
|
||||
@@ -40,84 +40,84 @@ public class Terminal
|
||||
|
||||
public Terminal( int width, int height, Runnable changedCallback )
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
onChanged = changedCallback;
|
||||
|
||||
text = new TextBuffer[this.height];
|
||||
textColour = new TextBuffer[this.height];
|
||||
backgroundColour = new TextBuffer[this.height];
|
||||
for( int i = 0; i < this.height; i++ )
|
||||
m_text = new TextBuffer[m_height];
|
||||
m_textColour = new TextBuffer[m_height];
|
||||
m_backgroundColour = new TextBuffer[m_height];
|
||||
for( int i = 0; i < m_height; i++ )
|
||||
{
|
||||
text[i] = new TextBuffer( ' ', this.width );
|
||||
textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
|
||||
backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
|
||||
m_text[i] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void reset()
|
||||
{
|
||||
cursorColour = 0;
|
||||
cursorBackgroundColour = 15;
|
||||
cursorX = 0;
|
||||
cursorY = 0;
|
||||
cursorBlink = false;
|
||||
m_cursorColour = 0;
|
||||
m_cursorBackgroundColour = 15;
|
||||
m_cursorX = 0;
|
||||
m_cursorY = 0;
|
||||
m_cursorBlink = false;
|
||||
clear();
|
||||
setChanged();
|
||||
palette.resetColours();
|
||||
m_palette.resetColours();
|
||||
}
|
||||
|
||||
public int getWidth()
|
||||
{
|
||||
return width;
|
||||
return m_width;
|
||||
}
|
||||
|
||||
public int getHeight()
|
||||
{
|
||||
return height;
|
||||
return m_height;
|
||||
}
|
||||
|
||||
public synchronized void resize( int width, int height )
|
||||
{
|
||||
if( width == this.width && height == this.height )
|
||||
if( width == m_width && height == m_height )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int oldHeight = this.height;
|
||||
int oldWidth = this.width;
|
||||
TextBuffer[] oldText = text;
|
||||
TextBuffer[] oldTextColour = textColour;
|
||||
TextBuffer[] oldBackgroundColour = backgroundColour;
|
||||
int oldHeight = m_height;
|
||||
int oldWidth = m_width;
|
||||
TextBuffer[] oldText = m_text;
|
||||
TextBuffer[] oldTextColour = m_textColour;
|
||||
TextBuffer[] oldBackgroundColour = m_backgroundColour;
|
||||
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
|
||||
text = new TextBuffer[this.height];
|
||||
textColour = new TextBuffer[this.height];
|
||||
backgroundColour = new TextBuffer[this.height];
|
||||
for( int i = 0; i < this.height; i++ )
|
||||
m_text = new TextBuffer[m_height];
|
||||
m_textColour = new TextBuffer[m_height];
|
||||
m_backgroundColour = new TextBuffer[m_height];
|
||||
for( int i = 0; i < m_height; i++ )
|
||||
{
|
||||
if( i >= oldHeight )
|
||||
{
|
||||
text[i] = new TextBuffer( ' ', this.width );
|
||||
textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
|
||||
backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
|
||||
m_text[i] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
}
|
||||
else if( this.width == oldWidth )
|
||||
else if( m_width == oldWidth )
|
||||
{
|
||||
text[i] = oldText[i];
|
||||
textColour[i] = oldTextColour[i];
|
||||
backgroundColour[i] = oldBackgroundColour[i];
|
||||
m_text[i] = oldText[i];
|
||||
m_textColour[i] = oldTextColour[i];
|
||||
m_backgroundColour[i] = oldBackgroundColour[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
text[i] = new TextBuffer( ' ', this.width );
|
||||
textColour[i] = new TextBuffer( base16.charAt( cursorColour ), this.width );
|
||||
backgroundColour[i] = new TextBuffer( base16.charAt( cursorBackgroundColour ), this.width );
|
||||
text[i].write( oldText[i] );
|
||||
textColour[i].write( oldTextColour[i] );
|
||||
backgroundColour[i].write( oldBackgroundColour[i] );
|
||||
m_text[i] = new TextBuffer( ' ', m_width );
|
||||
m_textColour[i] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
m_backgroundColour[i] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
m_text[i].write( oldText[i] );
|
||||
m_textColour[i].write( oldTextColour[i] );
|
||||
m_backgroundColour[i].write( oldBackgroundColour[i] );
|
||||
}
|
||||
}
|
||||
setChanged();
|
||||
@@ -125,94 +125,94 @@ public class Terminal
|
||||
|
||||
public void setCursorPos( int x, int y )
|
||||
{
|
||||
if( cursorX != x || cursorY != y )
|
||||
if( m_cursorX != x || m_cursorY != y )
|
||||
{
|
||||
cursorX = x;
|
||||
cursorY = y;
|
||||
m_cursorX = x;
|
||||
m_cursorY = y;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCursorBlink( boolean blink )
|
||||
{
|
||||
if( cursorBlink != blink )
|
||||
if( m_cursorBlink != blink )
|
||||
{
|
||||
cursorBlink = blink;
|
||||
m_cursorBlink = blink;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextColour( int colour )
|
||||
{
|
||||
if( cursorColour != colour )
|
||||
if( m_cursorColour != colour )
|
||||
{
|
||||
cursorColour = colour;
|
||||
m_cursorColour = colour;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setBackgroundColour( int colour )
|
||||
{
|
||||
if( cursorBackgroundColour != colour )
|
||||
if( m_cursorBackgroundColour != colour )
|
||||
{
|
||||
cursorBackgroundColour = colour;
|
||||
m_cursorBackgroundColour = colour;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public int getCursorX()
|
||||
{
|
||||
return cursorX;
|
||||
return m_cursorX;
|
||||
}
|
||||
|
||||
public int getCursorY()
|
||||
{
|
||||
return cursorY;
|
||||
return m_cursorY;
|
||||
}
|
||||
|
||||
public boolean getCursorBlink()
|
||||
{
|
||||
return cursorBlink;
|
||||
return m_cursorBlink;
|
||||
}
|
||||
|
||||
public int getTextColour()
|
||||
{
|
||||
return cursorColour;
|
||||
return m_cursorColour;
|
||||
}
|
||||
|
||||
public int getBackgroundColour()
|
||||
{
|
||||
return cursorBackgroundColour;
|
||||
return m_cursorBackgroundColour;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public Palette getPalette()
|
||||
{
|
||||
return palette;
|
||||
return m_palette;
|
||||
}
|
||||
|
||||
public synchronized void blit( String text, String textColour, String backgroundColour )
|
||||
{
|
||||
int x = cursorX;
|
||||
int y = cursorY;
|
||||
if( y >= 0 && y < height )
|
||||
int x = m_cursorX;
|
||||
int y = m_cursorY;
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
this.text[y].write( text, x );
|
||||
this.textColour[y].write( textColour, x );
|
||||
this.backgroundColour[y].write( backgroundColour, x );
|
||||
m_text[y].write( text, x );
|
||||
m_textColour[y].write( textColour, x );
|
||||
m_backgroundColour[y].write( backgroundColour, x );
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void write( String text )
|
||||
{
|
||||
int x = cursorX;
|
||||
int y = cursorY;
|
||||
if( y >= 0 && y < height )
|
||||
int x = m_cursorX;
|
||||
int y = m_cursorY;
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
this.text[y].write( text, x );
|
||||
textColour[y].fill( base16.charAt( cursorColour ), x, x + text.length() );
|
||||
backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ), x, x + text.length() );
|
||||
m_text[y].write( text, x );
|
||||
m_textColour[y].fill( base16.charAt( m_cursorColour ), x, x + text.length() );
|
||||
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ), x, x + text.length() );
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
@@ -221,86 +221,86 @@ public class Terminal
|
||||
{
|
||||
if( yDiff != 0 )
|
||||
{
|
||||
TextBuffer[] newText = new TextBuffer[height];
|
||||
TextBuffer[] newTextColour = new TextBuffer[height];
|
||||
TextBuffer[] newBackgroundColour = new TextBuffer[height];
|
||||
for( int y = 0; y < height; y++ )
|
||||
TextBuffer[] newText = new TextBuffer[m_height];
|
||||
TextBuffer[] newTextColour = new TextBuffer[m_height];
|
||||
TextBuffer[] newBackgroundColour = new TextBuffer[m_height];
|
||||
for( int y = 0; y < m_height; y++ )
|
||||
{
|
||||
int oldY = y + yDiff;
|
||||
if( oldY >= 0 && oldY < height )
|
||||
if( oldY >= 0 && oldY < m_height )
|
||||
{
|
||||
newText[y] = text[oldY];
|
||||
newTextColour[y] = textColour[oldY];
|
||||
newBackgroundColour[y] = backgroundColour[oldY];
|
||||
newText[y] = m_text[oldY];
|
||||
newTextColour[y] = m_textColour[oldY];
|
||||
newBackgroundColour[y] = m_backgroundColour[oldY];
|
||||
}
|
||||
else
|
||||
{
|
||||
newText[y] = new TextBuffer( ' ', width );
|
||||
newTextColour[y] = new TextBuffer( base16.charAt( cursorColour ), width );
|
||||
newBackgroundColour[y] = new TextBuffer( base16.charAt( cursorBackgroundColour ), width );
|
||||
newText[y] = new TextBuffer( ' ', m_width );
|
||||
newTextColour[y] = new TextBuffer( base16.charAt( m_cursorColour ), m_width );
|
||||
newBackgroundColour[y] = new TextBuffer( base16.charAt( m_cursorBackgroundColour ), m_width );
|
||||
}
|
||||
}
|
||||
text = newText;
|
||||
textColour = newTextColour;
|
||||
backgroundColour = newBackgroundColour;
|
||||
m_text = newText;
|
||||
m_textColour = newTextColour;
|
||||
m_backgroundColour = newBackgroundColour;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void clear()
|
||||
{
|
||||
for( int y = 0; y < height; y++ )
|
||||
for( int y = 0; y < m_height; y++ )
|
||||
{
|
||||
text[y].fill( ' ' );
|
||||
textColour[y].fill( base16.charAt( cursorColour ) );
|
||||
backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ) );
|
||||
m_text[y].fill( ' ' );
|
||||
m_textColour[y].fill( base16.charAt( m_cursorColour ) );
|
||||
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||
}
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public synchronized void clearLine()
|
||||
{
|
||||
int y = cursorY;
|
||||
if( y >= 0 && y < height )
|
||||
int y = m_cursorY;
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
text[y].fill( ' ' );
|
||||
textColour[y].fill( base16.charAt( cursorColour ) );
|
||||
backgroundColour[y].fill( base16.charAt( cursorBackgroundColour ) );
|
||||
m_text[y].fill( ' ' );
|
||||
m_textColour[y].fill( base16.charAt( m_cursorColour ) );
|
||||
m_backgroundColour[y].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized TextBuffer getLine( int y )
|
||||
{
|
||||
if( y >= 0 && y < height )
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
return text[y];
|
||||
return m_text[y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized void setLine( int y, String text, String textColour, String backgroundColour )
|
||||
{
|
||||
this.text[y].write( text );
|
||||
this.textColour[y].write( textColour );
|
||||
this.backgroundColour[y].write( backgroundColour );
|
||||
m_text[y].write( text );
|
||||
m_textColour[y].write( textColour );
|
||||
m_backgroundColour[y].write( backgroundColour );
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public synchronized TextBuffer getTextColourLine( int y )
|
||||
{
|
||||
if( y >= 0 && y < height )
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
return textColour[y];
|
||||
return m_textColour[y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized TextBuffer getBackgroundColourLine( int y )
|
||||
{
|
||||
if( y >= 0 && y < height )
|
||||
if( y >= 0 && y < m_height )
|
||||
{
|
||||
return backgroundColour[y];
|
||||
return m_backgroundColour[y];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -312,18 +312,18 @@ public class Terminal
|
||||
|
||||
public synchronized void write( PacketBuffer buffer )
|
||||
{
|
||||
buffer.writeInt( cursorX );
|
||||
buffer.writeInt( cursorY );
|
||||
buffer.writeBoolean( cursorBlink );
|
||||
buffer.writeByte( cursorBackgroundColour << 4 | cursorColour );
|
||||
buffer.writeInt( m_cursorX );
|
||||
buffer.writeInt( m_cursorY );
|
||||
buffer.writeBoolean( m_cursorBlink );
|
||||
buffer.writeByte( m_cursorBackgroundColour << 4 | m_cursorColour );
|
||||
|
||||
for( int y = 0; y < height; y++ )
|
||||
for( int y = 0; y < m_height; y++ )
|
||||
{
|
||||
TextBuffer text = this.text[y];
|
||||
TextBuffer textColour = this.textColour[y];
|
||||
TextBuffer backColour = backgroundColour[y];
|
||||
TextBuffer text = m_text[y];
|
||||
TextBuffer textColour = m_textColour[y];
|
||||
TextBuffer backColour = m_backgroundColour[y];
|
||||
|
||||
for( int x = 0; x < width; x++ )
|
||||
for( int x = 0; x < m_width; x++ )
|
||||
{
|
||||
buffer.writeByte( text.charAt( x ) & 0xFF );
|
||||
buffer.writeByte( getColour(
|
||||
@@ -333,26 +333,26 @@ public class Terminal
|
||||
}
|
||||
}
|
||||
|
||||
palette.write( buffer );
|
||||
m_palette.write( buffer );
|
||||
}
|
||||
|
||||
public synchronized void read( PacketBuffer buffer )
|
||||
{
|
||||
cursorX = buffer.readInt();
|
||||
cursorY = buffer.readInt();
|
||||
cursorBlink = buffer.readBoolean();
|
||||
m_cursorX = buffer.readInt();
|
||||
m_cursorY = buffer.readInt();
|
||||
m_cursorBlink = buffer.readBoolean();
|
||||
|
||||
byte cursorColour = buffer.readByte();
|
||||
cursorBackgroundColour = (cursorColour >> 4) & 0xF;
|
||||
this.cursorColour = cursorColour & 0xF;
|
||||
m_cursorBackgroundColour = (cursorColour >> 4) & 0xF;
|
||||
m_cursorColour = cursorColour & 0xF;
|
||||
|
||||
for( int y = 0; y < height; y++ )
|
||||
for( int y = 0; y < m_height; y++ )
|
||||
{
|
||||
TextBuffer text = this.text[y];
|
||||
TextBuffer textColour = this.textColour[y];
|
||||
TextBuffer backColour = backgroundColour[y];
|
||||
TextBuffer text = m_text[y];
|
||||
TextBuffer textColour = m_textColour[y];
|
||||
TextBuffer backColour = m_backgroundColour[y];
|
||||
|
||||
for( int x = 0; x < width; x++ )
|
||||
for( int x = 0; x < m_width; x++ )
|
||||
{
|
||||
text.setChar( x, (char) (buffer.readByte() & 0xFF) );
|
||||
|
||||
@@ -362,56 +362,56 @@ public class Terminal
|
||||
}
|
||||
}
|
||||
|
||||
palette.read( buffer );
|
||||
m_palette.read( buffer );
|
||||
setChanged();
|
||||
}
|
||||
|
||||
public synchronized CompoundNBT writeToNBT( CompoundNBT nbt )
|
||||
{
|
||||
nbt.putInt( "term_cursorX", cursorX );
|
||||
nbt.putInt( "term_cursorY", cursorY );
|
||||
nbt.putBoolean( "term_cursorBlink", cursorBlink );
|
||||
nbt.putInt( "term_textColour", cursorColour );
|
||||
nbt.putInt( "term_bgColour", cursorBackgroundColour );
|
||||
for( int n = 0; n < height; n++ )
|
||||
nbt.putInt( "term_cursorX", m_cursorX );
|
||||
nbt.putInt( "term_cursorY", m_cursorY );
|
||||
nbt.putBoolean( "term_cursorBlink", m_cursorBlink );
|
||||
nbt.putInt( "term_textColour", m_cursorColour );
|
||||
nbt.putInt( "term_bgColour", m_cursorBackgroundColour );
|
||||
for( int n = 0; n < m_height; n++ )
|
||||
{
|
||||
nbt.putString( "term_text_" + n, text[n].toString() );
|
||||
nbt.putString( "term_textColour_" + n, textColour[n].toString() );
|
||||
nbt.putString( "term_textBgColour_" + n, backgroundColour[n].toString() );
|
||||
nbt.putString( "term_text_" + n, m_text[n].toString() );
|
||||
nbt.putString( "term_textColour_" + n, m_textColour[n].toString() );
|
||||
nbt.putString( "term_textBgColour_" + n, m_backgroundColour[n].toString() );
|
||||
}
|
||||
|
||||
palette.writeToNBT( nbt );
|
||||
m_palette.writeToNBT( nbt );
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public synchronized void readFromNBT( CompoundNBT nbt )
|
||||
{
|
||||
cursorX = nbt.getInt( "term_cursorX" );
|
||||
cursorY = nbt.getInt( "term_cursorY" );
|
||||
cursorBlink = nbt.getBoolean( "term_cursorBlink" );
|
||||
cursorColour = nbt.getInt( "term_textColour" );
|
||||
cursorBackgroundColour = nbt.getInt( "term_bgColour" );
|
||||
m_cursorX = nbt.getInt( "term_cursorX" );
|
||||
m_cursorY = nbt.getInt( "term_cursorY" );
|
||||
m_cursorBlink = nbt.getBoolean( "term_cursorBlink" );
|
||||
m_cursorColour = nbt.getInt( "term_textColour" );
|
||||
m_cursorBackgroundColour = nbt.getInt( "term_bgColour" );
|
||||
|
||||
for( int n = 0; n < height; n++ )
|
||||
for( int n = 0; n < m_height; n++ )
|
||||
{
|
||||
text[n].fill( ' ' );
|
||||
m_text[n].fill( ' ' );
|
||||
if( nbt.contains( "term_text_" + n ) )
|
||||
{
|
||||
text[n].write( nbt.getString( "term_text_" + n ) );
|
||||
m_text[n].write( nbt.getString( "term_text_" + n ) );
|
||||
}
|
||||
textColour[n].fill( base16.charAt( cursorColour ) );
|
||||
m_textColour[n].fill( base16.charAt( m_cursorColour ) );
|
||||
if( nbt.contains( "term_textColour_" + n ) )
|
||||
{
|
||||
textColour[n].write( nbt.getString( "term_textColour_" + n ) );
|
||||
m_textColour[n].write( nbt.getString( "term_textColour_" + n ) );
|
||||
}
|
||||
backgroundColour[n].fill( base16.charAt( cursorBackgroundColour ) );
|
||||
m_backgroundColour[n].fill( base16.charAt( m_cursorBackgroundColour ) );
|
||||
if( nbt.contains( "term_textBgColour_" + n ) )
|
||||
{
|
||||
backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
||||
m_backgroundColour[n].write( nbt.getString( "term_textBgColour_" + n ) );
|
||||
}
|
||||
}
|
||||
|
||||
palette.readFromNBT( nbt );
|
||||
m_palette.readFromNBT( nbt );
|
||||
setChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@ package dan200.computercraft.core.terminal;
|
||||
|
||||
public class TextBuffer
|
||||
{
|
||||
private final char[] text;
|
||||
private final char[] m_text;
|
||||
|
||||
public TextBuffer( char c, int length )
|
||||
{
|
||||
text = new char[length];
|
||||
m_text = new char[length];
|
||||
for( int i = 0; i < length; i++ )
|
||||
{
|
||||
text[i] = c;
|
||||
m_text[i] = c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ public class TextBuffer
|
||||
public TextBuffer( String text, int repetitions )
|
||||
{
|
||||
int textLength = text.length();
|
||||
this.text = new char[textLength * repetitions];
|
||||
m_text = new char[textLength * repetitions];
|
||||
for( int i = 0; i < repetitions; i++ )
|
||||
{
|
||||
for( int j = 0; j < textLength; j++ )
|
||||
{
|
||||
this.text[j + i * textLength] = text.charAt( j );
|
||||
m_text[j + i * textLength] = text.charAt( j );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,37 +44,37 @@ public class TextBuffer
|
||||
public TextBuffer( TextBuffer text, int repetitions )
|
||||
{
|
||||
int textLength = text.length();
|
||||
this.text = new char[textLength * repetitions];
|
||||
m_text = new char[textLength * repetitions];
|
||||
for( int i = 0; i < repetitions; i++ )
|
||||
{
|
||||
for( int j = 0; j < textLength; j++ )
|
||||
{
|
||||
this.text[j + i * textLength] = text.charAt( j );
|
||||
m_text[j + i * textLength] = text.charAt( j );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int length()
|
||||
{
|
||||
return text.length;
|
||||
return m_text.length;
|
||||
}
|
||||
|
||||
public String read()
|
||||
{
|
||||
return read( 0, text.length );
|
||||
return read( 0, m_text.length );
|
||||
}
|
||||
|
||||
public String read( int start )
|
||||
{
|
||||
return read( start, text.length );
|
||||
return read( start, m_text.length );
|
||||
}
|
||||
|
||||
public String read( int start, int end )
|
||||
{
|
||||
start = Math.max( start, 0 );
|
||||
end = Math.min( end, text.length );
|
||||
end = Math.min( end, m_text.length );
|
||||
int textLength = Math.max( end - start, 0 );
|
||||
return new String( text, start, textLength );
|
||||
return new String( m_text, start, textLength );
|
||||
}
|
||||
|
||||
public void write( String text )
|
||||
@@ -92,10 +92,10 @@ public class TextBuffer
|
||||
int pos = start;
|
||||
start = Math.max( start, 0 );
|
||||
end = Math.min( end, pos + text.length() );
|
||||
end = Math.min( end, this.text.length );
|
||||
end = Math.min( end, m_text.length );
|
||||
for( int i = start; i < end; i++ )
|
||||
{
|
||||
this.text[i] = text.charAt( i - pos );
|
||||
m_text[i] = text.charAt( i - pos );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,94 +114,94 @@ public class TextBuffer
|
||||
int pos = start;
|
||||
start = Math.max( start, 0 );
|
||||
end = Math.min( end, pos + text.length() );
|
||||
end = Math.min( end, this.text.length );
|
||||
end = Math.min( end, m_text.length );
|
||||
for( int i = start; i < end; i++ )
|
||||
{
|
||||
this.text[i] = text.charAt( i - pos );
|
||||
m_text[i] = text.charAt( i - pos );
|
||||
}
|
||||
}
|
||||
|
||||
public void fill( char c )
|
||||
{
|
||||
fill( c, 0, text.length );
|
||||
fill( c, 0, m_text.length );
|
||||
}
|
||||
|
||||
public void fill( char c, int start )
|
||||
{
|
||||
fill( c, start, text.length );
|
||||
fill( c, start, m_text.length );
|
||||
}
|
||||
|
||||
public void fill( char c, int start, int end )
|
||||
{
|
||||
start = Math.max( start, 0 );
|
||||
end = Math.min( end, text.length );
|
||||
end = Math.min( end, m_text.length );
|
||||
for( int i = start; i < end; i++ )
|
||||
{
|
||||
text[i] = c;
|
||||
m_text[i] = c;
|
||||
}
|
||||
}
|
||||
|
||||
public void fill( String text )
|
||||
{
|
||||
fill( text, 0, this.text.length );
|
||||
fill( text, 0, m_text.length );
|
||||
}
|
||||
|
||||
public void fill( String text, int start )
|
||||
{
|
||||
fill( text, start, this.text.length );
|
||||
fill( text, start, m_text.length );
|
||||
}
|
||||
|
||||
public void fill( String text, int start, int end )
|
||||
{
|
||||
int pos = start;
|
||||
start = Math.max( start, 0 );
|
||||
end = Math.min( end, this.text.length );
|
||||
end = Math.min( end, m_text.length );
|
||||
|
||||
int textLength = text.length();
|
||||
for( int i = start; i < end; i++ )
|
||||
{
|
||||
this.text[i] = text.charAt( (i - pos) % textLength );
|
||||
m_text[i] = text.charAt( (i - pos) % textLength );
|
||||
}
|
||||
}
|
||||
|
||||
public void fill( TextBuffer text )
|
||||
{
|
||||
fill( text, 0, this.text.length );
|
||||
fill( text, 0, m_text.length );
|
||||
}
|
||||
|
||||
public void fill( TextBuffer text, int start )
|
||||
{
|
||||
fill( text, start, this.text.length );
|
||||
fill( text, start, m_text.length );
|
||||
}
|
||||
|
||||
public void fill( TextBuffer text, int start, int end )
|
||||
{
|
||||
int pos = start;
|
||||
start = Math.max( start, 0 );
|
||||
end = Math.min( end, this.text.length );
|
||||
end = Math.min( end, m_text.length );
|
||||
|
||||
int textLength = text.length();
|
||||
for( int i = start; i < end; i++ )
|
||||
{
|
||||
this.text[i] = text.charAt( (i - pos) % textLength );
|
||||
m_text[i] = text.charAt( (i - pos) % textLength );
|
||||
}
|
||||
}
|
||||
|
||||
public char charAt( int i )
|
||||
{
|
||||
return text[i];
|
||||
return m_text[i];
|
||||
}
|
||||
|
||||
public void setChar( int i, char c )
|
||||
{
|
||||
if( i >= 0 && i < text.length )
|
||||
if( i >= 0 && i < m_text.length )
|
||||
{
|
||||
text[i] = c;
|
||||
m_text[i] = c;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return new String( text );
|
||||
return new String( m_text );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.generators.*;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class BlockModelProvider extends BlockStateProvider
|
||||
private void registerComputer( BlockComputer block )
|
||||
{
|
||||
VariantBlockStateBuilder builder = getVariantBuilder( block );
|
||||
for( ComputerState state : BlockComputer.STATE.getPossibleValues() )
|
||||
for( ComputerState state : BlockComputer.STATE.getAllowedValues() )
|
||||
{
|
||||
BlockModelBuilder model = models()
|
||||
.getBuilder( suffix( block, "_" + state ) )
|
||||
@@ -61,7 +62,7 @@ public class BlockModelProvider extends BlockStateProvider
|
||||
.texture( "side", suffix( block, "_side" ) )
|
||||
.texture( "front", suffix( block, "_front" + toSuffix( state ) ) );
|
||||
|
||||
for( Direction facing : BlockComputer.FACING.getPossibleValues() )
|
||||
for( Direction facing : BlockComputer.FACING.getAllowedValues() )
|
||||
{
|
||||
builder.partialState()
|
||||
.with( BlockComputer.STATE, state )
|
||||
@@ -92,14 +93,14 @@ public class BlockModelProvider extends BlockStateProvider
|
||||
registerMonitorModel( name, "_ud", 21, 6, 0, 37 );
|
||||
|
||||
VariantBlockStateBuilder builder = getVariantBuilder( block );
|
||||
for( MonitorEdgeState edge : BlockMonitor.STATE.getPossibleValues() )
|
||||
for( MonitorEdgeState edge : BlockMonitor.STATE.getAllowedValues() )
|
||||
{
|
||||
String suffix = edge == MonitorEdgeState.NONE ? "" : "_" + edge.getSerializedName();
|
||||
String suffix = edge == MonitorEdgeState.NONE ? "" : "_" + edge.getString();
|
||||
ModelFile model = models().getBuilder( suffix( block, suffix ) );
|
||||
|
||||
for( Direction facing : BlockMonitor.FACING.getPossibleValues() )
|
||||
for( Direction facing : BlockMonitor.FACING.getAllowedValues() )
|
||||
{
|
||||
for( Direction orientation : BlockMonitor.ORIENTATION.getPossibleValues() )
|
||||
for( Direction orientation : BlockMonitor.ORIENTATION.getAllowedValues() )
|
||||
{
|
||||
builder.partialState()
|
||||
.with( BlockMonitor.STATE, edge )
|
||||
@@ -137,7 +138,7 @@ public class BlockModelProvider extends BlockStateProvider
|
||||
|
||||
private static int toYAngle( Direction direction )
|
||||
{
|
||||
return ((int) direction.toYRot() + 180) % 360;
|
||||
return ((int) direction.getHorizontalAngle() + 180) % 360;
|
||||
}
|
||||
|
||||
private static String toSuffix( ComputerState state )
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Generators
|
||||
DataGenerator generator = event.getGenerator();
|
||||
generator.addProvider( new Recipes( generator ) );
|
||||
generator.addProvider( new LootTables( generator ) );
|
||||
generator.addProvider( new Tags( generator ) );
|
||||
generator.addProvider( new Tags( generator, event.getExistingFileHelper() ) );
|
||||
generator.addProvider( new BlockModelProvider( generator, event.getExistingFileHelper() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ import dan200.computercraft.ComputerCraft;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.loot.LootParameterSets;
|
||||
import net.minecraft.loot.LootTable;
|
||||
import net.minecraft.loot.LootTableManager;
|
||||
import net.minecraft.loot.ValidationTracker;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.LootParameterSets;
|
||||
import net.minecraft.world.storage.loot.LootTable;
|
||||
import net.minecraft.world.storage.loot.LootTableManager;
|
||||
import net.minecraft.world.storage.loot.ValidationTracker;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
@@ -40,17 +40,17 @@ public abstract class LootTableProvider implements IDataProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run( @Nonnull DirectoryCache cache )
|
||||
public void act( @Nonnull DirectoryCache cache )
|
||||
{
|
||||
Map<ResourceLocation, LootTable> tables = new HashMap<>();
|
||||
ValidationTracker validation = new ValidationTracker( LootParameterSets.ALL_PARAMS, x -> null, tables::get );
|
||||
ValidationTracker validation = new ValidationTracker( LootParameterSets.GENERIC, x -> null, tables::get );
|
||||
|
||||
registerLoot( ( id, table ) -> {
|
||||
if( tables.containsKey( id ) ) validation.reportProblem( "Duplicate loot tables for " + id );
|
||||
if( tables.containsKey( id ) ) validation.addProblem( "Duplicate loot tables for " + id );
|
||||
tables.put( id, table );
|
||||
} );
|
||||
|
||||
tables.forEach( ( key, value ) -> LootTableManager.validate( validation, key, value ) );
|
||||
tables.forEach( ( key, value ) -> LootTableManager.validateLootTable( validation, key, value ) );
|
||||
|
||||
Multimap<String, String> problems = validation.getProblems();
|
||||
if( !problems.isEmpty() )
|
||||
@@ -64,7 +64,7 @@ public abstract class LootTableProvider implements IDataProvider
|
||||
Path path = getPath( key );
|
||||
try
|
||||
{
|
||||
IDataProvider.save( GSON, cache, LootTableManager.serialize( value ), path );
|
||||
IDataProvider.save( GSON, cache, LootTableManager.toJson( value ), path );
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
|
||||
@@ -13,10 +13,10 @@ import dan200.computercraft.shared.data.PlayerCreativeLootCondition;
|
||||
import dan200.computercraft.shared.proxy.ComputerCraftProxyCommon;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.loot.*;
|
||||
import net.minecraft.loot.conditions.Alternative;
|
||||
import net.minecraft.loot.conditions.SurvivesExplosion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.storage.loot.*;
|
||||
import net.minecraft.world.storage.loot.conditions.Alternative;
|
||||
import net.minecraft.world.storage.loot.conditions.SurvivesExplosion;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -47,8 +47,8 @@ public class LootTables extends LootTableProvider
|
||||
computerDrop( add, Registry.ModBlocks.TURTLE_ADVANCED );
|
||||
|
||||
add.accept( ComputerCraftProxyCommon.ForgeHandlers.LOOT_TREASURE_DISK, LootTable
|
||||
.lootTable()
|
||||
.setParamSet( LootParameterSets.ALL_PARAMS )
|
||||
.builder()
|
||||
.setParameterSet( LootParameterSets.GENERIC )
|
||||
.build() );
|
||||
}
|
||||
|
||||
@@ -56,13 +56,13 @@ public class LootTables extends LootTableProvider
|
||||
{
|
||||
Block block = wrapper.get();
|
||||
add.accept( block.getLootTable(), LootTable
|
||||
.lootTable()
|
||||
.setParamSet( LootParameterSets.BLOCK )
|
||||
.withPool( LootPool.lootPool()
|
||||
.builder()
|
||||
.setParameterSet( LootParameterSets.BLOCK )
|
||||
.addLootPool( LootPool.builder()
|
||||
.name( "main" )
|
||||
.setRolls( ConstantRange.exactly( 1 ) )
|
||||
.add( ItemLootEntry.lootTableItem( block ) )
|
||||
.when( SurvivesExplosion.survivesExplosion() )
|
||||
.rolls( ConstantRange.of( 1 ) )
|
||||
.addEntry( ItemLootEntry.builder( block ) )
|
||||
.acceptCondition( SurvivesExplosion.builder() )
|
||||
).build() );
|
||||
}
|
||||
|
||||
@@ -70,16 +70,16 @@ public class LootTables extends LootTableProvider
|
||||
{
|
||||
Block block = wrapper.get();
|
||||
add.accept( block.getLootTable(), LootTable
|
||||
.lootTable()
|
||||
.setParamSet( LootParameterSets.BLOCK )
|
||||
.withPool( LootPool.lootPool()
|
||||
.builder()
|
||||
.setParameterSet( LootParameterSets.BLOCK )
|
||||
.addLootPool( LootPool.builder()
|
||||
.name( "main" )
|
||||
.setRolls( ConstantRange.exactly( 1 ) )
|
||||
.add( DynamicLootEntry.dynamicEntry( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) )
|
||||
.when( Alternative.alternative(
|
||||
BlockNamedEntityLootCondition.builder(),
|
||||
HasComputerIdLootCondition.builder(),
|
||||
PlayerCreativeLootCondition.builder().invert()
|
||||
.rolls( ConstantRange.of( 1 ) )
|
||||
.addEntry( DynamicLootEntry.func_216162_a( new ResourceLocation( ComputerCraft.MOD_ID, "computer" ) ) )
|
||||
.acceptCondition( Alternative.builder(
|
||||
BlockNamedEntityLootCondition.BUILDER,
|
||||
HasComputerIdLootCondition.BUILDER,
|
||||
PlayerCreativeLootCondition.BUILDER.inverted()
|
||||
) )
|
||||
).build() );
|
||||
}
|
||||
|
||||
@@ -50,42 +50,42 @@ public final class RecipeWrapper implements IFinishedRecipe
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serializeRecipeData( @Nonnull JsonObject jsonObject )
|
||||
public void serialize( @Nonnull JsonObject jsonObject )
|
||||
{
|
||||
recipe.serializeRecipeData( jsonObject );
|
||||
recipe.serialize( jsonObject );
|
||||
|
||||
if( resultData != null )
|
||||
{
|
||||
JsonObject object = JSONUtils.getAsJsonObject( jsonObject, "result" );
|
||||
JsonObject object = JSONUtils.getJsonObject( jsonObject, "result" );
|
||||
object.addProperty( "nbt", resultData.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ResourceLocation getId()
|
||||
public ResourceLocation getID()
|
||||
{
|
||||
return recipe.getId();
|
||||
return recipe.getID();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IRecipeSerializer<?> getType()
|
||||
public IRecipeSerializer<?> getSerializer()
|
||||
{
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject serializeAdvancement()
|
||||
public JsonObject getAdvancementJson()
|
||||
{
|
||||
return recipe.serializeAdvancement();
|
||||
return recipe.getAdvancementJson();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ResourceLocation getAdvancementId()
|
||||
public ResourceLocation getAdvancementID()
|
||||
{
|
||||
return recipe.getAdvancementId();
|
||||
return recipe.getAdvancementID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import dan200.computercraft.data.Tags.CCTags;
|
||||
import dan200.computercraft.shared.PocketUpgrades;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import dan200.computercraft.shared.TurtleUpgrades;
|
||||
import dan200.computercraft.shared.common.IColouredItem;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
|
||||
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
|
||||
@@ -22,7 +21,7 @@ import net.minecraft.advancements.criterion.ItemPredicate;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.data.*;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.util.IItemProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.Tags;
|
||||
@@ -39,7 +38,7 @@ public class Recipes extends RecipeProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildShapelessRecipes( @Nonnull Consumer<IFinishedRecipe> add )
|
||||
protected void registerRecipes( @Nonnull Consumer<IFinishedRecipe> add )
|
||||
{
|
||||
basicRecipes( add );
|
||||
diskColours( add );
|
||||
@@ -57,15 +56,15 @@ public class Recipes extends RecipeProvider
|
||||
for( Colour colour : Colour.VALUES )
|
||||
{
|
||||
ShapelessRecipeBuilder
|
||||
.shapeless( Registry.ModItems.DISK.get() )
|
||||
.requires( Tags.Items.DUSTS_REDSTONE )
|
||||
.requires( Items.PAPER )
|
||||
.requires( DyeItem.byColor( ofColour( colour ) ) )
|
||||
.group( "computercraft:disk" )
|
||||
.unlocks( "has_drive", inventoryChange( Registry.ModBlocks.DISK_DRIVE.get() ) )
|
||||
.save( RecipeWrapper.wrap(
|
||||
.shapelessRecipe( Registry.ModItems.DISK.get() )
|
||||
.addIngredient( Tags.Items.DUSTS_REDSTONE )
|
||||
.addIngredient( Items.PAPER )
|
||||
.addIngredient( DyeItem.getItem( ofColour( colour ) ) )
|
||||
.setGroup( "computercraft:disk" )
|
||||
.addCriterion( "has_drive", inventoryChange( Registry.ModBlocks.DISK_DRIVE.get() ) )
|
||||
.build( RecipeWrapper.wrap(
|
||||
ImpostorShapelessRecipe.SERIALIZER, add,
|
||||
x -> x.putInt( IColouredItem.NBT_COLOUR, colour.getHex() )
|
||||
x -> x.putInt( "color", colour.getHex() )
|
||||
), new ResourceLocation( ComputerCraft.MOD_ID, "disk_" + (colour.ordinal() + 1) ) );
|
||||
}
|
||||
}
|
||||
@@ -87,14 +86,14 @@ public class Recipes extends RecipeProvider
|
||||
TurtleUpgrades.getVanillaUpgrades().forEach( upgrade -> {
|
||||
ItemStack result = TurtleItemFactory.create( -1, null, -1, family, null, upgrade, -1, null );
|
||||
ShapedRecipeBuilder
|
||||
.shaped( result.getItem() )
|
||||
.group( String.format( "%s:turtle_%s", ComputerCraft.MOD_ID, nameId ) )
|
||||
.pattern( "#T" )
|
||||
.define( '#', base.getItem() )
|
||||
.define( 'T', upgrade.getCraftingItem().getItem() )
|
||||
.unlocks( "has_items",
|
||||
.shapedRecipe( result.getItem() )
|
||||
.setGroup( String.format( "%s:turtle_%s", ComputerCraft.MOD_ID, nameId ) )
|
||||
.patternLine( "#T" )
|
||||
.key( '#', base.getItem() )
|
||||
.key( 'T', upgrade.getCraftingItem().getItem() )
|
||||
.addCriterion( "has_items",
|
||||
inventoryChange( base.getItem(), upgrade.getCraftingItem().getItem() ) )
|
||||
.save(
|
||||
.build(
|
||||
RecipeWrapper.wrap( ImpostorRecipe.SERIALIZER, add, result.getTag() ),
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, String.format( "turtle_%s/%s/%s",
|
||||
nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath()
|
||||
@@ -121,15 +120,15 @@ public class Recipes extends RecipeProvider
|
||||
PocketUpgrades.getVanillaUpgrades().forEach( upgrade -> {
|
||||
ItemStack result = PocketComputerItemFactory.create( -1, null, -1, family, null );
|
||||
ShapedRecipeBuilder
|
||||
.shaped( result.getItem() )
|
||||
.group( String.format( "%s:pocket_%s", ComputerCraft.MOD_ID, nameId ) )
|
||||
.pattern( "#" )
|
||||
.pattern( "P" )
|
||||
.define( '#', base.getItem() )
|
||||
.define( 'P', upgrade.getCraftingItem().getItem() )
|
||||
.unlocks( "has_items",
|
||||
.shapedRecipe( result.getItem() )
|
||||
.setGroup( String.format( "%s:pocket_%s", ComputerCraft.MOD_ID, nameId ) )
|
||||
.patternLine( "#" )
|
||||
.patternLine( "P" )
|
||||
.key( '#', base.getItem() )
|
||||
.key( 'P', upgrade.getCraftingItem().getItem() )
|
||||
.addCriterion( "has_items",
|
||||
inventoryChange( base.getItem(), upgrade.getCraftingItem().getItem() ) )
|
||||
.save(
|
||||
.build(
|
||||
RecipeWrapper.wrap( ImpostorRecipe.SERIALIZER, add, result.getTag() ),
|
||||
new ResourceLocation( ComputerCraft.MOD_ID, String.format( "pocket_%s/%s/%s",
|
||||
nameId, upgrade.getUpgradeID().getNamespace(), upgrade.getUpgradeID().getPath()
|
||||
@@ -142,167 +141,167 @@ public class Recipes extends RecipeProvider
|
||||
private void basicRecipes( @Nonnull Consumer<IFinishedRecipe> add )
|
||||
{
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModItems.CABLE.get(), 6 )
|
||||
.pattern( " # " )
|
||||
.pattern( "#R#" )
|
||||
.pattern( " # " )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_modem", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModItems.CABLE.get(), 6 )
|
||||
.patternLine( " # " )
|
||||
.patternLine( "#R#" )
|
||||
.patternLine( " # " )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.addCriterion( "has_modem", inventoryChange( CCTags.COMPUTER ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.COMPUTER_NORMAL.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#R#" )
|
||||
.pattern( "#G#" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_redstone", inventoryChange( Tags.Items.DUSTS_REDSTONE ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.COMPUTER_NORMAL.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#R#" )
|
||||
.patternLine( "#G#" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.key( 'G', Tags.Items.GLASS_PANES )
|
||||
.addCriterion( "has_redstone", inventoryChange( Tags.Items.DUSTS_REDSTONE ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.COMPUTER_ADVANCED.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#R#" )
|
||||
.pattern( "#G#" )
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_components", inventoryChange( Items.REDSTONE, Items.GOLD_INGOT ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.COMPUTER_ADVANCED.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#R#" )
|
||||
.patternLine( "#G#" )
|
||||
.key( '#', Tags.Items.INGOTS_GOLD )
|
||||
.key( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.key( 'G', Tags.Items.GLASS_PANES )
|
||||
.addCriterion( "has_components", inventoryChange( Items.REDSTONE, Items.GOLD_INGOT ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.COMPUTER_COMMAND.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#R#" )
|
||||
.pattern( "#G#" )
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'R', Blocks.COMMAND_BLOCK )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_components", inventoryChange( Blocks.COMMAND_BLOCK ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.COMPUTER_COMMAND.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#R#" )
|
||||
.patternLine( "#G#" )
|
||||
.key( '#', Tags.Items.INGOTS_GOLD )
|
||||
.key( 'R', Blocks.COMMAND_BLOCK )
|
||||
.key( 'G', Tags.Items.GLASS_PANES )
|
||||
.addCriterion( "has_components", inventoryChange( Blocks.COMMAND_BLOCK ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.DISK_DRIVE.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#R#" )
|
||||
.pattern( "#R#" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.DISK_DRIVE.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#R#" )
|
||||
.patternLine( "#R#" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.MONITOR_NORMAL.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#G#" )
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.MONITOR_NORMAL.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#G#" )
|
||||
.patternLine( "###" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'G', Tags.Items.GLASS_PANES )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.MONITOR_ADVANCED.get(), 4 )
|
||||
.pattern( "###" )
|
||||
.pattern( "#G#" )
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.MONITOR_ADVANCED.get(), 4 )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#G#" )
|
||||
.patternLine( "###" )
|
||||
.key( '#', Tags.Items.INGOTS_GOLD )
|
||||
.key( 'G', Tags.Items.GLASS_PANES )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModItems.POCKET_COMPUTER_NORMAL.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#A#" )
|
||||
.pattern( "#G#" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'A', Items.GOLDEN_APPLE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModItems.POCKET_COMPUTER_NORMAL.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#A#" )
|
||||
.patternLine( "#G#" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'A', Items.GOLDEN_APPLE )
|
||||
.key( 'G', Tags.Items.GLASS_PANES )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.addCriterion( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModItems.POCKET_COMPUTER_ADVANCED.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#A#" )
|
||||
.pattern( "#G#" )
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'A', Items.GOLDEN_APPLE )
|
||||
.define( 'G', Tags.Items.GLASS_PANES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModItems.POCKET_COMPUTER_ADVANCED.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#A#" )
|
||||
.patternLine( "#G#" )
|
||||
.key( '#', Tags.Items.INGOTS_GOLD )
|
||||
.key( 'A', Items.GOLDEN_APPLE )
|
||||
.key( 'G', Tags.Items.GLASS_PANES )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.addCriterion( "has_apple", inventoryChange( Items.GOLDEN_APPLE ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.PRINTER.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#R#" )
|
||||
.pattern( "#D#" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.define( 'D', Tags.Items.DYES )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.PRINTER.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#R#" )
|
||||
.patternLine( "#D#" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.key( 'D', Tags.Items.DYES )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.SPEAKER.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#N#" )
|
||||
.pattern( "#R#" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'N', Blocks.NOTE_BLOCK )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.SPEAKER.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#N#" )
|
||||
.patternLine( "#R#" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'N', Blocks.NOTE_BLOCK )
|
||||
.key( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#R#" )
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_cable", inventoryChange( Registry.ModItems.CABLE.get() ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#R#" )
|
||||
.patternLine( "###" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'R', Tags.Items.DUSTS_REDSTONE )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.addCriterion( "has_cable", inventoryChange( Registry.ModItems.CABLE.get() ) )
|
||||
.build( add );
|
||||
|
||||
ShapelessRecipeBuilder
|
||||
.shapeless( Registry.ModBlocks.WIRED_MODEM_FULL.get() )
|
||||
.requires( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.unlocks( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.save( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_from" ) );
|
||||
.shapelessRecipe( Registry.ModBlocks.WIRED_MODEM_FULL.get() )
|
||||
.addIngredient( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.addCriterion( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.build( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_from" ) );
|
||||
ShapelessRecipeBuilder
|
||||
.shapeless( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.requires( Registry.ModBlocks.WIRED_MODEM_FULL.get() )
|
||||
.unlocks( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.save( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_to" ) );
|
||||
.shapelessRecipe( Registry.ModItems.WIRED_MODEM.get() )
|
||||
.addIngredient( Registry.ModBlocks.WIRED_MODEM_FULL.get() )
|
||||
.addCriterion( "has_modem", inventoryChange( CCTags.WIRED_MODEM ) )
|
||||
.build( add, new ResourceLocation( ComputerCraft.MOD_ID, "wired_modem_full_to" ) );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#E#" )
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.STONE )
|
||||
.define( 'E', Tags.Items.ENDER_PEARLS )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#E#" )
|
||||
.patternLine( "###" )
|
||||
.key( '#', Tags.Items.STONE )
|
||||
.key( 'E', Tags.Items.ENDER_PEARLS )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.build( add );
|
||||
|
||||
ShapedRecipeBuilder
|
||||
.shaped( Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get() )
|
||||
.pattern( "###" )
|
||||
.pattern( "#E#" )
|
||||
.pattern( "###" )
|
||||
.define( '#', Tags.Items.INGOTS_GOLD )
|
||||
.define( 'E', Items.ENDER_EYE )
|
||||
.unlocks( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.unlocks( "has_wireless", inventoryChange( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) )
|
||||
.save( add );
|
||||
.shapedRecipe( Registry.ModBlocks.WIRELESS_MODEM_ADVANCED.get() )
|
||||
.patternLine( "###" )
|
||||
.patternLine( "#E#" )
|
||||
.patternLine( "###" )
|
||||
.key( '#', Tags.Items.INGOTS_GOLD )
|
||||
.key( 'E', Items.ENDER_EYE )
|
||||
.addCriterion( "has_computer", inventoryChange( CCTags.COMPUTER ) )
|
||||
.addCriterion( "has_wireless", inventoryChange( Registry.ModBlocks.WIRELESS_MODEM_NORMAL.get() ) )
|
||||
.build( add );
|
||||
}
|
||||
|
||||
private static DyeColor ofColour( Colour colour )
|
||||
@@ -310,13 +309,13 @@ public class Recipes extends RecipeProvider
|
||||
return DyeColor.byId( 15 - colour.ordinal() );
|
||||
}
|
||||
|
||||
private static InventoryChangeTrigger.Instance inventoryChange( Tag<Item> stack )
|
||||
private static InventoryChangeTrigger.Instance inventoryChange( ITag<Item> stack )
|
||||
{
|
||||
return InventoryChangeTrigger.Instance.hasItem( ItemPredicate.Builder.item().of( stack ).build() );
|
||||
return InventoryChangeTrigger.Instance.forItems( ItemPredicate.Builder.create().tag( stack ).build() );
|
||||
}
|
||||
|
||||
private static InventoryChangeTrigger.Instance inventoryChange( IItemProvider... stack )
|
||||
{
|
||||
return InventoryChangeTrigger.Instance.hasItem( stack );
|
||||
return InventoryChangeTrigger.Instance.forItems( stack );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,46 +7,55 @@ package dan200.computercraft.data;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.Registry;
|
||||
import net.minecraft.data.BlockTagsProvider;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.ItemTagsProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.tags.Tag;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import static dan200.computercraft.data.Tags.CCTags.*;
|
||||
|
||||
public class Tags extends ItemTagsProvider
|
||||
{
|
||||
private static final ITag.INamedTag<Item> PIGLIN_LOVED = ItemTags.PIGLIN_LOVED;
|
||||
|
||||
public static class CCTags
|
||||
{
|
||||
public static final Tag<Item> COMPUTER = item( "computer" );
|
||||
public static final Tag<Item> TURTLE = item( "turtle" );
|
||||
public static final Tag<Item> WIRED_MODEM = item( "wired_modem" );
|
||||
public static final Tag<Item> MONITOR = item( "monitor" );
|
||||
public static final ITag.INamedTag<Item> COMPUTER = item( "computer" );
|
||||
public static final ITag.INamedTag<Item> TURTLE = item( "turtle" );
|
||||
public static final ITag.INamedTag<Item> WIRED_MODEM = item( "wired_modem" );
|
||||
public static final ITag.INamedTag<Item> MONITOR = item( "monitor" );
|
||||
}
|
||||
|
||||
public Tags( DataGenerator generator )
|
||||
public Tags( DataGenerator generator, ExistingFileHelper helper )
|
||||
{
|
||||
super( generator );
|
||||
super( generator, new BlockTagsProvider( generator, ComputerCraft.MOD_ID, helper ), ComputerCraft.MOD_ID, helper );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTags()
|
||||
protected void registerTags()
|
||||
{
|
||||
tag( COMPUTER )
|
||||
.add( Registry.ModItems.COMPUTER_NORMAL.get() )
|
||||
.add( Registry.ModItems.COMPUTER_ADVANCED.get() )
|
||||
.add( Registry.ModItems.COMPUTER_COMMAND.get() );
|
||||
tag( TURTLE ).add( Registry.ModItems.TURTLE_NORMAL.get(), Registry.ModItems.TURTLE_ADVANCED.get() );
|
||||
tag( WIRED_MODEM ).add( Registry.ModItems.WIRED_MODEM.get(), Registry.ModItems.WIRED_MODEM_FULL.get() );
|
||||
tag( MONITOR )
|
||||
.add( Registry.ModItems.MONITOR_NORMAL.get() )
|
||||
.add( Registry.ModItems.MONITOR_ADVANCED.get() );
|
||||
getOrCreateBuilder( COMPUTER ).add(
|
||||
Registry.ModItems.COMPUTER_NORMAL.get(),
|
||||
Registry.ModItems.COMPUTER_ADVANCED.get(),
|
||||
Registry.ModItems.COMPUTER_COMMAND.get()
|
||||
);
|
||||
getOrCreateBuilder( TURTLE ).add( Registry.ModItems.TURTLE_NORMAL.get(), Registry.ModItems.TURTLE_ADVANCED.get() );
|
||||
getOrCreateBuilder( WIRED_MODEM ).add( Registry.ModItems.WIRED_MODEM.get(), Registry.ModItems.WIRED_MODEM_FULL.get() );
|
||||
getOrCreateBuilder( MONITOR ).add( Registry.ModItems.MONITOR_NORMAL.get(), Registry.ModItems.MONITOR_ADVANCED.get() );
|
||||
|
||||
getOrCreateBuilder( PIGLIN_LOVED ).add(
|
||||
Registry.ModItems.COMPUTER_ADVANCED.get(), Registry.ModItems.TURTLE_ADVANCED.get(),
|
||||
Registry.ModItems.WIRELESS_MODEM_ADVANCED.get(), Registry.ModItems.POCKET_COMPUTER_ADVANCED.get(),
|
||||
Registry.ModItems.MONITOR_ADVANCED.get()
|
||||
);
|
||||
}
|
||||
|
||||
private static Tag<Item> item( String name )
|
||||
private static ITag.INamedTag<Item> item( String name )
|
||||
{
|
||||
return new ItemTags.Wrapper( new ResourceLocation( ComputerCraft.MOD_ID, name ) );
|
||||
return ItemTags.makeWrapperTag( new ResourceLocation( ComputerCraft.MOD_ID, name ).toString() );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ public final class BundledRedstone
|
||||
|
||||
public static int getDefaultOutput( @Nonnull World world, @Nonnull BlockPos pos, @Nonnull Direction side )
|
||||
{
|
||||
return World.isInWorldBounds( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1;
|
||||
return World.isValid( pos ) ? DefaultBundledRedstoneProvider.getDefaultBundledRedstoneOutput( world, pos, side ) : -1;
|
||||
}
|
||||
|
||||
private static int getUnmaskedOutput( World world, BlockPos pos, Direction side )
|
||||
{
|
||||
if( !World.isInWorldBounds( pos ) ) return -1;
|
||||
if( !World.isValid( pos ) ) return -1;
|
||||
|
||||
// Try the providers in order:
|
||||
int combinedSignal = -1;
|
||||
|
||||
@@ -16,8 +16,6 @@ import dan200.computercraft.core.apis.http.options.Action;
|
||||
import dan200.computercraft.core.apis.http.options.AddressRuleConfig;
|
||||
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.Builder;
|
||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -30,6 +28,9 @@ import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static net.minecraftforge.common.ForgeConfigSpec.Builder;
|
||||
import static net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
||||
|
||||
@Mod.EventBusSubscriber( modid = ComputerCraft.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD )
|
||||
public final class Config
|
||||
{
|
||||
|
||||
@@ -40,13 +40,13 @@ public final class Peripherals
|
||||
@Nullable
|
||||
public static IPeripheral getPeripheral( World world, BlockPos pos, Direction side, NonNullConsumer<LazyOptional<IPeripheral>> invalidate )
|
||||
{
|
||||
return World.isInWorldBounds( pos ) && !world.isClientSide ? getPeripheralAt( world, pos, side, invalidate ) : null;
|
||||
return World.isValid( pos ) && !world.isRemote ? getPeripheralAt( world, pos, side, invalidate ) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IPeripheral getPeripheralAt( World world, BlockPos pos, Direction side, NonNullConsumer<LazyOptional<IPeripheral>> invalidate )
|
||||
{
|
||||
TileEntity block = world.getBlockEntity( pos );
|
||||
TileEntity block = world.getTileEntity( pos );
|
||||
if( block != null )
|
||||
{
|
||||
LazyOptional<IPeripheral> peripheral = block.getCapability( CAPABILITY_PERIPHERAL, side );
|
||||
|
||||
@@ -7,9 +7,7 @@ package dan200.computercraft.shared;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.pocket.IPocketUpgrade;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenCustomHashMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
|
||||
@@ -20,7 +18,7 @@ import java.util.*;
|
||||
public final class PocketUpgrades
|
||||
{
|
||||
private static final Map<String, IPocketUpgrade> upgrades = new HashMap<>();
|
||||
private static final Map<IPocketUpgrade, String> upgradeOwners = new Object2ObjectLinkedOpenCustomHashMap<>( Util.identityStrategy() );
|
||||
private static final IdentityHashMap<IPocketUpgrade, String> upgradeOwners = new IdentityHashMap<>();
|
||||
|
||||
private PocketUpgrades() {}
|
||||
|
||||
|
||||
@@ -92,21 +92,21 @@ public final class Registry
|
||||
|
||||
public static final class ModBlocks
|
||||
{
|
||||
static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>( ForgeRegistries.BLOCKS, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<Block> BLOCKS = DeferredRegister.create( ForgeRegistries.BLOCKS, ComputerCraft.MOD_ID );
|
||||
|
||||
private static Block.Properties properties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 2 );
|
||||
return Block.Properties.create( Material.ROCK ).hardnessAndResistance( 2 );
|
||||
}
|
||||
|
||||
private static Block.Properties turtleProperties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 2.5f );
|
||||
return Block.Properties.create( Material.ROCK ).hardnessAndResistance( 2.5f );
|
||||
}
|
||||
|
||||
private static Block.Properties modemProperties()
|
||||
{
|
||||
return Block.Properties.of( Material.STONE ).strength( 1.5f );
|
||||
return Block.Properties.create( Material.ROCK ).hardnessAndResistance( 1.5f );
|
||||
}
|
||||
|
||||
public static final RegistryObject<BlockComputer> COMPUTER_NORMAL = BLOCKS.register( "computer_normal",
|
||||
@@ -115,7 +115,7 @@ public final class Registry
|
||||
() -> new BlockComputer( properties(), ComputerFamily.ADVANCED, ModTiles.COMPUTER_ADVANCED ) );
|
||||
|
||||
public static final RegistryObject<BlockComputer> COMPUTER_COMMAND = BLOCKS.register( "computer_command", () -> new BlockComputer(
|
||||
Block.Properties.of( Material.STONE ).strength( -1, 6000000.0F ),
|
||||
Block.Properties.create( Material.ROCK ).hardnessAndResistance( -1, 6000000.0F ),
|
||||
ComputerFamily.COMMAND, ModTiles.COMPUTER_COMMAND
|
||||
) );
|
||||
|
||||
@@ -145,7 +145,7 @@ public final class Registry
|
||||
|
||||
public static class ModTiles
|
||||
{
|
||||
static final DeferredRegister<TileEntityType<?>> TILES = new DeferredRegister<>( ForgeRegistries.TILE_ENTITIES, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<TileEntityType<?>> TILES = DeferredRegister.create( ForgeRegistries.TILE_ENTITIES, ComputerCraft.MOD_ID );
|
||||
|
||||
private static <T extends TileEntity> RegistryObject<TileEntityType<T>> ofBlock( RegistryObject<? extends Block> block, Function<TileEntityType<T>, T> factory )
|
||||
{
|
||||
@@ -183,11 +183,11 @@ public final class Registry
|
||||
|
||||
public static final class ModItems
|
||||
{
|
||||
static final DeferredRegister<Item> ITEMS = new DeferredRegister<>( ForgeRegistries.ITEMS, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<Item> ITEMS = DeferredRegister.create( ForgeRegistries.ITEMS, ComputerCraft.MOD_ID );
|
||||
|
||||
private static Item.Properties properties()
|
||||
{
|
||||
return new Item.Properties().tab( mainItemGroup );
|
||||
return new Item.Properties().group( mainItemGroup );
|
||||
}
|
||||
|
||||
private static <B extends Block, I extends Item> RegistryObject<I> ofBlock( RegistryObject<B> parent, BiFunction<B, Item.Properties, I> supplier )
|
||||
@@ -200,24 +200,24 @@ public final class Registry
|
||||
public static final RegistryObject<ItemComputer> COMPUTER_COMMAND = ofBlock( ModBlocks.COMPUTER_COMMAND, ItemComputer::new );
|
||||
|
||||
public static final RegistryObject<ItemPocketComputer> POCKET_COMPUTER_NORMAL = ITEMS.register( "pocket_computer_normal",
|
||||
() -> new ItemPocketComputer( properties().stacksTo( 1 ), ComputerFamily.NORMAL ) );
|
||||
() -> new ItemPocketComputer( properties().maxStackSize( 1 ), ComputerFamily.NORMAL ) );
|
||||
public static final RegistryObject<ItemPocketComputer> POCKET_COMPUTER_ADVANCED = ITEMS.register( "pocket_computer_advanced",
|
||||
() -> new ItemPocketComputer( properties().stacksTo( 1 ), ComputerFamily.ADVANCED ) );
|
||||
() -> new ItemPocketComputer( properties().maxStackSize( 1 ), ComputerFamily.ADVANCED ) );
|
||||
|
||||
public static final RegistryObject<ItemTurtle> TURTLE_NORMAL = ofBlock( ModBlocks.TURTLE_NORMAL, ItemTurtle::new );
|
||||
public static final RegistryObject<ItemTurtle> TURTLE_ADVANCED = ofBlock( ModBlocks.TURTLE_ADVANCED, ItemTurtle::new );
|
||||
|
||||
public static final RegistryObject<ItemDisk> DISK =
|
||||
ITEMS.register( "disk", () -> new ItemDisk( properties().stacksTo( 1 ) ) );
|
||||
ITEMS.register( "disk", () -> new ItemDisk( properties().maxStackSize( 1 ) ) );
|
||||
public static final RegistryObject<ItemTreasureDisk> TREASURE_DISK =
|
||||
ITEMS.register( "treasure_disk", () -> new ItemTreasureDisk( properties().stacksTo( 1 ) ) );
|
||||
ITEMS.register( "treasure_disk", () -> new ItemTreasureDisk( properties().maxStackSize( 1 ) ) );
|
||||
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_PAGE = ITEMS.register( "printed_page",
|
||||
() -> new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.PAGE ) );
|
||||
() -> new ItemPrintout( properties().maxStackSize( 1 ), ItemPrintout.Type.PAGE ) );
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_PAGES = ITEMS.register( "printed_pages",
|
||||
() -> new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.PAGES ) );
|
||||
() -> new ItemPrintout( properties().maxStackSize( 1 ), ItemPrintout.Type.PAGES ) );
|
||||
public static final RegistryObject<ItemPrintout> PRINTED_BOOK = ITEMS.register( "printed_book",
|
||||
() -> new ItemPrintout( properties().stacksTo( 1 ), ItemPrintout.Type.BOOK ) );
|
||||
() -> new ItemPrintout( properties().maxStackSize( 1 ), ItemPrintout.Type.BOOK ) );
|
||||
|
||||
public static final RegistryObject<BlockItem> SPEAKER = ofBlock( ModBlocks.SPEAKER, BlockItem::new );
|
||||
public static final RegistryObject<BlockItem> DISK_DRIVE = ofBlock( ModBlocks.DISK_DRIVE, BlockItem::new );
|
||||
@@ -281,19 +281,19 @@ public final class Registry
|
||||
|
||||
public static class ModEntities
|
||||
{
|
||||
static final DeferredRegister<EntityType<?>> ENTITIES = new DeferredRegister<>( ForgeRegistries.ENTITIES, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create( ForgeRegistries.ENTITIES, ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<EntityType<TurtlePlayer>> TURTLE_PLAYER = ENTITIES.register( "turtle_player", () ->
|
||||
EntityType.Builder.<TurtlePlayer>createNothing( EntityClassification.MISC )
|
||||
.noSave()
|
||||
.noSummon()
|
||||
.sized( 0, 0 )
|
||||
EntityType.Builder.<TurtlePlayer>create( EntityClassification.MISC )
|
||||
.disableSerialization()
|
||||
.disableSummoning()
|
||||
.size( 0, 0 )
|
||||
.build( ComputerCraft.MOD_ID + ":turtle_player" ) );
|
||||
}
|
||||
|
||||
public static class ModContainers
|
||||
{
|
||||
static final DeferredRegister<ContainerType<?>> CONTAINERS = new DeferredRegister<>( ForgeRegistries.CONTAINERS, ComputerCraft.MOD_ID );
|
||||
static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create( ForgeRegistries.CONTAINERS, ComputerCraft.MOD_ID );
|
||||
|
||||
public static final RegistryObject<ContainerType<ContainerComputer>> COMPUTER = CONTAINERS.register( "computer",
|
||||
() -> ContainerData.toType( ComputerContainerData::new, ContainerComputer::new ) );
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@@ -20,13 +21,12 @@ public final class TurtlePermissions
|
||||
public static boolean isBlockEnterable( World world, BlockPos pos, PlayerEntity player )
|
||||
{
|
||||
MinecraftServer server = world.getServer();
|
||||
return server == null || world.isClientSide || !server.isUnderSpawnProtection( world, pos, player );
|
||||
return server == null || world.isRemote || (world instanceof ServerWorld && !server.isBlockProtected( (ServerWorld) world, pos, player ));
|
||||
}
|
||||
|
||||
public static boolean isBlockEditable( World world, BlockPos pos, PlayerEntity player )
|
||||
{
|
||||
MinecraftServer server = world.getServer();
|
||||
return server == null || world.isClientSide || !server.isUnderSpawnProtection( world, pos, player );
|
||||
return isBlockEnterable( world, pos, player );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -8,17 +8,12 @@ package dan200.computercraft.shared;
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.api.turtle.ITurtleUpgrade;
|
||||
import dan200.computercraft.shared.computer.core.ComputerFamily;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenCustomHashMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class TurtleUpgrades
|
||||
@@ -42,7 +37,7 @@ public final class TurtleUpgrades
|
||||
private static ITurtleUpgrade[] vanilla;
|
||||
|
||||
private static final Map<String, ITurtleUpgrade> upgrades = new HashMap<>();
|
||||
private static final Map<ITurtleUpgrade, Wrapper> wrappers = new Object2ObjectLinkedOpenCustomHashMap<>( Util.identityStrategy() );
|
||||
private static final IdentityHashMap<ITurtleUpgrade, Wrapper> wrappers = new IdentityHashMap<>();
|
||||
private static boolean needsRebuild;
|
||||
|
||||
private TurtleUpgrades() {}
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.minecraft.inventory.container.Container;
|
||||
import net.minecraft.inventory.container.INamedContainerProvider;
|
||||
import net.minecraft.network.play.server.SPlayerPositionLookPacket;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.IFormattableTextComponent;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
@@ -75,13 +76,13 @@ public final class CommandComputerCraft
|
||||
List<ServerComputer> computers = new ArrayList<>( ComputerCraft.serverComputerRegistry.getComputers() );
|
||||
|
||||
// Unless we're on a server, limit the number of rows we can send.
|
||||
World world = source.getLevel();
|
||||
BlockPos pos = new BlockPos( source.getPosition() );
|
||||
World world = source.getWorld();
|
||||
BlockPos pos = new BlockPos( source.getPos() );
|
||||
|
||||
computers.sort( ( a, b ) -> {
|
||||
if( a.getWorld() == b.getWorld() && a.getWorld() == world )
|
||||
{
|
||||
return Double.compare( a.getPosition().distSqr( pos ), b.getPosition().distSqr( pos ) );
|
||||
return Double.compare( a.getPosition().distanceSq( pos ), b.getPosition().distanceSq( pos ) );
|
||||
}
|
||||
else if( a.getWorld() == world )
|
||||
{
|
||||
@@ -145,7 +146,7 @@ public final class CommandComputerCraft
|
||||
if( computer.isOn() ) shutdown++;
|
||||
computer.shutdown();
|
||||
}
|
||||
context.getSource().sendSuccess( translate( "commands.computercraft.shutdown.done", shutdown, computers.size() ), false );
|
||||
context.getSource().sendFeedback( translate( "commands.computercraft.shutdown.done", shutdown, computers.size() ), false );
|
||||
return shutdown;
|
||||
} ) )
|
||||
|
||||
@@ -159,7 +160,7 @@ public final class CommandComputerCraft
|
||||
if( !computer.isOn() ) on++;
|
||||
computer.turnOn();
|
||||
}
|
||||
context.getSource().sendSuccess( translate( "commands.computercraft.turn_on.done", on, computers.size() ), false );
|
||||
context.getSource().sendFeedback( translate( "commands.computercraft.turn_on.done", on, computers.size() ), false );
|
||||
return on;
|
||||
} ) )
|
||||
|
||||
@@ -173,20 +174,20 @@ public final class CommandComputerCraft
|
||||
|
||||
if( world == null || pos == null ) throw TP_NOT_THERE.create();
|
||||
|
||||
Entity entity = context.getSource().getEntityOrException();
|
||||
Entity entity = context.getSource().assertIsEntity();
|
||||
if( !(entity instanceof ServerPlayerEntity) ) throw TP_NOT_PLAYER.create();
|
||||
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) entity;
|
||||
if( player.getCommandSenderWorld() == world )
|
||||
if( player.getEntityWorld() == world )
|
||||
{
|
||||
player.connection.teleport(
|
||||
player.connection.setPlayerLocation(
|
||||
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0,
|
||||
EnumSet.noneOf( SPlayerPositionLookPacket.Flags.class )
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
player.teleportTo( (ServerWorld) world,
|
||||
player.teleport( (ServerWorld) world,
|
||||
pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, 0, 0
|
||||
);
|
||||
}
|
||||
@@ -219,7 +220,7 @@ public final class CommandComputerCraft
|
||||
.requires( UserLevel.OP )
|
||||
.arg( "computer", oneComputer() )
|
||||
.executes( context -> {
|
||||
ServerPlayerEntity player = context.getSource().getPlayerOrException();
|
||||
ServerPlayerEntity player = context.getSource().asPlayer();
|
||||
ServerComputer computer = getComputerArgument( context, "computer" );
|
||||
new ViewComputerContainerData( computer ).open( player, new INamedContainerProvider()
|
||||
{
|
||||
@@ -247,7 +248,7 @@ public final class CommandComputerCraft
|
||||
getTimingContext( context.getSource() ).start();
|
||||
|
||||
String stopCommand = "/computercraft track stop";
|
||||
context.getSource().sendSuccess( translate( "commands.computercraft.track.start.stop",
|
||||
context.getSource().sendFeedback( translate( "commands.computercraft.track.start.stop",
|
||||
link( text( stopCommand ), stopCommand, translate( "commands.computercraft.track.stop.action" ) ) ), false );
|
||||
return 1;
|
||||
} ) )
|
||||
@@ -283,7 +284,7 @@ public final class CommandComputerCraft
|
||||
|
||||
private static ITextComponent linkComputer( CommandSource source, ServerComputer serverComputer, int computerId )
|
||||
{
|
||||
ITextComponent out = new StringTextComponent( "" );
|
||||
IFormattableTextComponent out = new StringTextComponent( "" );
|
||||
|
||||
// Append the computer instance
|
||||
if( serverComputer == null )
|
||||
@@ -300,19 +301,19 @@ public final class CommandComputerCraft
|
||||
}
|
||||
|
||||
// And ID
|
||||
out.append( " (id " + computerId + ")" );
|
||||
out.appendString( " (id " + computerId + ")" );
|
||||
|
||||
// And, if we're a player, some useful links
|
||||
if( serverComputer != null && UserLevel.OP.test( source ) && isPlayer( source ) )
|
||||
{
|
||||
out
|
||||
.append( " " )
|
||||
.appendString( " " )
|
||||
.append( link(
|
||||
text( "\u261b" ),
|
||||
"/computercraft tp " + serverComputer.getInstanceID(),
|
||||
translate( "commands.computercraft.tp.action" )
|
||||
) )
|
||||
.append( " " )
|
||||
.appendString( " " )
|
||||
.append( link(
|
||||
text( "\u20e2" ),
|
||||
"/computercraft view " + serverComputer.getInstanceID(),
|
||||
@@ -343,7 +344,7 @@ public final class CommandComputerCraft
|
||||
private static TrackingContext getTimingContext( CommandSource source )
|
||||
{
|
||||
Entity entity = source.getEntity();
|
||||
return entity instanceof PlayerEntity ? Tracking.getContext( entity.getUUID() ) : Tracking.getContext( SYSTEM_UUID );
|
||||
return entity instanceof PlayerEntity ? Tracking.getContext( entity.getUniqueID() ) : Tracking.getContext( SYSTEM_UUID );
|
||||
}
|
||||
|
||||
private static final List<TrackingField> DEFAULT_FIELDS = Arrays.asList( TrackingField.TASKS, TrackingField.TOTAL_TIME, TrackingField.AVERAGE_TIME, TrackingField.MAX_TIME );
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user