1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-11-03 07:03:00 +00:00

Compare commits

...

50 Commits

Author SHA1 Message Date
Jonathan Coates
c43d851e63 Register turtle upgrade models separately
ITurtleUpgrade.getModel has always been rather error-prone to use, due
to its client-only nature. As ModelResourceLocation is now client-only
again in Forge 1.19.1, no seems a good time to fix this.

The getter for models is now a separate interface inside a new
dan200.computercraft.api.client package. These are registered
per-TurtleUpgradeSerialiser (as those should correspond to class
anyway). It's a little ugly, and we may rename the XxxSerialiser classes
to something more general in a future update.

I'm not wild about the interface here either - happy to change it in
future versions too.

   * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Also clean up the generic arguments to IUpgradeBase/UpgradeSerialiser a
little bit. It's not great (wish Java had HKTs), but it's better.
2022-07-28 19:02:38 +01:00
Jonathan Coates
50fe7935a3 Merge branch 'mc-1.18.x' into mc-1.19.x 2022-07-28 09:49:25 +01:00
Jonathan Coates
bd19fdf350 Merge branch 'mc-1.16.x' into mc-1.18.x 2022-07-28 09:43:06 +01:00
Jonathan Coates
c3615d9c5b Update to 1.19.1 2022-07-28 08:52:03 +01:00
Jonathan Coates
e2041f7438 Bump version to 1.100.9 2022-07-27 08:25:31 +01:00
Jonathan Coates
d61202e2b8 Fix location of language file 2022-07-27 07:52:05 +01:00
Weblate
6ce88a7dcf Translations for Norwegian Bokmål
Co-authored-by: Erlend <erlend.bergersen@sandnesskolen.no>
2022-07-26 13:17:57 +00:00
Weblate
5d65b3e654 Added translation for Norwegian Bokmål
Co-authored-by: Erlend <erlend.bergersen@sandnesskolen.no>
2022-07-24 15:45:46 +00:00
Erlend
abf857f864 Clearify GPS documentation note (#1139) 2022-07-22 20:27:27 +00:00
Jonathan Coates
ebef3117f2 Update npm packages 2022-07-21 20:38:44 +01:00
Jonathan Coates
25a44bea6e Correctly set VertexBuffer.format
Fixes #1137. Maybe.
2022-07-21 09:50:33 +01:00
Jonathan Coates
b28c1ac8e0 Test various time locales exist
Not clear if we can really test their behaviour too much.

See 69b211b4fb.
2022-07-21 09:44:40 +01:00
Jonathan Coates
69b211b4fb Fix name of "ingame" time locale
This has been here since 1.17 :D. Class rename gone wrong!
2022-07-21 09:44:36 +01:00
Jonathan Coates
48147fa61c Don't use MultiBufferSource for monitors
We're doing lots of weird OpenGL shenangins anyway, so it doesn't make
sense to use it. Instead just draw directly using the Tesselator
BufferBuilder.

This might improve compatiability with Sodium/Rubidium. Please don't let
me know if it doesn't though - I really don't want to have to deal with
it any more.
2022-07-16 22:07:23 +01:00
Jonathan Coates
ba976f9a16 Fix monitor depth blocker being too small
This allowed you to see transparent blocks through the bottom/right
margins of the monitor when using the VBO renderer.
2022-07-16 22:07:15 +01:00
Luiz Krüger
969feb4a1c ItemGroup info on getItemDetail (#1127) 2022-07-16 20:30:20 +00:00
Jonathan Coates
4a273ae8e5 Update to latest Forge
- Lots of refactoring/cleanup to Forge's events and client APIs.
   - Render types/layers for blocks are now set on the model rather than
     in code.

   - Models now can work with multiple render types. As this would
     massively complicate the implementation of the turtle item model, we
     now implement a much simpler version, which makes use of Forge's
     BakedModel.getRenderPasses to return a separate model for the core
     turtle and each upgrade.

 - Send monitor contents to players immediately when they start watching
   the chunk. ChunkWatchEvent.Watch is now fired from a more sensible
   location, so this is much easier to implement!
2022-07-16 19:08:11 +01:00
JackMacWindows
bd5de11ad5 Add WAV support to speaker program (#1112) 2022-07-09 08:59:35 +01:00
Jonathan Coates
5366fcb9c8 Point people towards the http.rules config option
Rather than blanket disabling http with http.enabled. I think it's still
useful to keep the option around, but hopefully make it clearer what the
ramifications are.
2022-07-08 22:13:39 +01:00
Jonathan Coates
6335e77da6 Add a code of conduct
Been meaning to do this for years, woops.
2022-07-08 22:08:50 +01:00
heap-underflow
4cfd0a2d1c Fix off-by-1 error in generic inventory's getItemLimit() (#1131) 2022-07-08 07:44:13 +00:00
Jonathan Coates
be3a960273 Check for duplicate ids when registering channels
Should prevent #1130 occurring again. Possibly worth submitting a PR to
Forge for this too.
2022-07-08 08:27:37 +01:00
Jonathan Coates
f25a73b8f2 Fix packet ID conflict
Merge gone wrong I suspect. I should probably add a check for this.

Fixes #1130. Slightly embarassing that this has been around for 7
months.
2022-07-07 21:45:05 +01:00
Jonathan Coates
954254e7e4 Update Minecraft versions 2022-07-07 21:06:32 +01:00
Jonathan Coates
e906f3ebc3 Remove IArguments.releaseImmediate
Was deprecated pre-1.19, just forgot to remove it as part of the update.
2022-07-02 17:00:14 +01:00
Jonathan Coates
56f0e0674f Fix term.blit failing on substrings
Hahah. Serves me right for trying to optimise too much. Fixes #1123.
2022-07-02 16:47:43 +01:00
Jonathan Coates
4e438df9ad Update cct-javadoc
No longer warns about empty comments. Closes #1107.
2022-07-02 11:51:58 +01:00
Toad-Dev
51c3a9d8af Fix z-fighting on bold printout borders.
- Changed page background to render as one quad, instead of two halves.
- Set page background to a z-offset that is between zeroth (potentially
  bold border) and subsequent background pages. Bold borders were at the
  same z-offset before.
2022-07-02 11:24:40 +01:00
Jonathan Coates
d967730085 Run the JSX transformer without type checking
Makes it run about twice as fast. Still irritatingly slow, though really
want to avoid making it incremental or anything.
2022-07-02 10:12:47 +01:00
Lupus590
d6afee8deb Document setting up a gps constellation (#1070) 2022-07-02 10:09:38 +01:00
Jonathan Coates
41bddcab9f Use shorter mod version when publishing to Modrinth
i.e. 1.100.8 rather than 1.19-1.100.8.
2022-07-02 09:10:45 +01:00
Jonathan Coates
b8d7695392 Merge pull request #1126 from JohnnyIrvin/mc-1.16.x
Spelling error Turtle API
2022-07-01 21:13:18 +01:00
Johnny Irvin
b7fa4102df Fix spell err Turtle API Doc
* `throug` -> `through`
2022-07-01 09:19:11 -04:00
Jonathan Coates
92c613a7a2 Merge branch 'mc-1.18.x' into mc-1.19.x 2022-06-23 22:41:49 +01:00
Jonathan Coates
d2f94f2653 Merge branch 'mc-1.16.x' into mc-1.18.x 2022-06-23 22:26:09 +01:00
Jonathan Coates
718111787c Also propogate the Java launcher when copying tasks
We removed the config which ran all JavaExec tasks with the given
launcher, so need to override this again.

A little abusrd that this isn't done by Gradle, but there we go.
2022-06-23 22:24:53 +01:00
Jonathan Coates
bb0e449560 Switch over to using SLF4J
No bearing on MC, but allows us to drop the depenedency in other
projects (CCEmuX, eval.tweaked.cc, etc...)

I'd quite like to spin the core into a separate project which doesn't
depend on MC at all, but not worth doing right now.
2022-06-23 20:57:24 +01:00
Jonathan Coates
ee495b3359 Merge branch 'mc-1.16.x' into mc-1.18.x 2022-06-23 20:53:37 +01:00
Jonathan Coates
d1e952770d Bump version to 1.100.8 2022-06-23 20:44:14 +01:00
Jonathan Coates
2d30208631 Avoid early creation of tasks
Notionally speeds up the build a little, though not really noticable in
practice.
2022-06-23 20:44:14 +01:00
Jonathan Coates
03f50f9298 _Actually_ publish an API jar 2022-06-21 07:28:15 +01:00
Jonathan Coates
8fc7820a12 Sync each config type separately
Forge checks for early access now which is sensible, but given we
sidestep Forge's ConfigValue system anyway, not very useful for us :D:.

Fixes #1117
2022-06-20 19:58:10 +01:00
Jonathan Coates
1a0e3fc2fa Use the Gradle shadow plugin to shade deps
Just saves us from having to worry about conflicts with other mods which
bundle Cobalt. This might make the transition to Jar-in-Jar easier too -
not sure yet!

Also produce an API jar - fixes #1060.
2022-06-20 19:54:35 +01:00
Jonathan Coates
6d5b13dbbc Revert "Switch over to using SLF4J"
This reverts commit b7f698d6f7.

Apparently slf4j is on the classpath in dev but not in live. Will apply
this on 1.18 and later instead.
2022-06-20 19:52:23 +01:00
Jonathan Coates
f9f8233ef4 Some "improvements" to our Gradle script
- Switch to plugins { ... } imports for Forge (FG finally supports it!)

 - Use FG's new fg.component to clean up our Maven metadata instead. We
   also mark JEI as optional (using Gradle's registerFeature), which
   means we've no stray deps inside our POM any more.
2022-06-19 11:21:42 +01:00
Jonathan Coates
a2e3d9d9bd Update JEI to 1.19
Fixes #1116
2022-06-19 11:17:31 +01:00
Jonathan Coates
b7f698d6f7 Switch over to using SLF4J
No bearing on MC, but allows us to drop the depenedency in other
projects (CCEmuX, eval.tweaked.cc, etc...)

I'd quite like to spin the core into a separate project which doesn't
depend on MC at all, but not worth doing right now.
2022-06-19 11:10:53 +01:00
Jonathan Coates
93f3cd4a53 Fix lock code being null for newly placed blocks
This causes an NPE when serialising or opening printers and disk drives.
Fixes #1109
2022-06-16 07:56:54 +01:00
Jonathan Coates
755f8eff93 Mark 1.19 as alpha-quality
I knew I had an option for this, I just forgot to flip it!
2022-06-12 16:46:43 +01:00
Jonathan Coates
a879efc3d0 Don't shade all of Netty in the CC:T jar
Fixes #1108. Let this be a lesson to all of us: don't update mods at
midnight after a 20h day while half-delirious.
2022-06-12 16:39:57 +01:00
92 changed files with 1786 additions and 1094 deletions

View File

@@ -9,8 +9,8 @@ body:
description: What version of Minecraft are you using?
options:
- 1.16.x
- 1.17.x
- 1.18.x
- 1.19.x
validations:
required: true
- type: input

133
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,133 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
"conduct AT squiddev DOT cc". All complaints will be reviewed and investigated
promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations

View File

@@ -35,7 +35,8 @@ repositories {
}
dependencies {
implementation fg.deobf("org.squiddev:cc-tweaked-${mc_version}:${cct_version}")
compileOnly fg.deobf("org.squiddev:cc-tweaked-${mc_version}:${cct_version}:api")
runtimeOnly fg.deobf("org.squiddev:cc-tweaked-${mc_version}:${cct_version}")
}
```

View File

@@ -1,30 +1,19 @@
buildscript {
repositories {
mavenCentral()
maven { url = "https://maven.minecraftforge.net" }
maven { url = 'https://maven.parchmentmc.org' }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:5.1.+'
classpath "org.spongepowered:mixingradle:0.7.+"
classpath 'org.parchmentmc:librarian:1.+'
}
}
plugins {
id "checkstyle"
id "jacoco"
id "maven-publish"
id "com.github.hierynomus.license" version "0.16.1"
id "org.cadixdev.licenser" version "0.6.1"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.github.breadmoirai.github-release" version "2.2.12"
id "org.jetbrains.kotlin.jvm" version "1.6.0"
id "com.modrinth.minotaur" version "1.2.1"
id "org.jetbrains.kotlin.jvm" version "1.7.0"
id "com.modrinth.minotaur" version "2.+"
id "net.minecraftforge.gradle" version "5.1.+"
id "org.spongepowered.mixin" version "0.7.+"
id "org.parchmentmc.librarian.forgegradle" version "1.+"
id "com.github.johnrengelman.shadow" version "7.1.2"
}
apply plugin: 'net.minecraftforge.gradle'
apply plugin: "org.spongepowered.mixin"
apply plugin: 'org.parchmentmc.librarian.forgegradle'
import org.apache.tools.ant.taskdefs.condition.Os
version = mod_version
@@ -39,12 +28,7 @@ java {
withSourcesJar()
withJavadocJar()
}
tasks.withType(JavaExec).configureEach {
javaLauncher = javaToolchains.launcherFor {
languageVersion = javaVersion
}
registerFeature("extraMods") { usingSourceSet(sourceSets.main) }
}
sourceSets {
@@ -64,6 +48,7 @@ minecraft {
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
forceExit = false
mods {
computercraft {
@@ -108,6 +93,8 @@ minecraft {
gameTestServer {
workingDirectory project.file('test-files/server')
property("forge.logging.console.level", "info")
mods {
cctest {
source sourceSets.testMod
@@ -122,8 +109,8 @@ minecraft {
}
}
// mappings channel: 'parchment', version: "${mapping_version}-${mc_version}"
mappings channel: 'official', version: mc_version
mappings channel: 'parchment', version: "${mapping_version}-${mc_version}"
// mappings channel: 'official', version: mc_version
accessTransformer file('src/main/resources/META-INF/accesstransformer.cfg')
accessTransformer file('src/testMod/resources/META-INF/accesstransformer.cfg')
@@ -133,6 +120,10 @@ mixin {
add sourceSets.main, 'computercraft.mixins.refmap.json'
}
reobf {
shadowJar {}
}
repositories {
mavenCentral()
maven {
@@ -142,7 +133,7 @@ repositories {
}
configurations {
shade
shade { transitive = false }
implementation.extendsFrom shade
cctJavadoc
@@ -158,8 +149,9 @@ dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
annotationProcessor 'org.spongepowered:mixin:0.8.4:processor'
compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.116:api")
// runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.4.1.116")
extraModsCompileOnly fg.deobf("mezz.jei:jei-1.19-forge-api:11.1.1.236")
extraModsCompileOnly fg.deobf("mezz.jei:jei-1.19-common-api:11.1.1.236")
extraModsRuntimeOnly fg.deobf("mezz.jei:jei-1.19-forge:11.1.1.236")
shade 'org.squiddev:Cobalt:0.5.5'
shade 'io.netty:netty-codec-http:4.1.76.Final'
@@ -168,28 +160,32 @@ 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.6.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.0'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2'
testModImplementation sourceSets.main.output
testModExtra('org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.0') {
exclude group: "org.jetbrains", module: "annotations"
}
cctJavadoc 'cc.tweaked:cct-javadoc:1.4.6'
cctJavadoc 'cc.tweaked:cct-javadoc:1.4.7'
}
// Compile tasks
compileTestModJava {
dependsOn(compileJava)
}
javadoc {
include "dan200/computercraft/api/**/*.java"
}
task luaJavadoc(type: Javadoc) {
def apiJar = tasks.register("apiJar", Jar.class) {
archiveClassifier.set("api")
from(sourceSets.main.output) {
include "dan200/computercraft/api/**/*"
}
}
assemble.dependsOn(apiJar)
def luaJavadoc = tasks.register("luaJavadoc", Javadoc.class) {
description "Generates documentation for Java-side Lua functions."
group "documentation"
@@ -207,6 +203,9 @@ task luaJavadoc(type: Javadoc) {
}
jar {
finalizedBy("reobfJar")
archiveClassifier.set("slim")
manifest {
attributes([
"Specification-Title" : "computercraft",
@@ -215,20 +214,29 @@ jar {
"Implementation-Title" : "CC: Tweaked",
"Implementation-Version" : "${mod_version}",
"Implementation-Vendor" : "SquidDev",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
,
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
"MixinConfigs" : "computercraft.mixins.json",
])
}
duplicatesStrategy(DuplicatesStrategy.WARN)
from configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }
}
jar.finalizedBy('reobfJar')
shadowJar {
finalizedBy("reobfShadowJar")
[compileJava, compileTestJava, compileTestModJava].forEach {
archiveClassifier.set("")
configurations = [project.configurations.shade]
relocate("org.squiddev.cobalt", "cc.tweaked.internal.cobalt")
relocate("io.netty.handler.codec.http", "cc.tweaked.internal.netty")
minimize()
}
assemble.dependsOn("shadowJar")
[
tasks.named("compileJava", JavaCompile.class),
tasks.named("compileTestJava", JavaCompile.class),
tasks.named("compileTestModJava", JavaCompile.class)
].forEach {
it.configure {
options.compilerArgs << "-Xlint" << "-Xlint:-processing"
}
@@ -292,17 +300,11 @@ sourcesJar {
// Web tasks
import com.hierynomus.gradle.license.tasks.LicenseCheck
import com.hierynomus.gradle.license.tasks.LicenseFormat
import com.modrinth.minotaur.TaskModrinthUpload
import org.apache.tools.ant.taskdefs.condition.Os
List<String> mkCommand(String command) {
return Os.isFamily(Os.FAMILY_WINDOWS) ? ["cmd", "/c", command] : ["sh", "-c", command]
}
task rollup(type: Exec) {
def rollup = tasks.register("rollup", Exec.class) {
group = "build"
description = "Bundles JS into rollup"
@@ -315,9 +317,10 @@ task rollup(type: Exec) {
commandLine mkCommand('"node_modules/.bin/rollup" --config rollup.config.js')
}
task illuaminateDocs(type: Exec, dependsOn: [rollup, luaJavadoc]) {
group = "build"
def illuaminateDocs = tasks.register("illuaminateDocs", Exec.class) {
group = "documentation"
description = "Generates docs using Illuaminate"
dependsOn(rollup, luaJavadoc)
inputs.files(fileTree("doc")).withPropertyName("docs")
inputs.files(fileTree("src/main/resources/data/computercraft/lua/rom")).withPropertyName("lua rom")
@@ -330,9 +333,10 @@ task illuaminateDocs(type: Exec, dependsOn: [rollup, luaJavadoc]) {
commandLine mkCommand('"bin/illuaminate" doc-gen')
}
task jsxDocs(type: Exec, dependsOn: [illuaminateDocs]) {
group = "build"
def jsxDocs = tasks.register("jsxDocs", Exec) {
group = "documentation"
description = "Post-processes documentation to statically render some dynamic content."
dependsOn(illuaminateDocs)
inputs.files(fileTree("src/web")).withPropertyName("sources")
inputs.file("src/generated/export/index.json").withPropertyName("export")
@@ -341,10 +345,14 @@ task jsxDocs(type: Exec, dependsOn: [illuaminateDocs]) {
inputs.files(fileTree("$buildDir/docs/lua"))
outputs.dir("$buildDir/docs/site")
commandLine mkCommand('"node_modules/.bin/ts-node" --esm src/web/transform.tsx')
commandLine mkCommand('"node_modules/.bin/ts-node" -T --esm src/web/transform.tsx')
}
task docWebsite(type: Copy, dependsOn: [jsxDocs]) {
def docWebsite = tasks.register("docWebsite", Copy.class) {
group = "documentation"
description = "Copy additional assets to the website directory."
dependsOn(jsxDocs)
from('doc') {
include 'logo.png'
include 'images/**'
@@ -379,94 +387,75 @@ jacocoTestReport {
}
}
check.dependsOn jacocoTestReport
test.finalizedBy("jacocoTestReport")
license {
mapping("java", "SLASHSTAR_STYLE")
strictCheck true
header = file('config/license/main.txt')
lineEnding = '\n'
newLine = false
ext.year = Calendar.getInstance().get(Calendar.YEAR)
}
properties {
year = Calendar.getInstance().get(Calendar.YEAR)
}
[licenseMain, licenseFormatMain].forEach {
it.configure {
include("**/*.java")
exclude("dan200/computercraft/api/**")
header file('config/license/main.txt')
include("**/*.java") // We could apply to Kotlin, but for now let's not
matching("dan200/computercraft/api/**") {
header = file('config/license/api.txt')
}
}
[licenseTest, licenseFormatTest, licenseTestMod, licenseFormatTestMod].forEach {
it.configure {
include("**/*.java")
header file('config/license/main.txt')
}
}
check.dependsOn("licenseCheck")
gradle.projectsEvaluated {
tasks.withType(LicenseFormat) {
outputs.upToDateWhen { false }
}
}
def testServerClassDumpDir = new File(buildDir, "jacocoClassDump/runTestServer")
task licenseAPI(type: LicenseCheck)
task licenseFormatAPI(type: LicenseFormat)
[licenseAPI, licenseFormatAPI].forEach {
it.configure {
source = sourceSets.main.java
include("dan200/computercraft/api/**")
header file('config/license/api.txt')
}
}
tasks.register("testServer", JavaExec.class).configure {
it.group('In-game tests')
it.description("Runs tests on a temporary Minecraft instance.")
it.dependsOn("prepareRunGameTestServer", "cleanTestServer", 'compileTestModJava')
def testServer = tasks.register("testServer", JavaExec.class) {
group("In-game tests")
description("Runs tests on a temporary Minecraft instance.")
dependsOn("cleanTestServer")
finalizedBy("jacocoTestServerReport")
// 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("runGameTestServer")
dependsOn(exec.getDependsOn())
exec.copyTo(it)
it.setClasspath(exec.getClasspath())
it.mainClass = exec.mainClass
it.setArgs(exec.getArgs())
setClasspath(exec.getClasspath())
mainClass = exec.mainClass
javaLauncher = exec.javaLauncher
setArgs(exec.getArgs())
// 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/testServer")
jacoco.applyTo(it)
it.jacoco.setIncludes(["dan200.computercraft.*"])
it.jacoco.setClassDumpDir(coverageOut)
it.outputs.dir(coverageOut)
it.jacoco.setClassDumpDir(testServerClassDumpDir)
outputs.dir(testServerClassDumpDir)
// 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("jacocoTestServerReport", JacocoReport.class).configure {
it.group('In-game')
it.description("Generate coverage reports for testServer")
it.dependsOn("testServer")
tasks.register("jacocoTestServerReport", JacocoReport.class) {
group("In-game tests")
description("Generate coverage reports for testServer")
dependsOn(testServer)
it.executionData(new File(buildDir, "jacoco/testServer.exec"))
it.sourceDirectories.from(sourceSets.main.allJava.srcDirs)
it.classDirectories.from(new File(buildDir, "jacocoClassDump/testServer"))
executionData(new File(buildDir, "jacoco/testServer.exec"))
sourceDirectories.from(sourceSets.main.allJava.srcDirs)
classDirectories.from(testServerClassDumpDir)
it.reports {
reports {
xml.enabled true
html.enabled true
}
}
check.dependsOn("jacocoTestServerReport")
check.dependsOn(testServer)
// Upload tasks
task checkRelease {
def checkRelease = tasks.register("checkRelease") {
group "upload"
description "Verifies that everything is ready for a release"
@@ -504,9 +493,9 @@ task checkRelease {
if (!ok) throw new IllegalStateException("Could not check release")
}
}
check.dependsOn checkRelease
check.dependsOn(checkRelease)
def isStable = true
def isStable = false
curseforge {
apiKey = project.hasProperty('curseForgeApiKey') ? project.curseForgeApiKey : ''
@@ -514,36 +503,29 @@ curseforge {
id = '282001'
releaseType = isStable ? 'release' : 'alpha'
changelog = "Release notes can be found on the GitHub repository (https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
mainArtifact(shadowJar)
addGameVersion "${mc_version}"
}
}
tasks.register('publishModrinth', TaskModrinthUpload.class).configure {
dependsOn('assemble', 'reobfJar')
onlyIf {
project.hasProperty('modrinthApiKey')
}
modrinth {
token = project.hasProperty('modrinthApiKey') ? project.getProperty('modrinthApiKey') : ''
projectId = 'gu7yAYhd'
versionNumber = "${project.mc_version}-${project.mod_version}"
uploadFile = jar
versionType = isStable ? 'RELEASE' : 'ALPHA'
addGameVersion(project.mc_version)
versionName = "${project.mod_version}"
versionType = isStable ? 'release' : 'alpha'
uploadFile = shadowJar
gameVersions = [project.mc_version]
changelog = "Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v${mc_version}-${mod_version})."
addLoader('forge')
}
tasks.withType(GenerateModuleMetadata) {
// We can't generate metadata as that includes Forge as a dependency.
enabled = false
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact(apiJar)
fg.component(it)
pom {
name = 'CC: Tweaked'
@@ -562,11 +544,9 @@ publishing {
licenses {
license {
name = 'ComputerCraft Public License, Version 1.0'
url = 'https://github.com/cc-tweaked/CC-Tweaked/blob/mc-1.15.x/LICENSE'
url = 'https://github.com/cc-tweaked/CC-Tweaked/blob/mc-1.16.x/LICENSE'
}
}
withXml { asNode().remove(asNode().get("dependencies")) }
}
}
}
@@ -614,10 +594,11 @@ githubRelease {
prerelease !isStable
}
def uploadTasks = ["publish", "curseforge", "publishModrinth", "githubRelease"]
uploadTasks.forEach { tasks.getByName(it).dependsOn checkRelease }
def uploadTasks = ["publish", "curseforge", "modrinth", "githubRelease"]
uploadTasks.forEach { tasks.named(it) { dependsOn(checkRelease) } }
task uploadAll(dependsOn: uploadTasks) {
group "upload"
description "Uploads to all repositories (Maven, Curse, Modrinth, GitHub release)"
tasks.register("uploadAll") {
group = "upload"
description = "Uploads to all repositories (Maven, Curse, Modrinth, GitHub release)"
dependsOn(uploadTasks)
}

90
doc/guides/gps_setup.md Normal file
View File

@@ -0,0 +1,90 @@
---
module: [kind=guide] gps_setup
---
# Setting up GPS
The @{gps} API allows computers and turtles to find their current position using wireless modems.
In order to use GPS, you'll need to set up multiple *GPS hosts*. These are computers running the special `gps host`
program, which tell other computers the host's position. Several hosts running together are known as a *GPS
constellation*.
In order to give the best results, a GPS constellation needs at least four computers. More than four GPS hosts per
constellation is redundant, but it does not cause problems.
## Building a GPS constellation
![An example GPS constellation.](/images/gps-constellation-example.png){.big-image}
We are going to build our GPS constellation as shown in the image above. You will need 4 computers and either 4 wireless
modems or 4 ender modems. Try not to mix ender and wireless modems together as you might get some odd behavior when your
requesting computers are out of range.
:::tip Ender modems vs wireless modems
Ender modems have a very large range, which makes them very useful for setting up GPS hosts. If you do this then you
will likely only need one GPS constellation for the whole dimension (such as the Overworld or Nether).
If you do use wireless modems then you may find that you need multiple GPS constellations to cover your needs.
A computer needs a wireless or ender modem and to be in range of a GPS constellation that is in the same dimension as it
to use the GPS API. The reason for this is that ComputerCraft mimics real-life GPS by making use of the distance
parameter of @{modem_message|modem messages} and some maths.
:::
Locate where you want to place your GPS constellation. You will need an area at least 6 blocks high, 6 blocks wide, and
6 blocks deep (6x6x6). If you are using wireless modems then you may want to build your constellation as high as you can
because high altitude boosts modem message range and thus the radius that your constellation covers.
The GPS constellation will only work when it is in a loaded chunk. If you want your constellation to always be
accessible, you may want to permanently load the chunk using a vanilla or modded chunk loader. Make sure that your 6x6x6
area fits in a single chunk to reduce the number of chunks that need to be kept loaded.
Let's get started building the constellation! Place your first computer in one of the corners of your 6x6x6. Remember
which computer this is as other computers need to be placed relative to it. Place the second computer 4 blocks above the
first. Go back to your first computer and place your third computer 5 blocks in front of your first computer, leaving 4
blocks of air between them. Finally for the fourth computer, go back to your first computer and place it 5 blocks right
of your first computer, leaving 4 blocks of air between them.
With all four computers placed within the 6x6x6, place one modem on top of each computer. You should have 4 modems and 4
computers all within your 6x6x6 where each modem is attached to a computer and each computer has a modem.
Currently your GPS constellation will not work, that's because each host is not aware that it's a GPS host. We will fix
this in the next section.
## Configuring the constellation
Now that the structure of your constellation is built, we need to configure each host in it.
Go back to the first computer that you placed and create a startup file, by running `edit startup`.
Type the following code into the file:
```lua
shell.run("gps", "host", x, y, z)
```
Escape from the computer GUI and then press <kbd>F3</kbd> to open Minecraft's debug screen and then look at the computer
(without opening the GUI). On the right of the screen about halfway down you should see an entry labeled `Targeted
Block`, the numbers correspond to the position of the block that you are looking at. Replace `x` with the first number,
`y` with the second number, and `z` with the third number.
For example, if I had a computer at x = 59, y = 5, z = -150, then my <kbd>F3</kbd> debug screen entry would be `Target
Block: 59, 5, -150` and I would change my startup file to this `shell.run("gps", "host", 59, 5, -150)`.
To hide Minecraft's debug screen, press <kbd>F3</kbd> again.
Create similar startup files for the other computers in your constellation, making sure to input the each computer's own
coordinates.
:::caution Modem messages come from the computer's position, not the modem's
Wireless modems transmit from the block that they are attached to *not* the block space that they occupy, the
coordinates that you input into your GPS host should be the position of the computer and not the position of the modem.
:::
Congratulations, your constellation is now fully set up! You can test it by placing another computer close by, placing a
wireless modem on it, and running the `gps locate` program (or calling the @{gps.locate} function).
:::info Why use Minecraft's coordinates?
CC doesn't care if you use Minecraft's coordinate system, so long as all of the GPS hosts with overlapping ranges use
the same reference point (requesting computers will get confused if hosts have different reference points). However,
using MC's coordinate system does provide a nice standard to adopt server-wide. It also is consistent with how command
computers get their location, they use MC's command system to get their block which returns that in MC's coordinate
system.
:::

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 KiB

View File

@@ -1,10 +1,11 @@
org.gradle.jvmargs=-Xmx3G
kotlin.stdlib.default.dependency=false
# Mod properties
mod_version=1.100.6
mod_version=1.100.9
# Minecraft properties (update mods.toml when changing)
mc_version=1.19
mapping_version=2022.03.13
forge_version=41.0.16
mc_version=1.19.1
mapping_version=1.18.2-2022.07.03
forge_version=42.0.0
# NO SERIOUSLY, UPDATE mods.toml WHEN CHANGING

Binary file not shown.

View File

@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

640
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,7 +11,7 @@
},
"devDependencies": {
"@rollup/plugin-typescript": "^8.2.5",
"@rollup/plugin-url": "^6.1.0",
"@rollup/plugin-url": "^7.0.0",
"@types/glob": "^7.2.0",
"@types/react-dom": "^18.0.5",
"glob": "^8.0.3",

View File

@@ -1 +0,0 @@
rootProject.name = "cc-tweaked-${mc_version}"

17
settings.gradle.kts Normal file
View File

@@ -0,0 +1,17 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven("https://maven.minecraftforge.net")
maven("https://maven.parchmentmc.org")
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == "org.spongepowered.mixin") {
useModule("org.spongepowered:mixingradle:${requested.version}")
}
}
}
}
val mc_version: String by settings
rootProject.name = "cc-tweaked-${mc_version}"

View File

@@ -13,8 +13,8 @@ import dan200.computercraft.shared.computer.core.ClientComputerRegistry;
import dan200.computercraft.shared.computer.core.ServerComputerRegistry;
import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
import net.minecraftforge.fml.common.Mod;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.concurrent.TimeUnit;
@@ -81,7 +81,7 @@ public final class ComputerCraft
public static final ServerComputerRegistry serverComputerRegistry = new ServerComputerRegistry();
// Logging
public static final Logger log = LogManager.getLogger( MOD_ID );
public static final Logger log = LoggerFactory.getLogger( MOD_ID );
public ComputerCraft()
{

View File

@@ -0,0 +1,57 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.client;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import javax.annotation.Nonnull;
public final class ComputerCraftAPIClient
{
private ComputerCraftAPIClient()
{
}
/**
* Register a {@link TurtleUpgradeModeller} for a class of turtle upgrades.
*
* This may be called at any point after registry creation, though it is recommended to call it within {@link FMLClientSetupEvent}.
*
* @param serialiser The turtle upgrade serialiser.
* @param modeller The upgrade modeller.
* @param <T> The type of the turtle upgrade.
*/
public static <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller( @Nonnull TurtleUpgradeSerialiser<T> serialiser, @Nonnull TurtleUpgradeModeller<T> modeller )
{
getInstance().registerTurtleUpgradeModeller( serialiser, modeller );
}
private static IComputerCraftAPIClient instance;
@Nonnull
private static IComputerCraftAPIClient getInstance()
{
if( instance != null ) return instance;
try
{
return instance = (IComputerCraftAPIClient) Class.forName( "dan200.computercraft.client.ComputerCraftAPIClientImpl" )
.getField( "INSTANCE" ).get( null );
}
catch( ReflectiveOperationException e )
{
throw new IllegalStateException( "Cannot find ComputerCraft API", e );
}
}
public interface IComputerCraftAPIClient
{
<T extends ITurtleUpgrade> void registerTurtleUpgradeModeller( @Nonnull TurtleUpgradeSerialiser<T> serialiser, @Nonnull TurtleUpgradeModeller<T> modeller );
}
}

View File

@@ -0,0 +1,68 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.client.turtle;
import dan200.computercraft.api.client.ComputerCraftAPIClient;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
import net.minecraft.client.resources.model.ModelResourceLocation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Provides models for a {@link ITurtleUpgrade}.
*
* @param <T> The type of turtle upgrade this modeller applies to.
* @see ComputerCraftAPIClient#registerTurtleUpgradeModeller(TurtleUpgradeSerialiser, TurtleUpgradeModeller) To register a modeller.
*/
public interface TurtleUpgradeModeller<T extends ITurtleUpgrade>
{
/**
* Obtain the model to be used when rendering a turtle peripheral.
*
* When the current turtle is {@literal null}, this function should be constant for a given upgrade and side.
*
* @param upgrade The upgrade that you're getting the model for.
* @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
* @param side Which side of the turtle (left or right) the upgrade resides on.
* @return The model that you wish to be used to render your upgrade.
*/
@Nonnull
TransformedModel getModel( @Nonnull T upgrade, @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
/**
* A basic {@link TurtleUpgradeModeller} which renders using the upgrade's {@linkplain ITurtleUpgrade#getCraftingItem()
* crafting item}.
*
* This uses appropriate transformations for "flat" items, namely those extending the {@literal minecraft:item/generated}
* model type. It will not appear correct for 3D models with additional depth, such as blocks.
*
* @param <T> The type of the turtle upgrade.
* @return The constructed modeller.
*/
@SuppressWarnings( "unchecked" )
static <T extends ITurtleUpgrade> TurtleUpgradeModeller<T> flatItem()
{
return (TurtleUpgradeModeller<T>) TurtleUpgradeModellers.FLAT_ITEM;
}
/**
* Construct a {@link TurtleUpgradeModeller} which has a single model for the left and right side.
*
* @param left The model to use on the left.
* @param right The model to use on the right.
* @param <T> The type of the turtle upgrade.
* @return The constructed modeller.
*/
static <T extends ITurtleUpgrade> TurtleUpgradeModeller<T> sided( ModelResourceLocation left, ModelResourceLocation right )
{
return ( upgrade, turtle, side ) -> TransformedModel.of( side == TurtleSide.LEFT ? left : right );
}
}

View File

@@ -0,0 +1,31 @@
/*
* This file is part of the public ComputerCraft API - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. This API may be redistributed unmodified and in full only.
* For help using the API, and posting your mods, visit the forums at computercraft.info.
*/
package dan200.computercraft.api.client.turtle;
import com.mojang.math.Matrix4f;
import com.mojang.math.Transformation;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
class TurtleUpgradeModellers
{
private static final Transformation leftTransform = getMatrixFor( -0.40625f );
private static final Transformation rightTransform = getMatrixFor( 0.40625f );
private static Transformation getMatrixFor( float offset )
{
return new Transformation( new Matrix4f( new float[] {
0.0f, 0.0f, -1.0f, 1.0f + offset,
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f,
} ) );
}
static final TurtleUpgradeModeller<ITurtleUpgrade> FLAT_ITEM = ( upgrade, turtle, side ) ->
TransformedModel.of( upgrade.getCraftingItem(), side == TurtleSide.LEFT ? leftTransform : rightTransform );
}

View File

@@ -443,16 +443,4 @@ public interface IArguments
{
return optTable( index ).orElse( def );
}
/**
* This is called when the current function finishes, before any main thread tasks have run.
*
* Called when the current function returns, and so some values are no longer guaranteed to be safe to access.
*
* @deprecated This method was an internal implementation detail and is no longer used.
*/
@Deprecated
default void releaseImmediate()
{
}
}

View File

@@ -7,7 +7,7 @@ package dan200.computercraft.api.pocket;
import dan200.computercraft.api.upgrades.UpgradeDataProvider;
import net.minecraft.data.DataGenerator;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
import net.minecraftforge.data.event.GatherDataEvent;
import javax.annotation.Nonnull;
import java.util.function.Consumer;

View File

@@ -33,7 +33,7 @@ import java.util.function.Function;
* @see IPocketUpgrade
* @see PocketUpgradeDataProvider
*/
public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends UpgradeSerialiser<T, PocketUpgradeSerialiser<?>>
public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends UpgradeSerialiser<T>
{
/**
* The ID for the associated registry.
@@ -47,6 +47,7 @@ public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends Upgra
/**
* The associated registry.
*
* @return The registry for pocket upgrade serialisers.
* @see #REGISTRY_ID
*/
@@ -68,7 +69,7 @@ public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends Upgra
@Nonnull
static <T extends IPocketUpgrade> PocketUpgradeSerialiser<T> simple( @Nonnull Function<ResourceLocation, T> factory )
{
class Impl extends SimpleSerialiser<T, PocketUpgradeSerialiser<?>> implements PocketUpgradeSerialiser<T>
class Impl extends SimpleSerialiser<T> implements PocketUpgradeSerialiser<T>
{
private Impl( Function<ResourceLocation, T> constructor )
{
@@ -91,7 +92,7 @@ public interface PocketUpgradeSerialiser<T extends IPocketUpgrade> extends Upgra
@Nonnull
static <T extends IPocketUpgrade> PocketUpgradeSerialiser<T> simpleWithCustomItem( @Nonnull BiFunction<ResourceLocation, ItemStack, T> factory )
{
class Impl extends SerialiserWithCraftingItem<T, PocketUpgradeSerialiser<?>> implements PocketUpgradeSerialiser<T>
class Impl extends SerialiserWithCraftingItem<T> implements PocketUpgradeSerialiser<T>
{
private Impl( BiFunction<ResourceLocation, ItemStack, T> factory )
{

View File

@@ -5,16 +5,11 @@
*/
package dan200.computercraft.api.turtle;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.upgrades.IUpgradeBase;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.Direction;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.level.BlockEvent;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -85,21 +80,6 @@ public interface ITurtleUpgrade extends IUpgradeBase
return TurtleCommandResult.failure();
}
/**
* Called to obtain the model to be used when rendering a turtle peripheral.
*
* This can be obtained from {@link net.minecraft.client.renderer.ItemModelShaper#getItemModel(ItemStack)},
* {@link net.minecraft.client.resources.model.ModelManager#getModel(ModelResourceLocation)} or any other
* source.
*
* @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models!
* @param side Which side of the turtle (left or right) the upgrade resides on.
* @return The model that you wish to be used to render your upgrade.
*/
@Nonnull
@OnlyIn( Dist.CLIENT )
TransformedModel getModel( @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side );
/**
* Called once per tick for each turtle which has the upgrade equipped.
*

View File

@@ -14,7 +14,7 @@ import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nonnull;
@@ -140,7 +140,10 @@ public abstract class TurtleUpgradeDataProvider extends UpgradeDataProvider<ITur
add.accept( new Upgrade<>( id, serialiser, s -> {
s.addProperty( "item", ForgeRegistries.ITEMS.getKey( toolItem ).toString() );
if( adjective != null ) s.addProperty( "adjective", adjective );
if( craftingItem != null ) s.addProperty( "craftItem", ForgeRegistries.ITEMS.getKey( craftingItem ).toString() );
if( craftingItem != null )
{
s.addProperty( "craftItem", ForgeRegistries.ITEMS.getKey( craftingItem ).toString() );
}
if( damageMultiplier != null ) s.addProperty( "damageMultiplier", damageMultiplier );
if( breakable != null ) s.addProperty( "breakable", breakable.location().toString() );
} ) );

View File

@@ -6,6 +6,8 @@
package dan200.computercraft.api.turtle;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.client.ComputerCraftAPIClient;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
import dan200.computercraft.api.upgrades.IUpgradeBase;
import dan200.computercraft.api.upgrades.UpgradeSerialiser;
import dan200.computercraft.internal.upgrades.SerialiserWithCraftingItem;
@@ -54,25 +56,36 @@ import java.util.function.Function;
* }
* }</pre>
*
* Finally, we need to register a model for our upgrade. This is done with
* {@link ComputerCraftAPIClient#registerTurtleUpgradeModeller(TurtleUpgradeSerialiser, TurtleUpgradeModeller)}:
*
* <pre>{@code
* // Register our model inside FMLClientSetupEvent
* ComputerCraftAPIClient.registerTurtleUpgradeModeller(MY_UPGRADE.get(), TurtleUpgradeModeller.flatItem())
* }</pre>
*
* {@link TurtleUpgradeDataProvider} provides a data provider to aid with generating these JSON files.
*
* @param <T> The type of turtle upgrade this is responsible for serialising.
* @see ITurtleUpgrade
* @see TurtleUpgradeDataProvider
* @see TurtleUpgradeModeller
*/
public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends UpgradeSerialiser<T, TurtleUpgradeSerialiser<?>>
public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends UpgradeSerialiser<T>
{
/**
* The ID for the associated registry.
*
* This is largely intended for use with Forge Registry methods/classes, such as {@link DeferredRegister} and
* {@link RegistryManager#getRegistry(ResourceKey)}.
*
* @see #registry()
*/
ResourceKey<Registry<TurtleUpgradeSerialiser<?>>> REGISTRY_ID = ResourceKey.createRegistryKey( new ResourceLocation( ComputerCraft.MOD_ID, "turtle_upgrade_serialiser" ) );
/**
* The associated registry.
*
* @return The registry for pocket upgrade serialisers.
* @see #REGISTRY_ID
*/
@@ -94,7 +107,7 @@ public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends Upgra
@Nonnull
static <T extends ITurtleUpgrade> TurtleUpgradeSerialiser<T> simple( @Nonnull Function<ResourceLocation, T> factory )
{
class Impl extends SimpleSerialiser<T, TurtleUpgradeSerialiser<?>> implements TurtleUpgradeSerialiser<T>
class Impl extends SimpleSerialiser<T> implements TurtleUpgradeSerialiser<T>
{
private Impl( Function<ResourceLocation, T> constructor )
{
@@ -117,7 +130,7 @@ public interface TurtleUpgradeSerialiser<T extends ITurtleUpgrade> extends Upgra
@Nonnull
static <T extends ITurtleUpgrade> TurtleUpgradeSerialiser<T> simpleWithCustomItem( @Nonnull BiFunction<ResourceLocation, ItemStack, T> factory )
{
class Impl extends SerialiserWithCraftingItem<T, TurtleUpgradeSerialiser<?>> implements TurtleUpgradeSerialiser<T>
class Impl extends SerialiserWithCraftingItem<T> implements TurtleUpgradeSerialiser<T>
{
private Impl( BiFunction<ResourceLocation, ItemStack, T> factory )
{

View File

@@ -68,7 +68,7 @@ public interface IUpgradeBase
* @param stack The stack to check. This is guaranteed to be non-empty and have the same item as
* {@link #getCraftingItem()}.
* @return If this stack may be used to equip this upgrade.
* @see net.minecraftforge.common.crafting.NBTIngredient#test(ItemStack) For the implementation of the default
* @see net.minecraftforge.common.crafting.StrictNBTIngredient#test(ItemStack) For the implementation of the default
* check.
*/
default boolean isItemSuitable( @Nonnull ItemStack stack )

View File

@@ -5,8 +5,6 @@
*/
package dan200.computercraft.api.upgrades;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
@@ -36,10 +34,9 @@ import java.util.function.Function;
* @param <T> The base class of upgrades.
* @param <R> The upgrade serialiser to register for.
*/
public abstract class UpgradeDataProvider<T extends IUpgradeBase, R extends UpgradeSerialiser<?, R>> implements DataProvider
public abstract class UpgradeDataProvider<T extends IUpgradeBase, R extends UpgradeSerialiser<? extends T>> implements DataProvider
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private final DataGenerator generator;
private final String name;
@@ -134,7 +131,7 @@ public abstract class UpgradeDataProvider<T extends IUpgradeBase, R extends Upgr
try
{
@SuppressWarnings( "unchecked" ) var result = (T) upgrade.serialiser().fromJson( upgrade.id(), json );
var result = upgrade.serialiser().fromJson( upgrade.id(), json );
upgrades.add( result );
}
catch( IllegalArgumentException | JsonParseException e )
@@ -176,7 +173,7 @@ public abstract class UpgradeDataProvider<T extends IUpgradeBase, R extends Upgr
* @param serialise Augment the generated JSON with additional fields.
* @param <R> The type of upgrade serialiser.
*/
public static record Upgrade<R extends UpgradeSerialiser<?, R>>(
public record Upgrade<R extends UpgradeSerialiser<?>>(
ResourceLocation id, R serialiser, Consumer<JsonObject> serialise
)
{

View File

@@ -19,12 +19,11 @@ import javax.annotation.Nonnull;
*
* However, it may sometimes be useful to implement this if you have some shared logic between upgrade types.
*
* @param <R> The serialiser for this upgrade category, either {@code TurtleUpgradeSerialiser<?>} or {@code PocketUpgradeSerialiser<?>}.
* @param <T> The upgrade that this class can serialise and deserialise.
* @see TurtleUpgradeSerialiser
* @see PocketUpgradeSerialiser
*/
public interface UpgradeSerialiser<T extends IUpgradeBase, R extends UpgradeSerialiser<?, R>>
public interface UpgradeSerialiser<T extends IUpgradeBase>
{
/**
* Read this upgrade from a JSON file in a datapack.

View File

@@ -10,7 +10,7 @@ import dan200.computercraft.client.sound.SpeakerManager;
import dan200.computercraft.shared.peripheral.monitor.ClientMonitor;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.event.level.LevelEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -18,9 +18,9 @@ import net.minecraftforge.fml.common.Mod;
public class ClientHooks
{
@SubscribeEvent
public static void onWorldUnload( WorldEvent.Unload event )
public static void onWorldUnload( LevelEvent.Unload event )
{
if( event.getWorld().isClientSide() )
if( event.getLevel().isClientSide() )
{
ClientMonitor.destroyAll();
SpeakerManager.reset();
@@ -28,13 +28,13 @@ public class ClientHooks
}
@SubscribeEvent
public static void onLogIn( ClientPlayerNetworkEvent.LoggedInEvent event )
public static void onLogIn( ClientPlayerNetworkEvent.LoggingIn event )
{
ComputerCraft.clientComputerRegistry.reset();
}
@SubscribeEvent
public static void onLogOut( ClientPlayerNetworkEvent.LoggedOutEvent event )
public static void onLogOut( ClientPlayerNetworkEvent.LoggingOut event )
{
ComputerCraft.clientComputerRegistry.reset();
}

View File

@@ -6,10 +6,13 @@
package dan200.computercraft.client;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.client.ComputerCraftAPIClient;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
import dan200.computercraft.client.gui.*;
import dan200.computercraft.client.render.TileEntityMonitorRenderer;
import dan200.computercraft.client.render.TileEntityTurtleRenderer;
import dan200.computercraft.client.render.TurtleModelLoader;
import dan200.computercraft.client.turtle.TurtleModemModeller;
import dan200.computercraft.shared.Registry;
import dan200.computercraft.shared.common.IColouredItem;
import dan200.computercraft.shared.computer.inventory.ContainerComputerBase;
@@ -19,8 +22,6 @@ import dan200.computercraft.shared.media.items.ItemTreasureDisk;
import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.util.Colour;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.client.renderer.item.ItemProperties;
import net.minecraft.client.renderer.item.ItemPropertyFunction;
@@ -28,10 +29,8 @@ import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ColorHandlerEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ForgeModelBakery;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.client.event.RegisterColorHandlersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
@@ -69,17 +68,22 @@ public final class ClientRegistry
private ClientRegistry() {}
@SubscribeEvent
public static void registerModels( ModelRegistryEvent event )
public static void registerModelLoaders( ModelEvent.RegisterGeometryLoaders event )
{
event.register( "turtle", TurtleModelLoader.INSTANCE );
}
@SubscribeEvent
public static void registerModels( ModelEvent.RegisterAdditional event )
{
ModelLoaderRegistry.registerLoader( new ResourceLocation( ComputerCraft.MOD_ID, "turtle" ), TurtleModelLoader.INSTANCE );
for( String model : EXTRA_MODELS )
{
ForgeModelBakery.addSpecialModel( new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, model ), "inventory" ) );
event.register( new ModelResourceLocation( new ResourceLocation( ComputerCraft.MOD_ID, model ), "inventory" ) );
}
}
@SubscribeEvent
public static void onItemColours( ColorHandlerEvent.Item event )
public static void onItemColours( RegisterColorHandlersEvent.Item event )
{
if( Registry.ModItems.DISK == null || Registry.ModBlocks.TURTLE_NORMAL == null )
{
@@ -87,17 +91,17 @@ public final class ClientRegistry
return;
}
event.getItemColors().register(
event.register(
( stack, layer ) -> layer == 1 ? ((ItemDisk) stack.getItem()).getColour( stack ) : 0xFFFFFF,
Registry.ModItems.DISK.get()
);
event.getItemColors().register(
event.register(
( stack, layer ) -> layer == 1 ? ItemTreasureDisk.getColour( stack ) : 0xFFFFFF,
Registry.ModItems.TREASURE_DISK.get()
);
event.getItemColors().register( ( stack, layer ) -> {
event.register( ( stack, layer ) -> {
switch( layer )
{
case 0:
@@ -114,7 +118,7 @@ public final class ClientRegistry
}, Registry.ModItems.POCKET_COMPUTER_NORMAL.get(), Registry.ModItems.POCKET_COMPUTER_ADVANCED.get() );
// Setup turtle colours
event.getItemColors().register(
event.register(
( stack, tintIndex ) -> tintIndex == 0 ? ((IColouredItem) stack.getItem()).getColour( stack ) : 0xFFFFFF,
Registry.ModBlocks.TURTLE_NORMAL.get(), Registry.ModBlocks.TURTLE_ADVANCED.get()
);
@@ -123,20 +127,24 @@ public final class ClientRegistry
@SubscribeEvent
public static void setupClient( FMLClientSetupEvent event )
{
// While turtles themselves are not transparent, their upgrades may be.
ItemBlockRenderTypes.setRenderLayer( Registry.ModBlocks.TURTLE_NORMAL.get(), RenderType.translucent() );
ItemBlockRenderTypes.setRenderLayer( Registry.ModBlocks.TURTLE_ADVANCED.get(), RenderType.translucent() );
// Monitors' textures have transparent fronts and so count as cutouts.
ItemBlockRenderTypes.setRenderLayer( Registry.ModBlocks.MONITOR_NORMAL.get(), RenderType.cutout() );
ItemBlockRenderTypes.setRenderLayer( Registry.ModBlocks.MONITOR_ADVANCED.get(), RenderType.cutout() );
// Setup TESRs
BlockEntityRenderers.register( Registry.ModBlockEntities.MONITOR_NORMAL.get(), TileEntityMonitorRenderer::new );
BlockEntityRenderers.register( Registry.ModBlockEntities.MONITOR_ADVANCED.get(), TileEntityMonitorRenderer::new );
BlockEntityRenderers.register( Registry.ModBlockEntities.TURTLE_NORMAL.get(), TileEntityTurtleRenderer::new );
BlockEntityRenderers.register( Registry.ModBlockEntities.TURTLE_ADVANCED.get(), TileEntityTurtleRenderer::new );
ComputerCraftAPIClient.registerTurtleUpgradeModeller( Registry.ModTurtleSerialisers.SPEAKER.get(), TurtleUpgradeModeller.sided(
new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" ),
new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" )
) );
ComputerCraftAPIClient.registerTurtleUpgradeModeller( Registry.ModTurtleSerialisers.WORKBENCH.get(), TurtleUpgradeModeller.sided(
new ModelResourceLocation( "computercraft:turtle_crafting_table_left", "inventory" ),
new ModelResourceLocation( "computercraft:turtle_crafting_table_right", "inventory" )
) );
ComputerCraftAPIClient.registerTurtleUpgradeModeller( Registry.ModTurtleSerialisers.WIRELESS_MODEM_NORMAL.get(), new TurtleModemModeller( false ) );
ComputerCraftAPIClient.registerTurtleUpgradeModeller( Registry.ModTurtleSerialisers.WIRELESS_MODEM_ADVANCED.get(), new TurtleModemModeller( true ) );
ComputerCraftAPIClient.registerTurtleUpgradeModeller( Registry.ModTurtleSerialisers.TOOL.get(), TurtleUpgradeModeller.flatItem() );
event.enqueueWork( () -> {
registerContainers();

View File

@@ -8,8 +8,8 @@ package dan200.computercraft.client;
import dan200.computercraft.shared.command.text.ChatHelpers;
import dan200.computercraft.shared.command.text.TableBuilder;
import dan200.computercraft.shared.command.text.TableFormatter;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import net.minecraft.ChatFormatting;
import net.minecraft.client.GuiMessageTag;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.components.ChatComponent;
@@ -18,13 +18,12 @@ import net.minecraft.util.Mth;
import org.apache.commons.lang3.StringUtils;
import javax.annotation.Nullable;
import java.util.Objects;
public class ClientTableFormatter implements TableFormatter
{
public static final ClientTableFormatter INSTANCE = new ClientTableFormatter();
private static final Int2IntOpenHashMap lastHeights = new Int2IntOpenHashMap();
private static Font renderer()
{
return Minecraft.getInstance().font;
@@ -59,7 +58,7 @@ public class ClientTableFormatter implements TableFormatter
}
@Override
public void writeLine( int id, Component component )
public void writeLine( String label, Component component )
{
Minecraft mc = Minecraft.getInstance();
ChatComponent chat = mc.gui.getChat();
@@ -68,20 +67,25 @@ public class ClientTableFormatter implements TableFormatter
// int maxWidth = MathHelper.floor( chat.getChatWidth() / chat.getScale() );
// List<ITextProperties> list = RenderComponentsUtil.wrapComponents( component, maxWidth, mc.fontRenderer );
// if( !list.isEmpty() ) chat.printChatMessageWithOptionalDeletion( list.get( 0 ), id );
chat.addMessage( component, id );
chat.addMessage( component, null, createTag( label ) );
}
@Override
public int display( TableBuilder table )
public void display( TableBuilder table )
{
ChatComponent chat = Minecraft.getInstance().gui.getChat();
int lastHeight = lastHeights.get( table.getId() );
var tag = createTag( table.getId() );
if( chat.allMessages.removeIf( guiMessage -> guiMessage.tag() != null && Objects.equals( guiMessage.tag().logTag(), tag.logTag() ) ) )
{
chat.refreshTrimmedMessage();
}
int height = TableFormatter.super.display( table );
lastHeights.put( table.getId(), height );
TableFormatter.super.display( table );
}
for( int i = height; i < lastHeight; i++ ) chat.removeById( i + table.getId() );
return height;
private static GuiMessageTag createTag( String id )
{
return new GuiMessageTag( 0xa0a0a0, null, null, "ComputerCraft/" + id );
}
}

View File

@@ -0,0 +1,29 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client;
import dan200.computercraft.api.client.ComputerCraftAPIClient;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
import dan200.computercraft.client.turtle.TurtleUpgradeModellers;
import javax.annotation.Nonnull;
public final class ComputerCraftAPIClientImpl implements ComputerCraftAPIClient.IComputerCraftAPIClient
{
public static final ComputerCraftAPIClientImpl INSTANCE = new ComputerCraftAPIClientImpl();
private ComputerCraftAPIClientImpl()
{
}
@Override
public <T extends ITurtleUpgrade> void registerTurtleUpgradeModeller( @Nonnull TurtleUpgradeSerialiser<T> serialiser, @Nonnull TurtleUpgradeModeller<T> modeller )
{
TurtleUpgradeModellers.register( serialiser, modeller );
}
}

View File

@@ -23,7 +23,7 @@ import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.DrawSelectionEvent;
import net.minecraftforge.client.event.RenderHighlightEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -41,7 +41,7 @@ public final class CableHighlightRenderer
* @see net.minecraft.client.renderer.LevelRenderer#renderHitOutline
*/
@SubscribeEvent
public static void drawHighlight( DrawSelectionEvent.HighlightBlock event )
public static void drawHighlight( RenderHighlightEvent.Block event )
{
BlockHitResult hit = event.getTarget();
BlockPos pos = hit.getBlockPos();

View File

@@ -15,7 +15,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -25,7 +25,7 @@ import java.util.List;
public class DebugOverlay
{
@SubscribeEvent
public static void onRenderText( RenderGameOverlayEvent.Text event )
public static void onRenderText( CustomizeGuiOverlayEvent.DebugText event )
{
Minecraft minecraft = Minecraft.getInstance();
if( !minecraft.options.renderDebug || minecraft.level == null ) return;

View File

@@ -18,7 +18,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.DrawSelectionEvent;
import net.minecraftforge.client.event.RenderHighlightEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -38,7 +38,7 @@ public final class MonitorHighlightRenderer
}
@SubscribeEvent
public static void drawHighlight( DrawSelectionEvent.HighlightBlock event )
public static void drawHighlight( RenderHighlightEvent.Block event )
{
// Preserve normal behaviour when crouching.
if( event.getCamera().getEntity().isCrouching() ) return;

View File

@@ -116,8 +116,11 @@ public final class PrintoutRenderer
}
}
// Left half
drawTexture( transform, buffer, x, y, z, X_FOLD_SIZE * 2, 0, X_SIZE / 2.0f, Y_SIZE, light );
// Current page background: Z-offset is interleaved between the "zeroth" left/right page and the first
// left/right page, so that the "bold" border can be drawn over the edge where appropriate.
drawTexture( transform, buffer, x, y, z - 1e-3f * 0.5f, X_FOLD_SIZE * 2, 0, X_SIZE, Y_SIZE, light );
// Left pages
for( int n = 0; n <= leftPages; n++ )
{
drawTexture( transform, buffer,
@@ -128,8 +131,7 @@ public final class PrintoutRenderer
);
}
// Right half
drawTexture( transform, buffer, x + X_SIZE / 2.0f, y, z, X_FOLD_SIZE * 2 + X_SIZE / 2.0f, 0, X_SIZE / 2.0f, Y_SIZE, light );
// Right pages
for( int n = 0; n <= rightPages; n++ )
{
drawTexture( transform, buffer,

View File

@@ -8,7 +8,9 @@ package dan200.computercraft.client.render;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.platform.MemoryTracker;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector3f;
@@ -23,7 +25,6 @@ import dan200.computercraft.shared.peripheral.monitor.MonitorRenderer;
import dan200.computercraft.shared.peripheral.monitor.TileMonitor;
import dan200.computercraft.shared.util.DirectionUtil;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
@@ -113,7 +114,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
Matrix4f matrix = transform.last().pose();
renderTerminal( bufferSource, matrix, originTerminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale) );
renderTerminal( matrix, originTerminal, (float) (MARGIN / xScale), (float) (MARGIN / yScale) );
transform.popPose();
}
@@ -129,7 +130,7 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
transform.popPose();
}
private static void renderTerminal( @Nonnull MultiBufferSource bufferSource, Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin )
private static void renderTerminal( Matrix4f matrix, ClientMonitor monitor, float xMargin, float yMargin )
{
Terminal terminal = monitor.getTerminal();
int width = terminal.getWidth(), height = terminal.getHeight();
@@ -163,11 +164,13 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
MonitorTextureBufferShader shader = RenderTypes.getMonitorTextureBufferShader();
shader.setupUniform( monitor.tboUniform );
VertexConsumer buffer = bufferSource.getBuffer( RenderTypes.MONITOR_TBO );
BufferBuilder buffer = Tesselator.getInstance().getBuilder();
buffer.begin( RenderTypes.MONITOR_TBO.mode(), RenderTypes.MONITOR_TBO.format() );
tboVertex( buffer, matrix, -xMargin, -yMargin );
tboVertex( buffer, matrix, -xMargin, pixelHeight + yMargin );
tboVertex( buffer, matrix, pixelWidth + xMargin, -yMargin );
tboVertex( buffer, matrix, pixelWidth + xMargin, pixelHeight + yMargin );
RenderTypes.MONITOR_TBO.end( buffer, 0, 0, 0 );
break;
}
@@ -195,27 +198,27 @@ public class TileEntityMonitorRenderer implements BlockEntityRenderer<TileMonito
vbo.upload( termIndexes, RenderTypes.TERMINAL_WITHOUT_DEPTH.mode(), RenderTypes.TERMINAL_WITHOUT_DEPTH.format(), buffer );
}
bufferSource.getBuffer( RenderTypes.TERMINAL_WITHOUT_DEPTH );
RenderTypes.TERMINAL_WITHOUT_DEPTH.setupRenderState();
vbo.drawWithShader(
matrix, RenderSystem.getProjectionMatrix(), RenderTypes.getTerminalShader(),
// As mentioned in the above comment, render the extra cursor quad if it is visible this frame. Each
// // quad has an index count of 6.
FixedWidthFontRenderer.isCursorVisible( terminal ) && FrameInfo.getGlobalCursorBlink() ? vbo.getIndexCount() + 6 : vbo.getIndexCount()
);
RenderTypes.TERMINAL_WITHOUT_DEPTH.clearRenderState();
// TERMINAL_WITHOUT_DEPTH doesn't write to the depth blocker, so write a blocker over the monitor.
BufferBuilder buffer = Tesselator.getInstance().getBuilder();
buffer.begin( RenderTypes.TERMINAL_BLOCKER.mode(), RenderTypes.TERMINAL_BLOCKER.format() );
FixedWidthFontRenderer.drawBlocker(
FixedWidthFontRenderer.toVertexConsumer( matrix, bufferSource.getBuffer( RenderTypes.TERMINAL_BLOCKER ) ),
-xMargin, -yMargin, pixelWidth + xMargin, pixelHeight + yMargin
FixedWidthFontRenderer.toVertexConsumer( matrix, buffer ),
-xMargin, -yMargin, pixelWidth + xMargin * 2, pixelHeight + yMargin * 2
);
RenderTypes.TERMINAL_BLOCKER.end( buffer, 0, 0, 0 );
break;
}
}
// Force a flush of the buffer. WorldRenderer.updateCameraAndRender will "finish" all the built-in buffers
// before calling renderer.finish, which means our TBO quad or depth blocker won't be rendered yet!
bufferSource.getBuffer( RenderType.solid() );
}
private static void tboVertex( VertexConsumer builder, Matrix4f matrix, float x, float y )

View File

@@ -12,6 +12,7 @@ import com.mojang.math.Vector3f;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.client.turtle.TurtleUpgradeModellers;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.turtle.blocks.TileTurtle;
import dan200.computercraft.shared.util.DirectionUtil;
@@ -34,7 +35,7 @@ import net.minecraft.util.RandomSource;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.ModelData;
import javax.annotation.Nonnull;
import java.util.List;
@@ -148,7 +149,7 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
transform.mulPose( Vector3f.XN.rotationDegrees( toolAngle ) );
transform.translate( 0.0f, -0.5f, -0.5f );
TransformedModel model = upgrade.getModel( turtle.getAccess(), side );
TransformedModel model = TurtleUpgradeModellers.getModel( upgrade, turtle.getAccess(), side );
model.getMatrix().push( transform );
renderModel( transform, renderer, lightmapCoord, overlayLight, model.getModel(), null );
transform.popPose();
@@ -165,10 +166,10 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
private void renderModel( @Nonnull PoseStack transform, @Nonnull VertexConsumer renderer, int lightmapCoord, int overlayLight, BakedModel model, int[] tints )
{
random.setSeed( 0 );
renderQuads( transform, renderer, lightmapCoord, overlayLight, model.getQuads( null, null, random, EmptyModelData.INSTANCE ), tints );
renderQuads( transform, renderer, lightmapCoord, overlayLight, model.getQuads( null, null, random, ModelData.EMPTY, null ), tints );
for( Direction facing : DirectionUtil.FACINGS )
{
renderQuads( transform, renderer, lightmapCoord, overlayLight, model.getQuads( null, facing, random, EmptyModelData.INSTANCE ), tints );
renderQuads( transform, renderer, lightmapCoord, overlayLight, model.getQuads( null, facing, random, ModelData.EMPTY, null ), tints );
}
}
@@ -185,10 +186,10 @@ public class TileEntityTurtleRenderer implements BlockEntityRenderer<TileTurtle>
if( idx >= 0 && idx < tints.length ) tint = tints[bakedquad.getTintIndex()];
}
float f = (float) (tint >> 16 & 255) / 255.0F;
float f1 = (float) (tint >> 8 & 255) / 255.0F;
float f2 = (float) (tint & 255) / 255.0F;
buffer.putBulkData( matrix, bakedquad, f, f1, f2, lightmapCoord, overlayLight, true );
float r = (float) (tint >> 16 & 255) / 255.0F;
float g = (float) (tint >> 8 & 255) / 255.0F;
float b = (float) (tint & 255) / 255.0F;
buffer.putBulkData( matrix, bakedquad, r, g, b, lightmapCoord, overlayLight );
}
}
}

View File

@@ -0,0 +1,60 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.render;
import com.mojang.math.Transformation;
import dan200.computercraft.api.client.TransformedModel;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.BakedModelWrapper;
import net.minecraftforge.client.model.QuadTransformers;
import net.minecraftforge.client.model.data.ModelData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
import java.util.List;
public class TransformedBakedModel extends BakedModelWrapper<BakedModel>
{
private final Transformation transformation;
private final boolean isIdentity;
public TransformedBakedModel( BakedModel model, Transformation transformation )
{
super( model );
this.transformation = transformation;
isIdentity = transformation.isIdentity();
}
public TransformedBakedModel( TransformedModel model )
{
this( model.getModel(), model.getMatrix() );
}
@Nonnull
@Override
public List<BakedQuad> getQuads( @Nullable BlockState state, @Nullable Direction side, @Nonnull RandomSource rand )
{
return getQuads( state, side, rand, ModelData.EMPTY, null );
}
@Override
public @NotNull List<BakedQuad> getQuads( @Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData extraData, @Nullable RenderType renderType )
{
List<BakedQuad> quads = originalModel.getQuads( state, side, rand, extraData, renderType );
return isIdentity ? quads : QuadTransformers.applying( transformation ).process( quads );
}
public TransformedBakedModel composeWith( Transformation other )
{
return new TransformedBakedModel( originalModel, other.compose( transformation ) );
}
}

View File

@@ -13,11 +13,10 @@ import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.GsonHelper;
import net.minecraftforge.client.model.IModelConfiguration;
import net.minecraftforge.client.model.IModelLoader;
import net.minecraftforge.client.model.geometry.IModelGeometry;
import net.minecraftforge.client.model.geometry.IGeometryBakingContext;
import net.minecraftforge.client.model.geometry.IGeometryLoader;
import net.minecraftforge.client.model.geometry.IUnbakedGeometry;
import javax.annotation.Nonnull;
import java.util.Collection;
@@ -25,7 +24,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.TurtleModel>
public final class TurtleModelLoader implements IGeometryLoader<TurtleModelLoader.TurtleModel>
{
private static final ResourceLocation COLOUR_TURTLE_MODEL = new ResourceLocation( ComputerCraft.MOD_ID, "block/turtle_colour" );
@@ -35,20 +34,15 @@ public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.T
{
}
@Override
public void onResourceManagerReload( @Nonnull ResourceManager manager )
{
}
@Nonnull
@Override
public TurtleModel read( @Nonnull JsonDeserializationContext deserializationContext, @Nonnull JsonObject modelContents )
public TurtleModel read( @Nonnull JsonObject modelContents, @Nonnull JsonDeserializationContext deserializationContext )
{
ResourceLocation model = new ResourceLocation( GsonHelper.getAsString( modelContents, "model" ) );
return new TurtleModel( model );
}
public static final class TurtleModel implements IModelGeometry<TurtleModel>
public static final class TurtleModel implements IUnbakedGeometry<TurtleModel>
{
private final ResourceLocation family;
@@ -58,7 +52,7 @@ public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.T
}
@Override
public Collection<Material> getTextures( IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors )
public Collection<Material> getMaterials( IGeometryBakingContext context, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors )
{
Set<Material> materials = new HashSet<>();
materials.addAll( modelGetter.apply( family ).getMaterials( modelGetter, missingTextureErrors ) );
@@ -67,7 +61,7 @@ public final class TurtleModelLoader implements IModelLoader<TurtleModelLoader.T
}
@Override
public BakedModel bake( IModelConfiguration owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ItemOverrides overrides, ResourceLocation modelLocation )
public BakedModel bake( IGeometryBakingContext owner, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState transform, ItemOverrides overrides, ResourceLocation modelLocation )
{
return new TurtleSmartItemModel(
bakery.bake( family, transform, spriteGetter ),

View File

@@ -1,153 +0,0 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.render;
import com.mojang.math.Transformation;
import dan200.computercraft.api.client.TransformedModel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.EmptyModelData;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
public class TurtleMultiModel implements BakedModel
{
private final BakedModel baseModel;
private final BakedModel overlayModel;
private final Transformation 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 );
public TurtleMultiModel( BakedModel baseModel, BakedModel overlayModel, Transformation generalTransform, TransformedModel leftUpgradeModel, TransformedModel rightUpgradeModel )
{
// Get the models
this.baseModel = baseModel;
this.overlayModel = overlayModel;
this.leftUpgradeModel = leftUpgradeModel;
this.rightUpgradeModel = rightUpgradeModel;
this.generalTransform = generalTransform;
}
@Nonnull
@Override
@Deprecated
public List<BakedQuad> getQuads( BlockState state, Direction side, @Nonnull RandomSource rand )
{
return getQuads( state, side, rand, EmptyModelData.INSTANCE );
}
@Nonnull
@Override
public List<BakedQuad> getQuads( BlockState state, Direction side, @Nonnull RandomSource rand, @Nonnull IModelData data )
{
if( side != null )
{
if( !faceQuads.containsKey( side ) ) faceQuads.put( side, buildQuads( state, side, rand ) );
return faceQuads.get( side );
}
else
{
if( generalQuads == null ) generalQuads = buildQuads( state, side, rand );
return generalQuads;
}
}
private List<BakedQuad> buildQuads( BlockState state, Direction side, RandomSource rand )
{
ArrayList<BakedQuad> quads = new ArrayList<>();
transformQuadsTo( quads, baseModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), generalTransform );
if( overlayModel != null )
{
transformQuadsTo( quads, overlayModel.getQuads( state, side, rand, EmptyModelData.INSTANCE ), generalTransform );
}
if( leftUpgradeModel != null )
{
Transformation upgradeTransform = generalTransform.compose( leftUpgradeModel.getMatrix() );
transformQuadsTo( quads, leftUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
}
if( rightUpgradeModel != null )
{
Transformation upgradeTransform = generalTransform.compose( rightUpgradeModel.getMatrix() );
transformQuadsTo( quads, rightUpgradeModel.getModel().getQuads( state, side, rand, EmptyModelData.INSTANCE ), upgradeTransform );
}
quads.trimToSize();
return quads;
}
@Override
public boolean useAmbientOcclusion()
{
return baseModel.useAmbientOcclusion();
}
@Override
public boolean isGui3d()
{
return baseModel.isGui3d();
}
@Override
public boolean isCustomRenderer()
{
return baseModel.isCustomRenderer();
}
@Override
public boolean usesBlockLight()
{
return baseModel.usesBlockLight();
}
@Nonnull
@Override
@Deprecated
public TextureAtlasSprite getParticleIcon()
{
return baseModel.getParticleIcon();
}
@Nonnull
@Override
@Deprecated
public net.minecraft.client.renderer.block.model.ItemTransforms getTransforms()
{
return baseModel.getTransforms();
}
@Nonnull
@Override
public ItemOverrides getOverrides()
{
return ItemOverrides.EMPTY;
}
private void transformQuadsTo( List<BakedQuad> output, List<BakedQuad> quads, Transformation transform )
{
for( BakedQuad quad : quads )
{
BakedQuadBuilder builder = new BakedQuadBuilder();
TRSRTransformer transformer = new TRSRTransformer( builder, transform );
quad.pipe( transformer );
output.add( builder.build() );
}
}
}

View File

@@ -7,35 +7,28 @@ package dan200.computercraft.client.render;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Transformation;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.client.turtle.TurtleUpgradeModellers;
import dan200.computercraft.shared.turtle.items.ItemTurtle;
import dan200.computercraft.shared.util.Holiday;
import dan200.computercraft.shared.util.HolidayUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemOverrides;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.BakedModelWrapper;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TurtleSmartItemModel implements BakedModel
public class TurtleSmartItemModel extends BakedModelWrapper<BakedModel>
{
private static final Transformation identity, flip;
@@ -49,7 +42,7 @@ public class TurtleSmartItemModel implements BakedModel
flip = new Transformation( stack.last().pose() );
}
private static record TurtleModelCombination(
private record TurtleModelCombination(
boolean colour,
ITurtleUpgrade leftUpgrade,
ITurtleUpgrade rightUpgrade,
@@ -63,112 +56,64 @@ public class TurtleSmartItemModel implements BakedModel
private final BakedModel familyModel;
private final BakedModel colourModel;
private final HashMap<TurtleModelCombination, BakedModel> cachedModels = new HashMap<>();
private final ItemOverrides overrides;
private final Map<TurtleModelCombination, List<BakedModel>> cachedModels = new HashMap<>();
public TurtleSmartItemModel( BakedModel familyModel, BakedModel colourModel )
{
super( familyModel );
this.familyModel = familyModel;
this.colourModel = colourModel;
overrides = new ItemOverrides()
{
@Nonnull
@Override
public BakedModel resolve( @Nonnull BakedModel originalModel, @Nonnull ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int random )
{
ItemTurtle turtle = (ItemTurtle) stack.getItem();
int colour = turtle.getColour( stack );
ITurtleUpgrade leftUpgrade = turtle.getUpgrade( stack, TurtleSide.LEFT );
ITurtleUpgrade rightUpgrade = turtle.getUpgrade( stack, TurtleSide.RIGHT );
ResourceLocation overlay = turtle.getOverlay( stack );
boolean christmas = HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS;
String label = turtle.getLabel( stack );
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
BakedModel model = cachedModels.get( combo );
if( model == null ) cachedModels.put( combo, model = buildModel( combo ) );
return model;
}
};
}
@Nonnull
@Override
public ItemOverrides getOverrides()
public BakedModel applyTransform( @Nonnull ItemTransforms.TransformType cameraTransformType, @Nonnull PoseStack poseStack, boolean applyLeftHandTransform )
{
return overrides;
originalModel.applyTransform( cameraTransformType, poseStack, applyLeftHandTransform );
return this;
}
private BakedModel buildModel( TurtleModelCombination combo )
@Nonnull
@Override
public List<BakedModel> getRenderPasses( ItemStack stack, boolean fabulous )
{
ItemTurtle turtle = (ItemTurtle) stack.getItem();
int colour = turtle.getColour( stack );
ITurtleUpgrade leftUpgrade = turtle.getUpgrade( stack, TurtleSide.LEFT );
ITurtleUpgrade rightUpgrade = turtle.getUpgrade( stack, TurtleSide.RIGHT );
ResourceLocation overlay = turtle.getOverlay( stack );
boolean christmas = HolidayUtil.getCurrentHoliday() == Holiday.CHRISTMAS;
String label = turtle.getLabel( stack );
boolean flip = label != null && (label.equals( "Dinnerbone" ) || label.equals( "Grumm" ));
TurtleModelCombination combo = new TurtleModelCombination( colour != -1, leftUpgrade, rightUpgrade, overlay, christmas, flip );
return cachedModels.computeIfAbsent( combo, this::buildModel );
}
private List<BakedModel> buildModel( TurtleModelCombination combo )
{
Minecraft mc = Minecraft.getInstance();
ModelManager modelManager = mc.getItemRenderer().getItemModelShaper().getModelManager();
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay, combo.christmas );
BakedModel baseModel = combo.colour ? colourModel : familyModel;
BakedModel overlayModel = overlayModelLocation != null ? modelManager.getModel( overlayModelLocation ) : null;
Transformation 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;
return new TurtleMultiModel( baseModel, overlayModel, transform, leftModel, rightModel );
var transformation = combo.flip ? flip : identity;
ArrayList<BakedModel> parts = new ArrayList<>( 4 );
parts.add( new TransformedBakedModel( combo.colour() ? colourModel : familyModel, transformation ) );
ModelResourceLocation overlayModelLocation = TileEntityTurtleRenderer.getTurtleOverlayModel( combo.overlay(), combo.christmas() );
if( overlayModelLocation != null )
{
parts.add( new TransformedBakedModel( modelManager.getModel( overlayModelLocation ), transformation ) );
}
if( combo.leftUpgrade() != null )
{
parts.add( new TransformedBakedModel( TurtleUpgradeModellers.getModel( combo.leftUpgrade(), null, TurtleSide.LEFT ) ).composeWith( transformation ) );
}
if( combo.rightUpgrade() != null )
{
parts.add( new TransformedBakedModel( TurtleUpgradeModellers.getModel( combo.rightUpgrade(), null, TurtleSide.RIGHT ) ).composeWith( transformation ) );
}
return parts;
}
@Nonnull
@Override
@Deprecated
public List<BakedQuad> getQuads( BlockState state, Direction facing, @Nonnull RandomSource rand )
{
return familyModel.getQuads( state, facing, rand );
}
@Nonnull
@Override
@Deprecated
public List<BakedQuad> getQuads( BlockState state, Direction facing, @Nonnull RandomSource rand, @Nonnull IModelData data )
{
return familyModel.getQuads( state, facing, rand, data );
}
@Override
public boolean useAmbientOcclusion()
{
return familyModel.useAmbientOcclusion();
}
@Override
public boolean isGui3d()
{
return familyModel.isGui3d();
}
@Override
public boolean isCustomRenderer()
{
return familyModel.isCustomRenderer();
}
@Override
public boolean usesBlockLight()
{
return familyModel.usesBlockLight();
}
@Nonnull
@Override
@Deprecated
public TextureAtlasSprite getParticleIcon()
{
return familyModel.getParticleIcon();
}
@Nonnull
@Override
@Deprecated
public ItemTransforms getTransforms()
{
return familyModel.getTransforms();
}
}

View File

@@ -0,0 +1,59 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.turtle;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.shared.turtle.upgrades.TurtleModem;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.nbt.CompoundTag;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
public class TurtleModemModeller implements TurtleUpgradeModeller<TurtleModem>
{
private final ModelResourceLocation leftOffModel;
private final ModelResourceLocation rightOffModel;
private final ModelResourceLocation leftOnModel;
private final ModelResourceLocation rightOnModel;
public TurtleModemModeller( boolean advanced )
{
if( advanced )
{
leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_left", "inventory" );
rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_right", "inventory" );
leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_left", "inventory" );
rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_right", "inventory" );
}
else
{
leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_left", "inventory" );
rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_right", "inventory" );
leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_left", "inventory" );
rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_right", "inventory" );
}
}
@Nonnull
@Override
public TransformedModel getModel( @Nonnull TurtleModem upgrade, @Nullable ITurtleAccess turtle, @Nonnull TurtleSide side )
{
boolean active = false;
if( turtle != null )
{
CompoundTag turtleNBT = turtle.getUpgradeNBTData( side );
active = turtleNBT.contains( "active" ) && turtleNBT.getBoolean( "active" );
}
return side == TurtleSide.LEFT
? TransformedModel.of( active ? leftOnModel : leftOffModel )
: TransformedModel.of( active ? rightOnModel : rightOffModel );
}
}

View File

@@ -0,0 +1,72 @@
/*
* This file is part of ComputerCraft - http://www.computercraft.info
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
* Send enquiries to dratcliffe@gmail.com
*/
package dan200.computercraft.client.turtle;
import com.mojang.math.Transformation;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.client.turtle.TurtleUpgradeModeller;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
import dan200.computercraft.shared.TurtleUpgrades;
import dan200.computercraft.shared.UpgradeManager;
import net.minecraft.client.Minecraft;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
public final class TurtleUpgradeModellers
{
private static final TurtleUpgradeModeller<ITurtleUpgrade> NULL_TURTLE_MODELLER = ( upgrade, turtle, side ) ->
new TransformedModel( Minecraft.getInstance().getModelManager().getMissingModel(), Transformation.identity() );
private static final Map<TurtleUpgradeSerialiser<?>, TurtleUpgradeModeller<?>> turtleModels = new ConcurrentHashMap<>();
/**
* In order to avoid a double lookup of {@link ITurtleUpgrade} to {@link UpgradeManager.UpgradeWrapper} to
* {@link TurtleUpgradeModeller}, we maintain a cache here.
* <p>
* Turtle upgrades may be removed as part of datapack reloads, so we use a weak map to avoid the memory leak.
*/
private static final WeakHashMap<ITurtleUpgrade, TurtleUpgradeModeller<?>> modelCache = new WeakHashMap<>();
private TurtleUpgradeModellers()
{
}
public static <T extends ITurtleUpgrade> void register( @Nonnull TurtleUpgradeSerialiser<T> serialiser, @Nonnull TurtleUpgradeModeller<T> modeller )
{
synchronized( turtleModels )
{
if( turtleModels.containsKey( serialiser ) )
{
throw new IllegalStateException( "Modeller already registered for serialiser" );
}
turtleModels.put( serialiser, modeller );
}
}
public static TransformedModel getModel( @Nonnull ITurtleUpgrade upgrade, @Nullable ITurtleAccess access, @Nonnull TurtleSide side )
{
@SuppressWarnings( "unchecked" )
var modeller = (TurtleUpgradeModeller<ITurtleUpgrade>) modelCache.computeIfAbsent( upgrade, TurtleUpgradeModellers::getModeller );
return modeller.getModel( upgrade, access, side );
}
private static TurtleUpgradeModeller<?> getModeller( ITurtleUpgrade upgradeA )
{
var wrapper = TurtleUpgrades.instance().getWrapper( upgradeA );
if( wrapper == null ) return NULL_TURTLE_MODELLER;
var modeller = turtleModels.get( wrapper.serialiser() );
return modeller == null ? NULL_TURTLE_MODELLER : modeller;
}
}

View File

@@ -50,6 +50,7 @@ public class DirectVertexBuffer extends VertexBuffer
if( format != this.format )
{
if( this.format != null ) this.format.clearBufferState();
this.format = format;
GL15C.glBindBuffer( GL15C.GL_ARRAY_BUFFER, vertexBufferId );
format.setupBufferState();

View File

@@ -316,7 +316,7 @@ public class OSAPI implements ILuaAPI
* Returns the current time depending on the string passed in. This will
* always be in the range [0.0, 24.0).
*
* * If called with {@code dan200.computercraft.ingame}, the current world time will be returned.
* * If called with {@code ingame}, the current world time will be returned.
* This is the default if nothing is passed.
* * If called with {@code utc}, returns the hour of the day in UTC time.
* * If called with {@code local}, returns the hour of the day in the
@@ -326,10 +326,10 @@ public class OSAPI implements ILuaAPI
* which will convert the date fields into a UNIX timestamp (number of
* seconds since 1 January 1970).
*
* @param args The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code dan200.computercraft.ingame} locale if not specified.
* @param args The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code ingame} locale if not specified.
* @return The hour of the selected locale, or a UNIX timestamp from the table, depending on the argument passed in.
* @throws LuaException If an invalid locale is passed.
* @cc.tparam [opt] string|table locale The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code dan200.computercraft.ingame} locale if not specified.
* @cc.tparam [opt] string|table locale The locale of the time, or a table filled by {@code os.date("*t")} to decode. Defaults to {@code ingame} locale if not specified.
* @cc.see textutils.formatTime To convert times into a user-readable string.
* @cc.usage Print the current in-game time.
* <pre>{@code
@@ -347,14 +347,14 @@ public class OSAPI implements ILuaAPI
Object value = args.get( 0 );
if( value instanceof Map ) return LuaDateTime.fromTable( (Map<?, ?>) value );
String param = args.optString( 0, "dan200.computercraft.ingame" );
String param = args.optString( 0, "ingame" );
switch( param.toLowerCase( Locale.ROOT ) )
{
case "utc": // Get Hour of day (UTC)
return getTimeForCalendar( Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ) );
case "local": // Get Hour of day (local time)
return getTimeForCalendar( Calendar.getInstance() );
case "dan200.computercraft.ingame": // Get in-game hour
case "ingame": // Get in-game hour
return time;
default:
throw new LuaException( "Unsupported operation" );
@@ -364,14 +364,14 @@ public class OSAPI implements ILuaAPI
/**
* Returns the day depending on the locale specified.
*
* * If called with {@code dan200.computercraft.ingame}, returns the number of days since the
* * If called with {@code ingame}, returns the number of days since the
* world was created. This is the default.
* * If called with {@code utc}, returns the number of days since 1 January
* 1970 in the UTC timezone.
* * If called with {@code local}, returns the number of days since 1
* January 1970 in the server's local timezone.
*
* @param args The locale to get the day for. Defaults to {@code dan200.computercraft.ingame} if not set.
* @param args The locale to get the day for. Defaults to {@code ingame} if not set.
* @return The day depending on the selected locale.
* @throws LuaException If an invalid locale is passed.
* @cc.since 1.48
@@ -380,13 +380,13 @@ public class OSAPI implements ILuaAPI
@LuaFunction
public final int day( Optional<String> args ) throws LuaException
{
switch( args.orElse( "dan200.computercraft.ingame" ).toLowerCase( Locale.ROOT ) )
switch( args.orElse( "ingame" ).toLowerCase( Locale.ROOT ) )
{
case "utc": // Get numbers of days since 1970-01-01 (utc)
return getDayForCalendar( Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) ) );
case "local": // Get numbers of days since 1970-01-01 (local time)
return getDayForCalendar( Calendar.getInstance() );
case "dan200.computercraft.ingame":// Get game day
case "ingame":// Get game day
return day;
default:
throw new LuaException( "Unsupported operation" );
@@ -396,14 +396,14 @@ public class OSAPI implements ILuaAPI
/**
* Returns the number of milliseconds since an epoch depending on the locale.
*
* * If called with {@code dan200.computercraft.ingame}, returns the number of milliseconds since the
* * If called with {@code ingame}, returns the number of milliseconds since the
* 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.
* * If called with {@code local}, returns the number of milliseconds since 1
* January 1970 in the server's local timezone.
*
* @param args The locale to get the milliseconds for. Defaults to {@code dan200.computercraft.ingame} if not set.
* @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.
* @throws LuaException If an invalid locale is passed.
* @cc.since 1.80pr1
@@ -418,7 +418,7 @@ public class OSAPI implements ILuaAPI
@LuaFunction
public final long epoch( Optional<String> args ) throws LuaException
{
switch( args.orElse( "dan200.computercraft.ingame" ).toLowerCase( Locale.ROOT ) )
switch( args.orElse( "ingame" ).toLowerCase( Locale.ROOT ) )
{
case "utc":
{
@@ -432,7 +432,7 @@ public class OSAPI implements ILuaAPI
Calendar c = Calendar.getInstance();
return getEpochForCalendar( c );
}
case "dan200.computercraft.ingame":
case "ingame":
// Get in-game epoch
synchronized( alarms )
{

View File

@@ -47,13 +47,15 @@ public class TextBuffer
public void write( ByteBuffer text, int start )
{
int pos = start;
int bufferPos = text.position();
start = Math.max( start, 0 );
int length = text.remaining();
int end = Math.min( start + length, pos + length );
end = Math.min( end, this.text.length );
for( int i = start; i < end; i++ )
{
this.text[i] = (char) (text.get( i - pos ) & 0xFF);
this.text[i] = (char) (text.get( bufferPos + i - pos ) & 0xFF);
}
}

View File

@@ -8,9 +8,9 @@ package dan200.computercraft.data;
import dan200.computercraft.shared.Registry;
import net.minecraft.data.DataGenerator;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
@Mod.EventBusSubscriber( bus = Mod.EventBusSubscriber.Bus.MOD )
public class Generators

View File

@@ -21,10 +21,9 @@ import java.util.function.BiFunction;
*
* Do <strong>NOT</strong> directly reference this class. It exists for internal use by the API.
*
* @param <R> The serialiser for this upgrade category, either {@code TurtleUpgradeSerialiser<?>} or {@code PocketUpgradeSerialiser<?>}.
* @param <T> The upgrade that this class can serialise and deserialise.
*/
public abstract class SerialiserWithCraftingItem<T extends IUpgradeBase, R extends UpgradeSerialiser<?, R>> implements UpgradeSerialiser<T, R>
public abstract class SerialiserWithCraftingItem<T extends IUpgradeBase> implements UpgradeSerialiser<T>
{
private final BiFunction<ResourceLocation, ItemStack, T> factory;

View File

@@ -19,10 +19,9 @@ import java.util.function.Function;
*
* Do <strong>NOT</strong> directly reference this class. It exists for internal use by the API.
*
* @param <R> The serialiser for this upgrade category, either {@code TurtleUpgradeSerialiser<?>} or {@code PocketUpgradeSerialiser<?>}.
* @param <T> The upgrade that this class can serialise and deserialise.
*/
public abstract class SimpleSerialiser<T extends IUpgradeBase, R extends UpgradeSerialiser<?, R>> implements UpgradeSerialiser<T, R>
public abstract class SimpleSerialiser<T extends IUpgradeBase> implements UpgradeSerialiser<T>
{
private final Function<ResourceLocation, T> constructor;

View File

@@ -24,7 +24,7 @@ import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraftforge.client.model.data.IModelData;
import net.minecraftforge.client.model.data.ModelData;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -35,7 +35,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
/**
* Provides custom block breaking progress for modems, so it only applies to the current part.
*
* @see BlockRenderDispatcher#renderBreakingTexture(BlockState, BlockPos, BlockAndTintGetter, PoseStack, VertexConsumer, IModelData)
* @see BlockRenderDispatcher#renderBreakingTexture(BlockState, BlockPos, BlockAndTintGetter, PoseStack, VertexConsumer, ModelData)
*/
@Mixin( BlockRenderDispatcher.class )
public class BlockRenderDispatcherMixin
@@ -53,13 +53,13 @@ public class BlockRenderDispatcherMixin
private ModelBlockRenderer modelRenderer;
@Inject(
method = "name=/^renderBreakingTexture/ desc=/IModelData;\\)V$/",
method = "name=/^renderBreakingTexture/ desc=/ModelData;\\)V$/",
at = @At( "HEAD" ),
cancellable = true,
require = 0 // This isn't critical functionality, so don't worry if we can't apply it.
)
public void renderBlockDamage(
BlockState state, BlockPos pos, BlockAndTintGetter world, PoseStack pose, VertexConsumer buffers, IModelData modelData,
BlockState state, BlockPos pos, BlockAndTintGetter world, PoseStack pose, VertexConsumer buffers, ModelData modelData,
CallbackInfo info
)
{
@@ -85,6 +85,6 @@ public class BlockRenderDispatcherMixin
BakedModel model = blockModelShaper.getBlockModel( newState );
long seed = newState.getSeed( pos );
modelRenderer.tesselateBlock( world, model, newState, pos, pose, buffers, true, random, seed, OverlayTexture.NO_OVERLAY, modelData );
modelRenderer.tesselateBlock( world, model, newState, pos, pose, buffers, true, random, seed, OverlayTexture.NO_OVERLAY, modelData, null );
}
}

View File

@@ -73,7 +73,7 @@ public final class CommonHooks
IComputer computer = ((IContainerComputer) container).getComputer();
if( computer instanceof ServerComputer )
{
((ServerComputer) computer).sendTerminalState( event.getPlayer() );
((ServerComputer) computer).sendTerminalState( event.getEntity() );
}
}
}

View File

@@ -5,11 +5,7 @@
*/
package dan200.computercraft.shared;
import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
import com.google.common.base.CaseFormat;
import com.google.common.base.Converter;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.core.apis.http.NetworkUtils;
import dan200.computercraft.core.apis.http.options.Action;
@@ -150,7 +146,7 @@ public final class Config
builder.push( "http" );
httpEnabled = builder
.comment( "Enable the \"http\" API on Computers (see \"rules\" for more fine grained control than this)." )
.comment( "Enable the \"http\" API on Computers. This also disables the \"pastebin\" and \"wget\"\nprograms, that many users rely on. It's recommended to leave this on and use the\n\"rules\" config option to impose more fine-grained control." )
.define( "enabled", ComputerCraft.httpEnabled );
httpWebsocketEnabled = builder
@@ -291,7 +287,7 @@ public final class Config
ModLoadingContext.get().registerConfig( ModConfig.Type.CLIENT, clientSpec );
}
public static void sync()
private static void syncServer()
{
// General
ComputerCraft.computerSpaceLimit = computerSpaceLimit.get();
@@ -343,27 +339,30 @@ public final class Config
ComputerCraft.pocketTermHeight = pocketTermHeight.get();
ComputerCraft.monitorWidth = monitorWidth.get();
ComputerCraft.monitorHeight = monitorHeight.get();
}
// Client
private static void syncClient()
{
ComputerCraft.monitorRenderer = monitorRenderer.get();
ComputerCraft.monitorDistance = monitorDistance.get();
}
private static void sync( ModConfig config )
{
if( !config.getModId().equals( ComputerCraft.MOD_ID ) ) return;
if( config.getType() == ModConfig.Type.SERVER ) syncServer();
if( config.getType() == ModConfig.Type.CLIENT ) syncClient();
}
@SubscribeEvent
public static void sync( ModConfigEvent.Loading event )
{
sync();
sync( event.getConfig() );
}
@SubscribeEvent
public static void sync( ModConfigEvent.Reloading event )
{
// Ensure file configs are reloaded. Forge should probably do this, so worth checking in the future.
CommentedConfig config = event.getConfig().getConfigData();
if( config instanceof CommentedFileConfig loadable ) loadable.load();
sync();
sync( event.getConfig() );
}
private static final Converter<String, String> converter = CaseFormat.LOWER_CAMEL.converterTo( CaseFormat.UPPER_UNDERSCORE );
}

View File

@@ -13,7 +13,10 @@ import dan200.computercraft.api.network.wired.IWiredElement;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.pocket.PocketUpgradeSerialiser;
import dan200.computercraft.api.turtle.TurtleUpgradeSerialiser;
import dan200.computercraft.shared.command.arguments.*;
import dan200.computercraft.shared.command.arguments.ComputerArgumentType;
import dan200.computercraft.shared.command.arguments.ComputersArgumentType;
import dan200.computercraft.shared.command.arguments.RepeatArgumentType;
import dan200.computercraft.shared.command.arguments.TrackingFieldArgumentType;
import dan200.computercraft.shared.common.ColourableRecipe;
import dan200.computercraft.shared.common.ContainerHeldItem;
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
@@ -164,7 +167,7 @@ public final class Registry
public static class ModBlockEntities
{
static final DeferredRegister<BlockEntityType<?>> TILES = DeferredRegister.create( ForgeRegistries.BLOCK_ENTITIES, ComputerCraft.MOD_ID );
static final DeferredRegister<BlockEntityType<?>> TILES = DeferredRegister.create( ForgeRegistries.BLOCK_ENTITY_TYPES, ComputerCraft.MOD_ID );
private static <T extends BlockEntity> RegistryObject<BlockEntityType<T>> ofBlock( RegistryObject<? extends Block> block, FixedPointTileEntityType.FixedPointBlockEntitySupplier<T> factory )
{
@@ -283,7 +286,7 @@ public final class Registry
public static class ModContainers
{
static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create( ForgeRegistries.CONTAINERS, ComputerCraft.MOD_ID );
static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create( ForgeRegistries.MENU_TYPES, ComputerCraft.MOD_ID );
public static final RegistryObject<MenuType<ContainerComputerBase>> COMPUTER = CONTAINERS.register( "computer",
() -> ContainerData.toType( ComputerContainerData::new, ComputerMenuWithoutInventory::new ) );
@@ -317,7 +320,7 @@ public final class Registry
@SuppressWarnings( "unchecked" )
private static <T extends ArgumentType<?>> void registerUnsafe( String name, Class<T> type, ArgumentTypeInfo<?, ?> serializer )
{
ARGUMENT_TYPES.register( name, () -> ArgumentTypeInfos.registerByClass( type, (ArgumentTypeInfo<T, ?>)serializer ) );
ARGUMENT_TYPES.register( name, () -> ArgumentTypeInfos.registerByClass( type, (ArgumentTypeInfo<T, ?>) serializer ) );
}
private static <T extends ArgumentType<?>> void register( String name, Class<T> type, ArgumentTypeInfo<T, ?> serializer )

View File

@@ -37,12 +37,12 @@ import java.util.stream.Collectors;
* @see TurtleUpgrades
* @see PocketUpgrades
*/
public class UpgradeManager<R extends UpgradeSerialiser<? extends T, R>, T extends IUpgradeBase> extends SimpleJsonResourceReloadListener
public class UpgradeManager<R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> extends SimpleJsonResourceReloadListener
{
private static final Logger LOGGER = LogManager.getLogger();
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
public static record UpgradeWrapper<R extends UpgradeSerialiser<? extends T, R>, T extends IUpgradeBase>(
public record UpgradeWrapper<R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase>(
@Nonnull String id, @Nonnull T upgrade, @Nonnull R serialiser, @Nonnull String modId
) {}
@@ -66,6 +66,12 @@ public class UpgradeManager<R extends UpgradeSerialiser<? extends T, R>, T exten
return wrapper == null ? null : wrapper.upgrade();
}
@Nullable
public UpgradeWrapper<R, T> getWrapper( @Nonnull T upgrade )
{
return currentWrappers.get( upgrade );
}
@Nullable
public String getOwner( @Nonnull T upgrade )
{

View File

@@ -56,10 +56,6 @@ public final class CommandComputerCraft
{
public static final UUID SYSTEM_UUID = new UUID( 0, 0 );
private static final int DUMP_LIST_ID = 5373952;
private static final int DUMP_SINGLE_ID = 1844510720;
private static final int TRACK_ID = 373882880;
private CommandComputerCraft()
{
}
@@ -70,7 +66,7 @@ public final class CommandComputerCraft
.then( literal( "dump" )
.requires( UserLevel.OWNER_OP )
.executes( context -> {
TableBuilder table = new TableBuilder( DUMP_LIST_ID, "Computer", "On", "Position" );
TableBuilder table = new TableBuilder( "DumpAll", "Computer", "On", "Position" );
CommandSourceStack source = context.getSource();
List<ServerComputer> computers = new ArrayList<>( ComputerCraft.serverComputerRegistry.getComputers() );
@@ -115,7 +111,7 @@ public final class CommandComputerCraft
.executes( context -> {
ServerComputer computer = getComputerArgument( context, "computer" );
TableBuilder table = new TableBuilder( DUMP_SINGLE_ID );
TableBuilder table = new TableBuilder( "Dump" );
table.row( header( "Instance" ), text( Integer.toString( computer.getInstanceID() ) ) );
table.row( header( "Id" ), text( Integer.toString( computer.getID() ) ) );
table.row( header( "Label" ), text( computer.getLabel() ) );
@@ -392,7 +388,7 @@ public final class CommandComputerCraft
Component[] headers = new Component[1 + fields.size()];
headers[0] = translate( "commands.computercraft.track.dump.computer" );
for( int i = 0; i < fields.size(); i++ ) headers[i + 1] = translate( fields.get( i ).translationKey() );
TableBuilder table = new TableBuilder( TRACK_ID, headers );
TableBuilder table = new TableBuilder( "Metrics", headers );
for( ComputerTracker entry : timings )
{

View File

@@ -10,9 +10,9 @@ import com.mojang.brigadier.Message;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.Objects;
@@ -27,7 +27,7 @@ public class ArgumentUtils
{
JsonObject object = new JsonObject();
object.addProperty( "type", "argument" );
object.addProperty( "parser", Registry.COMMAND_ARGUMENT_TYPE.getKey( template.type() ).toString() );
object.addProperty( "parser", ForgeRegistries.COMMAND_ARGUMENT_TYPES.getKey( template.type() ).toString() );
var properties = new JsonObject();
serializeToJson( properties, template.type(), template );
@@ -50,13 +50,13 @@ public class ArgumentUtils
@SuppressWarnings( "unchecked" )
private static <A extends ArgumentType<?>, T extends ArgumentTypeInfo.Template<A>> void serializeToNetwork( FriendlyByteBuf buffer, ArgumentTypeInfo<A, T> type, ArgumentTypeInfo.Template<A> template )
{
buffer.writeVarInt( Registry.COMMAND_ARGUMENT_TYPE.getId( type ) );
buffer.writeRegistryIdUnsafe( ForgeRegistries.COMMAND_ARGUMENT_TYPES, type );
type.serializeToNetwork( (T) template, buffer );
}
public static ArgumentTypeInfo.Template<?> deserialize( FriendlyByteBuf buffer )
{
var type = Registry.COMMAND_ARGUMENT_TYPE.byId( buffer.readVarInt() );
var type = buffer.readRegistryIdUnsafe( ForgeRegistries.COMMAND_ARGUMENT_TYPES );
Objects.requireNonNull( type, "Unknown argument type" );
return type.deserializeFromNetwork( buffer );
}

View File

@@ -145,6 +145,7 @@ public final class RepeatArgumentType<T, U> implements ArgumentType<List<T>>
return new RepeatArgumentType.Template( this, child, isList, new SimpleCommandExceptionType( message ) );
}
@Nonnull
@Override
public RepeatArgumentType.Template unpack( RepeatArgumentType<?, ?> argumentType )
{
@@ -164,6 +165,7 @@ public final class RepeatArgumentType<T, U> implements ArgumentType<List<T>>
Info info, ArgumentTypeInfo.Template<?> child, boolean flatten, SimpleCommandExceptionType some
) implements ArgumentTypeInfo.Template<RepeatArgumentType<?, ?>>
{
@Nonnull
@Override
@SuppressWarnings( { "unchecked", "rawtypes" } )
public RepeatArgumentType<?, ?> instantiate( @NotNull CommandBuildContext commandBuildContext )
@@ -172,6 +174,7 @@ public final class RepeatArgumentType<T, U> implements ArgumentType<List<T>>
return flatten ? RepeatArgumentType.someFlat( (ArgumentType) child, some() ) : RepeatArgumentType.some( child, some() );
}
@Nonnull
@Override
public ArgumentTypeInfo<RepeatArgumentType<?, ?>, ?> type()
{

View File

@@ -42,7 +42,7 @@ public class ServerTableFormatter implements TableFormatter
}
@Override
public void writeLine( int id, Component component )
public void writeLine( String label, Component component )
{
source.sendSuccess( component, false );
}

View File

@@ -19,30 +19,27 @@ import java.util.List;
public class TableBuilder
{
private final int id;
private final String id;
private int columns = -1;
private final Component[] headers;
private final ArrayList<Component[]> rows = new ArrayList<>();
private int additional;
public TableBuilder( int id, @Nonnull Component... headers )
public TableBuilder( @Nonnull String id, @Nonnull Component... headers )
{
if( id < 0 ) throw new IllegalArgumentException( "ID must be positive" );
this.id = id;
this.headers = headers;
columns = headers.length;
}
public TableBuilder( int id )
public TableBuilder( @Nonnull String id )
{
if( id < 0 ) throw new IllegalArgumentException( "ID must be positive" );
this.id = id;
headers = null;
}
public TableBuilder( int id, @Nonnull String... headers )
public TableBuilder( @Nonnull String id, @Nonnull String... headers )
{
if( id < 0 ) throw new IllegalArgumentException( "ID must be positive" );
this.id = id;
this.headers = new Component[headers.length];
columns = headers.length;
@@ -65,7 +62,7 @@ public class TableBuilder
*
* @return This table's type.
*/
public int getId()
public String getId()
{
return id;
}

View File

@@ -39,13 +39,13 @@ public interface TableFormatter
int getWidth( Component component );
void writeLine( int id, Component component );
void writeLine( String label, Component component );
default int display( TableBuilder table )
default void display( TableBuilder table )
{
if( table.getColumns() <= 0 ) return 0;
if( table.getColumns() <= 0 ) return;
int rowId = table.getId();
String id = table.getId();
int columns = table.getColumns();
int[] maxWidths = new int[columns];
@@ -86,13 +86,13 @@ public interface TableFormatter
}
line.append( headers[columns - 1] );
writeLine( rowId++, line );
writeLine( id, line );
// Write a separator line. We round the width up rather than down to make
// it a tad prettier.
int rowCharWidth = getWidth( HEADER );
int rowWidth = totalWidth / rowCharWidth + (totalWidth % rowCharWidth == 0 ? 0 : 1);
writeLine( rowId++, coloured( StringUtils.repeat( HEADER.getString(), rowWidth ), ChatFormatting.GRAY ) );
writeLine( id, coloured( StringUtils.repeat( HEADER.getString(), rowWidth ), ChatFormatting.GRAY ) );
}
for( Component[] row : table.getRows() )
@@ -106,14 +106,12 @@ public interface TableFormatter
line.append( SEPARATOR );
}
line.append( row[columns - 1] );
writeLine( rowId++, line );
writeLine( id, line );
}
if( table.getAdditional() > 0 )
{
writeLine( rowId++, coloured( translate( "commands.computercraft.generic.additional_rows", table.getAdditional() ), ChatFormatting.AQUA ) );
writeLine( id, coloured( translate( "commands.computercraft.generic.additional_rows", table.getAdditional() ), ChatFormatting.AQUA ) );
}
return rowId - table.getId();
}
}

View File

@@ -63,7 +63,7 @@ public class CommandAPI implements ILuaAPI
try
{
receiver.clearOutput();
int result = commandManager.performCommand( computer.getSource(), command );
int result = commandManager.performPrefixedCommand( computer.getSource(), command );
return new Object[] { result > 0, receiver.copyOutput(), result };
}
catch( Throwable t )

View File

@@ -20,21 +20,22 @@ import dan200.computercraft.shared.turtle.items.ITurtleItem;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter;
import mezz.jei.api.recipe.IRecipeLookup;
import mezz.jei.api.recipe.IRecipeManager;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.registration.IAdvancedRegistration;
import mezz.jei.api.registration.ISubtypeRegistration;
import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.CraftingRecipe;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static dan200.computercraft.shared.integration.jei.RecipeResolver.MAIN_FAMILIES;
@@ -52,13 +53,13 @@ public class JEIComputerCraft implements IModPlugin
@Override
public void registerItemSubtypes( ISubtypeRegistration subtypeRegistry )
{
subtypeRegistry.registerSubtypeInterpreter( Registry.ModItems.TURTLE_NORMAL.get(), turtleSubtype );
subtypeRegistry.registerSubtypeInterpreter( Registry.ModItems.TURTLE_ADVANCED.get(), turtleSubtype );
subtypeRegistry.registerSubtypeInterpreter( VanillaTypes.ITEM_STACK, Registry.ModItems.TURTLE_NORMAL.get(), turtleSubtype );
subtypeRegistry.registerSubtypeInterpreter( VanillaTypes.ITEM_STACK, Registry.ModItems.TURTLE_ADVANCED.get(), turtleSubtype );
subtypeRegistry.registerSubtypeInterpreter( Registry.ModItems.POCKET_COMPUTER_NORMAL.get(), pocketSubtype );
subtypeRegistry.registerSubtypeInterpreter( Registry.ModItems.POCKET_COMPUTER_ADVANCED.get(), pocketSubtype );
subtypeRegistry.registerSubtypeInterpreter( VanillaTypes.ITEM_STACK, Registry.ModItems.POCKET_COMPUTER_NORMAL.get(), pocketSubtype );
subtypeRegistry.registerSubtypeInterpreter( VanillaTypes.ITEM_STACK, Registry.ModItems.POCKET_COMPUTER_ADVANCED.get(), pocketSubtype );
subtypeRegistry.registerSubtypeInterpreter( Registry.ModItems.DISK.get(), diskSubtype );
subtypeRegistry.registerSubtypeInterpreter( VanillaTypes.ITEM_STACK, Registry.ModItems.DISK.get(), diskSubtype );
}
@Override
@@ -89,27 +90,22 @@ public class JEIComputerCraft implements IModPlugin
if( !upgradeItems.isEmpty() )
{
runtime.getIngredientManager().addIngredientsAtRuntime( VanillaTypes.ITEM, upgradeItems );
runtime.getIngredientManager().addIngredientsAtRuntime( VanillaTypes.ITEM_STACK, upgradeItems );
}
// Hide all upgrade recipes
IRecipeCategory<?> category = registry.getRecipeCategory( VanillaRecipeCategoryUid.CRAFTING, false );
if( category != null )
{
for( Object wrapper : registry.getRecipes( category, List.of(), false ) )
{
if( !(wrapper instanceof Recipe) ) continue;
ResourceLocation id = ((Recipe<?>) wrapper).getId();
if( !id.getNamespace().equals( ComputerCraft.MOD_ID ) ) continue;
IRecipeLookup<CraftingRecipe> category = registry.createRecipeLookup( RecipeTypes.CRAFTING );
category.get().forEach( wrapper -> {
ResourceLocation id = wrapper.getId();
if( !id.getNamespace().equals( ComputerCraft.MOD_ID ) ) return;
String path = id.getPath();
if( path.startsWith( "turtle_normal/" ) || path.startsWith( "turtle_advanced/" )
|| path.startsWith( "pocket_normal/" ) || path.startsWith( "pocket_advanced/" ) )
{
registry.hideRecipe( wrapper, VanillaRecipeCategoryUid.CRAFTING );
}
String path = id.getPath();
if( path.startsWith( "turtle_normal/" ) || path.startsWith( "turtle_advanced/" )
|| path.startsWith( "pocket_normal/" ) || path.startsWith( "pocket_advanced/" ) )
{
registry.hideRecipes( RecipeTypes.CRAFTING, Collections.singleton( wrapper ) );
}
}
} );
}
/**

View File

@@ -6,10 +6,10 @@
package dan200.computercraft.shared.integration.jei;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.upgrades.IUpgradeBase;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.api.turtle.ITurtleUpgrade;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.upgrades.IUpgradeBase;
import dan200.computercraft.shared.PocketUpgrades;
import dan200.computercraft.shared.TurtleUpgrades;
import dan200.computercraft.shared.computer.core.ComputerFamily;
@@ -17,8 +17,9 @@ import dan200.computercraft.shared.pocket.items.ItemPocketComputer;
import dan200.computercraft.shared.pocket.items.PocketComputerItemFactory;
import dan200.computercraft.shared.turtle.items.ITurtleItem;
import dan200.computercraft.shared.turtle.items.TurtleItemFactory;
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.advanced.IRecipeManagerPlugin;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.core.NonNullList;
@@ -95,7 +96,7 @@ class RecipeResolver implements IRecipeManagerPlugin
@Nonnull
@Override
public <V> List<ResourceLocation> getRecipeCategoryUids( @Nonnull IFocus<V> focus )
public <V> List<RecipeType<?>> getRecipeTypes( @Nonnull IFocus<V> focus )
{
V value = focus.getTypedValue().getIngredient();
if( !(value instanceof ItemStack stack) ) return Collections.emptyList();
@@ -105,11 +106,11 @@ class RecipeResolver implements IRecipeManagerPlugin
case INPUT:
return stack.getItem() instanceof ITurtleItem || stack.getItem() instanceof ItemPocketComputer ||
hasUpgrade( stack )
? Collections.singletonList( VanillaRecipeCategoryUid.CRAFTING )
? Collections.singletonList( RecipeTypes.CRAFTING )
: Collections.emptyList();
case OUTPUT:
return stack.getItem() instanceof ITurtleItem || stack.getItem() instanceof ItemPocketComputer
? Collections.singletonList( VanillaRecipeCategoryUid.CRAFTING )
? Collections.singletonList( RecipeTypes.CRAFTING )
: Collections.emptyList();
default:
return Collections.emptyList();
@@ -120,7 +121,7 @@ class RecipeResolver implements IRecipeManagerPlugin
@Override
public <T, V> List<T> getRecipes( @Nonnull IRecipeCategory<T> recipeCategory, @Nonnull IFocus<V> focus )
{
if( !(focus.getTypedValue().getIngredient() instanceof ItemStack stack) || !recipeCategory.getUid().equals( VanillaRecipeCategoryUid.CRAFTING ) )
if( !(focus.getTypedValue().getIngredient() instanceof ItemStack stack) || recipeCategory.getRecipeType() != RecipeTypes.CRAFTING )
{
return Collections.emptyList();
}

View File

@@ -9,6 +9,8 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.shared.network.client.*;
import dan200.computercraft.shared.network.server.*;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
@@ -26,7 +28,8 @@ import java.util.function.Function;
public final class NetworkHandler
{
public static SimpleChannel network;
private static SimpleChannel network;
private static final IntSet usedIds = new IntOpenHashSet();
private NetworkHandler()
{
@@ -61,7 +64,7 @@ public final class NetworkHandler
registerMainThread( 18, NetworkDirection.PLAY_TO_CLIENT, SpeakerPlayClientMessage.class, SpeakerPlayClientMessage::new );
registerMainThread( 19, NetworkDirection.PLAY_TO_CLIENT, SpeakerStopClientMessage.class, SpeakerStopClientMessage::new );
registerMainThread( 20, NetworkDirection.PLAY_TO_CLIENT, UploadResultMessage.class, UploadResultMessage::new );
registerMainThread( 20, NetworkDirection.PLAY_TO_CLIENT, UpgradesLoadedMessage.class, UpgradesLoadedMessage::new );
registerMainThread( 21, NetworkDirection.PLAY_TO_CLIENT, UpgradesLoadedMessage.class, UpgradesLoadedMessage::new );
}
public static void sendToPlayer( Player player, NetworkMessage packet )
@@ -101,10 +104,11 @@ public final class NetworkHandler
*/
private static <T extends NetworkMessage> void registerMainThread( int id, NetworkDirection direction, Class<T> type, Function<FriendlyByteBuf, T> decoder )
{
if( !usedIds.add( id ) ) throw new IllegalStateException( "Duplicate message kind for for id " + id );
network.messageBuilder( type, id, direction )
.encoder( NetworkMessage::toBytes )
.decoder( decoder )
.consumer( ( packet, contextSup ) -> {
.consumerMainThread( ( packet, contextSup ) -> {
NetworkEvent.Context context = contextSup.get();
context.enqueueWork( () -> packet.handle( context ) );
context.setPacketHandled( true );

View File

@@ -16,6 +16,7 @@ import javax.annotation.Nonnull;
public class ChatTableClientMessage implements NetworkMessage
{
private static final int MAX_LEN = 16;
private final TableBuilder table;
public ChatTableClientMessage( TableBuilder table )
@@ -26,7 +27,7 @@ public class ChatTableClientMessage implements NetworkMessage
public ChatTableClientMessage( @Nonnull FriendlyByteBuf buf )
{
int id = buf.readVarInt();
String id = buf.readUtf( MAX_LEN );
int columns = buf.readVarInt();
TableBuilder table;
if( buf.readBoolean() )
@@ -55,7 +56,7 @@ public class ChatTableClientMessage implements NetworkMessage
@Override
public void toBytes( @Nonnull FriendlyByteBuf buf )
{
buf.writeVarInt( table.getId() );
buf.writeUtf( table.getId(), MAX_LEN );
buf.writeVarInt( table.getColumns() );
buf.writeBoolean( table.getHeaders() != null );
if( table.getHeaders() != null )

View File

@@ -46,7 +46,7 @@ public class UpgradesLoadedMessage implements NetworkMessage
pocketUpgrades = fromBytes( buf, RegistryManager.ACTIVE.getRegistry( PocketUpgradeSerialiser.REGISTRY_ID ) );
}
private <R extends UpgradeSerialiser<? extends T, R>, T extends IUpgradeBase> Map<String, UpgradeManager.UpgradeWrapper<R, T>> fromBytes(
private <R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> Map<String, UpgradeManager.UpgradeWrapper<R, T>> fromBytes(
@Nonnull FriendlyByteBuf buf, @Nonnull IForgeRegistry<R> registry
)
{
@@ -76,7 +76,7 @@ public class UpgradesLoadedMessage implements NetworkMessage
toBytes( buf, PocketUpgradeSerialiser.registry(), pocketUpgrades );
}
private <R extends UpgradeSerialiser<? extends T, R>, T extends IUpgradeBase> void toBytes(
private <R extends UpgradeSerialiser<? extends T>, T extends IUpgradeBase> void toBytes(
@Nonnull FriendlyByteBuf buf, IForgeRegistry<R> registry, Map<String, UpgradeManager.UpgradeWrapper<R, T>> upgrades
)
{
@@ -87,7 +87,7 @@ public class UpgradesLoadedMessage implements NetworkMessage
var serialiser = entry.getValue().serialiser();
@SuppressWarnings( "unchecked" )
var unwrapedSerialiser = (UpgradeSerialiser<T, R>) serialiser;
var unwrapedSerialiser = (UpgradeSerialiser<T>) serialiser;
buf.writeResourceLocation( Objects.requireNonNull( registry.getKey( serialiser ), "Serialiser is not registered!" ) );
unwrapedSerialiser.toNetwork( buf, entry.getValue().upgrade() );

View File

@@ -30,7 +30,7 @@ public interface ContainerData
default void open( Player player, MenuProvider owner )
{
NetworkHooks.openGui( (ServerPlayer) player, owner, this::toBytes );
NetworkHooks.openScreen( (ServerPlayer) player, owner, this::toBytes );
}
static <C extends AbstractContainerMenu, T extends ContainerData> MenuType<C> toType( Function<FriendlyByteBuf, T> reader, Factory<C, T> factory )

View File

@@ -58,7 +58,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
}
Component customName;
private LockCode lockCode;
private LockCode lockCode = LockCode.NO_LOCK;
private final Map<IComputerAccess, MountInfo> computers = new HashMap<>();
@@ -120,7 +120,7 @@ public final class TileDiskDrive extends TileGeneric implements DefaultInventory
// Open the GUI
if( !getLevel().isClientSide && isUsable( player ) )
{
NetworkHooks.openGui( (ServerPlayer) player, this );
NetworkHooks.openScreen( (ServerPlayer) player, this );
}
return InteractionResult.SUCCESS;
}

View File

@@ -30,7 +30,7 @@ class GenericPeripheral implements IDynamicPeripheral
GenericPeripheral( BlockEntity tile, String name, Set<String> additionalTypes, List<SaturatedMethod> methods )
{
ResourceLocation type = ForgeRegistries.BLOCK_ENTITIES.getKey( tile.getType() );
ResourceLocation type = ForgeRegistries.BLOCK_ENTITY_TYPES.getKey( tile.getType() );
this.tile = tile;
this.type = name != null ? name : (type != null ? type.toString() : "unknown");
this.additionalTypes = additionalTypes;

View File

@@ -67,6 +67,7 @@ public class ItemData
}
data.put( "tags", DataHelpers.getTags( stack.getTags() ) );
data.put( "itemGroups", getItemGroups( stack ) );
CompoundTag tag = stack.getTag();
if( tag != null && tag.contains( "display", Tag.TAG_COMPOUND ) )
@@ -116,6 +117,30 @@ public class ItemData
}
}
/**
* Retrieve all item groups an item stack pertains to.
*
* @param stack Stack to analyse
* @return A filled list that contains pairs of item group IDs and their display names.
*/
@Nonnull
private static List<Map<String, Object>> getItemGroups( @Nonnull ItemStack stack )
{
List<Map<String, Object>> groups = new ArrayList<>( 1 );
for( var group : stack.getItem().getCreativeTabs() )
{
if( group == null ) continue;
Map<String, Object> groupData = new HashMap<>( 2 );
groupData.put( "id", group.langId );
groupData.put( "displayName", group.getDisplayName().getString() );
groups.add( groupData );
}
return groups;
}
/**
* Retrieve all visible enchantments from given stack. Try to follow all tooltip rules : order and visibility.
*

View File

@@ -109,7 +109,9 @@ public class InventoryMethods implements GenericPeripheral
*
* The returned information contains the same information as each item in
* {@link #list}, as well as additional details like the display name
* (`displayName`) and item durability (`damage`, `maxDamage`, `durability`).
* (`displayName`), item groups (`itemGroups`), which are the creative tabs
* an item will appear under, and item and item durability (`damage`,
* `maxDamage`, `durability`).
*
* Some items include more information (such as enchantments) - it is
* recommended to print it out using @{textutils.serialize} or in the Lua
@@ -129,6 +131,11 @@ public class InventoryMethods implements GenericPeripheral
*
* print(("%s (%s)"):format(item.displayName, item.name))
* print(("Count: %d/%d"):format(item.count, item.maxCount))
*
* for _, group in pairs(item.itemGroups) do
* print(("Group: %s"):format(group.displayName))
* end
*
* if item.damage then
* print(("Damage: %d/%d"):format(item.damage, item.maxDamage))
* end
@@ -168,7 +175,7 @@ public class InventoryMethods implements GenericPeripheral
public static int getItemLimit( IItemHandler inventory, int slot ) throws LuaException
{
assertBetween( slot, 1, inventory.getSlots(), "Slot out of range (%s)" );
return inventory.getSlotLimit( slot );
return inventory.getSlotLimit( slot - 1 );
}
/**

View File

@@ -11,13 +11,11 @@ import dan200.computercraft.shared.network.client.MonitorClientMessage;
import dan200.computercraft.shared.network.client.TerminalState;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.world.ChunkWatchEvent;
import net.minecraftforge.event.level.ChunkWatchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@@ -28,7 +26,6 @@ import java.util.Queue;
public final class MonitorWatcher
{
private static final Queue<TileMonitor> watching = new ArrayDeque<>();
private static final Queue<PlayerUpdate> playerUpdates = new ArrayDeque<>();
private MonitorWatcher()
{
@@ -46,47 +43,28 @@ public final class MonitorWatcher
@SubscribeEvent
public static void onWatch( ChunkWatchEvent.Watch event )
{
// Get the current chunk if it has been loaded. This is safe as, if the chunk hasn't been loaded yet, then the
// monitor will have no contents, and so we won't need to send an update anyway.
ChunkPos chunkPos = event.getPos();
LevelChunk chunk = event.getWorld().getChunkSource().getChunkNow( chunkPos.x, chunkPos.z );
if( chunk == null ) return;
for( BlockEntity te : chunk.getBlockEntities().values() )
// Find all origin monitors who are not already on the queue and send the
// monitor data to the player.
for( BlockEntity te : event.getChunk().getBlockEntities().values() )
{
// Find all origin monitors who are not already on the queue.
if( !(te instanceof TileMonitor monitor) ) continue;
ServerMonitor serverMonitor = getMonitor( monitor );
if( serverMonitor == null || monitor.enqueued ) continue;
// The chunk hasn't been sent to the client yet, so we can't send an update. Do it on tick end.
playerUpdates.add( new PlayerUpdate( event.getPlayer(), monitor ) );
TerminalState state = monitor.cached;
if( state == null ) state = monitor.cached = serverMonitor.write();
NetworkHandler.sendToPlayer( event.getPlayer(), new MonitorClientMessage( monitor.getBlockPos(), state ) );
}
}
@SubscribeEvent
public static void onTick( TickEvent.ServerTickEvent event )
{
// Find all enqueued monitors and send their contents to all nearby players.
if( event.phase != TickEvent.Phase.END ) return;
PlayerUpdate playerUpdate;
while( (playerUpdate = playerUpdates.poll()) != null )
{
TileMonitor tile = playerUpdate.monitor;
if( tile.enqueued || tile.isRemoved() ) continue;
ServerMonitor monitor = getMonitor( tile );
if( monitor == null ) continue;
// Some basic sanity checks to the player. It's possible they're no longer within range, but that's harder
// to track efficiently.
ServerPlayer player = playerUpdate.player;
if( !player.isAlive() || player.getLevel() != tile.getLevel() ) continue;
NetworkHandler.sendToPlayer( playerUpdate.player, new MonitorClientMessage( tile.getBlockPos(), getState( tile, monitor ) ) );
}
long limit = ComputerCraft.monitorBandwidth;
boolean obeyLimit = limit > 0;
@@ -125,16 +103,4 @@ public final class MonitorWatcher
if( state == null ) state = tile.cached = monitor.write();
return state;
}
private static final class PlayerUpdate
{
final ServerPlayer player;
final TileMonitor monitor;
private PlayerUpdate( ServerPlayer player, TileMonitor monitor )
{
this.player = player;
this.monitor = monitor;
}
}
}

View File

@@ -55,7 +55,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
private static final int[] SIDE_SLOTS = new int[] { 0 };
Component customName;
private LockCode lockCode;
private LockCode lockCode = LockCode.NO_LOCK;
private final NonNullList<ItemStack> inventory = NonNullList.withSize( SLOTS, ItemStack.EMPTY );
private final SidedCaps<IItemHandler> itemHandlerCaps =
@@ -99,7 +99,7 @@ public final class TilePrinter extends TileGeneric implements DefaultSidedInvent
if( !getLevel().isClientSide && isUsable( player ) )
{
NetworkHooks.openGui( (ServerPlayer) player, this );
NetworkHooks.openScreen( (ServerPlayer) player, this );
}
return InteractionResult.SUCCESS;
}

View File

@@ -37,7 +37,7 @@ public final class FurnaceRefuelHandler implements TurtleRefuelEvent.Handler
ItemStack stack = turtle.getItemHandler().extractItem( slot, limit, false );
int fuelToGive = fuelPerItem * stack.getCount();
// Store the replacement item in the inventory
ItemStack replacementStack = stack.getItem().getContainerItem( stack );
ItemStack replacementStack = ForgeHooks.getCraftingRemainingItem( stack );
if( !replacementStack.isEmpty() )
{
ItemStack remainder = InventoryUtil.storeItems( replacementStack, turtle.getItemHandler(), turtle.getSelectedSlot() );

View File

@@ -26,7 +26,7 @@ import java.util.Optional;
* an internal inventory of 16 slots, allowing them to store blocks they have broken or would like to place.
*
* ## Movement
* Turtles are capable of moving throug the world. As turtles are blocks themselves, they are confined to Minecraft's
* Turtles are capable of moving through the world. As turtles are blocks themselves, they are confined to Minecraft's
* grid, moving a single block at a time.
*
* {@literal @}{turtle.forward} and @{turtle.back} move the turtle in the direction it is facing, while @{turtle.up} and

View File

@@ -5,25 +5,18 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
import dan200.computercraft.api.turtle.ITurtleAccess;
import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeType;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nonnull;
public class TurtleCraftingTable extends AbstractTurtleUpgrade
{
private static final ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_left", "inventory" );
private static final ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_crafting_table_right", "inventory" );
public TurtleCraftingTable( ResourceLocation id, ItemStack stack )
{
super( id, TurtleUpgradeType.PERIPHERAL, "upgrade.minecraft.crafting_table.adjective", stack );
@@ -34,12 +27,4 @@ public class TurtleCraftingTable extends AbstractTurtleUpgrade
{
return new CraftingTablePeripheral( turtle );
}
@Nonnull
@Override
@OnlyIn( Dist.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{
return TransformedModel.of( side == TurtleSide.LEFT ? leftModel : rightModel );
}
}

View File

@@ -5,21 +5,16 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.shared.peripheral.modem.ModemState;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessModemPeripheral;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nonnull;
@@ -63,30 +58,10 @@ public class TurtleModem extends AbstractTurtleUpgrade
private final boolean advanced;
private final ModelResourceLocation leftOffModel;
private final ModelResourceLocation rightOffModel;
private final ModelResourceLocation leftOnModel;
private final ModelResourceLocation rightOnModel;
public TurtleModem( ResourceLocation id, ItemStack stack, boolean advanced )
{
super( id, TurtleUpgradeType.PERIPHERAL, advanced ? WirelessModemPeripheral.ADVANCED_ADJECTIVE : WirelessModemPeripheral.NORMAL_ADJECTIVE, stack );
this.advanced = advanced;
if( advanced )
{
leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_left", "inventory" );
rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_off_right", "inventory" );
leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_left", "inventory" );
rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_advanced_on_right", "inventory" );
}
else
{
leftOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_left", "inventory" );
rightOffModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_off_right", "inventory" );
leftOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_left", "inventory" );
rightOnModel = new ModelResourceLocation( "computercraft:turtle_modem_normal_on_right", "inventory" );
}
}
@Override
@@ -102,23 +77,6 @@ public class TurtleModem extends AbstractTurtleUpgrade
return TurtleCommandResult.failure();
}
@Nonnull
@Override
@OnlyIn( Dist.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{
boolean active = false;
if( turtle != null )
{
CompoundTag turtleNBT = turtle.getUpgradeNBTData( side );
active = turtleNBT.contains( "active" ) && turtleNBT.getBoolean( "active" );
}
return side == TurtleSide.LEFT
? TransformedModel.of( active ? leftOnModel : leftOffModel )
: TransformedModel.of( active ? rightOnModel : rightOffModel );
}
@Override
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side )
{

View File

@@ -5,7 +5,6 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.api.turtle.AbstractTurtleUpgrade;
import dan200.computercraft.api.turtle.ITurtleAccess;
@@ -13,20 +12,14 @@ import dan200.computercraft.api.turtle.TurtleSide;
import dan200.computercraft.api.turtle.TurtleUpgradeType;
import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition;
import dan200.computercraft.shared.peripheral.speaker.UpgradeSpeakerPeripheral;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nonnull;
public class TurtleSpeaker extends AbstractTurtleUpgrade
{
private static final ModelResourceLocation leftModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_left", "inventory" );
private static final ModelResourceLocation rightModel = new ModelResourceLocation( "computercraft:turtle_speaker_upgrade_right", "inventory" );
private static class Peripheral extends UpgradeSpeakerPeripheral
{
final ITurtleAccess turtle;
@@ -61,14 +54,6 @@ public class TurtleSpeaker extends AbstractTurtleUpgrade
return new TurtleSpeaker.Peripheral( turtle );
}
@Nonnull
@Override
@OnlyIn( Dist.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{
return TransformedModel.of( side == TurtleSide.LEFT ? leftModel : rightModel );
}
@Override
public void update( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide turtleSide )
{

View File

@@ -5,11 +5,8 @@
*/
package dan200.computercraft.shared.turtle.upgrades;
import com.mojang.math.Matrix4f;
import com.mojang.math.Transformation;
import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftTags;
import dan200.computercraft.api.client.TransformedModel;
import dan200.computercraft.api.turtle.*;
import dan200.computercraft.shared.TurtlePermissions;
import dan200.computercraft.shared.turtle.core.TurtleBrain;
@@ -37,12 +34,10 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ToolActions;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.level.BlockEvent;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nonnull;
@@ -88,14 +83,6 @@ public class TurtleTool extends AbstractTurtleUpgrade
return true;
}
@Nonnull
@Override
@OnlyIn( Dist.CLIENT )
public TransformedModel getModel( ITurtleAccess turtle, @Nonnull TurtleSide side )
{
return TransformedModel.of( getCraftingItem(), side == TurtleSide.LEFT ? Transforms.leftTransform : Transforms.rightTransform );
}
@Nonnull
@Override
public TurtleCommandResult useTool( @Nonnull ITurtleAccess turtle, @Nonnull TurtleSide side, @Nonnull TurtleVerb verb, @Nonnull Direction direction )
@@ -276,22 +263,6 @@ public class TurtleTool extends AbstractTurtleUpgrade
DropConsumer.clearAndDrop( turtle.getLevel(), turtle.getPosition(), direction );
}
private static class Transforms
{
static final Transformation leftTransform = getMatrixFor( -0.40625f );
static final Transformation rightTransform = getMatrixFor( 0.40625f );
private static Transformation getMatrixFor( float offset )
{
return new Transformation( new Matrix4f( new float[] {
0.0f, 0.0f, -1.0f, 1.0f + offset,
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f,
} ) );
}
}
protected boolean isTriviallyBreakable( BlockGetter reader, BlockPos pos, BlockState state )
{
return state.is( ComputerCraftTags.Blocks.TURTLE_ALWAYS_BREAKABLE )

View File

@@ -13,7 +13,7 @@ import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@@ -80,10 +80,10 @@ public final class DropConsumer
}
@SubscribeEvent( priority = EventPriority.HIGHEST )
public static void onEntitySpawn( EntityJoinWorldEvent event )
public static void onEntitySpawn( EntityJoinLevelEvent event )
{
// Capture any nearby item spawns
if( dropWorld == event.getWorld() && event.getEntity() instanceof ItemEntity
if( dropWorld == event.getLevel() && event.getEntity() instanceof ItemEntity
&& dropBounds.contains( event.getEntity().position() ) )
{
handleDrops( ((ItemEntity) event.getEntity()).getItem() );

View File

@@ -3,8 +3,8 @@ public net.minecraft.client.renderer.ItemInHandRenderer m_109312_(F)F # calculat
public net.minecraft.client.renderer.ItemInHandRenderer m_109361_(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;ILnet/minecraft/world/entity/HumanoidArm;)V # renderMapHand
public net.minecraft.client.renderer.ItemInHandRenderer m_109346_(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;IFFLnet/minecraft/world/entity/HumanoidArm;)V # renderPlayerArm
# ClientTableFormatter
public net.minecraft.client.gui.components.ChatComponent m_93787_(Lnet/minecraft/network/chat/Component;I)V # addMessage
public net.minecraft.client.gui.components.ChatComponent m_93803_(I)V # removeById
public net.minecraft.client.gui.components.ChatComponent f_93760_ # allMessages
public net.minecraft.client.gui.components.ChatComponent m_241120_()V # refreshTrimmedMessage
# NoTermComputerScreen
public net.minecraft.client.Minecraft f_91080_ # screen
@@ -18,4 +18,7 @@ protected com.mojang.blaze3d.vertex.VertexBuffer f_166861_ # indexType
protected com.mojang.blaze3d.vertex.VertexBuffer f_166863_ # indexCount
protected com.mojang.blaze3d.vertex.VertexBuffer f_166864_ # mode
protected com.mojang.blaze3d.vertex.VertexBuffer f_166865_ # sequentialIndices
protected com.mojang.blaze3d.vertex.VertexBuffer f_85917_ # format
protected com.mojang.blaze3d.vertex.VertexBuffer f_85917_ # format
# ItemData
public net.minecraft.world.item.CreativeModeTab f_40763_ # langId

View File

@@ -1,5 +1,5 @@
modLoader="javafml"
loaderVersion="[41,42)"
loaderVersion="[42,43)"
issueTrackerURL="https://github.com/cc-tweaked/CC-Tweaked/issues"
logoFile="pack.png"
@@ -21,6 +21,6 @@ CC: Tweaked is a fork of ComputerCraft, adding programmable computers, turtles a
[[dependencies.computercraft]]
modId="forge"
mandatory=true
versionRange="[41.0.6,42)"
versionRange="[42.0.0,43)"
ordering="NONE"
side="BOTH"

View File

@@ -0,0 +1,135 @@
{
"itemGroup.computercraft": "ComputerCraft",
"block.computercraft.computer_normal": "Datamaskin",
"block.computercraft.computer_advanced": "Avansert Datamaskin",
"block.computercraft.computer_command": "Kommando Datamaskin",
"block.computercraft.disk_drive": "Diskstasjon",
"block.computercraft.printer": "Printer",
"block.computercraft.speaker": "Høytaler",
"block.computercraft.monitor_normal": "Skjerm",
"block.computercraft.monitor_advanced": "Avansert Skjerm",
"block.computercraft.wireless_modem_normal": "Trådløst Modem",
"block.computercraft.wireless_modem_advanced": "Ender Modem",
"block.computercraft.wired_modem": "Kablet Modem",
"block.computercraft.cable": "Nettverks kabel",
"block.computercraft.wired_modem_full": "Kablet Modem",
"block.computercraft.turtle_normal": "Skilpadde",
"block.computercraft.turtle_normal.upgraded": "%s Skilpadde",
"block.computercraft.turtle_normal.upgraded_twice": "%s %s Skilpadde",
"block.computercraft.turtle_advanced": "Avansert Skilpadde",
"block.computercraft.turtle_advanced.upgraded": "Avansert %s Skilpadde",
"block.computercraft.turtle_advanced.upgraded_twice": "Avansert %s %s Skilpadde",
"item.computercraft.disk": "Floppy Disk",
"item.computercraft.treasure_disk": "Floppy Disk",
"item.computercraft.printed_page": "Printet Side",
"item.computercraft.printed_pages": "Printet Sider",
"item.computercraft.printed_book": "Printet Bok",
"item.computercraft.pocket_computer_normal": "Lomme datamaskin",
"item.computercraft.pocket_computer_normal.upgraded": "%s Lomme Datamaskin",
"item.computercraft.pocket_computer_advanced": "Avansert Lomme Datamaskin",
"item.computercraft.pocket_computer_advanced.upgraded": "Avansert %s Lomme Datamaskin",
"upgrade.minecraft.diamond_sword.adjective": "Kjempende",
"upgrade.minecraft.diamond_shovel.adjective": "Gravende",
"upgrade.minecraft.diamond_pickaxe.adjective": "Brytende",
"upgrade.minecraft.diamond_axe.adjective": "Hoggende",
"upgrade.minecraft.diamond_hoe.adjective": "Dyrkende",
"upgrade.minecraft.crafting_table.adjective": "Håndverks",
"upgrade.computercraft.wireless_modem_normal.adjective": "Trådløs",
"upgrade.computercraft.wireless_modem_advanced.adjective": "Ender",
"upgrade.computercraft.speaker.adjective": "Høylydt",
"chat.computercraft.wired_modem.peripheral_connected": "Perifer \"%s\" koblet til nettverk",
"chat.computercraft.wired_modem.peripheral_disconnected": "Perifer \"%s\" koblet fra nettverk",
"commands.computercraft.synopsis": "Forskjellige kommandoer for å kontrollere datamaskiner.",
"commands.computercraft.desc": "Kommandoen /computercraft gir forskjellige feilsøkings- og administratorverktøy for å kontrollere og handle med datamaskiner.",
"commands.computercraft.help.synopsis": "Gi hjelp til en spesifikk kommando",
"commands.computercraft.help.desc": "Viser denne hjelpemeldingen",
"commands.computercraft.help.no_children": "%s har ingen underkommandoer",
"commands.computercraft.help.no_command": "Ingen kommando '%s'",
"commands.computercraft.dump.synopsis": "Viser statusen av datamaskiner.",
"commands.computercraft.dump.desc": "Viser statusen til alle datamaskiner eller spesifikk informasjon om én datamaskin. Du kan spesifisere datamaskinens forekomst id (f. eks 123), datamaskinens id (f. eks #123) eller datamaskinens merkelapp (f. eks \"@Min datamaskin\").",
"commands.computercraft.dump.action": "Vis mer informasjon om denne datamaskinen",
"commands.computercraft.dump.open_path": "Vis datamaskinens filer",
"commands.computercraft.shutdown.synopsis": "Slå av datamaskiner eksternt.",
"commands.computercraft.shutdown.desc": "Slå av de oppførte datamaskinene eller alle hvis ingen er spesifisert. Du kan spesifisere datamaskinens forekomst (f. eks 123), datamaskinens id (f. eks #123) eller merkelapp (f.eks \"@Min datamaskin\").",
"commands.computercraft.shutdown.done": "Skrudde av %s/%s datamaskiner",
"commands.computercraft.turn_on.synopsis": "Slå på datamaskiner eksternt.",
"commands.computercraft.turn_on.desc": "Slå på de oppførte datamaskinene. Du kan spesifisere datamaskinens forekomst id (f. eks 123), datamaskinens id (f.eks #123) eller navnelapp (f. eks \"@Min Datamaskin\").",
"commands.computercraft.turn_on.done": "Skrudde på %s/%s datamaskiner",
"commands.computercraft.tp.synopsis": "Teleporter til en spesifikk datamaskin.",
"commands.computercraft.tp.desc": "Teleporter til en datamaskin sin posisjon. Du kan enten spesifisere datamaskinens forekomst id (f. eks 123) eller datamaskinens id (f. eks #123).",
"commands.computercraft.tp.action": "Teleporter til denne datamaskinen",
"commands.computercraft.tp.not_player": "Kan kun åpne terminalen for spillere",
"commands.computercraft.tp.not_there": "Greide ikke å finne datamaskinen i denne verdenen",
"commands.computercraft.view.synopsis": "Vis terminal til en datamaskin.",
"commands.computercraft.view.desc": "Åpner terminalen til en datamaskin, lar deg fjernstyre den. Dette gir deg ikke tilgang til skilpadders inventar. Du kan enten spesifisere datamaskinens forekomst id (f. eks 123) eller datamaskinens id (f. eks #123).",
"commands.computercraft.view.action": "Vis denne datamaskinen",
"commands.computercraft.view.not_player": "Kan kun åpne terminal for spillere",
"commands.computercraft.track.synopsis": "Spor utførelsestider for datamaskiner.",
"commands.computercraft.track.desc": "Spor hvor lenge datamaskiner kjører, samt hvor mange hendelser de handler. Dette presenterer informasjon i en lignende vei til /forge track og kan være nyttig for å diagnostisere lagg.",
"commands.computercraft.track.start.synopsis": "Start sporing av alle datamaskiner",
"commands.computercraft.track.start.desc": "Start sporing av alle datamaskiners utførselstider og hendelser. Dette vil fjerne resultatene fra tidligere kjøringer.",
"commands.computercraft.track.start.stop": "Kjør %s for å stoppe sporingen og vise resultatene",
"commands.computercraft.track.stop.synopsis": "Stopp sporing av alle datamaskiner",
"commands.computercraft.track.stop.desc": "Stopp sporing av alle datamaskiners hendelser og utførelsestider",
"commands.computercraft.track.stop.action": "Klikk for å stoppe sporing",
"commands.computercraft.track.stop.not_enabled": "Sporer ingen datamaskiner",
"commands.computercraft.track.dump.synopsis": "Dump nyeste sporingsresultater",
"commands.computercraft.track.dump.desc": "Dump de nyeste resultatene av datamaskin sporing.",
"commands.computercraft.track.dump.no_timings": "Ingen timere tilgjengelige",
"commands.computercraft.track.dump.computer": "Datamaskin",
"commands.computercraft.reload.synopsis": "Last inn ComputerCraft sin konfigurasjonsfil på nytt",
"commands.computercraft.reload.desc": "Last inn ComputerCraft sin konfigurasjonsfil på nytt",
"commands.computercraft.reload.done": "Lastet konfigurasjon på nytt",
"commands.computercraft.queue.synopsis": "Send en computer_command hendelse til en kommando datamaskin",
"commands.computercraft.queue.desc": "Send en computer_command hendelse til en kommando datamaskin, sender også tilleggs-argumentene Dette er hovedsakelig designet for kartskapere, og fungerer som en mer datamaskin vennlig versjon av /trigger. Enhver spiller kan kjøre kommandoen, som mest sannsynlig vil bli gjort gjennom en tekst komponent sin klikk hendelse.",
"commands.computercraft.generic.no_position": "<ingen posisjon>",
"commands.computercraft.generic.position": "%s, %s, %s",
"commands.computercraft.generic.yes": "J",
"commands.computercraft.generic.no": "N",
"commands.computercraft.generic.exception": "Uhåndtert unntak (%s)",
"commands.computercraft.generic.additional_rows": "%d flere rader…",
"argument.computercraft.computer.no_matching": "Ingen datamaskiner som samsvarer med '%s'",
"argument.computercraft.computer.many_matching": "Flere datamaskiner samsvarer '%s' (%s treff)",
"argument.computercraft.tracking_field.no_field": "Ukjent felt '%s'",
"argument.computercraft.argument_expected": "Argument forventet",
"tracking_field.computercraft.tasks.name": "Jobber",
"tracking_field.computercraft.total.name": "Total tid",
"tracking_field.computercraft.average.name": "Gjennomsnitt tid",
"tracking_field.computercraft.max.name": "Maksimum tid",
"tracking_field.computercraft.server_count.name": "Server jobbantall",
"tracking_field.computercraft.server_time.name": "Server jobb tid",
"tracking_field.computercraft.peripheral.name": "Perifere kjøringer",
"tracking_field.computercraft.fs.name": "Filsystem operasjoner",
"tracking_field.computercraft.turtle.name": "Skilpadde operasjoner",
"tracking_field.computercraft.http.name": "HTTP-forespørsler",
"tracking_field.computercraft.http_upload.name": "HTTP-opplasting",
"tracking_field.computercraft.http_download.name": "HTTP-nedlasting",
"tracking_field.computercraft.websocket_incoming.name": "Innkommende Websocket",
"tracking_field.computercraft.websocket_outgoing.name": "Utgående Websocket",
"tracking_field.computercraft.coroutines_created.name": "Skapte coroutines",
"tracking_field.computercraft.coroutines_dead.name": "Kastede coroutiner",
"gui.computercraft.tooltip.copy": "Kopier til utklippstavle",
"gui.computercraft.tooltip.computer_id": "Datamaskin ID: %s",
"gui.computercraft.tooltip.disk_id": "Disk ID: %s",
"gui.computercraft.tooltip.turn_on": "Slå denne datamaskinen på",
"gui.computercraft.tooltip.turn_on.key": "Hold Ctrl + R",
"gui.computercraft.tooltip.turn_off": "Skru denne datamaskinen av",
"gui.computercraft.tooltip.turn_off.key": "Hold Ctrl + S",
"gui.computercraft.tooltip.terminate": "Stopp den kjørende koden",
"gui.computercraft.tooltip.terminate.key": "Hold Ctrl + T",
"gui.computercraft.upload.success": "Vellykket opplasting",
"gui.computercraft.upload.success.msg": "%d filer lastet opp.",
"gui.computercraft.upload.failed": "Opplasting Feilet",
"gui.computercraft.upload.failed.out_of_space": "Ikke nok lagringsplass på datamaskinen for disse filene.",
"gui.computercraft.upload.failed.computer_off": "Du må skru på datamaskinen før du kan laste opp filer.",
"gui.computercraft.upload.failed.too_much": "Filene dine er for store for å kunne bli lastet opp.",
"gui.computercraft.upload.failed.name_too_long": "Fil navnene er for lange til å bli lastet opp.",
"gui.computercraft.upload.failed.too_many_files": "Kan ikke laste opp så mange filer.",
"gui.computercraft.upload.failed.overwrite_dir": "Kan ikke laste opp %s, siden det allerede er en mappe med det samme navnet.",
"gui.computercraft.upload.failed.generic": "Opplasting av filer feilet (%s)",
"gui.computercraft.upload.failed.corrupted": "Filene ble korrupt mens opplasting. Vennligst prøv igjen.",
"gui.computercraft.upload.overwrite": "Filer ville blitt overskrevet",
"gui.computercraft.upload.overwrite.detail": "Følgende filer vil bli overskrevet under opplasting. Fortsette?%s",
"gui.computercraft.upload.overwrite_button": "Overskriv",
"gui.computercraft.pocket_computer_overlay": "Lommedatamaskin åpen. Trykk ESC for å lukke."
}

View File

@@ -1,5 +1,6 @@
{
"parent": "block/cube",
"render_type": "cutout",
"textures": {
"particle": "#front",
"down": "#top",

View File

@@ -1,5 +1,6 @@
{
"parent": "block/block",
"render_type": "translucent",
"textures": {
"particle": "#texture"
},

View File

@@ -10,8 +10,8 @@ gps program.
:::note
When entering in the coordinates for the host you need to put in the `x`, `y`,
and `z` coordinates of the computer, not the modem, as all modem distances are
measured from the block the computer is in.
and `z` coordinates of the block that the modem is connected to, not the modem.
All modem distances are measured from the block that the modem is placed on.
:::
Also note that you may choose which axes x, y, or z refers to - so long as your
@@ -24,6 +24,7 @@ height in the way that Minecraft's debug screen displays.
@module gps
@since 1.31
@see gps_setup For more detailed instructions on setting up GPS
]]
local expect = dofile("rom/modules/main/cc/expect.lua").expect

View File

@@ -1,3 +1,27 @@
# New features in CC: Tweaked 1.100.9
* Add documentation for setting up GPS (Lupus590).
* Add WAV support to the `speaker` program (MCJack123).
* Expose item groups in `getItemDetail` (itisluiz).
* Other fixes to documentation (Erb3, JohnnyIrvin).
* Add Norwegian translation (Erb3).
Several bug fixes:
* Fix z-fighting on bold printout borders (toad-dev).
* Fix `term.blit` failing on certain strings.
* Fix `getItemLimit()` using the wrong slot (heap-underflow).
* Increase size of monitor depth blocker.
# New features in CC: Tweaked 1.100.8
Several bug fixes:
* Fix NPE within disk drive and printer code.
# New features in CC: Tweaked 1.100.7
* Fix failing to launch outside of a dev environment.
# New features in CC: Tweaked 1.100.6
* Various documentation improvements (MCJack123, FayneAldan).

View File

@@ -1,17 +1,15 @@
New features in CC: Tweaked 1.100.6
New features in CC: Tweaked 1.100.9
* Various documentation improvements (MCJack123, FayneAldan).
* Allow CC's blocks to be rotated when used in structure blocks (Seniorendi).
* Several performance improvements to computer execution.
* Add parse_empty_array option to textutils.unserialiseJSON (@ChickChicky).
* Add an API to allow other mods to provide extra item/block details (Lemmmy).
* All blocks with GUIs can now be "locked" (via a command or NBT editing tools) like vanilla inventories. Players can only interact with them with a specific named item.
* Add documentation for setting up GPS (Lupus590).
* Add WAV support to the `speaker` program (MCJack123).
* Expose item groups in `getItemDetail` (itisluiz).
* Other fixes to documentation (Erb3, JohnnyIrvin).
* Add Norwegian translation (Erb3).
Several bug fixes:
* Fix printouts being rendered with an offset in item frames (coolsa).
* Reduce position latency when playing audio with a noisy pocket computer.
* Fix total counts in /computercraft turn-on/shutdown commands.
* Fix "Run" command not working in the editor when run from a subdirectory (Wojbie).
* Pocket computers correctly preserve their on state.
* Fix z-fighting on bold printout borders (toad-dev).
* Fix `term.blit` failing on certain strings.
* Fix `getItemLimit()` using the wrong slot (heap-underflow).
* Increase size of monitor depth blocker.
Type "help changelog" to see the full version history.

View File

@@ -18,6 +18,14 @@ local function get_speakers(name)
end
end
local function pcm_decoder(chunk)
local buffer = {}
for i = 1, #chunk do
buffer[i] = chunk:byte(i) - 128
end
return buffer
end
local cmd = ...
if cmd == "stop" then
@@ -40,12 +48,63 @@ elseif cmd == "play" then
error(err, 0)
end
local start = handle.read(4)
local pcm = false
local size = 16 * 1024 - 4
if start == "RIFF" then
handle.read(4)
if handle.read(8) ~= "WAVEfmt " then
handle.close()
error("Could not play audio: Unsupported WAV file", 0)
end
local fmtsize = ("<I4"):unpack(handle.read(4))
local fmt = handle.read(fmtsize)
local format, channels, rate, _, _, bits = ("<I2I2I4I4I2I2"):unpack(fmt)
if not ((format == 1 and bits == 8) or (format == 0xFFFE and bits == 1)) then
handle.close()
error("Could not play audio: Unsupported WAV file", 0)
end
if channels ~= 1 or rate ~= 48000 then
print("Warning: Only 48 kHz mono WAV files are supported. This file may not play correctly.")
end
if format == 0xFFFE then
local guid = fmt:sub(25)
if guid ~= "\x3A\xC1\xFA\x38\x81\x1D\x43\x61\xA4\x0D\xCE\x53\xCA\x60\x7C\xD1" then -- DFPWM format GUID
handle.close()
error("Could not play audio: Unsupported WAV file", 0)
end
size = size + 4
else
pcm = true
size = 16 * 1024 * 8
end
repeat
local chunk = handle.read(4)
if chunk == nil then
handle.close()
error("Could not play audio: Invalid WAV file", 0)
elseif chunk ~= "data" then -- Ignore extra chunks
local size = ("<I4"):unpack(handle.read(4))
handle.read(size)
end
until chunk == "data"
handle.read(4)
start = nil
end
print("Playing " .. file)
local decoder = require "cc.audio.dfpwm".make_decoder()
local decoder = pcm and pcm_decoder or require "cc.audio.dfpwm".make_decoder()
while true do
local chunk = handle.read(16 * 1024)
local chunk = handle.read(size)
if not chunk then break end
if start then
chunk, start = start .. chunk, nil
size = size + 4
end
local buffer = decoder(chunk)
while not speaker.playAudio(buffer) do

View File

@@ -14,9 +14,12 @@ import net.minecraft.network.FriendlyByteBuf;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import static dan200.computercraft.core.terminal.TerminalMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.*;
class TerminalTest
@@ -366,6 +369,19 @@ class TerminalTest
callCounter.assertNotCalled();
}
@Test
public void testBlitPartialBuffer()
{
Terminal terminal = new Terminal( 4, 3 );
ByteBuffer text = LuaValues.encode( "123456" );
text.position( 1 );
terminal.blit( text, LuaValues.encode( "aaaaaa" ), LuaValues.encode( "aaaaaa" ) );
assertThat( terminal.getLine( 0 ).toString(), equalTo( "2345" ) );
}
@Test
void testWriteFromOrigin()
{

View File

@@ -118,6 +118,19 @@ describe("The os library", function()
end)
describe("os.time", function()
it("supports in-game time", function()
expect(os.time("ingame")):equal(os.time())
end)
it("supports local and utc time", function()
os.time("utc")
os.time("local")
end)
it("fails on other times", function()
expect.error(os.time, "unknown"):eq("Unsupported operation")
end)
it("maps directly to seconds", function()
local t1 = os.time { year = 2000, month = 10, day = 1, hour = 23, min = 12, sec = 17 }
local t2 = os.time { year = 2000, month = 10, day = 1, hour = 23, min = 10, sec = 19 }
@@ -125,6 +138,38 @@ describe("The os library", function()
end)
end)
describe("os.day", function()
it("supports in-game time", function()
expect(os.day("ingame")):equal(os.day())
end)
it("supports local and utc time", function()
os.day("utc")
os.day("local")
end)
it("fails on other times", function()
expect.error(os.day, "unknown"):eq("Unsupported operation")
end)
end)
describe("os.epoch", function()
it("supports in-game time", function()
local in_game = os.epoch("ingame")
local default = os.epoch()
assert(math.abs(default - in_game) < 5)
end)
it("supports local and utc time", function()
os.epoch("utc")
os.epoch("local")
end)
it("fails on other times", function()
expect.error(os.epoch, "unknown"):eq("Unsupported operation")
end)
end)
describe("os.loadAPI", function()
it("validates arguments", function()
expect.error(os.loadAPI, nil):eq("bad argument #1 (expected string, got nil)")

View File

@@ -137,7 +137,7 @@ fun GameTestHelper.sequence(run: GameTestSequence.() -> GameTestSequence) {
run(startSequence()).thenSucceed()
}
private fun getName(type: BlockEntityType<*>): ResourceLocation = ForgeRegistries.BLOCK_ENTITIES.getKey(type)!!
private fun getName(type: BlockEntityType<*>): ResourceLocation = ForgeRegistries.BLOCK_ENTITY_TYPES.getKey(type)!!
fun <T : BlockEntity> GameTestHelper.getBlockEntity(pos: BlockPos, type: BlockEntityType<T>): T {
val tile = getBlockEntity(pos)

View File

@@ -29,7 +29,7 @@ public final class ClientHooks
}
@SubscribeEvent
public static void onGuiInit( ScreenEvent.InitScreenEvent event )
public static void onGuiInit( ScreenEvent.Init event )
{
if( triggered || !(event.getScreen() instanceof TitleScreen) ) return;
triggered = true;